importlib.util.find_spec()
importlib.util.find_spec() is a Python function in the Importlib Module category. Finds the module spec for a fully qualified module name. The syntax is importlib.util.find_spec(name, package=None). Returns: ModuleSpec or None. A typical example: spec = importlib.util.find_spec("os")
print(spec.origin) # "/usr/lib/python3.12/os.py"
print(spec.submodule_search_locations). A close sibling is importlib.import_module(), which dynamically imports a module by name at runtime (like `import` statement). A close sibling is importlib.reload(), which re-imports an already imported module (useful for development). A close sibling is importlib.resources.read_text(), which reads a text file resource from a package. A close sibling is importlib.resources.read_binary(), which reads a binary file resource from a package. More about this category: Import system — import_module, reload, resources, metadata. For a broader walkthrough, read the Importlib Module guide. Related Importlib Module entries: importlib.import_module(), importlib.reload(), importlib.resources.read_text(), importlib.resources.read_binary(), importlib.resources.files(), importlib.metadata.version(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.