methodtools
Expand standard functools to methods
What it is and what it does
methodtools extends Python's standard functools module to handle caching on methods, classmethods, and staticmethods—scenarios where functools.lru_cache does not work as expected. The core feature is lru_cache, a decorator that caches function results but respects the lifetime semantics of different callable types: instance methods cache per object, classmethods and staticmethods cache per class, and regular functions cache globally.
The package solves a real problem: functools.lru_cache treats bound methods as distinct on each access, defeating the cache. methodtools detects the callable type and manages cache storage accordingly. It supports Python 2.7 through 3.11 and has no runtime dependencies, making it a lightweight drop-in replacement for functools when you need method caching.
Use it for:
- Cache expensive computations in instance methods where results depend on object state but should persist across calls.
- Cache class-level computations (e.g., configuration parsing) that should be shared across all instances.
- Cache pure utility functions defined as staticmethods without creating spurious cache misses on each call.
- Migrate code from functools.lru_cache to methodtools when you discover caching is not working on bound methods.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides LRU caching for methods, classmethods, and staticmethods with proper lifetime management tied to instances or classes, extending functools.lru_cache to work correctly on class-bound callables.
Yes, if you need method caching and are not on Python 3.9+. For recent Python versions, verify first whether functools.lru_cache has addressed method caching natively; if not, methodtools is a straightforward, dependency-free solution. Dormant maintenance is acceptable for a stable, narrow-scope utility with no known vulnerabilities.
Install
methodtools on PyPI
pip
pip install methodtoolsuv
uv add methodtoolspoetry
poetry add methodtoolsInstalling methodtools
Before you install
Low friction: pure Python wheel with no runtime dependencies. Dormant maintenance (last release 2023-02-05, last commit 2024-08-23) but repository remains active and unarchived.
License in practice
BSD 2-Clause License (permissive) — you may use, modify, and distribute freely with minimal restrictions; suitable for both open and closed projects.
Quickstart
pip install methodtools
from methodtools import lru_cache
class A:
@lru_cache()
def cached_method(self, x):
return x * 2
Verify before relying
- Whether functools32 is still required or recommended for Python 2 support in modern environments.
- Performance characteristics compared to functools.lru_cache on modern Python versions.
- Whether the package is actively maintained or if functools.lru_cache has since addressed method caching.
Package facts
| License | BSD 2-Clause License (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,286 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 11,178,756/month — #1,412 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: methodtools-0.4.7-py2.py3-none-any.whl
Keywords: ring, functools, lru_cache, method
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
backports.functools-lru-cacheProvides the lru_cache decorator from Python…
permissive · top 5,000 on PyPI
cachetoolsProvides memoizing collections and function…
permissive · top 1,000 on PyPI
cached_methodProvides a method-level caching decorator that…
permissive · top 15,000 on PyPI
memoizationDecorator-based function result caching with…
permissive · top 5,000 on PyPI
asyncacheProvides decorator-based caching for async…
permissive · top 5,000 on PyPI
cachetools-asyncProvides async-aware memoization decorators for…
permissive · top 15,000 on PyPI
functools32Backport of Python 3.2's functools module…
permissive · top 15,000 on PyPI
kleptoklepto provides multiple caching algorithms…
permissive · top 15,000 on PyPI
pytest-antilruClears functools.lru_cache between pytest test…
permissive · top 15,000 on PyPI
fan-toolsA collection of internal testing utilities,…
permissive · top 15,000 on PyPI