Skip to main content
This guide will walk you through generating your first documentation using DocuGen AI. We’ll scan a Python project and create a comprehensive README.md file.

Prerequisites

Before starting, make sure you have:
  • DocuGen AI installed (see Installation)
  • A Gemini API key configured in your environment
  • A Python project to document

Basic Usage

The primary command for generating documentation is docugen generate. Let’s start with the simplest example.
1

Navigate to your project directory

cd /path/to/your/python/project
2

Run the generate command

docugen generate .
This command will:
  • Scan all Python files in the current directory
  • Parse the code structure using AST analysis
  • Generate documentation using Gemini AI
  • Save the output to README.md
3

View the generated documentation

cat README.md
You’ll see a professional, AI-generated README with descriptions of your project structure, classes, functions, and usage examples.
DocuGen AI respects .gitignore rules and automatically excludes common directories like venv/, __pycache__/, and .git/.

Command Line Options

The generate command supports several options for customization:

Path Argument

docugen generate <path>
path
string
required
Path to the Python project to analyze. Can be an absolute or relative path.
Example:
docugen generate ./src
docugen generate /home/user/my-project

Output Option

docugen generate . --output DOCUMENTATION.md
docugen generate . -o DOCUMENTATION.md
--output, -o
string
default:"README.md"
Output Markdown file name. Can be a filename or a relative/absolute path.
Example:
# Save to a different filename
docugen generate . --output API_DOCS.md

# Save to a specific directory
docugen generate . --output docs/README.md

Model Option

docugen generate . --model gemini-pro
--model
string
default:"gemini-3.1-flash-lite-preview"
Gemini model name to use for generation. Different models offer different capabilities and pricing.
Example:
docugen generate . --model gemini-pro
docugen generate . --model gemini-ultra

Prompt Option

docugen generate . --prompt "Focus on API security features"
docugen generate . -p "Include deployment instructions"
--prompt, -p
string
Optional additional instruction to guide the AI in generating specific content or emphasizing certain aspects.
Example:
docugen generate . --prompt "Emphasize the async capabilities"
docugen generate . -p "Target audience: beginner developers"

Config Option

docugen generate . --config config.toml
--config
path
Optional TOML configuration file path for advanced settings.

Complete Working Example

Let’s generate documentation for a Python package with custom settings:
# Generate docs for current directory
docugen generate .

Understanding the Output

When you run the generate command, you’ll see status messages indicating progress:
⠋ Scanning Python files...
⠙ Parsing source files with AST...
⠹ Generating markdown with Gemini...
✓ Documentation generated at: /path/to/project/README.md
ℹ Scanned 15 files, 8 classes, 42 functions, 28 methods.
The generated README.md will include:
  • Project Overview: High-level description of what the project does
  • Technical Architecture: Explanation of the code structure
  • Key Features: Main capabilities extracted from the code
  • API Reference: Documentation of classes, functions, and methods
  • Usage Examples: Code snippets showing how to use the project

Step-by-Step Tutorial

Let’s document a sample Python project from scratch:
1

Ensure API key is configured

Verify your Gemini API key is set:
echo $GEMINI_API_KEY  # Linux/macOS
echo %GEMINI_API_KEY%  # Windows CMD
If not set, configure it:
export GEMINI_API_KEY="your-api-key-here"
2

Navigate to your Python project

cd ~/projects/my-python-app
3

Run DocuGen AI

docugen generate . --output README.md
Watch as DocuGen AI:
  • Scans your Python files
  • Parses the AST structure
  • Calls the Gemini API
  • Generates professional documentation
4

Review the generated documentation

less README.md
# or
cat README.md
5

Customize if needed

If you want to adjust the output, regenerate with a custom prompt:
docugen generate . \
  --output README.md \
  --prompt "Add more detailed usage examples and include installation instructions"

Common Use Cases

# Document only the 'api' module
docugen generate ./my_project/api --output API_README.md
# Regenerate README after code changes
docugen generate . --output README.md
This will overwrite the existing README.md file. Consider backing it up first or using version control.
# Use a script to document multiple projects
for dir in project1 project2 project3; do
  docugen generate ./$dir --output $dir/README.md
done
Add to your GitHub Actions workflow:
.github/workflows/docs.yml
name: Generate Documentation
on: [push]
jobs:
  docs:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-python@v4
        with:
          python-version: '3.11'
      - run: pip install docugen-ai
      - run: docugen generate . --output README.md
        env:
          GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
      - run: git add README.md && git commit -m "Update docs" && git push

Troubleshooting

Problem: The API key is not configured.Solution:
export GEMINI_API_KEY="your-api-key-here"
Or create a .env file with:
GEMINI_API_KEY=your-api-key-here
Problem: DocuGen AI couldn’t find any Python files in the specified path.Solution:
  • Verify the path is correct: ls /path/to/project
  • Ensure the directory contains .py files
  • Check that files aren’t excluded by .gitignore
Problem: The specified path is invalid.Solution:
# Use absolute path
docugen generate /home/user/my-project

# Or navigate to the directory first
cd /home/user/my-project
docugen generate .
Problem: Communication with the Gemini API failed.Solution:
  • Verify your API key is valid
  • Check your internet connection
  • Ensure you have API quota remaining
  • Try a different model: --model gemini-pro

Next Steps

CLI Reference

Explore all available commands and options

Configuration

Learn about advanced configuration options

Core Concepts

Understand how DocuGen AI works internally

API Reference

Detailed API documentation for the DocuGen AI library

Build docs developers (and LLMs) love