Python SDK
Overview
The Brevo Python SDK provides a fully typed client library for interacting with the Brevo API. It offers Pydantic-based models, automatic retries, native async support, and comprehensive error handling.
Version 4.0 
Version 4.0 of the Python SDK has been released with significant improvements:
The legacy v1.x SDK (brevo-python < 4.0) will continue to receive critical security updates but no new features. We recommend migrating to v4.x for new projects and existing applications.
- Native async support with
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 - Configurable logging
Installation
Install the SDK using pip:
Quick start
Initialize the client and send your first email:
Configuration
Configure the client with custom timeout and HTTP settings:
Constructor parameters
Async client
The SDK exports an AsyncBrevo client for non-blocking calls. Use httpx.AsyncClient if passing a custom HTTP client.
Error handling
The SDK raises ApiError (or a specific subclass) for non-success HTTP status codes:
Error types
The SDK provides the following error types:
400-BadRequestError401-UnauthorizedError402-PaymentRequiredError403-ForbiddenError404-NotFoundError405-MethodNotAllowedError409-ConflictError412-PreconditionFailedError415-UnsupportedMediaTypeError417-ExpectationFailedError422-UnprocessableEntityError424-FailedDependencyError425-TooEarlyError429-TooManyRequestsError500-InternalServerError
All ApiError instances provide:
status_code: HTTP status codebody: Parsed error response bodyheaders: Response headers
Retries
Automatic retries with exponential backoff are enabled by default (2 retries). Configure retries at the client or request level:
Retry behavior
- Retryable status codes:
408,429,5xx - Exponential backoff with jitter
- Can be disabled per request with
max_retries: 0
Timeouts
Default timeout is 60 seconds. Configure at client or request level:
Recommended timeout values
- Standard API calls:
30-60s(default) - Quick operations:
10-15s - Bulk operations:
120-300s - Real-time:
5-10s
Request options
All service methods accept a request_options dictionary as the last parameter. Available options:
Additional headers
Add custom headers to requests:
Additional query parameters
Add query parameters to requests:
Raw response access
Access raw response headers, status codes, and parsed data via with_raw_response:
Type hints
The SDK ships with full type annotations and Pydantic-based models. All request and response types are importable from the brevo package:
Logging
Configure logging to debug API calls:
Custom logger
Pass a custom logger instance for integration with your preferred logging library:
Custom HTTP client
Override the default httpx client for proxies, custom transports, or mTLS:
Common use cases
Async with custom client
Use a custom async HTTP client:
Custom timeout and transport
Configure timeout and transport settings:
With request interceptors
Add custom middleware using httpx event hooks:
Available services
The SDK organizes API methods into service namespaces on the client:
Requirements
- Python 3.8+
httpx>= 0.21.2pydantic>= 1.9.2typing_extensions>= 4.0.0
Migration from v1.x
Version 4.0 includes breaking changes. For the full migration guide, see the GitHub migration reference.
Key changes
- New client initialization via single
Brevo(api_key="...")entry point - Native async support with
AsyncBrevo - Pydantic-based typed models
- Automatic retries with exponential backoff
httpxreplacesurllib3