This tool memoizes data to sqlite.
Project description
cachehash
Cachehash is a lightweight Python library for caching file, directory, and value data in SQLite using fast xxhash checksums.
It is designed to memoize expensive computations by binding results to the content hash of files or directories, so you can skip recomputation when inputs have not changed.
Features
- ⚡ Fast hashing with xxhash
- 📂 Hash individual files, whole directories (structure + metadata + file content), or arbitrary values
- 💾 Store and retrieve JSON-serializable Python values
- 🗄️ Backed by SQLite, easy to inspect and portable
- 🔑 Get/set by path + hash, or by hash alone
- 🧰 Simple API for integration into data pipelines or caching layers
Installation
pip install cachehash
Requires Python 3.9 – 3.13.
Quick Start
from pathlib import Path
from cachehash.main import Cache
cache = Cache()
# Hash a file
file_hash = cache.hash_file(Path("data.csv"))
print(file_hash)
# Store computation result tied to the file
cache.set("data.csv", {"rows": 1234, "checksum": file_hash})
# Later, retrieve result if file unchanged
result = cache.get("data.csv")
print(result)
API Overview
Cache
hash_file(path)→ str : Hash file contentshash_directory(path)→ str : Hash entire directory treehash_value(value)→ str : Hash an arbitrary string/bytesget(path)→ Any | None : Retrieve value by file path + hashget_by_hash(path)→ Any | None : Retrieve value by hash onlyset(path, value, append=False): Store a value by file path + hashset_by_hash(key, hash, value, append=False): Store a value for precomputed hashset_value(key, value): Store a value by key only (not tied to content)get_value(key): Get a value by key only
Development
Clone the repo and install with dev dependencies:
git clone https://github.com/VerinFast/cachehash.git
cd cachehash
pip install -e .[dev]
Run tests:
pytest
Format code:
black src
License
Free for non-commercial use. See LICENSE for details.
Links
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 cachehash-1.1.4.tar.gz.
File metadata
- Download URL: cachehash-1.1.4.tar.gz
- Upload date:
- Size: 16.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11289d9ff0734a775705d4a8149e05ff377edd70c46e1618b661e7b051d9f794
|
|
| MD5 |
165b2f499615940ac07fa4b0c6955455
|
|
| BLAKE2b-256 |
b2b9c223087c42d71f692c7ecd66ef0c4154436fadae18936d40b832a2000061
|
Provenance
The following attestation bundles were made for cachehash-1.1.4.tar.gz:
Publisher:
release.yml on VerinFast/cachehash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cachehash-1.1.4.tar.gz -
Subject digest:
11289d9ff0734a775705d4a8149e05ff377edd70c46e1618b661e7b051d9f794 - Sigstore transparency entry: 971664427
- Sigstore integration time:
-
Permalink:
VerinFast/cachehash@cea35836d0e71a7ff56608826ab985d9e15224ff -
Branch / Tag:
refs/tags/1.1.4 - Owner: https://github.com/VerinFast
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cea35836d0e71a7ff56608826ab985d9e15224ff -
Trigger Event:
release
-
Statement type:
File details
Details for the file cachehash-1.1.4-py3-none-any.whl.
File metadata
- Download URL: cachehash-1.1.4-py3-none-any.whl
- Upload date:
- Size: 12.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5b805e649b5e2040cfeeba8732e179e297d31cfb89d9c0aca739ab732be83bf
|
|
| MD5 |
5ef7e9aaf7af69a2653fb59178c78f6d
|
|
| BLAKE2b-256 |
e63ba584093fe6f6de978a21ce8db869c4d605ca31fed47cbd9c5db63dd3409f
|
Provenance
The following attestation bundles were made for cachehash-1.1.4-py3-none-any.whl:
Publisher:
release.yml on VerinFast/cachehash
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cachehash-1.1.4-py3-none-any.whl -
Subject digest:
e5b805e649b5e2040cfeeba8732e179e297d31cfb89d9c0aca739ab732be83bf - Sigstore transparency entry: 971664440
- Sigstore integration time:
-
Permalink:
VerinFast/cachehash@cea35836d0e71a7ff56608826ab985d9e15224ff -
Branch / Tag:
refs/tags/1.1.4 - Owner: https://github.com/VerinFast
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@cea35836d0e71a7ff56608826ab985d9e15224ff -
Trigger Event:
release
-
Statement type: