In this tutorial, we'll learn how to use Google Cloud Spanner by following the examples provided in the documentation.
- If you haven't already, you may sign-up for the free GCP trial credit.
Before you begin, set-up your project and enable billing. - (optional, but recommended) Set-up a Python virtual environment:
- Install pyenv-virtualenv (Instructions for macOS).
- Create and activate an environment:
$ pyenv virtualenv gcp_env $ pyenv activate gcp_env
- Install the Spanner Python API:
$ pip install -r requirements.txt
- Create a Spanner instance and create a Singers table in the UI as shown here.
(You may also run the
spanner-setup.sh
script to take care of this step.
$ chmod +x spanner-setup.sh
$ ./spanner-setup.sh
)
2. Write to the Singers table.
$ python write-to-table.py
These values are now visible in the UI.
- Delete both the database and the instance to avoid incurring charges to your account.
- If you created a Python virtual environment, deactivate it:
$ pyenv deactivate