Skip to main content
Add order status notifications to a Django app by calling Courier from a 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.
Save it as first_send.py, then run it with your API key and email address:
It prints a request id that you’ll find in Courier Logs. On a Test key, use your Courier login address. Test email reaches it with no provider connected.

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:
Install the Courier skill with 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 trycourier package (from courier import Courier), and create the client only in orders/notifications.py.
  • Read COURIER_API_KEY from the environment on the server. Never hard-code it or render it into a template.
  • Pass one idempotency_key per status change, built from the order number, the new status, and a timestamp, and reuse it on retries.
  • Send from the post_save receiver inside transaction.on_commit, only when Order.status changed.
  • Change status with save(), because QuerySet.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 a post_save signal:
  • Paid, shipped, delivered, and cancelled updates when Order.status changes, 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 send management command that ships a demo order to your inbox

Prerequisites

For the first send

For the full build

Clone the finished Django app

Clone the Courier Django quickstart to run the finished project with your own key:
The steps below add or change these files:

Install the Courier Python SDK in Django

The Courier Python SDK is trycourier on PyPI, imported as from courier import Courier. Install it in your virtualenv with python-dotenv, and add both to requirements.txt:
In 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:
Put your key and address in .env. DEMO_PHONE is optional, in E.164.

Add a phone number and a status to the Django models

Courier’s SMS channel reads phone_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
Add "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
The inline contact details merge over any saved profile, and a repeated idempotency key returns the first response for 25 hours.

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
Connect the receivers in orders/apps.py. Without this, nothing sends and manage.py check still passes:
To send from a Celery worker instead, with retries that reuse the key, set up Celery for Django and add this task in 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, run python 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_KEY and 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

Celery is optional for Courier notifications in Django. client.send.message returns once Courier accepts the request, and Courier handles delivery and retries.
Courier sends SMS only when the email fails if you route with {"method": "single", "channels": ["email", "sms"]}. A later bounce takes a fallback journey.
Django’s send_mail keeps working alongside Courier. Connect your provider, such as SendGrid, Amazon SES, or SMTP, and Courier sends through it.
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.