Typing Stubs for Waitress

3.0.1.20260408 · active · verified Thu Apr 16

This is a type stub package for the `waitress` WSGI server, providing static type annotations for use with type checkers like MyPy and Pyright. It allows developers to leverage type checking for `waitress` without modifying its runtime code. The current version is 3.0.1.20260408 and it is released as part of the `typeshed` project, with updates for third-party stubs typically occurring up to once a day.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic WSGI application that can be served by `waitress`. After installing `waitress` and `types-waitress`, a type checker like MyPy can validate the types used in the `simple_app` and `serve` call against the provided stubs, catching potential errors at development time. The example includes the recommended type hints for a WSGI application.

# app.py
from wsgiref.simple_server import make_server
from waitress import serve
from typing import Callable, Iterable, Dict, Any

def simple_app(environ: Dict[str, Any], start_response: Callable) -> Iterable[bytes]:
    """A barebones WSGI application with type hints."""
    status = '200 OK'
    headers = [('Content-type', 'text/plain; charset=utf-8')]
    start_response(status, headers)
    return [b"Hello, Waitress with types!"]

if __name__ == '__main__':
    print("Serving on http://127.0.0.1:8080")
    # Typical production deployment would use the command line:
    # waitress-serve --host=127.0.0.1 --port=8080 app:simple_app
    # For direct Python execution:
    serve(simple_app, host='127.0.0.1', port=8080)

# To type check this application:
# 1. Ensure you have a type checker installed, e.g., pip install mypy
# 2. Run the type checker from your terminal: mypy app.py

view raw JSON →