This document describes Celery 2.2. For development docs, go here.

Celery Application.

  1. 2009 - 2011 by Ask Solem.

BSD, see LICENSE for more details.


class, loader=None, backend=None, amqp=None, events=None, log=None, control=None, set_as_current=True, accept_magic_kwargs=False)

Celery Application.

  • main – Name of the main module if running as __main__.
  • loader – The loader class, or the name of the loader class to use. Default is
  • backend – The result store backend class, or the name of the backend class to use. Default is the value of the CELERY_RESULT_BACKEND setting.
  • amqp – AMQP object or class name.
  • events – Events object or class name.
  • log – Log object or class name.
  • control – Control object or class name.
  • set_as_current – Make this the global current app.

Name of the __main__ module. Required for standalone scripts.

If set this will be used instead of __main__ when automatically generating task names.


Sending/receiving messages. See AMQP.


Storing/retreiving task state. See BaseBackend.


Current loader.


Current configuration (dict and attribute access).


Controlling worker nodes. See Control.


Logging utilities. See Logging.

config_from_object(obj, silent=False)

Read configuration from object, where object is either a real object, or the name of an object to import.

>>> celery.config_from_object("myapp.celeryconfig")
>>> from myapp import celeryconfig
>>> celery.config_from_object(celeryconfig)
config_from_envvar(variable_name, silent=False)

Read configuration from environment variable.

The value of the environment variable must be the name of an object to import.

>>> os.environ["CELERY_CONFIG_MODULE"] = "myapp.celeryconfig"
>>> celery.config_from_envvar("CELERY_CONFIG_MODULE")
config_from_cmdline(argv, namespace='celery')

Read configuration from argv.

The config

task(*args, **options)

Decorator to create a task class out of any callable.


def refresh_feed(url):
    return Feed.objects.get(url=url).refresh()

With setting extra options and using retry.

def refresh_feed(url, **kwargs):
        return Feed.objects.get(url=url).refresh()
    except socket.error, exc:
        refresh_feed.retry(args=[url], kwargs=kwargs, exc=exc)

Calling the resulting task:

>>> refresh_feed("") # Regular
>>> refresh_feed.delay("") # Async
<AsyncResult: 8998d0f4-da0b-4669-ba03-d5ab5ac6ad5d>

Creates a base task class using default configuration taken from this app.

TaskSet(*args, **kwargs)

Create new TaskSet.

send_task(name, args=None, kwargs=None, countdown=None, eta=None, task_id=None, publisher=None, connection=None, connect_timeout=None, result_cls=None, expires=None, queues=None, **options)

Send task by name.

  • name – Name of task to execute (e.g. “tasks.add”).
  • result_cls – Specify custom result class. Default is using AsyncResult().

Supports the same arguments as apply_async().

AsyncResult(task_id, backend=None, task_name=None)

Create celery.result.BaseAsyncResult instance.

TaskSetResult(taskset_id, results, **kwargs)

Create celery.result.TaskSetResult instance.


Run celeryd using argv. Uses sys.argv if argv is not specified.


Create new Worker instance.


Create new Beat instance.

broker_connection(hostname=None, userid=None, password=None, virtual_host=None, port=None, ssl=None, insist=None, connect_timeout=None, transport=None, **kwargs)

Establish a connection to the message broker.


:returns kombu.connection.BrokerConnection:


With any function accepting connection and connect_timeout keyword arguments, establishes a default connection if one is not already passed to it.

Any automatically established connection will be closed after the function returns.

mail_admins(subject, body, fail_silently=False)

Send an e-mail to the admins in the ADMINS setting.


Prepare configuration before it is merged with the defaults.

either(default_key, *values)

Fallback to the value of a configuration key if none of the *values are true.

merge(l, r)

Like dict(a, **b) except it will keep values from a if the value in b is None.


Returns the app provided or the default app if none.

The environment variable CELERY_TRACE_APP is used to trace app leaks. When enabled an exception is raised if there is no active app.

Previous topic

API Reference

Next topic

This Page