celery
Distributed task queue for async and scheduled background jobs in Python.
Web requests need to return fast. Sending emails, resizing images, calling slow APIs, or running ML inference inside a request handler blocks the server and degrades UX. You need a way to hand off work to a separate process and respond immediately.
Celery is like a post office. Your web app drops tasks into a mailbox (broker โ usually Redis or RabbitMQ). Worker processes pick them up, execute them, and optionally drop results in a result backend. The web app never waits.
Define and run your first background task
pip install celery redis
from celery import Celery
app = Celery('tasks', broker='redis://localhost:6379/0')
@app.task
def send_email(to, subject):
# your email logic
print(f'Sending {subject} to {to}')
# In your web handler:
send_email.delay('user@example.com', 'Welcome!')
celery -A tasks worker --loglevel=infoUse it when
Sending emails or notifications, processing uploads, running scheduled cron-style jobs, chaining multi-step workflows, fan-out parallel processing.
Skip it when
Simple scripts that don't serve web traffic โ just use asyncio or threading. If you need sub-millisecond latency, Celery's overhead is too high. For tiny projects, consider RQ (simpler) or FastAPI BackgroundTasks.
Ready to explore the full API?
See every class, function, and relationship in an interactive graph.