This document describes the current stable version of Celery (4.2). For development docs, go here.


Object related utilities, including introspection, etc.

class celery.utils.objects.Bunch(**kwargs)[source]

Object that enables you to modify attributes.

class celery.utils.objects.FallbackContext(provided, fallback, *fb_args, **fb_kwargs)[source]

Context workaround.

The built-in @contextmanager utility does not work well when wrapping other contexts, as the traceback is wrong when the wrapped context raises.

This solves this problem and can be used instead of @contextmanager in this example:

def connection_or_default_connection(connection=None):
    if connection:
        # user already has a connection, shouldn't close
        # after use
        yield connection
        # must've new connection, and also close the connection
        # after the block returns
        with create_new_connection() as connection:
            yield connection

This wrapper can be used instead for the above like this:

def connection_or_default_connection(connection=None):
    return FallbackContext(connection, create_new_connection)
class celery.utils.objects.getitem_property(keypath, doc=None)[source]

Attribute -> dict key descriptor.

The target object must support __getitem__, and optionally __setitem__.


>>> from collections import defaultdict
>>> class Me(dict):
...     deep = defaultdict(dict)
...     foo = _getitem_property('foo')
...     deep_thing = _getitem_property('deep.thing')
>>> me = Me()
>>> = 10
>>> me['foo']
>>> me.deep_thing = 42
>>> me.deep_thing
>>> me.deep
defaultdict(<type 'dict'>, {'thing': 42})
celery.utils.objects.mro_lookup(cls, attr, stop=set([]), monkey_patched=[])[source]

Return the first node by MRO order that defines an attribute.

  • cls (Any) – Child class to traverse.
  • attr (str) – Name of attribute to find.
  • stop (Set[Any]) – A set of types that if reached will stop the search.
  • monkey_patched (Sequence) – Use one of the stop classes if the attributes module origin isn’t in this list. Used to detect monkey patched attributes.

The attribute value, or None if not found.

Return type: