SlideShare a Scribd company logo
Introduction to Google
App Engine with Python
           Brian Lyttle (http://brianlyttle.com)
                            @brianly on Twitter
What is Google App Engine?
 Google call it “cloud development in a box”.

 It is a hosted development environment along the lines of Microsoft
   Azure.
 Targets users building internet applications, but that is changing.

 Built on the same scalable platform 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.
Who’s using App Engine?




 Case Studies
   http://code.google.com/appengine/casestudies.html

 Most often GAE is used as a utility alongside another platform.

 GAE for Business will increase uptake. Eventually.
How much does it cost?
   It is free to get started, or run small applications.
       ~5M page views per month

   Google post quotas and costs on their website
       http://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 alternative deployment
    platforms.
       Choice of datastore can even impact costs

   Calculating costs can be tricky, but this is the case with all usage-based cloud providers and
    services.
       You need to know your application, and the how the platform can be best used applied to
        your needs.
       Cheaper features might have potential for higher lock-in.
Mapping use cases to App Engine
   You can’t 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 application needs to support a ridiculous number of users, or giant fluctuations in usage.
         You want to quickly prototype a larger application that you may develop elsewhere.

   Maybe
         An existing application is written in Python (or Java) and you want to create a web front end.

   Bad
         Data sources for your application 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.
Learning Python
 Zed Shaw’s “Learn Python the Hard Way” is recommended.
   http://learnpythonthehardway.org/index

 Many other resources are available:
   http://diveintopython.org/toc/index.html
   http://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.
Development tools
 Python 2.5
   Only this version is supported at present.
   Free from http://www.python.org/ftp/python/
   Get the latest 2.5.x release from http://www.python.org/ftp/python/2.5.5/

 Google App Engine SDK
   Download the latest version and it will auto-update.
   Free from http://code.google.com/appengine/downloads.html

 A suitable editor
   Most (good) text editors provide syntax highlighting.
   I like JetBrains’ PyCharm, but ActiveState 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.
Documentation and samples
   All docs can be downloaded as a ZIP
       http://code.google.com/appengine/downloads.html -
        Download_the_Google_App_Engine_Documentation

   Documentation
       http://code.google.com/appengine/docs/python/overview.html

   Sample Code
       http://code.google.com/p/google-app-engine-samples/
       http://code.google.com/p/rietveld/
       https://github.com/search?langOverride=&language=python&q=google+app+engine&repo=
        &start_value=1&type=Repositories&x=0&y=0
       http://brizzled.clapper.org/id/77/

   Videos
       Google IO Conference on YouTtube.
       PyCon: http://pycon.bliptv.com
Services provided by App Engine
                                               Datastore (SQL Server)
 Services are accessed via “webapp”.
                                               Blobstore (File system)
                                               Capabilities
 Most have equivalents in the .NET world
   (shown in parentheses)                      Channel (comet?)
                                               Images (ImageGlue.NET)
 Sites hosted at *.appspot.com                Mail (BCL)
                                               Memcache (AppFabric)
 Limitations:                                 Multitenancy (SQL Schemas)
   SSL for custom domains                     OAuth (BCL)
   Quotas impacting cost are complex          Prospective Search
   Users all have Gmail emails by default     Task Queues (MSMQ)

   Python libraries which depend on C         URL Fetch (BCL)
     extensions cannot run on the platform.    Users (BCL)

   Google-like search requires some effort.   XMPP (Lync API)
App Engine Launcher
SDK Console
Basic App Engine demo

 Bookmarkz
   Bookmark database
   URL shortener

 Using the default “webapp” framework

 Source code is available from
  https://bitbucket.org/brianly/bookmarkz/src
Webapp framework

 Based on a basic framework called 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.

 Convention or configuration? Neither.

 For a lot of applications you should be considering a
   framework like Tipfy (more later).
Example handler
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

class MainPage(webapp.RequestHandler):
    def get(self):
        self.response.headers['Content-Type'] = 'text/plain'
        self.response.out.write('Hello, webapp World!')

application = webapp.WSGIApplication(
                                        [('/', MainPage)],
                                        debug=True)

def main():
    run_wsgi_app(application)

if __name__ == "__main__":
    main()
Datastore

 You Entities based on Classes which derive from a special base class.

 Google provide a range of data types for Entity properties.

 Entities are stored in a system based on Big Table (Master/Slave) or
   Megastore (High Replication).
    You choose this when you create your application.

 Choice of storage affects costs and can’t be changed easily.

 Google recommend the High Replication datastore for better all
   round performance.
    Fewer peaks and troughs compared to the Master/Slave store.
Working with Models
 Models are defined in Python in a similar fashion to other ORM tools.

 The challenges are a little different from your experiences using ORMs with
   relational databases.

 Data types
   http://code.google.com/appengine/docs/python/datastore/typesandpropertycla
     sses.html
Definition                                Query

class Song(db.Model):                     query = GqlQuery("SELECT * FROM
    author = db.UserProperty()                     Song WHERE composer
    composer = db.StringProperty()                 = :composer",
    date = db.DateTimeProperty                     composer="Lennon, John")
             (auto_now_add=True)
    tags = db.StringListProperty()        query = db.Query(Song)
    description = db.TextProperty()       query.filter('composer=', id)
                                          result = query.get()
More Models

   Expando and PolyModel.

   More information can be found in the SDK documentation

class Person(db.Expando):              class Contact(polymodel.PolyModel):
   first_name = db.StringProperty()       phone_number = db.PhoneNumberProperty()
   last_name = db.StringProperty()        address = db.PostalAddressProperty()
   hobbies = db.StringListProperty()
                                       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()
Blobstore
 Limits apply to object size in the datastore.

 Store large objects e.g. images or documents in the Blobstore

 Exceptions 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.
URL Fetch
 Enables requests to HTTP and HTTPS 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.
Task Queues

 Allows you to do work later such as send a notification, 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)
