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
Metadata
Release files for larzpack 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| larzpack-0.1.0.tar.gz | 6.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| larzpack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / larzpack-0.1.0.tar.gz
| Download URL | larzpack-0.1.0.tar.gz |
|---|---|
| Size | 6.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b9bc6cd033593c7b951075e023e5b1f400803c728a0e97600e07d5837542d0b
|
|
BLAKE2b-256 checksum How to use checksums |
41d3cc122b8429cdd7d87b27e48748c92e3b61d2e9a7c77cf936e2dc0550bb15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / larzpack-0.1.0-py3-none-any.whl
| Download URL | larzpack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 6.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
978f6da4d9e27e54fc25b1e7a2251a9dc3845c387a80910c166f187b04330d95
|
|
BLAKE2b-256 checksum How to use checksums |
143674dfa585f82de06635b2a7e1c4f873bbfda22e6c034759f607f1566483da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|