Registry / web-framework / flask-smorest

flask-smorest

JSON →
library0.47.0pypypi✓ verified 24d ago

Flask-Smorest is a Flask/Marshmallow-based REST API framework that helps build documented REST APIs following the OpenAPI specification. It is currently at version 0.47.0 and maintains an active development pace with consistent minor and patch releases, primarily focusing on bug fixes and new features.

pip install flask-smorest
INSTALL
IMPORT
SIG · FLASK-SMOREST
F
flask-smorest
web-frameworkpythonv0.47.0
Install
2.7s avg
Import
1011ms
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.47.0 · 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 1.018s · 25.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.7s · import 1.004s · 26MB
24MB installed
● package 24MB
Code
Verified usage

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

Api
from flask_smorest import Api
Blueprint
from flask_smorest import Blueprint
Schema
from marshmallow import Schema
from flask_smorest import Schema
Marshmallow Schema classes are imported directly from the `marshmallow` library, not `flask_smorest`.
fields
from marshmallow import fields
from flask_smorest import fields
Marshmallow fields are imported directly from the `marshmallow` library, not `flask_smorest`.

This quickstart sets up a basic Flask application with Flask-Smorest. It defines a simple `Item` resource with a Marshmallow schema, creates endpoints for listing, creating, and retrieving items, and exposes OpenAPI documentation via Swagger UI. Run this Flask app and navigate to `/docs/swagger-ui` to see the generated API documentation.

