view.core.app

Functions

as_app(view, /)

Decorator for using a single function as an app.

execute_view(view, *args, **kwargs)

Classes

App(*[, router])

An application containing an automatic routing mechanism and error handling.

BaseApp()

Base view.py application.

SingleViewApp(view)

Application with a single view function that processes all requests.

class App(*, router: Router | None = None)

Bases: BaseApp

An application containing an automatic routing mechanism and error handling.

connect(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a CONNECT route.

delete(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a DELETE route.

error(status: int | type[HTTPError], /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Callable[[], ResponseLike | Awaitable[ResponseLike]]]

Decorator interface for adding an error handler to the app.

get(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a GET route.

head(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a HEAD route.

options(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding an OPTIONS route.

patch(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a PATCH route.

post(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a POST route.

async process_request(request: Request) Response

Get the response from the server for a given request.

put(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a PUT route.

route(path: str, /, *, method: Method) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a route to the app.

static_files(path: str, directory: str | Path) None
subrouter(path: str) Callable[[SubRouterViewT], SubRouterViewT]
trace(path: str, /) Callable[[Callable[[], ResponseLike | Awaitable[ResponseLike]]], Route]

Decorator interface for adding a TRACE route.

class BaseApp

Bases: ABC

Base view.py application.

asgi() ASGIProtocol

Get the ASGI callable for the app.

classmethod current_app() BaseApp
current_request() Request

Get the current request being handled.

property debug: bool

Is the app in debug mode?

If debug mode is enabled, some extra checks and settings are enabled to improve the development experience, at the cost of being slower and less secure.

abstract async process_request(request: Request) Response

Get the response from the server for a given request.

request_context(request: Request) Iterator[None]

Enter a context for the given request.

run(*, host: str = 'localhost', port: int = 5000, production: bool = False, server_hint: str | None = None) None

Run the app.

This is a sort of magic function that’s supposed to “just work”. If finer control over the server settings is desired, explicitly use the server’s API with the app’s asgi() or wsgi() method.

run_detached(*, host: str = 'localhost', port: int = 5000, production: bool = False, server_hint: str | None = None) Process

Run the app in a separate process. This means that the server is killable.

wsgi() WSGIProtocol

Get the WSGI callable for the app.

as_app(view: Callable[[Request], Response | str | bytes | AsyncGenerator[str | bytes] | Generator[str | bytes] | tuple[str | bytes, int] | tuple[str | bytes, int, HTTPHeaders | Mapping[str, str] | Mapping[bytes, bytes]] | Awaitable[Response | str | bytes | AsyncGenerator[str | bytes] | Generator[str | bytes] | tuple[str | bytes, int] | tuple[str | bytes, int, HTTPHeaders | Mapping[str, str] | Mapping[bytes, bytes]]]], /) SingleViewApp

Decorator for using a single function as an app.