Package: object-mapper
Version1.1.0AuthormaraztCopyrightmaraztLicenseThe MIT License (MIT)Last updated13 July 2019Package Downloadhttps://pypi.python.org/pypi/object-mapper—Versions1.1.0 - 2019/07/13Add basic support for nested object, thanks [@direbearform](https://github.com/direbearform)1.0.7 - 2019/06/19Fix type name inside mapper dict to avoid collision, thanks [@renanvieira](https://github.com/renanvieira)1.0.6 - 2018/10/28Added ability to specify excluded fields, thanks [@uralov](https://github.com/uralov)1.0.5 - 2018/02/21Support for dynamic properties [@nijm](https://github.com/nijm)1.0.4 - 2017/11/03Migration to new Pypi.org deployment1.0.3 - 2015/05/15Added support for None mapping [@ramiabughazaleh](https://github.com/ramiabughazaleh)1.0.2 - 2015/05/06Added support for case insensitivity mapping [@ramiabughazaleh](https://github.com/ramiabughazaleh)1.0.1 - 2015/02/19Fix of the package information1.0.0 - 2015/02/19Initial versionAboutObjectMapperis a class for automatic object mapping inspired by .NETAutoMapper. It helps you to create objects between project layers (data layer, service layer, view) in a simple, transparent way.ExampleMapping of the properties without mapping definitionIn this case are mapped only these properties of the target class which are in target and source classes. Other properties are not mapped. Suppose we have classAwith attributesnameandlast_nameand classBwith attributename. Initialization of the ObjectMapper will be:python   mapper = ObjectMapper()   mapper.create_map(A, B)   instance_b =mapper.map(A(),B)In this case, value of A.name will be copied into B.name.Mapping with defined mapping functionsSuppose we have classAwith attributesfirst_nameandlast_name, classBwith attributefull_nameand classCwith attribute reverse_name. And want to map it in a wayB.full_name = A.first_name + A.last_nameandC.reverse_name = A.last_name + A.first_nameInitialization of the ObjectMapper will be:```python mapper = ObjectMapper() mapper.create_map(A, B, {‘name’: lambda a : a.first_name + “ “ + a.last_name}) mapper.create_map(A, C, {‘name’: lambda a : a.last_name + “ “ + a.first_name})instance_b = mapper.map(A(), B) instance_c = mapper.map(A(), C) ```In this case, to theB.namewill be mappedA.first_name + " " + A.last_nameIn this case, to theC.namewill be mappedA.last_name + " " + A.first_nameMapping suppressionFor some purposes, it can be needed to suppress some mapping. Suppose we have classAwith attributesnameandlast_nameand classBwith attributesnameandlast_name. And we want to map only theA.nameintoB.name, but notA.last_nametoB.last_nameInitialization of the ObjectMapper will be:```python mapper = ObjectMapper() mapper.create_map(A, B, {‘last_name’: None})instance_b = mapper.map(A(), B) ```In this case, value of A.name will be copied intoB.nameautomatically by the attribute namename. AttributeA.last_namewill be not mapped thanks the suppression (lambda function is None).Case insensitive mappingSuppose we have classAwith attributesNameandAgeand classBwith attributesnameandageand we want to mapAtoBin a wayB.name=A.NameandB.age=A.AgeInitialization of the ObjectMapper will be:python   mapper = ObjectMapper()   mapper.create_map(A, B)   instance_b =mapper.map(A(),B, ignore_case=True)In this case, the value of A.Name will be copied into B.name and the value of A.Age will be copied into B.age.Note:You can find more examples in tests packageInstallationDownload this projectDownload from Pypi:https://pypi.python.org/pypi/object-mapperENJOY IT!