SlideShare a Scribd company logo
Google App Engine (GAE)
Wei-Tsung Su (蘇維宗)
ellington.su@gmail.com
06/30/2014 (Ver. 1.0)
Ubiquitous Computing and Ambient Networking Laboratory 1
Change Log
Date Ver. Authors Description
6/30/2014 1.0 Wei-Tsung Su Google App Engine (GAE); GAE for Python; Using Static Files; Google User Service
Ubiquitous Computing and Ambient Networking Laboratory 2
What?
• Google Cloud Platform
– App Engine provides Platform as a Service (PaaS)
– Compute Engine provides Infrastrcture as a Servce (IaaS)
– CloudSQL, Cloud Storage, and Cloud Datastore provide storage options
– BigQuery and Hadoop provide big data processing capability
• Language supported by GAE
– Python, Java, PHP, and GO
– Different languages may provide different features.
Ubiquitous Computing and Ambient Networking Laboratory 3
Why?
• Easily deploy your web services to public
• Seamlessly integrate with other Google services
• Free quotas (https://developers.google.com/appengine/docs/quotas)
– Code & Static Data Store (1GB free)
– Google Cloud Storage (5GB free)
– Blobstore Stored Data (5GB free)
– API access (which depends on different Google API)
– ...
Ubiquitous Computing and Ambient Networking Laboratory 4
How?
• Read Support Documentation
– https://developers.google.com/appengine/
• Try Administration Console
– https://appengine.google.com/
– https://console.developers.google.com
• Download SDK
– https://developers.google.com/appengine/downloads
Start Your Engine
3, 2, 1
Ubiquitous Computing and Ambient Networking Laboratory 5
GAE for Python
Ubiquitous Computing and Ambient Networking Laboratory 6
Setup Development Environment
• Install Python 2.7
– https://www.python.org/download/releases/2.7.7/
• Install App Engine SDK for Python
– https://developers.google.com/appengine/downloads
– Ex. we assume that google_appengine/ is the SDK directory.
• Install Git (optional)
– http://git-scm.com/downloads
Ubiquitous Computing and Ambient Networking Laboratory 7
How GAE for Python Works
• A Python web app interacts with the App Engine web server using
Web Server Gateway Interface (WSGI) protocol.
• WSGI-compatible web application frameworks, such as
– webapp2 (by default, simple)
– Django
– CherryPy
– Pylons
– web.py
– web2py
Ubiquitous Computing and Ambient Networking Laboratory 8
Project Structure of GAE for Python
• Modules
– Dynamic web page generation
– http://webapp-improved.appspot.com/
– Filename: xxx.py (ex. helloword.py)
• Configuration File
– Project configuration
– Routing requests to modules
– https://developers.google.com/appengine/docs/python/config/appconfig
– Filename: app.yaml (壓謀!)
• Ex. we assume that helloworld/ is the project directory
Ubiquitous Computing and Ambient Networking Laboratory 9
Module: helloworld. py
• import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/ html'
self.response.write('Hello, World!')
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
• For security issue, you should disable debug which will display a
stack trace in the browser when a handler raises an exception.
Ubiquitous Computing and Ambient Networking Laboratory 10
Configuration File: app.yaml
• application: your-app-id
version: 1
runtime: python27
api_version: 1
threadsafe: true
handlers:
- url: /.*
script: helloworld.app
• How to test your project locally
– # google_appengine/dev_appserver.py helloworld/
– Test your web app by visiting the URL: http://localhost:8080
Ubiquitous Computing and Ambient Networking Laboratory 11
Hello, World!
Ubiquitous Computing and Ambient Networking Laboratory 12
Using Static Files
• Sometimes, you may put static files, such images, CSS stylesheets,
JavaScript code, and so on, into your web applications.
• For example,
– <img src="/images/logo.png" >
• Unfortunately, you cannot just
create a directory and put the
static files into the directory.
• You also need to add route into
con figuration file: app.yaml
– - url: /images
static_dir: images
Ubiquitous Computing and Ambient Networking Laboratory 13
Google User Service
• Google user service (https://developers.google.com/appengine/docs/python/users/)
• Import user service module
– from google.appengine.api import users
• Get current user
– user = users.get_current_user() # Google Account, Google Apps Account, OpenID
• Access user information
– user.nickname()
– user.email()
– user.user_id()
• Administrator check
– user.is_current_user_admin()
• Create login/logout pages
– users.create_login_url('[destination URL]')
– users.create_logout_url('[destination URL]')
Ubiquitous Computing and Ambient Networking Laboratory 14
Google User Service - Example
• from google.appengine.api import users
import webapp2
class MainPage(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user:
self.response.headers['Content-Type'] = 'text/ html'
self.response.write('Hello, World, %s!<br>', %(user.nickname()))
self.response.write('<a href="%s">Sign Out</a>'
% users.create_logout_url(self.request.url))
else:
self.redirect(users.create_login_url(self.request.url) )
app = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Ubiquitous Computing and Ambient Networking Laboratory 15
Hello, World, User!
Ubiquitous Computing and Ambient Networking Laboratory 16
Deploy Your Application
• Step 1: Create Project in Developer Console
– https://console.developers.google.com
– You will get a random project id (Ex. your-app-id).
– The public URL of your web application will be
• http://your-app-id.appspot.com
• Step 2: Check if the application ID in app.yaml matches your-app-id
– application: your-app-id
• Step 3: Deploy your local project
– #google_appengine/appcfg.py update helloworld/
– Test your web app by visiting the URL: http://your-app-id.appspot.com
Ubiquitous Computing and Ambient Networking Laboratory 17
Q&A
You can clone the sample code by
git clone https://github.com/ucanlab/gae_python_basic_helloworld.git
or visiting
https://github.com/ucanlab/gae_python_basic_helloworld
Ubiquitous Computing and Ambient Networking Laboratory 18

More Related Content

PDF
Google app-engine-with-python
PPTX
The Best Way to Become an Android Developer Expert with Android Jetpack
PDF
Recap of Android Dev Summit 2018
PDF
Google apps script introduction
PPTX
Android Intermediatte IAK full
PPTX
Developing eXtensions for HUE
PDF
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
PDF
Best Practices in Widget Development - Examples and Counterexamples
Google app-engine-with-python
The Best Way to Become an Android Developer Expert with Android Jetpack
Recap of Android Dev Summit 2018
Google apps script introduction
Android Intermediatte IAK full
Developing eXtensions for HUE
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
Best Practices in Widget Development - Examples and Counterexamples

What's hot (20)

PDF
Build your application in seconds and optimize workflow as much as you can us...
PPTX
Tips and tricks for building Large web applications with Drupal
PDF
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
PDF
Deep dive into Vue.js
PDF
introduction to Vue.js 3
PPTX
Using and contributing to the next Guice
PDF
Play Framework on Google App Engine - Productivity Stack
PDF
DrupalGap. How to create native application for mobile devices based on Drupa...
PDF
Introducing the (new) Google Docs API (2019)
PPTX
Cloud Function For Firebase - GITS
PDF
An Introduction to Django Web Framework
PPT
Google Web Toolkit
PDF
Drupal and diversity of Single sign-on systems
PDF
Improving app performance with Kotlin Coroutines
PDF
Intro to sbt-web
PDF
Introduction to Google Cloud Endpoints: Speed Up Your API Development
PPTX
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
PDF
Ten practical ways to improve front-end performance
PDF
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
PDF
Drupal content automation with migrate 2.6
Build your application in seconds and optimize workflow as much as you can us...
Tips and tricks for building Large web applications with Drupal
ID Android TechTalk Series #6 : Google Service and Gradle - Anton Nurdin Tuha...
Deep dive into Vue.js
introduction to Vue.js 3
Using and contributing to the next Guice
Play Framework on Google App Engine - Productivity Stack
DrupalGap. How to create native application for mobile devices based on Drupa...
Introducing the (new) Google Docs API (2019)
Cloud Function For Firebase - GITS
An Introduction to Django Web Framework
Google Web Toolkit
Drupal and diversity of Single sign-on systems
Improving app performance with Kotlin Coroutines
Intro to sbt-web
Introduction to Google Cloud Endpoints: Speed Up Your API Development
SenchaCon 2016: Building Enterprise Ext JS Apps with Mavenized Sencha Cmd - F...
Ten practical ways to improve front-end performance
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Drupal content automation with migrate 2.6
Ad

Viewers also liked (20)

PPTX
Using Google App Engine Python
PPTX
Introduction to Google App Engine with Python
PDF
Introduction to Version Control
PPTX
Google Glass - Unit01: Design
PDF
創業的藝術
PDF
Introduction to OAuth
PDF
軟體系統測試簡介
PDF
Arduino Yun Mini - 使用SQLite
PDF
Google app engine python
KEY
Gae icc fall2011
PDF
App Engine On Air: Munich
PPT
Introduccion app engine con python
PDF
App Engine
PDF
App Engine for Python Developers
PDF
Arduino Yun Mini簡介
PPTX
LinkIt Smart 7688程式開發
PPTX
MQTT簡介與使用開放原始碼
PDF
Introduction to Wi-Fi Direct
PDF
Introducing MQTT
PPTX
Introduction to NFC
Using Google App Engine Python
Introduction to Google App Engine with Python
Introduction to Version Control
Google Glass - Unit01: Design
創業的藝術
Introduction to OAuth
軟體系統測試簡介
Arduino Yun Mini - 使用SQLite
Google app engine python
Gae icc fall2011
App Engine On Air: Munich
Introduccion app engine con python
App Engine
App Engine for Python Developers
Arduino Yun Mini簡介
LinkIt Smart 7688程式開發
MQTT簡介與使用開放原始碼
Introduction to Wi-Fi Direct
Introducing MQTT
Introduction to NFC
Ad

Similar to Google App Engine for Python - Unit01: Basic (20)

PDF
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
PPTX
Infinite Scale - Introduction to Google App Engine
KEY
GAE_20100112
PDF
Introduction to Google App Engine
PDF
Introduction to App Engine Development
PPT
Designing the Call of Cthulhu app with Google App Engine
PDF
What is Google App Engine?
PDF
Art & music vs Google App Engine
PPTX
CloudPlatforms-Cloud PLatforms evaluation
PDF
App engine devfest_mexico_10
PPTX
Googleappengineintro 110410190620-phpapp01
PDF
App Engine overview (Android meetup 06-10)
PDF
Download ebooks file Code in the Cloud 1st Edition Mark C. Chu-Carroll all ch...
PDF
Google App Engine in 40 minutes (the absolute essentials)
KEY
Introduction to Google App Engine
PDF
Code In The Cloud 1st Edition Mark C Chucarroll
PDF
Google App Engine 7 9-14
PDF
Build Android App using GCE & GAE
PDF
Appscale at CLOUDCOMP '09
PDF
Code in the Cloud 1st Edition Mark C. Chu-Carroll
Introduction to Google App Engine - Naga Rohit S [ IIT Guwahati ] - Google De...
Infinite Scale - Introduction to Google App Engine
GAE_20100112
Introduction to Google App Engine
Introduction to App Engine Development
Designing the Call of Cthulhu app with Google App Engine
What is Google App Engine?
Art & music vs Google App Engine
CloudPlatforms-Cloud PLatforms evaluation
App engine devfest_mexico_10
Googleappengineintro 110410190620-phpapp01
App Engine overview (Android meetup 06-10)
Download ebooks file Code in the Cloud 1st Edition Mark C. Chu-Carroll all ch...
Google App Engine in 40 minutes (the absolute essentials)
Introduction to Google App Engine
Code In The Cloud 1st Edition Mark C Chucarroll
Google App Engine 7 9-14
Build Android App using GCE & GAE
Appscale at CLOUDCOMP '09
Code in the Cloud 1st Edition Mark C. Chu-Carroll

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
cuic standard and advanced reporting.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Machine learning based COVID-19 study performance prediction
Mobile App Security Testing_ A Comprehensive Guide.pdf
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
A comparative analysis of optical character recognition models for extracting...
Spectral efficient network and resource selection model in 5G networks
Digital-Transformation-Roadmap-for-Companies.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
The AUB Centre for AI in Media Proposal.docx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Review of recent advances in non-invasive hemoglobin estimation
cuic standard and advanced reporting.pdf
Programs and apps: productivity, graphics, security and other tools
Spectroscopy.pptx food analysis technology
Encapsulation_ Review paper, used for researhc scholars
Building Integrated photovoltaic BIPV_UPV.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Google App Engine for Python - Unit01: Basic

  • 1. Google App Engine (GAE) Wei-Tsung Su (蘇維宗) ellington.su@gmail.com 06/30/2014 (Ver. 1.0) Ubiquitous Computing and Ambient Networking Laboratory 1
  • 2. Change Log Date Ver. Authors Description 6/30/2014 1.0 Wei-Tsung Su Google App Engine (GAE); GAE for Python; Using Static Files; Google User Service Ubiquitous Computing and Ambient Networking Laboratory 2
  • 3. What? • Google Cloud Platform – App Engine provides Platform as a Service (PaaS) – Compute Engine provides Infrastrcture as a Servce (IaaS) – CloudSQL, Cloud Storage, and Cloud Datastore provide storage options – BigQuery and Hadoop provide big data processing capability • Language supported by GAE – Python, Java, PHP, and GO – Different languages may provide different features. Ubiquitous Computing and Ambient Networking Laboratory 3
  • 4. Why? • Easily deploy your web services to public • Seamlessly integrate with other Google services • Free quotas (https://developers.google.com/appengine/docs/quotas) – Code & Static Data Store (1GB free) – Google Cloud Storage (5GB free) – Blobstore Stored Data (5GB free) – API access (which depends on different Google API) – ... Ubiquitous Computing and Ambient Networking Laboratory 4
  • 5. How? • Read Support Documentation – https://developers.google.com/appengine/ • Try Administration Console – https://appengine.google.com/ – https://console.developers.google.com • Download SDK – https://developers.google.com/appengine/downloads Start Your Engine 3, 2, 1 Ubiquitous Computing and Ambient Networking Laboratory 5
  • 6. GAE for Python Ubiquitous Computing and Ambient Networking Laboratory 6
  • 7. Setup Development Environment • Install Python 2.7 – https://www.python.org/download/releases/2.7.7/ • Install App Engine SDK for Python – https://developers.google.com/appengine/downloads – Ex. we assume that google_appengine/ is the SDK directory. • Install Git (optional) – http://git-scm.com/downloads Ubiquitous Computing and Ambient Networking Laboratory 7
  • 8. How GAE for Python Works • A Python web app interacts with the App Engine web server using Web Server Gateway Interface (WSGI) protocol. • WSGI-compatible web application frameworks, such as – webapp2 (by default, simple) – Django – CherryPy – Pylons – web.py – web2py Ubiquitous Computing and Ambient Networking Laboratory 8
  • 9. Project Structure of GAE for Python • Modules – Dynamic web page generation – http://webapp-improved.appspot.com/ – Filename: xxx.py (ex. helloword.py) • Configuration File – Project configuration – Routing requests to modules – https://developers.google.com/appengine/docs/python/config/appconfig – Filename: app.yaml (壓謀!) • Ex. we assume that helloworld/ is the project directory Ubiquitous Computing and Ambient Networking Laboratory 9
  • 10. Module: helloworld. py • import webapp2 class MainPage(webapp2.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/ html' self.response.write('Hello, World!') app = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) • For security issue, you should disable debug which will display a stack trace in the browser when a handler raises an exception. Ubiquitous Computing and Ambient Networking Laboratory 10
  • 11. Configuration File: app.yaml • application: your-app-id version: 1 runtime: python27 api_version: 1 threadsafe: true handlers: - url: /.* script: helloworld.app • How to test your project locally – # google_appengine/dev_appserver.py helloworld/ – Test your web app by visiting the URL: http://localhost:8080 Ubiquitous Computing and Ambient Networking Laboratory 11
  • 12. Hello, World! Ubiquitous Computing and Ambient Networking Laboratory 12
  • 13. Using Static Files • Sometimes, you may put static files, such images, CSS stylesheets, JavaScript code, and so on, into your web applications. • For example, – <img src="/images/logo.png" > • Unfortunately, you cannot just create a directory and put the static files into the directory. • You also need to add route into con figuration file: app.yaml – - url: /images static_dir: images Ubiquitous Computing and Ambient Networking Laboratory 13
  • 14. Google User Service • Google user service (https://developers.google.com/appengine/docs/python/users/) • Import user service module – from google.appengine.api import users • Get current user – user = users.get_current_user() # Google Account, Google Apps Account, OpenID • Access user information – user.nickname() – user.email() – user.user_id() • Administrator check – user.is_current_user_admin() • Create login/logout pages – users.create_login_url('[destination URL]') – users.create_logout_url('[destination URL]') Ubiquitous Computing and Ambient Networking Laboratory 14
  • 15. Google User Service - Example • from google.appengine.api import users import webapp2 class MainPage(webapp2.RequestHandler): def get(self): user = users.get_current_user() if user: self.response.headers['Content-Type'] = 'text/ html' self.response.write('Hello, World, %s!<br>', %(user.nickname())) self.response.write('<a href="%s">Sign Out</a>' % users.create_logout_url(self.request.url)) else: self.redirect(users.create_login_url(self.request.url) ) app = webapp2.WSGIApplication([ ('/', MainPage), ], debug=True) Ubiquitous Computing and Ambient Networking Laboratory 15
  • 16. Hello, World, User! Ubiquitous Computing and Ambient Networking Laboratory 16
  • 17. Deploy Your Application • Step 1: Create Project in Developer Console – https://console.developers.google.com – You will get a random project id (Ex. your-app-id). – The public URL of your web application will be • http://your-app-id.appspot.com • Step 2: Check if the application ID in app.yaml matches your-app-id – application: your-app-id • Step 3: Deploy your local project – #google_appengine/appcfg.py update helloworld/ – Test your web app by visiting the URL: http://your-app-id.appspot.com Ubiquitous Computing and Ambient Networking Laboratory 17
  • 18. Q&A You can clone the sample code by git clone https://github.com/ucanlab/gae_python_basic_helloworld.git or visiting https://github.com/ucanlab/gae_python_basic_helloworld Ubiquitous Computing and Ambient Networking Laboratory 18