Skip to main content

FastAPI middleware for x402 payments -- consumer and provider

Project description

payskill-fastapi

FastAPI middleware for x402 payments — both consumer and provider sides.

Install

pip install payskill-fastapi

Provider — Gate a route behind an x402 paywall

from fastapi import FastAPI, Depends
from payskill_fastapi import require_payment, PaymentInfo

app = FastAPI()

@app.get("/api/data")
async def get_data(
    payment: PaymentInfo = Depends(
        require_payment(
            price=0.01,
            settlement="tab",
            provider_address="0x...",
        )
    ),
):
    return {"data": "premium", "paid_by": payment.from_address}

Consumer — Auto-pay outbound x402 calls

from fastapi import FastAPI, Request
from payskill import Wallet
from payskill_fastapi import PayMiddleware

app = FastAPI()
wallet = Wallet()

app.add_middleware(PayMiddleware, wallet=wallet, max_per_request=1.00)

@app.get("/forecast")
async def forecast(request: Request):
    resp = request.state.pay.fetch("https://api.example.com/forecast")
    return resp.json()

License

MIT

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

payskill_fastapi-0.1.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

payskill_fastapi-0.1.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for payskill_fastapi-0.1.0.tar.gz
Algorithm Hash digest
SHA256 67d9080fd9c8f4a0b0d584201dd8c813e90d5256b214832ba97a1b44690b944a
MD5 95a15b9892afa102f6acd48bd4caf171
BLAKE2b-256 597987b62075bf47682cae52a8db7119e71083f673c111f24fd50f05a5a36885

See more details on using hashes here.

Provenance

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

Publisher: release.yml on pay-skill/pay-sdk

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

File details

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

File metadata

File hashes

Hashes for payskill_fastapi-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc8dfa72aaa95f9b4cf5fe399df4514827b022eca1ca59599418ddd5a34e184a
MD5 0b3dd7ab663cfa6cff4a29f529e1ce9d
BLAKE2b-256 0a0c10f274bb179b12a23baef160a6baf5467a7fb8fac443c18de955eeac7268

See more details on using hashes here.

Provenance

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

Publisher: release.yml on pay-skill/pay-sdk

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