{"id":1268,"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":"python","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":[{"wrong":"from py_serializable import Serializable","symbol":"Serializable","correct":"from py_serializable import Serializable"}],"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"},{"fix":"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`.","message":"The main `Serializable` class and other core components were moved directly under the `py_serializable` package namespace, removing the intermediate `py_serializable.serializable` submodule. Attempting to import from `py_serializable.serializable` will now result in a `ModuleNotFoundError`.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'2.1.0':53 'activ':47 'attribut':37 'cadenc':59 'class':36 'convers':76 'current':46 'data':75 'data-convers':74 'decor':32 'defin':34 'deseri':16,68 'design':11 'everi':64 'format':26 'handl':39 'json':23,69 'latest':50 'leverag':28 'librari':10,44 'maintain':55 'month':66 'object':19,73 'occur':63 'process':42 'properti':31 'py':2,5 'py-serializ':1,4 'python':9,18,29,72 'python-object':71 'regular':57 'releas':58 'serial':14,67 'serializ':3,6 'typic':62 'updat':61 'version':51 'xml':25,70","created_at":"2026-04-06T16:57:19.856313+00:00","updated_at":"2026-04-16T18:17:48.888500+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nImportError: cannot import name 'Serializable' from 'py_serializable' (/tmp/tmpm4ta2wm7/venv/lib/python3.12/site-packages/py_serializable/__init__.py). Did you mean: '_XmlSerializable'?"},"ecosystem":"pypi","meta_description":null,"install_score":0,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.1.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/madpah/serializable","docs":"https://py-serializable.readthedocs.io/","changelog":null,"pypi":"https://pypi.org/project/py-serializable/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-08-27","next_check":"2026-07-10","install_tag":"stale"}}