Python SDK
Gate any HTTP route for stablecoin payments with solana-pay-kit — one package, FastAPI / Flask / Django shims over a framework-agnostic core.
solana-pay-kit (the solana_pay_kit package) is stablecoin payment gating for HTTP services in Python. Pick a currency, give it your wallet address, and gate a route in two lines — an unpaid request gets a 402 Payment Required advertising both x402 and MPP, and the client settles with either. FastAPI, Flask, and Django ride on a framework-agnostic core.
Install
pip install "solana-pay-kit[flask]" # or [fastapi] / [django]The base install carries no web-framework dependency; the framework shims live in optional extras imported on demand.
Quick start
Configure and gate a route
solana_pay_kit.configure(...) builds the process-wide config once at boot. With no operator it uses a published demo signer and the Surfpool sandbox — enough to run locally. @require_payment(gate) answers a 402 when no valid proof was sent, or runs the view when one was.
import solana_pay_kit
from flask import Flask, jsonify
from solana_pay_kit import Gate, usd
from solana_pay_kit.flask import payment, require_paymentsolana_pay_kit.configure(network="solana_localnet")gate = Gate.build( name="quote", amount=usd("0.01"), description="Stock quote", default_pay_to=solana_pay_kit.config().effective_recipient(), accept_default=solana_pay_kit.config().accept,)app = Flask(__name__)# @require_payment settles the 402 (MPP or x402, the client's choice) before# the view runs; the verified proof is readable via solana_pay_kit.flask.payment().@app.get("/quote")@require_payment(gate)def quote(): return jsonify(ok=True, protocol=payment().protocol.value)Run it
python app.pyMake a paid call
Hit the route with the pay CLI — it walks the user through approval and pays in USDC:
pay curl http://127.0.0.1:8000/quoteThe same surface works in FastAPI and Django — see Frameworks.
Python also ships the paying side for x402. x402_async_client returns an httpx.AsyncClient that turns any 402 into a signed PAYMENT-SIGNATURE payment and replays the request:
from solana_pay_kit import Signer
from solana_pay_kit.protocols.x402.client import SolanaRpc, x402_async_client# x402_async_client returns an httpx.AsyncClient that turns any 402 into a# signed PAYMENT-SIGNATURE payment and replays the request — transparently.async with x402_async_client(signer, rpc) as http: resp = await http.get("https://api.example.com/quote") print(resp.status_code, resp.headers.get("payment-response"))See Client for the low-level building blocks.
No Python at all — the pay CLI is a client for any 402-gated route, handling wallet, signing, and the payment retry for you:
brew install pay # or: npm install -g @solana/pay
pay --sandbox curl https://debugger.pay.sh/mpp/quote/AAPLNext steps
- Payment schemes — fixed charge, metered usage (
upto), and session. - Frameworks — Flask, FastAPI, and Django shims.
- Pricing — the gate DSL, registries, fees, and dynamic pricing.
- Client — the paying side.
- Signers — local keys and fee sponsorship.
- Errors — the exception types and the boot-time safety rails.