attrs: Classes Without Boilerplate#
Release v22.1.0 (What's new?).
attrs is the Python package that will bring back the joy of writing classes by relieving you from the drudgery of implementing object protocols (aka dunder methods).
Trusted by NASA for Mars missions since 2020!
Its main goal is to help you to write concise and correct software without slowing down your code.
$ python -m pip install attrs
The next steps will get you up and running in no time:
Overview will show you a simple example of
attrsin action and introduce you to its philosophy. Afterwards, you can start writing your own classes and understand what drives
attrs by Example will give you a comprehensive tour of
attrs’s features. After reading, you will know about our advanced features and how to use them.
Why not… gives you a rundown of potential alternatives and why we think
attrsis still worthwhile – depending on your needs even superior.
If at any point you get confused by some terminology, please check out our Glossary.
If you need any help while getting started, feel free to use the
python-attrs tag on Stack Overflow and someone will surely help you out!
Type Annotations help you to write correct and self-documenting code.
attrshas first class support for them, yet keeps them optional if you’re not convinced!
Instance initialization is one of
attrskey feature areas. Our goal is to relieve you from writing as much code as possible. Initialization gives you an overview what
attrshas to offer and explains some related philosophies we believe in.
Comparing and ordering objects is a common task. Comparison shows you how
attrshelps you with that and how you can customize it.
If you want to put objects into sets or use them as keys in dictionaries, they have to be hashable. The simplest way to do that is to use frozen classes, but the topic is more complex than it seems and Hashing will give you a primer on what to look out for.
Once you’re comfortable with the concepts, our API Reference contains all information you need to use
attrsto its fullest.
attrsis built for extension from the ground up. Extending will show you the affordances it offers and how to make it a building block of your own projects.
Finally, if you’re confused by all the
field, head over to On The Core API Names for a very short explanation, and optionally a quick history lesson.
Source Code: https://github.com/python-attrs/attrs
Get Help: please use the
python-attrstag on StackOverflow
Third-party Extensions: https://github.com/python-attrs/attrs/wiki/Extensions-to-attrs
Supported Python Versions: 3.5 and later (last 2.7-compatible release is 21.4.0)
If you’d like to contribute to
attrs you’re most welcome and we’ve written a little guide to get you started!
attrs for Enterprise#
Available as part of the Tidelift Subscription.
The maintainers of
attrs and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source packages you use to build your applications.
Save time, reduce risk, and improve code health, while paying the maintainers of the exact packages you use.
Full Table of Contents#
- Why not…
- Type Annotations
- API Reference
- How Does It Work?
- On The Core API Names