Skip to main content

Django Generic Notifications

A flexible, multi-channel notification system for Django applications with built-in support for email digests, user preferences, and extensible delivery channels.

Features

  • Multi-channel delivery: Send notifications through multiple channels (website, email, and custom channels)
  • Flexible delivery frequencies: Support for real-time and digest delivery (daily, or custom schedules)
  • Notification grouping: Prevent repeated notifications by grouping notifications based on your own custom logic
  • User preferences: Fine-grained control over notification types and delivery channels
  • Extensible architecture: Easy to add custom notification types, channels, and frequencies
  • Generic relations: Link notifications to any Django model
  • Template support: Customizable email templates for each notification type
  • Developer friendly: Simple API for sending notifications with automatic channel routing
  • Full type hints: Complete type annotations for better IDE support and type checking

Requirements

  • Python >= 3.10
  • Django >= 4.2.0
  • django.contrib.contenttypes must be in INSTALLED_APPS

Installation

All instructions in this document use uv, but of course pip or Poetry will also work just fine.

uv add django-generic-notifications

Add to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "django.contrib.contenttypes",  # Required dependency
    "generic_notifications",
    ...
]

Run migrations:

uv run ./manage.py migrate generic_notifications

Settings

NOTIFICATION_BASE_URL

Configure the base URL for generating absolute URLs in email notifications:

# With protocol (recommended)
NOTIFICATION_BASE_URL = "https://www.example.com"
NOTIFICATION_BASE_URL = "http://localhost:8000"

# Without protocol (auto-detects based on DEBUG setting)
NOTIFICATION_BASE_URL = "www.example.com"

Protocol handling: If you omit the protocol, it's automatically added:

  • https:// in production (DEBUG = False)
  • http:// in development (DEBUG = True)

Fallback order if NOTIFICATION_BASE_URL is not set:

  1. BASE_URL setting
  2. SITE_URL setting
  3. Django Sites framework (if django.contrib.sites is installed)
  4. URLs remain relative if no base URL is found (not ideal in emails!)

Quick Start

1. Define a notification type

# myapp/notifications.py
from generic_notifications.types import NotificationType, register

@register
class CommentNotification(NotificationType):
    key = "comment"
    name = "Comment Notifications"
    description = "When someone comments on your posts"

2. Send a notification

from generic_notifications import send_notification
from myapp.notifications import CommentNotification

# Send a notification (only `recipient` and `notification_type` are required)
notification = send_notification(
    recipient=post.author,
    notification_type=CommentNotification,
    actor=comment.user,
    target=post,
    subject=f"{comment.user.get_full_name()} commented on your post",
    text=f"{comment.user.get_full_name()} left a comment: {comment.text[:100]}",
    url=f"/posts/{post.id}#comment-{comment.id}",
)

3. Working with notifications

from generic_notifications.channels import WebsiteChannel
from generic_notifications.models import Notification
from generic_notifications.lib import get_unread_count, get_notifications, mark_notifications_as_read

# Get unread count for a user
unread_count = get_unread_count(user=user, channel=WebsiteChannel)

# Get unread notifications for a user
unread_notifications = get_notifications(user=user, channel=WebsiteChannel, unread_only=True)

# Get notifications by channel
website_notifications = Notification.objects.prefetch().for_channel(WebsiteChannel)

# Mark as read
notification = website_notifications.first()
notification.mark_as_read()

# Mark all as read
mark_notifications_as_read(user=user)

4. Set up email digest sending

Create a cron job to send daily digests:

# Send daily digests at 9 AM
0 9 * * * cd /path/to/project && uv run ./manage.py send_notification_digests --frequency daily

If you already have a way to run scheduled jobs in your Django app and don't want to start a management command via a cron job, you can call the send_notification_digests function directly:

from generic_notifications.digest import send_notification_digests
from generic_notifications.frequencies import DailyFrequency

send_notification_digests(frequency=DailyFrequency, dry_run=False)

Example App

An example app is provided, which shows how to create a custom notification type, how to send a notification, it has a nice looking notification center with unread notifications as well as an archive of all read notifications, plus a settings view where you can manage notification preferences.

cd example
uv run ./manage.py migrate
uv run ./manage.py runserver

Then open http://127.0.0.1:8000/.

Admin Integration

While the library doesn't register admin classes by default, the example app includes admin configuration that you can copy into your project for debugging and monitoring purposes.

Further Documentation

License

MIT License - see LICENSE file for details.

Support

Commercial support is available via Loopwerk.

Metadata

Release files for django-generic-notifications 2.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-generic-notifications 2.4.0
File Size Uploaded Provenance
django_generic_notifications-2.4.0.tar.gz 19.4 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-generic-notifications 2.4.0
File Interpreter ABI Platform
django_generic_notifications-2.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 48.4 kB

Release files / django_generic_notifications-2.4.0.tar.gz

Download URL django_generic_notifications-2.4.0.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e83e21c2021d96042cb8d0971b40b43e49d35f423179cc41b8f70f41781d284d
BLAKE2b-256 checksum
How to use checksums
92c66b2abd8a9f7127df2524432848ace55c7424045c1814f777754d0b298502
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Release files / django_generic_notifications-2.4.0-py3-none-any.whl

Download URL django_generic_notifications-2.4.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63e5ce18eb5cab05fa4b15fce8f97cd5d82aab77360fa2513f8d92a49b8ddc3b
BLAKE2b-256 checksum
How to use checksums
8fc5db960de5e7f5d5a386c8afe7aa807e7bf28ad4f1234558ac110508cede05
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

Security for django-generic-notifications 2.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_generic_notifications-2.4.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 14, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page