google app engine
TRANSCRIPT
Copyright@share2create License 1
Google App engine
Senthilkumar M
Copyright@share2create License 2
What is Google App Engine?
• Google App Engine is a complete development stack that uses familiar technologies to build and host applications on the same infrastructure used at Google.
Copyright@share2create License 3
Four runtime environments
Python
Java GO
PHP
Copyright@share2create License 4
Your code runs in a sandbox
• Secure environment that provides limited access to the underlying operating system.
• The sandbox allows App Engine to• distribute web requests across multiple servers• start and stop servers to meet traffic demands• isolate apps in a secure, reliable environment• abstract hardware, operating system and
physical location of the web server
Copyright@share2create License 5
Sandbox limitations
• outbound connections: only through the provided URL fetch and email services or the experimental Socket API.
• inbound connections: only HTTP(s) on ports 80/443.• File system access: writing files is not allowed. An application
can read only files uploaded with the application code.• no native code: libraries that depend on native code are
generally not available.• time limits: app code must terminate within given time
limits. (60s for web requests, 10m for tasks but unlimited time for backend jobs)
Copyright@share2create License 6
Storing data
•Three options for data storage
App Engine Data store Google Cloud SQL Google Cloud Storage
NoSQL schemeless data storage built in GAE
relational SQL database service based on MySQL file based storage
Copyright@share2create License 7
What special in host on GAE
• No fixed cost pay only on what you use• FREE!!!!• Your APP running on the platform which
powers Google service.• App can be scalable to any extend.
Copyright@share2create License 8
Lets Run your First App
• Download the SDK• Go to
https://developers.google.com/appengine/downloads and grab the Python installer.
• Download Python 2.7 installer.• Go tohttp://www.python.org/download/releases/2.7/
Copyright@share2create License 9
Startup the Launcher
Copyright@share2create License 10
Create a Sample Application
Copyright@share2create License 11
Lets write your first code
• App.yaml => It is configuration file for your application
Copyright@share2create License 12
Main.py
#!/usr/bin/env python
import webapp2
class MainHandler(webapp2.RequestHandler): def get(self): self.response.write('Hello world!')
app = webapp2.WSGIApplication([ ('/', MainHandler)], debug=True)
Copyright@share2create License 13
Datastore(s)
• There are two implementations of datastore• The original one is implemented
in google.appengine.ext.db• The new one is called NDB and it is
implemented in google.appengine.ext.ndb• They are very similar but not identical• We will cover NDB
Copyright@share2create License 14
Creating Data store Entity
from google.appengine.ext import ndbclass Contact(ndb.Model): name = ndb.StringProperty() email = ndb.StringProperty() birth_date = ndb.DateProperty()
Copyright@share2create License 15
Querying the Data store
from google.appengine.ext import ndb
def StoresByCity(city, limit): query = Store.query(Store.city == city).order(Store.name) return query.fetch(limit, projection=[Store.name, Store.address])
• The Data store API is Object Oriented.• Queries are objects• Filters and projections are specified by calling methods• Make sure you know the limits!
Copyright@share2create License 16
Querying the Data store with GQL
from google.appengine.ext import ndb
def query_info(): qry = ndb.gql("SELECT * FROM Account WHERE balance < :1", 100) return qry
• You can write queries with GQL, a SQL-like language.• GQL is translated to NDB's native query API. (This is the
opposite of what traditional ORM libraries do!)
Copyright@share2create License 17
View templates
<html> <body> {% for contact in contacts %} {% if contact.name %} <b>{{ contact.name }}</b> {% else %} Unnamed contact {% endif %} <{{ contact.email }}> {% endfor %} <a href="{{ url }}">{{ url_linktext }}</a> </body> </html>
If you use webapp2, Django Templates are supported by default.
Copyright@share2create License 18
Dispatch to view templates
def render_template(self, view_filename, params=None) if not params: params = {} path = os.path.join(os.path.dirname(__file__), 'views', view_filename) self.response.out.write(template.render(path, params)):
Here is how to render a template in with webapp2
Copyright@share2create License 19
Memcache
from google.appengine.api import memcache def get_data(): data = memcache.get('key') if data is not None: return data else: data = self.query_for_data() memcache.add('key', data, 60) return data
• Memcache is a high-performance, distributed memory object caching system.
• Can be used to minimize hits to the Datastore or to save transient state information.
Copyright@share2create License 20
My sample host apps
• Check out this links• http://senonscreen.appspot.com/• http://me2mentor.appspot.com/• http://sentengo.appspot.com/
Copyright@share2create License 21
Questions?
Copyright@share2create License 22