importlib - A pure Python implementation of import.
| Use Case | Command | Description |
|---|---|---|
| π₯ Import a module | importlib.import_module('name') | Import a module by name, returns the module. |
| π Relative import | importlib.import_module('..submod', package=__name__) | Perform a relative import from a package. |
| π Reload a module | importlib.reload(module) | Reload an already imported module. |
| π§Ή Invalidate caches | importlib.invalidate_caches() | Clear finder caches stored in sys.meta_path. |
| π οΈ Lowβlevel import | importlib.__import__('name', globals, locals, fromlist, level) | Full control over import mechanics. |
https://docs.python.org/3.10/library/importlib.html
The following documentation is automatically generated from the Python source files. It may be incomplete, incorrect or include features that are considered implementation detail and may vary between Python implementations. When in doubt, consult the module reference at the location listed above.
__import__(name, globals=None, locals=None, fromlist=(), level=0) β Import a module. The 'globals' argument is used to infer where the import is occurring from to handle relative imports. The 'locals' argument is ignored. The 'fromlist' argument specifies what should exist as attributes on the module being imported (e.g. from module import <fromlist>). The 'level' argument represents the package location to import from in a relative import (e.g. from ..pkg import mod would have a 'level' of 2).import_module(name, package=None) β Import a module. The 'package' argument is required when performing a relative import. It specifies the package to use as the anchor point from which to resolve the relative import to an absolute import.invalidate_caches() β Call the invalidate_caches() method on all meta path finders stored in sys.meta_path (where implemented).reload(module) β Reload the module and return it. The module must have been successfully imported before.__all__ = ['__import__', 'import_module', 'invalidate_caches', 'reload', ...]
/usr/lib/python3.10/importlib/__init__.py
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 13:14 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format