Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

543 Commits

Repository files navigation

Desert: DRY deserialization

docsDocumentation Status
code
Latest commit
tests
GitHub Actions Build Status
Coverage Status
package
PyPI Package latest release
PyPI Wheel
Supported versions
Supported implementations

Desert generates serialization schemas for dataclasses and attrs classes. Writing code that's DRY ("don't repeat yourself") helps avoid bugs and improve readability. Desert helps you write code that's DRY.

Installation

pip install desert

or with Poetry

poetry add desert

Usage

A simple example models two Person objects in a Car.

fromdataclassesimportdataclass# Or using attrs# from attr import dataclassfromtypingimportListimportdesert@dataclassclassPerson:
name: strage: int@dataclassclassCar:
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)
assertcar==Car(passengers=[Person(name='Alice', age=21), Person(name='Bob', age=22)])

Documentation

https://desert.readthedocs.io/

Limitations

String annotations and forward references inside of functions are not supported.

Acknowledgements

About

Deserialize to objects while staying DRY

Topics

Resources

Contributing

Stars

161 stars

Watchers

3 watching

Forks

Releases

Packages

Used by

Contributors

Languages