Latest / Talk Python To Me / #149: 4 Python Web Frameworks, Compared
Transcript
- 0:00Are you considering getting into web programming?
- 0:01Choosing a web framework like Pyramid Flask or Django can be daunting.
- 0:05It would be great to see them all build out the same application and compare the results side by side.
- 0:10That's why when I heard what Nicholas Hunt Walker was up to, I had to have him on the podcast.
- 0:15He and I chatted about four web frameworks compared.
- 0:18He built a data-driven web app with Flask, Tornado, Pyramid, and Django,
- 0:22and then put it all together in a presentation.
- 0:24We're going to dive into that right now.
- 0:26This is Talk Python To Me, episode 149, recorded January 30th, 2018.
- 0:32Welcome to Talk Python To Me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities.
- 0:52This is your host, Michael Kennedy.
- 0:54Follow me on Twitter, where I'm @mkennedy.
- 0:56Keep up with the show and listen to past episodes at talkpython.fm, and follow the show on Twitter via at Talk Python.
- 1:03Talk Python To Me is partially supported by our training courses.
- 1:06How does your team keep their Python skills sharp?
- 1:09How do you make sure new hires get started fast and learn the Pythonic way?
- 1:14If the answer is a series of boring videos that don't inspire or a subscription service you pay way too much for and use way too little, listen up.
- 1:22At Talk Python Training, we have enterprise tiers for all of our courses.
- 1:26Get just the one course you need for your team with full reporting and monitoring.
- 1:31Or ditch that unused subscription for our course bundles, which include all the courses, and you pay about the same price as a subscription once.
- 1:38For details, visit training. talkpython.fm/business or just email sales at talkpython.fm.
- 1:47Nick, welcome to Talk Python.
- 1:48Hey, thanks for having me.
- 1:49Yeah, it's great to be here.
- 1:50It was really nice to meet you last week at PyCascades.
- 1:53That was a fun conference.
- 1:54Oh, man, that was awesome.
- 1:55That was my second Python conference ever, and it was on par for me with PyCon.
- 2:01Yeah, it was definitely a different vibe.
- 2:02It wasn't like a huge expo hall or things like that, but I felt it made up for it in the richness of conversations.
- 2:10You could sit and talk with three or four people, and those people were amazing.
- 2:13Right, and the one thing that's been different is I've done a lot of academic conferences.
- 2:16I used to do astronomy, so I've been to a few national conferences, and I've always missed out on talks.
- 2:21And this is the first conference that I've gone to where I had the actual opportunity to sit and hear every talk.
- 2:27I didn't feel like I missed out on anything.
- 2:29Yeah, and the talks were really good.
- 2:30So congrats to everyone.
- 2:31That's a new conference, and you missed it this year, but it's coming to Seattle next year and then Portland the year after.
- 2:37And it's supposed to kind of go up and down the Cascades and the West Coast of the U.S., the mountain range.
- 2:41So it should be a lot of fun.
- 2:42I'm looking forward to going next year already.
- 2:45But that's not what we're here to talk about exactly, although we are going to cover a talk that you gave there, which sort of surveys a bunch of the popular web frameworks.
- 2:53And we'll get into that.
- 2:54So let's start with your story.
- 2:55How did you get into programming in Python?
- 2:57Sure.
- 2:57I actually didn't think I'd ever be programming, ever.
- 3:01I started doing astronomy back in about 2007.
- 3:05I just got really interested in how stars lived and died.
- 3:08And so I started doing astronomy.
- 3:10I started doing science.
- 3:10It seems like one of the most amazing parts of all science is astronomy these days.
- 3:15Yeah.
- 3:16I mean, there's a lot going on in astronomy.
- 3:18A lot of my former colleagues are doing some amazing work finding planets, learning about black holes that we didn't know existed, all kinds of great things.
- 3:25When I started doing astronomy, I naively thought that I would just be looking through telescopes and taking down notes and thinking through equations and that kind of thing.
- 3:33I didn't think I'd be writing any programs at all.
- 3:36And so when I got into grad school, even before I got into grad school, I had to learn how to program a little bit.
- 3:41And I used Fortran 77.
- 3:43And that was, I hated it.
- 3:46I hated it.
- 3:46I hated it.
- 3:47I did, too.
- 3:48I had to take it.
- 3:49I was in engineering at first.
- 3:50And they told me, I said, can I please take C++?
- 3:52They said, no, you have to take Fortran.
- 3:54It's the most important language you'll ever learn.
- 3:56I'm like, no.
- 3:58Well, it's one of those things where, like, when you're in academia and you're an undergrad or you're in grad school, you learn the language that your advisor knows.
- 4:07And my advisor knew Fortran, so I learned Fortran.
- 4:10And then when I went, that was at Columbia.
- 4:13I was in the Bridge to the PhD program there.
- 4:14It's a great program for the scientists.
- 4:16And when I transferred into a graduate program at the University of Washington, then my advisor was using a language called IDL.
- 4:26I forget what it even stands for, but it's a proprietary language.
- 4:28So you have to have a license on your computer to use it.
- 4:30And if you wanted to be able to, like, do work at home, you have to have a license on your home computer to use it.
- 4:35And so it's a whole lot of stuff with that.
- 4:37You have to be connected to the internet so they can verify your license.
- 4:40Oh, it's that intense?
- 4:41It has, like, almost like a dongle type thing?
- 4:43No, it's not a dongle.
- 4:44It's more like if you're not connected to the internet, then you can't use the IDL editor.
- 4:49Wow, that's intense.
- 4:50And you can't run your IDL program.
- 4:51That's kind of the opposite of it.
- 4:53Which sucks.
- 4:53Yeah, it's terrible.
- 4:55Exactly, exactly.
- 4:56And so I actually learned Python partially to get away from IDL.
- 5:00It was kind of my way out.
- 5:02I was like, I had been introduced to this language, and I was like, oh, this is a free thing.
- 5:06I don't have to have a separate license to do this.
- 5:08I can install it on any machine.
- 5:10It looks like English.
- 5:11Like, this is...
- 5:12Yeah, yeah.
- 5:13Why not?
- 5:13Yeah, absolutely.
- 5:14So I used Python for my research.
- 5:16I used Python for my homework.
- 5:17And then one of my colleagues at the time, like, and this is kind of where it really took off for me.
- 5:22He had been doing blog posts about science.
- 5:25And I was like, oh, that sounds cool.
- 5:26I should do that too.
- 5:28And I used Python to help me learn more about the science that I was doing.
- 5:33And I was using the science to help me learn more about the Python that I was writing.
- 5:36And so I kind of got a lot of that practice, you know, after hours, just using Python to answer interesting questions.
- 5:43Yeah, that sounds really cool.
- 5:44It's a very organic story of just like, I kind of just found my way into it.
- 5:48And I just, you know, I sort of grew as you played with it.
- 5:51That's awesome.
- 5:52So like I said, I'm a big fan of astronomy.
- 5:54Are you still doing that today?
- 5:55You're not, right?
- 5:56You're sort of...
- 5:57I'm not.
- 5:57You took the path that I did.
- 5:59Like, let me work on a PhD and actually do nothing and just go programming with it later.
- 6:03Now I just feel bad.
- 6:04But yeah.
- 6:05No, I know I do too.
- 6:06I kind of looked at my advisors and stuff when I left.
- 6:09I'm like, yeah, I'm sorry, but I'm going.
- 6:11It was tough, actually.
- 6:13But I think it's totally the right choice for me.
- 6:16I don't know about you.
- 6:17Yeah, it was time.
- 6:18I wouldn't make a second choice in a second.
- 6:20You know, I met some great people there, but I'm much happier doing what I'm doing now.
- 6:26Yeah.
- 6:26I feel like the PC experience in all of grad school kind of taught me how to do what I do now.
- 6:31But I feel like I'm applying it in a place that makes a bigger difference for more people.
- 6:35Right.
- 6:35I'm still doing as much reading as I was doing during my PhD program.
- 6:39I'm still doing as much thinking, but it's toward...
- 6:42So one of the problems that I had with the work that I was doing in my PhD program was
- 6:45it was not very easy to explain to other people why it was interesting or important.
- 6:50I knew why it was interesting or important.
- 6:51I love like aged stars and seeing how like what was happening as they were dying.
- 6:55But in order to explain that, I've got to explain, okay, look, this is how stars evolve.
- 6:59This is what all this stuff means.
- 7:01I've got to apply all this background.
- 7:03Whereas, you know, what I'm doing right now, I'm teaching at Code Fellows.
- 7:07And I can just say, you know, I'm teaching people how to program, you know, teaching people how to make websites.
- 7:11So, you know, the kind of stuff you see like a Google.com or anything.com, I'm teaching people to do that, at least at the basic level so they can go out into the real world and get a job and do that stuff for real.
- 7:22Yeah.
- 7:23And it's a great experience to help people sort of change careers or advance their career down some other path they weren't doing before.
- 7:30So what is a typical day?
- 7:32So Code Fellows is a boot camp for those who don't know, right?
- 7:35And what's a typical day there look like?
- 7:37Yeah.
- 7:37Code Fellows is one of the coding schools in Seattle.
- 7:40I'm a little biased.
- 7:41I think it's one of the best ones.
- 7:42But I also work here and I know some really good people.
- 7:45But a typical day when I'm teaching looks like three hours of lecture.
- 7:49Let's say I'm teaching one of my Python lectures.
- 7:52It's like, okay, we do about an hour of code review.
- 7:55And then we talk about some topics.
- 7:56We do some data structures.
- 7:58We do some algorithms practice.
- 7:59I'll teach you about a web framework or some aspects of a web framework, like what a model is or what a view is or how to do routing or security, that kind of thing.
- 8:09And then we go to lunch.
- 8:11And afterward, they come back and they work with each other on lab assignments.
- 8:15And we build the lab assignments to complement the lectures.
- 8:18And so I teach a thing.
- 8:19And then they use that concept in their application.
- 8:23And after that point in time, they're kind of on their own.
- 8:26They're still on location.
- 8:28But they're on their own building the projects.
- 8:31And myself and the TAs are here to grade their assignments and to be resources when they need help.
- 8:36Yeah, that sounds like a really fun job.
- 8:38And how long does the boot camp run for?
- 8:39The full sequence.
- 8:40So there's three levels to it.
- 8:42201, 301, and 401.
- 8:43201 is four weeks.
- 8:45And that's the basics of HTML, CSS, and JavaScript.
- 8:48And then the 301 is also four weeks.
- 8:50Because you have to do that.
- 8:51There's no way to avoid JavaScript.
- 8:53Right.
- 8:53Like there's no way to avoid it.
- 8:54That is the language of the web.
- 8:56Let's be honest here.
- 8:57Yep.
- 8:57It is.
- 8:58So 301 is also four weeks.
- 8:59That's more intermediate.
- 9:00HTML, CSS, and JavaScript.
- 9:01We talk about jQuery.
- 9:02We talk about more libraries.
- 9:04We kind of get people kind of more interested in the wider scope of being a web developer.
- 9:09We start dipping into the back end a little bit with Express, but not too much.
- 9:13And then in the 401, that's 10 weeks.
- 9:15We have several 401s.
- 9:17We have Python.
- 9:18We have JavaScript.
- 9:19We have Java.
- 9:20We have C#.net.
- 9:22And that's 10 weeks.
- 9:23For the Python class, that's basics of Python, a preliminary web framework like Pyramid,
- 9:30and then a more advanced web framework like Django.
- 9:32This is actually where my talk came from because I've been teaching this course or at least
- 9:36being a part of the teaching process in some way, shape, or form for the last almost two
- 9:40years and having all this exposure to it.
- 9:43And I was like, huh, I wonder what these other frameworks look like because I'd only ever
- 9:46taught.
- 9:46I'd never actually learned Python for web development in my graduate work.
- 9:50I was doing astronomy.
- 9:51I was doing data analysis.
- 9:52I only learned how to do this stuff on the job.
- 9:54They don't have web frameworks for machine learning across.
- 10:00You don't build web apps, right?
- 10:02You do build other stuff.
- 10:03Yeah, it's all custom software.
- 10:05Yeah, exactly.
- 10:05I'd never actually used Python for web development.
- 10:07So I only learned this stuff when I was on the job.
- 10:10And so I'd only been exposed to Pyramid and Django.
- 10:14I did a little bit of Flask just kind of as a one-off thing, but I didn't really understand
- 10:18what I was doing.
- 10:19So I didn't really take the time to get to dig into these web frameworks.
- 10:22I was like, okay, I wonder what these other ones are like.
- 10:26I should try to talk about that because I'm sure I'm not the only one who thinks this.
- 10:29No, I think it's a super interesting idea because a lot of times what I find is people,
- 10:34they kind of do a quick survey.
- 10:36They're like, all right, what's out there?
- 10:37Django.
- 10:38Okay, there's a lot of building blocks already built.
- 10:39They're kind of big.
- 10:40And I like, okay, well, there's a micro frameworks and they're really small.
- 10:43I put pieces together.
- 10:44This one or that one is mine.
- 10:45That's my style.
- 10:46I'm going to do it.
- 10:46And then they kind of just stop, right?
- 10:48You learn what you need to know to do the job you try to do.
- 10:51Yeah.
- 10:51And most people aren't doing, unless you're a contractor, you're not doing a new project
- 10:56every three months.
- 10:57In a different framework.
- 10:58Right.
- 10:58In a different framework or a different language entirely.
- 11:01You have your job.
- 11:02You might jump around from company to company, but you still like, most places are hiring for
- 11:08Django, so you learn Django.
- 11:09Or they're hiring for Flask, so you learn Flask.
- 11:10Or you're just building tools for the backend.
- 11:13But yeah, in my 10-week class, it's all that plus data structures and algorithms and a little
- 11:21smattering of machine learning.
- 11:22So it's like end to end with the week breaking between each class, it's about 20 weeks total.
- 11:26Wow.
- 11:27It sounds really fun.
- 11:28It's something like I could actually kind of enjoy hanging out there and just being part
- 11:32of that.
- 11:32That sounds fun.
- 11:32It's great.
- 11:33It's super intense.
- 11:34And honestly, now that I've taught it, I really wish that I had learned to program this way.
- 11:39It's really directed.
- 11:41When you go through undergrad and you get your degree, you've got to do a lot of ancillary
- 11:46stuff, which is great for building a well-rounded person.
- 11:49But if you're focused on just wanting to do one thing, it tends to get distracting.
- 11:53Whereas with this, the goal is clear.
- 11:57We want you to get a job.
- 11:58So we're going to train you to be able to do the things that jobs are asking you to do.
- 12:03And that's it.
- 12:04There's no humanities requirements.
- 12:06There's no other paths here.
- 12:08It's just like you're here for a specific reason.
- 12:10If your cause doesn't fit that reason, then you want to go somewhere else.
- 12:14But it's directed.
- 12:15It's focused.
- 12:16And it's cheaper than an undergraduate degree by far.
- 12:20Yeah.
- 12:21By quite a bit.
- 12:22Yeah.
- 12:22And time and money.
- 12:23That's cool.
- 12:23I mean, I'm a huge fan of the liberal arts education.
- 12:26I feel like it's good to be a well-rounded person.
- 12:28But I'm not entirely sure how much college should drive career training.
- 12:34You know, more like be a good person in society and be well-informed.
- 12:39Now go learn the thing, right?
- 12:41Yeah.
- 12:42And I mean, it's also good for networking.
- 12:44It's good for, you know, expanding your interests beyond whatever you learned in high school.
- 12:48But, you know, most of the people that we get are people who are changing jobs, not people fresh out of high school.
- 12:54I've had a few people who are fresh out of high school, but most folks have gone through, you know, they might have an undergraduate degree.
- 12:59I've even had a few people with CS degrees, but they've had a job before.
- 13:03They want to do a different job.
- 13:05They don't need all the ancillary stuff.
- 13:07They just want to know how to do a new job, which is fine.
- 13:09And we teach them how to do that.
- 13:11Yeah.
- 13:11Yeah.
- 13:11That's cool.
- 13:12That's excellent.
- 13:12Yeah.
- 13:14So let's talk about your, the four frameworks that you chose and maybe even start with just because with the app, because your idea was, I'm going to build the same app in four different frameworks.
- 13:25Right.
- 13:26So what's that?
- 13:27Yeah.
- 13:27So the app itself, I tried to keep it as simple as possible while still displaying, you know, the aspects of what a web.
- 13:33A framework should handle.
- 13:34And so I chose a to do list, which is, you know, everyone knows a to do list.
- 13:38So there's not much that needs to be explained in that way.
- 13:40So when I get to talk, it's like, Hey, you know what a to do list is.
- 13:43This app does that.
- 13:44You know, with this, with this application, you can, you can add new users through registration.
- 13:48You can log in, log out.
- 13:49You can add new tasks, edit existing ones or complete existing ones.
- 13:54You can even delete them if you want to.
- 13:55And so that's just kind of the backdrop for investigating how these four frameworks work.
- 14:02Yeah.
- 14:02That sounds pretty simple, but actually it touches on a lot of stuff.
- 14:05You've got a data access layer.
- 14:07You've got a database.
- 14:08You've got forms because you've got to post back information to register.
- 14:12You've got like secure user management.
- 14:14There's a lot of stuff actually going on there.
- 14:17Oh, absolutely.
- 14:17And I didn't, I didn't get to go into all of it in my talk.
- 14:20I didn't even get to finish writing all the code just because time got away from me, but
- 14:23it's not just, I'm going to send some data somewhere and it gets handled.
- 14:27It's okay.
- 14:28How exactly is it being handled?
- 14:29What exactly am I handling?
- 14:30And how is every web framework supposed to be doing it?
- 14:33And so when I originally wrote this talk, it was looking at each aspect of a web framework
- 14:39across all four.
- 14:41And then I revised it to look at each web framework one at a time, doing all the things that's,
- 14:46that the app requires.
- 14:48So I started with Flask and the setup and installation and then getting things up and running
- 14:55configuration and then how to make a view.
- 14:57So like a view is just a function that handles a request.
- 15:01So an incoming HTTP request and sends back a properly formatted response.
- 15:05And the benefit of web frameworks, and this is definitely something that my students learn
- 15:09because I have them build a web server from scratch as part of the course, is that you
- 15:14don't have to worry about a lot of the stuff that goes into building a response or parsing
- 15:20an existing request.
- 15:21There's so many different ways that an incoming request can go wrong.
- 15:24And you don't have to think through all that logic.
- 15:27You want to think more about how your app is supposed to work.
- 15:29Right.
- 15:29You could open a socket and just go to town on that thing.
- 15:32Right.
- 15:32But right.
- 15:33You know, splitting strings and using regex to find different parts of the request headers
- 15:37and all that stuff.
- 15:39But who wants, no one wants to do all that.
- 15:41No, no, no.
- 15:41Something that's already pre-built.
- 15:43And you know, people smarter than myself have done it.
- 15:47So why should I do it myself?
- 15:48Exactly.
- 15:48And there's people actively working on it.
- 15:50So the four frameworks you chose, you chose Flask.
- 15:53And then Tornado, I thought, was an interesting option.
- 15:56Yeah.
- 15:57I had heard about Tornado.
- 15:58And I didn't have any idea what it looked like, what it would do.
- 16:03But I heard the word async.
- 16:05And I was like, that should be useful.
- 16:07That sounds fun.
- 16:08Yeah.
- 16:09That sounds really fun.
- 16:09That's cool.
- 16:10So yeah, I'll dig into it.
- 16:11Yeah.
- 16:11And you've got Pyramid and Django.
- 16:13So those are the four.
- 16:14And let's, I guess, start with Flask.
- 16:17It's on the smallish side, right?
- 16:21It doesn't bring a lot to the table.
- 16:22It's one of these micro frameworks.
- 16:23But for your example, you still use Flask, Flask SQLAlchemy, and Flask HTTP Auth, right?
- 16:29Right.
- 16:30And I have to have those external packages because Flask really is the barest bones.
- 16:34Where a framework, it's just, you know, you can make a function that handles requests
- 16:39and returns a response.
- 16:41And that's all that Flask does on its own.
- 16:44Yeah, pretty much.
- 16:44And so if you want to talk to a database, or if you want to do any sort of authentication,
- 16:49you've got to use something else or write your own.
- 16:52Yeah.
- 16:52So like Flask, and there's benefits and drawbacks to each of those.
- 16:57So like if you want to use a database like a MongoDB database, you download the package
- 17:01that someone has written to use Flask MongoDB.
- 17:04Or you can even just write, you know, straight up queries on your own without using a go-between.
- 17:12And then that'll work.
- 17:13Right.
- 17:14Just write a couple lines of code and like sort of piece it together yourself.
- 17:17Right.
- 17:17And that's something you can do, especially if you only need a very small application.
- 17:21Flask is the way to go.
- 17:22Once you want to start doing more of the classical CRUD application, CRUD being create, read, update,
- 17:28and delete functions, you're going to start wanting to move away from Flask.
- 17:32Just because it can still do those things, but it becomes harder.
- 17:36Yeah, you do more of the legwork yourself.
- 17:38Yeah.
- 17:38So maybe let's go through, like, we'll kind of go through the same section for each framework.
- 17:42For Flask, let's talk about like, how do you like connect to the database and sort of incorporate that?
- 17:49Sure.
- 17:49So I'm a fan of the 12-factor application.
- 17:53Give us the quick summary on what 12-factor app is, if you can.
- 17:57Sure.
- 17:57And the way that I'm trying to connect to it here is that one of the parts that's important is having your code not change between development production.
- 18:05Instead, be dependent on your environment and the variables that are set in your environment.
- 18:09So my application should have the same code running, whether it's on my own machine or on Heroku or on AWS.
- 18:17All that I'm changing are some flags, like, you know, am I in debug or not?
- 18:21Is my database a local database or is it a remote database?
- 18:24And so one of the ways that I do that is I use an environment variable.
- 18:27I call it database URL just because I use that everywhere.
- 18:30That's used in several places.
- 18:31One of the places it's used is Heroku, so it makes it very easy for that.
- 18:35So I use an environment variable called database URL to point to my database's URL.
- 18:40And then I use an environment variable called Flask Gap to point to the directory of my Flask Gap.
- 18:45And then I put all my working code in the location of my Flask Gap, that app.py file.
- 18:52Right.
- 18:52Yes, you just have the app.py.
- 18:53And basically, you could just use Flask.sqlalchemy.
- 18:57And what is that like?
- 18:58Is that integrated?
- 18:59It creates a sort of a base model, right?
- 19:01If you do SQLAlchemy on its own, you've got to create the declarative base and do all of that stuff.
- 19:06And so the Flask SQLAlchemy kind of does a little bit of that work for you, right?
- 19:11Yeah, Flask SQLAlchemy takes care of a lot of that work for you.
- 19:14It just gives you this model object that you use.
- 19:16That includes the declarative base and all the SQLAlchemy machinery.
- 19:20But just lets you focus on building the actual objects that you want to insert into your database.
- 19:25And it also does a nice thing for you where it includes a method.
- 19:29No, I guess it's not a method.
- 19:30It's an attribute on the model object that you create that will talk to the database for you.
- 19:35So you can query for one object by just saying, you know, object name.query.all.
- 19:40And that gives you all the instances of that object in your database.
- 19:42Oh, yeah.
- 19:43That's really cool.
- 19:43Because otherwise, you have to, like, create a session and then use the session to create the query.
- 19:47Right.
- 19:48Yeah, so it's kind of like a convenience wrapper around the SQLAlchemy stuff.
- 19:52But for the models and everything, you just define them the same, more or less.
- 19:55Right.
- 19:55You set up columns by declaring columns.
- 19:58Yeah, it's really easy.
- 19:59You set up columns by declaring columns.
- 20:00If you want a primary key field, you say, this column is going to have a primary key.
- 20:03And it's going to be true.
- 20:05Like, the primary key flag is true.
- 20:06If you want to set up an explicit table name, you have a table name attribute that you set in your class.
- 20:11Any other behavior you want to have.
- 20:13You know, it's still a class in Python.
- 20:15So you can still add whatever methods you want to do special things.
- 20:18Right, right.
- 20:18I find I don't do that often, but a little bit.
- 20:21There's sometimes there's just, like, a few things you want to compute in Python related to that entity.
- 20:28And you're just like, oh, it just needs, like, a property or something here.
- 20:30And it'll be perfect.
- 20:31Exactly.
- 20:32And one of the things that I use that for was, so in my models, I have two models.
- 20:36I have a task model, which is the actual, like, to-do list task.
- 20:38And then I have a profile model, which is the user who has the tasks.
- 20:42And one of the things I wanted to do was when you register a user, automatically give them, like, they joined.
- 20:48And then also automatically give them, like, a secret token that you can use to log in and log out with.
- 20:53And that's not handled by SQLAlchemy.
- 20:56And so in the init method, I just say, you know, do whatever you were going to do in your init method, but also set these properties on the class.
- 21:03Yeah, I really like that.
- 21:05This portion of Talk Python To Me is brought to you by Linode.
- 21:09Are you looking for bulletproof hosting that's fast, simple, and incredibly affordable?
- 21:13Look past that bookstore and check out Linode at talkpython.fm/Linode.
- 21:18That's L-I-N-O-D-E.
- 21:20Plans start at just $5 a month for a dedicated server with a gig of RAM.
- 21:25They have 10 data centers across the globe.
- 21:27So no matter where you are, there's a data center near you.
- 21:30Whether you want to run your Python web app, host a private Git server, or file server, you'll get native SSDs on all the machines,
- 21:38a newly upgraded 200 gigabit network, 24-7 friendly support, even on holidays, and a seven-day money-back guarantee.
- 21:45Do you need a little help with your infrastructure?
- 21:47They even offer professional services to help you get started with architecture, migrations, and more.
- 21:54Get a dedicated server for free for the next four months.
- 21:57Just visit talkpython.fm/Linode.
- 22:02So then also the Flask SQLAlchemy comes with sort of a create all function that would be the, you go get the metadata and then do that on the base, right?
- 22:12There's like a little bit of a nice utility method there.
- 22:14Then when you talk, you talk about views.
- 22:16So in Flask, views are basically functions with a decorator.
- 22:19And they're super simple, right?
- 22:21Yeah, and that decorator, yeah, absolutely.
- 22:23That decorator is the app.route.
- 22:25So like your Flask app is the app object.
- 22:27And everything goes through there, including the routing.
- 22:31And you decorate every function that you want to be a view with app.route.
- 22:35And you pass as an argument to that decorator the actual route that's going to connect to this view.
- 22:39So let's say I want to have a home route.
- 22:41I say slash home is that route.
- 22:43For my decorator, I say, you know, the app symbol, app.route, and then slash home for my route.
- 22:50And then directly underneath that, the function is going to be whatever handles that route.
- 22:54So when the home route is accessed, that function will run kind of like a callback in JavaScript.
- 22:59Yeah, the other thing that's interesting about Flask, I think, is this global request object that's kind of always there, right?
- 23:06That was one of the weirder aspects of Flask.
- 23:09I'd never encountered that before using Flask.
- 23:11Because typically, like with other web frameworks, the request object is populated.
- 23:15It's a parameter.
- 23:16Just as a local variable.
- 23:17Yeah.
- 23:17It's a parameter in a function or a method in a class.
- 23:20But it's just populated for that one instance.
- 23:24And it's only usable by that one function unless you pass it somewhere else.
- 23:27With Flask, the request object is a global variable.
- 23:30It is the incoming request.
- 23:32And it's usable not just by your view function, but any function or anything that you have in that file, that script file.
- 23:42You can use it to do whatever you want to.
- 23:43So you can set up, you know, background tasks if you want to use that request object without any actual reference to your view.
- 23:49Yeah, and that's kind of funky.
- 23:51But it also makes it pretty easy.
- 23:53I had the guys that did Quart.
- 23:55The guy who did Quart on, and Quart is an asyncified version of Flask.
- 24:01And this type of stuff was one of the things that made making it async really challenging.
- 24:05Because how do you control when the request thing points at the right one?
- 24:12And then you release the thread, another one runs.
- 24:14It's like, it gets a little tricky.
- 24:15Yeah, I have no idea how that would work, honestly.
- 24:19It took some crazy monkey patching, as from what I understand.
- 24:21Good God.
- 24:22I mean, it's certainly possible, and I'm sure there's use cases for it.
- 24:26But I can't imagine the mess that must be under the hood when you're trying to do that.
- 24:29Yeah, it gets interesting.
- 24:30Yeah.
- 24:31All right, speaking of interesting, the one that is the most out there of the four that you chose, I think, is Tornado.
- 24:38And I'll just read the quick summary for Tornado that they put on their website, like the paragraph.
- 24:43So Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed, which is like some interesting early social media, for a non-blocking network I.O., right?
- 24:54So it scales to tens of thousands of open connections and makes it ideal for long polling, WebSockets, and so on.
- 25:00So if what you're doing is waiting on stuff, I'm calling web services, I'm calling database things, and I want to not block up my web tier when that happens, like Tornado is pretty cool.
- 25:10There's other options that are more modern, but this is like a really popular one.
- 25:14Yeah, definitely.
- 25:15Yeah, Tornado is useful for if you want to have a long-lived connection or if you want to do anything that requires some long-running input-output.
- 25:24This particular use case, this to-do list, is not the best place for Tornado to be used.
- 25:31It's still like you don't need to do async stuff with Tornado.
- 25:34You can use it just like a Flask or like a Django.
- 25:37It'll work the exact same way.
- 25:39It just handles requests and sends back responses.
- 25:41But if you do have a long-running task like a database query that's going to take a while to aggregate some data or maybe you need to send a request to somewhere else,
- 25:50you can set up your views as coroutines that'll run in their own time and still free up the web service to handle other requests or do other operations.
- 25:59And it's really cool that way, and it's actually fairly simplified, where all you really need to do is know exactly which part of your code you want to, or which will be long-running.
- 26:08You set that up as being what's called a future object, something that's going to be running in the future, and set up the method as being a coroutine.
- 26:14Tornado will handle all the rest.
- 26:16You don't have to worry about the event loop.
- 26:17You don't have to worry about any of, well, most of the other asynchronous issues.
- 26:22It's just, it's done for you.
- 26:23Yeah.
- 26:24And so you're using SQLAlchemy here as well.
- 26:26And what gets interesting is SQLAlchemy itself is not async-enabled, coroutine-enabled, or things like that, right?
- 26:34So you have tornado-SQLAlchemy, which lets you do that, right?
- 26:38Mm-hmm.
- 26:39And the way that it does it is by setting up a context object where, so in that context, you have access to this session.
- 26:47And then whatever you would do with that session gets handed off as a task to your async event loop.
- 26:53And so you hand it off to the event loop.
- 26:56Your event loop continues to run.
- 26:58And you're not necessarily waiting for that process to finish before you handle your next request.
- 27:04It's just that when that process does finish, and the event loop is aware of that, then that response to that specific user is sent back as it needs to be sent back.
- 27:13The thing that it's not doing for you is, like, if you have some long-running computation, that's not going to be handled by a tornado.
- 27:19It's really just for input-output from some external service or from, like, clients.
- 27:25Right, exactly.
- 27:25You've got to have one of those things to make a future and wait upon it, right?
- 27:29And if that's just compute, it's just going to block up the same thread anyway, so.
- 27:32That's an interesting thing.
- 27:33Like, I was never actually trained in understanding async.
- 27:37And so...
- 27:38It's pretty mind-bending the more you dig into it.
- 27:40Yeah, it really is.
- 27:41It really is.
- 27:42It was interesting.
- 27:42And this goes back to PyCascades, where, like, I had kind of, like, dipped my toes into it with Tornado, but I was like, oh, I don't really know that much.
- 27:49I know I can decorate this method with a coroutine.
- 27:51It'll make it a coroutine.
- 27:53And then I got the privilege of being able to sit next to Guido during the speaker's dinner after the first night.
- 27:58And he talked to me for a while about, like, how async works.
- 28:03And I still didn't quite fully grasp it.
- 28:05But it was really interesting in how Python is still being a single-threaded process, but it's handing off tasks to be working in the background.
- 28:14And then I tweeted about, like, okay, I'm really going to be serious about learning about this async stuff.
- 28:19And he tweeted back at me, and he was like, hey, you want to check out this book?
- 28:22And it's been great thus far.
- 28:25I've been reading.
- 28:25I've read through it about this.
- 28:27This is one chapter in this book about twice now.
- 28:28I'd say my understanding is at about 25% level.
- 28:31That's awesome.
- 28:32What was the book you recommended?
- 28:33It was...
- 28:34Let's see if I can put...
- 28:35I don't have it on this machine.
- 28:36Do I?
- 28:36Let's see.
- 28:37I'm going to look for it.
- 28:39And if I find it, I'll send it to you.
- 28:41Yeah, we'll put it in the show notes or something like that.
- 28:43Yeah, sure.
- 28:43Absolutely.
- 28:43But it's an open source book about...
- 28:47It's very sharp.
- 28:48It's about the architecture of software.
- 28:50Oh, is it the one where they build all these different things and 500 lines of code or less?
- 28:54Yes, that's what it was.
- 28:55Is it the article of Jesse Davis and Guido's article, maybe?
- 28:59Yes, that is the exact one.
- 29:00Yeah, that's a good one.
- 29:02That is a really good one.
- 29:03A web crawler with asyncio coroutines.
- 29:06And it actually builds up what a coroutine is from ground level.
- 29:10It starts with your blocking sockets.
- 29:12And then it's still sockets, but non-blocking sockets.
- 29:15And then it goes to an actual web crawler using coroutines.
- 29:19And it's pretty awesome.
- 29:20Yeah, that's a really cool one.
- 29:21And I love the 500 lines or less aspect of it.
- 29:23That's pretty cool.
- 29:25Yeah, and for being 500 lines or less for such a complex topic, they do a really good job of explaining what async is and how it's supposed to work in the context of Python.
- 29:33Yeah, yeah, that's really cool.
- 29:34All right, so we've got these async coroutine view methods.
- 29:39Are they methods or are they classes in Tornado?
- 29:41I can't remember.
- 29:42So the views themselves are classes.
- 29:44And you connect the views to routes in Tornado's central application object.
- 29:48You can have multiple applications running at the same time, which goes back to that event loop thing.
- 29:52You can have in your one Tornado project four or five applications running at the same time, doing and handling different things if you want to.
- 30:00But the actual method that gets run depends on what kind of requests you come in.
- 30:03So you know that you have several types of HTTP requests.
- 30:06You can get, post, put, delete.
- 30:08Those are the main ones.
- 30:09There's other like hen, option, whatever, but normally you should use those.
- 30:12And then there are corresponding methods for those.
- 30:14So when an incoming get request comes in, whatever code that I've written for the get method will get run for that request.
- 30:22And the response is built from that request, from that method, and sent back to the client.
- 30:26Yeah, that sounds really cool.
- 30:27So the sort of fundamental building block in Flask is you have a decorated function.
- 30:33The fundamental building block here is I have a class.
- 30:35One URL points at it, but it can have different methods for the various HTTP verbs.
- 30:40So it's a little restful in that sense.
- 30:43It's a little restful in that sense.
- 30:44It works really well for a restful API.
- 30:46And the benefit of having it be a class is that you can set some instance attributes to only run for that one class, for that one type of request.
- 30:57You can think of them as, you know, semi-global things that only apply to that class.
- 31:01And you can have other methods in that class that work just for that class and whatever you want to do with those methods for those specific kinds of requests.
- 31:08For those methods, in this particular case, the to-do list, I add some methods to some base request handler for constructing responses, for setting default headers, for converting incoming data from post requests into Unicode, because they come in as byte code instead.
- 31:25Sorry, byte strains instead.
- 31:27That's really simple.
- 31:28It's just a method of the class.
- 31:29Yeah, that's cool.
- 31:30I find that that's a really nice design pattern, because there's probably like five or ten things like every web method wants access to.
- 31:37And if you put that in a base class and bundle it up, that's sweet.
- 31:39And that was very simple to do.
- 31:40Yeah, cool.
- 31:41And then for the SQLAlchemy, even though it's the Tornado SQLAlchemy, you still basically define it exactly the same, right?
- 31:47The declarative base and all that?
- 31:48It is almost the exact same thing as Flask.
- 31:52In fact, when I first written this project, I wrote it in Pyramid.
- 31:56And then when I was going through Tornado, I was like, oh, I can just copy and paste everything I wrote for Pyramid into Tornado and copy and paste everything I wrote for Pyramid into Flask, because it's all SQLAlchemy under the hood.
- 32:06And that's one of the things I like.
- 32:07If you have an ORM or like I use Mongo a lot, so an ODM that you really like, they kind of are portable, right?
- 32:13You learn the data part.
- 32:14It's almost like the 12-factor app idea that you were talking about.
- 32:17Like, you understand this part of your architecture independent of the framework, right?
- 32:23Like the pieces, you put them together.
- 32:25They're not like locked.
- 32:26And they're not like the one in the same, unlike, say, Django, which we'll get to in a second, right?
- 32:31Right, right.
- 32:32Yeah, that's the benefit of using things like Pyramid or Flask or Tornado.
- 32:36And they're similar in the way that there is some basic framework, but all the rest is just building.
- 32:41It's just Legos.
- 32:42Yeah.
- 32:42It's all the same stuff.
- 32:43Nice.
- 32:43So let's move on to Pyramid.
- 32:46I think Pyramid lives somewhere in between Flask and Django, maybe a little closer to the Flask world.
- 32:50But I really like their philosophy.
- 32:52They're the start small, finish big, stay finished framework.
- 32:55And they say their philosophy is it should be very quick and easy for you to learn to start with a web framework.
- 33:02But the stuff that you need as it grows more complex is just there.
- 33:06And so that's kind of a nice philosophy, I think.
- 33:09One of the things that was nice about Pyramid is that I use the cookie cutter template for building a Pyramid application where cookie cutter is a separate Python package that you download and then you point out a repository to copy over some files for you to build your application.
- 33:26There are cookie cutter templates for Flask, Tornado, and even Django.
- 33:29I didn't know how to use those as well as I knew for Pyramid.
- 33:32So I just used the one for Pyramid.
- 33:33Yeah.
- 33:33It's the official way to get started with Pyramid where the others you theoretically could use cookie cutter, but it's like there's some other sort of official starting point.
- 33:42Yeah.
- 33:42Actually.
- 33:44So it's interesting that you say that because when I first started teaching Pyramid almost two years ago, cookie cutter was not the way to do it.
- 33:51It was.
- 33:51I was using Pyramid 1.8.
- 33:53Yeah.
- 33:53It was pcreate.
- 33:53Like when you install Pyramid, it installs for you a command.
- 33:56It's actually still there in the current version of Pyramid.
- 33:58Yeah.
- 33:58If you still want to use it.
- 33:59I think it delegates to cookie.
- 34:01It just is a wrapper around the cookie cutter now, I think.
- 34:03Oh, is it?
- 34:03I haven't actually looked at it.
- 34:04I think so.
- 34:05I'm not entirely sure either.
- 34:06That makes sense.
- 34:07Okay, cool.
- 34:08But yeah, like the pcreate command would say, okay, you want to create a pyramid application.
- 34:14You want to do certain things.
- 34:15There are various templates you can use.
- 34:17The basic pyramid template says, okay, you have some main function, which is your main configuration.
- 34:22Maybe you want to hook up some views.
- 34:23Maybe you want to hook up some routes.
- 34:24Whatever.
- 34:25We got you.
- 34:26With the SQLAlchemy cookie cutter template, it says, oh, you want a database?
- 34:31Well, instead of having you write your own, because we know you don't know what you're doing,
- 34:36we're going to give you a script for initializing your database.
- 34:40Here it is.
- 34:41It's called initializeDB.
- 34:43It does exactly what you think it's supposed to do.
- 34:45Without you worrying about the actual implementation details.
- 34:48One of the things that I wish they had was an Alembic template.
- 34:52Maybe they have one now.
- 34:53I haven't checked in a few months.
- 34:54But that'd be cool, too, because one of the things that's hard to teach what I'm doing
- 34:59pyramid is, you know, you can actually, if you know how to use Alembic, you can set up
- 35:04these things called migrations, which are snapshots of your model as you change it over time.
- 35:08And that's a lot easier and better for production than just destroying it all and rebuilding it
- 35:13from scratch every single time you want to make a change.
- 35:14Yeah.
- 35:15The migrations are where that get tricky.
- 35:16And so the fact that if that were built in, that would be sweet, right?
- 35:20Yeah.
- 35:20And I'm sure that at this point in time, someone's done it.
- 35:22I just haven't looked.
- 35:24Maybe.
- 35:24I mean, one of the things that you could do for your courses is you could take one of
- 35:27these cookie cutter templates and make one that's like a little more focused on what
- 35:31you guys are trying to end up with the end goal.
- 35:34Like I have my Python for entrepreneurs course, which has just a crazy amount of different
- 35:39things brought into it, like bootstrap set up in a certain way and all sorts of templates.
- 35:43And so I actually created a cookie cutter template that is the, like, if you wanted to take what
- 35:48we built through the 20 hour course and start a new project from it, you would just run that
- 35:52new cookie cutter template and like you would start basically the end of the course.
- 35:56Yeah.
- 35:56That's awesome.
- 35:57Yeah.
- 35:58It's really fun.
- 35:58So that's a great idea.
- 35:59Yeah.
- 35:59It's really like you teaching the same thing.
- 36:01It's similar things you could like, you could help yourself by like,
- 36:04tweaking one of these and forking it.
- 36:06Yeah.
- 36:06That might be a thing that I'd do in the future.
- 36:09I have been trying, like, as I've modified the course.
- 36:12So it's worth noting that I didn't, I wasn't the one who created the course.
- 36:15The course was created by this awesome guy, Chris Ewing, great developer, great friend,
- 36:19extremely smart.
- 36:20And he created the course with Pyramid in there.
- 36:25He had done Flask before, but he decided to go with Pyramid instead as just kind of a more
- 36:29basic framework that could do a lot.
- 36:32And his idea was to not have the things that they learned be too heavily tied to just the
- 36:39course that we teach.
- 36:40Because when they get out in the real world, they need to be able to understand what's happening
- 36:44and not just fall back only onto what we taught, but be able to build up from scratch whatever
- 36:49they need to build up for whatever job they have.
- 36:52The benefit of using someone else's cookie cutter template is that someone else has done
- 36:57it.
- 36:57It's more likely to be used widely if someone's building a project and they can kind of just
- 37:03get direct, they can feed directly into that pipeline.
- 37:05But I think now that you mentioned it, I'm going to, I'm going to see if there's an Alumbic
- 37:09template out there for Pyramid.
- 37:11And if there isn't one, I might actually try to write one.
- 37:13Yeah, it'd be really cool.
- 37:14It would be useful.
- 37:15Yeah.
- 37:15I don't mean to derail you, but I do find this, these cookie cutters are really interesting
- 37:19to roll with.
- 37:19So this is how you get started in Pyramid.
- 37:21And let's say the terms of views, the default fundamental building block is very much like
- 37:27Flask, right?
- 37:27Oh yeah.
- 37:28It's just a function with a decorator.
- 37:30The difference between Pyramid and Flask is that your decorator, so your routes in Pyramid
- 37:36are separate from your views.
- 37:38They are just a listing of routes in, you can put them in a separate file, you can put them
- 37:42in your main configuration directly, and they have a name.
- 37:45So like, again, the home route, it would be called home, and then the actual pattern that's
- 37:52supposed to be matched to go to that route.
- 37:53And then your view has this view config decorator where you say, okay, here's the name of the
- 37:58route that I want you to connect to.
- 38:00Here's also the way in which I want you to render the response of this view.
- 38:04You can have, there's several options.
- 38:06One of those is JSON, so I can take my response, like if I pass a dictionary to my return value,
- 38:11then my response will just be a dictionary, and that's JSON serializable.
- 38:14Or I can make it, I can use a template like a Jinja template or a Chameleon template or any
- 38:19other template system that I want to, and just pass my response to that template, and Pyramid
- 38:24will build a response for me and send it back to the client.
- 38:25You can also go with the Tornado style and create these like handler classes that get
- 38:31one URL.
- 38:31You can, or they're called view classes, I think.
- 38:34You create handler classes.
- 38:35There's like a whole bunch of different ways.
- 38:36And I think that's one of the challenges of Pyramid.
- 38:39It's the framework I like most.
- 38:40My web apps are built in it.
- 38:42But I do feel like there's all these different ways to do the same thing.
- 38:45So I'm never like, am I doing it the best way?
- 38:48Or I'm just doing it the way that I know?
- 38:50You know what I mean?
- 38:51There's always a better way.
- 38:52It's more a matter of, my students often come to me with the question of like, is this best
- 38:57practice?
- 38:58Is what I'm doing best practice?
- 39:00And my response is always, well, best practice is oftentimes just defined by the person who's
- 39:05paying you.
- 39:06What do they want?
- 39:07It's a trade-off too, right?
- 39:09If I'm building Google, I'm making different trade-offs than if I'm building a small hotel's
- 39:15website.
- 39:16A best practice for Google is wasting money for the hotel and vice versa.
- 39:20The point there is that it always comes down to your use case, right?
- 39:23If your use case would be better served by using class-based views and having the mix-in
- 39:30pattern that Django has, then that's your best practice.
- 39:34But if your use case is better served by a function, then use the function and be okay
- 39:39with it.
- 39:39As long as the thing works.
- 39:41That's what matters more, is that the thing that you're building works.
- 39:44And then you can optimize as you need to for your specific use case.
- 39:48Yeah, for sure.
- 39:49All right, so you brought up Django.
- 39:50Let's move on to Django.
- 39:52So the summary there is it's a high-level Python web framework, and it encourages rapid development
- 39:58and pragmatic design.
- 39:59So it comes with lots of pre-built stuff, and the building blocks are kind of large.
- 40:06They're more like Duplo rather than Lego building blocks.
- 40:09I like to think of them as, right?
- 40:11Exactly.
- 40:11I would even say they're more like, if you know Power Rangers, where the robots come together
- 40:18to make one larger robot.
- 40:19There's still machinery in the individual robots, but their job is not to be inspected individually.
- 40:26Their job is to make one larger conglomerate.
- 40:30Yeah, yeah.
- 40:30One of the things that Django doesn't say in their description is that it is extremely opinionated
- 40:35about the way that things should be done.
- 40:37And so, yes, there are function-based views in Django.
- 40:40There's also class-based views in Django.
- 40:42There's the ability to talk to a database in Django, but the database you're talking to should
- 40:46probably be a SQL database.
- 40:47And the way that you build models in Django, at least through the tutorials and the documentation,
- 40:52assumes you want rows and columns.
- 40:55There are ways to incorporate a thing like Mongo into a Django application, but that takes a lot
- 41:00of extra legwork that you may not want to do.
- 41:02You're kind of fighting.
- 41:03You're going against the grain a lot of times, even though it's possible, I feel like.
- 41:07Django, it encourages rapid development as long as you want to do things the Django way.
- 41:11Which is oftentimes a good way to do things, but if you want to go outside that norm,
- 41:17you're going to have to pull apart some code to do that.
- 41:19I think Django is good.
- 41:20A lot of people use it.
- 41:22It certainly seems to be super effective for people who want to kind of get started quick
- 41:28and stuff.
- 41:29I personally lean more towards the micro framework because I want to pick that little data access
- 41:34layer and that little bit over here and just put it together, you know, but I think
- 41:38that's just my personality.
- 41:39Yeah, but if you want to start quick and build big to start, then Django is pretty much the
- 41:44way to go.
- 41:45Yeah.
- 41:46So in here, you design the models differently in a similar but different way because you
- 41:50use the Django ORM, not the SQLAlchemy style, right?
- 41:54Where the SQLAlchemy style has you inherit from this thing called the base.
- 41:56It's actually fairly similar with Django.
- 41:59When you're building a model, you inherit from Django's own base model, which handles the
- 42:04database interaction layer for you.
- 42:06And then instead of having columns or column objects, you have field objects, but it's still
- 42:10the same thing underneath.
- 42:11There are one of the benefits of using Django's fields is that there are some specific keyword
- 42:17arguments you can set for specific fields.
- 42:19One of my favorites is the auto now add that comes with the daytime field, which says, you
- 42:23know, when you create a new instance of this object, then I'm going to just set the date
- 42:27time on like for now.
- 42:28Whatever now is, that's the date time on this field.
- 42:31Yeah.
- 42:31And you could do that with SQLAlchemy, but it's easy to make mistakes on it, right?
- 42:37Like you could say, instead of saying the now function, you say now with parentheses and you
- 42:41get like every model is marked at the time that when the app started, you know, funky stuff
- 42:46like that.
- 42:47Exactly.
- 42:47One thing that's always kind of put me off on Django is the way you define URLs is like
- 42:53regular expressions.
- 42:54That's always sort of driven me crazy.
- 42:57Yeah.
- 42:57I mean, to a degree you do that in pyramid as well.
- 43:01If you want to have any variable routes.
- 43:02Right.
- 43:03If you want to, you say this can only be an integer.
- 43:05Right.
- 43:05Here.
- 43:06Right.
- 43:06You say the variable name, but if you want to constrain it, then it's a regular expression.
- 43:10Up through Django 111.
- 43:11I'm not sure if that's still the case in Django 2, actually, because they have the pattern
- 43:14now.
- 43:14They changed it.
- 43:15They changed the new pattern to make it a lot nicer.
- 43:17Up through Django 111, which is what I built the app in, is you have to have a specific
- 43:22regular expression to be matched for your pattern.
- 43:24And the way that you, like the whole pattern itself is a regular expression, not just the
- 43:29variable part.
- 43:30Whereas with Django 2 now, it's a little bit more natural, a little less nuanced for just
- 43:35regular expressions.
- 43:36You can still do the old way if you want to, but they're encouraging you to use the new pattern
- 43:40that isn't a regex unless you absolutely need it.
- 43:43Yeah.
- 43:44So instead of having like a regular expression for the integer, you know, you just say angle
- 43:50bracket int colon, you know, oh, so nice.
- 43:53Right.
- 43:54But if you want an integer that's only, you know, that must be four numbers long, then you
- 43:59want to get more and get more into doing regular expressions.
- 44:01Yeah, that's cool.
- 44:02All right.
- 44:03So you went through this whole experience.
- 44:05You went through these four frameworks.
- 44:07And to be honest, you just scratched the surface.
- 44:10There's a bunch more web frameworks like there's, there's bottle and there's webbed pie and there's
- 44:15There's cherry pie.
- 44:16There's sanding and cherry pie.
- 44:18There's hug, which is apparently a web framework.
- 44:21There's, yeah.
- 44:22Which is based on Falcon, which is another web framework.
- 44:25It's like, oh my gosh.
- 44:26So just to like, on one hand, this is just a sampling, but it is a sampling of the major
- 44:34elements of the Python web framework.
- 44:36So what are your takeaways here?
- 44:37My takeaways here for these four specifically, because I just didn't have a time to dig into
- 44:42any other ones.
- 44:42Well, and it's a talk.
- 44:43How many could, how many more could you have actually presented in like 35 minutes, right?
- 44:48Right.
- 44:48I mean, when I gave my talk, it was at 25 minutes, right?
- 44:51And even with just these four and with just a little bit of detail that I gave for each
- 44:55one, I still ran over time and I had to get cut off toward the end.
- 44:59They're shaking that red thing at you like, oh, you're over time.
- 45:01Yeah, exactly.
- 45:04But my impressions were as follows.
- 45:06For Flask, like Flask is good for small tasks or tasks that don't require a database.
- 45:12You can still do database stuff with Flask, but it becomes harder.
- 45:15So if you're going to start small and stay small and be simple, Flask is the way to go.
- 45:21It's really quick to get up and running.
- 45:23It's really simple to put together.
- 45:26And you can think more about the actual implementation of some of the logic you want to do.
- 45:30Pyramid is great if, as the slogan says, if you want to start small, but you anticipate
- 45:36getting larger, Pyramid is great for that.
- 45:38If you anticipate getting larger and you still want to know what's going on, you want to have
- 45:43a hand, you still want to have that do-it-yourself feel, Pyramid will give that to you.
- 45:48But it also can hand you some of the pieces to work with so you don't have to do too much
- 45:52thinking for yourself.
- 45:53Tornado is kind of like an in-between between Flask and Django.
- 45:58It can do Flask stuff if you want to do Flask sort of stuff.
- 46:00It can do Django sort of stuff if you want to do Django sort of stuff.
- 46:03But it's specifically good for any sort of asynchronous work you want to do or if you want to build a
- 46:08chat room, that's good for Tornado.
- 46:09If you want to have access to more of the bare networking layer of a web framework, Tornado
- 46:15is good for that as well.
- 46:16Django is if you want to build big and stay big, if you anticipate a lot of complexity
- 46:21and you don't want to think too much about the details, you want to think more about how
- 46:24it's supposed to all fit together, Django is good for that.
- 46:27All right.
- 46:27That sounds pretty good.
- 46:28What other frameworks were you thinking about or have you thought about that maybe?
- 46:33We sort of touched on them a little bit, but what else did you consider for this list?
- 46:37I was thinking, so it's interesting.
- 46:38One of the things that I only noticed after I started teaching about web dev is that we use
- 46:43a Jupyter Notebook, which is a popular data science tool for displaying your analysis,
- 46:50displaying your code.
- 46:51When you install Jupyter Notebook, let me just check if I could be installing it right
- 46:54now.
- 46:54When you install Jupyter Notebook, one of the dependencies is a web framework.
- 46:58And the web framework is Tornado.
- 47:00I think in the past it might have been Twisted, which is another asynchronous web framework.
- 47:04I didn't get a chance to look into it.
- 47:05From what I understand, it's a little twisted for writing.
- 47:09But yeah, that's another web framework that I kind of wanted to get into.
- 47:12I had seen Web2Py, but never actually used it.
- 47:15My friend Chris Ewing, he's a big proponent of Plone, which is an older web framework where
- 47:20Pyramid learned a lot from what Plone used to do.
- 47:22It's still around.
- 47:24Yeah, it's almost like the next generation of Plone, almost.
- 47:27The same people seem to work on it and stuff.
- 47:29Yeah.
- 47:29It's got some same idioms.
- 47:32When I started doing web dev, I started with WordPress.
- 47:34And this is a long way from WordPress.
- 47:36And I'm glad I didn't have to go through WordPress again.
- 47:40Yeah, that's cool.
- 47:41Those are all interesting ideas.
- 47:43I guess the other ones that kind of capture my imagination now are the async await enabled
- 47:48Python 3 ones, like API star, Sanic, Jepronto, Cort.
- 47:54They're sort of the Python 3 only ones that are pretty interesting.
- 47:58I think I might look into those then because I've kind of really had the fire lit under me
- 48:02for async.
- 48:03I feel like it doesn't need to be this esoteric thing.
- 48:06You know, it's a pattern in Python.
- 48:08It should be learnable.
- 48:10Yeah, it definitely should be learnable.
- 48:11I think, well, you know, you and I are teachers on one aspect of what we do.
- 48:16So we can work on that stuff, right?
- 48:18We can build it out for people.
- 48:19Yeah.
- 48:20Awesome.
- 48:21So I want to throw an idea out there that I just had while you're doing this that would
- 48:24be amazing that you could build for the community.
- 48:26You may be busy and not interested, but it would be amazing if there was like a website
- 48:31whose job was to have these comparisons.
- 48:35And somehow if it was like open to PRs, like somebody's like, oh, I want to submit an API
- 48:40star version of the same app to you.
- 48:43And that would be a killer community resource.
- 48:45If it like it was available for the community to write this app and sort of write an article
- 48:49for every framework that existed.
- 48:51The GitHub organization that holds all four of the web frameworks is there.
- 48:55You know, I'm perfectly happy to have PRs for that.
- 48:59Yeah, that's actually a pretty good starting point, isn't it?
- 49:01So we'll be sure to link to your repo for this in the show notes.
- 49:04Are you open for people to do PRs for you?
- 49:07To do another one?
- 49:07Sure.
- 49:08Oh, yeah.
- 49:09All right.
- 49:11So we talked about the web frameworks.
- 49:12We talked about your boot camp.
- 49:14What else have you got going on that you want to chat about that you'd like to let people
- 49:19know about?
- 49:19Yeah, absolutely.
- 49:20If you're in the Seattle area, the meetup group Puppy, Puget Sound Programming Python
- 49:23is really awesome.
- 49:24I've been lucky enough to be involved with them for the last year and a half or so.
- 49:28And they're really open to new people, to new developers.
- 49:32In the last year or so, we have a Slack channel.
- 49:35We've started the Q&A channel in the Slack team for people to just ask questions.
- 49:40We kind of have our own little Stack Overflow going in there.
- 49:42You know, and also just random stuff.
- 49:44If you have a pretty much like whatever interest you have, the organizers, Don and Alan, two of
- 49:49the people who helped put together PyCascades, they are always open to new ideas, to fresh
- 49:54ideas, to people who want to get more involved.
- 49:55So that's been cool to be a part of that.
- 49:58I've been really lucky there.
- 49:59Yeah, that's really great.
- 50:00And Puppy seems like a good organization.
- 50:02And what was surprising to me is how many people from Seattle and Portland we met in
- 50:06Vancouver.
- 50:07Yeah.
- 50:07Right?
- 50:08We left the country to meet people just down the street.
- 50:10It's time and opportunity, right?
- 50:11Like the conferences bring people together.
- 50:13But, you know, when you're at home, you have your work schedule, you have your home schedule.
- 50:16Like I have a kid.
- 50:17I can't even go out that much anymore.
- 50:18I know.
- 50:19I have three kids.
- 50:20It's like, go out at night?
- 50:21What are you talking about?
- 50:21Like it's super rare that I can go just hang out at like some tech evening event, right?
- 50:25Exactly.
- 50:26My wife's teaching or something.
- 50:27I got to be home.
- 50:27Right.
- 50:28Like if I'm going to go to Puppy, I need to know like two months in advance.
- 50:31You know, so I can, I can, I can warn my, my, my, my fiance.
- 50:35I can warn her again, two weeks later and warn her again, two weeks later after that.
- 50:38That, you know, I'm going to be going to this thing.
- 50:40We have to get a sitter or like you have to stay home.
- 50:42You know what?
- 50:43Something's got to happen.
- 50:43So we can, there's a lot of, there's a lot of logistical stuff going on in there.
- 50:47Right.
- 50:47But you go to a conference, you kind of, you've already stepped away from that.
- 50:50You've created that space.
- 50:52And so it's, it's easy to meet people, right?
- 50:54I'm here for this one specific reason.
- 50:55Just learn about Python and meet people.
- 50:57So that's, that was cool.
- 50:59And actually through Puppy, one of the things that I'm trying to do in the, in the coming
- 51:02year is to be more of a mentor.
- 51:03I've been, I've been the beneficiary of some really awesome people who have been mentors
- 51:07in the short term or the long term to give me advice every once in a while, give me some
- 51:11advice or, or help me deliver you through a process.
- 51:13And I kind of want to give that back to the community.
- 51:15And so as a teacher for the last two years, I've been able to graduate about a hundred or
- 51:20more people from the Python program.
- 51:21And I kind of want to get back in touch with those people and kind of figure out like what they're
- 51:24doing, what they're working on, where they're headed, where they're heading in their
- 51:27careers.
- 51:27Maybe if I can, if I can, even if it's not a mentorship position, more, more like a
- 51:31accountability partner, you know, help them move forward through their careers.
- 51:34I like being able to have a hand in developing talent in the same way that people help me
- 51:39develop my talent.
- 51:40It doesn't take a lot of effort on somebody who's experienced on their part to just give
- 51:44a little bit of guidance.
- 51:45Yeah.
- 51:45Because when you're new, you just look around and it's even like, it gets worse every day.
- 51:49There are more frameworks.
- 51:50There are more languages.
- 51:51There are more libraries.
- 51:52You're like, I have no idea what to do.
- 51:53I know I want to learn this stuff and I want to accomplish this, but where do I start?
- 51:57Right?
- 51:58Like, how do I go about this?
- 51:59And so you can give them some guidance.
- 52:00It goes beyond that too.
- 52:01It's like, you know, well, you know, I never thought about giving a talk at a conference.
- 52:05I never thought about giving a talk at a meetup.
- 52:07I hadn't thought about giving a talk at a meetup until my friend Chris said, Hey, you should
- 52:12give talks at meetups.
- 52:12And I was like, Oh, I can, I can do that.
- 52:14That's a thing that I can do.
- 52:15Yeah.
- 52:15There's no gatekeepers.
- 52:16You just have to decide that you can do it.
- 52:18Then you can do it.
- 52:18Exactly.
- 52:19Exactly.
- 52:19There are going to be some things that I'm aware of that people who are my former students
- 52:23are not aware of.
- 52:23Like if there's a panel going on, like, Hey, you should be on this panel.
- 52:26We should attend this panel.
- 52:27We should meet this person.
- 52:27You should go to this coffee meeting and see these people and be aware of these, of these
- 52:32concepts of these environments.
- 52:33Because, you know, have I found I've been in a lot of different spaces in the last, let's
- 52:39say like 10 years or so.
- 52:41And what I've noticed in each of those roles has been that most of the work isn't just
- 52:46being in the right place at the right time or meeting the right person at the right time.
- 52:50And if you never meet that person or if you're never in that place, you don't even know that
- 52:57those opportunities are there to be taken advantage of.
- 52:59Like I've been able to make some great contacts at Facebook just by going to a hackathon once and
- 53:05chatting up one of the organizers of the hackathon.
- 53:08Or Twitter has been an amazing resource to meet people, see what they're into, learning
- 53:14about other things going on in the field of Python development, just being aware of being
- 53:18around and being able to help new people get into that community.
- 53:22Yeah.
- 53:22I find that a lot of these little hands that you offer to people to help them actually
- 53:27come back in unexpected ways.
- 53:29And, you know, there's a lot of karma in the world in that sense.
- 53:32Oh, absolutely.
- 53:33Absolutely.
- 53:34I never would have gone to my first conference as an astronomer if my advisor never told
- 53:38me about that it existed.
- 53:39Yeah.
- 53:40And then I wouldn't have met the person who introduced me to Marcel Agueros, who runs the
- 53:44Bridge of the PhD program at Columbia.
- 53:45If I'd never gone to that, I would probably never be here in Seattle doing Python instruction
- 53:50at Code Fellows because I never would have gone for a PhD at UDEL.
- 53:54There's so many things in the chain of events that could have gone a different way if I had
- 53:58just been in the right place at the right time or talked to the right people.
- 54:00I think the big takeaway here is you can't too deeply overthink these little variations
- 54:06because your life could be so different.
- 54:08Just, you know, sort of chaos theory, right?
- 54:10Butterfly wings type of thing.
- 54:11Absolutely.
- 54:12Yeah.
- 54:12Cool.
- 54:13All right.
- 54:13Well, I think we're getting close to the end of our time together.
- 54:16Let me hit you with the two questions that I always put at the end.
- 54:19If you're going to write some Python code, what editor do you open up?
- 54:23My first instinct is Sublime Text, but I've been going more toward Visual Studio Code
- 54:27in the last week.
- 54:28Okay.
- 54:28Yeah, nice.
- 54:29Visual Studio Code with a Python plugin is quite nice.
- 54:31Oh, yeah.
- 54:32I use Visual Studio Code for like if I just want to open up one file and stuff.
- 54:35I'm doing a big project.
- 54:36I usually use PyCharm, but I definitely like Visual Studio Code as well.
- 54:41All right.
- 54:41And then notable PyPI package.
- 54:43I love the requests library.
- 54:44I also love beautiful soup.
- 54:46And then pandas, when I was a researcher, pandas changed my life.
- 54:50Like how I did research, how I did analysis.
- 54:52I was using NumPy and NumPy arrays.
- 54:53Pandas all the way.
- 54:55Oh, that's awesome.
- 54:56Yeah.
- 54:56Pandas is really, really cool and important.
- 54:58And to me, requests and beautiful soup literally feels like magic.
- 55:02Like there's this web page with stuff.
- 55:05And then I write like five lines of code.
- 55:07And then I have it like in structured data on my machine.
- 55:10I'm like, that just blew my mind that that just happened.
- 55:13Right?
- 55:13It is really cool.
- 55:14Oh, yeah.
- 55:15All right.
- 55:15So final call to action.
- 55:17People are excited.
- 55:18Maybe they're about checking out these web frameworks, your project, or maybe even your bootcamp.
- 55:22What do you say?
- 55:23If you want to talk to me, the easiest way to reach me is on Twitter.
- 55:26It's just at Enhan Walker.
- 55:27I'm on there literally all the time.
- 55:29Probably more than I should be.
- 55:30If you're interested in learning how to code, Code Fellows is a dope place.
- 55:34If you're in Seattle or in Portland, Code Fellows, great place to learn JavaScript, Java, C#, or Python.
- 55:40We have some really dedicated instructors who are really focused on getting people into careers as best as they can.
- 55:47All right.
- 55:47Awesome.
- 55:48Well, Nick, it's really been great to share the four framework comparison with you and the stories.
- 55:53Thank you so much for being on the show.
- 55:54Thanks for having me.
- 55:55I hope this was helpful to somebody.
- 55:56Yeah, I'm sure it will be.
- 55:57All right.
- 55:58Bye.
- 55:58Bye.
- 55:58This has been another episode of Talk Python To Me.
- 56:03Today's guest was Nicholas Hunt Walker, and this episode has been brought to you by Linode.
- 56:07Linode is bulletproof hosting for whatever you're building with Python.
- 56:11Get four months free at talkpython.fm/linode.
- 56:15That's L-I-N-O-D-E.
- 56:17Are you or a colleague trying to learn Python?
- 56:20Have you tried books and videos that just left you bored by covering topics point by point?
- 56:25Well, check out my online course, Python Jumpstart, by building 10 apps at talkpython.fm/course
- 56:31to experience a more engaging way to learn Python.
- 56:33And if you're looking for something a little more advanced, try my Write Pythonic code course
- 56:38at talkpython.fm/pythonic.
- 56:41Be sure to subscribe to the show.
- 56:43Open your favorite podcatcher and search for Python.
- 56:46We should be right at the top.
- 56:47You can also find the iTunes feed at /itunes, Google Play feed at /play, and direct
- 56:53RSS feed at /rss on talkpython.fm.
- 56:56This is your host, Michael Kennedy.
- 56:58Thanks so much for listening.
- 56:59I really appreciate it.
- 57:00Now get out there and write some Python code.
- 57:02I'll see you next time.
- 57:03Bye.
- 57:03Bye.
- 57:03Bye.
- 57:03Bye.
- 57:03Bye.
- 57:04Bye.
- 57:04Bye.
- 57:04Bye.
- 57:04Bye.
- 57:05Bye.
- 57:05Bye.
- 57:05Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:06Bye.
- 57:07Bye.
- 57:07Bye.
- 57:07Bye.
- 57:07Bye.
- 57:08Bye.
- 57:08Bye.
- 57:08Bye.
- 57:09Bye.
- 57:09Bye.
- 57:09Bye.
- 57:10Bye.
- 57:10Bye.
- 57:10Bye.
- 57:10Bye.
- 57:10Bye.
- 57:10Bye.
- 57:11Bye.
- 57:12Bye.
- 57:13Bye.
- 57:14Bye.
- 57:14Bye.
- 57:15Bye.
- 57:16Bye.
- 57:17Bye.
- 57:18Bye.
- 57:18Bye.
- 57:19Bye.
- 57:20you
- 57:20Thank you.
- 57:21Thank you.
- 57:23Thank you.