import-deps

0.5.1 · active · verified Sat Apr 11

import-deps is a Python library and CLI tool designed to find and analyze import dependencies within Python modules and packages. It helps identify issues like circular dependencies, re-imports, and inner imports. It is built upon Python's standard `ast` module, ensuring that analyzed modules are not executed. The library is actively maintained, with version 0.5.1 released in January 2026, indicating a regular release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic CLI usage of `import-deps` to analyze a Python package directory and output its dependencies in JSON format. It creates a temporary package structure, runs the `import_deps` command, and prints the result.

import os
import pathlib
import subprocess

# Create a dummy package for demonstration
package_dir = "my_dummy_package"
os.makedirs(f"{package_dir}/sub_module", exist_ok=True)

with open(f"{package_dir}/__init__.py", "w") as f:
    f.write("from .module_a import func_a\n")

with open(f"{package_dir}/module_a.py", "w") as f:
    f.write("import os\nfrom .sub_module.module_b import func_b\ndef func_a(): pass\n")

with open(f"{package_dir}/sub_module/module_b.py", "w") as f:
    f.write("import sys\ndef func_b(): pass\n")

# Run import-deps CLI to analyze the package and output JSON
print(f"\nAnalyzing '{package_dir}' with import-deps CLI:\n")
cmd = ["import_deps", package_dir, "--json"]
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
print(result.stdout)

# Clean up dummy package
import shutil
shutil.rmtree(package_dir)

view raw JSON →