skillfed

backports.functools-lru-cache

Backport of functools.lru_cache

backports-functools-lru-cache v2.0.0 1.7M downloads/30d#3,635 on PyPI37
Permissive license Active released

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

uv

uv add backports-functools-lru-cache

poetry

poetry add backports-functools-lru-cache

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3

Tags

lru cache decoratorfunction memoizationfunctools backportleast recently used cachepython 3.3 functoolscache decorator importbackport compatibility
cachingcompatibility

More Software Development packages