Brevo Python SDK

4.0.10 · active · verified Fri Apr 17

The Brevo Python SDK is a client library for interacting with the Brevo (formerly Sendinblue) API, providing access to email, SMS, contacts, CRM, and other marketing automation services. It is a modern, Fern-generated client built on `httpx` and `pydantic`. The library is actively maintained with frequent releases, currently at version 4.0.10.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Brevo client using an API key from an environment variable and then retrieves basic account details and a list of contacts to verify connectivity.

import os
from brevo import Brevo
from brevo.exceptions import ApiError

# Set your Brevo API key as an environment variable (e.g., BREVO_API_KEY)
api_key = os.environ.get("BREVO_API_KEY", "")

if not api_key:
    print("Error: BREVO_API_KEY environment variable not set. Please set it to your Brevo API key.")
else:
    try:
        client = Brevo(api_key=api_key)
        
        # Example: Get account details
        account = client.account.get_account()
        print(f"Successfully connected to Brevo API. Account email: {account.email}")
        print(f"Company name: {account.company_name}")
        
        # Example: Get contacts (first 10)
        contacts_response = client.contacts.get_contacts(limit=10)
        print(f"Found {len(contacts_response.contacts)} contacts.")
        if contacts_response.contacts:
            print(f"First contact email: {contacts_response.contacts[0].email}")

    except ApiError as e:
        print(f"Brevo API Error: {e}")
        if "Unauthorized" in str(e):
            print("Please check if your BREVO_API_KEY is valid and has the necessary permissions.")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

view raw JSON →