Warning: Bocadillo is now UNMAINTAINED. Users are recommended to migrate to a supported alternative, such as Starlette or FastAPI. Please see #344 for more information.


Definition of application types used in type annotations.

import typing

from .request import Request
from .response import Response

if typing.TYPE_CHECKING:  # pragma: no cover
    from .applications import App

Scope = dict
Event = typing.MutableMapping[str, typing.Any]
Receive = typing.Callable[[], typing.Awaitable[Event]]
Send = typing.Callable[[Event], None]

class ASGIApp:
    def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
        raise NotImplementedError

Handler = typing.Callable[
    [Request, Response, typing.Any], typing.Awaitable[None]
ErrorHandler = typing.Callable[
    [Request, Response, BaseException], typing.Awaitable[None]

class HTTPApp:
    async def __call__(self, req: Request, res: Response) -> Response:
        raise NotImplementedError

# Server lifespan events
EventHandler = typing.Callable[[], typing.Awaitable[None]]