Python SDK
santati is the official Python client for the Santati audit-log API, published on PyPI. Requires Python 3.10+.
Install
pip install santati
Create a client
import os
import santati
client = santati.Santati(os.environ["SANTATI_API_KEY"], trail="billing")
| option | default | meaning |
|---|---|---|
api_key | required, non-empty | team API key (sat_sk_…) |
base_url | https://api.santati.io | trailing / removed; may carry a path prefix |
trail | none | default trail for emits; never applied to reads |
timeout_ms | 10000 | per attempt |
max_retries | 2 | retries after the first attempt |
initial_backoff_ms | 250 | backoff base |
max_backoff_ms | 8000 | backoff cap |
headers | none | extra headers on every request |
trail is the default trail for emits and is never applied to reads. The client is also a context manager and has close(). Construction fails with a santati.ValidationError (with status None) for an empty key (field api_key) or an Authorization header in headers (field headers).
Emit an event
with santati.Santati(os.environ["SANTATI_API_KEY"], trail="billing") as client:
result = client.events.emit(
"invoice.voided",
organization_id="org_acme",
actor={"type": "user", "id": "usr_123", "name": "Valentine Michael Smith"},
targets=[{"type": "invoice", "id": "inv_555"}],
)
print(result.event.id, result.duplicate)
Without an idempotency_key one is generated — a lowercase UUIDv4 — and duplicate is True when the server replayed an earlier request with the same key. See Idempotency and Event envelope.
Emit a batch
with santati.Santati(os.environ["SANTATI_API_KEY"], trail="billing") as client:
batch = client.events.emit_batch([
{"event": "invoice.paid", "organization_id": "org_acme"},
{"event": "invoice.voided", "organization_id": "org_acme"},
])
print(batch.accepted, batch.rejected)
A 202 and a 207 both return a result with per-item status (accepted, duplicate or rejected), and the server enforces 500 events / 1 MiB — a 413 arrives as a validation error. See Batching.
List and iterate
with santati.Santati(os.environ["SANTATI_API_KEY"]) as client:
page = client.events.list(trail="billing", limit=50)
for event in page.results:
print(event.id, event.event)
for event in client.events.iterate(trail="billing", limit=100):
print(event.id)
list accepts trail, event, event_prefix, organization_id, actor_id, actor_type, target_type, target_id, created_after, created_before, q, sort and limit, plus cursor on list only; iterate takes the same minus cursor and walks every page. See Searching events.
Errors and retries
Every failure raises a santati.SantatiError subclass:
| kind | when |
|---|---|
santati.ValidationError | local validation (status is None), or HTTP 400, 413, 422 |
santati.AuthError | HTTP 401, 403 |
santati.NotFoundError | HTTP 404 |
santati.RateLimitedError | HTTP 429 |
santati.ServerError | HTTP 5xx |
santati.TransportError | no response: refused, DNS, TLS, timeout (status is None) |
santati.ApiError | any other status, an unexpected 2xx, or an undecodable body |
Each carries status, code, field, retry_after and message.
try:
client.events.emit("invoice.voided", organization_id="org_acme")
except santati.RateLimitedError as error:
print(f"retry after {error.retry_after}s")
An emit, a batch and a list retry transport failures, 500/502/503/504 and 429 (unless the code is quota_exceeded) up to max_retries times, re-sending the identical request with the same idempotency keys. A Retry-After header is honoured unless it exceeds max_backoff_ms, in which case the error is raised immediately. Redirects are never followed. See Errors and Rate limits.
Framework integrations
santati.integrations turns the callbacks of the frameworks you already run into audit events. Each integration lives behind its own extra:
| module | extra | records |
|---|---|---|
santati.integrations.django | santati[django] | user.logged_in, user.logged_out, user.login_failed |
santati.integrations.langchain | santati[langchain] | agent.tool_call.succeeded / .failed |
santati.integrations.openai_agents | santati[openai-agents] | agent.tool_call.succeeded / .failed |
santati.integrations.pydantic_ai | santati[pydantic-ai] | agent.tool_call.succeeded / .failed |
santati.integrations.claude_agent_sdk | santati[claude-agent-sdk] | agent.tool_call.succeeded / .failed |
from santati.integrations.django import instrument_auth
class BillingConfig(AppConfig):
def ready(self) -> None:
instrument_auth(client, organization_id="org_acme")
Every integration takes exactly one of client — sent inline through the synchronous client — or dispatch, a callable that receives each built envelope (a Celery task's delay, an RQ queue, a thread pool):
handler = SantatiCallbackHandler(dispatch=record_event.delay, organization_id="org_acme")
agent.invoke({"messages": [...]}, config={"callbacks": [handler]})
See the README for per-framework caveats.