cattrs functionality is exposed through a
cattrs functions, such as
cattr.unstructure(), use a single
global converter. Changes done to this global converter, such as registering new
unstructure hooks, affect all code using the global
A global converter is provided for convenience as
The following functions implicitly use this global converter:
Changes made to the global converter will affect the behavior of these functions.
Larger applications are strongly encouraged to create and customize a different,
private instance of
To create a private converter, simply instantiate a
Currently, a converter contains the following state:
a registry of unstructure hooks, backed by a
a registry of structure hooks, backed by a different
a LRU cache of union disambiguation functions.
a reference to an unstructuring strategy (either AS_DICT or AS_TUPLE).
dict_factorycallable, used for creating
GenConverter is a converter subclass that automatically generates,
compiles and caches specialized structuring and unstructuring hooks for
GenConverter differs from the old
cattr.Converter in the following ways:
structuring and unstructuring of
attrsclasses is slower the first time, but faster every subsequent time
structuring and unstructuring can be customized
attrsclasses with PEP563 (postponed) annotations
support for generic
GenConverter will become the default converter type in a later release.