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.
2019.12.10
Changes
Add UnknownType exception with better error message for types that should be generic. #8
2019.12.09
Changes
Marshmallow schema Meta arguments are accepted, allowing exclusion of unknown fields and other options. #3
2019.11.06 (2019-11-06)
Changes
Add twine and wheel development dependencies. #2
2019.11.06 (2019-11-06)
Changes
Switch to calver
Backward-incompatible Changes
Non-optional fields without a default or factory now have required=True so raise marshmallow.exceptions.ValidationError when missing. #1
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 Distribution
Built Distribution
File details
Details for the file desert-2019.12.10.tar.gz
.
File metadata
- Download URL: desert-2019.12.10.tar.gz
- Upload date:
- Size: 29.4 kB
- Tags: Source
- 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.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10bc3dfdd18cf5367d79a6a57b7cb0550896a9fd5575c14fd4d4c606b6176047 |
|
MD5 | 613a9d1cf3bfb9de64557b021e93d8a4 |
|
BLAKE2b-256 | 6a59f13cd6b90973fe3d9f372aa93039fa847405f14c45e143331a47eeeb8d6c |
File details
Details for the file desert-2019.12.10-py2.py3-none-any.whl
.
File metadata
- Download URL: desert-2019.12.10-py2.py3-none-any.whl
- Upload date:
- Size: 13.1 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.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 02eb580a4f9f40e65120877c1ab275981b60da762880fdbbada1a456c93c39cf |
|
MD5 | 9b9ea9277e98b4dcf8150b7132c44139 |
|
BLAKE2b-256 | f5dab0965ac33927107200509f1cc011823b621d9f8f153cca62439fc35cc4c6 |