Python: Policies and audit
List, create, test, evaluate and roll back access policies, check permissions, read or verify the audit log and access transparency, read the compliance overview and HIPAA status with the Python SDK.
spl = 'ALLOW IF "STAFF" IN ctx.actor.roles'
print(await sovaria.policy_simulate(spl, {"actor": {"roles": ["STAFF"]}, "action": "UPDATE", "resource": "books"}))
await sovaria.policy_create("pol_staff_edit_books", "staff edit books", spl, org_id)#Methods
sovaria.audit_append
Append an immutable audit entry.
await sovaria.audit_append(
*, event_type: str,
actor_id: str,
source: str,
action: str,
resource_id: str | None = None,
metadata: dict[str, Any] | None = None,
ip_address: str | None = None,
) -> dict[str, Any]Parameters
event_typestrrequiredactor_idstrrequiredsourcestrrequiredactionstrrequiredresource_idstr | NoneoptionaldefaultNonemetadatadict[str, Any] | NoneoptionaldefaultNoneip_addressstr | NoneoptionaldefaultNone
Returns
dict[str, Any]
{
"seq": 18343,
"event_type": "app.refund.approved",
"actor_id": "6e19c0a2-3f5b-4a8e-9b1d-0c7f2e8a4d51",
"resource_id": "order:1042",
"source": "backoffice",
"action": "APPROVE",
"metadata": {
"amount": 59.9
},
"ip_address": "203.0.113.24",
"timestamp": "2026-10-17T12:31:08.512Z",
"hmac": "9f1c…",
"prev_hmac": "41aa…",
"chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"chain_seq": 913,
"entry_hash": "c3e8…",
"prev_hash": "7b02…"
}sovaria.audit_count
Return current audit-entry count.
await sovaria.audit_count() -> dict[str, Any]Returns
dict[str, Any]
{
"count": 913
}sovaria.audit_list
Query audit entries.
await sovaria.audit_list(
*, actor_id: str | None = None,
event_type: str | None = None,
source: str | None = None,
resource_id: str | None = None,
limit: int = 50,
offset: int = 0,
) -> list[dict[str, Any]]Parameters
actor_idstr | NoneoptionaldefaultNoneevent_typestr | NoneoptionaldefaultNonesourcestr | NoneoptionaldefaultNoneresource_idstr | NoneoptionaldefaultNonelimitintoptionaldefault50offsetintoptionaldefault0
Returns
list[dict[str, Any]]
[
{
"seq": 18342,
"event_type": "policy.updated",
"actor_id": "6e19c0a2-3f5b-4a8e-9b1d-0c7f2e8a4d51",
"resource_id": "pol_orders_read",
"source": "guard",
"action": "UPDATE",
"metadata": {
"version": 3,
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07"
},
"ip_address": "203.0.113.24",
"timestamp": "2026-10-17T12:31:08.512Z",
"hmac": "9f1c…",
"prev_hmac": "41aa…",
"chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"chain_seq": 912,
"entry_hash": "c3e8…",
"prev_hash": "7b02…"
}
]sovaria.audit_verify
Verify audit hash-chain integrity.
await sovaria.audit_verify() -> dict[str, Any]Returns
dict[str, Any]
{
"chain_key": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"chain_valid": true,
"verified_entries": 913,
"head_chain_seq": 913,
"head_hash": "c3e8…"
}sovaria.get_compliance_overview
Compliance overview (organization owners and admins): audit-log check, encryption and own-key status, data regions, per-project backups / point-in-time recovery / Security Advisor counts, access summary.
await sovaria.get_compliance_overview(
org_id: str | None = None,
*, project_id: str | None = None,
) -> dict[str, Any]Parameters
org_idstr | NoneoptionaldefaultNoneproject_idstr | NoneoptionaldefaultNone
Returns
dict[str, Any]
sovaria.get_hipaa_status
HIPAA status (Enterprise): HIPAA mode (BAA signed), session limits, audit retention, PHI projects and the features turned off.
await sovaria.get_hipaa_status(
org_id: str | None = None,
) -> dict[str, Any]Other plans get 403 PLAN_FEATURE_REQUIRED with required_plan.
Parameters
org_idstr | NoneoptionaldefaultNone
Returns
dict[str, Any]
sovaria.list_access_transparency
List access transparency.
await sovaria.list_access_transparency(
*, org_id: str,
project_id: str | None = None,
event_type: str | None = None,
since: str | None = None,
limit: int | None = None,
offset: int | None = None,
) -> list[dict[str, Any]]Parameters
org_idstrrequiredproject_idstr | NoneoptionaldefaultNoneevent_typestr | NoneoptionaldefaultNonesincestr | NoneoptionaldefaultNonelimitint | NoneoptionaldefaultNoneoffsetint | NoneoptionaldefaultNone
Returns
list[dict[str, Any]]
[
{
"id": 41,
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"project_id": "f0c3e9a2-1b4d-4e7f-8a6c-2d9b5e3f1a07",
"occurred_at": "2026-10-12T09:20:00Z",
"event_type": "jit_grant",
"operator_email": "support@sovaria.in",
"summary": "Read-only access to investigate a failing migration (ticket 1182)",
"detail": {
"duration_min": 30
}
}
]sovaria.policy_check
Preflight one action/resource against active access policies.
await sovaria.policy_check(
*, org_id: str,
project_id: str,
action: str,
resource: str,
context: dict[str, Any] | None = None,
) -> dict[str, Any]Parameters
org_idstrrequiredproject_idstrrequiredactionstrrequiredresourcestrrequiredcontextdict[str, Any] | NoneoptionaldefaultNone
Returns
dict[str, Any]
{
"allowed": true,
"reason": "ALLOW",
"policy_id": "pol_orders_read"
}sovaria.policy_create
Create and compile a policy.
await sovaria.policy_create(
policy_id: str,
name: str,
spl_source: str,
org_id: str,
) -> dict[str, Any]Parameters
policy_idstrrequired- Your unique id, e.g.
pol_books_read. namestrrequired- Readable name.
spl_sourcestrrequired- The rule.
org_idstrrequired- Organization id.
Returns
dict[str, Any]
{
"policy_id": "pol_orders_read",
"version": 1,
"status": "compiled"
}sovaria.policy_delete
Delete (deactivate) a policy.
await sovaria.policy_delete(policy_id: str) -> NoneParameters
policy_idstrrequired
Returns
None
sovaria.policy_evaluate
Evaluate a policy against an explicit debug context.
await sovaria.policy_evaluate(
policy_id: str,
context: dict[str, Any],
) -> dict[str, Any]Parameters
policy_idstrrequiredcontextdict[str, Any]required
Returns
dict[str, Any]
{
"policy_id": "pol_orders_read",
"decision": "DENY",
"http_status": 403,
"deny_reason": "NO_MATCH",
"retry_after_ms": 0,
"latency_us": 41.2
}sovaria.policy_get
Get a single policy by ID.
await sovaria.policy_get(policy_id: str) -> dict[str, Any]Parameters
policy_idstrrequired
Returns
dict[str, Any]
{
"policy_id": "pol_orders_read",
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"name": "Signed-in users read orders",
"spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
"version": 3,
"is_active": true,
"env_id": null,
"inherited": false
}sovaria.policy_history
Return version history for a policy.
await sovaria.policy_history(policy_id: str) -> list[dict[str, Any]]Parameters
policy_idstrrequired
Returns
list[dict[str, Any]]
[
{
"audit_id": "v3",
"policy_id": "pol_orders_read",
"actor_user_id": "6e19c0a2-…",
"action": "UPSERT",
"new_spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
"version": 3,
"created_at": "2026-10-17T12:31:08Z"
}
]sovaria.policy_list
List active policies visible in current tenant scope.
await sovaria.policy_list() -> list[dict[str, Any]]Returns
list[dict[str, Any]]
[
{
"policy_id": "pol_orders_read",
"org_id": "b2f4a1c8-7d3e-4f0a-9c6b-5e8d2a1f3c90",
"name": "Signed-in users read orders",
"spl_source": "ALLOW IF ctx.resource.name == \"orders\" AND ctx.action IN [\"SELECT\", \"sql:select\"] AND ctx.actor.is_anonymous == False",
"version": 3,
"is_active": true,
"env_id": null,
"inherited": false
}
]sovaria.policy_preflight
Preflight against current SDK org/project scope.
await sovaria.policy_preflight(
action: str,
resource: str,
context: dict[str, Any] | None = None,
) -> dict[str, Any]Parameters
actionstrrequiredresourcestrrequiredcontextdict[str, Any] | NoneoptionaldefaultNone
Returns
dict[str, Any]
sovaria.policy_rollback
Rollback a policy to a historical version.
await sovaria.policy_rollback(
policy_id: str,
version: int,
) -> dict[str, Any]Parameters
policy_idstrrequiredversionintrequired
Returns
dict[str, Any]
{
"policy_id": "pol_orders_read",
"version": 5,
"restored_from": 2,
"status": "rolled_back"
}sovaria.policy_simulate
ALLOW/DENY for each {"action", "resource", "context"?} in operations under the project's live policies, plus draft_policies ({"spl_source", "policy_id"?, "replaces"?}, not saved) and minus disabled_policy_ids.
await sovaria.policy_simulate(
operations: list[dict[str, Any]],
*, draft_policies: list[dict[str, Any]] | None = None,
disabled_policy_ids: list[str] | None = None,
env_id: str | None = None,
explain: bool = False,
) -> dict[str, Any]Nothing is stored. Returns {"results": [{op_index, action, resource, decision, policy_id, reason}]}; with explain=True each result also carries explanation: the steps that decided it, in order ({step, outcome, detail, policy_id?, policy_name?}).
Parameters
operationslist[dict[str, Any]]requireddraft_policieslist[dict[str, Any]] | NoneoptionaldefaultNonedisabled_policy_idslist[str] | NoneoptionaldefaultNoneenv_idstr | NoneoptionaldefaultNoneexplainbooloptionaldefaultFalse
Returns
dict[str, Any]
{
"results": [
{
"op_index": 0,
"action": "sql:select",
"resource": "orders",
"decision": "DENY",
"policy_id": null,
"reason": "NO_POLICY_DEFINED"
},
{
"op_index": 1,
"action": "sql:select",
"resource": "orders",
"decision": "ALLOW",
"policy_id": "pol_orders_read",
"reason": "ALLOW"
}
]
}sovaria.policy_templates
List server-authoritative SPL templates.
await sovaria.policy_templates() -> dict[str, Any]Returns
dict[str, Any]
{
"templates": [
{
"category": "Basic",
"label": "Signed-in users can read",
"name": "Signed-in users can read",
"spl": "ALLOW IF ctx.actor.is_anonymous == False AND ctx.action == \"SELECT\"",
"desc": "Signed-in app users can read tables. Writes need another rule."
}
],
"categories": {
"Basic": [
{
"label": "Signed-in users can read",
"name": "Signed-in users can read",
"spl": "ALLOW IF ctx.actor.is_anonymous == False AND ctx.action == \"SELECT\"",
"desc": "Signed-in app users can read tables. Writes need another rule."
}
]
}
}sovaria.policy_update
Recompile and update an existing policy.
await sovaria.policy_update(
policy_id: str,
spl_source: str,
name: str | None = None,
) -> dict[str, Any]Parameters
policy_idstrrequiredspl_sourcestrrequirednamestr | NoneoptionaldefaultNone
Returns
dict[str, Any]
{
"policy_id": "pol_orders_read",
"version": 4,
"status": "recompiled"
}