Advanced Python import diagnostic tool with deep analysis, subprocess isolation, auto-fixing suggestions, and CI-ready enforcement.
Project description
importdoc
Production-Ready Import Diagnostic Tool for Python
A hardened diagnostic tool for deep, automated import analysis in Python projects. It features subprocess-safe imports, circular dependency detection, auto-fix suggestions, AST-based symbol resolution, and CI-ready JSON output.
๐ Quick Start (User View)
Prerequisites
- Python 3.10+
jsonschematqdmrichtomli(for Python < 3.11)
One-Command Installation
pip install importdoc
Usage Example
importdoc your_package
โจ Key Features
- ๐ Import graph discovery: Recursively maps and validates imports across a project.
- ๐ง AST-based analysis: Detects missing imports, wrong module paths, and unresolved symbols.
- โก Subprocess safe imports: Imports each module in a sandboxed subprocess, making it timeout-safe.
- ๐ Circular import detection: Identifies dependency cycles with detailed stack traces.
- ๐ ๏ธ Automated fix suggestions: Suggests proper import paths and generates JSON patches for auto-fixing.
- ๐ JSON diagnostic mode: Provides CI-friendly structured reports for easy integration.
- ๐ฆ Cache & telemetry: Includes an optional cache and performance metrics to speed up subsequent runs.
- ๐ก๏ธ Safe mode: Avoids dangerous imports outside the virtual environment by default.
- ๐ Graph export: Generates a DOT dependency graph for visualization with Graphviz.
- ๐ Interactive HTML Reports: Generates self-contained HTML reports for exploring import graphs interactively.
- โ๏ธ Configuration File Support: Reads settings from
pyproject.tomlor.importdoc.rcfor easy configuration management. - Enhanced
no module nameddiagnosis: God Level Parses import symbols from the AST to suggest correct paths based on symbol definitions, providing more accurate and actionable insights. - ๐ต๏ธ Fuzzy module search: God Level Enhanced search for missing modules and incomplete import detection.
- ๐ Plugin Architecture: Support for custom plugins to extend functionality and implement custom checks.
โ๏ธ Configuration & Advanced Usage (Dev View)
Environment Variables
You can configure importdoc behavior using standard environment variables for the underlying tools or shell environment.
CLI/API Table
| Argument | Description | Default |
|---|---|---|
package |
The root package to diagnose. | N/A |
--dir |
The directory of the package, which adds the parent to sys.path. |
N/A |
--continue-on-error |
Continues the diagnosis even after encountering errors. | False |
--dry-run |
Discovers modules without actually importing them. | False |
--max-depth |
The maximum depth for module discovery. | N/A |
--log-file |
The path to the log file. | N/A |
--verbose |
Enables detailed and extensive output. | False |
--quiet |
Minimizes the output to only essential information. | False |
--no-emoji |
Disables the use of emojis in the output. | False |
--timeout |
The timeout in seconds for each import. | 0 |
--unload |
Unloads modules after they are imported. | False |
--json |
Outputs the diagnosis in JSON format. | False |
--parallel |
The number of parallel imports to run. | 0 |
--dev-mode |
Enables developer mode for additional diagnostics. | False |
--dev-trace |
Traces the import chains for debugging. | False |
--graph |
Generates a DOT graph of the import dependencies. | False |
--dot-file |
The path to the output DOT file. | N/A |
--allow-root |
Allows the tool to be run as the root user. | False |
--show-env |
Shows the environment variables at the start. | False |
--enable-telemetry |
Enables production telemetry for performance tracking. | False |
--enable-cache |
Enables caching of results to speed up subsequent runs. | False |
--generate-fixes |
Generates automated fixes for import errors. | False |
--fix-output |
The output file for the automated fixes in JSON format. | N/A |
--no-safe-mode |
Disables safe mode, allowing imports from outside the virtual environment. | False |
--no-safe-skip |
Do not auto-skip imports if not in venv when safe mode active. | False |
--max-scan-results |
Max results for repo scans (defs/usages/fuzzy). | 200 |
--html |
Generates an interactive HTML report of the import graph. | False |
--version |
Shows the version of the tool. | N/A |
Note: For a full list of options, run
importdoc --help.
๐๏ธ Architecture
importdoc/
โโโ src/
โ โโโ importdoc/
โ โโโ __init__.py
โ โโโ banner.py
โ โโโ cli.py # CLI entry point and argument parsing
โ โโโ modules/
โ โโโ __init__.py
โ โโโ analysis.py # AST analysis logic
โ โโโ autofix.py # Fix generation logic
โ โโโ cache.py # Caching mechanism
โ โโโ config.py # Configuration management
โ โโโ diagnostics.py # Core diagnostic controller
โ โโโ discovery.py # Module discovery
โ โโโ plugin.py # Plugin architecture
โ โโโ processor.py # Result processing
โ โโโ reporting.py # Report generation (Text/JSON/HTML)
โ โโโ ... # Other utility modules
โโโ pyproject.toml # Project metadata and dependencies
โโโ README.md
The core logic resides in src/importdoc/modules/diagnostics.py, which is responsible for import analysis, subprocess management, and report generation. The CLI entry point, src/importdoc/cli.py, handles argument parsing and initializes the diagnostic process.
๐บ๏ธ Roadmap
A visionary, integration-oriented plan that categorizes features from "Core Essentials" to "God Level" ambition.
Phase 1: Foundation (Q1)
Focus: Core functionality, stability, security, and basic usage.
- Subprocess-safe imports
- Circular dependency detection
- AST-based symbol resolution
- CI-ready JSON output
- Enhanced error reporting for common import issues
- Official support for Python 3.11 and 3.12
- Comprehensive test suite with 95%+ coverage
Phase 2: The Standard (Q2)
Focus: Feature parity with top competitors, user experience improvements, and robust error handling.
- Interactive HTML reports for visualizing import graphs
- Configuration file support (e.g.,
pyproject.toml) - Caching of analysis results to speed up subsequent runs
- Performance optimization for large codebases
Phase 3: The Ecosystem (Q3-Q4)
Focus: Webhooks, API exposure, 3rd party plugins, SDK generation, and extensibility.
- Plugin architecture for custom checks and reporters
- IDE integration (VS Code, PyCharm) for real-time import diagnostics
- GitHub Actions integration for automated PR comments
- Pre-commit hook integration
Phase 4: The Vision (GOD LEVEL)
Focus: "Futuristic" features, AI integration, advanced automation, and industry-disrupting capabilities.
- AI-powered suggestions for refactoring complex import cycles
- Predictive dependency analysis to identify potential future conflicts
- Automated refactoring of import statements across the entire codebase
The Sandbox (OUT OF THE BOX / OPTIONAL)
Focus: Wild, creative, experimental ideas that set the project apart.
- "Import cost" analysis to identify heavy dependencies
- Integration with runtime profilers to connect import structure to performance
- Gamification of code health with import-related achievements
๐ค Contributing & License
Contributions are welcome! Please feel free to submit a pull request or open an issue.
This project is licensed under the MIT License. See the LICENSE file for details.
โญ Support
If you find this tool useful:
pip install importdoc
And give the repo a โญ on GitHub!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file importdoc-4.0.0.tar.gz.
File metadata
- Download URL: importdoc-4.0.0.tar.gz
- Upload date:
- Size: 55.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68bcf8d10e409dc5c8acad8fdc38689ef0a2fc36c546f7f9a09c8b8e59e9a952
|
|
| MD5 |
3b5ba1f34915dc46d20c90894f0e4994
|
|
| BLAKE2b-256 |
d66378b09b8f3a8fbbb6860b5d5c2ef60d43b0b5b5165954320a7e945fd52811
|
Provenance
The following attestation bundles were made for importdoc-4.0.0.tar.gz:
Publisher:
publish.yml on dhruv13x/importdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importdoc-4.0.0.tar.gz -
Subject digest:
68bcf8d10e409dc5c8acad8fdc38689ef0a2fc36c546f7f9a09c8b8e59e9a952 - Sigstore transparency entry: 747623321
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@cab558c38df9c54bbef3a664bb368ea510f2b26b -
Branch / Tag:
refs/tags/v4.0.0 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cab558c38df9c54bbef3a664bb368ea510f2b26b -
Trigger Event:
push
-
Statement type:
File details
Details for the file importdoc-4.0.0-py3-none-any.whl.
File metadata
- Download URL: importdoc-4.0.0-py3-none-any.whl
- Upload date:
- Size: 40.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7346e98c9163ad987d18cbad7e7518e926b91ae341f1f0cb699cca68ae3126c
|
|
| MD5 |
64d8de211734368fbe819b939d7ff5e3
|
|
| BLAKE2b-256 |
e7955f8c66f0c8f207b369b7846cb7a9a1259b91dfe5c535c16149045d27961a
|
Provenance
The following attestation bundles were made for importdoc-4.0.0-py3-none-any.whl:
Publisher:
publish.yml on dhruv13x/importdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
importdoc-4.0.0-py3-none-any.whl -
Subject digest:
a7346e98c9163ad987d18cbad7e7518e926b91ae341f1f0cb699cca68ae3126c - Sigstore transparency entry: 747623324
- Sigstore integration time:
-
Permalink:
dhruv13x/importdoc@cab558c38df9c54bbef3a664bb368ea510f2b26b -
Branch / Tag:
refs/tags/v4.0.0 - Owner: https://github.com/dhruv13x
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cab558c38df9c54bbef3a664bb368ea510f2b26b -
Trigger Event:
push
-
Statement type: