A Simple Tutorial How to Get Started with Google Apps Engine on OS X
Google Apps Engine is undoubtably standing for a revolutionary approach of creating web based applications. Amazon S3 was pioneering a similar system before, but in my opinion, GAE is even more advanced and powerful because of the built in Python runtime environment. Update: Amazon EC2 can be considered as strong competitor as you can run anything on these instances.
This is a really quick tutorial on how to get startet with GAE on Mac OS X.
1.) Download the Google Apps Engine Development server from http://code.google.com/appengine/downloads.html.
2.) Create a folder where you want to put your scripts on your computer
3.) Create the scaffold you will need for your program. For example:
- a folder “static/” for all your static files such as images, CSS etc.
- a file called “app.yaml” defining the URLs and associated Python scripts
- a file called “main.py” which contains all the logic associated to the application (controller)
- a file called “main.html” being the HTML template into which the site gets rendered (view)
The file contents could look something like this:
app.yaml:
application: helloworld
version: 1
api_version: 1
runtime: python
handlers:
- url: /static
static_dir: static
- url: /favicon.ico
static_files: static/favicon.ico
upload: static/favicon.ico
- url: .*
script: main.py
main.py
#!usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
class MyHandler(webapp.RequestHandler):
def get(self):
values = { "name" : "world" }
self.response.out.write(template.render('main.html', values))
def main():
app = webapp.WSGIApplication([
(r'/', MyHandler)],
debug=True)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()
main.html
<html>
<title>Hello {{name}}</title>
<body>Hello {{name}}</body>
</html>
Now if you like to add interactivity, add the following code:
add to class MyHandler() in main.py:
def post(self):
values = { "name" : self.request.get('name') }
self.response.out.write(template.render('main.html', values))
and to main.html within the body tag:
<form action="/" method="post" accept-charset="utf-8"> <label for="name">Name</label><input type="text" name="name" value="" id="name"> <p><input type="submit" value="Say hello"></p> </form>
4.) Save all the files, drag the folder to the GAE interface and hit the “play” button. That’s it! Click on the browser icon to test your app on your localhost.

You can now deploy your software via the “deploy” button, however you need to sign up your application beforehand online. You can also add a domain to your Google Apps Engine program easily by clicking on the button “add domain” within the application dashboard. If you want to test your app online, your application ID has to be unique.
What impresses me about the concept is that you don’t have to worry about your server, bandwidth, scalability, fixes, updates etc. It’s all there and you only pay for what you actually use on bandwidth and CPU time. Isn’t that great?
Download the ZIP file.
Update: Database Inserts and Selects
You may now want to add all the names to a database log. Therefore you have to do the following:
1.) Create a database model to the main.py file by adding:
from google.appengine.ext import db
and add the model class
class Log(db.Model): name= db.StringProperty(required=True) when = db.DateTimeProperty(auto_now_add=True)
2.) Now add the logic that adds the data to the database when executed to the post def of the post def within the handler:
log = Log(name=self.request.get('name'))
log.put()
3.) Now we need a “admin” URL, to see the log. Let’s call it /log. So we have to add that URL to the main.py file where the WSGI gets triggered:
(r'/log', ShowLog)
4.) Now we need to create the ShowLog handler. We also add that to main.py:
class ShowLog(webapp.RequestHandler): def get(self):
5.) and define what’s going to happen in the get request:
logs = db.GqlQuery('SELECT * FROM Log order by when desc')
values = { 'logs' : logs }
self.response.out.write(template.render('log.html', values))
6.) Obviously we need a log.html file to render the result. We create this file and add in django style:
<html>
<title>Log</title>
<body>
<h1>Log</h1>
<p>People have said "hello" with the following names:</p>
<ul>
{% for item in logs %}
<li>{{item.name}}</li>
{% endfor %}
</ul>
</body>
</html>
All in all, the main.py now looks like this:
#!usr/bin/env python
import wsgiref.handlers
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext import db
class Log(db.Model):
name = db.StringProperty(required=True)
when = db.DateTimeProperty(auto_now_add=True)
class MyHandler(webapp.RequestHandler):
def get(self):
values = { "name" : "world" }
self.response.out.write(template.render('main.html', values))
def post(self):
values = { "name" : self.request.get('name') }
self.response.out.write(template.render('main.html', values))
log = Log(name=self.request.get('name'))
log.put()
class ShowLog(webapp.RequestHandler):
def get(self):
logs = db.GqlQuery('SELECT * FROM Log order by when desc')
values = { 'logs' : logs }
self.response.out.write(template.render('log.html', values))
def main():
app = webapp.WSGIApplication([
(r'/', MyHandler),
(r'/log', ShowLog)],
debug=True)
wsgiref.handlers.CGIHandler().run(app)
if __name__ == '__main__':
main()
Download the ZIP file.
That’s all! Your new log interface can be requested via the /log URL. The next step will be how to change data within the database. Stay tuned!
Spread Net Neutrality Awareness
I’ve written about Net Neutrality earlier on a more academic angle. The below video also gives you the more popular view on what the issue is all about:
Spread the word! Net Neutrality is where all our innovation bases on.
Meet the families on Dollar Street

“All people of the world live on Dollar Street, the poorest to the left and the richest to the right. Everybody else live inbetween. Dollar Street contains complete photo-panoramas from households at different income levels. Current version includes 13 household and 3 school documentations from Mozambique, South Africa and Uganda. Scroll the street to left and right to move up and down the street. Click on the houses to get inside and explore different household functions.”
The Dollar Street application can be found on Gapminder.org
Source: Gapminder.org
