Post on 08-May-2015
description
Sebastián Serranosebastian@devsar.comtwitter: sserrano44 http://www.lp-gtug.or
g
Google App Engine + Pythonen 5 minutos
Cloud Computing??
0% Administracion = 100% Desarrollo
Google App Engine
• Fácil de Desarrollar
• Fácil de Mantener
• Fácil de Escalar
Servicios del App Engine
Lenguajes
Empezar es GRATIS!• ~5M pageviews/month
• 6.5 CPU hrs/day
• 1 GB storage
• 650K URL Fetch calls/day
• 2,000 recipients emailed
• 1 GB/day bandwidth
• 100,000 tasks enqueued
• 650K XMPP messages/day
App Engine Dashboard
SDK Console
Primeros pasos App Engine
• Descargar el SDKo http://code.google.com/appengine
• Registrar una cuentao https://appengine.google.com
• Escribir código - deploy!
$ dev_appserver.py helloworld # run dev svr$ appcfg.py update helloworld # deploy live
Linux, MacOS, etc. command-line:
Windows GUI (y Mac):
Arrancar un proyecto
app.yaml – archivo configuración main principal
index.yaml – generado automáticamente para indexar nuestros datos
main.py – el código de la aplicación
Contenido basico
main.py
$ dev_appserver.py helloworldINFO 2009-03-04 17:51:22,354 __init__.py]
Local development server
Deploying the application
• Set application identifier• Run deploy script• You're live!
Modifying app.yamlapplication: helloworldversion: 1runtime: pythonapi_version: 1
handlers:- url: .*script: main.py
Running the deploy script
$ appcfg.py update helloworldScanning files on local disk.Initiating update.Email: ...
You're live!
Demo time??
main.py: Skeleton applicationfrom google.appengine.ext import webappfrom google.appengine.ext.webapp import util
class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hello world!')
def main(): application = webapp.WSGIApplication([('/', MainHandler)], debug=True) util.run_wsgi_app(application)
if __name__ == '__main__': main()
main.py: Adding a handlerfrom google.appengine.ext import webappfrom google.appengine.ext.webapp.util import run_wsgi_app
class MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('<h1>Hello world!</h1>') self.response.out.write(''' <form action="/sign" method=post> <input type=text name=content> <br><input type=submit value="Sign Guestbook"> </form> ''')
class GuestBook(webapp.RequestHandler): def post(self): self.response.out.write( '<h2>You wrote:</h2> %s' % self.request.get('content') )
application = webapp.WSGIApplication([ ('/', MainHandler), ('/sign', GuestBook),], debug=True)
# start_wsgi_app etc ...
main.py: Persisting to the datastoreclass GuestBook(webapp.RequestHandler): def post(self): greeting = Greeting() greeting.content = self.request.get('content') greeting.put() self.redirect('/')
main.py: Collecting values from the datastoreclass MainHandler(webapp.RequestHandler): def get(self): self.response.out.write('Hello world!') self.response.out.write('<h1>My GuestBook</h1><ol>') greetings = Greeting.all() for greeting in greetings: self.response.out.write('<li> %s' % greeting.content) self.response.out.write(''' </ol><hr> <form action="/sign" method=post> <textarea name=content rows=3 cols=60></textarea> <br><input type=submit value="Sign Guestbook"> </form> ''')
Live demo??
Gracias!
email: sebastian@devsar.com
twitter: sserrano44