{"id":30240458,"url":"https://github.com/yostealth/dynamic-import","last_synced_at":"2025-08-15T04:57:32.752Z","repository":{"id":57424770,"uuid":"143788336","full_name":"YoSTEALTH/Dynamic-Import","owner":"YoSTEALTH","description":"Dynamic or Lazy Import Python Module","archived":false,"fork":false,"pushed_at":"2025-02-12T18:52:35.000Z","size":137,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-12T19:39:40.356Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://pypi.org/project/dynamic-import/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/YoSTEALTH.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-06T22:07:00.000Z","updated_at":"2025-02-12T18:52:39.000Z","dependencies_parsed_at":"2024-01-24T19:45:37.078Z","dependency_job_id":"315c6dd7-7dbf-4678-a304-9c70515e1833","html_url":"https://github.com/YoSTEALTH/Dynamic-Import","commit_stats":{"total_commits":94,"total_committers":2,"mean_commits":47.0,"dds":0.06382978723404253,"last_synced_commit":"cc78c36ce0fb7da50d5cf1317070dfe55bacaec3"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/YoSTEALTH/Dynamic-Import","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoSTEALTH%2FDynamic-Import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoSTEALTH%2FDynamic-Import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoSTEALTH%2FDynamic-Import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoSTEALTH%2FDynamic-Import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/YoSTEALTH","download_url":"https://codeload.github.com/YoSTEALTH/Dynamic-Import/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/YoSTEALTH%2FDynamic-Import/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270524606,"owners_count":24600205,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-08-15T04:57:30.144Z","updated_at":"2025-08-15T04:57:32.739Z","avatar_url":"https://github.com/YoSTEALTH.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|test-status| |downloads|\n\nDynamic Import\n==============\n\nLet Dynamic Import handle your projects(package) import needs. Enables you to dynamically(lazily)\nimport module as needed within the project and for external usage on run-time.\n\n* Place ``importer()`` into top ``__init__.py`` file and forget about where\n  variable, function, class, ... are located.\n* Just call ``from \u003cpackage\u003e import \u003cvariable\u003e`` while coding and when end-user calls from your\n  project. All names are accessible at top level, easy to remember.\n* Move/rename file within your project? No problem, auto updates. \n* Supports ``.py`` and ``.so`` (experimental)\n* Saves memory(for medium to large projects).\n\nUltimate worry free management comfort as your project grows from small to large.\n\n\nRequires\n--------\n\n    - Python 3.8+\n    - Linux, MacOS\n\n\nInstall, update \u0026 uninstall\n---------------------------\n\nUse `pip`_ to:\n\n.. code-block:: bash\n\n    python3 -m pip install dynamic-import            # install\n\n    python3 -m pip install --upgrade dynamic-import  # update\n\n    python3 -m pip uninstall dynamic-import          # uninstall\n\n\nInstall directly from GitHub\n____________________________\n\n\n.. code-block:: bash\n\n    python3 -m pip install --upgrade git+https://github.com/YoSTEALTH/Dynamic-Import\n\n\nUsage\n-----\n\n.. code-block:: python\n\n    # ./\u003cpackage\u003e/__init__.py\n    from dynamic_import import importer\n\n    importer()\n\n\n``importer()`` options\n______________________\n\n\n.. code-block:: python\n\n    importer(cache=False)  # disable \u0026 remove cache file (for temporary use only!)\n\n    importer(recursive=False)  # do not scan sub-directories\n\n    # exclude `.py, .so` file\n    importer(exclude_file='file.py')                          # single\n    importer(exclude_file=('one.py', 'sub-dir/two.py', ...))  # multiple\n\n    # exclude sub-directory\n    importer(exclude_dir='sub-dir')                        # single\n    importer(exclude_dir=('sub-dir', 'sub/sub-dir', ...))  # multiple\n\n\nExample\n-------\n\n.. code-block:: python\n\n    # ./example/pkg/__init__.py\n    from dynamic_import import importer\n\n\n    __version__ = '1.2.3'  # if need to use special name place it above `importer()`\n\n    importer()  # only need to call `importer()` once inside main `__init__.py` file.\n\n    # note: `importer()` will scan all package directory and sub-directories for `.py, .so`\n    # files and cache import names for dynamic use.\n\n\n.. code-block:: python\n\n    # ./example/pkg/var.py\n    import sys\n\n    # just like normal import if `__all__` is not defined, `my_var` will be included.\n    # Also `sys` will not be included.\n\n    my_var = sys.version_info.major\n\n\n.. code-block:: python\n\n    # ./example/pkg/functions/myfunction.py\n    from pkg import my_var\n    # all import names are available at higher level, \n    # no need for `from ..example.var import my_var`\n\n    __all__ = 'my_function'  # using just string for single name is ok\n\n\n    def my_function():\n        return my_var + 1\n\n\n.. code-block:: python\n\n    # ./example/classes/__init__.py\n\n    __all__ = ['MyClass']\n\n\n    class MyClass:\n        pass\n\n\nCalling\n_______\n\n\n.. code-block:: python\n\n    # ./example/calling.py\n    # import all 3 names regardless of where module is located\n    from pkg import my_var, my_function, MyClass\n\n    # or \n    import pkg\n\n    MyClass()\n    print(my_var, pkg.my_var is my_var) # 3 True\n    print(my_function())                # 4\n    print(dir(pkg))                     # ['my_var', 'my_function', 'MyClass', ...]\n\n\nNote\n----\n    - Only need to call ``importer()`` once inside ``__init__.py`` file.\n    - All sub-directories will be scanned for ``.py, .so`` file as ``recursive=True`` by default.\n    - Use ``exclude_dir`` to list sub-directories you would like to avoid scanning.\n    - You can still use normal static/relative import.\n    - For one word import name you can use string\n      e.g. ``__all__ = 'function'`` vs ``__all__ = ('function',)``\n    - All import names must be unique.\n    - Cache can be disabled \u0026 removed by using ``importer(cache=False)``\n    - Cached temporary files are stored in ``./__pycache__/__init__.importer-\u003cpython-version\u003e.pyc``\n    - You can move or rename any ``.py`` file within project directory or sub-directory and \n      import will not break.\n    - Special name e.g: ``__something__`` are ignored. If need to use special name place it \n      above ``importer()`` e.g.``__version__ = '1.2.3'; importer()``\n    - Using ``from \u003cpackage\u003e import *`` is not recommended unless you want to load all the modules.\n    - No need to have empty ``__init__.py`` inside sub-directories. Its \"like\" Namespace + Package\n      combined into one! but not technically.\n    - Calling ``dir(\u003cpackage\u003e)`` enables you to show all importable names without loading modules.\n\n\nExperimental\n------------\n    - Having module name and function name the same is ok! e.g. ``from pkg import my_fun`` while\n      ``./pkg/my_fun.py`` and calling ``my_fun()`` will not conflict with module name. Module will\n      still load in the background.\n    - ``importer()`` also works with certain ``.cpython-\u003c...\u003e.so`` ``.abi3.so`` file\n      (only tested with cython created ``*.so``).\n    - ``.so`` should not contain any function/class that auto-run on import e.g.``run_something()``\n    - Visit `Liburing`_ to see project using Dynamic Import with ``.so`` files in action.\n\n\nLicense\n-------\nFree, Public Domain (CC0). `Read more`_\n\n.. _pip: https://pip.pypa.io/en/stable/getting-started/\n.. _Read more: https://github.com/YoSTEALTH/Dynamic-Import/blob/master/LICENSE.txt\n.. _Liburing: https://github.com/YoSTEALTH/Liburing\n.. |test-status| image:: https://github.com/yostealth/dynamic-import/actions/workflows/test.yml/badge.svg?branch=master\u0026event=push\n    :target: https://github.com/yostealth/dynamic-import/actions/workflows/test.yml\n    :alt: Test status\n.. |downloads| image:: https://img.shields.io/pypi/dm/dynamic_import\n   :alt: PyPI - Downloads\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyostealth%2Fdynamic-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyostealth%2Fdynamic-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyostealth%2Fdynamic-import/lists"}