python - 使用 python-firestore AsyncClient 和 firebase

标签 python firebase google-cloud-firestore google-authentication

目前我有 Firebase 帐户设置。我希望通过 python asyncio 将项目添加到该项目的 firestore。

据我了解,包:python-firestore 确实通过 AsyncClient 支持异步。

python 包 firebase_admin,目前不支持异步。所以我想知道是否可以在没有 firebase_admin 的情况下使用它。

firebase_admin:

import firebase_admin
from firebase_admin import credentials    
cred = credentials.Certificate("path/to/serviceAccountKey.json")
firebase_admin.initialize_app(cred)

python-firestore:

from google.cloud.firestore import AsyncClient    
client = AsyncClient(credentials=???)

最佳答案

在深入挖掘源码后,我自己找到了答案。

from google.cloud.firestore import AsyncClient 
from google.oauth2 import service_account     
with open("path/to/serviceAccountKey.json") as json_file:
    json_data = json.load(json_file)
firestore_client = AsyncClient(
    project=json_data['project_id'],
    credentials=service_account.Credentials.from_service_account_info(json_data),
)

关于python - 使用 python-firestore AsyncClient 和 firebase,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67737730/

相关文章:

python - 使用装饰器补丁在 Python 中模拟类

firebase - 谷歌云平台 : Cloud Functions and Cloud Tasks doesn't work with authorized service account email

firebase - 为什么我在 Firestore(App 引擎)中有这些奇怪的配额数字?

firebase - 如何形成与未定义元素匹配的 Firestore 查询

firebase - 从服务帐户跨项目访问 Firebase 数据库

node.js - 使用给定的 uid 首次插入 Cloud Firestore 文档时触发 Firebase Cloud 函数

python - 为数据框中两列之间的所有日期添加行的快速方法

python - 有什么方法可以使 {% extends '...' %} 有条件吗? - Django

python - 如何在学习中使用 Mann-Whitney U 检验

java - 如何将用户引导至其特定 Activity ?