Skip to main content

Map objects to dataclasses and log differencies

Project description

Dataclass Map And Logtag Build codecov

Map dictionaries to pydantic dataclasses, log any extra attributes.

Example

from dataclass_map_and_log.mapper import DataclassMapper

@dataclass
class Child:
    name: str
    surname: str


@dataclass
class SingleChild:
    name: str


@dataclass
class Parent:
    name: str
    surname: str
    children: List[Child]
    single_child: SingleChild
    
data = {
    "name": "parent_name",
    "surname": "parent_surname",
    "extra": "parent_extra_data",
    "children": [
        {
            "name": "child1_name",
            "surname": "child1_surname",
            "extra": "child_extra_data",
        },
        {
            "name": "child2_name",
            "surname": "child2_surname",
        },
    ],
    "single_child": {"name": "test"},
}

definition = DataclassMapper.map(Parent, data)

You can then access the dataclass instance like:

definition.single_child.name

And you would have gotten the following warning log messages:

"Unexpected attribute extra on class <class 'tests.test_dataclass_map_and_log.Parent'> with value parent_extra_data",
"Unexpected attribute extra on class <class 'tests.test_dataclass_map_and_log.Child'> with value child_extra_data",

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

dataclass-map-and-log-0.1.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distribution

dataclass_map_and_log-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file dataclass-map-and-log-0.1.1.tar.gz.

File metadata

  • Download URL: dataclass-map-and-log-0.1.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for dataclass-map-and-log-0.1.1.tar.gz
Algorithm Hash digest
SHA256 98d97816f1d4fd1e6a442493e59d40da284f8899ffbd0f0f7dd136238dab7a21
MD5 79d7c39ee62f8648d72fa353b03a3546
BLAKE2b-256 e6a9231297f3beb9b0d9511e3a0233aeb74c43151e2851b90b8909c77a22a55d

See more details on using hashes here.

Provenance

File details

Details for the file dataclass_map_and_log-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for dataclass_map_and_log-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5682c8337f35a4669065433f03b373aa09f0c532f58287553eafd3090427bd04
MD5 dc6b77be5ffd7a54391740cb91871155
BLAKE2b-256 f038b2019689feca60c0ce7efc3c470189ab9ee7d351f6514d47d8002ab045c7

See more details on using hashes here.

Provenance

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