klepto
persistent caching to memory, disk, or database
What it is and what it does
klepto extends Python's standard caching with multiple replacement strategies and persistent storage backends. It provides LRU, LFU, MRU, and random-replacement caching algorithms, each available in standard and "safe" variants that recover from hashing errors. Beyond in-memory caching, klepto archives function results to files, SQL databases, or HDF5 files using a dictionary-style interface, enabling cache reuse across interpreter sessions.
The package is designed for distributed and parallel computing where caches need to be shared across threads and processes. It uses keymaps to convert function arguments into cache keys, supporting raw objects, hashes, strings, or serialized forms. klepto depends on dill for serialization and pox for utilities, and is part of the larger pathos framework for heterogeneous computing.
Use it for:
- Cache expensive computations across multiple Python sessions by saving results to disk or database
- Decorate functions in distributed workflows where multiple workers need access to the same cached results
- Implement custom caching strategies (LFU, MRU) instead of only LRU for domain-specific performance tuning
- Archive function call results to SQL or HDF5 for long-term storage and analysis
- Build fault-tolerant parallel applications that can recover cached state after restart
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
klepto provides multiple caching algorithms (LRU, LFU, MRU, random-replacement) and persistent archiving to files, databases, or HDF5, with a dictionary-style interface and function decorator support.
Yes. klepto is actively maintained, has low install friction, carries a permissive license, and fills a genuine gap for persistent, multi-algorithm caching in distributed settings. It's stable (Production/Stable status) with no known vulnerabilities. Install it if you need caching beyond functools.lru_cache or persistent result archiving; skip it if simple in-memory caching suffices.
Install
klepto on PyPI
pip
pip install kleptouv
uv add kleptopoetry
poetry add kleptoInstalling klepto
Before you install
Low friction install with only two runtime dependencies (pox and dill). Actively maintained with recent commits and stable production status.
License in practice
BSD-3-Clause permissive license allows commercial and private use with minimal restrictions; attribution and license notice required.
Quickstart
pip install klepto
from klepto.caches import lru_cache
@lru_cache()
def expensive_function(x):
return x ** 2
result = expensive_function(5)
Requires Python >=3.9; optional backends (HDF5, SQL) require additional dependencies.
Verify before relying
- Performance characteristics compared to functools.lru_cache for typical workloads
- Thread/process safety guarantees for concurrent access to persisted caches
- Serialization overhead when using different keymaps (hashmap, picklemap, stringmap)
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pox, dill |
| Maintenance | actively maintained — 207 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 96,083/month — #13,232 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: klepto-0.2.8-py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
cache-to-diskA decorator that caches function results to…
permissive · top 15,000 on PyPI
methodtoolsProvides LRU caching for methods, classmethods,…
permissive · top 5,000 on PyPI
cached_methodProvides a method-level caching decorator that…
permissive · top 15,000 on PyPI
cachierCachier is a decorator that adds persistent,…
permissive · top 15,000 on PyPI
backports.functools-lru-cacheProvides the lru_cache decorator from Python…
permissive · top 5,000 on PyPI
django-memoizeCaches function and method results in Django…
permissive · top 15,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
diskcacheDiskCache provides a pure-Python disk-backed…
permissive · top 1,000 on PyPI