Serialization library on top of dataclasses.
Project description
pyserde
Serialization library on top of dataclasses.
Installation
$ pip install pyserde
QuickStart
You can serialize/deserialize your class to/from various message formant (e.g. Json, MsgPack) quite easily!
# main.py
# /usr/bin/env python
from dataclasses import dataclass
from serde import deserialize, serialize
from serde.json import from_json, to_json
# Mark the class serializable/deserializable.
@deserialize
@serialize
@dataclass
class Hoge:
i: int
s: str
f: float
b: bool
h = Hoge(i=10, s='hoge', f=100.0, b=True)
print(f"Into Json: {to_json(h)}")
s = '{"i": 10, "s": "hoge", "f": 100.0, "b": true}'
print(f"From Json: {from_json(Hoge, s)}")
$ python main.py
Into Json: {"i": 10, "s": "hoge", "f": 100.0, "b": true}
From Json: Hoge(i=10, s='hoge', f=100.0, b=True)
Features
Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyserde-0.0.7.tar.gz
(12.8 kB
view hashes)
Built Distribution
pyserde-0.0.7-py3-none-any.whl
(16.9 kB
view hashes)