Flask-CeleryExt
raw JSON → 0.5.0 verified Fri May 01 auth: no python
Flask-CeleryExt provides a simple integration layer between Celery and Flask, offering a Flask extension for configuring Celery applications. Current version is 0.5.0 (requires Python >=3.6), with a maintenance-level release cadence.
pip install flask-celeryext Common errors
error AttributeError: module 'flask_celeryext' has no attribute 'create_celery_app' ↓
cause Importing directly from 'flask_celeryext' without upgrading to a version that includes create_celery_app (added in 0.4.0).
fix
Upgrade to flask-celeryext>=0.4.0: pip install --upgrade flask-celeryext
error celery.exceptions.ImproperlyConfigured: No broker configured ↓
cause Forgetting to set 'CELERY_BROKER_URL' in Flask app config, or setting it with wrong key name.
fix
Ensure app.config['CELERY_BROKER_URL'] is set to a valid broker URL (e.g., 'redis://localhost:6379/0')
error RuntimeError: Working outside of application context ↓
cause Using Celery tasks outside of Flask application context without proper setup.
fix
Initialize Celery using FlaskCeleryExt(app) or use 'with app.app_context():' when executing tasks outside request context.
Warnings
gotcha Flask-CeleryExt expects Celery configuration keys like 'CELERY_BROKER_URL' (uppercase with CELERY_ prefix). Using lowercase or missing prefix will silently default to localhost. ↓
fix Set config keys with 'CELERY_' prefix, e.g., app.config['CELERY_BROKER_URL'] = '...'.
deprecated The 'BROKER_URL' configuration key (without CELERY_ prefix) is deprecated as of v0.4.2. Use 'CELERY_BROKER_URL' instead. ↓
fix Replace app.config['BROKER_URL'] with app.config['CELERY_BROKER_URL'].
gotcha Flask-CeleryExt does not automatically handle Flask application context for Celery tasks. You must use the @celery.task decorator within an application context or use the create_celery_app helper to avoid context issues. ↓
fix Use the provided 'create_celery_app' function or ensure tasks are defined after the extension is initialized with the app.
Imports
- FlaskCeleryExt
from flask_celeryext import FlaskCeleryExt - create_celery_app
from flask_celeryext import create_celery_app
Quickstart
from flask import Flask
from flask_celeryext import FlaskCeleryExt
app = Flask(__name__)
app.config['CELERY_BROKER_URL'] = 'redis://localhost:6379/0'
app.config['CELERY_RESULT_BACKEND'] = 'redis://localhost:6379/0'
ext = FlaskCeleryExt(app)
celery = ext.celery
@celery.task
def add(x, y):
return x + y
if __name__ == '__main__':
app.run()