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.9
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 | Actions |
|---|---|---|---|---|
| qp_capsule-1.5.9.tar.gz | 135.1 kB | With provenance | Details for qp_capsule-1.5.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| qp_capsule-1.5.9-py3-none-any.whl | Python 3 | none | any | Details for qp_capsule-1.5.9-py3-none-any.whl |
Total release size: 188.4 kB
Release files / qp_capsule-1.5.9.tar.gz
| Download URL | qp_capsule-1.5.9.tar.gz |
|---|---|
| Size | 135.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
12dd9f4434f209af6c4d7d5627e3df8bdb2b0f469f92387578f3abb4d64c6e96
|
|
BLAKE2b-256 checksum How to use checksums |
332f1583af416cb09eb462c96a2e7ef07f85a3e1342259a2a3a9b1a36590f3e9
|
| 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 Nov 5, 2026.
Transparency logRelease files / qp_capsule-1.5.9-py3-none-any.whl
| Download URL | qp_capsule-1.5.9-py3-none-any.whl |
|---|---|
| Size | 53.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ff5c262e7f98a2b389b74ddb5d76c9af5abeed0c36e3287d33d0a453b0c2a2e3
|
|
BLAKE2b-256 checksum How to use checksums |
7fb2dd53fac4e6169c93adfcd25fd053febfab0e13aa922dc185f243ae1aaad9
|
| 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 Nov 5, 2026.
Transparency logSecurity for qp-capsule 1.5.9
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for qp_capsule-1.5.9.tar.gz
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 Nov 5, 2026.
Transparency logA 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.