xdol#

A toolkit for working with key-value stores (Extended Data Object Layers), built on dol. Record and replay costly calls, keep one mapping in sync with another, cap a fast store over a slow one, and register plugins in a typed dict.

pip install xdol

Documentation

Any MutableMapping works as a store: a dict, a folder of files, S3, a database, through dol. That is the difference from functools.lru_cache or joblib.Memory for memoization: the cache lives wherever your store does, and in replay mode a miss raises instead of quietly paying for the call.

from xdol import memoize_calls, update_with_policy

cache = {}


@memoize_calls(store=cache, mode="record")
def square(x):
    return x * x


assert square(3) == 9  # computed, and recorded in `cache`
assert square(3) == 9  # replayed from `cache`
assert len(cache) == 1

target = {"a": 1}
update_with_policy(target, {"a": 2, "b": 3})  # default: update keys whose values differ
assert target == {"a": 2, "b": 3}

What is in it#

Module

What it gives you

xdol.memoize

memoize_calls: persistent memoization with record and replay modes, spend-safe by default (a miss in replay mode raises).

xdol.keys

robust_key, make_key_func: stable, filesystem-safe cache keys from a call’s inputs.

xdol.updating

update_with_policy, backfill, reconcile, verify: controlled updates of one mapping from another.

xdol.tiering

TieredStore: a bounded hot store over a cold source of truth (write-through, GDSF or LRU release).

xdol.access

AccessStats, track_access: persisted, mergeable per-key access statistics for any store.

xdol.x_codecs

Codec, get_codec, paired_store: object-to-bytes codecs, and stores that apply them.

xdol.registry

Registry: a typed, dict-backed plugin registry with conflict rules.

xdol.pystores

PyFilesReader, PkgReader: mapping views of a folder’s or a package’s .py files.

xdol.from_dol

tools that left dol’s top level (igroupby, ihead, trace_getitem, to_zip_file, …).

Everything listed is importable from xdol directly.

Persistent memoizer (record/replay)#

Wrap a costly function (a paid API, a slow render) so the first run records its result to disk and every later run replays it:

from xdol import memoize_calls


# A path string becomes a folder store. The default mode is replay-only: a miss raises.
@memoize_calls(store="tests/cassettes", mode="record")
def slow_square(x):
    return {"result": x * x}

Stable keys (xdol.keys), text / JSON / binary / paired .json+.bin codecs, any MutableMapping as the store (a folder, S3), spend-safe replay by default. See the persistent memoizer guide.

This documentation as a single file: xdol.md (Markdown, for agents).

built 2026-11-23 11:04 UTC from e8a01c8 (master) · xdol 0.1.44 · about this build