Skip to main content

Adds Dramatiq support to your Flask application

Project description

Flask-Dramatiq

Flask-Dramatiq plugs Dramatiq task queue in your Flask web application.

// Features //

  • Configure Dramatiq from Flask configuration.
  • Ensure Flask app is available to Dramatiq actor.
  • Add worker command to Flask CLI.
  • Enable Flask Application factory.
  • Handle multiple brokers with configurable prefix.

// Installation and Usage //

Flask-Dramatiq is licensed under BSD-3-Clause. Add flask-dramatiq to your project:

$ poetry add flask-dramatiq

Then use Dramatiq object as a regular Flask extension:

from flask import Flask
from flask_dramatiq import Dramatiq

app = Flask(__name__)
dramatiq = Dramatiq(app)

@dramatiq.actor()
def my_actor():
    ...

@app.route("/")
def myhandler():
    my_actor.send()

Flask-Dramatiq adds two configuration keys:

  • DRAMATIQ_BROKER, points to broker class like dramatiq.brokers.rabbitmq.RabbitmqBroker or dramatiq.brokers.redis.RedisBroker.
  • DRAMATIQ_BROKER_URL is passed as url keyword argument to broker class.

Now run worker program to consume messages and execute tasks in the background:

$ flask worker --processes=1

A complete flask app is available in project source tree example.py.

// Multiple brokers //

You may need multiple broker, e.g. by associating a broker with a blueprint. Flask-Dramatiq supports this. Give other broker a name and run a dedicated worker for it.

bluebroker = Dramatiq(name='bluebroker')

# Configuration:

BLUEBROKER_BROKER_URL = 'rabbitmq://…'

Now run it :

$ flask worker bluebroker

// Using Dramatiq CLI //

You can still use dramatiq CLI by declaring a file containing:

app = create_app()
broker = dramatiq.broker

Now call dramatiq CLI with some_module:broker as usual.

// Credit and Support //

Feel free to open an issue or suggest a merge request on Gitlab project page. Contribution welcome!

The project is based on Bogdanp/flask_dramatiq_example.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask-dramatiq-0.3.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

flask_dramatiq-0.3.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file flask-dramatiq-0.3.0.tar.gz.

File metadata

  • Download URL: flask-dramatiq-0.3.0.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/3.6.7 Linux/4.19.0-2-amd64

File hashes

Hashes for flask-dramatiq-0.3.0.tar.gz
Algorithm Hash digest
SHA256 8e98810fbd465316236ed351e5373917f66caba8898387ec0567760dfddb2b47
MD5 459adeb9e7d25f18c92e47a3de5550e1
BLAKE2b-256 ea78839dd9b026f674cf6ad2c2f22c9d59db88312ec90d28d14eaa9975ca6f98

See more details on using hashes here.

File details

Details for the file flask_dramatiq-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: flask_dramatiq-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.10 CPython/3.6.7 Linux/4.19.0-2-amd64

File hashes

Hashes for flask_dramatiq-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f04d885e1fea7bf47f25ef6b6724ee1dc46be8887fcbb90f0b9ef2ea6321f73e
MD5 cb8346e54a5d0331708eab0bad652014
BLAKE2b-256 318c073e5e2b9da3bf8eda51e3b308efc48584e4093b4c3b89ac954d9d2ff505

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page