A Python dependency tree analyzer with rich terminal output
Project description
PyDepTree
A powerful Python dependency analyzer that visualizes module dependencies in your Python projects as a beautiful tree structure. Built with Rich for gorgeous terminal output.
Features
- 🎯 Smart Import Detection: Uses AST parsing to accurately find all imports
- 🌳 Beautiful Tree Visualization: Rich-powered colorful dependency trees
- 🔍 Configurable Depth: Control how deep to analyze dependencies
- 🚀 Fast & Efficient: Skips standard library and external packages
- 🎨 Import Preview: See actual import statements with
--show-code - 📊 Progress Tracking: Real-time progress for large codebases
- 🔄 Circular Dependency Detection: Identifies and handles circular imports
Installation
Using pip
pip install pydeptree
Using pipx (recommended)
pipx install pydeptree
From source
git clone https://github.com/tfaucheux/pydeptree.git
cd pydeptree
pip install -e .
Usage
Basic Usage
Analyze a Python file and see its direct dependencies:
pydeptree myapp.py
Advanced Options
# Analyze dependencies up to 3 levels deep
pydeptree myapp.py --depth 3
# Show import statements from each file
pydeptree myapp.py --show-code
# Specify a custom project root
pydeptree myapp.py --project-root /path/to/project
Example Output
Analyzing dependencies for: /home/user/project/main.py
Project root: /home/user/project
Max depth: 2
Dependency tree:
└── main.py
├── utils/config.py
│ ├── utils/validators.py
│ └── models/settings.py
└── services/api.py
├── utils/http.py
└── models/response.py
Found 6 files with 8 total dependencies
Command Line Options
FILE_PATH: Path to the Python file to analyze (required)-d, --depth INTEGER: Maximum depth to traverse (default: 1)-r, --project-root PATH: Project root directory (default: file's parent)-c, --show-code: Display import statements from each file--help: Show help message and exit
How It Works
PyDepTree uses Python's built-in AST (Abstract Syntax Tree) module to parse Python files and extract import statements. It then:
- Identifies which imports are part of your project (vs external libraries)
- Recursively analyzes imported modules up to the specified depth
- Builds a dependency graph while detecting circular imports
- Renders a beautiful tree visualization using Rich
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/tfaucheux/pydeptree.git
cd pydeptree
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode with dev dependencies
pip install -e ".[dev]"
Running Tests
# Run tests
pytest
# Run with coverage
pytest --cov=pydeptree
# Run linting
ruff check .
black --check .
mypy pydeptree
Building for Distribution
# Install build tools
pip install build twine
# Build distribution packages
python -m build
# Upload to TestPyPI (for testing)
twine upload --repository testpypi dist/*
# Upload to PyPI (for release)
twine upload dist/*
Contributing
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
Project details
Release history Release notifications | RSS feed
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 pydeptree-0.1.0.tar.gz.
File metadata
- Download URL: pydeptree-0.1.0.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
567dea3f2f9b1c60d8b621b3c5d4c2b00752a8622970413300166e78068e4105
|
|
| MD5 |
2418f475fbeb22ac0c0b71ee2549850e
|
|
| BLAKE2b-256 |
55b9c6581063717c5a5b9b4291fcf474f3b1cdecc8536d6e9f6af60ef2500c9c
|
File details
Details for the file pydeptree-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pydeptree-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b9d8e29c4efc459c06617a47b8b87b15f2063d663a3ad0303fbb0007a287134
|
|
| MD5 |
788714b3bf66799e230914eb246f1d6c
|
|
| BLAKE2b-256 |
6063e99372c6840357fd5398903ebd666c6d1c107f0e266710e829dc63ff641b
|