lru-dict
An Dict like LRU container.
What it is and what it does
lru-dict is a fixed-capacity dictionary-like container implemented in C that automatically evicts the least recently used item when the size limit is exceeded. It provides dict-like access patterns (get, set, delete, iteration) while maintaining insertion and access order, and supports optional callbacks when items are evicted. The main use case is building efficient LRU caches where you need predictable memory bounds and fast lookups without the overhead of pure-Python implementations.
The package trades ease of installation (requires a C compiler or platform-specific wheel) for speed and memory efficiency. It supports runtime capacity changes, introspection of MRU/LRU items, and statistics gathering. With no runtime dependencies and support for Python 3.9 through 3.14, it integrates into most modern Python projects; the aging maintenance status and search for a lead maintainer are the main caveats.
Use it for:
- Build a bounded HTTP response cache that automatically discards stale entries when memory pressure rises.
- Implement a session store with a fixed maximum number of concurrent users, evicting idle sessions automatically.
- Cache expensive database query results with a memory ceiling, ensuring the cache never grows unbounded.
- Speed up repeated computations in data processing pipelines by caching intermediate results with predictable memory use.
- Create a connection pool or resource manager that limits concurrent allocations and recycles the least-used resources.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A fast C-based LRU (Least Recently Used) dict container that evicts the oldest items when a fixed size limit is exceeded, with dict-like access and optional eviction callbacks.
Yes, if you need a fast, bounded cache with predictable memory use and can tolerate a C extension dependency. The MIT license, zero runtime dependencies, and broad platform support make it low-risk. However, the aging maintenance status (285 days since last release, seeking a lead maintainer) means you should verify the project's stability for your use case and be prepared to fork or switch if critical bugs emerge. For most new projects, consider whether a pure-Python alternative or functools.lru_cache suffices first.
Install
lru-dict on PyPI
pip
pip install lru-dictuv
uv add lru-dictpoetry
poetry add lru-dictInstalling lru-dict
Before you install
Medium install friction due to compiled C extension requiring platform-specific wheels; however, wheels are provided for common architectures (x86_64, ARM, PPC64LE) across macOS, Linux, and Windows. Last release was 285 days ago; project is marked stable but seeking a lead maintainer.
License in practice
MIT license permits commercial and private use with minimal restrictions—you may use, modify, and distribute lru-dict freely provided you include the license notice.
Quickstart
pip install lru-dict
from lru import LRU
l = LRU(5) # Create container holding 5 items
l[1] = 'value'
print(l.items()) # Items in MRU order
l.set_size(3) # Resize at runtime; oldest items evicted
Requires Python 3.9 or later; C extension must compile or a pre-built wheel must be available for your platform.
Verify before relying
- Whether the project's search for a lead maintainer signals risk of abandonment or is routine community stewardship.
- Performance characteristics (speed and memory gains) relative to pure-Python LRU implementations in current Python versions.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 285 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,871,723/month — #2,019 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lru_dict-1.4.1-cp310-cp310-macosx_10_9_universal2.whl; lru_dict-1.4.1-cp310-cp310-macosx_10_9_x86_64.whl; lru_dict-1.4.1-cp310-cp310-macosx_11_0_arm64.whl; lru_dict-1.4.1-cp310-cp310-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; lru_dict-1.4.1-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; lru_dict-1.4.1-cp310-cp310-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl; lru_dict-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl; lru_dict-1.4.1-cp310-cp310-musllinux_1_2_ppc64le.whl; lru_dict-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl; lru_dict-1.4.1-cp310-cp310-win32.whl; lru_dict-1.4.1-cp310-cp310-win_amd64.whl; lru_dict-1.4.1-cp311-cp311-macosx_10_9_universal2.whl; lru_dict-1.4.1-cp311-cp311-macosx_10_9_x86_64.whl; lru_dict-1.4.1-cp311-cp311-macosx_11_0_arm64.whl; lru_dict-1.4.1-cp311-cp311-manylinux1_x86_64.manylinux_2_28_x86_64.manylinux_2_5_x86_64.whl; lru_dict-1.4.1-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl; lru_dict-1.4.1-cp311-cp311-manylinux2014_ppc64le.manylinux_2_17_ppc64le.manylinux_2_28_ppc64le.whl; lru_dict-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl; lru_dict-1.4.1-cp311-cp311-musllinux_1_2_ppc64le.whl; lru_dict-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl
Keywords: lru, dict
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
pylruProvides a pure-Python LRU (least recently…
permissive · top 15,000 on PyPI
repoze-lruA lightweight LRU (least recently used) cache…
permissive · top 5,000 on PyPI
cacheoutCacheout provides in-memory caching with…
permissive · top 5,000 on PyPI
circular-dictCircularDict is a Python dictionary that…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
backports.functools-lru-cacheProvides the lru_cache decorator from Python…
permissive · top 5,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
functools32Backport of Python 3.2's functools module…
permissive · top 15,000 on PyPI
boltonsBoltons provides a collection of over 230…
permissive · top 1,000 on PyPI
methodtoolsProvides LRU caching for methods, classmethods,…
permissive · top 5,000 on PyPI