SlideShare a Scribd company logo
1 of 13
Download to read offline
Python alapú mobil
backend GAE felett
by Gyuri Horak
GAE Python
● Python 2.7
● WSGI, webapp2
● db, memcache, cloud-sql, url fetch,
blobstore, users, unit testing ...
● django (django-nonrel, django+cloud-sql)
Példaprojekt
● backend iOS, Android és weboldal számára
● REST/JSON
Flask
Flask microframework, @mitsuhiko
● url routing
● class based views
● debugger, gae-profiler
● ...
JSONView
● Flask.views.MethodView
● success és failure metódusok
● X-Location header
● néhány Exception kezelése
ExceptionHandlerViewMeta
class ReferenceErrorMeta(MethodViewType):
def __new__(mcs, name, bases, odict):
if 'get' in odict:
odict['get'] = mcs.wrapmethod(odict['get'])
return MethodViewType.__new__(mcs, name, bases, odict)
@staticmethod
def wrapmethod(method):
@wraps(method)
def wrapper(self, *args, **kwargs):
try:
return method(self, *args, **kwargs)
except db.ReferencePropertyResolveError:
return self.failure(10, 'Reference object seems to be deleted.')
return wrapper
DB: a lekérdezés pénz
● NE előre optimalizálj!
● cache: memcache, request scope cache
● aggregálni, okosan
● Mérj! (GAE profiler, datastore stats)
CachedModel
class CachedModel(db.Model):
@classmethod
def get_from_cache(id):
...
@classmethod
def get(cls, key):
obj = cls.get_from_cache(key.id())
if not obj:
obj = super(CachedModel, cls).get(key)
return obj
def put(self):
super(CachedModel, self).put()
self.update_in_cache()
def delete(self):
super(CachedModel, self).delete()
self.remove_in_cache()
def __eq__(self, other):
return self.key() == other.key()
class CachedReferenceProperty(db.ReferenceProperty):
def __get__(self, model_instance, model_class):
...
# instance = get(reference_id) # WTF?
instance = self.reference_class.get(reference_id)
if instance is None:
# Feature check vs. isinstance
if hasattr(model_instance, 'update_references'):
model_instance.update_references()
raise db.ReferencePropertyResolveError(...)
CachedReferenceProperty
class CachedReferenceProperty(db.ReferenceProperty):
def __get__(self, model_instance, model_class):
...
# instance = get(reference_id) # WTF?
instance = self.reference_class.get(reference_id)
if instance is None:
# Feature check vs. isinstance
if hasattr(model_instance, 'update_references'):
model_instance.update_references()
raise db.ReferencePropertyResolveError(...)
Aggregáció
Aggregáció
Sérülhet, akár rajtunk kívül álló okok miatt
is.
● cron jobok takarítani / update-elni
● javítás, amikor hibát találunk
Képkezelés
● blobstore
○ create_upload_url()
○ files API (experimental)
● images ~ PIL
● get_serving_url()
○ lehet, hogy nincs kész
Geomodel
● db.GeoPt(lat, lon)
● geocells
● bounding box és proximity lekérdezés
localmind is ezt használja clustering
megoldásként

More Related Content

Similar to Python alapu mobil backend

Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceBo-Yi Wu
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDBJeff Yemin
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web TechnologiesPerttu Myry
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best PracticesYekmer Simsek
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-senseBen Lin
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS偉格 高
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRJavier Abadía
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy EdgesJimmy Ray
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJSAaronius
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Kuo-Chun Su
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic ComponentsMateusz Tymek
 
Training: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and FacesTraining: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and FacesArtur Ventura
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBMongoDB
 

Similar to Python alapu mobil backend (20)

Introduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript ConferenceIntroduction to Grunt.js on Taiwan JavaScript Conference
Introduction to Grunt.js on Taiwan JavaScript Conference
 
Grails 101
Grails 101Grails 101
Grails 101
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
Modern Web Technologies
Modern Web TechnologiesModern Web Technologies
Modern Web Technologies
 
Scripting GeoServer
Scripting GeoServerScripting GeoServer
Scripting GeoServer
 
Android Best Practices
Android Best PracticesAndroid Best Practices
Android Best Practices
 
Heroku pop-behind-the-sense
Heroku pop-behind-the-senseHeroku pop-behind-the-sense
Heroku pop-behind-the-sense
 
