skillfed

x402

x402 Payment Protocol SDK for Python

x402 v2.19.0 180.1K downloads/30d#10,153 on PyPI6,502
Permissive license MIT Active released

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 x402

uv

uv add x402

poetry

poetry add x402

Installing 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

Development Status :: 3 - AlphaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Typing :: Typed

Tags

http 402 payment protocolblockchain payment sdkevm solana ton paymentsasync payment client serverx402 protocol implementation
blockchain-paymentshttp-402-protocolasync-sync-dual

More WWW/HTTP packages