Daily Shaarli

All links of one day in a single page.

September 18, 2024

cattrs · PyPI

cattrs: Flexible Object Serialization and Validation

Because validation belongs to the edges.

cattrs is a Swiss Army knife for (un)structuring and validating data in Python. In practice, that means it converts unstructured dictionaries into proper classes and back, while validating their contents.
Example

cattrs works best with attrs classes, and dataclasses where simple (un-)structuring works out of the box, even for nested data, without polluting your data model with serialization details: