QuickStart with UVICORN and FastAPI
Now that we understand why UVICORN is the preferred server for FASTAPI, let’s take a quick look at how to start a FASTAPI application using UVICORN.
Step 1:
First, install the FASTAPI library and uvicorn library using following commands.
pip install fastapi
pip install uvicorn
Step 2:
Create a simple FASTAPI template in a file named main.py
that returns “Hello world” in JSON format.
Python
from typing import Union from fastapi import FastAPI app = FastAPI() @app .get( "/" ) def read_root(): return { "Hello" : "World" } |
Start the server using the following command:
uvicorn main:app --reload
Here, uvicorn main:app
refers to:
Step 3:
Open your browser and navigate to http://localhost:8000/docs to access the HTML page that showcases the API documentation. This page is automatically generated by FastAPI and makes it easy for developers to understand and interact with the API.
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
Contact Us