Skip to content

Instantly share code, notes, and snippets.

@adri567
Created September 26, 2020 12:03
Show Gist options
  • Save adri567/f1722cf2e485ff3302ce82d320dcbe62 to your computer and use it in GitHub Desktop.
Save adri567/f1722cf2e485ff3302ce82d320dcbe62 to your computer and use it in GitHub Desktop.
upload .json file to firebase realtime database using python
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
from firebase_admin import firestore
from firebase_admin import messaging
import json
import requests
# Get the content of the service account key JSON file
cred = credentials.Certificate('path/to/certificate.json')
# Initialize the app with a service account and grant administration rights
firebase_admin.initialize_app(cred, {
'databaseURL': 'https://<AppName>.firebaseio.com'
})
# Json file is saved as data_file
with open('location of .json file') as data_file: data = json.load(data_file)
print(data )
# A reference to the database is established
ref = db.reference()
# The data are inserted using set
ref.set(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment