API Reference

Celery

Distributed task queue for Python with brokers, scheduling, retries, and result backends.

Official Documentation ↗
CompatibilityThis documentation covers version v5.4. Check the official docs for the latest API surface.

Installation

pippip install celery

Methods

Celery is a simple, flexible, and reliable distributed task queue system for Python. It processes millions of tasks a day, using brokers to pass messages between clients and workers with retries, scheduling, and result tracking.

Key Features

  • Brokers: Redis, RabbitMQ, SQS
  • Result backends: Store and query task results
  • Composition: chain, group, chord for workflows
  • Retries: Automatic with exponential backoff
  • Scheduling: Periodic tasks via beat

Errors

The official API reference declares the following error types:

  • celery.app.task.Task.MaxRetriesExceededError (exception(Task 上的异常类,任务最大重试次数超限时抛出)) — official text: “exception MaxRetriesExceededError(*args, **kwargs) The tasks max restart limit has been exceeded.” (source: https://docs.celeryq.dev/en/stable/reference/celery.app.task.html, fetched 2026-11-08T18:31:00+08:00)
  • TypeError (apply_async 的 Raises 条目) — official text: “TypeError – If not enough arguments are passed, or too many arguments are passed. Note that signature checks may be disabled by specifying @task(typing=False).” (source: https://docs.celeryq.dev/en/stable/reference/celery.app.task.html, fetched 2026-11-08T18:31:00+08:00)
  • ValueError (apply_async 的 Raises 条目) — official text: “ValueError – If soft_time_limit and time_limit both are set but soft_time_limit is greater than time_limit” (source: https://docs.celeryq.dev/en/stable/reference/celery.app.task.html, fetched 2026-11-08T18:31:00+08:00)
  • kombu.exceptions.OperationalError (apply_async 的 Raises 条目(连接失败/断连)) — official text: “kombu.exceptions.OperationalError – If a connection to the transport cannot be made, or if the connection is lost.” (source: https://docs.celeryq.dev/en/stable/reference/celery.app.task.html, fetched 2026-11-08T18:31:00+08:00)
  • RuntimeError (Celery 构造函数 autofinalize=False 时的抛出异常) — official text: “autofinalize (bool) – If set to False a RuntimeError will be raised if the task registry or tasks are used before the app is “ (source: https://docs.celeryq.dev/en/stable/reference/celery.html, fetched 2026-11-08T18:31:00+08:00)

Security

Official security statements captured from the package documentation:

  • Celery.setup_security 会禁用不受信任的序列化器(消息签名序列化器) — “Disables untrusted serializers and if configured to use the auth serializer will register the auth serializer with the provided settings into the Kombu serializer registry.” (source: https://docs.celeryq.dev/en/stable/reference/celery.html, fetched 2026-11-08T18:31:00+08:00)
  • setup_security 是影响所有应用实例的全局操作 — “This will affect all application instances (a global operation).” (source: https://docs.celeryq.dev/en/stable/reference/celery.html, fetched 2026-11-08T18:31:00+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T18:31:00+08:00 via WebFetch https://docs.celeryq.dev/en/stable/reference/celery.html;WebFetch https://docs.celeryq.dev/en/stable/reference/celery.app.task.html;WebFetch https://docs.celeryq.dev/en/stable/userguide/canvas.html.

FAQ

What brokers does Celery support?
Celery supports Redis, RabbitMQ, Amazon SQS, and others as brokers. Redis is simplest for small setups; RabbitMQ offers stronger guarantees and routing for production workloads.
How do I schedule periodic tasks?
Use the celery beat scheduler with a schedule definition, or django-celery-beat for Django. Define tasks in a schedule dict with crontab or timedelta entries and run the beat process alongside workers.
What is the difference between delay and apply_async?
delay is a shortcut for apply_async with positional args only. apply_async gives full control over countdown, eta, queue, retry policy, and routing, so prefer it for production configuration.