--- id: backports-weakref version: "1.0.post1" license: Python Software Foundation License license_treatment: permissive maintenance: abandoned --- # backports.weakref — Backport of new features in Python's weakref module License: permissive · Maintenance: abandoned · Downloads: 1.2M/mo ## What it is and what it does This package provides a backport of `weakref.finalize`, a feature added to Python's standard `weakref` module in Python 3.4. The `finalize` class lets you register a callback function to be called when an object is garbage collected, enabling deterministic cleanup of resources tied to that object's lifetime. It is intended only for projects that must support Python 2.7 or early Python 3.x versions (3.4–3.6) and cannot upgrade. On Python 3.4 and later, the standard library's `weakref.finalize` should be used directly. The package has no runtime dependencies and installs cleanly, but has been unmaintained since 2017. Use it for: - Register cleanup code for Python 2.7 projects that need to run finalizers when objects are garbage collected. - Support legacy Python 3.4–3.6 codebases that use `weakref.finalize` but cannot yet upgrade to a newer Python version. - Provide a uniform API across old and new Python versions when backporting code from Python 3.4+. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Backports the `weakref.finalize` class from Python 3.4+ to earlier Python versions, allowing you to register cleanup callbacks for objects when they are garbage collected. Only if you are maintaining code on Python 2.7, 3.4, 3.5, or 3.6 and need `weakref.finalize`. The package is abandoned and unmaintained since 2017, so it should not be used in new projects. On Python 3.4+, use the standard library's `weakref.finalize` directly. No known security vulnerabilities. ## Install pip install backports-weakref uv add backports-weakref poetry add backports-weakref ## Installing backports.weakref Before you install: Installation is straightforward with no runtime dependencies. The package is abandoned as of 2017 with no recent maintenance, so it should only be used if you are stuck on Python 2.7, 3.4, 3.5, or 3.6 and cannot upgrade. License in practice: Licensed under the Python Software Foundation License, a permissive license that allows use in most contexts without restriction. Quickstart: pip install backports.weakref from backports.weakref import finalize class MyClass: pass obj = MyClass() finalize(obj, print, "Object was garbage collected") Only useful on Python 2.7, 3.4, 3.5, or 3.6; on Python 3.4+ you should import `finalize` directly from the standard `weakref` module instead. Verify before relying: - Whether this package is still compatible with modern Python tooling and dependency resolvers despite being abandoned since 2017. ## Package facts - License: Python Software Foundation License (permissive) - Python support: unspecified - Install friction: low - Maintenance: abandoned - Downloads: 1.2M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags weakref finalize backport, python 2.7 weakref finalize, garbage collection callbacks, object cleanup on deletion, weakref module backport, finalize weak references, legacy-python, backport [View on SkillFed](https://skillfed.io/packages/backports-weakref) · [View on PyPI](https://pypi.org/project/backports-weakref/)