BangPypers June Meetup 2012

Google App Engine with Python

                Deepak Garg
           Citrix R&D, Bengaluru
     deepakgarg.iitg@gmail.com


    Google App Engine with Python by Deepak Garg is licensed under a
     Creative Commons Attribution-ShareAlike 3.0 Unported License.
      Based on a work at www.slideshare.net/khinnu4u/presentations.
Contents
✔   What my App needs ?
✔   App Engine ?
✔   Python for App Engine
✔   Set Up Your Env
✔   app.yaml
✔   Wsgi
✔   Webapp2 framework
✔   Templates
✔   Static Files
✔   DataStore
✔   Admin & DashBoard
✔   App Engine Feature Set
✔   FAQ
What my App needs ?
●   App = Business Logic + IT
●   IT =>
           deploying and maintaining web and db, server
           backup, HA, scale out/in, LB etc. etc..
           Upgrades, licenses
           Monitoring
●   IT efforts remain consistent and similar across
    different apps, Business Logic differs
●   Developers want to focus on the business logic
App Engine ?
✔
    Google App Engine (aka GAE) is a Platform as a Service (PaaS)
    cloud computing platform for developing and hosting web
    applications in Google-managed data centers
✔   Applications are sandboxed and run in Google’s best-of-breed data
    centers around the world
✔   App Engine offers automatic scaling for web applications—as the
    number of requests increases for an application
✔   App Engine automatically allocates more resources for the web
    application to handle the additional demand
✔   GAE is free up to a certain level of consumed resources
✔   Fees are charged for additional storage, bandwidth, or instance hours
Python for App Engine
●   Python → 2.5, 2.7
●   Frameworks → Django, web2py, webapp, cherryPy, pylons
●   External Libraries → jinja2, lxml, numpy, webob, yaml,
    pil, pycrypto, setuptools etc..
Set up Your Env
✔   Install Python :-)
✔
    Download App Engine SDK →
          ➔   a web server application that simulates the App Engine env
          ➔   dev_appserver.py myapp → for a local webserver
          ➔   appcfg.py update myapp → to deploy to the cloud
✔   Install Eclipse   [ Optional ]
✔   Install Pydev and App Engine Eclipse Plugin [ Optional ]

     https://developers.google.com/appengine/downloads
app.yaml
●   specifies runtime configuration → versions, url handlers etc.
                                  application identifier is
application: helloworld          ”helloworld”, name used to
version: 1                       register your application
runtime: python27                with App Engine
api_version: 1                   Uploading application with
threadsafe: true                 diff version no. creates
                                 different versions on the
handlers:                        server
- url: /.*                       code runs in the python27
  script: helloworld.app         runtime environment,
                                 version "1"
                                 app is threadsafe or not

                                 URL Routers → urls matching
                                 the regex are captured
WSGI
A WSGI application is a callable with the following signature:
 def application(environ, start_response)
environ is a dictionary which contains everything in os.environ plus
variables which contain data about the HTTP reqeust.
start_response is a callable which the application calls to set the
status code and headers for a response, before returning the body of
the response.
            start_response(status, response_headers, exc_info=None)


The return value for the WSGI application is an iterable object.
Each item in the iterable is a chunk of the HTTP response body as a
byte string.
Webapp2 framework
●   A webapp2 application has 2 parts:
         ➔   one or more RequestHandler classes that process requests
               and build responses
         ➔   a WSGIApplication instance that routes incoming requests to
               handlers based on the URL


       import webapp2
       class MainPage(webapp2.RequestHandler):
           def get(self):
               self.response.headers['Content-Type'] = 'text/plain'
               self.response.out.write('Hello, webapp World!')
       app = webapp2.WSGIApplication([('/', MainPage)],
                                     debug=True)
Templates
                                                         libraries:
●   Import jinja2 in app.yaml                            - name: jinja2
                                                           version: latest
●   Point jinja2 to your template dir
    jinjadir = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir))



●   Load your templates
                      fom = jinjadir.get_template('form.template')

●   Render your templates
                       fom.render({'items':['a', 'b', 'c']})
Static Files
●   create your static directory
                                              ­ url: /mystatic   
