Firestore is a NoSQL document database built for automatic scaling, high performance, and ease of application development. It is the newest version of Datastore and introduces several improvements over Datastore. Because Firestore in Datastore mode (Datastore) is optimized for server use cases and for App Engine, we recommend using Datastore for databases that will be used primarily by App Engine apps. Firestore in Native mode is most useful for mobile and real-time notification use cases. For more information about Firestore modes, see Choosing between Native Mode and Datastore mode.
This document describes how to use the
Cloud Client Libraries to store and
retrieve data in a Datastore mode database.
You can use the sample application in this guide for any
supported version of
Python by specifying the runtime version
and operating system in your app.yaml
file.
Prerequisites and setup
- Set up your environment and project to understand how apps are structured in App Engine. Write down and save your project ID, because you will need it to run the sample application described in this document.
Clone the repository
Download (clone) the sample:
git clone https://github.com/GoogleCloudPlatform/python-docs-samples
cd python-docs-samples/appengine/flexible/datastore
Edit project configuration and set dependencies
Include the google-cloud-datastore
library in requirements.txt
file. This
is the client library for Datastore mode.
Application code
The sample application logs, retrieves, and displays visitor IPs. You can see
that a log entry is a two-field class that is given the type visit
,
and is saved to Datastore mode using the
put
command. Then, the ten most recent visits are retrieved in descending order
using the query()
command.
Using index.yaml
files
The sample app performs queries. More elaborate
Datastore mode queries require one or more
indexes, which you must specify in an
index.yaml
file
that you upload along with your app. This file may be created manually, or
generated automatically while testing your app locally.
Local testing
If you need to develop and test your application locally, you can use the Datastore mode emulator.
For more information
For complete information on Datastore mode, including optimizations and concepts, see the Firestore in Datastore mode documentation.