asphalt.web.fastapi

asphalt.web.fastapi.AsphaltDepends(name='default')

Asphalt’s version of FastAPI’s Depends().

This should be marked as the default value on a parameter that should receive an Asphalt resource.

Parameters:

name (str) – the name of the resource within its unique type

Return type:

Any

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

Bases: ASGIComponent[FastAPI]

A component that serves a FastAPI application.

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

  • 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 FastAPI’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.