Skip to main content

chumicro-msgpack

Compact binary serialization for settings and config, smaller than JSON.

The subset of MessagePack that fits on a 256 KB board: 32-bit ints, single-precision floats, 16-bit lengths. Wire-compatible with the PyPI msgpack library when it's configured for the same subset (use_single_float=True); on CircuitPython firmware that ships the native msgpack C module, encoding and decoding delegate to the C path automatically.


Part of the ChuMicro family: small, focused Python libraries for microcontrollers and laptops. Browse all libraries.

Install

# CircuitPython (after `circup bundle-add ChuMicro/ChuMicro-Bundle-Experimental`)
circup install chumicro_msgpack

# MicroPython
mpremote mip install github:ChuMicro/ChuMicro-Bundle-Experimental/chumicro_msgpack

# CPython
pip install chumicro-msgpack-experimental

For bundle setup, pre-compiled .mpy bundles, the experimental channel, and details on PyPI naming, see the chumicro INSTALL guide.

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}

What's included

Stream-based API (preferred on microcontrollers)

Symbol Description
pack(obj, stream) Pack an object to a writable stream (streams without an intermediate buffer on the native CircuitPython encoder; on the pure path it encodes to bytes first)
unpack(stream) Unpack one object from a readable stream

Bytes-based API

Symbol Description
packb(obj) Pack a Python object to msgpack bytes (allocates a temporary buffer)
unpackb(data) Unpack msgpack bytes (bytes, bytearray, or memoryview) to a Python object

Use pack/unpack when writing to files, sockets, or NVM. Use packb/unpackb when you need the encoded bytes in memory (e.g., to measure length before framing).

Supported types

Python type msgpack format Limit
None nil none
True / False bool none
int fixint, int8/16/32, uint8/16/32 -2^31 ≤ value ≤ 2^32 − 1
float float32 single precision (~7 decimal digits)
str fixstr, str8, str16 up to 65 535 bytes UTF-8
bytes / bytearray bin8, bin16 up to 65 535 bytes
list / tuple fixarray, array16 up to 65 535 elements
dict fixmap, map16 up to 65 535 entries

Values outside these limits raise OverflowError on encode. Tags outside the subset (float64 0xcb, int64 0xd3, uint64 0xcf, the *32-length variants) raise a descriptive ValueError on decode that names the offending tag.

tuple decodes back as list, since msgpack has no tuple type. dict keys may be any supported type, including int (no strict_map_key enforcement). Ext types (timestamps, custom classes) are not supported in either direction.

Cross-runtime compatibility

Direction Works? Notes
chumicro device writes → host reads ✓ always Bytes are spec-compliant; any standard reader decodes them
chumicro device writes → chumicro device reads ✓ always The common case; full round-trip
Host writes with PyPI msgpack → chumicro device reads ✓ if host stays in subset See recipe below
Host writes default PyPI msgpack → chumicro device reads ✗ PyPI defaults to float64, decodes raise on device

Host-side recipe, when a host script needs to produce bytes a chumicro device will read:

import msgpack  # standard PyPI library
data = msgpack.packb(obj, use_single_float=True)
# Caller's job: keep ints in [-2**31, 2**32-1] and lengths under 65 536.

use_single_float=True switches PyPI msgpack from float64 to float32, matching what chumicro reads. This is what chumicro-workspace does when it writes runtime_config.msgpack for the device.

Where this fits

Leaf, no upstream ChuMicro deps. Used directly by chumicro-config to decode /runtime_config.msgpack on the device, and by host-side workspace tooling to write it.

Platform support

Runtime Implementation
CircuitPython (hardware) Delegates to the native C msgpack module; pure-Python code is never loaded
CircuitPython (unix port) Pure-Python encoder/decoder (native module not compiled in)
MicroPython Pure-Python encoder/decoder
CPython Pure-Python encoder/decoder

Examples

Example What it shows
packb_basic.py Pack and unpack a settings dict
packb_size_comparison.py Compare msgpack vs JSON size for the same dict (packs a five-field settings dict to 78 bytes where JSON needs 109, about 28 % smaller; integer keys instead of strings widen the gap further)
stream_roundtrip.py Use the stream-based pack / unpack API with BytesIO
circuitpython_nvm_settings.py Store and load settings in non-volatile memory (hardware)

Contributing

Issues, bug reports, and pull requests are welcome, and so is "I ran it on this board and here's what happened", some of the most useful feedback a hardware project can get. Development happens in the ChuMicro repository, whose contributing guide covers setup and the test workflow.

Docs

📖 Stable docs · Experimental docs

Find this library

License

MIT

Metadata

Release files for chumicro-msgpack-experimental 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chumicro-msgpack-experimental 0.2.4
File Size Uploaded
chumicro_msgpack_experimental-0.2.4.tar.gz 21.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chumicro-msgpack-experimental 0.2.4
File Interpreter ABI Platform
chumicro_msgpack_experimental-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 30.7 kB

Release files / chumicro_msgpack_experimental-0.2.4.tar.gz

Download URL chumicro_msgpack_experimental-0.2.4.tar.gz
Size 21.9 kB
Tags Source
SHA-256 checksum
How to use checksums
70f7cd793045dbbfd41e617022bb2f64ee1117f955f8c2b6f1f227b776e46508
BLAKE2b-256 checksum
How to use checksums
22c2a7e1ffe6a92145e112a5120b62764137af811ce24a85f681b325de963532
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2026.

Transparency log

Release files / chumicro_msgpack_experimental-0.2.4-py3-none-any.whl

Download URL chumicro_msgpack_experimental-0.2.4-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae67a018b35d6e0e804dce8bb7086e1ce1d1b7de2472c2620b8ac2f3def5341f
BLAKE2b-256 checksum
How to use checksums
5ee19ebab3dfce376c77ff86051eb9946759c81335a9acf7c0ecef75d5d4068c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 9, 2026.

Transparency log

Release history Release notifications | RSS feed

0.2.7

2 release files

0.2.6

2 release files

0.2.5

2 release files

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.1.23

2 release files

0.1.22

2 release files

0.1.21

2 release files

0.1.20

2 release files

0.1.19

2 release files

0.1.18

2 release files

0.1.16

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.0

2 release files

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