Top Banner

Click here to load reader

Using Google App Engine Python

Oct 19, 2014



Content prepared for delivering session in Python Pune meetup

PowerPoint Presentation

Akshay [email protected]

Ground Rules

Disturb EveryoneNot by phone ringsNot by local talksBy more information and questions



Lets Know Each Other

Do you code?OS?Language?Used GAE?Why are you attending?



Akshay Mathur

Founding Team Member ofShopSocially (Enabling social for retailers)AirTight Neworks (Global leader of WIPS)15+ years in IT industryCurrently Principal Architect at ShopSociallyMostly worked with StartupsFrom Conceptualization to StabilizationAt different functions i.e. development, testing, releaseWith multiple technologies



What shall we learn

Why GAE (Google App Engine)?General advantages of IaaS (Infrastructure as a Service)PaaS (Platform as a Service)Using GAE SDKAvailable Services from GoogleFilling the GapIncluding third party librariesCreating MVC structureAvailable boilerplate code for quick start




Application PaaS maintained by GoogleSame platform that powers Google ApplicationsFamiliar technologiesPython, PHP, Java, GoReadymade additional servicesStorage, Email, Chat, Task queue etc.No (or very low) initial costFree quotas






Move your local/data center servers to cloudDont worry about hardwareScale up/down as neededSimplified logistics for IT adminsPay only for used infrastructure

Custom hardware is not available



PaaS: Advantages

Move your application environment on cloudFocus only on your applicationDont worry for upgradesEasy to scaleEasy to administerGet all benefits of IaaSControl in developers hand





PaaS: Limitations

No control over machinesNo access to file systemNo sshNo native software installationUse only the provided softwareUpgrade with the providerLimitation on usage of network stackNo sniffing of trafficLimited use of ports



Getting Started

Hello world!

Why Python

Because we love it GAE says:



Getting Started

Install Python Download and install GAE SDKConfigure app.yamlWrite codeTest locally as GAE appDeploy



Runtime configuration: app.yaml











Gearing up for Bigger App

Creating the basic Structure

Included Libraries

Webapp2, Django, Ssl, PIL, Pycrypto, Setuptools, Webob, Yaml, MySQLdb

Endpoints: Libraries for building APIs in an App Engine application.Jinja2: A modern and designer friendly templating language for Python.Lxml: A Pythonic binding for the C libraries libxml2 and libxslt.Markupsafe: A XML/HTML/XHTML markup safe string for Python.Matplotlib: A 2D plotting library which produces publication-quality figures.Numpy: A general-purpose library for array-processing.Protorpc: A framework for implementing HTTP-based remote procedure call (RPC) services.PyAMF: A library that provides (AMF) Action Message Format functionality.



Available Services



Data Storage

DatastoreA schemaless object datastore providing robust, scalable storage for your web application, a rich data modeling API, and a SQL-like query language called GQL.BlobstoreAllows your application to serve large data objects, such as video or image files, that are too large for storage in the Datastore service.MemcacheA distributed, in-memory data cache that can be used to greatly improve application performance.LogsProvides programmatic access to application and request logs from within your application.




ChannelCreates a persistent connection between your application and Google servers, so you can send messages to JavaScript clients in real time without "polling."MailSends email messages on behalf of administrators and users with Google Accounts, and receives mail at various addresses.URL FetchUses Google's networking infrastructure to efficiently issue HTTP and HTTPS requests to URLs on the web.XMPPEnables an application to send and receive chat messages to and from any XMPP-compatible chat messaging service.



Process Management

Task QueueAllows applications to perform work outside of a user request, and organize that work into small, discrete units, called "tasks," to be executed later.Scheduled TasksAllows applications to configure regularly scheduled tasks that operate at defined times or regular intervals.




BackendsInstances of your application that are exempt from request deadlines and have access to more memory and CPU resources.ImagesManipulates, combines, and enhances images, converts images between formats, and queries image metadata such as height and frequency of colors.



App configuration and management

App IdentityGives code access to the application identity; provides framework to assert this identity over OAuth.CapabilitiesProvides detection of outages and scheduled maintenance for specific APIs and services, so that your application may bypass them or inform your users.SSL for Custom DomainsAllows applications to be served via both HTTPS and HTTP via a custom domain instead of an address.RemoteLets external applications transparently access App Engine services. For example, you can use Remote API to access a production datastore from an app running on your local machine.MultitenancyMakes it easy to compartmentalize your data to serve many client organizations from a single instance of your application.Traffic SplittingAllows you to roll out features for your app slowly over a period of time, and do A/B Testing. Traffic Splitting works by splitting incoming requests to different versions of your app.UsersAllows applications to sign in users with Google Accounts or OpenID, and address these users with unique identifiers.



Third-party Services

SendGrid (Email)Use SendGrid's library to send emails from your app and you can see statistics on opens, clicks, unsubscribes, spam reports and more.Twilio (SMS/Voice)Enables your application to make and receive phone calls, send and receive text messages, and make VoIP calls from any phone, tablet, or browser.



Preview Features

Google Cloud EndpointsEnables automatic generation of APIs, making it easier to create a web backend for web clients and mobile clients such as Android or Apple's iOS.Google Cloud SQLA fully-managed web service that allows you to create, configure, and use relational databases that live in Google's cloud.Google Cloud Storage Client LibraryLets your application read files from and write files to buckets in Google Cloud Storage, with with internal error handling and retry logic.ModulesLets developers factor large applications into logical components that can share stateful services and communicate in a secure fashion.SocketsEnables support for outbound sockets using the language-specific, built-in libraries.



Experimental Features

MapReduceAn optimized adaptation of the MapReduce computing model for efficient distributed computing over large data sets.OAuthUsing Google Accounts and the OAuth API, any App Engine application can be an OAuth consumer.OpenIDAn open technology used for authenticating users across various web services.PageSpeedA family of tools that automatically optimizes the performance of your application.Task Queue REST APIEnables the use of an App Engine task queue over REST.Task Queue TaggingLeases up to a specified number of tasks with the same tag from the queue for a specified period of time.




SearchAllows your application to perform Google-like searches over structured data such as: plain text, HTML, atom, numbers, dates, and geographic locations.Prospective SearchA querying service that allows your application to match search queries against real-time data streams.



Filling the Gap

Including other librariesPlace them within your appOnly pure Python libs can be usedCreating MVC structureCreate your own directory structureAdjust path for supporting it



MVC Structure



New Code:



Global Configuration:



Route List






Base Controller



Third Party Libs



Static Files





Dive Deeper

Get the app working

Scheduled Tasks: cron.yaml




NoSQL database is available in free quotaSQL database (Google Cloud SQL) is also available



Data Manipulation





GQL.gql()People.gql("where email_addr = :1 and passwd = :2", username, get_password_hash(passwd))gql_query()gql_query(select * from people where email_addr = :1 and passwd = :2", username, get_password_hash(passwd))

Task Queue