Async Support in Celery 5

Celery 5.0, released in September 2020, drops Python 2 and introduces experimental async task support. Workers can execute async def coroutines directly, benefiting from non-blocking I/O for network-bound tasks.

Async Task

python
from celery import Celery
import httpx

app = Celery('tasks', broker='redis://localhost:6379/0')

@app.task
async def fetch_url(url: str) -> str:
    """Async task: fetches a URL without blocking."""
    async with httpx.AsyncClient() as client:
        response = await client.get(url)
        return response.text[:200]

# Same call pattern as sync tasks
result = fetch_url.delay('https://example.com')
print(result.get(timeout=10))

Sources