lazy-imports
Tool to support lazy imports
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 on this page — 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
lazy-imports on PyPI
pip
pip install lazy-importsuv
uv add lazy-importspoetry
poetry add lazy-importsInstalling 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 the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 229 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,093,769/month — #3,300 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: lazy_imports-1.2.0-py3-none-any.whl
Keywords: import, imports, lazy
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
apipkgapipkg lets you define a package's exported…
permissive · top 5,000 on PyPI
extrasProvides three utility functions—try_import,…
permissive · top 15,000 on PyPI
lazy-loaderLazy-loader defers the import of subpackages…
permissive · top 1,000 on PyPI
lazyasdProvides lazy-loading and self-destructive…
permissive · top 15,000 on PyPI
lazy-importDefers module loading and ImportErrors until a…
copyleft · 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
zope.deferredimportDefers module imports until they are actually…
unclear · top 15,000 on PyPI
LazifyLazify provides lazy evaluation utilities for…
permissive · top 15,000 on PyPI
lazy-object-proxyProvides a proxy object that defers execution…
permissive · top 1,000 on PyPI