Python SDK scaffold for the Causal Agent Protocol
Project description
CAP Python SDK
Official Python SDK for building and integrating CAP-compatible systems.
This SDK currently targets the active CAP v0.3.0 public surface.
If you are new to CAP itself, start with the cap repository for the protocol overview, getting-started guides, and normative specification. This repository is the Python implementation layer for people who want to call CAP servers or expose CAP-compatible services in Python.
Choose The Right Repo
cap: learn CAP, read the docs, and track the protocol specificationpython-sdk: build CAP clients and CAP-compatible Python serverscap-example: inspect the official minimal example server that exposes CAP over HTTP
What This SDK Gives You
This repository ships three Python-facing layers that match the code today:
cap.core: typed CAP envelopes, verb contracts, builders, capability-card models, canonical constants, and error modelscap.client: an async HTTP client for calling CAP servers through the standard single-entry CAP routecap.server: a thin FastAPI adapter for validating requests, dispatching by verb, and returning CAP-shaped responses
It includes typed models and helpers for the mounted v0.3.0 verbs and capability-card structures.
Use this SDK when you want to:
- call a CAP server from Python without hand-writing request and response envelopes
- publish a CAP-compatible endpoint in a FastAPI service
- share one typed protocol layer across clients, servers, tests, and internal tooling
Installation
Install the published package:
pip install cap-protocol
This base install includes the typed protocol models and the HTTP client. It does not install FastAPI.
If you want to use the optional cap.server FastAPI adapter:
pip install "cap-protocol[server]"
For local development from source:
pip install -e ".[server,dev]"
The distribution name is cap-protocol. The Python import package is cap.
Quickstart: Call A CAP Server
import asyncio
from cap.client import AsyncCAPClient
async def main() -> None:
client = AsyncCAPClient("https://example.com")
try:
capabilities = await client.meta_capabilities()
print(capabilities.result.name)
neighbors = await client.graph_neighbors(
node_id="revenue",
scope="parents",
max_neighbors=5,
)
print(neighbors.result.neighbors)
finally:
await client.aclose()
asyncio.run(main())
The client currently provides first-class methods for:
meta.capabilitiesmeta.methodsnarrategraph.neighborsgraph.markov_blanketgraph.pathsobserve.predictintervene.dotraverse.parentstraverse.children
If you need a custom or extension verb, use request_verb(...) or request_route(...).
Quickstart: Expose A CAP Endpoint In FastAPI
from fastapi import FastAPI, Request
from cap.server import (
CAPHandlerSuccessSpec,
CAPProvenanceContext,
CAPProvenanceHint,
CAPVerbRegistry,
GRAPH_NEIGHBORS_CONTRACT,
build_fastapi_cap_dispatcher,
register_cap_exception_handlers,
)
app = FastAPI()
registry = CAPVerbRegistry()
@registry.core(GRAPH_NEIGHBORS_CONTRACT)
async def graph_neighbors(payload, request: Request):
del request
return CAPHandlerSuccessSpec(
result={
"node_id": payload.params.node_id,
"scope": payload.params.scope,
"neighbors": [],
"truncated": False,
"reasoning_mode": "graph_propagation",
"identification_status": "identified",
"assumptions": [],
},
provenance_hint=CAPProvenanceHint(algorithm="handwritten-demo"),
)
async def provenance_context_provider(payload, request: Request) -> CAPProvenanceContext:
del payload, request
return CAPProvenanceContext(
graph_version="dev",
server_name="example-cap-server",
server_version="0.1.0",
)
dispatch = build_fastapi_cap_dispatcher(
registry=registry,
provenance_context_provider=provenance_context_provider,
)
register_cap_exception_handlers(app)
@app.post("/cap")
async def cap_endpoint(payload: dict, request: Request):
return await dispatch(payload, request)
This adapter stays intentionally small. It handles CAP-shaped validation and dispatch, but it does not impose a larger server framework or hide your business logic.
Current Surface Area
The implementation in this repository currently includes:
- typed request and response models for the verbs listed above
- capability-card schema models for
meta.capabilities - canonical constants for reasoning modes, assumptions, mechanism families, and related protocol strings
- an async
httpx-based client with CAP error normalization - a FastAPI registry and dispatcher that validate both inbound requests and outbound responses
Treat this as a minimal SDK surface for the active v0.3.0 release line.
Richer Core Responses
Typed core response models define the canonical minimum fields a client can rely on.
Servers may still return additional result fields beyond those minimums.
The SDK's typed response parsing ignores unknown additive result fields, so a richer provider response does not break a client that only depends on the canonical fields.
For code-level details, use the docs below rather than treating the README as the full API inventory.
Where To Go Next
- CAP docs and specification: protocol overview, getting started, and normative CAP behavior
- docs/api-reference.md: public Python entry points and imports
- docs/architecture.md: package boundaries and request flow
- docs/development.md: local setup, tests, and common change paths
Contributing And Community
Use repo-local docs for repo-specific workflows:
Use the CAP organization docs for shared community policy:
License
This project is licensed under the Apache License 2.0. See 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 cap_protocol-1.0.4.tar.gz.
File metadata
- Download URL: cap_protocol-1.0.4.tar.gz
- Upload date:
- Size: 30.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8dcc0c02b710c8d2246b6b556f86c4309731a309c0a44373b4993e926aa531c
|
|
| MD5 |
84e8024891a759d20dc8a48872da4e00
|
|
| BLAKE2b-256 |
d0f6b1e8db6cb0b67004fe9155feb2968c2c8892dfe932c42ada2f8ee58e79f1
|
Provenance
The following attestation bundles were made for cap_protocol-1.0.4.tar.gz:
Publisher:
release.yml on CausalAgentProtocol/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cap_protocol-1.0.4.tar.gz -
Subject digest:
a8dcc0c02b710c8d2246b6b556f86c4309731a309c0a44373b4993e926aa531c - Sigstore transparency entry: 1261555416
- Sigstore integration time:
-
Permalink:
CausalAgentProtocol/python-sdk@4fdb1d145e4bcc43d1227537df7123374fb98dfa -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/CausalAgentProtocol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4fdb1d145e4bcc43d1227537df7123374fb98dfa -
Trigger Event:
push
-
Statement type:
File details
Details for the file cap_protocol-1.0.4-py3-none-any.whl.
File metadata
- Download URL: cap_protocol-1.0.4-py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f191f85d65eb7d0cbe7399a97a009ed9c463fdf25b758b4e1334c5e92f850ca2
|
|
| MD5 |
ccbf8562923c391420bf6f9aa552e025
|
|
| BLAKE2b-256 |
6c84a463158b54613884196f0a696f686c57ae8d95fa2a07bd60a0bb15826dbe
|
Provenance
The following attestation bundles were made for cap_protocol-1.0.4-py3-none-any.whl:
Publisher:
release.yml on CausalAgentProtocol/python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cap_protocol-1.0.4-py3-none-any.whl -
Subject digest:
f191f85d65eb7d0cbe7399a97a009ed9c463fdf25b758b4e1334c5e92f850ca2 - Sigstore transparency entry: 1261555529
- Sigstore integration time:
-
Permalink:
CausalAgentProtocol/python-sdk@4fdb1d145e4bcc43d1227537df7123374fb98dfa -
Branch / Tag:
refs/tags/v1.0.4 - Owner: https://github.com/CausalAgentProtocol
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@4fdb1d145e4bcc43d1227537df7123374fb98dfa -
Trigger Event:
push
-
Statement type: