#[1]Index [2]Search [3]Copyright [4]Backends and Brokers [5]Getting Started

Navigation

* [6]index * [7]modules | * [8]next | * [9]previous | * [10]Celery 5.5.1 documentation » * [11]Getting Started » * [12]Introduction to Celery

This document describes the current stable version of Celery (5.5). For development docs, [13]go here.

Introduction to Celery[14]¶

* [15]What’s a Task Queue? * [16]What do I need? * [17]Get Started * [18]Celery is… * [19]Features * [20]Framework Integration * [21]Quick Jump * [22]Installation

[23]What’s a Task Queue?[24]¶

Task queues are used as a mechanism to distribute work across threads or machines.

A task queue’s input is a unit of work called a task. Dedicated worker processes constantly monitor task queues for new work to perform.

Celery communicates via messages, usually using a broker to mediate between clients and workers. To initiate a task the client adds a message to the queue, the broker then delivers that message to a worker.

A Celery system can consist of multiple workers and brokers, giving way to high availability and horizontal scaling.

Celery is written in Python, but the protocol can be implemented in any language. In addition to Python there’s [25]node-celery and [26]node-celery-ts for Node.js, and a [27]PHP client.

Language interoperability can also be achieved exposing an HTTP endpoint and having a task that requests it (webhooks).

[28]What do I need?[29]¶

Version Requirements

Celery version 5.3 runs on * Python ❨3.8, 3.9, 3.10, 3.11❩ * PyPy3.8+ ❨v7.3.11+❩

Celery 4.x was the last version to support Python 2.7, Celery 5.x requires Python 3.6 or newer. Celery 5.1.x also requires Python 3.6 or newer. Celery 5.2.x requires Python 3.7 or newer.

If you’re running an older version of Python, you need to be running an older version of Celery: * Python 2.7 or Python 3.5: Celery series 4.4 or earlier. * Python 2.6: Celery series 3.1 or earlier. * Python 2.5: Celery series 3.0 or earlier. * Python 2.4 was Celery series 2.2 or earlier.

Celery is a project with minimal funding, so we don’t support Microsoft Windows. Please don’t open any issues related to that platform.

Celery requires a message transport to send and receive messages. The RabbitMQ and Redis broker transports are feature complete, but there’s also support for a myriad of other experimental solutions, including using SQLite for local development.

Celery can run on a single machine, on multiple machines, or even across data centers.

[30]Get Started[31]¶

If this is the first time you’re trying to use Celery, or if you haven’t kept up with development in the 3.1 version and are coming from previous versions, then you should read our getting started tutorials: * [32]First Steps with Celery * [33]Next Steps

[34]Celery is…[35]¶

* Simple

Celery is easy to use and maintain, and it doesn’t need configuration files. It has an active, friendly community you can talk to for support, including a [36]mailing-list and an IRC channel. Here’s one of the simplest applications you can make: from celery import Celery

app = Celery('hello', broker='amqp://guest@localhost//')

@app.task def hello(): return 'hello world'

* Highly Available

Workers and clients will automatically retry in the event of connection loss or failure, and some brokers support HA in way of Primary/Primary or Primary/Replica replication. * Fast

A single Celery process can process millions of tasks a minute, with sub-millisecond round-trip latency (using RabbitMQ, librabbitmq, and optimized settings). * Flexible

Almost every part of Celery can be extended or used on its own, Custom pool implementations, serializers, compression schemes, logging, schedulers, consumers, producers, broker transports, and much more.

It supports * Brokers

+ [37]RabbitMQ, [38]Redis, + [39]Amazon SQS, and more…

* Concurrency

+ prefork (multiprocessing), + [40]Eventlet, [41]gevent + thread (multithreaded) + solo (single threaded)

* Result Stores

+ AMQP, Redis + Memcached, + SQLAlchemy, Django ORM + Apache Cassandra, Elasticsearch, Riak + MongoDB, CouchDB, Couchbase, ArangoDB + Amazon DynamoDB, Amazon S3 + Microsoft Azure Block Blob, Microsoft Azure Cosmos DB + Google Cloud Storage + File system

* Serialization

+ pickle, json, yaml, msgpack. + zlib, bzip2 compression. + Cryptographic message signing.

[42]Features[43]¶

* Monitoring

A stream of monitoring events is emitted by workers and is used by built-in and external tools to tell you what your cluster is doing – in real-time. [44]Read more…. * Work-flows

Simple and complex work-flows can be composed using a set of powerful primitives we call the “canvas”, including grouping, chaining, chunking, and more. [45]Read more…. * Time & Rate Limits

You can control how many tasks can be executed per second/minute/hour, or how long a task can be allowed to run, and this can be set as a default, for a specific worker or individually for each task type. [46]Read more….

