Skip to main content

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 contents
  • hash_directory(path) → str : Hash entire directory tree
  • hash_value(value) → str : Hash an arbitrary string/bytes
  • get(path) → Any | None : Retrieve value by file path + hash
  • get_by_hash(path) → Any | None : Retrieve value by hash only
  • set(path, value, append=False) : Store a value by file path + hash
  • set_by_hash(key, hash, value, append=False) : Store a value for precomputed hash
  • set_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.


Metadata

Release files for cachehash 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cachehash 1.1.4
File Size Uploaded Provenance Actions
cachehash-1.1.4.tar.gz 16.0 kB With provenance Details for cachehash-1.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cachehash 1.1.4
File Interpreter ABI Platform Actions
cachehash-1.1.4-py3-none-any.whl Python 3 none any Details for cachehash-1.1.4-py3-none-any.whl

Total release size: 28.6 kB

Release files / cachehash-1.1.4.tar.gz

Download URL cachehash-1.1.4.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
11289d9ff0734a775705d4a8149e05ff377edd70c46e1618b661e7b051d9f794
BLAKE2b-256 checksum
How to use checksums
b2b9c223087c42d71f692c7ecd66ef0c4154436fadae18936d40b832a2000061
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.

Transparency log

Release files / cachehash-1.1.4-py3-none-any.whl

Download URL cachehash-1.1.4-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5b805e649b5e2040cfeeba8732e179e297d31cfb89d9c0aca739ab732be83bf
BLAKE2b-256 checksum
How to use checksums
e63ba584093fe6f6de978a21ce8db869c4d605ca31fed47cbd9c5db63dd3409f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.

Transparency log

Security for cachehash 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cachehash-1.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Feb 20, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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