Python Firestore Asyncio
December 9, 2020Environment
Ubuntu 20.04.1 LTS
Python 3.8.6
firebase-admin==4.4.0
google-cloud-core==1.4.3
google-cloud-firestore==2.0.1
grpcio==1.33.2
NOTE: asyncio seems to be supported since google-cloud-firestore==2.0.0
Usage
import asyncio
import sys
import firebase_admin
from firebase_admin import credentials, firestore, auth
from firebase_admin.firestore import AsyncDocumentReference
# from firebase_admin.firestore import AsyncClient
async def main():
cred = credentials.Certificate('firebase-adminsdk.json')
app = firebase_admin.initialize_app(cred)
# db = firestore.client(app = app)
db = firestore.AsyncClient(credentials=app.credential.get_credential(), project=app.project_id)
user_ref = db.collection('user')
ref = user_ref.document()
await ref.set({'name': 'test-user'})
docs = await user_ref.get()
for doc in docs:
print(doc.id, doc.get('name'))
docs = user_ref.stream()
async for doc in docs:
print(doc.id, doc.get('name'))
print('END')
if __name__ == "__main__":
asyncio.run(main())
print('main-END')
References:
❤️ Is this article helpful?
Buy me a coffee☕ or support my work to keep this space 🖖 and ad-free.
If you can't, do send some 💖 to @d_luaz or help to share this article.
If you can't, do send some 💖 to @d_luaz or help to share this article.
👶 Apps I built
Pixtory App (Alpha) - easily organize photos on your phone into a blog.COVID-19 - data, chart, information & news.
暖心芽 (WIP) 🌞❤️🌱 - reminder of hope, warmth, thoughts and feelings.
Travelopy - travel discovery and journal
LuaPass - offline password manager
WhatIDoNow - a public log of things I am working on now
By Desmond Lua
Tags:
Related entries:
- algolia
- analytics
- android
- android-ktx
- android-permission
- android-studio
- apps-script
- bash
- bootstrap
- bootstrapvue
- chartjs
- chrome
- cloud-functions
- coding-interview
- coroutines
- crashlytics
- css
- dagger2
- datastore
- datetime
- docker
- eslint
- firebase
- firebase-auth
- firebase-hosting
- firestore
- firestore-security-rules
- flask
- fontawesome
- fresco
- git
- github
- glide
- godot
- google-app-engine
- google-cloud-storage
- google-colab
- google-drive
- google-maps
- google-places
- google-play
- google-sheets
- gradle
- html
- hugo
- inkscape
- java
- java-time
- javascript
- jetson-nano
- kotlin
- layout
- lets-encrypt
- lifecycle
- linux
- logging
- lubuntu
- markdown
- mate
- material-design
- matplotlib
- md5
- mongodb
- moshi
- mplfinance
- mysql
- navigation
- nginx
- nodejs
- npm
- nuxtjs
- nvm
- pandas
- payment
- pip
- pwa
- pyenv
- python
- recylerview
- regex
- room
- rxjava
- scoped-storage
- selenium
- social-media
- ssh
- ssl
- static-site-generator
- static-website-hosting
- sublime-text
- ubuntu
- unit-test
- uwsgi
- viewmodel
- viewpager2
- virtualbox
- vue-chartjs
- vue-cli
- vue-router
- vuejs
- vuelidate
- vuepress
- web-development
- web-hosting
- webpack
- windows
- workmanager
- wsl
- yarn