Need help with flask-celery?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

ask
201 Stars 34 Forks BSD 3-Clause "New" or "Revised" License 58 Commits 11 Opened issues

Description

Celery integration for Flask (SINCE CELERY 3.0 THIS IS NO LONGER NEEDED)

Services available

!
?

Need anything else?

Contributors list

# 370
amqp
Django
python3
rabbitm...
31 commits
# 33,875
Ruby
prometh...
Django
python3
3 commits
# 1,595
Python
Clojure
Flask
repl
2 commits
# 573,317
Python
JavaScr...
Shell
2 commits
# 187,131
CSS
Shell
pelican
React
2 commits
# 179,009
Shell
pytest
pytest-...
HTML
1 commit

==============================

Flask <-> Celery Integration

:Version: 2.4.3

FROM CELERY 3.0 THIS LIBRARY IS NO LONGER NECESSARY, INSTEAD YOU SHOULD USE THE STANDARD CELERY API

.. _Celery: http://celeryproject.org

Using Flask with Celery

From Celery 3.0 the Flask-Celery integration package is no longer recommended and you should use the standard Celery API instead.

Please read the Celery getting started tutorial::

http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html

You can easily add Celery to your flask application like this:

myapp.py
::
from celery import Celery

celery = Celery('myapp', broker='amqp://[email protected]//')

@celery.task def add(x, y): return x + y

To start the worker you can then launch the

celery worker
command by pointing to your
celery
app instance::
$ celery -A myapp:celery worker -l info

See the commands help screen for more information::

$ celery help

If you want use the flask configuration as a source for the celery configuration you can do that like this::

celery = Celery('myapp')
celery.conf.add_defaults(app.config)

If you need access to the request inside your task then you can use the test context::

from flask import Flask
from celery import Celery

app = Flask('myapp') celery = Celery('myapp') celery.conf.add_defaults(app.config)

@celery.task def hello(): with app.test_request_context() as request: print('Hello {0!r}.format(request))

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.