●   point to it in app.yaml                     static_dir: mystatic 



                              Deploy
●   register your app_id           https://appengine.google.com/
●   point to it in app.yaml           application: app_id 
                                      version: 1 
●   update version no.
●   upload your app                appcfg.py update myapp



●   browse your app :)         http://app_id.appspot.com/
DataStore
●   Google’s Bigtable high-performance distributed database
●   Not a Relational DB – scales awesomely well !
●   Replicate data across multiple DCs
●   Data is written to the Datastore in objects known as entities.
    Each entity has a key that uniquely identifies it
●   Every entity has a unique identifier
●   An entity can optionally designate another entity as its parent
    and thus form a hierarchy
              Object Oriented Relational DB        DataStore
              Class             Table              Kind
              Object            Record             Entity
              Attribute         Column             Propery

     https://developers.google.com/appengine/docs/python/datastore/entities
DataStore
●   define your entity class       from google.appengine.ext import db

●   create object (entity)         class PyperDB(db.Model):
                                      name = db.StringProperty(multiline=True);
●   put it in db                      status = db.BooleanProperty();
                                      user_id = db.UserProperty();
●   check it in DB viewer             time = db.DateTimeProperty(auto_now_add=True)

                               us = PyperDB(name=val, status=False, user_id=uid)
                               us.put();


