Skip to main content

path-seeker

CI PyPI License: MIT

Find, count, and update keys anywhere in a nested dict or list of dicts — with full path disambiguation when the same key occurs at multiple depths.

Installation

pip install path-seeker

Usage

from path_seeker import PathSeeker

data = {
    "user": {
        "id": 1,
        "address": {"id": 42, "city": "Berlin"},
    },
    "orders": [
        {"id": 100, "status": "shipped"},
        {"id": 101, "status": "pending"},
    ],
}

seeker = PathSeeker(data)

# All values found under a key, at any depth
seeker.find_values("id")
# [1, 42, 100, 101]

# All (path, value) matches — use this to disambiguate duplicates
seeker.find_paths("id")
# [Match(path=['user', 'id'], value=1),
#  Match(path=['user', 'address', 'id'], value=42),
#  Match(path=['orders', 0, 'id'], value=100),
#  Match(path=['orders', 1, 'id'], value=101)]

# The first/last value found under a key, in traversal order
seeker.find_first_value("id")
# 1
seeker.find_last_value("id")
# 101

# The first/last (path, value) match found under a key, in traversal order
seeker.find_first_path("id")
# Match(path=['user', 'id'], value=1)
seeker.find_last_path("id")
# Match(path=['orders', 1, 'id'], value=101)

# Every distinct key name in the structure
seeker.get_keys()
# ['address', 'city', 'id', 'orders', 'status', 'user']

# How many times a key occurs
seeker.count_key("id")
# 4

# Whether a key occurs anywhere
seeker.has_key("id")
# True

# Update one exact occurrence, using a path from find_paths
seeker.set_value(["orders", 1, "status"], "cancelled")

# Update every occurrence of a key at once
seeker.update_values("id", 0)
# 4  (number of occurrences updated)

# Update just the first/last occurrence, in traversal order
seeker.update_first("id", -1)
# True
seeker.update_last("id", -2)
# True

# Delete every occurrence of a key
seeker.delete_key("status")
# 2  (number of occurrences deleted)

API

Method Returns Description
find_values(key) list[Any] Every value stored under key, at any depth.
find_paths(key) list[Match] Every (path, value) pair for key, at any depth.
find_first_value(key) Any The first value found under key, in traversal order. Raises UnknownKeyProvided if key doesn't occur anywhere.
find_last_value(key) Any The last value found under key, in traversal order. Raises UnknownKeyProvided if key doesn't occur anywhere.
find_first_path(key) Match The first (path, value) match found under key, in traversal order. Raises UnknownKeyProvided if key doesn't occur anywhere.
find_last_path(key) Match The last (path, value) match found under key, in traversal order. Raises UnknownKeyProvided if key doesn't occur anywhere.
get_keys() list[str] Every distinct key name in the structure, sorted.
count_key(key) int How many times key occurs.
has_key(key) bool Whether key occurs anywhere in the structure.
set_value(path, new_value) None Update the value at an exact path (from find_paths).
update_values(key, new_value) int Update every occurrence of key; returns count updated.
update_first(key, new_value) bool Update the first occurrence of key, in traversal order; False if absent.
update_last(key, new_value) bool Update the last occurrence of key, in traversal order; False if absent.
delete_key(key) int Delete every occurrence of key, at any depth; returns count deleted.
.data dict | list The current (possibly mutated) underlying structure.

Search is by key name, not by value — searching for a value and getting its path back is not supported yet.

Limitations

  • PathSeeker holds a reference to the structure you pass in — it does not make a defensive copy, so updates via set_value/update_values mutate your original object too.
  • Nested dicts and lists are traversed; other iterables (tuples, sets, generators) are treated as opaque values, since list-index-style paths don't make sense for them.
  • No cycle detection. This is fine for JSON/YAML-shaped data, which can't contain cycles, but a structure with a manually-introduced reference cycle will recurse forever.

Development

make install      # uv sync --all-extras
make check        # lint + typecheck + test (what CI runs)

Individual targets: make test, make lint, make format, make typecheck.

See CONTRIBUTING.md for the full workflow.

License

MIT — see LICENSE.

Release files for path-seeker 0.3.0

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

Source distribution (sdist)

Source distribution for path-seeker 0.3.0
File Size Uploaded
path_seeker-0.3.0.tar.gz 74.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for path-seeker 0.3.0
File Interpreter ABI Platform
path_seeker-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 79.9 kB

Release files / path_seeker-0.3.0.tar.gz

Download URL path_seeker-0.3.0.tar.gz
Size 74.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e8d964ce32687a8427956468140140a2b90c6e0dc0b6a2202890f1cb475d5319
BLAKE2b-256 checksum
How to use checksums
5593899dd3c31f3506f8019475435a956adf9281d1e042dd6e67a1b6011538c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release files / path_seeker-0.3.0-py3-none-any.whl

Download URL path_seeker-0.3.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
94d83b24a70438d2d328d0c7ec6cf84b234c9446ed9c688d89b3cf4003bb2ea9
BLAKE2b-256 checksum
How to use checksums
80336f9a1f3a9d5fcd8b830320932dcc80398e3b37aaff35db751d7dd9e05231
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 5, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.0

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

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