Skip to main content

themis-policy

Python reference implementation of Themis RFC v0 — a policy kernel for LLM agents that act on production systems. Four primitives — locks, drafts, scopes, audit — composed by one engine into a single decision per attempted action: allow, deny, redirect, or require_approval.

Byte-compatible with themis-policy (TypeScript): both pass the same conformance vectors.

from themis import (
    PolicyEngine, DefaultLockPolicy, DefaultScopePolicy, DefaultDraftPolicy,
    Requestor, Action, PolicyContext, ConsoleSink, is_deny,
)

engine = PolicyEngine(audit_sink=ConsoleSink())
engine.add_policy(DefaultLockPolicy())
engine.add_policy(DefaultScopePolicy())
engine.add_policy(DefaultDraftPolicy())

decision = engine.evaluate(PolicyContext(
    requestor=Requestor(id="key_1", kind="api_key", tenant_id=7, scopes=("pages:read",)),
    action=Action(verb="pages.update", resource_type="page", tenant_id=7, resource_id=42,
                  required_scope="pages:write"),
    now=0, correlation_id="req-123",
))
if is_deny(decision):
    print(decision.reason)          # missing_scope

The engine is synchronous (every core policy is pure CPU); evaluate_async exists for callers already inside an event loop. Stores (LockStore, DraftStore) are ports you implement against your persistence; audit sinks receive one event per evaluation and may never fail an evaluation.

Install: pip install themis-policy (Python 3.11+, no dependencies). Tests: pip install -e '.[test]' && pytest.

Apache-2.0 — see the repository LICENSE.

Download files

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

Source Distribution

themis_policy-0.1.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

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

themis_policy-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file themis_policy-0.1.0.tar.gz.

File metadata

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

File hashes

Hashes for themis_policy-0.1.0.tar.gz
Algorithm Hash digest
SHA256 043c16c32e8b5d42324705b2966570cedbc0f28502b21c4bcecfc8f006d66263
MD5 af88335db7db0117b29c389b570aed20
BLAKE2b-256 4067b5b329ac7b348b25b07f275e1ba00b38761d8f97b8fc43df295c8a140daa

See more details on using hashes here.

Provenance

The following attestation bundles were made for themis_policy-0.1.0.tar.gz:

Publisher: publish-pypi.yml on Adam-Camp-King/Themis

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

File details

Details for the file themis_policy-0.1.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for themis_policy-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0ea689c1ed13d1ea4c06d1f95b98563a41d9384d50755317097609c67b44b581
MD5 3444fc9883f10e28d0ecc4dd51d5f02f
BLAKE2b-256 c00f6eac942a8caf924bc5adaf3d5827f435d5786fc32eb156e2d2dcd6e6e516

See more details on using hashes here.

Provenance

The following attestation bundles were made for themis_policy-0.1.0-py3-none-any.whl:

Publisher: publish-pypi.yml on Adam-Camp-King/Themis

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

Release history Release notifications | RSS feed

0.2.0

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page