Python SDK
The T402 Python SDK provides comprehensive support for HTTP-native stablecoin payments with multi-chain support.
Installation
pip install t402Or with optional dependencies:
pip install t402[svm] # Solana support
pip install t402[all] # All optional dependenciesFeatures
| Feature | Status |
|---|---|
| Core Types & Utilities | ✅ |
| Server Middleware (FastAPI, Flask, Django, Starlette) | ✅ |
| Client Libraries (httpx, requests) | ✅ |
| Multi-Chain Support (EVM, Solana, TON, TRON, NEAR, Aptos, Tezos, Polkadot, Stacks, Cosmos) | ✅ |
| ERC-4337 Account Abstraction | ✅ |
| USDT0 Cross-Chain Bridge | ✅ |
| WDK Integration | ✅ |
| Facilitator Client | ✅ |
Quick Start
Server (FastAPI)
from fastapi import FastAPI
from t402.fastapi.middleware import require_payment
app = FastAPI()
app.middleware("http")(
require_payment(
price="0.01",
pay_to_address="0x209693Bc6afc0C5328bA36FaF03C514EF312287C"
)
)
@app.get("/")
async def root():
return {"message": "Premium content!"}Client (httpx)
from eth_account import Account
from t402.clients.httpx import t402HttpxClient
account = Account.from_key("your_private_key")
async with t402HttpxClient(account=account) as client:
response = await client.get("https://api.example.com/protected")
print(await response.aread())Modules
| Module | Description |
|---|---|
t402 | Core types and utilities |
t402.ton | TON blockchain support |
t402.tron | TRON blockchain support |
t402.near | NEAR Protocol support |
t402.aptos | Aptos blockchain support |
t402.tezos | Tezos blockchain support |
t402.polkadot | Polkadot Asset Hub support |
t402.stacks | Stacks (Bitcoin L2) support |
t402.cosmos | Cosmos/Noble support |
t402.erc4337 | ERC-4337 account abstraction |
t402.bridge | USDT0 cross-chain bridge |
t402.wdk | Tether WDK integration |
t402.fastapi | FastAPI middleware |
t402.flask | Flask middleware |
t402.django | Django middleware |
t402.starlette | Starlette middleware |
t402.clients.httpx | httpx client adapter |
t402.clients.requests | requests adapter |
Module Structure
- __init__.py
- httpx.py
- requests.py
Documentation
Requirements
- Python 3.10+
- pip or uv package manager