Import and Packaging Modules

importlib.machinery

Exposes standard finder and loader classes, module specifications and recognized file suffixes. A ModuleSpec holds import-related information such as name, loader and origin. Creating a specification does not execute module code. This is infrastructure for import tools rather than the usual application import interface.

Formal Syntax & Structure

python syntaxpython
import importlib.machinery

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
from importlib.machinery import ModuleSpecspec = ModuleSpec("demo", loader=None, is_package=True)print(spec.name, spec.submodule_search_locations)
Python Reference