rsgiadapter

An adapter for asgi to rsgi


Keywords
asgi, rsgi, adapter, to, asyncio, asgiadapter, granian, rsgiadapter, rsgiref
License
BSD-3-Clause
Install
pip install rsgiadapter==0.0.6

Documentation

rsgiadapter

PyPI - Version GitHub License PyPI - Downloads PyPI - Status

An Asgi to rsgi adapter.

RSGI Specification ref: https://github.com/emmett-framework/granian/blob/master/docs/spec/RSGI.md

rsgiadapter is an adapter for RSGI server run ASGI application like FastAPI and BlackSheep.

This project provides a way to run ASGI web frameworks on an RSGI server, but it is not recommended to use the RSGI server in this manner. Using frameworks that natively support the RSGI protocol can better leverage the performance advantages of RSGI.

Check examples for more framework examples. You can run the scripts in the examples directory to test.

Basic Usage:

app.py

import granian
from granian.constants import Interfaces
from rsgiadapter import ASGIToRSGI


# Declare your asgi application here
async def app(scope, receive, send):
    await send({"type": "http.response.start", "status": 200, "headers": []})
    await send(
        {"type": "http.response.body", "body": b"Hello, World!", "more_body": False}
    )


rsgi_app = ASGIToRSGI(app)

if __name__ == "__main__":
    serve = granian.Granian("app:rsgi_app", interface=Interfaces.RSGI)
    serve.serve()

with asgi lifespan:

from contextlib import asynccontextmanager

import granian
from granian.constants import Interfaces
from rsgiadapter import ASGIToRSGI


@asynccontextmanager
async def lifespan(_app):
    print("lifespan start")
    yield
    print("lifespan stop")


# Declare your asgi application here
async def app(scope, receive, send):
    await send({"type": "http.response.start", "status": 200, "headers": []})
    await send(
        {"type": "http.response.body", "body": b"Hello, World!", "more_body": False}
    )


rsgi_app = ASGIToRSGI(app, lifespan=lifespan)

if __name__ == "__main__":
    serve = granian.Granian("app:rsgi_app", interface=Interfaces.RSGI)
    serve.serve()

Supported Framework:

  1. FastAPI
  2. Starlette
  3. litestar
  4. falcon
  5. blacksheep
  6. quart
  7. sanic
  8. Django>=3.0
  9. and other Python web frameworks that support the ASGI protocol, with or without lifespan support.

Supported Feature:

  • HTTP Request Response
    • ASGI scope
    • ASGI receive
    • ASGI send
  • Extensions
    • http.response.pathsend
    • websocket.http.response
    • http.response.push
    • http.response.zerocopysend
    • http.response.early_hint
    • http.response.trailers
    • http.response.debug
  • Lifespan
    • lifespan.startup
    • lifespan.startup.complete(silence)
    • lifespan.startup.failed(will terminate)
    • lifespan.shutdown
    • lifespan.shutdown.complete(silence)
    • lifespan.shutdown.failed(will terminate)

Ref: