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 inside of functions are not supported.
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
File details
Details for the file desert-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: desert-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a60d0b21cfe1c7d767ff97eb2386b44adb1259d28ae83023ba4daa519d8df196 |
|
MD5 | 83f57b675115b6d807e7b19abce0797e |
|
BLAKE2b-256 | ac083e3afb20c1c69c2a53ea6694bae85ed71b9689d23dedb0e9e1f5d0ed5068 |