API Reference
cattrs
Composable conversions between Python classes and simple types like dicts, built on attrs.
Official Documentation ↗CompatibilityThis documentation covers version
v23.2. Check the official docs for the latest API surface.Installation
pip
pip install cattrsMethods
No methods match this filter.
cattrs provides structure and unstructure for converting between attrs classes and plain data.
Key Features
- structure and unstructure helpers
- Custom hooks for special types
- Works with attrs and dataclasses
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
FAQ
- Does it work with dataclasses?
- Yes. cattrs handles attrs classes and standard dataclasses, and can be pointed at either via its converter.
- How do I handle dates?
- Register a structure hook for datetime on a converter instance so incoming strings are parsed into datetime objects.
- What about nested classes?
- Nested classes are structured recursively from type hints, so annotate fields precisely for correct conversion.
Report a problem with this API docOpens a pre-filled issue on GitHub.