Skip to content

Latest commit

 

History

12 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PyDep icon

PyDep

License Python Buy Me a Coffee

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.

PyDep Dependency Graph Example

Features

  • Recursive Analysis: Scans directories for .py source 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.

Installation

Install dependencies using pip:

pip install networkx plotly numpy

Clone the repository:

git clone https://github.com/infinition/PyDep.git
cd PyDep

Usage

Run the script:

python PyDep.py

Provide the paths when prompted:

  1. Enter the target project directory.
  2. Choose whether to exclude specific subdirectories (e.g. tests, .venv).
  3. The interactive visualization will open automatically in your default web browser.

Example

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

Script Details

  • 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.

Star History

Star History Chart

License

MIT. See LICENSE.

About

PyDep is a Python script designed to analyze and visualize the dependencies within a Python project. It recursively scans the specified directory for Python files, extracts import statements and file interactions (CSV and JSON), and generates an interactive dependency graph using NetworkX and Plotly.

Topics

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages