Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

Photographer: Patrick Neumann Niklas Meinzer @NiklasMM Gotthard Base Tunnel

Slide 3

Slide 3 text

Python is amazing for web developers! ● Bottle ● BlueBream ● CherryPy ● CubicWeb ● Grok ● Nagare ● Pyjs ● Pylons ● TACTIC ● Tornado ● TurboGears ● web2py ● Webware ● Zope 2

Slide 4

Slide 4 text

Why would I want to use less? ● Learn how stuff works

Slide 5

Slide 5 text

Why would I want to use less? ● Avoid over-engineering – Wastes time and resources – Makes updates harder – It’s a security risk.

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Database Patient Data Lab Data Printers Pharmacy System REST HL7

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

A simple Application

Slide 11

Slide 11 text

A simple Application

Slide 12

Slide 12 text

URL Routing

Slide 13

Slide 13 text

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

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

HTTP Utilities ● Work with HTTP dates ● Read and dump cookies ● Parse form data

Slide 16

Slide 16 text

Using the test client

Slide 17

Slide 17 text

Using the test client - pytest fixtures

Slide 18

Slide 18 text

Using the test client - pytest fixtures

Slide 19

Slide 19 text

Interactive debugger in the Browser

Slide 20

Slide 20 text

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

Slide 21

Slide 21 text

Thank you! NiklasMM @NiklasMM Photographer: Patrick Neumann