Skip to main content

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.

Getting started

There are three ways to use the OCSF Schema Compiler:

  1. As a command-line tool, installed from PyPI.
  2. As a library, installed from PyPI.
  3. As a developer working on this project.

Python version 3.14 or later is required.

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
pip install ocsf-schema-compiler

The compiler is implemented in the SchemaCompiler class. The class constructor the same options as the command-line tool. The class's compile method does the heavy lifting, returning a dict containing the compiled schema. More 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 via a fork into your own GitHub profile or organization. Create your fork of this repo with the GitHub CLI tool (or, more painfully, manually).

This project requires Python 3.14 or later, and otherwise has no runtime dependencies. This mean you can run it directly from a cloned repo's src directory without creating a virtual environment.

I usually run with a subshell so my current directory remains in the base of the cloned repo. I also often use the jq tool to format the JSON output. For example:

cd path/to/ocsf-schema-compiler
$(cd src && python3 -m ocsf_schema_compiler ~/path/to/ocsf-schema > jq -S > ~/path/to/output/schema.json)

This project has regression tests in the tests directory built using the unittest library. These also can be run without a virtual environment. The tests can be run with the Makefile target tests.

make tests

This project uses Ruff for linting and code formatting. Ruff's formatting is very similar to Black with some minor differences (improvements, in my opinion). This requires a virtual environment with both installed. With the virtual environment activated the linting and formatting can be run with the Makefile target lint.

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
pip install 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

pip install -e .

Integrating Ruff with your editor is recommended. See Editor integration | Ruff.

Publishing

This project follows the publishing approach described by this tutorial: How to Publish an Open-Source Python Package to PyPI — Real Python, including use of the Build and Twine tools. The BumpVer tool is also used to increment versions and keep the various mentions of the version in sync.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ocsf_schema_compiler-0.9.2.tar.gz (37.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ocsf_schema_compiler-0.9.2-py3-none-any.whl (34.9 kB view details)

Uploaded Python 3

File details

Details for the file ocsf_schema_compiler-0.9.2.tar.gz.

File metadata

  • Download URL: ocsf_schema_compiler-0.9.2.tar.gz
  • Upload date:
  • Size: 37.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for ocsf_schema_compiler-0.9.2.tar.gz
Algorithm Hash digest
SHA256 a5a41b10a2b77391c1c3109a6201897933a2f657c7f3808d2edc493e42636755
MD5 134c0fadfaf9fd0913f53b25f9f3f191
BLAKE2b-256 61cc6a456f20c9613bdcc065d68c4cd426b17bcc07b4d67563afc26f8138ead2

See more details on using hashes here.

File details

Details for the file ocsf_schema_compiler-0.9.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ocsf_schema_compiler-0.9.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5952b94894052e32905a9f76ebea98e0c670373cf08e28210a24ab32fcc7acc3
MD5 dde4c9cd28a151e675e795919cfa67c3
BLAKE2b-256 72f1bc891a2839aa794ec1044f902778a68200da1eaaf30928cd43e3c3836231

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page