“cloud development in a box”. Ê It is a hosted development environment along the lines of MicrosoM Azure. Ê Targets users building internet applica)ons, but that is changing. Ê Built on the same scalable plaPorm used for other Google services. Ê Development is done locally in Python (or Java) on Windows, Mac OS X, or Linux. Ê Push to the cloud and Google will manage everything. Ê We’ll dig into the details shortly.
h:p://code.google.com/appengine/casestudies.html Ê Most oMen GAE is used as a u)lity alongside another plaPorm. Ê GAE for Business will increase uptake. Eventually.
to get started, or run small applica)ons. Ê ~5M page views per month Ê Google post quotas and costs on their website Ê h:p://code.google.com/appengine/docs/quotas.html Ê Once you reach certain limits Google will start charging you based on your usage. Ê Usage costs can be expensive depending on your requirements, or alterna)ve deployment plaPorms. Ê Choice of datastore can even impact costs Ê Calcula)ng costs can be tricky, but this is the case with all usage-‐based cloud providers and services. Ê You need to know your applica)on, and the how the plaPorm can be best used applied to your needs. Ê Cheaper features might have poten)al for higher lock-‐in.
really choose a framework or tool without some experience. Take this advice with a pinch of salt. Ê Good Ê You want to learn a Python web development framework. Ê Managing servers is not something you want to do. Ê Your applica)on needs to support a ridiculous number of users, or giant fluctua)ons in usage. Ê You want to quickly prototype a larger applica)on that you may develop elsewhere. Ê Maybe Ê An exis)ng applica)on is wri:en in Python (or Java) and you want to create a web front end. Ê Bad Ê Data sources for your applica)on live inside your company. Ê Other data security or privacy requirements. Ê You need a version of Python newer than 2.5. Ê Your Python library requires a C extension and does not have a Python fallback.
Way” is recommended. Ê h:p://learnpythonthehardway.org/index Ê Many other resources are available: Ê h:p://diveintopython.org/toc/index.html Ê h:p://docs.python.org/tutorial/ Ê Focus on learning Python 2.x if you want to use the broadest range of libraries today. Ê Python 3.2 is the latest but newbies will have issues with libraries. Ê GAE makes the choice easier. Use CPython 2.5. Ê Get familiar with REPL-‐style development in the shell.
version is supported at present. Ê Free from h:p://www.python.org/Mp/python/ Ê Get the latest 2.5.x release from h:p://www.python.org/Mp/python/2.5.5/ Ê Google App Engine SDK Ê Download the latest version and it will auto-‐update. Ê Free from h:p://code.google.com/appengine/downloads.html Ê A suitable editor Ê Most (good) text editors provide syntax highligh)ng. Ê I like JetBrains’ PyCharm, but Ac)veState Komodo is also good. A lot of people like the Wingware IDE. Ê You could use the latest Python support for Visual Studio 2010 if you want but it does not have special support for App Engine.
Blobstore (File system) Capabili>es Channel (comet?) Images (ImageGlue.NET) Mail (BCL) Memcache (AppFabric) Mul>tenancy (SQL Schemas) OAuth (BCL) Prospec>ve Search Task Queues (MSMQ) URL Fetch (BCL) Users (BCL) XMPP (Lync API) Ê Services are accessed via “webapp”. Ê Most have equivalents in the .NET world (shown in parentheses) Ê Sites hosted at *.appspot.com Ê Limita)ons: Ê SSL for custom domains Ê Quotas impac)ng cost are complex Ê Users all have Gmail emails by default Ê Python libraries which depend on C extensions cannot run on the plaPorm. Ê Google-‐like search requires some effort.
WebOb that runs atop WSGI. Ê WSGI is an interface to Python web servers. Ê Whilst you have basic support for MVC, you don’t have the support provided by a full framework like ASP.NET MVC. Ê Conven)on or configura)on? Neither. Ê For a lot of applica)ons you should be considering a framework like Tipfy (more later).
from a special base class. Ê Google provide a range of data types for En)ty proper)es. Ê En))es are stored in a system based on Big Table (Master/Slave) or Megastore (High Replica)on). Ê You choose this when you create your applica)on. Ê Choice of storage affects costs and can’t be changed easily. Ê Google recommend the High Replica)on datastore for be:er all round performance. Ê Fewer peaks and troughs compared to the Master/Slave store.
in a similar fashion to other ORM tools. Ê The challenges are a li:le different from your experiences using ORMs with rela)onal databases. Ê Data types Ê h:p://code.google.com/appengine/docs/python/datastore/ typesandpropertyclasses.html Query query = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John") query = db.Query(Song) query.filter('composer=', id) result = query.get() Defini>on class Song(db.Model): author = db.UserProperty() composer = db.StringProperty() date = db.DateTimeProperty (auto_now_add=True) tags = db.StringListProperty() description = db.TextProperty()
= db.StringProperty() last_name = db.StringProperty() hobbies = db.StringListProperty() class Contact(polymodel.PolyModel): phone_number = db.PhoneNumberProperty() address = db.PostalAddressProperty() class Person(Contact): first_name = db.StringProperty() last_name = db.StringProperty() mobile_number = db.PhoneNumberProperty() class Company(Contact): name = db.StringProperty() fax_number = db.PhoneNumberProperty() Ê Expando and PolyModel. Ê More informa)on can be found in the SDK documenta)on
datastore. Ê Store large objects e.g. images or documents in the Blobstore Ê Excep)ons might be small thumbnails where they are always returned with related fields. Ê Use the BlobstoreUploadHandler class to make uploading blob objects less painful. Ê BlobstoreDownloadHandler provides a way to specify byte ranges. Ê BlobReader gives you a stream-‐like API. Ê Plays well with the Images API.
resources. Ê Use for calls to REST (and SOAP) web services. Ê Supports calls to your intranet through the Google Secure Data Connector (SDC). from google.appengine.api import urlfetch result = urlfetch.fetch(url="http://www.corp.example.com/sales.csv", headers={'use_intranet': 'yes'}) if result.status_code == 200: parseCSV(result.content) Ê Download size is limited to 32 MB.
such as send a no)fica)on, or update a 3rd party system. # Application queues a task taskqueue.add(url='/worker', params={'key': key}) # Handler does the work class CounterWorker(webapp.RequestHandler): def post(self): # should run at most 1/s key = self.request.get('key') def txn(): counter = Counter.get_by_key_name(key) if counter is None: counter = Counter(key_name=key, count=1) else: counter.count += 1 counter.put() db.run_in_transaction(txn)
on Windows compared to other languages. Ê Google’s imaging library needs an extension called PIL. Ê 64-‐bit versions of Python and the Python Imaging Library (PIL) Ê Make sure that the architectures of extensions match up. Ê Windows programs a 64-‐bit applica)on cannot load a 32-‐bit DLL, and vice versa. Ê See my blog post on this topic. Ê Windows Firewall and blocked ports Ê No server == no fun
you experience issues. Ê Situa)ons Ê Read-‐only Datastore Ê “Regular” failures Ê The Capabili)es API is provided to enable you to handle maintenance periods.
is bare bones and based on WSGI. Ê Any WSGI framework can run on App Engine. Ê Kay Ê Components: Django, Werkzeug, Jinja2, babel Ê h:p://code.google.com/p/kay-‐framework/ Ê Tipfy Ê Custom framework with mul)ple template engines, and plugins. Ê h:p://www.)pfy.org/ Ê Django-‐nonrel Ê A NoSQL-‐op)mized version of Django. Ê Wesley Chun’s from Google presented on this at PyCon. Ê h:p://www.allbu:onspressed.com/projects/django-‐nonrel
Service” can lock you in Ê Data lock-‐in is probably a bigger problem than frameworks. Ê Possible solu)ons Ê Typhoon AE: h:p://code.google.com/p/typhoonae/ Ê AppScale: h:p://sites.google.com/site/gaeasaframework/appscale Ê Essen)ally these are a lot of pain to setup, and you are probably using the App Engine framework to solve the wrong problem. Ê A be:er solu)on is to use a na)ve Python framework: Ê Django: h:p://www.djangoproject.com/ Ê Pyramid (Pylons): h:p://pylonsproject.org/ Ê Flask: h:p://flask.pocoo.org/