Import and Packaging Modules
modulefinder
Analyzes a script for imports and records discovered modules. It can help investigate dependencies without executing the target script, but dynamic imports and runtime conditions mean the result is not an exhaustive dependency manifest. The example scans a tiny trusted local script.
Formal Syntax & Structure
python syntaxpython
import modulefinderReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from modulefinder import ModuleFinderfrom tempfile import TemporaryDirectoryfrom pathlib import Pathwith TemporaryDirectory() as d: p = Path(d) / "demo.py" p.write_text("import math\n") finder = ModuleFinder() finder.run_script(str(p)) print("math" in finder.modules)