FastAPI is a very cool open-source framework to construct API using Python. Its syntax is similar to Flask, so if you use it, you should not have any trouble learning it.
FastAPI是一个非常酷的开源框架,可以使用Python构造API。 它的语法类似于Flask ,因此,如果您使用它,那么学习它就不会有任何麻烦。
It has some advantages over Flask, such as:
与Flask相比,它具有一些优势,例如:
- It is fast (as compared with Flask); 它快(与Flask相比);
- It has automatic docs (OpenAPI); 它具有自动文档(OpenAPI);
It can use async functions;
它可以使用异步功能;
- It has support for websocket; 它支持websocket;
And many more;
还有更多 ;
It is a relative new development (< 2 years), but it has already 20k stars on Github.
这是一个相对较新的发展(<2年),但是在Github上已经有2万颗星。
You can learn more about this framework in these articles:
您可以在以下文章中了解有关此框架的更多信息:
MongoDB is a document database where you can store data directly in JSON format. It is very simple to start and create an application using MongoDB. Yet it is a powerful tool.
MongoDB是一个文档数据库,您可以在其中直接以JSON格式存储数据。 使用MongoDB启动和创建应用程序非常简单。 但这是一个强大的工具。
In this article, I’m going to show you how to implement an API for a MongoDB database.
在本文中,我将向您展示如何为MongoDB数据库实现API。
Note: this tutorial was done with MongoDB version 4.4 and Python 3.8, in a machine with Ubuntu 20.04.
注意 :本教程是在装有Ubuntu 20.04的计算机中使用MongoDB 4.4版和Python 3.8完成的。
正在安装 (Installing)
You can install MongoDB following the instructions for your operating system here.
您可以按照此处针对您的操作系统的说明安装MongoDB。
You can use pip
to install FastAPI:
您可以使用pip
安装FastAPI:
pip install fastapi
To connect with the MongoDB database, we’re going to use the PyMongo package:
要连接MongoDB数据库,我们将使用PyMongo软件包:
pip install pymongo
Since FastAPI uses