The `google-cloud-firestore` client library provides a Pythonic interface for interacting with Google Cloud Firestore. Firestore is a fully-managed, scalable NoSQL document database for mobile, web, and server development, offering real-time data synchronization and offline support. It is currently at version 2.26.0 and receives regular updates as part of the broader `google-cloud-python` client libraries.
pip install --upgrade google-cloud-firestoreVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize the Firestore client, add a new document to a collection, retrieve a single document, and perform a basic query for documents. It assumes 'Application Default Credentials' are set up (e.g., via `gcloud auth application-default login` or by setting the `GOOGLE_APPLICATION_CREDENTIALS` environment variable to a service account key file path).
Review the 2.0.0 migration guide in the official documentation. The library may ship `fixup_firestore_v1_keywords.py` and `fixup_firestore_admin_v1_keywords.py` scripts to assist with code modification.
Ensure that Application Default Credentials are valid and up-to-date. For local development, run `gcloud auth application-default login` regularly. For production, ensure service account permissions and key validity.
When encountering index errors, follow the link provided in the error message to the Firebase/Google Cloud console to create the necessary composite index. Plan for index creation during development for complex queries.
Choose the appropriate library based on your project's needs: `google-cloud-firestore` for direct Google Cloud integration, `firebase-admin` for projects heavily leveraging Firebase services (Authentication, Realtime Database, etc.).
Ensure your Python environment is running Python 3.7 or higher. For new projects, consider Python 3.10+ for better forward compatibility.