如何在mongodb中使用fastapi

本文介绍如何利用FastAPI这个Python框架构建针对MongoDB的API。FastAPI比Flask更快,支持自动文档和异步功能,并且在Github上获得了高关注度。教程中将展示在MongoDB 4.4和Python 3.8环境下实现API的步骤。
摘要由CSDN通过智能技术生成

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值