dataclasses
Stdlib — DataPython 3.7+Intermediate
Decorator for auto-generating class boilerplate (__init__, __repr__, etc.)
Quick Info
- Documentation
- Official Docs
- Python Version
- 3.7+
- Dependencies
- None — Python Standard Library
- Install
Included with Python
Learn by Difficulty
Quick Example
python
from dataclasses import dataclass, field @dataclass class Point: x: float y: float @dataclass class Person: name: str age: int hobbies: list = field(default_factory=list) p = Point(3.0, 4.0) print(p) person = Person("Alice", 30, ["reading", "coding"]) print(person)
The dataclasses module is part of Python's standard library. Decorator for auto-generating class boilerplate (__init__, __repr__, etc.).
Try in PlaygroundTags
stdliboopdata-structuredatatypedecorator
Related Items
class
Keyword
Defines a new class (blueprint for creating objects)
attrs
Package — Validation
Classes without boilerplate: attributes with validation
pydantic
Package — Validation
Data validation using Python type annotations; settings management
typing
Stdlib — Typing
Type hint support: List, Dict, Optional, Union, Any, Callable, Generic, Protocol
__init__
Dunder Method
Constructor; called when a new instance is created to initialize its attributes
__repr__
Dunder Method
Returns an unambiguous developer-facing string representation