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://gw.example.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.3.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.3.0
File Size Uploaded
contractgate-0.3.0.tar.gz 33.5 kB Details

Built distribution (wheel)

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

Total release size: 62.3 kB

Release files / contractgate-0.3.0.tar.gz

Download URL contractgate-0.3.0.tar.gz
Size 33.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ee53c219a55adfaa09182c1a4d84e8043721d2f43bd6d892a42d16d9d4934e19
BLAKE2b-256 checksum
How to use checksums
ddfbb6ef845383cf9576d85686220dfbf42e0bbc916e46aba973d10e1ac53efb
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 12, 2026.

Transparency log

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

Download URL contractgate-0.3.0-py3-none-any.whl
Size 28.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d0c1d7f63e03f04dbd1934ad225fc29bd5f8d35580b32310201b63018b95bb0e
BLAKE2b-256 checksum
How to use checksums
31b253a480a3b9ed86c0af1790cf7ec7d78192d80122ef5d31ca6c7f891d91d7
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 12, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

This release

0.3.0 This release

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