A robust object serialization format with compression, encryption, checksum validation, and diagnostics metadata.
Project description
mtdump
Robust Python object serialization to a single .mtd file with optional compression, encryption, checksum validation, and rich environment diagnostics metadata for compatibility and debugging.
Intro
mtdump provides two simple functions — save_dump and load_dump — to persist arbitrary Python objects safely. Dumps can be compressed, encrypted with a key, validated with checksum, and include environment diagnostics metadata (Python, optionally specified packages, and versions of currently imported modules) to aid debugging and compatibility when loading across environments.
Key features:
- Compression via Zstandard
- Encryption via AES-256-CBC
- Integrity verification via SHA-256 checksum
- Environment diagnostics, versions of currently imported modules, and custom metadata embedded alongside the payload
Installation
- From PyPI (once published):
pip install mtdump - From source:
pip install -e . - Optional dill support:
pip install mtdump[dill](orpip install dill)
Examples
Basic use:
from mtdump import save_dump, load_dump
obj = {"a": 1, "b": [1, 2, 3]}
result = save_dump(obj, "data.mtd")
restored = load_dump("data.mtd")
assert restored == obj
Enable encryption with checksum validation (auto-generate a secure key):
result = save_dump(obj, "secret.mtd", passphrase="auto")
restored = load_dump("secret.mtd", passphrase=result["passphrase"], checksum=result["checksum"]) # base64 key; validates SHA-256
Use dill instead of pickle (for broader object support):
# pip install mtdump[dill] or pip install dill
save_dump(obj, "data.mtd", serializer="dill")
Attach custom metadata and read it back:
meta = {"experiment_id": "exp_123", "user": "alice"}
save_dump(obj, "meta.mtd", meta=meta)
restored, info = load_dump("meta.mtd", return_info=True)
assert info["meta"]["experiment_id"] == "exp_123"
Verify integrity with a known checksum:
result = save_dump(obj, "chk.mtd")
restored = load_dump("chk.mtd", checksum=result["checksum"]) # raises if mismatch
Load from URL with headers (e.g., auth):
obj = load_dump(
"https://example.com/path/to/file.mtd",
storage_options={"Authorization": "Bearer <token>"},
)
Record versions for specific packages in the environment diagnostics metadata:
save_dump(obj, "env.mtd", env_packages=["numpy"])
Documentation
API:
def save_dump(
obj,
path,
compression: "zstd | None" = "zstd",
protocol: int = 5,
serializer: "pickle | dill" = "pickle",
passphrase: None | bytes | str | "auto" = None,
meta: dict | None = None,
env_packages: list[str] | None = None,
) -> dict
def load_dump(
path: str | pathlib.Path,
passphrase: None | bytes | str = None,
checksum: str | None = None,
return_info: bool = False,
storage_options: dict[str, str] | None = None,
) -> object | tuple[object, dict]
Notes:
- Compression:
compression="zstd"(default) orNone. - Encryption: AES-256-CBC with random IV and PKCS#7. Provide a 32‑byte key (as bytes) or a base64 string;
passphrase="auto"generates a secure key and returns its base64 string in the result. - Integrity: SHA-256 checksum is computed pre-compression and verified on load. Supply
checksum=to enforce a specific expected digest. - Serializer:
pickle(default) ordill(optional dependency) for more complex objects. - Metadata: The
infoJSON includes the Python version and, if provided viaenv_packages, versions for those packages (e.g.,"numpy","scikit-learn"). It also includes a mapping of all currently loaded installed top-level modules with versions, dump settings, and yourmetadict — useful for diagnosing loading issues and confirming environment compatibility. - File format:
MTD1magic header; 8‑byte little-endian lengths for theinfoJSON and payload; payload is optionally encrypted and/or compressed bytes.
License: MIT
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 mtdump-0.2.0.tar.gz.
File metadata
- Download URL: mtdump-0.2.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
82b87771831b0aa9e5f376aa278c95422b080fdce652832dc04363f8af9d9473
|
|
| MD5 |
360e3c356e815615305293d67ddda5fd
|
|
| BLAKE2b-256 |
f4395a0f16c8a3d4890944c6432b82783b7cc9da0e870f2cac72e2f48addefc6
|
Provenance
The following attestation bundles were made for mtdump-0.2.0.tar.gz:
Publisher:
python-publish.yml on chentl/mtdump
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtdump-0.2.0.tar.gz -
Subject digest:
82b87771831b0aa9e5f376aa278c95422b080fdce652832dc04363f8af9d9473 - Sigstore transparency entry: 554279952
- Sigstore integration time:
-
Permalink:
chentl/mtdump@18f378154499ebc2594eb694dff6bd51452b3da0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chentl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@18f378154499ebc2594eb694dff6bd51452b3da0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mtdump-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mtdump-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5172653c3a8e8fe3444b9a410e01f17ef9c3c94eefd67d65bfd55f705131a49
|
|
| MD5 |
8eb7f88b5bcab1b982e37fd9093910f1
|
|
| BLAKE2b-256 |
5332bdf7d3d4cc9b96e42730d3c2c03875ff30cdf920ad3f6ee8958c69992557
|
Provenance
The following attestation bundles were made for mtdump-0.2.0-py3-none-any.whl:
Publisher:
python-publish.yml on chentl/mtdump
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mtdump-0.2.0-py3-none-any.whl -
Subject digest:
b5172653c3a8e8fe3444b9a410e01f17ef9c3c94eefd67d65bfd55f705131a49 - Sigstore transparency entry: 554279967
- Sigstore integration time:
-
Permalink:
chentl/mtdump@18f378154499ebc2594eb694dff6bd51452b3da0 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/chentl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@18f378154499ebc2594eb694dff6bd51452b3da0 -
Trigger Event:
push
-
Statement type: