[Python-Dev] Reference implementation of an import hook

Noam Raphael noamr at myrealbox.com
Sun Jun 27 08:15:23 EDT 2004


I've sent this question to comp.lang.python and didn't get any response.

Do you know of a reference implementation of an import hook? I mean a
class, written in Python, that imitates Python's default module loading
behaviour. I mean that I would be able to append the class to 
sys.path_hooks, and module loading won't be affected.

I want it so that it would be easy for me to modify it, or subclass it,
for my own needs, while preserving its behaviour. (My situation, if you
are interested, is that in my current setup, modules are loaded from the 
network, which takes a long time. I want to create a caching mechanism 
which will use the local hard disk.)

It seems to me that such an implementation should be added to the 
standard library or at least to the documentation, since it would help 
anyone who would like to write an import hook, and would also help 
clarify Python's import mechanism. If such an implementation doesn't 
exist, I would probably write one anyway, and I would be willing to 
share it, if people want it.

Thank you,
Noam Raphael

More information about the Python-Dev mailing list