Skip to main content

No project description provided

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

# CPython (pip)
pip install chumicro-msgpack

# CircuitPython (circup)
circup bundle-add ChuMicro/ChuMicro-Bundle
circup install chumicro-msgpack

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

For experimental (pre-release) versions from the develop branch:

pip install chumicro-msgpack-experimental
circup bundle-add ChuMicro/ChuMicro-Bundle-Experimental
circup install chumicro-msgpack
mpremote mip install github:ChuMicro/ChuMicro-Bundle-Experimental/chumicro_msgpack

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

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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chumicro_msgpack_experimental-0.1.8.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file chumicro_msgpack_experimental-0.1.8.tar.gz.

File metadata

File hashes

Hashes for chumicro_msgpack_experimental-0.1.8.tar.gz
Algorithm Hash digest
SHA256 891daa4c79a57e997c70e94b89afea58cf3b79c424e0a90f9ba8924ba96c3ef2
MD5 68cdb037aa98e697d97663c4fc491e28
BLAKE2b-256 adc62a035758cdff9ea2b4d9da65bd6f863569f758ac5723bb09f931c80b9167

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_msgpack_experimental-0.1.8.tar.gz:

Publisher: release.yml on ChuMicro/ChuMicro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file chumicro_msgpack_experimental-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for chumicro_msgpack_experimental-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dfedcd4c358dcc71329c1ba7c0bfb3f283698f973492e4106acb8e4f415853c6
MD5 a6c613191f4c97d4c23ed570542399ca
BLAKE2b-256 3ec3c7ba0995dc089856f67c6e8f5d301a81b89c2dbd2f0bcae8271fa01a2c6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for chumicro_msgpack_experimental-0.1.8-py3-none-any.whl:

Publisher: release.yml on ChuMicro/ChuMicro

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page