CoreGuard Python SDK
The eve-coreguard Python SDK provides a typed, ergonomic interface to the CoreGuard governance decision engine. Install it from PyPI, configure your API key, and your first governance-enforced evaluation is running in under five minutes.
Contents
Installation
The SDK requires Python 3.9 or later. It has zero required dependencies — it uses only the Python standard library (urllib) for HTTP transport. Install from PyPI:
The package is published on PyPI: pypi.org/project/eve-coreguard.
To pin to a specific version (recommended for production):
For projects using pyproject.toml:
Verify the installation:
Quick Start — 5 Lines
The following example evaluates a loan approval action against the lending_v1 policy pack and prints the disposition:
API key security: Never hardcode your API key in source code. Load it from an environment variable: api_key=os.environ["COREGUARD_API_KEY"]. See Configuration for all available options.
Configuration
The EveCoreguardClient accepts the following configuration parameters:
| Parameter | Type | Default | Description |
|---|---|---|---|
| api_key | str | required | Your CoreGuard API key. Recommended to load from environment variable COREGUARD_API_KEY. |
| base_url | str | https://api.eveaicore.com | Base URL for the CoreGuard API. Override for on-premises or private cloud deployments. |
| timeout | float | 10.0 | Request timeout in seconds. For high-throughput applications, 2.0 seconds is typical. |
| max_retries | int | 3 | Maximum number of retries on transient errors (5xx, network timeout). Uses exponential backoff. |
| verify_ssl | bool | True | Verify TLS certificate. Do not disable in production. |
| hmac_verification_key_hex | str or None | None | If provided, the client automatically verifies the HMAC signature on every response. Raises CertificateVerificationError on failure. |
Configuration from environment variables (all parameters can be set via environment):
EvaluationRequest Schema
Every call to client.evaluate() takes an EvaluationRequest object. The schema mirrors the POST /v1/decisions/evaluate request body.
| Field | Type | Description | |
|---|---|---|---|
| policy_set | str | required | Policy pack identifier. Example: "lending_v1", "healthcare_v1", "enterprise_v1". |
| user | dict | required | Dict with at minimum id (str) and role (str). Recorded in the decision certificate as the actor. |
| action | dict | required | The action being evaluated. Must include type (str). Additional fields are policy-pack-specific. |
| context | dict | optional | Additional context for policy evaluation: session metadata, prior decisions, environmental signals. Defaults to empty dict. |
| request_id | str or None | optional | Caller-supplied idempotency key. If provided, duplicate requests with the same request_id within 60 seconds return the cached response. |
| dry_run | bool | optional | If True, evaluates the request but does not record a certificate. Useful for testing policy configurations. Defaults to False. |
Typed Construction
EvaluationResponse Fields
The evaluate() method returns an EvaluationResponse object with the following structure:
| Field | Type | Description |
|---|---|---|
| decision.status | str | Final disposition: "ALLOWED", "BLOCKED", or "MODIFIED". |
| decision.risk_level | str | Risk assessment: "LOW", "MEDIUM", or "HIGH". |
| decision.violations | list[PolicyViolation] | List of policy violations that fired. Empty for ALLOWED decisions. |
| decision.violations[].rule_id | str | Rule identifier. Example: "lending.prohibited_basis". |
| decision.violations[].severity | str | "LOW", "MEDIUM", or "HIGH". |
| decision.violations[].description | str | Human-readable violation description with statutory citation. |
| decision.violations[].remediation | str | Recommended remediation action. |
| decision.modifications | dict or None | Required modifications for MODIFIED decisions. Contains pack-specific modification instructions. |
| audit_record | AuditRecord | The signed Decision Certificate. See Decision Certificates for full schema. |
| audit_record.decision_id | str | Unique certificate identifier (ULID format). |
| audit_record.hmac_signature | str | HMAC-SHA256 signature over the canonical audit record. |
| certificate_verified | bool or None | Set to True or False if hmac_verification_key_hex was provided at client construction. None if verification was not configured. |
Error Handling
The SDK uses a structured exception hierarchy. All exceptions inherit from CoreGuardError:
Async Usage
The SDK provides a fully async client for use with asyncio-based frameworks (FastAPI, Starlette, Tornado). The async client is API-compatible with the synchronous client:
Advanced Usage
Batch Evaluation
For high-throughput scenarios, evaluate_batch() sends multiple evaluation requests in a single HTTP call, reducing per-request overhead and improving throughput:
Custom Policy Sets
Organizations on Enterprise plans may have custom policy packs deployed under organization-specific identifiers. Use these the same way as first-party packs:
Certificate Verification at Scale
Changelog
Initial public release.
- Synchronous
EveCoreguardClientwithevaluate()andevaluate_batch(). - Asynchronous
AsyncEveCoreguardClientwith identical API surface. - Typed
EvaluationRequestandEvaluationResponsemodels with Pydantic v2 support. verify_certificate()andverify_chain()for offline HMAC verification.- Automatic retry with exponential backoff on 5xx and network errors.
- Full exception hierarchy:
AuthenticationError,RateLimitError,PolicyNotFoundError,ValidationError,ServiceUnavailableError,CertificateVerificationError. EveCoreguardClient.from_env()for environment variable configuration.- 28 tests covering happy path, all error cases, certificate verification, and batch evaluation.
- Type stubs (
.pyifiles) for IDE autocompletion. - Compatible with Python 3.9, 3.10, 3.11, 3.12, 3.13.
For upcoming releases and the full commit history, see the GitHub repository. Bug reports and feature requests are welcome via GitHub Issues or [email protected].