Skip to main content
Django-RMQ

License: MIT Ruff pyrefly PyPI PyPI pyversions PyPI djversions PyPI status PyPI - Downloads PyPI - Types

RabbitMQ Support


CI OpenSSF Best Practices Codecov pre-commit.ci status


Documentation: https://django-rmq.rdd-lab.com/

Source Code: https://github.com/RDDLab/Django-RMQ


Django-RMQ

Django-RMQ 1.1.7 adds Python 3.15 support with Django 6.1.3 or later.

Django-RMQ provides RabbitMQ wrappers and tools for Django projects, built on top of Pika. It is a lightweight integration layer — not a task queue or a Celery replacement — for projects that need to publish and consume messages while keeping broker infrastructure code predictable and close to the Django configuration. Supports RabbitMQ 3.13–4.4.

Features

  • Django-native settings — configure broker connections via RABBITMQ_CONNECTIONS in settings.py, one entry per alias.
  • Producer and Consumer wrappers — thin classes over Pika's blocking connection that handle channel lifecycle and lazy queue declaration.
  • Decorator-style publishing — use a Producer instance as a @producer decorator to auto-publish a function's return value.
  • Reliable delivery — publisher confirms, mandatory=True, and delivery_mode=2 (persistent) are enforced on every message.
  • Auto-reconnect with backoff — producers retry once on transient channel errors; consumers reconnect with exponential backoff capped at a configurable maximum.
  • Dead-letter routing — declare queues with QueueConfig(dead_letter_exchange=...) so unhandled messages are nacked without requeue and routed to a DLX.
  • Management commands — setup_rabbitmq_topology (idempotent exchange/queue/binding setup), start_consumers (threaded runner with graceful SIGTERM/SIGINT shutdown), and check_rabbitmq_connections (healthcheck for container probes).
  • Multiple connections — configure several broker aliases and select per producer/consumer via using=.
  • RabbitMQ clusters — point one alias at several nodes via NODES for client-side failover; pika tries each node until one connects. Optional SHUFFLE_NODES spreads clients across the cluster; per-alias SOCKET_TIMEOUT/STACK_TIMEOUT give faster failover.
  • Fully typed — ships py.typed; compatible with pyrefly and standard type checkers.

Compatibility

Python Minimum Django in CI
3.10–3.11 4.2
3.12 4.2.8
3.13 5.1.3
3.14 5.2.8
3.15 6.1.3

CI tests these minimum Django versions and the versions selected by uv.lock. Django-RMQ supports RabbitMQ 3.13–4.4 and installs Pika (>=1.4.1,<2.0) automatically.

Installation

pip install django-rmq

Add 'django_rmq' to INSTALLED_APPS and configure at least one connection alias:

INSTALLED_APPS = [
    # ...
    'django_rmq',
]

RABBITMQ_CONNECTIONS = {
    'default': {
        'HOST': 'localhost',
        'PORT': 5672,
        'VIRTUAL_HOST': '/',
        'USER': 'guest',
        'PASSWORD': 'guest',
        'HEARTBEAT': 600,
        'BLOCKED_CONNECTION_TIMEOUT': 300,
        'RECONNECT_INITIAL_BACKOFF': 1.0,
        'RECONNECT_MAX_BACKOFF': 30.0,
    },
}

For multi-node clusters, use a NODES list instead of HOST/PORT — see the Clusters guide.

Quick start

Publish a message:

from django_rmq.producer import Producer

Producer(queue='orders').publish(body='{"order_id": 42}')

Consume messages (e.g. myapp/consumers.py):

from pika.adapters.blocking_connection import BlockingChannel
from pika.spec import Basic, BasicProperties

from django_rmq.consumer import Consumer
from django_rmq.registries.registry import get_consumers_registry

consumer: Consumer = Consumer(queue='orders')


@consumer
def handle_order(
    ch: BlockingChannel,
    method: Basic.Deliver,
    props: BasicProperties,
    body: bytes,
) -> None:
    print(body)
    ch.basic_ack(delivery_tag=method.delivery_tag)


get_consumers_registry().register(consumer=consumer)

Import consumers.py inside your app's AppConfig.ready(), then start consuming:

uv run python manage.py start_consumers

Documentation

Read the documentation for configuration, reliability, and the API reference.

Use the Node.js version in .nvmrc and install the pinned npm version before building both locales.

cd docs
npm install --global "$(node -p 'require("./package.json").packageManager')"
npm ci
npm run docs:typecheck
npm run docs:build

Documentation deployment covers the GitHub Actions environment and server setup.


Testing

GitHub Actions runs security checks on pull requests and pushes. On main, CI continues with unit tests, the RabbitMQ integration and cluster matrices, package builds, and documentation checks. Other protected branches run the same tests after a successful push scan. PyPI publishing and documentation deployment require a successful run for the selected commit.

Unit tests

Unit tests mock pika and need no broker. They run by default — integration tests are marked integration and deselected:

uv run pytest
uv run --locked --python 3.15 pytest

On Python 3.15, CI runs the unit suite with both locked Django and the minimum Django 6.1.3. The single-broker integration tests and the three-node cluster tests also run on Python 3.15.

Integration tests

Integration tests run against a real RabbitMQ broker. The repo ships a .github/docker-compose.yml that starts the same image CI uses (with the management plugin the suite needs on port 15672). Connection params are read from RMQ_* env vars (defaults: localhost:5672, guest/guest, vhost /), which already match the Compose service:

docker compose -f .github/docker-compose.yml up -d --wait    # start the broker, block until healthy
uv run pytest -m "integration and not cluster"
docker compose -f .github/docker-compose.yml down            # stop it when done

The suite isolates itself with per-test uuid-suffixed queues/exchanges and cleans them up, so it is safe against a shared broker (use a dedicated vhost).

For failover tests, start the three-node cluster after stopping the single broker:

docker compose -f .github/docker-compose.cluster.yml up -d --wait
docker compose -f .github/docker-compose.cluster.yml exec -T rabbit1 rabbitmqctl await_online_nodes 3 --timeout 60
uv run pytest -m cluster
docker compose -f .github/docker-compose.cluster.yml down -v

License

MIT


Support project

Cryptocurrency & Bitcoin donation button by NOWPayments

Metadata

Release files for django-rmq 1.1.7

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-rmq 1.1.7
File Size Uploaded Provenance Actions
django_rmq-1.1.7.tar.gz 47.7 kB With provenance Details for django_rmq-1.1.7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-rmq 1.1.7
File Interpreter ABI Platform Actions
django_rmq-1.1.7-py3-none-any.whl Python 3 none any Details for django_rmq-1.1.7-py3-none-any.whl

Total release size: 87.4 kB

Release files / django_rmq-1.1.7.tar.gz

Download URL django_rmq-1.1.7.tar.gz
Size 47.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2287edfb36345449e66eaf2482b3513398a2c41091399257601e45c6cde65492
BLAKE2b-256 checksum
How to use checksums
b872d149a2de72bc23c72639688c75d5fb8e91445689dada85d0411edf634bfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / django_rmq-1.1.7-py3-none-any.whl

Download URL django_rmq-1.1.7-py3-none-any.whl
Size 39.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1b57f0d86584f8ce20eb9c7dbd5dfcccd3fee76888ba2187dd62235ffc670225
BLAKE2b-256 checksum
How to use checksums
7582b8f2aa245981c6210c511f7cf6a959cf3de1068fd1fade6041fbc083d18c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for django-rmq 1.1.7

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_rmq-1.1.7.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 Nov 26, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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