{"library":"mo-imports","title":"More Imports! - Delayed importing","description":"mo-imports is a Python library designed to simplify and manage complex import patterns, especially those involving cyclic dependencies. It provides mechanisms like 'expect/export' and 'delay_import' to make late importing cleaner and avoid common Python import pitfalls. The library is currently in a beta development status, with version 7.685.25166 released on June 15, 2025, and generally follows a frequent release schedule.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install mo-imports"],"cli":null},"imports":["from mo_imports import expect","from mo_imports import export","from mo_imports import delay_import"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\n\n# Example for breaking cyclic dependencies with expect/export\n# File: foos.py\n# from mo_imports import expect\n# bar = expect(\"bar\")\n# def foo():\n#     return bar() + \" from foo\"\n#\n# File: bars.py\n# from mo_imports import export\n# from foos import foo\n# def bar():\n#    return foo() + \" from bar\"\n# export(\"bar\", bar)\n\n# Simulating the usage (actual usage requires separate files)\n# To demonstrate, imagine 'foos.py' defines 'bar' as expect('bar')\n# and 'bars.py' defines 'bar' and then export('bar', bar)\n\n# Example for delayed import\n# File: lazy_module.py\n# def some_function():\n#     return \"Function from lazy_module\"\n\n# File: main_app.py\nfrom mo_imports import delay_import\n\n# Instead of: from lazy_module import some_function\n# We use delay_import:\nlazy_function = delay_import(\"lazy_module.some_function\")\n\nprint(f\"Initial state: {lazy_function}\") # This is a proxy object, not the actual function yet\n\n# The import happens when lazy_function is first 'used'\n# For a function, this means when it's called.\ntry:\n    result = lazy_function()\n    print(f\"Result from delayed import: {result}\")\nexcept ImportError as e:\n    print(f\"Caught expected ImportError: {e}\")\n    print(\"Note: For this example to run correctly, 'lazy_module.py' must exist in the Python path.\")\n\n# For demonstration, let's create a dummy lazy_module.py temporarily\nwith open('lazy_module.py', 'w') as f:\n    f.write('def some_function():\\n    return \"Function from lazy_module\"\\n')\n\n# Rerun the delayed import to show it working\nimport sys\n# Remove from sys.modules to force re-import if it was loaded before\nif 'lazy_module' in sys.modules:\n    del sys.modules['lazy_module']\n\nlazy_function_working = delay_import(\"lazy_module.some_function\")\nprint(f\"Result from delayed import after creating file: {lazy_function_working()}\")\n\n# Clean up the dummy file\nos.remove('lazy_module.py')\n","lang":"python","description":"The `mo-imports` library offers two primary patterns: `expect`/`export` for breaking cyclic dependencies and `delay_import` for deferring module loading until the first access. The `delay_import` example demonstrates how a module's content is loaded only when its components are first invoked, leading to cleaner code and potentially faster startup times if imports are expensive and not always used.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"7.685.25166","pypi_latest":"7.685.25166","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.6,"avg_import_s":0.07,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.09,"mem_mb":2,"disk_size":"17.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.08,"mem_mb":2,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.09,"mem_mb":1.9,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.6,"import_time_s":0.08,"mem_mb":1.9,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.06,"mem_mb":1.4,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.06,"mem_mb":1.4,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.06,"mem_mb":1.8,"disk_size":"11.4M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.5,"import_time_s":0.07,"mem_mb":1.6,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.04,"mem_mb":2,"disk_size":"17.4M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"mo-imports","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":1.8,"import_time_s":0.04,"mem_mb":2,"disk_size":"18M"}]}}