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.0.tar.gz (2.0 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.0-py3-none-any.whl (2.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: remapdict-0.1.0.tar.gz
  • Upload date:
  • Size: 2.0 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.0.tar.gz
Algorithm Hash digest
SHA256 c0b757b17e5c512f3b184c763d62ec705e968cfef27b907b0ee812eaff0db221
MD5 59a67a420c7535b127598c5996452dd5
BLAKE2b-256 b61c99c6ee350770cf74172abdb3477aaa333d26cb817058efe9f23c9ac67226

See more details on using hashes here.

File details

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

File metadata

  • Download URL: remapdict-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0d2d8cfa923d40a35b1ebab2b7c454d7a37b11d4455321c4f4e37e9a631f63b
MD5 76cf61decd2c5e3162d35d44de18b8e1
BLAKE2b-256 26019d03361efd8ce4e8ed5b3fdbfa3998fd4ddd94d00f42a212d64426824b4f

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