post_save signal. Courier emails the customer on each status change and texts them when the email can’t go out, all from one client.send.message call.
first_send.py, then run it with your API key and email address:
courier-django-quickstart
The finished Django project from this guide, ready to clone and run.
Build this with a coding agent
To have a coding agent add Courier to your Django app, paste this prompt into Claude Code, Cursor, or Codex from the project root:npx skills add trycourier/courier-skills, and connect the Courier MCP server so the agent can check Courier Logs and templates itself.
Rules for AI agents
- Use the
trycourierpackage (from courier import Courier), and create the client only inorders/notifications.py. - Read
COURIER_API_KEYfrom the environment on the server. Never hard-code it or render it into a template. - Pass one
idempotency_keyper status change, built from the order number, the new status, and a timestamp, and reuse it on retries. - Send from the
post_savereceiver insidetransaction.on_commit, only whenOrder.statuschanged. - Change status with
save(), becauseQuerySet.update()skips signals. - Send these notifications through Courier, not the SendGrid or Twilio SDKs. Courier routes email, then SMS.
What you’ll build
This Django project sends order updates through Courier from apost_save signal:
- Paid, shipped, delivered, and cancelled updates when
Order.statuschanges, and nothing on other saves - Email first, then SMS if the email can’t be sent, through SendGrid, Twilio, or any provider you connect
- A
sendmanagement command that ships a demo order to your inbox
Prerequisites
For the first send
- A Courier API key
- Python 3.12 or newer
For the full build
- A Django 6 project
- A connected email provider
- A connected SMS provider
Clone the finished Django app
Clone the Courier Django quickstart to run the finished project with your own key:Install the Courier Python SDK in Django
The Courier Python SDK istrycourier on PyPI, imported as from courier import Courier. Install it in your virtualenv with python-dotenv, and add both to requirements.txt:
shop/settings.py, load .env, set the custom user model before the first migration, and log the orders app so you see each request id:
.env. DEMO_PHONE is optional, in E.164.
Add a phone number and a status to the Django models
Courier’s SMS channel readsphone_number from a custom user. In an existing project with its own user model, skip this file and change the line in recipient_for (below) that reads the phone number.
accounts/models.py
Order remembers the status it was loaded with, so a save spots a change without another query:
orders/models.py
"accounts" and "orders" to INSTALLED_APPS, then run python manage.py makemigrations and python manage.py migrate.
Send the order status email and SMS from Django
notify_order_status makes one Courier call to POST /send for a Django order.
orders/notifications.py
Send the notification from a Django post_save signal
The Django receiver calls Courier only on a status change, once the transaction commits, so a rolled-back save sends nothing.orders/signals.py
orders/apps.py. Without this, nothing sends and manage.py check still passes:
orders/tasks.py. Then in signals.py, import send_order_status and replace notify_order_status(instance, key) with send_order_status.delay(instance.pk, key):
Verify
In the cloned repo, runpython manage.py send. orders/management/commands/send.py ships a demo order through the same signal. In your own app, change an order’s status in the admin. Courier Logs shows the channel and provider:
Go to production with Courier
Courier is notification infrastructure for humans and AI agents. In a Django app it sends through SendGrid and Twilio. Go live covers moving from Test to Production:- Set a Production
COURIER_API_KEYand connect your providers there. - Move the copy into a template and pass
"template"instead of"content". - Map it to a subscription topic so customers opt out in a preference center.
FAQ
Do I need Celery to send notifications from Django?
Do I need Celery to send notifications from Django?
Celery is optional for Courier notifications in Django.
client.send.message returns once Courier accepts the request, and Courier handles delivery and retries.How do I send SMS only when the email fails?
How do I send SMS only when the email fails?
Courier sends SMS only when the email fails if you route with
{"method": "single", "channels": ["email", "sms"]}. A later bounce takes a fallback journey.Can I keep Django's send_mail or my existing provider?
Can I keep Django's send_mail or my existing provider?
Django’s
send_mail keeps working alongside Courier. Connect your provider, such as SendGrid, Amazon SES, or SMTP, and Courier sends through it.How do I send SMS from Django?
How do I send SMS from Django?
Django sends SMS through Courier with
client.send.message, a phone_number in E.164, and "sms" in the route. Connect an SMS provider such as Twilio first.