Reputation: 81
I understand the answer is "always depends", but generally speaking would there be a reason to use asgiref wrapper within Async frameworks such as Sanic.
https://github.com/django/asgiref https://github.com/channelcat/sanic
My main question is, why would anyone uses this within an async framework, I understand the use case for Django, but if you're async programming is thought through, something like this seems a bit of an lazy way to handle a problem.
Tell me I'm wrong.
Upvotes: 0
Views: 1140
Reputation: 33911
First, background:
Some of the asyncio frameworks such as sanic
and aiohttp
predate the point at which ASGI matured, and because suitable as an asyncio server/application interface.
As a result they already have webserver implementations built into their codebases. They could switch to using ASGI as the interface, rather than their own internal interfaces, but it'd mean a bunch of work for their maintainers.
So, why might it be worth the effort?
Well, the benefit they'd get if they did do so would be:
uvicorn
, hypercorn
, daphne
servers.) Being able to transparently switch between server implementations gives a more robust ecosystem, and mean that server implementations can be shared across frameworks. Sanic would gain server implementation that have HTTP/2 support, Windows support, and PyPy support, and that resolve some outstanding issues it has with socket flow control.In short, ASGI is beneficial for the same set of reasons that WSGI was beneficial. It's less of a win for sanic
than it is for anyone writing a new asyncio framework now, since they've already done all the heavy lifting of writing a server implementation, but there's still benefits they'd get from doing so, and it'd absolutely be a win for the community overall.
Related: ASGI ticket on Sanic.
(Also note asgiref
is just a Python package with a few helpers for working with ASGI frameworks, that also happens to be the repo where the ASGI specification docs are kept. The question is really about using ASGI for Sanic, not using asgiref
.)
Upvotes: 1
Reputation: 7102
I am not familiar with asgiref
in particular. However, with that said, I am familiar with the idea of asgi to sort of be a replacement for wsgi.
In terms of Sanic, this is sort of irrelevant. Sanic has its own server built in, and it operates asynchronously out of the box.
I don't want to tell you that you are wrong per se, but I do not see a use for it in the Sanic world.
Upvotes: 2