Library for automatically mapping one object to another
Project description
py-automapper
Python object auto mapper
Current mapper can be useful for multilayer architecture which requires constant mapping between objects from separate layers (data layer, presentation layer, etc).
For more information read the documentation.
Usage example:
from automapper import mapper
# Add automatic mappings
mapper.add(SourceClass, TargetClass)
# Map object of SourceClass to output object of TargetClass
mapper.map(obj)
# Map object to AnotherTargetClass not added to mapping collection
mapper.to(AnotherTargetClass).map(obj)
# Override specific fields or provide missing ones
mapper.map(obj, field1=value1, field2=value2)
# Don't map None values to target object
mapper.map(obj, skip_none_values = True)
Advanced features
from automapper import Mapper
# Create your own Mapper object without any predefined extensions
mapper = Mapper()
# Add your own extension for extracting list of fields from class
# for all classes inherited from base class
mapper.add_spec(
BaseClass,
lambda child_class: child_class.get_fields_function()
)
# Add your own extension for extracting list of fields from class
# for all classes that can be identified in verification function
mapper.add_spec(
lambda cls: hasattr(cls, "get_fields_function"),
lambda cls: cls.get_fields_function()
)
For more information about extensions check out existing extensions in automapper/extensions
folder
Not yet implemented features
# TODO: multiple from classes
mapper.add(FromClassA, FromClassB, ToClassC)
# TODO: add custom mappings for fields
mapper.add(ClassA, ClassB, {"Afield1": "Bfield1", "Afield2": "Bfield2"})
# TODO: Advanced: map multiple objects to output type
mapper.multimap(obj1, obj2)
mapper.to(TargetType).multimap(obj1, obj2)
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
py-automapper-0.1.1.tar.gz
(6.9 kB
view hashes)
Built Distribution
Close
Hashes for py_automapper-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aaa5007339e96e60ec71f3ee0b7459914b62545c8899d5ca1aa8df46ac2d273e |
|
MD5 | 1394cfdf787f7ef8cf75d33df9f5184d |
|
BLAKE2b-256 | e496c4ed4933fad47506d41ed79b9b365474cbcea806889ba80c36eece38f6c1 |