attrs

Python Classes Without Boilerplate

https://github.com/python-attrs/attrs

Science Score: 46.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    5 of 176 committers (2.8%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (9.9%) to scientific vocabulary

Keywords

attributes boilerplate classes oop python

Keywords from Contributors

closember unit-testing fuzzing property-based-testing autopep8 codeformatter formatter gofmt pre-commit-hook yapf
Last synced: 6 months ago · JSON representation

Repository

Python Classes Without Boilerplate

Basic Info
  • Host: GitHub
  • Owner: python-attrs
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage: https://www.attrs.org/
  • Size: 4.08 MB
Statistics
  • Stars: 5,598
  • Watchers: 60
  • Forks: 394
  • Open Issues: 137
  • Releases: 25
Topics
attributes boilerplate classes oop python
Created about 11 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing Funding License Code of conduct Citation Security

README.md

attrs

Documentation Downloads per month DOI

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.

Sponsors

attrs would not be possible without our amazing sponsors. Especially those generously supporting us at the The Organization tier and higher:

Please consider joining them to help make attrs’s maintenance more sustainable!

Example

attrs gives you a class decorator and a way to declaratively define the attributes on that class:

```pycon

from attrs import asdict, define, make_class, Factory

@define ... class SomeClass: ... anumber: int = 42 ... listofnumbers: list[int] = Factory(list) ... ... def hardmath(self, anothernumber): ... return self.anumber + sum(self.listofnumbers) * another_number

sc = SomeClass(1, [1, 2, 3]) sc SomeClass(anumber=1, listof_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) {'anumber': 1, 'listof_numbers': [1, 2, 3]}

SomeClass() SomeClass(anumber=42, listof_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__,
  • equality-checking methods,
  • an initializer,
  • and much more,

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


This example uses attrs's modern APIs that have been introduced in version 20.1.0, and the attrs package import name that has been added in version 21.3.0. The classic APIs (@attr.s, attr.ib, plus their serious-business aliases) and the attr package import name will remain indefinitely.

Check out On The Core API Names for an in-depth explanation!

Hate Type Annotations!?

No problem! Types are entirely optional with attrs. Simply assign attrs.field() to the attributes instead of annotating them with types:

```python from attrs import define, field

@define class SomeClass: anumber = field(default=42) listof_numbers = field(factory=list) ```

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 and is more flexible. For instance, it allows you to define special handling of NumPy arrays for equality checks, allows more ways to plug into the initialization process, has a replacement for __init_subclass__, and allows for stepping through the generated methods using a debugger.

For more details, please refer to our comparison page, but generally speaking, we are more likely to commit crimes against nature to make things work that one would expect to work, but that are quite complicated in practice.

Project Information

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.

Owner

  • Name: The attrs Cabal
  • Login: python-attrs
  • Kind: organization

Dedicated to empower Python developers to write better code with less effort.

GitHub Events

Total
  • Fork event: 31
  • Create event: 66
  • Commit comment event: 3
  • Release event: 4
  • Issues event: 68
  • Watch event: 325
  • Delete event: 59
  • Issue comment event: 225
  • Push event: 210
  • Gollum event: 3
  • Pull request review comment event: 39
  • Pull request review event: 86
  • Pull request event: 113
Last Year
  • Fork event: 31
  • Create event: 66
  • Commit comment event: 3
  • Release event: 4
  • Issues event: 68
  • Watch event: 325
  • Delete event: 59
  • Issue comment event: 225
  • Push event: 210
  • Gollum event: 3
  • Pull request review comment event: 39
  • Pull request review event: 86
  • Pull request event: 113

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 1,669
  • Total Committers: 176
  • Avg Commits per committer: 9.483
  • Development Distribution Score (DDS): 0.237
Past Year
  • Commits: 127
  • Committers: 21
  • Avg Commits per committer: 6.048
  • Development Distribution Score (DDS): 0.331
Top Committers
Name Email Commits
Hynek Schlawack hs@o****x 1,274
Tin Tvrtković t****r@g****m 51
pre-commit-ci[bot] 6****] 31
David Euresti d****d@e****m 18
Sviatoslav Sydorenko wk@s****a 14
dependabot[bot] 4****] 10
Christopher Armstrong r****x@t****m 9
Kyle Altendorf s****a@f****t 8
wouter bolsterlee w****r@b****e 7
Stefan Scherfke s****n@s****g 7
David Cournapeau c****e@g****m 7
chrysle i****t@p****e 5
Filipe Brandenburger f****e@h****m 5
Thomas Grainger t****n@g****m 4
Alex Ford a****d@a****m 4
Samuel A. Falvo II s****o@r****m 4
Ryan Gabbard g****d@i****u 4
Glyph g****h@t****m 3
John Belmonte j****n@n****t 3
Joshua Oreman o****j@g****m 3
Tim Gates t****s@i****m 3
Denis Laxalde d****s@l****g 3
Antonio Botelho m****t@g****m 3
Aaron Stephens a****t 3
paul fisher p****r@t****m 3
Paul Ganssle p****l@g****o 3
mikejturner m****r@a****u 2
Łukasz Langa l****z@l****l 2
Nick Pope n****k@n****k 2
Oliver Bestwalter o****r@b****e 2
and 146 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 214
  • Total pull requests: 322
  • Average time to close issues: 6 months
  • Average time to close pull requests: 24 days
  • Total issue authors: 158
  • Total pull request authors: 66
  • Average comments per issue: 3.46
  • Average comments per pull request: 2.06
  • Merged pull requests: 261
  • Bot issues: 0
  • Bot pull requests: 44
Past Year
  • Issues: 39
  • Pull requests: 111
  • Average time to close issues: 22 days
  • Average time to close pull requests: 11 days
  • Issue authors: 32
  • Pull request authors: 31
  • Average comments per issue: 1.85
  • Average comments per pull request: 1.1
  • Merged pull requests: 77
  • Bot issues: 0
  • Bot pull requests: 20
Top Authors
Issue Authors
  • hynek (14)
  • AdrianSosic (11)
  • glyph (4)
  • redruin1 (4)
  • euresti (3)
  • Darkdragon84 (3)
  • Tinche (3)
  • raphCode (2)
  • webknjaz (2)
  • txemi (2)
  • rklasen (2)
  • befeleme (2)
  • serge-sans-paille (2)
  • my1e5 (2)
  • ikonst (2)
Pull Request Authors
  • hynek (132)
  • pre-commit-ci[bot] (31)
  • Tinche (16)
  • dependabot[bot] (15)
  • webknjaz (14)
  • filbranden (12)
  • dlax (9)
  • chrysle (5)
  • diabolo-dan (4)
  • geofft (4)
  • esteevens (4)
  • frenzymadness (4)
  • sscherfke (4)
  • redruin1 (4)
  • koenigdavidmj (3)
Top Labels
Issue Labels
Feature (27) Typing (18) Bug (17) Documentation (13) Thinking (6) Performance (5) Good for New Contributors (4) Meta (3) Invalid (2) On Hold (2) dataclasses (2) Question (1)
Pull Request Labels
dependencies (16) github_actions (5) Feature (2) Cleanup (2) Meta (1)

Packages

  • Total packages: 3
  • Total downloads:
    • pypi 392,796,576 last-month
  • Total docker downloads: 7,038,711,185
  • Total dependent packages: 3,093
    (may contain duplicates)
  • Total dependent repositories: 229,719
    (may contain duplicates)
  • Total versions: 67
  • Total maintainers: 1
pypi.org: attrs

Classes Without Boilerplate

  • Versions: 34
  • Dependent Packages: 2,857
  • Dependent Repositories: 226,649
  • Downloads: 392,796,576 Last month
  • Docker Downloads: 7,038,711,185
Rankings
Dependent repos count: 0.0%
Downloads: 0.0%
Docker downloads count: 0.0%
Dependent packages count: 0.0%
Average: 0.7%
Stargazers count: 0.8%
Forks count: 3.6%
Maintainers (1)
Funding
  • https://github.com/sponsors/hynek
Last synced: 6 months ago
conda-forge.org: attrs

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). 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:

  • Versions: 16
  • Dependent Packages: 205
  • Dependent Repositories: 1,535
Rankings
Dependent packages count: 0.3%
Dependent repos count: 0.4%
Average: 3.8%
Stargazers count: 5.1%
Forks count: 9.3%
Last synced: 6 months ago
anaconda.org: attrs

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). 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:

  • Versions: 17
  • Dependent Packages: 31
  • Dependent Repositories: 1,535
Rankings
Dependent packages count: 1.2%
Dependent repos count: 2.6%
Average: 8.5%
Stargazers count: 11.7%
Forks count: 18.4%
Last synced: 6 months ago

Dependencies

.github/workflows/build-docset.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • step-security/harden-runner v2 composite
.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/download-artifact v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • hynek/build-and-inspect-python-package v1 composite
  • re-actors/alls-green release/v1 composite
  • step-security/harden-runner v2 composite
.github/workflows/codeql-analysis.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/init v2 composite
  • step-security/harden-runner v2 composite
.github/workflows/pypi-package.yml actions
  • actions/checkout v3 composite
  • pypa/gh-action-pypi-publish release/v1 composite
  • step-security/harden-runner v2 composite
pyproject.toml pypi
  • importlib_metadata python_version<'3.8'