persistent-bundles
Save and load versioned Python object bundles with optional metadata.
persistent-bundles is a small library for objects that manage their own on-disk persistence. It writes a bundle directory containing the saved object, a manifest with the object's class name and semantic version, and optional JSON metadata.
Installation
pip install persistent-bundles
Usage
import json
from pathlib import Path
from typing import Self, override
from persistent_bundles.api import load_bundle, save_bundle
from persistent_bundles.types import Loadable, Savable
class MyObject(Savable, Loadable):
def __init__(self, number: int) -> None:
self.number = number
@override
def save(self, path: Path) -> None:
with (path / "number.json").open("w") as f:
json.dump({"number": self.number}, f)
@classmethod
@override
def load(cls, path: Path) -> Self:
with (path / "number.json").open("r") as f:
data = json.load(f)
return cls(data["number"])
@classmethod
@override
def get_class_version(cls) -> str:
return "1.0.0"
path = Path("example.bundle")
save_bundle(MyObject(42), path, metadata={"created_by": "example"})
obj, metadata = load_bundle(path, {"MyObject": MyObject})
Bundles require a .bundle path suffix. When loading, the saved class version must have the same semantic-version major number as the current class version.
Development
uv run pytest
uv build
Metadata
Release files for persistent-bundles 0.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| persistent_bundles-0.4.1.tar.gz | 2.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| persistent_bundles-0.4.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / persistent_bundles-0.4.1.tar.gz
| Download URL | persistent_bundles-0.4.1.tar.gz |
|---|---|
| Size | 2.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9917999148611e5e36fb9d71635490856b3dece4c754f691304146143c9ca59a
|
|
BLAKE2b-256 checksum How to use checksums |
18f1c7d2289579461306c47bebc1f61a75e90968e937a7a7cd437d86294178e5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|
Release files / persistent_bundles-0.4.1-py3-none-any.whl
| Download URL | persistent_bundles-0.4.1-py3-none-any.whl |
|---|---|
| Size | 5.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
751b4f3599960d12be7c2a65ee746253c492972d9529f034fefb0ba7f4186c89
|
|
BLAKE2b-256 checksum How to use checksums |
1b557ad1b7e077457bc41e8823b196acedc97b3da56638f15620ceecf29fa93c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.15
|