Compile an Open Cybersecurity Schema Framework (OCSF) schema.
Project description
OCSF Schema Compiler
This is a Python library and command-line tool for compiling the Open Cybersecurity Schema Framework (OCSF) schema, specifically the schema at https://github.com/ocsf/ocsf-schema.
This project is published to PyPI: ocsf-schema-compiler · PyPI.
Getting started
There are three ways to use the OCSF Schema Compiler:
- As a command-line tool, installed from PyPI.
- As a library, installed from PyPI.
- As a developer working on this project.
Python version 3.14 or later is required. The core project code does not require any dependencies, though optional developer dependencies are used (see below).
Using ocsf-schema-compiler as a command-line tool
Create a virtual environment then install with pip. For example:
python3 -m venv .venv
source ./.venv/bin/activate
python -m pip install ocsf-schema-compiler
Running from this environment is now a matter of calling ocsf-schema-compiler:
ocsf-schema-compiler -h
The basic usage is passing the base directory of a schema to the compiler and capturing the output to a file.
ocsf-schema-compiler path/to/ocsf-schema > schema.json
Using ocsf-schema-compiler as a library
Create a virtual environment then install with pip. For example:
python3 -m venv .venv
source ./.venv/bin/activate
python -m pip install ocsf-schema-compiler
The compiler is implemented in the SchemaCompiler class. The class constructor accepts the same options as the command-line tool. The class's compile method does the heavy lifting, returning a dict containing the compiled schema. Specifically, compiler returns an ocsf_schema_compiler.jsonish.JObject, which is a type alias for JSON-compatible dict.
from pathlib import Path
from ocsf_schema_compiler.compiler import SchemaCompiler
compiler = SchemaCompiler(Path("path/to/ocsf-schema"))
output = compiler.compile()
See ocsf_schema_compiler.__main__ for a working example.
Developing ocsf-schema-compiler
The recommended way to work on OCSF projects is to create fork in your own GitHub profile or organization. Create your fork of this repo using the GitHub CLI tool (or, more painfully, manually).
This project requires Python 3.14 or later; otherwise, it has no runtime dependencies. This means you can run it directly from a cloned repo's src directory without creating a virtual environment.
cd path/to/ocsf-schema-compiler
cd src
python3 -m ocsf_schema_compiler ~/path/to/ocsf-schema > ~/path/to/output/schema.json
This project includes regression tests in the tests directory, built using the unittest library. These can also be run without a virtual environment so long as python3 refers to Python 3.14 or later. The tests can be run with the Makefile target tests.
make tests
This project uses basedpyright for type checking and Ruff for linting and code formatting.
Basedpyright was picked as an alternative to Pylance because I'm using the open-source and telemetry-free VSCodium variation of VS Code. The Microsoft-proprietary Pylance extension (part of the Python extension) does not work in VSCodium by design. Basedpyright also offers other benefits: it is strict by default and includes additional type checking rules. Extensions are available for both VSCodium and VS Code; in both cases look for "BasedPyright" by detachhead. Use in VS Code does, however, take a little more work. I hope Pyright fans — and especially VS Code users — will find this workable, and perhaps consider using the privacy-focused VSCodium themselves.
The choice of Ruff should be less controversial: it is the current favorite for Python linting and code formatting. The formatting is very similar to Black with some minor differences (which I consider improvements).
Use of these tools requires a virtual environment. With the virtual environment activated, the linting and formatting can be run with the Makefile target lint.
Integrating basedpyright and Ruff with your editor is recommended. In both cases, these tools will pick up the configuration in this project's pyproject.toml file.
Note: this project's .gitignore assumes the virtual environment is at .venv.
# A standard Python virtual environment works fine
python3 -m venv .venv
source ./.venv/bin/activate
# Install the tools
python -m pip install basedpyright ruff
# Now the lint target will work
make lint
Also, with a virtual environment, a local install can be used to run the compiler.
# A standard Python virtual environment works fine
python3 -m venv .venv
source ./.venv/bin/activate
python -m pip install -e .
To ensure the project can be built for distribution, the build-check target in the Makefile can be used. This project is built with Flit, a modern minimal build and publishing tool. It can be run locally to ensure the project remains buildable. This target runs flit build and flit install to build the package and install it locally, and then runs ocsf-schema-compiler -h to verify it works.
# Create virtual environment if it doesn't already exist
python3 -m venv .venv
# Activate it
source ./.venv/bin/activate
# Install Flit
python -m pip install flit
# Run the build check
make build-check
Continuous integration
The continuous integration is done via a GitHub action in .github/workflows/ci.yaml. This action uses the Makefile targets test, lint-github, and build-check. (The lint-github target is a minor variation of the lint target with Ruff's GitHub output format option.)
Publishing
Publishing details are covered in docs/publishing.md.
Copyright
Copyright © OCSF a Series of LF Projects, LLC. See NOTICE for details.
License
This project is distributed under the Apache License Version 2.0. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ocsf_schema_compiler-0.9.4.tar.gz.
File metadata
- Download URL: ocsf_schema_compiler-0.9.4.tar.gz
- Upload date:
- Size: 2.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73263e5140def7a35a531fdbb6e4a32a46fcc611add1e3f5dd0fd468da2a960d
|
|
| MD5 |
b2c91c3eaa18ab620c22c89e3eaeb030
|
|
| BLAKE2b-256 |
e646b8a406458e7eab1f4562e39a5c9ed056ed7a05e7cdd34e868f72a9367982
|
Provenance
The following attestation bundles were made for ocsf_schema_compiler-0.9.4.tar.gz:
Publisher:
publish.yaml on ocsf/ocsf-schema-compiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocsf_schema_compiler-0.9.4.tar.gz -
Subject digest:
73263e5140def7a35a531fdbb6e4a32a46fcc611add1e3f5dd0fd468da2a960d - Sigstore transparency entry: 733824057
- Sigstore integration time:
-
Permalink:
ocsf/ocsf-schema-compiler@8fc2533a2f495bf431be50c084057b0e06827e53 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/ocsf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8fc2533a2f495bf431be50c084057b0e06827e53 -
Trigger Event:
release
-
Statement type:
File details
Details for the file ocsf_schema_compiler-0.9.4-py3-none-any.whl.
File metadata
- Download URL: ocsf_schema_compiler-0.9.4-py3-none-any.whl
- Upload date:
- Size: 37.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e8fb5fbe6a91048b34080d3431445394e2841795fe3d709cdd6b2cdf7423f525
|
|
| MD5 |
af9687747b67b35b97005212efbba9be
|
|
| BLAKE2b-256 |
3583ced120298fde2a83b9b9fae7b9f0f5db452c07f85870b4bb71349e27f1ff
|
Provenance
The following attestation bundles were made for ocsf_schema_compiler-0.9.4-py3-none-any.whl:
Publisher:
publish.yaml on ocsf/ocsf-schema-compiler
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ocsf_schema_compiler-0.9.4-py3-none-any.whl -
Subject digest:
e8fb5fbe6a91048b34080d3431445394e2841795fe3d709cdd6b2cdf7423f525 - Sigstore transparency entry: 733824108
- Sigstore integration time:
-
Permalink:
ocsf/ocsf-schema-compiler@8fc2533a2f495bf431be50c084057b0e06827e53 -
Branch / Tag:
refs/tags/v0.9.4 - Owner: https://github.com/ocsf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8fc2533a2f495bf431be50c084057b0e06827e53 -
Trigger Event:
release
-
Statement type: