SlideShare a Scribd company logo
Introduction to Google App Engine with PythonBrian 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 Studieshttp://code.google.com/appengine/casestudies.htmlMost 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 monthGoogle post quotas and costs on their websitehttp://code.google.com/appengine/docs/quotas.htmlOnce 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 costsCalculating 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 EngineYou can’t really choose a framework or tool without some experience. Take this advice with a pinch of salt.GoodYou 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.MaybeAn existing application is written in Python (or Java) and you want to create a web front end.BadData 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 PythonZed Shaw’s “Learn Python the Hard Way” is recommended.http://learnpythonthehardway.org/indexMany other resources are available:http://diveintopython.org/toc/index.htmlhttp://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 toolsPython 2.5Only 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 SDKDownload the latest version and it will auto-update.Free from http://code.google.com/appengine/downloads.htmlA suitable editorMost (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 samplesAll docs can be downloaded as a ZIPhttp://code.google.com/appengine/downloads.html - Download_the_Google_App_Engine_DocumentationDocumentationhttp://code.google.com/appengine/docs/python/overview.htmlSample Codehttp://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=0http://brizzled.clapper.org/id/77/VideosGoogle IO Conference on YouTtube.PyCon: http://pycon.bliptv.com
Services provided by App EngineDatastore (SQL Server)Blobstore (File system)CapabilitiesChannel (comet?)Images (ImageGlue.NET)Mail (BCL)Memcache (AppFabric)Multitenancy (SQL Schemas)OAuth (BCL)Prospective SearchTask 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.comLimitations:SSL for custom domainsQuotas impacting cost are complexUsers all have Gmail emails by defaultPython libraries which depend on C extensions cannot run on the platform.Google-like search requires some effort.
App Engine Launcher
SDK Console
Basic App Engine demoBookmarkzBookmark databaseURL shortenerUsing the default “webapp” frameworkSource code is available from https://bitbucket.org/brianly/bookmarkz/src
Webapp frameworkBased on a basic framework called WebObthat 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 handlerfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_appclass 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()
DatastoreYou 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 ModelsModels 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 typeshttp://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.htmlQueryquery = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John")query = db.Query(Song)query.filter('composer=', id)result = query.get()Definitionclass Song(db.Model):    author = db.UserProperty()composer = db.StringProperty()    date = db.DateTimeProperty    (auto_now_add=True)    tags = db.StringListProperty()    description = db.TextProperty()
More ModelsExpando and PolyModel.More information can be found in the SDK documentationclass Person(db.Expando):first_name = 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()
BlobstoreLimits apply to object size in the datastore. Store large objects e.g. images or documents in the BlobstoreExceptions 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 FetchEnables 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 urlfetchresult = 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 QueuesAllows you to do work later such as send a notification, or update a 3rd party system.# Application queues a tasktaskqueue.add(url='/worker', params={'key': key})# Handler does the workclass CounterWorker(webapp.RequestHandler):def post(self): # should run at most 1/s        key = self.request.get('key')deftxn():            counter = Counter.get_by_key_name(key)            if counter is None:                counter = Counter(key_name=key, count=1)            else:counter.count += 1counter.put()db.run_in_transaction(txn)
Notes for Windows usersPython 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 portsNo server == no fun
App Engine Dashboard
Health and uptimeCheck the status page if you experience issues.SituationsRead-only Datastore“Regular” failuresThe Capabilities API is provided to enable you to handle maintenance periods.
Better frameworks for App EngineThe “webapp” framework is bare bones and based on WSGI.Any WSGI framework can run on App Engine.KayComponents: Django, Werkzeug, Jinja2, babelhttp://code.google.com/p/kay-framework/TipfyCustom framework with multiple template engines, and plugins.http://www.tipfy.org/Django-nonrelA 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 inData lock-in is probably a bigger problem than frameworks.Possible solutionsTyphoon AE: http://code.google.com/p/typhoonae/AppScale: http://sites.google.com/site/gaeasaframework/appscaleEssentially 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

PDF
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
PDF
Introduction to Google App Engine
PPT
Developing Java Web Applications In Google App Engine
ZIP
Google App Engine
PDF
Google App Engine tutorial
PPT
Google App Engine for Java
PPT
Google App Engine
PPT
Google app engine introduction
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
Introduction to Google App Engine
Developing Java Web Applications In Google App Engine
Google App Engine
Google App Engine tutorial
Google App Engine for Java
Google App Engine
Google app engine introduction

What's hot (20)

PDF
Introduction to Google App Engine
PDF
Google App Engine: An Introduction
PDF
What is Google App Engine
PDF
Cloud Computing Bootcamp On The Google App Engine v1.2.1
PPTX
Google app engine
PDF
Google App Engine's Latest Features
PPTX
Google App Engine
ODP
Introduction to Google App Engine
PDF
What is Google App Engine?
PDF
Google App Engine (Introduction)
PDF
Google Application Engine
PPTX
Google app engine - Overview
PPT
Google App Engine - Overview #3
PDF
App Engine Overview @ Google Hackathon SXSW 2010
PDF
Introduction to Google Cloud Endpoints: Speed Up Your API Development
KEY
Introduction to Google App Engine
PDF
DEVOPS AND MACHINE LEARNING
PPTX
Getting Started with Firebase Cloud Functions
PDF
Introduction to Firebase from Google
PPTX
TypeScript and SharePoint Framework
Introduction to Google App Engine
Google App Engine: An Introduction
What is Google App Engine
Cloud Computing Bootcamp On The Google App Engine v1.2.1
Google app engine
Google App Engine's Latest Features
Google App Engine
Introduction to Google App Engine
What is Google App Engine?
Google App Engine (Introduction)
Google Application Engine
Google app engine - Overview
Google App Engine - Overview #3
App Engine Overview @ Google Hackathon SXSW 2010
Introduction to Google Cloud Endpoints: Speed Up Your API Development
Introduction to Google App Engine
DEVOPS AND MACHINE LEARNING
Getting Started with Firebase Cloud Functions
Introduction to Firebase from Google
TypeScript and SharePoint Framework
Ad

Viewers also liked (20)

PDF
Google app-engine-with-python
PPTX
Using Google App Engine Python
PPTX
Google App Engine for Python - Unit01: Basic
PDF
Build website in_django
PDF
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
PPTX
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
PDF
Quick flask an intro to flask
PDF
Python and GIS
PDF
Writing your first web app using Python and Flask
PDF
Google app engine python
KEY
Gae icc fall2011
PDF
App Engine for Python Developers
PDF
App Engine On Air: Munich
PDF
App Engine
PPT
Introduccion app engine con python
PDF
Flask patterns
PDF
Making use of OpenStreetMap data with Python
PPTX
Flask – Python
PPTX
OpenStreetMap in 3D using Python
PDF
Docker on Google App Engine
Google app-engine-with-python
Using Google App Engine Python
Google App Engine for Python - Unit01: Basic
Build website in_django
Flask Full Stack - Desenvolvendo um CMS com Flask e MongoDB
Quokka CMS - Desenvolvendo web apps com Flask e MongoDB - grupy - Outubro 2015
Quick flask an intro to flask
Python and GIS
Writing your first web app using Python and Flask
Google app engine python
Gae icc fall2011
App Engine for Python Developers
App Engine On Air: Munich
App Engine
Introduccion app engine con python
Flask patterns
Making use of OpenStreetMap data with Python
Flask – Python
OpenStreetMap in 3D using Python
Docker on Google App Engine
Ad

Similar to Introduction to Google App Engine with Python (20)

PPTX
Googleappengineintro 110410190620-phpapp01
PDF
Introduction to App Engine Development
PPTX
Infinite Scale - Introduction to Google App Engine
PDF
Gentle App Engine Intro
PPT
Google App Engine - Overview #1
PDF
Google App Engine – niekonwencjonalna platforma aplikacji SaaS do Twojego nas...
PDF
I've (probably) been using Google App Engine for a week longer than you have
PPT
PyCon India 2010 Building Scalable apps using appengine
PDF
Web App Prototypes with Google App Engine
ODP
Google App Engine - unusual application plaform for your next SaaS Project
PPTX
Google app engine
PPTX
Google app engine
PPT
APP engine regarding Google app engine presentation
PPT
App_Engine_PPT.ppt
PPT
App_Engine_PPT..........................
PPT
App_Engine_PPT.ppt
PDF
Nzpug google appengine
PDF
App Engine overview (Android meetup 06-10)
ZIP
Introduction to Google App Engine
Googleappengineintro 110410190620-phpapp01
Introduction to App Engine Development
Infinite Scale - Introduction to Google App Engine
Gentle App Engine Intro
Google App Engine - Overview #1
Google App Engine – niekonwencjonalna platforma aplikacji SaaS do Twojego nas...
I've (probably) been using Google App Engine for a week longer than you have
PyCon India 2010 Building Scalable apps using appengine
Web App Prototypes with Google App Engine
Google App Engine - unusual application plaform for your next SaaS Project
Google app engine
Google app engine
APP engine regarding Google app engine presentation
App_Engine_PPT.ppt
App_Engine_PPT..........................
App_Engine_PPT.ppt
Nzpug google appengine
App Engine overview (Android meetup 06-10)
Introduction to Google App Engine

Recently uploaded (20)

