Skip to content

Latest commit

 

History

History
158 lines (109 loc) · 4.24 KB

README.md

File metadata and controls

158 lines (109 loc) · 4.24 KB

image

Python Version OS License PyPI GitHub pull request

[ English | 中文 ]

DocAPI is a Python library powered by Large Language Models (LLMs) designed for automatically generating API documentation. It currently supports Flask and Django, enabling seamless documentation generation and updates to enhance developer productivity.


Important Notes

  • Version 1.x.x introduces significant changes compared to Version 0.x.x. Please refer to the updated usage guide below.
  • By default, generating or updating documentation requires the API service's dependency environment.
  • Add the --static parameter for static route scanning that does not depend on the project environment. This option only supports Flask projects. The downside is that it may include unused routes in the generated documentation. It suitable for single-page Flask API projects.

Key Features

  • Framework Support: Automatically scans routing structures for Flask and Django applications.
  • Multi-Model Compatibility: Works with a wide range of commercial and open-source LLMs.
  • Documentation Management: Generates complete documentation or performs incremental updates.
  • Multi-Language Support: Creates multilingual API documentation (requires LLM support).
  • Web Integration: Supports deploying documentation on a web interface.

Changelog

  • [2024-12-16]: Display a progress bar when generating or updating documentation; The Flask project supports static route scanning independent of the project environment.
  • [2024-12-05]: Fully supported Django versions 3, 4, and 5, with comprehensive testing completed.
  • [2024-12-02]: Passed Windows system testing (requires PowerShell or Windows Terminal). Optimized model name management to avoid conflicts with environment variables.
  • [2024-11-26]: Added support for loading environment variables from .env files and multilingual documentation.
  • [2024-11-24]: Introduced multithreading to accelerate request processing.
  • [2024-11-20]: Added support for custom documentation templates.
  • [2024-11-17]: Supported Zhipu AI and Baidu Qianfan models, improved documentation structure, and added JavaScript example code. Removed configuration file execution mode.

Installation

Install the latest version via PyPI:

pip install -U docapi

Install with all dependencies:

pip install -U "docapi[all]"

Install for specific frameworks:

pip install -U "docapi[flask]"
pip install -U "docapi[django]"

Install from PyPI official source:

pip install -U "docapi[all]" -i https://pypi.org/simple

Install from GitHub:

pip install git+https://github.com/Shulin-Zhang/docapi

Usage Guide

Here are typical usage examples:

OpenAI Model Example

1. Set up the model and API key:

export DOCAPI_MODEL=openai:gpt-4o-mini

export OPENAI_API_KEY=your_api_key

2. Generate documentation:

  • For Flask:
docapi generate server.py

# Static route scanning, independent of the project environment.
# docapi generate server.py --static
  • For Django:
docapi generate manage.py

3. Update documentation:

  • For Flask:
docapi update server.py

# Static route scanning, independent of the project environment.
# docapi update server.py --static
  • For Django:
docapi update manage.py

4. Start a web server to display the documentation:

docapi serve

Find more usage details in the guide.


Supported Models

  • OpenAI
  • Azure OpenAI
  • XAI
  • Open-Source Models
  • Baidu Qianfan
  • Tongyi Qianwen
  • Zhipu AI

Supported Frameworks

  • Flask (>=3.0.0)
  • Django (3, 4, 5)

Example: API Documentation Web Page

image


TODO

  • Add support for additional models and frameworks.