skillfed

lazy-import

A module for lazy loading of Python modules

lazy-import v0.2.2 92.0K downloads/30d#13,490 on PyPI88
Copyleft license GPL Abandoned released

What it is and what it does

lazy_import provides functions to defer the loading of Python modules and callables until they are actually used. Instead of importing a module immediately, you register it as lazy, and the actual import and initialization happen only when you access an attribute or call the function. This is useful for optional dependencies that have heavy loading times or memory footprints—you pay the cost only if the module is needed.

The package works by wrapping modules and callables without using import hooks, so it has minimal impact on other code in the same session. When a lazy module is registered in sys.modules, any subsequent import of that module in the same session gets the lazy version until it is fully loaded. Once an attribute is accessed, the module loads in place and behaves like a normal module thereafter.

Use it for:

  • Reduce startup time in CLI tools or servers that load heavy optional libraries like numpy or scipy only in certain code paths.
  • Delay ImportError for missing optional dependencies until they are actually needed, allowing graceful fallback or user-friendly error messages.
  • Defer initialization of large machine-learning or scientific libraries in applications where they may not be used in every execution.
  • Mark optional submodules as lazy at package initialization so downstream code can import them normally while they remain lazy.
  • Wrap callable functions to defer their module loading until the function is actually invoked.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Defers module loading and ImportErrors until a module or callable is actually used, avoiding initialization costs for optional dependencies.

No. The package is abandoned (last updated January 2018, no commits since July 2023) and targets Python 2.7 and early Python 3 versions. Compatibility with modern Python is uncertain. The GPLv3 copyleft license restricts use in proprietary projects. Unless you are maintaining legacy Python 2.7 code or have specific compatibility constraints, modern alternatives or native Python features (e.g., importlib, __getattr__ on modules) are safer choices.

Install

lazy-import on PyPI

pip

pip install lazy-import

uv

uv add lazy-import

poetry

poetry add lazy-import

Installing lazy-import

Before you install

Installation friction is high and maintenance is abandoned: the package has not been updated since January 2018 and the repository shows no recent activity. It targets Python 2.7 and early Python 3 versions, which may cause compatibility issues with modern Python environments.

License in practice

Released under GPL v3 (copyleft). Any code that imports lazy_import must be compatible with GPLv3 terms; proprietary or incompatibly-licensed projects cannot use it without legal review.

Quickstart

import lazy_import
np = lazy_import.lazy_module("numpy")
# numpy loads only when np.pi or another attribute is accessed
np.pi  # triggers full loading

Package targets Python 2.7 and Python 3.3–3.6; compatibility with Python 3.7+ is not explicitly stated and may require testing.

Verify before relying

  • Whether lazy_import works reliably with Python 3.7 and later versions despite the lack of recent updates.
  • Real-world performance gains in typical application scenarios compared to standard imports.
  • Interaction with modern import systems (e.g., namespace packages, PEP 420) not documented in the excerpt.

Package facts

License GPL (copyleft)
Python support not specified
Install friction high — source build required
Runtime dependencies none
Maintenance abandoned — 3,126 days since the last release
Last repo commit
First released
Downloads 92,001/month — #13,490 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: lazy_import-0.2.2.tar.gz

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)Operating System :: OS IndependentProgramming Language :: Python :: 2Programming Language :: Python :: 2.7Programming Language :: Python :: 3Programming Language :: Python :: 3.3Programming Language :: Python :: 3.4Programming Language :: Python :: 3.5Programming Language :: Python :: 3.6Topic :: Software Development :: Libraries :: Python Modules

Tags

lazy module loadingdefer import errorsoptional dependency loadingdelay module initializationlazy callable wrapperconditional importperformance optimization imports
import-optimizationlazy-loadinglegacy-python

More Python Modules packages