Flask-Swagger-UI

5.32.2 · maintenance · verified Tue Apr 14

Flask-Swagger-UI is a Python library that provides a simple Flask blueprint to integrate Swagger UI into your Flask applications. It currently bundles Swagger UI version 5.32.1. While the project is not actively maintained, it receives occasional updates to keep the bundled Swagger UI version current. Users requiring more active development or specific new features might consider forking the repository.

Warnings

Install

Imports

Quickstart

This example sets up a basic Flask application and registers the Swagger UI blueprint, pointing to a remote OpenAPI specification. After running, navigate to `/api/docs` in your browser to see the Swagger UI.

from flask import Flask
from flask_swagger_ui import get_swaggerui_blueprint

app = Flask(__name__)

SWAGGER_URL = '/api/docs'  # URL for exposing Swagger UI (without trailing '/')
API_URL = 'https://petstore.swagger.io/v2/swagger.json'  # Our API url (can of course be a local resource)

# Call factory function to create our blueprint
swaggerui_blueprint = get_swaggerui_blueprint(
    SWAGGER_URL,  # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
    API_URL,
    config={
        'app_name': 'Test application'
    }
)

app.register_blueprint(swaggerui_blueprint)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(debug=True)

view raw JSON →