Event-driven transactional notifications for Django booking and SaaS workflows.
Project description
mroudai-django-notifications
Event-driven transactional notifications for Django (app label: notifications). Email-first, tenant-aware optional, works without Celery.
What it does
- Store notification templates per event/channel (optionally scoped to a tenant) with fallback to global templates.
- Enqueue immediate or scheduled notification jobs with idempotency keys.
- Inline sending (optional) plus a worker-friendly dispatcher with retries, backoff, and attempt logs.
- Email delivery via Django email backends; SMS/WhatsApp hooks are stubbed for future backends.
- Admin screens for templates, jobs, and attempts with requeue/cancel actions.
What it avoids
- No booking/payment logic, slot generation, or user-facing UI.
- No external queue required; works entirely on Django + DB.
Quick install
- Install the package:
pip install mroudai-django-notifications - Add to
INSTALLED_APPS:"notifications". - Configure settings as needed (defaults shown below).
- Run migrations:
python manage.py migrate.
Key settings (defaults)
NOTIFY_TENANT_MODEL = None # e.g. "tenants.Tenant"
NOTIFY_USER_MODEL = None # defaults to AUTH_USER_MODEL
NOTIFY_EMAIL_FROM_DEFAULT = "no-reply@example.com"
NOTIFY_EMAIL_PROVIDER = "django"
NOTIFY_SEND_IMMEDIATELY = True
NOTIFY_MAX_ATTEMPTS = 5
NOTIFY_RETRY_BACKOFF_SECONDS = [60, 300, 1800, 7200]
NOTIFY_LOCK_TIMEOUT_SECONDS = 300
NOTIFY_ALLOW_GLOBAL_TEMPLATE_FALLBACK = True
Creating templates
- Via Django admin: add a Notification Template for each
event_key/channel, optionally tied to a tenant. - Or via shell:
from notifications.models import NotificationTemplate, NotificationChannel
NotificationTemplate.objects.create(
event_key="booking.confirmed",
channel=NotificationChannel.EMAIL,
name="Booking confirmation",
subject="Your booking is confirmed, {{ name }}",
body_text="Hi {{ name }}, your booking is confirmed.",
body_html="<p>Hi {{ name }}, your booking is confirmed.</p>",
)
Enqueue a notification
from notifications.services import enqueue_notification
from notifications.models import NotificationChannel
job = enqueue_notification(
event_key="booking.confirmed",
channel=NotificationChannel.EMAIL,
to={"email": "person@example.com", "name": "Alex"},
context={"name": "Alex"},
# tenant=<Tenant instance> # if NOTIFY_TENANT_MODEL is set
)
- Jobs scheduled in the past are treated as immediate.
- Idempotency keys are required; they are auto-generated unless you provide one.
Run the worker (cron-friendly)
Use the bundled management command—no Celery required:
python manage.py send_notifications --limit 50 --worker-id "worker-1"
- It locks due jobs, sends them, and reschedules failures with backoff until
NOTIFY_MAX_ATTEMPTSis reached.
Tenancy
- Set
NOTIFY_TENANT_MODEL(e.g."tenants.Tenant") to enable tenant scoping. - If
NOTIFY_ALLOW_GLOBAL_TEMPLATE_FALLBACKisTrue, tenant-specific templates are preferred and global templates (tenantnull) are used as a fallback.
Channels
- Email is implemented via Django's email backends (respects
NOTIFY_EMAIL_FROM_DEFAULT). - SMS and WhatsApp are intentionally stubbed; extend
notifications.channelswith real backends when needed.
Tests
Run the included test suite with SQLite + locmem email:
python test notifications
Publish to PyPI
Build and upload using the helper script (auto-installs twine and build if missing; supply credentials via environment variables):
python upload project
- Add
--repository-url https://test.pypi.org/legacy/to publish to TestPyPI. - Use
--skip-buildif you already have fresh artifacts indist/.
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 mroudai_django_notifications-0.1.0.tar.gz.
File metadata
- Download URL: mroudai_django_notifications-0.1.0.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3baf0e067e79767d8252ec581d7e69b5c62a89d1d874c3b482796dca7a1bc090
|
|
| MD5 |
d2deb669af4655a4387468ae99051cc8
|
|
| BLAKE2b-256 |
5f4505cb426c10084085f718c50db377222c61d36c45abde3d28d0e216022f60
|
File details
Details for the file mroudai_django_notifications-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mroudai_django_notifications-0.1.0-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc9c9e032bc7b61af0970ea87f8ab1ecf37af5f5c2aa3f07474c82793a9c2a81
|
|
| MD5 |
d2409bc3c0891aecd1d1d451cec17ff9
|
|
| BLAKE2b-256 |
7a13f42e12d43a4fc380d45afbd8587ea9f95270c481d7d9bf3cfd3a36f9203b
|