Registry / serialization / oslo-serialization

oslo-serialization

JSON →
library5.11.0pypypi✓ verified 28d ago

The oslo.serialization library, part of the OpenStack Oslo project, provides robust utilities for representing Python objects in transmittable and storable formats like JSON and MessagePack. It aims to offer high-quality, stable, and consistent serialization functionalities for OpenStack and other projects. The library is actively maintained and currently at version 5.9.1.

pip install oslo-serialization
INSTALL
IMPORT
SIG · OSLO-SERIALIZATION
O
oslo-serialization
serializationpythonv5.11.0
Install
3.3s avg
Import
223ms
Disk
39MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v5.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.236s · 36.3MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 3.3s · import 0.210s · 38MB
39MB installed
● package 39MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

jsonutils
✓ from oslo_serialization import jsonutils
✗ import oslo_serialization.jsonutils
While 'import oslo_serialization.jsonutils' works, directly importing the module is the standard and cleaner approach for accessing its functions like dumps, loads, and to_primitive.

This quickstart demonstrates how to use `oslo_serialization.jsonutils.dumps` and `loads` to serialize and deserialize a custom Python object. It highlights the automatic handling of types like `datetime` and `UUID` by `jsonutils.to_primitive`, which `dumps` utilizes by default.

from oslo_serialization import jsonutils import datetime import uuid class CustomObject: def __init__(self, name, value, created_at=None): self.name = name self.value = value self.id = str(uuid.uuid4()) self.created_at = created_at or datetime.datetime.now(datetime.timezone.utc) # oslo_serialization.jsonutils.to_primitive will handle this automatically # but for custom types, you might explicitly define how to convert them. # For datetime and UUID, jsonutils has built-in support. def to_dict(self): return { 'name': self.name, 'value': self.value, 'id': self.id, 'created_at': self.created_at.isoformat() } # Example usage obj = CustomObject('test_item', 123.45) # Serialize to JSON string json_string = jsonutils.dumps(obj, indent=2) print(f"Serialized JSON:\n{json_string}") # Deserialize from JSON string data_dict = jsonutils.loads(json_string) print(f"Deserialized dictionary: {data_dict}") # Demonstrate to_primitive (used internally by dumps by default) primitive_data = jsonutils.to_primitive(obj) print(f"Primitive representation: {primitive_data}")
Debug
Known issues
breakingSupport for Python 2.7 has been dropped since version 3.0.0. The minimum supported Python version is now 3.10 (as of oslo.serialization 5.9.1). Older Python versions will not work.
fix
Ensure your project runs on Python 3.10 or newer. Upgrade your Python environment if necessary.
affects: >=3.0.0
deprecatedThe `oslo_serialization.yamlutils` module is deprecated since the Ussuri series (version 3.1.1) and its support will be removed in a future release. PyYAML is now considered safe by default.
fix
Migrate any usage of `oslo_serialization.yamlutils` to direct usage of the PyYAML library. Review OpenStack documentation for recommended patterns if specific OpenStack-isms were relied upon.
affects: >=3.1.1
gotchaThe `oslo_serialization.jsonutils.to_primitive` function (used internally by `dumps`) now explicitly raises a `ValueError` when the input value cannot be converted to a primitive type. Previously, it might have silently skipped or handled it differently.
fix
Review code that serializes complex or potentially unhandled types. Implement a `to_dict` method on custom objects or provide a `default` function to `jsonutils.dumps` to handle non-primitive types gracefully, catching `ValueError` if specific error handling is needed.
affects: >=5.3.0
gotchaSerialization of Python traceback objects (e.g., as part of remote exceptions) is inherently lossy. The reconstructed traceback on the receiving end may not be as rich or complete as the original due to missing local stack frame information.
fix
Be aware of this limitation when designing systems that rely on remote exception handling. Consider capturing additional context or logging details at the source if a full traceback is critical for remote debugging.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'oslo_serialization'
The 'oslo-serialization' library is not installed in the current Python environment, or there's a typo in the import statement.
fix
Ensure the library is installed using pip: `pip install oslo-serialization`
ValueError: Cannot convert <value> to primitive
The `oslo_serialization.jsonutils.dumps` function, which relies on `to_primitive` by default, encountered an object type (e.g., a custom class instance without a `to_dict` method) that it cannot automatically serialize into a basic JSON-compatible type. This behavior became an explicit `ValueError` in newer versions of the library.
fix
Define a `to_dict` method on your custom object that returns a dictionary representation, or provide a custom `default` callable function to `jsonutils.dumps` to handle the non-primitive type.
Could not deserialize msgpack message: unpack(b) received extra data
This error, originating from the underlying `msgpack` library, indicates that the MessagePack data being unpacked is either corrupted, incomplete, or contains unexpected trailing bytes after a valid MessagePack object.
fix
Verify that the source of the MessagePack data is sending complete and correctly formatted messages. Ensure no extra data is appended to the MessagePack payload before deserialization.
unpackb() got an unexpected keyword argument 'max_buffer_size'
This issue occurs when attempting to pass the `max_buffer_size` argument to `msgpack.unpackb()` (or a similar one-shot unpacking function in `oslo_serialization.msgpackutils`) which does not support this argument directly. This argument is typically for the `msgpack.Unpacker` object for stream-based unpacking.
fix
Remove the `max_buffer_size` argument when using `unpackb()`. If handling large data and needing buffer control, use `msgpack.Unpacker` directly with its `max_buffer_size` parameter, feeding data in chunks.
Upgrade
Version history
5.11.0latest on PyPI · released Jul 10, 2026
Audit
Dependencies
oslo.utilsrequiredProvides core utility functions used by oslo.serialization.
msgpack-pythonoptionalRequired for MessagePack serialization support (imported as `msgpack`).
PyYAMLoptionalRequired for YAML serialization, though the `yamlutils` module is deprecated.
Agent activity
14 hits · last 30 days
node
12
Resources
oslo-serialization — pip install oslo-serialization · libregistry