Skip to main content

dictnavigator

dictnavigator is a tool for working with nested dictionaries in Python. The main DictNavigatorKey class provides convenience methods for retrieving, updating, and deleting values for given keys at any dictionary depth, even if the key:value pair is contained in another nested data type (tuple, list, dictionary). In addition, it allows you to get a list of all keys in the dictionary at any nesting level. This library will come in handy if you work with data in JSON format, especially if you receive it from an API. It simplifies working with this data, allowing you to quickly retrieve the values you need and update them.

Requirements

Python >=3.5.2.

Install

pip install dictnavigator

Usage example

>>> from dictnavigator.navigator import DictNavigatorKey

>>> dictionary = {
        "key1": "value1",
        "key2": {
            "nested_key1": "nested_value1",
            "nested_key2": {
                "deeply_nested_key1": "deeply_nested_value1",
                "deeply_nested_key2": "deeply_nested_value2",
                "deeply_nested_key3": [{"list_key1": "list_deeply_value1"}],
                "deeply_nested_key4": ["deeply_nested_value4", "deeply_nested_value5"]
            }
        },
        "key3": [
            {"list_key1": "list_value1"},
            {"list_key2": "list_value2"},
            {"list_key3": "list_value3"}
        ],
        "key4": (
            {"tuple_key1": "tuple_value1"},
            {"tuple_key2": "tuple_value2"}
        )
    }

>>> navigator_one = DictNavigatorKey(dictionary)
>>> print(navigator_one.extract_keys_values("deeply_nested_key3"))
>>> print(navigator_one.extract_keys_values("list_key1"))
>>> print(navigator_one.extract_keys_values("key1"))
>>> print(navigator_one.extract_keys_values("tuple_key2"))

[{'deeply_nested_key3': [{'list_key1': 'list_deeply_value1'}]}]
[{'list_key1': 'list_deeply_value1'}, {'list_key1': 'list_value1'}]
[{'key1': 'value1'}]
[{'tuple_key2': 'tuple_value2'}]

>>> navigator_one.delete_key("key4", ({"tuple_key1": "tuple_value1"}, {"tuple_key2": "tuple_value2"}))
>>> navigator_one.update_value("deeply_nested_key4", ["deeply_nested_value4", "deeply_nested_value5"], ['Liza', 'Peter'])
>>> print(navigator_one.get_dict())

{'key1': 'value1', 'key2': {'nested_key1': 'nested_value1', 
                            'nested_key2': {'deeply_nested_key1': 'deeply_nested_value1', 'deeply_nested_key2': 'deeply_nested_value2', 
                                            'deeply_nested_key3': [{'list_key1': 'list_deeply_value1'}], 
                                            'deeply_nested_key4': ['Liza', 'Peter']}}, 
                    'key3': [{'list_key1': 'list_value1'}, {'list_key2': 'list_value2'}, {'list_key3': 'list_value3'}]}

>>> print(navigator_one.extract_keys_values("deeply_nested_key3"))
>>> print(navigator_one.extract_keys_values("deeply"))
>>> print(navigator_one.extract_all_keys())

[{'deeply_nested_key3': [{'list_key1': 'list_deeply_value1'}]}]
[]
['deeply_nested_key1', 'deeply_nested_key3', 'deeply_nested_key4', 'key1', 'list_key1', 'nested_key2', 'key3', 'deeply_nested_key2', 'key2', 'nested_key1', 'list_key2', 'list_key3']

Metadata

Release files for dictnavigator 1.1

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

Source distribution (sdist)

Source distribution for dictnavigator 1.1
File Size Uploaded Provenance
dictnavigator-1.1.tar.gz 3.4 kB Without provenance Details

Release files / dictnavigator-1.1.tar.gz

Download URL dictnavigator-1.1.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2a8c59883b088fc00f9dacbab2ecced228dd8ca45a4f1d6803a2d2039d857bed
BLAKE2b-256 checksum
How to use checksums
70aad2f25081f817e814556f096181c11c2d29cfdedfddd1aec9e4a5850b56fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for dictnavigator 1.1

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.

Release history Release notifications | RSS feed

This release

1.1 This release

1 release file No provenance

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