> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sleetpay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Python SDK

> sleetpay: a dependency-free Python client.

`sleetpay` is a dependency-free client (Python 3.9+, standard library only).

```bash theme={null}
pip install sleetpay
```

```python theme={null}
import os
from sleetpay import SleetPay

sleetpay = SleetPay(api_key=os.environ["SLEETPAY_API_KEY"])  # server-side only
```

| Argument | Default | Notes |
| - | - | - |
| `api_key` | `None` | Not needed for `licenses.*` |
| `base_url` | `https://app.sleetpay.com` | Set for a self-hosted deployment |
| `max_retries` | `2` | Retries 429 for every method; 502, 503, 504 and network errors for GETs |
| `timeout` | `30.0` | Seconds, per request |

## Resources

`checkouts`, `products`, `customers`, `orders`, `subscriptions`, `seats`, `customer_sessions`, `events`, `meters`, `credits`, `license_keys` and `licenses` mirror the [API reference](https://docs.sleetpay.com/api-reference/introduction.md). Methods return the decoded JSON as dictionaries. Lists have an `iterate()` that walks every page.

```python theme={null}
checkout = sleetpay.checkouts.create("prod_...", external_customer_id=user.id)
state = sleetpay.customers.state_by_external_id(user.id)
for order in sleetpay.orders.iterate(customer_id=cid):
    print(order["id"])
sleetpay.subscriptions.pause(sub_id)
```

For an endpoint not wrapped yet: `sleetpay.request("GET", "/api/v1/...", query={...})`.

## Webhooks

```python theme={null}
from sleetpay import construct_event, verify_webhook, WebhookVerificationError

event = construct_event(secret, request.body, request.headers)  # verify + parse, or raise
ok = verify_webhook(secret, request.body, request.headers)      # bool
```

Pass the raw body as `bytes` or `str`.

## Errors

```python theme={null}
from sleetpay import SleetPayError

try:
    sleetpay.checkouts.create("prod_...")
except SleetPayError as e:
    print(e.status, e.body, e.retry_after)
```

## Migrating from `sleet-sdk`

Package `sleet` -> `sleetpay`, `Sleet` -> `SleetPay`, `SleetError` -> `SleetPayError`. The constructor is now `SleetPay(api_key=..., base_url=...)`.

Source: [github.com/sleetpay/sleetpay-sdk](https://github.com/sleetpay/sleetpay-sdk/tree/main/packages/python).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.