Saturday 8 December 2012

Google App Engine


        Google App Engine lets us to run web applications on Google's infrastructure.App Engine applications are easy to build, easy to maintain, and easy to scale.With App Engine, there are no servers to maintain.

                Google App Engine supports apps written in several programming languages.With App Engine's there are 3 different types of runtime environment.

  • Java runtime environment
  • Python runtime environment
  • Go runtime environment  

 

The Python Runtime Environment

 

                With App Engine's Python runtime environment, we can implement our app using the Python programming language, and run it on an optimized Python interpreter.The primary Python runtime environment uses Python version 2.7.2. we can also choose the older Python 2.5.2 runtime.The Python environment includes the Python standard library. Of course, not all of the library's features can run in the sandbox environment.The Python environment provides rich Python APIs for the datastore, Google Accounts, URL fetch, and email services.

 

How To Use The App Engine To Host An Application


              At first we download and  install the Google App Engine SDK in our systemThen we can register our application with unique application id and application name in our google app engine account.We can create a folder in our system containing 3 files. First one is the file which to be upload to the google app engine,second is the configuration file called app.yaml this file describes which handler scripts should be used for which URLs.


                       application: nithinconwaysgameoflife
                       version: 1
                       api_version: 1
                       runtime: python
                       handlers:

                      - url: /.*
                      script: main.py 

here nithinconwaysgameoflife is the application id.
Third one is main.py ,the python file where we access our web application file.


                          import wsgiref.handlers
                          from google.appengine.ext import webapp
                          from google.appengine.ext.webapp import Request
                          from google.appengine.ext.webapp.util import run_wsgi_app
                          from google.appengine.ext.webapp import template

                          class mainh(webapp.RequestHandler):
                              def get(self):
                                  self.response.out.write(template.render("game.html",{}))  
      
                         def main():
                             app = webapp.WSGIApplication([
                                 (r'.*',mainh)], debug=True)
                             wsgiref.handlers.CGIHandler().run(app)


                          if __name__ == "__main__":
                                     main()

Testing the Application

 

With a handler script and configuration file mapping every URL to the handler, the application is complete. We can now test it with the web server included with the App Engine SDK.

Type the command on terminal


google_appengine/dev_appserver.py "path to applicationid folder"
 
we can test the application by visiting the following URL 


http:// localhost:8080/

 

Upload the application to google app engine 


$cd google_appengine


after enter the  google_appengine folder in the system.

Type the following command on terminal


python appcfg.py update " path to applicationid folder".


Enter your google user name and password at the prompt
Now we can see our application run with url  http://applicationid.appspot.com/ on google app engine



click here for see example

 

 


No comments:

Post a Comment