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
2
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
4
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
5
6. Storing data
• Three options for data storage
App Engine Data store
NoSQL schemeless data
storage built in GAE
Google Cloud SQL
relational SQL database
service based on MySQL
Copyright@share2create License
Google Cloud Storage
file based storage
6
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
7
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 to
http://www.python.org/download/releases/2.7/
Copyright@share2create License
8
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
13
14. Creating Data store Entity
from google.appengine.ext import ndb
class Contact(ndb.Model):
name = ndb.StringProperty()
email = ndb.StringProperty()
birth_date = ndb.DateProperty()
Copyright@share2create License
14
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
15
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
16
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
17
18. Dispatch to view templates
Here is how to render a template in with webapp2
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)):
Copyright@share2create License
18
19. Memcache
• 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.
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
Copyright@share2create License
19
20. My sample host apps
•
•
•
•
Check out this links
http://senonscreen.appspot.com/
http://me2mentor.appspot.com/
http://sentengo.appspot.com/
Copyright@share2create License
20