PDF
NewMind AI Monthly Chronicles - July 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Electronic commerce courselecture one. Pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Machine learning based COVID-19 study performance prediction
NewMind AI Monthly Chronicles - July 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
The AUB Centre for AI in Media Proposal.docx
Understanding_Digital_Forensics_Presentation.pptx
Electronic commerce courselecture one. Pdf
Network Security Unit 5.pdf for BCA BBA.
madgavkar20181017ppt McKinsey Presentation.pdf
GamePlan Trading System Review: Professional Trader's Honest Take
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Per capita expenditure prediction using model stacking based on satellite ima...
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
“AI and Expert System Decision Support & Business Intelligence Systems”
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Machine learning based COVID-19 study performance prediction

Introduction to Google App Engine with Python

  • 1. Introduction to Google App Engine with PythonBrian 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 Studieshttp://code.google.com/appengine/casestudies.htmlMost 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 monthGoogle post quotas and costs on their websitehttp://code.google.com/appengine/docs/quotas.htmlOnce 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 costsCalculating 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 EngineYou can’t really choose a framework or tool without some experience. Take this advice with a pinch of salt.GoodYou 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.MaybeAn existing application is written in Python (or Java) and you want to create a web front end.BadData 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 PythonZed Shaw’s “Learn Python the Hard Way” is recommended.http://learnpythonthehardway.org/indexMany other resources are available:http://diveintopython.org/toc/index.htmlhttp://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 toolsPython 2.5Only 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 SDKDownload the latest version and it will auto-update.Free from http://code.google.com/appengine/downloads.htmlA suitable editorMost (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 samplesAll docs can be downloaded as a ZIPhttp://code.google.com/appengine/downloads.html - Download_the_Google_App_Engine_DocumentationDocumentationhttp://code.google.com/appengine/docs/python/overview.htmlSample Codehttp://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=0http://brizzled.clapper.org/id/77/VideosGoogle IO Conference on YouTtube.PyCon: http://pycon.bliptv.com
  • 9. Services provided by App EngineDatastore (SQL Server)Blobstore (File system)CapabilitiesChannel (comet?)Images (ImageGlue.NET)Mail (BCL)Memcache (AppFabric)Multitenancy (SQL Schemas)OAuth (BCL)Prospective SearchTask 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.comLimitations:SSL for custom domainsQuotas impacting cost are complexUsers all have Gmail emails by defaultPython libraries which depend on C extensions cannot run on the platform.Google-like search requires some effort.
  • 12. Basic App Engine demoBookmarkzBookmark databaseURL shortenerUsing the default “webapp” frameworkSource code is available from https://bitbucket.org/brianly/bookmarkz/src
  • 13. Webapp frameworkBased on a basic framework called WebObthat 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 handlerfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_appclass 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. DatastoreYou 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 ModelsModels 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 typeshttp://code.google.com/appengine/docs/python/datastore/typesandpropertyclasses.htmlQueryquery = GqlQuery("SELECT * FROM Song WHERE composer = :composer", composer="Lennon, John")query = db.Query(Song)query.filter('composer=', id)result = query.get()Definitionclass Song(db.Model): author = db.UserProperty()composer = db.StringProperty() date = db.DateTimeProperty (auto_now_add=True) tags = db.StringListProperty() description = db.TextProperty()
  • 17. More ModelsExpando and PolyModel.More information can be found in the SDK documentationclass Person(db.Expando):first_name = 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()
  • 18. BlobstoreLimits apply to object size in the datastore. Store large objects e.g. images or documents in the BlobstoreExceptions 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 FetchEnables 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 urlfetchresult = 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 QueuesAllows you to do work later such as send a notification, or update a 3rd party system.# Application queues a tasktaskqueue.add(url='/worker', params={'key': key})# Handler does the workclass CounterWorker(webapp.RequestHandler):def post(self): # should run at most 1/s key = self.request.get('key')deftxn(): counter = Counter.get_by_key_name(key) if counter is None: counter = Counter(key_name=key, count=1) else:counter.count += 1counter.put()db.run_in_transaction(txn)
  • 21. Notes for Windows usersPython 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 portsNo server == no fun
  • 23. Health and uptimeCheck the status page if you experience issues.SituationsRead-only Datastore“Regular” failuresThe Capabilities API is provided to enable you to handle maintenance periods.
  • 24. Better frameworks for App EngineThe “webapp” framework is bare bones and based on WSGI.Any WSGI framework can run on App Engine.KayComponents: Django, Werkzeug, Jinja2, babelhttp://code.google.com/p/kay-framework/TipfyCustom framework with multiple template engines, and plugins.http://www.tipfy.org/Django-nonrelA 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 inData lock-in is probably a bigger problem than frameworks.Possible solutionsTyphoon AE: http://code.google.com/p/typhoonae/AppScale: http://sites.google.com/site/gaeasaframework/appscaleEssentially 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.