Skip to main content

Command-line tool to visualize Python project dependencies.

Project description

DepCycle

Python 3.8+ License: MIT Downloads Downloads per month

DepCycle is a command-line tool to visualize Python project dependencies. It helps developers understand complex codebases by automatically generating visual maps of how modules are connected, making it easy to spot architectural problems like circular dependencies and untangle coupled code.

Features

  • Automatic Dependency Discovery: Scans Python projects and builds a complete dependency graph
  • Cycle Detection: Identifies circular dependencies that can lead to architectural issues
  • Flexible Visualization: Multiple output formats including PNG, SVG, and HTML
  • Smart Filtering: Exclude specific patterns, third-party libraries, or standard library modules
  • AST-Based Parsing: Uses Python's Abstract Syntax Tree for accurate import detection

Links

Prerequisites

  • Python 3.8 or higher
  • Graphviz (for PNG/SVG output)

Installing Graphviz

macOS:

brew install graphviz

Ubuntu/Debian:

sudo apt-get install graphviz

Windows: Download and install from Graphviz website

Installation

Install via pip (recommended)

pip install depcycle

or 

# install directly from GitHub
pip install git+https://github.com/Matricess/depcycle.git

Install from a clone (editable dev setup)

git clone https://github.com/Matricess/depcycle.git
cd depcycle
pip install -e .[dev]

If you prefer requirements files, pip install -r requirements.txt will install runtime deps plus pytest for the test suite.

Usage

Basic Usage

Analyze a Python project and generate a dependency graph (PNG by default):

depcycle /path/to/your/project

The output is written to dependencies.png in the current working directory.

Note: By default DepCycle skips common noise directories such as venv/, .venv/, .git/, __pycache__/, node_modules/, build artifacts, and Python cache folders. Use -e flags if you need extra exclusions, or disable the defaults via the API (Project.get_python_files(include_defaults=False)).

Using as a Module

python -m depcycle /path/to/your/project

Advanced Options

Generate a different output format or explicit location:

depcycle /path/to/project --format svg --output diagrams/dependencies.svg

Exclude specific directories or files (glob syntax):

depcycle /path/to/project -e venv -e ".*/tests/*" -e "*.test.py"

Focus only on local code:

depcycle /path/to/project --no-third-party --no-stdlib

Full help:

depcycle --help

Tests

Tests live under tests/ and run without touching the sample projects in examples/.

pip install -e .[dev]
pytest -q

See tests/README.md for a quick summary.

Project Structure

depcycle/
├── src/
│   └── depcycle/
│       ├── __init__.py
│       ├── __main__.py
│       ├── cli.py                  # Command-line interface
│       ├── config.py               # Configuration management
│       ├── graph/
│       │   ├── __init__.py
│       │   ├── dependency_graph.py # Core graph logic
│       │   └── module_node.py      # Module representation
│       ├── parsing/
│       │   ├── __init__.py
│       │   ├── ast_parser.py       # AST-based import parsing
│       │   └── project.py          # File discovery
│       └── rendering/
│           ├── __init__.py
│           ├── interface.py        # Visualization interface
│           └── visualizers.py      # Output implementations
├── requirements.txt
├── README.md
└── LICENSE

Architecture

DepCycle follows a clean, modular architecture:

  1. CLI Layer (cli.py): Handles user input and orchestrates the workflow
  2. Configuration (config.py): Manages all settings and options
  3. Graph Layer (graph/): Core data structures for the dependency graph
  4. Parsing Layer (parsing/): Discovers files and extracts imports using AST
  5. Rendering Layer (rendering/): Generates visualizations in various formats

Key Classes

  • DepCycleCLI: Main entry point that handles command-line arguments
  • DependencyGraph: Central data structure holding all module relationships
  • ModuleNode: Represents a single Python module/file
  • Project: Discovers and manages Python files in a project
  • ASTParser: Extracts imports using Python's AST module
  • GraphvizVisualizer: Renders graphs as PNG/SVG images
  • HtmlVisualizer: Generates interactive HTML visualizations

How It Works

  1. Discovery: Recursively scans the project directory for all .py files
  2. Parsing: Uses Python's AST to extract import statements from each file
  3. Resolution: Maps import strings to actual modules in the project
  4. Classification: Categorizes modules as LOCAL, THIRD_PARTY, or STDLIB
  5. Analysis: Detects circular dependencies using depth-first search
  6. Visualization: Renders the graph using Graphviz or HTML

Example Output

When you run DepCycle, you'll see output like:

Analyzing project: /path/to/my-project
Building dependency graph...
Found 42 modules
✓ No circular dependencies detected
Generating PNG visualization...
✓ Visualization saved to: dependencies.png

If circular dependencies are found:

⚠️  Warning: Found 2 circular dependency cycles!
  Cycle 1: app.models.user → app.services.auth → app.models.user
  Cycle 2: app.core.database → app.core.config → app.core.database

Analytics

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

Built as part of a Software Design and Testing course project (IT643).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depcycle-0.2.5.tar.gz (25.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

depcycle-0.2.5-py3-none-any.whl (24.4 kB view details)

Uploaded Python 3

File details

Details for the file depcycle-0.2.5.tar.gz.

File metadata

  • Download URL: depcycle-0.2.5.tar.gz
  • Upload date:
  • Size: 25.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for depcycle-0.2.5.tar.gz
Algorithm Hash digest
SHA256 77aeea346c26c3ec2f5c5c581f8e03265ec1ed5a97f4bd6357e713d1aeec2e7d
MD5 ce6a1288a98117ed80c93fe13c1add25
BLAKE2b-256 0242c5e0160abb1208a3c5b119b45b007ad19eed1f3798bf9b6ea81c0fd43370

See more details on using hashes here.

Provenance

The following attestation bundles were made for depcycle-0.2.5.tar.gz:

Publisher: publish.yml on Matricess/depcycle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file depcycle-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: depcycle-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 24.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for depcycle-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 a0c815dec9ba7dda6bb37b2ab7c644f573ed54ed2dd8dcab6f852dd1ee7c1eae
MD5 66091d4bac6f547f366c46d65844803a
BLAKE2b-256 476ddac81517ce21b0e2295d9fbb336f154814efe31cf09a6a874ad0ac70d476

See more details on using hashes here.

Provenance

The following attestation bundles were made for depcycle-0.2.5-py3-none-any.whl:

Publisher: publish.yml on Matricess/depcycle

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page