Skip to main content

PyPI version License: MIT

ai-docify 🤖

A simple, secure, and cost-aware CLI tool for generating high-quality NumPy/Sphinx style docstrings using AI.

ai-docify helps you document your Python code instantly using either cloud-based models (OpenAI) or local privacy-focused models (Ollama). It is designed to be safe (using AST parsing), transparent (pre-flight cost checks), and non-destructive.


✨ Key Features

  • 💰 Cost-Aware Design: Calculates and displays the estimated input token cost via tiktoken before you spend a penny.
  • 🔒 Privacy-First: Switch seamlessly between OpenAI (Cloud) and Ollama (Local) with a single flag. Keep proprietary code on your machine when needed.
  • 🛡️ AST-Powered Safety: Unlike other tools that "guess" where to put text, ai-docify parses your code's Abstract Syntax Tree to surgically inject docstrings without breaking indentation or logic.
  • ↩️ The "Undo" Button: Includes a strip command to safely remove all docstrings if you change your mind.
  • ✌️ Dual Generation Modes: Choose between rewrite for speed/coverage, or inject for surgical precision.
  • 🎯 Granular Control: Document an entire file or target a single function or class for surgical precision.
  • ⚡ "Lean" Architecture: Optimized prompt engineering ensures high-quality documentation without wasting tokens on conversational fluff.

🚀 Installation

Install ai-docify directly from PyPI:

pip install ai-docify

Prerequisites

  • Python 3.8+
  • Ollama (Optional, required only if using local models)

Setup (OpenAI Only)

If you plan to use OpenAI models, set your API key as an environment variable:

Mac/Linux:

export OPENAI_API_KEY=sk-your-api-key-here

Windows (PowerShell):

$env:OPENAI_API_KEY="sk-your-api-key-here"

(Alternatively, you can create a .env file in your project root)


💻 VS Code Extension

Prefer a GUI? This CLI powers the AI Docify for VS Code extension. 👉 **Download AI Docify for VS Code


📖 Usage

1. Generating Documentation

You must specify the Provider, Model, and Mode.

Best for: Surgical precision and preserving formatting. Uses AST parsing to find functions and classes, injecting docstrings exactly where they belong without touching a single line of your actual code.

ai-docify generate my_script.py --provider openai --model gpt-5-mini --mode inject

rewrite Mode

Best for: Speed and heavy refactoring. Asks the AI to rewrite the file with docs included. Good for initial drafts or undocumented legacy files.

# Using a local model (Free)
ai-docify generate my_script.py --provider ollama --model llama3 --mode rewrite

2. Targeting a Single Function

Best for: Quickly documenting a specific piece of code you're working on.

Use the --function flag to target a single function or class by name. This is faster, cheaper, and automatically uses the safe inject mode.

# Target only the 'calculate_total' function in the file
ai-docify generate utils.py --provider openai --model gpt-5-mini --function calculate_total

3. The Safety Check 🛡️

Before generating anything, the tool will pause and show you an exact cost estimate:

🤖 ai-docify: Checking my_script.py in INJECT mode

📊 Estimation (Input Only):
   Tokens: 350
   Est. Cost: $0.00009

Do you want to proceed? [y/n]:

3. Stripping Docstrings (Undo) ↩️

Need to start over? The strip command uses AST parsing to cleanly remove all docstrings from a file, leaving your logic intact. It saves the clean version to a stripped_scripts/ folder by default.

ai-docify strip my_script.py

4. Cleaning Output

To remove all generated files from the default ai_output/ directory:

ai-docify clean

⚙️ Supported Models

ai-docify comes pre-configured with pricing and token limits for popular models.

OpenAI:

  • o3-2025-04-16
  • gpt-5 / gpt-5-mini / gpt-5-nano
  • gpt-5.2

Ollama (Local):

  • llama3.1:8b
  • qwen2.5-coder:7b
  • (Any model pulled via ollama pull works with the --provider ollama flag)

Missing a model? Feel free to open an Issue or Pull Request to update the internal pricing configuration!


🤝 Contributing

We welcome contributions! Whether it's a bug fix, a new feature, or a better prompt template:

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/NewModel)
  3. Commit your Changes (git commit -m 'Add GPT-6 support')
  4. Push to the Branch (git push origin feature/NewModel)
  5. Open a Pull Request

📄 License

Distributed under the MIT License. See LICENSE for more information.

Metadata

Release files for ai-docify 1.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ai-docify 1.1.2
File Size Uploaded Provenance
ai_docify-1.1.2.tar.gz 27.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ai-docify 1.1.2
File Interpreter ABI Platform
ai_docify-1.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 48.7 kB

Release files / ai_docify-1.1.2.tar.gz

Download URL ai_docify-1.1.2.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c1d7ded9cd54469c2a3f0b55acef299e5b42504f014e5d086ca5739d49bb3fde
BLAKE2b-256 checksum
How to use checksums
27bc0ac0c1979ebb16e5e78be434251049a74ef6bc829c698bf35b12fa0c5d87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Release files / ai_docify-1.1.2-py3-none-any.whl

Download URL ai_docify-1.1.2-py3-none-any.whl
Size 21.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f96df85058bf7af344499ea059382d084abe456590026fbb08f5de03f38c998
BLAKE2b-256 checksum
How to use checksums
498c69f989046633a42c8947b676b86d8967792a469dc48bce142065e1edcac6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.2

Security for ai-docify 1.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page