Skip to main content

open402

HTTP 402 payment protocol for machine-to-machine commerce — reference implementation in Python

Installation

pip install open402

Zero dependencies — pure Python protocol types, header parsing, and version negotiation.

Usage

Parse a 402 Response

from open402 import X402PaymentChallenge, parse_www_authenticate

# Parse the WWW-Authenticate header from a 402 response
challenge = parse_www_authenticate(
    'x402 chain="solana" token="USDC" amount="0.05" address="SolAddr..."'
)
# challenge.chain == "solana"
# challenge.token == "USDC"
# challenge.amount == "0.05"
# challenge.address == "SolAddr..."

Build an Authorization Header

from open402 import build_authorization

header_value = build_authorization(tx_hash="5abc...def")
# "x402 5abc...def"

Version Negotiation

from open402 import negotiate_version

result = negotiate_version(client_version="v1.0", server_versions=["v1.0", "v0.9"])
# result == "v1.0"

Protocol Flow

Client                                  Server
  │                                       │
  │── GET /api/resource ────────────────▶│
  │                                       │
  │◀── 402 Payment Required ─────────────│
  │    WWW-Authenticate: x402 ...         │
  │                                       │
  │ [Parse challenge → Pay on-chain]      │
  │                                       │
  │── GET /api/resource ────────────────▶│
  │   Authorization: x402 <tx_hash>       │
  │                                       │
  │◀── 200 OK ───────────────────────────│

Compatible with the Coinbase x402 standard.

Part of Ag402

open402 is the protocol layer of the Ag402 project. Use it standalone for protocol parsing, or with ag402-core for the full payment engine.

Metadata

Release files for open402 0.1.20

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for open402 0.1.20
File Size Uploaded Provenance
open402-0.1.20.tar.gz 8.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for open402 0.1.20
File Interpreter ABI Platform
open402-0.1.20-py3-none-any.whl Python 3 none any Details

Total release size: 16.3 kB

Release files / open402-0.1.20.tar.gz

Download URL open402-0.1.20.tar.gz
Size 8.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c94a3f7ab6be33d6024e352b99e0dab24559b950fc33c44d47ef41a14b089cc4
BLAKE2b-256 checksum
How to use checksums
24eda034332ef40ce9068a0c9f9f9d15a54717cef88aa37a5e8f3634565787ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.

Transparency log

Release files / open402-0.1.20-py3-none-any.whl

Download URL open402-0.1.20-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
91c7ed6d709fb25de42dee58495f5489be4f253d0c93d7452cf9aec507b87b63
BLAKE2b-256 checksum
How to use checksums
0a16961d02e7bfdac47a29526caf9a5cf26d78803ee97a808b9aca40621d6272
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.

Transparency log

Security for open402 0.1.20

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for open402-0.1.20.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 15, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page