skillfed

weakrefmethod

A WeakMethod class for storing bound methods using weak references.

weakrefmethod v1.0.3 74.0K downloads/30d#14,899 on PyPI3
Permissive license PSF AGING released

What it is and what it does

WeakMethod is a utility for storing references to bound methods without preventing their parent object from being garbage collected. This package backports Python 3.4's standard library WeakMethod class to Python 2.6 and 2.7, allowing developers on those older versions to use weak method references in their code.

The package has no runtime dependencies and is a pure-Python implementation. However, it targets Python versions that are no longer actively maintained. Installing this package makes sense only if you are maintaining legacy Python 2 code that specifically needs weak method storage.

Use it for:

  • Prevent memory leaks in Python 2 code by storing weak references to bound methods instead of strong references
  • Implement observer patterns or event handlers in Python 2 that don't keep objects alive
  • Maintain legacy Python 2.6 or 2.7 projects that require weak method references without reimplementing the logic

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides a WeakMethod class for storing bound methods using weak references, backported to Python 2.6 and 2.7 from Python 3.4's standard library.

No, unless you are actively maintaining Python 2.6 or 2.7 code. The package is unmaintained (last release 2016-07-18), and modern Python versions include WeakMethod in the standard library. For any new or current projects, use the built-in weakref.WeakMethod instead.

Install

weakrefmethod on PyPI

pip

pip install weakrefmethod

uv

uv add weakrefmethod

poetry

poetry add weakrefmethod

Installing weakrefmethod

Before you install

High install friction due to source distribution only. The package is aging—last release in 2016, no updates since then—and targets Python 2.6 and 2.7, which are long out of support.

License in practice

Licensed under the Python Software Foundation License (permissive). No restrictions on use, modification, or distribution in your own code.

Quickstart

pip install weakrefmethod

from weakrefmethod import WeakMethod

class MyClass:
    def method(self):
        pass

obj = MyClass()
weak_method = WeakMethod(obj.method)

Package targets Python 2.6 and 2.7, which are no longer supported. WeakMethod is available in the standard library for Python 3.4 and later.

Verify before relying

  • Whether this package actually works on modern Python versions despite targeting only Python 2.6–2.7
  • Whether any real-world projects still depend on this backport or if it is purely historical
  • Current status of Python 2 support in production environments

Package facts

License PSF (permissive)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance aging — 3,679 days since the last release
Last repo commit
First released
Downloads 73,952/month — #14,899 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: weakrefmethod-1.0.3.tar.gz

Keywords: weakref, WeakMethod

Development Status :: 3 - AlphaEnvironment :: ConsoleIntended Audience :: DevelopersLicense :: OSI Approved :: Python Software Foundation LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2.6Programming Language :: Python :: 2.7Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

weak references bound methodsweakref WeakMethod backportweak method storage python 2garbage collection bound methodsweakref memory management
python-2-legacymemory-management

More Libraries packages