trace-dkey
==========
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
Installation
============
For stable version
- pip install trace-dkey
For developement
- git clone https://github.com/Agent-Hellboy/trace-dkey
- cd trace-dkey
- python -m venv .venv
- source .venv/bin/activate
Example
=======
.. code:: py
>>> from trace_dkey import trace
>>> l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}
>>> print(trace(l,'f'))
[['a', 'b', 'c', 'd', 'e', 'f']]
Now you can query it as l['a']['b']['c']['d']['e']['f']
>>> l['a']['b']['c']['d']['e']['f']
1
General Info
============
- The value returned by the `trace` function is an array of paths, where each path is an array of dictionary keys.
- Because of that, the library can be used in a practical way by taking advantage of this format.
- In the example below we use the returned path to iterate over the dictionary keys and print the key value:
.. 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)
- This is addressing a wide range of question asked on stackoverflow about key inside a nested dict
- Atleast 13 duplicate questions can be found on stackoverflow
- This can be tracked on https://you.com/search?q=find%20key%20in%20nested%20dictionary%20python
| Someone made a nice comparision of this lib(trace-dkey) with one of the famous lib(yamlpath) which is doing the similar thing
.. image:: /images/img.png
:width: 600
Contributing
============
Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.
Raw data
{
"_id": null,
"home_page": "https://github.com/Agent-Hellboy/trace-dkey",
"name": "trace-dkey",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "tracer,dict-key-path-finder",
"author": "Prince Roshan",
"author_email": "princekrroshan01@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/0f/65/dfa77b9e5ebc4338e9eeb21035bebd74ef9a6f47e87e803dd21007e13a40/trace-dkey-0.0.4.tar.gz",
"platform": null,
"description": "trace-dkey\n==========\n\nPython library to trace path of a particular key inside a nested dict\n\n.. image:: https://img.shields.io/pypi/v/trace-dkey\n :target: https://pypi.python.org/pypi/trace-dkey/\n\n.. image:: https://github.com/Agent-Hellboy/trace-dkey/actions/workflows/python-app.yml/badge.svg\n :target: https://github.com/Agent-Hellboy/trace-dkey/\n \n.. image:: https://img.shields.io/pypi/pyversions/trace-dkey.svg\n :target: https://pypi.python.org/pypi/trace-dkey/\n\n.. image:: https://img.shields.io/pypi/l/trace-dkey.svg\n :target: https://pypi.python.org/pypi/trace-dkey/\n\n.. image:: https://pepy.tech/badge/trace-dkey\n :target: https://pepy.tech/project/trace-dkey\n\n.. image:: https://img.shields.io/pypi/format/trace-dkey.svg\n :target: https://pypi.python.org/pypi/trace-dkey/\n\n.. image:: https://coveralls.io/repos/github/Agent-Hellboy/trace-dkey/badge.svg?branch=main\n :target: https://coveralls.io/github/Agent-Hellboy/trace-dkey?branch=main\n\nInstallation\n============\n\nFor stable version \n - pip install trace-dkey\n\nFor developement \n - git clone https://github.com/Agent-Hellboy/trace-dkey\n - cd trace-dkey \n - python -m venv .venv \n - source .venv/bin/activate\n\nExample\n=======\n\n.. code:: py\n\n >>> from trace_dkey import trace\n >>> l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}\n >>> print(trace(l,'f'))\n [['a', 'b', 'c', 'd', 'e', 'f']]\n\n Now you can query it as l['a']['b']['c']['d']['e']['f']\n\n >>> l['a']['b']['c']['d']['e']['f']\n 1\n\nGeneral Info\n============\n\n - The value returned by the `trace` function is an array of paths, where each path is an array of dictionary keys.\n - Because of that, the library can be used in a practical way by taking advantage of this format.\n - In the example below we use the returned path to iterate over the dictionary keys and print the key value:\n\n .. code:: py\n \n from trace_dkey import trace\n l={'a':{'b':{'c':{'d':{'e':{'f':1}}}}}}\n \n paths = trace(l,'f')\n \n for path in paths:\n dic = l\n for key in path:\n dic = dic[key]\n print(dic)\n\n\n - This is addressing a wide range of question asked on stackoverflow about key inside a nested dict\n - Atleast 13 duplicate questions can be found on stackoverflow \n - This can be tracked on https://you.com/search?q=find%20key%20in%20nested%20dictionary%20python\n \n\n\n| Someone made a nice comparision of this lib(trace-dkey) with one of the famous lib(yamlpath) which is doing the similar thing \n\n\n\n.. image:: /images/img.png\n :width: 600\n\nContributing\n============\n\nPull requests are welcome. For major changes, please open an issue first\nto discuss what you would like to change.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python library to trace path of a particular key inside a nested dict",
"version": "0.0.4",
"split_keywords": [
"tracer",
"dict-key-path-finder"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "853b0bb394e51ca89787bb315d51893079b679b5db65011b8207bd666c5ac510",
"md5": "f604ba8745f41aec587265f3192ccbe2",
"sha256": "3fd2602429c43269747c5f461dc989743503c6d4c5d3f50ec1f54d3444ddc90f"
},
"downloads": -1,
"filename": "trace_dkey-0.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f604ba8745f41aec587265f3192ccbe2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 3886,
"upload_time": "2023-01-11T10:17:23",
"upload_time_iso_8601": "2023-01-11T10:17:23.590186Z",
"url": "https://files.pythonhosted.org/packages/85/3b/0bb394e51ca89787bb315d51893079b679b5db65011b8207bd666c5ac510/trace_dkey-0.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0f65dfa77b9e5ebc4338e9eeb21035bebd74ef9a6f47e87e803dd21007e13a40",
"md5": "26562c64f56578ab06de58b65dc9ba98",
"sha256": "b8c6e721296deca7be570183cfbf958ca4f925d3826fd2157561a5c812feae95"
},
"downloads": -1,
"filename": "trace-dkey-0.0.4.tar.gz",
"has_sig": false,
"md5_digest": "26562c64f56578ab06de58b65dc9ba98",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 3726,
"upload_time": "2023-01-11T10:17:25",
"upload_time_iso_8601": "2023-01-11T10:17:25.217677Z",
"url": "https://files.pythonhosted.org/packages/0f/65/dfa77b9e5ebc4338e9eeb21035bebd74ef9a6f47e87e803dd21007e13a40/trace-dkey-0.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-11 10:17:25",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "Agent-Hellboy",
"github_project": "trace-dkey",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "trace-dkey"
}