使用 python-firestore AsyncClient,与 firebase
Use python-firestore AsyncClient, with firebase
目前我有 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),
)
目前我有 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),
)