Command line utility to show dependency tree of packages.
npx @tessl/cli install tessl/pypi-pipdeptree@2.28.0A command-line utility for displaying installed Python packages in a hierarchical dependency tree format. Unlike pip freeze which shows packages as a flat list, pipdeptree visualizes package relationships, identifies conflicting dependencies, supports reverse dependency lookups, and provides multiple output formats including text, JSON, and GraphViz.
pip install pipdeptree# CLI entry point
from pipdeptree.__main__ import main
# Core model classes
from pipdeptree._models import DistPackage, ReqPackage, PackageDAG
# Discovery functions
from pipdeptree._discovery import get_installed_distributions
# CLI options
from pipdeptree._cli import get_options, Options
# Validation
from pipdeptree._validate import validate
# Rendering
from pipdeptree._render import render
# Freeze utilities
from pipdeptree._freeze import dist_to_frozen_repr# Show dependency tree for all packages
pipdeptree
# Show specific packages only
pipdeptree --packages django,requests
# Show reverse dependencies (what depends on a package)
pipdeptree --reverse --packages numpy
# Output as JSON
pipdeptree --json
# Output as nested JSON tree
pipdeptree --json-tree
# Use custom Python interpreter
pipdeptree --python /path/to/python
# Auto-detect virtual environment
pipdeptree --python autofrom pipdeptree._discovery import get_installed_distributions
from pipdeptree._models import PackageDAG
from pipdeptree._validate import validate
from pipdeptree._render import render
from pipdeptree._cli import get_options
# Get installed packages
distributions = get_installed_distributions()
# Create dependency tree
tree = PackageDAG.from_pkgs(distributions)
# Validate for conflicts and cycles
validate(tree)
# Parse CLI options and render
options = get_options(['--json'])
render(options, tree)pipdeptree uses a directed acyclic graph (DAG) structure to represent package dependencies:
Discovers and queries installed Python packages across different environments, interpreters, and installation scopes.
def get_installed_distributions(
interpreter: str = sys.executable or "",
supplied_paths: list[str] | None = None,
local_only: bool = False,
user_only: bool = False,
) -> list[Distribution]: ...Core classes for representing packages, requirements, and dependency relationships in a hierarchical structure.
class DistPackage:
def __init__(self, obj: Distribution, req: ReqPackage | None = None): ...
def requires(self) -> Iterator[Requirement]: ...
@property
def version(self) -> str: ...
class ReqPackage:
def __init__(self, obj: Requirement, dist: DistPackage | None = None): ...
@property
def version_spec(self) -> str | None: ...
def is_conflicting(self) -> bool: ...
class PackageDAG(Mapping[DistPackage, list[ReqPackage]]):
@classmethod
def from_pkgs(cls, pkgs: list[Distribution]) -> PackageDAG: ...
def filter_nodes(self, include, exclude, exclude_deps=False): ...
def reverse(self) -> ReversedPackageDAG: ...Validates dependency trees to identify conflicting versions and circular dependencies with detailed reporting.
def validate(tree: PackageDAG) -> None: ...
def conflicting_deps(tree: PackageDAG) -> dict[DistPackage, list[ReqPackage]]: ...
def cyclic_deps(tree: PackageDAG) -> list[list[Package]]: ...Command-line argument parsing and option handling with comprehensive configuration support.
class Options(Namespace):
freeze: bool
python: str
packages: str
exclude: str
reverse: bool
json: bool
json_tree: bool
output_format: str | None
# ... additional options
def get_options(args: Sequence[str] | None) -> Options: ...
def main(args: Sequence[str] | None = None) -> int | None: ...Renders dependency trees in multiple formats including text, JSON, GraphViz, Mermaid, and freeze formats.
def render(options: Options, tree: PackageDAG) -> None: ...Automatically detects and configures for virtual environments including venv, virtualenv, conda, and Poetry.
def detect_active_interpreter() -> str: ...Configurable warning and error reporting system with different verbosity levels and output control.
class WarningType(Enum):
SILENCE = "silence"
SUPPRESS = "suppress"
FAIL = "fail"
class WarningPrinter:
def __init__(self, warning_type: WarningType = WarningType.SUPPRESS): ...
def should_warn(self) -> bool: ...
def print_single_line(self, line: str) -> None: ...