Deserialize to objects while staying DRY
Project description
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.
from dataclasses import dataclass
# Or using attrs
# from attr 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)])
Documentation
Limitations
String annotations and forward references are not yet supported. See this upstream issue.
Changelog
0.1.0 (2019-06-22)
Changes
First release on PyPI.
—
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
desert-0.1.4-py2.py3-none-any.whl
(12.4 kB
view hashes)
Close
Hashes for desert-0.1.4-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b7d28e57f3728bd9c1ecbe7e1d1763889ed44b0d06ef6e21e2e3231325376fa |
|
MD5 | 3f9108193c6bc48d514e9dcef25ffd45 |
|
BLAKE2b-256 | f102750e5ff459d9e528cdd9a5848da2b4b1c48d9323c1475443aeadcbfa3199 |