Category: Database, Data

By reading this piece, you will learn about the fundamental concepts behind FastAPI and the steps involved in transitioning from Flask to FastAPI. At the end of this tutorial, you should be able to migrate your Flask server entirely into aFastAPI server.

If you intend to test out FastAPI, you only need to install FastAPI and Uvicorn.

Run the following command to install it: You can use any template engine with FastAPI if you intend to serve webpage via template.

In Flask, you specify the main function as follows: Then, you run the file via the following command in the terminal: For FastAPI, you need to import uvicorn and specify the main function as follows (myapp refers to the name of the file while app refers to the variable name declared for FastAPI instance): Then, you run it normally from the terminal: However, the recommended method is to run it directly via uvicorn from the terminal without the need to call the main function.

Related Articles