importsearch is a CLI tool that inspects Python files and reports the import dependency graph for a given entry point.
Specify a target file and instantly view the downstream files and modules that it touches.
Looking for the Japanese guide? See README-ja.md.
- Rich CLI report: Presents dependencies and visited files in a styled table.
- Multiple output formats: Choose between
print(decorated),text, andjson. - Stable traversal: Works on
Pathobjects, avoiding cycles and duplicates during analysis.
pip install importsearchimportsearch path/to/main.py --root . --output-format print--root / -r: Root directory for the analysis (defaults to the current directory)--output-format / -o:print|text|json--output-file / -of: Base name fortext/jsonreports (extension is added automatically)--verbose / -v: Display progress logs during the walk
importsearch src/main.py --root . --output-format text --output-file reportThe command prints the summary to stdout and writes it to report.txt.
While the CLI is the primary interface, you can instantiate the searcher directly:
import argparse
from pathlib import Path
from importsearch import importsearch
args = argparse.Namespace(
file_path=Path("src/main.py"),
root_path=Path("."),
output_format="json",
output_path=Path("dependencies"),
verbose=False,
)
searcher = importsearch(args)
searcher.search()
searcher.summary()Run the test suite with pytest:
pytestContributions are welcome! If you have ideas for improvements, please open an issue or submit a pull request.