Agent-readable docs index: /llms.txt. Full docs in one file: /llms-full.txt. Download /docs.zip to grep all markdown files locally.

Python Decorator Integration

The @dmint.protect decorator places a deterministic authorization gate directly in front of Python callables.
Dmint intercepts invocations, canonicalizes arguments, verifies policies, and persists pending approval records without altering your business logic.

1. Supported Callable Types

Dmint supports the following callable types:
  • Synchronous Functions (def)
  • Asynchronous Coroutines (async def)
  • Instance Methods (methods taking self)
  • Class Methods (@classmethod, taking cls)
  • Static Methods (@staticmethod)
Generators are not supported: Python generator functions (yield) and asynchronous generators (yield in async def) cannot be decorated because execution resumes in chunks across multiple caller ticks, violating atomic pre-execution authorization.

2. Zero-Config Local Setup (Dmint.local)

For local development and single-host workflows, Dmint.local() automatically provisions .dmint/signing.key (0600), .dmint/integrity.key (0600), and .dmint/approvals.sqlite3:
local_example.py
from dmint import ApprovalRequiredError, Dmint, Policy, Rule policy = Policy([ Rule.allow("payments", "get_status"), Rule.approval_required("payments", "refund"), ]) dmint = Dmint.local(policy, agent_id="agent-01") @dmint.protect("payments.refund") def issue_refund(payment_id: str, amount: float) -> dict: return {"id": payment_id, "refunded": amount}

Explicit Production Setup (Dmint)

For distributed or custom-configured production environments:
sync_example.py
from datetime import datetime, timezone, timedelta from dmint import ( Dmint, Policy, Rule, PolicyProvenance, SQLiteApprovalStore, TrustedContext, policy_digest, ) policy = Policy([ Rule.allow("payments", "get_status"), Rule.approval_required("payments", "refund"), ]) store = SQLiteApprovalStore("approvals.sqlite3", deployment_epoch="default") provenance = PolicyProvenance("v1", policy_digest(policy), datetime.now(timezone.utc)) dmint = Dmint( policy=policy, agent_id="agent-01", context=TrustedContext({"environment": "production"}), approval_store=store, policy_provenance=provenance, approval_ttl=timedelta(minutes=5), ) @dmint.protect("payments.get_status") def get_payment_status(payment_id: str) -> dict: return {"id": payment_id, "status": "SETTLED"} @dmint.protect("payments.refund") def issue_refund(payment_id: str, amount: float) -> dict: return {"id": payment_id, "refunded": amount}

3. Asynchronous (async def) Protection

When wrapping an async def coroutine, Dmint evaluates authorization before the coroutine begins and returns an awaitable result:
async_example.py
import asyncio from dmint import Dmint, Policy, Rule, TrustedContext, ApprovalRequiredError policy = Policy([ Rule.allow("api", "fetch"), Rule.approval_required("api", "mutate"), ]) dmint = Dmint( policy=policy, agent_id="async-worker-01", context=TrustedContext({"environment": "staging"}), ) @dmint.protect("api.mutate") async def async_database_mutate(record_id: str, payload: dict) -> dict: await asyncio.sleep(0.01) # Simulated async I/O return {"record_id": record_id, "updated": True} async def main(): try: result = await async_database_mutate("rec_99", {"status": "archived"}) print(f"Result: {result}") except ApprovalRequiredError as exc: print(f"Halted: {exc.code} for request {exc.request_id}") if __name__ == "__main__": asyncio.run(main())

4. Class Methods, Static Methods, and Instance Methods

Dmint cleanly handles OOP method signatures:
methods_example.py
class LedgerService: def __init__(self, tenant_id: str): self.tenant_id = tenant_id # Instance method: Dmint strips 'self' from arguments and scopes action as 'LedgerService.record_entry' # (Matched by Rule.allow("ledger", "LedgerService.record_entry") or Rule.allow("ledger", "*")) @dmint.protect("ledger.record_entry") def record_entry(self, entry_id: str, amount: float) -> str: return f"Tenant {self.tenant_id}: Recorded entry {entry_id} for ${amount:.2f}" # Class method: Dmint preserves class reference @classmethod @dmint.protect("ledger.get_version") def get_version(cls) -> str: return "ledger-v2.1" # Static method: @staticmethod @dmint.protect("ledger.compute_tax") def compute_tax(subtotal: float, rate: float) -> float: return subtotal * rate

5. Dynamic Resource Resolvers

Policies can match against specific resources (such as file paths, database tables, or target URLs). Use a callable resource resolver to extract the resource string dynamically from the function's arguments:
# Resource extracted dynamically from arguments dict: @dmint.protect( "filesystem.read", resource=lambda args: args["path"], ) def read_system_file(path: str) -> str: with open(path, "r", encoding="utf-8") as f: return f.read() # Dynamic resource with compound formatting: @dmint.protect( "database.table_operation", resource=lambda args: f"{args['schema']}.{args['table']}", ) def run_table_op(schema: str, table: str, query: str): ...
If the resource resolver returns an invalid type or fails validation, Dmint fails closed with RequestValidationError.

6. Remote Policy Loading and Digest Pinning

In microservices or containerized workers, policies can be loaded directly from a centralized HTTPS endpoint with strict SHA-256 digest pinning:
import os from dmint import Dmint, TrustedContext # Remote policy loading requires expected_policy_digest: dmint = Dmint( policy_file="https://internal-security.company.com/policies/billing-v2.json", expected_policy_digest=os.environ["DMINT_EXPECTED_POLICY_DIGEST"], agent_id="agent-01", context=TrustedContext({"env": "prod"}), )
If the remote payload does not match the expected SHA-256 digest, Dmint refuses to start and raises PolicyError.

7. Handling Non-JSON Argument Types (datetime, Decimal, UUID, Path)

Because Dmint computes deterministic RFC 8785 (JCS) fingerprints, protected functions accept JSON-native argument types (str, int, float, bool, None, list, dict). Passing non-JSON objects such as datetime, Decimal, UUID, or pathlib.Path fails closed with CanonicalizationError (code="DMT_CANONICALIZATION_ERROR").
Convert rich types to canonical strings or numbers at the tool boundary before calling the protected function:
from datetime import datetime from pathlib import Path from uuid import UUID @dmint.protect("audit.write_event") def write_event(event_id: str, path: str, occurred_at: str) -> dict: return {"event_id": event_id, "path": path, "occurred_at": occurred_at} # Normalize rich Python objects to strings at the call site: def log_user_event(event_id: UUID, path: Path, occurred_at: datetime) -> dict: return write_event(str(event_id), path.as_posix(), occurred_at.isoformat())

Next Steps