asphalt.web.starlette

class asphalt.web.starlette.StarletteComponent(components=None, *, app=None, host='127.0.0.1', port=8000, debug=None, middlewares=())

Bases: ASGIComponent[Starlette]

A component that serves a Starlette application.

Parameters:
  • app – the Starlette application object

  • host – the IP address to bind to

  • port – the port to bind to

  • debug – whether to enable debug mode in an implicitly created application (default: the value of __debug__; ignored if an application object is explicitly passed in)

  • middlewares – list of callables or dicts to be added as middleware using add_middleware()

add_middleware(middleware)

Add a middleware to the application.

Unlike the raw ASGI version of this method, this one adds the middleware to Starlette’s own middleware stack instead of wrapping the application directly.

Parameters:

middleware – either a callable that takes the application object and returns an ASGI 3.0 application, or a dictionary containing a reference to such a callable. This dictionary must contain the key type which is a non-async callable (or a module:varname reference to one) and which will be called with the application object as the first positional argument and the rest of the keys in the dict as keyword arguments.