Skip to main content

contractgate (Python SDK)

First-party Python SDK for ContractGate — 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.2.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.2.0
File Size Uploaded
contractgate-0.2.0.tar.gz 23.8 kB Details

Built distribution (wheel)

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

Total release size: 47.0 kB

Release files / contractgate-0.2.0.tar.gz

Download URL contractgate-0.2.0.tar.gz
Size 23.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cfedf0e7fb7bb63d84080c74a3d8304508c72708c3d8e869684348bb245fd5b0
BLAKE2b-256 checksum
How to use checksums
2dcea3e457641e4e4dbf86ed806a616805f88e0576c872bbe9e55c1dfee969de
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 1, 2026.

Transparency log

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

Download URL contractgate-0.2.0-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b89d32b7799a6aa5060563e18e9c9a539a0085990bdf3730498c4bfacab7c448
BLAKE2b-256 checksum
How to use checksums
17a588a8eef4af30717cb31922a2339e4e21ff8e56fd8ae8aaa137dab1bc2293
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 1, 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

0.3.0

2 release files

This release

0.2.0 This release

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