cattrs.preconf package#
Submodules#
cattrs.preconf.bson module#
Preconfigured converters for bson.
- class cattrs.preconf.bson.Base85Bytes[source]#
Bases:
bytes
A subclass to help with binary key encoding/decoding.
- class cattrs.preconf.bson.BsonConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, check_keys=False, codec_options=CodecOptions(document_class=dict, tz_aware=False, uuid_representation=UuidRepresentation.UNSPECIFIED, unicode_decode_error_handler='strict', tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), datetime_conversion=DatetimeConversion.DATETIME))[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
check_keys (bool) –
codec_options (CodecOptions) –
- Return type:
bytes
- forbid_extra_keys#
- loads(data, cl, codec_options=CodecOptions(document_class=dict, tz_aware=False, uuid_representation=UuidRepresentation.UNSPECIFIED, unicode_decode_error_handler='strict', tzinfo=None, type_registry=TypeRegistry(type_codecs=[], fallback_encoder=None), datetime_conversion=DatetimeConversion.DATETIME))[source]#
- Parameters:
data (bytes) –
cl (Type[T]) –
codec_options (CodecOptions) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.bson.configure_converter(converter)[source]#
Configure the converter for use with the bson library.
sets are serialized as lists
byte mapping keys are base85-encoded into strings when unstructuring, and reverse
non-string, non-byte mapping keys are coerced into strings when unstructuring
a deserialization hook is registered for bson.ObjectId by default
- Parameters:
converter (BaseConverter) –
cattrs.preconf.cbor2 module#
Preconfigured converters for cbor2.
- class cattrs.preconf.cbor2.Cbor2Converter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
bytes
- forbid_extra_keys#
- loads(data, cl, **kwargs)[source]#
- Parameters:
data (bytes) –
cl (Type[T]) –
kwargs (Any) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.cbor2.configure_converter(converter)[source]#
Configure the converter for use with the cbor2 library.
datetimes are serialized as timestamp floats
sets are serialized as lists
- Parameters:
converter (BaseConverter) –
cattrs.preconf.json module#
Preconfigured converters for the stdlib json.
- class cattrs.preconf.json.JsonConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
str
- forbid_extra_keys#
- loads(data, cl, **kwargs)[source]#
- Parameters:
data (bytes | str) –
cl (Type[T]) –
kwargs (Any) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.json.configure_converter(converter)[source]#
Configure the converter for use with the stdlib json module.
bytes are serialized as base64 strings
datetimes are serialized as ISO 8601
counters are serialized as dicts
sets are serialized as lists
- Parameters:
converter (BaseConverter) –
cattrs.preconf.msgpack module#
Preconfigured converters for msgpack.
- class cattrs.preconf.msgpack.MsgpackConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
bytes
- forbid_extra_keys#
- loads(data, cl, **kwargs)[source]#
- Parameters:
data (bytes) –
cl (Type[T]) –
kwargs (Any) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.msgpack.configure_converter(converter)[source]#
Configure the converter for use with the msgpack library.
datetimes are serialized as timestamp floats
sets are serialized as lists
- Parameters:
converter (BaseConverter) –
cattrs.preconf.orjson module#
Preconfigured converters for orjson.
- class cattrs.preconf.orjson.OrjsonConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
bytes
- forbid_extra_keys#
- loads(data, cl)[source]#
- Parameters:
data (bytes | bytearray | memoryview | str) –
cl (Type[T]) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.orjson.configure_converter(converter)[source]#
Configure the converter for use with the orjson library.
bytes are serialized as base85 strings
datetimes and dates are passed through to be serialized as RFC 3339 by orjson
sets are serialized as lists
string enum mapping keys have special handling
mapping keys are coerced into strings when unstructuring
- Parameters:
converter (BaseConverter) –
cattrs.preconf.pyyaml module#
Preconfigured converters for pyyaml.
- class cattrs.preconf.pyyaml.PyyamlConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
str
- forbid_extra_keys#
- omit_if_default#
- type_overrides#
- cattrs.preconf.pyyaml.configure_converter(converter)[source]#
Configure the converter for use with the pyyaml library.
frozensets are serialized as lists
string enums are converted into strings explicitly
datetimes and dates are validated
- Parameters:
converter (BaseConverter) –
cattrs.preconf.tomlkit module#
Preconfigured converters for tomlkit.
- class cattrs.preconf.tomlkit.TomlkitConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
str
- forbid_extra_keys#
- omit_if_default#
- type_overrides#
- cattrs.preconf.tomlkit.configure_converter(converter)[source]#
Configure the converter for use with the tomlkit library.
bytes are serialized as base85 strings
sets are serialized as lists
tuples are serializas as lists
mapping keys are coerced into strings when unstructuring
- Parameters:
converter (BaseConverter) –
cattrs.preconf.ujson module#
Preconfigured converters for ujson.
- class cattrs.preconf.ujson.UjsonConverter(dict_factory=<class 'dict'>, unstruct_strat=UnstructureStrategy.AS_DICT, omit_if_default=False, forbid_extra_keys=False, type_overrides={}, unstruct_collection_overrides={}, prefer_attrib_converters=False, detailed_validation=True, unstructure_fallback_factory=<function Converter.<lambda>>, structure_fallback_factory=<function Converter.<lambda>>)[source]#
Bases:
Converter
- Parameters:
detailed_validation (bool) – Whether to use a slightly slower mode for detailed validation errors.
unstructure_fallback_factory (Callable[[Any], Callable[[Any], Any]]) – A hook factory to be called when no registered unstructuring hooks match.
structure_fallback_factory (Callable[[Any], Callable[[Any, Any], Any]]) – A hook factory to be called when no registered structuring hooks match.
dict_factory (Callable[[], Any]) –
unstruct_strat (UnstructureStrategy) –
omit_if_default (bool) –
forbid_extra_keys (bool) –
type_overrides (Mapping[Type, AttributeOverride]) –
unstruct_collection_overrides (Mapping[Type, Callable]) –
prefer_attrib_converters (bool) –
New in version 23.2.0: unstructure_fallback_factory
New in version 23.2.0: structure_fallback_factory
- dumps(obj, unstructure_as=None, **kwargs)[source]#
- Parameters:
obj (Any) –
unstructure_as (Any) –
kwargs (Any) –
- Return type:
str
- forbid_extra_keys#
- loads(data, cl, **kwargs)[source]#
- Parameters:
data (AnyStr) –
cl (Type[T]) –
kwargs (Any) –
- Return type:
T
- omit_if_default#
- type_overrides#
- cattrs.preconf.ujson.configure_converter(converter)[source]#
Configure the converter for use with the ujson library.
bytes are serialized as base64 strings
datetimes are serialized as ISO 8601
sets are serialized as lists
- Parameters:
converter (BaseConverter) –