Hello to the World in 8 Web Frameworks (micro, batteries included & async)
This is a modal window.
The media could not be loaded, either because the server or network failed or because the format is not supported.
Formal Metadata
Title |
| |
Title of Series | ||
Number of Parts | 132 | |
Author | ||
License | 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 | |
Identifiers | 10.5446/44999 (DOI) | |
Publisher | ||
Release Date | ||
Language |
Content Metadata
Subject Area | ||
Genre | ||
Abstract |
|
EuroPython 20186 / 132
2
3
7
8
10
14
15
19
22
27
29
30
31
34
35
41
44
54
55
56
58
59
61
66
74
77
78
80
81
85
87
91
93
96
98
103
104
105
109
110
111
113
115
116
118
120
121
122
123
125
127
128
129
130
131
132
00:00
Software frameworkSoftwareIntelSoftware frameworkWeb 2.0Twitter1 (number)Different (Kate Ryan album)Software developerBitMedical imagingGoodness of fitMeeting/Interview
01:04
Smith chartCoccinellidaeUniform resource locatorWater vaporSoftware developerHardware-in-the-loop simulationTelecommunicationSystem callCartesian coordinate systemBitSoftware developerDifferent (Kate Ryan album)CodeTheory of relativityClient (computing)Product (business)Computer animation
01:42
DivisorAuthenticationClient (computing)Software developerTheory of relativityLibrary (computing)Computer programmingSoftware frameworkChemical equationExpressionPoint cloudPeer-to-peerFlash memorySupersonic speedComputer animation
02:15
ExpressionDifferent (Kate Ryan album)Android (robot)Branch (computer science)Insertion lossOrder (biology)Theory of relativitySoftware frameworkSoftware developerProduct (business)Maxima and minimaContent (media)BlogMultiplication signComputer clusterComputer animation
03:05
RootGroup actionGame controllerBuildingPower (physics)Computer fileSoftware frameworkOrder (biology)System callData conversionElectronic mailing listDifferent (Kate Ryan album)Object (grammar)Reading (process)Source codeMultiplication signComputer animation
04:27
Flash memoryUniform resource locatorDeclarative programmingRootCurvatureMobile appFunctional (mathematics)TwitterSlide ruleComputer fileEmailSoftware frameworkBitSingle-precision floating-point formatComputer animation
05:18
BitRegular graphSocial classFunctional (mathematics)View (database)RoutingObject (grammar)PiComputer fileMaizePoint (geometry)RootComputer animation
06:10
PiSocial classBitObject (grammar)ConvolutionComputer animation
06:52
HypermediaType theoryComputer virusRoutingRange (statistics)Revision control1 (number)Equaliser (mathematics)CuboidSpacetimeString (computer science)Internet service providerForestFunctional (mathematics)Object (grammar)CodeWeb browserError messageInformationType theoryUniform resource locatorSoftware frameworkParameter (computer programming)Multiplication signBitBuildingExtension (kinesiology)PiFunction (mathematics)RootPoint (geometry)Computer animation
09:07
CodeLine (geometry)Data miningSimilarity (geometry)Web browserDemo (music)Point (geometry)Functional (mathematics)View (database)Social classFiber (mathematics)Computer animation
10:02
Uniform resource locatorView (database)Computer virusWeb pageView (database)BitCodeDefault (computer science)Uniform resource locatorSoftware testingData conversionMobile appSet (mathematics)Server (computing)Entire functionData structureRootSystem administratorProjective planeBoilerplate (text)Endliche ModelltheorieDemo (music)Wrapper (data mining)Human migrationSoftware frameworkDatabaseLetterpress printingNetwork topologyFunctional (mathematics)Different (Kate Ryan album)Content (media)Computer fileVulnerability (computing)MereologyLevel (video gaming)MathematicsVapor barrierRegular graphFlagTemplate (C++)VolumenvisualisierungObject (grammar)Exploit (computer security)NP-hardWebsiteMultiplication signScripting languageInstallation artConfiguration spacePoint (geometry)Term (mathematics)Dependent and independent variablesDisk read-and-write headRadio-frequency identificationVideoconferencingComplex numberSocial classCodeElement (mathematics)Domain name
17:23
Server (computing)Configuration spaceElectronic data processingElectronic mailing listFunctional (mathematics)Software frameworkWeb pageHTTP cookieCodeDifferent (Kate Ryan album)Type theorySingle-precision floating-point formatObject (grammar)Projective planeView (database)Cartesian coordinate systemComputer fileInstance (computer science)RootConfiguration spacePiFunction (mathematics)Similarity (geometry)Scaling (geometry)PlanningUniform resource locatorIntegrated development environmentSocial classProduct (business)Software developerBitDatabaseDefault (computer science)Order (biology)Data structureServer (computing)Directory serviceObject-relational mappingTemplate (C++)Web 2.0Endliche ModelltheorieLogicSystem administratorRoutingSet (mathematics)AdditionCore dumpAnglePanel paintingComputer animation
22:33
Disk read-and-write headNumberSoftware frameworkBuffer overflowRoutingSoftware developer1 (number)View (database)Stack (abstract data type)GoogolConcurrency (computer science)DatabaseSocial classMereologyWeb browserData structureCodeTriangleElectronic mailing listRing (mathematics)Projective planeDifferent (Kate Ryan album)Vulnerability (computing)CASE <Informatik>Response time (technology)BitGroup actionException handlingPlanningBit rateDivisorError messageCartesian coordinate systemAreaObject-relational mappingRootComputer animation
26:22
Inclusion mapSocial classVulnerability (computing)Block (periodic table)Water vaporCodeHacker (term)FehlererkennungView (database)Confidence intervalSupersonic speedException handlingArray data structureLine (geometry)Web pageError messageType theoryUniqueness quantificationComputer animation
28:14
Flash memoryComputer virusDependent and independent variablesView (database)Configuration spaceRadical (chemistry)Supersonic speedProjective planeEnterprise architectureComputer-assisted translationDrop (liquid)ForestSoftware frameworkCodeView (database)Similarity (geometry)BitProduct (business)Type theoryPoint (geometry)Directed graphCoefficient of determinationLoop (music)RootCASE <Informatik>1 (number)System callFigurate numberSocial classMultiplication signNetwork topologyFunctional (mathematics)SineDifferential (mechanical device)Covering spaceData structurePiVideo gameRoutingQuicksortComputer animation
33:24
Different (Kate Ryan album)String (computer science)CodeWeb 2.0Software frameworkBitRepository (publishing)TwitterComputer animation
34:06
BuildingOnline chatAuthenticationMobile appThermische ZustandsgleichungDivisorGraphics tabletSlide ruleBlog1 (number)Link (knot theory)Different (Kate Ryan album)Expert systemRepository (publishing)Android (robot)Peer-to-peerExpressionCodeSoftware frameworkComputer animation
35:19
Software frameworkTwitterSlide ruleMultiplication signInformation securityScheduling (computing)WebsiteDecision theoryMathematicsStability theoryLink (knot theory)PlanningComputer animationMeeting/Interview
38:19
DivisorAuthenticationFerry CorstenSlide ruleFront and back endsDependent and independent variablesView (database)Software frameworkFlow separationGateway (telecommunications)Projective planePairwise comparisonOrder (biology)DatabaseCapability Maturity ModelPiObject (grammar)Extension (kinesiology)Mereology1 (number)Different (Kate Ryan album)Suite (music)Moment (mathematics)RoutingPlug-in (computing)Object-relational mappingRootGoogolRegular graphSequelLine (geometry)Computer animation
Transcript: English(auto-generated)
00:00
So yeah Thanks for coming along folks Basically, we're gonna do a really quick look at eight different web frameworks So we're gonna start looking at some micro frameworks gonna look at some batteries included ones I'm gonna finish off with some async So yeah, just a quick introduction to who I am Yeah, so I'm our ambassador
00:23
That's my Twitter handle. It's very imaginative. It's literally just my name and And I'm gonna try and go for because it's like eight web frameworks We're gonna go to the whole little world. It kind of sounded a bit like, you know around the world 80 days, but Jules Verne's e So I'm gonna go for like a bit of a steampunk Victorian kind of aesthetic for the whole thing. So I probably should be a bit better on this image. Give some a hat
00:45
Let's swap out those Rayvans Gotta have a bow tie if we're going Victorian and like that facial hair really needs an upgrade So, yes, this is me I'm a developer advocate for people who don't know what that is I'm I literally get paid to wear branded t-shirts and hand out leaflets. I
01:03
Do that for a company called Nexmo? We're one of the sponsors here today. So we have a a booth actually on this floor I think so if you haven't checked it out yet, you should we may still have some t-shirts left Hopefully go grab some swag. Talk to us about what we do but essentially we're just a An API company we do telecommunications API so make it really easy to add the ability to
01:26
To kind of invite him an SMS or voice calls and things to your own applications. So I work with this team We're kind of a bit different than most developer relations teams and that we don't come under sales and marketing We actually come under product. We're all developers. We write all our own code
01:43
So all the client libraries and things that any of the developers interact with they were all been written by the developer relations team You know, we we still program an awful lot to be honest as well as programming. We we write a lot as well You know, we we want to make it as easy as possible people integrate our API's so we write a bunch of tutorials
02:01
So this one and uses JavaScript and then ionic framework. This one's Microsoft bought Android and firebase flashing Google Cloud The that peer-to-peer protocol and hug express and deployed on the glitch Sanic Django Android Swift angular Express we go through a lot of different
02:22
technologies at next month because well As we hear an API company, we want to like show people how they can integrate our products into whatever stack they're using But also it's kind of fun. You know, we enjoyed trying out new technologies. We enjoy trying out new frameworks I personally come from a background of Python and Django. I use Django for a very long time
02:42
So a lot of this stuff when I first arrived there was written in Django Now I've started to branch out look other kind of Python frameworks look at lots of JavaScript frameworks And that's what I'm gonna be talking about today is the fact that like over my last year doing developer relations I've obviously worked with an awful lot of different frameworks Writing these blog posts and reproducing this content and I'm gonna look at some of those that have used
03:02
As you go through this, so what I'm going to build essentially this so In order to power a lot of our API's we use Jason We call it a next move conversation control object, but it's a JSON file. It's essentially just a list of actions So this one is telling a telephone call to use a synthesized voice to read out some text
03:25
You know pretty straightforward and that's gonna build for each of these different frameworks today So it's gonna be one roots. That's just gonna spit out some Jason, you know, so really kind of easy So first one we're gonna look at is flask So flask actually started off as a an April's Fool's joke the offer of flask
03:43
Was quite well known at the time for being credibly critical of different frameworks So as an April's Fool's joke He decided to write his own framework a framework that did everything he hated about micro frameworks And he released it and he didn't tell anybody it was a joke. He just released on the github. He did a screencast
04:01
He actually got like a friend of his to record the voice and stuff for it he wrote a couple of posts and things and You know even I think even the source code was actually obticated when he first released it before and people start asking for the source and It's not incredibly popular probably one of the most popular micro frameworks And this is something the guy built with everything that he hated. So I think April Fool's jokes really kind of on him
04:25
But getting up running is very straightforward It's a single file kind of micro framework, you know, so you just create a Python file And we can see here that I'm just importing kind of flask I'm starting a new flask app and then my Root declaration is just a decorator on a function and that function using the JSON if I
04:44
flash method will set the headers correctly to say that it is a it's actually JSON that are returning it'll properly encode it and It'll then serve that up and running it again is incredibly easy You know I've got it here telling it what the name of my file is and it's just flask run and we have that served up
05:02
And ready to go so that's the first one kind of a taster of what we're gonna looking at today I'll put the URLs up for for each of the different frameworks as we go through them Don't worry too much about trying to like write them down or anything I'll be publishing all the slides on my Twitter anyway So next one is cherry cherries a little bit older than flasks being around for a little bit more
05:21
But it's very very similar. It's uses class based views rather than function based use So here we can see I'm defining a class Just a regular kind of object and I have again a couple of decorators on the methods and I'm just returning Again, another Python object which is going to be correctly encoded in a JSON and served up on that roots
05:42
And this one rather than defining the actual route on the method like I was before We're defining this Sorry in our cherry pie quick start we have our different routes and we're telling what handlers to use for those There's no special way of running this, you know You've run it with guinea corn or your point your Python file on it
06:00
There's no cherry pie run etc. Like we had for flask but it is very very similar again. So Yeah, you're out for it Falcons kind of in that new it's really kind of geared mortaroids creating API, so it's You know really kind of easy to to return JSON on it
06:21
That's what it's kind of expecting you're gonna be want to be doing anyway, we can see here It's very similar to what we have a cherry pie. We're declaring a class We have an on get and then we're just returning this this object and we don't even need to tell it that it's gonna be Just encoded anything it expects that because it's it's built for API's now
06:41
This is kind of where? Well, I'll put it live up for a falcon first. So a falcon you can kind of see some of this stuff. It's It's nice, but it's a little bit convoluted So the people behind the next one hug kind of agreed in that as well and they try to simplify it a little bit Now we can see with hug. It's very similar to what we had with kind of flask or what we have with cherry pie
07:03
You know, it's just a function that's returning a Python object. It's gonna get encoded into Jason We have a decorator that's telling it what the root is, you know, it's very compact. It's very easy to run You're not saving an awful lot of space compared to what you wear or an awful lot of code compared to what Falcon Provided but that's only for the very simple example of hug
07:22
Where it kind of gets more interesting is when we start looking at more complex examples So in this example, you can see I've actually got two functions that are the same name And each function is actually operating on the same URL. So they're both on this NCCO root, you know, they're both Called called NCCO weirdly enough
07:42
But whenever we actually try to call any of these URLs you can see it's got a versions in it So the first one is good as versions equal one and next one's got this versions of a range of two to five So whenever we call a URL now We can just add the v1 or v2 v3 in the URL and it automatically does the versioning for us It also allows us to provide things like examples So in the second example there the we can see I've got this f-string that's gonna substitute the who
08:04
Into our hello world that's returning and we're showing in the in our decorator that you know this Who all right, we're sorry. We're finding an example of what who should be so we've got like who's gonna equal world and we're also saying in our And our method that we have this who promise coming free and we can actually type it as well
08:23
So we're saying that it's gonna be a string. It's gonna be a hug type of text Now if I try to access URL doesn't exist or I try to provide the wrong information to hug We get this lovely kind of error output in the browser, you know, so it's showing us what roots are available It's showing us what those roots are gonna return and showing us what the examples were that we provided
08:43
You know There's a lot of kind of really useful information for whenever trying to explore that that API And this is all kind of provided out of the box from hugs. It really builds upon what Falcon gives you But then extent extends it with a lot of kind of useful things But you end up building time and time again yourself in Falcon anyway
09:00
So that's hug So that's our first kind of just look at micro frameworks. It's not an awful lot to them That's kind of the point of them as you can see in the code it's you know, we're talking four or five lines each and you're up and you're running and They're really really handy in that With the micro frameworks a lot of the stuff that we do is obviously building demos
09:21
I mean want to get stuff up and running really fast You know we want just to be able to people don't want to be wondering too long about the infrastructure or the code or The things that aren't next way PIs essentially We just want something that we can show them a couple lines of code have it running in the browser immediately And they can they can get to work and that's where these really come in and we can see the majority of them
09:41
Looking really kind of similar and They might encode this required. They're looking very similar in hiding which they handle kind of fiber class based views or function decorators so We've done our our quick look at the micro frameworks, I know they're Not an awful lot of code to do them. That's that's kind of the point of them. So I'm gonna move on into
10:04
These batteries included framework and the term term get bars included really was kind of coined by by Django It was the first kind of batteries included, you know, everything's in there with the micro frameworks. They just give you The littlest amount possible, you know, they're gonna maybe give you rooting
10:20
they might give you template handling and they're gonna give you kind of Views and that's it, you know everything beyond that point is up to you but with your parties included frameworks they're gonna specify an awful lot more and they're gonna provide an awful lot more and for many of them it's going to be kind of You know a convention over configuration, you know So it's they'll have a way in which you they prefer you to do things and if you stick to that
10:44
Then it normally works out pretty well So if Django and we have a few different commands once it's kind of installed you've done your your pip install your pip Install etc. You've got this Django admin and Django admin has a start project Which is saying essentially is just going to build out your your initial kind of template now for anybody who use Django
11:04
Probably not 0.9 ish to 1.4 maybe and Whenever you did your original kind of start project and then you would do your run server It wasn't the greatest experience didn't set up your static files for you. Things were a little bit
11:21
Difficult, shall we say? Not anymore with Django now as soon as you run your do your start project and do your run server You immediately get this lovely kind of web page already up and running for you It also has a start app. So here I'm creating a new conversation app And it's gonna create a bit of a file structure for you So I've got just a print tree of that there we can see that
11:42
You know It's gonna create a new folder and that folders gonna be things run for your migrations for your deep for your database for your models For your views, it really gets an entire kind of structure and that's normally in the structure most people continue to follow with Django is the one that it kind of suggests So once we have our app created we need to add it to our settings
12:03
This is where you can kind of see, you know, these these frameworks. I'll only provide a lot more They need a lot more configuration as well. Whereas the micro frameworks is like a single page So you just wrote some code in run your pipe and you were done with these There's gonna be multiple different files. You need change lots of different bits need to be updated It's why we tend to avoid using these a lot and demos because you end up having to explain an awful lot of boilerplate
12:24
To people but if you were using it for your own kind of major projects It's probably what I would go for rather than micro. So anyway here we're in stock. We're adding it to our installed apps We then have our URLs So you can't put the URLs directly in the the URLs file
12:41
What most people tend to do is have your URLs file local to each app and then? Just reference that from your main URLs file. So here I'm I'm looking at them including these conversation dot URLs And then we create our view now Django does support function-based use so with you can just have a
13:02
View that's gonna return and take a request and return a response they preferred method method nice use class-based views They've been around for a while. They're still not By some people fully understood or fully utilized. I personally prefer them to make it a lot easier to test stuff trying to isolate things of in one large function-based view for testing is
13:23
Problematic and with class-based views obviously makes the testing a lot easier If people are having problems trying to get their heads wrapped around how class-based views actually work And there's a fantastic reference called CCBV.co.uk It'll lists all the different views that are in there It allows you to drill down into them
13:42
You know see exactly where they inherit from what the methods are available on them what the code of those methods are should you? Need to extend it yourself. It's incredibly useful I probably spend more time on that site when I'm writing Django than on the actual Django documentation itself I don't know if that says something about Django documentation around class-based views or not
14:01
But it's still a wonderful reference, and I highly recommend it the other thing that we have here is I don't know people spotted is whenever I'm turning this JSON response So I'm overriding the regular kind of response that we have Coming back of this get handler and instead I'm returning JSON, and I do have this C if equals false That's always a major red flag whenever you're having to do C if equals false on any method
14:24
Probably not something you want to be doing lightly maybe we want to be considering first and the reason for that is is I'm actually returning a array as part of my JSON Now there is a Vulnerability around returning a JSON file that has an array at the root
14:45
So if you were if you return a JSON file where essentially it's a dictionary at the root You know so it's an object rather well or both objects, but where it's a dictionary rather than an array and you include that in a script tag from a on your own website, so
15:01
Kind of cross through across the main exploits that won't render You know it's not going to execute anything. You can't just include a a JavaScript object on the page using an external tag It's not going to actually run anything However, if you have an array at the top level well the you can then overwrite the array function in JavaScript
15:21
And have that read out the contents of it So essentially the the array becomes like your JSON P your function wrapper around around that code So there's a great article that goes into this in a lot much detail, but why it's a really bad idea it's also why things like Django by default if you try to To return a JSON response that has an array as the root element. It's not gonna let you do it
15:44
You're gonna have to actually specifying that hey. I know what I'm doing. I'm a I'm a big person I'm a professional Please let me shoot myself in the foot. It's okay But you're still gonna have to let them to actually kind of go This is my responsibility, and I will I'll handle any repercussions from it
16:03
Okay, so once we get our view then we're gonna reference that in our in our URL So this is the actual URLs for the the app itself We can see we've got this app name equals conversation. I'm renaming the year the actual URL. This is just it's a nicety it allows you then if you if you reference in that URL throughout your code rather than having to
16:24
Like reference the URL itself or the roots you can just do conversation colon NCCO I need so if you change the roots or your URLs change at any point You don't need to go through all your coding and reach and change all your hard coded paths So putting it all together. You know we've got our Modifications to our settings file. We've got our two different URLs file
16:43
It's the need to be updated, and then we've got our view itself Which is actually doing it all the hard kind of work all the heavy lifting So there's a bit more to it the actual Once you get down to it the views are very similar to what we've seen before It's just we now need to kind of place them in the structure provided from Django So there's a lot more boilerplate to update
17:00
There's a lot more kind of configuration settings to set There's obviously gonna be a lot more code as well when you look at all the generated code from Django start project You know it's gonna create an awful lot of stuff a lot of kind of things It's gonna require to run, but and yeah, I'll give you the the URL for it as well Most people probably were familiar with Django anyway, and everyone that we've got then a lot on our kind of our barriers included this pyramid
17:25
so Pyramids got a long history. I think actually the Plone people might be down there Like sponsoring, so they're probably to give you a lot more of the background on it than I can but their slogan is start small and
17:40
finish big You know so and then you really can so with pyramids It can act like a micro framework. You know you can have it all in one page You can define your your views in there using your decorators to tell you want to render from Jason Configure your app, and you're done. You know there's not an awful lot more code there than what we saw for the likes of
18:01
Falcon for example or cherry pie you know it's it's a single function per view That's just gonna decorate on it. You know it really can't start that that small if you want But they've got this whole thing about finishing big So if you need it just for doing really quick kind of micro framework stuff You can do it that way if you're starting off on a larger scale project
18:20
Then they actually use cookie cutter for doing their templating so rather than having like a built-in kind of admin like Django does And there's using cookie cutter. There's a bunch of different cookie cutters out there depending upon the type of project when start I'm just using their their default permit starter, so you can see I've Done my cookie cutter here I've gotten this Pippin and install of all the dependencies one of the things that I find a little bit strange
18:45
Probably just my own way of approaching these is the fact that pyramid actually Packages everything as a Python package so your project then becomes deployable as a Python package itself You know it's just gonna have its own setup the pie in there Which is gonna list this kind of requirements etc and whenever you're doing your development
19:03
You can see that I've and Pippin have installed that with dash e to show that You know I'm still actually in development on this so I can still modify that the code that's contained within there and have it executed And then it comes with all the configuration is done in any files. You know so you'll have a development any a production any
19:20
For one for all your different environments And we have this p serve to allow you then to start serving the files up I once very similar to Django once you've run this kind of p serve on your your different configuration file Then it's going to stand up a server for you and present you with this lovely web very red web page in this instance Now once if we're using it as a in this finish big kind of way
19:43
So as a much larger kind of framework rather than using it as a micro framework on a single page Then we're very similar to what we had with With Django, and we've got a couple different configuration files to edit and this one. They actually put it all in your in it that pie Since we have this permit config
20:01
We're telling it where to lift the settings from we're setting up our roots So we've got a separate URLs that py or anything like that for it's all done within this configuration I know we're telling it just in this instance. Just a scanner our views file and find any any views that are in there So we switch from using just a single kind of function of a decorator in this one in this instance now instead
20:21
We're actually switched to a class based view Again, it has the same kind of benefits as what I was outlining with Django makes it a lot easier to test It makes it a lot easier to to override different methods and to create mixins etc And we can see here that I Have created a really simple kind of roots that again is just returning this Python object
20:40
It's going to be automatically encoded forming the JSON returned with the correct application type So the URL for pyramid there and if we look at the two kind of side-by-side We can see even with Pyramids kind of finished big mentality, there's Not a huge amount of difference between it to so pythons or Django's is a little bit more scattered for different files
21:06
Some of that's not really necessarily required. That's just my personal preference things like having additional URLs that PI It's not actually needed. You could just put it all in your in your First year else. In fact, there's actually a project out there that will turn Django into a single file
21:23
Framework much the same as flask or and if there were micro frameworks, it's disgusting So the good thing about any of these kind of Large frameworks over the micro frameworks is that there is conventions in there, you know
21:41
There is ways you should follow to get things done. There's lots of books and things like there that explain for Django two scoops is probably the main one, you know go for all the best practices and Hopefully if you approach one Django project, you know It should look very similar to any other Django project You're gonna be structured very much the same way You're gonna your models are gonna be using the same ORM in order to access a database
22:00
You know your views are gonna be structured in very similar ways Okay, you might have some functional base use rather than class based use But again, it should all be in a logical kind of place and you should be able to navigate the directory structure and find What you need very quickly Micro frameworks, they're slightly different in that. Well, they just give you the very very basics and leave the rest up to yourself
22:22
And for developers sometimes that even for larger projects that seems like a great idea You know, we don't want to be constrained by other people's ways of doing things Sometimes, you know, we've got this grand grand plan of what we're gonna build, you know We're gonna pour a heart and soul into this project and it's gonna be fantastic And we're not gonna make any of the mistakes that Django made or any mistakes that permit made
22:42
You know our use case is unique to us So we're gonna start with the most basic framework we can and then we're gonna like start adding in all the different things that we Need that are written exactly for us and just the way that we need them, you know We're not gonna worry about the fact that you know, obviously Django is a great framework There's a lot of work to put into it But concessions have probably had to be made because well, it's it's not geared exactly to what we need
23:05
So instead you start off a micro framework and then you might add in like SQL alchemy Or you might start adding in like some of your own ORM stuff Of course, these are all interesting problems and that's what developers like to do So that's why we do it. Why would we use somebody else's ORM?
23:21
You know when it might not do it exactly the way we want So we write our own and we integrate that instead and well, that's the interesting part documentation is not interesting So it's not documentation. Nobody does documentation So the next developer comes along and they maybe they like what you did. Maybe they don't like what you did you know, they might Like meant it slightly differently or they may not quite understand the way which I've meant to that
23:43
There's no documentation. So they might use it slightly differently to what you'd use that You might not even see what you've done previously and they might start a completely new way of accessing the database And then a third developer comes along and they actually they don't want to rule their own So they just go and like Google it and take the first stack overflow answer and start doing it that way instead
24:01
You know and suddenly this lovely framework that you'd designed in your head starts to look a little bit different You know, I've seen this happen as well in Countless different places where they go we're gonna we're not gonna use Django because you know, we don't like the way in which it handles Views or we're not going to use pyramid because we don't like the way in which it's packaged for deployment
24:22
Oh, we're not going to use, you know, list your favorite frameworks here, you know We're gonna we're gonna build it ourselves because we can do better, you know probably not Okay, so we're running for this really quickly, but we're now on to our async So we're gonna start off with probably granddaddy of always think once which is tornado
24:41
the benefits of async most people think of immediately is kind of speed and Tornadoes actually slower than Django considerably slower than Django if you're talking about first response times to render a piece of Jason to the to the browser It's considerably slower like by I think a factor of two But where it really excels is in concurrency
25:03
And also in accuracy. So whereas with Django as your number of concurrent users in Increases your area also increases with tornado it tends to stay pretty consistent and pretty low as well, you know So it's gonna be able to handle
25:20
Requests might be slightly slower, but it's gonna handle a lot more concurrent requests with a lot lower failure rate So let's look at how tornadoes kind of set up then Again, it's gonna be pretty straightforward It's much the same as a lot of the micro frameworks. You can use kind of last class-based views You can structure it a lot differently. It doesn't really put a lot of kind of conventions around you here
25:42
We can see I'm just defining a a class with a gap method I'm configuring my my roots again, and I'm starting my application now this Will work, but if we look at this action here We can see it's not actually gonna work for next month next one requires that to be a list Even though there's one only one action occurring in there
26:01
It has to be a list now if I try turning that into a list and running in tornado, we're gonna get this You know, it's gonna throw an exception because of that that security vulnerability to be talked about earlier It's a really nice exception actually and it explains why it's going to do it But it's trying to stop me from introducing a security vulnerability in my code You know, but as we've talked about earlier, like I will find a way to shoot myself in the foot
26:25
My tornado doesn't have a way for me to go, you know, see if equals false and allow me to do it It just blocks it, you know, it's It's saying this is a security vulnerability. You should not be doing this. We're not gonna let you do it But it's it's a Python class, you know, it's got all this lovely we can go in we can look at the actual
26:44
The code for it. We can see it's got all this error checking in there. You know, it's looking to ensure that That it's either bytes a unique code type or a dictionary, you know It's making sure that it's not going to be an array if it is an array to return that that exception But we're professionals
27:00
You know error checking is for people who do not have confidence in their code So, so we're gonna get rid of all of that, you know, and because it's a class-based view We can just strip all that stuff out. We can overwrite their their right method. We can remove all that all that Error checking, you know, let's we will be wholly and solely responsible for introducing all the security vulnerabilities
27:24
We want in our code dammit. It's our code and if we want to be insecure we will be So we remove all their error checking But now doesn't even check to see what kind of thing we're passing it Everything's gonna be JSON from now on that's that's that's fine. We're just gonna always return to you soon And we we run this line. It's gonna work
27:43
So it's returning them Now the the last kind of one that we're we're gonna look at and I know we've gone through seven already I really wish I'd brought some of that water up on the desk. Um, yes the last we're gonna look at is amazing is Sanic So whenever I first came across Sanic, I actually completely and utterly dismissed it. Thank you so much
28:04
I Thought it was a joke to be honest. I Came up in like Hacker News. I went to the github page and this is their mascot
28:20
Very enterprise friendly, you know, I have for people who don't wear it's it's just really bad drawing of Sonic and Sanic, but yeah, it actually completely turned me off from the project, you know And even when you start off the terminal like you get this in the terminal like they've really gone all-in on this mascot
28:41
And It I immediately assumed it was a joke, I thought okay, so somebody's done basically a flask but for a sink And I I completely dismissed it. Like I didn't really look into anymore I didn't go back to it for probably Like 18 months until I never come friends. Somebody was raving about this this framework
29:01
I completely forgotten all about it and whenever I went to look it up. I was like seriously This is still a thing. That's a long-running joke But no, it's actually great and I don't know if this is I don't know The moral here is like I ever don't judge a book by its cover or maybe branding matters. I'm not sure but Yeah, I know I know people sometimes have a go at the whole Django like Pegasus unicorn type thing
29:27
And how it's not, you know, it's not enterprise friendly. It's not very professional Yeah, it could be worse So Sonic, you know by basically because of UV loop and so in in Python from three point four, I think we've had kind of async and
29:45
There's now a drop in replacement for another built-in async a python call UV loop. It's a lot faster And sonic really just came as a way to take full advantage of that Much that we have before it's really simple to get up and running. You know, we're we're just defining a
30:02
Function and we're going to Got our decorator on that to say what the root should be so it's always gonna be this NCCO for any of our our calls here and then we just we just run it from the command line with our our our Python Hello, I think we call these and we're gonna get this similar this I put thankfully this I should say this only appears if you've
30:21
Got debug set to true We don't get the lovely mascot if in your production when you're running it, so it's not quite so bad But it can also support class-based views So we can see here that it looks very similar to some of the ones we've had, you know I'm defining our class we have this and in this case, so we're using async
30:40
So we've got this async methods that's usually turn our JSON for us and then we can just run that as we did before So our sonic one Now as I was going through Writing the code for all eight of these different ones By the way, that's that's that was a fantastic idea of mine, let's let's let's do a conference talk I need to write the same code eat bloody times
31:04
That's the going for you writing the code I see started notice that it's really similar So here is how we define our written flask And here is it in sonic and here is in hug You know, we've got very very similar Okay, so it's up that route up that route hug that get you know, but it's it's a very similar kind of structure
31:24
You know and then I saw no sort of things like I'm pyramid, you know, so whenever we're defining our roots there, okay It's not app dot route, but it's again. It's you know, if you come figure in a root name or whenever we're looking at our Class-based views, you know, we've just got these get methods and then on tornado
31:40
We've got a get method and on Django. We've got a get method and on Falcon. We've got an on get You know again very similar And then I started noticing things like so on Falcon there. We've got this API ad route as well You know which kind of looks like tornadoes, you know, first the configuring it was kind of looks like pyramids for configuring it You know for all these like the actual similarities to many of them were well very similar
32:07
So it's it's kind of an odd one then if you know What's how do you choose a trimmer to use or which one's the better one and to be honest? I've Got very little Kind of differentiation between them Django would be really my favorite to go for for batteries included because I know it best
32:25
If I had started out my career writing pyramid, I'd probably be up here like using pyramid for most of my examples instead. Um Whenever I come to use a micro framework again, I'll normally do use flask because that's the one I used first You know, it's it's not because I couldn't
32:42
Articulate that so my reasoning for it why I prefer flask over cherry pie or why I would use flask over Hug or over Falcon because it's it's not a case of oh It's this particular feature is a killer feature or that particular way that does it is the way that I really enjoy It's just it's the one I use first you know, and I probably should explore that myself a little bit more because I probably I'm missing out on on
33:05
better ways of doing things because I'm You know, like most people I'm sick with what's familiar now I stick with what I know and but we're running all these it turns out that actually You know the Examples are at least the basics of each one is so similar that that reskilling or learning the different frameworks didn't take very long at all
33:22
But I guess that's kind of like the whole point of life in you know There should be one and hopefully only one way of doing things apart from if it's string concatenation Then we should have lots of different ways apparently okay, so I've been our ambassador. This has been my talk on eight different web frameworks
33:42
Hopefully you got a chance to Absorb a little bit of each one. I know there was an awful lot of code going through very very quickly there and I will post the I have a github repository that has everything I went through all the code examples With like explanations how to run each one. And so that's all up on my github
34:03
I'll tweet it on our ambassador. I also put it on I should probably go right away back to the start There was a lot of slides Just One or two here. There we go. Keep going. All right, and on next month's account as well So we have an expo dev account
34:21
I'll put all the links to the slides links to get hub repositories also the different blog posts I went through earlier, you know, so once of angular Swift Android Django Sanic, you know Express or peer-to-peer stuff all that kind of blog posts all up on a next one. I'll come to Again, they're gonna be using all different frameworks. I've talked about today
34:42
This is actually one from mark. So mark is one of my colleagues. You may have seen him He's the other dude in the kill walking about and he doesn't wear it quite so well So he's gonna be talking actually around today, but about half to so I recommend catching that as well if you can
35:01
Other than that, we're gonna be on the booth for the for the rest of the conference Please come say hello And if you've any questions about like any of the frameworks and things that I went through I will try my best to answer them But as I said a lot for a lot of them, I'm really just a beginner as well I've just been using them because I thought they were interesting and trying to get some example code and stuff like that for people but yeah, so
35:22
Again, that's my my Twitter Please follow along. I'll tweet out all links and things and thank you very much for your time
35:52
Thanks, Aaron. Hey, that was quite a nice overview. Um You mentioned it to be at the end. That's you Probably would just go for flask or just go for jenga because you got experience there
36:04
when you look at the frameworks from a more Company or from a business decision. Would you consider or to have you looked into any? I don't know security handling of those frameworks and how they compare to each other would that be a
36:21
thing where you would make decision based on Yeah, so for me really the The reason that I probably would pick Django again And this was probably people will be able to tell me that all the frameworks of this I'm sure but is their deprecation schedule The way in which they handle kind of releases
36:42
And stability of the actual framework is in my mind Crucial for really any kind of company and that feeds into the security stuff I've seen companies where they just fail to upgrade because there's too many breaking changes or the way in which the different frameworks have handled kind of
37:01
Deprecation of of API etc has been so bad in the past That they're really scared to do any kind of upgrades and that means they end up not doing even security upgrades as well So for me the fact that they have a stable release schedule a published and deprecation schedule They stick to and the handling of their actual releases both security and and feature
37:25
It's probably why I would stick with Django My question is is it you Could recommend some API over another?
37:44
And if you plan to have a JavaScript framework managing the pronoun and more the back-end side handled by Can you say again the website that you are using for
38:05
Yeah, sure, oh I'll just put the let's get that slide back up sitting here somewhere After my thing off Draw all this stuff back on my face
38:24
You know what? Let's just exit out of this and let's just go directly to the slide I kind of forgot just how many slides I actually had Yeah, so for anybody can't read it it's CCBV.co.uk and it's a reference for Django's class-based views. It's incredibly useful
38:43
so the first part of your question is so if you're Essentially using the back-end just as an API like so driving either I'm assuming like react or or view your angular and The all of the ones we're looking at there had the ability built in to respond of Jason for some of them like flask
39:02
It required using like just on if I rather than like the regular response Once like Falcon are are really built to be API kind of back ends so you don't even need to specify that you're returning Jason as soon as it detects that the Your it's the object that you're returning from your view is a Python object rather than like one of their response objects
39:22
Or just plain text. It's gonna Assume that you want that encoded as Jason anyway So most of the modern frameworks will be geared towards that that kind of way of working and Django obviously is slightly different and that's In order to to turn it into really a API kind of back end
39:40
You're gonna need to use something like Django rest framework Which is really mature Successfully on several kind of large projects and things. So I would highly recommend that if you wanted to go kind of the Django route Again, even with the async ones. They're gonna be geared towards being API backends as well, you know So things like tornado again, if you just provide it with a a Python object, it's gonna assume that you want adjacent response
40:05
so I wouldn't worry too much about you know, whether or not they're gonna act as a Just as an API gateway All of them are capable of doing that and they all handle it really well again It's just looking for whichever one kind of suits your your style or your requirements best
41:20
And usually the ability to connect to some data
41:23
With So for For flask, I know that they do flask has got a very mature kind of plug-in Kind of ecosystem around it. It's it's one of those ones as well though that for things like database database access That there tends to be you know, a preferred method of doing it
41:42
So if you're giving around you're gonna find for flask it's gonna be flask It's gonna be sick welcoming and it's gonna be flask alchemy, you know Those things combined is normally way most people do the database access But because the whole idea of it is it just does the minimum mind required and allows you to configure the rest yourself I have come across situations where people have been using flask and abuse and seek welcoming
42:01
But then they've written their own ORM on top of it rather than using flask alchemy, etc And for Falcon and and hug which is based upon Falcon. I'm not really sure I know they're fairly new another not a lot research into what's available for them at the moment. I do know for Most of the reframeworks are went through as well. They do have like
42:22
for cherry pie especially essentially, especially they have a very mature kind of Ecosystem around different extensions for it. So they will have a preferred method of doing it again For the second for your question is if I've seen any major comparisons between all of them I haven't normally what you'll find is comparisons between maybe one or two, you know one will show you like, okay
42:42
This is how you get database access and flask and this is how you do it in cherry pie, you know Or something I'll look at like, okay So here is that how you will do the preferred method in Falcon but not see somebody do it for like all of the micro frameworks