
Security News
NVD Quietly Sweeps 100K+ CVEs Into a “Deferred” Black Hole
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
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.
::
pip install desert
or with Poetry
_
::
poetry add desert
.. start-basic-usage
A simple example models two Person
objects in a Car
.
.. code-block:: python
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)])
.. end-basic-usage
https://desert.readthedocs.io/
String annotations and forward references inside of functions are not supported.
.. _Poetry: https://poetry.eustace.io .. _marshmallow-dataclass: https://pypi.org/project/marshmallow-dataclass/ .. _attrs: http://www.attrs.org/
Backward-incompatible Changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
#161 <https://github.com/python-desert/desert/issues/161>
_Changes ^^^^^^^
It is now possible to use type-variant generics
_ in your dataclasses, such as Sequence
or MutableSequence
instead of List
, Mapping
instead of Dict
, etc.
This allows you to hide implementation details from users of your dataclasses. If a field
in your dataclass works just as fine with a tuple as a list, you no longer need to force
your users to pass in a list
just to satisfy type checkers.
For example, by using Mapping
or MutableMapping
, users can pass OrderedDict
to
a Dict
attribute without MyPy complaining.
.. code-block:: python
@dataclass
class OldWay:
str_list: List[str]
num_map: Dict[str, float]
# MyPy will reject this even though Marshmallow works just fine. If you use
# type-variant generics, MyPy will accept this code.
instance = OldClass([], collections.ChainMap(MY_DEFAULTS))
@dataclass
class NewWay:
str_list: List[str] # Type-invariants still work
num_map: MutableMapping[str, float] # Now generics do too
.. _type-variant generics: https://mypy.readthedocs.io/en/stable/generics.html
#140 <https://github.com/python-desert/desert/issues/140>
_
Changes ^^^^^^^
#79 <https://github.com/python-desert/desert/issues/79>
_Changes ^^^^^^^
#28 <https://github.com/python-desert/desert/issues/28>
_Changes ^^^^^^^
self
(attr.Factory(..., takes_self=True)
).
#27 <https://github.com/python-desert/desert/issues/27>
_Changes ^^^^^^^
#16 <https://github.com/python-desert/desert/issues/16>
_ Thanks to @sveinse for reporting and testing.#18 <https://github.com/python-desert/desert/issues/18>
_#19 <https://github.com/python-desert/desert/issues/19>
#20 <https://github.com/python-desert/desert/issues/20>
_Changes ^^^^^^^^
Optional
fields allow None
. #11 <https://github.com/python-desert/desert/issues/11>
__. Thanks to @sveinse for reporting and testing.Changes ^^^^^^^
#10 <https://github.com/python-desert/desert/pull/10>
_Changes ^^^^^^^
UnknownType
exception with better error message for types that should be generic.
#8 <https://github.com/python-desert/desert/issues/8>
_Changes ^^^^^^^
Meta
arguments are accepted, allowing exclusion of unknown fields and other options.
#3 <https://github.com/python-desert/desert/pull/3>
_Changes ^^^^^^^
#2 <https://github.com/python-desert/desert/issues/2>
_Changes ^^^^^^^
Backward-incompatible Changes ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
required=True
so raise marshmallow.exceptions.ValidationError
when missing.
#1 <https://github.com/python-desert/desert/issues/1>
_Changes ^^^^^^^
FAQs
Deserialize to objects while staying DRY
We found that desert demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD now marks all pre-2018 CVEs as "Deferred," signaling it will no longer enrich older vulnerabilities, further eroding trust in its data.
Research
Security News
Lazarus-linked threat actors expand their npm malware campaign with new RAT loaders, hex obfuscation, and over 5,600 downloads across 11 packages.
Security News
Safari 18.4 adds support for Iterator Helpers and two other TC39 JavaScript features, bringing full cross-browser coverage to key parts of the ECMAScript spec.