Skip to main content
The Courier Python SDK provides typed access to the Courier REST API from any Python 3.9+ application. It includes synchronous and asynchronous clients, Pydantic response models, and TypedDict request params. Available on GitHub and PyPI.

Installation

Requires Python 3.9+.

Quick Start

The client reads COURIER_API_KEY from your environment automatically. You can also pass it explicitly: Courier(api_key='your-key').

Authentication

Get your API key from Settings > API Keys in the Courier dashboard. Set it as an environment variable:
The SDK picks this up by default. To pass it explicitly:
We recommend using a .env file with python-dotenv so your API key stays out of source control.

Sending Notifications

With a template

Design your notification in Design Studio, then reference it by ID:

With inline content

Skip templates and define content directly in code:

To multiple recipients

Send to a list of users in a single call:

Async Usage

Basic async client

Import AsyncCourier instead of Courier and use await:
The async client has the same API as the sync client; every method returns an awaitable.

Using aiohttp instead of httpx

For improved concurrency performance, you can swap the HTTP backend to aiohttp:

Available Resources

The SDK covers the full Courier API. Every method is typed and documented with docstrings.

Common Operations

Checking Message Status

After sending, use the request_id to check delivery status or get the full event timeline:
You can also list recent messages with optional filters:

Managing User Profiles

Profiles store recipient data (email, phone, custom fields) that Courier uses for delivery. You need a profile before you can send to a user_id.
create merges with any existing profile. Use replace for a full overwrite (any fields not included will be removed).

Issuing JWT Tokens

If you use Courier’s client-side SDKs (React, JavaScript, mobile), your backend needs to issue JWT tokens for user authentication. The auth.issue_token method handles this:
The scope string controls what the token can access. Common scopes:

Bulk Sending

For large recipient lists, use the bulk API. It works in three steps: create a job, add users, then run it.
For email-based bulk jobs, include profile.email on each user. The to.email field alone is not sufficient for email provider routing.

Type Safety

Request parameters are TypedDicts, and responses are Pydantic models. This gives you autocomplete and inline docs in your editor.
For VS Code type checking, set python.analysis.typeCheckingMode to basic in your settings.

Configuration

Error Handling

The SDK throws typed errors for API failures. All errors extend courier.APIError:

Retries

The SDK automatically retries failed requests up to 2 times with exponential backoff. Retried errors include connection failures, 408, 409, 429, and 5xx responses.

Timeouts

Requests time out after 60 seconds by default. Configure globally or per-request:
On timeout, an APITimeoutError is thrown. Timed-out requests are retried by default.

Logging

Enable debug logging with the COURIER_LOG environment variable:
The SDK uses Python’s standard logging module, so it integrates with any logging setup you already have.

Raw Response Access

Access HTTP headers or stream the response body:

Custom HTTP Client

Override the default httpx client for proxies, custom transports, or other advanced use cases:

Journeys

Journeys are multi-step workflows (send, delay, branch, throttle, digest, and more). Invoke one by ID or alias to start a run, then cancel runs by ID or a shared cancelation token.
cancel takes exactly one of run_id or cancelation_token (spelled with one “l”). You can also build and manage journeys from code with client.journeys.create, list, publish, and archive. See Build journeys via API.

More Operations

The SDK covers the full Courier REST API. Here are a few more resources beyond what’s documented above:

API Reference

Full REST API docs with request/response examples.

Send API

Learn about the Send endpoint, routing, and message options.

Quickstart

Send your first notification in under two minutes.

GitHub

Source code, issues, and changelog.