attrs is a Python package that generates class boilerplate such as repr, equality, and constructors from declarative fields.
Overview
attrs lets Python developers declare attributes on a class and automatically receive initializer, comparison, string representation, and related protocols without hand-written dunder methods.
Modern APIs use the attrs package name and attrs.field definitions introduced in recent releases, while classic attr.s decorators remain supported. Types are optional; untyped field assignments are supported.
The project positions itself as a flexible alternative to dataclasses with hooks for custom equality, initialization, and subclass behavior. NASA Mars mission use is highlighted as a production reference.
Documentation covers migration from dataclasses, third-party extensions, and sponsorship-supported maintenance. attrs is widely used across the Python ecosystem for concise data classes.
Key features
- Declarative class fields
- Auto-generated repr and eq
- Optional type annotations
- Classic and modern APIs
- Custom initialization hooks
- Comparison to dataclasses
- Third-party extension ecosystem
Use cases
- Structured domain models
- Config and data objects
- Reducing class boilerplate