larzpack
Compact, MessagePack-compatible, deterministic serialization. Zero dependencies.
Encode Python data to compact binary — smaller than JSON, readable by any MessagePack tool — with one property plain MessagePack doesn't guarantee: the output is canonical. The same value always packs to the same bytes.
from larzpack import packb, unpackb
packb({"b": 2, "a": 1}) == packb({"a": 1, "b": 2}) # True — key order irrelevant
unpackb(packb([1, "two", 3.0, {"x": True}])) # round-trips
Why the determinism matters
Integers use their smallest representation and map keys are emitted in sorted byte order, so identical logical values produce identical bytes. That makes the output safe to:
- hash / sign — a stable digest of a structure (pair with larzcrypt);
- content-address — use the bytes (or their hash) as a key;
- compare — two structures are equal iff their packed bytes are equal.
Plain json.dumps and most MessagePack encoders don't promise this — key order
and integer widths can vary.
Why else
- Interoperable. It's the real MessagePack wire format for the core types, so other languages and tools can read it.
- Compact. Binary, with fix-forms for small ints/strings/arrays/maps.
- Zero dependencies. Pure standard library.
Install
pip install larzpack
Usage
from larzpack import packb, unpackb
blob = packb({"user": 42, "tags": ["a", "b"], "active": True, "score": 3.5})
unpackb(blob) # {'user': 42, 'tags': ['a', 'b'], 'active': True, 'score': 3.5}
Supports None, bool, int, float, str, bytes, list, and dict.
Tests
python -m unittest discover -s tests -v # 22 tests incl. spec bytes + determinism
The Larz stack
Pure-Python, zero-dependency building blocks: larz · larzchain · larzmoney · larzcrypt · larzdb · larzagent · larzchart · larzmark · larztask · larzvault · larzvm · larzcache · larzvalidate · larzid · larzrpc · larzstate · larzhttp · larzconf · larzcron · larzlimit · larzlog · larzcli · larzretry · larztime · larzpdf · larzpack
License
MIT © larz-scripter
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 larzpack-0.1.0.tar.gz.
File metadata
- Download URL: larzpack-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b9bc6cd033593c7b951075e023e5b1f400803c728a0e97600e07d5837542d0b
|
|
| MD5 |
e664cd2eea546e45d754452b84a62a90
|
|
| BLAKE2b-256 |
41d3cc122b8429cdd7d87b27e48748c92e3b61d2e9a7c77cf936e2dc0550bb15
|
File details
Details for the file larzpack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: larzpack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
978f6da4d9e27e54fc25b1e7a2251a9dc3845c387a80910c166f187b04330d95
|
|
| MD5 |
ad13807e781b93b3a27ccb5564e04850
|
|
| BLAKE2b-256 |
143674dfa585f82de06635b2a7e1c4f873bbfda22e6c034759f607f1566483da
|