hypercorn.asyncio package

Module contents

async hypercorn.asyncio.serve(app: Union[Type[hypercorn.typing.ASGI2Protocol], Callable[[Union[hypercorn.typing.HTTPScope, hypercorn.typing.WebsocketScope, hypercorn.typing.LifespanScope], Callable[], Awaitable[Union[hypercorn.typing.HTTPRequestEvent, hypercorn.typing.HTTPDisconnectEvent, hypercorn.typing.WebsocketConnectEvent, hypercorn.typing.WebsocketReceiveEvent, hypercorn.typing.WebsocketDisconnectEvent, hypercorn.typing.LifespanStartupEvent, hypercorn.typing.LifespanShutdownEvent]]], Callable[[Union[hypercorn.typing.HTTPResponseStartEvent, hypercorn.typing.HTTPResponseBodyEvent, hypercorn.typing.HTTPServerPushEvent, hypercorn.typing.HTTPDisconnectEvent, hypercorn.typing.WebsocketAcceptEvent, hypercorn.typing.WebsocketSendEvent, hypercorn.typing.WebsocketResponseStartEvent, hypercorn.typing.WebsocketResponseBodyEvent, hypercorn.typing.WebsocketCloseEvent, hypercorn.typing.LifespanStartupCompleteEvent, hypercorn.typing.LifespanStartupFailedEvent, hypercorn.typing.LifespanShutdownCompleteEvent, hypercorn.typing.LifespanShutdownFailedEvent]], Awaitable[None]]], Awaitable[None]]], config: hypercorn.config.Config, *, shutdown_trigger: Optional[Callable[[...], Awaitable[None]]] = None)None

Serve an ASGI framework app given the config.

This allows for a programmatic way to serve an ASGI framework, it can be used via,

asyncio.run(serve(app, config))

It is assumed that the event-loop is configured before calling this function, therefore configuration values that relate to loop setup or process setup are ignored.

Parameters
  • app – The ASGI application to serve.

  • config – A Hypercorn configuration object.

  • shutdown_trigger – This should return to trigger a graceful shutdown.