Open-source project
python-attrs/attrs avatar
python-attrs/attrs

attrs ships zero dependencies and keeps two API generations alive on purpose

Python Classes Without Boilerplate

5,865 stars522 forksPythonMIT

At a glance

What is it?
attrs writes the dunder methods for your Python classes so you do not have to, with an empty dependency list and a floor of Python 3.10. The interesting part is what it refuses to drop: the modern define API and the old attr.s spelling are both permanent, versions come straight from git tags, and the comparison with dataclasses is argued out loud rather than quietly.
Who is it for?
Use it when your classes carry real behaviour and you want a repr, equality and an initializer without writing them, and start from the define API rather than the legacy spelling. Do not reach for it as a validation layer, since coercion and parsing are never mentioned on the front page, and read the names page before migrating older code because two API generations are permanent by design.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 1 day ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 24, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • python-attrs/attrs5,865 ★ · +21
Star history
Repository2026-09-232026-11-24
python-attrs/attrs5.8k5.9k

21 Stars in the last 62 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

dependencies is an empty list and every test tool lives in a dependency group

The dependency field in pyproject.toml is an empty list, which is the whole runtime story: attrs pulls nothing into your environment when it is installed. Everything else is grouped. The tests group carries hypothesis, pympler, pytest greater than version 9 and pytest-xdist with psutil, plus cloudpickle on CPython with an inline comment explaining that it is there for a regression test to make sure cloudpickle compatibility does not break. The mypy group adds pytest-mypy-plugins, gated on CPython and Python 3.10 or later. Linting is ruff 0.16 or newer with prek 0.4 or newer, and there are separate groups for coverage, pyright and ty, meaning the library is checked by more than one type checker. The project floor is requires-python at 3.10, and the classifiers name CPython, PyPy and a typed marker.

The version number is derived from git tags, not written in pyproject.toml

version and readme are both listed as dynamic fields, and the build system explains why: hatchling with hatch-vcs and hatch-fancy-pypi-readme at 23.2.0 or newer. So the version published to PyPI is derived from the repository's tags rather than typed into a string, and the long description on the package index is assembled from README.md instead of being kept in the project file by hand. The tags themselves use a calendar style scheme: 26.1.0 published 2026-03-19, 25.4.0 on 2025-10-06, and 25.3.0 on 2025-03-13. Those dates show uneven gaps, seven months then five. The last push to main landed 2026-11-02, so work is landing between releases rather than only at tag time.

@attr.s is permanent and @define arrived in 20.1.0, so both spellings ship

The example on the front page uses what the file calls the modern APIs, introduced in version 20.1.0, together with the attrs package import name added in 21.3.0. Alongside that, the classic APIs, @attr.s and attr.ib plus their aliases, which the file calls serious business aliases, and the older attr import name are said to remain indefinitely. That is an unusual promise for a library at this stage: two generations of API surface, one decorator you write on new code and one you keep writing in old code, both supported in the same release. The file defers the details to a page called On The Core API Names, which is where the naming split between attr and attrs is explained in depth. Nothing in the front page tells you which one a new project should start with, so that choice is left to you.

Types are optional, so field() with a factory is a first class spelling

One heading on the front page is a question with a one word answer: you do not have to want type annotations. Types are described as entirely optional, and the alternative is to assign field() to the attributes instead of annotating them:

python
from attrs import define, field

@define
class SomeClass:
    a_number = field(default=42)
    list_of_numbers = field(factory=list)

The annotated form in the earlier example uses Factory from attrs for the mutable default, so a list attribute gets a fresh list per instance, while this form uses factory=list to say the same thing without a type. That matters beyond style: the point of the library is that the protocol methods are generated for you either way, so opting out of annotations costs you nothing at the class body level. What the page does not show is any validation, coercion or parsing hook, which is the gap between this and the libraries people reach for when they want their input checked.

attrs claims more than dataclasses, and admits the cost of doing it

The comparison section starts by conceding the resemblance: on the tin, attrs might remind you of dataclasses, and dataclasses are in fact a descendant of attrs. Then it argues the other direction. attrs allows custom handling of NumPy arrays for equality checks, allows more ways to plug into the initialization process, provides a replacement for __init_subclass__, and lets you step through the generated methods with a debugger instead of treating them as opaque. The honesty is notable. Rather than claiming a clean win, the file says its authors 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. In other words the flexibility is real and so is the weirdness, and the page asks you to accept both. Details live on a separate comparison page rather than here.

The sponsor logos in the README are generated out of pyproject.toml by cog

The sponsor block is not maintained by hand. Between HTML comment markers the file contains a cog script that imports pathlib and tomllib, reads tool.sponcon.sponsors out of pyproject.toml, and prints one anchor tag per sponsor, which is why the listed logos appear in the same order as the project file and regenerate whenever cog runs. The listed names are variomedia, tidelift, kraken.tech, privacy-solutions.org, klaviyo, filepreviews.io, testmuai and polar.sh, and the appeal is aimed at The Organization tier and higher, with the stated reason that sponsorship makes maintenance more sustainable. Commercial support runs through the Tidelift subscription, which sells maintenance for the exact packages you use. The header badges also link a coreinfrastructure best practices entry and an AI policy file in the repository's .github directory.

bench/ and codspeed.yml track performance, but no number appears on the front page

The front page claims the generated methods come without runtime performance penalties, and the repository is set up to check that. There is a bench/ directory and a codspeed.yml configuration at the root, which is the shape of a project that measures speed in continuous integration rather than by hand. The rest of the root is telling too: tests/, tox.ini, typing_tests/ as a directory of its own, a .pre-commit-config.yaml, a .python-version-default file, uv.lock for dependency locking, CHANGELOG.md and a changelog.d/ directory for fragments, plus CITATION.cff and .git_archival.txt. What is missing is the number itself. No timing, no comparison against a plain class written by hand, and no statement about memory sits on the front page, so the performance claim is a promise with machinery behind it rather than a figure you can check before installing.

Editorial conclusion

Use it when your classes carry real behaviour and you want a repr, equality and an initializer without writing them, and start from the define API rather than the legacy spelling. Do not reach for it as a validation layer, since coercion and parsing are never mentioned on the front page, and read the names page before migrating older code because two API generations are permanent by design. Check your interpreter against the 3.10 floor and pin a release, since the version number is derived from git tags rather than written in the project file.

Frequently asked questions

how to use attrs

Apply the define decorator to a class and declare attributes either as annotations or by assigning field() to them. Mutable defaults are expressed as Factory(list) in the annotated form and as field(factory=list) in the plain form, and asdict() turns an instance into a regular dictionary.

what is attrs in python

A Python package that implements the object protocols for you. Given a class whose attributes are declared, it generates a human readable __repr__, equality checking methods and an initializer, with types entirely optional and no runtime dependencies.

attrs vs dataclasses

dataclasses are a descendant of attrs, and the project argues attrs is the more flexible of the two: custom equality handling such as NumPy arrays, more ways to hook into initialization, a replacement for __init_subclass__, and generated methods you can step through in a debugger.

Official sources

  1. License: MIT
  2. Project website
  3. python-attrs/attrs on GitHub
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/python-attrs-attrs.svg)](https://hysenlabs.com/projects/python-attrs-attrs)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/python-attrs-attrs.svg)](https://hysenlabs.com/projects/python-attrs-attrs)

Was this useful?