Pathable: Object-Oriented Paths

0.5.0 · active · verified Sat Mar 28

Pathable is a Python library that provides object-oriented paths for traversing hierarchical data structures like dictionaries and lists, as well as file systems. It offers an intuitive, chainable API for deep lookups, incremental path building, and safe probing of data. The library is actively maintained with frequent releases, with version 0.5.0 being the latest stable release.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `LookupPath` to navigate and access values within nested dictionary structures using a pathlib-like syntax. It shows basic navigation, value reading, existence checks, and safe access with a default fallback.

from pathable import LookupPath

data = {
    "parts": {
        "part1": {"name": "Part One"},
        "part2": {"name": "Part Two"}
    }
}

root = LookupPath.from_lookup(data)

# Navigate using slash operator
name_path = root / "parts" / "part2" / "name"
name = name_path.read_value()

print(f"Value found: {name}")
assert name == "Part Two"

# Check existence
assert (root / "parts" / "part1").exists()
assert not (root / "non_existent").exists()

# Safe access with .get()
part3_name = (root / "parts").get("part3", default=None)
print(f"Value with .get(): {part3_name}")
assert part3_name is None

view raw JSON →