attrs

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

Library
PyPI
v26.1.0
5,860 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
82 /100 Excellent
Development Activity 92
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

TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,235

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
74
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 6 days ago
Python
94%
Apache 2.0

knowhere

AI Development · AI Memory · Developer Tools

3,755

Transform messy, unstructured documents into persistent, navigable memory that AI agents can actually use.

View details
83
Repo Health
75
Technical
66
Dependency
Built with
Python 94%
Updated 6 days ago
TypeScript
39%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,540

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
64
Dependency
Built with
TypeScript 39%
JavaScript 27%
Python 25%
Updated 1 weeks ago
Python
62%
Apache 2.0

marimo

Data Engineering · Developer Tools

23,309

A reactive Python notebook that eliminates hidden state, runs reproducibly, and deploys as a web app or script — stored as pure Python, built for the AI era.

View details
90
Repo Health
91
Technical
65
Dependency
Built with
Python 62%
TypeScript 37%
Updated 6 days ago
Python
39%
Apache 2.0

OpenSandbox

Developer Tools · Security

16,116

Secure, fast, and extensible sandbox runtime for AI agents with multi-language SDKs and Docker/Kubernetes runtimes.

View details
85
Repo Health
81
Technical
70
Dependency
Built with
Python 39%
Go 36%
Updated 6 days ago
Go
71%
Apache 2.0

OSV.dev

Security

3,001

Google's open-source vulnerability database that maps CVEs to exact package versions across 50+ ecosystems with a public API and data dumps.

View details
87
Repo Health
82
Technical
66
Dependency
Built with
Go 71%
Python 19%
Updated 1 weeks ago
TypeScript
50%
Other

Phase Console

Devops · Security

931

End-to-end encrypted secrets management for engineering teams — from local dev to Kubernetes production.

View details
85
Repo Health
73
Technical
63
Dependency
Built with
TypeScript 50%
Python 48%
Updated 1 weeks ago
Rust
63%
MIT

PostgresML

AI Development · Databases

6,823

Run ML training and LLM inference natively inside PostgreSQL with GPU acceleration — no data movement required.

View details
51
Repo Health
76
Technical
64
Dependency
Built with
Rust 63%
JavaScript 11%
Updated 1 years ago
Python
99%
Apache 2.0

Rasa Open Source

AI Assistants · AI Development · Voice AI

21,353

Rasa Open Source is a Python machine learning framework for building contextual, multi-turn chatbots and voice assistants that understand natural language and maintain conversation state.

View details
62
Repo Health
78
Technical
63
Dependency
Built with
Python 99%
Updated 3 months 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