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'stransformed_eventfield. - Audit honesty: every per-event result carries the
contract_versionthat actually matched the event (relevant undermulti_stable_resolution: fallback). Surface it as-is — do not substitute the requested version. - Retries are off by default. Layer
httpx.HTTPTransport(retries=)ortenacityif you need them. Avoid client-side retry on ingest to prevent double-write; use the gateway's quarantine replay endpoint instead. httpxis pinned>=0.25,<1.0; we'll widen once 1.x ships.
License
MIT. See LICENSE.
Metadata
Release files for contractgate 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| contractgate-0.3.1.tar.gz | 34.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| contractgate-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 63.6 kB
Release files / contractgate-0.3.1.tar.gz
| Download URL | contractgate-0.3.1.tar.gz |
|---|---|
| Size | 34.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
799ca9cc46a858a9987016967cb616af4526ddba153f59bad497ba57a4a83a90
|
|
BLAKE2b-256 checksum How to use checksums |
72d94dd7d3e1eb220224e11a13d0998dc15c068836ab8542b5b1eb55729972d7
|
| 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 logRelease files / contractgate-0.3.1-py3-none-any.whl
| Download URL | contractgate-0.3.1-py3-none-any.whl |
|---|---|
| Size | 29.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1263857c2ef99e9c93393a2a7f9083b58da7c3abd362bd382c2256d1837e7800
|
|
BLAKE2b-256 checksum How to use checksums |
ffbaa348e16abaec052bf953d5f815e3181a2a3520d1c104da5ddfd5156c7713
|
| 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