Python's Gateway Interfaces: WSGI VS ASGI
ASGI and WSGI are two python standards for communicating between web servers and applications.
Their basic difference is in the ASYNCHRONOUS nature. Let's quickly discuss both.
WSGI? Web Server Gateway Interface
This is a single calling convention interface for webservers to forward requests to web applications or frameworks written in Python program on a single available path. In other words, its client-server request-handling approach is UNIDIRECTIONAL by default. Simple.
This makes it limited to only web protocols that are traditionally a one-by-one transfer protocol (e.g http/1.1). More involved web protocols (like WebSockets,http/2), however, find it unsuitable to integrate with a single-callable interface like this.
WSGI consists of a callable function comprising of an environ and a start_response argument
```def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) yield b'Hello, World!\n'
If efforts are even made to upgrade WSGI, as it is the most raised suggestion to its predicament, by providing *"asynchronicity"*, protocols like (WebSocket and http/2) that are traditionally nonunidirectional can't get triggered by its single path provided.
WSGI-COMPATIBILITIES
Servers- Apache, NGINX, Cunicorn, uWSGI
Frameworks- Django, Flask, Bottle
**ASGI?**
***Asynchronous Server Gateway Interface***
ASGI, a superset of WSGI, on the other hand, is a non-unidirectional interface and a "spiritual" successor to WSGI. Of course, it can now handle multiple requests/events.
It can also carry out background checks for incoming events (listening).
Websocket can't be grateful enough.
In its simplest form, an application can be written as an asynchronous function, like this:
```async def application(scope, receive, send):
event = await receive()
...
await send({"type": "websocket.send", ...})
Consisting of three arguments over its callable function; a scope, receive and a send argument. It also has an await function; its asynchronous function.
ASGI-COMPATIBILITY SERVERS- Daphne, Hypercorn, e.t.c FRAMEWORKS- Zope, Quixote, SkonkWeb, PSO,Twist, e.t.c
Daphne itself, is a very compatible server that supports asynchronousness in Python frameworks, Django most especially. Information on how to deploy your frameworks on asynchronous servers can be found here
https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/
NOTE: This is not to say that WSGI isn't a great and efficient interface. It serves static files. And many web servers still use it. Asynchronousness is the only bone of contention.
DISCLAIMER: This is a personal opinion. The views and opinions expressed here are only the author's. They don't represent those of any institution or any individual the author may be associated with.
Thanks for reading, Timiboi.