Python wsgi asgi - ghdrako/doc_snipets GitHub Wiki

WSGI

WSGI is a standard interface which allows to seperate server code from the application code where you add your business logic.

WSGI (stands for Web Server Gateway Interface) is simple where you can define your application as a callable that takes two arguments the first argument environ describes the request and the environment the server running in and the second argument is a synchronous callable which you call to start the response to yield the body.

There are a lots of WSGI frameworks Bottle, Flask, Falcon, Django etc. There are WSGI servers like Gunicorn, uWSGI, Apache.

Limitations of WSGI  It doesn’t have the ability to officially deal with Web Sockets. Wsgi.websocket is an unofficial work around though. WSGI can’t also work with HTTP/2. We also can’t use async or await with WSGI.q

ASGI

ASGI stands for Asynchronous Server Gateway Interface. In ASGI also you define your application as a callable which is asynchronous by default.

In ASGI there are three arguments the scope which is similar to the environ in WSGI which gives an idea about the specific connection. Receive and Send where you as an application has to receive and send messages both are asynchronous callable. This allows multiple incoming events and outgoing events for each application . The main advantage is that it allows background coroutine so the application is able to do other things such listening for events on an external trigger like a redis queue.