py-serializable is a Pythonic library designed for the serialization and deserialization of Python objects to and from JSON and XML formats. It leverages Python's `@property` decorator to define how class attributes are handled during these processes. The library is currently active, with its latest version being 2.1.0, and maintains a regular release cadence, with updates typically occurring every few months.
pip install py-serializableVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates the core functionality of `py-serializable` by defining a simple class `MyObject` that inherits from `Serializable`. The library automatically provides `to_json` and `from_json` methods (or equivalent functions) for classes using Python's `@property` decorator. It shows how to serialize an object to JSON and then deserialize it back into a Python object. A second example using `ViewType` illustrates how to control which properties are serialized based on a specified view, useful for public/private data separation.
Update your import statements to use `py_serializable` instead of `serializable`. For example, change `from serializable import SomeClass` to `from py_serializable import SomeClass`.
Upgrade your Python environment to version 3.8 or higher. If unable to upgrade Python, you must use a `py-serializable` version older than 1.0.0, which may lack newer features and bug fixes.
Ensure all class attributes intended for serialization/deserialization are defined using the `@property` decorator. Refer to the official documentation for advanced customization of serialization behavior.
Upgrade to `py-serializable` v2.1.0 or later, which adds support to ignore unknown properties during deserialization. Alternatively, ensure your input data strictly matches your class definitions, or preprocess input to remove unknown fields.
Update your import statements for the `Serializable` class (and potentially other core classes) from `from py_serializable.serializable import Serializable` to `from py_serializable import Serializable`.