Dramatiq: alternative to Celery

Ever since I started doing web development async tasks were a thing. You can't send an email synchronously and risk leaving the suer hanging. The solution was Celery. I used celery in a lot of projects. Simple websites to full single page applications.

But celery started to feel bulky, heavy and slugish. One of the major problems I've had with celery is the sheer complexity of the code. It's impossible to dig into it.

When I heard about Dramatiq I was very intrigued. It promisses things that Celery never had (like prioritization of tasks) and probably will never have. After trying it out I can say that it is really good. Declaring and sending tasks is as easy as ever, having only to annotate a method and calling task.send.

Dramatiq also has middlewares so you can enable and disable features really easily (like error reporting, message retries, prioritization and so on).

import dramatiq

def count_words(url):
    response = requests.get(url)
    count = len(response.text.split(" "))
    print(f"There are {count} words at {url!r}.")

Check out their documentation as it's really complete and easy to understand (example taken from said docs).

Show Comments