sarif-pydantic
An implementation of the SARIF (Static Analysis Results Interchange Format) format using Pydantic.
Overview
This library provides Pydantic models for working with the SARIF specification (version 2.1.0). It enables Python developers to:
- Create, validate, and manipulate SARIF data
- Parse existing SARIF files into typed Python objects
- Export SARIF data to JSON with proper validation
Installation
pip install sarif-pydantic
Usage
Creating a SARIF Log
from sarif_pydantic import (
ArtifactLocation,
Invocation,
Level,
Location,
Message,
PhysicalLocation,
Region,
Result,
Run,
Sarif,
Tool,
ToolDriver
)
# Create a tool driver
tool_driver = ToolDriver(
name="Example Analyzer",
version="1.0.0",
)
# Create a tool with the driver
tool = Tool(driver=tool_driver)
# Create a physical location
physical_location = PhysicalLocation(
artifact_location=ArtifactLocation(
uri="src/example.py",
),
region=Region(
start_line=42,
start_column=5,
end_line=42,
end_column=32,
),
)
# Create a result
result = Result(
rule_id="EX001",
level=Level.WARNING,
message=Message(
text="Example warning message",
),
locations=[Location(
physical_location=physical_location,
)],
)
# Create a SARIF log
sarif_log = Sarif(
version="2.1.0",
runs=[Run(
tool=tool,
invocations=[Invocation(
execution_successful=True,
)],
results=[result],
)],
)
# Export to JSON
sarif_json = sarif_log.model_dump_json(indent=2, exclude_none=True)
print(sarif_json)
Loading a SARIF Log from JSON
import json
from sarif_pydantic import Sarif
# Load from a file
with open("example.sarif", "r") as f:
sarif_data = json.load(f)
# Parse into a Sarif object
sarif_log = Sarif.model_validate(sarif_data)
# Access data via typed objects
for run in sarif_log.runs:
for result in run.results or []:
print(f"Rule: {result.rule_id}, Level: {result.level}")
print(f"Message: {result.message.text}")
SARIF Specification
This implementation follows the SARIF 2.1.0 specification.
License
[LICENSE]
Metadata
Release files for sarif-pydantic 0.6.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sarif_pydantic-0.6.2.tar.gz | 54.7 kB | Without provenance | Details for sarif_pydantic-0.6.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sarif_pydantic-0.6.2-py3-none-any.whl | Python 3 | none | any | Details for sarif_pydantic-0.6.2-py3-none-any.whl |
Total release size: 62.1 kB
Release files / sarif_pydantic-0.6.2.tar.gz
| Download URL | sarif_pydantic-0.6.2.tar.gz |
|---|---|
| Size | 54.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
634df2784533fcac8e86f0c60a0e45ead1d35452dc2331d32596275595906e7f
|
|
BLAKE2b-256 checksum How to use checksums |
b678a361e0f8e4758a8cf7aa0f1df7651c317d0eef2528436bc804d1ab5dae8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Release files / sarif_pydantic-0.6.2-py3-none-any.whl
| Download URL | sarif_pydantic-0.6.2-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6b22adbed76482f1b649b46c3274d9505c9d4084abbaf851de7ed3e61b8d0527
|
|
BLAKE2b-256 checksum How to use checksums |
ab1e0953f9074cf9a7709347d0ce0eab48441621bcf21c7dcef658adfcacef5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.7.19
|
Security for sarif-pydantic 0.6.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.