Skip to content

Local Datastore Setup

Wesley Jones edited this page Sep 24, 2021 · 1 revision

Instructions for setting up Google Datastore on your local

You will need to start your emulator with the following command:

gcloud beta emulators datastore start --data-dir=. --project test --host-port "localhost:8001"

Use the following code in main.py:

import os
if os.getenv('GAE_ENV', '').startswith('standard'):
    # production
    datastore_client = datastore.Client()
else:
    os.environ["DATASTORE_DATASET"] = "test"
    os.environ["DATASTORE_EMULATOR_HOST"] = "localhost:8001"
    os.environ["DATASTORE_EMULATOR_HOST_PATH"] = "localhost:8001/datastore"
    os.environ["DATASTORE_HOST"] = "http://localhost:8001"
    os.environ["DATASTORE_PROJECT_ID"] = "test"

    datastore_client = datastore.Client(
        project="test"
    )
Clone this wiki locally