papyri 0.0.8 Pypi GitHub

Example:

In [14]: from dataclasses import dataclass
    ...: from typing import Optional, Union, List
    ...:

Note that Author and Reviewer are isomorphic even if totally unrelated.

In [15]: @dataclass
    ...: class Author:
    ...:     first: Optional[str]
    ...:     last: str
    ...:
    ...: @dataclass
    ...: class Reviewer:
    ...:     first: Optional[str]
    ...:     last: str
    ...:

Here, items can be heterogenous, or of ambiguous type based only on its fields values.

In [16]: @dataclass
    ...: class Book:
    ...:     author: List[Union[Author, Reviewer]]
    ...:     title: str
    ...:

In [17]: obj = Book([Author("Matthias", "B"), Reviewer("Tony", "Fast")], "pyshs")
    ...:
    ...: data = serialize(obj , Book)
    ...:
    ...: deserialize(Book, Book, data)

Out[17]: Book(author=[Author(first='Matthias', last='B'), Reviewer(first='Tony', last='Fast')], title='pyshs')

                      ^...................................^
                                        .
                                        .Note the conserved types.

Unlike other similar libraries that automatically serialise/deserialise it has the following properties:

Both Pydantic and Jetblack-serialize would have erased the types and returned either 2 Authors or 2 Reviewers.

A mini-implementation of an automatic serialiser-deserialiser for nested dataclass like class based on type annotations.

A mini-implementation of an automatic serialiser-deserialiser for nested dataclass like class based on type annotations.

Example:

In [14]: from dataclasses import dataclass
    ...: from typing import Optional, Union, List
    ...:

Note that Author and Reviewer are isomorphic even if totally unrelated.

In [15]: @dataclass
    ...: class Author:
    ...:     first: Optional[str]
    ...:     last: str
    ...:
    ...: @dataclass
    ...: class Reviewer:
    ...:     first: Optional[str]
    ...:     last: str
    ...:

Here, items can be heterogenous, or of ambiguous type based only on its fields values.

In [16]: @dataclass
    ...: class Book:
    ...:     author: List[Union[Author, Reviewer]]
    ...:     title: str
    ...:


In [17]: obj = Book([Author("Matthias", "B"), Reviewer("Tony", "Fast")], "pyshs")
    ...:
    ...: data = serialize(obj , Book)
    ...:
    ...: deserialize(Book, Book, data)

Out[17]: Book(author=[Author(first='Matthias', last='B'), Reviewer(first='Tony', last='Fast')], title='pyshs')

                      ^...................................^
                                        .
                                        .Note the conserved types.

Unlike other similar libraries that automatically serialise/deserialise it has the following properties:

Both Pydantic and Jetblack-serialize would have erased the types and returned either 2 Authors or 2 Reviewers.

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /papyri/miniserde.py#0
type: <class 'module'>
Commit: