ocsf-semtools 0.1.0a4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. ocsf_semtools-0.1.0a4/.gitignore +20 -0
  2. ocsf_semtools-0.1.0a4/.importlinter +46 -0
  3. ocsf_semtools-0.1.0a4/CHANGELOG.md +106 -0
  4. ocsf_semtools-0.1.0a4/CONTRIBUTING.md +129 -0
  5. ocsf_semtools-0.1.0a4/LICENSE +202 -0
  6. ocsf_semtools-0.1.0a4/Makefile +114 -0
  7. ocsf_semtools-0.1.0a4/NOTICE +19 -0
  8. ocsf_semtools-0.1.0a4/PKG-INFO +218 -0
  9. ocsf_semtools-0.1.0a4/README.md +189 -0
  10. ocsf_semtools-0.1.0a4/SECURITY.md +22 -0
  11. ocsf_semtools-0.1.0a4/docs/cli.md +90 -0
  12. ocsf_semtools-0.1.0a4/docs/diff.md +63 -0
  13. ocsf_semtools-0.1.0a4/docs/events.md +174 -0
  14. ocsf_semtools-0.1.0a4/docs/models.md +107 -0
  15. ocsf_semtools-0.1.0a4/docs/observables.md +81 -0
  16. ocsf_semtools-0.1.0a4/docs/schema.md +149 -0
  17. ocsf_semtools-0.1.0a4/ocsf.lock +114 -0
  18. ocsf_semtools-0.1.0a4/packaging/build-requirements.txt +14 -0
  19. ocsf_semtools-0.1.0a4/packaging/version_dist/README.md.tmpl +22 -0
  20. ocsf_semtools-0.1.0a4/packaging/version_dist/dist.py +270 -0
  21. ocsf_semtools-0.1.0a4/packaging/version_dist/pyproject.toml.tmpl +38 -0
  22. ocsf_semtools-0.1.0a4/pyproject.toml +134 -0
  23. ocsf_semtools-0.1.0a4/src/ocsf_semtools/__init__.py +51 -0
  24. ocsf_semtools-0.1.0a4/src/ocsf_semtools/_version.py +24 -0
  25. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/__init__.py +48 -0
  26. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/_common.py +61 -0
  27. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/_upstream.py +153 -0
  28. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/check.py +83 -0
  29. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/compile.py +57 -0
  30. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/diff.py +65 -0
  31. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/generate.py +118 -0
  32. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/ir.py +119 -0
  33. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/lock.py +341 -0
  34. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/models.py +96 -0
  35. ocsf_semtools-0.1.0a4/src/ocsf_semtools/cli/trees.py +27 -0
  36. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/__init__.py +10 -0
  37. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/emit.py +290 -0
  38. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/generate.py +358 -0
  39. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/layout.py +74 -0
  40. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/naming.py +78 -0
  41. ocsf_semtools-0.1.0a4/src/ocsf_semtools/codegen/types.py +27 -0
  42. ocsf_semtools-0.1.0a4/src/ocsf_semtools/conform.py +414 -0
  43. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.0.0.json +28073 -0
  44. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.1.0.json +41579 -0
  45. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.2.0.json +50321 -0
  46. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.3.0.json +57198 -0
  47. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.4.0.json +85424 -0
  48. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.5.0.json +91969 -0
  49. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.6.0.json +94639 -0
  50. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.7.0.json +96525 -0
  51. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.8.0.json +98267 -0
  52. ocsf_semtools-0.1.0a4/src/ocsf_semtools/data/ir-1.9.0.json +108067 -0
  53. ocsf_semtools-0.1.0a4/src/ocsf_semtools/derive.py +276 -0
  54. ocsf_semtools-0.1.0a4/src/ocsf_semtools/diff.py +127 -0
  55. ocsf_semtools-0.1.0a4/src/ocsf_semtools/engine.py +298 -0
  56. ocsf_semtools-0.1.0a4/src/ocsf_semtools/export.py +470 -0
  57. ocsf_semtools-0.1.0a4/src/ocsf_semtools/ir.py +335 -0
  58. ocsf_semtools-0.1.0a4/src/ocsf_semtools/loader.py +290 -0
  59. ocsf_semtools-0.1.0a4/src/ocsf_semtools/models.py +235 -0
  60. ocsf_semtools-0.1.0a4/src/ocsf_semtools/observables.py +198 -0
  61. ocsf_semtools-0.1.0a4/src/ocsf_semtools/py.typed +0 -0
  62. ocsf_semtools-0.1.0a4/src/ocsf_semtools/schema.py +319 -0
  63. ocsf_semtools-0.1.0a4/src/ocsf_semtools/walk.py +284 -0
  64. ocsf_semtools-0.1.0a4/tests/__init__.py +0 -0
  65. ocsf_semtools-0.1.0a4/tests/architecture/__init__.py +0 -0
  66. ocsf_semtools-0.1.0a4/tests/architecture/support.py +6 -0
  67. ocsf_semtools-0.1.0a4/tests/architecture/test_docs.py +50 -0
  68. ocsf_semtools-0.1.0a4/tests/architecture/test_imports.py +119 -0
  69. ocsf_semtools-0.1.0a4/tests/architecture/test_scope.py +26 -0
  70. ocsf_semtools-0.1.0a4/tests/bench/__init__.py +0 -0
  71. ocsf_semtools-0.1.0a4/tests/bench/engine.py +151 -0
  72. ocsf_semtools-0.1.0a4/tests/conftest.py +49 -0
  73. ocsf_semtools-0.1.0a4/tests/fixtures/__init__.py +0 -0
  74. ocsf_semtools-0.1.0a4/tests/fixtures/compiled.py +182 -0
  75. ocsf_semtools-0.1.0a4/tests/fixtures/events.py +131 -0
  76. ocsf_semtools-0.1.0a4/tests/fixtures/notations.py +10 -0
  77. ocsf_semtools-0.1.0a4/tests/fixtures/packages.py +42 -0
  78. ocsf_semtools-0.1.0a4/tests/generated/__init__.py +0 -0
  79. ocsf_semtools-0.1.0a4/tests/generated/conftest.py +45 -0
  80. ocsf_semtools-0.1.0a4/tests/generated/samples/usage.py +43 -0
  81. ocsf_semtools-0.1.0a4/tests/generated/test_import.py +68 -0
  82. ocsf_semtools-0.1.0a4/tests/generated/test_readme.py +24 -0
  83. ocsf_semtools-0.1.0a4/tests/generated/test_snapshot.py +19 -0
  84. ocsf_semtools-0.1.0a4/tests/generated/test_static.py +54 -0
  85. ocsf_semtools-0.1.0a4/tests/golden/detection_finding_1_9_0.py +178 -0
  86. ocsf_semtools-0.1.0a4/tests/property/__init__.py +0 -0
  87. ocsf_semtools-0.1.0a4/tests/property/strategies.py +217 -0
  88. ocsf_semtools-0.1.0a4/tests/property/test_hostile.py +69 -0
  89. ocsf_semtools-0.1.0a4/tests/property/test_repair.py +159 -0
  90. ocsf_semtools-0.1.0a4/tests/property/test_roundtrip.py +75 -0
  91. ocsf_semtools-0.1.0a4/tests/property/test_strategies.py +35 -0
  92. ocsf_semtools-0.1.0a4/tests/unit/__init__.py +0 -0
  93. ocsf_semtools-0.1.0a4/tests/unit/cli/__init__.py +0 -0
  94. ocsf_semtools-0.1.0a4/tests/unit/cli/conftest.py +48 -0
  95. ocsf_semtools-0.1.0a4/tests/unit/cli/support.py +58 -0
  96. ocsf_semtools-0.1.0a4/tests/unit/cli/test_check.py +111 -0
  97. ocsf_semtools-0.1.0a4/tests/unit/cli/test_compile.py +253 -0
  98. ocsf_semtools-0.1.0a4/tests/unit/cli/test_diff.py +91 -0
  99. ocsf_semtools-0.1.0a4/tests/unit/cli/test_generate.py +129 -0
  100. ocsf_semtools-0.1.0a4/tests/unit/cli/test_ir.py +124 -0
  101. ocsf_semtools-0.1.0a4/tests/unit/cli/test_lock.py +277 -0
  102. ocsf_semtools-0.1.0a4/tests/unit/cli/test_main.py +40 -0
  103. ocsf_semtools-0.1.0a4/tests/unit/cli/test_models.py +72 -0
  104. ocsf_semtools-0.1.0a4/tests/unit/codegen/__init__.py +0 -0
  105. ocsf_semtools-0.1.0a4/tests/unit/codegen/test_emit.py +113 -0
  106. ocsf_semtools-0.1.0a4/tests/unit/codegen/test_generate.py +251 -0
  107. ocsf_semtools-0.1.0a4/tests/unit/codegen/test_naming.py +100 -0
  108. ocsf_semtools-0.1.0a4/tests/unit/codegen/test_types_layout.py +57 -0
  109. ocsf_semtools-0.1.0a4/tests/unit/conftest.py +41 -0
  110. ocsf_semtools-0.1.0a4/tests/unit/test_conform.py +291 -0
  111. ocsf_semtools-0.1.0a4/tests/unit/test_derive.py +307 -0
  112. ocsf_semtools-0.1.0a4/tests/unit/test_diff.py +184 -0
  113. ocsf_semtools-0.1.0a4/tests/unit/test_engine.py +515 -0
  114. ocsf_semtools-0.1.0a4/tests/unit/test_export.py +196 -0
  115. ocsf_semtools-0.1.0a4/tests/unit/test_ir_loader.py +284 -0
  116. ocsf_semtools-0.1.0a4/tests/unit/test_models.py +263 -0
  117. ocsf_semtools-0.1.0a4/tests/unit/test_observables.py +245 -0
  118. ocsf_semtools-0.1.0a4/tests/unit/test_packaging.py +149 -0
  119. ocsf_semtools-0.1.0a4/tests/unit/test_public_api.py +91 -0
  120. ocsf_semtools-0.1.0a4/tests/unit/test_schema.py +409 -0
  121. ocsf_semtools-0.1.0a4/tests/unit/test_walk.py +137 -0
  122. ocsf_semtools-0.1.0a4/uv.lock +736 -0
