Skip to main content

DepCycle

PyPI Python PyPI Downloads CI License: MIT

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.

Features

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

See DepCycle in action

The reports below are generated from the example projects in this repository. DepCycle natively generates HTML, JSON, and DOT files.

Layered dependencies

A small application with dependencies flowing between layers.

Interactive HTML · JSON · DOT

Layered app dependency graph

Circular dependencies

Demonstrates a direct cycle and a longer circular dependency chain.

Interactive HTML · JSON · DOT

Circular dependencies graph

A realistic project

A larger multi-package example containing an intentional circular dependency.

Interactive HTML · JSON · DOT

Realistic app dependency graph

DepCycle analyzing itself

These reports show DepCycle's own module dependency graph.

Interactive HTML · JSON · DOT

DepCycle analyzing itself dependency graph

Example projects

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.

Installation

Install the published release from PyPI:

python -m pip install depcycle

Check the CLI:

depcycle --help

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

Quick start

Analyze a Python project and generate the default HTML report:

depcycle analyze /path/to/your/project

By 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.dot

If --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 -

Output formats

HTML

The HTML report provides an interactive dependency map for exploring module relationships and circular dependencies.

Screenshot of the DepCycle HTML report

JSON

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

DOT

DOT 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.dot

Inspect modules and cycles

Inspect a particular module:

depcycle inspect /path/to/your/project my_package.service

List circular dependencies in a project:

depcycle inspect /path/to/your/project --cycles

Inspection results are printed as JSON. The query subcommand is retained as a legacy command; inspect is the recommended interface.

Circular dependencies and CI

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-cycles

This is useful in CI workflows where detected cycles should fail a check.

Filtering the graph

Hide third-party dependencies:

depcycle analyze /path/to/your/project --no-third-party

Hide standard-library modules:

depcycle analyze /path/to/your/project --no-stdlib

Hide unknown dependencies:

depcycle analyze /path/to/your/project --no-unknown

Combine filters to focus on local dependencies:

depcycle analyze /path/to/your/project --no-third-party --no-stdlib --no-unknown

DepCycle 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 generated

Project configuration

DepCycle 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 = false

For third-party dependency recognition, DepCycle can read declared dependencies from pyproject.toml, requirements.txt, requirements-*.txt, setup.cfg, setup.py, and Pipfile.

Development

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 --help

Common development commands:

make format
make lint
make typecheck
make test
make coverage
make check
make build

Regenerate an example report using the checked-out source:

uv run depcycle analyze examples/basic_app --format html --output docs/generated/basic_app.html

Requirements

DepCycle supports Python 3.10 and newer.

License

DepCycle is licensed under the MIT License. See LICENSE for the full license text.

Metadata

Release files for depcycle 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for depcycle 1.0.0
File Size Uploaded
depcycle-1.0.0.tar.gz 787.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for depcycle 1.0.0
File Interpreter ABI Platform
depcycle-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.6 MB

Release files / depcycle-1.0.0.tar.gz

Download URL depcycle-1.0.0.tar.gz
Size 787.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2652f2a7a746acadc65dc2f1326e54c1f7b76ea43ccd52cf087a88cf90495c51
BLAKE2b-256 checksum
How to use checksums
60e748b721155c4aa14007ad48bd550a16e796e5e3963ca51f73d4121e0250c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release files / depcycle-1.0.0-py3-none-any.whl

Download URL depcycle-1.0.0-py3-none-any.whl
Size 811.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa74956e7032c47f7078177e27dbdd78237e6b8bb05f7d0befb8455b339bdf3b
BLAKE2b-256 checksum
How to use checksums
14cfe97a5373021f15aa1c0a12db30c969950aa18af30f92a0ead65a47dd5ce2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 14, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page