fourotwo-agent-sdk (Python)
Python SDK for automatic layer402 payment handling — the Python twin of
@fourotwo/agent-sdk. Same DID derivation, same canonical
envelope signing, so a Python agent is verified by the same facilitator with
no server-side changes.
Install
pip install ./packages/agent-sdk-py # from the monorepo
# or once published:
pip install fourotwo-agent-sdk
Requires Python ≥ 3.9. Dependencies: cryptography (ed25519), httpx.
Usage
import os
from fourotwo import FourotwoAgent, SpendBudget
agent = FourotwoAgent(
private_key_hex=os.environ["FOUROTWO_PRIVATE_KEY"], # 32-byte ed25519 seed, hex
budget=SpendBudget(daily_tokens=10.0, per_request_tokens=0.5), # whole tokens
)
# 402s are handled automatically: decode terms -> budget check -> sign -> retry
response = agent.get("https://meridian-fa2d.onrender.com/api/assets/RE-NYC-001")
data = response.json()
# httpx-session style also works
with agent.session() as s:
data = s.get("https://meridian-fa2d.onrender.com/api/assets/RE-NYC-001").json()
print(agent.did) # did:fourotwo:casper:<account-hash>
print(agent.get_transaction_log()) # local spend ledger
What happens on a 402
- Read + decode the
PAYMENT-REQUIREDenvelope - Check the spend budget (daily / per-request limits, in whole tokens)
- Sign the canonical envelope bytes with the agent's ed25519 key
- Retry with
PAYMENT-REQUIRED(original bytes),PAYMENT-SIGNATURE, andX-FOUROTWO-DIDheaders - Log the result to the local ledger
Keys
from fourotwo import generate_casper_keypair, keypair_from_private_key
kp = generate_casper_keypair() # ephemeral (unfunded) key for dry runs
kp = keypair_from_private_key("<64-char hex seed>")
kp.did, kp.tagged_public_key_hex # 01-tagged Casper ed25519 public key
Only ed25519 keys are supported — fourotwo signs and verifies with ed25519.
Tests
python -m pytest packages/agent-sdk-py/tests
tests/vectors.json is generated from the TypeScript SDK
(node packages/agent-sdk-py/tests/generate-vectors.mjs after turbo build),
so the suite proves both SDKs produce byte-identical DIDs, canonical messages,
and signatures.
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 fourotwo_agent_sdk-1.0.0.tar.gz.
File metadata
- Download URL: fourotwo_agent_sdk-1.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff87b4af0265b15fdcf925a9de8cbe6fdfa2484b3423e8c106f43bba7bf297bc
|
|
| MD5 |
e0bfaac0500300d4bd456ef2e77b907f
|
|
| BLAKE2b-256 |
b1e40feff7b92bc6380bbb92c4c1ee55d359cfb2cd8a404a5ca3ab90d8c9f65a
|
File details
Details for the file fourotwo_agent_sdk-1.0.0-py3-none-any.whl.
File metadata
- Download URL: fourotwo_agent_sdk-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b96a50756b8d91a2d9b3b922c73ef3bbd2cf34d3bdd8a515c5c5a1f5b17c1e4
|
|
| MD5 |
f6a87013d15c2e48628bde5f2e398dd4
|
|
| BLAKE2b-256 |
cb5d740c07ce35c5a77e04387fc3375617ca9e4edd057c107fe98d305b7ddfd8
|