All Projects → python-attrs → Attrs

python-attrs / Attrs

Licence: mit
Python Classes Without Boilerplate

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Attrs

Bash Oo Framework
Bash Infinity is a modern standard library / framework / boilerplate for Bash
Stars: ✭ 5,247 (+38.59%)
Mutual labels:  oop, boilerplate
Electron React Boilerplate
A Foundation for Scalable Cross-Platform Apps
Stars: ✭ 18,727 (+394.64%)
Mutual labels:  boilerplate
React Bolt
⚡ The most simple & robust boilerplate for your React projects.
Stars: ✭ 298 (-92.13%)
Mutual labels:  boilerplate
Kratos Boilerplate
🔥 A simple boilerplate for creating statics PWA using Webpack, Pug, PostCSS and CSS Modules
Stars: ✭ 308 (-91.86%)
Mutual labels:  boilerplate
Fullstack Apollo Express Mongodb Boilerplate
💥A sophisticated GraphQL with Apollo, Express and MongoDB boilerplate project.
Stars: ✭ 301 (-92.05%)
Mutual labels:  boilerplate
Ionic Boilerplate
✨ An Ionic Starter kit featuring Tests, E2E, Karma, Protractor, Jasmine, Istanbul, Gitlab CI, Automatic IPA and APK, TypeScript 2, TsLint, Codelyzer, Typedoc, Yarn, Rollup, and Webpack 2
Stars: ✭ 309 (-91.84%)
Mutual labels:  boilerplate
Stampit
OOP is better with stamps: Composable object factories.
Stars: ✭ 3,021 (-20.21%)
Mutual labels:  oop
React Webpack Boilerplate
Minimalistic ES6+ React boilerplate with Hot Reloading using Webpack 4 and Babel 7
Stars: ✭ 336 (-91.13%)
Mutual labels:  boilerplate
Pyspark Boilerplate
A boilerplate for writing PySpark Jobs
Stars: ✭ 318 (-91.6%)
Mutual labels:  boilerplate
Laconia
🏺 ‎ A minimalist MVC framework.
Stars: ✭ 307 (-91.89%)
Mutual labels:  oop
React Redux Boilerplate
Awesome React Redux Workflow Boilerplate with Webpack 4
Stars: ✭ 307 (-91.89%)
Mutual labels:  boilerplate
Laravel Api Boilerplate
Laravel API Boilerplate | Please consult the Wiki !
Stars: ✭ 300 (-92.08%)
Mutual labels:  boilerplate
Nuxt Material Admin
Vue-CLI Boilerplate based on Nuxt and vue-material-admin template.
Stars: ✭ 310 (-91.81%)
Mutual labels:  boilerplate
Project Stub
deps
Stars: ✭ 300 (-92.08%)
Mutual labels:  boilerplate
Android Architecture Components
The template project that uses Android Architecture Components with Repository pattern. The simple app that uses awesome Fuel library instead of Retrofit for perfoming HTTP request. The app also persists data using the Room library and display data in RecyclerView.
Stars: ✭ 329 (-91.31%)
Mutual labels:  boilerplate
Flask Api Starter Kit
Start a Flask API in less than 5 minutes
Stars: ✭ 296 (-92.18%)
Mutual labels:  boilerplate
React Native Auth Boilerplate
A react native boilerplate with authentication already implemented
Stars: ✭ 307 (-91.89%)
Mutual labels:  boilerplate
Graphql Starter
💥 Monorepo template (seed project) pre-configured with GraphQL API, PostgreSQL, React, Relay, and Material UI.
Stars: ✭ 3,377 (-10.8%)
Mutual labels:  boilerplate
Tensorflow Project Template
A best practice for tensorflow project template architecture.
Stars: ✭ 3,466 (-8.45%)
Mutual labels:  oop
Cpp Project
Boiler plate template for C++ projects, with CMake, Doctest, Travis CI, Appveyor, Github Actions and coverage reports.
Stars: ✭ 328 (-91.34%)
Mutual labels:  boilerplate

attrs

Documentation License: MIT

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.

For that, it gives you a class decorator and a way to declaratively define the attributes on that class:

>>> from typing import List
>>> from attr import asdict, define, make_class, Factory

>>> @define
... class SomeClass:
...     a_number: int = 42
...     list_of_numbers: List[int] = Factory(list)
...
...     def hard_math(self, another_number):
...         return self.a_number + sum(self.list_of_numbers) * another_number


>>> sc = SomeClass(1, [1, 2, 3])
>>> sc
SomeClass(a_number=1, list_of_numbers=[1, 2, 3])

>>> sc.hard_math(3)
19
>>> sc == SomeClass(1, [1, 2, 3])
True
>>> sc != SomeClass(2, [3, 2, 1])
True

>>> asdict(sc)
{'a_number': 1, 'list_of_numbers': [1, 2, 3]}

>>> SomeClass()
SomeClass(a_number=42, list_of_numbers=[])

>>> C = make_class("C", ["a", "b"])
>>> C("foo", "bar")
C(a='foo', b='bar')

After declaring your attributes attrs gives you:

  • a concise and explicit overview of the class's attributes,
  • a nice human-readable __repr__,
  • a complete set of comparison methods (equality and ordering),
  • an initializer,
  • and much more,

without writing dull boilerplate code again and again and without runtime performance penalties.

This gives you the power to use actual classes with actual types in your code instead of confusing tuples or confusingly behaving namedtuples. Which in turn encourages you to write small classes that do one thing well. Never again violate the single responsibility principle just because implementing __init__ et al is a painful drag.


In case you're wondering: this example uses attrs's modern APIs that have been introduced in version 20.1.0. The classic APIs (@attr.s, attr.ib, @attr.attrs, attr.attrib, and attr.dataclass) will remain indefinitely. Type annotations will also stay entirely optional forever.

Please check out On The Core API Names for a more in-depth explanation.

Data Classes

On the tin, attrs might remind you of dataclasses (and indeed, dataclasses are a descendant of attrs). In practice it does a lot more more and is more flexible. For instance it allows you to define special handling of NumPy arrays for equality checks, or allows more ways to plug into the initialization process.

For more details, please refer to our comparison page.

Getting Help

Please use the python-attrs tag on Stack Overflow to get help.

Answering questions of your fellow developers is also a great way to help the project!

Project Information

attrs is released under the MIT license, its documentation lives at Read the Docs, the code on GitHub, and the latest release on PyPI. It’s rigorously tested on Python 2.7, 3.5+, and PyPy.

We collect information on third-party extensions in our wiki. Feel free to browse and add your own!

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. Learn more.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].