- Why spanner-django
- How does spanner-django benefit me
- How do I use spanner-django in my application
- How do I authenticate to Cloud Spanner
- How does spanner.django work?
- How do I configure the Google credentials environment variable
Why spanner-django?
Spanner-Django allows you to use Cloud Spanner as a SQL database for your web applications.
How does spanner-django benefit me?
- With a single
pip install
and setting the database configuration in your Djangosettings.py
file, you can now use Cloud Spanner while running on any cloud.
How do I use spanner-django in my application?
a) Install spanner-django
simply by pip3 spanner-django
b) Update your INSTALLED_APPS
and DATABASES
section in settings.py
to include the sub-sections:
INSTALLED_APPS
Please ensure that the very first app in your INSTALLED_APPS
section in your settings.py
file is spanner.django
, so:
INSTALLED_APPS = [
'spanner.django',
...
]
ENGINE
Must be spanner.django
PROJECT
Must be a valid Google Cloud Platform project-id, for example
'PROJECT': 'appdev-soda-spanner-staging'
INSTANCE
Must be an existing Cloud Spanner instance, for example
'INSTANCE': 'django-dev1'
DATABASE
Must be an existing Cloud Spanner database, for example
'NAME': 'db1'
Full Example
INSTALLED_APPS = [
'spanner.django',
...
]
DATABASES = {
'default': {
'ENGINE': 'spanner.django',
'PROJECT': 'appdev-soda-spanner-staging',
'INSTANCE': 'django-dev1',
'NAME': 'db1',
}
}
How do I authenticate to Cloud Spanner?
One can authenticate to Cloud Spanner using Google Service Account credentials, which if you don’t have, you can learn more about by visiting authentication
How do I configure the Google credentials environment variable?
Please set the GOOGLE_APPLICATION_CREDENTIALS
environment variable and set it to the path of the JSON file containing your service account.
For example:
export GOOGLE_APPLICATION_CREDENTIALS=~/Downloads/scratch/creds.json
How does spanner.django work?
Please see the diagram below:
Where do I find tutorials for new applications?
Glad you asked, please see quickstart