Skip to main content

Django Gotify

Django CI PyPI version Python Versions License

Self-hosted push notifications and alerting for your Django projects.

django-gotify is a lightweight package that integrates your Django application with a Gotify server. It provides a custom Email Backend to send standard Django emails as push notifications, a built-in Logging Handler to instantly alert your devices about server errors and warnings, and a management command to verify your Gotify connection.

Features

  • Email Backend Integration: Acts as a drop-in replacement for Django's default email backend. Send notifications using standard send_mail() calls.
  • Smart Logging Handler: Automatically routes Django logs to Gotify. It intelligently maps Python log levels (DEBUG, ERROR, CRITICAL) to Gotify message priorities.
  • Connection Check: check_gotify management command verifies connectivity to your Gotify server.
  • Programmatic API: check_connection() and get_gotify_client() — reusable functions to verify connectivity and construct clients from any Python code.
  • Thread-Safe: Safely processes and sends multiple messages concurrently.
  • Fail Silently Support: Respects Django's fail_silently flag to prevent notification errors from crashing your application.
  • Markdown Support: Send formatted messages via X-Gotify-Markdown header or markdown content subtype.

Installation

Install via pip:

pip install django-gotify

(Note: You only need to add 'django_gotify' to INSTALLED_APPS temporarily to use the check_gotify management command. For normal backend/handler usage it is not required.)

Configuration

Add your Gotify server credentials to your settings.py:

GOTIFY_URL = 'http://127.0.0.1:6543'
GOTIFY_TOKEN = 'your_app_token'       # For logging and create_message
GOTIFY_CLIENT = 'your_client_token'   # Optional, for client-authenticated endpoints

Usage

1. Email Backend

To route all outgoing Django emails to Gotify, update your email backend in settings.py:

EMAIL_BACKEND = 'django_gotify.GotifyEmailBackend'

On Django 6.1+ the EMAIL_* settings are deprecated in favor of the new MAILERS setting. The same configuration with MAILERS looks like:

MAILERS = {
    'default': {
        'BACKEND': 'django_gotify.GotifyEmailBackend',
        'OPTIONS': {
            # Optional — fall back to the GOTIFY_* settings when omitted.
            'base_url': 'http://127.0.0.1:6543',
            'app_token': 'your_app_token',
            'client_token': 'your_client_token',  # optional
            'fail_silently': False,               # optional
        },
    },
}

OPTIONS entries take precedence over the GOTIFY_URL, GOTIFY_TOKEN, and GOTIFY_CLIENT settings. On Django < 6.1 the MAILERS setting is ignored and the classic EMAIL_BACKEND + GOTIFY_* configuration is used.

Now, anytime you use Django's send_mail(), it will appear as a push notification:

from django.core.mail import send_mail

send_mail(
    subject="New User Registration",
    message="A new user just signed up on the platform.",
    from_email=None,
    recipient_list=[],  # Not required for Gotify
)

2. Logging Handler

To get real-time alerts for server errors, add the Gotify handler to your LOGGING configuration in settings.py:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'gotify': {
            'level': 'ERROR',
            'class': 'django_gotify.GotifyLogHandler',
        },
    },
    'loggers': {
        'django': {
            'handlers': ['gotify', 'console'],
            'level': 'ERROR',
            'propagate': True,
        },
    },
}

Log levels are automatically mapped to Gotify priorities:

Python level Gotify priority
DEBUG 2
INFO, WARNING 5
ERROR 8
CRITICAL 9

3. Connection Check

Management command

Temporarily add 'django_gotify' to INSTALLED_APPS, then run:

python manage.py check_gotify

The command validates that GOTIFY_URL and GOTIFY_TOKEN are configured and verifies connectivity to your Gotify server. If settings are missing, it prints guidance on how to configure them.

Programmatic API

Use from any Python code without adding to INSTALLED_APPS:

from django_gotify import check_connection, get_gotify_client

# Verify connectivity
ok, message, health = check_connection()
if not ok:
    print(f"Gotify is not reachable: {message}")

# Get a configured client
client = get_gotify_client()
client.create_message(
    message="Hello from code!",
    title="Programmatic Message",
    priority=5,
)

4. Message Priority & Markdown

Control priority and formatting via EmailMessage headers:

from django.core.mail import EmailMessage

msg = EmailMessage(
    subject="**Important** alert",
    body="Server disk usage exceeded **90%**",
    to=["ops@example.com"],
    headers={
        "X-Gotify-Priority": "8",
        "X-Gotify-Markdown": "true",
    },
)
msg.send()

Alternatively, use content_subtype="markdown" on the message.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Development setup

git clone https://github.com/swayll/django-gotify.git
cd django-gotify
python -m venv venv && source venv/bin/activate
pip install -e .
pip install -r requirements.txt
pre-commit install

Running checks

python runtests.py                 # Run test suite
ruff check .                       # Lint
ruff format --check .              # Format check
ruff format .                      # Auto-format

License

MIT

Metadata

Release files for django-gotify 0.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-gotify 0.4.0
File Size Uploaded
django_gotify-0.4.0.tar.gz 11.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-gotify 0.4.0
File Interpreter ABI Platform
django_gotify-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.1 kB

Release files / django_gotify-0.4.0.tar.gz

Download URL django_gotify-0.4.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
85c961d6d2d11583833f61b12a0ba0f2d211ee3272483885a0047bd6dcae1996
BLAKE2b-256 checksum
How to use checksums
407dafe4069cdcfeb1f54f424b315c0493119e25e05c9f753ecfde000b7fffcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 9, 2026.

Transparency log

Release files / django_gotify-0.4.0-py3-none-any.whl

Download URL django_gotify-0.4.0-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f8317fdeec70571e2c3323d5e2328cb275e64770da232b5727ecd5e6babb582
BLAKE2b-256 checksum
How to use checksums
5ff53f5983f869f4c0d0f13c0868b94e286ff2d8f021f40cd6100f24e69c4521
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Aug 9, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

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