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
Support for the OpenAPI Specification (versions 2 and 3)
Compatibility with SwaggerUI (latest version - 4.18.1)
Support for frameworks which include:
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 apispec and Flask installed, run:
$ 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="Pet Store",
version="1.0.0",
openapi_version="3.1.0",
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
File details
Details for the file apispec_ui-1.0.0.tar.gz
.
File metadata
- Download URL: apispec_ui-1.0.0.tar.gz
- Upload date:
- Size: 2.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1034-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 460c116ae91dbbdbc29e49143d015283b296063fe9c52f6326ffe294b9f669cd |
|
MD5 | 85336b922d8cda67fd770cebf4245cbc |
|
BLAKE2b-256 | cb200a8dbfc4778787285396595566bb499f4a6b7caa0ddc1bebc3c1ca8394da |
File details
Details for the file apispec_ui-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: apispec_ui-1.0.0-py3-none-any.whl
- Upload date:
- Size: 2.6 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.9.16 Linux/5.15.0-1034-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6759e4cf7c8e91e0f6279a666a48995a943f5c914f7624332710370549b8b595 |
|
MD5 | 3192cad96245e1c028ef6b9480975ef5 |
|
BLAKE2b-256 | 6d5dcb43a00b08c6b1e70d0f3aa67e3327af4fccf90dd77b350f5faab01eb449 |