Registry / web-framework / swagger-ui-py

swagger-ui-py

JSON →
library25.7.1pypypi✓ verified 82d ago

A library to easily integrate Swagger UI and Swagger Editor into Python web frameworks (Tornado, Flask, Quart, Sanic, Falcon). Current version 25.7.1. Releases follow CalVer, approximately monthly.

pip install swagger-ui-py
INSTALL
IMPORT
SIG · SWAGGER-UI-PY
S
swagger-ui-py
web-frameworkpythonv25.7.1
Install
2.2s avg
Import
Disk
45MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v25.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 46.4MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.000s · 48MB
45MB installed
● package 45MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

api_doc
from swagger_ui import api_doc
from swagger_ui import get_swagger_ui_html
flask_api_doc
from swagger_ui import flask_api_doc
tornado_api_doc
from swagger_ui import tornado_api_doc

Integrate Swagger UI in a Flask app using the api_doc function.

from flask import Flask, jsonify, send_from_directory from swagger_ui import api_doc app = Flask(__name__) @app.route('/spec') def spec(): return jsonify({ "openapi": "3.0.0", "info": {"title": "Sample API", "version": "1.0.0"}, "paths": {} }) # Serve swagger UI at /docs, with spec at /spec api_doc(app, config={'spec_url': '/spec'}) if __name__ == '__main__': app.run()
Debug
Known issues
breakingThe `api_doc` function signature changed in v25.x. Previously it accepted `config_spec` and other keyword arguments; now it expects a `config` dictionary.
fix
Use `api_doc(app, config={'spec_url': '/spec'})` instead of old `api_doc(app, spec_url='/spec')`.
affects: >=25.0.0
deprecatedThe old `swagger-ui` import path (without underscore) is deprecated. Use `swagger_ui` (with underscore) as the package name.
fix
Change `import swagger_ui` to correct spelling: `from swagger_ui import ...`.
affects: all
gotchaIf using Falcon, the `resp.body` attribute was deprecated in Falcon 3.0+. In v25.7.1, the library correctly uses `resp.text`, but older versions (<25.7.1) may trigger a DeprecationWarning or error with Falcon >=3.0.
fix
Update to swagger-ui-py >=25.7.1 or pin Falcon <3.0.
affects: <25.7.1
gotchaThe `custom_css` parameter introduced in v25.7.1 expects a string path or URL to a CSS file, not the CSS content itself. Passing CSS content directly will cause a 404 or broken styling.
fix
Use `custom_css='/path/to/custom.css'` or a URL, not inline CSS.
affects: >=25.7.1
deprecatedThe `host_injection` parameter is deprecated as of v23.9.23; use `config` dictionary to disable host injection.
fix
Set `config={'disable_host_injection': True}` in `api_doc`.
affects: >=23.9.23
Upgrade
Version history
25.7.1latest on PyPI · released Jul 1, 2025
Audit
Dependencies
tornadooptionalRequired for Tornado support
flaskoptionalRequired for Flask support
quartoptionalRequired for Quart support
sanicoptionalRequired for Sanic support
falconoptionalRequired for Falcon support
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
swagger-ui-py — pip install swagger-ui-py · libregistry