cattrs
Composable complex class support for attrs and dataclasses.
Decision gist · record as of 2026-08-14
Yes. cattrs is actively maintained, permissively licensed, has low install friction, and solves a common problem—bridging unstructured and typed data—without requiring you to pollute your models with serialization logic. It's a good fit if you work with attrs or dataclasses and need flexible, recursive (un)structuring with validation.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.10 or later.
- Low friction installation with three lightweight runtime dependencies (attrs, exceptiongroup, typing-extensions).
- Actively maintained as of 2026-02-18 with recent commits and 1049 repository stars.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted commercial and private use with minimal obligations—only attribution required.
last release 2026-02-18 (177 days) · last repo commit 2026-08-09 · 1,049 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 73,830,482 downloads/mo, #455 on PyPI
Alternatives
Verify before relying
from attrs import define
from cattrs import structure, unstructure
@define
class C:
a: int
b: list[str]
instance = structure({'a': 1, 'b': ['x', 'y']}, C)
unstructure(instance)- Performance characteristics compared to alternative serialization libraries under real-world workloads.
- Extent of support for complex union disambiguation beyond the documented unique-field strategy.
What it is and what it does
cattrs is a data (un)structuring library that bridges unstructured data (dictionaries, JSON) and typed Python objects. It converts dictionaries into attrs classes or dataclasses recursively, validating types along the way, and can reverse the process to serialize objects back to dictionaries. The library keeps serialization rules separate from your data models, so you can define multiple conversion strategies for the same class without modifying it.
It handles nested structures, optional fields, collections (lists, sets, tuples, dicts), TypedDict, and custom types through registered hooks. The package includes pre-configured converters for JSON, msgpack, CBOR, BSON, YAML, TOML, and other serialization formats. Runtime dependencies are minimal: attrs (which it's designed around), exceptiongroup (for grouped validation errors), and typing-extensions (for type hint compatibility).
Use it for
- Deserialize API responses or configuration files into typed dataclasses with automatic validation.
- Convert database query results into attrs classes while enforcing field types and constraints.
- Build data pipelines that transform unstructured input into strongly-typed intermediate objects.
- Serialize domain models to multiple formats (JSON, YAML, msgpack) without adding format-specific code to the model.
- Validate and normalize user input from web forms or CLI arguments into typed objects.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
cattrs is actively maintained, permissively licensed, has low install friction, and solves a common problem—bridging unstructured and typed data—without requiring you to pollute your models with serialization logic. It's a good fit if you work with attrs or dataclasses and need flexible, recursive (un)structuring with validation.
Install
cattrs on PyPI
Before you install
Low friction installation with three lightweight runtime dependencies (attrs, exceptiongroup, typing-extensions). Actively maintained as of 2026-02-18 with recent commits and 1049 repository stars.
Requires Python 3.10 or later.
License in practice
MIT license permits unrestricted commercial and private use with minimal obligations—only attribution required.
Quickstart
from attrs import define
from cattrs import structure, unstructure
@define
class C:
a: int
b: list[str]
instance = structure({'a': 1, 'b': ['x', 'y']}, C)
unstructure(instance)
Verify before relying
- Performance characteristics compared to alternative serialization libraries under real-world workloads.
- Extent of support for complex union disambiguation beyond the documented unique-field strategy.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.10 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 3 packagesattrsexceptiongrouptyping-extensions |
| Maintenance | Actively maintained 177 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 73,830,482 / month, #455 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTyping :: Typed |
Evidence: cattrs-26.1.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “dict to class conversion”
- cattrsConverts unstructured dictionaries into properly typed Python classes…
- dict2xmlConverts Python dictionaries into XML strings with configurable…
- desertDesert generates marshmallow serialization schemas automatically from…
Give your agent the search over MCP, or paste the wish link into any chat.
Similar packages
attrs is a Python library that automatically generates common class methods (__init__, __repr__, __eq__, etc.) from declarative attribute definitions, eliminating boilerplate code while maintaining runtime performance.
Install it if you write classes regularly.
Generates lightweight container classes with automatic `__repr__`, comparison methods, and field initialization from a fluent attribute-chain syntax, eliminating boilerplate for simple data holders.
No, not for new projects.
Adds JSON serialization and type validation to Python dataclasses, letting you convert between dataclass instances and JSON/dict representations with automatic type checking.
Dataclass Wizard converts Python dataclasses to and from JSON, YAML, TOML, and environment variables with automatic type coercion and case transformation, using code-generated serialization for performance.
Install it if you need JSON/YAML/TOML/environment variable marshalling for dataclasses and want automatic type coercion and case transformation out of the box.
dictknife provides utility functions for manipulating, querying, and transforming Python dictionaries, with optional support for loading data from files and command-line operations.
However, the aging maintenance status (405 days since last release) and sparse documentation suggest checking whether the specific dict operations you need are…
Serializes and deserializes Python dataclasses to/from dictionaries, JSON, or MessagePack, with built-in validation and support for nested types.
See also databind · databind.json · pyserde · adaptix