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

When Django is too bloated - Specialized Web-Ap...

When Django is too bloated - Specialized Web-Applications with Werkzeug

Did you ever think, Django and all the other “batteries included” frameworks are not flexible enough for your needs? Do you feel like they limit you in your creativity and design? Then this talk is for you!

Werkzeug is a very lightweight HTTP/WSGI utility for Python. You might have actually used it before, since the popular framework Flask is based on it. Werkzeug handles the WSGI communication with the web server and parsing of HTTP packets for you, after that, you are left to do whatever you want. No pre-defined ORM, no request dispatching or template rendering. As a developer you are supported with a live debugger that runs in the browser and a great variety of testing tools making it easy to write fine grained unit tests for your application.

As a developer at MPS - Medical Systems, I work with Werkzeug on a daily basis. One of our products is ChemoCompile, a chemo therapy planning, management and documentation tool used in hospitals in various European countries. It is a single-page web application written in Python (backend) and AngularJS (frontend). When we created it, we first prototyped it using Django, but soon realized, that we did not need most of the functionality that Django provides and many of our needs, like interfacing with hospital information systems, are too much out of the scope of a regular web applications. I will talk about, how we then discovered Werkzeug and built our own very customized stack on top of it and how you can do it too!

Niklas Meinzer

July 13, 2017
Tweet

More Decks by Niklas Meinzer

Other Decks in Programming

Transcript

  1. Python is amazing for web developers! • Bottle • BlueBream

    • CherryPy • CubicWeb • Grok • Nagare • Pyjs • Pylons • TACTIC • Tornado • TurboGears • web2py • Webware • Zope 2
  2. Why would I want to use less? • Avoid over-engineering

    – Wastes time and resources – Makes updates harder – It’s a security risk.
  3. Why would I want to use less? • You want

    to do something very specific • Plan, manage and document chemotherapy treatments • Built with modern web technology • Used by hospitals in three European countries
  4. Werkzeug = German for “tool” • Developed by pocoo team

    @ pocoo.org – Flask, Sphinx, Jinja2 • A “WSGI utility” • Very lightweight • No ORM, No templating engine, etc • The basis of Flask and others
  5. Werkzeug Features Overview • WSGI – WSGI 1.0 compatible, WSGI

    Helpers • Wrapping of requests and responses • HTTP Utilities – Header processing, form data parsing, cookies • Unicode support • URL routing system • Testing tools – Testclient, Environment builder • Interactive Debugger in the Browser
  6. Middlewares Part of Application without DB access Part of Application

    with DB access • Separate parts of the Application as wsgi apps • Combine as needed Static files User auth Dispatcher DB conn Request Response
  7. HTTP Utilities • Work with HTTP dates • Read and

    dump cookies • Parse form data
  8. Endless possibilities • Connect to a database with SQLalchemy •

    Use Jinja2 to render documents • Use Celery to schedule asynchronous tasks • Talk to 3rd party APIs with requests • Make syscalls • Remote control a robot to perform tasks at home