Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for automapping, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size automapping-0.0.1.tar.gz (7.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page