--- id: theine version: "2.0.0" license: BSD-3-Clause license_treatment: permissive maintenance: aging --- # theine — high performance in-memory cache License: permissive · Maintenance: aging · Downloads: 144.3K/mo ## 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 above — 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 pip install theine uv add theine 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_current - Install friction: low - Maintenance: aging - Downloads: 144.3K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags in-memory cache python, high performance caching, rust-backed cache, thread-safe cache, lfu eviction policy, cache with ttl, adaptive cache eviction, caching, rust-core, thread-safe [View on SkillFed](https://skillfed.io/packages/theine) · [View on PyPI](https://pypi.org/project/theine/)