English · 中文 · Español · 日本語 · Português
dcp-ai — Python SDK
Official Python SDK for the Digital Citizenship Protocol (DCP v2.0). Pydantic v2 models, hybrid post-quantum signatures (Ed25519 + ML-DSA-65, plus SLH-DSA-192f), the ML-KEM-768 KEM primitive, composite signatures with pq_over_classical binding, V1 and V2 bundle signing and verification, OpenTelemetry observability, DCP-04 through DCP-09 behavior, and a full-featured CLI.
Installation
pip install dcp-ai
Optional extras
pip install "dcp-ai[fastapi]" # FastAPI middleware
pip install "dcp-ai[langchain]" # LangChain integration
pip install "dcp-ai[openai]" # OpenAI wrapper
pip install "dcp-ai[crewai]" # CrewAI multi-agent
pip install "dcp-ai[otlp]" # OpenTelemetry OTLP exporter
Features
| Area | Status |
|---|---|
| Ed25519 / ML-DSA-65 (FIPS 204) providers | Yes |
| SLH-DSA-192f provider | Yes, FIPS 205 (pure, empty context), interoperable with the other SDKs |
| ML-KEM-768 | KEM primitive: yes (MlKem768Provider, FIPS 203). DCP-04 X25519 + ML-KEM-768 hybrid key exchange: not yet |
Composite signatures (pq_over_classical) + verification |
Yes |
| Canonical JSON v2 + domain separation | Yes |
| Dual hash (SHA-256 + SHA3-256) + Merkle roots | Yes |
| Bundle signing + verification | V1: yes. V2 (SignedBundleV2): yes, BundleBuilderV2 / sign_bundle_v2 / verify_signed_bundle_v2 |
DCP-04 A2A discovery + handshake + AES-256-GCM session (via cryptography) |
Yes |
| DCP-05 agent lifecycle (commissioning / vitality / decommissioning) | Yes |
| DCP-06 digital succession (testament, memory transfer, ceremony) | Yes |
| DCP-07 dispute resolution + arbitration + jurisprudence | Yes |
| DCP-08 rights + obligations + compliance | Yes |
| DCP-09 delegation + awareness threshold + principal mirror | Yes |
Session nonce helpers, security tier engine (compute_security_tier(intent, policy_decision), spec §14.2), emergency revocation |
Yes |
Lazy PQ checkpoints + PQCheckpointManager |
Yes |
| Blinded RPR, multi-party authorization, algorithm advisory helpers | Yes |
Canonical error codes (38 shared across all SDKs) + detect_wire_format |
Yes |
OpenTelemetry / OTLP exporter (optional [otlp] extra) |
Yes |
Quickstart
from dcp_ai import (
BundleBuilder,
sign_bundle,
verify_signed_bundle,
generate_keypair,
ResponsiblePrincipalRecord,
AgentPassport,
Intent,
IntentTarget,
PolicyDecision,
)
# 1. Generate Ed25519 keypair
keys = generate_keypair()
# 2. Build a Citizenship Bundle
bundle = (
BundleBuilder()
.responsible_principal_record(ResponsiblePrincipalRecord(
dcp_version="1.0",
human_id="human-001",
entity_type="natural_person",
jurisdiction="ES",
liability_mode="full",
created_at="2025-01-01T00:00:00Z",
expires_at=None,
))
.agent_passport(AgentPassport(
dcp_version="1.0",
agent_id="agent-001",
human_id="human-001",
agent_name="MyAgent",
capabilities=["browse", "api_call"],
risk_tier="medium",
status="active",
created_at="2025-01-01T00:00:00Z",
expires_at=None,
))
.intent(Intent(
dcp_version="1.0",
agent_id="agent-001",
human_id="human-001",
timestamp="2025-01-01T00:00:00Z",
action_type="api_call",
target=IntentTarget(channel="api", endpoint="https://api.example.com/data"),
data_classes=["public"],
estimated_impact="low",
))
.policy_decision(PolicyDecision(
dcp_version="1.0",
agent_id="agent-001",
human_id="human-001",
timestamp="2025-01-01T00:00:00Z",
decision="allow",
matched_rules=["default-allow"],
))
.build()
)
# 3. Sign
signed = sign_bundle(bundle, keys["secret_key_b64"])
# 4. Verify
result = verify_signed_bundle(signed, keys["public_key_b64"])
print(result) # {"verified": True, "errors": []}
CLI
The SDK includes a CLI built with Typer. Available as dcp after installation.
# Version
dcp version
# Generate Ed25519 keypair
dcp keygen [out_dir]
# Validate an object against a DCP schema
dcp validate <schema_name> <json_path>
# Validate a complete Citizenship Bundle
dcp validate-bundle <bundle_path>
# Verify a Signed Bundle
dcp verify <signed_path> [public_key_path]
# Compute bundle hash (SHA-256)
dcp bundle-hash <bundle_path>
# Compute Merkle root of audit entries
dcp merkle-root <bundle_path>
# Compute intent_hash
dcp intent-hash-cmd <intent_path>
API Reference
Crypto
| Function | Signature | Description |
|---|---|---|
generate_keypair() |
() -> dict[str, str] |
Returns {"public_key_b64": ..., "secret_key_b64": ...} |
sign_object(obj, secret_key_b64) |
(Any, str) -> str |
Signs, returns base64 |
verify_object(obj, signature_b64, public_key_b64) |
(Any, str, str) -> bool |
Verifies signature |
canonicalize(obj) |
(Any) -> str |
Deterministic JSON |
public_key_from_secret(secret_key_b64) |
(str) -> str |
Derives public key |
Merkle & Hashing
| Function | Signature | Description |
|---|---|---|
hash_object(obj) |
(Any) -> str |
SHA-256 of canonicalized JSON |
merkle_root_from_hex_leaves(leaves) |
(list[str]) -> str | None |
Merkle root |
merkle_root_for_audit_entries(entries) |
(list[Any]) -> str | None |
Merkle root of audit entries |
intent_hash(intent) |
(Any) -> str |
Intent hash |
prev_hash_for_entry(prev_entry) |
(Any) -> str |
Previous entry hash |
Schema Validation
| Function | Signature | Description |
|---|---|---|
validate_schema(schema_name, data) |
(str, Any) -> dict |
Returns {"valid": bool, "errors": [...]} |
validate_bundle(bundle) |
(dict) -> dict |
Validates a complete bundle |
Bundle Builder
bundle = (
BundleBuilder()
.responsible_principal_record(rpr)
.agent_passport(passport)
.intent(intent)
.policy_decision(policy)
.add_audit_entry(entry) # Manual
.create_audit_entry(...) # Auto-computes hashes
.build() # => CitizenshipBundle
)
Bundle Signing
sign_bundle(
bundle: CitizenshipBundle,
secret_key_b64: str,
signer_type: str = "human",
signer_id: str | None = None,
) -> dict[str, Any]
Bundle Verification
verify_signed_bundle(
signed_bundle: dict[str, Any],
public_key_b64: str | None = None,
) -> dict[str, Any] # {"verified": bool, "errors": [...]}
Verifies: schema, Ed25519 signature, bundle_hash, merkle_root, intent_hash chain, prev_hash chain.
V2 Bundles
BundleBuilderV2, sign_bundle_v2 and verify_signed_bundle_v2 (in dcp_ai.v2) port the TypeScript SDK's builder-v2.ts, signer-v2.ts and verify-v2.ts. Artifacts are SignedPayload dicts ({"payload", "payload_hash", "composite_sig"}); the bundle signature is a composite signature over the manifest.
from dcp_ai.providers import Ed25519Provider, MlDsa65Provider
from dcp_ai.v2 import AlgorithmRegistry, BundleBuilderV2, sign_bundle_v2, verify_signed_bundle_v2
registry = AlgorithmRegistry()
registry.register_signer(Ed25519Provider())
registry.register_signer(MlDsa65Provider())
bundle = (
BundleBuilderV2(session_nonce)
.responsible_principal_record(signed_rpr)
.agent_passport(signed_passport)
.intent(signed_intent)
.policy_decision(signed_policy)
.add_audit_entries(audit_events)
.build()
)
signed = await sign_bundle_v2(bundle, registry, "human", "human-001", classical_key, pq_key)
result = await verify_signed_bundle_v2(signed, registry) # DEFAULT_VERIFIER_POLICY
# {"verified": bool, "errors": [...], "warnings": [...], "details": {...}}
The verifier also checks each artifact's own composite signature (the RPR against the principal's binding_keys, the rest against the passport keys) and, in every policy mode, rejects a PQ signature that is present but invalid. The mode is the stricter of the policy mode and the security tier's mode (spec §14.3), and details["resolved_tier"] reports the tier.
Pydantic Models
All DCP v1 artifacts are available as Pydantic v2 models with automatic validation:
ResponsiblePrincipalRecord, AgentPassport, Intent, IntentTarget, PolicyDecision, AuditEntry, AuditEvidence, CitizenshipBundle, SignedBundle, BundleSignature, SignerInfo, RevocationRecord, HumanConfirmation
V2 Models (DCP-05–09):
DCP-05 — Lifecycle: LifecycleState, TerminationMode, DataDisposition, VitalityMetrics, CommissioningCertificate, VitalityReport, DecommissioningRecord
DCP-06 — Succession: TransitionType, MemoryDisposition, MemoryClassification, SuccessorPreference, DigitalTestament, SuccessionRecord, MemoryTransferEntry, DualHashRef, MemoryTransferManifest
DCP-07 — Disputes: DisputeType, EscalationLevel, DisputeStatus, ObjectionType, AuthorityLevel, DisputeRecord, ArbitrationResolution, JurisprudenceBundle, ObjectionRecord
DCP-08 — Rights: RightType, ComplianceStatus, RightEntry, RightsDeclaration, ObligationRecord, RightsViolationReport
DCP-09 — Delegation: AuthorityScopeEntry, DelegationMandate, AdvisoryDeclaration, PrincipalMirror, InteractionRecord, ThresholdRule, ThresholdOperator, ThresholdAction, AwarenessThreshold
# Example: Lifecycle management
from dcp_ai.v2.models import CommissioningCertificate, LifecycleState
cert = CommissioningCertificate(
certificate_id="cert-001",
agent_id="agent-001",
commissioned_by="human-001",
commissioned_at="2026-03-01T00:00:00Z",
initial_state=LifecycleState.COMMISSIONED,
conditions=["Must complete onboarding within 30 days"],
)
Domain Separation (V2)
V2 Domain Separation Contexts: Bundle, Intent, Passport, Revocation, Governance, Lifecycle, Succession, Dispute, Rights, Delegation, Awareness
Development
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest -v
# Async tests
pytest -v --asyncio-mode=auto
Dependencies
pynacl— Ed25519 cryptographyjsonschema— JSON Schema validationpydanticv2 — Data modelstyper— CLI frameworkpqcrypto≥ 1.0 — ML-DSA-65, SLH-DSA-192f, ML-KEM-768 (FIPS 204/205/203)cryptography— AES-256-GCM for DCP-04 A2A sessions
License
Apache-2.0
Metadata
Release files for dcp-ai 2.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| dcp_ai-2.9.0.tar.gz | 105.6 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| dcp_ai-2.9.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 197.6 kB
Release files / dcp_ai-2.9.0.tar.gz
| Download URL | dcp_ai-2.9.0.tar.gz |
|---|---|
| Size | 105.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7aea6a17dca031e4304f901d9743de8a9dd3d7303627432242ae3bf81d5be278
|
|
BLAKE2b-256 checksum How to use checksums |
0f50c0d64c4b8f18a163dc878d7f2bb9fd091373d44007e5f5cf3a5e3a3cccf0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 22, 2026.
Transparency logRelease files / dcp_ai-2.9.0-py3-none-any.whl
| Download URL | dcp_ai-2.9.0-py3-none-any.whl |
|---|---|
| Size | 92.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d213a7390aa35697e958e7955b50bef307c20127195a412e382ddc366fb9e796
|
|
BLAKE2b-256 checksum How to use checksums |
fc692964f84200f14dece1197296d8c45f0a707a5f7d5b8bc57827988f557bb5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Oct 22, 2026.
Transparency logSecurity for dcp-ai 2.9.0
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.
Attestation for dcp_ai-2.9.0.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 Oct 22, 2026.
Transparency logA 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.