Desert is a Python library that generates serialization schemas for dataclasses and attrs classes, building upon the Marshmallow library. It aims to help developers write DRY (Don't Repeat Yourself) code by automatically deriving serialization/deserialization logic from class definitions. The library is actively maintained, with its current version being 2022.9.22.
pip install desertVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define dataclasses, create a Desert schema from them, and then load data into the defined objects.
Upgrade your Python environment to version 3.7 or newer.
Avoid using string annotations and forward references within function scopes for types processed by Desert. Ensure all types are fully resolved at definition time.
Review custom field implementations to ensure compatibility with `desert`'s type resolution. For `TYPE_CHECKING` blocks, ensure that `desert`-compatible type hints are available for runtime schema generation outside these blocks if they are critical.
Always use `Optional[Type]` (e.g., `Optional[str]`) and verify that any custom fields define their types in a way `desert` can resolve.
Ensure that type hints essential for schema generation are not hidden within `TYPE_CHECKING` blocks or use `from __future__ import annotations` and ensure type resolution works at runtime.
When possible, explicitly create and reuse a single schema instance for a given dataclass to ensure consistency. Investigate how dataclass references are managed in complex scenarios.