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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for dataclass-map-and-log-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 172136b3f59dad2843a2f545d04a38a5c6dd3886c0b5a71e2f11e0fcdda96a25 |
|
MD5 | 1903b97ae4e8b922547885bf0880268f |
|
BLAKE2b-256 | fda2c60e59dd9f0eea3841efe11d267484d1d661cb56b87fc9a99838041b6d8d |
Close
Hashes for dataclass_map_and_log-0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc3faa560fa586726698da1cedc44f425ecddfc39d7984ea17648bc1dc0b257f |
|
MD5 | 2bedb3f8f2736f8680c71cc31bd575eb |
|
BLAKE2b-256 | 917058b14fcca0f9af63a05c31d44555a3ef635dd7946a0e0e4296043b205b44 |