A convenience function for arbitrarily remapping dictionary keys, taking subsets, etc.
Project description
remapdict
Really simple Python function for arbitrarily remapping dictionary keys value pairs with arbitrary transformations and convenience configuration like passthrough and error handling.
Documentation
Example usage:
user = {
'email': 'email@email.com',
'firstName': 'Foo',
'lastName': 'Bar',
'status': 'active',
'type': 'administrator',
'tenantId': 1,
}
payload = remap_dict(user,
const={'password': 'password'},
passthrough={
'email',
'status',
'type',
},
mapper={
'first_name': 'firstName',
'last_name': 'lastName',
'tenant_id': 'tenantId',
},
transformer={
'full_name': lambda x: f'{x["firstName"]} {x["lastName"]}'
}
)
>>> payload
{
'status': 'active',
'email': 'email@email.com',
'type': 'administrator',
'password': 'password',
'first_name': 'Foo',
'last_name': 'Bar',
'tenant_id': 1,
'full_name': 'Foo Bar'
}
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
remapdict-0.1.1.tar.gz
(1.9 kB
view hashes)
Built Distribution
Close
Hashes for remapdict-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbe7238505148bc6d80bcb89e20742e2ec0a113ec5336420222544da243195fd |
|
MD5 | 8ad2496140fff110cfa57666b411e136 |
|
BLAKE2b-256 | 55565dd363fcb63d692cf2a2e1b4ed808747e9ebeca1988c758b6ce878fd2797 |