Fields
raw JSON → 5.0.0 verified Fri May 01 auth: no python
A Python library for eliminating class boilerplate by providing an attrs/dataclass-like container class with built-in validation and transformation. Current version is 5.0.0, released on 2025-12-05. Development appears slow; pre-5.0.0 releases were irregular.
pip install fields Common errors
error TypeError: 'Field' object is not callable ↓
cause Trying to call a Field instance as a function (e.g., after defining it as a class attribute).
fix
Fields are descriptors; access via instance attribute, not class attribute. Use instance.field_name.
error ValueError: Field 'x' is required ↓
cause Required field not provided during instantiation.
fix
Pass all required fields as keyword arguments to the constructor.
Warnings
breaking Classmethod and staticmethod descriptors conflict with field inspection; avoid using them inside @fields classes. ↓
fix Define classmethods/staticmethods outside the @fields class or use a different decorator pattern.
gotcha Field name checking uses both the slot name and the variable name; renaming a field variable but not updating the Field's 'name' argument can cause silent failures. ↓
fix Use keyword argument 'name' only when necessary; prefer relying on the variable name.
deprecated The 'validate' parameter in Field is deprecated in 5.0.0; use the 'check' parameter instead. ↓
fix Replace Field(validate=func) with Field(check=func).
Imports
- Field wrong
from fields.field import Fieldcorrectfrom fields import Field - fields wrong
import fieldscorrectfrom fields import fields
Quickstart
from fields import fields, Field
@fields
class Point:
x: int = Field(required=True)
y: int = 0
p = Point(x=3)
print(p.x, p.y) # 3 0