Notes for Windows users
 Python works pretty well 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 application 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
App Engine Dashboard
Health and uptime

 Check the status page if
   you experience issues.

 Situations
    Read-only Datastore
    “Regular” failures

 The Capabilities API is
   provided to enable you
   to handle maintenance
   periods.
Better frameworks for App Engine
 The “webapp” framework is bare bones and based on WSGI.

 Any WSGI framework can run on App Engine.

 Kay
    Components: Django, Werkzeug, Jinja2, babel
    http://code.google.com/p/kay-framework/

 Tipfy
    Custom framework with multiple template engines, and plugins.
    http://www.tipfy.org/

 Django-nonrel
    A NoSQL-optimized version of Django.
    Wesley Chun’s from Google presented on this at PyCon.
    http://www.allbuttonspressed.com/projects/django-nonrel
Run your own App Engine
 “Platform as a Service” can lock you in
   Data lock-in is probably a bigger problem than frameworks.

 Possible solutions
   Typhoon AE: http://code.google.com/p/typhoonae/
   AppScale: http://sites.google.com/site/gaeasaframework/appscale

 Essentially these are a lot of pain to setup, and you are probably
   using the App Engine framework to solve the wrong problem.
 A better solution is to use a native Python framework:
   Django: http://www.djangoproject.com/
   Pyramid (Pylons): http://pylonsproject.org/
   Flask: http://flask.pocoo.org/
Thanks!

 Don’t forget to provide provide feedback on my talk and
   others you attended today.

 Slides and code will be posted to http://brianlyttle.com
   shortly.

More Related Content

What's hot (13)

PPT
WPF Concepts
Doncho Minkov
 
PPT
Pragmatics of Declarative Ajax
davejohnson
 
PPT
Declarative Development Using Annotations In PHP
Stephan Schmidt
 
PPTX
Django Architecture Introduction
Haiqi Chen
 
PPT
Ajax to the Moon
davejohnson
 
KEY
Jumpstart Django
ryates
 
