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


Streaming, truncating, non-recursive version of repr().

Differences from regular repr():

  • Sets are represented the Python 3 way: {1, 2} vs set([1, 2]).

  • Unicode strings does not have the u' prefix, even on Python 2.

  • Empty set formatted as set() (Python 3), not set([]) (Python 2).

  • Longs don’t have the L suffix.

Very slow with no limits, super quick with limits.

celery.utils.saferepr.reprstream(stack: ~collections.deque, seen: ~typing.Set | None = None, maxlevels: int = 3, level: int = 0, isinstance: ~typing.Callable = <built-in function isinstance>) Iterator[Any][source]

Streaming repr, yielding tokens.

celery.utils.saferepr.saferepr(o: Any, maxlen: int | None = None, maxlevels: int = 3, seen: Set | None = None) str[source]

Safe version of repr().


Make sure you set the maxlen argument, or it will be very slow for recursive objects. With the maxlen set, it’s often faster than built-in repr.