skillfed

lru-dict

An Dict like LRU container.

lru-dict v1.4.1 5.9M downloads/30d#2,019 on PyPI284
Permissive license MIT AGING released

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-dict

uv

uv add lru-dict

poetry

poetry add lru-dict

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentOperating System :: POSIXProgramming Language :: CProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTopic :: Software Development :: Libraries :: Python Modules

Tags

lru cache dictleast recently used containerfixed size dict evictionc implementation lrumemory efficient cachelru dict pythonbounded cache container
cachingmemory-boundedc-extension

More Python Modules packages