Yet another serialization library on top of dataclasses, inspired by serde-rs.
pyserde
Yet another serialization library on top of dataclasses, inspired by serde-rs.
Declare a class with pyserde's @serde
decorator.
@serde
class Foo:
i: int
s: str
f: float
b: bool
You can serialize Foo
object into JSON.
>>> to_json(Foo(i=10, s='foo', f=100.0, b=True))
'{"i":10,"s":"foo","f":100.0,"b":true}'
You can deserialize JSON into Foo
object.
>>> from_json(Foo, '{"i": 10, "s": "foo", "f": 100.0, "b": true}')
Foo(i=10, s='foo', f=100.0, b=True)
int
, float
, str
, bool
)list
, set
, tuple
, dict
frozenset
, defaultdict
typing.Optional
typing.Union
@dataclass
typing.NewType
for primitive typestyping.Any
typing.Literal
typing.Generic
typing.ClassVar
dataclasses.InitVar
Enum
and IntEnum
numpy
typesThanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
This project is licensed under the MIT license.