Incremental file processing with persistent savepoints.
Project description
rprocess
rprocess provides glob_rprocessor and glob_rmprocessor utilities to process files matched by a glob pattern with persistent savepoints. glob_rprocessor processes files sequentially, while glob_rmprocessor uses multiprocessing for concurrent processing.
The savepoint file stores per-file results keyed by content hash. This makes reruns faster when files are unchanged, and supports incremental recovery when interruptions happen.
Installation
pip install rprocess
Quick Start
from rprocess import glob_rprocessor
def parse_file(path: str) -> int:
with open(path, "r", encoding="utf-8") as f:
return len(f.read())
def collect(total, current):
if total is None:
return current
return total + current
total_chars = glob_rprocessor(
pathname="data/**/*.txt",
file_function=parse_file,
safepoint_path=".rprocess.savepoint.pkl",
cumulative_function=collect,
recursive=True,
increment_savepoint=True,
)
print(total_chars)
How Savepoints Work
- Each matched file is hashed using SHA-256.
- If the hash already exists in the savepoint, the previous result is reused.
- If it is new, file_function(path) runs and the result is cached.
- Savepoint entries for files that no longer exist in the glob result are removed.
This enables fast incremental processing because unchanged files are skipped.
Interruption and Incremental Recovery
Use increment_savepoint=True to write the savepoint after each newly processed file.
This is useful for long-running jobs:
- If execution is interrupted, progress from already-processed files is preserved.
- The next run resumes with cached results for files completed before the interruption.
If increment_savepoint=False (default), savepoint updates are written at the end when changes occurred.
API
glob_rprocessor(
pathname,
file_function,
safepoint_path,
cumulative_function=None,
root_dir=None,
dir_fd=None,
recursive=False,
verbose=False,
increment_savepoint=False,
)
- pathname: glob pattern to select files.
- file_function: function called per file path.
- safepoint_path: pickle file path used to persist cached results.
- cumulative_function: optional reducer that combines per-file outputs.
- recursive: enable recursive glob patterns like **.
- verbose: print progress and savepoint maintenance messages.
- increment_savepoint: write savepoint after each new file result.
Parallel Processing with glob_rmprocessor
For improved performance on I/O-bound operations, use glob_rmprocessor() which processes files concurrently using Python's multiprocessing.Pool:
from rprocess import glob_rmprocessor
total_chars = glob_rmprocessor(
pathname="data/**/*.txt",
file_function=parse_file,
safepoint_path=".rprocess.savepoint.pkl",
cumulative_function=collect,
recursive=True,
verbose=True,
)
API
glob_rmprocessor(
pathname,
file_function,
safepoint_path,
cumulative_function=None,
processes=None
root_dir=None,
dir_fd=None,
recursive=False,
verbose=False,
)
Parameters are identical to glob_rprocessor(). The key difference is that file processing happens concurrently in worker processes, making it faster for I/O-bound workloads. The savepoint mechanism and caching behavior remain the same.
The additional parameter processes let's you specifiy the number of used workers.
If processes is None then the number returned by os.process_cpu_count() is used.
Development
python -m pip install --upgrade build twine pytest
python -m pytest
python -m build
python -m twine check dist/*
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rprocess-0.2.0.tar.gz.
File metadata
- Download URL: rprocess-0.2.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
519b0c0f34279d03b2224ebdebd2b9a84b5beb0bed1a08573da73131ed2c3de8
|
|
| MD5 |
478b4cba92436cb2b2ca884117b17344
|
|
| BLAKE2b-256 |
db336d28cbddfcc0ed95dbd7c645c8e5b220712c71b146a3d94c91ed7260f1b3
|
Provenance
The following attestation bundles were made for rprocess-0.2.0.tar.gz:
Publisher:
publish.yml on Cutyno/rprocess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rprocess-0.2.0.tar.gz -
Subject digest:
519b0c0f34279d03b2224ebdebd2b9a84b5beb0bed1a08573da73131ed2c3de8 - Sigstore transparency entry: 1436057657
- Sigstore integration time:
-
Permalink:
Cutyno/rprocess@88651d9c39226499099b545f6edf329467402c8d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Cutyno
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@88651d9c39226499099b545f6edf329467402c8d -
Trigger Event:
release
-
Statement type:
File details
Details for the file rprocess-0.2.0-py3-none-any.whl.
File metadata
- Download URL: rprocess-0.2.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c68a2ec0bd397a4127b4ab68e9206d573eefbafa56e393efed8a3a4e578744cd
|
|
| MD5 |
a742db90d6dd3304d7132df015603774
|
|
| BLAKE2b-256 |
9d3c60c51d78452966900ea06d4c3c9c507dcc0dad8459ff22d7e378cc6039d6
|
Provenance
The following attestation bundles were made for rprocess-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Cutyno/rprocess
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rprocess-0.2.0-py3-none-any.whl -
Subject digest:
c68a2ec0bd397a4127b4ab68e9206d573eefbafa56e393efed8a3a4e578744cd - Sigstore transparency entry: 1436057658
- Sigstore integration time:
-
Permalink:
Cutyno/rprocess@88651d9c39226499099b545f6edf329467402c8d -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Cutyno
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@88651d9c39226499099b545f6edf329467402c8d -
Trigger Event:
release
-
Statement type: