Skip to main content

Map objects to dataclasses and log differencies

Project description

Dataclass Map and Log

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.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

dataclass_map_and_log-0.1-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataclass-map-and-log-0.1.tar.gz
  • Upload date:
  • Size: 3.2 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.tar.gz
Algorithm Hash digest
SHA256 172136b3f59dad2843a2f545d04a38a5c6dd3886c0b5a71e2f11e0fcdda96a25
MD5 1903b97ae4e8b922547885bf0880268f
BLAKE2b-256 fda2c60e59dd9f0eea3841efe11d267484d1d661cb56b87fc9a99838041b6d8d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataclass_map_and_log-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dc3faa560fa586726698da1cedc44f425ecddfc39d7984ea17648bc1dc0b257f
MD5 2bedb3f8f2736f8680c71cc31bd575eb
BLAKE2b-256 917058b14fcca0f9af63a05c31d44555a3ef635dd7946a0e0e4296043b205b44

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