Registry / payments / x402
library2.9.0pypypi✓ verified 79d ago

The x402 Python SDK implements the x402 Payment Protocol, enabling micropayments for HTTP resources. Version 2.9.0 supports Python 3.10+ and provides client and server utilities. Active development under the x402-foundation.

pip install x402
INSTALL
IMPORT
SIG · X402
X
x402
paymentspythonv2.9.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FacilitatorClient
from x402 import FacilitatorClient
from x402.client import Client
FacilitatorClientSync
from x402 import FacilitatorClientSync
FacilitatorConfig
from x402 import FacilitatorConfig

Initialize the x402 client and make a paywalled GET request. The private key is read from environment variable; leave empty for demo.

import os from x402.client import Client url = "https://api.example.com/protected" # In production, set X402_PRIVATE_KEY environment variable private_key = os.environ.get('X402_PRIVATE_KEY', '') client = Client(private_key=private_key) try: response = client.get(url) print(response.status_code) print(response.text) except Exception as e: print(f"Error: {e}")
Debug
Known issues
breakingIn version 2.x, the `private_key` parameter is required for Client instantiation. In version 1.x it was optional and a default test key was used. Code without explicit key will break.
fix
Always pass `private_key` to `Client()` or set `X402_PRIVATE_KEY` environment variable.
affects: <=1.x -> >=2.0
breakingThe `PaymentRequest` class was removed in version 2.0. Use `x402.client.prepare_payment()` instead.
fix
Replace `from x402.payment import PaymentRequest` with `from x402.client import prepare_payment`.
affects: <2.0 -> >=2.0
gotchaThe SDK expects the private key in PEM format. Plain hex or raw bytes will raise a `cryptography` error.
fix
Ensure the private key is in PEM format, e.g., read from file like `open('key.pem').read()`.
affects: all
deprecatedMethod `Client.make_payment()` is deprecated since 2.8.0 and will be removed in 3.0. Use `Client.get()` or `Client.post()` directly.
fix
Call `client.get(url)` instead of `client.make_payment('GET', url)`.
affects: >=2.8.0
Upgrade
Version history
2.9.0latest on PyPI · released Apr 27, 2026
Audit
Dependencies
httpxrequiredRequired for HTTP client functionality.
cryptographyrequiredRequired for cryptographic operations.
pydanticrequiredUsed for data validation and settings management.
Agent activity
44 hits · last 30 days
node
38
OpenAI (training)
1
Resources
x402 — pip install x402 · libregistry