Skip to main content

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


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

remapdict-0.1.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file remapdict-0.1.1.tar.gz.

File metadata

  • Download URL: remapdict-0.1.1.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for remapdict-0.1.1.tar.gz
Algorithm Hash digest
SHA256 acf5980bf2b86b3553fcc7b8dd207a221ebf52ec30c85a1cd14ca23ed69076d3
MD5 fe2bfd00b51cfc4fbca817d7f2dcbf29
BLAKE2b-256 70dafbcbb256b9c649b80d25a4433ab28c049461c6d5711b4559d8eeb3bb9b04

See more details on using hashes here.

File details

Details for the file remapdict-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: remapdict-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for remapdict-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bbe7238505148bc6d80bcb89e20742e2ec0a113ec5336420222544da243195fd
MD5 8ad2496140fff110cfa57666b411e136
BLAKE2b-256 55565dd363fcb63d692cf2a2e1b4ed808747e9ebeca1988c758b6ce878fd2797

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page