Registry / serialization / desert

desert

JSON →
library2022.9.22pypypi✓ verified 91d ago

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 desert
INSTALL
IMPORT
SIG · DESERT
D
desert
serializationpythonv2022.9.22
Install
1.9s avg
Import
594ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2022.9.22 · 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.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.600s · 19.4MB
glibc
py 3.10–3.920 runs
installs and imports cleanly · install 1.9s · import 0.588s · 20MB
17MB installed
● package 17MB
Code
Verified usage

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

desert
✓ import desert
dataclass
✓ from dataclasses import dataclass

This quickstart demonstrates how to define dataclasses, create a Desert schema from them, and then load data into the defined objects.

from dataclasses import dataclass from typing import List import desert @dataclass class Person: name: str age: int @dataclass class Car: passengers: List[Person] # Load some simple data types. data = {'passengers': [{'name': 'Alice', 'age': 21}, {'name': 'Bob', 'age': 22}]} # Create a schema for the Car class. schema = desert.schema(Car) # Load the data. car = schema.load(data) assert car == Car(passengers=[Person(name='Alice', age=21), Person(name='Bob', age=22)])
Debug
Known issues
breakingPython 3.6 support was dropped in version 2022.09.22 to allow updating internal dependencies.
fix
Upgrade your Python environment to version 3.7 or newer.
affects: >=2022.09.22
gotchaDesert does not support string annotations and forward references inside of functions, which can lead to unexpected behavior or failures in schema generation.
fix
Avoid using string annotations and forward references within function scopes for types processed by Desert. Ensure all types are fully resolved at definition time.
affects: <2022.09.22
gotchaThe library may encounter crashes or unexpected behavior when dealing with optional types that use custom fields or type hints encapsulated within `TYPE_CHECKING` blocks.
fix
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.
affects: <2022.09.22
Errors
Common errors & fixes
TypeError: An Optional type expects 1 subtype
Incorrect usage of `typing.Optional` (e.g., `Optional` instead of `Optional[str]`) or conflicts arising from custom fields and `desert`'s type introspection.
fix
Always use `Optional[Type]` (e.g., `Optional[str]`) and verify that any custom fields define their types in a way `desert` can resolve.
AttributeError: 'NoneType' object has no attribute 'load' (or similar errors during schema generation)
Desert failed to generate a valid schema for a dataclass, often due to unsupported type hints, especially those conditionally defined within `if typing.TYPE_CHECKING:` blocks.
fix
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.
Different schema classes are generated per reference of the same data class.
Under certain conditions, `desert` might generate multiple distinct schema instances for what is conceptually the same dataclass, leading to inconsistent behavior.
fix
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.
Upgrade
Version history
2022.9.22latest on PyPI · released Sep 23, 2022
Audit
Dependencies
marshmallowrequiredCore dependency for schema generation.
attrsoptionalOptional dependency if using attrs classes instead of dataclasses.
Agent activity
6 hits · last 30 days
node
6
Resources
desert — pip install desert · libregistry