Metadata-Version: 2.4
Name: runtime-serialization
Version: 0.0.0a1
Summary: Provides serialization to and from json, hjson, yaml and toml files.
Author-email: Anders Madsen <anders.madsen@alphavue.com>
License-Expression: MIT
Project-URL: repository, https://github.com/apmadsen/runtime-serialization
Keywords: windows,linux,serialization
Classifier: Development Status :: 5 - Production/Stable
Classifier: Development Status :: 6 - Mature
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Software Development :: Libraries
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: typing-utilities<0.1,>=0.0.6
Requires-Dist: runtime-reflection-lite<0.2,>=0.1.1
Requires-Dist: python-dateutil<2.10,>=2.9.0
Provides-Extra: test
Requires-Dist: pytest>=8.3; extra == "test"
Requires-Dist: pytest-cov>=6.1; extra == "test"
Requires-Dist: numpy<2.2,>=2.1.3; extra == "test"
Requires-Dist: PyYAML<6.1,>=6.0.2; extra == "test"
Requires-Dist: toml<0.11,>=0.10.2; extra == "test"
Requires-Dist: hjson<3.2,>=3.1.0; extra == "test"
Requires-Dist: delegate-events>=0.0.1; extra == "test"
Dynamic: license-file

[![Test](https://github.com/apmadsen/runtime-serialization/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/runtime-serialization/actions/workflows/python-test.yml)
[![Coverage](https://github.com/apmadsen/runtime-serialization/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/runtime-serialization/actions/workflows/python-test-coverage.yml)
[![Stable Version](https://img.shields.io/pypi/v/runtime-serialization?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/runtime-serialization/releases)
![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/runtime-serialization?label=pre-release&include_prereleases&sort=semver&color=blue)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/runtime-serialization)
[![PyPI Downloads](https://static.pepy.tech/badge/runtime-serialization/week)](https://pepy.tech/projects/runtime-serialization)

# runtime-serialization

Provides serialization to and from json, hjson, yaml and toml files.

## Example

```python
from runtime.serialization.json import Serializer, serialize, deserialize
from runtime.serialization import serializable
from datetime import date

@serializable(namespace="tests.examples")
class Author:
    def __init__(self, name: str, birthday: date):
        self.__name = name
        self.__birthday = birthday

    @property
    def name(self) -> str:
        return self.__name

    @property
    def birthday(self) -> date:
        return self.__birthday

@serializable(namespace="tests.examples")
class Book:
    def __init__(self, title: str, author: Author):
        self.__title = title
        self.__author = author

    @property
    def title(self) -> str:
        return self.__title

    @property
    def author(self) -> Author:
        return self.__author

author = Author("Stephen King", date(1947, 9, 21))
book = Book("The Shining", author)
serializer = Serializer[Book]()
serialized = serializer.serialize(book) # -> {"author": {"birthday": "1947-09-21", "name": "Stephen King"}, "title": "The Shining"}
deserialized = serializer.deserialize(serialized)
assert deserialized.author.name == author.name
assert deserialized.title == book.title

# same result, different approach without the need for instantiating Serializer manually
serialized = serialize(book, Book)

# and without a base type, the type info is embedded
serialized_untyped = serialize(book) # -> {"author": {"birthday": "1947-09-21", "name": "Stephen King"}, "title": "The Shining", "~type": "tests.examples.Book"}
deserialized_untyped = deserialize(serialized_untyped)
assert deserialized_untyped.author.name == deserialized.author.name
assert deserialized_untyped.title == deserialized.title
```
## Full documentation

[Go to documentation](https://github.com/apmadsen/runtime-serialization/blob/main/docs/documentation.md)
