Typing Stubs for Werkzeug

1.0.9 · active · verified Fri Apr 10

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.

Warnings

Install

Imports

Quickstart

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.

import os
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple

@Request.application
def application(request: Request) -> Response:
    """A simple Werkzeug application demonstrating type hints."""
    name = request.args.get('name', 'World')
    return Response(f"Hello, {name}!")

if __name__ == "__main__":
    # This part is for running the server, not directly for type checking.
    # To check types, save this as `app.py` and run `mypy app.py`
    # You'd typically need `pip install werkzeug mypy` and optionally `pip install types-werkzeug`
    # (unless Werkzeug >= 2.0 is used, which has its own types).
    print("To run the app: http://127.0.0.1:5000/")
    # run_simple("127.0.0.1", 5000, application)

view raw JSON →