backports.functools-lru-cache
Backport of functools.lru_cache
What it is and what it does
This package backports the lru_cache decorator from Python 3.3's functools module, allowing developers to use function result caching via a simple decorator on Python versions that lack it. The decorator caches function results based on input arguments, avoiding redundant computation for repeated calls with the same parameters.
The package is designed for compatibility scenarios where code must run on Python versions predating lru_cache's introduction. It follows the standard import-fallback pattern: code attempts to import from the standard library first, then falls back to this backport if unavailable. With zero runtime dependencies and a permissive MIT license, it introduces minimal overhead to any project that includes it.
Use it for:
- Caching expensive computations (database queries, API calls, mathematical calculations) in long-running applications.
- Providing function result caching in libraries that must support multiple Python versions via a single import.
- Optimizing recursive algorithms by caching intermediate results to reduce redundant computation.
- Reducing redundant I/O operations in utilities that repeatedly call the same function with overlapping parameters.
- Ensuring consistent behavior across codebases that target both older and modern Python versions.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides the lru_cache decorator from Python 3.3's functools module for Python environments that lack it natively.
Yes, if you need function caching and must support Python versions before 3.2, or if you want a single import pattern across multiple Python versions. However, verify whether your actual minimum Python version truly requires this backport—Python 3.8+ already includes functools.lru_cache natively, making this package redundant for most modern codebases.
Install
backports-functools-lru-cache on PyPI
pip
pip install backports-functools-lru-cacheuv
uv add backports-functools-lru-cachepoetry
poetry add backports-functools-lru-cacheInstalling backports.functools-lru-cache
Before you install
Low install friction with a single pure-Python wheel dependency. Actively maintained as of 2026-04-13 with stable production status.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects.
Quickstart
pip install backports.functools-lru-cache
try:
from functools import lru_cache
except ImportError:
from backports.functools_lru_cache import lru_cache
Requires Python 3.8 or later.
Verify before relying
- Whether this backport is still necessary given the stated Python 3.8+ requirement, since functools.lru_cache has been available since Python 3.2.
- Specific use cases where the standard library version is unavailable despite meeting the Python 3.8+ minimum.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 975 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,705,926/month — #3,635 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: backports.functools_lru_cache-2.0.0-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
functools32Backport of Python 3.2's functools module…
permissive · top 15,000 on PyPI
methodtoolsProvides LRU caching for methods, classmethods,…
permissive · top 5,000 on PyPI
pytest-antilruClears functools.lru_cache between pytest test…
permissive · top 15,000 on PyPI
async-lruAn LRU cache decorator for async functions that…
permissive · top 1,000 on PyPI
pylruProvides a pure-Python LRU (least recently…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
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
backports.cached-propertyProvides the cached_property decorator for…
permissive · top 15,000 on PyPI
lru-dictA fast C-based LRU (Least Recently Used) dict…
permissive · top 5,000 on PyPI