Skip to main content

contractgate (Python SDK)

First-party Python SDK for DataContractGate — a high-performance semantic contract enforcement gateway (Patent Pending).

Install

pip install contractgate

Python 3.9+. Runtime deps: httpx, PyYAML.

Quickstart — HTTP client

from contractgate import Client

cg = Client(base_url="https://api.datacontractgate.com", api_key="cg_live_...")

result = cg.ingest(
    contract_id="11111111-1111-1111-1111-111111111111",
    events=[
        {"user_id": "alice_01", "event_type": "click", "timestamp": 1712000000},
    ],
)

print(result.passed, "/", result.total, "events passed")
for r in result.results:
    if not r.passed:
        for v in r.violations:
            print(v.field, v.kind, v.message)

Async equivalent:

import asyncio
from contractgate import AsyncClient

async def main():
    async with AsyncClient(base_url="...", api_key="...") as cg:
        result = await cg.ingest(contract_id="...", events=[...])

asyncio.run(main())

Quickstart — local validator

Pure-Python port of the Rust validator. Useful in unit tests and pre-commit hooks:

from contractgate import Contract

contract = Contract.from_yaml(open("user_events.yaml").read())
compiled = contract.compile()

vr = compiled.validate({
    "user_id": "alice_01",
    "event_type": "click",
    "timestamp": 1712000000,
})
assert vr.passed, vr.violations

GitHub Action / pre-commit

Same compile, no API key:

# GitHub Actions
- uses: nightmoose/contractgate/actions/validate@main
# .pre-commit-config.yaml
repos:
  - repo: https://github.com/nightmoose/contractgate
    rev: main   # pin to a git sha
    hooks:
      - id: contractgate-validate

The hook only looks at contracts/**/*.yaml. Override files: in your config if contracts live elsewhere.

Caveats

  • Local validator does not run RFC-004 PII transforms (mask, hash, drop, redact). The per-contract salt is server-side only. The gateway is the single source of truth for the post-transform payload — read it from each per-event result's transformed_event field.
  • Audit honesty: every per-event result carries the contract_version that actually matched the event (relevant under multi_stable_resolution: fallback). Surface it as-is — do not substitute the requested version.
  • Retries are off by default. Layer httpx.HTTPTransport(retries=) or tenacity if you need them. Avoid client-side retry on ingest to prevent double-write; use the gateway's quarantine replay endpoint instead.
  • httpx is pinned >=0.25,<1.0; we'll widen once 1.x ships.

License

MIT. See LICENSE.

Metadata

Release files for contractgate 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for contractgate 0.4.0
File Size Uploaded
contractgate-0.4.0.tar.gz 35.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for contractgate 0.4.0
File Interpreter ABI Platform
contractgate-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 65.3 kB

Release files / contractgate-0.4.0.tar.gz

Download URL contractgate-0.4.0.tar.gz
Size 35.6 kB
Tags Source
SHA-256 checksum
How to use checksums
22930ca0999b0c16451e71f84b19a8e018a223c15ac13ccd6e76a9b62d6869e1
BLAKE2b-256 checksum
How to use checksums
e9def0eb085ac2b6e2f137963841a67c6c5236ecaf76562b4c5eca096f7a4dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release files / contractgate-0.4.0-py3-none-any.whl

Download URL contractgate-0.4.0-py3-none-any.whl
Size 29.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6b0c0e48571b8dc6a600b457021e85d34be3e9cdecf4027a9db8e1737dfef6fa
BLAKE2b-256 checksum
How to use checksums
f049fe63dce2919b4848baa41783e607503028f418322d0ea137c65237d55782
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page