Skip to main content

Logo

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

RabbitMQ Support


Tests 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 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.3.

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 commandssetup_rabbitmq_topology (idempotent exchange/queue/binding setup) and start_consumers (threaded runner with graceful SIGTERM/SIGINT shutdown).
  • 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.
  • Fully typed — ships py.typed; compatible with pyrefly and standard type checkers.

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

Full reference, configuration guide, reliability details, and more:

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


Testing

Unit tests

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

uv run pytest

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
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).


License

MIT


Support project

Cryptocurrency & Bitcoin donation button by NOWPayments

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_rmq-1.0.5.tar.gz (36.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_rmq-1.0.5-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file django_rmq-1.0.5.tar.gz.

File metadata

  • Download URL: django_rmq-1.0.5.tar.gz
  • Upload date:
  • Size: 36.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for django_rmq-1.0.5.tar.gz
Algorithm Hash digest
SHA256 e96d372c305f1e3a6c59611fb50db7a431edb0f24fac119443e3419e8538cfd0
MD5 f7ae7d5a405775113f044f841c34463f
BLAKE2b-256 76ed9e6adb31544fb43ddc75a68830714ac1596b2e9ef14622587e3e4c937845

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_rmq-1.0.5.tar.gz:

Publisher: publish.yml on RDDLab/Django-RMQ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_rmq-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: django_rmq-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for django_rmq-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9d76c82cb3067121ec7f55421f3ae68027c69e1f35ea253e2a75e21f2ad071fb
MD5 c96d5b45d9835c6facd0c5c244d1fa59
BLAKE2b-256 ea1a1d538826603370d6cdf9bad24130b17b3ad915af24fc1463eb1424bde65a

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_rmq-1.0.5-py3-none-any.whl:

Publisher: publish.yml on RDDLab/Django-RMQ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.5 This release

2 files

1.0.4

2 files

1.0.3

2 files

1.0.2

2 files

0.0.1

2 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