Create data structures from dictionaries.
Project description
from-dict
Create data structures from dictionaries.
Features
- Transform dicts to
attr.s
,dataclass
andNamedTuple
- Insert additional fields existing in dict into structure with
f__read_unknown=True
- Experimental type-checking at runtime with
fd__type_check=True
Example
import dataclasses
from from_dict import from_dict
@dataclasses.dataclass(frozen=True)
class MyDataclass:
foo: int
baz: str
input = {
"foo": 22,
"baz": "Hello",
"additional": "ignored key",
}
input_as_my_dataclass = from_dict(MyDataclass, input)
assert input_as_my_dataclass.foo == 22
assert input_as_my_dataclass.baz == "Hello"
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
from-dict-0.1.0.tar.gz
(2.9 kB
view hashes)
Built Distribution
Close
Hashes for from_dict-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a92eb63343e69707049a644450a5f4f5b26ce6ef3ed9e043ffade040c7546945 |
|
MD5 | 440b371888c54540948c56779c3b0703 |
|
BLAKE2b-256 | cba229e5621ba8ec5e43e762bc98fd76b48443372c117da320d7a9171d920bfd |