Skip to main content

aws-flask-swagger-ui

Tests Status Release Status

Simple Flask blueprint for adding Swagger UI to your flask application. Including a WSGI adapter for AWS API Gateway/Lambda Proxy Integration to allows you to use WSGI-compatible middleware and frameworks like Flask and Django with the AWS API Gateway/Lambda proxy integration for your Swagger documentation.

Included Swagger UI version: see here

Installation

pip install aws-flask-swagger-ui

Usage

Simple usage example is shown below for more options check the file extend examples:

from flask import Flask
from aws_flask_swagger_ui import get_swaggerui_blueprint, flask_ui_response

app = Flask(__name__)

swaggerui_blueprint = get_swaggerui_blueprint(
    "/api-doc",
    aws_gw_config={
        "exportType": "oas30",
        "parameters": {
            "extensions": "integrations",
            "extensions": "apigateway",
            "extensions": "authorizers",
        },
    },
)

app.register_blueprint(swaggerui_blueprint)


def lambda_handler(event, context):
    return flask_ui_response(app, event, context, base64_content_types={"image/png"})

AWS Gateway Configuration

http://mysite.com = https://restApiId.execute-api.region.amazonaws.com/stage/

In order that the above example works correctly the Lambda function must be connected as Proxy to the endpoint http://mysite.com/api-doc/

Configure your API Gateway with a {proxy+} resource with an ANY method. Your "Method Response" should likely include an application/json "Response Body for 200" that uses the Empty model.

Because API Gateway doesn't match the root folder with {proxy+} definition, your default URL should contain index.html. It is suggested to create a mock integration on your path /api-doc to return a 301. (ex: /api-doc => 301 => /api-doc/index.html) Source code based on Terraform to achieve this can be found in this article.

Lambda Test Event

The Lambda function must have the permissions to export the API definition!

If you wish to use the "Test" functionality in Lambda for your function, you will need a "API Gateway AWS Proxy" event. Check the event JSON objects in the events folder.

To update your test event, click "Actions" -> "Configure test event".

Within the Events you need to update the "apiId" and "stage" with values for your AWS account.

Protect documentation with password

If you create an environment variable like, SWAGGER_PASSWORD=abc

Then you will need to pass a query parameter in the URL like, http://mysite.com/api-doc/?pass=abc

If you don't have the environment variable then endpoint is not password protected and you can access it as per normal http://mysite.com/api-doc/

Configuration

The blueprint supports overloading all Swagger UI configuration options that can be JSON serialized. See swagger-ui configuration for options.

Plugins and function parameters are not supported at this time.

OAuth2 parameters can be found at swagger-ui oauth2.

License

This library is licensed under the Apache 2.0 License.

Test

  • Clone the repo and run pytest
git clone https://github.com/tb102122/aws_flask_swagger_ui.git
python -m venv virtualenv
virtualenv/bin/activate
pip install --upgrade pip, setuptools, wheel
pip install flake8 pytest boto3 pytest-cov
pip install .
flake8 .
pytest

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_flask_swagger_ui-1.2.2.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aws_flask_swagger_ui-1.2.2-py3-none-any.whl (3.2 MB view details)

Uploaded Python 3

File details

Details for the file aws_flask_swagger_ui-1.2.2.tar.gz.

File metadata

  • Download URL: aws_flask_swagger_ui-1.2.2.tar.gz
  • Upload date:
  • Size: 3.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for aws_flask_swagger_ui-1.2.2.tar.gz
Algorithm Hash digest
SHA256 1a2c4044ebec4a6a1a632cf4c25f475cd7d129360337b795289e5bcb1fd3af36
MD5 28d23f0f2f3ac1b6317fac15ad1bbdb0
BLAKE2b-256 571cdc12dcd479dc4737e738502f606c15c2c8c048169a47ce101b6386888793

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_flask_swagger_ui-1.2.2.tar.gz:

Publisher: py-publish.yml on tb102122/aws_flask_swagger_ui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aws_flask_swagger_ui-1.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for aws_flask_swagger_ui-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 485f292ea7f34f43dcc5a454088d223230e95eae79fd4345f607ea3a0b327541
MD5 b9ad161d5341d03b2b51e4fb463328b3
BLAKE2b-256 33b83dcaf9f15752f2803eedbca0cd82dc9b3e5a2fc2d9cf6371eb8350c30bc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for aws_flask_swagger_ui-1.2.2-py3-none-any.whl:

Publisher: py-publish.yml on tb102122/aws_flask_swagger_ui

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page