a python a web service - files.meetup.comfiles.meetup.com/8579852/pytim #4 vlad temian - a python...
TRANSCRIPT
A Python a web service
A Python a web service@vtemian
A Python a web service
Let’s imaginea perfect world...
A Python a web service
WEB APPLICATION
A Python a web serviceWEB APPLICATION
Tools & Utilities
A Python a web serviceWEB APPLICATION
Tools & Utilities Web Process
A Python a web service
Tools & Utilities Web Process Worker Process
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process Worker Process
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasks
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasks
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasks
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasks
WEB APPLICATION
A Python a web service
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasks
WEB APPLICATION
A Python a web service
Single codebase areEVIL!
A Python a web serviceWEB APPLICATION
Tools & Utilities
management tools
supporting services
Web Process
user interface
api service
data persistence
auth
crud admin
Worker Process
deferred tasks
scheduled tasksTOTAL MESS
A Python a web service
Decouple!
A Python a web service
Developers
API service
Data persistence
Frontend
End Users
A Python a web service
Developers End Users Internal
API service API service API service
Data persistence
A Python a web service
Good API
A Python a web service
Good API
A Python a web service
Good APIIntuitive
similar things should be similar, ugly things should look ugly
Documented
Opinionated
A Python a web service
Featurespagination
propper HTTPresponse handling throttling
permissions serializationauthentification
posting of data with validation
A Python a web service
Django
regex routing system
A Python a web service
Django
regex routing system built-in orm
A Python a web service
users = Users.objects.filter(last_login__lt=timestamp)
Django
A Python a web service
regex routing system
authmigrations
management tools makes decision for you
templating system
built-in orm crud admin
testing tools
Django
A Python a web service NOBODY CARES
A Python a web service
Developers End Users Internal
API service API service API service
Data persistence
Django
A Python a web service
regex routing system
makes decision for you
templating system
testing tools
Django
A Python a web service
A Python a web service
Django REST Framework
A Python a web service
Just install it, write 20 lines of code> CRUD API
A Python a web service
API Console
A Python a web service
Great community
A Python a web service
Easy to document your API
A Python a web service
Integration test usingAPIRequestFactory
A Python a web service
OAuth 1 & 2 out of the box
A Python a web service
Serialization
A Python a web service
Django paginatoror PaginationSerializer
A Python a web service
Object or field level validation
A Python a web service
Using django caching policy
A Python a web service
For throttling, just add: DEFAULT_THROTTLE_CLASSES +
DEFAULT_THROTTLE_RATESin settings.py
A Python a web service
Powerful and extensible object level permissions
A Python a web service
A Python a web service
Depends on Django >get all the Django mess
A Python a web service
Pretty huge
A Python a web service
Can do a lot of black magic
A Python a web service
Rigid
A Python a web service
Django Tastypie
A Python a web service
Plug and play
A Python a web service
Decent auth support
A Python a web service
Documented
A Python a web service
Still supported
A Python a web service
Paginator for pagination
A Python a web service
Validation --- you can extend it
A Python a web service
serializer = Serializer(formats=[‘json’, ‘jsonp’, ‘xml’, ‘yaml’, ‘html’, ‘plist’])
A Python a web service
throttle = BaseThrottle(throttle_at=100)
A Python a web service
NO NO NO
A Python a web service
Not intuitive
A Python a web service
Ugly
A Python a web service
class ParentResource(ModelResource): children = fields.ToManyField(ChildResource, ‘children’)
def prepend_urls(self): return [ url(r”^(?P<resource_name>%s)/(?P<pk>\w[\w/-]*)/children%s$” % (self._meta.resource_name, trailing_slash()), self.wrap_view(‘get_children’), name=”api_get_children”), ] def get_children(self, request, **kwargs): try: bundle = self.build_bundle(data={‘pk’: kwargs[‘pk’]}, request=request) obj = self.cached_obj_get(bundle=bundle, **self.remove_api_resource_names(kwargs)) except ObjectDoesNotExist: return HttpGone() except MultipleObjectsReturned: return HttpMultipleChoices(“More than one resource is found at this URI.”)
child_resource = ChildResource() return child_resource.get_detail(request, parent_id=obj.pk)
A Python a web service
Depends on Django >get all the Django mess
A Python a web service
Can do a lot of black magic
A Python a web service
Can do a lot of black magic
A Python a web service
Rigid
A Python a web service
Flask
A Python a web service
A Python a web service
from flask import Flaskapp = Flask(__name__)
@app.route(“/”)def hello(): return “Hello World!”
if __name__ == “__main__”: app.run()
A Python a web service
Werkzeug, Jinja 2 and good intentions
A Python a web service
Very small and easy to learn(super intuitive)
A Python a web service
Solid and well documented
A Python a web service
Awesome and strong community
A Python a web service
Great debugging tools
A Python a web service
Application dispatcher (on wsgi level)
A Python a web service
Integrating unittest and integration tests (also check flask-testing)
A Python a web service
Signals
A Python a web service
Configuration == dict
A Python a web service
Blueprints
A Python a web service
Response object == wsgi app
A Python a web service
SHOW ME THE SOURCEYOU MUST
A Python a web service
BYOB
A Python a web service
Some batteries
Flask-SQLAlchemy Flask-Testing
Flask-Oauthlib
Flask-Script
Flask-PrincipalFlask-Cache
Flask-Classy
A Python a web service
A Python a web service
Q/A
A Python a web service
Resources
Kenneth ReitzFlask GoodnessAPI Driven DevelopmentHow I develop Things and Why?
Kevin LackerHow to Design Great APIs?
A Python a web service
Thank you!
DRINK ALL THE BEERS!