Registry / serialization / ocsf-pydantic

ocsf-pydantic

JSON →
library0.0.6pypypi✓ verified 82d ago

ocsf-pydantic provides Pydantic v2 models for the Open Cybersecurity Schema Framework (OCSF). It enables type-safe Python representations of OCSF schemas, facilitating event parsing, validation, and generation in cybersecurity applications. The current version is 0.0.6, and its release cadence is irregular, typically aligned with updates to the OCSF specification or bug fixes.

pip install ocsf-pydantic
INSTALL
IMPORT
SIG · OCSF-PYDANTIC
O
ocsf-pydantic
serializationpythonv0.0.6
Install
1.6s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.0.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.3MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 1.6s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OCSF_VERSION
from ocsf import OCSF_VERSION
from ocsf_pydantic.events.file_activity import FileActivity

This quickstart demonstrates how to create a `FileActivity` OCSF event using the `ocsf-pydantic` models. It populates essential fields like time, correlation ID, file details, and user information, then prints the resulting event in JSON format. It also shows how to access nested fields.

from datetime import datetime, timezone from ocsf_pydantic.events.file_activity import FileActivity from ocsf_pydantic.objects.file import File from ocsf_pydantic.objects.user import User # Create an OCSF FileActivity event file_activity_event = FileActivity( time=datetime.now(timezone.utc), correlation_uid="example-correlation-id-456", activity_id=1, # Represents FileActivityId.CREATE file=File( name="report.pdf", path="/home/user/documents/report.pdf", size=10240, hash_md5="d41d8cd98f00b204e9800998ecf8427e" ), user=User(name="analyst_user", uid="U007"), message="New report generated by analyst_user" ) # Print the event as JSON print(file_activity_event.model_dump_json(indent=2)) # Access a specific field print(f"\nEvent Type Name: {file_activity_event.activity_name}") print(f"File Name: {file_activity_event.file.name}")
Debug
Known issues
breakingThis library is pre-1.0, and its API is subject to change without strict adherence to semantic versioning. Updates to the underlying OCSF specification can also lead to breaking changes in model structure.
fix
Always review release notes for new versions and test your code against new releases, especially for breaking changes in model fields or required arguments.
affects: <1.0.0
gotcha`ocsf-pydantic` strictly requires Pydantic V2 (>=2.0.0). It is incompatible with Pydantic V1.
fix
Ensure `pydantic` is installed at version 2.x. If you have Pydantic V1 installed, upgrade it (`pip install --upgrade 'pydantic>=2,<3'`) or use a virtual environment.
affects: *
gotchaMany common OCSF event fields (e.g., `type_id`, `class_name`, `severity`, `category_name`) are automatically set by the specific event models (e.g., `FileActivity`) based on the OCSF specification. Attempting to manually override these can lead to unexpected behavior or validation errors.
fix
Trust the default values set by the models for these common event fields. Focus on providing data for the specific fields relevant to your event type. If you need to manipulate common fields, do so carefully after model instantiation, or ensure your data strictly adheres to OCSF enum values.
affects: *
Upgrade
Version history
0.0.6latest on PyPI · released Nov 11, 2024
Audit
Dependencies
pydanticrequiredCore dependency for model definition and validation.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
ocsf-pydantic — pip install ocsf-pydantic · libregistry