* Scheduling

You can specify the time to run a task in seconds or a [47]datetime, or you can use periodic tasks for recurring events based on a simple interval, or Crontab expressions supporting minute, hour, day of week, day of month, and month of year. [48]Read more…. * Resource Leak Protection

The [49]--max-tasks-per-child option is used for user tasks leaking resources, like memory or file descriptors, that are simply out of your control. [50]Read more…. * User Components

Each worker component can be customized, and additional components can be defined by the user. The worker is built up using “bootsteps” — a dependency graph enabling fine grained control of the worker’s internals.

[51]Framework Integration[52]¶

Celery is easy to integrate with web frameworks, some of them even have integration packages:

[53]Pyramid

[54]https://pypi.org/project/pyramid_celery/

[55]Pylons

[56]https://pypi.org/project/celery-pylons/

[57]Flask

not needed

[58]web2py

[59]https://pypi.org/project/web2py-celery/

[60]Tornado

[61]https://pypi.org/project/tornado-celery/

[62]Tryton

[63]https://pypi.org/project/celery_tryton/

For [64]Django see [65]First steps with Django.

The integration packages aren’t strictly necessary, but they can make development easier, and sometimes they add important hooks like closing database connections at fork(2).

[66]Quick Jump[67]¶

I want to ⟶ * [68]get the return value of a task * [69]use logging from my task * [70]learn about best practices * [71]create a custom task base class * [72]add a callback to a group of tasks * [73]split a task into several chunks * [74]optimize the worker * [75]see a list of built-in task states * [76]create custom task states * [77]set a custom task name * [78]track when a task starts * [79]retry a task when it fails * [80]get the id of the current task

* [81]know what queue a task was delivered to * [82]see a list of running workers * [83]purge all messages * [84]inspect what the workers are doing * [85]see what tasks a worker has registered * [86]migrate tasks to a new broker * [87]see a list of event message types * [88]contribute to Celery * [89]learn about available configuration settings * [90]get a list of people and companies using Celery * [91]write my own remote control command * [92]change worker queues at runtime

Jump to ⟶ * [93]Brokers * [94]Applications * [95]Tasks * [96]Calling

* [97]Workers * [98]Daemonizing * [99]Monitoring * [100]Optimizing

* [101]Security * [102]Routing * [103]Configuration * [104]Django

* [105]Contributing * [106]Signals * [107]FAQ * [108]API Reference

[109]Installation[110]¶

You can install Celery either via the Python Package Index (PyPI) or from source.

To install using pip: $ pip install -U Celery

Bundles[111]¶

Celery also defines a group of bundles that can be used to install Celery and the dependencies for a given feature.

You can specify these in your requirements or on the pip command-line by using brackets. Multiple bundles can be specified by separating them by commas. $ pip install "celery[librabbitmq]"

$ pip install "celery[librabbitmq,redis,auth,msgpack]"

The following bundles are available:

Serializers[112]¶

celery[auth]: for using the auth security serializer.

celery[msgpack]: for using the msgpack serializer.

celery[yaml]: for using the yaml serializer.

Concurrency[113]¶

celery[eventlet]: for using the [114]https://pypi.org/project/eventlet/ pool.

celery[gevent]: for using the [115]https://pypi.org/project/gevent/ pool.

Transports and Backends[116]¶

celery[librabbitmq]: for using the librabbitmq C library.

celery[redis]: for using Redis as a message transport or as a result backend.

celery[sqs]: for using Amazon SQS as a message transport (experimental).

celery[tblib]: for using the [117]task_remote_tracebacks feature.

