A lightweight Python dependency analyzer
Project description
DigDep
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
Show the File → Unused Imports tree:
digdep unused-imports ./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()
# Get the File -> Unused Import tree
unusedimports_tree = analyzer.get_unused_imports_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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file digdep-0.0.7.tar.gz.
File metadata
- Download URL: digdep-0.0.7.tar.gz
- Upload date:
- Size: 11.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3f9057c0358ce0b9fd1a9491b12de95df20501858cdf9f537b5118dde7d6cc6
|
|
| MD5 |
bbd676db3acee1fc0bfdb5277825d9a3
|
|
| BLAKE2b-256 |
931dfcfa748aff77d207b68b70949135b57788610b4698eccd8e5785fa57ca20
|
File details
Details for the file digdep-0.0.7-py3-none-any.whl.
File metadata
- Download URL: digdep-0.0.7-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93a87fd0d64aaef52125e037bf0d2973e3734f157252756355f8f31b36612e11
|
|
| MD5 |
9d105dbe855c89abf700648541b7de89
|
|
| BLAKE2b-256 |
b20a82f8be78fc18ae66e88b873736d4efebe59afaa2ca96eb89087b33cb85f9
|