Actual App instance implementation.

Module Contents


Celery(self,main=None,loader=None,backend=None,amqp=None,events=None,log=None,control=None,set_as_current=True,tasks=None,broker=None,include=None,changes=None,config_source=None,fixups=None,task_cls=None,autofinalize=True,namespace=None,strict_typing=True,**kwargs) Celery application.


app_has_custom(app,attr) Return true if app has customized method attr.
_unpickle_appattr(reverse_name,args) Unpickle app.
app_has_custom(app, attr)

Return true if app has customized method attr.

This is used for optimizations in cases where we know how the default behavior works, but need to account for someone using inheritance to override a method/property.
_unpickle_appattr(reverse_name, args)

Unpickle app.

class PendingConfiguration(conf, callback)
__init__(conf, callback)
__setitem__(key, value)
update(*args, **kwargs)
setdefault(*args, **kwargs)
class Celery(main=None, loader=None, backend=None, amqp=None, events=None, log=None, control=None, set_as_current=True, tasks=None, broker=None, include=None, changes=None, config_source=None, fixups=None, task_cls=None, autofinalize=True, namespace=None, strict_typing=True, **kwargs)

Celery application.

main (str): Name of the main module if running as __main__.
This is used as the prefix for auto-generated task names.
Keyword Arguments:

broker (str): URL of the default broker used. backend (Union[str, type]): The result store backend class,

or the name of the backend class to use.

Default is the value of the :setting:`result_backend` setting.

autofinalize (bool): If set to False a RuntimeError
will be raised if the task registry or tasks are used before the app is finalized.

set_as_current (bool): Make this the global current app. include (List[str]): List of modules every worker should import.

amqp (Union[str, type]): AMQP object or class name. events (Union[str, type]): Events object or class name. log (Union[str, type]): Log object or class name. control (Union[str, type]): Control object or class name. tasks (Union[str, type]): A task registry, or the name of

a registry class.
fixups (List[str]): List of fix-up plug-ins (e.g., see
config_source (Union[str, type]): Take configuration from a class,
or object. Attributes may include any settings described in the documentation.
__init__(main=None, loader=None, backend=None, amqp=None, events=None, log=None, control=None, set_as_current=True, tasks=None, broker=None, include=None, changes=None, config_source=None, fixups=None, task_cls=None, autofinalize=True, namespace=None, strict_typing=True, **kwargs)

Optional callback called at init.

__autoset(key, value)

Make this the current app for this thread.


Make this the default app for all threads.


Clean up after the application.

Only necessary for dynamically created apps, and you should probably use the with statement instead.

>>> with Celery(set_as_current=False) as app:
...     with app.connection_for_write() as conn:
...         pass

Run celery using argv.

Uses sys.argv if argv is not specified.


Run celery worker using argv.

Uses sys.argv if argv is not specified.

task(*args, **opts)

Decorator to create a task class out of any callable.

def refresh_feed(url):

with setting extra options:

def refresh_feed(url):
    return store_feed(feedparser.parse(url))

App Binding: For custom apps the task decorator will return a proxy object, so that the act of creating the task is not performed until the task is used or the task registry is accessed.

If you’re depending on binding to be deferred, then you must not access any attributes on the returned object until the application is fully set up (finalized).

_task_from_fun(fun, name=None, base=None, bind=False, **options)

Utility for registering a task-based class.

This is here for compatibility with old Celery 1.0 style task classes, you should not need to use this for new projects.
gen_task_name(name, module)

Finalize the app.

This loads built-in tasks, evaluates pending task decorators, reads configuration, etc.


Add default configuration from dict d.

If the argument is a callable function then it will be regarded as a promise, and it won’t be loaded until the configuration is actually needed.

This method can be compared to:

>>> celery.conf.update(d)

with a difference that 1) no copy will be made and 2) the dict will not be transferred when the worker spawns child processes, so it’s important that the same configuration happens at import time when pickle restores the object on the other side.

config_from_object(obj, silent=False, force=False, namespace=None)

Read configuration from object.

Object is either an actual object or the name of a module to import.

>>> celery.config_from_object('myapp.celeryconfig')
>>> from myapp import celeryconfig
>>> celery.config_from_object(celeryconfig)

silent (bool): If true then import errors will be ignored. force (bool): Force reading configuration immediately.

By default the configuration will be read only when required.
config_from_envvar(variable_name, silent=False, force=False)

Read configuration from environment variable.

The value of the environment variable must be the name of a module to import.

>>> os.environ['CELERY_CONFIG_MODULE'] = 'myapp.celeryconfig'
>>> celery.config_from_envvar('CELERY_CONFIG_MODULE')
config_from_cmdline(argv, namespace="celery")
setup_security(allowed_serializers=None, key=None, cert=None, store=None, digest="sha1", serializer="json")

Setup the message-signing serializer.

This will affect all application instances (a global operation).

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.

allowed_serializers (Set[str]): List of serializer names, or
content_types that should be exempt from being disabled.
key (str): Name of private key file to use.
Defaults to the :setting:`security_key` setting.
cert (str): Name of certificate file to use.
Defaults to the :setting:`security_certificate` setting.
store (str): Directory containing certificates.
Defaults to the :setting:`security_cert_store` setting.
digest (str): Digest algorithm used when signing messages.
Default is sha1.
serializer (str): Serializer used to encode messages after
they’ve been signed. See :setting:`task_serializer` for the serializers supported. Default is json.
autodiscover_tasks(packages=None, related_name="tasks", force=False)

Auto-discover task modules.

Searches a list of packages for a “” module (or use related_name argument).

