Python SDK for Route402 - USDC payments for AI agents
Project description
Route402 Python SDK
Python SDK for Route402 - USDC payment infrastructure for AI agents on Base blockchain.
Installation
pip install route402
Quick Start
from route402 import Route402Client
# Initialize client
client = Route402Client(api_key="apk_your_key_here")
# Create payment
payment = client.create_payment(
seller="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
amount="0.05", # 0.05 USDC
reference="order-123"
)
print(f"Payment ID: {payment.id}")
print(f"Status: {payment.status}")
print(f"Amount: {payment.amount} USDC")
print(f"Fee: {payment.fee_amount} USDC")
print(f"Net: {payment.net_amount} USDC")
Features
- ✅ Create and manage USDC payments
- ✅ Check payment status
- ✅ Export transactions as CSV (for accounting)
- ✅ Type-safe with dataclasses
- ✅ Built-in error handling
- ✅ Supports Base mainnet
Usage
Initialize Client
from route402 import Route402Client
client = Route402Client(
api_key="apk_your_key_here",
api_url="https://api.route402.com" # Optional, uses default
)
Create Payment
payment = client.create_payment(
seller="0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
amount="0.10",
chain_id=8453, # Base mainnet (default)
reference="invoice-456" # Optional
)
# Check status
if payment.is_confirmed:
print("Payment confirmed!")
Get Payment Status
payment = client.get_payment("pay_abc123")
print(f"Status: {payment.status}")
print(f"Confirmed: {payment.is_confirmed}")
print(f"TX Hash: {payment.tx_hash}")
List Payments
# Get all payments
payments = client.list_payments(limit=10)
# Filter by status
from route402 import PaymentStatus
confirmed = client.list_payments(
status=PaymentStatus.CONFIRMED,
limit=100
)
for payment in confirmed:
print(f"{payment.id}: {payment.amount} USDC")
Export CSV for Accounting
# Export all payments
csv_data = client.export_payments_csv()
# Export with filters
csv_data = client.export_payments_csv(
start_date="2025-01-01",
end_date="2025-12-31",
status=PaymentStatus.CONFIRMED
)
# Save to file
with open("transactions.csv", "w") as f:
f.write(csv_data)
Check Supported Chains
chains = client.get_chains()
for chain in chains:
print(f"{chain['name']} (ID: {chain['chainId']})")
print(f"Router: {chain['router']}")
print(f"USDC: {chain['usdc']}")
Error Handling
from route402 import Route402Client, APIError, PaymentError, ValidationError
client = Route402Client(api_key="apk_xxx")
try:
payment = client.create_payment(
seller="0x123...",
amount="0.05"
)
except ValidationError as e:
print(f"Invalid input: {e}")
except APIError as e:
print(f"API error ({e.status_code}): {e.message}")
except PaymentError as e:
print(f"Payment failed: {e}")
Types
Payment
@dataclass
class Payment:
id: str
chain_id: int
buyer: str
seller: str
amount: str
fee_bps: int
tx_hash: Optional[str]
status: PaymentStatus
reference: Optional[str]
created_at: datetime
confirmed_at: Optional[datetime]
# Computed properties
@property
def fee_amount(self) -> float:
"""Fee amount in USDC"""
@property
def net_amount(self) -> float:
"""Net amount after fee"""
@property
def is_confirmed(self) -> bool:
"""Is payment confirmed"""
@property
def is_pending(self) -> bool:
"""Is payment pending"""
PaymentStatus
class PaymentStatus(str, Enum):
PENDING = "PENDING"
BROADCASTED = "BROADCASTED"
MINED = "MINED"
CONFIRMED = "CONFIRMED"
FAILED = "FAILED"
Chain
class Chain(int, Enum):
BASE = 8453
POLYGON_AMOY = 80002 # Testnet
Requirements
- Python 3.8+
requests>=2.31.0eth-account>=0.10.0web3>=6.0.0
Links
- Website: https://route402.com
- Documentation: https://docs.route402.com
- API Reference: https://docs.route402.com/api
- GitHub: https://github.com/route402/route402
- Support: hello@route402.com
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
route402-0.1.0.tar.gz
(11.4 kB
view details)
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 route402-0.1.0.tar.gz.
File metadata
- Download URL: route402-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d370f09fa7931ce5817c5f22892019745a1194a37c2c1c3ed0661d0bf6867b6c
|
|
| MD5 |
1f88dfa5ea4d225c68867e853549968f
|
|
| BLAKE2b-256 |
4a1f74a5921b6aaea517d872401073664c3143eb0e1220445e8cb67e8cf04830
|
File details
Details for the file route402-0.1.0-py3-none-any.whl.
File metadata
- Download URL: route402-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5dac54f17e8e9c3318751db6d0f718dee9c5211dca3fde41e060df192bd1849
|
|
| MD5 |
21f0a486f37c2fa83655db3d685f51d2
|
|
| BLAKE2b-256 |
f346b7d409b1eaec03b7834c14c70241f2ab491dcb4edd4d8f54656b157387f9
|