DepCycle is a command-line tool for understanding dependencies between Python modules. It scans Python source files, extracts imports, builds a directed dependency graph, detects circular dependencies, and generates reports for visual exploration or further processing.
- Discover Python files while excluding common generated and environment paths.
- Build a graph of module dependencies.
- Detect circular dependency chains.
- Classify modules as local, standard-library, third-party, or unknown where possible.
- Export reports as interactive HTML, JSON, or Graphviz DOT.
- Filter third-party, standard-library, and unknown dependencies.
- Use JSON and DOT output in scripts and other tools.
Dependency classification is best-effort. A distribution name declared in project metadata may differ from the name used to import it in Python, so some imports may remain classified as unknown.
The reports below are generated from the example projects in this repository. DepCycle natively generates HTML, JSON, and DOT files.
A small application with dependencies flowing between layers.
Interactive HTML · JSON · DOT
Demonstrates a direct cycle and a longer circular dependency chain.
Interactive HTML · JSON · DOT
A larger multi-package example containing an intentional circular dependency.
Interactive HTML · JSON · DOT
These reports show DepCycle's own module dependency graph.
Interactive HTML · JSON · DOT
The examples/ directory contains five projects, progressing from simple imports to a more involved application.
| Example | Demonstrates |
|---|---|
basic_app |
Basic local imports and one-way dependencies |
layered_app |
A layered application structure |
mixed_dependencies |
Local, standard-library, and third-party imports |
cyclic_app |
Direct and multi-module circular dependencies |
realistic_app |
A larger multi-package example with an intentional cycle |
Generated reports for all five examples are available under docs/generated/. Each example has HTML, JSON, and DOT output.
Install the published release from PyPI:
python -m pip install depcycleCheck the CLI:
depcycle --helpDevelopment version: the code in this repository may contain changes that are not yet included in the published PyPI release. To run the checked-out source, see Development.
Analyze a Python project and generate the default HTML report:
depcycle analyze /path/to/your/projectBy default, DepCycle writes dependencies.html to the current working directory. Open it in a browser to explore the dependency graph.
Choose the output format and destination explicitly:
depcycle analyze /path/to/your/project --format html --output dependencies.html
depcycle analyze /path/to/your/project --format json --output dependencies.json
depcycle analyze /path/to/your/project --format dot --output dependencies.dotIf --format is omitted, DepCycle infers the format from a recognized output filename extension. If it cannot infer a format, it defaults to HTML. Use - as the output path to write the report to standard output:
depcycle analyze /path/to/your/project --format json --output -The HTML report provides an interactive dependency map for exploring module relationships and circular dependencies.
JSON output is suitable for scripts and other tools. It contains project information, nodes, edges, detected cycles, and summary statistics, including fan-in, fan-out, and isolated-module counts.
depcycle analyze /path/to/your/project --format json --output dependencies.jsonDOT output is a text-based graph description that can be used by compatible tools and workflows. DepCycle writes DOT source; it does not itself generate PNG or SVG graph images.
depcycle analyze /path/to/your/project --format dot --output dependencies.dotInspect a particular module:
depcycle inspect /path/to/your/project my_package.serviceList circular dependencies in a project:
depcycle inspect /path/to/your/project --cyclesInspection results are printed as JSON. The query subcommand is retained as a legacy command; inspect is the recommended interface.
DepCycle reports detected cycles during analysis. Use --fail-on-cycles to exit with status 1 when at least one cycle is found:
depcycle analyze /path/to/your/project --fail-on-cyclesThis is useful in CI workflows where detected cycles should fail a check.
Hide third-party dependencies:
depcycle analyze /path/to/your/project --no-third-partyHide standard-library modules:
depcycle analyze /path/to/your/project --no-stdlibHide unknown dependencies:
depcycle analyze /path/to/your/project --no-unknownCombine filters to focus on local dependencies:
depcycle analyze /path/to/your/project --no-third-party --no-stdlib --no-unknownDepCycle excludes common generated and environment paths by default, including virtual environments, __pycache__, version-control directories, build output, tests, examples, and migrations. Add exclusion patterns with -e or --exclude; the option can be repeated:
depcycle analyze /path/to/your/project --exclude tests --exclude 'generated/*.py'Use --include-all to disable the built-in exclusion patterns and rely only on patterns explicitly supplied for that run:
depcycle analyze /path/to/your/project --include-all --exclude generatedDepCycle reads supported settings from the [tool.depcycle] section of a project's pyproject.toml. For example:
[tool.depcycle]
exclude = ["generated", "docs"]
show_third_party = true
show_stdlib = true
show_unknown = true
fail_on_cycles = falseFor third-party dependency recognition, DepCycle can read declared dependencies from pyproject.toml, requirements.txt, requirements-*.txt, setup.cfg, setup.py, and Pipfile.
This repository uses uv and the Makefile for development tasks. From the repository root, install the development environment and check the CLI:
make install
uv run depcycle --helpCommon development commands:
make format
make lint
make typecheck
make test
make coverage
make check
make buildRegenerate an example report using the checked-out source:
uv run depcycle analyze examples/basic_app --format html --output docs/generated/basic_app.htmlDepCycle supports Python 3.10 and newer.
DepCycle is licensed under the MIT License. See LICENSE for the full license text.



