Documentation Index
Fetch the complete documentation index at: https://reasonblocks.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
ImportGraph builds a directed dependency graph from Python source files and lets you query which files are affected when a given file changes. The core use case is cache invalidation: before re-reviewing a changed file, you expand the set of affected files to include everything that imports it, then call CodebaseMemory.invalidate() on the expanded set to keep the findings store consistent.
ImportGraph requires networkx. Install it with pip install networkx before calling build_from_files(). If networkx is not installed, build_from_files() raises an ImportError with installation instructions. Constructing an ImportGraph and querying it without calling build_from_files() does not require networkx.Constructor
ImportGraph() takes no parameters. Call build_from_files() to populate the graph before running any queries.
build_from_files()
Parses each file’s imports with Python’s ast module and wires up directed edges. An edge from A to B means “A imports B”.
A dict mapping file paths to their source code strings —
{path: source_code}. Paths that can’t be parsed (syntax errors, binary content) are silently skipped. Only .py and .pyi files are processed; other extensions are ignored. Check stats() after building to see how many nodes and edges were created.ImportGraph — returns self so you can chain the call:
blast_radius()
Returns every file affected by changes in the given set of files. The result includes the changed files themselves plus their transitive dependents — files that import them — up to depth hops away.
An iterable of file paths that have changed. Files not present in the graph are included in the returned set unchanged (they are never silently dropped).
How many hops of importer traversal to include.
0— returns only the changed files themselves.1— adds direct importers (files that directly import the changed files). This is the default and usually the right choice.2— adds importers-of-importers. Use sparingly.
The set of affected file paths including the original
changed_files.importers()
Returns the files that directly import the given file — its immediate dependents in the graph.
The file to look up. Returns an empty list if the file is not in the graph or if the graph has not been built.
A list of file paths that import
file_path. Order is not guaranteed.dependencies()
Returns the files that the given file imports — its outgoing edges in the graph.
The file to look up. Returns an empty list if the file is not in the graph or if the graph has not been built.
A list of file paths that
file_path imports. Order is not guaranteed.contains()
Reports whether the given file path is a node in the graph.
The file path to check.
True if the path is in the graph, False otherwise (including when the graph has not been built).resolve()
Fuzzy-resolves a file path to a canonical node in the graph. Tries an exact match first; if that fails, tries a suffix match so that "main.py" resolves to "pydantic/main.py".
The path to resolve. Can be a bare filename, a partial path, or a full path.
The canonical node path from the graph, or
None if no match is found or the graph has not been built.stats()
Returns summary counters for the built graph. Useful for logging after build_from_files() to confirm the graph was populated.
A dict with two integer fields:Returns
{"nodes": 0, "edges": 0} when the graph has not been built.format_impact()
Produces a human-readable impact analysis string for a given file, suitable for returning directly from an LLM tool observation.
(+N more) line is appended.
The file to analyze. The path is first run through
resolve(), so bare filenames and partial paths work. Returns a descriptive message string if the file is not in the graph.A multi-line formatted string showing the file’s importers and dependencies. Returns
"(file not in import graph: {file_path})" when the file cannot be resolved.