$30 off During Our Annual Pro Sale. View Details »

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

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

More Decks by Niklas Meinzer

Other Decks in Programming


  1. When Django is too bloated
    Specialized Web-Applications with Werkzeug
    EuroPython 2017 – Rimini, Italy

    View Slide

  2. Photographer: Patrick Neumann
    Niklas Meinzer
    Gotthard Base Tunnel

    View Slide

  3. Python is amazing for web developers!














    Zope 2

    View Slide

  4. Why would I want to use less?

    Learn how stuff works

    View Slide

  5. Why would I want to use less?

    Avoid over-engineering
    – Wastes time and resources
    – Makes updates harder
    – It’s a security risk.

    View Slide

  6. 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

    View Slide

  7. Database
    Data Lab
    Pharmacy System

    View Slide

  8. 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

    View Slide

  9. Werkzeug Features Overview

    – 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

    View Slide

  10. A simple Application

    View Slide

  11. A simple Application

    View Slide

  12. URL Routing

    View Slide

  13. 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

    View Slide

  14. View Slide

  15. HTTP Utilities

    Work with HTTP dates

    Read and dump cookies

    Parse form data

    View Slide

  16. Using the test client

    View Slide

  17. Using the test client - pytest fixtures

    View Slide

  18. Using the test client - pytest fixtures

    View Slide

  19. Interactive debugger in the Browser

    View Slide

  20. 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

    View Slide

  21. Thank you!
    Photographer: Patrick Neumann

    View Slide