目前我有 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/