Skip to main content

Swagger UI bundled for usage with Python

Project description

py_swagger_ui

This package contains the static files for swagger-ui as a python package.

Basic configuration options are templated with the Jinja2 templating language.

This package is intended to be webserver-agnostic, so it only includes the static files, and some very basic configuration.

Getting Started

You can import the swagger_ui_path from the py_swagger_ui package like so:

from py_swagger_ui import swagger_ui_path

You can easily serve up this directory as all static files to get the default swagger-ui distribution. Here’s an example in flask:

from py_swagger_ui import swagger_ui_path

from flask import Flask, Blueprint, send_from_directory, render_template

swagger_bp = Blueprint(
    'swagger_ui',
    __name__,
    static_url_path='',
    static_folder=swagger_ui_path,
    template_folder=swagger_ui_path
)

app = Flask(__name__, static_url_path='')
app.register_blueprint(swagger_bp, url_prefix='/ui')

if __name__ == "__main__":
    app.run()

You may wish to override some of the configuration variables. Included is a jinaj2 templated file where you can modify these parameters. You can add another route to render this template with your desired configuration like so:

SWAGGER_UI_CONFIG = {
    "openapi_spec_url": "https://petstore.swagger.io/v2/swagger.json"
}

@swagger_bp.route('/')
def swagger_ui_index():
    return render_template('index.j2', **SWAGGER_UI_CONFIG)

Have a look at example.py for a complete server for the Flask webserver.

License

Since this is just repackaging swagger-ui releases, the license comes from the swagger ui project (https://github.com/swagger-api/swagger-ui).

All vendored code is published under the Apache 2.0 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

py_swagger_ui-1.0.0.tar.gz (7.5 MB view details)

Uploaded Source

Built Distribution

py_swagger_ui-1.0.0-py3-none-any.whl (7.6 MB view details)

Uploaded Python 3

File details

Details for the file py_swagger_ui-1.0.0.tar.gz.

File metadata

  • Download URL: py_swagger_ui-1.0.0.tar.gz
  • Upload date:
  • Size: 7.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for py_swagger_ui-1.0.0.tar.gz
Algorithm Hash digest
SHA256 383da8747f57a4821f0e9ebba37d47d098f6969992de237f9c97d49c1e46fadf
MD5 32febb7ca8587ab01dc46167ef0f2871
BLAKE2b-256 496a3b53bbc4c83e320a8fb398b5969be15536927d9f52d51b49ae9eedb6faaa

See more details on using hashes here.

File details

Details for the file py_swagger_ui-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_swagger_ui-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eac09b642adbce9cdc46b02a058550dd584f9d21b2387cde96b686d6610c6cf4
MD5 9fdd300e06c848f358b825e431cf7fed
BLAKE2b-256 04268863ea96522ba274eae89b9e9d733a33f0c046a95013a41121450ecf65ca

See more details on using hashes here.

Supported by

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