Registry / serialization / pyserde

pyserde

JSON →
library0.32.1pypypi✓ verified 24d ago

PySerde is a Python serialization/deserialization library built on top of dataclasses, inspired by Rust's Serde. It allows for declarative definition of data structures and automatically generates serialization and deserialization functions for various formats like JSON, YAML, TOML, and MessagePack. Currently at version 0.31.2, it maintains an active release cadence with frequent bug fixes and minor feature additions.

pip install pyserde
INSTALL
IMPORT
SIG · PYSERDE
P
pyserde
serializationpythonv0.32.1
Install
3.7s avg
Import
450ms
Disk
41MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.32.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.460s · 41.6MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.7s · import 0.440s · 43MB
41MB installed
● package 41MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serde
from serde import serde
field
from serde import field
to_json
from serde.json import to_json
from_json
from serde.json import from_json

Decorate a dataclass with `@serde` to enable serialization and deserialization. Use format-specific functions like `to_json` and `from_json` from `serde.json`. The `@serde` decorator also adds `to_dict()` and `from_dict()` methods directly to the class for generic dictionary conversion.

from dataclasses import dataclass from serde import serde, field from serde.json import to_json, from_json @serde @dataclass class User: name: str age: int = field(default=30) email: str | None = None # Create an instance user_instance = User(name="Alice", email="alice@example.com") # Serialize to JSON string json_string = to_json(user_instance) print(f"Serialized JSON: {json_string}") # Deserialize from JSON string deserialized_user = from_json(User, json_string) print(f"Deserialized User: {deserialized_user}") # The @serde decorator also adds to_dict() and from_dict() methods directly to the class user_dict = user_instance.to_dict() print(f"Converted to dict: {user_dict}") another_user = User.from_dict({"name": "Bob", "age": 25, "email": "bob@example.com"}) print(f"Created from dict: {another_user}")
Debug
Known issues
breakingPySerde version 0.31.2 and later requires Python 3.10 or newer. Attempting to install or use these versions on older Python interpreters will result in an installation error.
fix
Upgrade your Python interpreter to 3.10+ to use the latest versions of pyserde.
affects: >=0.31.2
gotchaTo use serialization/deserialization for specific formats (e.g., YAML, TOML, faster JSON backends like `orjson`), you must install `pyserde` with the corresponding extras. The base `pip install pyserde` only includes JSON support via Python's standard `json` library.
fix
Install `pyserde` with the necessary extras, e.g., `pip install 'pyserde[json,yaml,orjson]'`.
affects: All
gotchaThe `@serde` decorator is designed to be applied to `dataclasses.dataclass` (or `attrs` classes when using `serde_attrs`). It will not work on plain Python classes, as it relies on the metadata and structure provided by dataclasses.
fix
Ensure your classes are defined as dataclasses (or `attrs` classes) before applying `@serde`.
affects: All
gotchaAdvanced field options such as `skip_if_none`, `skip_if_default`, `flatten`, `skip_serializing`, and `skip_deserializing` were introduced in versions 0.29.0 and 0.30.0. If you rely on these specific features, ensure your `pyserde` installation is version 0.30.0 or later.
fix
Upgrade `pyserde` to 0.30.0 or later to utilize all advanced field customization options.
affects: <0.30.0
Errors
Common errors & fixes
error: can't find rust-src component
pyserde's underlying Rust components require the `rust-src` toolchain component, which is not installed by default with Rust.
fix
rustup component add rust-src
ModuleNotFoundError: No module named 'serde'
The Python library is named `pyserde`, so imports must specify `pyserde` instead of just `serde`.
fix
from pyserde import serde, field, to_json, from_json
SerdeError: Class MyData is not a serde class. Please make sure you have `@serde` decorator on top of your dataclass.
The `@serde` decorator was omitted, preventing `pyserde` from generating the necessary serialization and deserialization methods for the dataclass.
fix
from dataclasses import dataclass
from pyserde import serde, to_json

@serde
@dataclass
class MyData:
    value: int

data = MyData(value=1)
print(to_json(data))
TypeError: Object of type datetime is not JSON serializable
Python's standard `json` module, used by `pyserde` by default for JSON serialization, cannot serialize `datetime` objects without a custom encoder.
fix
from dataclasses import dataclass
from datetime import datetime
from pyserde import serde, field, to_json

@serde
@dataclass
class Event:
    timestamp: datetime = field(
        serializer=lambda dt: dt.isoformat(),
        deserializer=lambda s: datetime.fromisoformat(s)
    )

event = Event(timestamp=datetime.now())
print(to_json(event))
Upgrade
Version history
0.32.1latest on PyPI · released Aug 29, 2026
Audit
Dependencies
pyyamloptionalRequired for YAML serialization/deserialization. Install with `pyserde[yaml]`.
tomloptionalRequired for TOML serialization/deserialization. Install with `pyserde[toml]`.
orjsonoptionalOptional faster JSON backend. Install with `pyserde[orjson]`.
ujsonoptionalOptional faster JSON backend. Install with `pyserde[ujson]`.
msgpackoptionalRequired for MessagePack serialization/deserialization. Install with `pyserde[msgpack]`.
Agent activity
9 hits · last 30 days
node
8
Resources
pyserde — pip install pyserde · libregistry