Top Related Projects
Quick Overview
Dramatiq is a distributed task processing library for Python. It's designed to be simple, reliable, and high-performance, allowing developers to easily distribute tasks across multiple workers. Dramatiq supports multiple brokers, including RabbitMQ and Redis, and provides features like automatic retries, rate limiting, and prioritization.
Pros
- Simple and intuitive API, making it easy to integrate into existing projects
- High performance and scalability, capable of processing millions of tasks per day
- Built-in support for multiple brokers (RabbitMQ, Redis)
- Robust features like automatic retries, rate limiting, and prioritization
Cons
- Relatively young project compared to alternatives like Celery
- Limited ecosystem and third-party integrations
- Requires additional infrastructure setup (broker) for distributed processing
- Documentation could be more comprehensive for advanced use cases
Code Examples
- Defining and enqueuing a task:
import dramatiq
@dramatiq.actor
def add(a, b):
return a + b
# Enqueue the task
add.send(1, 2)
- Using middleware for rate limiting:
from dramatiq.rate_limits import RateLimiter
from dramatiq.rate_limits.backends import RedisBackend
redis_backend = RedisBackend()
rate_limiter = RateLimiter(redis_backend, "my-limit", limit=10, window=60000)
@dramatiq.actor(rate_limiter=rate_limiter)
def limited_task():
print("This task is rate limited")
- Setting up a custom broker:
from dramatiq.brokers.rabbitmq import RabbitmqBroker
rabbitmq_broker = RabbitmqBroker(url="amqp://guest:guest@localhost:5672")
dramatiq.set_broker(rabbitmq_broker)
Getting Started
- Install Dramatiq:
pip install dramatiq[rabbitmq,watch]
- Create a file named
tasks.py
:
import dramatiq
@dramatiq.actor
def hello(name):
print(f"Hello, {name}!")
if __name__ == "__main__":
hello.send("World")
- Run a worker:
dramatiq tasks
- In another terminal, run your script:
python tasks.py
This will enqueue and process the "Hello, World!" task.
Competitor Comparisons
Distributed Task Queue (development branch)
Pros of Celery
- More mature and widely adopted, with a larger ecosystem and community support
- Supports a wider range of message brokers and result backends
- Offers more advanced features like task routing, periodic tasks, and task prioritization
Cons of Celery
- More complex configuration and setup process
- Steeper learning curve for beginners
- Heavier resource usage, especially for smaller projects
Code Comparison
Celery task definition:
from celery import Celery
app = Celery('tasks', broker='redis://localhost:6379')
@app.task
def add(x, y):
return x + y
Dramatiq task definition:
import dramatiq
@dramatiq.actor
def add(x, y):
return x + y
Dramatiq offers a simpler API and configuration process, making it easier to get started with task queues. However, Celery provides more advanced features and flexibility for complex use cases. Both libraries are suitable for distributed task processing, but the choice depends on project requirements and complexity.
Simple job queues for Python
Pros of RQ
- Simpler setup and configuration, making it easier for beginners
- Tighter integration with Redis, which can be beneficial for Redis-centric architectures
- More mature project with a larger community and ecosystem
Cons of RQ
- Limited to Redis as the only supported broker
- Lacks some advanced features like middleware and actor-based programming model
- May have lower performance for high-throughput scenarios compared to Dramatiq
Code Comparison
RQ:
from rq import Queue
from redis import Redis
q = Queue(connection=Redis())
job = q.enqueue(my_function, arg1, arg2)
Dramatiq:
import dramatiq
from dramatiq.brokers.redis import RedisBroker
broker = RedisBroker()
dramatiq.set_broker(broker)
@dramatiq.actor
def my_function(arg1, arg2):
pass
my_function.send(arg1, arg2)
Both RQ and Dramatiq are popular Python task queue libraries, but they have different approaches and feature sets. RQ is simpler and more Redis-focused, while Dramatiq offers more flexibility and advanced features. The choice between them depends on specific project requirements and preferences.
a little task queue for python
Pros of Huey
- Simpler setup and configuration, making it easier for beginners
- Supports both Redis and SQLite as task storage backends
- Lightweight with minimal dependencies
Cons of Huey
- Less robust error handling and retry mechanisms
- Limited support for distributed task execution
- Fewer built-in middleware options
Code Comparison
Huey task definition:
@huey.task()
def my_task(param):
return do_something(param)
Dramatiq task definition:
@dramatiq.actor
def my_task(param):
return do_something(param)
Both libraries use decorators to define tasks, but Dramatiq uses the term "actor" instead of "task". Huey's syntax is slightly more concise, while Dramatiq offers more options for configuring actors.
Huey is generally simpler to set up and use, making it a good choice for smaller projects or those new to task queues. Dramatiq, on the other hand, provides more advanced features and better scalability for larger, distributed systems. The choice between the two depends on the specific requirements of your project and your familiarity with task queue systems.
Real-time monitor and web admin for Celery distributed task queue
Pros of Flower
- Web-based UI for monitoring and managing Celery tasks
- Supports real-time updates and task filtering
- Integrates well with existing Celery-based systems
Cons of Flower
- Limited to Celery task queue systems
- Requires additional setup and configuration
- May introduce overhead in production environments
Code Comparison
Flower (task monitoring):
from flower.views import tasks
@tasks.route('/api/task/<task_id>', methods=['GET'])
def get_task_info(task_id):
task = tasks.get_task_by_id(task_id)
return jsonify(task.as_dict())
Dramatiq (task definition):
import dramatiq
@dramatiq.actor
def process_data(data):
# Process the data
result = perform_complex_operation(data)
return result
Flower focuses on monitoring and managing Celery tasks through a web interface, while Dramatiq is a task processing library that provides an alternative to Celery. Flower offers a user-friendly way to visualize and interact with Celery tasks, whereas Dramatiq emphasizes simplicity and performance in task processing.
Dramatiq provides a more straightforward approach to defining and executing tasks, with less boilerplate code compared to Celery. However, it lacks the extensive monitoring capabilities that Flower offers for Celery-based systems.
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME

dramatiq
A fast and reliable distributed task processing library for Python 3.
Changelog: https://dramatiq.io/changelog.html
Community: https://groups.io/g/dramatiq-users
Documentation: https://dramatiq.io
Sponsors
Installation
If you want to use it with RabbitMQ
pip install 'dramatiq[rabbitmq, watch]'
or if you want to use it with Redis
pip install 'dramatiq[redis, watch]'
Quickstart
Make sure you've got RabbitMQ running, then create a new file called
example.py
:
import dramatiq
import requests
import sys
@dramatiq.actor
def count_words(url):
response = requests.get(url)
count = len(response.text.split(" "))
print(f"There are {count} words at {url!r}.")
if __name__ == "__main__":
count_words.send(sys.argv[1])
In one terminal, run your workers:
dramatiq example
In another, start enqueueing messages:
python example.py http://example.com
python example.py https://github.com
python example.py https://news.ycombinator.com
Check out the user guide to learn more!
License
dramatiq is licensed under the LGPL. Please see COPYING and COPYING.LESSER for licensing details.
Top Related Projects
Convert
designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot