Skip to main content

Composable directory-based data cascade loader/saver with per-file origins and a convenient path/proxy API.

Project description

data-cascade

A composable directory-based data cascade loader/saver for Python (>=3.10). It merges files in a tree (YAML/JSON/TOML), keeps a per-key origin map for round-tripping, and offers both a path API and an ergonomic proxy API with dirty-file saves.

Features

  • Merge __main__.* into the current node and per-file trees by stem name.
  • Directory-level __config__.* with data.merge options (dict/list modes, per-key overrides, excludes).
  • Supports YAML (ruamel.yaml preferred, PyYAML fallback), JSON (stdlib), TOML (tomllib or tomli; writers via tomli-w or toml).
  • Returns a CascadeMap mapping each merged key path to the source file and local path.
  • save_data_cascade writes values back to their original files, or sensible defaults for new keys.
  • Cascade object with:
    • Path API: get("a.b[1]"), set("a.b[1]", value), delete("a.b[1]")
    • Proxy API: c.node("a").b[1].set(value) and c.node().a.b[1].get()
    • Dirty-file saves: c.save() only rewrites files you touched.

Install (with Poetry)

poetry add data-cascade
# Optionally enable YAML and TOML writers/readers
poetry add data-cascade -E yaml -E toml

Quick start

from pathlib import Path
from data_cascade import load_data_cascade, save_data_cascade

data, cmap = load_data_cascade(Path("data"))
data["project"] = {"name": "Alpha"}
save_data_cascade(Path("data"), data, cmap)

The Cascade object

from data_cascade import make_cascade

c = make_cascade("data")

# Path API
members = c.get('team.members')
c.set('team.members[1]', 'Carol')
c.save()  # only touches the file that owns team.members

# Proxy API
node = c.node('a').b[1]
node.set(42)
print(node.get())
c.save()

Configuring merge

Put a __config__.yaml in any directory. Example:

__config__:
  data:
    merge:
      dict: deep            # deep | override | first_wins
      list:
        mode: merge_by_key  # replace | extend | unique | merge_by_key
        key: id
      per_key:
        tasks:
          list:
            mode: unique
      exclude: ["scratch"]  # skip stems or keys

Handling missing libraries

YAML and TOML are optional. If a file is encountered and no handler exists for its extension, a warning is logged and the file is skipped/raises on save for that type. Install extras (-E yaml, -E toml) for full support.

Tasks (poethepoet)

poe test   # run pytest
poe pack   # packaging info
poe fmt    # placeholder for formatters

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

data_cascade-0.2.0.dev0.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

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

data_cascade-0.2.0.dev0-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file data_cascade-0.2.0.dev0.tar.gz.

File metadata

  • Download URL: data_cascade-0.2.0.dev0.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for data_cascade-0.2.0.dev0.tar.gz
Algorithm Hash digest
SHA256 123f4cbe862a01552b44c2fde1d83128bfe841fac1bf1d32bed43ebf551d3a9e
MD5 d636577fa4684c9591c5dd4bf797c101
BLAKE2b-256 966a945ea0a65333b77d2a542d82c71fe674e70dca82d062f5035ef213818d32

See more details on using hashes here.

File details

Details for the file data_cascade-0.2.0.dev0-py3-none-any.whl.

File metadata

  • Download URL: data_cascade-0.2.0.dev0-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.2.1 CPython/3.12.12 Linux/6.6.87.2-microsoft-standard-WSL2

File hashes

Hashes for data_cascade-0.2.0.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 9798fab75b9a354814122049e850905cded004730b68a6099f1e633ef5973d75
MD5 895afd787e086b00ba9e437061bd25bc
BLAKE2b-256 97849ab3957fa86bc0bf0dea242be4620b5be5f9a19904e03121ec51b1a33f30

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