Stay organized with collections
Save and categorize content based on your preferences.
This page describes how to configure the Firestore in Datastore mode client libraries
to use a locational endpoint.
When you use Firestore in Datastore mode client libraries, you can use either of the following endpoints:
Global endpoint: By default, the Firestore in Datastore mode client libraries send API requests to a global
service endpoint named datastore.googleapis.com. The global service endpoint
routes the request to your database. During routing, the request
might pass through a locational service endpoint in a location that's different
from your database location.
Locational endpoint: A locational endpoint enforces regional restrictions, ensuring that data is stored and processed in a specified region.
To guarantee that the service endpoint processes your app's Firestore in Datastore mode
requests in the same region as your database, specify a locational endpoint
in the client library.
Set a locational endpoint
The following examples show how to set a locational endpoint when you initialize
a Firestore in Datastore mode client.
importcom.google.cloud.datastore.Datastore;importcom.google.cloud.datastore.DatastoreOptions;publicclassRegionalEndpoint{publicDatastorecreateClient()throwsException{// Instantiates a clientDatastoreOptionsoptions=DatastoreOptions.newBuilder().setHost("https://nam5-datastore.googleapis.com").build();Datastoredatastore=options.getService();returndatastore;}}
[[["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-09-04 UTC."],[[["\u003cp\u003eFirestore in Datastore mode client libraries can use either a global endpoint (\u003ccode\u003edatastore.googleapis.com\u003c/code\u003e) or a regional endpoint to direct API requests.\u003c/p\u003e\n"],["\u003cp\u003eRegional endpoints ensure that data is processed and stored within the specified region, unlike the global endpoint which may route requests through different regions.\u003c/p\u003e\n"],["\u003cp\u003eTo set a regional endpoint, specify the regional endpoint URL during client initialization using the correct formatting, which varies slightly by language (Java, Python, Go).\u003c/p\u003e\n"],["\u003cp\u003eSetting the regional endpoint to a region where the data does not reside may cause a \u003ccode\u003ePermissionDeniedError\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eRegional endpoints use the format \u003ccode\u003ehttps://REGION_NAME-datastore.googleapis.com\u003c/code\u003e, with the full \u003ccode\u003ehttps\u003c/code\u003e URL and sometimes a port number required, replacing \u003ccode\u003eREGION_NAME\u003c/code\u003e with the appropriate location identifier, such as \u003ccode\u003eeur3\u003c/code\u003e or \u003ccode\u003enam5\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Configure data locality with locational endpoints\n\nThis page describes how to configure the Firestore in Datastore mode client libraries\nto use a locational endpoint.\n\nWhen you use Firestore in Datastore mode client libraries, you can use either of the following endpoints:\n\n- **Global endpoint** : By default, the Firestore in Datastore mode client libraries send API requests to a global\n service endpoint named `datastore.googleapis.com`. The global service endpoint\n routes the request to your database. During routing, the request\n might pass through a locational service endpoint in a location that's different\n from your database location.\n\n- **Locational endpoint** : A locational endpoint enforces regional restrictions, ensuring that data is stored and processed in a specified region.\n To guarantee that the service endpoint processes your app's Firestore in Datastore mode\n requests in the same region as your database, specify a *locational endpoint*\n in the client library.\n\nSet a locational endpoint\n-------------------------\n\nThe following examples show how to set a locational endpoint when you initialize\na Firestore in Datastore mode client.\n**Note:** Setting a locational endpoint other than where your data resides might result in a `PermissionDeniedError` error. \n\n### Java\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Java API\nreference documentation](https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/history).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n\n import com.google.cloud.datastore.https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Datastore.html;\n import com.google.cloud.datastore.https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions.html;\n\n public class RegionalEndpoint {\n\n public https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Datastore.html createClient() throws Exception {\n // Instantiates a client\n https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions.html options =\n https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions.html.newBuilder().https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.DatastoreOptions.Builder.html#com_google_cloud_datastore_DatastoreOptions_Builder_setHost_java_lang_String_(\"https://nam5-datastore.googleapis.com\").build();\n https://cloud.google.com/java/docs/reference/google-cloud-datastore/latest/com.google.cloud.datastore.Datastore.html datastore = options.getService();\n return datastore;\n }\n }\n\n### Python\n\n\nTo learn how to install and use the client library for Datastore mode, see\n[Datastore mode client libraries](/datastore/docs/reference/libraries).\n\n\nFor more information, see the\n[Datastore mode Python API\nreference documentation](https://cloud.google.com/python/docs/reference/datastore/latest).\n\n\nTo authenticate to Datastore mode, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n ENDPOINT = \"https://eur3-datastore.googleapis.com\"\n client_options = ClientOptions(api_endpoint=ENDPOINT)\n client = datastore.Client(client_options=client_options)\n\n query = client.query(kind=\"Task\")\n results = list(query.fetch())\n for r in results:\n print(r)\n\n\u003cbr /\u003e\n\n### Locational endpoint semantics\n\nFirestore in Datastore mode supports locational endpoints for both region and multi-region locations.\n\nUse the following format to define locational endpoints: \n\n### Java\n\n https://\u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e-firestore.googleapis.com:443\n\nMake sure that the complete `https` URL is used and that the port number is defined along with the endpoint.\n\n### Python\n\n https://\u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-n\"\u003eREGION_NAME\u003c/span\u003e\u003c/var\u003e-firestore.googleapis.com\n\nMake sure that the complete `https` URL is set as the locational endpoint.\n\n### Go\n\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-nx\"\u003eREGION_NAME\u003c/span\u003e\u003c/var\u003e-firestore.googleapis.com:443\n\nMake sure that the port number is defined along with the endpoint.\n\nReplace \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e with the name of a regional or multi-regional hostnames.\n\nSome examples of hostnames are:\n\n- `eur3-datastore.googleapis.com`\n- `nam5-datastore.googleapis.com`\n- `europe-west6-datastore.googleapis.com`\n- `asia-northeast2-datastore.googleapis.com`\n\nFor a complete list of multi-regional and regional hostnames, see [Firestore in Datastore mode locations](/datastore/docs/locations).\n\nWhat's next\n-----------\n\n- Learn about the Firestore in Datastore mode data model. See [Entities, properties, and keys](/datastore/docs/concepts/entities).\n- See the [Best practices](/datastore/docs/best-practices) for Firestore in Datastore mode."]]