Skip to main content

DocAPI is a Python package that automatically generates API documentation using LLM, with support for both Flask and Django frameworks.

Project description

image

Python Version OS Lisence PyPI GitHub pull request

[ English | 中文 ]

DocAPI is a Python package that uses LLM to automatically generate API documentation.

Features

  • The Flask framework supports automatic scanning of the routing structure of API services;

  • Supports a variety of mainstream commercial and open source models at home and abroad;

  • Supports automatic document generation and partial document update;

  • Support API documentation in multiple languages ​​(requires large model support);

  • Supports web page deployment to display API documentation.

Changelog

  • [2024-11-17] Support Zhipu AI, Baidu Qianfan model, optimize document structure, and add javascript code examples; Remove the execution mode that uses the configuration file.

  • [2024-11-20] Support custom document templates.

  • [2024-11-24] Support multi-threaded acceleration requests.

  • [2024-11-26] Support .env to load environment variables and multi-language documents.

Installation

pip install -U docapi

or

pip install -U docapi -i https://pypi.org/simple

GitHub source code installation

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

Usage

Automatically scan the routing structure. This is only valid for flask projects and must be used in the environment of api projects.

OpenAI:

export OPENAI_API_KEY=api_key

export OPENAI_API_MODEL=gpt-4o-mini

# Generate documents
docapi generate server.py --lang en

# Update documents
docapi update server.py --lang en

# Start web service
docapi serve

Azure OpenAI:

export AZURE_OPENAI_API_KEY=api_key

export AZURE_OPENAI_ENDPOINT=endpoint

export OPENAI_API_VERSION=version

export AZURE_OPENAI_MODEL=gpt-4o-mini

# 生成文档
docapi generate server.py --template <template_path>

# 更新文档
docapi update server.py --template <template_path>

# 启动web服务
docapi serve docs --ip 0.0.0.0 --port 9000

Qianwen, Open source deployment:

export OPENAI_API_KEY=api_key

export OPENAI_API_BASE=api_base_url

export OPENAI_API_MODEL=model_name

# Generate documents
docapi generate server.py --lang en --workers 6

# Update documents
docapi update server.py --lang en --workers 6

# Start web service
docapi serve

Baidu Qianfan:

export QIANFAN_ACCESS_KEY=access_key

export QIANFAN_SECRET_KEY=secret_key

export QIANFAN_MODEL=ERNIE-3.5-8K

# Generate documents
docapi generate server.py --lang en

# Update documents
docapi update server.py --lang en

# Start web service
docapi serve

ZhipuAI:

export ZHIPUAI_API_KEY=api_key

export ZHIPUAI_MODEL=glm-4-flash

# Generate documents
docapi generate server.py

# Update documents
docapi update server.py

# Start web service
docapi serve

.env environment variable file:

# .env
OPENAI_API_KEY='xxx'
OPENAI_API_BASE='xxx'
OPENAI_API_MODEL='xxx'
# Generate documents
docapi generate server.py --env .env

Code calls

import os
from docapi import DocAPI

os.environ['OPENAI_API_KEY'] = "api_key"
os.environ['OPENAI_API_BASE'] = "api_base"
os.environ['OPENAI_API_MODEL'] = "model_name"

docapi = DocAPI.build(lang="en")

docapi.generate("flask_project/flask_server.py", "docs")

# docapi.update("flask_project/flask_server.py", "docs")

# docapi.serve("docs", ip="127.0.0.1", port=8080)

Supported Models

  • OpenAI

  • AzureOpenAI

  • Tongyi Qianwen

  • Zhipu AI

  • Baidu Qianfan

  • Open source model

Supported API Frameworks

  • Flask

Automatic scanning is only valid for the Flask framework and is recommended for use on Flask services.

API Web Page

image

TODO

  • Supports large models such as Wenxin Yiyan and Zhipu AI.

  • Supports online web page display of documents.

  • Supports custom document templates.

  • Multithreading accelerates requests.

  • Supports automatic scanning of frameworks such as Django.

  • Import to postman.

  • Support Windows operating system.

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

docapi-0.1.7.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

docapi-0.1.7-py3-none-any.whl (20.7 kB view details)

Uploaded Python 3

File details

Details for the file docapi-0.1.7.tar.gz.

File metadata

  • Download URL: docapi-0.1.7.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.2 Darwin/21.6.0

File hashes

Hashes for docapi-0.1.7.tar.gz
Algorithm Hash digest
SHA256 a1431299844ff474168c7dd3f943c760e9bbd1d61fa2be22329622621d3e83f6
MD5 54096b8ca3bc9703259f3721cb8c64cd
BLAKE2b-256 d2fe61eb67f48d85101e0ae016038f3f056f7f5480320be9f1a240c7c9227659

See more details on using hashes here.

File details

Details for the file docapi-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: docapi-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 20.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.2 Darwin/21.6.0

File hashes

Hashes for docapi-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 e317360d6f9b0d3c866cd80b6d7baa068b8bff7e1807fe772909d46fe0b86044
MD5 d336529ab81235d2ddc6252b0563e36e
BLAKE2b-256 ff212d3abca5992461da643b3385c9b92a1f6f329b4f5c23d13d13cfac85957f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page