A utility library to map between dataclass
Project description
Python 3.7 helper tool to work with mapping of dataclasses.
It allow automapping a dataclass attributes
from automapping import Mapper, Rename
@dataclass
class InnerA:
number: int
list_of_values: List[str]
untyped_list: list
@dataclass
class A:
name: str
id_a: int
inner: InnerA
@dataclass
class InnerB:
number: int
list_of_values: List[str]
untyped_list: list
@dataclass
class B:
name: str
id_b: int
inner: InnerB
mapper = Mapper()
mapper.add_mapper(AutoMap(A, B, [
Rename('id_a', 'id_b')
]))
mapper.add_mapper(AutoMap(InnerA, InnerB))
input_a = A(name='Paul', id_a=6, inner=InnerA(
number=10, list_of_values=['a', 'b'], untyped_list=[1, True]))
result = mapper.map(input_a, B, ObjectDictTypeUpdater)
print(result) # B(name='Paul', id_b=6, inner=InnerB(number=10, list_of_values=['a', 'b'], untyped_list=[1, True]))
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
automapping-0.0.1.tar.gz
(7.8 kB
view details)
File details
Details for the file automapping-0.0.1.tar.gz
.
File metadata
- Download URL: automapping-0.0.1.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 60bfcf94d704c24a2e001b8aa8dacf42c48c256985db4a18908d52ed237dc8b8 |
|
MD5 | 1def9b016931495f62e1dd80cbbea07a |
|
BLAKE2b-256 | 960dba8b0e35791774d6e87ac6bbceb8707cbaabe3ee961241cdd4096182cb7c |