Skip to content

A convenience function for arbitrarily remapping dictionary key/value pairs, including arbitrary transformations.

License

Notifications You must be signed in to change notification settings

DylanCulfogienis/remapdict

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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'
}

About

A convenience function for arbitrarily remapping dictionary key/value pairs, including arbitrary transformations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages