Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

On-demand imports, taken from mercurial

Project Description


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

import demandimport; demandimport.enable()

Imports of the following form will be delayed

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

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


There are also versions that can be used with with

with demandimport.enabled():
   # do something
   with demandimport.disabled():
      import troublesome.module
   with demandimport.ignored('test'):
      import other.troublemaker


To install demandimport, simply run:

pip install demandimport


Matt Mackall <> is the original author of the module in Mercurial on which this module is based. Bas Westerbaan <> maintains it now.

py-demandimport Changelog

0.3.4 (2017-06-08)

  • Python 3.6
  • Add sip to the default ignore list. #6

0.3.3 (2016-10-20)

  • Add is_loaded and is_proxy. Thanks-to:

0.3.2 (2015-12-22)

  • Fixed issue #2: import a.b.c will incorrectly try to import b.c

0.3.1 (2015-12-21)

  • Relicense GPL version 2 or later (GPLv2+)

0.3.0 (2015-12-21)

  • Do not delay ImportError in a special case.
  • Add optional logging (for debugging)
  • Fixed issue #1: import a.b in a module a.c was incorrectly executed as a relative import c.
  • Improve thread safety

0.2.2 (2015-12-05)

  • Moved to zest.releaser
  • Add some basic unittests
  • Python 3 support
Release History

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
demandimport-0.3.4.tar.gz (12.9 kB) Copy SHA256 Checksum SHA256 Source Jun 8, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting