Celery configuration templates for all frameworks (Django, Flask, FastAPI, standalone). Use when configuring Celery, setting up task queues, creating Celery apps, integrating with frameworks, or when user mentions Celery configuration, task queue setup, broker configuration, or framework integration.
Limited to specific tools
Additional assets for this skill
This skill is limited to using the following tools:
examples/django-setup.mdexamples/fastapi-setup.mdexamples/flask-setup.mdexamples/standalone-setup.mdscripts/detect-framework.shscripts/generate-config.shscripts/test-broker-connection.shscripts/validate-config.shtemplates/beat-schedule.pytemplates/celery-app-django.pytemplates/celery-app-fastapi.pytemplates/celery-app-flask.pytemplates/celery-app-standalone.pytemplates/config-rabbitmq.pytemplates/config-redis.pytemplates/tasks-example.pyProvides production-ready Celery configuration templates for all major Python frameworks (Django, Flask, FastAPI, standalone) with complete broker setup (Redis, RabbitMQ), security best practices, and framework-specific integration patterns.
celery-config-patterns/
├── SKILL.md # This file
├── scripts/
│ ├── validate-config.sh # Validate Celery configuration
│ ├── detect-framework.sh # Auto-detect Python framework
│ ├── generate-config.sh # Generate framework-specific config
│ └── test-broker-connection.sh # Test broker connectivity
├── templates/
│ ├── celery-app-standalone.py # Standalone Celery app
│ ├── celery-app-django.py # Django Celery integration
│ ├── celery-app-flask.py # Flask Celery integration
│ ├── celery-app-fastapi.py # FastAPI Celery integration
│ ├── config-redis.py # Redis broker configuration
│ ├── config-rabbitmq.py # RabbitMQ broker configuration
│ ├── tasks-example.py # Sample task definitions
│ └── beat-schedule.py # Celery Beat schedule config
└── examples/
├── django-setup.md # Complete Django setup guide
├── flask-setup.md # Complete Flask setup guide
├── fastapi-setup.md # Complete FastAPI setup guide
└── standalone-setup.md # Standalone Python setup guide
Use the detection script to identify the Python framework:
bash scripts/detect-framework.sh
Detects:
manage.py, settings.py)app.py)main.py)Based on framework detection, choose the appropriate template:
| Framework | Template | Integration File |
|---|---|---|
| Django | celery-app-django.py | projectname/celery.py |
| Flask | celery-app-flask.py | app/celery.py or celery.py |
| FastAPI | celery-app-fastapi.py | app/celery.py or celery.py |
| Standalone | celery-app-standalone.py | celery_app.py |
Choose broker configuration template:
Redis (Recommended for simplicity):
# Use templates/config-redis.py
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
RabbitMQ (Recommended for production):
# Use templates/config-rabbitmq.py
CELERY_BROKER_URL = 'amqp://guest:guest@localhost:5672//'
CELERY_RESULT_BACKEND = 'rpc://'
Use the generation script:
bash scripts/generate-config.sh --framework=django --broker=redis
bash scripts/generate-config.sh --framework=flask --broker=rabbitmq
bash scripts/generate-config.sh --framework=fastapi --broker=redis
Script will:
Run validation script before starting Celery:
bash scripts/validate-config.sh
Validates:
Verify broker connectivity:
bash scripts/test-broker-connection.sh
Tests:
Standalone Celery application without web framework integration.
Features:
Usage:
# celery_app.py
from celery import Celery
app = Celery('myapp')
app.config_from_object('celeryconfig')
@app.task
def add(x, y):
return x + y
Django-specific Celery configuration using Django settings.
Features:
Usage:
# myproject/celery.py
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
app = Celery('myproject')
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
Flask-specific Celery configuration with Flask app context.
Features:
Usage:
# celery.py
from celery import Celery
def make_celery(app):
celery = Celery(app.import_name)
celery.conf.update(app.config)
return celery
# app.py
celery = make_celery(app)
FastAPI-specific Celery configuration with async support.
Features:
Usage:
# celery.py
from celery import Celery
celery_app = Celery('fastapi_app')
celery_app.config_from_object('celeryconfig')
# main.py
from fastapi import FastAPI
from celery_app import celery_app
Redis broker and result backend configuration.
Features:
Configuration:
CELERY_BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_BROKER_CONNECTION_RETRY_ON_STARTUP = True
CELERY_REDIS_MAX_CONNECTIONS = 50
RabbitMQ broker configuration with advanced routing.
Features:
Configuration:
CELERY_BROKER_URL = 'amqp://user:pass@localhost:5672//'
CELERY_RESULT_BACKEND = 'rpc://'
CELERY_TASK_ROUTES = {
'app.tasks.critical': {'queue': 'critical'},
'app.tasks.normal': {'queue': 'default'},
}
Example task definitions with best practices.
Features:
Examples:
@app.task(bind=True, max_retries=3)
def process_data(self, data):
try:
# Process data
return result
except Exception as exc:
raise self.retry(exc=exc, countdown=60)
@app.task(rate_limit='10/m')
def send_email(to, subject, body):
# Send email
pass
Celery Beat periodic task scheduling.
Features:
Examples:
CELERY_BEAT_SCHEDULE = {
'cleanup-every-midnight': {
'task': 'app.tasks.cleanup',
'schedule': crontab(hour=0, minute=0),
},
'report-every-monday': {
'task': 'app.tasks.weekly_report',
'schedule': crontab(day_of_week=1, hour=9),
},
}
Validates Celery configuration for errors.
Usage:
bash scripts/validate-config.sh
bash scripts/validate-config.sh --config=celeryconfig.py
bash scripts/validate-config.sh --app=myapp.celery:app
Checks:
Exit Codes:
Detects Python web framework in current project.
Usage:
bash scripts/detect-framework.sh
bash scripts/detect-framework.sh /path/to/project
Output:
{
"framework": "django",
"version": "4.2.0",
"celery_location": "myproject/celery.py",
"settings_location": "myproject/settings.py"
}
Detection Logic:
manage.py and settings.pyapp.pymain.pyGenerates framework-specific Celery configuration.
Usage:
bash scripts/generate-config.sh --framework=django --broker=redis
bash scripts/generate-config.sh --framework=flask --broker=rabbitmq --output=celery_config.py
Options:
--framework: django, flask, fastapi, standalone--broker: redis, rabbitmq--output: Custom output file path--with-beat: Include Celery Beat configuration--with-monitoring: Include monitoring configurationGenerated Files:
.env.example with broker credentialsTests message broker connectivity.
Usage:
bash scripts/test-broker-connection.sh
bash scripts/test-broker-connection.sh redis://localhost:6379/0
bash scripts/test-broker-connection.sh amqp://guest:guest@localhost:5672//
Tests:
Output:
✓ Broker host is reachable
✓ Port 6379 is open
✓ Authentication successful
✓ Message publish successful
✓ Message consume successful
✓ Connection pool working
All tests passed!
See examples/django-setup.md for complete walkthrough:
myproject/celery.pysettings.pySee examples/flask-setup.md for complete walkthrough:
See examples/fastapi-setup.md for complete walkthrough:
See examples/standalone-setup.md for complete walkthrough:
All configuration templates and examples in this skill follow strict security rules:
Environment Variables:
your_redis_password_hereExample .env.example:
# Redis Configuration
CELERY_BROKER_URL=redis://:your_redis_password_here@localhost:6379/0
CELERY_RESULT_BACKEND=redis://:your_redis_password_here@localhost:6379/0
# RabbitMQ Configuration
CELERY_BROKER_URL=amqp://your_rabbitmq_user:your_rabbitmq_password@localhost:5672//
Code Examples:
# ALWAYS read from environment
import os
CELERY_BROKER_URL = os.getenv('CELERY_BROKER_URL', 'redis://localhost:6379/0')
Security Checklist:
Production Settings:
# Task execution
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT = ['json']
CELERY_TIMEZONE = 'UTC'
CELERY_ENABLE_UTC = True
# Performance
CELERY_WORKER_PREFETCH_MULTIPLIER = 4
CELERY_WORKER_MAX_TASKS_PER_CHILD = 1000
CELERY_BROKER_POOL_LIMIT = 10
# Reliability
CELERY_TASK_ACKS_LATE = True
CELERY_TASK_REJECT_ON_WORKER_LOST = True
CELERY_TASK_TIME_LIMIT = 300
CELERY_TASK_SOFT_TIME_LIMIT = 240
Development Settings:
# Easier debugging
CELERY_TASK_ALWAYS_EAGER = True
CELERY_TASK_EAGER_PROPAGATES = True
Broker Connection Failed:
# Test broker connectivity
bash scripts/test-broker-connection.sh
# Check broker is running
# Redis: redis-cli ping
# RabbitMQ: rabbitmqctl status
Tasks Not Discovered:
# Validate configuration
bash scripts/validate-config.sh
# Check task module paths
celery -A myapp inspect registered
Import Errors:
# Verify Python path includes project
export PYTHONPATH="${PYTHONPATH}:/path/to/project"
# Check Celery app is importable
python -c "from myapp.celery import app; print(app)"
Python Packages:
Framework-Specific:
Broker Requirements:
System Tools:
Skill Version: 1.0.0 Last Updated: 2025-11-16