Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use python-firestore AsyncClient, with firebase

Currently I have firebase account setup. I wish to add item to firestore of this project, via python asyncio.

As I understand it, the package: python-firestore, does support async via AsyncClient.

The python package firebase_admin, currently doos not support async. So I am wondering if it is possible to use it without 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=???)
like image 250
Bads Avatar asked Apr 29 '26 11:04

Bads


1 Answers

After digging in the source code, I found the answer myself.

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),
)
like image 133
Bads Avatar answered Apr 30 '26 23:04

Bads



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!