chumicro-msgpack¶
Cross-runtime MessagePack serialization for CircuitPython, MicroPython, and CPython.
Encodes Python objects to compact binary bytes and decodes them back. On CircuitPython firmware that ships the native msgpack C module, every function delegates to that built-in and the pure-Python encoder never loads.
Quick example¶
from chumicro_msgpack import packb, unpackb
settings = {0: "MyNetwork", 1: "secret", 2: True}
data = packb(settings) # compact binary bytes
print(len(data)) # much smaller than JSON
restored = unpackb(data)
print(restored) # {0: 'MyNetwork', 1: 'secret', 2: True}
Documentation¶
- User Guide: the stream and bytes APIs, when to reach for msgpack instead of
struct, decoding corrupt or untrusted input, integer keys for compact storage, the supported types, and the size comparison against JSON - API Reference:
packbandunpackbfor bytes,packandunpackfor streams