Skip to main content

Swagger UI for Python web framework, such Tornado, Flask, Quart, Sanic and Falcon.

Project description

swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask, Quart, aiohttp, Sanic and Falcon.

Only support Python3.

Supported

  • tornado
  • flask
  • sanic
  • aiohttp
  • quart
  • starlette
  • falcon
  • bottle

Usage

  • Install

    pip3 install swagger-ui-py
    
  • Code

    Using the local config file

    from swagger_ui import api_doc
    api_doc(app, config_path='./config/test.yaml', url_prefix='/api/doc', title='API doc')
    

    Or using config url, but need to suport CORS

    api_doc(app, config_url='https://petstore.swagger.io/v2/swagger.json', url_prefix='/api/doc', title='API doc')
    

    Or using the config spec string

    from swagger_ui import api_doc
    spec_string = '{"openapi":"3.0.1","info":{"title":"python-swagger-ui test api","description":"python-swagger-ui test api","version":"1.0.0"},"servers":[{"url":"http://127.0.0.1:8989/api"}],"tags":[{"name":"default","description":"default tag"}],"paths":{"/hello/world":{"get":{"tags":["default"],"summary":"output hello world.","responses":{"200":{"description":"OK","content":{"application/text":{"schema":{"type":"object","example":"Hello World!!!"}}}}}}}},"components":{}}'
    
    api_doc(app, config_spec=spec_string, url_prefix='/api/doc', title='API doc')
    

    Or using the config dict

    from swagger_ui import api_doc
    config = {"openapi":"3.0.1","info":{"title":"python-swagger-ui test api","description":"python-swagger-ui test api","version":"1.0.0"},"servers":[{"url":"http://127.0.0.1:8989/api"}],"tags":[{"name":"default","description":"default tag"}],"paths":{"/hello/world":{"get":{"tags":["default"],"summary":"output hello world.","responses":{"200":{"description":"OK","content":{"application/text":{"schema":{"type":"object","example":"Hello World!!!"}}}}}}}},"components":{}}
    
    api_doc(app, config=config, url_prefix='/api/doc', title='API doc')
    

    And suport config file with editor

    api_doc(app, config_path='./config/test.yaml', editor=True)
    

    And keep the old way

    # for Tornado
    from swagger_ui import tornado_api_doc
    tornado_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
    # for Sanic
    from swagger_ui import sanic_api_doc
    sanic_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
    # for Flask
    from swagger_ui import flask_api_doc
    flask_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
    # for Quart
    from swagger_ui import quart_api_doc
    quart_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
    # for aiohttp
    from swagger_ui import aiohttp_api_doc
    aiohttp_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
    # for Falcon
    from swagger_ui import falcon_api_doc
    falcon_api_doc(app, config_path='./conf/test.yaml', url_prefix='/api/doc', title='API doc')
    
  • Edit Swagger config file (JSON or YAML)

    Please see https://swagger.io/resources/open-api/.

  • Access

    Open http://<host>:<port>/api/doc/editor, you can edit api doc config file.

    Open http://<host>:<port>/api/doc view api doc.

Swagger UI

Swagger UI version is 3.25.1. see https://github.com/swagger-api/swagger-ui.

Swagger Editor

Swagger Editor version is 3.8.1. see https://github.com/swagger-api/swagger-editor.

Update

You can update swagger ui and swagger editor version with

cd swagger-ui-py/tools
python update.py ui
# or
python update.py editor

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

swagger_ui_py-0.4.0-py3-none-any.whl (7.2 MB view details)

Uploaded Python 3

File details

Details for the file swagger_ui_py-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: swagger_ui_py-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.6

File hashes

Hashes for swagger_ui_py-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 de1de4d9e77e3156a323853188cde3ef373eabd61f294f1ae67566ba9eef67fc
MD5 870b9dfaa034a6c1498ae45d9b92e561
BLAKE2b-256 344fa483a8c2a536568d34c53728d460a1749655b646ae73593d71071779b24d

See more details on using hashes here.

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