skillfed

mo-imports

More Imports! - Delayed importing

mo-imports v7.685.25166 335.8K downloads/30d#7,472 on PyPI2
Copyleft license MPL 2.0 AGING released

What it is and what it does

mo-imports solves the problem of circular module dependencies by providing two main patterns: expect/export for explicit cycle breaking, and delay_import for lazy loading. When modules import each other at the top level, Python can fail or produce incomplete initialization. This package lets you declare expected names upfront (expect) and fulfill them later (export), or defer imports until first use (delay_import), keeping all imports visible at the top of files rather than scattered inline or at the bottom.

The package depends only on mo-future and installs as a pure Python wheel with no compiled dependencies. It targets Python 3.9 through 3.13 and has been maintained since 2020, though releases have slowed. The expect/export pattern is the recommended approach for most cycles; delay_import is simpler but requires the imported name to be called or accessed to trigger loading, so it cannot be used for sentinel values or default arguments.

Use it for:

  • Break circular imports in modular libraries where two or more modules need to reference each other's functions or classes.
  • Defer expensive imports (e.g., heavy data science or ML libraries) until they are actually used in a function.
  • Maintain clean import organization at the top of files while resolving cycles that would otherwise require inline or end-of-file imports.
  • Verify at module load time that all expected names are exported, catching configuration errors early rather than at runtime.
  • Refactor monolithic code into separate modules without restructuring to avoid cycles or keeping code in a single file.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides patterns to resolve circular module dependencies in Python through delayed imports and expect/export mechanisms, keeping imports at the top of files while breaking cycles.

Yes, if you have circular dependencies in a modular codebase. The expect/export pattern is cleaner and more maintainable than inline imports or end-of-file imports, and the package is stable with low friction. The aging maintenance status (last release 425 days ago) is a minor concern for a mature utility, but check whether the pattern fits your use case—delay_import has limitations for non-callable values.

Install

mo-imports on PyPI

pip

pip install mo-imports

uv

uv add mo-imports

poetry

poetry add mo-imports

Installing mo-imports

Before you install

Low install friction with a single lightweight dependency (mo-future). Maintenance is aging—last release was 425 days ago, though the repository remains active and the package has been stable since its 2020 initial release.

License in practice

Licensed under MPL 2.0 (copyleft). You must disclose source code modifications and distribute under the same license if you modify and redistribute the package, but can use it in proprietary applications without disclosing your own code.

Quickstart

# Install
pip install mo-imports

# Use expect/export pattern to break cycles
# foos.py
from mo_imports import expect
bar = expect("bar")

# bars.py
from mo_imports import export
export("bars", bar)

Verify before relying

  • Whether delay_import() works correctly with type checkers and IDE autocompletion
  • Performance overhead of expect/export pattern at scale with many circular dependencies
  • Compatibility with dynamic import systems or import hooks beyond standard Python imports

Package facts

License MPL 2.0 (copyleft)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — mo-future
Maintenance aging — 425 days since the last release
Last repo commit
First released
Downloads 335,768/month — #7,472 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: mo_imports-7.685.25166-py3-none-any.whl

Development Status :: 4 - BetaLicense :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python Modules

Tags

circular dependency resolutiondelayed import proxycyclic module importsexpect export patternlate binding importsmodule cycle breakingdeferred import loading
module-organizationimport-cycles

More Libraries packages