To develop and test your application locally, you can use the Google Cloud
Datastore
Emulator,
which provides local
emulation of the
production Google Cloud Datastore environment. You can start the Google Cloud
Datastore emulator using the gcloud command-line tool.
When you run the Cloud Datastore emulator you will see a message similar to the
following printed:
If you are using a library that supports the DATASTORE_EMULATOR_HOST
environment variable, run:
export DATASTORE_EMULATOR_HOST=localhost:8978
Now you can connect to the emulator using the DATASTORE_EMULATOR_HOST
environment variable:
require"google/cloud/datastore"# Make Datastore use the emulatorENV["DATASTORE_EMULATOR_HOST"]="localhost:8978"datastore=Google::Cloud::Datastore.newproject:"emulator-project-id"task=datastore.entity"Task","emulatorTask"do|t|t["type"]="Testing"t["done"]=falset["priority"]=5t["description"]="Use Datastore Emulator"enddatastore.savetask
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["Version latestkeyboard_arrow_down\n\n- [2.13.0 (latest)](/ruby/docs/reference/google-cloud-datastore/latest/EMULATOR)\n- [2.12.0](/ruby/docs/reference/google-cloud-datastore/2.12.0/EMULATOR)\n- [2.11.0](/ruby/docs/reference/google-cloud-datastore/2.11.0/EMULATOR)\n- [2.10.0](/ruby/docs/reference/google-cloud-datastore/2.10.0/EMULATOR)\n- [2.9.0](/ruby/docs/reference/google-cloud-datastore/2.9.0/EMULATOR)\n- [2.8.0](/ruby/docs/reference/google-cloud-datastore/2.8.0/EMULATOR)\n- [2.7.1](/ruby/docs/reference/google-cloud-datastore/2.7.1/EMULATOR)\n- [2.6.0](/ruby/docs/reference/google-cloud-datastore/2.6.0/EMULATOR)\n- [2.5.0](/ruby/docs/reference/google-cloud-datastore/2.5.0/EMULATOR)\n- [2.4.0](/ruby/docs/reference/google-cloud-datastore/2.4.0/EMULATOR)\n- [2.3.1](/ruby/docs/reference/google-cloud-datastore/2.3.1/EMULATOR)\n- [2.2.4](/ruby/docs/reference/google-cloud-datastore/2.2.4/EMULATOR) \n\nGoogle Cloud Datastore Emulator\n===============================\n\nTo develop and test your application locally, you can use the [Google Cloud\nDatastore\nEmulator](https://cloud.google.com/datastore/docs/tools/datastore-emulator),\nwhich provides [local\nemulation](https://cloud.google.com/sdk/gcloud/reference/beta/emulators/) of the\nproduction Google Cloud Datastore environment. You can start the Google Cloud\nDatastore emulator using the `gcloud` command-line tool.\n\nWhen you run the Cloud Datastore emulator you will see a message similar to the\nfollowing printed: \n\n If you are using a library that supports the DATASTORE_EMULATOR_HOST\n environment variable, run:\n\n export DATASTORE_EMULATOR_HOST=localhost:8978\n\nNow you can connect to the emulator using the `DATASTORE_EMULATOR_HOST`\nenvironment variable: \n\n```ruby\nrequire \"google/cloud/datastore\"\n\n# Make Datastore use the emulator\nENV[\"DATASTORE_EMULATOR_HOST\"] = \"localhost:8978\"\n\ndatastore = Google::Cloud::Datastore.new project: \"emulator-project-id\"\n\ntask = datastore.entity \"Task\", \"emulatorTask\" do |t|\n t[\"type\"] = \"Testing\"\n t[\"done\"] = false\n t[\"priority\"] = 5\n t[\"description\"] = \"Use Datastore Emulator\"\nend\n\ndatastore.save task\n```\n\nOr by providing the `emulator_host` argument: \n\n```ruby\nrequire \"google/cloud/datastore\"\n\ndatastore = Google::Cloud::Datastore.new emulator_host: \"localhost:8978\"\n\ntask = datastore.entity \"Task\", \"emulatorTask\" do |t|\n t[\"type\"] = \"Testing\"\n t[\"done\"] = false\n t[\"priority\"] = 5\n t[\"description\"] = \"Use Datastore Emulator\"\nend\n\ndatastore.save task\n```"]]