skillfed

methodtools

Expand standard functools to methods

methodtools v0.4.7 11.2M downloads/30d#1,412 on PyPI85
Permissive license BSD 2-Clause License DORMANT released

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 methodtools

uv

uv add methodtools

poetry

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

License :: OSI Approved :: BSD LicenseProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

lru cache for methodsfunctools for class methodsmethod caching decoratorcache instance methodsclassmethod cachingstaticmethod cachingmethod memoization
cachingfunctools-extension

More Software Development packages