Skip to main content

trace-dkey

Python library to trace path of a particular key inside a nested dict

https://img.shields.io/pypi/v/trace-dkey https://github.com/Agent-Hellboy/trace-dkey/actions/workflows/python-app.yml/badge.svg https://img.shields.io/pypi/pyversions/trace-dkey.svg https://img.shields.io/pypi/l/trace-dkey.svg https://pepy.tech/badge/trace-dkey https://img.shields.io/pypi/format/trace-dkey.svg https://coveralls.io/repos/github/Agent-Hellboy/trace-dkey/badge.svg?branch=main

Installation

For stable version
  • pip install trace-dkey

For development

Example

you can use the library as python3 -m trace_dkey --file=test.json --key=name, test.json is

A JSON file containing name as key

>>> 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

Documentation

For more details, you can refer to the documentation.

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:

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)
Someone made a nice comparision of this lib(trace-dkey) with one of the famous lib(yamlpath) which is doing the similar thing
/images/img.png

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Metadata

Release files for trace-dkey 0.0.8

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

Source distribution (sdist)

Source distribution for trace-dkey 0.0.8
File Size Uploaded
trace_dkey-0.0.8.tar.gz 5.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trace-dkey 0.0.8
File Interpreter ABI Platform
trace_dkey-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / trace_dkey-0.0.8.tar.gz

Download URL trace_dkey-0.0.8.tar.gz
Size 5.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c225a6ebd3da6a37651bdb812d6cc34830cec21cc8b6212da522cd7c28a44011
BLAKE2b-256 checksum
How to use checksums
c99b2771b68ecbdbd99d0b8c521dbba68b82a1bd185d0fba759edc8db7e19744
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / trace_dkey-0.0.8-py3-none-any.whl

Download URL trace_dkey-0.0.8-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a9521d60b1b53ddc79bc10e01556527e3fe74d81ac10671ce0db70ef425cf6a5
BLAKE2b-256 checksum
How to use checksums
0977ac509ef7ecfbde477dcec77b2018149de6bda3c96da1ca751725a80f249b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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