celery[memcache]: for using Memcached as a result backend (using [118]https://pypi.org/project/pylibmc/)

celery[pymemcache]: for using Memcached as a result backend (pure-Python implementation).

celery[cassandra]: for using Apache Cassandra/Astra DB as a result backend with DataStax driver.

celery[couchbase]: for using Couchbase as a result backend.

celery[arangodb]: for using ArangoDB as a result backend.

celery[elasticsearch]: for using Elasticsearch as a result backend.

celery[riak]: for using Riak as a result backend.

celery[dynamodb]: for using AWS DynamoDB as a result backend.

celery[zookeeper]: for using Zookeeper as a message transport.

celery[sqlalchemy]: for using SQLAlchemy as a result backend (supported).

celery[pyro]: for using the Pyro4 message transport (experimental).

celery[slmq]: for using the SoftLayer Message Queue transport (experimental).

celery[consul]: for using the Consul.io Key/Value store as a message transport or result backend (experimental).

celery[django]: specifies the lowest version possible for Django support.

You should probably not use this in your requirements, it’s here for informational purposes only.

celery[gcs]: for using the Google Cloud Storage as a result backend (experimental).

celery[gcpubsub]: for using the Google Cloud Pub/Sub as a message transport (experimental)..

Downloading and installing from source[119]¶

Download the latest version of Celery from PyPI:

[120]https://pypi.org/project/celery/

You can install it by doing the following,: $ tar xvfz celery-0.0.0.tar.gz $ cd celery-0.0.0 $ python setup.py build # python setup.py install

The last command must be executed as a privileged user if you aren’t currently using a virtualenv.

Using the development version[121]¶

With pip[122]¶

The Celery development version also requires the development versions of [123]https://pypi.org/project/kombu/, [124]https://pypi.org/project/amqp/, [125]https://pypi.org/project/billiard/, and [126]https://pypi.org/project/vine/.

You can install the latest snapshot of these using the following pip commands: $ pip install https://github.com/celery/celery/zipball/main#egg=celery $ pip install https://github.com/celery/billiard/zipball/main#egg=billiard $ pip install https://github.com/celery/py-amqp/zipball/main#egg=amqp $ pip install https://github.com/celery/kombu/zipball/main#egg=kombu $ pip install https://github.com/celery/vine/zipball/main#egg=vine

With git[127]¶

Please see the [128]Contributing section.

[129]Logo of Celery

IFRAME: [130]https://ghbtns.com/github-btn.html?user=celery&repo=celery&type=wa tch&count=true&size=large

Donations

Please help support this community project with a donation. [131][button@2x.png?color=blue]

Previous topic

[132]Getting Started

Next topic

[133]Backends and Brokers

This Page

* [134]Show Source

Quick search

____________________ Go

Navigation

* [135]index * [136]modules | * [137]next | * [138]previous | * [139]Celery 5.5.1 documentation » * [140]Getting Started » * [141]Introduction to Celery

© [142]Copyright 2009-2023, Ask Solem & contributors.

References

1. https://docs.celeryq.dev/en/stable/genindex.html 2. https://docs.celeryq.dev/en/stable/search.html 3. https://docs.celeryq.dev/en/stable/copyright.html 4. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/index.html 5. https://docs.celeryq.dev/en/stable/getting-started/index.html 6. https://docs.celeryq.dev/en/stable/genindex.html 7. https://docs.celeryq.dev/en/stable/py-modindex.html 8. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/index.html 9. https://docs.celeryq.dev/en/stable/getting-started/index.html 10. https://docs.celeryq.dev/en/stable/index.html 11. https://docs.celeryq.dev/en/stable/getting-started/index.html 12. https://docs.celeryq.dev/en/stable/getting-started/introduction.html 13. https://docs.celeryq.dev/en/main/getting-started/introduction.html 14. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#introduction-to-celery 15. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#what-s-a-task-queue 16. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#what-do-i-need 17. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#get-started 18. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#celery-is 19. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#features 20. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#framework-integration 21. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#quick-jump 22. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#installation 23. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id2 24. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#what-s-a-task-queue 25. https://github.com/mher/node-celery 26. https://github.com/IBM/node-celery-ts 27. https://github.com/gjedeer/celery-php 28. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id3 29. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#what-do-i-need 30. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id4 31. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#get-started 32. https://docs.celeryq.dev/en/stable/getting-started/first-steps-with-celery.html#first-steps 33. https://docs.celeryq.dev/en/stable/getting-started/next-steps.html#next-steps 34. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id5 35. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#celery-is 36. https://groups.google.com/group/celery-users 37. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/rabbitmq.html#broker-rabbitmq 38. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/redis.html#broker-redis 39. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/sqs.html#broker-sqs 40. http://eventlet.net/ 41. http://gevent.org/ 42. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id6 43. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#features 44. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#guide-monitoring 45. https://docs.celeryq.dev/en/stable/userguide/canvas.html#guide-canvas 46. https://docs.celeryq.dev/en/stable/userguide/workers.html#worker-time-limits 47. https://docs.python.org/dev/library/datetime.html#datetime.datetime 48. https://docs.celeryq.dev/en/stable/userguide/periodic-tasks.html#guide-beat 49. https://docs.celeryq.dev/en/stable/reference/cli.html#cmdoption-celery-worker-max-tasks-per-child 50. https://docs.celeryq.dev/en/stable/userguide/workers.html#worker-max-tasks-per-child 51. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id7 52. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#framework-integration 53. http://docs.pylonsproject.org/en/latest/docs/pyramid.html 54. https://pypi.org/project/pyramid_celery/ 55. http://pylonshq.com/ 56. https://pypi.org/project/celery-pylons/ 57. http://flask.pocoo.org/ 58. http://web2py.com/ 59. https://pypi.org/project/web2py-celery/ 60. http://www.tornadoweb.org/ 61. https://pypi.org/project/tornado-celery/ 62. http://www.tryton.org/ 63. https://pypi.org/project/celery_tryton/ 64. https://djangoproject.com/ 65. https://docs.celeryq.dev/en/stable/django/first-steps-with-django.html#django-first-steps 66. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id8 67. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#quick-jump 68. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-states 69. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-logging 70. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-best-practices 71. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-custom-classes 72. https://docs.celeryq.dev/en/stable/userguide/canvas.html#canvas-chord 73. https://docs.celeryq.dev/en/stable/userguide/canvas.html#canvas-chunks 74. https://docs.celeryq.dev/en/stable/userguide/optimizing.html#guide-optimizing 75. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-builtin-states 76. https://docs.celeryq.dev/en/stable/userguide/tasks.html#custom-states 77. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-names 78. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-track-started 79. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-retry 80. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-request-info 81. https://docs.celeryq.dev/en/stable/userguide/tasks.html#task-request-info 82. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#monitoring-control 83. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#monitoring-control 84. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#monitoring-control 85. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#monitoring-control 86. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#monitoring-control 87. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#event-reference 88. https://docs.celeryq.dev/en/stable/contributing.html#contributing 89. https://docs.celeryq.dev/en/stable/userguide/configuration.html#configuration 90. https://docs.celeryq.dev/en/stable/community.html#res-using-celery 91. https://docs.celeryq.dev/en/stable/userguide/workers.html#worker-custom-control-commands 92. https://docs.celeryq.dev/en/stable/userguide/workers.html#worker-queues 93. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/index.html#brokers 94. https://docs.celeryq.dev/en/stable/userguide/application.html#guide-app 95. https://docs.celeryq.dev/en/stable/userguide/tasks.html#guide-tasks 96. https://docs.celeryq.dev/en/stable/userguide/calling.html#guide-calling 97. https://docs.celeryq.dev/en/stable/userguide/workers.html#guide-workers 98. https://docs.celeryq.dev/en/stable/userguide/daemonizing.html#daemonizing 99. https://docs.celeryq.dev/en/stable/userguide/monitoring.html#guide-monitoring 100. https://docs.celeryq.dev/en/stable/userguide/optimizing.html#guide-optimizing 101. https://docs.celeryq.dev/en/stable/userguide/security.html#guide-security 102. https://docs.celeryq.dev/en/stable/userguide/routing.html#guide-routing 103. https://docs.celeryq.dev/en/stable/userguide/configuration.html#configuration 104. https://docs.celeryq.dev/en/stable/django/index.html#django 105. https://docs.celeryq.dev/en/stable/contributing.html#contributing 106. https://docs.celeryq.dev/en/stable/userguide/signals.html#signals 107. https://docs.celeryq.dev/en/stable/faq.html#faq 108. https://docs.celeryq.dev/en/stable/reference/index.html#apiref 109. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#id9 110. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#installation 111. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#bundles 112. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#serializers 113. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#concurrency 114. https://pypi.org/project/eventlet/ 115. https://pypi.org/project/gevent/ 116. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#transports-and-backends 117. https://docs.celeryq.dev/en/stable/userguide/configuration.html#std-setting-task_remote_tracebacks 118. https://pypi.org/project/pylibmc/ 119. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#downloading-and-installing-from-source 120. https://pypi.org/project/celery/ 121. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#using-the-development-version 122. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#with-pip 123. https://pypi.org/project/kombu/ 124. https://pypi.org/project/amqp/ 125. https://pypi.org/project/billiard/ 126. https://pypi.org/project/vine/ 127. https://docs.celeryq.dev/en/stable/getting-started/introduction.html#with-git 128. https://docs.celeryq.dev/en/stable/contributing.html#contributing 129. https://docs.celeryq.dev/en/stable/index.html 130. https://ghbtns.com/github-btn.html?user=celery&repo=celery&type=watch&count=true&size=large 131. https://opencollective.com/celery/donate 132. https://docs.celeryq.dev/en/stable/getting-started/index.html 133. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/index.html 134. https://docs.celeryq.dev/en/stable/_sources/getting-started/introduction.rst.txt 135. https://docs.celeryq.dev/en/stable/genindex.html 136. https://docs.celeryq.dev/en/stable/py-modindex.html 137. https://docs.celeryq.dev/en/stable/getting-started/backends-and-brokers/index.html 138. https://docs.celeryq.dev/en/stable/getting-started/index.html 139. https://docs.celeryq.dev/en/stable/index.html 140. https://docs.celeryq.dev/en/stable/getting-started/index.html 141. https://docs.celeryq.dev/en/stable/getting-started/introduction.html 142. https://docs.celeryq.dev/en/stable/copyright.html

;