Skip to main content

AI-powered Python documentation enhancer supporting local LLMs (LLaMA, Ollama) and cloud providers.

Project description

PyDocEnhancer

AI-powered Python plugin to enhance documentation with summaries, code explanations, examples, semantic search, automated example testing, and multilingual documentation.

Features

  • Auto-Generated Summaries: Summarize modules, classes, and functions.
  • Code Explanations: Plain-English explanations of code logic.
  • Semantic Search: Query documentation with natural language (e.g., "find data processing functions").
  • Auto-Generated Examples: Create working code examples from docstrings.
  • Automated Example Testing: Extracts and runs code examples from docstrings, reporting results in the docs.
  • Multilingual Documentation: Generate documentation in multiple languages (e.g., English, French, Spanish, Chinese) using LLM translation.
  • Local LLM Support: Privacy-first processing with local models (e.g., LLaMA 3.2, ctransformers backend).
  • Integrations: Works with Sphinx, MkDocs, and Jupyter Notebooks.

Installation

pip install pydocenhancer[local]

For most users, the [local] extra is recommended. This uses the ctransformers backend, which does not require C++ build tools and works on most platforms. Only use the base install or cloud extras if you specifically need those features.

If you want to use the llama-cpp-python backend, install with:

pip install pydocenhancer[llama]

Note: This requires C++ build tools on Windows (see Troubleshooting below).

Quick Start

from pydocenhancer import DocEnhancer

# Initialize with a local LLM (Ollama or LLaMA), generate docs in French
enhancer = DocEnhancer(provider="local", model="ollama/llama3", language="fr")
enhancer.generate_docs(module_path="my_project/utils.py", output_dir="docs", language="fr")

# Search documentation
results = enhancer.search_docs("file handling functions", "docs")
print(results)

CLI Usage

# Generate documentation with Ollama in Spanish, with example testing
pydocenhancer enhance --module my_project/utils.py --output docs/ --provider local --model ollama/llama3 --language es

# Search documentation
pydocenhancer search --query "data processing functions" --docs-dir docs/

Requirements

  • Python 3.8+
  • Local LLM (e.g., LLaMA 3.2 via ctransformers)
  • Optional: Sphinx or MkDocs for integration

Windows Users

If you want to use local LLMs, install with:

pip install pydocenhancer[local]

No C++ build tools required for ctransformers wheels.

Troubleshooting Installation (Windows)

Some features (such as local LLMs using llama-cpp-python) require compiling native code. If you see errors like:

CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
CMake Error at CMakeLists.txt:3 (project):
  Running 'nmake' '-?' failed with: no such file or directory

This means your system is missing the required C/C++ build tools for compiling Python packages with native code.

How to Fix (Windows)

  1. Install Visual Studio Build Tools
  2. Restart your terminal (or use the "Developer Command Prompt for VS").
  3. Retry installation:
    pip install pydocenhancer
    

Debugging Tips

  • If you see errors about missing nmake or C/C++ compilers, the build tools are not installed or not in your PATH.
  • Try installing llama-cpp-python directly to see detailed errors:
    pip install llama-cpp-python
    
  • If you want to avoid C++ build tools, use the [local] extra to install with ctransformers backend (pre-built wheels):
    pip install pydocenhancer[local]
    
  • For advanced debugging, check the full error log and search for the first error message.

Alternative: Use WSL

If you have trouble with Windows build tools, consider using Windows Subsystem for Linux (WSL) for easier compilation of native code.

Common Errors & Solutions

Error Message Cause Solution
ImportError: ctransformers is required for local LLMs. You tried to use a local LLM without installing ctransformers. Run pip install pydocenhancer[local]
FileNotFoundError: [Errno 2] No such file or directory The module path you provided does not exist. Check the path and try again.
RuntimeError: Local LLM is not initialized. The local model failed to load or is not available. Check your model name and installation.
requests.exceptions.ConnectionError Ollama is not running or not reachable. Start Ollama and ensure the model is pulled.
Error: ... in Example Test Result The example code in the docstring is invalid or raises an exception. Fix the example code in your docstring.
CMake Error: CMAKE_C_COMPILER not set... Missing C++ build tools on Windows. See Troubleshooting Installation (Windows) above.
ModuleNotFoundError: No module named 'llama_cpp_python' You tried to use the llama backend without installing it. Run pip install pydocenhancer[llama]

Additional Debugging Steps

  • Verbose Output: Run with -v or --verbose if available, or set environment variable PYTHONVERBOSE=1 for more details.
  • Check Python Version: Ensure you are using Python 3.8+.
  • Check Dependencies: Run pip check to see if any dependencies are missing or incompatible.
  • Update pip: Sometimes, upgrading pip helps: python -m pip install --upgrade pip.

Packaging Note for Windows Users

  • If you want to use local LLMs without C++ build tools, install with:
    pip install pydocenhancer[local]
    
    This uses the ctransformers backend, which provides pre-built wheels and does not require compilation.
  • If you want to use the llama-cpp-python backend, you must have Visual Studio Build Tools installed as described above, and install with:
    pip install pydocenhancer[llama]
    

Documentation

Full documentation is available in this README and at GitHub.

License

MIT © Abdoullah Ndao abdoullahaljersi@gmail.com

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

pydocenhancer-3.0.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

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

pydocenhancer-3.0.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file pydocenhancer-3.0.0.tar.gz.

File metadata

  • Download URL: pydocenhancer-3.0.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for pydocenhancer-3.0.0.tar.gz
Algorithm Hash digest
SHA256 96a86458130edb938da75c9397c0e4a85d482c054ae012216e35f0494918d45f
MD5 a340dba6c0c35259c5ed2b65c3ed2ffd
BLAKE2b-256 572ccfedbc921e363ba7d6534fdc3c335d15e448adbcb7e806bfbcde7f7dd9be

See more details on using hashes here.

File details

Details for the file pydocenhancer-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydocenhancer-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for pydocenhancer-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b04f6c1994f81c8a7058186f00240c0df98221efb4dfee704cb3b44c288de187
MD5 146524f3f162f89fc35df4b5ea45d6e8
BLAKE2b-256 8fefd4962d330624c0ccc193733b0d826282930b92cd7800c23f946591ce3e57

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