x402
x402 Payment Protocol SDK for Python
What it is and what it does
x402 is a Python SDK implementing the x402 payment protocol, a standard for HTTP 402 (Payment Required) responses that bridges web services with blockchain payments. It provides three main roles—client (initiates payments), resource server (enforces payment requirements), and facilitator (settles transactions)—each with async and sync variants. The protocol is transport-agnostic and supports multiple blockchains: EVM networks (Ethereum, Base, etc.), Solana, and TON/TVM.
You use it to add cryptographic payment verification to web services without building blockchain integration from scratch. Register payment schemes for your target networks, define payment requirements (amount, recipient, network), and the SDK handles signature generation, verification, and settlement. It integrates with FastAPI and Flask via middleware, works with httpx or requests for HTTP clients, and auto-detects async vs. sync contexts. The library is young (first release February 2025) but actively maintained and designed for declarative configuration via policies and lifecycle hooks.
Use it for:
- Protect API endpoints with blockchain-backed micropayments (e.g., charge per API call in USDC on Base).
- Build a content delivery service that requires payment in Solana before serving resources.
- Implement a facilitator node that verifies and settles x402 payments across multiple blockchains.
- Add pay-per-use billing to a FastAPI service with EVM wallet signatures.
- Create a cross-chain payment gateway supporting EVM, Solana, and TON in a single codebase.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Implements the x402 payment protocol with transport-agnostic client, server, and facilitator components supporting EVM, Solana, and TON blockchains via both async and sync APIs.
Yes, if you are building a service that needs HTTP 402 payment protocol support with blockchain settlement. The SDK is actively maintained, has low install friction, and covers the major blockchains. However, the Alpha status and recent first release (February 2025) mean the protocol and API may still evolve—use in production only after reviewing the security model and testing thoroughly with your blockchain of choice.
Install
x402 on PyPI
pip
pip install x402uv
uv add x402poetry
poetry add x402Installing x402
Before you install
Low friction: pure Python wheel with only three runtime dependencies (nest-asyncio, pydantic, typing-extensions). Active maintenance—released 3 days ago with 6502 repository stars and continuous commits.
License in practice
MIT license (permissive) places no restrictions on commercial or proprietary use, modification, or distribution.
Quickstart
pip install x402[evm]
from x402 import x402Client
from x402.mechanisms.evm.exact import ExactEvmScheme
client = x402Client()
client.register("eip155:*", ExactEvmScheme(signer=my_signer))
payload = await client.create_payment_payload(payment_required)
Requires Python 3.10+. Optional extras (httpx, requests, fastapi, flask, evm, svm, tvm) must be installed separately depending on your transport and blockchain choice.
Verify before relying
- Whether the protocol is finalized or still evolving (Alpha status suggests ongoing changes).
- Production readiness and security audit status for blockchain payment handling.
- Specific performance characteristics and throughput limits for payment verification.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — nest-asyncio, pydantic, typing-extensions |
| Maintenance | actively maintained — 3 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 180,138/month — #10,153 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: x402-2.19.0-py3-none-any.whl
Keywords: 402, http, payment, protocol, x402
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
traia-iatpAdds HTTP 402 Payment Required protocol support…
unclear · top 15,000 on PyPI
cdp-sdkPython client library for the Coinbase…
permissive · top 15,000 on PyPI
py-evmPy-EVM is a Python implementation of the…
permissive · top 15,000 on PyPI
solanaSolana.py is a Python SDK for building…
permissive · top 5,000 on PyPI
soldersSolders is a high-performance Python toolkit…
unclear · top 5,000 on PyPI
xrpl-pyA pure Python library for building applications…
permissive · top 15,000 on PyPI
pytoniq-core-forkProvides TON Blockchain SDK primitives for…
unclear · top 15,000 on PyPI
eip712Provides Python message classes for EIP-712…
permissive · top 15,000 on PyPI
paypalrestsdkA REST client library for integrating PayPal…
unclear · top 5,000 on PyPI
AdyenProvides official Python bindings for Adyen's…
permissive · top 5,000 on PyPI