Skip to main content

A tool for iterating dictionaries as trees and printing all leaf nodes at some path

Project description


Takes a dict, and a path delimited with slashes like A/B/C/D, and returns a list of all leaves at all trajectories dict[A][B][C][D]

If the path is an empty string, returns the original dict

Each non-leaf node can be either a dictionary or list of objects including dictionaries.

Each leaf node can be an arbitrary object.

Non-leaf inner nodes that are not dictionaries are ignored.


Jsons sometimes have many levels and are a pain to parse.

This package was motivated by the pain in iterating dicts I received from calling simplejson on objects returned from various Twitter API calls. The API objects I had to parse had quadruple level nested dictionaries, and when I was playing around with the data, I wanted to be able to query different levels to see if the data was interesting.
Then I found out nothing in the Python language natively supports querying nested dicts when they may or may not exist:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
dictsearch-1.2.tar.gz (1.5 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page