Automatically generate comprehensive documentation for your Python projects using OpenAI's GPT models. This tool analyzes your codebase and creates detailed, well-structured documentation that helps developers understand and use your code effectively.
- π Intelligent Code Analysis: Uses AST parsing to understand your code structure
- π Comprehensive Documentation: Generates detailed docs for modules, classes, functions, and more
- π Incremental Updates: Only regenerates docs for files that have changed
- π§ Git Integration: Tracks changes through git history
- π° Cost-Effective: Minimal API usage through smart caching and incremental updates
- π¨ Beautiful Output: Generates well-structured Markdown documentation
- βοΈ Highly Configurable: Customize what gets documented and how
- π₯οΈ CLI & API: Use as a command-line tool or integrate into your Python projects
pip install ai-doc-generatorOr install from source:
git clone https://github.com/haseebrj17/ai-doc-generator.git
cd ai-doc-generator
pip install -e .- Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"- Generate documentation for your project:
ai-doc-gen /path/to/your/projectThat's it! Your documentation will be generated in docs/generated/.
# Generate docs for current directory
ai-doc-gen
# Generate docs for specific path
ai-doc-gen /path/to/project
# Force full regeneration (ignore cache)
ai-doc-gen --full
# Use a specific model
ai-doc-gen --model gpt-4o-mini
# Custom output directory
ai-doc-gen --output docs/api
# Include test files
ai-doc-gen --include-tests
# Dry run to see what would be documented
ai-doc-gen --dry-runfrom ai_doc_generator import Config, DocumentationGenerator
# Create configuration
config = Config(
project_root="./my_project",
output_dir="./docs",
include_tests=False,
model="gpt-4o"
)
# Generate documentation
generator = DocumentationGenerator(config)
generator.generate_documentation()Create a ai-doc-config.json file in your project root:
{
"model": "gpt-4o",
"output_dir": "docs/generated",
"include_patterns": ["*.py"],
"exclude_dirs": ["tests", "__pycache__", ".venv"],
"exclude_files": ["setup.py"],
"max_file_size": 100000,
"include_tests": false
}For a typical Python project:
- Small project (10k lines): ~$2-3
- Medium project (50k lines): ~$8-12
- Large project (100k lines): ~$15-25
After initial generation, incremental updates cost 90% less!
docs/generated/
βββ README.md # Main documentation index
βββ project-overview.md # High-level project analysis
βββ api-reference.md # Complete API reference
βββ modules/ # Module-specific documentation
β βββ core/
β βββ utils/
β βββ ...
βββ documentation.json # Raw documentation data
Only regenerate documentation for files that have changed:
# First run - documents everything
ai-doc-gen
# Subsequent runs - only changed files
ai-doc-genCustomize the documentation style:
config = Config(
system_prompt="Generate concise API documentation focusing on usage examples..."
)Use different models for different purposes:
gpt-4o: Best quality, detailed documentationgpt-4o-mini: Faster and cheaper, good for most projectsgpt-4-turbo-preview: Balance of quality and cost
# Clone the repository
git clone https://github.com/haseebrj17/ai-doc-generator.git
cd ai-doc-generator
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Run linting
black .
flake8 .
mypy .
# Run tests with coverage
pytest --cov=ai_doc_generatorThe project documentation is available at: https://haseebrj17.github.io/ai-doc-generator/
- Go to Settings β Pages in your GitHub repository
- Under "Build and deployment", select "Deploy from a branch"
- Choose
gh-pagesbranch and/ (root)folder - Click Save
This project has automated publishing workflows:
When you push changes to main with an updated version in pyproject.toml, the package will automatically be published to PyPI if all tests pass.
- Create a new tag:
git tag v1.0.1 && git push origin v1.0.1 - The workflow will automatically publish to PyPI
- Create an account on PyPI
- Generate an API token from your account settings
- Add the token as
PYPI_API_TOKENin your repository secrets (Settings β Secrets β Actions) - Optionally, add
TEST_PYPI_API_TOKENfor test releases
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for providing the GPT models
- The Python AST module for code analysis
- All contributors and users of this project
- π§ Email: muhamadhaseeb2001@gmail.com
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
Made with β€οΈ by Muhammad Haseeb