attrs

Python classes without boilerplate — generate init, repr, equality, and more from declarative field definitions.

Library
PyPI
v26.1.0
5,846 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
80 /100 Excellent
Development Activity 84
Maintenance 72
Community 64
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 90
Code Quality 95
Innovation 92
Learning Curve 80

attrs is a mature, dependency-free Python library that brings back the joy of writing classes by removing the drudgery of implementing object protocols by hand. With a single class decorator and declarative field definitions, it generates initializers, string representations, equality and ordering methods, hashing, and slots — without runtime performance penalties.

Trusted in production across the ecosystem (and by NASA for Mars missions), attrs is the direct ancestor of the standard library’s dataclasses and remains far more flexible, offering validators, converters, custom setattr hooks, and deep customization of the generated code.

What You Get

  • A class decorator (@define / @attr.s) that generates init, repr, eq, and optional ordering and hashing methods.
  • Declarative field definitions via type annotations or field() calls, with defaults, factories, and keyword-only support.
  • Built-in validators and converters to enforce and normalize attribute values at construction time.
  • Memory-efficient slotted classes by default, plus frozen (immutable) class support.
  • Helper functions like asdict, astuple, evolve, and fields for introspection and transformation.
  • Full type-checker support with bundled stubs and py.typed, plus a stable classic API kept indefinitely.

Common Use Cases

  • Modeling structured data and value objects without hand-writing initializers and comparison logic.
  • Building immutable, frozen configuration or domain objects with validation on construction.
  • Replacing verbose plain classes or extending beyond the limits of the standard dataclasses module.
  • Normalizing and validating inputs automatically via converters and validators.
  • Introspecting and transforming instances with asdict, astuple, and evolve for serialization or updates.

Under The Hood

Architecture - attrs is organized as two importable packages under src/: the classic attr namespace and the modern attrs namespace, which is a thin keyword-only facade (src/attr/_next_gen.py defines @define and field by partially applying the classic attrs/attrib with better defaults). The engine lives in src/attr/_make.py (~3,435 lines), which collects declared fields, builds Attribute descriptors, and dynamically compiles init, repr, eq, hash, and setattr logic by generating source code and exec-ing it for near-hand-written speed. Supporting concerns are cleanly separated into focused modules: _funcs.py (asdict/astuple/evolve), validators.py, converters.py, setters.py, filters.py, _cmp.py, and exceptions.py.

Tech Stack - Pure Python (99.9% of the codebase) with zero runtime dependencies, supporting CPython and PyPy across Python 3.9 through 3.15. It builds with Hatchling plus hatch-vcs for VCS-derived versioning and hatch-fancy-pypi-readme. Development tooling is modern: uv for locking (uv.lock), Ruff for lint/format, tox for the test matrix, and Sphinx with the Furo theme and towncrier changelog fragments for docs. Types ship as inline .pyi stubs alongside py.typed markers in both packages.

Code Quality - Quality is exemplary. The tests/ directory holds 31 test modules covering make, next-gen APIs, validators, converters, slots, setattr, pattern matching, annotations, pickling compatibility, and packaging, and the suite uses Hypothesis for property-based testing plus pytest-xdist for parallelism and pytest-codspeed for benchmark regressions. Static-analysis conformance is verified against mypy, pyright, ty, and pyrefly. Naming is consistent, public and private modules are clearly delineated by underscore convention, and errors surface through a dedicated exceptions module rather than generic raises.

API Design - The public API is deliberately ergonomic and minimal: @define with field() gives a zero-boilerplate path, type annotations are fully optional, and everything is keyword-only in the modern API to prevent argument-order mistakes. Getting started requires only a decorator and attribute declarations. Documentation is thorough (a full Sphinx site at attrs.org, an extensive changelog, comparison and API-naming guides), and the project intentionally preserves the classic @attr.s API indefinitely so upgrades never break existing code.

Used by 22 apps in this directory

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 5 days ago
Python
89%
Apache 2.0

Apache Airflow

Data Engineering

46,995

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
64
Dependency
Built with
Python 89%
Updated 5 days ago
Python
59%
Apache 2.0

argilla

AI Development · Data Engineering

5,125

Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.

View details
65
Repo Health
81
Technical
61
Dependency
Built with
Python 59%
Jupyter Notebook 21%
Updated 1 weeks ago
Python
100%
Apache 2.0

ClearML

Automation · Devops

6,892

Auto-magical MLOps platform that tracks experiments, versions data, orchestrates pipelines, and serves models with just two lines of code.

View details
94
Repo Health
79
Technical
68
Dependency
Built with
Python 100%
Updated 1 weeks ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
PLpgSQL
98%
Apache 2.0

DataLens

Analytics

1,704

Open-source business intelligence platform with drag-and-drop dashboards, multi-source SQL connectors, and Kubernetes-ready deployment built by Yandex.

View details
62
Repo Health
71
Technical
78
Dependency
Built with
PLpgSQL 98%
Updated 1 months ago
C++
73%
Other

Dragonfly

Databases · Developer Tools · Devops

31,706

A modern Redis and Memcached replacement engineered for multi-core servers — delivering 25x more throughput, better cache hit rates, and up to 80% lower memory consumption with full API compatibility.

View details
90
Repo Health
9
Technical
71
Dependency
Built with
C++ 73%
Python 16%
Updated 6 days ago
Python
70%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

29,650

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
91
Repo Health
91
Technical
63
Dependency
Built with
Python 70%
TypeScript 18%
Updated 1 weeks ago
TypeScript
97%
Other

GrowthBook

Ab Testing Experimentation · Analytics · Developer Tools

8,446

Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.

View details
92
Repo Health
85
Technical
63
Dependency
Built with
TypeScript 97%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers