Compact MessagePack serialization for CircuitPython, MicroPython, and CPython — delegates to the native C module when available.
Project description
chumicro-msgpack
Cross-runtime MessagePack serialization for CircuitPython, MicroPython, and CPython.
Encodes Python objects to compact binary bytes and decodes them back. Supports the subset of msgpack needed for embedded use: integers (up to 32-bit), floats (32-bit), strings, bytes, booleans, None, lists, tuples, and dicts.
On CircuitPython boards with the native msgpack C module, all functions delegate to the built-in — the pure-Python encoder is never loaded, saving ~700 bytes of heap RAM.
Installation
CircuitPython (circup)
Register the ChuMicro bundle (remove the other channel first if switching):
circup bundle-remove ChuMicro/ChuMicro-Bundle-Experimental # skip if never added
circup bundle-add ChuMicro/ChuMicro-Bundle
circup install chumicro-msgpack
MicroPython (mip)
mpremote mip install github:ChuMicro/ChuMicro-Bundle/chumicro_msgpack
CPython (pip)
pip install chumicro-msgpack
Experimental (pre-release) versions
Pre-release builds are published automatically when a library version is bumped. Do not register both bundles simultaneously — circup may pick either version for a given package.
# CircuitPython
circup bundle-remove ChuMicro/ChuMicro-Bundle # skip if never added
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
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 directly to a writable stream — no intermediate buffer |
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 |
|---|---|
None |
nil |
True / False |
bool |
int (−2³¹ to 2³²−1) |
fixint, int8/16/32, uint8/16/32 |
float |
float32 |
str |
fixstr, str8, str16 |
bytes / bytearray |
bin8, bin16 |
list / tuple |
fixarray, array16 |
dict |
fixmap, map16 |
64-bit integers and floats are not supported, matching CircuitPython's built-in limitation.
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 |
Docs
📖 Stable docs · Experimental docs
Browse on GitHub:
- User guide — getting started, usage patterns, size comparison
- API reference — full API documentation
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 |
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) |
Find this library
PyPI: chumicro-msgpack Bundle: ChuMicro-Bundle (CircuitPython & MicroPython) Source: ChuMicro/ChuMicro — cross-runtime Python libraries for ESP32, RP2040, and other microcontrollers.
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 chumicro_msgpack_experimental-0.1.13.tar.gz.
File metadata
- Download URL: chumicro_msgpack_experimental-0.1.13.tar.gz
- Upload date:
- Size: 5.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 |
22fad0506f8204b66fe787466bddd905400bdc62867e5f3b86df2d6affd0921e
|
|
| MD5 |
14f87fa5f54715860e60d391ccb417c3
|
|
| BLAKE2b-256 |
f86fe0d1d6a3c3b8e9e9f24d62f4051a0edb48f04b616d3432c2dc26a5d58d08
|
Provenance
The following attestation bundles were made for chumicro_msgpack_experimental-0.1.13.tar.gz:
Publisher:
release.yml on ChuMicro/ChuMicro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chumicro_msgpack_experimental-0.1.13.tar.gz -
Subject digest:
22fad0506f8204b66fe787466bddd905400bdc62867e5f3b86df2d6affd0921e - Sigstore transparency entry: 1245219216
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@a14d86481238a6568263da66916e86ed0f0907c6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a14d86481238a6568263da66916e86ed0f0907c6 -
Trigger Event:
push
-
Statement type:
File details
Details for the file chumicro_msgpack_experimental-0.1.13-py3-none-any.whl.
File metadata
- Download URL: chumicro_msgpack_experimental-0.1.13-py3-none-any.whl
- Upload date:
- Size: 6.1 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 |
98acc328d28a72f9f93ea940f8a22ba29269dd2394c63e4d94abd4089907d032
|
|
| MD5 |
9ac4fcd87720eb07ed5b2cb0f1ccac6b
|
|
| BLAKE2b-256 |
3ae60ed2f1110e6e3b9b9094f1b1120f3651189f0be16e31151b880e4c1ec054
|
Provenance
The following attestation bundles were made for chumicro_msgpack_experimental-0.1.13-py3-none-any.whl:
Publisher:
release.yml on ChuMicro/ChuMicro
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
chumicro_msgpack_experimental-0.1.13-py3-none-any.whl -
Subject digest:
98acc328d28a72f9f93ea940f8a22ba29269dd2394c63e4d94abd4089907d032 - Sigstore transparency entry: 1245219221
- Sigstore integration time:
-
Permalink:
ChuMicro/ChuMicro@a14d86481238a6568263da66916e86ed0f0907c6 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ChuMicro
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a14d86481238a6568263da66916e86ed0f0907c6 -
Trigger Event:
push
-
Statement type: