# Python SDK

Install dimmi-sdk to call the REST API (sync or async), paginate lists, sign identity tokens, and verify webhooks.

`dimmi-sdk` requires Python 3.10 or later and imports as `dimmi`.

```bash
pip install dimmi-sdk
```

## Create a client and make a call

```python title="main.py"

from dimmi import Dimmi, DimmiError, ValidationError

client = Dimmi(token=os.environ["DIMMI_API_TOKEN"])

try:
    contact = client.post("/contacts", json={"email": "ada@example.com", "name": "Ada Lovelace"})["data"]
    print(contact["id"])
except ValidationError as error:
    print(error.fields)
except DimmiError as error:
    print(error.status, error.code, error.message)

for conversation in client.paginate("/conversations", {"filter[status]": "open"}):
    print(conversation["id"])
```

Set `DIMMI_API_TOKEN` (or `DIMMI_TOKEN`) to your [API token](/developers/api/authentication/). `Dimmi()` reads those environment variables automatically if you omit `token=`. When self-hosting, pass `base_url=` or set `DIMMI_BASE_URL`.

## Ways to call the API

- **HTTP helpers:** `client.get`, `post`, `put`, `patch`, `delete`, and `request(method, path)` accept any path from the [API reference](/api-reference/) and return decoded JSON.
- **Pagination:** `client.paginate()` iterates cursor-paginated lists (`meta.next_cursor`), and `client.pages()` iterates page-numbered lists. Both request 100 items per page unless you set `limit`.
- **Async support:** use `async with AsyncDimmi() as client:` for async/await code with the same methods.
- **Generated modules:** `dimmi._generated.api.default` exposes one typed module per operation ID (such as `conversations_index.sync(client=client.api)`).

## Exceptions

Every exception inherits from `DimmiError` with `status`, `code`, `message`, and `fields`:

| HTTP status | Exception |
| --- | --- |
| 400 | `BadRequestError` |
| 401 | `AuthenticationError` |
| 403 | `PermissionDeniedError` |
| 404 | `NotFoundError` |
| 409 | `ConflictError` |
| 422 | `ValidationError` |
| 429 | `RateLimitError` (includes `retry_after` in seconds) |
| 500+ | `ServerError` |

## Retries and idempotency

| `Dimmi()` argument | Default | What it does |
| --- | --- | --- |
| `max_retries` | `3` | Retries on `429`, `503`, or connection errors. |
| `max_retry_wait` | `60.0` | Max retry delay in seconds (honors `Retry-After`). |
| `timeout` | `30.0` | Per-attempt timeout in seconds. |

Every `POST` automatically sends an [`Idempotency-Key`](/developers/api/idempotency/) and reuses it across retries. Pass `idempotency_key=` to `client.post()` to set your own.

## Webhooks and identity tokens

Use `dimmi.Webhook` to check webhook signatures (see [Verify webhook signatures](/developers/webhooks/verify-signatures/)) and `dimmi.sign_identity_token()` to sign JWTs for [identity verification](/developers/messenger/identity-verification/).

---

Index of all dimmi docs: https://trydimmi.com/llms.txt (full text: https://trydimmi.com/llms-full.txt)
