Sunday, January 27, 2013

App Engine and Pyramid

There are so many interesting libraries and frameworks which help bootstrap and start building modern web apps. I decided to explore some of the choices for a personal project. I want this project to run on Google's App Engine, using python on the server. Everything else is negotiable.


Setting up OS/X
Because I'm new to OS/X, I didn't know the ins and outs of developing on it. This is a digression from the topic of this post, but here are a few tips which would have helped me. Firstly, you must install the command-line development tools because oddly, they aren't installed (even after installing Xcode). Secondly, save yourself some trouble and avoid Apple's pre-installed python. Use the Homebrew version of python instead.

Choosing a framework
There is no shortage of python-based web frameworks, including many which work on App Engine. Wikipedia has a comparison. Two very popular choices are Django and Pyramid. I've used Django before in a toy project, and its biggest selling point is its ORM. The Pylons (predecessor to Pyramid) creator thoughtfully described the differences in a StackOverflow answer. Here are a few talks worth watching discussing the options:




I chose Pyramid. It is flexible, popular, lightweight, and works on App Engine.

Getting started
Follow these instructions to create a Pyramid-based App Engine project. Remember to use the Homebrew version of python!

Next, you'll want some boilerplate... HTML5 boilerplate. Alternatively, check out Initializr, which has responsive and bootstrap-included versions of HTML5 boilerplate. This boilerplate also pulls in jQuery and a few other useful Javascript libraries.

Note: Check out GAE boilerplate. It uses webapp2 instead of Pyramid, so it's not directly applicable if you must have Pyramid. But it has basic user authentication and management which could give you a head start. The user authentication doesn't suit my purposes. I want to require user accounts to be tied to an external identity provider (no local passwords). And I want to handle multiple external accounts easily. For example, I would like to display the account chooser when logging in via Google. GAE boilerplate uses the App Engine users service which doesn't display the account chooser. Even worse, logging out logs the user out of more than just the app. It logs the user out of all Google services (Gmail and so on)! A better solution seems to be to avoid the App Engine users API completely, and instead use GITkit.

Stay tuned for more...