A python web service

1,480 views
1,314 views

Published on

Simple presentation about how to build an API in python uing Django, Django-REST-Framework, Django-Tastypie and Flask (Flask rules)

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,480
On SlideShare
0
From Embeds
0
Number of Embeds
7
Actions
Shares
0
Downloads
54
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

A python web service

  1. 1. A Python a web service A Python a web service @vtemian
  2. 2. A Python a web service Let’s imagine a perfect world...
  3. 3. A Python a web service WEB APPLICATION
  4. 4. A Python a web service Tools & Utilities WEB APPLICATION
  5. 5. A Python a web service WEB APPLICATION Tools & Utilities Web Process
  6. 6. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process
  7. 7. A Python a web service WEB APPLICATION Tools & Utilities Web Process management tools supporting services Worker Process
  8. 8. A Python a web service WEB APPLICATION Tools & Utilities Web Process management tools user interface supporting services api service data persistence auth crud admin Worker Process
  9. 9. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks data persistence auth crud admin
  10. 10. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks data persistence auth crud admin
  11. 11. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks data persistence auth crud admin
  12. 12. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks data persistence auth crud admin
  13. 13. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks data persistence auth crud admin
  14. 14. A Python a web service Single codebase are EVIL!
  15. 15. A Python a web service WEB APPLICATION Tools & Utilities Web Process Worker Process management tools user interface deferred tasks supporting services api service scheduled tasks SS E M AL T TO data persistence auth crud admin
  16. 16. A Python a web service Decouple!
  17. 17. A Python a web service Developers End Users API service Data persistence Frontend
  18. 18. A Python a web service Developers API service End Users API service Internal API service Data persistence
  19. 19. A Python a web service Good API
  20. 20. A Python a web service Good API
  21. 21. A Python a web service Good API Intuitive similar things should be similar, ugly things should look ugly Documented Opinionated
  22. 22. A Python a web service Features posting of data with validation pagination propper HTTP response handling permissions throttling serialization authentification
  23. 23. A Python a web service Django regex routing system
  24. 24. A Python a web service Django regex routing system built-in orm
  25. 25. A Python a web service Django users = Users.objects.filter(last_login__lt=timestamp)
  26. 26. A Python a web service Django regex routing system built-in orm templating system auth management tools crud admin migrations testing tools makes decision for you
  27. 27. A Python a web service NOBODY CARES
  28. 28. A Python a web service Developers API service Django End Users API service Internal API service Data persistence
  29. 29. A Python a web service Django regex routing system testing tools templating system makes decision for you
  30. 30. A Python a web service
  31. 31. A Python a web service Django REST Framework
  32. 32. A Python a web service Just install it, write 20 lines of code > CRUD API
  33. 33. A Python a web service API Console
  34. 34. A Python a web service Great community
  35. 35. A Python a web service Easy to document your API
  36. 36. A Python a web service Integration test using APIRequestFactory
  37. 37. A Python a web service OAuth 1 & 2 out of the box
  38. 38. A Python a web service Serialization
  39. 39. A Python a web service Django paginator or PaginationSerializer
  40. 40. A Python a web service Object or field level validation
  41. 41. A Python a web service Using django caching policy
  42. 42. A Python a web service For throttling, just add: DEFAULT_THROTTLE_CLASSES + DEFAULT_THROTTLE_RATES in settings.py
  43. 43. A Python a web service Powerful and extensible object level permissions
  44. 44. A Python a web service
  45. 45. A Python a web service Depends on Django > get all the Django mess
  46. 46. A Python a web service Pretty huge
  47. 47. A Python a web service Can do a lot of black magic
  48. 48. A Python a web service Rigid
  49. 49. A Python a web service Django Tastypie
  50. 50. A Python a web service Plug and play
  51. 51. A Python a web service Decent auth support
  52. 52. A Python a web service Documented
  53. 53. A Python a web service Still supported
  54. 54. A Python a web service Paginator for pagination
  55. 55. A Python a web service Validation --- you can extend it
  56. 56. A Python a web service serializer = Serializer(formats=[‘json’, ‘jsonp’, ‘xml’, ‘yaml’, ‘html’, ‘plist’])
  57. 57. A Python a web service throttle = BaseThrottle(throttle_at=100)
  58. 58. A Python a web service NO NO NO
  59. 59. A Python a web service Not intuitive
  60. 60. A Python a web service Ugly
  61. 61. 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)
  62. 62. A Python a web service Depends on Django > get all the Django mess
  63. 63. A Python a web service Can do lot black magic Can do aalot of black magic
  64. 64. A Python a web service Rigid
  65. 65. A Python a web service Flask
  66. 66. A Python a web service
  67. 67. A Python a web service from flask import Flask app = Flask(__name__) @app.route(“/”) def hello(): return “Hello World!” if __name__ == “__main__”: app.run()
  68. 68. A Python a web service Werkzeug, Jinja 2 and good intentions
  69. 69. A Python a web service Very small and easy to learn (super intuitive)
  70. 70. A Python a web service Solid and well documented
  71. 71. A Python a web service Awesome and strong community
  72. 72. A Python a web service Great debugging tools
  73. 73. A Python a web service Application dispatcher (on wsgi level)
  74. 74. A Python a web service Integrating unittest and integration tests (also check flask-testing)
  75. 75. A Python a web service Signals
  76. 76. A Python a web service Configuration == dict
  77. 77. A Python a web service Blueprints
  78. 78. A Python a web service Response object == wsgi app
  79. 79. A Python a web service SHOW ME THE SOURCE YOU MUST
  80. 80. A Python a web service BYOB
  81. 81. A Python a web service Some batteries Flask-SQLAlchemy Flask-Testing Flask-Oauthlib Flask-Classy Flask-Cache Flask-Script Flask-Principal
  82. 82. A Python a web service
  83. 83. A Python a web service Q/A
  84. 84. A Python a web service Resources Kenneth Reitz Flask Goodness API Driven Development How I develop Things and Why? Kevin Lacker How to Design Great APIs?
  85. 85. A Python a web service Thank you! DRINK ALL THE BEERS!

×