--- id: lazy-import version: "0.2.2" license: GPL license_treatment: copyleft maintenance: abandoned --- # lazy-import — A module for lazy loading of Python modules License: copyleft · Maintenance: abandoned · Downloads: 92.0K/mo ## 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 above — 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 pip install lazy-import uv add lazy-import 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: unspecified - Install friction: high - Maintenance: abandoned - Downloads: 92.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags lazy module loading, defer import errors, optional dependency loading, delay module initialization, lazy callable wrapper, conditional import, performance optimization imports, import-optimization, lazy-loading, legacy-python [View on SkillFed](https://skillfed.io/packages/lazy-import) · [View on PyPI](https://pypi.org/project/lazy-import/)