python-monkey-business is a Python package offering utility functions for monkey-patching code at runtime. It primarily provides a decorator to replace functions within classes or modules. The current version is 1.1.0, with the latest package upload on PyPI on July 11, 2024, though the project appears to have a very infrequent release cadence.
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.024s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.023s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Typically used as a decorator: @monkeybiz.patch(...)
from monkeybiz import patch
Used to revert a monkey-patched function to its original state.
from monkeybiz import unpatch
Demonstrates how to use the `monkeybiz.patch` decorator to replace a method within a class and how to revert the patch using `monkeybiz.unpatch`.
import monkeybiz
# Assume 'foomodule' and 'FooClass' exist for demonstration
class FooClass:
def bar(self):
return "original"
# Patch a method in a class
@monkeybiz.patch(FooClass)
def bar(original_fn, *args, **kwargs):
print("Patched!")
return "patched_" + original_fn(*args, **kwargs)
instance = FooClass()
print(instance.bar()) # Should print 'Patched!' and 'patched_original'
monkeybiz.unpatch(FooClass, 'bar')
print(instance.bar()) # Should print 'original' again
# Example of patching a module-level function (requires a dummy module)
# import sys
# class DummyModule:
# def baz(): return 'original_module_baz'
# sys.modules['barmodule'] = DummyModule()
# import barmodule
#
# @monkeybiz.patch(barmodule)
# def baz(original_fn, *args, **kwargs):
# return 'patched_' + original_fn(*args, **kwargs)
#
# print(barmodule.baz()) # Should print 'patched_original_module_baz'
# monkeybiz.unpatch(barmodule, 'baz')
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.