Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@vishalroygeek
Last active May 10, 2020 16:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishalroygeek/53e0732db538d1e81c1f6f993b8f542d to your computer and use it in GitHub Desktop.
Save vishalroygeek/53e0732db538d1e81c1f6f993b8f542d to your computer and use it in GitHub Desktop.
A python script to get all the user data from firestore database and put it into a CSV file πŸ“
import firebase_admin
from firebase_admin import credentials
from firebase_admin import firestore
import csv
#Initializing firebase
cred = credentials.Certificate("path/to/serviceAccount.json")
firebase_admin.initialize_app(cred)
db = firestore.client()
#Getting all the users from database
users = db.collection(u'users').stream()
#Opening a CSV file for users data
with open('path/to/users.csv', 'w', newline='') as file:
writer = csv.writer(file)
#Writing header row of CSV file. Change it according to your needs ;)
writer.writerow(["Name", "Email"])
#Writing all the users data
for user in users:
writer.writerow([user.get("name"), user.get("email")])
print("All users have been exported to the CSV file πŸ‘")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment