attrs
Python classes without boilerplate — generate init, repr, equality, and more from declarative field definitions.
Repository Health
Technical Analysis
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
Agno
Devops · AI Development · Automation
Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.
Apache Airflow
Data Engineering
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.
argilla
AI Development · Data Engineering
Collaborate on high-quality AI training data with a self-hosted annotation platform built for LLMs, NLP, and multimodal models.
ClearML
Devops · Automation
Auto-magical MLOps platform that tracks experiments, versions data, orchestrates pipelines, and serves models with just two lines of code.
CubeSandbox
Developer Tools · Security · AI Agents
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.
DataLens
Analytics
Open-source business intelligence platform with drag-and-drop dashboards, multi-source SQL connectors, and Kubernetes-ready deployment built by Yandex.
Dragonfly
Databases · Developer Tools · Devops
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.
GPT Researcher
Productivity · AI Assistants
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.
GrowthBook
Developer Tools · Analytics · Monitoring
Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.