Dictor is a Python JSON and Dictionary (Hash, Map) handler. It takes a dictionary or JSON data and returns a value for a specific key, simplifying access to deeply nested structures. Its primary goal is to eliminate the need for repetitive `try/except` blocks when performing lookups and to provide flexible fallback values for missing keys. The current version is 0.1.12, with new releases typically driven by feature additions or bug fixes rather than a strict cadence.
pip install dictorVerified import paths — ran on the pinned version, not inferred.
This example demonstrates basic usage of `dictor` to safely retrieve nested values from a dictionary using dot notation, providing a default value for non-existent keys, and accessing elements within lists.
If currently using Python 2, either upgrade your project to Python 3 or explicitly pin the `dictor` dependency to `dictor==0.1.12` in your `requirements.txt`.
Use the `pathsep` argument to specify a different character for path separation (e.g., `dictor(data, 'my.key', pathsep='_')`) or ensure keys with dots are not used in dot-separated search paths.
Only use `checknone=True` when `None` is explicitly considered an invalid value for the path, and you intend for a `ValueError` to be raised. Otherwise, rely on the default behavior where `None` is returned, or provide a `default` fallback value.
Be aware that `rtype` does not enforce type conversion for complex data structures; manual casting or further processing may be required if a specific type for these is desired.
If `None` is an acceptable value for the path, remove `checknone=True` from the `dictor` call. Alternatively, ensure the data at the specified path is not `None` or provide a `default` fallback value to `dictor`.
If the `dictor` call is expected to return a list, access its elements using list indexing (e.g., `my_list[0]`) or iterate over it. If a dictionary *within* the list is intended, adjust the path in `dictor` or perform list indexing before making another `dictor` call or using dictionary methods.
If your dictionary keys contain literal dots, use the `pathsep` argument in `dictor` to specify a different character for path separation (e.g., `dictor(data, 'my.key', pathsep='_')`) or ensure such keys are not used in dot-separated search paths.
No dependency data recorded yet.