2022年2月5日土曜日

Advantages and disadvantages for using FastAPI, a fast framework for the web programming language Python.

https://shimi-dai.com/fastapi-merit-demerit/

I shared it.


Advantages and disadvantages for using FastAPI

2022

1/15

Backend

Programming Languages

 Jan 15, 2022

 Jan 15, 2022

FastAPI is a modern, fast (high performance) web framework for building APIs in Python.


It is much faster than Django and Flask, and can be as fast as Golang's Gin.


It is also written in the same way as Flask, so companies that use Flask or people who understand it can easily implement it.


Advantages of FastAPI

FastAPI has the following advantages


Faster than other Python web frameworks

Relatively easy to develop.

It can be developed with fewer bugs because it is typed.

The official documentation is in Japanese.

API documente generator is available.


Let's take a look at the details.


Faster than other Python web frameworks

FastAPI is much faster than Django, Flask, and Bottle. In the following figure, the higher the number, the faster it is.



Reference URL: Why did we choose FAST API over Flask and Django for our RESTFUL Micro-services


Python is an easy language to use, but it is said to be slow.


Relatively easy to develop

FastAPI can be coded similarly to Flask and is simple to code.


The following is the simplest API.



from fastapi import FastAPI


app = FastAPI()


@app.get("/")

async def root():

    return {"message": "Hello World"}

Next is the Flask web app.



from flask import Flask


app = Flask(__name__)


@app.route('/')

def hello_world():

    return 'Hello World!


if __name__ == '__main__':

    app.run()

In contrast, HelloWorld in Django requires modification of some files. The Hello World articles for each of the web frameworks, which are not included in this article, are listed below.


Python Web Frameworks

Hello World with FastAPI, let's try out Python's fast web framework!

Implementing Hello World's first web screen in Django!

[Python] How to implement an application that displays Hello World in Flask on a Linux server [Beginners are welcome].

Development with fewer bugs due to typing

Using a validator called pydantic, we can reduce errors when returning data, creating data in the database, and updating data.


Official documentation in Japanese

The official documentation is available in Japanese.


When you wanted to use other frameworks, you may have found it difficult because there is no Japanese explanation.


FastAPI Japanese Manual

Japanese manual of FastAPI

API document generator is available

FastAPI has a document generator function that automatically generates API documentation by default, and the document generator is provided in Swagger-UI for easy API usage.


FastAP's document generator

FastAP's document generator

Disadvantages of FastAPI

The following are the disadvantages of FastAPI


There are few functions by default, so you need to select a library.

The community is small and knowledge is scarce.


Let me introduce the details.


By default, there are few features, so you need to choose a library.

Since FastAPI is a lightweight framework, DB connection and authentication functions need to be added separately.


However, it is possible to use SQLAlchemy for DB connection and python-jose for authentication as described in the official manual.


The community is small and knowledge is scarce

The biggest disadvantage of FastAPI is that the community is small, as it is a framework that was just created in 2018.


Since there is not much documentation and knowledge, you need to verify it by yourself, which is a big disadvantage for development.

The community size is small.

0 コメント:

コメントを投稿