Skip to content

Commit ba1d7d4

Browse files
committed
Rebuild Python SDK with typed client, verification, docs, and tests
1 parent d910454 commit ba1d7d4

File tree

16 files changed

+902
-271
lines changed

16 files changed

+902
-271
lines changed

python-sdk/README.md

Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,21 @@ Semantic verbs. Signed receipts. Deterministic verification.
44

55
Official Python SDK for **CommandLayer Commons v1.0.0**.
66

7+
---
8+
79
## Installation
810

911
```bash
1012
pip install commandlayer
1113
```
1214

13-
Python 3.10+ is supported.
15+
Python **3.10+** is supported.
16+
17+
For local development:
18+
19+
```bash
20+
pip install -e '.[dev]'
21+
```
1422

1523
---
1624

@@ -33,48 +41,37 @@ print(receipt["status"])
3341
print(receipt["metadata"]["receipt_id"])
3442
```
3543

36-
> `verify_receipts` is **off by default** (matching TypeScript SDK behavior).
44+
> `verify_receipts` is **off by default** (matching the TypeScript SDK behavior).
3745
3846
---
3947

4048
## Client Configuration
4149

4250
```python
43-
client = create_client(
51+
from commandlayer import CommandLayerClient
52+
53+
client = CommandLayerClient(
4454
runtime="https://runtime.commandlayer.org",
4555
actor="my-app",
4656
timeout_ms=30_000,
57+
headers={"X-Trace-ID": "abc123"},
58+
retries=1,
4759
verify_receipts=True,
4860
verify={
4961
"public_key": "ed25519:7Vkkmt6R02Iltp/+i3D5mraZyvLjfuTSVB33KwfzQC8=",
5062
# or ENS:
51-
# "ens": {"name": "runtime.commandlayer.eth", "rpcUrl": "https://..."}
63+
# "ens": {"name": "summarizeagent.eth", "rpcUrl": "https://..."},
5264
},
5365
)
5466
```
5567

5668
### Verification options
57-
- `verify["public_key"]` (alias: `publicKey`): explicit Ed25519 pubkey (`ed25519:<base64>`, `<base64>`, `0x<hex>`, `<hex>`)
58-
- `verify["ens"]`: `{ "name": str, "rpcUrl"|"rpc_url": str, "pubkeyTextKey"|"pubkey_text_key"?: str }`
59-
60-
---
61-
62-
## Supported Verbs
6369

64-
All verbs return a signed receipt.
65-
66-
```python
67-
client.summarize(content="...", style="bullet_points")
68-
client.analyze(content="...", goal="extract key risks")
69-
client.classify(content="...", max_labels=5)
70-
client.clean(content="...", operations=["trim", "normalize_newlines"])
71-
client.convert(content='{"a":1}', from_format="json", to_format="csv")
72-
client.describe(subject="x402 receipt", detail="medium")
73-
client.explain(subject="receipt verification", style="step-by-step")
74-
client.format(content="a: 1\nb: 2", to="table")
75-
client.parse(content='{"a":1}', content_type="json", mode="strict")
76-
client.fetch(source="https://example.com", include_metadata=True)
77-
```
70+
- `verify["public_key"]` (alias: `publicKey`): explicit Ed25519 pubkey
71+
- accepted formats: `ed25519:<base64>`, `<base64>`, `0x<hex>`, `<hex>`
72+
- `verify["ens"]`: `{ "name": str, "rpcUrl"|"rpc_url": str }`
73+
- resolves `cl.receipt.signer` on the agent ENS name
74+
- resolves `cl.sig.pub` and `cl.sig.kid` on the signer ENS name
7875

7976
---
8077

@@ -98,21 +95,51 @@ ENS-based verification:
9895
result = verify_receipt(
9996
receipt,
10097
ens={
101-
"name": "runtime.commandlayer.eth",
98+
"name": "summarizeagent.eth",
10299
"rpcUrl": "https://mainnet.infura.io/v3/YOUR_KEY",
103-
"pubkeyTextKey": "cl.pubkey",
104100
},
105101
)
106102
```
107103

108104
---
109105

106+
## Supported Verbs
107+
108+
All verbs return a signed receipt.
109+
110+
```python
111+
client.summarize(content="...", style="bullet_points")
112+
client.analyze(content="...", goal="extract key risks")
113+
client.classify(content="...", max_labels=5)
114+
client.clean(content="...", operations=["trim", "normalize_newlines"])
115+
client.convert(content='{"a":1}', from_format="json", to_format="csv")
116+
client.describe(subject="x402 receipt", detail="medium")
117+
client.explain(subject="receipt verification", style="step-by-step")
118+
client.format(content="a: 1\nb: 2", to="table")
119+
client.parse(content='{"a":1}', content_type="json", mode="strict")
120+
client.fetch(source="https://example.com", include_metadata=True)
121+
```
122+
123+
---
124+
110125
## Development
111126

112127
```bash
113128
cd python-sdk
114129
python -m venv .venv
115130
source .venv/bin/activate
116131
pip install -e '.[dev]'
132+
ruff check .
133+
mypy commandlayer
117134
pytest
118135
```
136+
137+
---
138+
139+
## Documentation
140+
141+
See `docs/` for usage and API details:
142+
143+
- `docs/getting-started.md`
144+
- `docs/client.md`
145+
- `docs/verification.md`

python-sdk/commandlayer/__init__.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,36 @@
22

33
from .client import CommandLayerClient, create_client
44
from .errors import CommandLayerError
5-
from .types import Receipt, VerifyResult
6-
from .verify import verify_receipt
5+
from .types import (
6+
EnsVerifyOptions,
7+
Receipt,
8+
SignerKeyResolution,
9+
VerifyOptions,
10+
VerifyResult,
11+
)
12+
from .verify import (
13+
canonicalize_stable_json_v1,
14+
parse_ed25519_pubkey,
15+
recompute_receipt_hash_sha256,
16+
resolve_signer_key,
17+
sha256_hex_utf8,
18+
verify_receipt,
19+
)
720

821
__all__ = [
922
"CommandLayerClient",
1023
"create_client",
1124
"CommandLayerError",
25+
"EnsVerifyOptions",
26+
"VerifyOptions",
27+
"SignerKeyResolution",
1228
"Receipt",
1329
"VerifyResult",
30+
"canonicalize_stable_json_v1",
31+
"sha256_hex_utf8",
32+
"parse_ed25519_pubkey",
33+
"recompute_receipt_hash_sha256",
34+
"resolve_signer_key",
1435
"verify_receipt",
1536
]
1637

0 commit comments

Comments
 (0)