Skip to main content

dotreach

Typed, zero-dependency get/set/delete/has on nested dicts and lists by dotted path.

Install

pip install dotreach

Usage

import dotreach

data = {"user": {"name": "Ada", "roles": ["admin", "editor"]}}

dotreach.get(data, "user.name")            # "Ada"
dotreach.get(data, "user.roles.0")         # "admin"  (integers index sequences)
dotreach.get(data, "user.roles.-1")        # "editor" (negative indices work)
dotreach.get(data, "user.age", default=0)  # 0        (no default: raises KeyError)

dotreach.has(data, "user.roles.1")         # True

dotreach.set(data, "user.age", 36)         # missing dict keys are created
dotreach.set(data, "user.roles.0", "owner")

dotreach.delete(data, "user.roles.1")
dotreach.delete(data, "user.nope", missing_ok=True)

Mapping segments are always treated as keys and sequence segments as integer indices, so there is no ambiguity: get({"0": "x"}, "0") returns "x", while get(["x"], "0") returns the first element. Strings and bytes are never indexed into. Need a different delimiter? Pass sep:

dotreach.get({"a": {"b": 1}}, "a/b", sep="/")  # 1

Why

Reaching into JSON-shaped data by a single string path is a common need, but the existing options all ask for a compromise:

  • glom is powerful but heavy: it pulls in boltons, attrs and face, and its spec language is far more than a dotted lookup.
  • python-benedict wraps every dict and drags a large dependency tree (slugify, requests, and more under its extras) for what is often a one-line need.
  • dpath is dependency-free but path-oriented in a clunky way: slash-and-glob paths and a search-style API rather than a plain get(obj, "a.b.0.c", default).
  • dotty_dict and scalpl take the wrapper-object route and have not shipped a release since 2022 and 2021 respectively.

dotreach is the small, maintained middle: four plain functions, full type hints checked under mypy --strict, ships py.typed, no runtime dependencies, and one unambiguous rule for how a segment is read. Reach for it when you want dotted-path access to nested data and nothing else.

License

MIT. See LICENSE.

Metadata

Release files for dotreach 0.1.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 dotreach 0.1.0
File Size Uploaded
dotreach-0.1.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dotreach 0.1.0
File Interpreter ABI Platform
dotreach-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.2 kB

Release files / dotreach-0.1.0.tar.gz

Download URL dotreach-0.1.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
60979e4f80cccb3e06d533665af45728d9f61163345b9f9fca938e5cdb84c3b6
BLAKE2b-256 checksum
How to use checksums
87915b36450c7ef0135d2bb7080f03a3dd0008882fdbd485db32193381185dee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / dotreach-0.1.0-py3-none-any.whl

Download URL dotreach-0.1.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f72570c9d81bfee3ebcd9944c6f3c1d8990e82fa4fe1db6541576708afea194
BLAKE2b-256 checksum
How to use checksums
aedd080f9854a69e31826334b126ff358191e469189a7b53b8bb073bd11271cc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.1.0 This release

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