{"id":27557,"library":"x402","title":"x402 Payment Protocol SDK","description":"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.","status":"active","version":"2.9.0","language":"python","source_language":"en","source_url":"https://github.com/x402-foundation/x402","tags":["x402","payment-protocol","micropayments","sdk","python3"],"install":[{"cmd":"pip install x402","lang":"bash","label":"Install x402 SDK"}],"dependencies":[{"reason":"Required for HTTP client functionality.","package":"httpx","optional":false},{"reason":"Required for cryptographic operations.","package":"cryptography","optional":false},{"reason":"Used for data validation and settings management.","package":"pydantic","optional":false}],"imports":[{"wrong":"from x402.client import Client","symbol":"FacilitatorClient","correct":"from x402 import FacilitatorClient"},{"symbol":"FacilitatorClientSync","correct":"from x402 import FacilitatorClientSync"},{"symbol":"FacilitatorConfig","correct":"from x402 import FacilitatorConfig"}],"quickstart":{"code":"import os\nfrom x402.client import Client\n\nurl = \"https://api.example.com/protected\"\n# In production, set X402_PRIVATE_KEY environment variable\nprivate_key = os.environ.get('X402_PRIVATE_KEY', '')\nclient = Client(private_key=private_key)\ntry:\n    response = client.get(url)\n    print(response.status_code)\n    print(response.text)\nexcept Exception as e:\n    print(f\"Error: {e}\")","lang":"python","description":"Initialize the x402 client and make a paywalled GET request. The private key is read from environment variable; leave empty for demo."},"warnings":[{"fix":"Always pass `private_key` to `Client()` or set `X402_PRIVATE_KEY` environment variable.","message":"In 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.","severity":"breaking","affected_versions":"<=1.x -> >=2.0"},{"fix":"Replace `from x402.payment import PaymentRequest` with `from x402.client import prepare_payment`.","message":"The `PaymentRequest` class was removed in version 2.0. Use `x402.client.prepare_payment()` instead.","severity":"breaking","affected_versions":"<2.0 -> >=2.0"},{"fix":"Ensure the private key is in PEM format, e.g., read from file like `open('key.pem').read()`.","message":"The SDK expects the private key in PEM format. Plain hex or raw bytes will raise a `cryptography` error.","severity":"gotcha","affected_versions":"all"},{"fix":"Call `client.get(url)` instead of `client.make_payment('GET', url)`.","message":"Method `Client.make_payment()` is deprecated since 2.8.0 and will be removed in 3.0. Use `Client.get()` or `Client.post()` directly.","severity":"deprecated","affected_versions":">=2.8.0"}],"env_vars":null,"search_vec":"'2.9.0':20 '3.10':23 'activ':30 'client':26 'develop':31 'enabl':14 'foundat':36 'http':17 'implement':9 'micropay':15,41 'payment':2,12,39 'payment-protocol':38 'protocol':3,13,40 'provid':25 'python':7,22 'python3':43 'resourc':18 'sdk':4,8,42 'server':28 'support':21 'util':29 'version':19 'x402':1,6,11,35,37 'x402-foundation':34","created_at":"2026-05-01T17:46:53.146759+00:00","updated_at":"2026-05-01T17:46:53.146759+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":"https://x402.org","github":"https://github.com/x402-foundation/x402","docs":"https://x402.org","changelog":null,"pypi":"https://pypi.org/project/x402/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["payments","http-networking","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}