Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Utility functions for monkey-patching python code

Project Description


python-monkey-business is a package that provides a decorator for monkey-patching python functions at runtime.


Using pip:

pip install python-monkey-business

Or, to install from source:

pip install -e git+

If the source is already checked out, use setuptools:

python develop


To use python-monkey-business to swap out a function in a class or module at runtime:

import monkeybiz

from foomodule import FooClass
import barmodule

# This replaces with our method
def bar(original_fn, *args, **kwargs):
    print "Patched!"
    return original_fn(*args, **kwargs)

# This replaces barmodule.baz with our function
def baz(original_fn, *args, **kwargs):

The first argument to monkeybiz.patch can be either a module, a class, or a list of modules and/or classes. The decorator also takes optional name and avoid_doublewrap keyword arguments. If name is omitted, the name of the function being patched will be the name of the function being decorated. If avoid_doublewrap is True (the default), then functions and methods can only be patched once using this function.

Use monkeybiz.unpatch() to revert a monkey-patched function to its original.


This code is licensed under the Simplified BSD License. View the LICENSE file under the root directory for complete license and copyright information.

Release History

This version
History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(5.5 kB) Copy SHA256 Hash SHA256
Wheel 2.7 Mar 22, 2016
(4.0 kB) Copy SHA256 Hash SHA256
Source None Mar 22, 2016

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Kabu Creative Kabu Creative UX & Design Google Google Cloud Servers Fastly Fastly CDN StatusPage StatusPage Statuspage DigiCert DigiCert EV Certificate