Generate UI interactive API's from APISpec specifications.
Project description
A library to generate a UI interface from an APISpec specification. As per the APISpec initiative, it currently supports OpenAPI Specification (aka. Swagger specification) and SwaggerUI.
Features
Supports the OpenAPI Specification (versions 2 and 3)
Supports SwaggerUI for Swagger specifications (latest version - 4.0.0)
Currently supported frameworks include:
Flask
Installation
Install the package directly from PyPI (recommended):
$ pip install -U apispec-ui
Plugin dependencies like apispec and Flask are not installed with the package by default. To have it installed, do like so:
$ pip install -U apispec-ui[apispec,Flask]
Example usage
A simple example on how to work with a Flask application:
from apispec import APISpec
from apispec.ext.marshmallow import MarshmallowPlugin
from apispec_plugins import FlaskPlugin
from apispec_ui.flask import Swagger
from flask import Flask
app = Flask(__name__)
apispec = APISpec(
title="Test API",
version="0.1.0",
openapi_version="3.0.3",
plugins=(FlaskPlugin(), MarshmallowPlugin()), # optional
)
...
Swagger(app=app, apispec=apispec, config={})
With this example, the application contains 2 extra views:
swagger.ui: endpoint to serve SwaggerUI
swagger.specs: endpoint to serve swagger specs, in yaml
With configs parameter one can tweak some parameters:
config = {
"swaggerui": True, # enable/disable SwaggerUI
"swagger_route": "/api/", # change swagger routes
"swagger_static": "/static/", # change location for static files
"swagger_favicon": "favicon.ico", # change favicon
"swagger_hide_bar": True, # hide SwaggerUI top bar
}
These settings can also be configured through the SWAGGER config variable that is part of the app config.
In terms of precedence, the config that takes the most precedence is the config parameter from Swagger class, followed by the SWAGGER app config.
Tests & linting
Run tests with tox:
# ensure tox is installed
$ tox
Run linter only:
$ tox -e lint
Optionally, run coverage as well with:
$ tox -e coverage
License
MIT licensed. See LICENSE.
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
Built Distribution
Hashes for apispec_ui-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a36be49bc00e34f943d266a59290246434afeb8a7203ef68e46fb723ff79c408 |
|
MD5 | 86bc151430c55956b5b087da843e3245 |
|
BLAKE2b-256 | 58131b21a43741e882df6b4c8d3fdf752c1b1fe3e17793ec8876018777eee854 |