Skip to main content

Django + Brevo for transactional emails and customer journey automations.

Project description

dj-brevo

Django integration for Brevo (formerly Sendinblue) - transactional emails and contact management.

Installation

pip install dj-brevo

Quick Start

  1. Add to your INSTALLED_APPS:
INSTALLED_APPS = [
    ...
    "dj_brevo",
]
  1. Configure your Brevo API key:
DJ_BREVO = {
    "API_KEY": "your-brevo-api-key",
    "DEFAULT_FROM_EMAIL": "noreply@yourdomain.com",
}
  1. Run migrations:
python manage.py migrate dj_brevo
  1. Set the email backend (optional):
EMAIL_BACKEND = "dj_brevo.backends.BrevoEmailBackend"

Sending Emails

Using Django's Email Functions

from django.core.mail import send_mail

send_mail(
    subject="Welcome!",
    message="Thanks for signing up.",
    from_email="hello@yourdomain.com",
    recipient_list=["user@example.com"],
)

Using Brevo Templates

Send emails using templates created in Brevo's dashboard:

from dj_brevo.services import BrevoClient

client = BrevoClient()
client.send_template_email(
    to=[{"email": "user@example.com", "name": "David"}],
    template_id=12,
    params={"firstName": "David", "orderTotal": "$50"},
)

Contact Management

Models

dj-brevo provides Django models for managing Brevo contacts, lists, and attributes locally:

from dj_brevo.models import BrevoContact, BrevoList, BrevoAttribute

# Create a contact
contact = BrevoContact.objects.create(
    email="user@example.com",
    attributes={"FIRSTNAME": "David", "MRR": 99.99},
)

# Create a list (auto-syncs to Brevo when AUTO_SYNC=True)
newsletter = BrevoList.objects.create(
    name="Newsletter",
    folder_id=1,  # Required for Brevo sync
)

# Add contact to list
contact.lists.add(newsletter)

# Create an attribute (auto-syncs to Brevo when AUTO_SYNC=True)
attr = BrevoAttribute.objects.create(
    name="SUBSCRIPTION_STATUS",
    attribute_type="text",
    category="normal",
)

Auto-Sync

When AUTO_SYNC is enabled (default), BrevoList and BrevoAttribute models automatically sync to Brevo on save:

  • BrevoList: Creates/updates the list in Brevo, stores the returned brevo_id
  • BrevoAttribute: Creates the attribute in Brevo, marks brevo_synced=True

Contacts do not auto-sync - use the API client directly for contact operations.

Direct API Access

For full control, use the BrevoClient directly:

from dj_brevo.services import BrevoClient

client = BrevoClient()

# Contacts
client.create_contact(email="user@example.com", attributes={"FIRSTNAME": "David"})
client.get_contact("user@example.com")
client.update_contact(identifier="user@example.com", attributes={"MRR": 150})

# Lists
client.get_lists()
client.create_list(name="Newsletter", folder_id=1)
client.add_contacts_to_list(list_id=5, emails=["user@example.com"])
client.remove_contacts_from_list(list_id=5, emails=["user@example.com"])

# Attributes
client.get_attributes()
client.create_attribute(
    attribute_name="MRR",
    attribute_type="float",
    attribute_category="normal",
)

Configuration

All settings are optional except API_KEY:

DJ_BREVO = {
    # Required
    "API_KEY": "your-brevo-api-key",

    # Optional
    "DEFAULT_FROM_EMAIL": "noreply@yourdomain.com",
    "TIMEOUT": 10,  # Request timeout in seconds
    "API_BASE_URL": "https://api.brevo.com/v3",  # Override for testing
    "SANDBOX": False,  # Enable sandbox mode for testing
    "AUTO_SYNC": True,  # Auto-sync lists/attributes to Brevo on save
}

Disabling Auto-Sync

To manually control when data syncs to Brevo:

DJ_BREVO = {
    "API_KEY": "your-brevo-api-key",
    "AUTO_SYNC": False,
}

This is recommended for tests to prevent API calls.

Sandbox Mode

Use sandbox mode to test your integration without sending actual emails:

DJ_BREVO = {
    "API_KEY": "your-brevo-api-key",
    "SANDBOX": True,  # Emails won't be sent
}

In sandbox mode:

  • No emails are sent to recipients
  • No email logs are created in your Brevo account
  • You receive a success response with a messageId confirming the API is working

This is useful for automated testing and CI/CD pipelines.

Requirements

  • Python 3.12+
  • Django 5.0+

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj_brevo-0.2.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_brevo-0.2.0-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file dj_brevo-0.2.0.tar.gz.

File metadata

  • Download URL: dj_brevo-0.2.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_brevo-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2de5c12d94b28d23f3a260ee2f45ec7c1b0e2504109cf117b0abafbc487c4a0f
MD5 5fbdd1142d5faa257c7421193dd6c076
BLAKE2b-256 21061eb8ddc2b7813c84bc886a95d0a586c7e8822087a94faa8f2da9e1ec743d

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_brevo-0.2.0.tar.gz:

Publisher: publish.yml on dmckim1977/dj-brevo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dj_brevo-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dj_brevo-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_brevo-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b245450027d1f65242701e9d8ddf129ab129c4cf32b3ba82f99008b5d67b61fa
MD5 6f6abf16d66cb2fbb594be3a4827aa01
BLAKE2b-256 cc83d043cc36521ec6ffafb46c9bf1c98f647e73cfef0a80c968d238d5e924fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_brevo-0.2.0-py3-none-any.whl:

Publisher: publish.yml on dmckim1977/dj-brevo

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page