 Hello, you'll have to bear with me the presentation will definitely fit on this screen because I adjusted it for 700 and it's 1900 so I have a lot of extra space So where am I well I was ready to juice just now been doing a lot of stuff and most recently more path So why would somebody create a new web framework in 2014? I started in 2013 I'm gonna try to show you why you can still do new things with more or less traditional routing web frameworks and In order to do so. I have to contrast more more path with other Python web frameworks So I'm gonna do like a laundry detergent commercial, you know when you the stuff you put in your washer You put this white powder in and in the traditional commercial for that you have like the shiny box there and You have the evil brand X which really sucks so I'm gonna be this annoying sales guy who is gonna tell you all that the shining box is awesome and Brent X is horrible So yeah, Brent X. What do you mean with Brent X? Brent X is one of the popular routing web frameworks in Python that you probably use I will not name them And by this talk you might learn something about more path But also more about Brent X because the contrast works both ways that might benefit you as well And I really won't name Brent X Okay Could be bottle or flask or Django or or or pyramid in its most common configuration though pyramid is kind of special Well, they're all special and they all have their benefits I'm not trying to put them down. I'm just contrasting and of course I'm gonna say that Brent X sucks and I'm better at more path and all that but And pyramid is especially special and I learn a lot from it Who here uses a brand X web framework like routing and fuse and stuff? Yeah, lots of people So a little bit about the more path origins. I won't go into this very deeply. So this is exploding planet soap and Just at the last moment they they they shoot out this this This sort of hero with superpowers As long as you're not exposed to old pieces of the planet soap, right? That's really bad So they shoot it out. That's actually not the first thing they shut out They already shut out a whole pyramid before It was only crumbling then but you know the pyramid people were a bit smarter They sort of crumbles earlier, so they but anyway, we just got out in time. It's okay And the soap pieces are really easy to recognize because they sort of have this weird alien green glow So it's it's simple. Anyway, so what are the goals of more path? More path is focused on the on the modern web And the modern web means rest and it means rich JavaScript based clients had applications run in the browser They use some kind of rest backend and more past tries to be easy to develop with to be powerful so that when you are sort of Trying to do something more sophisticated You can still do it and it tries to be small as well because it needs needed to be embedded in an existing system that Didn't want to take too much on board So yeah, I claim that more path has superpowers it looks like so that this innocent clock Ken guy who definitely doesn't have superpowers on the Outside so it looks like your average flask or something and then you know He pulls open his shirt and then suddenly the superpowers come out and it's important to realize that the superpowers of more path are not a Different mode of working Clock Kent actually has those superpowers too and doing the normal clock Kent things, you know routing and views and all that stuff in more path Automatically sort of doing the super things is sort of doing more of the same So you only need to learn the primitives that you don't need to learn something new in order to use those superpowers So I'm gonna discuss three topics. I'm gonna compare routing with brand X I'm gonna compare linking more path linking with Brand X and I'm gonna talk about reuse in more path like how you reuse code So let's discuss routing so we have a route a URL path and it goes to a A cat if you're hoping for more beautifully drawn pictures. I didn't have enough time to make more So we're gonna get boring slides now So, you know, it takes time to draw that well. So anyway So we have a route to a to a cat And you know that sort of means get the representation of an animal with the ID cat in a typical routing framework And we have a one extra requirement if the cat ID does not exist in the database or whatever Then we want to get a for for not found error from our web server It's pretty simple case. So this is what you do in a sort of typical I mean, this is hypothetical code But it's sort of what you typically do in a brand and brand X framework You declare some kind of route with a variable in there is ID there And then ID is used in a function that does two things It queries the database for an animal with that ID and then it represents that animal in this case of Jason But you could be using a template or whatever So, yeah, that looks simple But we're actually not done we haven't fulfilled our requirements if we query an animal This is that the ID with idea that does not exist if you're querying for a t-rex and it's not in our database then We will get a 400 a 500 error because it tries to find a t-rex And maybe this thing returns none of many or m mappers will return none And he tried to get a title of none and that doesn't work And there's an exception and the web server will make this into a 500 error But that's not what you want from your API on the four four error So you have to add code you have to say well if there's nothing there you have to say, okay We're gonna return not found maybe you can do an exception. Maybe you just return to a response So this is brand X routing with error handling So this is more path routing We split the code up into two functions if I knew I had 1900s horizontal I would have put the first line on one line, but I thought I had much less available So but there's two functions. It's the same amount of lines of code if you write normal lines You don't have you have normal line lengths. It's the same amount of code at least same amount of lines So first you say there's a path to a cat or to an animal You have to say what kind of class you're gonna return from that function first that will be used later And then you do the query there and then this returns either none or an animal object an instance of animal And then you have a way to represent that animal you have a view when you say, okay This is the default way to represent an animal you make in style so you do that you split it up like that and Yeah, so it could first go to the model and then a viewers looked up for the model It's a two-step approach instead of a one-step approach now a nice benefit of this that Not not found actually happens automatically because you this will return on the first function get animal and then the system knows Oh wait, we don't have an animal to represent then four four So you don't have to do anything special you just work in a normal way you get a four four. That's nice And you can also have multiple named views for the same model if you also want to have an added view or whatever You can give it a name and then animal slash cat slash edit goes to the added few So these biases that yeah, it's harder to do it wrong and because it's easy to forget look simple, but then you forget the special case and You get better linking so now we go on to the next topic. So let's do a little rant about linking So links make the web work quite traditional HTML websites work with links web applications work with links Rest work with links. I mean there was a talk about hypermedia APIs on Tuesday Talking about, you know, how useful it is for loose coupling and a scaling Over multiple servers to use links and let you know your client follow links just like somebody clicking on a link in the website So why then do bread and brand X web frameworks barely care about link generation? They do hardly anything What they do is this so You have to give your routed name so you can refer to it later Then you have to use that name when you generate a link somehow You know some API and you have to know that an ID needs to go into the Template of the URL to make the link work. So you have to know the name introducing tight coupling between your Routes and your code that uses the routes. So if you change the routes, you you might have a problem You don't want that tight coupling. I thought routes were for loose coupling So you could 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 there. So, yeah, I just discussed this This is more path linking so there's no change to our previous code. It just is 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 has a route declared with a path the decorator Will be linkable and it's this is loose coupling You can just make a link to an object without knowing what it is making it possible to write generic code That doesn't need to know about what kind of links you want to generate And it's just easier. Don't have to remember all this stuff anymore. You just do it So let's look about a linking with query parameters So imagine instead of doing what we did before we do slash animals and then we have a query parameter in a URL It's called ID and then we give it a cap. It's very similar to the last case and Of course, this is a bad example It's a very simple example as I put it there a better example would be like some kind of filtering search API The idea of URLs is that in a good RESTful web design or a traditional HTTP website The client does not Construct any part of the URL except for the query parameters so That's why I'm giving you this example here so Yeah, you want to get a representation still the same you want to get a four four if it's not there if you ask for the t-rex And if you don't supply the ID while you either you want to assume some default like okay the default animal is a cat why not right and Or you want to say no there is no default if you don't supply an ID That's a bad request and you want to get a bad request error from the system. So in brand actually do that like this You you have to add another special case there you have to say okay We well well you first you have to know that you have to extract this from the from the request You have to do that and then you have to say well if it's not there then we have to do something special You have to do all that extra work and your function is beginning less simple So and if you are if you were to have no default then you want to raise a bad request now Flask does automate that actually If you ask for something and automatically raise and that doesn't exist in your request parameters where it's like automatically raises bad requests So that's kind of nice, but most of them you have to implement it yourself In more path, this is the more pathway to do that. So we've actually not changed the Last three lines of the code at all. We've barely changed the top The only thing is we've changed the URL path there to just slash animals We've added the parameter to our get animal function and we have given a default there like Python and That will do this for us so Now you can just So yeah, this is the same so you don't need to do something special here So now we can look at linking with query parameters. So in brand X In some frameworks have different things, but they don't do very much It's so either you sort of refer to the route name and then you give it some keyword parameters And that will be added to the query parameters Or perhaps they recommend that in your template you start, you know adding things there That's really ugly or you do it by hand basically to just sort of drop the ball on that typically They don't really think about career parameters very much because after all there are fundamental mechanisms how the web works So I would think about that, right so So in more part it just works like that like before there is no change this link will still generate a link It just will generate one with the cat ID in there now if you my animal happens to be a cat And more part also knows about the type of the parameter involved So if you give it them if you say this this parameter needs to be an int and often It's enough to just give the default parameter and make that be an int the system will assume Okay, well, this is should be an int So if you then give a something that cannot be converted to an int string as a parameter It will try to convert it get a value error and say, okay, wait, we cannot convert this 400 better quest so we'll do that for you for free and it will do that for all kinds of parameters You can actually plug in your own so you so by default it does dates and things like that timestamps So that moves on from linking I hope I've shown you that linking can be done better So let's look at reuse So more path offers a lot of facilities for for for reusing cone because when web applications grow or You have different pieces of app application You want to combine or you have an application and it's perfect and it's developed by somebody else We just want to make few changes You want to do reuse and you want to make that easy and more path reuse is not like a special case You don't have to go to a special kind of subsystem and learn all these new things reuse is just there as part of the system So let's talk about view reuse first So here we have a collection of animals That's maybe on slash animals, you know without this cat bit there and we want to return some kind of Jason that has an array of animals a list of animals and Instead of creating a list of links to animals, which we could have done with request link We want to actually embed the information about the animal in The Jason so we can just say okay, give me the Jason representation or at least the Python Representation that translates to Jason for the animal and it doesn't care what kind of animal it is if you are doing If you're getting a list of whatever is and you don't know what they are in this code This code can be generic and still embed them or link to them So that's fewer use you can just reuse views and there's again You have loose coupling and you write generic code by default and it's actually easier to write generic code by default So here we also have a generic view so If you have a live form base class you have an animal subclass that subclasses from from from live form And you make a view for life form that view also exists for animals It's just inheritance basically 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 you can make an exception you say okay Well for elephants we have this extra thing going on here So you can do stuff like that and that allows you again to write generic frameworks You can write a generic collection based class that then has a set of set of generic views And you just have to fill in a few details and that sort of flows from the primitives of the system You don't have to do something else and learn new things You can have more than one application so a mobile application Recently actually in the most recent release became a class And you just have two classes here and then you can do all these paths and routes and stuff to them You can add them to the classes And they're independent from each other so they don't interfere with each other They don't share anything so you can just have two of them, and that's actually very useful But we'll see a little bit more that later first. We're going to talk about inheritance You can also just inherit you know a derived application from a base application meaning it will share everything with the base application So you you just get that you don't have to it's just Python basically But you're sharing everything not just methods, but you know all these path registrations all that stuff is also inherited And then you could do overwrite so I can do extensions So let's look at the extensions first you could say well the base and just inheritance is just copying us boring You want to add something so you could say okay in the derived application? Everything is as the base application when you have one extra view You know it's called so slash animal slash cat slash extra You know and and that does some extra thing for you So you have the same application with one extra little thing at it. It's kind of nice And you can think about framework Applications that offers sort of set of framework views that you can then reuse in multiple applications You can do override so it's still is kind of like Python So we have a base application here and the base application has a default view For animal, but then you say okay well base application is great all its routes views are all great We want to change one thing. Okay, you can do that You can say okay, I read a re-register the default view for animal then in the derived application That's the view you'll get but if you use the original application That's maybe maintained by somebody else who doesn't want that override it will still work will still work as before You can do composition of applications, so you have an application a user application and you have a You have a wiki application and they're independently developed from each other Or maybe you are developing both of them and you don't want to think about users when you develop wiki So you don't want to think about wikis when you develop users So you don't want to have a URL space with like Users, you know you don't want to have to think about worry about users when you are developing the wiki URLs So you just have two applications here the one special thing We've done there to say that the wiki application as a variable expects to be it's parameterized and it's parameterized with The wiki ID you need to in order to create a wiki application to instantiate it You actually have to give it the wiki ID otherwise it won't do anything and they just are completely independent from each other They they just one does a wiki and wiki pages and the other one does users and now you want to combine them in each other So you say okay We have the user application and we want there to be a slash wiki on every user that has the wiki so you say okay we mount the wiki application onto the user application and Then we give it a this is the path where we want to mount it on So we want to mount it on wiki and then we have to say how to get the wiki ID from the context of the user application So we know the username and we need to have some way to find the wiki ID for username You look it up in some database, but that that's only in the mounting code The wiki doesn't need to care about user names anymore and they you can merge them together You actually still have access to the username if you want to in the in the wiki application So more path has a bunch of other features. I won't go into details about here There's a built-in identity and permission system so you can protect Views with permissions and you can define rules for your your specifics is saying saying models of this kind like animals They people only have the edit permission if they you know this table in the database says so Whatever you can just do whatever rules you want. It's a very flexible system It doesn't assume anything so the basic core of more path doesn't make many assumptions But it does let you to come up with whatever rules are appropriate to your application More path is extensible the new view predicates. We've really only seen the name predicate where you have multiple names views Those are get requests, but you can also make a post request for the post view So you can have request method that's built in but you can extend it to say okay This view only matches when the HTTP accept header in the request says this and this so you can extend to that in sort of the normal more pathway with a few decorators It's also extensible with new converters if your application has specific, you know data type like a car or whatever and you you have a way to represent it in url You can define a converter for it to just parse that and also convert it back again from a car object to to a Representation that you can use in your url either in your path or in your quest parameters and you can extend more path itself So you can say I mean I haven't documented this so it's sort of a special thing But a more path application is a bunch of generic functions You can actually override those generic functions in your applications So if you don't like the way more path does routing or whatever you can actually override little bits And it's sort of using the same mechanism to implement more path that more path sort of allows you to to override and extend it More path does have a few extensions I have a more dot transaction extension that I sort of copied from the pyramid version of that That basically lets you it integrates with a transaction module and the transaction module integrates with sequel alchemy and zdb and whatever else sort of has Integrates with that and that lets that automatically commits whenever when a request is handled Unless there was an error or you're returning, you know explicit status code that indicates error Then it will not commit the transaction will abort the transaction. So that's kind of a nice feature to integrate these systems in a general way and recently I released a more dot static, which is a extension that adds the ability to publish static resources like JavaScript files and CSS files in a cache friendly way, but also in a developer friendly way busting the cache when you need it To the web And it sort of plugs in as a whiskey middleware. It's similar to fan static But it's oriented the rents around the power tool So you can use the power tool to install these JavaScript libraries and then you can just start using them without having to do any extra Special work to wrap them. It's similar to fan static, but there you need to do that extra work And all this stuff is documented Well, some of the extending a more path itself is not documented, but Extended the rest of that is all documented on more path read docs.org I just checked the PDF version of the documentation and it's about 90 pages. So I did end up writing quite a bit Let's look a little bit at performance like maybe there's a huge performance cost that makes more path very slow But I did a I mean as benchmarks, right? I did a very simple hello world benchmark and it's raw whiskey calls There's no real whiskey server there and more path. Well, it's it's it's sort of in the middle Some systems are a lot faster But of course in reality when you look at the real web application the overhead of actually implementing your stuff like doing the database Interaction or generating views is going to be so much higher than the web framework It's negligible, but I just wanted to check that more path is not ridiculously slow And it's not it's faster than than flask, but my lots slow and unbottled. So Code size like maybe more path is enormous. It's like whoops soap and No, it's not I checked and I was kind of surprised that More path depending on how you measure it is smaller than bottle Though if you realize the bottle has no dependencies whatsoever, I don't know what why they don't have Yeah, I don't see the reason not to use dependencies But more path is a few dependency if you add them all up It's about well, it's gonna be smaller than flask or the good definitely all and don't call the code code base Reg is sort of the main library that more path depends on which is sort of a rewrite of the old soap component Architecture in terms of generic functions the tests I excluded the test and the doc strings in measuring this a test Are a lot bigger than the actual code that's like being tested, which is how it should be Yeah, we w o is webop and see I is so blood interface I didn't list all the dependencies and W z is is work. So I could have spelled it all out if I had nine high if I knew I had 1900 horizontal instead of 756 or something Conclusion so yeah, I hope to have shown that routing and link generation and reuse in more path is better than your brand X More path tries to be and I hope I've shown that more path is both easy to use, right? It's not much harder than flask. It's not so intimidating At the same time very powerful in its reuse and overwrite and potential like that and it's also still small So it's not intimidating in sort of what's there, and I hope I didn't make you frustrated with brand X that you may be using so Are there any questions? Yeah, that's what happens That's what happens when you wash your tiger with brand X, right? Yeah my time thanks for very Go to one of the mics. Yes Thanks for a very interesting talk What I what is the kind of status and also the Outlook or so is it kind of like stabilizing and you think that the next things are going to like Happen with them. I mean what is what are your next plans basically on with that, right? So there's also the question of you start to use it now sure what changes do you need to adapt? It's a you know, so maybe a few weeks ago I thought it was pretty stable It was not going to change any massive way and then I decided to make applications classes instead of instances Which was a rather big way though not a high burden for a developer to actually adjust any code in I mean that that was not So I don't think there's going to be any changes that make give you a huge problem if you start developing with it now My plans are mostly involving writing extensions for it Like you know looking at some of these restful standards for making links to things building on top of more path not Growing more path itself. There's also a lot of sort of potential for writing an extension that sort of Reimplements some of the pyramid authenticators to stick it based on authentication, but that's all extension. That's not core stuff So I don't think I'm going to change it very much anymore, but you never know within three weeks time I have some brilliant idea, but I even then I don't think it's going to be a giant burden on whoever has a code base then So 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 real-world code of it. So it's ready. I think yeah Okay, if the next speaker can come and set up please and Martin will take any more questions