If it can be of any help, I recently released a Python library named Gorilla to make the process of monkey patching more convenient.
Using a function needle()
to patch a module named guineapig
goes as follows:
import gorilla
import guineapig
@gorilla.patch(guineapig)
def needle():
print("awesome")
But it also takes care of more interesting use cases as shown in the FAQ from the documentation.
The code is available on GitHub.