Capsule Protocol — Python Reference Implementation
The canonical implementation of the Capsule Protocol Specification (CPS).
Install
pip install qp-capsule
| Command | What You Get | Dependencies |
|---|---|---|
pip install qp-capsule |
Create, seal, verify | 1 (pynacl) |
pip install qp-capsule[storage] |
+ Hash chain + SQLite persistence | 2 (+ sqlalchemy) |
pip install qp-capsule[postgres] |
+ Hash chain + PostgreSQL (multi-tenant) | 2 (+ sqlalchemy) |
pip install qp-capsule[pq] |
+ Post-quantum ML-DSA-65 signatures | 2 (+ liboqs) |
Quick Start
from qp_capsule import Capsule, Seal, CapsuleType, TriggerSection
capsule = Capsule(
type=CapsuleType.AGENT,
trigger=TriggerSection(
source="deploy-bot",
request="Deploy service v2.4 to production",
),
)
seal = Seal()
seal.seal(capsule)
assert seal.verify(capsule)
With Hash Chain
from qp_capsule import Capsule, Seal, CapsuleChain, CapsuleStorage, CapsuleType, TriggerSection
storage = CapsuleStorage()
chain = CapsuleChain(storage)
seal = Seal()
capsule = Capsule(
type=CapsuleType.AGENT,
trigger=TriggerSection(source="deploy-bot", request="Deploy v2.4"),
)
capsule = await chain.seal_and_store(capsule, seal)
result = await chain.verify()
assert result.valid
High-Level API
from qp_capsule import Capsules
capsules = Capsules() # SQLite, zero config
@capsules.audit(type="agent")
async def run_agent(task: str, *, site_id: str):
cap = capsules.current()
cap.reasoning.model = "gpt-4o"
cap.reasoning.confidence = 0.92
result = await llm.complete(task)
cap.outcome.summary = f"Generated {len(result.text)} chars"
return result
await run_agent("Write a summary", site_id="tenant-123")
FastAPI Integration
from qp_capsule.integrations.fastapi import mount_capsules
app = FastAPI()
mount_capsules(app, capsules, prefix="/api/v1/capsules")
Conformance
This implementation passes all 16 golden test vectors:
cd reference/python
make test-golden
Documentation
| Document | Description |
|---|---|
| Getting Started | Detailed quickstart |
| High-Level API | Capsules class, @audit decorator |
| API Reference | Every class and method |
| Audit Report | Security audit results |
Development
cd reference/python
pip install -e ".[dev,storage]"
make test # 350 tests, 100% coverage
make lint # ruff check
make typecheck # mypy strict
make test-golden # Conformance tests only
make test-all # lint + typecheck + test + golden
License
Metadata
Release files for qp-capsule 1.5.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 | |
|---|---|---|---|
| qp_capsule-1.5.4.tar.gz | 127.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| qp_capsule-1.5.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 176.8 kB
Release files / qp_capsule-1.5.4.tar.gz
| Download URL | qp_capsule-1.5.4.tar.gz |
|---|---|
| Size | 127.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
61ad8f69af7bad5935953d89301793b536a5167a0b3eb9109bc96dec4f9f1dea
|
|
BLAKE2b-256 checksum How to use checksums |
7da8fb6a5a1196fe4a241b1a1c46265a34e8ed6ff6837e7371f2e0b4280211f6
|
| 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 14, 2026.
Transparency logRelease files / qp_capsule-1.5.4-py3-none-any.whl
| Download URL | qp_capsule-1.5.4-py3-none-any.whl |
|---|---|
| Size | 49.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c834926530c72b6aba996f9bfaea6cc282f7c66d98ab1613ee512387f10118a8
|
|
BLAKE2b-256 checksum How to use checksums |
5f3042f06c345ef960367070f97150aced67903bf4e0f0a20097db99ed25d31c
|
| 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 14, 2026.
Transparency log