{"id":4305,"library":"types-smorest","title":"Type Stubs for flask-smorest","description":"types-smorest provides PEP 561 compatible type stubs for the `flask-smorest` library, a REST API framework built upon Flask and Marshmallow. It allows static type checkers like MyPy to perform type verification on `flask-smorest` applications, enhancing code quality and maintainability. The library is currently at version 1.1.2 and receives updates as needed to track `flask-smorest` features and fixes.","status":"active","version":"1.1.2","language":"en","source_language":"en","source_url":"https://github.com/cex-solutions/types-smorest","tags":["type stubs","flask","api","marshmallow","openapi","mypy"],"install":[{"cmd":"pip install types-smorest","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"This package provides type stubs for `flask-smorest`. It is not a runtime dependency, but a dependency for static type checking (e.g., with MyPy).","package":"flask-smorest","optional":false}],"imports":[{"note":"You import the symbols from `flask_smorest` itself. `types-smorest` is a stub package and does not provide runtime modules to import from directly.","symbol":"Api","correct":"from flask_smorest import Api"},{"note":"You import the symbols from `flask_smorest` itself. `types-smorest` is a stub package and does not provide runtime modules to import from directly.","symbol":"Blueprint","correct":"from flask_smorest import Blueprint"},{"note":"While `flask-smorest` heavily uses `marshmallow.Schema`, the type stubs for it would typically come from `types-marshmallow` or be provided within `flask-smorest`'s own types where applicable, enabled by `types-smorest` for `flask-smorest`'s interaction with `Schema` objects.","symbol":"Schema","correct":"from marshmallow import Schema"}],"quickstart":{"code":"from flask import Flask\nfrom flask.views import MethodView\nfrom marshmallow import Schema, fields\nfrom flask_smorest import Api, Blueprint, abort\n\napp = Flask(__name__)\napp.config[\"API_TITLE\"] = \"My API\"\napp.config[\"API_VERSION\"] = \"v1\"\napp.config[\"OPENAPI_VERSION\"] = \"3.0.2\"\n\napi = Api(app)\n\nclass ItemSchema(Schema):\n    id = fields.Int(dump_only=True)\n    name = fields.String(required=True)\n    price = fields.Float(required=True)\n\nblp = Blueprint(\"items\", \"items\", url_prefix=\"/items\", description=\"Operations on items\")\napi.register_blueprint(blp)\n\n@blp.route(\"/\")\nclass Items(MethodView):\n    @blp.response(200, ItemSchema(many=True))\n    def get(self) -> list[dict]:\n        \"\"\"List all items\"\"\"\n        # In a real app, this would fetch from a database\n        items = [{\n            \"id\": 1,\n            \"name\": \"Example Item\",\n            \"price\": 10.99\n        }]\n        return items\n\n    @blp.arguments(ItemSchema)\n    @blp.response(201, ItemSchema)\n    def post(self, new_item_data: dict) -> dict:\n        \"\"\"Create a new item\"\"\"\n        # In a real app, this would save to a database\n        new_item_data['id'] = len(self.get()) + 1 # Simulate ID generation\n        return new_item_data\n\n# To run this example (requires flask-smorest, marshmallow):\n# 1. pip install Flask flask-smorest marshmallow\n# 2. Save as app.py\n# 3. export FLASK_APP=app.py\n# 4. flask run\n#\n# To use with type checking (requires types-smorest, mypy):\n# 1. pip install types-smorest mypy\n# 2. mypy app.py\n","lang":"python","description":"This quickstart demonstrates a basic `flask-smorest` application. Installing `types-smorest` alongside `flask-smorest` allows static type checkers like MyPy to analyze this code for type consistency. The stubs provide type information for `Api`, `Blueprint`, and other `flask-smorest` constructs, ensuring that method arguments, return types, and decorator usage are correctly typed according to `flask-smorest`'s API."},"warnings":[{"fix":"Always import symbols from the original library, `flask_smorest`, e.g., `from flask_smorest import Api`.","message":"This is a type stub package; it contains no runtime code. You should never import modules or symbols directly from `types_smorest` in your application's runtime code. Its sole purpose is to provide type hints for static analysis tools like MyPy.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the `types-smorest` GitHub repository for details on covered components. Contributions to expand stub coverage are welcome.","message":"`types-smorest` is a partial stub package. This means it may not cover every function, class, or object available in `flask-smorest`, leading to some `Any` types or incomplete type checking in certain scenarios.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that the `types-smorest` version is compatible with your `flask-smorest` version. Check the `types-smorest` GitHub releases and issue tracker for specific compatibility notes. Consider pinning both `flask-smorest` and `types-smorest` versions in your project's dependencies.","message":"Compatibility between `types-smorest` and `flask-smorest` versions is crucial. Breaking changes in `flask-smorest` might not be immediately reflected in `types-smorest`, potentially leading to incorrect type hints or errors during static analysis. `types-smorest` v1.1.2 was released in Dec 2022, while `flask-smorest` has continued to release updates, including v0.47.0 in March 2026.","severity":"gotcha","affected_versions":"All versions, especially when using newer `flask-smorest` versions with older `types-smorest`"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}