{"id":22430,"library":"swagger-ui-py","title":"Swagger UI for Python","description":"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.","status":"active","version":"25.7.1","language":"python","source_language":"en","source_url":"https://github.com/PWZER/swagger-ui-py","tags":["swagger","openapi","flask","tornado","sanic","quart","falcon","api-documentation"],"install":[{"cmd":"pip install swagger-ui-py","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Required for Tornado support","package":"tornado","optional":true},{"reason":"Required for Flask support","package":"flask","optional":true},{"reason":"Required for Quart support","package":"quart","optional":true},{"reason":"Required for Sanic support","package":"sanic","optional":true},{"reason":"Required for Falcon support","package":"falcon","optional":true}],"imports":[{"note":"","wrong":"","symbol":"get_swagger_ui_html","correct":"from swagger_ui import get_swagger_ui_html"},{"note":"","wrong":"","symbol":"get_swagger_editor_html","correct":"from swagger_ui import get_swagger_editor_html"},{"note":"","wrong":"","symbol":"swagger_ui_path","correct":"from swagger_ui import swagger_ui_path"},{"note":"","wrong":"","symbol":"swagger_editor_path","correct":"from swagger_ui import swagger_editor_path"}],"quickstart":{"code":"from flask import Flask, jsonify, send_from_directory\nfrom swagger_ui import api_doc\n\napp = Flask(__name__)\n\n@app.route('/spec')\ndef spec():\n    return jsonify({\n        \"openapi\": \"3.0.0\",\n        \"info\": {\"title\": \"Sample API\", \"version\": \"1.0.0\"},\n        \"paths\": {}\n    })\n\n# Serve swagger UI at /docs, with spec at /spec\napi_doc(app, config={'spec_url': '/spec'})\n\nif __name__ == '__main__':\n    app.run()","lang":"python","description":"Integrate Swagger UI in a Flask app using the api_doc function."},"warnings":[{"fix":"Use `api_doc(app, config={'spec_url': '/spec'})` instead of old `api_doc(app, spec_url='/spec')`.","message":"The `api_doc` function signature changed in v25.x. Previously it accepted `config_spec` and other keyword arguments; now it expects a `config` dictionary.","severity":"breaking","affected_versions":">=25.0.0"},{"fix":"Change `import swagger_ui` to correct spelling: `from swagger_ui import ...`.","message":"The old `swagger-ui` import path (without underscore) is deprecated. Use `swagger_ui` (with underscore) as the package name.","severity":"deprecated","affected_versions":"all"},{"fix":"Update to swagger-ui-py >=25.7.1 or pin Falcon <3.0.","message":"If 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.","severity":"gotcha","affected_versions":"<25.7.1"},{"fix":"Use `custom_css='/path/to/custom.css'` or a URL, not inline CSS.","message":"The `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.","severity":"gotcha","affected_versions":">=25.7.1"},{"fix":"Set `config={'disable_host_injection': True}` in `api_doc`.","message":"The `host_injection` parameter is deprecated as of v23.9.23; use `config` dictionary to disable host injection.","severity":"deprecated","affected_versions":">=23.9.23"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install: `pip install swagger-ui-py`. Import: `from swagger_ui import ...`.","cause":"Package installed as `swagger-ui-py` but imported as `swagger_ui`. If you see this error, the package might not be installed, or you used the wrong import name (e.g., `import swagger-ui`).","error":"ModuleNotFoundError: No module named 'swagger_ui'"},{"fix":"Use `api_doc(app, config={'spec_url': '/spec'})`.","cause":"In v25.x, `api_doc` changed from accepting keyword arguments to accepting a `config` dictionary.","error":"TypeError: api_doc() got an unexpected keyword argument 'spec_url'"},{"fix":"Upgrade to swagger-ui-py >=25.7.1.","cause":"Using Falcon >=3.0 with swagger-ui-py <25.7.1, where the library still used the deprecated `resp.body` attribute.","error":"AttributeError: 'Response' object has no attribute 'body'"},{"fix":"Always import as `from swagger_ui import ...`.","cause":"The hyphen in the package name causes confusion; the importable module uses underscore.","error":"swagger-ui is not a package (no import 'swagger-ui')"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}