Skip to main content

Python SDK for ContractGate — high-performance semantic contract enforcement gateway.

Project description

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

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.

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

contractgate-0.1.0.tar.gz (21.8 kB view details)

Uploaded Source

Built Distribution

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

contractgate-0.1.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file contractgate-0.1.0.tar.gz.

File metadata

  • Download URL: contractgate-0.1.0.tar.gz
  • Upload date:
  • Size: 21.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for contractgate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d8519eb03b8863a751864b83264dd3a131ac4d4bc5379c4cd3e70c52292ff1c6
MD5 e94a41d0c5046da8548282a755f732ef
BLAKE2b-256 18db6fc3fb874c6dbd49c93269d0f2205399dcdebbe32cb16ebf80e0cef000a4

See more details on using hashes here.

File details

Details for the file contractgate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: contractgate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 22.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for contractgate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3cbe0c96586e078e3f1e9c9652a81dbacbeceee9183a4814dd5d2c8a370b89ea
MD5 b27291bd54d1059690ffb7e612a2d922
BLAKE2b-256 8e05e4b95ab3559d8d8d1243332dc7b66cbee36b2140534a584074b44d9cd82b

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