Automatically create Python API documentation with Sphinx

Creating Python API documentation with Sphinx

It is convenient if you can see the API document of the class you are making while making a program So, I summarized how to automatically create and browse API documents for Python modules using Sphinx.

environment

Linux (I did it on CentOS 6.6 this time) Python 2.7 (with pip installed)

Put Sphinx

Sphinx is a document creation tool. (By the way, it's written in Python.) In short, it's a tool that makes it easy to create "intelligent and beautiful documents." Reference: http://docs.sphinx-users.jp/

With pip, it's easy to install.

$ pip install sphinx

Prepare to automatically generate API documentation

I did it with the following directory structure.

- project #Python project
   |
   |- src #A directory of Python code for which you want to automatically generate API documentation
   |   |- __init__.py or something
   |   |- hoge #Submodules
   |
   |- docs #Sphinx project directory

Create a Sphinx project for your API documentation in the docs directory. This can be created with a single command.

$ cd project
$ sphinx-apidoc -F -o docs/ src/

In the "-o" option of the sphinx-apidoc command, specify the directory where you want to create the Sphinx project, and in the last argument, specify the directory of the Python source where you want to generate the API document. (The "-F" option seems to be an option to create a full-featured Sphinx project. I'll add it for now.)

Now you are ready to generate the API documentation from the Python source under the src directory. (Early

Create an API document from your own Python source.

Go into the docs directory and run the make command.

$ cd docs
$ make html

This will create an API document from your Python source.

By the way, if you update the source code Do "make html" again to get the latest API documentation.

View API documentation

docs/_build/html An HTML file is created under it. "Index.html" is the home page.

If you can see it locally, open it in your browser.

There is no GUI on the remote VM! Who says

$ cd _build/html
$ python -m SimpleHTTPServer

So, if you set up a simple web server, you can see it remotely. It's just simple and there seems to be no cache, so HTML file update (make html) → browser update (F5) You can see the latest information at.

reference

I found it in the middle of writing.

http://qiita.com/icoxfog417/items/9e2eb932b61aa9b9e427

If you want to know more details, please see ↑.

Recommended Posts

Automatically create Python API documentation with Sphinx
Automatically build Python documentation with Sphinx
Create Awaitable with Python / C API
Create Python project documentation in Sphinx
Write documentation in Sphinx with Python Livereload
[Python] Quickly create an API with Flask
Try to automatically generate Python documents with Sphinx
Create an API server quickly with Python + Falcon
Use Trello API with python
Create an API with Django
Use Twitter API with Python
Create 3d gif with python3
Web API with Python + Falcon
Play RocketChat with API / Python
Call the API with python3.
Use subsonic API with python3
Create a directory with python
Compile Sphinx documentation with Wercker
[LINE Messaging API] Create parrot return BOT with Python
Create a Mastodon bot with a function to automatically reply with Python
Create API with Python, lambda, API Gateway quickly using AWS SAM
[AWS] Create API with API Gateway + Lambda
Get reviews with python googlemap api
Create folders from '01' to '12' with python
Run Rotrics DexArm with python API
Quine Post with Qiita API (Python)
Create a virtual environment with Python!
Create an Excel file with Python3
Hit the Etherpad-lite API with Python
Create Gmail in Python without API
[python] Read information with Redmine API
Create API using hug with mod_wsgi
[Python] Create API to send Gmail
Create REST API that returns the current time with Python3 + Falcon
[LINE Messaging API] Create a BOT that connects with someone with Python
Collecting information from Twitter with Python (Twitter API)
Create a Python function decorator with Class
Create wordcloud from your tweet with python3
Build a blockchain with Python ① Create a class
Simple Slack API client made with Python
Create a dummy image with Python + PIL.
Retrieving food data with Amazon API (Python)
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
Quickly create an excel file with Python #python
Create Python module [CarSensor API support module csapi]
HTML document your Python program with Sphinx
Create Python + uWSGI + Nginx environment with Docker
Create and decrypt Caesar cipher with python
Automatically aggregate JCG deck distribution with Python
Get started with the documentation tool Sphinx
Create miscellaneous Photoshop videos with Python + OpenCV ③ Create miscellaneous Photoshop videos
Create Excel file with Python + similarity matrix
Create a word frequency counter with Python 3.4
Create an English word app with python
[Python] Automatically operate the browser with Selenium
Serverless face recognition API made with Python
Create Page / Todo Block with Notion API
[Python] Get Python package information with PyPI API
Challenge to create time axis list report with Toggl API and Python
Create a tool to automatically furigana with html using Mecab from Python3