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.5.2.tar.gz (110.6 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.5.2-py3-none-any.whl (41.9 kB view details)

Uploaded Python 3

File details

Details for the file qp_capsule-1.5.2.tar.gz.

File metadata

  • Download URL: qp_capsule-1.5.2.tar.gz
  • Upload date:
  • Size: 110.6 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.5.2.tar.gz
Algorithm Hash digest
SHA256 7c69840d9f736490df483363bbb4f895dbb9f395365920e7064f66c345b50e1d
MD5 b339f787f391e69ff58150b1723534f0
BLAKE2b-256 884212b61a15879c0d934a4d4ed7822499b112c3b8426d5bce7107fc5477d880

See more details on using hashes here.

Provenance

The following attestation bundles were made for qp_capsule-1.5.2.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.5.2-py3-none-any.whl.

File metadata

  • Download URL: qp_capsule-1.5.2-py3-none-any.whl
  • Upload date:
  • Size: 41.9 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.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 56aebf2eb5d5e9e893938db2a5f4a8a1d9ae93582e6283ad0ce65b7b79389df1
MD5 0bc79c6cd8457787c36e058ce882bd2d
BLAKE2b-256 505f795e9814dce420ea4a2b71d029b5ac6fc156f75cc9a5cbc39c5ee3f25526

See more details on using hashes here.

Provenance

The following attestation bundles were made for qp_capsule-1.5.2-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