Registry / workflow / dramatiq

dramatiq

JSON →
library2.2.0pypypi✓ verified 27d ago

Dramatiq is a fast, robust, and performant Python 3 background task processing library. It allows you to defer functions to run in the background, typically using message brokers like Redis or RabbitMQ. Currently at version 2.1.0, it maintains an active development cycle with frequent minor releases and occasional major versions introducing breaking changes.

pip install dramatiq
INSTALL
IMPORT
SIG · DRAMATIQ
D
dramatiq
workflowpythonv2.2.0
Install
1.8s avg
Import
273ms
Disk
22MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.2.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.915 runs
installs and imports cleanly · install 0.0s · import 0.281s · 23.8MB
glibc
py 3.10–3.915 runs
installs and imports cleanly · install 1.8s · import 0.265s · 24MB
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

actor
✓ from dramatiq import actor
set_broker
✓ from dramatiq import set_broker
Broker
✓ from dramatiq import Broker
RedisBroker
✓ from dramatiq.brokers.redis import RedisBroker
RabbitmqBroker
✓ from dramatiq.brokers.rabbitmq import RabbitmqBroker
StubBroker
✓ from dramatiq.brokers.stub import StubBroker
ResultMiddleware
✓ from dramatiq.middleware import ResultMiddleware

This quickstart demonstrates defining and sending a task using Dramatiq with a `StubBroker` for synchronous, in-process execution, ideal for testing. For production, you would configure a `RedisBroker` or `RabbitmqBroker` and run a separate `dramatiq worker` process to consume tasks.

import dramatiq from dramatiq.brokers.stub import StubBroker import time import os # Configure the stub broker for local testing and synchronous processing # Note: StubBroker processes tasks directly without a separate worker process. # For real applications, use RedisBroker, RabbitmqBroker, etc., with 'pip install dramatiq[broker]'. broker = StubBroker() dramatiq.set_broker(broker) @dramatiq.actor def my_task(name): print(f"[Task] Starting task for {name}...") time.sleep(0.01) # Simulate some work print(f"[Task] Task for {name} completed.") return f"Hello, {name}!" # Send a message to the broker print("Sending message...") message = my_task.send("World") print(f"Sent message with ID: {message.message_id}") # With StubBroker, you can explicitly process pending messages # In a real application, a 'dramatiq worker' process would handle this. broker.join(drop_messages=True) # Process all pending messages print("All stub broker messages processed.") # If ResultMiddleware and a backend were configured, you could retrieve results: # try: # result = message.get_result(block=True, timeout=1) # print(f"Task result: {result}") # except Exception as e: # print(f"Could not get result: {e}")
dramatiq --version
Debug
Known issues
breakingIn v2.0.0, the `ResultMiddleware` constructor now requires a `backend` argument. Previously, it would implicitly try to infer one or default.
fix
Pass a backend instance (e.g., `RedisBackend()`) when initializing `ResultMiddleware`: `ResultMiddleware(backend=RedisBackend())`.
affects: >=2.0.0
breakingIn v2.0.0, the `StubBroker.join()` `fail_fast` parameter's default value changed from `False` to `True`. This means `join()` will now raise an exception immediately on task failure.
fix
If you relied on the previous behavior where `join()` would attempt to process all tasks regardless of individual failures, explicitly set `fail_fast=False` when calling `StubBroker.join()`.
affects: >=2.0.0
gotchaUsing Gevent with free-threaded Python (e.g., Python 3.13+) is not recommended by Dramatiq and can lead to unexpected behavior. Dramatiq will issue a warning if this combination is detected.
fix
Avoid using Gevent with free-threaded Python versions. Consider alternative concurrency models or using a standard Python runtime if Gevent is critical.
affects: >=2.1.0
gotchaDramatiq relies on a global broker instance configured via `dramatiq.set_broker()`. In multi-application environments, tests, or concurrent contexts, careful management is needed to ensure the correct broker is active for each operation.
fix
Always call `dramatiq.set_broker()` explicitly at the entry point of your application or test setup. In tests, use distinct broker instances and reset them as necessary for isolation.
affects: All versions
gotchaSpecific broker backends (e.g., Redis, RabbitMQ) and other features (e.g., Prometheus metrics) are installed via optional 'extras' (e.g., `pip install dramatiq[redis]`). Forgetting these will result in `ModuleNotFoundError` or similar import errors.
fix
Ensure you install the required extras for your chosen broker and features: `pip install dramatiq[redis]` or `pip install dramatiq[rabbitmq]`.
affects: All versions
Errors
Common errors & fixes
dramatiq.errors.ActorNotFound: <actor_name>
The Dramatiq worker received a message for an actor that has not been properly declared or imported into the worker's scope, meaning the worker process cannot find the definition of the requested actor.
fix
Ensure that the module containing the `@dramatiq.actor` decorated functions is loaded by the worker. When running the `dramatiq` worker CLI, specify the module path (e.g., `dramatiq my_app.tasks` if your actors are in `my_app/tasks.py`).
Consumer encountered a connection error: Error <error_code> connecting to <broker_address>. Connection refused.
The Dramatiq worker or producer failed to establish a connection with the configured message broker (Redis or RabbitMQ), often due to the broker not running, incorrect host/port, or network issues.
fix
Verify that your message broker service (Redis or RabbitMQ) is running and is accessible from where Dramatiq is being executed. Double-check the broker URL/host/port configuration in your Dramatiq setup code, for example: `broker = RedisBroker(host='your_redis_host', port=6379)`.
TypeError: Object of type <type> is not JSON serializable
Dramatiq uses JSON for message serialization by default, and this error occurs when an actor is sent arguments that are not natively JSON-serializable (e.g., `datetime.datetime` objects, custom class instances).
fix
Convert non-JSON-serializable arguments to a serializable format (e.g., `datetime` objects to ISO 8601 strings or timestamps) before sending the message. Alternatively, implement a custom JSON encoder and decoder and configure Dramatiq to use it via `dramatiq.set_encoder(MyCustomEncoder())`.
ModuleNotFoundError: No module named '<module_name>'
When running the `dramatiq` CLI worker, the specified module containing actors cannot be found in Python's `sys.path`, or the command was used with a `.py` file extension which is incorrect for module paths.
fix
Ensure that the directory containing your module is on Python's path (e.g., by running from the correct working directory or configuring `PYTHONPATH`). When using the `dramatiq` CLI, provide the module name without the `.py` extension (e.g., `dramatiq my_app.tasks` instead of `dramatiq my_app/tasks.py`).
Upgrade
Version history
2.2.0latest on PyPI · released Jun 17, 2026
Audit
Dependencies
redisoptionalRedis broker backend. Required for `RedisBroker`.
pikaoptionalRabbitMQ broker backend. Required for `RabbitmqBroker`.
prometheus_clientoptionalPrometheus metrics integration.
Agent activity
31 hits · last 30 days
node
28
OpenAI (training)
1
Resources
dramatiq — pip install dramatiq · libregistry