From fb9e2a2f7b8140fb38d0e417af4717481f74297b Mon Sep 17 00:00:00 2001 From: larkee Date: Wed, 19 Aug 2020 12:05:59 +1000 Subject: [PATCH 1/2] docs: add instructions for using a Cloud Spanner emulator --- docs/client-usage.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/docs/client-usage.rst b/docs/client-usage.rst index f3157dc0f1..7005ae4387 100644 --- a/docs/client-usage.rst +++ b/docs/client-usage.rst @@ -50,6 +50,29 @@ Configuration Be sure to use the **Project ID**, not the **Project Number**. +Using a Cloud Spanner Emulator +------------------------------ + +There are two ways to use the client with a Cloud Spanner emulator: programmatically or via an environment variable. + +To programmatically use an emulator, you must specify the project, the endpoint of the emulator, and use anonymous credentials: + +.. code:: python + + from google.cloud import spanner + from google.auth.credentials import AnonymousCredentials + + client = spanner.Client( + project='my-project', + client_options={"api_endpoint": "0.0.0.0:9010"}, + credentials=AnonymousCredentials() + ) + +To use an emulator via an environmental variable, set the `SPANNER_EMULATOR_HOST` environmental variable to the emulator endpoint: + +.. code:: + + export SPANNER_EMULATOR_HOST=0.0.0.0:9010 Next Step --------- From 586a20802dd977cd9db6ec70e7b735e8261ad2ef Mon Sep 17 00:00:00 2001 From: larkee <31196561+larkee@users.noreply.github.com> Date: Fri, 21 Aug 2020 11:47:32 +1000 Subject: [PATCH 2/2] docs: address comment --- docs/client-usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/client-usage.rst b/docs/client-usage.rst index 7005ae4387..ce13bf4aa0 100644 --- a/docs/client-usage.rst +++ b/docs/client-usage.rst @@ -68,7 +68,7 @@ To programmatically use an emulator, you must specify the project, the endpoint credentials=AnonymousCredentials() ) -To use an emulator via an environmental variable, set the `SPANNER_EMULATOR_HOST` environmental variable to the emulator endpoint: +To use an emulator via an environment variable, set the `SPANNER_EMULATOR_HOST` environment variable to the emulator endpoint: .. code::