Skip to main content

Dictionary Search tools

License Pypi Python Versions

In a nutshell Dictionary Search is a small library to search in a dictionaries recursively. Also have some other dictionary tools to make your life easier.

Install

> pip install dictionary-search

Search

# File: example.py

from dictionary_search import search_first, search_all

d = {
    "a": {
        "b": {
            "c": "C value 1"
        }
    },
    "e": "f",
    "h": [
        {
            "i": "j"
        },
        {
            "c": "C value 2"
        }
    ]
}

print("Search First: ", search_first(d, "c"))
print("Search All: ", search_all(d, "c"))
print()
print("Search First (path as tuple): ", search_first(d, "c", path_as_string=False))
print("Search All (path as tuple): ", search_all(d, "c", path_as_string=False))

After running the code, you will see:

> python examples/example.py
Search First:  ('a.b.c', 'C value 1')
Search All:  [('a.b.c', 'C value 1'), ('h.c', 'C value 2')]

Search First (path as tuple):  (('a', 'b', 'c'), 'C value 1')
Search All (path as tuple):  [(('a', 'b', 'c'), 'C value 1'), (('h', 'c'), 'C value 2')]

Flat and Nest

Allow you to flat and rebuild a dict. Nest only work with str and index keys.

data = {"a": {"b": 1, "c": 2}}
flat_data = flat(data) # will produce: [("a.b", 1), ("a.c", 2)]
assert data == nest(flat_data)

TODO: describe list

If you want more information, please take a look to our test

Authors

License

Dictionary Search is Open Source and available under the MIT.

Contributions

Contributions are very welcome. See CONTRIBUTING.md or skim existing tickets to see where you could help out.

Metadata

Release files for dictionary-search 1.1.1

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

Source distribution (sdist)

Source distribution for dictionary-search 1.1.1
File Size Uploaded Provenance
dictionary-search-1.1.1.tar.gz 5.5 kB Without provenance Details

Release files / dictionary-search-1.1.1.tar.gz

Download URL dictionary-search-1.1.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
61651e7c9d9826f58cc904a384db7a4fac4f862f6ee378643fb343adfae94443
BLAKE2b-256 checksum
How to use checksums
db35a6d0d497d655621fe10acd2a0d863a7a4a80f2493f9f85135357f92553d9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Security for dictionary-search 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.1.1 This release

1 release file No provenance

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