rsgiadapter
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:
- FastAPI
- Starlette
- litestar
- falcon
- blacksheep
- quart
- sanic
- Django>=3.0
- 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
- WebSocket Request Response
- ASGI scope
- websocket.connect
- websocket.accept
- websocket.receive
- websocket.send
- websocket.close
- Lifespan
- lifespan.startup
- lifespan.startup.complete(silence)
- lifespan.startup.failed(will terminate)
- lifespan.shutdown
- lifespan.shutdown.complete(silence)
- lifespan.shutdown.failed(will terminate)
- Extensions
- http.response.pathsend
- websocket.http.response
- http.response.debug (only logged by the adapter, not sent to the wire)
- http.response.push (requires RSGI server support)
- http.response.zerocopysend (requires RSGI server support)
- http.response.early_hint (requires RSGI server support)
- http.response.trailers (requires RSGI server support)
Unsupported HTTP extensions are not advertised in
scope["extensions"], so ASGI frameworks will not attempt to use them; if an application sends such a message anyway, the adapter consumes it without breaking the response and logs a warning. The RSGI protocol exposed by granian (RSGI spec 1.6) has no transport for server push, zero-copy sends, 103 early hints or response trailers, and granian's native ASGI support does not implement them either.WebSocket caveats imposed by the RSGI server: the selected subprotocol cannot be negotiated,
websocket.closecodes/reasons are dropped (see granian #645), and a denial response (websocket.http.response) only carries its status code - custom headers and body cannot cross the RSGI boundary yet.
Ref:
Metadata
Release files for rsgiadapter 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rsgiadapter-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Release files / rsgiadapter-0.1.0-py3-none-any.whl
| Download URL | rsgiadapter-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38207f6c20bf06d45e5234dc06c54571f78ea5b55d0f9f6121003e7e202479ab
|
|
BLAKE2b-256 checksum How to use checksums |
b6815dd890f98e5b60e76540f24abd0223590d2103881e44f800aa4c7cbffa1d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.9 {"installer":{"name":"uv","version":"0.12.9","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|