skillfed

lazy-imports

Tool to support lazy imports

lazy-imports v1.2.0 2.1M downloads/30d#3,300 on PyPI15
Permissive license Apache-2.0 AGING released

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-imports

uv

uv add lazy-imports

poetry

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 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Software DevelopmentTopic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

lazy module loadingdefer importsoptional dependenciesreduce import timeconditional importslazy attributesimport deferral
import-optimizationperformanceoptional-deps

More Software Development packages