{"library":"py-serializable","title":"py-serializable","description":"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.","status":"active","version":"2.1.0","language":"en","source_language":"en","source_url":"https://github.com/madpah/serializable","tags":["serialization","deserialization","json","xml","python-objects","data-conversion"],"install":[{"cmd":"pip install py-serializable","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Requires Python 3.8 or higher, but less than 4.0.","package":"python","optional":false}],"imports":[{"note":"The top-level package was renamed from `serializable` to `py_serializable` in v2.0.0. All imports must reflect this change.","wrong":"from serializable.serializable import Serializable","symbol":"Serializable","correct":"from py_serializable.serializable import Serializable"},{"note":"The top-level package was renamed from `serializable` to `py_serializable` in v2.0.0.","wrong":"from serializable import ViewType","symbol":"ViewType","correct":"from py_serializable import ViewType"}],"quickstart":{"code":"from py_serializable.serializable import Serializable\nfrom py_serializable.enums import ViewType\n\nclass MyObject(Serializable):\n    def __init__(self, name: str, value: int):\n        self._name = name\n        self._value = value\n\n    @property\n    def name(self) -> str:\n        return self._name\n\n    @property\n    def value(self) -> int:\n        return self._value\n\n    # The library automatically generates to_json and from_json methods\n    # or similar serialization/deserialization functions based on @property.\n    # For demonstration, we'll assume direct methods exist or use library functions.\n\n# Create an instance\nmy_instance = MyObject(name=\"Test Item\", value=123)\n\n# Serialize to JSON\n# In typical usage, an object inheriting from Serializable will gain these methods.\n# Actual library usage might involve py_serializable.serialize.to_json(my_instance)\n# However, for simplicity and common pattern, we assume direct method if it's auto-added.\n# The documentation states the library handles serialization 'magically'.\njson_output = my_instance.to_json(indent=2)\nprint(\"Serialized JSON:\")\nprint(json_output)\n\n# Deserialize from JSON\ndeserialized_instance = MyObject.from_json(json_output)\nprint(\"\\nDeserialized Object Name:\", deserialized_instance.name)\nprint(\"Deserialized Object Value:\", deserialized_instance.value)\n\nassert deserialized_instance.name == my_instance.name\nassert deserialized_instance.value == my_instance.value\n\n# Example with a specific view (if defined in a real Serializable class)\nclass User(Serializable):\n    def __init__(self, user_id: str, email: str, password_hash: str):\n        self._user_id = user_id\n        self._email = email\n        self._password_hash = password_hash\n\n    @property\n    def user_id(self) -> str:\n        return self._user_id\n\n    @property(view=ViewType.PUBLIC)\n    def email(self) -> str:\n        return self._email\n\n    @property(view=ViewType.PRIVATE)\n    def password_hash(self) -> str:\n        return self._password_hash\n\nuser_instance = User(user_id=\"user123\", email=\"test@example.com\", password_hash=\"hashed_secret\")\n\n# Serialize only public view\npublic_json = user_instance.to_json(view=ViewType.PUBLIC, indent=2)\nprint(\"\\nPublic View JSON (email should be present, password_hash absent):\")\nprint(public_json)\n\n# Expected output for public_json should contain 'user_id' and 'email'\nassert 'user_id' in public_json and 'email' in public_json\nassert 'password_hash' not in public_json","lang":"python","description":"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."},"warnings":[{"fix":"Update your import statements to use `py_serializable` instead of `serializable`. For example, change `from serializable import SomeClass` to `from py_serializable import SomeClass`.","message":"The Python package name was renamed from `serializable` to `py_serializable` in v2.0.0. All import statements must be updated from `import serializable` to `from py_serializable import ...` to avoid `ModuleNotFoundError`.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"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.","message":"Support for Python versions older than 3.8 was dropped in v1.0.0. Projects using `py-serializable` v1.0.0 or later must run on Python 3.8 or newer.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"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.","message":"`py-serializable` primarily relies on Python's `@property` decorator for defining attributes that should be serialized or deserialized. If you define attributes directly without `@property`, they might not be automatically included in the serialization/deserialization process as expected.","severity":"gotcha","affected_versions":"All versions"},{"fix":"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.","message":"Prior to v2.1.0, deserialization would raise an error if the input JSON/XML contained properties/attributes/elements that were not defined in the Python class. This could lead to crashes when processing external data with unexpected fields.","severity":"gotcha","affected_versions":"<2.1.0"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}