{"id":4181,"library":"py-ubjson","title":"Universal Binary JSON","description":"py-ubjson is a Python library providing a Universal Binary JSON (UBJSON) encoder and decoder, adhering to the draft-12 specification. It aims to offer an API similar to Python's built-in `json` module for seamless serialization and deserialization of UBJSON data. The library includes an optional C extension for significant performance improvements. The current version is 0.16.1.","status":"active","version":"0.16.1","language":"en","source_language":"en","source_url":"https://github.com/Iotic-Labs/py-ubjson","tags":["json","serialization","ubjson","binary","data-interchange","high-performance"],"install":[{"cmd":"pip install py-ubjson","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Runtime dependency for the library.","package":"python","optional":false},{"reason":"Optional build dependency for the C extension, which provides a significant speed boost.","package":"cython","optional":true}],"imports":[{"symbol":"ubjson","correct":"import ubjson"},{"note":"Used to encode Python objects to a UBJSON `bytes` object.","symbol":"dumpb","correct":"from ubjson import dumpb"},{"note":"Used to decode a UBJSON `bytes` object to a Python object.","symbol":"loadb","correct":"from ubjson import loadb"},{"note":"Used to encode Python objects to a file-like object.","symbol":"dump","correct":"from ubjson import dump"},{"note":"Used to decode a file-like object containing UBJSON data.","symbol":"load","correct":"from ubjson import load"}],"quickstart":{"code":"import ubjson\n\ndata = {\n    'name': 'Alice',\n    'age': 30,\n    'isStudent': False,\n    'courses': ['Math', 'Science'],\n    'grades': {'Math': 95, 'Science': 88}\n}\n\n# Encode to UBJSON bytes\nencoded_data = ubjson.dumpb(data)\nprint(f\"Encoded (bytes): {encoded_data!r}\")\n\n# Decode from UBJSON bytes\ndecoded_data = ubjson.loadb(encoded_data)\nprint(f\"Decoded: {decoded_data}\")\n\nassert data == decoded_data","lang":"python","description":"This example demonstrates how to encode a Python dictionary into UBJSON bytes and then decode it back using `ubjson.dumpb` and `ubjson.loadb`."},"warnings":[{"fix":"To explicitly skip the extension build (e.g., for troubleshooting), set the environment variable `PYUBJSON_NO_EXTENSION=1` before installation: `PYUBJSON_NO_EXTENSION=1 pip install py-ubjson`. To verify if the extension is enabled at runtime, check `ubjson.EXTENSION_ENABLED`.","message":"The C extension is not strictly required but offers a significant speed boost. If performance is critical, ensure Cython is available during installation to build the extension. Installations via `pip install py-ubjson` typically attempt to build the extension by default.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Avoid generating No-Op types in your data when encoding. When decoding, be aware of its specific limitations if encountering No-Op types in incoming UBJSON streams.","message":"The UBJSON 'No-Op' type is only supported by the decoder, not the encoder. Additionally, its usage is restricted to the start or between elements of a container and only within un-typed containers, as its presence in typed containers can lead to ambiguity.","severity":"gotcha","affected_versions":"All versions"},{"fix":"When encoding, `py-ubjson` will produce dynamically-typed containers. When decoding, understand that while strongly-typed containers can be consumed, you cannot explicitly create them using the `py-ubjson` encoder at this time.","message":"Strongly-typed containers (e.g., for arrays or objects) are primarily supported by the decoder (with the exception of bytes/bytearray). The encoder does not currently support generating strongly-typed containers, and they do not support the No-Op type.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}