cap-protocol 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cap_protocol-0.1.0/PKG-INFO +190 -0
- cap_protocol-0.1.0/README.md +166 -0
- cap_protocol-0.1.0/cap_protocol/__init__.py +6 -0
- cap_protocol-0.1.0/cap_protocol/client/__init__.py +3 -0
- cap_protocol-0.1.0/cap_protocol/client/http.py +377 -0
- cap_protocol-0.1.0/cap_protocol/core/__init__.py +204 -0
- cap_protocol-0.1.0/cap_protocol/core/builders.py +210 -0
- cap_protocol-0.1.0/cap_protocol/core/canonical.py +146 -0
- cap_protocol-0.1.0/cap_protocol/core/capability_card.py +144 -0
- cap_protocol-0.1.0/cap_protocol/core/constants.py +11 -0
- cap_protocol-0.1.0/cap_protocol/core/contracts.py +206 -0
- cap_protocol-0.1.0/cap_protocol/core/disclosure.py +21 -0
- cap_protocol-0.1.0/cap_protocol/core/envelopes.py +83 -0
- cap_protocol-0.1.0/cap_protocol/core/errors.py +47 -0
- cap_protocol-0.1.0/cap_protocol/py.typed +1 -0
- cap_protocol-0.1.0/cap_protocol/server/__init__.py +59 -0
- cap_protocol-0.1.0/cap_protocol/server/contracts.py +99 -0
- cap_protocol-0.1.0/cap_protocol/server/errors.py +120 -0
- cap_protocol-0.1.0/cap_protocol/server/fastapi.py +97 -0
- cap_protocol-0.1.0/cap_protocol/server/registry.py +186 -0
- cap_protocol-0.1.0/cap_protocol/server/responses.py +142 -0
- cap_protocol-0.1.0/cap_protocol.egg-info/PKG-INFO +190 -0
- cap_protocol-0.1.0/cap_protocol.egg-info/SOURCES.txt +27 -0
- cap_protocol-0.1.0/cap_protocol.egg-info/dependency_links.txt +1 -0
- cap_protocol-0.1.0/cap_protocol.egg-info/requires.txt +5 -0
- cap_protocol-0.1.0/cap_protocol.egg-info/top_level.txt +1 -0
- cap_protocol-0.1.0/pyproject.toml +44 -0
- cap_protocol-0.1.0/setup.cfg +4 -0
- cap_protocol-0.1.0/tests/test_public_imports.py +27 -0
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cap-protocol
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK scaffold for the Causal Agent Protocol
|
|
5
|
+
Author: CausalAgentProtocol
|
|
6
|
+
License-Expression: LicenseRef-Proprietary
|
|
7
|
+
Project-URL: Homepage, https://github.com/CausalAgentProtocol/python-sdk
|
|
8
|
+
Project-URL: Repository, https://github.com/CausalAgentProtocol/python-sdk
|
|
9
|
+
Keywords: causal,protocol,sdk,cap,agents
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
Requires-Dist: httpx<1,>=0.24
|
|
21
|
+
Requires-Dist: pydantic<3,>=2
|
|
22
|
+
Provides-Extra: server
|
|
23
|
+
Requires-Dist: fastapi<1,>=0.100; extra == "server"
|
|
24
|
+
|
|
25
|
+
# CAP Python SDK
|
|
26
|
+
|
|
27
|
+
Lightweight Python SDK scaffold for the Causal Agent Protocol (CAP) v0.2.2.
|
|
28
|
+
|
|
29
|
+
This repository currently provides:
|
|
30
|
+
|
|
31
|
+
- Typed CAP request and response models built with Pydantic
|
|
32
|
+
- Builder helpers for common CAP verbs
|
|
33
|
+
- An async HTTP client for CAP servers
|
|
34
|
+
- A small FastAPI adapter for wiring CAP verbs to handlers
|
|
35
|
+
- Capability card models for `meta.capabilities`
|
|
36
|
+
|
|
37
|
+
## Package Layout
|
|
38
|
+
|
|
39
|
+
`cap_protocol/core`
|
|
40
|
+
|
|
41
|
+
- Protocol constants, request/response envelopes, contracts, builders, errors, and capability card models
|
|
42
|
+
|
|
43
|
+
`cap_protocol/client`
|
|
44
|
+
|
|
45
|
+
- `AsyncCAPClient` and route helpers for calling a CAP endpoint
|
|
46
|
+
|
|
47
|
+
`cap_protocol/server`
|
|
48
|
+
|
|
49
|
+
- Verb contracts, registry utilities, FastAPI dispatch adapter, and response/error helpers for implementing a CAP server
|
|
50
|
+
|
|
51
|
+
## Supported Verbs
|
|
52
|
+
|
|
53
|
+
Core verbs included in the SDK:
|
|
54
|
+
|
|
55
|
+
- `meta.capabilities`
|
|
56
|
+
- `graph.neighbors`
|
|
57
|
+
- `graph.markov_blanket`
|
|
58
|
+
- `graph.paths`
|
|
59
|
+
- `observe.predict`
|
|
60
|
+
- `intervene.do`
|
|
61
|
+
|
|
62
|
+
Traversal contracts also included:
|
|
63
|
+
|
|
64
|
+
- `traverse.parents`
|
|
65
|
+
- `traverse.children`
|
|
66
|
+
|
|
67
|
+
## Requirements
|
|
68
|
+
|
|
69
|
+
Install from a local checkout:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
pip install .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Once published to PyPI, the intended install command is:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install cap-protocol
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Base installation includes the core models and async HTTP client. If you also want the FastAPI server adapter, install the optional server extra:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "cap-protocol[server]"
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
The package keeps the import surface you asked for:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from cap_protocol.core import (
|
|
91
|
+
ASSUMPTION_CAUSAL_SUFFICIENCY,
|
|
92
|
+
ASSUMPTION_FAITHFULNESS,
|
|
93
|
+
ASSUMPTION_LINEARITY,
|
|
94
|
+
ASSUMPTION_NO_INSTANTANEOUS_EFFECTS,
|
|
95
|
+
ASSUMPTION_NO_LATENT_CONFOUNDERS_ADDRESSED,
|
|
96
|
+
)
|
|
97
|
+
from cap_protocol.core.disclosure import sanitize_fields
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Client Example
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
import asyncio
|
|
104
|
+
|
|
105
|
+
from cap_protocol.client import AsyncCAPClient
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
async def main() -> None:
|
|
109
|
+
client = AsyncCAPClient("https://example.com")
|
|
110
|
+
try:
|
|
111
|
+
capabilities = await client.meta_capabilities()
|
|
112
|
+
print(capabilities.result.name)
|
|
113
|
+
|
|
114
|
+
neighbors = await client.graph_neighbors(
|
|
115
|
+
node_id="revenue",
|
|
116
|
+
scope="parents",
|
|
117
|
+
max_neighbors=5,
|
|
118
|
+
)
|
|
119
|
+
print(neighbors.result.neighbors)
|
|
120
|
+
finally:
|
|
121
|
+
await client.aclose()
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
asyncio.run(main())
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
You can also call verbs dynamically with `request_verb(...)` or route aliases with `request_route(...)`.
|
|
128
|
+
|
|
129
|
+
## FastAPI Server Example
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from fastapi import FastAPI, Request
|
|
133
|
+
|
|
134
|
+
from cap_protocol.server import (
|
|
135
|
+
GRAPH_NEIGHBORS_CONTRACT,
|
|
136
|
+
CAPVerbRegistry,
|
|
137
|
+
build_fastapi_cap_dispatcher,
|
|
138
|
+
)
|
|
139
|
+
|
|
140
|
+
app = FastAPI()
|
|
141
|
+
registry = CAPVerbRegistry()
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
@registry.core(GRAPH_NEIGHBORS_CONTRACT)
|
|
145
|
+
async def graph_neighbors(payload, request: Request):
|
|
146
|
+
return {
|
|
147
|
+
"request_id": payload.request_id,
|
|
148
|
+
"verb": payload.verb,
|
|
149
|
+
"status": "success",
|
|
150
|
+
"result": {
|
|
151
|
+
"node_id": payload.params.node_id,
|
|
152
|
+
"scope": payload.params.scope,
|
|
153
|
+
"neighbors": [],
|
|
154
|
+
"truncated": False,
|
|
155
|
+
"reasoning_mode": "deterministic",
|
|
156
|
+
"identification_status": "identified",
|
|
157
|
+
"assumptions": [],
|
|
158
|
+
},
|
|
159
|
+
"provenance": {
|
|
160
|
+
"algorithm": "handwritten-demo",
|
|
161
|
+
"graph_version": "dev",
|
|
162
|
+
"computation_time_ms": 1,
|
|
163
|
+
"server_name": "example-cap-server",
|
|
164
|
+
"server_version": "0.1.0",
|
|
165
|
+
"cap_spec_version": "0.2.2",
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
dispatch = build_fastapi_cap_dispatcher(registry=registry)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
@app.post("/api/v1/cap")
|
|
174
|
+
async def cap_endpoint(payload: dict, request: Request):
|
|
175
|
+
return await dispatch(payload, request)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Notes
|
|
179
|
+
|
|
180
|
+
- `CAPClientRoutes` maps all verbs to a single endpoint path by default: `/api/v1/cap`
|
|
181
|
+
- `CAPVerbRegistry` supports core, convenience, and extension verbs
|
|
182
|
+
- `build_fastapi_cap_dispatcher(...)` validates incoming payloads against the registered request models and validates the outgoing response model before returning it
|
|
183
|
+
|
|
184
|
+
## Status
|
|
185
|
+
|
|
186
|
+
This repository is an internal scaffold extracted from a reference implementation and is a good base for:
|
|
187
|
+
|
|
188
|
+
- sharing CAP request and response schemas across services
|
|
189
|
+
- standing up a CAP-compatible FastAPI endpoint
|
|
190
|
+
- building internal client integrations against a CAP server
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# CAP Python SDK
|
|
2
|
+
|
|
3
|
+
Lightweight Python SDK scaffold for the Causal Agent Protocol (CAP) v0.2.2.
|
|
4
|
+
|
|
5
|
+
This repository currently provides:
|
|
6
|
+
|
|
7
|
+
- Typed CAP request and response models built with Pydantic
|
|
8
|
+
- Builder helpers for common CAP verbs
|
|
9
|
+
- An async HTTP client for CAP servers
|
|
10
|
+
- A small FastAPI adapter for wiring CAP verbs to handlers
|
|
11
|
+
- Capability card models for `meta.capabilities`
|
|
12
|
+
|
|
13
|
+
## Package Layout
|
|
14
|
+
|
|
15
|
+
`cap_protocol/core`
|
|
16
|
+
|
|
17
|
+
- Protocol constants, request/response envelopes, contracts, builders, errors, and capability card models
|
|
18
|
+
|
|
19
|
+
`cap_protocol/client`
|
|
20
|
+
|
|
21
|
+
- `AsyncCAPClient` and route helpers for calling a CAP endpoint
|
|
22
|
+
|
|
23
|
+
`cap_protocol/server`
|
|
24
|
+
|
|
25
|
+
- Verb contracts, registry utilities, FastAPI dispatch adapter, and response/error helpers for implementing a CAP server
|
|
26
|
+
|
|
27
|
+
## Supported Verbs
|
|
28
|
+
|
|
29
|
+
Core verbs included in the SDK:
|
|
30
|
+
|
|
31
|
+
- `meta.capabilities`
|
|
32
|
+
- `graph.neighbors`
|
|
33
|
+
- `graph.markov_blanket`
|
|
34
|
+
- `graph.paths`
|
|
35
|
+
- `observe.predict`
|
|
36
|
+
- `intervene.do`
|
|
37
|
+
|
|
38
|
+
Traversal contracts also included:
|
|
39
|
+
|
|
40
|
+
- `traverse.parents`
|
|
41
|
+
- `traverse.children`
|
|
42
|
+
|
|
43
|
+
## Requirements
|
|
44
|
+
|
|
45
|
+
Install from a local checkout:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Once published to PyPI, the intended install command is:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
pip install cap-protocol
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Base installation includes the core models and async HTTP client. If you also want the FastAPI server adapter, install the optional server extra:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
pip install "cap-protocol[server]"
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The package keeps the import surface you asked for:
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from cap_protocol.core import (
|
|
67
|
+
ASSUMPTION_CAUSAL_SUFFICIENCY,
|
|
68
|
+
ASSUMPTION_FAITHFULNESS,
|
|
69
|
+
ASSUMPTION_LINEARITY,
|
|
70
|
+
ASSUMPTION_NO_INSTANTANEOUS_EFFECTS,
|
|
71
|
+
ASSUMPTION_NO_LATENT_CONFOUNDERS_ADDRESSED,
|
|
72
|
+
)
|
|
73
|
+
from cap_protocol.core.disclosure import sanitize_fields
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Client Example
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import asyncio
|
|
80
|
+
|
|
81
|
+
from cap_protocol.client import AsyncCAPClient
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
async def main() -> None:
|
|
85
|
+
client = AsyncCAPClient("https://example.com")
|
|
86
|
+
try:
|
|
87
|
+
capabilities = await client.meta_capabilities()
|
|
88
|
+
print(capabilities.result.name)
|
|
89
|
+
|
|
90
|
+
neighbors = await client.graph_neighbors(
|
|
91
|
+
node_id="revenue",
|
|
92
|
+
scope="parents",
|
|
93
|
+
max_neighbors=5,
|
|
94
|
+
)
|
|
95
|
+
print(neighbors.result.neighbors)
|
|
96
|
+
finally:
|
|
97
|
+
await client.aclose()
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
asyncio.run(main())
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
You can also call verbs dynamically with `request_verb(...)` or route aliases with `request_route(...)`.
|
|
104
|
+
|
|
105
|
+
## FastAPI Server Example
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from fastapi import FastAPI, Request
|
|
109
|
+
|
|
110
|
+
from cap_protocol.server import (
|
|
111
|
+
GRAPH_NEIGHBORS_CONTRACT,
|
|
112
|
+
CAPVerbRegistry,
|
|
113
|
+
build_fastapi_cap_dispatcher,
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
app = FastAPI()
|
|
117
|
+
registry = CAPVerbRegistry()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
@registry.core(GRAPH_NEIGHBORS_CONTRACT)
|
|
121
|
+
async def graph_neighbors(payload, request: Request):
|
|
122
|
+
return {
|
|
123
|
+
"request_id": payload.request_id,
|
|
124
|
+
"verb": payload.verb,
|
|
125
|
+
"status": "success",
|
|
126
|
+
"result": {
|
|
127
|
+
"node_id": payload.params.node_id,
|
|
128
|
+
"scope": payload.params.scope,
|
|
129
|
+
"neighbors": [],
|
|
130
|
+
"truncated": False,
|
|
131
|
+
"reasoning_mode": "deterministic",
|
|
132
|
+
"identification_status": "identified",
|
|
133
|
+
"assumptions": [],
|
|
134
|
+
},
|
|
135
|
+
"provenance": {
|
|
136
|
+
"algorithm": "handwritten-demo",
|
|
137
|
+
"graph_version": "dev",
|
|
138
|
+
"computation_time_ms": 1,
|
|
139
|
+
"server_name": "example-cap-server",
|
|
140
|
+
"server_version": "0.1.0",
|
|
141
|
+
"cap_spec_version": "0.2.2",
|
|
142
|
+
},
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
dispatch = build_fastapi_cap_dispatcher(registry=registry)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
@app.post("/api/v1/cap")
|
|
150
|
+
async def cap_endpoint(payload: dict, request: Request):
|
|
151
|
+
return await dispatch(payload, request)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
## Notes
|
|
155
|
+
|
|
156
|
+
- `CAPClientRoutes` maps all verbs to a single endpoint path by default: `/api/v1/cap`
|
|
157
|
+
- `CAPVerbRegistry` supports core, convenience, and extension verbs
|
|
158
|
+
- `build_fastapi_cap_dispatcher(...)` validates incoming payloads against the registered request models and validates the outgoing response model before returning it
|
|
159
|
+
|
|
160
|
+
## Status
|
|
161
|
+
|
|
162
|
+
This repository is an internal scaffold extracted from a reference implementation and is a good base for:
|
|
163
|
+
|
|
164
|
+
- sharing CAP request and response schemas across services
|
|
165
|
+
- standing up a CAP-compatible FastAPI endpoint
|
|
166
|
+
- building internal client integrations against a CAP server
|