wrapt

raw JSON →
2.1.2 verified Tue May 12 auth: no python install: verified quickstart: verified

wrapt is a Python module designed for decorators, wrappers, and monkey patching. It emphasizes correctness and transparency, ensuring that decorators preserve introspectability and function signatures. The current version is 2.1.2, with a release cadence that reflects active maintenance and updates.

pip install wrapt
breaking In Python 3.13, the behavior of @classmethod.__get__() was reverted to its pre-3.9 state, affecting decorators applied inside @classmethod.
fix Apply decorators outside of @classmethod to ensure correct behavior.
gotcha Using a decorated class with super() requires accessing the original wrapped class to avoid issues.
fix Use super(OriginalClass, self).__init__() instead of super().__init__() within decorated classes.
gotcha Deriving from a decorated class necessitates using the original wrapped class as the base to prevent inheritance issues.
fix Use Base.__wrapped__ as the base class when deriving from a decorated class.
gotcha Using issubclass() on abstract classes decorated with wrapt can raise TypeError due to Python's handling of abstract base classes.
fix Avoid using issubclass() on decorated abstract classes or access the original class using __wrapped__.
gotcha Uninstalling wrapt improperly can lead to Python runtime errors, especially if other packages depend on it.
fix Ensure wrapt is reinstalled correctly if uninstallation causes issues, particularly when other packages rely on it.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.12s 18.3M
3.10 slim (glibc) - - 0.08s 19M
3.11 alpine (musl) - - 0.17s 20.2M
3.11 slim (glibc) - - 0.14s 21M
3.12 alpine (musl) - - 0.14s 12.1M
3.12 slim (glibc) - - 0.13s 13M
3.13 alpine (musl) - - 0.09s 11.7M
3.13 slim (glibc) - - 0.09s 12M
3.9 alpine (musl) - - 0.06s 17.8M
3.9 slim (glibc) - - 0.05s 18M

This example demonstrates creating a simple pass-through decorator using wrapt.

import wrapt

@wrapt.decorator
def pass_through(wrapped, instance, args, kwargs):
    return wrapped(*args, **kwargs)

@pass_through
def function():
    print("Function executed")

function()