theine
high performance in-memory cache
What it is and what it does
Theine is an in-memory cache library for Python with a Rust-based core that implements an adaptive W-TinyLFU eviction policy. It stores key-value pairs in memory and automatically removes expired entries using a hierarchical timer wheel. The cache is fully typed, thread-safe by default, and supports free-threading in Python 3.13.6+.
The library provides both a direct Cache API for manual caching and a Memoize decorator for function result caching. It supports both synchronous and asynchronous functions, offers cache stampede protection, and includes a Django cache backend. Version 2.0 simplified the API by consolidating to a single eviction policy, changing Cache.get to return an explicit (value, exists) tuple, and renaming the timeout parameter to ttl.
Use it for:
- Cache expensive database queries or API responses in web applications to reduce latency and load.
- Memoize function results in data processing pipelines to avoid redundant computation.
- Store session data or temporary state in multi-threaded Python services with automatic expiration.
- Use as a Django cache backend for application-level caching without external infrastructure.
- Accelerate machine learning inference by caching model predictions or intermediate results.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Theine is a high-performance in-memory cache with a Rust core, adaptive W-TinyLFU eviction, automatic expiration, and thread-safe operations including free-threading support.
Yes, if you need a performant, thread-safe in-memory cache with minimal setup. The low install friction, permissive license, and lack of known vulnerabilities make it a safe choice. However, the aging maintenance status (362 days since last release) means you should verify that its feature set and performance characteristics match your workload before committing to production use.
Install
theine on PyPI
pip
pip install theineuv
uv add theinepoetry
poetry add theineInstalling theine
Before you install
Low install friction with a pure wheel distribution. Maintenance status is aging—last release was 362 days ago—but the package remains functional and receives updates.
License in practice
BSD-3-Clause is permissive; you may use, modify, and distribute Theine freely in commercial and private projects provided you include the license notice.
Quickstart
pip install theine
from theine import Cache
from datetime import timedelta
cache = Cache(10000)
cache.set("key", {"foo": "bar"}, timedelta(seconds=100))
v, ok = cache.get("key")
if ok:
print(v)
Requires Python 3.9 or later; free-threaded Python 3.13.6+ is recommended for best results with free-threading.
Verify before relying
- Whether the Rust core dependency (theine-core) is pre-built for all major platforms or requires compilation.
- Performance benchmarks against other Python caching libraries in typical production workloads.
- Whether the single shared expiration thread scales well with thousands of cache instances.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (<4.0,>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — theine-core, typing-extensions, zstandard |
| Maintenance | aging — 362 days since the last release |
| First released | |
| Downloads | 144,330/month — #11,154 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: theine-2.0.0-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
async-cacheIn-memory async cache for Python applications…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
cacheboxCachebox is a high-performance in-memory…
permissive · top 5,000 on PyPI
repoze-lruA lightweight LRU (least recently used) cache…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
aiocacheProvides asyncio-compatible caching with…
unclear · top 5,000 on PyPI
onecacheOneCache provides LRU-based caching decorators…
permissive · top 15,000 on PyPI