Skip to main content

kaparoo-python

License: MIT PyPI version Downloads Python uv Ruff ty Copier

Personally common and useful Python features.

📦 Installation

Requires Python 3.13 or newer.

# With uv (recommended)
uv add kaparoo-python

# With pip
pip install kaparoo-python

🧩 Modules

Each submodule ships its own README with focused examples.

kaparoo.filesystem

pathlib-based filesystem helpers: existence checks (*_exists), the contains(subpath) predicate factory, ensure_* validators, make_dir(s) (with a destructive clean reset option), prune_upward for upward empty-parent removal, dir_empty(s), reserve_path(s) guards for not-yet-existing destinations, StagedFile / StagedDirectory for safe (atomic) writes, path stringification, extension helpers (ensure_file_extension, file_extension, normalize_extension(s)), and a small exception hierarchy.

kaparoo.filesystem.search

Filesystem traversal with composable filters: search_paths / search_files / search_dirs, wired to the kaparoo.filters DSL via part_filter / name_filter / predicate, with min_depth / max_depth control, a subtree-pruning exclude, a walk-narrowing descend, and a SearchKwargs bundle for forwarding the shared keywords; plus a path-aware select that filters an already-gathered collection by an include / exclude name spec (exact subpaths, .json / .txt files, patterns, or filters).

kaparoo.filesystem.hierarchy

A declarative description of a filesystem tree: File / Directory nodes whose names are drawn from the kaparoo.filters DSL (so one node can stand for many regularly-named siblings), plus Exclusive / Together constraints and per-node attribute conditions. It drives four disk operations — locate (map on-disk paths to spec nodes), validate (check a directory against the spec), conformer (build a search predicate from a spec), and scaffold (create the tree on disk).

kaparoo.filters

A declarative, composable string-matching DSL: a Filter family (pattern, multi-pattern, logical, constant Any, and enumerable Literal / OneOf / Template) that round-trips through JSON-friendly dicts, plus an extension hook for custom filter kinds; and select / resolve_selector, which filter a collection by an include / exclude name spec. Used by kaparoo.filesystem.search for path matching and kaparoo.filesystem.hierarchy for declaring trees.

kaparoo.utils

Timer / SpanTimer context-manager-and-decorator timers (with lap-split and measure-block timings); Aggregator for nested, pluggable metric aggregation (the batch → epoch → run pattern); ensure_one_of / ensure_in_range validation guards; resolve_enum / literal_values for config-driven Enum / Literal sets; quantify for pluralized counts; plus helpers for Optional[T] values (replace_if_none, unwrap_or_default, ...).

kaparoo.data

Building blocks for dataset code: DataSequence[T, M] ABC (item + metadata), composers (SlicedSequence, ConcatSequence, TransformedSequence, WindowedSequence, ZippedSequence), file-backed templates (FileFolderSequence, FileListSequence, SingleFileSequence), and generate_batches.

🎯 Quick example

Search a tree with composable filters:

from kaparoo.filesystem import search_files
from kaparoo.filters import And, EndsWith, Equals, Not

# All .py files except __init__.py
py_files = search_files(
    "src",
    name_filter=And((EndsWith(".py"), Not(Equals("__init__.py")))),
)

…or describe a tree declaratively and check a directory against it:

from kaparoo.filesystem.hierarchy import Directory, File, validate
from kaparoo.filters import Glob

spec = Directory("dataset", [
    File("metadata.json"),
    Directory("images", [File(Glob("*.png"))]),
])
report = validate(spec, "data/dataset", root_as_top=True)
assert report.ok  # required entries present, nothing unexpected

See each submodule's README for more.

📋 TODO

See TODO.md for tracked open items.

📜 Changelog

See CHANGELOG.md for the version history.

⚖️ License

This project is distributed under the terms of the MIT license.

Download files

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

Source Distribution

kaparoo_python-0.13.1.tar.gz (114.1 kB view details)

Uploaded Source

Built Distribution

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

kaparoo_python-0.13.1-py3-none-any.whl (108.9 kB view details)

Uploaded Python 3

File details

Details for the file kaparoo_python-0.13.1.tar.gz.

File metadata

  • Download URL: kaparoo_python-0.13.1.tar.gz
  • Upload date:
  • Size: 114.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kaparoo_python-0.13.1.tar.gz
Algorithm Hash digest
SHA256 ff988311dfdea0f262e51c8a128bd3e4a8699e6f0491463298b8e9b1a88e3f59
MD5 35711b996a189b145709ad791cda2858
BLAKE2b-256 9af55caff12f638b6cde7d3304c2f562596611a403aba3739b8b061af6df7162

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaparoo_python-0.13.1.tar.gz:

Publisher: publish.yml on kaparoo/kaparoo-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kaparoo_python-0.13.1-py3-none-any.whl.

File metadata

  • Download URL: kaparoo_python-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 108.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kaparoo_python-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa0dcf171aeb0b2b5addc298255b3c83bb972842c061f01006a4f18a5ffe8dd3
MD5 23e182ed8f87536ce810c12f2e8a365d
BLAKE2b-256 1ea9dfc97a9d6e3fdfd9edfae1e908b8bc14a382be9f840830d115f4eb236471

See more details on using hashes here.

Provenance

The following attestation bundles were made for kaparoo_python-0.13.1-py3-none-any.whl:

Publisher: publish.yml on kaparoo/kaparoo-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.14.0

2 files

This release

0.13.1 This release

2 files

0.13.0

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.0

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.12

2 files

0.1.11

2 files

0.1.10

2 files

0.1.9

2 files

0.1.8

2 files

0.1.7

2 files

0.1.6

2 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