Registry / web-framework / flask-swagger

flask-swagger

JSON →
library0.2.14pypypi✓ verified 86d ago

Flask-Swagger is a Python library designed to extract Swagger 2.0 specifications from Flask projects. Its latest version is 0.2.14, released in February 2021. The project appears to be in maintenance mode with infrequent updates, and lacks support for newer Python versions (3.9+) and OpenAPI 3.0.

pip install flask-swagger
INSTALL
IMPORT
SIG · FLASK-SWAGGER
F
flask-swagger
web-frameworkpythonv0.2.14
Install
3.2s avg
Import
154ms
Disk
24MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.2.14 · 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.910 runs
installs and imports cleanly · install 0.0s · import 0.155s · 26MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 3.2s · import 0.153s · 27MB
24MB installed
● package 24MB
Code
Verified usage

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

swagger
from flask_swagger import swagger

This quickstart demonstrates how to integrate Flask-Swagger into a Flask application to generate Swagger 2.0 API specifications. It sets up a `/spec` endpoint to serve the JSON specification and a simple `/hello/<name>` endpoint with docstring-based Swagger annotations.

from flask import Flask, jsonify from flask_swagger import swagger app = Flask(__name__) @app.route('/spec') def spec(): swag = swagger(app) swag['info']['title'] = "My Flask API" swag['info']['version'] = "1.0" return jsonify(swag) @app.route('/hello/<name>') def hello(name): """ Hello World Endpoint This is a test endpoint returning a greeting. --- parameters: - name: name in: path type: string required: true default: World responses: 200: description: A greeting message schema: type: string example: Hello, John! """ return f"Hello, {name}!" # To run the app: # if __name__ == '__main__': # app.run(debug=True)
Debug
Known issues
deprecatedFlask-Swagger is no longer actively maintained and has known compatibility issues with Python versions 3.9 and newer. For modern OpenAPI (3.x) support and active development, consider using `flasgger` or `flask-restx`.
fix
Migrate to `flasgger` (pip install flasgger) or `flask-restx` (pip install flask-restx).
affects: <=0.2.14
gotchaThis library exclusively supports Swagger 2.0 specifications. It does not provide support for the newer OpenAPI 3.x standards. If your project requires OpenAPI 3.x, an alternative library is necessary.
fix
Use a library like `flasgger` or `flask-restx` which supports OpenAPI 3.x.
affects: <=0.2.14
breakingIn version 0.2.0, a change was introduced where Swagger specifications should reference 'id' instead of 'name' in certain contexts (e.g., for operation IDs). Code written for pre-0.2.0 versions may break.
fix
Update your Swagger specification definitions to use `id` where appropriate, following the Swagger 2.0 specification.
affects: <0.2.0
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask_swagger'
The flask-swagger package is not installed or not available in the current Python environment.
fix
Run `pip install flask-swagger` to install the package.
TypeError: object of type 'Response' is not JSON serializable
The Flask `swagger` function returns a dictionary, which must be converted to a JSON response using Flask's `jsonify` utility before returning from a view function.
fix
Import `jsonify` from `flask` and wrap the `swagger` output: `return jsonify(swagger(app))`.
RuntimeError: No application found. Either work inside a request context or set the 'FLASK_APP' environment variable.
The `swagger(app)` function might be called outside of an application context or before the Flask app instance is properly initialized, especially if trying to access application config or routes dynamically.
fix
Ensure `swagger(app)` is called within the context of a running Flask application, typically inside a view function or after `app` has been fully configured.
Upgrade
Version history
0.2.14latest on PyPI · released Mar 26, 2019
Audit
Dependencies
FlaskrequiredWeb framework integration
PyYAMLrequiredYAML parsing for spec definitions
jsonschemarequiredJSON Schema validation
Agent activity
4 hits · last 30 days
node
4
Resources
flask-swagger — pip install flask-swagger · libregistry