Integrations

ASGI 3.0

Component: asgi3 (ASGIComponent)

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/asgi3

This is a generic integration for ASGI 3.0 applications.

Resources available on the global context:

Resources available to request handlers:

Django

Component: django (DjangoComponent)

Requires manual insertion of the asphalt.web.django.AsphaltMiddleware middleware to the MIDDLEWARE list in settings.py for resource injection to work.

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/django

This integration is based on the ASGI 3.0 integration.

Resources available on the global context:

Resources available to request handlers:

Note

Websocket support via Django Channels has not been implemented.

Starlette

Component: starlette (StarletteComponent)

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/starlette

This integration is based on the ASGI 3.0 integration.

Resources available on the global context:

Resources available to HTTP request handlers:

Resources available to websocket handlers:

FastAPI

Component: fastapi (FastAPIComponent)

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/fastapi

This integration is based on the ASGI 3.0 integration.

FastAPI has its own dependency injection system which means Asphalt resources must be injected a bit differently in FastAPI endpoints. Instead of using Depends() as the default value for a resource parameter you wish to inject, you need to use AsphaltDepends() instead. The machinery in FastAPIComponent will handle the appropriate translation.

Resources available on the global context:

Resources available to HTTP request handlers:

Resources available to websocket handlers:

Litestar

Component: litestar (LitestarComponent)

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/litestar

This integration is based on the ASGI 3.0 integration.

Litestar has its own dependency injection system which can optionally be used to inject Asphalt resources in web endpoints. This can be done by using AsphaltProvide instead of Provide:

from litestar import get
from asphalt.web.litestar import AsphaltProvide

@get("/endpointname", dependencies={"myresource": AsphaltProvide(SomeConnection)})
async def myendpoint(myresource: SomeConnection) -> None:
    ...

This would be roughly equivalent to:

from litestar import get
from asphalt.core import require_resource

@get("/endpointname")
async def myendpoint() -> None:
    myresource = require_resource(SomeConnection)
    ...

Resources available on the global context:

Resources available to HTTP request handlers:

  • the ASGI scope of the request

  • the request object

    Note

    The request resource is created from the ASGI scope object by the Asphalt middleware, and does NOT share state with any request object provided by the Litestar framework

Resources available to websocket handlers:

AIOHTTP

Component: aiohttp (AIOHTTPComponent)

Example: https://github.com/asphalt-framework/asphalt-web/tree/master/examples/aiohttp

Unlike the other frameworks supported here, AIOHTTP is not based on the ASGI standard.

Resources available on the global context:

Resources available to request handlers: