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

# Python SDK

> Install and configure the Qubrics Python SDK packages.

Use the Python SDK when your application needs Qubrics API clients with API-key validation, retry handling, cursor helpers, and typed API errors.

> [!NOTE]
>
> For API-key authentication, Sending clients accept a send-capable `smx_mbx_` key or owner-approved Sending-resource `smx_agent_` token. Mailbox clients accept
> `smx_mbx_` keys or scoped `smx_agent_` tokens. Management API-key clients require
> team-scoped `smx_root_` keys.

## Requirements

* Python 3.10 or newer.
* An API key or [REST OAuth grant](https://sendmux.ai/docs/developer-tools/oauth.md) for the surface you are calling.

## Install

Install the umbrella package when one application needs more than one API surface.

```bash Umbrella theme={null}
pip install sendmux-sdk
```

```bash Sending theme={null}
pip install sendmux-sending
```

```bash Mailbox theme={null}
pip install sendmux-mailbox
```

```bash Management theme={null}
pip install sendmux-management
```

## OAuth access tokens

Set `access_token` to a bare token string or callable. Do not also set `api_key`.

```python theme={null}
import os
from sendmux_mailbox import create_mailbox_client

client = create_mailbox_client(
    access_token=lambda: os.environ["QUBRICS_ACCESS_TOKEN"],
)
```

The provider runs before each request. Your application owns secure token storage, expiry checks, and refresh coordination; see [OAuth for REST APIs](https://sendmux.ai/docs/developer-tools/oauth.md#refresh-and-disconnect). The same token option is available for Sending and Management clients.

The `langchain-sendmux` wrapper accepts the same `access_token` option in `SendmuxToolkit(...)`. To use all three tools, request `mailbox.read` and `email.send` and select one mailbox at consent; the tools do not supply a mailbox selector.

## Create a client

The umbrella package lazy-loads `sending`, `mailbox`, and `management` modules.

```python Sending theme={null}
import os
from sendmux_sdk import sending

client = sending.create_sending_client(
    api_key=os.environ["QUBRICS_MAILBOX_API_KEY"],
)
```

```python Mailbox theme={null}
import os
from sendmux_sdk import mailbox

client = mailbox.create_mailbox_client(
    api_key=os.environ["QUBRICS_MAILBOX_API_KEY"],
)
```

```python Management theme={null}
import os
from sendmux_sdk import management

client = management.create_management_client(
    api_key=os.environ["QUBRICS_ROOT_API_KEY"],
)
```

Surface packages expose `create_sending_client`, `create_mailbox_client`, and `create_management_client` directly.

## Choose a surface

| Surface | Package | Factory | API key |
| - | - | - | - |
| Sending | `sendmux-sending` | `create_sending_client` | `smx_mbx_` or owner-approved `smx_agent_` with `email.send` |
| Mailbox | `sendmux-mailbox` | `create_mailbox_client` | `smx_mbx_` or scoped `smx_agent_` |
| Management | `sendmux-management` | `create_management_client` | `smx_root_` |

> [!NOTE]
>
> Durable `smx_agent_` tokens are mailbox-compatible and include `mailbox.read`
> and `email.receive`, not `email.send`. After owner acceptance and approval,
> exchange the durable token for a one-hour Sending-resource token before sending.

Sending uses `https://smtp.sendmux.ai/api/v1` by default. Mailbox and Management use `https://app.sendmux.ai/api/v1`.

## Shared API behaviour

The surface factories validate API key prefixes, attach bearer auth, and wrap generated API errors.

### Pagination

List responses use cursor pagination with `pagination.has_more` and `pagination.next_cursor`. The core package exports `iter_cursor_pages()` for cursor iteration when you wrap a page-fetching function.

### Retries and rate limits

Surface clients use a retrying request client. It retries safe methods and retry-safe `POST` requests that include `Idempotency-Key`, then honours `Retry-After` and `X-RateLimit-Reset` response headers.

Pass `RetryOptions` into a client factory to change attempts, delays, or sleep behaviour.

### Idempotency and ETags

Use core header helpers when a generated operation accepts custom headers.

```python theme={null}
from sendmux_core import conditional_headers, idempotency_headers

headers = {
    **idempotency_headers("order-123"),
    **conditional_headers(if_match=etag),
}
```

Use `Idempotency-Key` for retry-safe mutating requests. Use `If-Match` and `If-None-Match` with single-resource endpoints that support ETags.

### Errors

Generated client exceptions are mapped to `SendmuxApiError`. The error carries the API error code, retryability, request ID, status, headers, and raw body when available.

Use `error.retryable` and `error.request_id` when deciding whether to retry or contact support.

## Next steps

> [card] [SDK overview](https://sendmux.ai/docs/developer-tools/sdks)
>
> Choose the right package family and API surface.

> [card] [Versioning and support](https://sendmux.ai/docs/developer-tools/sdks/versioning-support.md)
>
> Check compatibility, support, and upgrade guidance.

> [card] [Mailbox API](https://sendmux.ai/docs/mailbox-api/introduction.md)
>
> Review the Mailbox API contract used by `sendmux-mailbox`.

> [card] [API keys](https://sendmux.ai/docs/account/api-keys.md)
>
> Create and scope the credentials used by SDK clients.


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