--- id: methodtools version: "0.4.7" license: BSD 2-Clause License license_treatment: permissive maintenance: dormant --- # methodtools — Expand standard functools to methods License: permissive · Maintenance: dormant · Downloads: 11.2M/mo ## 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 above — 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 pip install methodtools uv add methodtools poetry add methodtools ## Installing 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 11.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags lru cache for methods, functools for class methods, method caching decorator, cache instance methods, classmethod caching, staticmethod caching, method memoization, caching, functools-extension [View on SkillFed](https://skillfed.io/packages/methodtools) · [View on PyPI](https://pypi.org/project/methodtools/)