capnagent — Python bindings
Python bindings for capnagent, the capability-based authority-token engine for AI agent tool calls.
The bindings cover the same surface as the TypeScript/WASM bindings:
Issuer, CapabilityBuilder, Capability, Verifier, Auditor. The
Rust core (capnagent-core) is shared 1:1 — same engine, different
language surface.
Install
pip install capnagent
(Pre-1.0: built from source via pip install capnagent once the
first wheel is published; until then, install from source — see
"Build from source" below.)
Quick start
import json
import os
from capnagent import Issuer, Verifier, Auditor
root_key = os.urandom(32) # production: KMS / secret manager
audit_key = os.urandom(32)
# Issue a scoped capability.
cap = (
Issuer.from_key(root_key)
.issue("checkout")
.caveat('caller == "agent:planner"')
.caveat('tool == "checkout.purchase"')
.caveat("now <= @2099-01-01T00:00:00Z")
.build()
)
verifier = Verifier(root_key)
auditor = Auditor(audit_key)
# Verify a call: returns a JSON-encoded receipt.
ctx = {
"caller": "agent:planner",
"tool": "checkout.purchase",
"args": {"sku": "USB-C cable", "amount_cents": 1299},
"nowMs": 1_700_000_000_000,
}
receipt_json = verifier.verify_with_context(cap, json.dumps(ctx), auditor)
receipt = json.loads(receipt_json)
assert receipt["outcome"]["kind"] == "allowed"
API
| Class | Method | Notes |
|---|---|---|
Issuer |
from_key(bytes) -> Issuer |
32+ bytes from CSPRNG. |
issue(identifier) -> CapabilityBuilder |
||
CapabilityBuilder |
caveat(predicate) |
DSL: see docs/WEEK2_SPEC.md §2.2. |
holder_of_key(pubkey_32_bytes) |
DPoP-style hok binding. | |
build() -> Capability |
Raises if zero caveats (angle C.5). | |
Capability |
serialize() -> str |
URL-safe base64. |
parse(token) -> Capability |
Static. | |
attenuate(predicate) -> Capability |
Pre-validates parse (angle B.2). | |
Verifier |
Verifier(key_bytes) |
|
verify_with_context(cap, ctx_json, auditor) -> str |
Receipt as JSON string. Pass json.dumps(ctx) for full A.1 protection. |
|
Auditor |
Auditor(key_bytes) |
Empty key raises (angle B.3). |
verify(receipt_json) |
Raises on tampered receipt. |
Why the Python binding gets A.1 closure for free
The v0.6 angle finding A.1 (sub-ulp f64 collapse) has a JS-layer
artefact: JS's Number IS f64, so JSON.parse collapses sub-ulp
digits BEFORE the WASM boundary. v0.6.1 added a JSON-string entry
point to the WASM binding to work around this for JS callers.
Python doesn't have that problem. Python's json.dumps preserves
arbitrary integer precision (Python ints are unbounded), and float
literals round-trip through repr() in a way that preserves
syntactic shape. The Rust side parses the JSON string with
serde_json::from_str (with arbitrary_precision), keeping the
source text past the parse boundary. So the v0.6 integer-domain rule
fires correctly end-to-end through the Python binding by default.
The test test_v0_6_integer_caveat_rejects_decimal_arg in
tests/test_basic.py exercises this directly.
Build from source
Prerequisites:
- Rust toolchain (stable)
- Python 3.8+ with development headers
pip install maturin
cd crates/capnagent-py
maturin develop # editable install into the current venv
python -m pytest tests/ -v
To produce a publishable wheel:
maturin build --release
# Wheel appears under crates/capnagent-py/target/wheels/
License
Apache-2.0 — same as the Rust core.
Metadata
Release files for capnagent 0.7.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| capnagent-0.7.4.tar.gz | 95.4 kB | Without provenance | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| capnagent-0.7.4-cp38-abi3-win_amd64.whl | CPython 3.8 | abi3 | Windows x86-64 | Details |
| capnagent-0.7.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.8 | abi3 | Linux glibc 2.17+ x86-64 | Details |
| capnagent-0.7.4-cp38-abi3-macosx_11_0_arm64.whl | CPython 3.8 | abi3 | macOS 11.0+ ARM64 | Details |
Total release size: 1.4 MB
Release files / capnagent-0.7.4.tar.gz
| Download URL | capnagent-0.7.4.tar.gz |
|---|---|
| Size | 95.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3096730390245511fecbbcd525ff390d3b2af0492a0f42b7cdc8ee97b1c62c65
|
|
BLAKE2b-256 checksum How to use checksums |
0165634aa08da5b3442cf63dba8d3b21232642bfaa79c591975451a2d89b6555
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.13.3
|
Release files / capnagent-0.7.4-cp38-abi3-win_amd64.whl
| Download URL | capnagent-0.7.4-cp38-abi3-win_amd64.whl |
|---|---|
| Size | 339.5 kB |
| Tags | CPython 3.8 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
f49d206d3650eb903248d7d6a8016284319a805a7941a5a16e7139148813ea22
|
|
BLAKE2b-256 checksum How to use checksums |
68be44617b77e9905af346877f42a75a5a831c489f41ae4bf62b1c3604d2cdfb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.13.3
|
Release files / capnagent-0.7.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | capnagent-0.7.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 503.5 kB |
| Tags | CPython 3.8 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
704e6e76a674b2f93f4296b6449f958ee66c1ec75bfdc4134e4917feb410dfb3
|
|
BLAKE2b-256 checksum How to use checksums |
c9e260e95b0310d4ebf5c6ee28e24932de87d30c9f0f1d501a6cce230a5cfd3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.13.3
|
Release files / capnagent-0.7.4-cp38-abi3-macosx_11_0_arm64.whl
| Download URL | capnagent-0.7.4-cp38-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 444.0 kB |
| Tags | CPython 3.8 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1eb7bf063f5785a040943faa7c0c9fd69a0d86e99757712bb50a478664f52273
|
|
BLAKE2b-256 checksum How to use checksums |
842a4239dccea73855a81d3538ed9007d09f2d8581da42fb3126595b79298499
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.13.3
|
Security for capnagent 0.7.4
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.