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
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d97816f1d4fd1e6a442493e59d40da284f8899ffbd0f0f7dd136238dab7a21 |
|
MD5 | 79d7c39ee62f8648d72fa353b03a3546 |
|
BLAKE2b-256 | e6a9231297f3beb9b0d9511e3a0233aeb74c43151e2851b90b8909c77a22a55d |
Provenance
File details
Details for the file dataclass_map_and_log-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: dataclass_map_and_log-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5682c8337f35a4669065433f03b373aa09f0c532f58287553eafd3090427bd04 |
|
MD5 | dc6b77be5ffd7a54391740cb91871155 |
|
BLAKE2b-256 | f038b2019689feca60c0ce7efc3c470189ab9ee7d351f6514d47d8002ab045c7 |