Metadata-Version: 2.5
Name: xdol
Version: 0.1.44
Summary: Extended Data Object Layers - dol-based tools
Project-URL: Homepage, https://github.com/i2mint/xdol
License: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.10
Requires-Dist: config2py
Requires-Dist: dol>=0.3.113
Requires-Dist: tomli; python_version < '3.11'
Requires-Dist: typing-extensions
Provides-Extra: dev
Requires-Dist: pytest-cov>=4.0; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Requires-Dist: ruff>=0.1.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: sphinx-rtd-theme>=1.0; extra == 'docs'
Requires-Dist: sphinx>=6.0; extra == 'docs'
Provides-Extra: s3
Requires-Dist: s3dol>=1.0; extra == 's3'
Description-Content-Type: text/markdown

# xdol

A toolkit for working with key-value stores (Extended Data Object Layers), built on [`dol`](https://github.com/i2mint/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](https://i2mint.github.io/xdol/)

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.

```python
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:

```python
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](https://github.com/i2mint/xdol/blob/master/misc/docs/persistent_memoizer.md).
