Registry / serialization / datafiles

datafiles

JSON →
library2.5pypypi✓ verified 85d ago

A file-based ORM for Python dataclasses that stores objects in YAML, JSON, or TOML files. Current version: 2.5. Release cadence: irregular, latest in 2023.

pip install datafiles
INSTALL
IMPORT
SIG · DATAFILES
D
datafiles
serializationpythonv2.5
Install
3.8s avg
Import
510ms
Disk
23MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.542s · 24.4MB
glibc
py 3.103.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
Debug
Known issues
breakingIn version 2.0, the storage directory structure changed. Files are now saved by default under the 'data' subdirectory relative to the working directory, not the module's directory.
fix
Update file patterns to use explicit paths or migrate existing data.
affects: >=2.0
deprecatedSupport for TOML format requires the `toml` library, which is not installed by default. Install with `pip install datafiles[toml]`.
fix
Specify the extra dependency.
affects: >=2.0
gotchaFile patterns can be ambiguous. If multiple objects map to the same file, they will overwrite each other. Use unique patterns per class.
fix
Include unique identifiers in the pattern, e.g., '{self.name}'.
affects: all
gotchaChanging a field name after data has been stored will break deserialization because the file format uses field names as keys.
fix
Add migration logic or manually update stored files.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'datafiles'
The library is not installed.
fix
Run `pip install datafiles`.
ModuleNotFoundError: No module named 'yaml'
PyYAML is required for YAML files and not installed.
fix
Run `pip install datafiles[yaml]` or `pip install PyYAML`.
AttributeError: 'Person' object has no attribute '_datafile_'
The class was not decorated with @datafile.
fix
Add `@datafile(...)` decorator to the dataclass.
TypeError: datafile() missing 1 required positional argument: 'pattern'
The @datafile decorator requires a file pattern argument.
fix
Use `@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.
Agent activity
8 hits · last 30 days
node
8
Resources
datafiles — pip install datafiles · libregistry