{"id":4833,"library":"u-msgpack-python","title":"u-msgpack-python","description":"u-msgpack-python is a lightweight MessagePack serializer and deserializer module written entirely in pure Python. It is compatible with both Python 2 and 3, as well as CPython and PyPy implementations, and fully complies with the latest MessagePack specification, including support for binary, UTF-8 string, application-defined ext, and timestamp types. The current version is 2.8.0, with releases occurring a few times per year to maintain compliance and add features.","status":"active","version":"2.8.0","language":"en","source_language":"en","source_url":"https://github.com/vsergeev/u-msgpack-python","tags":["serialization","msgpack","binary","pure-python"],"install":[{"cmd":"pip install u-msgpack-python","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The package name on PyPI is `u-msgpack-python`, but the module to import is `umsgpack`.","wrong":"import u_msgpack_python","symbol":"umsgpack","correct":"import umsgpack"}],"quickstart":{"code":"import umsgpack\n\ndata = {\"name\": \"Alice\", \"age\": 30, \"is_student\": False}\n\n# Serialize a Python object to MessagePack bytes\npacked_data = umsgpack.packb(data)\nprint(f\"Packed data: {packed_data}\")\n\n# Deserialize MessagePack bytes back to a Python object\nunpacked_data = umsgpack.unpackb(packed_data)\nprint(f\"Unpacked data: {unpacked_data}\")\n\n# Example with streaming to/from a file-like object\nfrom io import BytesIO\n\nf = BytesIO()\numsgpack.pack({\"compact\": True, \"schema\": 0}, f)\numsgpack.pack([1, 2, 3], f)\nf.seek(0)\n\n# Unpack multiple objects from the stream\nobj1 = umsgpack.unpack(f)\nobj2 = umsgpack.unpack(f)\nprint(f\"Object 1 from stream: {obj1}\")\nprint(f\"Object 2 from stream: {obj2}\")","lang":"python","description":"This quickstart demonstrates how to pack Python objects into MessagePack bytes and unpack them. It also shows an example of streaming serialization and deserialization using file-like objects for multiple MessagePack objects."},"warnings":[{"fix":"Explicitly choose `u-msgpack-python` for a pure Python solution or `msgpack` for C extensions. Review the documentation for the chosen library to understand its specific behavior, especially concerning string/binary types and old MessagePack specification compatibility.","message":"Confusing `u-msgpack-python` with the `msgpack` library (the CPython binding with fallback). While both handle MessagePack, `u-msgpack-python` is a pure Python implementation and may have subtle behavioral or performance differences. The `msgpack` library (on PyPI as `msgpack`) had significant breaking changes in its 1.0 release regarding Python 2 support, default binary/string handling, and removed encoding options. Users should be aware of which library they are using.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Set `umsgpack.compatibility = True` before packing/unpacking if you need to serialize both unicode strings and bytes into the old 'raw' type, or deserialize 'raw' into bytes. Be aware this is a global module setting.","message":"Handling old MessagePack specification data. By default, `u-msgpack-python` is fully compliant with the latest MessagePack specification, which distinguishes between string and binary types. Older specifications used a single 'raw' type. If interacting with systems that generate old-spec MessagePack, you might need to enable `umsgpack.compatibility = True` or use specific packing/unpacking options.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Only use `force_float_precision='single'` when explicitly intending to reduce float precision for storage efficiency, and understand the implications. Otherwise, omit this option to retain default precision.","message":"Loss of float precision during serialization. The `packb` and `pack` functions offer a `force_float_precision` option ('single' or 'double'). Using 'single' will force floats to be packed as IEEE-754 single-precision, which may result in a loss of precision if the original float was double-precision.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}