skillfed

theine

high performance in-memory cache

theine v2.0.0 144.3K downloads/30d#11,154 on PyPI
Permissive license BSD-3-Clause AGING released

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 theine

uv

uv add theine

poetry

poetry add theine

Installing 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

Programming Language :: Python :: 3Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

in-memory cache pythonhigh performance cachingrust-backed cachethread-safe cachelfu eviction policycache with ttladaptive cache eviction
cachingrust-corethread-safe

More Libraries packages