Baize

raw JSON →
0.23.1 verified Fri May 01 auth: no python

Baize is a powerful and elegant WSGI/ASGI framework/toolkit for Python, providing high-level abstractions for building HTTP applications. It supports both WSGI and ASGI interfaces, includes routing, request/response handling, middleware, and WebSocket support. The current version is 0.23.1, released with a focus on stability and performance. The library follows a semver-like release cadence, with minor releases every few months.

pip install baize
error ModuleNotFoundError: No module named 'baize.http'
cause Trying to import from a submodule that no longer exists in recent versions.
fix
Use 'from baize import Request, Response' instead.
error TypeError: 'Request' object is not callable
cause Using Request as a function instead of a class. This happens when importing incorrectly.
fix
Ensure you import Request as a class: 'from baize import Request'.
error RuntimeError: You cannot use sync middleware on an ASGI app
cause Middleware that is not async is registered on an ASGI app.
fix
Make all middleware callables async functions when using the ASGI backend.
breaking In version 0.23.0, the top-level exports changed. Classes like Request, Response, and Routing are now directly accessible from 'baize' instead of submodules.
fix Update imports to match new top-level exports; e.g., 'from baize import Request' instead of 'from baize.http import Request'.
deprecated The 'baize.wsgi' and 'baize.asgi' submodules are deprecated. Use the unified 'baize.Baize' class instead.
fix Replace 'from baize.wsgi import Baize as WSGI' with 'from baize import Baize' and configure the backend using the 'backend' parameter.
gotcha Route handlers must be async functions for ASGI. Using synchronous functions will cause runtime errors.
fix Ensure route handlers are declared with 'async def' when using the ASGI backend (the default).

A minimal ASGI Baize application with a single route returning a JSON response.

import os
from baize import Baize, Request, Response

app = Baize()

@app.route("/")
async def home(request: Request) -> Response:
    name = request.query_params.get("name", "World")
    return Response.json({"message": f"Hello, {name}!"})

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)