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.

Release files for themis-policy 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for themis-policy 0.2.1
File Size Uploaded
themis_policy-0.2.1.tar.gz 17.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for themis-policy 0.2.1
File Interpreter ABI Platform
themis_policy-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 37.3 kB

Release files / themis_policy-0.2.1.tar.gz

Download URL themis_policy-0.2.1.tar.gz
Size 17.5 kB
Tags Source
SHA-256 checksum
How to use checksums
7f1b29a9053eb296aa8fcb6acbdbeb711077bc8c3b62a372224c9e6868213700
BLAKE2b-256 checksum
How to use checksums
ba41eefb6935ed67aa92cca1ab206931244695b8413e805a3c5629542bbe05fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / themis_policy-0.2.1-py3-none-any.whl

Download URL themis_policy-0.2.1-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9268eea891abe664c8b9ed98eec85cf3b6e55d47f4e743b1877866c7dd57d073
BLAKE2b-256 checksum
How to use checksums
ee558ddbf7af11eecb857579a1461a80b2772ded0ee8d8f0dd8a2bfb43cc2950
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release 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