Skip to main content

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

  1. Read + decode the PAYMENT-REQUIRED envelope
  2. Check the spend budget (daily / per-request limits, in whole tokens)
  3. Sign the canonical envelope bytes with the agent's ed25519 key
  4. Retry with PAYMENT-REQUIRED (original bytes), PAYMENT-SIGNATURE, and X-FOUROTWO-DID headers
  5. 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.

Metadata

Release files for fourotwo-agent-sdk 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fourotwo-agent-sdk 1.0.0
File Size Uploaded Provenance Actions
fourotwo_agent_sdk-1.0.0.tar.gz 10.8 kB Without provenance Details for fourotwo_agent_sdk-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fourotwo-agent-sdk 1.0.0
File Interpreter ABI Platform Actions
fourotwo_agent_sdk-1.0.0-py3-none-any.whl Python 3 none any Details for fourotwo_agent_sdk-1.0.0-py3-none-any.whl

Total release size: 21.7 kB

Release files / fourotwo_agent_sdk-1.0.0.tar.gz

Download URL fourotwo_agent_sdk-1.0.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ff87b4af0265b15fdcf925a9de8cbe6fdfa2484b3423e8c106f43bba7bf297bc
BLAKE2b-256 checksum
How to use checksums
b1e40feff7b92bc6380bbb92c4c1ee55d359cfb2cd8a404a5ca3ab90d8c9f65a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Release files / fourotwo_agent_sdk-1.0.0-py3-none-any.whl

Download URL fourotwo_agent_sdk-1.0.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9b96a50756b8d91a2d9b3b922c73ef3bbd2cf34d3bdd8a515c5c5a1f5b17c1e4
BLAKE2b-256 checksum
How to use checksums
cb5d740c07ce35c5a77e04387fc3375617ca9e4edd057c107fe98d305b7ddfd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.4

Security for fourotwo-agent-sdk 1.0.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page