DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

Migrate From Flask to FastAPI Smoothly

4 years ago medium.com
Migrate From Flask to FastAPI Smoothly

Summary: This is a summary of an article originally published by the source. Read the full original article here →

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.

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com