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
- Add to your
INSTALLED_APPS:
INSTALLED_APPS = [
...
"dj_brevo",
]
- Configure your Brevo API key:
DJ_BREVO = {
"API_KEY": "your-brevo-api-key",
"DEFAULT_FROM_EMAIL": "noreply@yourdomain.com",
}
- Run migrations:
python manage.py migrate dj_brevo
- 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
messageIdconfirming 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dj_brevo-0.3.2.tar.gz.
File metadata
- Download URL: dj_brevo-0.3.2.tar.gz
- Upload date:
- Size: 20.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfdcfd27a9ed0eea3d970115982c078624f361c2a5f8a9e2883d7b0f8fdca2dc
|
|
| MD5 |
cd5557cda5538145a9d13e368333ec0e
|
|
| BLAKE2b-256 |
f8f2a1424977e4501697d1f9c9c8e701f6700eabe6a431ce28a5fc0ae8456ce8
|
Provenance
The following attestation bundles were made for dj_brevo-0.3.2.tar.gz:
Publisher:
publish.yml on dmckim1977/dj-brevo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_brevo-0.3.2.tar.gz -
Subject digest:
bfdcfd27a9ed0eea3d970115982c078624f361c2a5f8a9e2883d7b0f8fdca2dc - Sigstore transparency entry: 832959937
- Sigstore integration time:
-
Permalink:
dmckim1977/dj-brevo@6aafb873252245011b3cf577ff26acffc8cc4e72 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/dmckim1977
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6aafb873252245011b3cf577ff26acffc8cc4e72 -
Trigger Event:
release
-
Statement type:
File details
Details for the file dj_brevo-0.3.2-py3-none-any.whl.
File metadata
- Download URL: dj_brevo-0.3.2-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1aaa74696a442d90cc40211097234a4e14c0bbad9f9669c08563a65d55e15a91
|
|
| MD5 |
a780654f0533445106a127ab2b16644a
|
|
| BLAKE2b-256 |
df75789522e13bb3d6c58c7504418d605712bf947c077184fb62a0a207598127
|
Provenance
The following attestation bundles were made for dj_brevo-0.3.2-py3-none-any.whl:
Publisher:
publish.yml on dmckim1977/dj-brevo
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dj_brevo-0.3.2-py3-none-any.whl -
Subject digest:
1aaa74696a442d90cc40211097234a4e14c0bbad9f9669c08563a65d55e15a91 - Sigstore transparency entry: 832959938
- Sigstore integration time:
-
Permalink:
dmckim1977/dj-brevo@6aafb873252245011b3cf577ff26acffc8cc4e72 -
Branch / Tag:
refs/tags/v0.3.2 - Owner: https://github.com/dmckim1977
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6aafb873252245011b3cf577ff26acffc8cc4e72 -
Trigger Event:
release
-
Statement type: