{"id":2971,"library":"import-deps","title":"import-deps","description":"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.","status":"active","version":"0.5.1","language":"en","source_language":"en","source_url":"https://github.com/schettino72/import-deps","tags":["dependency-analysis","cli-tool","static-analysis","module-imports"],"install":[{"cmd":"pip install import-deps","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"Used for higher-level package dependency analysis.","symbol":"ModuleSet","correct":"from import_deps import ModuleSet"},{"note":"Used for low-level AST-based import extraction from a single file path.","symbol":"ast_imports","correct":"from import_deps.analyzer import ast_imports"}],"quickstart":{"code":"import os\nimport pathlib\nimport subprocess\n\n# Create a dummy package for demonstration\npackage_dir = \"my_dummy_package\"\nos.makedirs(f\"{package_dir}/sub_module\", exist_ok=True)\n\nwith open(f\"{package_dir}/__init__.py\", \"w\") as f:\n    f.write(\"from .module_a import func_a\\n\")\n\nwith open(f\"{package_dir}/module_a.py\", \"w\") as f:\n    f.write(\"import os\\nfrom .sub_module.module_b import func_b\\ndef func_a(): pass\\n\")\n\nwith open(f\"{package_dir}/sub_module/module_b.py\", \"w\") as f:\n    f.write(\"import sys\\ndef func_b(): pass\\n\")\n\n# Run import-deps CLI to analyze the package and output JSON\nprint(f\"\\nAnalyzing '{package_dir}' with import-deps CLI:\\n\")\ncmd = [\"import_deps\", package_dir, \"--json\"]\nresult = subprocess.run(cmd, capture_output=True, text=True, check=True)\nprint(result.stdout)\n\n# Clean up dummy package\nimport shutil\nshutil.rmtree(package_dir)\n","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.10+ or pin `import-deps<0.4.0` in your project dependencies.","message":"Dropped support for Python 3.8 and 3.9 in version 0.4.0. Users on these Python versions must use an older version of `import-deps`.","severity":"breaking","affected_versions":"0.4.0+"},{"fix":"Review scripts using `import_deps --check` and explicitly specify the check type, e.g., `import_deps --check=all` for all checks, or `import_deps <path> --check` (without a type before the path) which implies `--check=all`.","message":"The `--check` CLI flag behavior was unified and changed in version 0.5.0. Previously, it might have had a default check, but now it supports optional types like `--check=all`, `--check=circular`, `--check=reimports`, or `--check=inner`. The behavior of a bare `--check` flag might be different from prior versions.","severity":"breaking","affected_versions":"0.5.0+"},{"fix":"Be aware of this specific behavior. If strict re-import checks are needed for `__init__.py` files, custom tooling would be required or a different approach to package structure.","message":"When using `--check=reimports`, `__init__.py` files are explicitly whitelisted by default, as they commonly re-export symbols for a cleaner public API. This means re-imports in `__init__.py` files will not trigger a check failure.","severity":"gotcha","affected_versions":"0.4.0+"},{"fix":"When migrating from older versions or designing new analysis, leverage the ability to pass multiple paths to `import_deps` directly for comprehensive analysis, e.g., `import_deps path/to/file.py path/to/dir/`","message":"Version 0.5.0 added support for analyzing multiple paths (files and/or directories) in a single command. Older versions might have handled single paths differently or lacked this flexibility.","severity":"gotcha","affected_versions":"0.5.0+"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}