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.2.0.tar.gz (80.5 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.2.0-py3-none-any.whl (30.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qp_capsule-1.2.0.tar.gz
  • Upload date:
  • Size: 80.5 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.2.0.tar.gz
Algorithm Hash digest
SHA256 13c76a42f1f2589901ecffaceea1688f602e5aca0f5a6af6e9d2f5fcd5027b4c
MD5 5604b47c0090221fba66183e1602f55f
BLAKE2b-256 175f1747c98060f1f9225cbbf632fab1f49b8eccdbcec08ada3cc9ec92f57af0

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: qp_capsule-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 868b3bcbacc1738342487fccfe464539b231a3468b8b328a76c95a4c31cb8f4e
MD5 51ccde9b143358ad0ccddae083c202ae
BLAKE2b-256 09bcee4d5019d3d9f767414b424827d375ff559c76a0f97750c7e7626c0b6d97

See more details on using hashes here.

Provenance

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