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

Service Oriented Flask

Service Oriented Flask

OMG! Services! Flask! Yey!

Randall Degges

August 17, 2014
Tweet

More Decks by Randall Degges

Other Decks in Programming

Transcript

  1. Yo, I’m Randall! “I’m just a happy programmer that likes

    to hack stuff.” Developer Evangelist, Stormpath
  2. • What SOA is, exactly. • Why SOA is awesome.

    • The most import rule. • How to build reliable services. • How to make faster services. • How to scale Flask services. • The biggest SOA issue. • How to have more fun. What I’ll Cover
  3. Users Service GET /users Returns a list of all user

    accounts. GET /users/<uid> Returns the user identified by uid. POST /users Create a new user. POST /users/authenticate Authenticate a user. PUT /users/<uid> Update a user account identified by uid. PATCH /users/<uid> Update a user account identified by uid. DELETE /users/<uid> Delete a user identified by uid.
  4. import urllib2 from flask import Flask from flask.ext.testing import LiveServerTestCase

    class MyTest(LiveServerTestCase): def create_app(self): app = Flask(__name__) app.config['TESTING'] = True app.config['LIVESERVER_PORT'] = 8943 return app def test_server_is_up_and_running(self): response = urllib2.urlopen(self.get_server_url()) self.assertEqual(response.code, 200)
  5. Foreman / Docker Make Testing with SOA Easier web: gunicorn

    myproject:app -k gevent -b 0.0.0.0:$PORT servicea: cd ~/servicea && gunicorn myproject:app -k gevent -b 0.0.0.0:$PORT serviceb: cd ~/serviceb && gunicorn myproject:app -k gevent -b 0.0.0.0:$PORT $ foreman start 16:39:22 web.1 | started with pid 82834 16:39:22 worker.1 | started with pid 82835 16:39:22 blah.1 | started with pid 82836
  6. from flask import Flask from flask_sslify import SSLify app =

    Flask(__name__) sslify = SSLify(app) Flask-SSLify
  7. Flask-BasicAuth from flask import Flask from flask.ext.basicauth import BasicAuth app

    = Flask(__name__) app.config['BASIC_AUTH_USERNAME'] = 'john' app.config['BASIC_AUTH_PASSWORD'] = 'matrix' app.config['BASIC_AUTH_FORCE'] = True basic_auth = BasicAuth(app)
  8. from flask import Flask from flask.ext.cache import Cache app =

    Flask(__name__) cache = Cache(app, config={'CACHE_TYPE': 'simple'}) Flask-Cache
  9. from flask import Flask form flask.ext.rq import RQ, job app

    = Flask(__name__) RQ(app) @job def process(i): pass process.delay(3) Flask-RQ
  10. Outsource what you can. • Stormpath • Twilio • Loggly

    • Sendgrid • NewRelic • Ducksboard Less code, less *.
  11. Flask-Security • Works with SQLAlchemy. • Configurable. • Password reset.

    • Basic Authentication (with email / password). • Token authentication. • Self hosted. • You have to build the API around it yourself.