Skip to main content

Dict/list wrappers that track key access for reporting unconsumed data

Project description

tracked-dict

Dict and list wrappers that track key access for reporting unconsumed data.

Wrap a parsed JSON/YAML/TOML structure in TrackedDict, read what you need through normal dict access, then call unaccessed() to get dotted paths for every key that was never touched.

Install

pip install tracked-dict

Usage

import json
from tracked_dict import TrackedDict

with open("config.json") as f:
    data = TrackedDict(json.load(f))

name = data["project"]["name"]
version = data["project"]["version"]

for path in data.unaccessed():
    print(f"  unhandled: {path}")

API

TrackedDict(data: dict, _path: str = "")

  • d[key] / d.get(key, default) — read access; marks key as accessed
  • key in d, len(d), bool(d), iter(d) — standard container ops (do not mark accessed)
  • d.keys() — returns keys (does not mark accessed)
  • d.values() / d.items() — iterate with wrapping; marks all keys accessed
  • d.raw — the underlying plain dict
  • d.mark_accessed(*keys) — explicitly mark keys
  • d.mark_all_accessed() — mark every key at this level
  • d.unaccessed() — sorted list of dotted paths for all unaccessed keys, recursively
  • d.accessed_keys() — set of keys accessed at this level

Nested dicts are automatically wrapped in TrackedDict, nested lists in TrackedList.

TrackedList(data: list, _path: str = "")

  • lst[i], len(lst), bool(lst), iter(lst) — standard access
  • lst.raw — the underlying plain list
  • lst.unaccessed() — collects unaccessed paths from wrapped children

How it works

When you access a key via [] or .get(), TrackedDict records that key. Nested dicts and lists are lazily wrapped on first access so their keys are tracked too. After your parser finishes, unaccessed() walks the tree and returns dotted paths (e.g. "server.timeout", "users[0].email") for anything never read.

This catches both parser omissions (data present but ignored) and unknown user-supplied fields — without maintaining a separate list of expected keys.

License

MIT

Project details


Download files

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

Source Distribution

tracked_dict-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tracked_dict-0.1.0-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file tracked_dict-0.1.0.tar.gz.

File metadata

  • Download URL: tracked_dict-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tracked_dict-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0962eeb9b2d0ee577b00010fc8315d0f4b9ba59c470eefa4211e1a2dcfb61fec
MD5 410197f6631ee4606f3124a1a465a3f8
BLAKE2b-256 9b8826808999945e7338e85fa82e3edfafc3dd26814b8b8918aa2bae47cf6436

See more details on using hashes here.

File details

Details for the file tracked_dict-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: tracked_dict-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for tracked_dict-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 956f548d9c91408d0c64c5c1cdbf24a57275e333ba493b9647c16a7dc4bd19da
MD5 c0ed4b628181febd66bb74a644810fa2
BLAKE2b-256 17e539dd27beaeeb0f9ffd08cbfeed432baa273632cf7aaae304fb30c9f29e76

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page