Skip to main content

A Python dependency tree analyzer with rich terminal output

Project description

PyDepTree

PyPI version Python Support License: MIT

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.

Demo

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:

  1. Identifies which imports are part of your project (vs external libraries)
  2. Recursively analyzes imported modules up to the specified depth
  3. Builds a dependency graph while detecting circular imports
  4. 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.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with Click for CLI
  • Beautiful output powered by Rich
  • Inspired by various dependency analysis tools in the Python ecosystem

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

pydeptree-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

pydeptree-0.1.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for pydeptree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 567dea3f2f9b1c60d8b621b3c5d4c2b00752a8622970413300166e78068e4105
MD5 2418f475fbeb22ac0c0b71ee2549850e
BLAKE2b-256 55b9c6581063717c5a5b9b4291fcf474f3b1cdecc8536d6e9f6af60ef2500c9c

See more details on using hashes here.

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

Hashes for pydeptree-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9b9d8e29c4efc459c06617a47b8b87b15f2063d663a3ad0303fbb0007a287134
MD5 788714b3bf66799e230914eb246f1d6c
BLAKE2b-256 6063e99372c6840357fd5398903ebd666c6d1c107f0e266710e829dc63ff641b

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