PPTX
RailsConf 2010: From 1 to 30 - How to refactor one monolithic application int...
jpalley
 
PDF
<img src="../i/r_14.png" />
tutorialsruby
 
ODP
REST dojo Comet
Carol McDonald
 
PDF
You suck at Memory Analysis
Francisco Ribeiro
 
KEY
A Conversation About REST
Jeremy Brown
 
PPT
Boston Computing Review - Java Server Pages
John Brunswick
 
PDF
Intro to mobile web application development
zonathen
 
WPF Concepts
Doncho Minkov
 
Pragmatics of Declarative Ajax
davejohnson
 
Declarative Development Using Annotations In PHP
Stephan Schmidt
 
Django Architecture Introduction
Haiqi Chen
 
Ajax to the Moon
davejohnson
 
Jumpstart Django
ryates
 
RailsConf 2010: From 1 to 30 - How to refactor one monolithic application int...
jpalley
 
<img src="../i/r_14.png" />
tutorialsruby
 
REST dojo Comet
Carol McDonald
 
You suck at Memory Analysis
Francisco Ribeiro
 
A Conversation About REST
Jeremy Brown
 
Boston Computing Review - Java Server Pages
John Brunswick
 
Intro to mobile web application development
zonathen
 

Viewers also liked (7)

PPT
SE@M 2010: Automatic Keywords Extraction - a Basis for Content Recommendation
Ivana Bosnic
 
PDF
如何建置關鍵字精靈 How to Build an Keyword Wizard
晨揚 施
 
PPTX
Text Analytics on 2 Million Documents: A Case Study
Alyona Medelyan
 
PPTX
KiwiPyCon 2014 - NLP with Python tutorial
Alyona Medelyan
 
PDF
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Jimmy Lai
 
PPTX
Introduction to Text Mining
Minha Hwang
 
PDF
Summarization using ntc approach based on keyword extraction for discussion f...
eSAT Publishing House
 
SE@M 2010: Automatic Keywords Extraction - a Basis for Content Recommendation
Ivana Bosnic
 
如何建置關鍵字精靈 How to Build an Keyword Wizard
晨揚 施
 
Text Analytics on 2 Million Documents: A Case Study
Alyona Medelyan
 
KiwiPyCon 2014 - NLP with Python tutorial
Alyona Medelyan
 
Text Classification in Python – using Pandas, scikit-learn, IPython Notebook ...
Jimmy Lai
 
Introduction to Text Mining
Minha Hwang
 
Summarization using ntc approach based on keyword extraction for discussion f...
eSAT Publishing House
 
Ad

Similar to Googleappengineintro 110410190620-phpapp01 (20)

PPTX
Introduction to Google App Engine with Python
Brian Lyttle
 
PDF
Introduction to App Engine Development
Ron Reiter
 
PDF
Google app-engine-with-python
Deepak Garg
 
PDF
App Engine On Air: Munich
dion
 
PDF
Web App Prototypes with Google App Engine
Vlad Filippov
 
PDF
I've (probably) been using Google App Engine for a week longer than you have
Simon Willison
 
PDF
Gentle App Engine Intro
robinb123
 
PPT
Google App Engine - Overview #1
Kay Kim
 
PDF
App Engine overview (Android meetup 06-10)
jasonacooper
 
PPTX
Google app engine
Senthilkumar Murugesan
 
PPT
PyCon India 2010 Building Scalable apps using appengine
Pranav Prakash
 
PDF
What is Google App Engine?
weschwee
 
PDF
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
hosleadamsfy
 
PPTX
Google app engine
Renjith318
 
PDF
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
mahadekurg
 
PPTX
Infinite Scale - Introduction to Google App Engine
Marian Borca
 
PDF
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
folepechet
 
PDF
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
bejdajzaher
 
PDF
Google App Engine – niekonwencjonalna platforma aplikacji SaaS do Twojego nas...
3camp
 
PDF
App Engine
Loren Davie
 
Introduction to Google App Engine with Python
Brian Lyttle
 
