Capsule Protocol Specification (CPS) — tamper-evident audit records for AI operations. Create, seal, verify, and chain Capsules in Python.
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file qp_capsule-1.4.0.tar.gz.
File metadata
- Download URL: qp_capsule-1.4.0.tar.gz
- Upload date:
- Size: 100.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fa6fc7fe915f62abe057bc09b8572681d17e35f2421c19cfea3b9373b59b7d8
|
|
| MD5 |
74eb5757504f21ab9a9ad18e1ecde227
|
|
| BLAKE2b-256 |
2abb50140940d228b362e94b34b03f4ecc1837e5e0e243c0a4259de927c3a612
|
Provenance
The following attestation bundles were made for qp_capsule-1.4.0.tar.gz:
Publisher:
python-release.yaml on quantumpipes/capsule
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qp_capsule-1.4.0.tar.gz -
Subject digest:
0fa6fc7fe915f62abe057bc09b8572681d17e35f2421c19cfea3b9373b59b7d8 - Sigstore transparency entry: 1108040338
- Sigstore integration time:
-
Permalink:
quantumpipes/capsule@1a8cb94a1098dc64e22662ee373f50e8bea11546 -
Branch / Tag:
refs/tags/py-v1.4.0 - Owner: https://github.com/quantumpipes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@1a8cb94a1098dc64e22662ee373f50e8bea11546 -
Trigger Event:
push
-
Statement type:
File details
Details for the file qp_capsule-1.4.0-py3-none-any.whl.
File metadata
- Download URL: qp_capsule-1.4.0-py3-none-any.whl
- Upload date:
- Size: 40.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf373f81d57a5af785e0d6b524b82c8e42794bf6b0a943d751ff6136daf7773b
|
|
| MD5 |
14a5230bec081b1a9b71132ea7050836
|
|
| BLAKE2b-256 |
4fa29d319e39061bdbc7b6d5564af9de9995263daaea330a22bff52426af65bd
|
Provenance
The following attestation bundles were made for qp_capsule-1.4.0-py3-none-any.whl:
Publisher:
python-release.yaml on quantumpipes/capsule
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
qp_capsule-1.4.0-py3-none-any.whl -
Subject digest:
cf373f81d57a5af785e0d6b524b82c8e42794bf6b0a943d751ff6136daf7773b - Sigstore transparency entry: 1108040350
- Sigstore integration time:
-
Permalink:
quantumpipes/capsule@1a8cb94a1098dc64e22662ee373f50e8bea11546 -
Branch / Tag:
refs/tags/py-v1.4.0 - Owner: https://github.com/quantumpipes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-release.yaml@1a8cb94a1098dc64e22662ee373f50e8bea11546 -
Trigger Event:
push
-
Statement type: