Skip to main content

A lightweight Python dependency analyzer

Project description

DigDep

Version License Status Open Source GitHub issues Last Commit

A lightweight Python dependency analyzer that scans Python projects and visualizes import relationships.


Installation

pip install digdep

Quick Start (CLI)

List all imported dependencies:

digdep deps ./myproject

Show the File → Dependency tree:

digdep file-tree ./myproject

Show the Dependency → File tree:

digdep dep-tree ./myproject

Sample Output

File → Dependency Tree

Root (/projects/example)

├── main.py              → requests, pathlib
├── config.py            → json
│
├── modules/
│   ├── logger.py        → logging
│   ├── parser.py        → re, typing
│
└── utils/
    └── helpers.py       → functools

Dependency → File Tree

requests
├── main.py

re
├── modules/
│   └── parser.py

logging
├── modules/
│   └── logger.py

Filtering

Filter dependencies by type.

Show only standard library imports:

digdep file-tree ./myproject --type stdlib

Show both standard library and third-party imports:

digdep file-tree ./myproject --type stdlib,third-party

Show only local imports:

digdep file-tree ./myproject --type local

Ignoring Directories

Ignore from command line

digdep file-tree ./myproject --ignore venv __pycache__ tests

Ignore from a file

Create a text file (for example, ignore.txt):

venv
.git
build
__pycache__
tests

Then run:

digdep . --ignore-file ignore.txt

Each non-empty line in the file is treated as a directory to ignore.

The --ignore and --ignore-file options can be used together.


Write Output to a File

Use the -o (--output) option to write command output to a file. Currently, DigDep supports JSON output.

Export the dependency list

digdep deps . -o deps.json

Output:

{
    "dependencies": [
        "argparse",
        "ast",
        "json",
        "pathlib",
        "rich"
    ]
}

Export the file-dependency tree

digdep file-tree . -o file-tree.json

Export the dependency-file tree

digdep dep-tree . -o dep-tree.json

The output format is determined by the file extension. Currently, only .json is supported.

Redirecting Output

Save the generated tree to a file:

digdep dep-tree ./myproject > dependencies.txt

Commands

Command Description
deps List all imported dependencies
file-tree Show the File → Dependency tree
dep-tree Show the Dependency → File tree

Run digdep <command> --help for command-specific options.


Using as a Python Library

from digdep import DepAnalyzer, DepType

analyzer = DepAnalyzer()

# Ignoring directories
analyzer.ignore([
    "__pycache__",
    "venv",
    "build",
    "tests"
])

analyzer.scan("./myproject")

# List imported dependencies
deps = analyzer.get_deps()

# Get the File -> Dependency tree
filedep_tree = analyzer.get_filedep_tree()

# Get the Dependency -> File tree
depfile_tree = analyzer.get_depfile_tree()

# Write File -> Dependency to json file
analyzer.file_tree_json("file_tree.json")

# Get File -> Dependency as json
filetree_json = analyzer.file_tree_json()

Filter dependencies by type:

from digdep import DepAnalyzer, DepType

analyzer = DepAnalyzer()
analyzer.scan("./myproject")

# Show only standard library imports
filedep_tree = analyzer.get_filedep_tree(
    filters=DepType.STDLIB
)

# Show standard library and third-party imports
depfile_tree = analyzer.get_depfile_tree(
    filters=DepType.STDLIB | DepType.THIRD_PARTY
)

# Write File -> Dependency to json file
analyzer.file_tree_json(
    fpath="file_tree.json",
    filters=DepType.STDLIB | DepType.LOCAL
)

Roadmap

  • Local module detection
  • Dependency statistics
  • JSON export
  • Circular dependency detection
  • Unused dependency detection

Requirements

  • Python 3.11+

License

Released under the MIT License.


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

digdep-0.0.6.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

digdep-0.0.6-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file digdep-0.0.6.tar.gz.

File metadata

  • Download URL: digdep-0.0.6.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for digdep-0.0.6.tar.gz
Algorithm Hash digest
SHA256 a3043d1d92927e790c7d9c83c805fdcaa076177ee0faaf0a3fea6e0349672365
MD5 d099f6a8e9ce5f099b4615129cad2d5d
BLAKE2b-256 d27e559a27b5223a7ae453ae96f53f420650ae43de5481bff7442a3f46ea61b4

See more details on using hashes here.

File details

Details for the file digdep-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: digdep-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for digdep-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 07620ef86dcac4ebc05ff4d7a1d93e15ace0a195414396e72f797573d0052c13
MD5 096efedfbc976ad3ce75531b70a71837
BLAKE2b-256 385a0862a1f14557a3d5fcc76ad867bd904446d4d67c4857ed9f41f82fa1cb43

See more details on using hashes here.

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