Documentation generator for flask
Project description
Flask-Autodoc
=============
Flask-Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes, function arguments and docstrings.
[![Build](https://api.travis-ci.org/acoomans/flask-autodoc.png)](https://travis-ci.org/acoomans/flask-autodoc)
[![Pypi version](http://img.shields.io/pypi/v/flask-autodoc.svg)](https://pypi-hypernode.com/pypi/Flask-Autodoc)
[![Pypi license](http://img.shields.io/pypi/l/flask-autodoc.svg)](https://pypi-hypernode.com/pypi/Flask-Autodoc)
![Python 2](http://img.shields.io/badge/python-2-blue.svg)
![Python 3](http://img.shields.io/badge/python-3-blue.svg)
## Requirements
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
## Install
To install Flask-Autodoc, run pip:
pip install flask-autodoc
or clone this directory and run setup:
python setup.py install
## Usage
Start using Flask-Autodoc by importing it and initializing it:
from flask import Flask
from flask.ext.autodoc import Autodoc
app = Flask(__name__)
auto = Autodoc(app)
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
@app.route('/user/<int:id>')
@auto.doc()
def show_user(id):
return user_from_database(id)
to generate the documentation, use the _html()_ method:
@app.route('/documentation')
def documentation():
return auto.html()
## Custom documentation
To access the documentation without rendering html:
@app.route('/documentation')
def documentation():
return auto.generate()
the documentation will be returned as a list of rules, where each rule is a dictionary containing:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function name (ie 'show_user')
- doc: docstring of the function
- args: function arguments
- defaults: defaults values for the arguments
## Custom template
To use a custom template for your documentation, give a _template_ argument to the _html_ method. This will use a template from the flask _templates_ directory.
Additionnal arguments (other than _group_, _groups_, and _template_) will be passed down to the template:
auto.html(
template='custom_documentation.html'
title='My Documentation',
author='John Doe',
)
_title_ and _author_ will be available in the template:
<!-- templates/custom_documentation.html -->
...
{% if title is defined %}
{{title}}
{% endif %}
...
## Documentation sets
Endpoints can be grouped together in different documentation sets. It is possible for instance to show some endpoints to third party developers and have full documentation for primary developers.
To assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
@app.route('/user/<int:id>')
@auto.doc('public')
def show_user(id):
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
@app.route('/user/<int:id>')
@auto.doc(groups=['public','private'])
def show_user(id):
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
auto.html('public')
auto.html(groups=['public','private'])
auto.generate('public')
## Examples
Apps in the _examples_ directory are an api for a blog:
- _simple_ is a simple app
- _factory_ uses blueprints
Run with
python simple/blog.py
and connect to [/doc/public](http://127.0.0.1:5000/doc/public) and [/doc/private](http://127.0.0.1:5000/doc/private) to see public and private documentations.
## Screenshots
![screenshots](screenshots/screenshot00.png)
![screenshots](screenshots/screenshot01.png)
=============
Flask-Autodoc is a Flask extension that automatically creates documentation for your endpoints based on the routes, function arguments and docstrings.
[![Build](https://api.travis-ci.org/acoomans/flask-autodoc.png)](https://travis-ci.org/acoomans/flask-autodoc)
[![Pypi version](http://img.shields.io/pypi/v/flask-autodoc.svg)](https://pypi-hypernode.com/pypi/Flask-Autodoc)
[![Pypi license](http://img.shields.io/pypi/l/flask-autodoc.svg)](https://pypi-hypernode.com/pypi/Flask-Autodoc)
![Python 2](http://img.shields.io/badge/python-2-blue.svg)
![Python 3](http://img.shields.io/badge/python-3-blue.svg)
## Requirements
Flask-Autodoc is compatible with Python versions 2 and 3; and it depends only on Flask.
## Install
To install Flask-Autodoc, run pip:
pip install flask-autodoc
or clone this directory and run setup:
python setup.py install
## Usage
Start using Flask-Autodoc by importing it and initializing it:
from flask import Flask
from flask.ext.autodoc import Autodoc
app = Flask(__name__)
auto = Autodoc(app)
by default, Flask-Autodoc will only document the routes explicitly decorated with _doc_:
@app.route('/user/<int:id>')
@auto.doc()
def show_user(id):
return user_from_database(id)
to generate the documentation, use the _html()_ method:
@app.route('/documentation')
def documentation():
return auto.html()
## Custom documentation
To access the documentation without rendering html:
@app.route('/documentation')
def documentation():
return auto.generate()
the documentation will be returned as a list of rules, where each rule is a dictionary containing:
- methods: the set of allowed methods (ie ['GET', 'POST'])
- rule: relative url (ie '/user/<int:id>')
- endpoint: function name (ie 'show_user')
- doc: docstring of the function
- args: function arguments
- defaults: defaults values for the arguments
## Custom template
To use a custom template for your documentation, give a _template_ argument to the _html_ method. This will use a template from the flask _templates_ directory.
Additionnal arguments (other than _group_, _groups_, and _template_) will be passed down to the template:
auto.html(
template='custom_documentation.html'
title='My Documentation',
author='John Doe',
)
_title_ and _author_ will be available in the template:
<!-- templates/custom_documentation.html -->
...
{% if title is defined %}
{{title}}
{% endif %}
...
## Documentation sets
Endpoints can be grouped together in different documentation sets. It is possible for instance to show some endpoints to third party developers and have full documentation for primary developers.
To assign an endpoint to a group, pass the name of the group as argument of the _doc_ decorator:
@app.route('/user/<int:id>')
@auto.doc('public')
def show_user(id):
to assign an endpoint to multiple groups, pass a list of group names as the _groups_ argument to _doc_:
@app.route('/user/<int:id>')
@auto.doc(groups=['public','private'])
def show_user(id):
to generate the documentation for a specific group, pass the name of the group to the _html_ or _generate_ methods:
auto.html('public')
auto.html(groups=['public','private'])
auto.generate('public')
## Examples
Apps in the _examples_ directory are an api for a blog:
- _simple_ is a simple app
- _factory_ uses blueprints
Run with
python simple/blog.py
and connect to [/doc/public](http://127.0.0.1:5000/doc/public) and [/doc/private](http://127.0.0.1:5000/doc/private) to see public and private documentations.
## Screenshots
![screenshots](screenshots/screenshot00.png)
![screenshots](screenshots/screenshot01.png)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Flask-Autodoc-0.1.2.tar.gz
(5.5 kB
view details)
File details
Details for the file Flask-Autodoc-0.1.2.tar.gz
.
File metadata
- Download URL: Flask-Autodoc-0.1.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 364468726b8a4579959685d696a078ff59f589ab3963f537427a8400dcddf403 |
|
MD5 | d08809434c4102ebe7440f5ed75b3279 |
|
BLAKE2b-256 | ecfdcba920b70474b236e6033adcd979d04db221b7278cb7c442a867b669596d |