Skip to main content

An AI-powered tool to automatically document, refactor, and format Python code.

Project description

AutoDoc: AI-Powered Code Documentation Generator

Project Overview

AutoDoc is a command-line utility designed to help developers maintain high-quality documentation in their Python projects. It automatically analyzes existing source code, identifies undocumented functions and classes, and uses a Large Language Model (LLM) to generate or validate necessary docstrings.

This tool ensures code completeness, reduces documentation debt, and allows developers to focus on writing code, not comments.

Features

  • Intelligent Docstring Insertion: Scans Python files, finds missing docstrings for functions and classes, and injects high-quality, generated documentation directly into the Abstract Syntax Tree (AST).
  • Docstring Evaluation: Uses a well-crafted LLM prompt to evaluate existing docstrings. If a docstring is found to be low-quality (e.g., a "TODO" placeholder or too generic), the tool can flag it or automatically replace it with a superior generated version.
  • Pluggable AI Backend: The architecture is designed to easily swap between different LLM providers (e.g., Groq, OpenAI) or even run in a placeholder Mock mode for rapid local testing.
  • Non-Destructive AST Modification: Safely modifies the code structure at the tree level, ensuring the resulting code is syntactically correct and properly formatted.

Technology Stack

Component Technology Role
Language Python 3.9+ Core development language.
AST Parsing ast (Built-in) Used for reading source code into an Abstract Syntax Tree.
Code Rewrite ast.unparse / astor (Optional) Converts the modified AST back into source code.
AI Backend Groq SDK Primary LLM provider for fast, real-time generation and evaluation.
Dependency Management dotenv Manages API keys and configuration settings.

Getting Started

Prerequisites

  1. Python 3.9 or higher.
  2. A Groq API key (or equivalent for a different LLM service).

Installation

  1. Clone the repository:
    git clone https://github.com/paudelnirajan/autodoc
    cd autodoc
    
  2. Set up a virtual environment and install dependencies:
    python3 -m venv venv
    source venv/bin/activate
    pip install -r requirements.txt
    
  3. Create a file named .env in the project root and add your API key:
    # .env
    GROQ_API_KEY="sk-..."
    GROQ_MODEL_NAME="llama-3.3-70b-versatile" # Optional, defaults to this model
    

Usage

Run the tool from the command line, specifying the file you wish to document and the strategy to use:

# Preview changes (dry run) using the LLM strategy
python3 main.py --file=path/to/my_script.py --strategy=groq

# Apply changes to the file using the LLM strategy
python3 main.py --file=path/to/my_script.py --strategy=groq --write

# Run in mock mode to test the AST modification without API calls
python3 main.py --file=path/to/my_script.py --strategy=mock --write

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

autodoc_ai_paudelnirajan-0.1.0.tar.gz (12.6 kB view details)

Uploaded Source

Built Distribution

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

autodoc_ai_paudelnirajan-0.1.0-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file autodoc_ai_paudelnirajan-0.1.0.tar.gz.

File metadata

File hashes

Hashes for autodoc_ai_paudelnirajan-0.1.0.tar.gz
Algorithm Hash digest
SHA256 99895f8e2bb3d3c5c34748e2f9905a07396b3c9bcfbc92f82dad38a89f251d94
MD5 3f1b9fe05f4e36b9779d9bd7524a9c22
BLAKE2b-256 4fb80946aae2e26947d9df775cebb54a1d2f0bf1864db047173a34d7c824dcb8

See more details on using hashes here.

File details

Details for the file autodoc_ai_paudelnirajan-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for autodoc_ai_paudelnirajan-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 38c34d2caeb4c337d41a2ce1d69b2c805edb063cc0aa7fcd3c154bf20415e04e
MD5 09d8cc583cb00b6af84f1ddd3bca6d09
BLAKE2b-256 304c0731e4d6f3a00c0d52f9e2e47c706d7711b3dfc11074b54c917b978a82c2

See more details on using hashes here.

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