Module, AMD, RequireJS
Module, AMD, RequireJSModule, AMD, RequireJS
Module, AMD, RequireJS
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Vue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMRVue.js + Django - configuración para desarrollo con webpack y HMR
Vue.js + Django - configuración para desarrollo con webpack y HMR
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Dynamic Groovy Edges
Dynamic Groovy EdgesDynamic Groovy Edges
Dynamic Groovy Edges
 
Dependency Management with RequireJS
Dependency Management with RequireJSDependency Management with RequireJS
Dependency Management with RequireJS
 
Expressを使ってみた
Expressを使ってみたExpressを使ってみた
Expressを使ってみた
 
Spring Data MongoDB 介紹
Spring Data MongoDB 介紹Spring Data MongoDB 介紹
Spring Data MongoDB 介紹
 
Zend Framework 2 - Basic Components
Zend Framework 2  - Basic ComponentsZend Framework 2  - Basic Components
Zend Framework 2 - Basic Components
 
Training: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and FacesTraining: Day Four - Struts, Tiles, Renders and Faces
Training: Day Four - Struts, Tiles, Renders and Faces
 
Web-Performance
Web-PerformanceWeb-Performance
Web-Performance
 
Pyramid Framework
Pyramid FrameworkPyramid Framework
Pyramid Framework
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 

More from EU Edge

Synchronization with CouchDB and PouchDB
Synchronization with CouchDB and PouchDBSynchronization with CouchDB and PouchDB
Synchronization with CouchDB and PouchDBEU Edge
 
How I learned to Stop Worrying and Love the inline-block
How I learned to Stop Worrying and Love the inline-blockHow I learned to Stop Worrying and Love the inline-block
How I learned to Stop Worrying and Love the inline-blockEU Edge
 
What is python
What is pythonWhat is python
What is pythonEU Edge
 
Advanced python
Advanced pythonAdvanced python
Advanced pythonEU Edge
 
Res tful services
Res tful servicesRes tful services
Res tful servicesEU Edge
 
Google glass a developers perspective
Google glass   a developers perspectiveGoogle glass   a developers perspective
Google glass a developers perspectiveEU Edge
 
Google glass ict day presentation
Google glass   ict day presentationGoogle glass   ict day presentation
Google glass ict day presentationEU Edge
 
How does it work the keyboard
How does it work   the keyboardHow does it work   the keyboard
How does it work the keyboardEU Edge
 
Node webkit-meetup
Node webkit-meetupNode webkit-meetup
Node webkit-meetupEU Edge
 
Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25EU Edge
 
Eu edge intro
Eu edge introEu edge intro
Eu edge introEU Edge
 
Halado css eu edge
Halado css   eu edgeHalado css   eu edge
Halado css eu edgeEU Edge
 
Miért jó oktatóanyagot készíteni?
Miért jó oktatóanyagot készíteni?Miért jó oktatóanyagot készíteni?
Miért jó oktatóanyagot készíteni?EU Edge
 

More from EU Edge (16)

Synchronization with CouchDB and PouchDB
Synchronization with CouchDB and PouchDBSynchronization with CouchDB and PouchDB
Synchronization with CouchDB and PouchDB
 
How I learned to Stop Worrying and Love the inline-block
How I learned to Stop Worrying and Love the inline-blockHow I learned to Stop Worrying and Love the inline-block
How I learned to Stop Worrying and Love the inline-block
 
Node.js
Node.jsNode.js
Node.js
 
What is python
What is pythonWhat is python
What is python
 
Advanced python
Advanced pythonAdvanced python
Advanced python
 
WebGL
WebGLWebGL
WebGL
 
Res tful services
Res tful servicesRes tful services
Res tful services
 
Open gl
Open glOpen gl
Open gl
 
Google glass a developers perspective
Google glass   a developers perspectiveGoogle glass   a developers perspective
Google glass a developers perspective
 
Google glass ict day presentation
Google glass   ict day presentationGoogle glass   ict day presentation
Google glass ict day presentation
 
How does it work the keyboard
How does it work   the keyboardHow does it work   the keyboard
How does it work the keyboard
 
Node webkit-meetup
Node webkit-meetupNode webkit-meetup
Node webkit-meetup
 
Frontend meetup 2014.06.25
Frontend meetup 2014.06.25Frontend meetup 2014.06.25
Frontend meetup 2014.06.25
 
Eu edge intro
Eu edge introEu edge intro
Eu edge intro
 
Halado css eu edge
Halado css   eu edgeHalado css   eu edge
Halado css eu edge
 
Miért jó oktatóanyagot készíteni?
Miért jó oktatóanyagot készíteni?Miért jó oktatóanyagot készíteni?
Miért jó oktatóanyagot készíteni?
 

Python alapu mobil backend