Yet another serialization library on top of dataclasses, inspired by serde-rs.
Declare a class with pyserde's @serde
decorator.
@serde
@dataclass
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)
- Supported data formats
- dict
- tuple
- JSON
- Yaml
- Toml
- MsgPack
- Supported types
- Primitives (
int
,float
,str
,bool
) - Containers (
List
,Set
,Tuple
,Dict
) typing.Optional
typing.Union
- User defined class with
@dataclass
typing.NewType
for primitive typestyping.Any
typing.Generic
Enum
andIntEnum
- Standard library
- PyPI library
numpy
types
- Primitives (
- Attributes
- Decorators
- Union Representation
- Python 3.10 Union operator
- Python 3.9 type hinting
- Postponed evaluation of type annotation
- Forward reference
- Case Conversion
- Rename
- Skip
- Conditional Skip
- Custom field (de)serializer
- Custom class (de)serializer
- Flatten
This project is licensed under the MIT license.