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,collections.abc.Sequence,collections.abc.MutableSequence,tupleset,collections.abc.Set,collections.abc.MutableSetdict,collections.abc.Mapping,collections.abc.MutableMappingfrozenset,defaultdict,deque,Counter
typing.Optionaltyping.Union- User defined class with
@dataclass typing.NewTypefor primitive typestyping.Anytyping.Literaltyping.Generictyping.ClassVardataclasses.InitVarEnumandIntEnum- Standard library
- PyPI library
numpytypesSQLAlchemyDeclarative 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
- PEP695 Type Parameter Syntax
- PEP747 Annotating Type Forms
- Case Conversion
- Rename
- Alias
- Skip (de)serialization (skip, skip_if, skip_if_false, skip_if_none, skip_if_default at field or class level)
- 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:
Made with contrib.rocks.
LICENSE
This project is licensed under the MIT license.
Metadata
Release files for pyserde 0.34.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyserde-0.34.0.tar.gz | 503.1 kB | Without provenance | Details for pyserde-0.34.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyserde-0.34.0-py3-none-any.whl | Python 3 | none | any | Details for pyserde-0.34.0-py3-none-any.whl |
Total release size: 556.5 kB
Release files / pyserde-0.34.0.tar.gz
| Download URL | pyserde-0.34.0.tar.gz |
|---|---|
| Size | 503.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b909f38adb201ecaecb1b66eb6c93f830ce4f92752daf16d684aec463a02ca8
|
|
BLAKE2b-256 checksum How to use checksums |
bcfc5c4eacd41655d4a8435095d6a88dec1f8766960a19e19dabf936a0aacf91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pyserde-0.34.0-py3-none-any.whl
| Download URL | pyserde-0.34.0-py3-none-any.whl |
|---|---|
| Size | 53.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb7cc51d3f08bdf5071925916bf246ca9b661c80fa26f79f0e7e3484d7b72a87
|
|
BLAKE2b-256 checksum How to use checksums |
7d0d36d6651e408f3e5d1ec067a3c92cd264a88d6e8f50399a54f351c3683bd0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pyserde 0.34.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.