Firestore Python: Use Server Timestamp and

May 30, 2019

For Firestore Database Server timestamp, use firebase_admin.firestore.SERVER_TIMESTAMP

For local timestamp, use (assuming your local machine/server is setup with UTC timezone) or datetime.datetime.utcnow().

import datetime
# from import SERVER_TIMESTAMP
# from import SERVER_TIMESTAMP
from firebase_admin.firestore import SERVER_TIMESTAMP

doc_ref = db.collection('test').document()
    'created': SERVER_TIMESTAMP,
    'name': 'Test'

NOTE: Kotlin have a special Timestamp class for Firestore timestamp, but datetime module is sufficient for Python.

NOTE: Refer Setup Firestore on Cloud Functions (Python) for db instance.

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.