Django RabbitMQ Wrappers & Tools over Pika
Project description
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_CONNECTIONSinsettings.py, one entry per alias. ProducerandConsumerwrappers — thin classes over Pika's blocking connection that handle channel lifecycle and lazy queue declaration.- Decorator-style publishing — use a
Producerinstance as a@producerdecorator to auto-publish a function's return value. - Reliable delivery — publisher confirms,
mandatory=True, anddelivery_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) andstart_consumers(threaded runner with graceful SIGTERM/SIGINT shutdown). - Multiple connections — configure several broker aliases and select per producer/consumer via
using=. - 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,
},
}
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
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 django_rmq-1.0.3.tar.gz.
File metadata
- Download URL: django_rmq-1.0.3.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e69cdcb037f1452627058d734719c6f75b4d2c211f54337e410c61951fc7992f
|
|
| MD5 |
45428ca783865a539b8efd48c1db3264
|
|
| BLAKE2b-256 |
801a7c7ca0ba6d047c3be745b4fad4117956c309829a105f58f2b46788386104
|
Provenance
The following attestation bundles were made for django_rmq-1.0.3.tar.gz:
Publisher:
publish.yml on RDDLab/Django-RMQ
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_rmq-1.0.3.tar.gz -
Subject digest:
e69cdcb037f1452627058d734719c6f75b4d2c211f54337e410c61951fc7992f - Sigstore transparency entry: 2105360032
- Sigstore integration time:
-
Permalink:
RDDLab/Django-RMQ@a504bc587d57fd8104a240eb03daa17b7b78edfd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RDDLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish.yml@a504bc587d57fd8104a240eb03daa17b7b78edfd -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file django_rmq-1.0.3-py3-none-any.whl.
File metadata
- Download URL: django_rmq-1.0.3-py3-none-any.whl
- Upload date:
- Size: 29.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a9b843a486b16ae22d74005bea28c57cf255256e4b7231e84ef058e87d8600f
|
|
| MD5 |
e23a4d2ac145f4ec9881f98fe37f274c
|
|
| BLAKE2b-256 |
287a08e3894eee349af436cbd3510026ef3cd00110fbba55ea1f67449a68fdd6
|
Provenance
The following attestation bundles were made for django_rmq-1.0.3-py3-none-any.whl:
Publisher:
publish.yml on RDDLab/Django-RMQ
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_rmq-1.0.3-py3-none-any.whl -
Subject digest:
6a9b843a486b16ae22d74005bea28c57cf255256e4b7231e84ef058e87d8600f - Sigstore transparency entry: 2105360343
- Sigstore integration time:
-
Permalink:
RDDLab/Django-RMQ@a504bc587d57fd8104a240eb03daa17b7b78edfd -
Branch / Tag:
refs/heads/main - Owner: https://github.com/RDDLab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
self-hosted -
Publication workflow:
publish.yml@a504bc587d57fd8104a240eb03daa17b7b78edfd -
Trigger Event:
workflow_dispatch
-
Statement type: