Skip to main content

ODIN Provenance Passport — Python instrumentation + CLI

Project description

OPP Python SDK (opp_py)

Instrumentation + CLI for ODIN Provenance Passport (OPP).

Features

  • @stamp(step_type, attrs=..., inputs=..., outputs=...) decorator emits start/end signed receipts.
  • Automatic input/output content IDs (CIDs) via optional callables.
  • Fallback lightweight OPE client (no external odin-sdk required) using env Ed25519 seed.
  • Graph + Passport generation (opp graph, opp passport).
  • Policy evidence aggregation & breach summary (opp policy).
  • Optional C2PA bridge (opp.c2pa.embed_bundle_cid) to embed bundle CID into images (extra deps).

Install (editable dev)

pip install -e packages/opp_py

Required env for stamping (generate a random 32‑byte seed once):

export OPP_GATEWAY_URL=http://127.0.0.1:8080
export OPP_SENDER_PRIV_B64=<base64url_32byte_seed>
export OPP_SENDER_KID=opp-sender

Generate a seed (PowerShell):

$bytes = New-Object byte[] 32; [Security.Cryptography.RandomNumberGenerator]::Create().GetBytes($bytes); \
$seed = [Convert]::ToBase64String($bytes).TrimEnd('=') -replace '\+','-' -replace '/','_'; $seed

Decorator Usage

from opp.decorators import stamp

@stamp(
		"train.v1",
		attrs={"model":"resnet"},
		inputs=lambda args, kwargs: {"hyperparams": kwargs.get("hp")},
		outputs=lambda ret: {"metrics": ret.get("metrics")}
)
def train(data, *, hp):
		# ... training ...
		return {"metrics": {"accuracy": 0.93}}

train([], hp={"lr":1e-3})

Emitted start receipt includes inputs_cid; end receipt includes outputs_cid and status.

CLI

opp graph --trace TRACE --gateway $OPP_GATEWAY_URL         # build minimal graph
opp validate --trace TRACE --gateway $OPP_GATEWAY_URL      # continuity + basic validation
opp passport --trace TRACE --gateway $OPP_GATEWAY_URL      # rich model/data passport JSON
opp policy --trace TRACE --gateway $OPP_GATEWAY_URL        # summarized policy evidence + breaches

Passport Fields (excerpt)

{
	"trace_id": "...",
	"receipts": 12,
	"steps": ["ingest.v1","train.v1"],
	"dataset_roots": ["sha256:..."],
	"model_id": "model-123",
	"metrics": {"accuracy": 0.93},
	"safety_flags": {"pii_redacted": true},
	"policy_engines": ["opa"],
	"policy_breaches": [{"rule":"no_public_data","outcome":"deny"}]
}

Policy Evidence

If receipts carry a normalized policy object with engine + decisions[], breaches are auto‑derived when an outcome is not in {allow, pass, ok}.

Optional C2PA Bridge

pip install c2pa Pillow
python examples/c2pa_embed.py image.png

Adds a custom assertion with the bundle_cid to the image manifest.

Airflow & Dagster Examples

See examples/airflow_dag.py and examples/dagster_job.py for task/op instrumentation and trace continuity.

Testing

pytest -q packages/opp_py/tests

Backward Compatibility

New fields are additive; existing receipt payload fields preserved. Hashing uses canonical JSON (stable order, no whitespace).

License

Apache 2.0

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

opp_py-0.1.1.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

opp_py-0.1.1-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file opp_py-0.1.1.tar.gz.

File metadata

  • Download URL: opp_py-0.1.1.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for opp_py-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d7e2f307ee53eda3d2fff3ab2d235b5bb717b9aa6adacbe26164c2bc5ebb78a9
MD5 83818e073102ae3a6463ad27696438da
BLAKE2b-256 21cc216fecc91091854b82305372a0b1afdcf2a249d977b29b6e7aabc320b297

See more details on using hashes here.

File details

Details for the file opp_py-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: opp_py-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.13

File hashes

Hashes for opp_py-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3aa017c3bb2313931d9a9427a49970c5e711be9465d459e62dcadf93f592e646
MD5 fcbb87e7ef9bc5a6dc5ee105c1dff8cc
BLAKE2b-256 1bb97100f5e879fa97d20cf40298161aa890c5718165d5e4cd9721bc6ee83542

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