Install & Compatibility
Where this runs
tested against v2.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.542s · 24.4MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 3.8s · import 0.478s · 25MB
23MB installed
● package 23MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
datafiles
✓ import datafiles
✗ from datafiles import datafile
datafiles uses decorators, not direct import of a class named datafile.
datafile
✓ from datafiles import datafile
✗ import datafile
The decorator is in the datafiles package.
Define a dataclass decorated with @datafile to map its instances to a YAML file.
from dataclasses import dataclass
from datafiles import datafile
@datafile("data/{self.name}.yml")
class Person:
name: str
age: int = 0
p = Person("Alice")
p.age = 30
print(p.age) # 30
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'datafiles'
The library is not installed.
fixRun `pip install datafiles`.
ModuleNotFoundError: No module named 'yaml'
PyYAML is required for YAML files and not installed.
fixRun `pip install datafiles[yaml]` or `pip install PyYAML`.
AttributeError: 'Person' object has no attribute '_datafile_'
The class was not decorated with @datafile.
fixAdd `@datafile(...)` decorator to the dataclass.
TypeError: datafile() missing 1 required positional argument: 'pattern'
The @datafile decorator requires a file pattern argument.
fixUse `@datafile('path/to/file.{self.attr}.yml')`. Upgrade
Version history
2.5latest on PyPI · released Jan 30, 2026
Audit
Dependencies
PyYAMLrequiredRequired for YAML file support.
tomloptionalRequired for TOML file support.