How to Configure Firebase with Python Code Snippet for Firestore Document Creation

This topic was automatically generated from Slack. You can find the original thread here.

Hi , How do I configure firebase within a python code snippet inorder to create a document in firestore . Like in case of nodejs I was using this code const { projectId, clientEmail, privateKey } = this.firebase_admin_sdk.$auth
const formattedPrivateKey = privateKey.replace(/\n/g, ‘\n’)
if (!admin.apps.length) {
admin.initializeApp({
credential: admin.credential.cert({
projectId,
clientEmail,
privateKey: formattedPrivateKey,
})
})
}
const db = admin.firestore();

Hello , you can refer to this doc to understand how to connect to Firebase app and get the credentials from Python: Connecting apps in Python

I have found this code

import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore

cred = credentials.Certificate("serviceAccountKey.json")
firebase_admin.initialize_app(cred)

db = firestore.client()

But I don’t want to pass my key as a param. So is there any alternative code where it will use creds from props defined in step itself.

Hello I think the document above is already stating how you can get the authentication information of your connected Pipedream x Firebase account. Would you mind read through it? It will save you a lot of time