Skip to main content

Advanced Python import diagnostic tool with deep analysis, subprocess isolation, auto-fixing suggestions, and CI-ready enforcement.

Project description

importdoc logo

PyPI version Python Wheel Release

Build status Codecov Test Coverage Code style: black Ruff Security

Downloads OS Python Versions

License: MIT

Docs

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+
  • jsonschema
  • tqdm
  • rich
  • tomli (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.toml or .importdoc.rc for easy configuration management.
  • Enhanced no module named diagnosis: 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!

https://github.com/dhruv13x/importdoc

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

importdoc-4.0.0.tar.gz (55.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

importdoc-4.0.0-py3-none-any.whl (40.6 kB view details)

Uploaded Python 3

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

Hashes for importdoc-4.0.0.tar.gz
Algorithm Hash digest
SHA256 68bcf8d10e409dc5c8acad8fdc38689ef0a2fc36c546f7f9a09c8b8e59e9a952
MD5 3b5ba1f34915dc46d20c90894f0e4994
BLAKE2b-256 d66378b09b8f3a8fbbb6860b5d5c2ef60d43b0b5b5165954320a7e945fd52811

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-4.0.0.tar.gz:

Publisher: publish.yml on dhruv13x/importdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for importdoc-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a7346e98c9163ad987d18cbad7e7518e926b91ae341f1f0cb699cca68ae3126c
MD5 64d8de211734368fbe819b939d7ff5e3
BLAKE2b-256 e7955f8c66f0c8f207b369b7846cb7a9a1259b91dfe5c535c16149045d27961a

See more details on using hashes here.

Provenance

The following attestation bundles were made for importdoc-4.0.0-py3-none-any.whl:

Publisher: publish.yml on dhruv13x/importdoc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page