lazy-import
A module for lazy loading of Python modules
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-importuv
uv add lazy-importpoetry
poetry add lazy-importInstalling 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
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
lazy-loaderLazy-loader defers the import of subpackages…
permissive · top 1,000 on PyPI
lazy-importsDefers loading of module attributes and their…
permissive · top 5,000 on PyPI
lazyasdProvides lazy-loading and self-destructive…
permissive · top 15,000 on PyPI
LazifyLazify provides lazy evaluation utilities for…
permissive · top 15,000 on PyPI
sliceratorSlicerator wraps a class's `__getitem__` method…
permissive · top 15,000 on PyPI
proxy_toolsProvides a lazy-evaluation proxy object that…
permissive · top 5,000 on PyPI
lazyProvides a @lazy decorator that defers…
permissive · top 15,000 on PyPI
lmllml provides a lazy plugin management system…
permissive · top 5,000 on PyPI
lazy-modelLazy-model provides on-demand field parsing for…
permissive · top 5,000 on PyPI
xmodLets a module behave like a callable object or…
permissive · top 5,000 on PyPI