Python classes without boilerplate
open sourceMITfree
attrs is a Python library that writes the boring parts of classes for you: you declare a class's attributes with a decorator, and it generates the initializer, a readable repr, equality and ordering methods and more, without a runtime performance cost. Type annotations are optional. Python's own dataclasses descend from it, and attrs does more: custom equality for things like NumPy arrays, hooks into initialization, and generated methods you can step through in a debugger. Hynek Schlawack and its contributors maintain it.
Problems it solves
- stop writing init, repr and eq by hand for every Python class
- define Python data classes with validation and more control than dataclasses
- compare objects holding NumPy arrays correctly in an equality check
Features
- generated init, repr and equality methods
- ordering and hashing on request
- type annotations optional
- custom equality, for example for NumPy arrays
- hooks into initialization
- no runtime performance penalty
Alternatives
The same job
These do what attrs does.
- Pydantic Data validation using Python type hints
