Versioned persistence for Python dataclasses with hash validation, declarative migrations, and pluggable backends
Project description
versionable
Future-proof your data files. Save structured Python objects with versioning, declarative migrations, and open file formats.
Why versionable ?
Your data lives in files. Your code keeps changing. Without versioning, old files silently load with missing fields, wrong types, or stale values.
versionable fixes that. Every file is stamped with a version number and a fingerprint of its structure. Files
written by v1 of your code load cleanly into v5, automatically migrated, never silently broken. Save to standard formats
out of the box: JSON, HDF5, YAML, and TOML.
What you get:
- Zero boilerplate — no schema files, no code generation, no build step. Just inherit from
Versionable - Simple versioning with declarative migrations — rename, add, remove, or transform fields across versions
- Rich type support — datetime, Path, UUID, Enum, numpy arrays, and more — easy to extend with your own
- Nested objects with independent versioning — compose complex dataclasses from smaller
Versionablepieces - Incremental HDF5 writes — append rows as data arrives, no need to hold everything in memory
- Random access for huge files — read slices directly from disk without loading the whole file
- JSON, HDF5, YAML, TOML — or bring your own backend
- Import-time safety — schema hash mismatches are caught when your module loads, not in production
- Modern, type-safe Python — fully typed and compatible with mypy, pyright, and other static analyzers
How does it compare?
| Versionable Features | pickle | dc libs¹ | protobuf | raw JSON | sidecars |
|---|---|---|---|---|---|
| ✅ Zero boilerplate | ✅ | ✅ | 🛠️ | - | - |
| ✅ Versioning with declarative migrations | 🛠️ | - | - | 🛠️ | - |
| ✅ Rich type support | ✅ | ✅ | 🛠️ | 🛠️ | 🟠 |
| ✅ Nested objects, versioned independently | 🟠 | 🛠️ | 🟠 | 🛠️ | - |
| ✅ Incremental HDF5 writes | - | - | - | - | 🛠️ |
| ✅ Random access for huge files | - | - | - | - | 🛠️ |
| ✅ Custom Backends | - | 🟠 | 🟠 | 🟠 | - |
| ✅ Import-time validation | - | - | 🛠️ | - | - |
| ✅ Modern, type-safe Python | - | ✅ | ✅ | - | - |
¹ pydantic, dataclasses-json, etc.
- 🛠️ = requires manual effort / build step
- 🟠 = partial
Installation
The base install includes the JSON backend (no extra dependencies beyond numpy):
pip install versionable
Add backend support as needed (JSON is included by default):
pip install pyyaml # YAML backend (.yaml, .yml)
pip install toml # TOML backend (.toml)
pip install h5py hdf5plugin # HDF5 backend (.h5, .hdf5)
Or install the latest main from source:
pip install git+https://github.com/hendrickmelo/versionable.git
Quick Start
Simple files
You save a config file today:
from dataclasses import dataclass
import versionable
from versionable import Versionable
@dataclass
class SensorConfig(Versionable, version=1, hash="4b7866"):
name: str
value: float
config = SensorConfig(name="experiment-A", value=9.81)
versionable.save(config, "config.json")
A few weeks later you rename value to magnitude. Without versionable, old files silently load with missing data.
With it, you bump the version and declare a migration — old files upgrade automatically:
from versionable import Migration
@dataclass
class SensorConfig(Versionable, version=2, hash="a70249"):
name: str
magnitude: float # renamed from "value"
class Migrate:
v1 = Migration().rename("value", "magnitude")
# Old v1 file loads and the old field is automatically migrated
loaded = versionable.load(SensorConfig, "config.yaml")
assert loaded.magnitude == 9.81
Catching Version Drift
The hash parameter is a fingerprint of your fields and their types. It's optional, but when present it catches version
drift: if you change a field and forget to bump the version, Python raises an error as soon as the module is imported.
Not when a user opens a corrupt file in production. During development, in CI, at deploy time.
For example, if you rename value to magnitude but keep the old hash:
# This raises at import time — not at runtime, not in production
@dataclass
class SensorConfig(Versionable, version=2, hash="4b7866"): # ⬅ Old V1 Hash
name: str
magnitude: float # changed, but hash wasn't updated
...
# HashMismatchError: SensorConfig: hash mismatch — declared '4b7866',
# computed 'a70249'. Update the hash parameter to 'a70249'.
Update the hash, add a migration, and you're done ✔️. A few weird looking characters now, and your data is future-proof.
Working with Large Data
For scientific and engineering workflows, fields map to native HDF5 chunked datasets. You can append rows incrementally and read slices from disk without loading the whole file into memory:
import numpy as np
from numpy.typing import NDArray
@dataclass
class Experiment(Versionable, version=1, hash="536849"):
name: str
traces: NDArray[np.float64] = field(default_factory=lambda: np.empty((0, 1024)))
# Append to a chunked, resizable dataset as data arrives
session = versionable.hdf5.open(Experiment, "run.h5")
with session as obj:
obj.name = "long-running-acquisition"
for batch in data_source:
obj.traces.append(batch) # extends the dataset on disk
session.flush() # flush HDF5 buffers to OS
# Read slices directly from disk without loading the whole file
with versionable.hdf5.open(Experiment, "run.h5", mode="read") as obj:
print(obj.traces[1000]) # reads only row 1000
print(obj.traces[50:100]) # reads only this slice
Learn More
Want to see how old files get upgraded automatically when your schema changes?
- See migrations in action
- Explore the available backends
For AI Agents
If you're an AI agent working with versionable, see AGENT.md for a condensed API reference.
Complete Documentation
For custom type converters, HDF5 support, and more, see the full documentation.
Acknowledgements
The idea behind versionable started over 15 years ago in C++, where I first learned the approach from
Steve Araiza. Over the years the idea of a Serializable / Versionable class evolved from
using CArchive to make use of C++11, variadic macros, and other fun modern C++ features. Some version of this pattern
has been a part of every project I've worked on since those days.
This is the Python version of the idea. It is built using modern, type-safe Python with great fresh ideas from Emma Powers.
A big thank you to both of them! 🥓🥞🍳
License
MIT - Copyright ©️ 2026 Hendrick Melo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file versionable-0.1.0.tar.gz.
File metadata
- Download URL: versionable-0.1.0.tar.gz
- Upload date:
- Size: 397.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c5d310bff509a5133102b7686946e80d100c6f1836f89d6d8375441e56a0d3bc
|
|
| MD5 |
5f8bdfc3530785a5157eab3038d6a6d3
|
|
| BLAKE2b-256 |
c6372e68269aeb0a1e6640284dd56063d75b581acb1b5ffb4c8012f726e58f35
|
Provenance
The following attestation bundles were made for versionable-0.1.0.tar.gz:
Publisher:
publish.yml on hendrickmelo/versionable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
versionable-0.1.0.tar.gz -
Subject digest:
c5d310bff509a5133102b7686946e80d100c6f1836f89d6d8375441e56a0d3bc - Sigstore transparency entry: 1311791350
- Sigstore integration time:
-
Permalink:
hendrickmelo/versionable@c4aef87c420f90de335cfeaadd6ab94d3c43ca82 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hendrickmelo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4aef87c420f90de335cfeaadd6ab94d3c43ca82 -
Trigger Event:
release
-
Statement type:
File details
Details for the file versionable-0.1.0-py3-none-any.whl.
File metadata
- Download URL: versionable-0.1.0-py3-none-any.whl
- Upload date:
- Size: 52.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8195757b6d085e1bc9b81a6fab0d6a819a825aa1244f3f6e35e5e1c4a32ffe12
|
|
| MD5 |
8f81c314c7681c02f110709580dee667
|
|
| BLAKE2b-256 |
a6654d9b36b3477f4b48e22c12c17a2aee08e6993821c248276b35a8d6f5b62b
|
Provenance
The following attestation bundles were made for versionable-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on hendrickmelo/versionable
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
versionable-0.1.0-py3-none-any.whl -
Subject digest:
8195757b6d085e1bc9b81a6fab0d6a819a825aa1244f3f6e35e5e1c4a32ffe12 - Sigstore transparency entry: 1311791467
- Sigstore integration time:
-
Permalink:
hendrickmelo/versionable@c4aef87c420f90de335cfeaadd6ab94d3c43ca82 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/hendrickmelo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c4aef87c420f90de335cfeaadd6ab94d3c43ca82 -
Trigger Event:
release
-
Statement type: