Skip to content

API Reference

chumicro_msgpack

packb and unpackb work on bytes in memory; pack and unpack read and write a stream, which keeps a large value off the heap on a small board.

chumicro_msgpack

MessagePack serialization for CircuitPython, MicroPython, and CPython.

packb(obj)

Pack obj to msgpack bytes.

Parameters:

Name Type Description Default
obj object

Python object to serialize.

required

Returns:

Type Description
bytes

Msgpack-encoded data.

Raises:

Type Description
ValueError

Nesting deeper than the depth cap.

OverflowError

An int, string, bytes, array, or map outside the supported subset's ranges.

TypeError

An unsupported type.

unpackb(data)

Unpack msgpack data to a Python object.

Parameters:

Name Type Description Default
data bytes | bytearray | memoryview

Msgpack-encoded data.

required

Returns:

Type Description
object

Deserialized Python object.

Raises:

Type Description
ValueError

On truncated or over-length framing, nesting beyond the decoder's depth bound, or bytes left over after one complete object.

pack(obj, stream)

Pack obj to stream in msgpack format.

Parameters:

Name Type Description Default
obj object

Python object to serialize.

required
stream object

Writable stream with a write() method.

required

unpack(stream)

Unpack a single object from stream.

Parameters:

Name Type Description Default
stream object

Readable stream with a read() method.

required

Returns:

Type Description
object

Deserialized Python object.

Raises:

Type Description
ValueError

Truncated framing, or bytes past the first object.