Django adapter

The Django adapter wires the BabelQueue runtime into a Django project via settings, with helpers to publish from your code and a management command to run the worker.

Install

pip install "babelqueue[django]"

The [django] extra adds django>=4.2. Add the app to INSTALLED_APPS:

# settings.py
INSTALLED_APPS = [
    # ...
    "babelqueue.django",
]

Configure

A single BABELQUEUE settings dict configures the runtime. broker_url selects the transport; the other recognised keys (queue, on_unknown_urn, max_attempts, dead_letter, dead_letter_queue, dead_letter_suffix, transport) are forwarded to the runtime:

# settings.py
BABELQUEUE = {
    "broker_url": "redis://localhost:6379/0",
    "queue": "orders",
    "dead_letter": True,
}

Publish

# views.py
from babelqueue.django import publish

def create_order(request):
    publish("urn:babel:orders:created", {"order_id": 1042})
    ...

publish(urn, data, **kwargs) → str returns the message meta.id, using the process-wide app from get_app().

Register handlers

Register handlers into the same app the worker uses — the app config’s ready() is the natural place:

# apps.py
from django.apps import AppConfig
from babelqueue.django import get_app

class MyAppConfig(AppConfig):
    name = "myapp"

    def ready(self):
        @get_app().handler("urn:babel:orders:created")
        def on_created(data, meta):
            ...

Run the worker

python manage.py babelqueue_worker --queue orders

Options: --queue (defaults to the configured queue), --max-messages (default: run until interrupted), --timeout (per-poll seconds, default 1.0).

The messages your Django app produces and consumes are the canonical envelope, interoperable with every BabelQueue SDK.