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.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 051dbc0635c556cb8d999339922b00b33f9db1fc6a1307f936f2efe9ff7e9b32 |
|
MD5 | 8b186be7c5487ed91b69ffe98d244e91 |
|
BLAKE2b-256 | 09b2aaf95f33dc95cb14ee42b038d63ab8f5c1a0cdb9deba681fa434be46673e |
Close
Hashes for dataclass_map_and_log-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5797901d3529abdc1371d63f81dfebb0e7ed7fa2d7d1c4f6792735dde9e9b2a1 |
|
MD5 | 1f104e1edaf921c4b46f8048c2505885 |
|
BLAKE2b-256 | 9c1ecc5013db16bc3de974aeb1b6d58a16541d118e2297daa434b7b1dcead842 |