# 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

```bash
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

<Tabs items={['Server', 'Client', 'CLI']}>

<Tab value="Server">

<Steps>

<Step>

### 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.

```python
import solana_pay_kit
from flask import Flask, jsonify
from solana_pay_kit import Gate, usd
from solana_pay_kit.flask import payment, require_payment
```

<Snippet lang="python" name="charge.server" path="/quote" />

</Step>

<Step>

### Run it

```bash
python app.py
```

</Step>

<Step>

### Make a paid call

Hit the route with the [`pay`](/docs/toolchain) CLI — it walks the user through approval and pays in USDC:

```bash
pay curl http://127.0.0.1:8000/quote
```

</Step>

</Steps>

The same surface works in FastAPI and Django — see [Frameworks](/docs/sdk/python/frameworks).

</Tab>

<Tab value="Client">

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:

```python
from solana_pay_kit import Signer
from solana_pay_kit.protocols.x402.client import SolanaRpc, x402_async_client
```

<Snippet lang="python" name="charge.client" url="https://api.example.com/quote" />

See [Client](/docs/sdk/python/client) for the low-level building blocks.

</Tab>

<Tab value="CLI">

No Python at all — the `pay` CLI is a client for any 402-gated route, handling wallet, signing, and the payment retry for you:

```bash
brew install pay     # or: npm install -g @solana/pay
pay --sandbox curl https://debugger.pay.sh/mpp/quote/AAPL
```

</Tab>

</Tabs>

## Next steps

- [Payment schemes](/docs/sdk/python/schemes) — fixed charge, metered usage (`upto`), and session.
- [Frameworks](/docs/sdk/python/frameworks) — Flask, FastAPI, and Django shims.
- [Pricing](/docs/sdk/python/pricing) — the gate DSL, registries, fees, and dynamic pricing.
- [Client](/docs/sdk/python/client) — the paying side.
- [Signers](/docs/sdk/python/signers) — local keys and fee sponsorship.
- [Errors](/docs/sdk/python/errors) — the exception types and the boot-time safety rails.
