Yet another serialization library on top of dataclasses
Project description
pyserde
Yet another serialization library on top of dataclasses, inspired by serde-rs.
Guide🇬🇧 | ガイド🇯🇵 | API Reference | Examples
Overview
pyserde
is a simple yet powerful serialization library on top of dataclasses. It allows you to convert Python objects to and from JSON, YAML, and other formats easily and efficiently.
Declare your class with @serde
decorator and annotate fields using PEP484 as below.
@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)
That's it! If you're interested in pyserde, please check our documentation! Happy coding with pyserde! 🚀
Features
- Supported data formats
- dict
- tuple
- JSON
- Yaml
- Toml
- MsgPack
- Pickle
- Supported types
- Primitives (
int
,float
,str
,bool
) - Containers
list
,set
,tuple
,dict
frozenset
,defaultdict
typing.Optional
typing.Union
- User defined class with
@dataclass
typing.NewType
for primitive typestyping.Any
typing.Literal
typing.Generic
typing.ClassVar
dataclasses.InitVar
Enum
andIntEnum
- Standard library
- PyPI library
numpy
typesSQLAlchemy
Declarative Dataclass Mapping (experimental)
- Primitives (
- Class Attributes
- Field Attributes
- Decorators
- Type Check
- Union Representation
- Forward reference
- PEP563 Postponed Evaluation of Annotations
- PEP585 Type Hinting Generics In Standard Collections
- PEP604 Allow writing union types as X | Y
- PEP681 Data Class Transform
- Case Conversion
- Rename
- Alias
- Skip (de)serialization (skip, skip_if, skip_if_false, skip_if_default)
- Custom field (de)serializer
- Custom class (de)serializer
- Custom global (de)serializer
- Flatten
Extensions
- pyserde-timedelta: (de)serializing datetime.timedelta in ISO 8601 duration format.
Contributors ✨
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
LICENSE
This project is licensed under the MIT license.
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
Built Distribution
File details
Details for the file pyserde-0.22.2.tar.gz
.
File metadata
- Download URL: pyserde-0.22.2.tar.gz
- Upload date:
- Size: 43.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9972707cb7bbcfa1f960b8a3589cc7035d522c4c6d6675fb7ebbb0ca7668469 |
|
MD5 | 353ea8bf1c3143d9254bf4abe0d345cf |
|
BLAKE2b-256 | 3adab919339182406b2b02b306b84607cda5a0cfa304deed64b1d88043b45d1a |
File details
Details for the file pyserde-0.22.2-py3-none-any.whl
.
File metadata
- Download URL: pyserde-0.22.2-py3-none-any.whl
- Upload date:
- Size: 45.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19875810db90782e968fbdf0ef2846f751eb456db1d289e927fc0e88053a7958 |
|
MD5 | 71ed5b614d0e5d3f6c4a73db27ab8e3b |
|
BLAKE2b-256 | 306cd56ebfce94fc0b75df37c95de636d0567db26c77d8c551ec930f23aa3254 |