Brevo (formerly Sendinblue) API Python SDK

7.6.0 · active · verified Thu Apr 16

The `sib-api-v3-sdk` is the official Python client library for the Brevo (formerly Sendinblue) API v3. It provides a wrapper around the RESTful API, enabling developers to programmatically manage email campaigns, transactional emails, SMS, contacts, and retrieve statistics. The library is currently at version 7.6.0 and is actively maintained, with updates typically released as needed for bug fixes and new features.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to configure the Brevo Python SDK using an API key and send a basic transactional email. Ensure your `BREVO_API_KEY` environment variable is set or replace 'YOUR_API_KEY' with your actual API key.

import sib_api_v3_sdk
from sib_api_v3_sdk.api import transactional_emails_api
from sib_api_v3_sdk.model.send_smtp_email import SendSmtpEmail
import os

# Configure API key authorization: api-key
configuration = sib_api_v3_sdk.Configuration()
configuration.api_key['api-key'] = os.environ.get('BREVO_API_KEY', 'YOUR_API_KEY')

# Create an instance of the API class
api_instance = transactional_emails_api.TransactionalEmailsApi(sib_api_v3_sdk.ApiClient(configuration))

# Define the email to be sent
sender = {"name":"Sender Name", "email":"sender@example.com"}
to = [{"email":"recipient@example.com", "name":"Recipient Name"}]

send_smtp_email = SendSmtpEmail(
    sender=sender,
    to=to,
    subject="My Test Subject",
    html_content="<html><body><h1>This is a test email from Brevo!</h1></body></html>"
)

try:
    # Send a transactional email
    api_response = api_instance.send_transac_email(send_smtp_email)
    print(f"API called successfully. Returned data: {api_response}")
except sib_api_v3_sdk.rest.ApiException as e:
    print(f"Exception when calling TransactionalEmailsApi->send_transac_email: {e}")

view raw JSON →