Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Added sample for using Cloud Spanner with App Engine Python 3.7 runtime. #1757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions 5 appengine/standard_python37/spanner/app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
runtime: python37

env_variables:
SPANNER_INSTANCE: "YOUR-SPANNER-INSTANCE-ID"
SPANNER_DATABASE: "YOUR-SPANNER-DATABASE-ID"
35 changes: 35 additions & 0 deletions 35 appengine/standard_python37/spanner/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# [START gae_python37_cloudsql_mysql]
import os

from flask import Flask
from google.cloud import spanner

app = Flask(__name__)
spanner_client = spanner.Client()

instance_id = os.environ.get('SPANNER_INSTANCE')
database_id = os.environ.get('SPANNER_DATABASE')


@app.route('/')
def main():
database = spanner_client.instance(instance_id).database(database_id)
with database.snapshot() as snapshot:
cursor = snapshot.execute_sql('SELECT 1')
results = list(cursor)

return 'Query Result: {}'.format(results[0][0])
26 changes: 26 additions & 0 deletions 26 appengine/standard_python37/spanner/main_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


def test_main():
import main

main.database_id = 'example-db'

main.app.testing = True
client = main.app.test_client()

r = client.get('/')
assert r.status_code == 200
assert 'Query Result: 1' in r.data.decode('utf-8')
2 changes: 2 additions & 0 deletions 2 appengine/standard_python37/spanner/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
google-cloud-spanner==1.6.0
Flask==1.0.2
Morty Proxy This is a proxified and sanitized view of the page, visit original site.