{"id":2300,"library":"swagger-ui-bundle","title":"Swagger UI Bundle","description":"Swagger UI bundle provides the static files for Swagger UI, making it easy to integrate into Python web frameworks without needing to manage frontend assets. It ships a specific version of Swagger UI, which is then served by the user's web application. The current version is 1.1.0. Release cadence is infrequent, typically aligning with significant upstream Swagger UI updates or maintenance.","status":"active","version":"1.1.0","language":"en","source_language":"en","source_url":"https://github.com/spec-first/swagger_ui_bundle","tags":["swagger","openapi","api documentation","web framework","static files","flask","fastapi"],"install":[{"cmd":"pip install swagger-ui-bundle Flask Jinja2","lang":"bash","label":"With a common web framework"}],"dependencies":[],"imports":[{"note":"The function name changed to a simpler variable representing the path.","wrong":"from swagger_ui_bundle import get_swagger_ui_bundle_path","symbol":"swagger_ui_path","correct":"from swagger_ui_bundle import swagger_ui_path"}],"quickstart":{"code":"import os\nfrom flask import Flask, render_template_string, send_from_directory\nfrom swagger_ui_bundle import swagger_ui_path\n\napp = Flask(__name__)\n\n# 1. Route to serve Swagger UI static files\n@app.route('/swagger-ui-assets/<path:filename>')\ndef serve_swagger_ui_assets(filename):\n    return send_from_directory(swagger_ui_path, filename)\n\n# 2. Route to serve your OpenAPI specification (example)\n@app.route('/openapi.json')\ndef serve_openapi_spec():\n    return {\n        \"openapi\": \"3.0.0\",\n        \"info\": {\"title\": \"Sample API\", \"version\": \"1.0.0\"},\n        \"paths\": {\n            \"/hello\": {\n                \"get\": {\n                    \"summary\": \"Says hello\",\n                    \"responses\": {\"200\": {\"description\": \"A greeting\"}}\n                }\n            }\n        }\n    }\n\n# 3. Route to display the Swagger UI page\n@app.route('/docs/')\ndef show_swagger_ui():\n    html_content = '''\n<!DOCTYPE html>\n<html>\n<head>\n    <title>Swagger UI</title>\n    <link rel=\"stylesheet\" type=\"text/css\" href=\"/swagger-ui-assets/swagger-ui.css\">\n</head>\n<body>\n    <div id=\"swagger-ui\"></div>\n    <script src=\"/swagger-ui-assets/swagger-ui-bundle.js\"></script>\n    <script src=\"/swagger-ui-assets/swagger-ui-standalone-preset.js\"></script>\n    <script>\n        window.onload = function() {\n            SwaggerUIBundle({\n                url: \"/openapi.json\",  // URL to your OpenAPI spec\n                dom_id: '#swagger-ui',\n                presets: [\n                    SwaggerUIBundle.presets.apis,\n                    SwaggerUIStandalonePreset\n                ],\n                layout: \"StandaloneLayout\"\n            });\n        };\n    </script>\n</body>\n</html>\n    '''\n    return render_template_string(html_content)\n\nif __name__ == '__main__':\n    # Run this example after installing Flask: pip install Flask\n    print(f\"Swagger UI bundle path: {swagger_ui_path}\")\n    print(\"Go to http://127.0.0.1:5000/docs/ to see the Swagger UI.\")\n    app.run(debug=True)","lang":"python","description":"This quickstart demonstrates how to use `swagger_ui_path` with Flask to serve the Swagger UI assets and display an API documentation page. The core idea is to expose the directory returned by `swagger_ui_path` via your web framework's static file serving mechanism and then reference these files in an HTML template."},"warnings":[{"fix":"Thoroughly test your Swagger UI integration after upgrading to 1.1.0 or newer. Review Swagger UI's own changelogs for any breaking changes in its frontend assets if you have custom scripts.","message":"Version 1.1.0 includes a major update to the bundled Swagger UI (from 3.x to 4.x). While the Python API `swagger_ui_path` remains stable, any custom JavaScript or CSS directly interacting with or relying on specific internal structures of the Swagger UI frontend might break.","severity":"breaking","affected_versions":"Prior to 1.1.0"},{"fix":"Follow your web framework's documentation for serving static files from a specific directory, typically by setting up a route that uses `send_from_directory` or similar.","message":"This library only provides the filesystem path to the Swagger UI assets. It does not include a built-in web server or a direct integration with any specific web framework. You must explicitly configure your web framework (e.g., Flask, Django, FastAPI) to serve these static files.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Check the `swagger-ui-bundle` release notes (e.g., on GitHub or PyPI) to determine which Swagger UI version is included. If you require the absolute latest Swagger UI features or fixes, you might need to bundle it manually or wait for an update to this package.","message":"The version of Swagger UI bundled with this library may not always be the absolute latest upstream version. `swagger-ui-bundle` updates its bundled Swagger UI only when a new version of the Python package is released.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}