Python mapper library
Project description
py-mapper
Python Mapper Library
How to use this library
1. Mapping Flat Dictionary
from pymapper import Mapper
mapper = Mapper({
'dest_1': '$source_1',
'dest_2': '$source_2'
})
result = mapper.map({
'source_1': 1,
'source_2': 'Lorem ipsum',
'source_3': 3.4
})
# result = {'dest_1': 1, 'dest_2': 'Lorem ipsum'}
2. Mapping Nested Dictionary
from pymapper import Mapper
mapper = Mapper({
'dest_1': {
'dest_2': '$source_1.source_2'
},
'dest_2': '$source_1.source_3.source_4'
})
result = mapper.map({
'source_1': {
'source_2': [1, 2, 3],
'source_3': {
'source_4': 5
}
},
})
# result = {'dest_1': {'dest_2': [1, 2, 3]}, 'dest_2': 5}
3. Mapping a List of Dictionaries
from pymapper import Mapper
mapper = Mapper({
'dest_1': {
'dest_2': '$source_1.source_2'
},
'dest_2': '$source_1.source_3.source_4'
})
result = mapper.map([
{
'source_1': {
'source_2': [1, 2, 3],
'source_3': {
'source_4': 5
}
}
},
{
'source_1': {
'source_2': [4, 5, 6],
'source_3': {
'source_4': 7
}
}
}
])
# result = [{'dest_1': {'dest_2': [1, 2, 3]}, 'dest_2': 5}, {'dest_1': {'dest_2': [4, 5, 6]}, 'dest_2': 7}]
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-mapper-0.1.0a0.tar.gz
(2.5 kB
view hashes)
Built Distribution
Close
Hashes for py_mapper-0.1.0a0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 262050ec8b0c7a7b64e83daa45f3f8e9f946dd4e83c8594be3eddea8acbcbe34 |
|
MD5 | ad69a31281b328132141485963781b2f |
|
BLAKE2b-256 | 669acfc3a26576e3138c06c73dbb5d2932366a37941389c3234e3346c7e8ad80 |