Bottle on GAE April 6th, 2014


For simple applications, Bottle is one of the simpliest and handiest options out there. 

Bottle is a fast, simple and lightweight WSGI micro web-framework for Python.

It is distributed as a single file module and has no dependencies other than the Python Standard Library.

That makes Bottle so lovely.  See a simple example from its official site: 

from bottle import route, run, template

def index(name):
    return template('<b>Hello {{name}}</b>!', name=name)

run(host='localhost', port=8080)

So is it possible to get it running on Google App Engine (GAE)? 

Yes, this note simply introduces how to do that.

Since it is super easy, just present an example.


1. put '' into your GAE fold -- '' can be used standalone and be downloaded on its official site.

2. edit app.yaml


application: gdict
version: 1
runtime: python27
api_version: 1
threadsafe: yes

- remote_api: on


- url: /.*

Note: the handling script is "", not "mainbottle". 


3. "" is as follow: 


__author__ = 'zheng'

import bottle
from bottle import *
import urllib2
from bs4 import BeautifulSoup

def crawl_page(keyword='happy'):
    url = '' % keyword
    url = ''
    # use try to check network connection
        page = urllib2.urlopen(url).read()
        print 'ERROR: network connection failed.'
    soup = BeautifulSoup(page)
    return soup

app = Bottle()

def homeGET():
    return "Look mah, Python 2.7 with no training wheels!"

def get_url():
	soup = crawl_page()
	return str(soup), server='gae')



Only 3 simple steps, just a little bit different from running Bottle (should use ', server='gae')' for handling).








Relate Posts:

Tags: GAE Bottle

Posted in Google App English |

Leave a Reply