An AI-powered tool to automatically document, refactor, and format Python code.
Project description
AutoDoc AI
AutoDoc AI is a smart command-line developer tool that automates the tedious parts of maintaining high-quality Python code. It leverages Large Language Models (LLMs) to automatically generate docstrings, suggest intelligent refactorings, and integrate seamlessly into a modern development workflow.
This project was built on a foundation of solid Object-Oriented Programming principles and design patterns, including the Visitor, Strategy, Factory, and Adapter patterns.
Core Features
- AI-Powered Docstring Generation: Automatically create high-quality, context-aware docstrings for any function or class that's missing them.
- Intelligent Docstring Correction: Uses AI to evaluate existing docstrings and replaces poor-quality or placeholder documentation with new, improved versions.
- AI-Powered Refactoring:
- Safe Variable Renaming: Automatically renames poorly named local variables within function scope.
- Intelligent Naming Suggestions: Acts as an AI-powered linter, suggesting better names for classes and functions that are too short or non-descriptive.
- Seamless Git Integration: Use the
--diffflag to only process files that have been changed in your current Git branch, making it incredibly fast and efficient for pre-commit hooks and CI pipelines. - Codebase-Wide Scanning: Run
autodocon a single file or an entire directory. It automatically finds all Python files and respects your.gitignoreto avoid processing virtual environments or build artifacts. - Automatic Formatting: Integrates with the
blackcode formatter to ensure that all generated and refactored code is perfectly styled. - Highly Configurable: Set project-wide defaults for style, AI provider, and behavior in your
pyproject.tomlfile.
Installation
You can install AutoDoc AI directly from PyPI:
pip install autodoc-ai-paudelnirajan
Configuration
1. Set Up Your AI Provider
AutoDoc requires an API key from an LLM provider. This project is configured to use Groq.
-
Create a
.envfile in the root of your project. -
Add your Groq API key and desired model to the file:
GROQ_API_KEY="gsk_YourActualGroqApiKeyHere" GROQ_MODEL_NAME="llama3-8b-8192"
2. Configure Project Defaults (Optional)
You can set default behaviors for your project in your pyproject.toml file. AutoDoc will use these settings unless they are overridden by a command-line flag.
# In your pyproject.toml
[tool.autodoc]
# Settings for your AutoDoc tool
strategy = "groq"
style = "google" # 'google', 'numpy', or 'rst'
overwrite_existing = true # Regenerate poor-quality docstrings
refactor = true # Enable AI-powered refactoring
Usage
AutoDoc is a flexible command-line tool.
Get help:
autodoc --help
Run on a specific file (dry run, prints to console):
autodoc path/to/your/file.py
Run on an entire directory and save changes in-place:
autodoc src/ --in-place
Run in "Git mode" to only process changed files (most common use case):
autodoc --diff --in-place
Enable all AI features to perform a full quality pass:
autodoc . --in-place --overwrite-existing --refactor
How It Works
AutoDoc uses a "Surgical Hybrid" architecture that combines the strengths of traditional and modern tooling:
- Fast Local Analysis: It uses Python's
ast(Abstract Syntax Tree) module to rapidly parse code and identify potential issues (like a missing docstring or a short variable name). This is done locally and is extremely fast. - Targeted AI Intelligence: Only when a potential issue is found does it send the small, relevant code snippet to an LLM for intelligent analysis (e.g., "Is this a good name?" or "Generate a docstring for this function").
- Precise Code Modification: The AI's response is used to perform a safe and precise modification of the AST, which is then unparsed back into valid Python code.
- Toolchain Integration: Finally, it uses
blackto ensure the final code is perfectly formatted, integrating seamlessly into the existing Python ecosystem.
License
This project is licensed under the MIT License.
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 autodoc_ai_paudelnirajan-0.1.1.tar.gz.
File metadata
- Download URL: autodoc_ai_paudelnirajan-0.1.1.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34ddd7d540eb99e2b3424ae8ac86fe87969577f761f1792b21af08335d93bb29
|
|
| MD5 |
1d0ee13c25b0f5ba4ee18a370a7ea66d
|
|
| BLAKE2b-256 |
888b6edf61ef18104809314a8adcc5ec53925c50a27b1ba8ef89a670a0d798d3
|
File details
Details for the file autodoc_ai_paudelnirajan-0.1.1-py3-none-any.whl.
File metadata
- Download URL: autodoc_ai_paudelnirajan-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2864e41fbdab4ec0769dfeabb2af39dd2473359dc4d8ce64cbd22413b42cb2c
|
|
| MD5 |
8633e5e3b778804362c249ea0cfcb6ad
|
|
| BLAKE2b-256 |
d6347b13ef43b63619e03c60244facbb3be4fab05da70bcb87fb74a302e25ee3
|