introduccion app engine con python

25
Sebastián Serrano [email protected] twitter: sserrano44 http://www.lp-gt ug.org Google App Engine + Python en 5 minutos

Upload: sserrano44

Post on 08-May-2015

2.290 views

Category:

Technology


2 download

DESCRIPTION

Slides de la charla en GTUG Buenos Aires acerca de el Google App Engine con Python

TRANSCRIPT

Page 1: Introduccion app engine con python

Sebastián [email protected]: sserrano44 http://www.lp-gtug.or

g

Google App Engine + Pythonen 5 minutos

Page 2: Introduccion app engine con python

Cloud Computing??

Page 3: Introduccion app engine con python

0% Administracion = 100% Desarrollo

Page 4: Introduccion app engine con python

Google App Engine

• Fácil de Desarrollar

• Fácil de Mantener

• Fácil de Escalar

Page 5: Introduccion app engine con python

Servicios del App Engine

Page 6: Introduccion app engine con python

Lenguajes

Page 7: Introduccion app engine con python

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 

Page 8: Introduccion app engine con python

App Engine Dashboard

Page 9: Introduccion app engine con python

SDK Console

Page 10: Introduccion app engine con python

Primeros pasos App Engine

• Descargar el SDKo http://code.google.com/appengine

• Registrar una cuentao https://appengine.google.com

• Escribir código - deploy!

Page 11: Introduccion app engine con python

$ 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

Page 12: Introduccion app engine con python

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

Page 13: Introduccion app engine con python

main.py

Page 14: Introduccion app engine con python

$ dev_appserver.py helloworldINFO 2009-03-04 17:51:22,354 __init__.py]

Local development server

Page 15: Introduccion app engine con python

Deploying the application

• Set application identifier• Run deploy script• You're live!

Page 16: Introduccion app engine con python

Modifying app.yamlapplication: helloworldversion: 1runtime: pythonapi_version: 1

handlers:- url: .*script: main.py

Page 17: Introduccion app engine con python

Running the deploy script

$ appcfg.py update helloworldScanning files on local disk.Initiating update.Email: ...

Page 18: Introduccion app engine con python

You're live!

Page 19: Introduccion app engine con python

Demo time??

Page 20: Introduccion app engine con python

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()

Page 21: Introduccion app engine con python

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 ... 

Page 22: Introduccion app engine con python

main.py: Persisting to the datastoreclass GuestBook(webapp.RequestHandler):    def post(self):        greeting = Greeting()        greeting.content = self.request.get('content')        greeting.put()        self.redirect('/')

Page 23: Introduccion app engine con python

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>        ''')

Page 24: Introduccion app engine con python

Live demo??

Page 25: Introduccion app engine con python

Gracias!

email: [email protected]

twitter: sserrano44