PyDep analyzes and visualizes dependencies within a Python codebase. It recursively scans a directory for Python files, extracts imports and external file interactions (such as JSON and CSV read/write operations), and maps them in an interactive dependency graph.
- Recursive Analysis: Scans directories for
.pysource files, with support for ignoring custom paths (e.g. tests, build artifacts). - Dependency Detection: Extracts import statements as well as data file interactions (CSV and JSON files).
- Interactive Graphing: Uses Plotly and NetworkX to generate a zoomable, interactive network graph in the browser.
- Custom Layout: Optimizes node spacing for clarity in large codebases.
Install dependencies using pip:
pip install networkx plotly numpyClone the repository:
git clone https://github.com/infinition/PyDep.git
cd PyDepRun the script:
python PyDep.pyProvide the paths when prompted:
- Enter the target project directory.
- Choose whether to exclude specific subdirectories (e.g.
tests,.venv). - The interactive visualization will open automatically in your default web browser.
Running the analysis:
Enter the path to the Python project directory: /home/user/projects
Do you want to ignore any directories? (Y/N): Y
Enter the directories to ignore, separated by commas: tests, docs
find_python_files(directory, ignore_dirs=None): Recursively locates Python source files while skipping ignored paths.extract_imports(file_path): Parses a Python file to locate imports and file read/writes.build_dependency_graph(directory, ignore_dirs): Compiles the list of dependencies into a mapping.generate_graph(dependencies): Creates a NetworkX graph structure.custom_layout(graph, iterations=500, k=0.5): Positions nodes using a custom force-directed spring layout.draw_graph(graph): Builds and displays the interactive Plotly HTML chart.
MIT. See LICENSE.
