--- id: lazy-imports version: "1.2.0" license: Apache-2.0 license_treatment: permissive maintenance: aging --- # lazy-imports — Tool to support lazy imports License: permissive · Maintenance: aging · Downloads: 2.1M/mo ## What it is and what it does lazy-imports is a utility for deferring module attribute loading until they are actually accessed, along with a context manager for optional imports that delay exceptions until use. It wraps Python's import system to avoid loading submodules and their dependencies upfront, which can reduce startup time and memory footprint in large projects. The package provides three main tools: LazyModule for defining lazy attributes in a module's __init__.py (with support for type checking via TYPE_CHECKING), try_import for wrapping optional package imports so exceptions are raised only when the package is actually used, and LazyImporter (a legacy API) for simpler lazy import structures. The fact sheet emphasizes that Python's import system has complex side effects, so lazy imports require careful use in well-structured projects, but the package handles the low-level details so you don't have to. Use it for: - Reduce startup time in CLI tools or services by deferring heavy dependencies until needed. - Support optional features that depend on packages users may not have installed. - Defer import exceptions for optional dependencies to the point where they're actually called. - Minimize memory footprint in large monolithic packages by loading submodules on demand. - Structure package exports with type-checking support while keeping runtime imports lazy. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Defers loading of module attributes and their dependencies until first access, and provides optional imports that delay exceptions until use. Yes, if you need to defer module loading to reduce startup time or memory use. The package is stable (Production/Stable status) with no known vulnerabilities and low install friction. Maintenance is aging (229 days since last release) but the repository remains active. Best suited for projects with heavy dependencies or optional features; requires Python 3.10 or later and careful use in well-structured code. ## Install pip install lazy-imports uv add lazy-imports poetry add lazy-imports ## Installing lazy-imports Before you install: Low install friction with no runtime dependencies. Last release 229 days ago; repository is active and not archived, though maintenance status is aging. License in practice: Apache-2.0 permissive license allows commercial and private use with minimal restrictions. Quickstart: pip install lazy-imports from lazy_imports import LazyModule, as_package, load, module_source load( LazyModule( *as_package(__file__), module_source("._exports", __name__), name=__name__, ) ) Requires Python 3.10 or later. Verify before relying: - Whether lazy modules work correctly with all type checkers (mypy, pyright, etc.) beyond TYPE_CHECKING patterns shown. - Performance gains and memory reduction in real-world applications—fact sheet provides no benchmarks. - Compatibility with dynamic import tools or frameworks that introspect module structure. ## Package facts - License: Apache-2.0 (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 2.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags lazy module loading, defer imports, optional dependencies, reduce import time, conditional imports, lazy attributes, import deferral, import-optimization, performance, optional-deps [View on SkillFed](https://skillfed.io/packages/lazy-imports) · [View on PyPI](https://pypi.org/project/lazy-imports/)