Skip to main content

ASGI middleware for XRPL-backed x402 API payments

Project description

xrpl-x402-middleware

xrpl-x402-middleware protects ASGI and FastAPI routes with exact XRPL x402 payments.

Install

pip install xrpl-x402-middleware

Optional Coinbase Python x402 interop:

pip install "xrpl-x402-middleware[x402]"

Quick Start

from fastapi import FastAPI, Request

from xrpl_x402_middleware import PaymentMiddlewareASGI, require_payment

app = FastAPI()
app.add_middleware(
    PaymentMiddlewareASGI,
    route_configs={
        "GET /premium": require_payment(
            facilitator_url="http://127.0.0.1:8000",
            bearer_token="replace-with-your-token",
            pay_to="rPT1Sjq2YGrBMTttX4GZHjKu9dyfzbpAYe",
            network="xrpl:1",
            xrp_drops=1000,
            description="One premium request",
        )
    },
)

@app.get("/premium")
async def premium(request: Request) -> dict[str, str]:
    payment = request.state.x402_payment
    return {"payer": payment.payer, "tx_hash": payment.tx_hash}

Public API

  • PaymentMiddlewareASGI
  • require_payment(...)
  • XRPLFacilitatorClient
  • Optional adapters under xrpl_x402_middleware.adapters.x402

Compatibility

  • Python 3.12
  • Depends on xrpl-x402-core
  • Optional adapter extra pins x402==2.3.0
  • Examples target xrpl:1; mainnet usage uses xrpl:0

Provenance

The implementation is independently developed for the open x402 protocol and does not copy x402-xrpl.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xrpl_x402_middleware-0.1.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xrpl_x402_middleware-0.1.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file xrpl_x402_middleware-0.1.0.tar.gz.

File metadata

  • Download URL: xrpl_x402_middleware-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for xrpl_x402_middleware-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a81256497f2206cd41b007769cd1af54b22c86adcb005f5c91ca7af25c08e4d
MD5 8f3f0fcdb4aadb564537cc53f33835fb
BLAKE2b-256 9a4fbe97db0b51c8e1e56028fd3603f5df5d51a471e84083d3f8457cc76c2d63

See more details on using hashes here.

Provenance

The following attestation bundles were made for xrpl_x402_middleware-0.1.0.tar.gz:

Publisher: publish-package.yml on lgcarrier/xrpl-x402-stack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xrpl_x402_middleware-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for xrpl_x402_middleware-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20ddd8a19e70a030f1cbdb6532b2c8e65e3a71542b04a3b6e3160a7e14a9d5db
MD5 ed9a4b36bdf4124f28dc88feaadade3b
BLAKE2b-256 46a99df022cf3392c45cd903a9a625a5b4fc95e4d70096933f7c8fb6498164d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for xrpl_x402_middleware-0.1.0-py3-none-any.whl:

Publisher: publish-package.yml on lgcarrier/xrpl-x402-stack

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page