Skip to main content

Help for working with modules.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

A library for working with Python modules.

Module Contents

lazy_import(importer_name, to_import)

Returns the importing module and a callable for lazy importing.

The module named by importer_name represents the module performing the import to help facilitate resolving relative imports.

to_import is an iterable of the modules to be potentially imported. Modules may be specified either as absolute and relative names. The attribute name that the specified module is ultimately bound to is specified in one of two ways. First, the general case is the end of the dotted name of the module is what the attribute name will be, e.g. pkg.mod will be bound to mod on the importer module. Second, the as format of importing is also supported, so one may say, e.g. "pkg.mod as spam" and have pkg.mod bound to the attribute spam on the importer module.

This function returns a tuple of two items. The first is the importer module itself for easy reference within itself. The second item is a callable which is expected to be set to __getattr__ within the importer module to allow for lazy importing. For instance:

mod, __getattr__ = lazy_import(__name__, {'sys', '.submodule',
                                          'importlib.abc as i_abc'})

def func():
    return mod.i_abc.answer == 42

Project details


Download files

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

Source Distribution

modutil-1.0.0.tar.gz (4.2 kB view details)

Uploaded Source

Built Distribution

modutil-1.0.0-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file modutil-1.0.0.tar.gz.

File metadata

  • Download URL: modutil-1.0.0.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for modutil-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8b1205dd4900abe62d2fa126dac18d27b6af5720bb746f1bb6d99c87959a9f31
MD5 7954b350e8221c63fa4e6b28f0c7c1c3
BLAKE2b-256 c5f4b944b16d818eb96858f14e09db2db6fe89fe87c6b0e8225d2465447cefd3

See more details on using hashes here.

File details

Details for the file modutil-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modutil-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c410966aefba16c5faeba05c08bba44499a7aa7f03fcee128ab05aced30f2730
MD5 d75ae980670249c7242fe24e47cb4a1c
BLAKE2b-256 7633a365bfd0f293e5ab6e61f55eb9a2cef92ca4949bf8135b78a625ab965d60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page