A lightweight Python library that uses MD5 checksums to track file changes and execute code only when files have been modified. PyChecksumCache maintains a persistent cache of file checksums, making it ideal for build systems, asset processors, incremental compilers, and any tools that need efficient change detection.
Project description
PyChecksumCache
A lightweight Python library that uses MD5 checksums to track file changes and execute code only when files have been modified. PyChecksumCache maintains a persistent cache of file checksums, making it ideal for build systems, asset processors, incremental compilers, and any tools that need efficient change detection.
How It Works
flowchart TD
A[File to process] --> B{Calculate MD5}
B --> C[Current checksum]
D[(Checksum cache)] --> E{Compare with cached checksum}
C --> E
E -->|Different or not in cache| F[Execute code]
E -->|Same| G[Skip processing]
F --> H[Update cache with new checksum]
style A fill:#f9f9f9,stroke:#333,stroke-width:2px
style D fill:#c9e6ff,stroke:#0066cc,stroke-width:2px
style F fill:#d9f7be,stroke:#389e0d,stroke-width:2px
style G fill:#ffccc7,stroke:#cf1322,stroke-width:2px
Features
- Track changes to files using MD5 checksums
- Persistent cache storage in JSON format
{
"tests/file1.txt": "ff1e0283123d14cf8bd52ac449770017",
"tests/file2.txt": "b445bf8b5da4cf880dd14e98c18c1bfa"
}
- Execute functions only when file content has changed
- Batch transform multiple files with automatic output management
- Full async/await support
- Works with Python 3.10+
- No external dependencies
Installation
pip install pychecksumcache
Or with uv:
uv pip install pychecksumcache
Quick Start
Basic Usage
import pytest
from pychecksumcache import PyChecksumCache
import os
input_files = ["tests/file1.txt", "tests/file2.txt"]
output_folder = "output"
output_extension = ".generated.txt"
@pytest.mark.asyncio
async def test_pychecksumcache_skipped():
# Define a transformation function
def transform_func(input_path, output_path):
with open(input_path, 'r') as infile, open(output_path, 'w') as outfile:
content = infile.read()
# Apply some transformation
transformed = content.upper() # For example, convert to uppercase
outfile.write(transformed)
# Perform the transformation
results = PyChecksumCache().transform(input_files, output_folder, output_extension, transform_func)
# See which files were processed
for output_file, was_transformed in results:
assert not was_transformed, f"Skipped (unchanged): {output_file}"
assert os.path.exists("checksum_cache.json") is True
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 pychecksumcache-1.0.1.tar.gz.
File metadata
- Download URL: pychecksumcache-1.0.1.tar.gz
- Upload date:
- Size: 19.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e77ef5cf19b32417f92482914fcfb03ea9791714c3e6bfbc283a9d595d6110e
|
|
| MD5 |
8c9e5f92b14f39cae4960155066ce648
|
|
| BLAKE2b-256 |
2cfab5d9fcbf5513ae9be165a0c3d5639b075d288019f7ac9e8f3caf2773ce97
|
File details
Details for the file pychecksumcache-1.0.1-py3-none-any.whl.
File metadata
- Download URL: pychecksumcache-1.0.1-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7694f36ff0df9f02ac56bc8f2848d092b0409b85c0ed1ee36f44e9a853d95131
|
|
| MD5 |
8d23422766a36fbd46247bb62fa0526b
|
|
| BLAKE2b-256 |
f45767b56cad9c7bce68f6291dce68496f170e3676280545e0e7fe23d98afc96
|