Introduction to App Engine Development
Ron Reiter
 
Google app-engine-with-python
Deepak Garg
 
App Engine On Air: Munich
dion
 
Web App Prototypes with Google App Engine
Vlad Filippov
 
I've (probably) been using Google App Engine for a week longer than you have
Simon Willison
 
Gentle App Engine Intro
robinb123
 
Google App Engine - Overview #1
Kay Kim
 
App Engine overview (Android meetup 06-10)
jasonacooper
 
Google app engine
Senthilkumar Murugesan
 
PyCon India 2010 Building Scalable apps using appengine
Pranav Prakash
 
What is Google App Engine?
weschwee
 
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
hosleadamsfy
 
Google app engine
Renjith318
 
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
mahadekurg
 
Infinite Scale - Introduction to Google App Engine
Marian Borca
 
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
folepechet
 
Distributed and Cloud Computing 1st Edition Hwang Solutions Manual
bejdajzaher
 
Google App Engine – niekonwencjonalna platforma aplikacji SaaS do Twojego nas...
3camp
 
App Engine
Loren Davie
 
Ad

Googleappengineintro 110410190620-phpapp01

  • 1. Introduction to Google App Engine with Python Brian Lyttle (http://brianlyttle.com) @brianly on Twitter
  • 2. What is Google App Engine?  Google call it “cloud development in a box”.  It is a hosted development environment along the lines of Microsoft Azure.  Targets users building internet applications, but that is changing.  Built on the same scalable platform 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.
  • 3. Who’s using App Engine?  Case Studies  http://code.google.com/appengine/casestudies.html  Most often GAE is used as a utility alongside another platform.  GAE for Business will increase uptake. Eventually.
  • 4. How much does it cost?  It is free to get started, or run small applications.  ~5M page views per month  Google post quotas and costs on their website  http://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 alternative deployment platforms.  Choice of datastore can even impact costs  Calculating costs can be tricky, but this is the case with all usage-based cloud providers and services.  You need to know your application, and the how the platform can be best used applied to your needs.  Cheaper features might have potential for higher lock-in.
  • 5. Mapping use cases to App Engine  You can’t 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 application needs to support a ridiculous number of users, or giant fluctuations in usage.  You want to quickly prototype a larger application that you may develop elsewhere.  Maybe  An existing application is written in Python (or Java) and you want to create a web front end.  Bad  Data sources for your application 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.
  • 6. Learning Python  Zed Shaw’s “Learn Python the Hard Way” is recommended.  http://learnpythonthehardway.org/index  Many other resources are available:  http://diveintopython.org/toc/index.html  http://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.
  • 7. Development tools  Python 2.5  Only this version is supported at present.  Free from http://www.python.org/ftp/python/  Get the latest 2.5.x release from http://www.python.org/ftp/python/2.5.5/  Google App Engine SDK  Download the latest version and it will auto-update.  Free from http://code.google.com/appengine/downloads.html  A suitable editor  Most (good) text editors provide syntax highlighting.  I like JetBrains’ PyCharm, but ActiveState 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.
  • 8. Documentation and samples  All docs can be downloaded as a ZIP  http://code.google.com/appengine/downloads.html - Download_the_Google_App_Engine_Documentation  Documentation  http://code.google.com/appengine/docs/python/overview.html  Sample Code  http://code.google.com/p/google-app-engine-samples/  http://code.google.com/p/rietveld/  https://github.com/search?langOverride=&language=python&q=google+app+engine&repo= &start_value=1&type=Repositories&x=0&y=0  http://brizzled.clapper.org/id/77/  Videos  Google IO Conference on YouTtube.  PyCon: http://pycon.bliptv.com
  • 9. Services provided by App Engine Datastore (SQL Server)  Services are accessed via “webapp”. Blobstore (File system) Capabilities  Most have equivalents in the .NET world (shown in parentheses) Channel (comet?) Images (ImageGlue.NET)  Sites hosted at *.appspot.com Mail (BCL) Memcache (AppFabric)  Limitations: Multitenancy (SQL Schemas)  SSL for custom domains OAuth (BCL)  Quotas impacting cost are complex Prospective Search  Users all have Gmail emails by default Task Queues (MSMQ)  Python libraries which depend on C URL Fetch (BCL) extensions cannot run on the platform. Users (BCL)  Google-like search requires some effort. XMPP (Lync API)
  • 12. Basic App Engine demo  Bookmarkz  Bookmark database  URL shortener  Using the default “webapp” framework  Source code is available from https://bitbucket.org/brianly/bookmarkz/src
  • 13. Webapp framework  Based on a basic framework called 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.  Convention or configuration? Neither.  For a lot of applications you should be considering a framework like Tipfy (more later).
  • 14. Example handler from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class MainPage(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') application = webapp.WSGIApplication( [('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main()
  • 15. Datastore  You Entities based on Classes which derive from a special base class.  Google provide a range of data types for Entity properties.  Entities are stored in a system based on Big Table (Master/Slave) or Megastore (High Replication).  You choose this when you create your application.  Choice of storage affects costs and can’t be changed easily.  Google recommend the High Replication datastore for better all round performance.  Fewer peaks and troughs compared to the Master/Slave store.
  • 16. Working with Models  Models are defined in Python in a similar fashion to other ORM tools.  The challenges are a little different from your experiences using ORMs with relational databases.  Data types  http://code.google.com/appengine/docs/python/datastore/typesandpropertycla sses.html Definition Query class Song(db.Model): query = GqlQuery("SELECT * FROM author = db.UserProperty() Song WHERE composer composer = db.StringProperty() = :composer", date = db.DateTimeProperty composer="Lennon, John") (auto_now_add=True) tags = db.StringListProperty() query = db.Query(Song) description = db.TextProperty() query.filter('composer=', id) result = query.get()
  • 17. More Models  Expando and PolyModel.  More information can be found in the SDK documentation class Person(db.Expando): class Contact(polymodel.PolyModel): first_name = db.StringProperty() phone_number = db.PhoneNumberProperty() last_name = db.StringProperty() address = db.PostalAddressProperty() hobbies = db.StringListProperty() 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()
  • 18. Blobstore  Limits apply to object size in the datastore.  Store large objects e.g. images or documents in the Blobstore  Exceptions 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.
  • 19. URL Fetch  Enables requests to HTTP and HTTPS 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.
  • 20. Task Queues  Allows you to do work later such as send a notification, 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)
  • 21. Notes for Windows users  Python works pretty well 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 application 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
  • 23. Health and uptime  Check the status page if you experience issues.  Situations  Read-only Datastore  “Regular” failures  The Capabilities API is provided to enable you to handle maintenance periods.
  • 24. Better frameworks for App Engine  The “webapp” framework is bare bones and based on WSGI.  Any WSGI framework can run on App Engine.  Kay  Components: Django, Werkzeug, Jinja2, babel  http://code.google.com/p/kay-framework/  Tipfy  Custom framework with multiple template engines, and plugins.  http://www.tipfy.org/  Django-nonrel  A NoSQL-optimized version of Django.  Wesley Chun’s from Google presented on this at PyCon.  http://www.allbuttonspressed.com/projects/django-nonrel
  • 25. Run your own App Engine  “Platform as a Service” can lock you in  Data lock-in is probably a bigger problem than frameworks.  Possible solutions  Typhoon AE: http://code.google.com/p/typhoonae/  AppScale: http://sites.google.com/site/gaeasaframework/appscale  Essentially these are a lot of pain to setup, and you are probably using the App Engine framework to solve the wrong problem.  A better solution is to use a native Python framework:  Django: http://www.djangoproject.com/  Pyramid (Pylons): http://pylonsproject.org/  Flask: http://flask.pocoo.org/
  • 26. Thanks!  Don’t forget to provide provide feedback on my talk and others you attended today.  Slides and code will be posted to http://brianlyttle.com shortly.