Skip to main content
The Python SDK gives Python applications typed access to the Dodo Payments REST API. It has a synchronous client, DodoPayments, and an asynchronous client, AsyncDodoPayments, both built on httpx. Nested request parameters are typed dictionaries, and responses are Pydantic models.

Installation

Install the SDK with pip:
To use aiohttp as the HTTP backend for the async client, install the aiohttp extra:
To verify webhook signatures with client.webhooks.unwrap(), also install the webhooks extra: pip install "dodopayments[webhooks]".
The SDK requires Python 3.9 or later. Use the latest stable Python release to get security updates.

Quick Start

Synchronous Client

Create a client, then create a checkout session:
If you omit bearer_token, the client reads the DODO_PAYMENTS_API_KEY environment variable. If you omit environment, the client connects to live mode. A test mode API key works only with environment="test_mode".

Asynchronous Client

AsyncDodoPayments has the same methods as DodoPayments. Await each call:
Keep API keys in environment variables or a secrets manager. Never commit them to version control.

Core Features

Pythonic Interface

Keyword arguments for parameters, TypedDict types for nested objects, and Pydantic models for responses.

Async/Await

AsyncDodoPayments for asyncio, with aiohttp as an optional HTTP backend.

Type Hints

Type hints on every method, for editor autocomplete and type checking with mypy.

Auto-Pagination

List methods return iterators that fetch the next page as you loop.

Configuration

Environment Variables

Store your API key in an environment variable:
.env
The client reads these variables when you don’t pass the matching argument: If DODO_PAYMENTS_BASE_URL is set and you also pass environment, the constructor raises an “Ambiguous URL” error. To use environment in that case, pass base_url=None. To verify a webhook, pass the raw request body and headers to client.webhooks.unwrap(payload, headers=headers). It checks the signature with your webhook key and returns the parsed event. client.webhooks.unsafe_unwrap(payload) parses the body without verifying it, so use it only for testing. See Webhooks.

Timeouts

Requests time out after 1 minute by default, with a 5-second connection timeout. Pass timeout in seconds, or an httpx.Timeout for separate read, write, and connect limits:
When a request times out, the SDK raises APITimeoutError. Timed-out requests are retried, so a call can take longer than timeout before it fails.

Retries

Set max_retries on the client, or on a single request with with_options():
The SDK retries connection errors and responses with status 408, 409, 429, or 500 and above. It retries twice by default, with exponential backoff. When a request still fails, the SDK raises a subclass of dodopayments.APIError: The status exceptions inherit from dodopayments.APIStatusError, which has status_code and response attributes. APITimeoutError is a subclass of APIConnectionError.

Workload Identity

The SDK can use workload identity federation instead of an API key. The SDK exchanges an OIDC token from your CI or cloud platform for a short-lived Dodo Payments token. It refreshes the token before the token expires. This feature is available from version 1.124.0. Before you start, create an identity provider and a mapping in the dashboard. Refer to Dashboard Setup. This example uses the GitHub Actions helper, github_actions():
If DODO_PAYMENTS_API_KEY is not set and DODO_PAYMENTS_IDENTITY_PROVIDER_ID is set, the SDK uses workload identity. It finds the platform from the environment. To stop the token before it expires, for example at the end of a CI job, revoke it:
Do not set an API key and workload identity together. The SDK gives an error when you set the two options.
For the other platform helpers and the refresh behavior, refer to Use Workload Identity with the SDKs.

Common Operations

The examples in this section use the client from Quick Start.

Create a Checkout Session

Create a checkout session, then redirect the customer to the returned checkout_url:
Each checkout_url works once and expires after 24 hours. For every session option, see Checkout Sessions.

Manage Customers

Create a customer with an email address and name, then retrieve it by ID:

Handle Subscriptions

Start a subscription with a checkout session, charge an on-demand subscription, and read a subscription’s usage history.
The subscription starts when the customer completes checkout. Read its subscription_id from the subscription.active webhook or from the return_url query parameters. customer takes {"customer_id": ...} to attach an existing customer or {"email": ..., "name": ...} to create one. charge is for on-demand subscriptions, and product_price is in the smallest currency unit. retrieve_usage_history returns a paginated list, which you can iterate as shown in Pagination.

Usage-Based Billing

Ingest Usage Events

Send usage events for a customer:
The event_id is the idempotency key, so give each event a unique value. If the same event_id appears twice in one request, the whole request is rejected. If an event_id was already ingested, the new event is ignored. A request accepts up to 1,000 events. timestamp defaults to the current time and is rejected if it’s more than 1 hour in the past or more than 5 minutes in the future.

List and Retrieve Events

Retrieve a single event by its event_id, or list events filtered by customer and event name:
usage_events.list also accepts meter_id, start, and end filters.

Pagination

Auto-Pagination

List methods return an iterator that fetches the next page as you loop:

Async Pagination

With the async client, loop with async for:

Manual Pagination

To work with one page at a time, read items and call has_next_page() and get_next_page(). next_page_info() returns the parameters for the next request:

HTTP Client Configuration

To add a proxy, a custom transport, or other httpx settings, pass your own http_client. DefaultHttpxClient keeps the SDK’s default connection limits, timeout, and redirect settings:
To use a different HTTP client for one request, call client.with_options(http_client=...).

Async with AIOHTTP

By default, the async client sends requests with httpx. For better concurrency, install the aiohttp extra and pass DefaultAioHttpClient() as http_client:

Logging

The SDK logs with the standard library logging module. To turn on logging, set DODO_PAYMENTS_LOG to info:
For more detail, set it to debug:

Framework Integration

These examples create a checkout session from a web endpoint and return its URL.

FastAPI

This endpoint uses the async client:

Django

This view uses the sync client:

Resources

GitHub Repository

Source code, releases, and the full method list.

API Reference

Every endpoint, parameter, and response.

Discord Community

Ask questions and talk with other developers.

Report Issues

Report bugs or request features.

Support

For help with the Python SDK:

Contributing

To contribute, read the contributing guidelines.
Last modified on October 28, 2026