app engine
DESCRIPTION
A presentation given to django-nyc on June 19th, 2008, on django and the Google AppEngine.TRANSCRIPT
![Page 1: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/1.jpg)
Google App EngineDjango-style
![Page 2: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/2.jpg)
Python Development on Google Infrastructure
- Allows deployment of web applications on Google’s famously robust infrastructure.- Google is a big Python shop - Python is the only language initially supported on AppEngine- (“Wordle” Google AppEngine application).
![Page 3: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/3.jpg)
• Data Store
• Images
• Memcache
• URL Fetch
• Users
App Engine APIs
- Data Store API offers persistent storage in a RDBMS-like environment- Image API offers uploadable images and transformations such as resize, rotate, crop, flip, and the mysterious “I’m feeling lucky” transformation.- Mail API offers email services.- Memcache API offers use of the same memory caching technology used in production Django deployments.- URL Fetch offers HTTP client services, allowing HTTP access to other web services.- Users API offers integration with Google Accounts.
![Page 4: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/4.jpg)
App Engine Basics- We’re going to look briefly at creating “Hello World” as an AppEngine app.
![Page 5: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/5.jpg)
Dev Environment
- First you need to download the development environment.- Nice graphical tools available for Windows and OS X- Command line tools otherwise available
![Page 6: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/6.jpg)
Dev Environment
- On OS X, the app launcher shows the apps you have available, providing tools to run them locally and deploy them to Google.
![Page 7: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/7.jpg)
Dev Environment
dev_appserver.py
appcfg.py
- Ultimately this is icing over the command line tools that do the work:
dev_appserver.py is the development web server.
appcfg.py is the tool for uploading your app to Google.
![Page 8: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/8.jpg)
- First you need to create an application at appengine.google.com.- Currently you are limited to 3 applications, and you must live on the namespace .appspot.com.
![Page 9: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/9.jpg)
Vanilla App- From there you can generate a new app. A basic AppEngine app contains three files at minimum:1. “app.yaml” is a YAML file that identifies basic information about the application, and maps URL patterns to “handlers”.2. “index.yaml” is a YAML file that is used in conjunction with queries to the Data Store service.4. “main.py” is the starter “handler” code. It is referenced in “app.yaml”.
![Page 10: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/10.jpg)
app.yaml- specifies meta-data about the application - name - version
- specifies “handlers”, somewhat similar to how Apache maps url patterns to handlers.- handlers are python files.
![Page 11: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/11.jpg)
handler: main.py
- handler classes subclass RequestHandler- handler is registered by sending the handler class and the context path to a WSGIApplication.- the WSGIApplication is passed to the wsgiref.handlers module (part of standard Python WSGI).(WSGI, the Web Server Gateway Interface, is the standard for Python web applications. It is Django’s goal for 1.0 to be 100% WSGI compliant.)- The Handler implements methods corresponding to HTTP methods. These methods are called when an HTTP request comes in that matches the context path set in the WSGIApplication.
![Page 12: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/12.jpg)
Development Commands
• dev_appserver.py django-nyc
• appcfg.py update django-nyc
- dev_appserver.py runs the development server for that app, analagous to manage.py runserver- appcfg.py will upload the latest version of the application to Google - you must have created the app on the AppEngine console before doing this
![Page 13: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/13.jpg)
Where’s the Django?
![Page 14: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/14.jpg)
The Django Helper project
- Google has a project that allows people to adapt Django projects to Google AppEngine- Allows for a higher level of abstraction than the vanilla AppEngine apps provide.
![Page 15: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/15.jpg)
appengine_django- google-app-engine-django provides a new app for you to copy into your project: appengine_django. You need to add it to your INSTALLED_APPS.
![Page 16: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/16.jpg)
app.yaml- app.yaml is mostly the same.- note that /static is routed to a static directory, and not to the python handler
![Page 17: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/17.jpg)
main.py- main.py is supplied by appengine_django. It uses a built in handler to act as the RequestHandler - delegating to the Django framework.- from here the request path becomes standard Django: the settings.py file specifies the main urls.py file, which in turn delegate to other urls.py files, or maps requests to views.
![Page 18: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/18.jpg)
Data Modeling
- Google doesn’t use a relational database system in the traditional sense.- The appengine_django app provides an alternate ORM to the application than the standard Django ORM.
![Page 19: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/19.jpg)
- The familiar Poll app, redone in AppEngine.- Note that the *Property objects are analogous to Field classes in the Django ORM
![Page 20: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/20.jpg)
There is no spoon syncdb.
![Page 21: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/21.jpg)
There’s also no admin console.
WTF?
![Page 22: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/22.jpg)
http://localhost:8080/_ah/admin
- There is, however, a different kind of development admin console that allows browsing of data...
![Page 23: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/23.jpg)
http://localhost:8080/_ah/admin
- ...and entry of new data.
![Page 24: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/24.jpg)
Django versions
• 0.96 supported out of the box
• Later versions (trunk) can be supported by adding Django itself as a module in the application.
![Page 25: App Engine](https://reader034.vdocuments.us/reader034/viewer/2022042614/559ca46a1a28abaa0d8b4635/html5/thumbnails/25.jpg)
Discussion