Recently, I’ve been playing with Google App Engine. It is a neat platform and I wanted to take it around with me so I could develop anywhere. To get a portable version of Google App Engine for Windows you need to download the following:
- Portable Python (Download the 2.5.x release)
- Google App Engine SDK (Download the Linux/Other Platforms release)
Grab a USB thumb drive and install Portable Python to it.
Extract the “google_appengine” folder from the Google App Engine SDK zip file into the PortablePython folder on your thumb drive.
Create a new folder in your PortablePython directory called “google_appengine_datastores”.
Creating your Application
All your application folders will go in the PortablePython folder along side the google_appengine folder. For this example, I’ll walk you through creating the first step of the HelloWorld Tutorial on the main Google App Engine site.
Create a new folder in your PortablePython directory called “HelloWorld”.
Create a new file called “helloworld.py” in this folder with the following contents:
print 'Content-Type: text/plain' print '' print 'Hello, world!'
Create a new file called “app.yaml” in the same folder with the following contents:
application: helloworld version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.py
Running your Application
Alright, now that we have the physical files for our first Application. Lets see how it looks. Double click on “IPythonShell-Portable.exe” in your PortablePython directory. It might take a minute if this is your first time running this program.
Once you get to the IPython shell, type the following command:
%run google_appengine/dev_appserver.py --datastore_path=google_appengine_datastores/helloworld_datastore --history_path=google_appengine_datastores/helloworld_history helloworld/
Hit the enter button and it should being running. This starts the development webserver and loads our HelloWorld application. Open your browser and go to http://localhost:8080 to execute the Application. You should see “Hello, World!” in your browser. The datastore_path and history_path command line parameters from above will store the datastore and query history information into the “google_appengine_datastores” directory that we created earlier. If you don’t include these, the datastore will not be portable as it will save to your local system hard drive. I like to add the project name into the datastore and history path so that I could clear only the datastore for a specific project that I’m working on.
If you want to create a batch file that runs your application you can use the following command line in the batch file (You should create it in the root of your PortablePython directory):
apppython.exe google_appengine/dev_appserver.py --datastore_path=google_appengine_datastores/helloworld_datastore --history_path=google_appengine_datastores/helloworld_history helloworld/
Your application is now running! You can leave the IPython shell running in the background while you develop in an IDE like SPE or PyScripter. As you modify your source, the development web server will reload your modified code so you don’t have to restart it all the time.
You now have a fully functioning Portable Google App Engine development environment! If you ever need to update the Google App Engine SDK, just delete the google_appengine folder from your PortablePython directory and extract the new one from the main download site.
Warning: One slight oddity that appears, is if you try to close the IPython window by hitting “Ctrl + C” you have to refresh the website before IPython will acknowledge and stop the server.