https://github.com/bwesterb/py-demandimport
Lazy import python modules for low start-up time. (Taken from mercurial.)
https://github.com/bwesterb/py-demandimport
lazy python
Last synced: 11 months ago
JSON representation
Lazy import python modules for low start-up time. (Taken from mercurial.)
- Host: GitHub
- URL: https://github.com/bwesterb/py-demandimport
- Owner: bwesterb
- License: gpl-2.0
- Created: 2013-04-28T14:38:46.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2024-07-15T10:56:04.000Z (almost 2 years ago)
- Last Synced: 2025-06-29T22:16:08.463Z (about 1 year ago)
- Topics: lazy, python
- Language: Python
- Homepage:
- Size: 39.1 KB
- Stars: 50
- Watchers: 3
- Forks: 8
- Open Issues: 5
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
demandimport
************
Delays loading of modules until they are actually used. Perfect for Python
apps that need to be snappy like command-line utils. Source-code derived
from mercurial.
To enable, write
.. code:: python
import demandimport; demandimport.enable()
Imports of the following form will be delayed
.. code:: python
import a, b.c
import a.b as c
from a import b, c # a will be loaded immediately, though
These imports with not be delayed
.. code:: python
from a import *
b = __import__(a)
Delayed loading will confuse some third-party modules. In that case you
can disable the delay for just that module. For example
.. code:: python
demandimport.ignore('Crypto.PublicKey._fastmath')
There are also versions that can be used with ``with``
.. code:: python
with demandimport.enabled():
# do something
with demandimport.disabled():
import troublesome.module
with demandimport.ignored('test'):
import other.troublemaker
Installation
============
To install ``demandimport``, simply run::
pip install demandimport
Attribution
===========
Olivia Mackall is the original author of the module in
Mercurial on which this module is based. Bas Westerbaan
maintains it now.