You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Literals containing enums are now unstructured properly, and their unstructuring is greatly optimized in the _bson_, stdlib JSON, _cbor2_, _msgpack_, _msgspec_, _orjson_ and _ujson_ preconf converters.
Copy file name to clipboardexpand all lines: docs/preconf.md
+11-2
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,26 @@
2
2
3
3
The {mod}`cattrs.preconf` package contains factories for preconfigured converters, specifically adjusted for particular serialization libraries.
4
4
5
-
For example, to get a converter configured for BSON:
5
+
For example, to get a converter configured for _orjson_:
6
6
7
7
```{doctest}
8
8
9
-
>>> from cattrs.preconf.bson import make_converter
9
+
>>> from cattrs.preconf.orjson import make_converter
10
10
11
11
>>> converter = make_converter() # Takes the same parameters as the `cattrs.Converter`
12
12
```
13
13
14
14
Converters obtained this way can be customized further, just like any other converter.
15
15
16
+
For compatibility and performance reasons, these converters are usually configured to unstructure differently than ordinary `Converters`.
17
+
A couple of examples:
18
+
* the {class}`_orjson_ converter <cattrs.preconf.orjson.OrjsonConverter>` is configured to pass `datetime` instances unstructured since _orjson_ can handle them faster.
19
+
* the {class}`_msgspec_ JSON converter <cattrs.preconf.msgspec.MsgspecJsonConverter>` is configured to pass through some dataclasses and _attrs_classes,
20
+
if the output is identical to what normal unstructuring would have produced, since _msgspec_ can handle them faster.
21
+
22
+
The intended usage is to pass the unstructured output directly to the underlying library,
23
+
or use `converter.dumps` which will do it for you.
24
+
16
25
These converters support all [default hooks](defaulthooks.md)
17
26
and the following additional classes and type annotations,
0 commit comments