If the name is empty, this will be delegated to fix-ups (e.g., Django).

For example if you have a directory layout like this:




Then calling app.autodiscover_tasks(['foo', 'bar', 'baz']) will result in the modules foo.tasks and bar.tasks being imported.

packages (List[str]): List of packages to search.
This argument may also be a callable, in which case the value returned is used (for lazy evaluation).
related_name (str): The name of the module to find. Defaults
to “tasks”: meaning “look for ‘module.tasks’ for every module in packages.”
force (bool): By default this call is lazy so that the actual
auto-discovery won’t happen until an application imports the default modules. Forcing will cause the auto-discovery to happen immediately.
_autodiscover_tasks(packages, related_name, **kwargs)
_autodiscover_tasks_from_names(packages, related_name)
send_task(name, args=None, kwargs=None, countdown=None, eta=None, task_id=None, producer=None, connection=None, router=None, result_cls=None, expires=None, publisher=None, link=None, link_error=None, add_to_parent=True, group_id=None, retries=0, chord=None, reply_to=None, time_limit=None, soft_time_limit=None, root_id=None, parent_id=None, route_name=None, shadow=None, chain=None, task_type=None, **options)

Send task by name.

Supports the same arguments as @-Task.apply_async().

name (str): Name of task to call (e.g., “tasks.add”). result_cls (AsyncResult): Specify custom result class.
connection_for_read(url=None, **kwargs)

Establish connection used for consuming.

See Also:
connection() for supported arguments.
connection_for_write(url=None, **kwargs)

Establish connection used for producing.

See Also:
connection() for supported arguments.
connection(hostname=None, userid=None, password=None, virtual_host=None, port=None, ssl=None, connect_timeout=None, transport=None, transport_options=None, heartbeat=None, login_method=None, failover_strategy=None, **kwargs)

Establish a connection to the message broker.

Please use connection_for_read() and connection_for_write() instead, to convey the intent of use for this connection.


url: Either the URL or the hostname of the broker to use. hostname (str): URL, Hostname/IP-address of the broker.

If a URL is used, then the other argument below will be taken from the URL instead.

userid (str): Username to authenticate as. password (str): Password to authenticate with virtual_host (str): Virtual host to use (domain). port (int): Port to connect to. ssl (bool, Dict): Defaults to the :setting:`broker_use_ssl`

transport (str): defaults to the :setting:`broker_transport`

transport_options (Dict): Dictionary of transport specific options. heartbeat (int): AMQP Heartbeat in seconds (pyamqp only). login_method (str): Custom login method to use (AMQP only). failover_strategy (str, Callable): Custom failover strategy. **kwargs: Additional arguments to kombu.Connection.

kombu.Connection: the lazy connection instance.
_connection(url, userid=None, password=None, virtual_host=None, port=None, ssl=None, connect_timeout=None, transport=None, transport_options=None, heartbeat=None, login_method=None, failover_strategy=None, **kwargs)

Helper for connection_or_acquire().

connection_or_acquire(connection=None, pool=True, *_, **__)

Context used to acquire a connection from the pool.

For use within a with statement to get a connection from the pool if one is not already provided.

connection (kombu.Connection): If not provided, a connection
will be acquired from the connection pool.

Context used to acquire a producer from the pool.

For use within a with statement to get a producer from the pool if one is not already provided

producer (kombu.Producer): If not provided, a producer
will be acquired from the producer pool.

Prepare configuration before it is merged with the defaults.


Return the current time and date as a datetime.


Select subset of queues.

queues (Sequence[str]): a list of queue names to keep.
either(default_key, *defaults)

Get key from configuration or use default values.

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


Return information useful in bug reports.


Get config value by key and finalize loading the configuration.

This is used by PendingConfiguration:
as soon as you access a key the configuration is read.
signature(*args, **kwargs)

Return a new Signature bound to this app.

add_periodic_task(schedule, sig, args=tuple, kwargs=tuple, name=None, **opts)
_sig_to_periodic_task_entry(schedule, sig, args=tuple, kwargs=dict, name=None, **opts)
_add_periodic_task(key, entry)

Create a base task class bound to this app.

subclass_with_self(Class, name=None, attribute="app", reverse=None, keep_reduce=False, **kw)

Subclass an app-compatible class.

App-compatible means that the class has a class attribute that provides the default app it should use, for example: class Foo: app = None.


Class (type): The app-compatible class to subclass. name (str): Custom name for the target class. attribute (str): Name of the attribute holding the app,

Default is ‘app’.
reverse (str): Reverse path to this object used for pickling
purposes. For example, to get app.AsyncResult, use "AsyncResult".
keep_reduce (bool): If enabled a custom __reduce__
implementation won’t be provided.

Keyword arguments used to reconstruct the object when unpickling.


Deprecated method, please use __reduce_keys__() instead.


Worker application.

See Also:

Embeddable worker.

See Also:

celery beat scheduler application.

See Also:

Base task class for this app.


Create new result instance.

See Also:

Create new group result instance.

See Also:

Broker connection pool: @pool.

This attribute is not related to the workers concurrency pool.

Instance of task being executed, or None.


The task currently being executed by a worker or None.

Differs from current_task in that it’s not affected by tasks calling other tasks directly, or eagerly.


Universally unique identifier for this app.


AMQP related functionality: @amqp.


Current backend instance.


Current configuration.


Remote control: @control.


Consuming and sending events: @events.


Current loader instance.


Logging: @log.


Task registry.

Accessing this attribute will also auto-finalize the app.

Check if the application uses the UTC timezone.


Current timezone for this app.

This is a cached property taking the time zone from the :setting:`timezone` setting.