Skip to main content

spctre-sdk

Python client for the Spctre policy operations control plane.

pip install spctre-sdk

Requires Python 3.11+.

Usage

from spctre import SpctreClient
from spctre.models import GatewayDecisionRequest

client = SpctreClient(
    base_url="https://app-staging.spctre.dev",
    token=token,
)

decision = client.gateway.decide(
    GatewayDecisionRequest(
        decision_id="d-1",
        artifact_hash="sha256:...",
        policy_context=[...],
    )
)

if decision.decision.outcome.value == "PROCEED":
    ...  # act
    client.evidence.ingest(record)

base_url is the deployment origin, not the API root — the client owns the /api/v1 path segment. Staging, production and self-hosted deployments differ only in this value:

Given Requests go to
https://app-staging.spctre.dev https://app-staging.spctre.dev/api/v1/...
http://localhost:3000 http://localhost:3000/api/v1/...
https://internal.example.com/spctre https://internal.example.com/spctre/api/v1/...

A URL that already ends in /api/v1 is accepted as-is rather than doubled.

Domains

The client is organized by product domain, following the control-plane loop: policy changes become published controls, controls produce enforced decisions, decisions produce evidence, evidence supports assurance.

Domain Operations
client.gateway decide, resolve, escalation_status, list_escalations, register_agt_escalation
client.evidence ingest, ingest_git_checkpoint, forensic_query
client.policy import_policy
client.trust ingest_score, evaluate, ingest_context_budget
client.verification ingest, list
client.bundle latest, retain_latest
client.compliance export
client.approvals get

Models come from spctre.models. Field names are snake_case in Python and are serialized to the API's camelCase automatically.

Operations outside these domains — SCIM, auth token rotation, blueprint import, simulation — are reachable through spctre._generated, which is regenerated wholesale from the OpenAPI spec and carries no stability promise. Anything you find yourself needing there is a reasonable thing to request as a facade addition.

Errors

Every failure is raised as a SpctreError subclass. Generated exceptions never escape:

Raised When
SpctreAuthError 401: token missing, expired, or revoked
SpctrePermissionError 403: token lacks the required scope
SpctreRequestError other 4xx
SpctreServerError 5xx
SpctreTransportError no HTTP response at all (DNS, TLS, timeout)
SpctreResponseError answered, but the response did not parse

Each carries status, body, and trace_id lifted from the response envelope's meta.traceId — quote it when reporting a problem.

SpctreResponseError is deliberately distinct from SpctreTransportError: it means the client and the deployment disagree about the API contract, usually an SDK too old or too new for the server. Reporting that as an unreachable host would send debugging in the wrong direction.

Testing

transport= accepts any httpx.BaseTransport, so tests need no network:

import httpx
from spctre import SpctreClient


def handler(request: httpx.Request) -> httpx.Response:
    assert request.url.path == "/api/v1/gateway/decide"
    return httpx.Response(200, json={...})


client = SpctreClient(
    base_url="https://app.example.com",
    token="test-token",
    transport=httpx.MockTransport(handler),
)

How this package is built

spctre._generated is produced by openapi-python-client from the control plane's OpenAPI spec, at a pinned generator version. Unlike most generated code in this repository it is checked in, so installing or building the package needs no code generator, and CI can assert the committed client still matches the spec.

License

Apache-2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spctre_sdk-0.2.0.tar.gz (60.9 kB view details)

Uploaded Source

Built Distribution

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

spctre_sdk-0.2.0-py3-none-any.whl (176.2 kB view details)

Uploaded Python 3

File details

Details for the file spctre_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: spctre_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 60.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for spctre_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fd4416df4bb824e72ed51a04db1c0accce1ba5fd1c55648e1f6c828906424a6e
MD5 74f8cd47599bf9f6eca73bd6053494fb
BLAKE2b-256 dbb4278e63d32afeac00f61612ec2cac7c14646e3fe1dd74c9c022517198ac25

See more details on using hashes here.

Provenance

The following attestation bundles were made for spctre_sdk-0.2.0.tar.gz:

Publisher: release-python.yml on getspctre/spctre

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

File details

Details for the file spctre_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: spctre_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 176.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for spctre_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8c403dc515a2889665a787fd455da69320cc33c25ef85aa1f51df36d1e6e5e5
MD5 b13ea251bc8a6a1eb9062b94184ad43e
BLAKE2b-256 f6672e8880291bad43d099ca59e75121edf14fcfce8b073a2bb225879d4596f2

See more details on using hashes here.

Provenance

The following attestation bundles were made for spctre_sdk-0.2.0-py3-none-any.whl:

Publisher: release-python.yml on getspctre/spctre

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 Sentry Error logging StatusPage Status page