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

Video in TIB AV-Portal: When Django is too bloated - Specialized Web-Applications with Werkzeug

Formal Metadata

When Django is too bloated - Specialized Web-Applications with Werkzeug
Title of Series
CC Attribution - NonCommercial - ShareAlike 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal and non-commercial purpose as long as the work is attributed to the author in the manner specified by the author or licensor and the work or content is shared also in adapted form only under the conditions of this license.
Release Date

Content Metadata

Subject Area
When Django is too bloated - Specialized Web-Applications with Werkzeug [EuroPython 2017 - Talk - 2017-07-13 - PythonAnywhere Room] [Rimini, Italy] 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
Intel Neumann boundary condition Bargaining problem Multiplication sign Software
Programming language Heegaard splitting Slide rule Word Presentation of a group Personal digital assistant Bit
Multiplication sign Wave packet
Wind tunnel Word Presentation of a group Software Web-Designer Software framework
Web 2.0 Electronic mailing list Software framework Social class
Process (computing) Software framework Right angle
Web 2.0 Server (computing) Mobile app Email Word Web-Designer Well-formed formula Telecommunication Configuration space HTTP cookie
Lie group
Service (economics) Inheritance (object-oriented programming) Multiplication sign Surface Gender Source code Virtual machine Bookmark (World Wide Web) Vector space Operator (mathematics) Website HTTP cookie Information security Window
Product (business) Compiler
Word Calculation Universe (mathematics) Error message Number
Web 2.0 Software Right angle Cartesian coordinate system Window Computer architecture Neuroinformatik
Laptop Web page Server (computing) Workstation <Musikinstrument> Bit Client (computing) Cartesian coordinate system Product (business) Front and back ends Tablet computer Web 2.0 Single-precision floating-point format Telecommunication
Angle Telecommunication Software framework Database Replication (computing) Demoscene
Web page Server (computing) Information Multiplication sign Execution unit Sampling (statistics) Bit Database Multilateration Message passing Queue (abstract data type) Quicksort Communications protocol
Multiplication sign Planning Neuroinformatik
Process (computing) Software Personal digital assistant Order (biology) Right angle
Web application Operator (mathematics) Maxima and minima Client (computing) Regular graph Physical system
Word Vector space Consistency Weight Bit Software framework Utility software Replication (computing) Product (business) Template (C++)
Web page Velocity Software framework Basis <Mathematik> Quicksort
Web 2.0 Gateway (telecommunications) Server (computing) Interface (computing) Website Online help Cartesian coordinate system Communications protocol Computer programming
Web 2.0 Web application Dependent and independent variables Server (computing) Telecommunication Utility software Object (grammar) Quicksort
Email Parsing Validity (statistics) Right angle HTTP cookie Physical system
Weight Multiplication sign Software developer Debugger Client (computing) Mereology Cartesian coordinate system Bookmark (World Wide Web) Vector space Integrated development environment Software testing Form (programming) Physical system Social class
Functional (mathematics) Dependent and independent variables Wrapper (data mining) Integrated development environment Information Dependent and independent variables Configuration space Web browser Parameter (computer programming) Cartesian coordinate system
Dependent and independent variables Server (computing) Wrapper (data mining) Integrated development environment Dependent and independent variables Software developer Sound effect Software testing Object (grammar) Parameter (computer programming) Mereology
Dependent and independent variables Parsing Wrapper (data mining) Mapping Dependent and independent variables Multiplication sign Cartesian coordinate system
Uniform resource locator Rule of inference Functional (mathematics) Mapping Dependent and independent variables View (database) Multiplication sign String (computer science) Free variables and bound variables Mereology Rule of inference Template (C++)
Uniform resource locator Rule of inference Default (computer science) Information management Vector space Oval Dependent and independent variables String (computer science) Integer Data type
Vector space Computer file Energy level Database Mereology Cartesian coordinate system Middleware
Authentication Dependent and independent variables Database Mereology Object (grammar) Mereology Middleware Connected space
Slide rule Dependent and independent variables Functional (mathematics) Shared memory Database Mereology Cartesian coordinate system Middleware
Web 2.0 Server (computing) Computer file Integrated development environment Different (Kate Ryan album) Ultraviolet photoelectron spectroscopy Set (mathematics) Database Mereology Middleware Routing
Authentication Parsing Observational study Software developer Multiplication sign Strut File format Maxima and minima Streaming media Wave Personal digital assistant Software testing Utility software Middleware
Parsing Different (Kate Ryan album) String (computer science) Computer file File format Length Streaming media Utility software HTTP cookie
Dependent and independent variables Email Wrapper (data mining) Dependent and independent variables Code Client (computing) Client (computing) Function (mathematics) Replication (computing) Mereology Bookmark (World Wide Web) Vector space Right angle Software testing
Wrapper (data mining) Dependent and independent variables Different (Kate Ryan album) 1 (number) Code Client (computing) Client (computing) Middleware
Authentication Wrapper (data mining) Dependent and independent variables Code Client (computing) Software testing Middleware
Injektivität Radical (chemistry) Uniform resource locator Error message Demo (music) Debugger Web browser Open set Cartesian coordinate system Exception handling
Sequel Gender Database Cartesian coordinate system Bookmark (World Wide Web)
Wind tunnel Remote administration Vector space Robotics Cartesian coordinate system System call Task (computing) Probability density function
Game controller Existence Decision theory Multiplication sign Mereology Template (C++) Web 2.0 Exterior algebra Different (Kate Ryan album) Forest Energy level International Date Line God
Functional (mathematics) Personal digital assistant Computer configuration Right angle Frequency response Physical system
right 1st of all thanks everyone for coming taking the time I am Yemen is that this is a picture of a town called for by work is in South Germany is my current home in my workplace so but of course I'm not there right now because I'm here in Europe
license and it's actually quite funny Europe Python you think if you think of it and
it's a compound word python a programming language and in Europe is a continent which is a geographical concept so you would think maybe the
conferences and 50 50 split between Python and dude geography but I I have found that it's actually not the case and to rectify this a bit
Simon donating 1 slide of my presentation drew geography so on cannot interested please bear it means and let's go Central Europe the
red not sexually indicating the position of
fry what when comic coming from its which wedged in between France Switzerland and the i actually come here by train which was really nice so the trains here in Italy where
all on time air-conditioned and very fast now and I had across all Switzerland for this and of course there is a problem because there is a there large mountains there and Switzerland namely the Alps and until last year we actually had to go over the mountains but as G I got based on opened up and we can just smoothly go through the mountains and I that's a really nice time is just over 57 kilometers long as the longest train tunnel in the world it's actually the longest traffic time of any kind in the world so yeah this you drop fun fact if you if you will but of course are not your true to talk about
and geography or tunnels although I would like to but when you talk about web development now and web developer the a company called MPs which is an abbreviation for a bunch of long German words I won't bother you with 9
1 and I just have no we we make medical software and the title of my presentation might be uh sometimes you might have thought is it's a bit provocative and I would like to say of course and all of Python is amazing of for web developers we have all the to cool from the frameworks like Django with
class and we have pyramids and of course there's nothing wrong with them or course and I'm sure there's something wrong with all of them but do know they're just amazing and used to use them to look on wikipedia you will find that
irrespective of the whole list of Python-based web frameworks that I don't even all in all some of them are considered normal which I'm sure it's just a nice way to say that but you know and right so so these are outlook cooler and frameworks that do very much very much
work for you but I do suggest that sometimes it can be useful to you
know not have such a huge framework but use less use like very little to get the job done and I would like to present to you 3 reasons why why we might want to do that the 1st
as you want to learn stuff right for example if you want to learn how internal combustion
engine works you wouldn't look at the whole Formula 1 car but you would instead just take the engine out and see what and the same can be said for web development if you run and so in if you're in web development and you have maybe a Django up
or whatever you will eventually run into issues and you have to divide them and you might have to understand how the was the communication between your app and the server to the web server application words you have to understand HTTP headers weird cookie configuration and all that stuff so and if you want to look at these things and try to
understand and it can be a good idea to play around with just a small the lies stack and familiarize yourself with a 2nd and the motivation for using less to avoid over overengineering
and Over engineering is a bad idea and most so I would say in most situations I right it
wasted time raise 3 sources so I it's there is a lot of dependencies which makes it can make make can make it hard to update stuff so I don't know if you just want to make a website for your parents to have their favorite cookie recipes or
something then I don't know maybe you don't need to to use gender and of course it's always a security risk to use more stuff because more stuff means more surface and more service means more attack on vectors and just for fun example if you're in the national rail operator in the country you might not want to use full on Windows machines and with which I network-enabled to display a timetables person might get hacked and the 3rd reason and this is actually the reason why I got into a vector and
this you might want to move on to something so specific why the general and the general-purpose
frameworks and bring with with them and stuff that you just don't need the and and make assumptions that are just not relevant to your case so that and this brings me to and the product of my company just got chemo compiler of it together with
the university hospital in my work as a problem to plan manage and document chemotherapy treatment now do very few can of course
can be very risky for example if you make just the tiniest are in those such calculations you might actually harm patients if you make a make an error in maybe a date so you send out an order from for chemotherapy to be prepared a day early you might have to throw away and medication worth 15 thousand euros that's not a made-up number to I right you combined as the word is the
marketing sentences in the rights but with modern web technology whatever that means it's not used in hospitals and of 3 European countries an issue of whether enumerates the most the biggest German can speaking countries then you might not be far off the
and let's go quickly over of the application and architecture it's the revocation as I said so some window customers are interested there's a star where our software is running and then every computer
laptop or tablet that has access to the server can't just use of suffering is actually quite on from an uncommon for professional of products they are often in client base and you have
to install everything on on each workstation for itself so our customers are very happy to have direct webs based on applications application the front-end is built with Angular JS that's a single base page application and the back and we are of course using python I'm not going to tell you which because that might be a bit embarrassing to it's not too 6 so I'm and then forward a communication we have rest of the i which just sense of back enforced Jason data so this immediate you live eliminates the need for any kind of HTML rendering in the background which
frameworks like angle and so forth bring with them and but there's more going on is not just of replication we have to do the some actually a lot of communication behind the scenes where we have to talk to a database is not all that
uncommon about the art we also tightly integrated in the infrastructure that's already
there and hospitals so we have to talk to way possible Information center to retrieve patient data is done with uh a protocol called Health Level Seven has anyone ever use or a couple so you would maybe agree this kind of ancient and a bit clunky at times so the and for example as no all you cannot just
request patient data you have to sit there subscribe to a message queue and wait for the data to come by and store it like in a database for later use this can be a bit complicated units have to talk to our lack equipment so let let servers to natural basically retrieve and data about blood samples and so on which is also done with page 7 we have to talk to print us believe it or not most of these hospitals and have a sort of like printer-based workflow will open
doctors and plan of the therapy and its gets automatically printed all and at certain times and certain computer in certain printers and and people we have shown that start to work on them so we have to get rest to talk to print as we have to make so
basically you have to uh to make use of the of the article and finally we have
to talk to farmers assistance of because as I told you all these are chemotherapy medications they are
and what highly individualized so on each of the order was prepared and mixed basically for for the patient for today and
specifically so this is not a farmers like you're commercial farms it is a pharmacy within the hospital so basically that's more more for chemical lab right and there's an expert softwares that handle these kinds of processes and we have to implement then of the indifference to all of
these systems so yeah and so this
course happens within the intranet and for each installation there's only like maybe 20 clients maximum operating on concurrently so this really takes away
from a lot of us scaling things that you have in the problems that you can't have regular web application because you just witches don't have to do it and yeah
so that we can protect our education actually with general which was 1st very easy and uh nice but then we just follow the
generous and that's that's OK and I'm not saying we couldn't have done in general but we can set the site to basically role or on 1 of our own stack and we did that on top of a cool tool called back so now acts
is a bit of a we had worked and it has a lot of consonants it's various long and hard to pronounce and you of course know what's going on it's German and actually the german to look at the German word for tool very generic it's actually a very generic tool as well so it can fit and writes a vector is developed by the quality if you were here on Monday on 1 of
those famous member of the team and other products include flask ginger due to templating engine and more and so it's called 1 the documentation coated whiskey utility in this specifically not called a framework the and because it's just intentionally left very light weight it's basically yeah it's a toolbox the 2 what's replication and not more than these 2 very a very much freedom to use whatever the things you want to plot on top of it or them right it has no or an templating engine not these things that most of our
frameworks will bring with them and that's that's a basic a flat databases of last if you're ever worked with velocity of actually also worked
with that like and to you Wikipedia page said says is also the basis for others but I don't know what these other things are
I'm OK let's go quickly over the features of the sort and that's the most
important thing is that it's the for making was the
applications was used for those of you who don't know what I web server gateway interface so it's a protocol that Python applications will generate dynamic on sites used to talk to the web server to observing an engine x or Apache but only if those
programs this was the last 1 . 0 or has a lot of help us 2 of 2 of
facilitate and the communication between the with the web server for example and the most important concepts was the on the web application we are of course requests and responses so declined this request something
I responses generated by programs and by the desire to wrapped in red so it with the objects that lets you introspect them and work with them create them and so on yeah there's a couple of HTTP utilities on this sort of status on on the learning how stuff works the thing that I said earlier on is there nice so nice tools to
introspect headers to young basically look at headers and parse formed a and the cookies right cookies parse cookies
validate could be so yes it is you could support us and it hasn't neural routing system which is optional so you don't actually have to use it but it's of course something that most revocation would
use and any time in any in any form so there's a nice routing system was also very light weight we look at it in a 2nd and for developers it's actually this is
my favorite part about vectors very friendly to us developers to have a nice test client
and not environment Builder which lets you know which lets you and built a environments to test your application different some kind of circumstances and there's a nice interactive debugger I think that's also part of the class so you can interactively by your
application in a browser and yet it's looking at how they basic virtually application looks so this is that you just have 1 function and the function takes 2 arguments environ
and sub responds in these 2 arguments are actually so given by the whiskey proposal environs basically holds the environment information which is the request and configuration data and starve response is information needed to win the center of the of response back I would work so you can
then use the requests are constructed to get in and the actual of all of the environment you can then access for example and the arguments so the fiction get get arguments in neural with that object and you can use response constructive should put to rest the responses and effect
and you have you have to have a nice test on our on simple which sponsor server for development purposes and gets even part easier but there could request
application decorator which takes
away our solve hides the parsing of the request because this is something that you would most likely want to do all of the time and you can just return a response of so this is the easiest application at you will notice that there is no I know you're on mapping and routing of any kind going on so every request no matter the path would just go to this 1 function but if you would want
to do your part you can use denies
built in on a map of functionality you just get your view of map and you have a you would posit a bunch of rules and these rules basically consist
of a URL template and an end point and the end point can be anything so it's very simple also and this and regard what most of the time of course the end point would be some kind of you function here just have some strings and your have in your in your l templates you can use a placeholders on for example you
can requests an integer and you can request any on the the any of of a couple of values and or just the default which the example resistance just passed as a string and yeah the sorry you you little bit and
that's behind so I'm just gonna skip over this the another nice concept in vector other
middlewares and Midwest just a cool concept to compartmentalize your
application and so you would have a theologically separated parts of the application as a
single what director applications and you can combine them as needed and for example you would have a part of the application that needs database access would have part of the application of maybe don't that that doesn't and you would also serve static files you can then connect them in vector with some level you
could connect them in in this fashion the and all of these and objects are middleware so on In the end a request with come with come through and would be passed its 1st middleware which would
take care of user authentication and benefits of the regressors for static would go to the static Find middleware and the response would be sent back and in there's especially dispatcher middleware which are can dispatch between different it was gaps and for database part we also use connection middleware which we can plot on top of it
and yet any of the Midwest can manipulate the requests or the response can decide to send it to different
parts uh or can decide to just send a response but this is how it would look in a cold
1 so this Bill application
function would just and take and haven't put shares of Midwest just that is basically the example of from the previous slide and you would wrap Europe my database at on what DVConnect uh middleware and you would
then plug that in into a dispatcher middleware which so takes the non and the my regular habits see part without the to be have access under 1 l route and the now he reconnected part and another euro and we can wrap around a shared data serve static files
and is of course something you would only do in in the development environment because in your production environment you would most likely do that with the web server so this is very nice if you on you can with his mother west you can have different set ups for
some different and yeah use case very easy for example the last thing that wraparound this the authentication middleware which would be maybe not want to use in our development studies because we have on our tests
that because it and don't want to deal with authentication all the time yeah the should
utilities I'm just gonna gloss over on there is so apparently issue he has a little weird
and date formats and also different base formants and red has the utilities to parse right all of these the can as as already said green right cookies easily you can for example paras form daytime and what it would look like on you would you you just similar to simulate a request
with formed data and the and we can excessive with a dictionary not a fun
part is always a test and right and vector has this really nice comes of this the test client and not a hundred per cent sure but I think it's basically the same and fast and yeah you can just pass declined your replication and you can call on this client find all the or your favorite HTTP methods GET POST delete output what have you and give them the URL you want to access and if you have
data or want to past Special P headers to can also give it to the to to the client and you just get a response that you have now I just simulated in the whole of replication which is very nice and then you can run assertions by we want to have
lecture success status and the data should look like this very nice to you is a very
nice use as a pi test fixture for example just so that this is of course very either very simple but in in a
fixed so you you could also do the plotting together off the middleware's and everything on then you young just defined this one's and just use the fixture everywhere or you could have different kinds of clients
for example as I said maybe you don't want to have the authentication in most of your our test so you have a declined it doesn't use the doesn't you do occasionally you have a special off climbed was just a wraps around the authentication middleware and when you want
to test the authentication use this fixture to for example check that if you're not logged in you get a 4 1 yeah no
I'm not brave enough to do alive demos you have to live with screenshot of the left divided and here I've just put together a simple application to look at the urinal bomb repressive 2000 uh 18 for something and I got a key around so I can just go into the browser open of of injective terminal term-related flown into uh the scope and I can introspect and other things in the scope and I find out I think she requested to the and I've actually
requests that the location of your Python 2000 18 which is uh as far as I know not defined yet and this is still the problem of my application this debugger is also implemented as a middleware sold before want to you there just to wrap the bottom middleware around in my application and any exception that bubbles up would just get caught and presented this nice way yeah so those are the things I wanted to mention these are close only the things that I use mostly with of
acts like a and but this take a look at the great documentation and if you which want to see what what a lot of things there are and the and if you have a right application you can use you can just do anything on top of it right you can connect to a database we for example the sequel alchemy but you can use your favourite or an and you could use gender to surrender their
documents which we do for example to render
PDF documents yeah I you salary to scheduled task of I synchronous asynchronous leave or any other task that you like and 4 to third-party applications around with requests for example to to call the API as makes his calls and I'll go wired remote control a robot to watch
and that's pretty much thank you for listening I would like to talk to me about yeah tunnels train tunnels or vector like talk come talk to me or often and with thank you he thank you what means that you need to be and questions you yeah just 1
were still going through use of all what he what what did you prefer a valid over other choices like wet-bulb idle under the web
all those which is the full visual off by the army and final years it's nearly the same so I have well and what is God I was actually at the wrong 1 made the decision so uh I don't know I don't subliminal and the tool you were talking about I guess it's just a matter of taste 90 and we we want it to be very much in control all of this stuff so we want to have an the and like would libraries and right most of the stuff ourselves but you could you could use most other tools as well for here think her talk was really nice not out of curiosity which parts of the jungle work to build it for you and yes well as I said it's a it's just for the use of and forest special because of an asset template rendering for example we may want to use that we also didn't want to use the Django or which is I guess just a matter of taste i and at the time I yeah we were just not all of us were not too familiar with general sold then the difference of 2 so you have better make a decision as to learn genuine like on an expert level and which we didn't really know if it would benefit us enough so or the other alternative was to stuff what is more questions OK question would island when which he cheese Vexillarius versus false and wine and for I don't it really depends on act as as I'm not I'm not just suggesting that you can't do all these things with with other things I think are general arrest is also in existence I mean we have to look at this and yet flask
brings with it and the on top of this routing systems and I think the or was also options like a applied in on I think that's that depends on the on the and use cases think it's a really nice tool tool to learn stuff if you want to begin to how how GP whiskey work whose work talk on that if you want to do something special was this stuff response function the whiskey function that the of the the environment with and I we would have to say I don't really know at all I knows this and had some whole it's a callable that somehow we used to know and generates the request you not do you know more about this but is positive with the these and I think yeah it's a quotable which like like like if you look at was these which in the PAP somewhere explains yes yeah a rights yeah the good on that I might you