Skip to main content

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

https://desert.readthedocs.io/

Limitations

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

Acknowledgements

2020.01.03

Changes

  • Optional fields allow None. #11. Thanks to @sveinse for reporting and testing.

2019.12.18

Changes

  • Improve error message for unknown generics. #10

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

desert-2020.1.3.tar.gz (30.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

desert-2020.1.3-py2.py3-none-any.whl (9.0 kB view details)

Uploaded Python 2Python 3

File details

Details for the file desert-2020.1.3.tar.gz.

File metadata

  • Download URL: desert-2020.1.3.tar.gz
  • Upload date:
  • Size: 30.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for desert-2020.1.3.tar.gz
Algorithm Hash digest
SHA256 58370a361311c3402e080499663c898e5e9e3d1ffa8a8f915a4ec3dce14a4122
MD5 67e7ce94bf76dd1e98774d2b969fd173
BLAKE2b-256 4733b99d6ec72625101aceea9be7998489b58f658b3493dc4bede29ff03c53be

See more details on using hashes here.

File details

Details for the file desert-2020.1.3-py2.py3-none-any.whl.

File metadata

  • Download URL: desert-2020.1.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.6.8

File hashes

Hashes for desert-2020.1.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e563c97056d8664195b8d9f0f90f5e594e301431da8c41b8d5da864300500ecc
MD5 a004b038d3ec823734344e23a878425e
BLAKE2b-256 86feb904e99e4b54983c3b2cb4746c418acee5f25cabdf9aa45cc7b7dfa1e3bf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page