Skip to content

Support for lazy imports #43

@mauvilsa

Description

@mauvilsa

A topic closely related to optional imports are lazy imports. When a package is optional, it commonly happens that even though it is installed, it is not used for some process execution. In these cases, always importing all packages is a waste of resources. Implementing lazy imports can provide "startup time improvements up to 70% and memory-use reductions up to 40% on real-world Python CLIs".

Eventually lazy imports could become a native feature of python, but for the moment there are only long discussions and a rejected PEP 690. Thus, a package that provides it would certainly be welcome.

From my understanding adding lazy imports to generalimport would be relatively easy given what it already does. So I propose to add this as a feature.

Possible implementations

  1. Add a new function lazy_imports() to explicitly make imports lazy.
  2. Modify the existing generalimport() so that imports are always lazy.

Independent from this, from generalimport import generalimport does not look very nice or readable. Might be nicer if it were from generalimport import optional_import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions