Building Data-Driven Web Apps with Pyramid and SQLAlchemy Transcripts
Chapter: Introducing the Pyramid framework
Lecture: Choosing a Python web framework
0:00 Now this is obviously a course on Pyramid, so we're going to choose Pyramid as our web framework for this course, but let's talk through the
0:09 various considerations and some of the trade-offs that you make with the web frameworks in Python. The best way to think about these frameworks
0:17 is as a spectrum and on one end we have what I refer to as the building block frameworks. These are things like Django.
0:26 Now what do I mean by building blocks? Well, they're really large sections of functionality you can just drop in or turn on and off.
0:35 For example, if I want an Excel-like editing experience for all of my database, all my tables in my database, with Django I can just drop that in.
0:45 I can just turn on a thing and, boom, you have Excel-like editing or maybe Google spreadsheets, more accurate because it's in the web,
0:53 but you have this sort of big things you can drop in. You want to a CMS, drop in the CMS. You want user management, you drop that in there.
0:59 It comes with a built-in data access layer. This is all a positive thing in a sense that you get these great pieces of functionality.
1:08 The drawback, and to me just personally, this is a pretty big drawback, is if you don't like the way those things work,
1:14 if you don't to follow the prescribed way of doing things that Django offers you, well, too bad. Django's going to make it much harder for you
1:24 to be different or to choose what I think of as the best of breed building blocks. Do you want to use, say MongoDB and Redis
1:35 in this unusual way, you want to create your own little management backend, things like that? Well, then you still have all the baggage of Django,
1:42 but none of the benefits because it doesn't work that way. You're fighting against the system. If you would rather work that way,
1:49 what you probably want is a microframework. We have one in our framework called Bottle out there, super, super lightweight.
1:59 It doesn't do a ton, but it basically says, "Here's HTTP request, what do you want to do with that?" That's more or less it.
2:06 Probably the most popular microframework would be Flask. Flask is very well known and used a lot. Flask is a fine framework.
2:14 Probably my second favorite of all of them. Flask is good. It's a little more common to use Flask to create web services than it is
2:23 to create web applications, so HTTP services rather than a bunch of pages, but of course Flask is used for that as well.
2:33 I'd say Flask offers a little more functionality than Bottle and then we have Pyramid, which has a little bit more support
2:40 for building full-on web applications than say Flask comes with, in my opinion. There's some benefits. There's some drawbacks.
2:48 Some of the benefits of Pyramid include, it has better Python 3 support, it has better template support, it's faster, couple of other things.
2:57 We'll maybe talk about those. It really comes down to the trade-off of do you want a microframework or do you want one of these big building block
3:04 frameworks like Django, then the difference between, say, Flask and Pyramid is actually much, much smaller.
3:10 What you learn in one is largely applicable to the other. We're going to see that Pyramid being a microframework
3:16 will allow us to use something like SQLAlchemy and then if we decide, no actually we'd rather switch to MongoDB, no problem.
3:23 That's a super, super minor change and everything else will just keep working. That's the really nice stuff of a microframework,
3:30 real nice features of a microframework is that it let's you pick the various pieces and put them together just the way you want,
3:37 not the way the framework wants you to or the few choices that framework has made for you.