#379: 17 Libraries You Should Be Using in Django Transcript
00:00 Do you write web apps in Django?
00:01 The framework has come a long way lately, with versions 3 and 4 adopting many of the modern Python capabilities.
00:08 Async, for example.
00:09 But there are so many other libraries and apps that you can use to do more with less code and plug in new functionality.
00:16 I'm happy to have Christopher Trudeau here on Talk Python to take us through his 17 favorite libraries you should be using in Django.
00:24 This is Talk Python to me, episode 379, recorded August 22nd, 2022.
00:30 Welcome to Talk Python to me, a weekly podcast on Python.
00:46 This is your host, Michael Kennedy.
00:48 Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past episodes at talkpython.fm.
00:54 And follow the show on Twitter via at Talk Python.
00:57 We've started streaming most of our episodes live on YouTube.
01:01 Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
01:09 This episode of Talk Python to me is brought to you by the IRL podcast, an original podcast from Mozilla.
01:15 This season, they're looking at AI in real life.
01:18 Listen to an episode at talkpython.fm/IRL.
01:22 And it's brought to you by Microsoft for Startups Founders Hub.
01:25 Get early stage support for your company and build that startup you've been dreaming about.
01:29 Visit talkpython.fm/foundershub to apply for free.
01:34 Transcripts for this and all of our episodes are brought to you by Assembly AI.
01:38 Do you need a great automatic speech to text API?
01:40 Get human level accuracy in just a few lines of code.
01:43 Visit talkpython.fm/assemblyai.
01:47 Hey all, a quick announcement before we jump into the interview.
01:50 Some of the ideas we discuss in this episode come from a brand new Django course that Chris authored over at Talk Python Training.
01:57 If you enjoy this episode and want to put these ideas into practice or you want to just get started with Django,
02:02 be sure to check out his course at talkpython.fm/Django.
02:06 Now let's dive in.
02:07 Chris, welcome to Talk Python to me.
02:11 Thanks for having me.
02:12 Yeah, it's great to have you here on the show.
02:13 You know, we've worked on some projects together and talked otherwise, but your first time here on Talk Python.
02:19 Monumental.
02:19 Indeed, indeed.
02:21 So I'm super excited to talk about Django.
02:23 I don't do that much Django, which is why you're here because you do a ton of stuff with Django.
02:28 So really excited to have you share your experience.
02:31 And we're going to focus on a bunch of cool little tools and apps that you can plug into Django and make it better,
02:36 make it do more and do a lot of the Django things, you know, pull a few pieces together and make your app better without a lot of coding, right?
02:42 That's the idea.
02:43 Indeed.
02:43 Before we get to all that, though, let's just start with your background.
02:46 How do you get into programming in Python?
02:48 I'm an old man, not punch card old, but single digit megahertz old.
02:53 My dad worked for IBM.
02:55 So my first computer was an IBM PC Junior.
02:58 256 kilobytes of memory with the expansion card.
03:02 No hard drive, five and a quarter floppy and 4.77 megahertz.
03:08 And that second seven is really, really important.
03:10 It made all the difference.
03:11 Did it have a turbo button?
03:12 It did not.
03:14 IBM did not do that little bit of marketing stuff.
03:18 But I'm pretty sure my USB charger has more processing power now.
03:22 But all my friends had Commodores.
03:24 And so I couldn't trade pirated games with them because that's what everyone did.
03:28 And the box came with this kid friendly teach yourself basic book.
03:33 And so that was kind of my intro.
03:35 There was I had one game and nothing else to do with the computer.
03:38 And the first program I remember writing was a Batman logo, not copying it from a book, like on my own kind of thing.
03:46 And so like the basic library had like draw arc and fill in yellow and it kind of clicked for me.
03:51 And 30 years later, I was running a software department at a company that got acquired by a large firm who shall remain nameless.
04:00 They just own all of your favorite movie franchises and have a rodent fronting it.
04:04 I think you know who I'm talking about.
04:05 And as part of that acquisition, the department got shut down, but we were asked to stick around to help with the transition.
04:10 We had about two weeks worth of work to do and we had six months to do it in.
04:14 So I had a fair amount of spare time on my hands and I used that to pick up Python.
04:18 And the first script I wrote in Python was that we had a photo sharing site and the due diligence of the transfer included looking for questionable content in that photo sharing site.
04:31 And I had to, for the police investigation, go off and grab a whole bunch of stuff out of S3 and download it that belonged to this one individual.
04:39 So the script was kind of icky, but I was very, very impressed on how little code I had to write in comparison to previous languages.
04:46 Part of that's Python itself and part of it was just, you know, pip install, pip install, pip install, and it solved all these problems.
04:52 And I've never looked back.
04:55 It's been my primary language for almost 15 years now.
04:58 What a good language.
04:58 What a good choice.
04:59 Who knew 15 years ago or 10 years ago or whenever we all got into it that it would be so incredibly popular these days, right?
05:07 Yeah, it's grown a lot.
05:08 It's, yeah, it's really taken off.
05:10 Yeah, I just saw an article.
05:11 What was it called?
05:13 The Unstoppable Programming Language or something like that from InfoWorld.
05:19 And boy, it, I'll even pull it up.
05:21 What an interesting situation where, you know, the subtitle of the article is Unstoppable Python.
05:28 Once again, ranked number one in the TOV index.
05:31 I think it's the breadth of the libraries, right?
05:33 Like most of the languages, there's, you know, JavaScript is often at the top of that list, but it's only really for one purpose.
05:39 It's for building web applications.
05:41 And I know you can do other things in it and not trying to upset the internet.
05:44 But with the data science behind.
05:47 You're going to get us email, Chris.
05:48 Oh, yeah, I'm sure.
05:49 Well, you'll get them email.
05:50 I'll be long gone.
05:51 So that's fine.
05:52 With the data science side, with the ML side, with the, you can do things on the web side, right?
05:58 Like there's being number two in all of these areas very easily makes you want number one overall, right?
06:04 So it's, I think it's the breadth more than anything.
06:07 Yeah.
06:07 You talked about how the company around was acquired and you had all this sort of time to kind of think about changes.
06:14 I find times like that are really interesting ways to maybe refocus your career or to think about where you've been and where you might be going.
06:23 Maybe whether you should turn left or right or just keep going the way you are.
06:27 You know, I've had a few like that.
06:28 And it's, those are some good opportunities to take if you can get them.
06:31 Yeah, it gives you a chance to experiment if nothing else.
06:34 You know, there was no pressure to pick up a language.
06:36 I was a manager at the time.
06:37 So there was no pressure at all, period.
06:39 But yeah, it gives you the breathing room to go and play with a few things and get comfortable with it.
06:45 And the next job I took was helping a small startup.
06:48 And a manager comes to me and says, oh, pick the language, pick the stack.
06:53 And I was like, okay, we'll do Python.
06:55 We'll do Django.
06:55 Then it sort of went from there.
06:57 So good choice.
06:58 How about now?
06:58 What are you doing these days?
06:59 My marketing people tells me, tell me I'm supposed to call myself a fractional CTO.
07:03 So I help organizations with technical decisions and software processes.
07:08 So that's architecture, some coding.
07:10 Often it means nowadays the agile process stuff.
07:13 So it's a bit of a mixed bag.
07:14 I tend to specialize in trying to get small teams more efficient in some tech way, either the process or the learning itself.
07:22 And because of the agile thing, I've done a fair amount of teaching.
07:25 Because oftentimes when you're bootstrapping new teams, you got to start out with Scrum 101 and all that kind of good stuff.
07:30 And that kind of led into the screencasting and online teaching world.
07:34 So now I've done over 30 courses in Python and I'm still clicking along.
07:38 So it's become this sort of side thing that I have that has blown up into its own thing.
07:45 I can relate.
07:46 I can definitely.
07:47 It's awesome.
07:49 Well, cool.
07:50 So part of that actually is you and I just recently worked on a course for Talk Python training, Django, getting started.
07:57 Which there's been, you know, it's a six hour course.
08:00 People can check it out.
08:01 There's a bunch of good stuff.
08:02 We're not going to really talk about that.
08:04 But it kind of got me thinking like, hey, wouldn't it be great to just cover all the cool little things that you touch on here and then just, you know, in your other training.
08:14 I guess people probably could reach out to you if they've got a team and they want to maybe help them shift gears, help them change technologies or change the way they're working.
08:22 Sure.
08:23 Always nice to have the pipeline full.
08:25 So for sure.
08:26 Indeed.
08:26 Yeah.
08:27 So, you know, you always, you might be brought in to do one thing like, hey, help us do Django or help us change the way we're working with sort of deploying our apps or whatever.
08:36 But then there's like, oh, but did you know about this tool?
08:38 And have you tried this?
08:39 And wouldn't it be easier if you use that?
08:40 And so how about we make that the next hour?
08:42 Yeah.
08:43 You know, and this kind of ties back to that.
08:46 You know, we were sort of talking about Python and the breadth of that, right?
08:48 One of the reasons it's so easy to get a lot of things going is because there are so many libraries that have been there and done that.
08:56 And I often, we're going to talk about later, you know, one of the ones that's sort of a catch all.
09:01 And every time I'm in there, I'm like, oh, oh, wait, I need to remember that's in here because I keep writing that code.
09:06 Right.
09:06 And so knowing that things are out there and finding this stuff can make a big difference in how little code you have to write.
09:13 And it's always great when someone else has tested it, because then not only are you not having to write it yourself, but it's probably more stable than the stuff that you're writing yourself.
09:21 Or at least I'll speak for myself.
09:22 It's more stable than my code.
09:23 For sure.
09:24 Well, I think, you know, people who are getting into programming think about what is an expert.
09:28 An expert is somebody who could write these crazy algorithms or implement this wild file processing stuff from scratch.
09:36 And that somewhat is true.
09:38 But more often, the expert is the person that knows they can pip install this other thing and not have to write that.
09:43 You know, they're like, oh, these libraries exist.
09:45 I know they'll work in this situation.
09:47 I don't need to do this.
09:48 Right.
09:48 So, yeah.
09:50 It's both a power, but it's also really like knowing Python.
09:52 I think knowing Python is partly knowing the libraries outside just the language.
09:57 I would say more than partly like picking up a new language is if you've done a few before and it's in the same vein, although, you know, all the grandchildren of C based languages.
10:07 It's like, OK, so how do they what's variable assignment look like?
10:10 What does four loops look like?
10:12 Once you've done that, you know, a few days later, you're ready to go.
10:15 Knowing the depth of what's out there so that you don't have to write it, that takes forever.
10:20 Right.
10:20 So, you know, there's language expertise within months.
10:23 There's library expertise, which is years and is constantly changing.
10:28 It's nonstop.
10:29 It's like you can't learn them as quickly as they come out, really, especially if you're in JavaScript.
10:33 That's another story.
10:34 Yeah, I saw a funny T-shirt that said I learned Python.
10:37 It was a great weekend.
10:38 And that's in some sense true.
10:40 Right.
10:41 But on the other, you'll compare and contrast that to like, I feel like I've been doing this forever.
10:45 And I'm still learning every single day.
10:47 How do you square those two things?
10:49 Right.
10:49 It's a lot largely what you just said.
10:51 Yeah.
10:51 All right.
10:52 So we're going to talk about a bunch of different topics.
10:55 We'll see what the final number is.
10:56 17 ish different libraries, some of them directly pluggable into Django for specific things,
11:03 and some of them just really helpful for Django.
11:05 So you want to kick us off with the first one here?
11:07 So there's sort of two groups in the first group of things that we're going to talk about are libraries that any project of a reasonable size should consider using.
11:15 So these are like you said, these aren't the Django specific stuff.
11:17 And then we'll get through a few of those and then we'll get into the actual this you should use this for Django.
11:22 So this first one that you've got up on the screen there, this is coverage.
11:26 This measures how much of your code gets run when you run your code.
11:31 So it's typically used for your user tests.
11:34 And what you're trying to figure out is how many how much of your code has been exercised when you run your tests.
11:40 So it has sub commands, one of which is run, and you basically hand it any script and it will give you a output listing of what it saw as it went along.
11:51 That output listing is like a file by file listing and shows you like a percentage mark that says, oh, you know, 30% or 50% or whatever of this file got executed in your run.
12:00 And then there's a couple other commands that you can run that will combine all this information into a report.
12:06 And the report is spit out in HTML and that gives you a fully annotated list of your code.
12:12 So you can go in and see, oh, there's the red line.
12:14 That's a line that didn't get triggered.
12:16 So often I find when I'm writing tests, it's usually fairly easy to get the, you know, the easy path through, right?
12:23 You're not thinking about the errors or whatever.
12:25 You just sort of, oh, I exercised it.
12:26 And then you go, oh, I've only got 75%.
12:28 Well, finding if you want that, you want to have something higher than that.
12:32 You go in, you look at the report and you go, oh, that red line is that error condition.
12:36 Okay, I need to add a test to make sure that that error condition is handled properly.
12:39 So I often take this one and then write a little bash script that does this, runs my tests and then runs a linter afterwards.
12:47 So it's my little check-in hook, right?
12:49 So just before I do a push, it'll go off and run all my tests and give me coverage.
12:53 And if I don't like the numbers, then I go off and fix it some more.
12:56 I think when you're learning about testing, it's important to test the happy path, but that's the one that often kind of obvious, right?
13:04 You're going to know right away if that thing is broken.
13:06 But it's those edge cases.
13:07 What if I put a string into this input where, you know, a number like the word seven versus the number seven?
13:14 Is that a 500 server error or is that a, sorry, invalid data, ideally even caught on the client side with HTML5 validation or something?
13:23 Those kinds of things are really hard to think about.
13:25 And coverage really points out, you know what?
13:28 All the parts that are read that are uncovered, those are the error handling or the guarding clauses or the other cases where you're not normally going to run into them.
13:37 So you really need to have a test to check them.
13:39 Yeah, that's right.
13:40 I'm also independent of coverage.
13:42 I'm also a big fan of when bugs show up.
13:44 I'm not a pure TDD guy until bugs show up.
13:47 So when the bug shows up, I go and write the test that triggers the bug and then I fix it because then I'm adding to my regression test as well.
13:55 Right.
13:55 So that's also to your point, it's those weird conditions that you didn't even think of.
13:59 And coverage, because it is only line based, you can get into trouble where, you know, the first part of an if clause passes and the second part doesn't.
14:08 And so it's green.
14:09 It looks like it's happy, but that doesn't mean you don't have a bug.
14:12 Right.
14:12 So there's always this mix and go.
14:14 But coverage can help you find this stuff first time through if you're looking.
14:18 I'm definitely not a purist, TDD purist myself either.
14:21 I find there's tests add a lot of value, but there's also a practical, I just got to get some stuff done and I don't need to like retest everything.
14:28 It'll only so many hours in the day.
14:30 Yes, exactly.
14:31 But I do like this idea of like once you found a bug, if you can reproduce it with a test, you kind of pin it down so you don't play whack-a-mole and have it ever come back.
14:39 Exactly.
14:40 Yeah.
14:40 Kind of related to this whole part of the conversation, Anthony in the audience asks, he's interested to know how best to test Django web apps with pytest.
14:49 Feels that there ought to be ready-made recipes for this, given how opinionated Django is.
14:54 You got any thoughts on that?
14:55 I don't actually use pytest myself, so I'm only vaguely familiar with it.
14:59 There are some recipes out there.
15:00 I know there are Django apps that you can install that will help you and pre-canned with the recipes.
15:06 Django is fairly robust itself.
15:10 It builds a whole bunch of things on top of the unit test framework that is very Django specific.
15:15 And it allows you to shortcut the web as well.
15:19 So you can access the views directly, which means you don't have to worry about like a lot of JavaScript and things like that.
15:25 And it also has a live server mode, which I was playing with this afternoon, actually, which runs a server so that you can run things like Selenium on top of it.
15:33 So there's a fairly rich set of mechanisms in there for Django to begin with.
15:38 From what I understand of the pytest library, it really just sort of makes some of those hooks easier and exposes them rather than introducing a lot of extra functionality.
15:47 For sure.
15:47 Wouldn't you know that there's an awesome Django list?
15:50 And it happens to be done by Will Vincent.
15:52 In here, there's a whole section on testing.
15:55 And you've got some pytest Django.
15:59 You've got Factory Boy for test fixture replacements.
16:01 A feature flipper Django waffle.
16:04 That's kind of an interesting name.
16:06 Model Bakery for creating, I'm guessing, the ORM models in interesting ways.
16:12 And yeah, people can check this out.
16:13 Another related question, Nick asks, I like to hear opinions on mocking the ORM database when testing versus actually using the database.
16:20 I don't know how you feel about this, Chris.
16:22 I don't tend to mock unless I absolutely have to.
16:25 I usually mock for things like, oh, we have to do something with dates.
16:29 And dates and times always cause problems because, you know, you're running the test now.
16:34 For the ORM, I tend to just use tests straight into the ORM.
16:38 Django comes with a lot of mechanisms like fixtures that allow you to push things into the database.
16:43 And the test suite automatically will install those fixtures and wraps each test in transactions.
16:49 So it does it and then undoes what you did.
16:52 So you're always in a known good state at the beginning of each one of your functions.
16:56 So I haven't really come across a case where I really need to mock out the ORM.
17:00 I would guess there's probably a argument about speed there.
17:05 But I tend to get around that with things like tagging my tests.
17:09 So I will tag much that are like the smoke test, the quick one pass through.
17:13 And if I need like a really fast test to run on, say, check in, then use a smoke tag and then let the regression run overnight if I have to or whatever.
17:22 So I haven't come across the need for mocking it out yet myself.
17:25 Yeah.
17:26 And you can use SQLite with an in-memory database model as well.
17:30 And just as start of the whole test run, you could fill that in-memory version up with known good test data.
17:36 The transactions will kind of roll it back each time, right?
17:38 And so just let it rip on SQLite in memory and then disappear into the ether of RAM.
17:44 Yeah.
17:44 It tends to be, unless you're doing huge amounts of work, it tends to be pretty peppy.
17:49 Sure.
17:50 Yeah.
17:50 And you can choose how much data you put in it, right?
17:52 So you can chill out on that.
17:56 This episode of Talk Python to Me is brought to you by the IRL podcast, an original podcast from Mozilla.
18:02 If you're like me, you care about the ideas behind technology, not just the tech itself.
18:07 We know that tech has an enormous influence on society.
18:11 Many of these effects are hugely beneficial.
18:14 Just think about how much information we carry with us every day through our cell phones.
18:19 Other tech influences can be more negative.
18:22 I really appreciate that Mozilla is always on the lookout for and working to mitigate negative influences of tech for all of us.
18:30 If those kinds of ideas resonate with you, you should definitely check out the IRL podcast.
18:35 It's hosted by Bridget Todd, and this season of IRL looks at AI in real life.
18:40 Who can AI help?
18:41 Who can it harm?
18:42 The show features fascinating conversations with people who are working to build a more trustworthy AI.
18:49 For example, there's an episode on how the world is mapped with AI, but it's the data that's missing from those maps that tells as much of the story as the data that's there.
18:59 Another episode is about gig workers who depend on apps for their livelihood.
19:03 It looks at how they're pushing back against algorithms that control how much they get paid,
19:08 and how they're seeking new ways to gain power over data and create better working conditions for all of them.
19:14 And for you political junkies, there's even an episode about the role that AI plays when it comes to the spread of disinformation around elections.
19:21 Obviously, a huge concern for democracies around the world.
19:25 I just listened to The Tech That We Won't Build, which explores when developers and data scientists should consider saying no to projects that can be harmful to society,
19:34 even though we do have the tech to build them.
19:37 The next thing kind of related to that is PyFlakes.
20:05 I mentioned at the end of that that I often use a linter.
20:07 This is the one that I tend to go to.
20:09 PyFlakes is code-focused rather than style-focused.
20:13 So when I first started linting Python, a lot of the code I was maintaining was not PEP8 compliant,
20:19 and we'd run the linters and they were just constantly screaming about everything.
20:23 PyFlakes was like a nice little happy medium for us.
20:27 It runs using the abstract syntax trees, which means it doesn't actually load the modules, which is good because that means you're not having to do the side effects of your actual code.
20:35 And I usually use it for things like finding unused imports and weird variables and things like that.
20:41 The other place is I find if I've made a lot of changes across a whole bunch of files, running PyFlakes before I run my tests, it's sort of a bit of an idiot check, right?
20:50 So the things that don't compile or whatever, it'll go through and run everything once for you.
20:53 And it seems I find it faster to do that than, say, run all my tests first.
20:58 Sure.
20:58 This is kind of like a compiler, you know, and compiled languages, C++, C Sharp, Swift, whatever.
21:05 You press compile and there's a how does it all hang together sort of check that the system has to go through as a static language.
21:11 And we don't have that.
21:12 Even if you put type hints, that's a hint, not a requirement for accuracy.
21:16 And so not saying that this does, you know, type validation like mypy, but it makes sure that your code at least somewhat hangs together, right?
21:24 It's a nice, nice quick check.
21:25 Yeah, it's a sanity checking.
21:27 Yeah, absolutely.
21:28 And there's a version of this, if you want to dig down into it, that is called Flake 8 that combines PyFlakes with PEP 8.
21:35 So if you want to get all anal retentive about the code cleaning and all the rest of that, you can dig into that.
21:41 And essentially, it's just called the same kind of commands after it.
21:44 Also has a nice little, one of the things I always look for in a linter is the pragma that says ignore this line so that you can turn off the noise.
21:52 Because every once in a while, there's going to be something that you want it to ignore.
21:56 And I find as soon as you've got warnings popping up in your code, it starts to become broken window theory, right?
22:02 Like, oh, there's a warning there.
22:03 Oh, now there's two warnings there.
22:05 Now there's three warnings there.
22:06 And the next thing you know, you've got 100 warnings and nobody's doing anything about them.
22:09 So I like to try.
22:10 That's exactly the analogy I was thinking as well.
22:13 And that's the way it is.
22:14 Because especially in a team situation, you know, there's some people who are really bought into like CI and that kind of stuff.
22:22 There's other people who are not really that interested and worried whether the test still passed or worried about whether the linters pass.
22:29 And they're just going to go along.
22:30 But certainly if that kind of stuff starts showing up, they're like, well, if it's already got warnings, I don't care about one more, you know?
22:37 Yeah.
22:37 So the zero warnings policy is pretty good.
22:39 And this kind of thing helps you find that and check it easily.
22:42 Right. So for people who are listening, you just put hash for comment, Blake 8 colon no QA on a line and then it'll skip that line.
22:50 You know, there's times when you get advice that in general is good advice, like try accept past or something like that.
22:58 You should never do that.
22:59 Except for sometimes in little weird situations, you're like, no, I really just need this to not care if there's an error and just keep going.
23:06 And we're just, you know, stuff and you'll you'll be stuck with this permanent warning.
23:10 This file has an error.
23:11 You're catching too broad of an exception.
23:13 Like in general, yes.
23:14 But right now I don't care.
23:16 I accept that.
23:17 Let's just keep going together.
23:18 Yeah.
23:18 And this kind of stuff really is great for making those warnings go away.
23:22 And you can tie it into your PR process as well.
23:24 So if I'm doing a poll review for something you've done where you've put this, we can have a policy that says there better be a comment above it that explains why you're allowed to ignore it in this session.
23:34 So it becomes sort of two kinds of flag.
23:37 It's a flag for pie flakes.
23:38 And it's also a flag flag for your code reviewer to go, oh, we should explain why, you know, is this a valid case?
23:44 Oh, yes, we do.
23:45 This is this is the generic.
23:46 So let's put a comment that says, yes, we meant to do this rather than I was just too lazy to fix it.
23:51 Yeah, that's a really good point.
23:52 Actually, I like that a lot.
23:53 All right.
23:53 On to another Sphinx, the Python documentation generator.
23:58 Yeah.
23:58 So this is a sort of bit of a left turn here.
24:01 I will admit I am obsessive compulsive when it comes to comments and documentation.
24:06 I did co-op in university, which is what I think they call paid internships in the US.
24:10 And my third co-op term was with the same department as my second.
24:15 And the first day back into the office, I said hello to everyone.
24:18 And then my boss says, yeah, there's a bug in the code you wrote last term.
24:21 Go fix it.
24:22 And if my name had not been at the top of the commit, I would have sworn this was written by somebody else.
24:27 The code was just hideous.
24:28 And this is where I learned the whole comments are for other people is only half right.
24:32 Sometimes you're that other person like eight months later.
24:35 Just shifted in time.
24:37 Yeah.
24:37 Yeah.
24:37 So I've become very, very, very retentive about it.
24:41 And so what Sphinx is, is a mechanism for taking your PyDoc comments and turning it into documentation.
24:49 And so if you were writing your comments already, it gives you a couple little formatting tags that you should take advantage of.
24:55 But once you've done that, it's a lot of effort.
25:03 So I've got a lot of effort to take advantage of the code.
25:10 And so I've got a lot of effort to take advantage of the code.
25:12 And so I've got a lot of effort to take advantage of the code.
25:13 And so I've got a lot of effort to take advantage of the code.
25:15 And so I've got a lot of effort to take advantage of the code.
25:17 But one of the things I find I use a lot is you can highlight references to other parts of your code.
25:25 So if I've got a class that I'm using here, an object that is some sort of class, if I note it properly in the comment, when the documentation is created, I can click a link and it'll take me through to it.
25:37 So you can always find the cross references.
25:39 Yeah, that's fantastic.
25:40 Generates all sorts of different kinds of output.
25:43 I personally only ever use the HTML, but it does EPUB, ManPages, LaTeX, if you want to spit out some PDF and some other things as well.
25:50 Comes with a sort of a quick start command that builds all your cookie cutter files for what you need.
25:56 It also allows you to intermix in general RST files.
26:01 So if you want to write, say, a how-to guide separate from your code, but then suck in some documentation from your code, it allows you to mix and match that.
26:09 So as an example.
26:10 Tutorial or installing or something like that.
26:13 Yeah, so I often will write, although Markdown is the most common format for the readme file on GitHub, I use readme.rst.
26:20 And the reason I do that is because I usually use that same readme file as the intro file in my Sphinx doc.
26:28 So I essentially just say, oh, go grab that readme.rst, pull it in here as the title page, add a little table of contents flag on the bottom of it.
26:37 And the next thing you know, you've got some documentation.
26:39 Yeah, that's really fantastic.
26:41 It's great when you can get your work to multiply automatically.
26:45 And obviously, you know, you've got to have been in the habit of doing this kind of stuff anyways.
26:50 But if you were, adding a little bit of rigor to how you're writing the comments helps a lot.
26:55 And I find particularly with things like APIs, right?
26:59 Because you should be writing that doc string anyways that says this is what the call is.
27:02 These are the parameters and what they mean.
27:04 And it turns all that into a PDF document that you can, you know, hand off to managers or whatever, put up on your web page or however you like to do that.
27:12 Yeah.
27:12 For those who are not a fan of restructured text, there's the MIST markdown version or plugin.
27:20 So you can do markdown as well these days.
27:23 I have to check that out.
27:23 I haven't played with that one yet.
27:24 Yeah, yeah.
27:25 It's pretty neat.
27:25 You can even do inline restructured text within your markdown.
27:29 So you're like, markdown, markdown.
27:30 Oh, I need something a little bit more complicated.
27:32 There's a way.
27:33 I don't remember what the syntax is, but there's a way to, you know, inline a little restructured text.
27:38 Excellent.
27:38 And then fall back to markdown.
27:39 Yeah.
27:40 A little bit of an escape hatch.
27:41 And then embed your HTML inside of your restructured text inside of your markdown.
27:46 It's turtles all the way down.
27:47 Excellent.
27:48 Absolutely.
27:48 The other thing, there are companion plugins for this as well.
27:52 So one of the other libraries that I use is something called a Sphinx RTD theme, which is a read the docs style theme and plugs right in.
28:00 And essentially, it allows you to generate your HTML looking like the read the docs site.
28:06 And if you combine that with a git hook into read the docs, your read the docs will get automatically updated every single time you do your push up to git.
28:13 So nice little combination there.
28:15 Yeah, that's very cool.
28:16 I do find it sort of meta that the Sphinx read the docs theme is hosted on read the docs.
28:21 Yes.
28:22 So fun.
28:25 All right.
28:26 PUDB.
28:28 Is that the right?
28:29 I have no idea how you're supposed to pronounce it.
28:31 I always say PUDB, but that's fine.
28:33 PUDB.
28:34 Well, I do feel like a lot of these projects like this one, if you have too much of an acronym or you have too clever of a name, you really should put a, and here's the MP3 of how you say it.
28:43 Hey, there you go.
28:44 Yes.
28:44 The little, I loved that answer with Linux.
28:47 It was, hi, my name is Linus and this is how you spell Linux.
28:50 And I couldn't understand his accent.
28:51 It didn't clear anything up.
28:52 It was fantastic.
28:53 That's funny.
28:54 I think I've mentioned up front that I'm old.
28:57 So a lot of my early career was spent on Unix systems, SunSpark systems, that kind of stuff.
29:02 And at the time there was this whole war between VI and Emacs.
29:06 The war is over.
29:07 I think VS Code won.
29:09 But I picked VI because it was the only thing guaranteed to be installed on any of the systems I was telnetting into.
29:14 And so I'm still very old school using Vim to this day.
29:18 Yeah.
29:19 I mean, you just said the word telnet.
29:20 Come on.
29:20 I'm keeping it.
29:21 It was telnetting.
29:23 It was pre-SSH.
29:24 I know.
29:24 Yeah.
29:24 Now, hold on now.
29:25 Did you do like Archie and Gopher before telnet?
29:28 A little bit of Gopher.
29:29 I'd never, I was never on an Archie system.
29:32 I did a little bit of Gopher.
29:33 Yeah.
29:33 So.
29:34 It could even go more old school than that, but yeah.
29:36 Okay.
29:36 Yeah.
29:36 Great.
29:36 So maybe these days you're SSH'd in, but same basic idea, right?
29:40 Same basic idea.
29:40 So why am I babbling about this?
29:43 Well, what this means is because I use an editor rather than an IDE.
29:46 And of course there's another place where you'll get letters because you can do everything in Vim
29:49 script.
29:50 So it's an IDE as well, but I tend to just use it as a letter editor.
29:53 What that means is I tend to use a standalone debugger.
29:57 So PUDB is one of those.
29:59 It's a standalone debugger.
30:00 I'm not sure why, but I've never been a big fan of PDB.
30:04 The one that comes with Python.
30:06 Part of that is because it's based on GDB, which I never liked either.
30:09 I just need to see more screen, more code on my screen at a time.
30:14 And so this is a TUI program, which is text user interface.
30:18 And it's for, and if you want to, again, shout out to the old folks in the audience, it's
30:23 got a very Borland turbo feel to it.
30:25 So you can see the screen and the text that you're working on.
30:28 And then there's a couple little side windows with your stack and your variables and set
30:32 breakpoints, all the things you expect a debugger to do.
30:35 And if you're stopped at a breakpoint, you can open up a REPL and it gives you full context
30:39 of where you are, just like you would with inside of PDB.
30:41 So I find oftentimes I'm doing more debugging in the REPL in context than I am actually in
30:46 the debugger.
30:47 Now, why this is a big deal for me is let alone the local.
30:52 If I were using PyCharm or whatever, I can work locally.
30:54 This will work anywhere where I can SSH into.
30:58 So because it runs over the terminal, I can get into a machine.
31:02 I can use this and have it work.
31:03 And it means I'm using consistent environment across all the places I go.
31:07 So I don't try to sell this to other people.
31:09 When I manage teams, I don't say you will use this, but it tends to be my go-to.
31:14 And I like to tell people that it's out there because you never know when you have to do that
31:19 remote stuff.
31:20 Yeah.
31:20 A lot of times, you know, like it works on my machine and you get the certification even
31:25 there.
31:25 It works on my machine.
31:26 And then I go to the server and it doesn't work.
31:29 And I can't really figure out why, you know, especially when you're setting up a new environment,
31:34 you're like, ah, trying to run the web app now and micro WSGI over here and it just won't
31:39 start or something like that.
31:40 Right.
31:40 So the ability to get a little more insight over SSH is pretty cool.
31:44 Yep.
31:44 Good.
31:45 All right.
31:45 Is this, I think this may be our last sort of, nope, second to last general, general library
31:52 is talks.
31:52 Yep.
31:52 So this is a wrapper for all your tests.
31:56 So it essentially builds virtual environments based on a quick little configuration file.
32:01 So give you an example.
32:03 Let's say I've got a line that says pi brace three, seven, three, eight, three, nine, three,
32:08 10 dash Django 400.
32:11 It knows how to split that apart and we'll do all the combinations of running Python three,
32:16 seven with 400, three, eight with 400 and et cetera, et cetera, et cetera.
32:19 And it creates a little virtual environment for each one of those combinations and then runs
32:24 all of your unit tests inside of that virtual environment.
32:27 So if you're doing library support across multiple Python versions or across multiple, say,
32:32 Django versions, then you can mix and match these with just a few lines inside of a configuration
32:37 file and it will go off and run all of this.
32:39 And those virtual environments are created locally and cached.
32:43 So although the first time it runs, it's dreadfully slow because it has to pip install all of your
32:48 requirements in each one of those environments.
32:50 Once that's set up, it just leaves them there, which means, you know, first time hurts.
32:55 And after that, it's not too bad.
32:56 It's one of those trade-offs between I want an absolutely clean from scratch reproducible thing.
33:02 Yes.
33:03 Also, when I get my job done.
33:04 So if you're going to test across five different versions of Python, maybe don't try to pip install
33:09 something like micro whiskey or other things that have to compile for a great long while.
33:15 Just, just leave it there.
33:17 Because it does compile and leave it, you know, let it do it.
33:19 Go get dinner.
33:20 Come back and just never delete that virtual environment ever, ever again.
33:24 Yeah.
33:25 I suspect it has multiple levels of caching as well.
33:27 Like if I pip install something and it's exactly the same version, it'll still be cached
33:31 even on my machine, even if I recreate the virtual environment.
33:34 So probably.
33:34 There's levels of it.
33:35 It essentially just creates a, I'm trying to remember.
33:38 I think it's dot.
33:39 It might even be dot VM.
33:40 It might be dot talks.
33:42 I can't remember.
33:42 But it essentially just creates a directory and creates a directory inside of that for each
33:46 one of your combinations.
33:47 And then pip installs into that virtual environment.
33:50 So when it runs the next time, it'll do upgrades and things like that.
33:52 And if you need to, you can just go in and RMRF the directory and blow it away if you're
33:57 running into trouble and need to start from scratch.
33:58 It sounds interesting for a web app.
34:01 It sounds super useful for a library package.
34:04 That's where I tend to use it.
34:05 So we'll talk later about one of my little bits of self-promotion here.
34:10 But I've got a couple of Django libraries that are out there.
34:12 And, you know, I support 3.6 through 4.0, I haven't got around to 4.1 yet, and three
34:18 or four versions of Django in it.
34:19 And every once in a while, you'll run into something that just doesn't work in some version
34:24 that you think is generic.
34:25 And it's become a lot easier since I've dropped support for 2.7 because there was a lot more
34:30 crap having to deal with that.
34:31 But that's how you catch those things.
34:32 Yeah, absolutely.
34:33 The last general one here is Pillow.
34:36 This is semi-general.
34:38 In case you're sleepy, you're programming too long and you just need to take like a little
34:41 bit of a nap or what's going on here?
34:42 That's what it's for.
34:43 That's right.
34:44 Pillow is for sleeping.
34:45 It's also for image manipulation.
34:48 So I don't do a lot of graphics stuff.
34:52 My Batman logo, notwithstanding, was very early on in my programming career.
34:56 But in fact, Django has a semi-dependency on this.
35:01 You don't need it out of the gate.
35:03 But if you're using certain features in Django, you do have to have it installed.
35:07 There's a field in Django, which is the image file field.
35:09 And it uses the Pillow library to make sure that the files that are associated with it
35:14 actually are images.
35:15 So this is a really deep, really cool image processing library.
35:19 And I tend to just skim the surface of it.
35:22 I use it for image and I use it for a couple libraries as well that deal with image thumbnails.
35:26 But otherwise, I don't really touch it.
35:28 But it tends to be one of those things that if I go through all of the virtual environments
35:33 set up on my system, I'm finding, oh, it's installed in a lot of them.
35:36 So it's one of those that's kind of common that I, because I don't do a lot of image stuff,
35:40 it's not something that I'm playing with a lot.
35:43 But it's very, very powerful.
35:44 So if you're into this kind of stuff, this is a great library to play with.
35:47 And if you're not, you may want just the surface level pieces for some web things like thumbnails.
35:54 If you're running a website that accepts, say, image upload, for example.
35:58 Yes.
35:59 You obviously need this for the Django ORM field.
36:02 That's the image type.
36:03 But you could also say, if it's too large, let's just resize it.
36:06 Or you can resize it to the same size all the time.
36:09 You know, it drives me crazy when I go to sites where like, this image is 1500 by something
36:14 and we only support 1280.
36:15 It's like, just resize it then.
36:17 Yes.
36:17 Yeah.
36:19 I've also used it in like in some command line scripts, which will like create like two
36:25 or three versions of an image that is in the static files.
36:28 Right.
36:28 So it'll automatically go through.
36:30 And like you said, okay, we've got our master that's, you know, 1500 by 1500.
36:33 And it'll go create some extra ones or whatever.
36:36 And you run a command and it'll run through all your static files and check that there's two
36:39 or three size versions or that kind of thing.
36:41 So again, if you're playing with the web, size is important.
36:44 Right.
36:45 So yeah, for example, if you want to have icons for your web app that can be saved to
36:50 iOS home screens, you know, they want all these different sizes from like 512 down to 64.
36:54 And if you're doing retina or high resolution, you can have different ones that get swapped
36:59 in and out.
37:00 And like, it'd be really nice to just automate all that.
37:02 Right.
37:03 That's right.
37:03 Yeah.
37:03 This portion of Talk Python to Me is brought to you by Microsoft for Startups Founders Hub.
37:10 Starting a business is hard.
37:12 By some estimates, over 90% of startups will go out of business in just their first year.
37:17 With that in mind, Microsoft for Startups set out to understand what startups need to be successful
37:23 and to create a digital platform to help them overcome those challenges.
37:26 Microsoft for Startups Founders Hub was born.
37:29 Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
37:36 The platform provides technology benefits, access to expert guidance and skilled resources,
37:41 mentorship and networking connections, and much more.
37:44 Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be
37:50 investor backed or third party validated to participate.
37:53 Founders Hub is truly open to all.
37:57 So what do you get if you join them?
37:58 You speed up your development with free access to GitHub and Microsoft Cloud computing resources
38:03 and the ability to unlock more credits over time.
38:06 To help your startup innovate, Founders Hub is partnering with innovative companies like OpenAI,
38:11 a global leader in AI research and development, to provide exclusive benefits and discounts.
38:17 Through Microsoft for Startups Founders Hub, becoming a founder is no longer about who you know.
38:21 You'll have access to their mentorship network, giving you a pool of hundreds of mentors across a range of disciplines
38:27 and areas like idea validation, fundraising, management and coaching, sales and marketing,
38:33 as well as specific technical stress points.
38:35 You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
38:40 Make your idea a reality today with the critical support you'll get from Founders Hub.
38:46 To join the program, just visit talkpython.fm/founders hub, all one word, no links in your show notes.
38:51 Thank you to Microsoft for supporting the show.
38:54 This one, I'm going to vote this next one here as probably the best icon of all the things we're going to talk about.
39:05 It's the Django Ninja.
39:06 Yes, they've done a good job with it.
39:09 There's a special flavor of marketing to open source projects, isn't there?
39:14 Yes, there is.
39:15 Yes, I think it's called none.
39:16 We could talk for hours on why it's called the GIMP.
39:22 Anyways, I find that because I'm a Django guy, I don't have a really strong need for single page applications.
39:30 A lot of the work I find I end up doing, Django templates is good enough for many of the pages in the application.
39:37 But then there's going to be some pages where you want to do fancier stuff.
39:40 So I often use view.js so that I can do best of both worlds there.
39:45 So I, you know, this is kind of a multi page application.
39:48 So those pages that require SPA kind of feel to it, they have view on it.
39:53 And those that don't, I just use generic 1.0 web style stuff.
39:58 So in the 2.0 world, you need REST APIs and enter Django Ninja.
40:05 This is what it does.
40:06 So it sits on top of a Django view and essentially RESTifies the view.
40:11 And I, when I say on top, I mean that literally you actually use decorators.
40:15 So you write a view, decorate it with an HTTP method like get or put, and then that view outputs JSON instead of your usual HTML.
40:24 The library is built on top of Pydantic.
40:27 So it relies heavily on the types to help it define the JSON that comes out.
40:31 You write a little schema file that says the names and types of the fields for the JSON output.
40:36 And it's got a schema that is based on top of Django models.
40:43 So this works a lot like a model form if you've ever used one of those.
40:47 So let's say I've got, you know, a Django model called a customer.
40:50 I can create a schema called customer out that inherits from Django, from Ninja's model schema.
40:56 I create a subclass called config, which is kind of like the meta subclass in Django.
41:00 And it sets the model attribute to point to the customer.
41:04 And if I want to use all the fields in the model, that's it.
41:07 It's basically just the three lines.
41:08 And you can customize that.
41:11 So like model form, you can say, don't use all the fields, only use these fields.
41:15 Or you can add fields if there's things like, say you want a field called name that combines first name and last name.
41:21 You can build something that computes that so that it doesn't actually use the model directly.
41:25 So oftentimes you end up having to write a couple of these because you often need the inbound and the outbound to have different fields in it.
41:33 So a common practice is to have your schema for customer be called, say, customer out or customer in.
41:40 There's nothing that enforces that, but that's how they do it in their documentation.
41:43 And I've kind of just sort of picked up the habit as you go along.
41:46 Yeah, it's so tempting sometimes to think, oh, we can just exchange the same model inbound and outbound in so many ways that just doesn't pan out.
41:53 Even if you're using something like Beanie or SQL model or something where like literally the Pydantic model goes in the database as well.
41:59 Often that's not even the same thing because, for example, your inbound create user, you want a password.
42:04 Your response, you'd never want to send the user the password directly back.
42:09 You shouldn't even know what it is.
42:10 The ID field is the most common thing, right?
42:13 Like every model's got one and there's hacks you can do to say, oh, if it's zero, it's a create, you know, and that's a common way of doing things.
42:19 But for Django Ninja, what I often just do is just leave it out.
42:23 And because there are objects like anything else, you can inherit it, right?
42:26 So you can start with the in and then add the ID to it.
42:29 So there's ways around it.
42:30 It's what it comes down to.
42:31 The Django Ninja can be plugged into an existing Django app.
42:35 It's not like a separate thing that I run that is also correct like Django.
42:38 It's actually just stuff that sits on top.
42:41 It's got its own routes.
42:42 So essentially you're building Django views, but you're decorating them with the Ninja.
42:47 And when you decorate it, it automatically collects all of those underneath one path in the URLs file.
42:54 So you set up a router.
42:56 Usually you set it to say something like slash API.
42:58 And so back to that customer example I was using, if I added a view for create customer, I set it to the customer path.
43:05 And because it's decorated, it automatically ends up under slash API slash customers.
43:09 So it takes care of a lot of that for you.
43:12 It looks like it also has async support as well, which is pretty neat.
43:16 It started from scratch with the asyncio.
43:18 I'm not 100% sure of this, but I think there's a couple former DRF guys on here.
43:23 And I think it was a rewrite from scratch with async from the beginning and Pydantic.
43:28 So I think it's sort of the next generation.
43:30 The key writers weren't in the DRF.
43:33 They obviously took a lot of learning from what was there and what worked and what didn't work.
43:37 It's pretty familiar to FastAPI type of programming.
43:41 And it has a lot of uses of type hints, right?
43:44 For example, you have an API function that takes a delay.
43:47 It says it's an integer.
43:48 I suppose it probably actually parses that and validates it and so on.
43:51 Yes.
43:52 And it's particularly useful as well because by the time you're getting things down, you
43:56 know, your web string, everything is string, right?
43:59 Like when you post it, it's all coming up in the string.
44:01 So somebody somewhere has to go, oh, that's supposed to be an int and try to convert it.
44:05 So it takes care of a lot of that kind of stuff.
44:07 And in fact, one of the reasons there's so little coding in this, particularly with the
44:12 schema definitions is because you're just, if you've already got that model file, it knows
44:16 the Django field is a text field or is a Boolean or is an integer.
44:20 And it goes, oh, okay, I know what to do with that, right?
44:22 So it essentially is building on top of that stuff that's already there for your existing
44:26 code.
44:27 That's really cool.
44:27 And you basically so much of the validation has already happened.
44:31 By the time it gets to you, you're much closer to the right answer.
44:34 You don't have to check so many things.
44:35 Much less code you have to write.
44:36 Yeah, for sure.
44:37 And if that's not good enough on top of all of this is it comes with a web-based debugging
44:42 view.
44:42 So it lists all of your registered calls.
44:44 You can go and click on things.
44:46 Authentication is required for the call.
44:48 And it's got a whole bunch of stuff in the back end for that as well.
44:50 You can click through and say, okay, I push this button and paste in my key or hit the
44:56 login button in my Django and then use it that way.
44:58 So it allows you to sort of see all of this and it includes in it the output in curl.
45:03 So as you're using the debugger, you can copy and paste the line into your terminal and then
45:08 run it in curl.
45:09 It's a quick little tool for helping you sort of figure it all out.
45:12 Pretty powerful.
45:14 It even has an interesting sync to async adapter decorator to allow you to work with the ORM
45:20 until it's kind of migrated along.
45:22 Shouldn't be as necessary now that 4.1's out because that was one of the major changes in
45:26 Django 4.1 is they added async to the ORM.
45:28 So yeah, that's really a big deal.
45:30 Yeah.
45:30 I actually remember one of the comments I saw on Twitter after 4.1 came out was, oh, the
45:34 Django guys, the ninja guys are going to love this.
45:36 I'm like, yeah.
45:38 Sounds like it.
45:39 All right.
45:40 Julio asks, is this as complete as Django REST framework?
45:43 And Nick Harvey says it looks lighter than Django REST framework.
45:46 Maybe give your thoughts and then we can maybe pull up the next topic.
45:50 Why don't we punt seeing as the next one is the Django REST framework and we can talk about
45:56 it as we go along.
45:56 The short answer is no, it's definitely not as complete.
45:59 So the Django REST framework or DRF to its friends is Ninja's granddaddy.
46:04 And it for a long time was the go-to REST library in Django.
46:08 Like Ninja, it breaks things down into serializers.
46:11 That's the equivalent of a schema and then views and routes.
46:14 And like Ninja, it supports decorators, but it also supports classes.
46:18 But because it's older, it doesn't support the type mechanism.
46:21 So you have to do a little more boilerplate code to get this going.
46:24 You have to do a few more things with the serializers.
46:27 It tends to, I was going to say it tends to favor a class-based approach.
46:32 I'm not sure if that's true.
46:33 When I write with the DRF, I tend to use the class-based approach.
46:36 There are other mechanisms in there, but it seems to be the one that felt natural for
46:40 me there.
46:40 It has a concept called a view set class.
46:43 And this is really where it shines because you define an object, which is an endpoint.
46:48 And then you can say inside of that endpoint, I want to do list and create and retrieve and
46:53 update and destroy.
46:54 And you tie that into your query set.
46:56 And it does all of those things for your object.
46:59 So back to my customer example, I could build out that customer endpoint.
47:03 And then I can say, I want to use list, create and retrieve.
47:06 And it'll allow me to create a customer or list all the customers or get a specific customer.
47:11 And it does it based on mix-ins.
47:13 So you can mix and match what, which of those choices you want.
47:17 So it's sort of this composing kind of mechanism.
47:20 I question or sort of an observation here from, to be fair, I haven't done much with
47:24 DRF.
47:25 But it feels to me like a lot of what you're getting with DRF is like, I have a database
47:31 table.
47:31 Let me do the rest things to it.
47:34 Like I want to be able to do a get against and get all of them or get against an ID and
47:38 get individual ones.
47:39 I want to be able to do a post and maybe create one where it's a lot.
47:43 It seems like it's very structured around CRUD, but over API.
47:46 Is that accurate or no?
47:48 There are ways around it.
47:49 So the concept of a serializer does not have to be tied to a model, but this is a tool for
47:55 Django.
47:55 So it's not really a surprise that it's kind of tied to the models.
47:59 And that's for the most part, even with Ninja, I find 80% of what you're doing over the rest
48:04 API is mapping to your database models in the first place.
48:08 particular if you're doing it for something like React, because the things in your database
48:12 are usually what you're showing up on the screen.
48:15 So it usually tends to map fairly easily.
48:17 And there's enough depth there that if you need to introduce new fields or do something
48:22 custom, it doesn't handcuff you.
48:24 It does allow you to do a lot of this stuff easier, though.
48:28 So like if you are sticking with things that map nicely to your database, then, you know,
48:32 it requires far less code is what it comes down to.
48:35 I guess to get back to that sort of question, it is just definitely lighter weight.
48:40 It definitely I find requires less code than the DRF because it takes advantage of things
48:45 like the typing that which DRF is older and it didn't exist.
48:48 And it was compatible with Python 2 and some of the stuff where those type pieces weren't
48:52 there.
48:53 DRF has a much richer output listing.
48:56 So if I were going to need something that was not JSON based, for example, over REST, I might
49:02 go back to the DRF.
49:03 So it's got mechanisms for either through it or through plugins, YAML, XML, MessagePack, Excel,
49:10 even LaTeX, right?
49:12 So there's libraries that go with these libraries that make this that sort of connect these things
49:16 together.
49:16 So, yeah, there's there's a lot of depth here.
49:18 The only place that the DRF makes me really, really nervous and is the permission mechanism.
49:25 I have shot myself in the foot a few too many times doing it.
49:29 It's fine by default, but then as soon as you start mucking with it a little bit, it seems
49:34 to open up a whole bunch of things.
49:36 You have to make sure once you start playing in that space that you do it correctly and test
49:40 properly.
49:41 Otherwise, you could have gaping holes.
49:43 Ninja seemed to be a little more locked down by default.
49:46 So I kind of liked that.
49:47 But that could just because I'm missing toes from playing with the DRF over the years.
49:51 You know what the guns look like?
49:54 Yeah.
49:54 Tishar asked, I think this is probably in reference to the Django Ninja.
49:58 It looks similar to FastAPI and how would you compare them?
50:00 It's a lot of sort of similar kind of concepts.
50:03 And in fact, you know, either between FastAPI, the typing mechanisms, is FastAPI directly based
50:10 on Pydantic or just deeply influenced by it?
50:13 I think just I feel like Pydantic became very popular because of FastAPI, but they're separate
50:18 projects.
50:18 Okay.
50:19 Separate maintainers.
50:20 Ninja is built on top of Pydantic.
50:21 So, you know, they're all being inspired by the same thing and trying to solve very similar
50:25 problems.
50:26 So it's not surprising me that people are seeing.
50:28 Yeah, exactly.
50:29 And at the bottom of the Django Ninja site, it says, this project was heavily inspired by
50:33 FastAPI.
50:34 Yeah.
50:34 My feeling is like, if you're already doing Django and you want to add APIs and you like
50:39 FastAPI, this might be a really good option because it brings so much of a similar model,
50:44 but you don't have to now maintain two apps that like run separately or version separately,
50:48 all that.
50:49 Yeah.
50:49 I also find it's got a little bit of a flask flavoring as well, right?
50:54 As to how some of those pieces.
50:55 And again, that's the same thing, FastAPI, using the decorators, using the types, right?
50:59 So it's a similar kind of influences if nothing else.
51:03 Yeah.
51:03 Very neat.
51:03 I think.
51:04 All right.
51:05 Django Grappelli.
51:06 What's this one for?
51:08 All right.
51:08 So a little bit of a tangent here for a second.
51:10 Django is named after a jazz guitarist named Django Reinhardt.
51:15 And he was often a duo working with somebody named Stefan Grappelli.
51:19 So if you're looking for a name for a library for Django, Grappelli is a good fit.
51:24 So now great.
51:26 We've got a name.
51:27 What does it do?
51:29 This is actually a reskinning of the Django admin.
51:32 So the Grappelli folks have taken advantage of the fact that the Django admin is built on
51:37 top of the Django templating mechanism, and they've rewritten all those templates using
51:42 a new style.
51:43 The style still feels a little dated, but not quite as dated as the Django admin.
51:48 So it's a step in the right direction.
51:49 It does logical things like a lot of the top right-hand corner, you know, reset password
51:55 view page.
51:56 A lot of that stuff gets moved into like little dropdowns and that kind of thing.
51:59 The coloring is a little more consistent.
52:01 It uses a footer.
52:03 So like the actions are always in the same place.
52:06 It just generally feels cleaner to me.
52:08 I often use the Django admin for like my backend support people.
52:13 Don't tend to use it customer facing.
52:15 So, you know, folks who are trainable and I find that when I've used it with them, Grappelli
52:21 feels better for them.
52:22 They just, it feels a little more intuitive.
52:24 So it's just a, it really is just a skin, but it's a nice skin and it's a really easy install.
52:30 You have very little you have to do.
52:32 You get a couple, a couple of changes to your settings.py file and it's all done for you.
52:36 So.
52:36 Yeah.
52:36 And also it looks like, you know, you hear skin, you think, oh, it's pretty, but it also
52:41 seems like it adds more functionality.
52:43 Like it adds autocomplete for foreign keys and relationships.
52:46 It adds like a tiny MCE, which is rich text editor.
52:50 It adds reordering through drag and drop.
52:53 I mean, those are a little bit more than just pretty, right?
52:56 It's modernization of the interface is really what it comes down to.
52:58 Yeah.
52:59 Yeah.
52:59 Very cool.
52:59 So another random Django bit of history to go along with the musicians was created in Lawrence,
53:05 Kansas, right?
53:06 Yes.
53:06 By the newspaper.
53:07 That's where I went to college.
53:09 So.
53:09 Ah, okay.
53:10 Right, right down the street from the home of Django around the same timeframe.
53:14 There you go.
53:14 Right.
53:15 All right.
53:15 So what's up next?
53:16 Import export.
53:17 So it's like a distributor.
53:19 It's going to make some money off selling rugs or what's the deal?
53:22 Rugs.
53:22 Yes.
53:22 Sure.
53:23 Rugs.
53:23 All right.
53:26 Unlike Grappelli, where you have no idea by the name, this one's a little better.
53:31 You might have an idea what it does, right?
53:34 Less creative, more straight to the point.
53:36 Like this is a utilitarian name.
53:37 I can import or I can export stuff from Django.
53:40 Okay.
53:40 That's exactly it.
53:41 How does it work though?
53:41 What?
53:42 Like, I mean, not just a database dump, probably something more interesting than that.
53:46 Yeah.
53:46 So it's built on top of Tablib, which is a Python library for tabular data formats.
53:51 And essentially it maps things out of your ORM to whatever Tablib can handle.
53:57 So that's Excel, JSON, YAML, Pandas, HTML, JIRA, TSV, ODS, CSV, DBF.
54:04 And I even know what some of those acronyms mean.
54:06 It's essentially your go-to place for spitting stuff out.
54:10 So like Ninja and like the DRF, it has this, what it calls resources.
54:15 This is like our schema.
54:16 And it essentially does that mapping thing again.
54:19 So you can say, I want to take this model and I want to map it to this mechanism.
54:24 And then it'll, you just run it and say, export this to JSON and you'll get it in JSON.
54:28 Export this to YAML and it'll export it to YAML.
54:31 There are mechanisms inside of the resources, similar to what I was talking about in Ninja
54:35 and the DRF to do compositing.
54:37 So if I want a name field, which is based on first name and last name, it'll combine all
54:42 those things and give that to you together.
54:43 One of the things that I like most, I haven't used this library a lot, but when I have used
54:47 it, it's because of this feature, which is it integrates nicely with the Django admin.
54:52 So you essentially can build one of these resources.
54:55 Let's say back to my customer example, let's say you want to be able to import customers.
55:00 You can essentially define the resource and then you add a mix in to your customer admin
55:06 object and it automatically gives you an import button on the client screen.
55:10 And when you hit that import, it'll upload, you give it the CSV file.
55:13 It gives you a little screen that says, oh, this is the data that's coming in.
55:17 And you can say, yes, I like it.
55:19 And it'll put it into the database.
55:21 And it's smart enough to know the difference between creates and updates.
55:24 So depending on whether or not your ID field is blank, this is back to that zero thing we
55:29 were talking about before.
55:30 It will actually update things that are there.
55:32 So if you've got a situation where you've got a client phone book or something that's maintained
55:38 through some other system and you need to keep them in sync, this is a quick and easy way
55:43 to do that.
55:44 throw it together with a management command and stick it in a cron job and you can constantly
55:50 push these things through.
55:51 It might sound really simple, but the ability to say, hey, business person or manager or salesperson,
55:56 you can just take your CSV and upload it.
55:59 You don't have to bother the dev team to add your data.
56:03 Like that's pretty fantastic, actually.
56:05 One of my clients is a very lightweight CMS.
56:08 And of course, when they sign up a new customer, they don't want to have to input their customer's
56:14 data by hand.
56:14 Right.
56:15 So you can say, oh, go.
56:16 You have it in an Excel file somewhere.
56:18 Great.
56:18 Save as put it in this format.
56:20 Suck it all the data in.
56:21 So it can make a big difference.
56:23 Yeah.
56:23 And the preview, make sure this looks good.
56:25 Like that's also an important part.
56:26 That's a lifesaver, right?
56:28 You know exactly what you're getting in there.
56:29 You can check it rather than it going, you know, running havoc all over your database.
56:34 Which it probably would if people just randomly start uploading stuff.
56:38 Exactly.
56:39 And that might make your app crash, but you could use the Django debug toolbar to figure out
56:42 what's going on.
56:43 Look at you, king of the segues.
56:44 Yes.
56:45 Oh, yeah.
56:46 So the next one here is, as you said, this is the Django debug toolbar.
56:50 So this is a plugin for Django that overlays over your views and gives you all sorts of
56:55 information what's going on in your page.
56:57 The installation is a little more involved than, hey, just add this to settings.py because
57:02 you need some middleware and some static files and things.
57:04 But once you've, the instructions are good though.
57:06 So as long as you follow the instructions closely, you'll be okay.
57:09 And once you got that going, it pops up in the top right-hand corner.
57:12 I think that's actually configurable.
57:14 And it has a list of panels.
57:17 It comes with, I think it's 12 of them.
57:20 And then there's a whole bunch of plugins that you can do as well.
57:22 So for example, there's history information.
57:25 A useful one I find I use a fair amount is the time panel.
57:28 So it shows you the breakdown of where, you know, where your call has been spent.
57:33 The one you've got up on the screen there right now is the one that saves my bacon all
57:37 the time, which is the SQL panel.
57:39 So it shows you exactly what queries were run, how long each of them took.
57:42 I understand enough database stuff to just get me in trouble, right?
57:46 The ORM provides this nice abstraction that I find really helpful, but I'm aware that I'm,
57:50 you know, sometimes I'm doing things that aren't efficient in SQL.
57:53 Or you don't know you're doing something inefficient, right?
57:55 You might not be aware you forgot a join.
57:58 Exactly.
57:58 And now you have this N plus one problem where you're like, I thought I did one query.
58:01 Why are there 50 queries, 51 queries on this page?
58:03 Exactly.
58:03 You know?
58:04 So when you've got that sluggishness, you go to the time panel, you see that you're
58:08 spending all your time in the SQL space.
58:10 Then you go to the SQL panel and you go, oh, okay.
58:12 So this is where it is.
58:13 I'm beating my database to death.
58:15 Why?
58:15 And then you can figure out, like you said, oh, I need to add an index or, you know, I
58:19 need to change the join or whatever.
58:20 Right.
58:21 So in the Django debug toolbar, it has a time section that says CPU and total.
58:25 And if the CPU time is the majority, then it's your Python code.
58:29 If it's not, then it's like, what are you waiting on?
58:32 Are you waiting on a database or an API?
58:34 Or go look somewhere else because it's not your code exactly.
58:37 It's an external resource that's holding it up, right?
58:40 Yeah.
58:40 So it helps you sort of pull these things through it.
58:43 And it's information that's available in any profiler as well, but it's there in combined
58:47 with other things.
58:48 So you don't have to go do it separately.
58:49 So there's other ones there.
58:51 Things like caching, headers, signal registering, logging, the list goes on.
58:56 And then it's a published mechanism for how you build your own panels.
59:00 So even on the main site, there's another 19 panels with instructions on how to write your
59:05 own.
59:06 And if you go digging, there are people that aren't in the official list as well.
59:09 So there are dozens and dozens of them out there.
59:12 For sure.
59:12 Probably in the awesome Django.
59:14 I bet.
59:15 You know, I bet there's like, there's a whole thing on the toolbar.
59:19 Yeah.
59:20 It was right there at the top where you're testing.
59:21 That's right.
59:22 Yeah.
59:22 Yeah.
59:22 I thought maybe there'd be a list of plugins as well.
59:25 Oh, a subset.
59:25 Yeah.
59:26 Yeah.
59:26 Yeah.
59:27 Yeah.
59:27 Like a subsection.
59:28 But yeah, these things are really nice and I find them to be quite useful on the, you
59:32 know, they've got different, I got the whole list here.
59:34 Like profiling.
59:35 That's kind of cool.
59:36 I guess one also, one really quick thing you might want to touch on for everybody is it might
59:42 not be best to put this in production.
59:44 Yes.
59:45 I think there's a rule against turning this off in production.
59:48 If I remember correctly, it will not run if debug is set to true.
59:51 It's to false.
59:52 Excuse me.
59:52 So by out of the box.
59:54 So if you're, if you're following best practices of setting debug to false in your production environments,
59:59 it won't be there.
01:00:00 It doesn't hurt to belt and suspenders that though.
01:00:02 I usually put this, if I'm using it, I usually put it inside of my, you know, requirements
01:00:07 dash dev.
01:00:08 And I have a little hack I use to build up my installed apps that I add to it from local
01:00:14 things, which there's a podcast in and of itself there as to how you configure in different
01:00:18 environments.
01:00:19 But I often only add this to that piece or hackishly commented in and out as I need to.
01:00:24 It's a little bit of a crude lever, but if it's not in the requirements.txt or pyproject.toml
01:00:30 or whatever, you're not going to accidentally run the toolbar if it's not installed.
01:00:33 So don't install it in production.
01:00:35 Yep.
01:00:35 Exactly.
01:00:36 Effective, right?
01:00:36 Yep.
01:00:37 How about some local flavor?
01:00:38 Yep.
01:00:39 Local flavor.
01:00:40 So this package eons ago used to actually be inside of Django and it just got kept getting
01:00:46 bigger and bigger.
01:00:47 And essentially this is the localization information for different countries.
01:00:52 So for example, the CA folder is for Canada, which is where I'm from.
01:00:56 It includes a list of all the provinces.
01:00:58 That's what we call states.
01:01:00 It's got a widget for postal codes, which is what we call zip codes and social insurance
01:01:05 numbers, which is what we call social insurance numbers.
01:01:07 Although we use a different acronym for whatever reason.
01:01:10 So essentially, if you're using things like shipping addresses, you want local flavor.
01:01:15 It's mostly just giant dictionaries and collections of tuples, but it's useful data that often you
01:01:22 would end up writing yourself.
01:01:23 And it's always nice when somebody else is maintaining it.
01:01:26 And for any fellow non-Americans listening, it is spelt without the U.
01:01:30 I'm not sure if it was intentional when they picked the name that the name itself needs
01:01:34 internationalization or whether that was just an amusing little accident, but that's what it is.
01:01:40 So even just having the country codes is great.
01:01:42 Is this something that maybe makes sense to use outside of Django or is it?
01:01:45 I'm not sure how easy.
01:01:47 I've never done it.
01:01:49 It might work.
01:01:50 It really is just a long dictionary and collections of tuples, but some of it's kind of Django
01:01:55 Django-esque.
01:01:56 For example, the list of provinces is set up so that you can use it easily inside of
01:02:01 a dropdown in a choices field.
01:02:03 Got it.
01:02:04 You might be able to take advantage of it without that, but it's formatted in a fashion that makes
01:02:08 sense in the Django world.
01:02:09 Good to know.
01:02:10 All right.
01:02:10 We already talked about the import and the export buttons, but even more buttons on the admin
01:02:15 if we want them.
01:02:16 Even more buttons.
01:02:16 Yes.
01:02:17 You can always do with more buttons.
01:02:18 So I've only used this one a couple times, but it saved me a whole bunch of work.
01:02:23 So I thought it deserved a mention.
01:02:25 The Django admin area pretty much is mapped to your model objects.
01:02:30 It really is just sitting on top of your ORM.
01:02:32 And every once in a while, you're going to need something that you want your support staff
01:02:37 to be able to do that isn't really directly tied to the ORM.
01:02:41 And in fact, I've seen libraries out there that hack things, creating fake objects inside
01:02:46 of the database so that they will show up in the ORM properly.
01:02:49 And instead of doing that, you use admin extra buttons.
01:02:52 So this is really just a way of inserting views into your admin.
01:02:57 And it's got a quick little mechanism for forms so that if you hit a button, it'll pop up the
01:03:03 form for you.
01:03:04 You can fill in the form and then it'll give you the data from the form as a callback.
01:03:08 And then you can do whatever you want with it.
01:03:10 So where I've used it recently was I had a complex count creation mechanism that has to create
01:03:16 like five or six different objects that have to be tied together.
01:03:19 So instead of having my support staff going in and using the admin to create each one of
01:03:23 those separately, I gave them a little button.
01:03:25 They fill in the form and it creates all the objects and ties them together nicely.
01:03:29 And actually just a couple of days ago, I added one, which was sometimes I'll have in
01:03:34 production code, like a couple of accounts that are like sample accounts that you want
01:03:38 to reset the data to a known state so that you can hand it off to demo somebody or quick
01:03:42 if you're trying to sell a client or something.
01:03:44 So this doesn't even require the form.
01:03:46 There's a mechanism in here called confirm action, which essentially is it gives you the
01:03:50 button.
01:03:50 It pops up a little thing that says, are you sure you want to do this?
01:03:53 And if you say yes, it goes off and calls your little five lines of code.
01:03:56 So it's nice and clean.
01:03:59 The form rendering is ugly is the word, but that kind of fits with the traditional,
01:04:05 traditional.
01:04:05 It's traditional.
01:04:06 It fits very nicely with what's inside of the Django admin.
01:04:09 It doesn't look out of place, but there's nothing sexy with it.
01:04:12 I have not used it in combination with Grappelli yet.
01:04:15 So it'd be interesting to see what happens in that case.
01:04:18 There's basically very little styling on the form, but it has saved me a whole bunch of
01:04:23 code.
01:04:23 And oftentimes I find when you're writing things for your support staff, they're spending 90%
01:04:28 of the time inside of the admin anyways.
01:04:30 So pulling them out of it for one special page is a bit of a pain.
01:04:35 And you usually have to write a whole bunch of extra stuff on top of it.
01:04:38 And so this, because it inserts it right inside of the admin means you don't have to get them
01:04:41 into a different place.
01:04:42 And they're in an interface that they know how to use and makes things easier.
01:04:46 So very much like that import export.
01:04:48 If import export didn't exist and give you that button up top, this would be a way of building
01:04:52 it.
01:04:53 Really nice.
01:04:53 And it's very decorator heavy.
01:04:55 It is.
01:04:56 Yes.
01:04:56 Yeah.
01:04:57 Everything's a button or a view.
01:04:59 And you've got up on the screen there, right?
01:05:01 That's the confirm that I was talking about at the top.
01:05:03 You call it decorate the view.
01:05:06 And that's because in this case, you're inserting it inside of the actual Django admin model pieces,
01:05:11 right?
01:05:11 So you have to essentially, the decorators are doing the registration to say, okay, this is
01:05:17 extra code for the admin.
01:05:18 It's how they're hooking it all.
01:05:20 Yeah, it looks very, very useful.
01:05:21 All right.
01:05:22 We've got a couple more.
01:05:23 Yep.
01:05:23 This one, I think I know the guy who created this one.
01:05:25 Yes.
01:05:25 So this is a little bit of blatant self-promotion.
01:05:28 This is Django All, A-W-L, like the leather working tool.
01:05:32 And yeah, this is one of mine.
01:05:33 If I had been aware of the Django extensions library at the time that I wrote this, I probably
01:05:38 should have just contributed to the Django extensions library.
01:05:40 It would have been the smarter thing.
01:05:41 But at the time, I wasn't familiar with it.
01:05:44 And since then, I've been maintaining this beast.
01:05:46 It's a general collection of a whole bunch of crap, like extensions that I just found
01:05:52 I was writing over and over again every single time I went to a client.
01:05:54 So one of the times I was doing that, the client, I went to the client and said, let's open source
01:05:59 this stuff.
01:06:00 And they went, okay, great.
01:06:00 And since then, I've been doing this.
01:06:02 You sell widgets.
01:06:03 You don't sell Django admin extensions.
01:06:05 Like, let's make the world a better place and contribute back ideas.
01:06:08 Exactly.
01:06:09 This will hurt you.
01:06:10 Big list of random crap, right?
01:06:12 So a bunch of mix-ins, CSS color utilities, some context processor pieces.
01:06:18 Custom admin commands.
01:06:19 Yep.
01:06:20 There's decorators in here that make sure that you're doing a post with JSON content.
01:06:25 So that if somebody's calling your view in the illegal way, it screams ranked models.
01:06:31 So one, two, three, four, five, and gives you a little thing inside of the admin to move
01:06:35 them up and down.
01:06:36 Some testing tools.
01:06:38 So there's a custom test runner in here, which adds a whole bunch of features for doing
01:06:42 things like getting out information out of the Django admin and checking that the fields
01:06:47 and the admin are correct.
01:06:48 So really just sort of a little catch-all that's out there.
01:06:51 But yeah, it's here and I happily take PRs.
01:06:55 So go find it, break it.
01:06:58 If you find it useful, great.
01:06:59 If you don't, send me a note and tell me why not and I'll fix it.
01:07:02 Yeah.
01:07:02 Lovely.
01:07:03 It looks really useful.
01:07:03 I'll stop with the shameless promotion after this one.
01:07:07 Hey, I'll keep going.
01:07:08 These are good.
01:07:08 This is a Django airplane.
01:07:10 So I used to, I used to have to do a lot of traveling when I was consulting and being on
01:07:17 a plane is a great place to get some uninterrupted four or five hours of coding in unless you're
01:07:21 coding on the web.
01:07:22 And particularly in the olden days when you didn't get wifi on the planes and even now it's
01:07:26 spotty and expensive.
01:07:27 You can't really count on it.
01:07:28 Yeah.
01:07:28 Yeah.
01:07:28 So what I found was, you know, if I'm using something like bootstrap from a CDN, I would
01:07:34 get in and I'd be trying to run my Django site and be like, oh crap, nothing's looking right
01:07:38 because the CDN is there.
01:07:40 So this is essentially a little tag that you use anywhere where you would use an HREF for,
01:07:45 you know, links or style sheets or whatever.
01:07:47 And then there is a setting that defines the mode of the system.
01:07:53 And if you're in build mode, anytime these tags find it, they'll go off, they'll grab the
01:07:58 content and they'll save it to the disc and just runs the page normally.
01:08:01 And then when you're in cache mode, instead of trying to get to the internet, it pulls it
01:08:05 off of the disc.
01:08:06 So it's nothing terribly complicated, but it solved a particular problem that I was having
01:08:12 a lot.
01:08:12 And now that I'm not really traveling, I'm not touching it as much, but if folks out there
01:08:18 find it useful.
01:08:19 People travel less.
01:08:20 I don't know.
01:08:20 It's kind of weird.
01:08:20 Yeah.
01:08:21 There's been a few changes.
01:08:22 Life has changed.
01:08:23 There have been changes.
01:08:25 Although I did travel recently in a pandemonium.
01:08:27 So if you want madness, you can go back and try to fly.
01:08:30 Yeah.
01:08:30 So this is really nice.
01:08:31 So basically you say airplane, instead of a static ref to a CDN, you say airplane and then
01:08:36 the reference to the CDN and either it just passes through or it can download and then
01:08:40 pass through, or you can say I'm in this development mode.
01:08:43 Just, I don't have, I'm either at like a coffee shop or I'm traveling or whatever.
01:08:47 And just let me, I'm, you know, another good use case, not just airplane, even though that's
01:08:51 the name is if you're at a hotel with notoriously bad internet and you're traveling for work and
01:08:57 you got to get a presentation or new version ready for the morning, like that can be a super
01:09:01 frustrating experience.
01:09:02 It essentially moves anything that's normally on your internet down to your hard drive.
01:09:05 If you've tagged it properly and there's a couple of management commands as well.
01:09:09 So like, it'll tell you what's in your cache and you know, how to see it and how to wipe
01:09:12 it out if you need to.
01:09:13 So there's a couple little utilities, but like I said, it's one of those, one of those libraries
01:09:19 that is simple, doesn't do a lot, but solves a particular problem.
01:09:23 So if you're having that problem, go for it.
01:09:25 Yeah.
01:09:25 Fantastic.
01:09:25 Your example is for a CSS.
01:09:27 Can I like leverage this to like JSON API somehow like offline, some API calls or anything,
01:09:34 or is it, is there not really a way to fit that together?
01:09:36 I don't think it would work.
01:09:39 If it's a straight URL that was always coming back with the same value and it was hard coded,
01:09:44 it probably shouldn't care.
01:09:46 But yeah, it would depend on how you were using it.
01:09:49 Yeah, sure.
01:09:49 Last one.
01:09:50 The thing you always put last security, right?
01:09:52 Just kidding.
01:09:53 Okay.
01:09:54 We're skipping ahead.
01:09:55 Got it.
01:09:55 No problem.
01:09:55 Oh, are we skipping ahead?
01:09:56 I had a Django extensions next.
01:09:58 So.
01:09:58 Oh yeah.
01:09:59 I think I just didn't open that one.
01:10:00 That's fine.
01:10:01 I kind of touched on this one when I was talking about Django All.
01:10:04 This is a collection of things that probably should just be built into Django is really what
01:10:10 it comes down to.
01:10:11 There's a whole bunch of different areas.
01:10:13 Again, it's this huge hodgepodge.
01:10:15 So there's extra tools for the admin, more management commands, more signals, template filters, extra model fields, job management.
01:10:24 It's a very lightweight job management.
01:10:26 But if you're not at the level where you want to use Celery or something like that, this might be good enough for you.
01:10:30 Some model mix-ins, permission mix-ins, extra validators, some utility methods.
01:10:35 The one I use here all the time, particularly when I was learning Django Ninja and I was trying to understand how the router worked, is a management command called show URLs.
01:10:44 It'll show you all the URLs you've registered, what their keywords are, and how to call them.
01:10:50 So it's a nice little introspective kind of thing to work through backwards.
01:10:54 It's got another management command called run script.
01:10:58 And this one's so useful that I had the exact same thing in Django All.
01:11:01 Again, as I said, I should have just looked at this library first.
01:11:04 And the idea of run script is it gives you a Django context for running a Python script.
01:11:10 So this is kind of like the dash dot slash management shell command, where it gives you inside of a Django context, but it does it for the script that you're running.
01:11:18 Oh, that's cool.
01:11:19 So things like the database are initialized and stuff?
01:11:22 Exactly.
01:11:22 Yeah.
01:11:22 Okay.
01:11:23 I find I generally use it if I'm debugging, right?
01:11:26 So if I've got three or four things I want to do in the database and I need to run it three or four times until I figured out what the problem is, rather than constantly doing that in the REPL over and over again,
01:11:34 you stick it in a file, run the script, look at your debug or use it in the debugger.
01:11:39 Of course, is the other thing there, because you can step through that a lot easier than you can say inside of a inside of a REPL.
01:11:45 So a lot of good stuff here.
01:11:46 And it's one of those libraries that I find every time I look at it.
01:11:49 I'm like, oh, I have to remember that's there.
01:11:50 And then I forget.
01:11:51 But you always have to sort of go back and dig through it.
01:11:54 So it's a good little toolbox.
01:11:57 Diff looks cool for probably pre-post migration.
01:12:00 There's three or four SQL commands in there that'll tell you how your migrations are, how they've changed, how you're managing them, what it's doing to them.
01:12:08 Django has since added a couple things that are similar to it inside of the core library.
01:12:13 But these are definitely more powerful.
01:12:15 So, yeah, if you're trying to figure out what's going on with your models, there's some interesting stuff in there as well.
01:12:19 Yeah, fantastic.
01:12:20 All right.
01:12:21 Maybe that brings us to Django All-Off.
01:12:23 This is it.
01:12:24 This is the last one.
01:12:25 So this is Django All-Off.
01:12:28 This is your go-to place for authentication.
01:12:30 It has a series of workflows in it that are your typical user management things like sign up, email addresses, email verification, password resets.
01:12:40 And so I don't usually use it for that.
01:12:43 I use it for the thing that most people use it for, which is it's got this hook for your social media account authentication.
01:12:48 So most social media sites use either OAuth or OAuth2.
01:12:53 And so if you've ever been on one of those web pages that says, you know, you can sign in or create an account with your Facebook account or your Google account, this is a plugin that allows you to do that inside of your Django space.
01:13:03 They have over a hundred different providers.
01:13:06 I stopped counting.
01:13:07 I just gave up after a while.
01:13:09 Most of them are overlays on top of OAuth2, but there are also some that are custom as well.
01:13:16 And what happens is when a user signs up using one of these, it still uses the standard Django user, but then it creates an associated object.
01:13:25 And the advantage of this design is it means different users can use different things.
01:13:29 I can sign in using Facebook.
01:13:30 You can sign in using Git or Google or GitHub or Google.
01:13:34 But we still end up in the same user style account inside of the database.
01:13:39 But the other advantage of it is you can also associate multiple things.
01:13:42 So say you were writing a site that wanted people to be able to log in through GitHub or GitLab, but also wanted to be able to tweet.
01:13:49 Well, you could not necessarily allow logging in with Twitter, but you could allow them to authenticate through it so that you could tweet on their behalf.
01:13:56 So it allows you to start connecting and play with all those things.
01:13:59 The plugin, the workflow is plugin.
01:14:02 Try that again.
01:14:03 The workflow is pluggable as well.
01:14:05 So there's hooks inside of the signup process.
01:14:08 So let's say you've got some questions that you need to ask the user when they sign up, like extra information that Django doesn't normally have.
01:14:14 It's got a flow for that that helps you with it.
01:14:17 So really, really comprehensive library.
01:14:19 The only thing I find that's challenging with this really has nothing to do with the library itself.
01:14:24 It's just that third-party authentication tends to be messy.
01:14:27 You are always dealing with tokens and provider sites and all the rest of it.
01:14:31 And you're going to be...
01:14:33 Have you registered your OAuth application at...
01:14:36 Exactly.
01:14:36 ...AngelList?
01:14:37 Did you do it right?
01:14:39 Like, oh.
01:14:39 You're always going to be in this space of, did I screw it up?
01:14:42 Is it the token that's not right?
01:14:44 Am I not hooking the library incorrectly?
01:14:46 I always find it's a little finicky.
01:14:48 Now, once you get it going, it's fine.
01:14:49 But there, it does tend to be a little cumbersome getting there.
01:14:53 Yeah, it's a little magical in, like, the traditional sense.
01:14:55 Like, it can just work amazingly.
01:14:57 But if it doesn't, you're like, I just don't know what the incantation I'm supposed to give it is.
01:15:01 Because it's just not...
01:15:02 It won't.
01:15:02 It won't do the thing.
01:15:03 You're debugging something that is somebody else's responsibility.
01:15:07 So you're not getting a lot of information out of the host system, usually.
01:15:10 Yeah, and often it's encrypted and signed and, like, stuff doesn't match.
01:15:15 It's like, how are you supposed to know how it doesn't match?
01:15:17 Anyway, but, I mean, that's the story of OAuth.
01:15:20 OAuth 2, not this library's problem, right?
01:15:23 The library makes it a lot easier.
01:15:25 It's just, like you said, there's still a level that is painful.
01:15:29 It swims in complex water.
01:15:31 One thing that is kind of nice here is you can unroll your OAuth as well.
01:15:35 You can say, I did originally sign up on GitHub, but I just want to make a password from my account now.
01:15:41 I'll let you drop that out, which is, I think, kind of cool.
01:15:43 I think it was a very smart architectural decision to continue to use the Django authentication mechanism underneath.
01:15:48 It means, from a support standpoint, you don't have to worry about a lot of things.
01:15:53 You can still see them inside of the admin.
01:15:55 You're not having to worry those pieces.
01:15:56 And like you said, if something goes wrong with somebody's Facebook account, you don't lose anything.
01:16:01 You basically, you know, they can send you a support email and you can send them a password reset off of a primary account and rehook them up another way, which is a thing of beauty.
01:16:10 Yeah, that's great.
01:16:10 All right.
01:16:11 Well, I would say we're a little over time, but it's been a super interesting list to talk through with.
01:16:15 So maybe call it a wrap on however many topics we came up with.
01:16:19 A whole bunch of cool ideas for doing more with Django and Python web apps in general.
01:16:24 So thanks for that.
01:16:25 Happy to do it.
01:16:26 Yeah.
01:16:26 Now, before we get out of here, I've got to answer the two questions.
01:16:29 Well, I've answered one of them already.
01:16:31 You're going to write a code.
01:16:33 What editor do you use?
01:16:35 Yeah.
01:16:35 So I'm Vim.
01:16:36 And for those who are taking the course, I used PyCharm there.
01:16:39 So you don't have to understand antiquated.
01:16:40 Speaking of magic, you don't have to follow along there.
01:16:43 So I did use PyCharm there, but Vim is still my standard.
01:16:46 And then notable PyPI package.
01:16:48 It can be any one of these you want to give a shout out to.
01:16:50 We've really kind of answered that question a bunch of times.
01:16:53 But if you want to give a shout out to something else as well.
01:16:55 I got something else for you, which is Ascii Maddox.
01:16:57 So I do a lot of TUI work and I'm really keen on this library.
01:17:02 They have a bunch of form widget stuff and also a whole bunch of cool, awesome 80s style
01:17:08 animation bits and pieces.
01:17:09 Core developer is a guy named Peter Britton.
01:17:12 Very responsive.
01:17:13 Always looking for MRs.
01:17:15 So yay, Peter and Ascii Maddox.
01:17:17 So if you're into this space, this is definitely something to check out.
01:17:20 Wow.
01:17:21 Amazing.
01:17:21 Yeah, it looks pretty awesome.
01:17:22 All right.
01:17:23 Great example.
01:17:23 All right.
01:17:24 Final Call to Action, so many of the things that we've talked about here, if they're
01:17:28 interesting, people want to learn how to actually use them.
01:17:30 Grappelli, create your own admin command, a bunch of other stuff covered in your course.
01:17:35 So check that out over at talkpython.fm.
01:17:38 Just click on courses, find the Getting Started with Django course.
01:17:40 Well done on that.
01:17:41 Thank you so much for coming here and sharing all these.
01:17:45 You know, maybe give a final call to action.
01:17:47 People want to get started with these ideas and bring some of the material to their apps.
01:17:51 What would you say?
01:17:52 I think a lot of it depends.
01:17:53 You know, anytime I'm trying to learn something new for me, it's always about the project,
01:17:56 right?
01:17:57 So if I, you know, if you're doing something that needs the REST API, then, you know, Ninja
01:18:01 or DRF might be the place to go.
01:18:02 If you're, you know, if you just want to play a little bit, then, or you're learning more
01:18:07 about how Django works, the debug toolbar is a fantastic way of sort of learning some of
01:18:13 the internals and taking your Django to the next level, because it's exposing a bunch of
01:18:16 that stuff that you kind of think you know how it works.
01:18:19 Yeah.
01:18:19 It's a nice little place of doing a tutorial.
01:18:21 So those might be good places to start.
01:18:23 Yeah.
01:18:23 That's cool.
01:18:24 The framework tries to hide a lot of that stuff.
01:18:25 The toolbar will like reveal it what's going on, right?
01:18:28 Yeah.
01:18:29 Well, as good framework should, but every once in a while, you want to see the guy behind
01:18:32 the curtain.
01:18:33 So that's right.
01:18:34 All right, Chris.
01:18:35 Well, thank you so much for being here.
01:18:36 It's been a whole lot of fun.
01:18:37 Enjoyed it.
01:18:38 Yeah.
01:18:38 Same.
01:18:39 See ya.
01:18:39 Cheers.
01:18:39 Cheers.
01:18:39 This has been another episode of Talk Python to Me.
01:18:44 Thank you to our sponsors.
01:18:45 Thank you to our sponsors.
01:18:45 Be sure to check out what they're offering.
01:18:47 It really helps support the show.
01:18:48 You care about the ideas behind technology, not just the tech itself.
01:18:52 And you know that tech has an enormous influence on society.
01:18:55 So check out the IRL podcast.
01:18:57 It's hosted by Bridget Todd.
01:18:59 And this season of IRL looks at AI in real life.
01:19:02 Listen to an episode at talkpython.fm/IRL.
01:19:05 Starting a business is hard.
01:19:07 Microsoft for startups, Founders Hub provides all founders at any stage with free resources
01:19:13 and connections to solve startup challenges.
01:19:16 Apply for free today at talkpython.fm/founders hub.
01:19:21 Want to level up your Python?
01:19:22 We have one of the largest catalogs of Python video courses over at Talk Python.
01:19:27 Our content ranges from true beginners to deeply advanced topics like memory and async.
01:19:32 And best of all, there's not a subscription in sight.
01:19:34 Check it out for yourself at training.talkpython.fm.
01:19:37 Be sure to subscribe to the show.
01:19:39 Open your favorite podcast app and search for Python.
01:19:42 We should be right at the top.
01:19:43 You can also find the iTunes feed at /itunes, the Google Play feed at /play,
01:19:48 and the direct RSS feed at /rss on talkpython.fm.
01:19:53 We're live streaming most of our recordings these days.
01:19:56 If you want to be part of the show and have your comments featured on the air,
01:19:59 be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
01:20:04 This is your host, Michael Kennedy.
01:20:06 Thanks so much for listening.
01:20:07 I really appreciate it.
01:20:08 Now get out there and write some Python code.
01:20:10 I'll see you next time.