I would like to have some callback run whenever a particular module is imported. For example (using a fake
This PEP has been withdrawn by its author, as much of the detailed design is no longer valid following the migration to importlib in Python 3.3.
wrapt module provides an implementation of this.
Watch this video about
wrapt, including this feature:
Don't think the documentation for
wrapt mentions it yet.
Some of the blogs posts at end of:
talk about it though.
There is a companion module for
autowrapt which allows you to do monkey patching using this mechanism without needing to change the application code itself to trigger it.