三个Firestore Python包之间的区别

huangapple go评论53阅读模式
英文:

Difference between the three Firestore Python packages

问题

以下是翻译好的部分:

Simple question, in Python you can import the Firestore library from three different sources. I can't seem to find any documentation on what the differences are.

All three are official libraries from Google:

from firebase_admin import firestore

from google.cloud import firestore

from google.cloud import firestore_v1

Anyone that can shed some light on this?

英文:

Simple question, in Python you can import the Firestore library from three different sources. I can't seem to find any documentation on what the differences are.

All three are official libraries from Google:

> from firebase_admin import firestore

> from google.cloud import firestore

> from google.cloud import firestore_v1

Anyone that can shed some light on this?

答案1

得分: 1

  1. firebase-admin 库允许您从服务器端代码与 Firebase 服务交互,包括 Firestore。它需要单独安装到项目中并需要身份验证才能使用。因此,当您使用其他 Firebase 服务时,这是最佳选择,因为这个包包含所有身份验证、Firestore、实时数据库、存储、函数等功能。

  2. google.cloud.firestore 库允许您从本地计算机与 GCP 服务交互(假设您的计算机上已安装 gcloud)。它不需要任何身份验证即可使用。

  3. google.cloud.firestore_v1 链接是 Firestore V1 中的第一个项目:这个库提供了与 Firestore 交互的低级 API。这个库允许您直接调用 Firestore REST API,并提供更多对请求和响应的控制。

所以简而言之,在构建使用 Firebase 服务的项目时,使用 firebase-admin,如果您使用 Firebase 函数,它效果非常好。如果您正在创建使用 GCP 服务的 Python 应用程序,那么使用 google.cloud.firestore,或者如果您需要更精细的控制API,可以使用 google.cloud.firestore_v1

英文:

Let’s see what all 3 does and how it does:

  1. firebase-admin library allows you to interact with Firebase services, including Firestore, from your server-side code. It needs to be installed separately in the project and requires authentication to be able to use it. So this is the best approach when you are using other firebase services as this one package has all authentication, firestore, realtime database, storage , functions etc.
  2. google.cloud.firestore library allows you to interact with the GCP services from your local machine (assume like gcloud installed on your machine). It does not require any authentication to use.
  3. google.cloud.firestore_v1 link is for first item in firestoreV1 : This library provides low-level API for interacting with FIrestore. This library allows you to directly call Firestore REST APIs and provides more control over the requests and responses.

So TLDR use firebase-admin when building stuff with Firebase Services, works great if you use firebase functions. If you are creating python applications which use GCP services then use google.cloud.firestore or google.cloud.firestore_v1 if you need more granular control over the API.

huangapple
  • 本文由 发表于 2023年2月24日 16:41:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/75554314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定