Skip to main content

Python SDK client for the ComplianceGuard HTTP API

Project description

complianceguard

Python client for the ComplianceGuard HTTP API.

This SDK supports the current MVP evidence contract:

  • decision_event() / decision_event_async()
  • metric_snapshot() / metric_snapshot_async()
  • human_intervention() / human_intervention_async()
  • dataset_registration()
  • model_release()
  • log_human_feedback()

Async event delivery is disk-backed. log_async, decision_event_async, metric_snapshot_async, and human_intervention_async durably spool events, replay pending files on startup, retry with backoff, and move exhausted deliveries to a dead-letter directory instead of silently dropping them.

Install

pip install complianceguard

Decision events

from complianceguard import ComplianceGuardClient

client = ComplianceGuardClient(
    base_url="http://localhost:5214",
    api_key="<environment-api-key>",
    spool_directory="/var/lib/complianceguard-sdk",
)

client.decision_event_async(
    model_id="credit-score-v1",
    version="2026.04.15",
    input={"applicant_id": "A-1001", "income": 65000},
    output={"score": 0.82, "decision": "approve"},
    metadata={"team": "risk", "feature_set": "baseline"},
    correlation_id="decision-1001",
    model_release_id="<model-release-id>",
)

client.flush()

log() and log_async() remain as backward-compatible aliases for typed decision events.

Metric snapshots

client.metric_snapshot(
    model_id="credit-score-v1",
    version="2026.04.15",
    metrics={"accuracy": 0.98, "drift": 0.03},
    metadata={"window": "5m", "service": "monitoring"},
    model_release_id="<model-release-id>",
)

Human intervention

client.human_intervention(
    model_id="credit-score-v1",
    version="2026.04.15",
    input={"applicant_id": "A-1001"},
    original_output={"decision": "deny"},
    final_output={"decision": "manual_review"},
    reviewer_display="Senior Analyst",
    intervention_type="overrode",
    notes="Escalated due to conflicting source records.",
    model_release_id="<model-release-id>",
)

Governance registration

dataset = client.dataset_registration(
    name="credit-review-corpus",
    version="2026.04",
    usage="validation",
    source="approved analyst review queue",
    provenance="sampled from manually reviewed decisions",
    record_count=3200,
    metadata={"region": "eu"},
)

release = client.model_release(
    environment_id="<environment-id>",
    name="credit-score-prod",
    model_id="credit-score-v1",
    version="2026.04.15",
    status="active",
    architecture_summary="transformer ensemble",
    intended_use="credit underwriting support",
    system_version="sys-2026.04.15",
    parameter_count=125000000,
    training_data_hash="abc123",
)

Backend responses use the API's snake_case JSON contract. The SDK normalizes responses before returning them so Python callers receive stable camelCase dictionaries.

Decorator tracing

from complianceguard import ComplianceGuardClient

client = ComplianceGuardClient(
    base_url="http://localhost:5214",
    api_key="<environment-api-key>",
    spool_directory="/var/lib/complianceguard-sdk",
)

@client.trace(
    model_id="credit-score-v1",
    version="2026.04.15",
    metadata={"service": "underwriting"},
)
def score_application(application: dict) -> dict:
    return {"score": 0.82, "decision": "approve"}

score_application({"applicant_id": "A-1001", "income": 65000})
client.flush()

Context manager tracing

from complianceguard import ComplianceGuardClient

client = ComplianceGuardClient(
    base_url="http://localhost:5214",
    api_key="<environment-api-key>",
    spool_directory="/var/lib/complianceguard-sdk",
)

with client.trace_context(
    model_id="credit-score-v1",
    version="2026.04.15",
    input={"applicant_id": "A-1001", "income": 65000},
    metadata={"service": "underwriting"},
    correlation_id="decision-1001",
) as trace:
    trace.output = {"score": 0.82, "decision": "approve"}

client.flush()

Delivery semantics

  • Synchronous log() posts directly and generates an idempotency key if one is not provided.
  • Asynchronous log_async() writes a spool file before background delivery begins.
  • Pending spool files are replayed when the client starts again with the same spool_directory.
  • Exhausted deliveries are moved to dead-letter/.

Human feedback

client.log_human_feedback(
    event_id="<event-id>",
    reviewer_display="Senior Analyst",
    label="approved",
    score=1.0,
    notes="Manual review confirmed the decision.",
    feedback={"review_ticket": "REV-1024"},
)

For correlation-level feedback:

client.log_human_feedback(
    correlation_id="decision-1001",
    environment_id="<environment-id>",
    reviewer_display="Senior Analyst",
    label="escalated",
    notes="Grouped review across the full decision chain.",
    feedback={"reason": "manual escalation"},
)

Test

python -m unittest discover -s tests -v

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

complianceguard-0.1.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

complianceguard-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file complianceguard-0.1.1.tar.gz.

File metadata

  • Download URL: complianceguard-0.1.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for complianceguard-0.1.1.tar.gz
Algorithm Hash digest
SHA256 69f49f1452072dc886b5cbafaf75652e61acaa91625f35c6195ec9abe6e88440
MD5 0854ccaea51fa27008d15bced99c38ed
BLAKE2b-256 623d1ff73929bde45d5c92f1445512ae74482f55052b0681f7eb59e7b9353cac

See more details on using hashes here.

Provenance

The following attestation bundles were made for complianceguard-0.1.1.tar.gz:

Publisher: python-sdk-publish.yml on Zakinahimi/ComplianceGuardBackend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file complianceguard-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for complianceguard-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6ee3a6ebdf56c1d5d2e4f3db43f50b0fb1f6012bd903b107a25ff86dd4551e1a
MD5 8321658a0974a31b3d37d1e7bdc90569
BLAKE2b-256 c5a55c0d85c234eabf5b93382aa2fed2d99f8d2c0772f0c5b18bc0196a02fd88

See more details on using hashes here.

Provenance

The following attestation bundles were made for complianceguard-0.1.1-py3-none-any.whl:

Publisher: python-sdk-publish.yml on Zakinahimi/ComplianceGuardBackend

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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