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.2.0.tar.gz (17.1 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.2.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: themis_policy-0.2.0.tar.gz
  • Upload date:
  • Size: 17.1 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.2.0.tar.gz
Algorithm Hash digest
SHA256 6a75db237d01c9ce95ed6982998cdd67db612ec06f04f75da84a3626249bec27
MD5 13a095b4273c4d66efb718e18994427a
BLAKE2b-256 a1a91038e332df2d51c80efa7e5c6a7d8e1cc4a596a939b07142a39ce88f82e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for themis_policy-0.2.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.2.0-py3-none-any.whl.

File metadata

  • Download URL: themis_policy-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f589c7dd9df445daed36cc2f630a92199c2f5e31721e58d24775bd15f742d17c
MD5 a62228fe011b9efb1bf29dc1012d84f8
BLAKE2b-256 db522cc3dc076943616253633006c87bb2ee7a1fae610bff6fac32e6d802eeb0

See more details on using hashes here.

Provenance

The following attestation bundles were made for themis_policy-0.2.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

This release

0.2.0 This release

2 files

0.1.0

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