Add to Watchlist

Morepath: a Python Web Framework with Super Powers


Citation of segment
Embed Code
Purchasing a DVD Cite video

Formal Metadata

Title Morepath: a Python Web Framework with Super Powers
Title of Series EuroPython 2014
Part Number 104
Number of Parts 120
Author Faassen, Martijn
License CC Attribution 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 purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
DOI 10.5446/20002
Publisher EuroPython
Release Date 2014
Language English
Production Place Berlin

Content Metadata

Subject Area Computer Science
Abstract Martijn Faassen - Morepath: a Python Web Framework with Super Powers Morepath is a server web framework written with modern, rich client web development in mind. Why another new Python web framework in 2014? Because it can be done better: Morepath understands how to construct hyperlinks from models. Writing a generic view in Morepath is like writing any other view. With Morepath, you can reuse, extend and override apps as easily as you can construct them. Even if you don't end up using Morepath, you will learn something about how the nature of web frameworks. ----- Morepath is a new server web framework written with modern, rich client web development in mind. In the talk I will be discussing some core features of Morepath that make it different: * Its different take on routing and linking. Morepath has support to help you construct hyperlinks to models. * Its view system: plain views, generic views, view composition. * Morepath's approach to application construction allows application extension and overriding, and composition. This talk will attempt to convince people to try Morepath. For those unable or unwilling to try, I will communicate some design principles behind Morepath which can be of help to any web developer.
Keywords EuroPython Conference
EP 2014
EuroPython 2014
you as the bear with me the presentation will definitely get on this screen is I just for 700 and it's 1900 so I have a lot of extra space of and
so it when I have more was ready to use just now have we you not understand and
most recently more the so why would somebody new web framework in 2014 sort of through the regular try to show you why you could still be new things with more less traditional out incorrect frameworks and in order to do so I have to compare contrast more more about other vital web frameworks and so I'm going to do like laundry detergent commercial you know when you the stuff you put your washer because white powder in and the traditional commercial for that you have like the shiny books that and you have little
brand X which really sucks so I'm going to be this annoying sales guy was going to tell you all that the Chinese boxes also and Brent axis horrible so yeah Brand X with you you would brand acts rent tax is 1 of the popular routing web frameworks entitlement you probably use I will not only in the and by this book you might learn something about mobile the but also more about Brand X because the contrast works both ways that might benefit you and I really
won't name brand that's OK and so could be bottle flask gender or or
or or pyramid in its most common configuration go through this kind of special what all special and all have their benefits I'm not trying to pretend that just contrast the and of course in say yeah brand X and I'm better and more popular but and there is especially special and I learned a lot from it we here uses a brand X web framework like
routing and fuse and stuff yeah also people so a little bit about the more about origins that we're going to very the citizens exploding planet zone
and just at the last moment they they they shoot out this this uh this sort of hero with superpowers as always you know exposed to all pieces of the planet so right as feedback so that issue that out is that you know of the 1st English evaluation of the pyramid horse is already crumbling down but you know to pyramid people orbits Montessori crumbles earlier so the binary images that out of time it's OK and so this is a really easy to recognize because state so that this really alien blow so it's it's a simple anyway so what are the goals of mobile more about this
focused on the on the modern Web and the model Web means rest and these rich JavaScript based applies at applications run in the browser that use some kind arrest and past price to be easy to develop with to be powerful so that when you are sort of trying to do something more sophisticated you still do well and it tries to be small as well because it needs to be embedded in
existing system that that didn't want to take too too much on board but so yeah I claim that more profit superpowers it looks like to do this in a city block and I guess he doesn't have superpowers on the outside to
look like your average flask or something and then you know you pools open is short and and so superpowers come out and it's important to realize that the superpowers of more power not that different mode of working the clock and actually has the superpowers to and do the normal block and the you know routing of using all that something more pop automatically sort of doing the super things is sort of doing more the same so you only need to learn the parameters that you don't even learn something new in order to use those to prepare so I'm going to discuss 3 topics i'm gonna
compare routing read friend acts and compared became more part meeting with Brewer event X and talk about we use a more pop like how you reuse code so let's discuss routing so we have about URL by and it goes to area the cat if you're hoping for more beautifully drawn pictures I didn't have enough time to to make more so we get 40 flights so and you know it takes time to draw that well so
anyway so we have a relative to to to recap
and you know that sort of these get representation of an animal it I get in typical routing framework and we have 1 extra requirement is you get the idea that not exist exists in the database or whatever then we want to get a 404 Not Found error from our
web server pretty simple case of this is what we do in a sort of typical I mean this hypothetical code but it's sort of what did you do in a rat Brand X framework to declare some kind around with a variable in there besides the there and then ideas used in a function of those 2 things it queries the database for an animal with that idea and then it represents that animal in this case adjacent but you could be using template the so yeah that example of the way actually not done we haven't fulfill the requirements if you train an
animal this is that the idea of an idea that does not exist in creating for a two-year axis on another database then we will get if 400 of 500 error because it tries to find a T. rex and maybe this thing returns non notable for many of our members will not any try to get the title of none of that doesn't work this an exception and the web server will make this into a 500 error but that's not what you want from your 1 4 for error so you have that at at call you have to say well if there's nothing there you have to say OK we're going return not found in you can do an exception maybe just returned response so this is friend x routing with area so this is not what about the we spent the code up into 2 functions if I knew I had 19 hundreds horizontal I would have put the 1st line on 1 line but I thought I had much less available so I would have to functions the same underlying code right normal lines you don't have to have normal line like this is in 1 of the scene 1 lines so 1st you say a popular can do an animal you have to say what kind of plastic in return from the function 1st that will be used later on and they needed a query there and and this with the inside and non on animal object cancers of animals and then you have a way to represent that animal if if you would say OK this is the full way to represent an animal unique style he didn't use the development like then I I guess at the 1st go to the model in interviews with that for the model is a two-step approach is that once approach now a nice benefit is that not modeled found actually happens automatically because sure this will return on the 1st function that animal and and the system knows all right we don't have an animal to represent them for for so you don't have to
do anything special you just work in a normal way 4 as can also have multiple names used the same model you also when I haven't had few whatever you can give the name and an animal slash gets less and it goes to the so despises that the ontology during long and because it's easy to forget the looks simple but then you forget the special case of an you get that anything so now we go on to the next topic so let's do a little rant about linking some links to make the web work right traditional HTML web sites were released web applications were released rest work at least I mean there was talk about hypermedia API said on Tuesday talking about you know how useful it is from stop playing and scaling up over multiple servers to use length and let you know your client follow links just like somebody clicking on a link in a website so wide into bread and x reference works better care about the generation that you hardly anything but it do is so you have to give your other being speaker referred to it later then you have to use that name is a generative link somehow you know some API and you have to know note that an idea is to go into that then played of your house To make a link works so we have to note in a duty to using type coupling between your routs your code and use it around to the changed around so you might have a problem you want a tight coupling and I thought about for a for loose coupling change things and you have to you have to know what parameters go in and you have to extract that information from the object in order to put it in so yeah I just discussed this but this is more about linking so there is no change to our previous coded just exactly the same and then you just have an animal object and you say give me a link to it and that works for any object that we know how to make links for any object as a rout declaring part the decorated real be linkable and it is this is loose coupling you can just make a link to an object without knowing what is making it possible to write generic code that doesn't need to know about what kind of insurance agent and it's just easier don't have to remember all this stuff anymore and you just do it so let's look about linking with query parameters so imagine instead of doing what we did before we do such animals and then we have a true parameter in your well it was called the idea and immediately the cat it's very similar to the last case and of course this is a bad example is this very simple example of by put there a better example would be like some kind of filtering search API the idea of your health is that in a good RESTful web designer traditional HTTP website that the client does not construct any part of the year except for the query parameters so that's why I'm giving you this example here so yeah you wanna get representations still the same you wanna get a 4 for it it's not there the off the racks and if you don't supplied idea want and you want to assume some default like OK to the full panel was it gets why not quite and or you want to say is no default if you don't apply an idea that's about requests and you wanna get a progress the references so we're and actually do that like this and you you have to add another special case study say OK we well at 1st you have to know that you have to extracted from the from the question of the day that and they have to see why it's not there then we have to do something special you have to do a lot of extra work in your function is given less simple so and and if yeah if you were to that no default that you want to raise about question how fast does automated that actually if you ask for something automatically raise that doesn't exist the your request parameters right so I got my view is that restless that's nice but most of them you have to to implement this in more but this is the more populated do that so we've actually not change the last 3 lines of the code at all we've barely changed the thought the only thing is changed the robot there to just such animals we've added a parameter to Oregon animal function and we have given a default there like and that will do this for us so now we can just the so that is is the same so you don't need do to something special so notable linking with group parameters so in brand acts In some frameworks have different things that don't very much uh it says so so I did use the further out name and you give it some keyword parameters and those will be added to the true parameters or perhaps the recommended in your plate you start you know adding things that is really ugly only do by hand basically just sort of dropped the ball that typically they don't really think about peer pressure that very much because after all the fundamental mechanism how the web works so I would think about that right so so you more about just works like that like before there's no change this label still generate linkages will generate 1 with the cat idea and if you might want to be kept the and more bubbles knows about the type of the parameter involves so i if you give them if you say this this parameter needs to be named and often it's enough to just give the default parameter and make that the and the system will assume OK well this is this should be an end to it and give us something that can be converted to an industry as a parameter we will try to convert it to get a value error so the connectivities 400 better graph so we'll do that for you for free and will do that for all kinds of parameters you can actually plug in your own so you so by default the does dates and things like that timestamps but so that moves on linking I have shown you that linking can be done by of so let's look at reuse and some or part of the facilities for for for reusing called because when web applications scroll or you have different pieces of that because you and combining them or you have an application and it's perfect and the developers of the alpha just want to make a few changes you wanted to read you want to make that easy and more popular use it's not like a special case you don't have to go to a special kind of subsystem and learn all these new things we use is just there part of the system so let's talk about you reuse 1st the so here we have a collection of animals that's maybe on slash animals you know without that but is there it want to return from an adjacent that has a rate of animals the list of animals and instead of creating a list of links to animals and you could have done it request link we want to actually embed information about the animal in the Jason so we can just say OK give me did Jason representation the Bible representation of translates adjacent for the animal and it doesn't care what kind animal this you're doing if if you're getting a list of whatever is you don't know what they are in this scope this code can be generic and still and that the more linked to them so that you use industry use use and this again you have loose coupling and you write generic code by default it is actually easier to write generic code by default so here we also generate views so and if you have a life form based class even animals subclass that subclass from from from life forms and you make a few for life forms that fuels exist for animals just inheritance you right so you can make a generic view for all life forms we say well for elephants we really want to add some extra information to make an exception is OK well for elephants we have this extra thing going on so you can do stuff like that and that allows you again to write you but framework to write a generic black collection based plaster then has a set of set of generic views and you have to fill in a few details and that sort of flows from the parameters of the system you don't have to do something else in the new things we have more than 1 application so a mobile application recently actually the the most recent release begin class you just have to classes here and then you can do all these past about some stuff to do you can add them to the classes but and the independent from each other so don't interfere with each other they don't share anything so you can just have to of them and that's actually very useful for um but we'll see a little bit more that later
1st we're going to talk about inheritance can also just inherits derived application based application we will share everything with the base applications so you just get that you don't have to that's just by from basically but you're sharing everything not just methods but you know the spot registration let's stuff is also in here that they could do over right so I can extensions lots of stages 1st Interstate while the based on just Americans just copying of war and you want to add something so you can say OK in the right application everything is as the base application we have 1 extra few you know was also such animals slash cat such extra you know and and that of some extra things for you so you have the same application with 1 extra little thing and scandalized you can think about framework applications that offer sort of set a framework for use that you can be used in multiple applications in all right so this is still it's kind of like Python so you have a base application here and the base application has the full view for animals with a you say OK well based applications great always routs use all great we want change 1 thing OK you can do that is to say OK I read every registered the full view for animal that in the derived application that you will get but if you use the original application of meaning thing with somebody else who doesn't want to override will still work will still work as before you can do composition of applications so you have an application user applications and you have a you have a wiki applications and their independently developed from each other or maybe your developing both of them and you don't want to think about users read about reducing don't think about which is been about users so you don't want to have a URL spaces like users say no you don't have that to think about where you end users when you are developing the we your house so you just have to applications to the 1 special thing we we've done their associated with the application as a variable expects to be is parameterized and is parameterized with the with the idea in order to create a wiki application to instantiated reactions have to do with the with the idea of what it won't do anything and I just put completely independent from each other they did just 1 that's a weak yen wiki pages and the other 1 that uses and now you want to combine them in each other so you would you say OK we have user application we want there to be a slash wiki on every user that has the which so you still get the amount to which the application on to the user application and every given day and this is the part where we want to mounted on story the model we can and we have to say how to get to wiki idea from the context of the user application so we know username and we need to have some way to find the we judge for use in and you look it up in some database but that that's only in the mountain code which he doesn't care about user names anymore and they you can merge them together you actually still have access to the user name if you want to in the in the week application on so more but there's a bunch of features that will go into details here there is a built-in identity information system and so you can protect and fused with permissions and you can define rules for your of your specific sensing saying models of this kind like animals are uh and they have people only have the added permission and a they know this table in the database S or whatever you can just do whatever rules you want it's very flexible system it doesn't assume anything so the basic core of more problems equally assumptions but led you to do come out wherever rules are appropriate application more others extensible when you few predicates we've really only seen the name predicate we have multiple names used and those that get request you can also make a POST request for the post fusing progress method that's building you can extended to say OK this you only matches 20 HDP except can vary in their request as this and this city can act extent that means for the normal pathway with a few decades and is also extensible with new converters if your application specific known datatype like a car or whatever and you have a way to represent the EU you can define a converter for it to just past that and also converted back again for Macao objected to to representation that you can use your your letter in your bathroom request parameters and you can extend more smallpox itself so you can say that I mean I haven't documented this so it's sort of a special thing but more about the application is a bunch of generic functions you can actually override those generic functions your applications if you don't like to read more about this routing or whatever direction right little bits of this so using the same mechanism to implement more part that more parts of a large to to override an extended most of us have a few extensions I have more adult transfection extension that are sort of copied from the pyramid the version of that and that basically let you it integrated transaction module and a transaction model integrated Socol community be whatever else sort of has had a debate with that and that that's that automatically commits mineral when a request is handled on their schools an error or you returning you know explicit status code that indicates error then it will not commit the transactional aborted transactions so that's kind of a nice feature to integrate systems in general way and recently I release more dogs static which is an extension that and adds the ability to publish static resources like the I'm not a script files users files in cash friendly way but also in a developer friendly way busting the catch you needed and to the web but and instead of blogs in as it was the middleware is similar to that static but it's oriented runs around the empowered tools you can use the tool to install these JavaScript libraries and then you can just start using them without having to do any extra special work to run to wrap them it's similar to fast static but there you need to do extra work I have a list of his documents while some idea extending more about itself is not documented but extend and address that is all documents or more talks log so I just checked the PDF of version of the documentation is about 90 pages and end running quite a bit of let's look at little bit at performance like maybe there's a huge performance cost make more smallpox very slow but the idea and benchmarks tried at a very simple Hello world benchmarking is always has no real whiskey server there and more it's it's sort of in the middle some system solid faster but of course in reality when you look at the real web application the overhead of actually implementing your stuff like during the database through interaction on generating views so much higher than in the WET framework it's imaginable but I just want to check the more boxes not ridiculously slowness is faster than the last model also a number of the code size I maybe more passes enormously slide which is OK but and I you know it's not reject it was kind of surprised the more popular depending on how you measure the smaller the model and always use RealizePalette dependencies whatsoever I don't know what wide and that was the reason not to use dependencies but more but if you do that is if you add them all up it's about what's going to be smaller than a lot of different people and local the cold but could be a red is some of the main library that more pop depends on which is sort of a rewrite of the old so component architecture in terms of generic functions the test site through the test docstrings imagine is a test or a little bigger than the actual code that's being tested which is how it should yeah we good w always Web opens the eyes so called interface I've list all the dependencies and WC-users is Rex cycle would have spent a lot of I had in mind I knew I had 1900 horizontal instead of 756 or something but conclusions so well that I would have shown that routing and the generation and reusing more smallpox is better than your brand X that the more pop tries to be and I hope I showed that more populous both use right is not much harder than flask also intimidated and it's a that very powerful is reuse and override potential like that and it's also still small so it's not intimidating so what's there and I hope that in nature frustrated Brand X that you may be using so well on any questions you bet you on the on the right that's what happens when you
watch Tiger Woods Brand X right there time and so are you and want to another not just the infirmary interesting talk um the what was the kind of status and also in the outlook of so as a kind of like stabilizing and you think that the next things are going to like what happened with them I mean what is the next plans physically on with that right so there's there's also the question of historical use sure what changes you need to get at the right so maybe a few weeks ago I thought it was pretty stable something changes massive women and decided to make applications losses as that of instances which was a rather big don't normally hybrid and for a developer to actually just anti-codon I mean that that was not so I don't think there's going to be any changes that may give you a huge problem if you start developing rated now my plans are mostly involving writing extensions spread like uh you know looking at some of these stressful standards for and for making links to these Boolean bubble more pop up throwing more part itself is also a lot of potential for writing an extension that sort of thing we implement some of the pyramid of indicators this database authentication that's all extension that's not cost of the so I don't think I'm going to change very much anymore when you never know in 3 weeks time some brilliant idea but even then I don't think it's going to be a giant burden on whereas code based so it's it's getting pretty stable I think we are starting to use it ourselves in our own project now so people are starting building real world in my customer project code itself is ready to go national and international next features can come and set up please and
mounting speaking through online
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation
Computer animation


  393 ms - page object


AV-Portal 3.8.0 (dec2fe8b0ce2e718d55d6f23ab68f0b2424a1f3f)