|Google App Engine changes everything.|
Much of the out-of-the-gate resistance inherent in kicking out a new web app has been greased by Google.
Google gives you essential software services, storage, and scalable hardware.
If boat-loads of customers start pounding on your app, App Engine allocates more resources.
You only pay for the resources you use.
Google measures resource consumption at the gigabyte level with no monthly fees or set-up charges. CPU usage, storage per month, incoming and outgoing bandwidth, and resources specific to App Engine services are potentially billable items - But ONLY if your app hits pay dirt.
Developers get a generous chunk of free resources for exploratory apps and Lean Startup hypothesis testing (approximately 5 million page views a month).
Google language support consists of Java and Python.
The following My Preferences example I cobbled together uses the Python SDK to demonstrate two key features:
- Google Accounts (for authentication) and
- Google Datastore (data access & persistence)
I wrote My Preferences to learn how out-of-the-box Google Account authentication and Datastore "cloud" persistence is done via App Engine.
My Preferences lets one sign in to select preferences for:
- Page Theme (4 color schemes) and
- Time Zone (offset from GMT).
Screen capture #2 (below) shows the Default theme (white background) and GMT time zone after I sign in with with my Google account, but before I have specified my preferences.
Screen capture #3 (below) shows the Winter Green theme I chose. It also shows that I have changed to my time zone (GMT -5.00). These preferences are persisted and keyed to my Google account on the onChange events of the two dropdown lists.
If I Sign Out and then Sign In, my preferences will be displayed.
What You'll Need Bare Bones
Getting started requires a minimum amount of software. All free. Following is a checklist of items you'll need to copy and run My Preferences on a Windows computer (Win 7 or Windows XP SP3). You will need:
- The Python 2.5 programming language. There are newer versions, but I worked with the recommended version 2.5. The Windows installer for Python 2.5 from python.org is at
- The Google App Engine SDK for Python. The Windows installer for version 1.3.4 from Google is at
After running the Python msi and the Google App Engine SDK for Python msi, I had to make sure the Python directory was in the Windows path.
I made a Windows folder for my source code. The source files and a sub-folder for my css stylesheets looked like the adjacent screen capture (right).
app.yaml (below) is a config file in the root of your app directory.
models.py (below) contains my datastore objects (e.g., theme, zone, and user) that I want to persist using the Google Datastore.
prefs.py (below) gets the page post and stores preferences. That is, the authenticated user specifies and posts their theme choice and time zone preference. The userprefs method I created is called to put( ) them into the Datastore.
main.py (below) is the main page that includes code and HTML.
Python is persnickety about whitespace and column alignment, so beware. If you cut & paste the code below, you'll probably have to format it nicely so Python can digest it. I had to jury rig the HTML for this blog post, so lookout for munged HTML if you cut & paste.
index.yaml (not shown) is an auto-generated file that is updated whenever the dev_appserver detects that a new type of query has been run.
style0.css (below) contains the css stylesheet for the Default theme. There are 3 additional stylesheets (style1.css, style2.css, and style3.css) that are identical except for tweaks in colors. Here's the Default template:
Kickin It Old-School
You invoke the Python compiler from a command prompt as shown below.
Once compilation completes, you can run the app from localhost on port 8080 as shown below.
Uploading To Google App Engine
Once you have developed your app locally, you can create a developer account and upload it to run on Google App Engine via the App Engine Admin Console.
Programming Google App Engine by Dan Sanderson.