{"id":2835,"library":"types-werkzeug","title":"Typing Stubs for Werkzeug","description":"types-werkzeug is a PEP 561 type stub package providing static type annotations for the Werkzeug WSGI utility library. It is used by type-checking tools like MyPy, PyCharm, and Pytype to verify the correctness of code that utilizes Werkzeug. The stubs are sourced from the typeshed project, which automatically releases updates to PyPI, often daily. Note that Werkzeug versions 2.0 and newer include their own inline type annotations, making this stub package redundant for those versions.","status":"active","version":"1.0.9","language":"en","source_language":"en","source_url":"https://github.com/python/typeshed","tags":["typing","stubs","type-hints","werkzeug","flask"],"install":[{"cmd":"pip install types-werkzeug","lang":"bash","label":"Install types-werkzeug"}],"dependencies":[{"reason":"Provides runtime functionality; `types-werkzeug` only adds type hints for it. The stubs are useless without the runtime library.","package":"Werkzeug","optional":false},{"reason":"A type checker is required to utilize the provided type stubs for static analysis.","package":"mypy","optional":true}],"imports":[{"note":"Type checkers automatically discover and use installed stub packages like `types-werkzeug`. You should import directly from the runtime `werkzeug` package, not from `types_werkzeug`.","wrong":"from types_werkzeug.wrappers import Request","symbol":"Request, Response","correct":"from werkzeug.wrappers import Request, Response"}],"quickstart":{"code":"import os\nfrom werkzeug.wrappers import Request, Response\nfrom werkzeug.serving import run_simple\n\n@Request.application\ndef application(request: Request) -> Response:\n    \"\"\"A simple Werkzeug application demonstrating type hints.\"\"\"\n    name = request.args.get('name', 'World')\n    return Response(f\"Hello, {name}!\")\n\nif __name__ == \"__main__\":\n    # This part is for running the server, not directly for type checking.\n    # To check types, save this as `app.py` and run `mypy app.py`\n    # You'd typically need `pip install werkzeug mypy` and optionally `pip install types-werkzeug`\n    # (unless Werkzeug >= 2.0 is used, which has its own types).\n    print(\"To run the app: http://127.0.0.1:5000/\")\n    # run_simple(\"127.0.0.1\", 5000, application)","lang":"python","description":"This example demonstrates a basic Werkzeug application with type annotations. To utilize the `types-werkzeug` stubs, first install `werkzeug`, `types-werkzeug` (if using Werkzeug < 2.0), and a type checker like `mypy`. Then, run `mypy your_app_file.py` to perform static type checking."},"warnings":[{"fix":"pip uninstall types-werkzeug","message":"Werkzeug versions 2.0 and newer ship with their own inline type annotations. If you are using Werkzeug >= 2.0, you should uninstall `types-werkzeug` to avoid conflicts and ensure your type checker uses the native types.","severity":"breaking","affected_versions":"Werkzeug >= 2.0"},{"fix":"Ensure `pip install werkzeug` is executed in your environment.","message":"`types-werkzeug` provides only type hints; it does not include the actual runtime code for Werkzeug. The core `werkzeug` library must be installed alongside `types-werkzeug` for your application to function.","severity":"gotcha","affected_versions":"< 2.0"},{"fix":"Attempt to keep `types-werkzeug` and `werkzeug` versions in sync, or at least ensure `types-werkzeug` supports the range of your `werkzeug` version. Consult `types-werkzeug` PyPI page for version compatibility notes.","message":"Stub package versions are generally tied to the runtime package versions they're meant to type. Using an older `types-werkzeug` with a much newer (or vice-versa) `werkzeug` could lead to inaccurate or incorrect type checking results.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Address new type errors as they arise; consider pinning `types-werkzeug` to a specific version or range if strict stability is required, but regularly update to benefit from improved type accuracy.","message":"For type checkers like MyPy, sometimes strictness in stubs can expose existing 'type errors' in code that previously passed. Updates to `types-werkzeug` might introduce new checks that break existing type-checking passes.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly add `-> NoReturn` as the return type annotation to functions that call `abort()` to indicate that they never return normally. (e.g., `from typing import NoReturn`)","message":"When using Werkzeug's `abort()` function (often via Flask), MyPy might report issues if the return type is not correctly annotated. This is because type checkers need to understand that `abort()` prevents further execution in the function.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}