Skip to main content

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).

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.

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

qp_capsule-1.4.0.tar.gz (100.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qp_capsule-1.4.0-py3-none-any.whl (40.4 kB view details)

Uploaded Python 3

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

Hashes for qp_capsule-1.4.0.tar.gz
Algorithm Hash digest
SHA256 0fa6fc7fe915f62abe057bc09b8572681d17e35f2421c19cfea3b9373b59b7d8
MD5 74eb5757504f21ab9a9ad18e1ecde227
BLAKE2b-256 2abb50140940d228b362e94b34b03f4ecc1837e5e0e243c0a4259de927c3a612

See more details on using hashes here.

Provenance

The following attestation bundles were made for qp_capsule-1.4.0.tar.gz:

Publisher: python-release.yaml on quantumpipes/capsule

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for qp_capsule-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf373f81d57a5af785e0d6b524b82c8e42794bf6b0a943d751ff6136daf7773b
MD5 14a5230bec081b1a9b71132ea7050836
BLAKE2b-256 4fa29d319e39061bdbc7b6d5564af9de9995263daaea330a22bff52426af65bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for qp_capsule-1.4.0-py3-none-any.whl:

Publisher: python-release.yaml on quantumpipes/capsule

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page