Python SDK
Overview
The Brevo Python SDK (brevo-python) is a fully typed client library for the Brevo API. It provides:
- A unified
Brevoclient with namespaced service clients - Native async support via
AsyncBrevo - Pydantic-based typed models with full type annotations
- Automatic retries with exponential backoff
- Raw response access with headers and status codes
- Custom
httpxclient support for proxies and mTLS
Version 5.0 introduces breaking changes versus v4.x. v4.x remains supported and continues to receive wire-compatibility fixes — see the changelog for the list of changes and the README for migration steps.
Requirements
- Python 3.8+
httpx>= 0.21.2pydantic>= 1.9.2typing_extensions>= 4.0.0
Installation
Quick start
Initialize the client and send your first email:
Configuration
Pass keyword arguments to the constructor to configure the client:
Constructor parameters
Async client
Use AsyncBrevo for non-blocking calls. Pass httpx.AsyncClient instead of httpx.Client when providing a custom HTTP client:
Error handling
The SDK raises ApiError (or a typed subclass) for non-2xx HTTP responses:
Error classes
All ApiError instances expose:
status_code— HTTP status codebody— Parsed response bodyheaders— Response headers
Retries
Automatic retries with exponential backoff are enabled by default (2 retries). Configure at the client or request level:
Retry behavior
- Retryable status codes:
408,429,5xx - Backoff: Exponential with jitter
- Disable: Set
max_retries: 0inrequest_options
Timeouts
Default timeout is 60 seconds. Configure at the client or request level:
Recommended timeout values
Request options
All service methods accept a request_options dict as the final keyword argument:
Raw response access
Access response headers and status code via .with_raw_response:
Logging
The SDK has a built-in, opt-in logger you can plug your own implementation into. Pass a LogConfig dict (or a pre-built Logger) via the logging constructor option.
By default the SDK is silent: nothing is logged unless you set silent=False. This keeps integration changes from accidentally producing log volume in production.
LogConfig fields
Custom logger
Implement the ILogger protocol (a typing.Protocol with debug, info, warn, error methods) to forward to any logging library — Python’s stdlib logging, structlog, loguru, or your own sink.
Integrations
structlog
loguru
Reusing a pre-built Logger
Build a Logger once and reuse it across Brevo and AsyncBrevo instances:
The default ConsoleLogger uses Python’s stdlib logging module under the logger name "fern". If you only need to filter or reformat output, configuring that logger via logging.getLogger("fern") may be enough — you don’t always need a custom ILogger.
Custom HTTP client
Override the default httpx client for proxies, custom transports, or mTLS:
Common integrations
Async with custom client
Custom timeout and transport
With event hooks
Available services
The Brevo and AsyncBrevo clients expose the following service namespaces: