Skip to main content

maidkit

Maidkit provides small, typed tools for Python scripts. It keeps each API narrow and avoids application framework features.

  • Python 3.12+
  • Apache-2.0

Installation

pip install maidkit

With uv:

uv add maidkit

Batch jobs

maidkit.batch processes a finite iterable of items on a fixed number of worker threads. It shows progress with Rich and returns results in input order.

import hashlib
from pathlib import Path

from maidkit.batch import TaskContext, run_batch


def hash_file(path: Path, task: TaskContext) -> str:
    digest = hashlib.sha256()
    total = path.stat().st_size

    task.status("hashing")
    with path.open("rb") as source:
        while chunk := source.read(1024 * 1024):
            task.check_cancelled()
            digest.update(chunk)
            task.advance(len(chunk), total=total, unit="bytes")

    return digest.hexdigest()


files = (path for path in Path("input").iterdir() if path.is_file())
result = run_batch(
    files,
    hash_file,
    title="Hash files",
    workers=4,
    label=lambda path: path.name,
)

for item in result.failed:
    print(f"{item.label}: {item.error}")

raise SystemExit(0 if result.ok else 1)

A worker receives one item and a TaskContext. The context lets the worker:

  • Set its status with task.status(...).
  • Report absolute or incremental progress.
  • Check for cancellation with task.check_cancelled().
  • Skip the item with task.skip(...).
  • Run a child process with task.run_process(...).

Each item gets one ItemResult. A normal return succeeds. If a worker raises an exception, the item fails. The batch continues by default.

The display supports single-item and multi-item batches. Redirected output uses stable text instead of live progress.

Batch behavior

  • run_batch reads all items and labels before it starts a worker.
  • It runs at most workers items at the same time.
  • It returns results in input order, even when workers finish in a different order.
  • It stores worker exceptions in failed results instead of raising them.
  • fail_fast=True stops new items after the first failure. Active workers continue.
  • The first Ctrl+C stops scheduling new items and requests cancellation from active workers.

TaskContext.run_process captures stdout and stderr and checks the exit status. Batch cancellation also stops the child process. Output callbacks run in the worker thread and receive one line at a time without its newline.

Download files

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

Source Distribution

maidkit-0.1.0.tar.gz (14.5 kB view details)

Uploaded Source

Built Distribution

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

maidkit-0.1.0-py3-none-any.whl (18.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: maidkit-0.1.0.tar.gz
  • Upload date:
  • Size: 14.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for maidkit-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6e6107a26dc330d44e3e779116df1f0261e3323aa337d7c0bb4e0bba9a1fd98e
MD5 4d3fd425c7d998099f920d4c3104faaf
BLAKE2b-256 94341d006840e18dac0b51d63b0d66e26104034617148a3e30ae5fa12e8f43fe

See more details on using hashes here.

File details

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

File metadata

  • Download URL: maidkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for maidkit-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 613dd1ae860acac3dae83be4fd3f0bf0cde5b1086ea4d438c16f570b30170539
MD5 abf74f13fd4d071d9bb941af3d049d09
BLAKE2b-256 1549d70fcecc15cfe01d6707b8e73350ef9f29f464949243becae07b8092cbd1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

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