ASGI vs. WSGI
ASGI represents a significant advancement over WSGI (Web Server Gateway Interface). While WSGI is designed for single, synchronous applications that handle a request and return a response, it does not support long-lived connections like WebSocket connections. In contrast, ASGI is asynchronous and accepts three arguments:
- Scope: A Python dictionary containing details of the specific connection.
- Send: Allows the application to send event messages to the client.
- Receive: Permits the application to receive event messages from the client.
ASGI enables multiple incoming and outgoing events for each application simultaneously, allowing the application to remain responsive to user input while background coroutines run.
FastAPI – Uvicorn
FastAPI is a modern, high-performance, and robust Python web framework used for building REST APIs. It seamlessly integrates with UVICORN, a lightweight ASGI server, which excels in handling multiple connections and events concurrently. The choice of UVICORN for FastAPI is driven by its exceptional performance, ease of integration with FastAPI, and its ability to serve numerous incoming requests. In this article, we will delve deeper into UVICORN, exploring what it is and how it is employed in conjunction with FASTAPI