Skip to main content

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 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.


Links

Project details


Download files

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

Source Distribution

cachehash-1.1.3.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

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

cachehash-1.1.3-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file cachehash-1.1.3.tar.gz.

File metadata

  • Download URL: cachehash-1.1.3.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for cachehash-1.1.3.tar.gz
Algorithm Hash digest
SHA256 49420036f96a45d6bfbfb2800fa92db46b75902df284c4d2066b4f92eb835c77
MD5 7980eba4bcc176ec9746e515f00be463
BLAKE2b-256 f2af2eee0b0fe2b02dc322339f2bb71a2076c5e558b0df0a830044ff29af1a17

See more details on using hashes here.

Provenance

The following attestation bundles were made for cachehash-1.1.3.tar.gz:

Publisher: release.yml on VerinFast/cachehash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file cachehash-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: cachehash-1.1.3-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.12.9

File hashes

Hashes for cachehash-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 445097562502caa3a177114c772373d0fc279e4ac8aba856b01ca42ece4b116c
MD5 e19466e7c2f44436c5b498e34eb05686
BLAKE2b-256 840f433364eecf0bbbd7e4ff7e15ec16265c59e5e75c982128d331767d9495a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for cachehash-1.1.3-py3-none-any.whl:

Publisher: release.yml on VerinFast/cachehash

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page