Flasgger is a Python library that integrates Swagger UI into Flask applications, automatically extracting Swagger/OpenAPI specifications from docstrings within your Flask project's endpoints. The current version is 0.9.7.1, with development continuing through beta releases and stable updates to address compatibility and new features.
pip install flasggerVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize Flasgger with a Flask app and document a simple endpoint using a docstring. Once run, navigate to `/apidocs` in your browser to see the generated Swagger UI.
Upgrade to Python 3.x or pin Flasgger version to 0.9.4 or earlier for Python 2 projects.
Upgrade Flasgger to at least 0.9.7b1 (or the latest stable) if using Flask 2.3 or newer.
Review and update your Swagger specifications to use `#/components/schemas` for reusable data models when `config['SWAGGER']['openapi'] = '3.0.0'` is set.
If encountering dependency resolution issues, check the `apispec` and `jsonschema` versions installed and consider using virtual environments or dependency pinning.
Run `pip install flasgger` or `pip3 install flasgger` in your terminal to install the library. If using a virtual environment, ensure it is activated before installation.
Carefully review your API endpoint docstrings or external YAML/YML specification files for syntax errors, incorrect indentation, or missing required fields. Ensure the YAML adheres to the OpenAPI/Swagger specification. Using a YAML linter or validator can help identify issues. Setting `app.config['SWAGGER']['debug'] = True` might also provide more detailed error messages.
Check your Flask application logs for more specific errors (e.g., `AttributeError` related to malformed YAML). Ensure all docstrings are valid YAML/OpenAPI specifications. If using external YAML files, verify their paths and content. Temporarily simplifying your API definitions to isolate the problematic endpoint can help in debugging.
Ensure that the argument passed to `@swag_from` is a string representing the file path (e.g., `'path/to/my_spec.yml'`) and not an already loaded dictionary. If you intend to use a dictionary, ensure it's structured correctly for direct use by Flasgger, or convert your Path object to a string before passing it.