Flask-OpenAPI3-Swagger

5.31.0 · active · verified Sat Apr 11

Flask-OpenAPI3-Swagger is a Python library that provides the Swagger UI for Flask-OpenAPI3, enabling interactive API documentation directly within Flask applications. It acts as an optional plugin for Flask-OpenAPI3, automatically providing Swagger UI integration once installed. The library is currently in version 5.31.0 and follows a regular release cadence as part of the wider Flask-OpenAPI3 ecosystem.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic Flask application with `flask-openapi3` and enable Swagger UI. Once `flask-openapi3-swagger` is installed, simply configuring the `OpenAPI` app from `flask_openapi3` automatically makes the Swagger UI available at the specified path (or default `/openapi/swagger`).

from flask import Flask
from flask_openapi3 import OpenAPI, Info, Tag
import os

info = Info(title="Flask API", version="1.0.0", description="A simple Flask OpenAPI3 application.")
tags = [
    Tag(name="hello", description="Hello world endpoints"),
]

app = OpenAPI(__name__, info=info, tags=tags)

# Configure Swagger UI path (optional, default is /openapi/swagger)
app.config["OPENAPI_SWAGGER_UI_PATH"] = "/swagger-ui"


@app.get("/hello", tags=["hello"])
def hello():
    """Say Hello
    Gets a greeting message.
    ---
    responses:
        200:
            description: A greeting message.
    """
    return {"message": "Hello, World!"}


if __name__ == "__main__":
    # Run with `flask run` or `python app.py`
    # Access Swagger UI at http://127.0.0.1:5000/swagger-ui/
    app.run(debug=True)

view raw JSON →