phdargen 9a718b002d
Fix py publishing (#2295)
* fix uv build

* exclude-newer = 3 days
2026-05-13 22:37:58 +02:00
..
2026-05-13 22:37:58 +02:00
2026-05-13 22:37:58 +02:00
2026-05-13 22:37:58 +02:00
2026-05-13 22:37:58 +02:00
2026-05-13 22:37:58 +02:00
2026-05-13 22:37:58 +02:00

x402 Python v2 Client Examples

This directory contains examples demonstrating how to use the x402 v2 SDK with different Python HTTP clients.

Available Examples

Directory HTTP Client Pattern
httpx/ httpx Async
requests/ requests Sync

Quick Start

  1. Choose an HTTP client (httpx for async, requests for sync)
  2. Navigate to the example directory
  3. Follow the setup instructions in the README

httpx (Async)

cd httpx
cp .env-local .env
# Edit .env with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY
uv sync
uv run python main.py

requests (Sync)

cd requests
cp .env-local .env
# Edit .env with your EVM_PRIVATE_KEY and/or SVM_PRIVATE_KEY
uv sync
uv run python main.py

Features Demonstrated

  • Automatic 402 handling - Payment handling is transparent to your code
  • EVM payments - Uses EthAccountSigner with register_exact_evm_client
  • Payment response extraction - Shows how to decode settlement confirmations
  • Environment validation - Checks for required configuration

Architecture

Both examples follow the same pattern:

from x402 import x402Client
from x402.mechanisms.evm.exact.register import register_exact_evm_client
from x402.mechanisms.evm.signers import EthAccountSigner

# 1. Create account
account = Account.from_key(private_key)

# 2. Create x402 client
client = x402Client()

# 3. Register EVM payment scheme
register_exact_evm_client(client, EthAccountSigner(account))

# 4. Use with your preferred HTTP client
# ... httpx or requests ...

Learn More