Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flask API backend

Flask API backend

Mikhail Kashkin

April 23, 2015
Tweet

More Decks by Mikhail Kashkin

Other Decks in Programming

Transcript

  1. About me • Python developer, community member • Now Flask

    if web, most frameworks before • Twitter: @mikashkin • GitHub: @xen
  2. Few words before we start • It is ok for

    tutorial, but some people really try to use this approach for real life. Don’t be that guy • In real project this is terrible idea to have everything in one file • Shameless plug, I’ve done everything for you 
 https://github.com/xen/flask-project-template • Flask have all needed parts: Blueprints and Extensions
  3. Flask ecosystem • pip search flask | wc -l
 830

    • django - 7562, plone - 1633, zope - 838, tornado - 259 • Platforms available: WSGI, GAE, Heroku
  4. …batteries (blackjack, hookers) • Flask-Script -> click.py • Flask-FlatPages •

    Flask-Babel • Flask-WTF • Flask-Cache • Flask-Admin • python-social • Flask-Mail • Flask-SQLAlchemy (peewee) • Flask-migrate (alembic) • Flask-Cache • Flask-restless • Flask-rq • Celery • DS connectors: RDBMS, NoSQL
  5. RESTFul API • Framework should care: • Nice URL schema,

    be nice for people who will use it • Versioning • Aliases • Search • Limit fields returned by API • Cache headers • JSON • HTTP_X_HTTP_METHOD_OVERRIDE • Out of the scope: • SSL • Documentation
  6. HTTP Method Overrides • http://flask.pocoo.org/docs/0.10/patterns/methodoverrides/ • Sometimes users are behind

    proxies that not support some HTTP methods. There is convenient way to support them
 
 
 
 
 
 
 

  7. Throttling* • Generally bad idea, your API is not really

    open if you use this technics • Storing data about how much user consumed data is bottle neck for most cases • If you still need it use memcache via Flask-Cache
  8. User authentication • Can be very complicated or not •

    If you just need to authorize user use Flask-Auth • If you need Facebook, Twitter, etc use python-social • python-social can ruin your day, or two. Not sure that integration now works. Freeze version that is working for you
  9. Background tasks • Celery, fit all cases • Flask-rq (redis),

    if you just need quick background tasks aka defer
  10. Flask in clouds • Google App Engine, have MySQL instances.

    Be careful with regions • Heroku. You can use Postgres • AWS. Build your own server • Digital Ocean. You can use Ansible for your tasks