{"library":"py-serializable","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.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}