Skip to main content

Capsule Protocol — Python Reference Implementation

The canonical implementation of the Capsule Protocol Specification (CPS).

Python Coverage


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

Apache License 2.0 with additional patent grant.

Metadata

Release files for qp-capsule 1.5.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qp-capsule 1.5.8
File Size Uploaded Provenance Actions
qp_capsule-1.5.8.tar.gz 134.7 kB With provenance Details for qp_capsule-1.5.8.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qp-capsule 1.5.8
File Interpreter ABI Platform Actions
qp_capsule-1.5.8-py3-none-any.whl Python 3 none any Details for qp_capsule-1.5.8-py3-none-any.whl

Total release size: 187.9 kB

Release files / qp_capsule-1.5.8.tar.gz

Download URL qp_capsule-1.5.8.tar.gz
Size 134.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b9788823b26f056a8ea3d07bc65451500c360aacdb4787e6b8271f115e2aede2
BLAKE2b-256 checksum
How to use checksums
0debceab466f3bcbfd4c4feb70b36884530f03dabd85e58e77832a10f38f157e
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 log

Release files / qp_capsule-1.5.8-py3-none-any.whl

Download URL qp_capsule-1.5.8-py3-none-any.whl
Size 53.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c49198787ace25c049f986ce6d531d01b25f65607ec9b6e8988248a339b43d64
BLAKE2b-256 checksum
How to use checksums
6eb5e7a7455c7d701f9e7c43b2c938481d1b6515718adab95ceb1f9819ab54f8
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 log

Security for qp-capsule 1.5.8

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

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for qp_capsule-1.5.8.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 log

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.

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