SDKsPythonOverview

Python SDK

The T402 Python SDK provides comprehensive support for HTTP-native stablecoin payments with multi-chain support.

Installation

pip install t402

Or with optional dependencies:

pip install t402[svm]     # Solana support
pip install t402[all]     # All optional dependencies

Features

FeatureStatus
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

ModuleDescription
t402Core types and utilities
t402.tonTON blockchain support
t402.tronTRON blockchain support
t402.nearNEAR Protocol support
t402.aptosAptos blockchain support
t402.tezosTezos blockchain support
t402.polkadotPolkadot Asset Hub support
t402.stacksStacks (Bitcoin L2) support
t402.cosmosCosmos/Noble support
t402.erc4337ERC-4337 account abstraction
t402.bridgeUSDT0 cross-chain bridge
t402.wdkTether WDK integration
t402.fastapiFastAPI middleware
t402.flaskFlask middleware
t402.djangoDjango middleware
t402.starletteStarlette middleware
t402.clients.httpxhttpx client adapter
t402.clients.requestsrequests adapter

Module Structure

    • __init__.py
      • httpx.py
      • requests.py

Documentation

Requirements

  • Python 3.10+
  • pip or uv package manager