import os from flask import Flask from flask_smorest import Api, Blueprint from marshmallow import Schema, fields # 1. Basic Flask app setup app = Flask(__name__) # 2. Configuration for Flask-Smorest and OpenAPI app.config["API_TITLE"] = "Simple Item API" app.config["API_VERSION"] = "v1" app.config["OPENAPI_VERSION"] = "3.0.2" app.config["OPENAPI_URL_PREFIX"] = "/docs" app.config["OPENAPI_SWAGGER_UI_PATH"] = "/swagger-ui" app.config["SECRET_KEY"] = os.environ.get("FLASK_SECRET_KEY", "super-secret-key-development") # 3. Initialize Flask-Smorest API api = Api(app) # 4. Define a Marshmallow Schema class ItemSchema(Schema): id = fields.Integer(dump_only=True) name = fields.String(required=True) price = fields.Float(required=True) # 5. Define a Blueprint blp = Blueprint("items", __name__, url_prefix="/items", description="Operations on items") # In-memory store for demonstration items_db = {} next_id = 1 # 6. Define API endpoints using the blueprint @blp.route("/", methods=["POST"]) @blp.arguments(ItemSchema) @blp.response(201, ItemSchema) def create_item(new_item_data): """Create a new item""" global next_id new_item_data["id"] = next_id items_db[next_id] = new_item_data next_id += 1 return new_item_data @blp.route("/<int:item_id>", methods=["GET"]) @blp.response(200, ItemSchema) def get_item(item_id): """Get an item by ID""" item = items_db.get(item_id) if item is None: return {"message": "Item not found"}, 404 return item @blp.route("/", methods=["GET"]) @blp.response(200, ItemSchema(many=True)) def get_all_items(): """Get all items""" return list(items_db.values()) # 7. Register the blueprint with the API api.register_blueprint(blp) # Add a simple root route for testing if desired @app.route("/") def hello(): return "Hello from Flask-Smorest API! Visit /docs/swagger-ui for API documentation."
Debug
Known issues
breakingAs of v0.23.0, API title and version are mandatory parameters. They no longer default to `app.name` and `"1"` respectively. Attempting to initialize the API without these will raise an error.
fix
Set `API_TITLE` and `API_VERSION` in your Flask app configuration (e.g., `app.config["API_TITLE"] = "My API"`) or pass them directly when initializing `Api`.
affects: >=0.23.0
breakingIn v0.24.0, Swagger UI configuration moved to a single `OPENAPI_SWAGGER_UI_CONFIG` dictionary. Old individual configuration parameters like `OPENAPI_SWAGGER_UI_SUPPORTED_SUBMIT_METHODS`, `layout`, and `deepLinking` were removed.
fix
Consolidate Swagger UI settings into a dictionary assigned to `app.config["OPENAPI_SWAGGER_UI_CONFIG"]`. For example, `app.config["OPENAPI_SWAGGER_UI_CONFIG"] = {"supportedSubmitMethods": ["get", "post"]}`.
affects: >=0.24.0
breakingVersion 0.22.0 dropped support for Python 3.5. Subsequent versions require Python 3.6+ (and currently 3.10+ as of 0.47.0).
fix
Ensure your project is running on Python 3.10 or newer to use the latest versions of Flask-Smorest.
affects: >=0.22.0
breakingAs of v0.21.0, Flask-Smorest dropped support for `webargs < 6.0.0`. If you have an older version of `webargs` pinned, this will cause dependency conflicts or runtime errors.
fix
Upgrade your `webargs` dependency to version 6.0.0 or higher (e.g., `pip install 'webargs>=6.0.0'`).
affects: >=0.21.0
breakingIn v0.20.0, error component naming changed from `HTTPStatus.phrase` to `HTTPStatus.name` to avoid issues with spaces in URLs. Also, `DefaultError` was renamed to `DEFAULT_ERROR`.
fix
If you have custom error handlers or refer to these internal error names, update your code to use the new naming convention (`DEFAULT_ERROR` and `HTTPStatus.name`).
affects: >=0.20.0
gotchaPrior to v0.21.1, `apispec` (used internally by Flask-Smorest) could mutate documentation information dictionaries for view functions, especially when a single view served multiple HTTP methods. This could lead to incorrect or missing OpenAPI spec generation.
fix
Upgrade to Flask-Smorest v0.21.1 or newer. If stuck on an older version, ensure distinct documentation dictionaries are used or deep-copied for each method's specification.
affects: <0.21.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'flask-smorest'
The flask-smorest package is not installed in the active Python environment or the virtual environment is not activated.
fix
Install the package using pip: `pip install flask-smorest`.
cannot import name 'abort' from 'flask_smorest'
Developers might mistakenly attempt to import 'abort' directly from 'flask_smorest' when it's re-exported from 'webargs.flaskparser', or they encounter import conflicts with Flask's own 'abort'.
fix
Ensure `flask-smorest` is installed and import 'abort' as `from flask_smorest import abort`. If there's a conflict with `flask.abort`, alias them (e.g., `from flask import abort as flask_abort` and `from flask_smorest import abort as api_abort`).
Flask-smorest response schema or status code not applied correctly (no explicit error, but unexpected API behavior or documentation)
The `@blp.response` decorator is placed before the route decorator (e.g., `@blp.route`, `@blp.get`, `@blp.post`), causing the response serialization and documentation to not be correctly linked to the endpoint.
fix
Reorder the decorators so that the route decorator comes first, followed by `@blp.response`.
```python
# Incorrect
# @blp.response(200, PetSchema)
# @blp.route("/pets/<int:pet_id>")
# def get_pet(pet_id):
#     pass

# Correct
@blp.route("/pets/<int:pet_id>")
@blp.response(200, PetSchema)
def get_pet(pet_id):
    pass
```
TypeError: object() takes no parameters (when using schema for path parameters)
Flask-Smorest expects path parameters to be validated by Flask's URL converters or specified via the `parameters` argument in `@blp.route` or `@blp.doc`, not by directly passing a Marshmallow `Schema` instance for path segments.
fix
Use Flask's built-in converters for basic type validation in the route itself (e.g., `<int:pet_id>`). For more detailed path parameter documentation, use the `parameters` argument within `@blp.doc` or the `doc` parameter of `@blp.route`.
```python
# Incorrect (attempting to use a schema directly in route for path param)
# class PetIdSchema(ma.Schema):
#     pet_id = ma.fields.Int(required=True, validate=lambda x: x > 0)
# @blp.route("/pets/<PetIdSchema:pet_id>") # This is not how schemas are used for path params
# def get_pet(pet_id):
#     pass

# Correct (using Flask converter for type, and manual validation if needed)
@blp.route("/pets/<int:pet_id>")
@blp.response(200, PetSchema)
def get_pet(pet_id):
    if pet_id <= 0:
        abort(400, message="Pet ID must be positive")
    # ... logic here
```
Upgrade
Version history
0.47.0latest on PyPI · released Mar 22, 2026
Audit
Dependencies
FlaskrequiredCore web framework dependency.
marshmallowrequiredUsed for defining API schemas and data validation.
webargsrequiredUsed for parsing arguments from requests.
apispecrequiredUsed for generating OpenAPI specifications from code.
furloptionalUsed for pagination features.
PyYAMLoptionalRequired for `apispec[yaml]` to generate YAML OpenAPI specs.
Agent activity
47 hits · last 30 days
node
40
OpenAI (training)
1
Resources
flask-smorest — pip install flask-smorest · libregistry