A typical python app starts with lots of import
s of modules which are not always used. Usually this isn’t a problem. However, if you are writing a commandline-util in Python which should be snappy, every fraction of a second counts. Mercurial, the SCM written in Python, loads its modules on-demand to be snappy. I took their code and packaged it into a separate module demandimport
such that everyone can use it for their own command-line utils.
Its use is simple:
import demandimport; demandimport.enable()
You can find demandimport on github.