Skip to main content

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)

Source distribution for persistent-bundles 0.4.1
File Size Uploaded Provenance Actions
persistent_bundles-0.4.1.tar.gz 2.9 kB Without provenance Details for persistent_bundles-0.4.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for persistent-bundles 0.4.1
File Interpreter ABI Platform Actions
persistent_bundles-0.4.1-py3-none-any.whl Python 3 none any Details for persistent_bundles-0.4.1-py3-none-any.whl

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

Security for persistent-bundles 0.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page