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.
pip install import-depsVerified import paths — ran on the pinned version, not inferred.
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.
Upgrade to Python 3.10+ or pin `import-deps<0.4.0` in your project dependencies.
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`.
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.
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/`
Ensure the library is installed in your active Python environment by running `pip install import-deps`. If using a virtual environment, ensure it is activated.
Refactor your code to break the circular dependency. Common solutions include moving shared code to a new, independent module, using late imports (importing inside a function/method if the dependency is only needed there), or reframing the module structure. The `import-deps --check=circular` command can help identify the exact cycles.
Verify that the name you are trying to access (e.g., `MyClass` in `module.MyClass`) is correctly defined and exported in the module. For packages, ensure that `__init__.py` files properly expose submodules or their contents if you expect them to be accessible via the parent package name. If it's a subpackage, ensure it's explicitly imported.
Consult the `import-deps` documentation or run `import_deps --help` to understand the correct command-line arguments. For example, to analyze a single file, use `import_deps your_module.py`, or to check a package, use `import_deps your_package/`.
No dependency data recorded yet.