x402 in Python: call a paid API with the 2sio SDK

The 2sio Python SDK handles the entire x402 probe → sign → retry loop, so calling a paid API is one method call. Here is the whole thing.

Install and call

Install the SDK, put an EVM wallet key in your environment, and call any endpoint. The SDK probes, signs the USDC payment, retries, and returns the data:

Python — 2siopython
# pip install 2sio
import os
from twosio import TwoS

client = TwoS(private_key=os.environ["EVM_PRIVATE_KEY"])

res = client.weather.zip(zip="94103")
print(res.data)        # real forecast
print(res.cost_usd)    # USDC charged
print((res.settlement or {}).get("tx_hash"))

Try before you pay

Pass trial=True to make a free real call (one per endpoint per hour) — handy in tests or to verify a response shape before funding a wallet:

Python — trial modepython
from twosio import TwoS

# No key, no wallet needed for a trial call:
client = TwoS(trial=True)
res = client.validate.iban(iban="GB82WEST12345698765432")
print(res.data)  # real validation result, marked meta.trial

Paying on Solana

To settle on Solana instead of Base, install the Solana extra and pass a Solana key. Same method calls, different rail:

Python — Solana extrabash
pip install "2sio[svm]"

Call a live x402 API right now — no signup.

Browse the full endpoint directory, grab the quickstart, or read the llms.txt manifest. Every endpoint is keyless and pay-per-call.

FAQ

How do I call an x402 API in Python?
Install the 2sio package, construct TwoS(private_key=...) with an EVM wallet key, and call any endpoint method (e.g. client.weather.zip(zip="94103")). The SDK handles the 402 payment flow for you.
Can I test without a wallet in Python?
Yes — construct TwoS(trial=True) and you get one free real call per endpoint per hour, no key or payment required.
Does the Python SDK support Solana payments?
Yes. Install the 2sio[svm] extra and provide a Solana wallet key to settle in USDC on Solana instead of Base.

Related

Topics: x402 python · x402 python example · x402 python tutorial · python x402 client · pay per call api python