●   Model defines a unique id by             key = us.key().id_or_name()
    default for each entity
                                          result = db.GqlQuery("SELECT * "
●   Fetch data using GQL queries                          "FROM PyperDB "
                                                          ”WHERE ANCESTOR IS :1 "
                                          ”ORDER BY date DESC LIMIT 10",key_value)
●   Delete   uis = PyperDB.all()

             for p in uis:
                 p.delete()

https://developers.google.com/appengine/docs/python/datastore/gqlreference
Admin & DashBoard
●   Local Admin console running at http://localhost:9999/_ah/admin
●   GAE Dashboard, logs, DS viewer etc. are used to manage your
    app
GAE Features




https://developers.google.com/appengine/docs/python/apis
FAQ
●   Can I run existing django apps on App Engine ?
●   Can I move my App Engine application to my hosting
    environment ?
            Yes, Look at django-rel (django for non-relational db
              http://www.allbuttonspressed.com/projects/django-nonrel
              http://www.allbuttonspressed.com/projects/djangoappengine
●   Can I run any Python code on App Engine ?
            With certain limitations →
                     cannot write to FS but you can read ( from flat file you
                        uploaded )
                     cannot open a socket, can't make system call,
                     can't respond slowly to requests ( 60 secs )
Many Thanks !

deepakgarg.iitg@gmail.com

         @donji

   github.com/gargdeepak

More Related Content

PPTX
Google App Engine for Python - Unit01: Basic
PDF
Introduction to App Engine Development
PDF
Modular Test-driven SPAs with Spring and AngularJS
PPTX
Cloud Endpoints _Polymer_ Material design by Martin Görner
PDF
Introduction to Google Cloud Endpoints: Speed Up Your API Development
PPTX
AngularJS for Java Developers
PPTX
Introduction to angular with a simple but complete project
PPTX
Voluminous_Weibo
Google App Engine for Python - Unit01: Basic
Introduction to App Engine Development
Modular Test-driven SPAs with Spring and AngularJS
Cloud Endpoints _Polymer_ Material design by Martin Görner
Introduction to Google Cloud Endpoints: Speed Up Your API Development
AngularJS for Java Developers
Introduction to angular with a simple but complete project
Voluminous_Weibo

What's hot (20)

PDF
DrupalGap. How to create native application for mobile devices based on Drupa...
PDF
Page object pattern
PDF
How to React Native
PDF
React Native +Redux + ES6 (Updated)
PDF
The Gist of React Native
PDF
Ten practical ways to improve front-end performance
PDF
React Native custom components
PPTX
Android jetpack compose | Declarative UI
PDF
PyUIA 0.3
PPTX
Using Google App Engine Python
PPTX
Angular js 2
PPTX
Angular js
PDF
Advanced Dagger talk from 360andev
PDF
Android dev tips
PDF
Try Jetpack Compose
PPTX
React inter3
PDF
React Native - Workshop
PDF
Build and Distributing SDK Add-Ons
PDF
Overview of the AngularJS framework
PDF
React Native Workshop - React Alicante
DrupalGap. How to create native application for mobile devices based on Drupa...
Page object pattern
How to React Native
React Native +Redux + ES6 (Updated)
The Gist of React Native
Ten practical ways to improve front-end performance
React Native custom components
Android jetpack compose | Declarative UI
PyUIA 0.3
Using Google App Engine Python
Angular js 2
Angular js
Advanced Dagger talk from 360andev
Android dev tips
Try Jetpack Compose
React inter3
React Native - Workshop
Build and Distributing SDK Add-Ons
Overview of the AngularJS framework
React Native Workshop - React Alicante
Ad

Viewers also liked (11)

PPTX
Introduction to Google App Engine with Python
PDF
App Engine On Air: Munich
PDF
App Engine for Python Developers
PDF
App Engine
PPT
Introduccion app engine con python
KEY
Gae icc fall2011
PDF
Google app engine python
PDF
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
PDF
Google datastore & search api
PPTX
Google Cloud Platform. Google App Engine
PDF
Google App Engine
Introduction to Google App Engine with Python
App Engine On Air: Munich
App Engine for Python Developers
App Engine
Introduccion app engine con python
Gae icc fall2011
Google app engine python
Soft-Shake 2016 : Jigsaw est prêt à tuer le classpath
Google datastore & search api
Google Cloud Platform. Google App Engine
Google App Engine
Ad

Similar to Google app-engine-with-python (20)

PPTX
Googleappengineintro 110410190620-phpapp01
PDF
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
PPTX
Infinite Scale - Introduction to Google App Engine
PPT
Google App Engine - Overview #1
PDF
What is Google App Engine?
PDF
Gentle App Engine Intro
PDF
App Engine overview (Android meetup 06-10)
PDF
Python Ireland Nov 2009 Talk - Appengine
KEY
GAE_20100112
PDF
Web App Prototypes with Google App Engine
ZIP
Introduction to Google App Engine
PPT
Designing the Call of Cthulhu app with Google App Engine
PDF
Art & music vs Google App Engine
PDF
Google App Engine in 40 minutes (the absolute essentials)
PDF
Managing Large Flask Applications On Google App Engine (GAE)
PPT
Introduction to Google App Engine
PPTX
PDF
Introduction to Google App Engine
PDF
OSCON Google App Engine Codelab - July 2010
PDF
Appscale at CLOUDCOMP '09
Googleappengineintro 110410190620-phpapp01
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
Infinite Scale - Introduction to Google App Engine
Google App Engine - Overview #1
What is Google App Engine?
Gentle App Engine Intro
App Engine overview (Android meetup 06-10)
Python Ireland Nov 2009 Talk - Appengine
GAE_20100112
Web App Prototypes with Google App Engine
Introduction to Google App Engine
Designing the Call of Cthulhu app with Google App Engine
Art & music vs Google App Engine
Google App Engine in 40 minutes (the absolute essentials)
Managing Large Flask Applications On Google App Engine (GAE)
Introduction to Google App Engine
Introduction to Google App Engine
OSCON Google App Engine Codelab - July 2010
Appscale at CLOUDCOMP '09

More from Deepak Garg (6)

PPT
Foundation launch
PDF
Developing with-devstack
PDF
NetScaler and advanced networking in cloudstack
PDF
Openstack India May Meetup
PDF
Bangpypers april-meetup-2012
PDF
Social coding and Participating in Open Source Communitites
Foundation launch
Developing with-devstack
NetScaler and advanced networking in cloudstack
Openstack India May Meetup
Bangpypers april-meetup-2012
Social coding and Participating in Open Source Communitites

Recently uploaded (20)

PDF
0520_Scheme_of_Work_(for_examination_from_2021).pdf
PDF
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
PDF
Journal of Dental Science - UDMY (2022).pdf
PDF
Compact First Student's Book Cambridge Official
PDF
Literature_Review_methods_ BRACU_MKT426 course material
PPTX
PLASMA AND ITS CONSTITUENTS 123.pptx
PPTX
ACFE CERTIFICATION TRAINING ON LAW.pptx
PPTX
Climate Change and Its Global Impact.pptx
PDF
Hospital Case Study .architecture design
PDF
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
PDF
Everyday Spelling and Grammar by Kathi Wyldeck
PDF
Journal of Dental Science - UDMY (2020).pdf
PDF
semiconductor packaging in vlsi design fab
PDF
Disorder of Endocrine system (1).pdfyyhyyyy
PPTX
Thinking Routines and Learning Engagements.pptx
PPTX
BSCE 2 NIGHT (CHAPTER 2) just cases.pptx
PDF
Nurlina - Urban Planner Portfolio (english ver)
PPT
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
PDF
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
PDF
The TKT Course. Modules 1, 2, 3.for self study
0520_Scheme_of_Work_(for_examination_from_2021).pdf
LIFE & LIVING TRILOGY - PART (3) REALITY & MYSTERY.pdf
Journal of Dental Science - UDMY (2022).pdf
Compact First Student's Book Cambridge Official
Literature_Review_methods_ BRACU_MKT426 course material
PLASMA AND ITS CONSTITUENTS 123.pptx
ACFE CERTIFICATION TRAINING ON LAW.pptx
Climate Change and Its Global Impact.pptx
Hospital Case Study .architecture design
Horaris_Grups_25-26_Definitiu_15_07_25.pdf
Everyday Spelling and Grammar by Kathi Wyldeck
Journal of Dental Science - UDMY (2020).pdf
semiconductor packaging in vlsi design fab
Disorder of Endocrine system (1).pdfyyhyyyy
Thinking Routines and Learning Engagements.pptx
BSCE 2 NIGHT (CHAPTER 2) just cases.pptx
Nurlina - Urban Planner Portfolio (english ver)
REGULATION OF RESPIRATION lecture note 200L [Autosaved]-1-1.ppt
Fun with Grammar (Communicative Activities for the Azar Grammar Series)
The TKT Course. Modules 1, 2, 3.for self study

Google app-engine-with-python

  • 1. BangPypers June Meetup 2012 Google App Engine with Python Deepak Garg Citrix R&D, Bengaluru [email protected] Google App Engine with Python by Deepak Garg is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Based on a work at www.slideshare.net/khinnu4u/presentations.
  • 2. Contents ✔ What my App needs ? ✔ App Engine ? ✔ Python for App Engine ✔ Set Up Your Env ✔ app.yaml ✔ Wsgi ✔ Webapp2 framework ✔ Templates ✔ Static Files ✔ DataStore ✔ Admin & DashBoard ✔ App Engine Feature Set ✔ FAQ
  • 3. What my App needs ? ● App = Business Logic + IT ● IT =>  deploying and maintaining web and db, server  backup, HA, scale out/in, LB etc. etc..  Upgrades, licenses  Monitoring ● IT efforts remain consistent and similar across different apps, Business Logic differs ● Developers want to focus on the business logic
  • 4. App Engine ? ✔ Google App Engine (aka GAE) is a Platform as a Service (PaaS) cloud computing platform for developing and hosting web applications in Google-managed data centers ✔ Applications are sandboxed and run in Google’s best-of-breed data centers around the world ✔ App Engine offers automatic scaling for web applications—as the number of requests increases for an application ✔ App Engine automatically allocates more resources for the web application to handle the additional demand ✔ GAE is free up to a certain level of consumed resources ✔ Fees are charged for additional storage, bandwidth, or instance hours
  • 5. Python for App Engine ● Python → 2.5, 2.7 ● Frameworks → Django, web2py, webapp, cherryPy, pylons ● External Libraries → jinja2, lxml, numpy, webob, yaml, pil, pycrypto, setuptools etc..
  • 6. Set up Your Env ✔ Install Python :-) ✔ Download App Engine SDK → ➔ a web server application that simulates the App Engine env ➔ dev_appserver.py myapp → for a local webserver ➔ appcfg.py update myapp → to deploy to the cloud ✔ Install Eclipse [ Optional ] ✔ Install Pydev and App Engine Eclipse Plugin [ Optional ] https://developers.google.com/appengine/downloads
  • 7. app.yaml ● specifies runtime configuration → versions, url handlers etc. application identifier is application: helloworld ”helloworld”, name used to version: 1 register your application runtime: python27 with App Engine api_version: 1 Uploading application with threadsafe: true diff version no. creates different versions on the handlers: server - url: /.* code runs in the python27   script: helloworld.app runtime environment, version "1" app is threadsafe or not URL Routers → urls matching the regex are captured
  • 8. WSGI A WSGI application is a callable with the following signature: def application(environ, start_response) environ is a dictionary which contains everything in os.environ plus variables which contain data about the HTTP reqeust. start_response is a callable which the application calls to set the status code and headers for a response, before returning the body of the response. start_response(status, response_headers, exc_info=None) The return value for the WSGI application is an iterable object. Each item in the iterable is a chunk of the HTTP response body as a byte string.
  • 9. Webapp2 framework ● A webapp2 application has 2 parts: ➔ one or more RequestHandler classes that process requests and build responses ➔ a WSGIApplication instance that routes incoming requests to handlers based on the URL import webapp2 class MainPage(webapp2.RequestHandler):     def get(self):         self.response.headers['Content-Type'] = 'text/plain'         self.response.out.write('Hello, webapp World!') app = webapp2.WSGIApplication([('/', MainPage)],                               debug=True)
  • 10. Templates libraries: ● Import jinja2 in app.yaml - name: jinja2   version: latest ● Point jinja2 to your template dir jinjadir = jinja2.Environment(loader=jinja2.FileSystemLoader(template_dir)) ● Load your templates fom = jinjadir.get_template('form.template') ● Render your templates fom.render({'items':['a', 'b', 'c']})
  • 11. Static Files ● create your static directory ­ url: /mystatic    ● point to it in app.yaml   static_dir: mystatic  Deploy ● register your app_id https://appengine.google.com/ ● point to it in app.yaml application: app_id  version: 1  ● update version no. ● upload your app appcfg.py update myapp ● browse your app :) http://app_id.appspot.com/
  • 12. DataStore ● Google’s Bigtable high-performance distributed database ● Not a Relational DB – scales awesomely well ! ● Replicate data across multiple DCs ● Data is written to the Datastore in objects known as entities. Each entity has a key that uniquely identifies it ● Every entity has a unique identifier ● An entity can optionally designate another entity as its parent and thus form a hierarchy Object Oriented Relational DB DataStore Class Table Kind Object Record Entity Attribute Column Propery https://developers.google.com/appengine/docs/python/datastore/entities
  • 13. DataStore ● define your entity class from google.appengine.ext import db ● create object (entity) class PyperDB(db.Model): name = db.StringProperty(multiline=True); ● put it in db status = db.BooleanProperty(); user_id = db.UserProperty(); ● check it in DB viewer time = db.DateTimeProperty(auto_now_add=True) us = PyperDB(name=val, status=False, user_id=uid) us.put(); ● Model defines a unique id by key = us.key().id_or_name() default for each entity result = db.GqlQuery("SELECT * " ● Fetch data using GQL queries                 "FROM PyperDB "                 ”WHERE ANCESTOR IS :1 " ”ORDER BY date DESC LIMIT 10",key_value) ● Delete uis = PyperDB.all() for p in uis:     p.delete() https://developers.google.com/appengine/docs/python/datastore/gqlreference
  • 14. Admin & DashBoard ● Local Admin console running at http://localhost:9999/_ah/admin ● GAE Dashboard, logs, DS viewer etc. are used to manage your app
  • 16. FAQ ● Can I run existing django apps on App Engine ? ● Can I move my App Engine application to my hosting environment ?  Yes, Look at django-rel (django for non-relational db http://www.allbuttonspressed.com/projects/django-nonrel http://www.allbuttonspressed.com/projects/djangoappengine ● Can I run any Python code on App Engine ?  With certain limitations →  cannot write to FS but you can read ( from flat file you uploaded )  cannot open a socket, can't make system call,  can't respond slowly to requests ( 60 secs )
  • 17. Many Thanks ! [email protected] @donji github.com/gargdeepak