asphalt.web.aiohttp

class asphalt.web.aiohttp.AIOHTTPComponent(components=None, *, app=None, host='127.0.0.1', port=8000, middlewares=())

Bases: ContainerComponent

A component that serves an aiohttp application.

Parameters:
  • app – the application object, or a module:varname reference to one

  • host – the IP address to bind to

  • port – the port to bind to

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

add_middleware(middleware)

Add middleware to the application.

Parameters:

middleware – either a special coroutine function (as specified here), or a dictionary containing a reference to a setup function. 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.

async start_server(ctx)

Start the HTTP server.

This method is called by the component after the subcomponents have been started. If you need to add any middleware that requires resources provided by subcomponents, you can override this method and call the superclass implementation after the middleware has been added.

Return type:

AsyncGenerator[None, Exception | None]