Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Django AMQP

AMQP support for Django, with implementations for RabbitMQ and Azure ServiceBus.

Overview

Django AMQP is an extension for Django that provides Advanced Message Queuing Protocol (AMQP) support. It enables you to easily implement message queues and task processing in your Django applications using either RabbitMQ or Azure Service Bus as the backend.

The library integrates with Django's task framework, allowing you to define, queue, and process asynchronous tasks with support for scheduled/deferred execution.

Installation

pip install django-amqp

OR

uv add django-amqp

Configuration

Add django_amqp to your INSTALLED_APPS in settings.py:

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

Configure your task backend in settings.py:

SERVICEBUS_CONNECTION_STRING = os.environ.get("SERVICEBUS_CONNECTION_STRING")

TASKS = {
    "default": {
        "BACKEND": "django_amqp.backend.ServiceBusBackend",
        "QUEUES": [
            "default",
        ],
        "OPTIONS": {"connection_string": SERVICEBUS_CONNECTION_STRING},
    }
}

Usage

Defining Tasks

Create a task using Django's task decorator:

from django.tasks import task

@task(queue_name="my-queue")
def my_background_task(param1, param2, **kwargs):
    # Your task logic here
    pass

NOTE: queue_name defaults to "default" (as per django tasks implementation). You may want to name your main worker ServiceBus/RabbitMQ queue as "default" to match this. Otherwise, specifyqueue_name for each task.*

Queueing Tasks

Queue a Task for Immediate Execution

from myapp.tasks import my_background_task

# Queue for immediate execution
my_background_task.enqueue(param1="value1", param2="value2")

you can also batch queue

from myapp.tasks import my_background_task

# Batch Queue for immediate execution
my_background_task.get_backend().batch_enqueue(
    my_background_task, [
            ([], {param1="value1", param2="value2"}),
            ([], {param1="value3", param2="value4"})
        ]
)
# It's more performant to queue many messages at once, instead of making a connection
# for each

Queue and Cancel a Task for Delayed Execution

You can cancel scheduled messages using the sequence number returned when scheduling a message:

from django_amqp.service_bus import cancel_deferred_message

# Schedule a task and get the sequence number
sequence_number = my_background_task.delay_until(future_time, param1="value1")

# Later, if you need to cancel it
cancel_deferred_message(sequence_number, queue_name="my-queue")

Running Workers

To process messages from a specific queue:

python manage.py amqp_worker --queue-name="my-queue" --burst

The --burst flag tells the worker to process all available messages and then exit.

Error Handling

When using the ServiceBus Backend, failed tasks are automatically moved to the dead-letter queue with the error reason and description. You can implement additional error handling in your task functions.

License

This project is licensed under the BSD 3-Clause License - see the LICENSE file for details.

Metadata

Release files for django-amqp 0.1.1a1

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-amqp 0.1.1a1
File Size Uploaded
django_amqp-0.1.1a1.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-amqp 0.1.1a1
File Interpreter ABI Platform
django_amqp-0.1.1a1-py3-none-any.whl Python 3 none any Details

Total release size: 21.5 kB

Release files / django_amqp-0.1.1a1.tar.gz

Download URL django_amqp-0.1.1a1.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
e399231aa1e433728dd9f6c0c8a648f936bf4797a8f7643479687488f9f83d86
BLAKE2b-256 checksum
How to use checksums
5a8b4709078d8426a40ce580541c0f2aa291fbf63b80564ec37d52296ea6596d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / django_amqp-0.1.1a1-py3-none-any.whl

Download URL django_amqp-0.1.1a1-py3-none-any.whl
Size 9.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51f0206e211255b6d7a4ae921b958eadca5c3aedda89e3944008e908aa7f127b
BLAKE2b-256 checksum
How to use checksums
8b25f1c72057a61ade8b9a8f96b4fa8198f54080510c6a78a242aa14c301d021
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.22 {"installer":{"name":"uv","version":"0.9.22","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
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