Storing Data in the Cloud

  • Cloud applications can't use files.
    • Files live on computers
    • Entities live in the cloud
  • Cloud applications require the use of databases.
  • There are many options for using databases in the cloud
  • We'll use Google's Cloud Datastore
    • Datastore is a No-SQL database
    • SQL type databases work similarly in Python.

We're making an app for App Engine Standard Environment: It must be Python 2 :-(

You must first upgrade pip so that we have the latest:

sudo pip install --upgrade pip 

You will need to add flask as a vendor library:

mkdir lib 
pip install -t lib flask 

When you vendor in flask you'll need to tell appengine. Complete instructions can be found here:

The short version is add this to

from google.appengine.ext import vendor
# Add any libraries install in the "lib" folder.

You need an app.yaml:

runtime: python27
api_version: 1
threadsafe: true

- url: /static 
  static_dir: static 
- url: /.*
- name: flask
  version: 0.12

Run your App --host= --port=8080 ./app.yaml

Entities in the Datastore are organized into classes:

class Author(ndb.Model):
    """Sub model for representing an author."""
    identity = ndb.StringProperty(indexed=False)
    email = ndb.StringProperty(indexed=False)

Reference Code

You can download this week's code sample here: week14.tar.gz