@@ -0,0 +1,20 @@
1
+ # build outputs: compiled schemas, schema checkouts, generated dists, wheels
2
+ build/
3
+ dist/
4
+ *.egg-info/
5
+
6
+ # written by hatch-vcs at build time
7
+ src/ocsf_semtools/_version.py
8
+
9
+ # environments and caches
10
+ .venv/
11
+ __pycache__/
12
+ *.py[cod]
13
+ .pytest_cache/
14
+ .ruff_cache/
15
+ .mypy_cache/
16
+ .import_linter_cache/
17
+ .coverage
18
+ .coverage.*
19
+ htmlcov/
20
+ .DS_Store
@@ -0,0 +1,46 @@
1
+ # Import contracts: the core layering, the msgspec boundary, and no imports of generated packages.
2
+ # (A `forbidden` contract errors on a missing source module, so per-module rules are expressed
3
+ # as layers or anchored on the root package.)
4
+
5
+ [importlinter]
6
+ root_package = ocsf_semtools
7
+ include_external_packages = True
8
+
9
+ # ir <- loader/export <- schema <- walk <- derive/conform/observables <- engine <- models,
10
+ # with codegen and diff beside walk: they may use schema and below, nothing above, not each other.
11
+ # cli is the outermost layer; nothing in core imports it.
12
+ [importlinter:contract:layers]
13
+ name = Core layering (codegen and diff depend on schema only)
14
+ type = layers
15
+ containers = ocsf_semtools
16
+ layers =
17
+ cli
18
+ models
19
+ engine
20
+ derive | conform | observables
21
+ walk | codegen | diff
22
+ schema
23
+ loader | export
24
+ ir
25
+
26
+ # Architecture rule 2 also allows codegen to import msgspec; it has no need to, so this is stricter.
27
+ [importlinter:contract:msgspec-boundary]
28
+ name = Only models imports msgspec
29
+ type = forbidden
30
+ source_modules =
31
+ ocsf_semtools
32
+ forbidden_modules =
33
+ msgspec
34
+ allow_indirect_imports = True
35
+ ignore_imports =
36
+ ocsf_semtools.models -> msgspec
37
+
38
+ [importlinter:contract:no-generated-packages]
39
+ name = Nothing in ocsf_semtools imports a generated version package (ocsf_semtools_v*)
40
+ type = forbidden
41
+ source_modules =
42
+ ocsf_semtools
43
+ forbidden_modules =
44
+ ocsf_semtools_v1_7_0
45
+ ocsf_semtools_v1_8_0
46
+ ocsf_semtools_v1_9_0
@@ -0,0 +1,106 @@
1
+ # Changelog
2
+
3
+ The library follows SemVer on its own API; before 1.0, a minor release may change it. OCSF schema
4
+ versions are data, so support for a new OCSF version ships as a minor release. Each change gets a
5
+ line here, written for users, in the commit that makes it.
6
+
7
+ ## Unreleased
8
+
9
+ ### Changed
10
+
11
+ - The project is now ocsf-semtools: `pip install ocsf-semtools`, `import ocsf_semtools`, the
12
+ `ocsf-semtools` command, and model packages such as `ocsf-semtools-v1-9-0`. Releases up to 0.1.0a3
13
+ were published as `ocsf-toolkit`, a name the Go project `ocsf/ocsf-toolkit` also uses.
14
+
15
+ ## 0.1.0a3 (2026-11-07)
16
+
17
+ The model packages are unchanged: their releases on PyPI run on this core.
18
+
19
+ ### Changed
20
+
21
+ - The command line exits 2 when a command can't do its job: a usage error, a missing file, an unknown version, profile or class, or a failed pipeline gate. Exit 1 now means only that `check` found an error or `diff` a difference.
22
+ - `parse` and `repair` read extensions from `metadata.extensions`, so an event of an extension class
23
+ such as `win/prefetch_query` is checked against that class; before, it was checked as `base_event`.
24
+ Both also take `schema=`, a schema from `load()` or `resolve()`, for custom extensions.
25
+ - Conformance enforces numbers as OCSF defines them: NaN and the infinities are a `type_mismatch` for
26
+ `float_t`, and `integer_t` and `long_t` values must fit in a signed 64-bit integer. An event that
27
+ passed before may now report these errors.
28
+ - An object an event holds twice, through a cycle or under two paths, is a `repeated_node` error and
29
+ is walked once. Every run stops after `max_nodes` attribute visits, 100,000 by default; `parse`,
30
+ `repair` and `extract` take `max_nodes=`, and `None` walks everything.
31
+ - An event that is not a dict raises `TypeError`; a malformed `(schema, class key)` reference is a
32
+ `TypeError`, and an unknown `class_key` is a `KeyError` naming the schema.
33
+ - `load_ir` reads a `str` as a path, and refuses NaN, infinity, an enum on a non-scalar type and a
34
+ table of the wrong kind. `resolve` refuses an IR with no `base_event`, an item in the wrong table,
35
+ an attribute naming a missing object, or non-integer `type_uid` keys. Each is a `ValueError` naming
36
+ the key path.
37
+ - Enum values in `enum_out_of_range` messages and in `expected` are listed in numeric order.
38
+ - `Report.to_dict()` always returns valid JSON, writing non-finite values as strings.
39
+ - A diff lists a renamed class once, without a separate change to its `key`, and sorts integer keys
40
+ numerically.
41
+ - Every package carries a NOTICE with the OCSF schema's attribution. Package metadata says Alpha and
42
+ links the documentation and issue tracker.
43
+ - Releases build with a pinned backend (`packaging/build-requirements.txt`), so a tag rebuilds to its
44
+ published hashes, and a release requires a passing CI run on the tagged commit.
45
+
46
+ ### Added
47
+
48
+ - `RepairAction` (the type of `Finding.repair`), `export_ir`, and `ConformanceError.fatal`, the
49
+ findings that stopped a build.
50
+ - `ResolvedItem.inactive`: the attributes that only inactive profiles add.
51
+ - `ResolvedSchema`, `Report` and `ConformanceError` can be pickled, so they cross process boundaries.
52
+
53
+ ### Removed
54
+
55
+ - `Policy`, `STRICT`, `LENIENT` and `REPAIR` from the public API. No function accepted them;
56
+ [Building and checking events](docs/events.md) says what each entry point changes.
57
+
58
+ ### Fixed
59
+
60
+ - `build()` and `parse(as_=...)` raised `AttributeError` for a model package generated inside another package (such as `myapp.acme_models`); they find the package root wherever it is nested, and a package regenerated in the same process is read again.
61
+ - A missing `git` or `uv` was reported as `[Errno 2] No such file or directory`; the error now says what to install, or to pass `--compiler-cmd`, and a broken cached checkout says to delete it.
62
+ - `generate()` accepted a class or enum named `Literal`, `Struct`, `IntEnum`, `StrEnum` or `Any`, which shadowed the module's import and broke it at import time; such names are refused.
63
+ - `ocsf-toolkit generate --ext` needed `ocsf.lock` in the current directory, which only a checkout of this repository has; it takes the pin from the shipped IR when there is none. An extension's hash leaves out hidden files such as `.git`, so a git operation no longer changes it.
64
+ - Generated code was not ruff-format stable for a required field whose line passed the width, which only long custom names reach; `generate()` now also refuses class, enum and field names over 100 characters, so every line can wrap.
65
+ - `generate()` lost the package it was replacing when both the swap and the restore failed; it now keeps it and names where it is.
66
+ - `build()` and `parse(as_=...)` on a superset model class raised `msgspec.ValidationError` for a
67
+ wrong-typed attribute of an inactive profile. Such values are checked now, and objects under them
68
+ walked.
69
+ - Events nested deeper than Python's recursion limit raised `RecursionError` from `build` and
70
+ `repair`, and an event holding a cycle made `parse` and `repair` hang.
71
+ - `type_uid` was derived from an `activity_id` the class doesn't define, so `activity_id=-1` produced
72
+ a plausible `type_uid` such as 400099.
73
+ - Observables were read before coercion, so `repair` reported a caller entry for a coerced value as
74
+ unfounded.
75
+ - A deprecated value moved into a successor present as null was never checked.
76
+ - `repair` reported unknown attributes instead of relocating them when the event had `unmapped: null`.
77
+ - `Report.by_kind("filled")` returned nothing; it matches a `Kind` or its name.
78
+ - A timezone-aware `datetime` with no UTC instant, such as year 1 at +01:00, raised `OverflowError`,
79
+ and an integer too long to print raised `ValueError` from a message.
80
+
81
+ ## 0.1.0a2 (2026-11-06)
82
+
83
+ - Publishes the model package `ocsf-toolkit-v1-9-0`.
84
+
85
+ ## 0.1.0a1 (2026-11-06)
86
+
87
+ The first alpha, with the model packages `ocsf-toolkit-v1-7-0` and `ocsf-toolkit-v1-8-0`.
88
+
89
+ - Every OCSF release from 1.0.0 to 1.9.0 ships as data. `load()` resolves a version under a set of
90
+ profiles and extensions into a `ResolvedSchema`: classes, objects, attribute requirements, enums,
91
+ sibling pairs, class identity and observable markers, with no model needed.
92
+ - `build()` constructs a conformant event and derives what the schema computes: class identity,
93
+ `type_uid`, sibling labels, `*_dt` timestamps and `metadata.version`. It raises one exception,
94
+ `ConformanceError`, carrying the full report.
95
+ - `parse()` checks an event and reports every deviation as a `Finding` in a `Report`; `repair()`
96
+ returns a normalized copy, with every change recorded as a finding.
97
+ - `extract()` and `merge()` derive an event's observables from the schema and check the ones it
98
+ already lists.
99
+ - `diff()` compares two OCSF versions or IRs, matching classes by uid so a renamed class shows as a
100
+ rename.
101
+ - `generate()` writes a typed package of msgspec Structs for any version or IR, including one with
102
+ your own extensions; `build()` and `parse()` take and return its classes.
103
+ - The `ocsf-toolkit` command line: `check`, `diff` (with `--json` and `--semver`), `generate`, and the
104
+ schema pipeline commands that maintain `ocsf.lock` and the shipped IRs.
105
+ - Releases are reproducible, publish to PyPI through trusted publishing, and attach `ocsf.lock` and
106
+ `SHA256SUMS` to a GitHub release.
@@ -0,0 +1,129 @@
1
+ # Contributing
2
+
3
+ ## Reporting a problem
4
+
5
+ Open an [issue](https://github.com/k4otix/ocsf-semtools/issues/new/choose). For a wrong finding or a
6
+ missed one, the bug template asks for what reproduces it: the OCSF version, the event (trimmed to
7
+ what matters) and `ocsf-semtools --version`. Report a security problem privately, as
8
+ [SECURITY.md](SECURITY.md) describes.
9
+
10
+ ## Setup
11
+
12
+ Requires [uv](https://docs.astral.sh/uv/) and git. The library runs on Python 3.12 or newer.
13
+ Compiling an OCSF schema needs Python 3.14, because `ocsf-schema-compiler` does; `uv` fetches it for
14
+ that step, so you don't need to install it yourself.
15
+
16
+ ```shell
17
+ make setup # uv sync: the dev environment in .venv
18
+ make format # ruff format and ruff check --fix
19
+ make lint # ruff format --check, ruff check, lint-imports
20
+ make type # pyright in strict mode (blocking), mypy --strict (informational)
21
+ make test # pytest, including the doctests in README.md and docs/
22
+ ```
23
+
24
+ `uvx pre-commit install` runs the blocking lint and type checks on every commit
25
+ (`.pre-commit-config.yaml`).
26
+
27
+ The schema pipeline and the model packages have their own targets:
28
+
29
+ ```shell
30
+ make schema # compile every lockfile schema and check every shipped IR against it
31
+ make ir VERSION=... # rewrite data/ir-<version>.json; RECORD=1 accepts a new IR hash
32
+ make lock VERSION=... # pin a new OCSF version (see below)
33
+ make generate OCSF=x.y.z # one model package, in build/dists/
34
+ make dists # every model-window package, then the regeneration check
35
+ make wheels # core and model sdists and wheels in build/wheels/ (a new directory), each wheel checked
36
+ make test-generated # pyright, the snapshot, laziness and a clean install over the built packages
37
+ make compat # the model packages on PyPI run on this core (LOCAL=1: the ones just built)
38
+ make bench # engine throughput, on this machine; not part of CI
39
+ make version # the version hatch-vcs derives, with the pinned build backend
40
+ make clean # remove build/ and the tool caches
41
+ make help # every target, with what it does
42
+ ```
43
+
44
+ ## Rules that bind code
45
+
46
+ These architecture rules bind the code, and a PR that needs to break one argues for it in its
47
+ description:
48
+
49
+ - One traversal of an event, `walk()`; derivation, conformance and observables are visitors on it.
50
+ - The import direction that `.importlinter` enforces: `ir` ← `loader`/`export` ← `schema` ← `walk` ←
51
+ `derive`/`conform`/`observables` ← `engine` ← `models`, with `codegen` and `diff` on `schema` alone.
52
+ - One exception type, `ConformanceError`; everything else is a builtin exception.
53
+ - No `__getattr__` in the library itself; lazy loading lives only in generated packages.
54
+ - Thin entry points: `build`, `parse` and `repair` each choose a policy, run the engine and convert.
55
+ - Thirteen core modules: `ir`, `loader`, `export`, `schema`, `walk`, `derive`, `conform`,
56
+ `observables`, `engine`, `diff`, `models`, `codegen` and `cli`.
57
+ - A query surface of read-only mappings, plus the few methods that compute something.
58
+
59
+ Conventions:
60
+
61
+ - No runtime dependencies besides `msgspec`. The CLI uses `argparse`.
62
+ - Each module's docstring states its single responsibility in one sentence.
63
+ - Lines are at most 120 characters; ruff format sets the layout.
64
+ - Every public module, class and function has a docstring whose first line is an imperative
65
+ summary (pydocstyle, pep257 convention). Tests are exempt.
66
+ - Docs and comments say what something is and does.
67
+
68
+ ## Pull requests
69
+
70
+ - `main` is protected: a PR needs the CI checks to pass and is squash-merged.
71
+ - Plain commit messages; no conventional-commits prefixes.
72
+ - A change users would notice gets a line in `CHANGELOG.md` under Unreleased, in the same PR.
73
+ - Changing `ocsf.lock`, the loader or the shipped IRs runs the schema workflow too.
74
+ - A compiler bump records its new hashes in the same PR, as [Bumping the compiler](#bumping-the-compiler)
75
+ describes.
76
+
77
+ ## Adding an OCSF version
78
+
79
+ A new OCSF release ships as a minor release of the library, with a model package for it.
80
+
81
+ 1. Pin it, ship its IR and move the model window:
82
+
83
+ ```shell
84
+ make lock VERSION=x.y.z # REF=<branch or tag> if the tag isn't x.y.z or vx.y.z
85
+ ```
86
+
87
+ This resolves the upstream tag (`x.y.z`, then `vx.y.z`), pins its commit, compiles it, records
88
+ `compiled_sha256`, exports the IR with its `ir_sha256`, and records `models_tree_sha256` for the
89
+ newest three versions. The compile fails if the compiled schema's `version` isn't `x.y.z`: tag
90
+ `1.5.0` upstream is one such case, so pin the branch with `REF=v1.5.0`. If a step fails, fix the
91
+ cause and run `make lock` again; a version already pinned at the same commit is kept.
92
+ 2. Add the new package, `ocsf_semtools_vX_Y_Z`, to `forbidden_modules` in `.importlinter`; a test
93
+ fails until you do.
94
+ 3. Update the package table in `docs/models.md`.
95
+ 4. Set up publishing for the new package, once:
96
+ - on PyPI, a pending trusted publisher for project `ocsf-semtools-vX-Y-Z`, repository
97
+ `k4otix/ocsf-semtools`, workflow `release.yaml`, environment `pypi-vX-Y-Z`;
98
+ - on GitHub, the environment `pypi-vX-Y-Z`, limited to `v*` tags like the others.
99
+
100
+ PyPI allows three pending publishers per account. While none is free, add `X.Y.Z` to the
101
+ repository variable `RELEASE_HOLD_DISTS`: the release builds and checks that package without
102
+ publishing it, and the next release after you clear the variable publishes it.
103
+ 5. The package that leaves the window gets no further releases and stays on the core minor it last
104
+ required; [Typed models](docs/models.md) tells its users their options. Note it in the
105
+ changelog.
106
+
107
+ ## Bumping the compiler
108
+
109
+ The compiler version in `[toolchain]` in `ocsf.lock` is part of every IR's provenance, so a bump
110
+ changes every hash:
111
+
112
+ ```shell
113
+ uv run ocsf-semtools compile --record # every compiled_sha256
114
+ make ir RECORD=1 # every ir_sha256 and data/ir-*.json
115
+ uv run ocsf-semtools models record # every models_tree_sha256
116
+ ```
117
+
118
+ Review the IR diffs (`ocsf-semtools diff OLD.json NEW.json`), since a compiler change can change the
119
+ schema itself. The next release republishes every model package in the window, as their trees
120
+ changed.
121
+
122
+ ## Releasing
123
+
124
+ 1. Run the release workflow by hand (Actions, release, Run workflow) on `main` as a dry run: it runs
125
+ every gate and builds every package twice, and publishes nothing.
126
+ 2. Tag the commit and push the tag: `git tag -s vX.Y.Z -m "ocsf-semtools X.Y.Z" && git push origin vX.Y.Z`.
127
+ The release needs a passing CI run on that commit.
128
+ 3. Approve the `release` environment when the workflow asks. It publishes the core and each model
129
+ package PyPI lacks, and attaches `ocsf.lock` and `SHA256SUMS` to a GitHub release.
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,114 @@
1
+ .PHONY: help setup format lint type test bench schema ir lock version generate dists wheels compat test-generated clean
2
+
3
+ UV ?= uv
4
+
5
+ # list the targets, each with the first line of its comment
6
+ help:
7
+ @awk '/^# / { if (!c) c = substr($$0, 3); next } /^[a-z][a-z-]*:/ { n = $$1; sub(/:.*/, "", n); \
8
+ if (c) printf " %-15s %s\n", n, c } { c = "" }' $(firstword $(MAKEFILE_LIST))
9
+
10
+ # create the dev environment in .venv
11
+ setup:
12
+ $(UV) sync
13
+
14
+ # rewrite the code the way ruff formats and fixes it
15
+ format:
16
+ $(UV) run ruff format .
17
+ $(UV) run ruff check --fix .
18
+
19
+ # ruff format --check, ruff check, and the import contracts
20
+ lint:
21
+ $(UV) run ruff format --check .
22
+ $(UV) run ruff check .
23
+ $(UV) run lint-imports
24
+
25
+ # pyright strict, the blocking gate, then mypy strict, informational
26
+ type:
27
+ $(UV) run pyright
28
+ -$(UV) run mypy
29
+
30
+ # the test suite, in random order, with the doctests in README.md and docs/
31
+ test:
32
+ $(UV) run pytest
33
+
34
+ # engine throughput at 2-20 KB per event, on this machine; slow, so not part of `test` or CI
35
+ bench:
36
+ $(UV) run python -m tests.bench.engine
37
+
38
+ # gates 1 and 2: compile every lockfile schema, then check every committed IR against it
39
+ schema:
40
+ $(UV) run ocsf-semtools compile
41
+ $(UV) run ocsf-semtools ir check
42
+
43
+ # rewrite data/ir-<ver>.json for VERSION (default: every entry with an ir_sha256); RECORD=1 accepts a new IR
44
+ ir:
45
+ $(UV) run ocsf-semtools ir export $(VERSION) $(if $(RECORD),--record)
46
+
47
+ # pin a new OCSF version, ship its IR and move the model window; safe to rerun after a failure
48
+ # (REF= pins a branch or tag of another name)
49
+ lock:
50
+ @test -n "$(VERSION)" || { echo "usage: make lock VERSION=x.y.z"; exit 2; }
51
+ $(UV) run ocsf-semtools lock --add $(VERSION) $(if $(REF),--ref $(REF))
52
+ $(UV) run ocsf-semtools ir export $(VERSION) --record
53
+ $(UV) run ocsf-semtools models record
54
+
55
+ # The model dist for one OCSF version as an installable project in build/dists/<package>/.
56
+ # Nothing here deletes: `generate` replaces <package>/ only if every file in it is generated,
57
+ # and the rendered project files are overwritten by name. The dist requires the core version
58
+ # building it, up to its next minor release.
59
+ OCSF ?= 1.9.0
60
+ PACKAGE = ocsf_semtools_v$(subst .,_,$(OCSF))
61
+ DIST = build/dists/$(PACKAGE)
62
+ # the model-window versions, from the one rule that defines them (cli/lock.py)
63
+ WINDOW = $(shell $(UV) run python -c 'from pathlib import Path; from ocsf_semtools.cli import lock; \
64
+ print(*lock.window(lock.read(Path("ocsf.lock"))))')
65
+ WHEELS = build/wheels
66
+ # Sdists and wheels carry this timestamp and the version of the backend that built them, so a commit
67
+ # rebuilt with the pinned backend gives identical bytes.
68
+ export SOURCE_DATE_EPOCH ?= $(shell git log -1 --format=%ct)
69
+ BUILD_CONSTRAINTS = packaging/build-requirements.txt
70
+ export UV_BUILD_CONSTRAINT := $(CURDIR)/$(BUILD_CONSTRAINTS)
71
+ VERSION_CMD = $(UV) tool run --quiet --constraints $(BUILD_CONSTRAINTS) --with hatch-vcs hatchling version
72
+
73
+ # the version hatch-vcs derives from git, with the pinned backend
74
+ version:
75
+ @$(VERSION_CMD)
76
+
77
+ # one model dist, OCSF=x.y.z (default 1.9.0), in build/dists/
78
+ generate:
79
+ @echo "$(OCSF)" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$$' || { echo "OCSF must be x.y.z"; exit 2; }
80
+ mkdir -p $(DIST)
81
+ $(UV) run ocsf-semtools generate $(OCSF) --package $(PACKAGE) --out $(DIST)
82
+ version=$$($(VERSION_CMD)) && \
83
+ $(UV) run python packaging/version_dist/dist.py render --ocsf $(OCSF) --version "$$version" \
84
+ --out $(DIST)
85
+
86
+ # every model-window dist, then regeneration gate 3 over the trees on disk
87
+ dists:
88
+ for v in $(WINDOW); do $(MAKE) --no-print-directory generate OCSF=$$v || exit 1; done
89
+ $(UV) run ocsf-semtools models check
90
+
91
+ # core and every model-window dist as sdist and wheel in build/wheels/, each wheel checked
92
+ # (WHEELS must not exist yet: wheels left from an earlier commit would be checked too)
93
+ wheels: dists
94
+ @test ! -e $(WHEELS) || { echo "$(WHEELS) exists; run make clean, or pass WHEELS=<new dir>"; exit 2; }
95
+ $(UV) build --quiet --out-dir $(WHEELS)
96
+ for v in $(WINDOW); do \
97
+ $(UV) build --quiet --out-dir $(WHEELS) build/dists/ocsf_semtools_v$$(echo $$v | tr . _) \
98
+ || exit 1; \
99
+ done
100
+ $(UV) run python packaging/version_dist/dist.py check-wheels $(WHEELS)/*.whl
101
+
102
+ # the released model dists (LOCAL=1: the wheels in build/wheels) run on the core in this checkout
103
+ compat:
104
+ version=$$($(VERSION_CMD)) && \
105
+ $(UV) run python packaging/version_dist/dist.py compat --version "$$version" \
106
+ $(if $(LOCAL),--wheels $(WHEELS))
107
+
108
+ # static analysis, snapshot, laziness and a clean-environment install of the generated dist
109
+ test-generated:
110
+ $(UV) run pytest tests/generated
111
+
112
+ # remove build/ and the tool caches
113
+ clean:
114
+ rm -rf build dist .pytest_cache .ruff_cache .mypy_cache .import_linter_cache
@@ -0,0 +1,19 @@
1
+ ocsf-semtools
2
+ Copyright 2026 Eddie Allan
3
+
4
+ This product bundles schema data compiled from the Open Cybersecurity Schema Framework (OCSF)
5
+ schema, https://github.com/ocsf/ocsf-schema, and its model packages are generated from that data.
6
+ The OCSF schema is licensed under the Apache License, Version 2.0, and carries this notice:
7
+
8
+ Open Cybersecurity Schema Framework
9
+
10
+ Copyright © OCSF a Series of LF Projects, LLC
11
+ For web site terms of use, trademark policy and other project policies please see https://lfprojects.org.
12
+
13
+ This project includes the ICD Schema developed by Symantec, a division of Broadcom.
14
+
15
+ Licensed under the Apache 2 license.
16
+ Refer to the Apache 2 license in the file LICENSE.
17
+
18
+ ocsf-semtools is an independent project. It is not affiliated with or endorsed by OCSF or
19
+ LF Projects, LLC.