Python library to trace path of a particular key inside a nested dict
MIT License
Python library to trace path of a particular key inside a nested dict
.. image:: https://img.shields.io/pypi/v/trace-dkey :target: https://pypi.python.org/pypi/trace-dkey/
.. image:: https://github.com/Agent-Hellboy/trace-dkey/actions/workflows/python-app.yml/badge.svg :target: https://github.com/Agent-Hellboy/trace-dkey/
.. image:: https://img.shields.io/pypi/pyversions/trace-dkey.svg :target: https://pypi.python.org/pypi/trace-dkey/
.. image:: https://img.shields.io/pypi/l/trace-dkey.svg :target: https://pypi.python.org/pypi/trace-dkey/
.. image:: https://pepy.tech/badge/trace-dkey :target: https://pepy.tech/project/trace-dkey
.. image:: https://img.shields.io/pypi/format/trace-dkey.svg :target: https://pypi.python.org/pypi/trace-dkey/
.. image:: https://coveralls.io/repos/github/Agent-Hellboy/trace-dkey/badge.svg?branch=main :target: https://coveralls.io/github/Agent-Hellboy/trace-dkey?branch=main
For stable version
For development
For more details, you can refer to the documentation <https://agent-hellboy.github.io/trace-dkey/>
_.
trace
function is an array of paths, where each path is an array of dictionary keys... code:: py
from trace_dkey import trace
l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}
paths = trace(l,'f')
for path in paths:
dic = l
for key in path:
dic = dic[key]
print(dic)
Added example scripts demonstrating how to use trace-dkey with responses from popular APIs. These examples can be found in the examples
folder:
github_api_example.py
): Demonstrates fetching repository informationopenweathermap_api_example.py
): Retrieves current weather datajsonplaceholder_api_example.py
): Shows how to interact with a mock REST APITo run these examples:
Install the required dependencies:
pip install -r examples/requirements.txt
For the OpenWeatherMap example, you'll need to sign up for a free API key at https://openweathermap.org/ and set it as an environment variable:
export OPENWEATHERMAP_API_KEY=your_api_key_here
Run the examples:
python examples/github_api_example.py
python examples/openweathermap_api_example.py
python examples/jsonplaceholder_api_example.py
These examples demonstrate how to use trace-dkey to find specific keys in nested JSON responses from real-world APIs.
| Someone made a nice comparison of this lib(trace-dkey) with one of the famous lib(yamlpath) which is doing the similar thing
.. image:: /images/img.png :width: 600
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.