Skip to main content

transmogrifydict

The "map a dict from one API into a dict for another" python module.

That dict is so cool...

master

Tests Coverage

Tests Coverage

Tests Coverage

Tests Coverage

Tests Coverage

Flake8

develop

Tests Coverage

Tests Coverage

Tests Coverage

Tests Coverage

Tests Coverage

Flake8

methods

  • resolve_mapping_to_dict(mapping, source) - move values from source into a returned dict, using mapping for paths and returned keys.

    from transmogrifydict import resolve_mapping_to_dict
    
    mapping = {
        'a': 'd',
        'b': 'e',
        'c': 'f'
    }
    
    source = {
        'd': 1,
        'e': 2,
        'f': 3
    }
    
    resolve_mapping_to_dict(mapping, source)
    # {
    #     'a': 1,
    #     'b': 2,
    #     'c': 3,
    # }
    
  • resolve_path_to_value(source, path) - fetch a value out of source using path as the pointer to the desired value. see docstring for path string formats.

    from transmogrifydict import resolve_path_to_value
    
    source = {
        'd': 1,
        'e': 2,
        'f': 3
    }
    
    found, value = resolve_path_to_value(source, 'e')
    
    print((found, value))
    # (True, 2)
    

path or mapping value format

from transmogrifydict import resolve_path_to_value

source = {
    'some-key': {
        'another-key': '123'
    }
}

# dot notation can be used to descend into dictionaries.
resolve_path_to_value(source, 'some-key.another-key')
# (True, '123')

source = {
    'some-key': '{"another-key":"123"}'
}

# dot notation can also be used to descend into json strings that are dictionary like
resolve_path_to_value(source, 'some-key.another-key')
# (True, '123')

source = {
    'some-key': {
        'another-key': ['1', '2', '3']
    }
}

# square brackets can be used to get specific indexes from a list
resolve_path_to_value(source, 'some-key.another-key[1]')
# (True, '2')

source = {
    'some-key': {
        'another-key': [
            {
                'filter-key': 'yeah',
                'each-key': 'a',
            },
            {
                'filter-key': 'yeah',
                'each-key': 'b',
            },
            {
                'filter-key': 'nah',
                'each-key': 'c',
            }
        ]
    }
}

# dot notation can be used after square brackets if the list contains dict-like values
resolve_path_to_value(source, 'some-key.another-key[1].each-key')
# (True, ['b']) 

# square brackets can be used to iterate over arrays to descend into the items
resolve_path_to_value(source, 'some-key.another-key[].each-key')
# (True, ['a', 'b', 'c'])

# when iterating over a list, a filter can be applied using [key=value]
resolve_path_to_value(source, 'some-key.another-key[filter-key=yeah].each-key')
# (True, ['a', 'b'])

source = {
    'a-key': [
        {
            'b-key': {
                'c-key': 1,
                'd-key': 2,
            }
        },
        {
            'b-key': {
                'c-key': 1,
                'd-key': 3,
            }
        },
        {
            'b-key': {
                'c-key': 0,
                'd-key': 4,
            }
        }
    ]
}
# tidle notation can be used to filter on sub keys of dict list items.
resolve_path_to_value(source, 'a-key[b-key~c-key=1].b-key.d-key')
# (True, [2, 3, 4])
# 

Metadata

Release files for transmogrifydict 1.1.3.post1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for transmogrifydict 1.1.3.post1
File Size Uploaded Provenance Actions
transmogrifydict-1.1.3.post1.tar.gz 11.8 kB Without provenance Details for transmogrifydict-1.1.3.post1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for transmogrifydict 1.1.3.post1
File Interpreter ABI Platform Actions
transmogrifydict-1.1.3.post1-py3-none-any.whl Python 3 none any Details for transmogrifydict-1.1.3.post1-py3-none-any.whl

Total release size: 18.5 kB

Release files / transmogrifydict-1.1.3.post1.tar.gz

Download URL transmogrifydict-1.1.3.post1.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
38991572abd66ea7a657917be94751cf32278f5d742b5d2fef3963b34211d05e
BLAKE2b-256 checksum
How to use checksums
fad5e5bef42bb9378149ad909c070010666a1d2620ac8eae3235e52a99832b5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.9

Release files / transmogrifydict-1.1.3.post1-py3-none-any.whl

Download URL transmogrifydict-1.1.3.post1-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e624db49b400e2c32e26ad139f9d45d19156e06ffeac17f808453408cc0ea16
BLAKE2b-256 checksum
How to use checksums
384f705a865d700e8e1858c8adbabd787cf1f5beb246a8b0d46988a45c8b617f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.9

Security for transmogrifydict 1.1.3.post1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page