Skip to main content

Create data structures from dictionaries.

Project description

from-dict

Create data structures from dictionaries.

Features

  • Transform dicts to attr.s, dataclass and NamedTuple
  • 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)

Uploaded Source

Built Distribution

from_dict-0.1.0-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

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