{"id":5028,"library":"pyserde","title":"PySerde: Serialization for Dataclasses","description":"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.","status":"active","version":"0.31.2","language":"en","source_language":"en","source_url":"https://github.com/yukinarit/pyserde","tags":["serialization","deserialization","dataclasses","json","toml","yaml","msgpack"],"install":[{"cmd":"pip install pyserde","lang":"bash","label":"Base installation"},{"cmd":"pip install 'pyserde[json,yaml,toml]' # Install with common backends","lang":"bash","label":"Installation with optional backends"}],"dependencies":[{"reason":"Required for YAML serialization/deserialization. Install with `pyserde[yaml]`.","package":"pyyaml","optional":true},{"reason":"Required for TOML serialization/deserialization. Install with `pyserde[toml]`.","package":"toml","optional":true},{"reason":"Optional faster JSON backend. Install with `pyserde[orjson]`.","package":"orjson","optional":true},{"reason":"Optional faster JSON backend. Install with `pyserde[ujson]`.","package":"ujson","optional":true},{"reason":"Required for MessagePack serialization/deserialization. Install with `pyserde[msgpack]`.","package":"msgpack","optional":true}],"imports":[{"symbol":"serde","correct":"from serde import serde"},{"symbol":"field","correct":"from serde import field"},{"symbol":"to_json","correct":"from serde.json import to_json"},{"symbol":"from_json","correct":"from serde.json import from_json"}],"quickstart":{"code":"from dataclasses import dataclass\nfrom serde import serde, field\nfrom serde.json import to_json, from_json\n\n@serde\n@dataclass\nclass User:\n    name: str\n    age: int = field(default=30)\n    email: str | None = None\n\n# Create an instance\nuser_instance = User(name=\"Alice\", email=\"alice@example.com\")\n\n# Serialize to JSON string\njson_string = to_json(user_instance)\nprint(f\"Serialized JSON: {json_string}\")\n\n# Deserialize from JSON string\ndeserialized_user = from_json(User, json_string)\nprint(f\"Deserialized User: {deserialized_user}\")\n\n# The @serde decorator also adds to_dict() and from_dict() methods directly to the class\nuser_dict = user_instance.to_dict()\nprint(f\"Converted to dict: {user_dict}\")\n\nanother_user = User.from_dict({\"name\": \"Bob\", \"age\": 25, \"email\": \"bob@example.com\"})\nprint(f\"Created from dict: {another_user}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade your Python interpreter to 3.10+ to use the latest versions of pyserde.","message":"PySerde 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.","severity":"breaking","affected_versions":">=0.31.2"},{"fix":"Install `pyserde` with the necessary extras, e.g., `pip install 'pyserde[json,yaml,orjson]'`.","message":"To 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.","severity":"gotcha","affected_versions":"All"},{"fix":"Ensure your classes are defined as dataclasses (or `attrs` classes) before applying `@serde`.","message":"The `@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.","severity":"gotcha","affected_versions":"All"},{"fix":"Upgrade `pyserde` to 0.30.0 or later to utilize all advanced field customization options.","message":"Advanced 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.","severity":"gotcha","affected_versions":"<0.30.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}