Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #239: No module named pythonbytes

Return to episode page view on github
Recorded on Wednesday, Jun 23, 2021.

00:00 Hello and welcome to Python Bytes, where we deliver news and headlines directly to your earbuds.

00:05 This is episode 239, recorded June 23rd.

00:09 It's almost the end of June. Wow.

00:10 2021. I am Brian Okken.

00:13 I'm Michael Kennedy.

00:14 And I am Nick Moore.

00:16 Welcome, Nick. Thanks for joining the show.

00:18 Before we jump in, tell me a little bit about yourself.

00:21 Yeah, sure. So as I said, Nick Moore.

00:24 I'm based out of Ohio and I work as a data engineer, Trimble Transportation.

00:30 It's a software company aiming to like revolutionize the way we supply the world and like simplify and connect like the world supply chain.

00:38 Like it tries to make it easier to move goods and freight all around the world.

00:43 I'm also the co-organizer of ClePy, which is Cleveland's Python meetup group.

00:49 Thank you, Michael, for sharing it up on the screen.

00:52 So, yeah, that's a bit about me.

00:54 Nice. I enjoyed Cleveland when we were there for PyCon.

00:57 Yeah, I think I met you guys there.

01:00 Cool.

01:00 I think you guys were in the JetBrains.

01:02 That's right. We were.

01:04 It was really great to be in Cleveland for a couple of years.

01:07 And I guess we just completely missed Pittsburgh.

01:09 But they're going to get another round out of here as a redo, which is cool from COVID.

01:14 I got a chance to speak at the Cleveland Python meetup and talked about memory.

01:20 Was that right?

01:21 Yeah.

01:21 You talked about how Python manages memory.

01:24 It was like a really cool deep dive into that.

01:26 Yeah.

01:26 Thanks.

01:27 That was super fun for having me.

01:28 Now it's good to have you on our show.

01:29 Yeah.

01:30 So was that on purpose?

01:31 Did you make a joke that you couldn't remember what the talk was about?

01:34 No.

01:36 I know how my brain might store the memory of what I spoke about, but I just, it could have been that or async and I wasn't 100% sure which one it was.

01:44 We did talk about async too, though.

01:47 Cool.

01:48 Yeah.

01:48 Yeah.

01:49 For sure.

01:49 Speaking of async, Brian, you see what databases tells us about it.

01:52 Well, this is object relational mappers also.

01:57 So we have ORMAR, which is an async mini ORM for Python, which supports Postgres, MySQL, and SQLite.

02:07 This was a suggestion sent to us by John Hagen.

02:13 So thanks, John, for sending this in.

02:14 And I actually haven't played with this a lot.

02:17 I was looking around.

02:18 It looks pretty neat.

02:18 But I'm going to quote John here.

02:20 He says, it's a really cool ORM that combines Pydantic models and SQL models into a single definition.

02:27 What is great about this is it can be used to reduce the repetitive duplication between the models for an ORM and the Pydantic models for that FastAPI needs to describe serialization.

02:40 So I guess you do have to specify that twice normally.

02:43 Yeah.

02:44 Normally what you do is you would have the data model, the classes that do the exchange on the API level.

02:51 So those would probably be Pydantic.

02:53 But maybe then you have something like a SQLAlchemy model.

02:56 And then somewhere in the middle, you've got to copy the SQLAlchemy data over to the Pydantic model, send out over FastAPI and you get it back.

03:03 Then you've got to copy that from FastAPI and Pydantic back into SQLAlchemy.

03:08 Because SQLAlchemy types are not really meant to be transferred on the wire.

03:11 You don't get the open API documentation that you get from Pydantic integration and all those sorts of things.

03:17 So that's normally what happens.

03:18 But if your database model can also be a Pydantic model, then you don't do that back and forth.

03:24 Yeah.

03:24 And anytime you've got duplication, it's like that dry issue of just you're going to mess it up sometime.

03:30 It's going to be wrong.

03:31 And I think that's why SQLAlchemy, I think in version 1.4, they've been playing around with a lot of ideas on how to integrate data, not Pydantic, but data classes and the ORM style base models.

03:49 Four different propositions of how that should be done, but it's not yet perfect.

03:54 So I think that's something that it looks like they could learn from Omar here.

03:59 Or at least it's good to have these sort of experiments going on for everybody to look around and see how do we move forward so that we can do this cleanly.

04:07 Yeah.

04:08 The one thing I will say is that with all of these ORMs, I don't know why they never give some love to SQL Server.

04:15 I always see Postgres, MySQL, and SQLite.

04:18 But like SQL Server is pretty cool too.

04:20 Where is the support for that?

04:23 What's SQL Server?

04:24 So that's like Microsoft's, you know what?

04:28 I think it really matters what audience you're addressing, Nick, right?

04:36 So if you're talking startups and a lot of the open source crowd, yeah, it's all Postgres.

04:42 Or, you know, if you're talking to Michael, it's all MongoDB, right?

04:45 But if you're talking to enterprises, boy, oh, boy, do a big bunch of those enterprises run on the Microsoft stack.

04:53 Yeah.

04:54 Windows, Windows Servers, Microsoft SQL Server.

04:57 And that's a non-trivial amount of the use cases for these things.

05:02 So I agree that it should get some attention, even if it's not necessarily the one that the maintainers or many of the people are most keen to use.

05:10 Yeah, and I agree.

05:11 It was a joke, but one of the things I wanted to point out that John mentioned is that one of the benefits of Ormar is there's a quick start specifically for FastAPI.

05:25 So you can look at the documentation and there's a FastAPI quick start on how to get this running with FastAPI.

05:30 What an interesting combination of descriptors from the ORM class side and Pydantic models you get here.

05:40 So for this, we have like the Pydantic model-based type of thing.

05:45 We've got the columns specified with type information that Pydantic would use, but then you set them to things like an integer column that's a primary key or a string that has a max length setting and things like that.

05:56 Yeah, it's like the worst of every world.

05:58 But it's better than repeating stuff, right?

06:03 So, yeah, interesting.

06:05 Yeah, I think it's pretty good.

06:06 And Nick, you mentioned SQL, Alchemy, and Data Classes.

06:11 Pydantic also has some integration for working with Data Classes as well.

06:15 So maybe there's a way to bridge those things across for like FastAPI and similar situations as well.

06:21 I haven't tried that, but it's possible.

06:23 Yeah, let's see.

06:24 Out there in the live stream, we've got Sam Morley.

06:25 Hey, Sam.

06:26 Says, this looks a lot like a Django ORM.

06:28 Yeah, absolutely.

06:28 It really does.

06:30 And then Dean is hoping that we'll get some support for a very important database, AccessDB.

06:35 That and, oh gosh, what was it?

06:39 DB2 and a couple of the others.

06:40 Yeah, there's some really important ones that we might be forgetting, but I think it's going to be okay.

06:44 Oh man, Access, that gives me PTSD from college.

06:47 I can imagine.

06:50 I can imagine.

06:51 All right.

06:52 Well, speaking of people who might be getting some trauma, let's talk about NoModuleNamed.com.

07:01 In fact, it's now its own website.

07:03 You used to think of it as like an error, and now it's actually a service.

07:08 So error explanations of a service, I guess, is what you would call it.

07:11 All right.

07:11 So Garrett Dune pointed out that there's this website called NoModuleNamed.

07:17 And it looks super plain.

07:18 And I went to it like, what is this?

07:20 It has 3,626 packages.

07:24 And, oh my goodness, like 2 million modules or something like that.

07:28 And it has 151,000 package install guidelines.

07:32 So for example, what if I'm working with HTTPX?

07:34 And I get the message that says, Python error, no module named HTTPX.

07:39 Right?

07:40 This is what you would have if you wrote import HTTPX and you went and tried to run it,

07:44 but you were new and you didn't realize there were external dependencies or that HTTPX wasn't

07:49 built into the standard library, you would get that error, right?

07:52 Yeah.

07:53 So this tells you how to fix it.

07:55 It says, oh, this is probably because you don't have the package HTTPX.

07:58 Let's see if I can go something like FastAPI.responses.

08:03 Is that a thing?

08:04 And what will it tell me if I try, oh, no such module.

08:07 Yeah.

08:08 But so NumPy, for example, it'll give you a lot of these and it'll tell you, this is

08:13 probably because you don't have the package NumPy or NumPy MIPS64 installed.

08:19 So that's what I was looking for is if it would sort of show like, well, the package name is

08:23 not exactly what you're looking for.

08:25 So maybe BS4, right?

08:28 Sometimes there's these modules that, yeah.

08:30 So for example, if I say BS4, it'll say, oh, it's because you don't have, if you have

08:34 the error, no module name BS4, it's because you don't have beautiful Super 4 installed,

08:38 right?

08:38 So it's more than just like, duh, pip install the thing that there's no module of.

08:42 It tries to help a little bit more with understanding that and it tells you how to get the latest

08:47 version.

08:47 It tells you how to install it.

08:48 So yeah.

08:49 And there's even a related article.

08:51 Extremely beautiful like SEO on that with people just Googling error messages as well.

08:57 Yeah.

08:58 So pretty, pretty interesting.

09:00 Garrett Dunn, thank you so much for sending that in.

09:03 It's simple, but you know, these kinds of things can help people who are new and are getting

09:08 in.

09:08 And I think one of the powers of Python is we have people coming from all these different

09:13 backgrounds and experiences, and they are not all computer science people that know about

09:17 package managers and like love that.

09:19 They're just like, oh, I know that I can do cool.

09:21 I can like load this file and make a picture out of it that I need to work on.

09:24 But I get this stupid no module named this.

09:26 What is this?

09:27 Right.

09:27 And then they can, you know, these kinds of things can help.

09:29 Yeah.

09:30 Well, I'm trying to teach my 11 year old some programming and we started with packaging.

09:34 Yeah.

09:34 We didn't.

09:35 I know you started with virtual environments and then packaging.

09:39 Yeah.

09:41 Brian, I thought you would have started with testing first.

09:44 Yeah.

09:44 I always test first.

09:45 Yeah.

09:46 I think this is like a really, this is like a really cool project.

09:50 I find it's like a really cool thing.

09:51 I find it super useful when I'm working on projects related to GUIs like Qt or Phoenix.

10:00 No, no.

10:00 WX Python.

10:01 Because like those packages come with so many underlying dependencies.

10:06 And sometimes you might miss one or might miss something that like is an OS dependency that you don't know.

10:12 I feel like this could help you out.

10:13 And I've run through this a few times where like I'm using like a package that is built on top of Qt.

10:19 But then it tells me you don't have PyQt GT.

10:23 PyQt 5.

10:24 Right.

10:24 Exactly.

10:25 Well, I like that.

10:27 I think you probably already mentioned this, but the error message is the module not found.

10:33 That's often not the same.

10:35 It's not the same name as the thing you pip install.

10:37 Yeah.

10:39 Like one that drives me crazy is DateUtil.

10:41 I love DateUtil.

10:42 I think it's like magic for the pain of parsing dates.

10:45 But that's not what you install.

10:47 You install Python underscore DateUtil.

10:49 Right.

10:49 And so there's just, it's those situations where you're like, why is there no DateUtil?

10:53 I pip install DateUtil.

10:55 And then it's not even the right thing.

10:56 Or, you know, it's just, yeah, I think it's helpful to sort of put those things together for people.

11:01 Yeah.

11:01 And for people doing new packages, don't do this if you can.

11:04 Even if you have the perfect name for your package, maybe come up with something else that you can actually, it's available on PyPI.

11:12 Yeah.

11:13 Yeah, for sure.

11:13 All right.

11:14 Nick, you got the next one, right?

11:15 Yep.

11:16 I got the next one.

11:18 So I was looking through Jupyter.

11:23 So I'm going to get, as I said, as a data engineer, I often use Jupyter for like data wrangling and just trying out how to like clean up some kind of data before I actually do the actual cleaning in our data pipeline.

11:37 And so I stumbled, I got the new iPad.

11:39 And I was, I went, I went to like tinkering around with like Python code and I was like researching into how to do that.

11:46 And I stumbled across Jupyter light and I was like, okay, cool.

11:49 Jupyter light.

11:50 But sometimes I'm not going to always going to be connected to internet using my iPad.

11:55 And then I looked deeper into it and it's a, Jupyter distribution that runs entirely in the browser.

12:02 And it's like built from the ground up using Jupyter lab components and extensions.

12:07 And that's cool.

12:09 And the, and the kernels that are available are like in the browser.

12:14 So like there's a Python kernel that is like in the browser and it's built using PyIodide.

12:19 That was like really cool to see.

12:21 and there's also like, I think there is a, where is it in the user guide, there are other kernels such as, yeah.

12:31 JavaScript and P5 JS, which I think is like a graphics library to build like things on canvas, but it was really cool to see like it's supports Python 3.8.

12:42 And, you get like start session.

12:45 You can run Python code, Python completion, which is really cool.

12:50 It's interesting.

12:50 They call the, the kernel Pyolite.

12:53 Pyolite based on PyIodide.

12:56 Yeah.

12:57 And this is, I pulled it on.

12:59 This is how it looks like.

13:00 And it looks pretty cool.

13:02 So it also supports, right.

13:04 I think for now it supports Altair and, I think Matplotlib as well.

13:10 I think.

13:10 Yeah.

13:11 Matplotlib.

13:12 And so like open up this Altair notebook.

13:17 it even has something called Micropip.

13:20 which is like, I don't know what this means, but if you're, it, I think it means that it's, like, is a package manager, but for the browser for Python, which is interesting.

13:32 Oh, and it's, it's, it's, asynchronous because it's JavaScript basically.

13:37 Right.

13:37 So it's a wait micro pip installed like Jinja2, or Altair or something like that.

13:42 How interesting.

13:42 That's very cool.

13:44 I think it also, everything that you download and everything that, all the data that you, like, load up,

13:52 it's being stored in the browsers, like local storage or some other, I don't know, indexed DB.

13:59 So it's, like, self-contained.

14:02 The only thing I noticed is that right now, it's not, what was the word here?

14:09 A PWA.

14:10 Yes, I was just thinking it would be fantastic if that was a progressive web app

14:15 and then you could just have it in mostly offline mode, yeah.

14:18 Edge does a great job with PWAs and every time it detects, like, a manifest adjacent

14:25 to show you, do you want to install this app?

14:26 And I would just love to have, like, just click install and then have Jupyter Lite wherever I go

14:32 or load it up on my iPad and then disconnect and still be tinkering around with what I want.

14:36 So this is all browser-based.

14:38 So that's really cool.

14:39 I'm not going to run any of these, but I encourage everybody to check this out.

14:43 It's pretty cool.

14:44 Yeah, yeah, this is really cool.

14:45 I do the same thing with, I use Brave.

14:47 So I have, like, a YouTube app installed on my Mac and I've got a Twitter app installed.

14:54 All is progressive web apps, so you can just launch them.

14:56 I do wish Firefox supported that.

14:58 Firefox, people, if you're listening, bring back the progressive web app.

15:01 We all need this.

15:02 Yep.

15:03 Yeah, that's cool.

15:03 What are some of the other notebooks in there that look cool?

15:05 Are these, like, demo ones or did you create these?

15:09 Yeah, there's a demo one.

15:10 So there's a P5JS one.

15:13 There's the Altair one.

15:15 I don't know what Folium is.

15:16 There's the interactive widgets, which is cool.

15:19 So it still uses Jupyter's iPython notebook widgets, Matplotlib.

15:26 Oh, Plotly as well.

15:28 Nice.

15:29 And Plotly, cool.

15:30 And so this is a de facto, like, Pyolite one.

15:33 So it supports Matplot, Pandas.

15:36 That's cool.

15:37 It supports LaTeX as well.

15:39 Yeah, it's great.

15:40 And so, like, as I was saying before, Pyolite is, what is it?

15:46 It's, like, implementation of Python on the browser.

15:51 Actually, implementation of Python is on the computing stack on the browser.

15:56 So I think things like Pandas, NoobPy, SciPy, SciCutLearn are already, like, available.

16:02 It's within the Pyolite ecosystem.

16:05 So you don't have to...

16:05 Yeah, I had the guys behind it, you know, Firefox and Mozilla were behind it originally, at least.

16:10 And I had them on Talk Python.

16:12 I believe it's WebAssembly based.

16:14 I think what they did is they took all these major visualization libraries and things like Pandas and NumPy

16:20 and compiled them all into a Python plus those WebAssembly thing that runs in the browser.

16:26 instead of a JavaScript version, which is pretty awesome.

16:28 Oh, even Symbol.

16:29 Yeah, the symbolic output, like, got the math symbol integral of the square root of one over XDX.

16:35 Beautiful.

16:36 I wonder if you could get hand calcs on it.

16:38 Oh, yeah.

16:39 Awesome.

16:42 Cool.

16:43 All right.

16:43 Well, that's a really good one.

16:44 I love it.

16:45 All the data scientists out there can definitely enjoy that.

16:48 Yeah, cool.

16:49 What do we got next?

16:51 I think you're up next.

16:52 Oh, right.

16:53 Okay.

16:54 So next, we've got...

16:56 More plotting, maybe?

16:57 Yeah, more plotting.

16:58 So this is a long title.

17:02 Basically, it's lots of plots.

17:03 There's eight popular graphs made with Pandas, Map, Plotlib, Seaborn, and Plotly Express.

17:11 And I've seen a lot of articles and stuff talking about how to do different plots in one or more of these.

17:19 And a lot of them are...

17:20 A lot of the articles, and rightly so, are focused on something cool you can do with one library that you can't do with others.

17:26 And I've seen Seaborn ones like that.

17:29 And that's great.

17:30 What I like about this article is it's like, well, let's just take these different pandas plotting and Map, Plotlib, Seaborn, Plotly Express, and do the same plot.

17:42 Let's do something they can all do.

17:44 And so that's what this article does.

17:46 It does a whole list.

17:49 You've got normal line charts, grouped bar charts, stacked bars, pies, a whole bunch of things, and histograms.

17:57 And then you can just compare to see what it looks like before you try.

18:01 And for one, it's got the output, what do the graphs look like, which is important.

18:08 But also, it's a fairly simple article.

18:11 It's talking about what the plots look like, but also how do you make them?

18:14 It's in a Jupyter Notebook Viewer.

18:18 And it shows you what's the code look like to get these plots set up.

18:23 And I think that's a big part of choosing your plotting library is looking at the API to see what kind of API looks comfortable to you.

18:30 Yeah, I've got to write this code.

18:32 Will I be able to remember this?

18:33 Yeah.

18:34 Or will it be like regular expressions and I learn it every time I use it?

18:37 Yeah, or if you get stuck with one and you want to switch to other to sort of look at what the deltas are.

18:42 I like these side-by-side apples-to-apples comparison sort of articles.

18:46 So I think this is good for choosing the simple parts of plotting.

18:50 But some of the comparisons are sort of funny because the bar charts just kind of all look the same.

18:55 That one's orange versus orange and blue versus green and blue.

19:02 It's not all the same.

19:03 Yeah, but you get down into some of the fancy ones and they do look great.

19:08 Some of the area charts.

19:10 Yeah, that one looks great.

19:12 What's that?

19:13 Polly Express area charts look awesome.

19:15 Yeah, the area charts look good.

19:17 And I didn't know what a donut chart was.

19:20 A donut chart looks like a pie chart with a hole in it.

19:22 Yep.

19:23 Why do people use that?

19:24 I think it's because of like with the pie charts, the sectors are kind of, it's kind of, sometimes it can be hard to see like how much width.

19:35 No, like, yeah, the circumference of like this sector.

19:39 So maybe the donut chart kind of makes it easier to see like, okay, this takes like all of this.

19:44 It's just a visual thing, to be honest.

19:46 Yeah.

19:46 Okay, good.

19:48 Nick, this is your world.

19:49 What do you think?

19:49 I think this is really cool, but to be honest, all of these APIs don't compare to the grammar of graphics from R.

19:57 And so I usually, if I am going to do graphics in Python, I would prefer to use something that like conforms to the grammar of graphics.

20:07 Because to me, that's kind of, you know how like Python has the import this and it's all philosophy of how to write Python.

20:16 The grammar of graphics like has that.

20:18 So it has like, gives you these like sentences, so to speak, to build graphics.

20:23 And I was like, that makes so much sense in my head.

20:25 So like for graph, for graphing lab reads, it's either Altair or ggplot.

20:30 And there is like a Python port of ggplot that's pretty good.

20:36 But I think Altair is like the Pythonic de facto version that I've used.

20:40 That's really nice.

20:42 All the other ones that make me have to do like, like, like, like, do these method calls on objects.

20:50 Just, I can't, I can't remember it.

20:52 I have to come back to something like this.

20:54 So how do you use gnm.lib?

20:56 Are you using Seaborn?

20:57 I really like the fact that like Seaborn has a lot of one liners to like do simple charts in one line, which is great.

21:05 Like with the grammar graphics, right?

21:06 It still makes you have to build everything out.

21:08 But if I'm building something really custom or I am just building something that I have, I want to have complete control over.

21:18 The grammar graphics just gives me a better way of like remembering what to do compared to having to remember all this API, all this API, all this method API calls.

21:27 Well, I mean, the author, Dylan Castillo, says, let me know what you think.

21:32 So maybe we can give him some feedback to add Altair and a couple others.

21:37 Oh, yeah, that'd be cool.

21:38 Dean also has some thoughts out there, right?

21:41 Oh, Seaborn and Pandas use Matplotlib in the backend.

21:44 So you can do everything they can do with Matplotlib.

21:47 Okay, maybe harder, but not impossible.

21:49 And also, that's probably why they look all the same.

21:51 They are the same.

21:55 Turtles all the way down.

21:56 And he also says, remember, kids, almost every command in Matplotlib returns the object it charts.

22:01 That's the start of OOP, object-oriented plotting.

22:04 All right, right on.

22:05 Oop, it'd be two Ps.

22:07 Oop, oop, oop.

22:08 I don't know how to pronounce that.

22:10 All right, well, Brian, you got to talk about databases.

22:14 So I'm going to talk about databases, too.

22:16 But my databases are going to be smaller and in-memory and embedded, but also about MongoDB.

22:22 So there's this really cool one created by David Latwi called MontyDB.

22:28 So it's a Monty.

22:31 It's a MongoDB tiny-ified.

22:34 So it's MongoDB implemented in Python.

22:37 And you can have it in process, kind of like SQLite, I believe.

22:41 We've covered a couple of these libraries that are starting to show up that let you do sort of embedded MongoDB, which I think is really neat.

22:48 So it's inspired by TinyDB and its extension TinyMongo.

22:52 So the way you work with it, it's super simple.

22:55 You just import the Monty client.

22:57 And if you want to go crazy, you could say as Mongo client and make it basically the same.

23:01 And then you can give it connection strings like colon memory colon.

23:04 That should look familiar from something like SQLite.

23:07 And then you can insert data to it, do all sorts of things, and do queries against it, run the MongoDB query syntax against it, and you get the responses back, which I think is pretty cool.

23:18 It's certainly interesting for testing.

23:20 If you told it to use a file storage, it could be an interesting little embedded database and things like that.

23:27 So pretty cool.

23:28 It supports many of the MongoDB versions up to 4.2 and 4.4 on the way with wave emoji.

23:34 I'm not really sure about that, but also supports the...

23:38 What's that?

23:38 I think it's sweat.

23:39 Oh, gotcha.

23:41 Like the work is being done.

23:42 Gotcha.

23:42 So you can pip install MontyDB, and it will work in sort of its way.

23:49 If you want to use the actual serialization library from MongoDB itself, you can say install MontyDB bracket BSON to install that as well.

23:59 And it also has a lightning memory map DB, LMDB library.

24:05 You can use that as the storage engine as well.

24:07 So you can pip install, you know, add that on as well.

24:10 So for the storage, you've got in memory, you've got a flat file.

24:13 It'll actually use SQLite as a back-end store, which is pretty cool.

24:16 And then that LMDB lightning memory mapped DB.

24:20 So this looks pretty neat to me if you're going to do some kind of embedded thing or you're going to do some testing and you want something lightweight that's not a separate server you've got to set up and run and all those kinds of things.

24:32 This is cool.

24:33 I think it's awesome.

24:35 Could you make this a pytest fixture, Brian, that just gives you, like, presets up your database and gives you access to the connection or something?

24:41 Yeah.

24:42 I mean, actually, I'm not really a fan of people switching their databases too much for testing because most modern databases have in-memory options or smaller version options.

24:52 But, I mean, we use SQLite for tons of stuff that's not just for testing.

24:57 And if you've got SQLite at the back-end, there's no reason why this couldn't be a production thing then.

25:02 Yeah, absolutely.

25:04 No, this is really cool.

25:05 This could be really useful for, like, CLI apps that need to store your things.

25:11 Yes, exactly.

25:12 You want to have a little thing, but you don't want to say, oh, you want to run my little utility I packaged up with Py2 app or Py2.exe or something?

25:20 Yeah.

25:20 You're going to need to install MongoDB and become an admin of that.

25:23 No, you just use, like, a SQLite file as the back-end store or the LMDB version.

25:29 Another thing that's common from the MongoDB world is there's a set of CLI tools that allows you to manage it.

25:35 So I can connect to it.

25:37 I can import a bunch of exported files from some other or backed-up files from some other MongoDB instance and import that into my current server or whatever or create those exports, right?

25:51 There's actually a bunch of utilities called Monty Import, Monty Export, Monty Restore, Monty Dump.

25:57 All of these are the parallels of Mongo, Mongo Dump, Mongo Restore, and so on, right?

26:04 So if you were used to working with MongoDB, it's not just explicitly that there's some API to talk to some file.

26:11 There's also, like, the tools that are there as well.

26:13 Yeah.

26:14 Yeah, I don't know.

26:15 I think that could be a cool project.

26:17 So why don't I make this mostly for just fun and practicing on it, but also need it to run in this limited little environments for, like, render farms in the film industry.

26:26 So that's pretty cool.

26:27 It's a side project also with render farms.

26:33 It's a side project for my supercomputer, yes.

26:35 I love the name, by the way, Monty, Monty Python.

26:40 I love it.

26:40 Yeah, I mean, yeah, it really brings the MongoDB wordplay in with Monty Python, Python origin.

26:47 Yeah, pretty cool.

26:48 All right, Nick, you got the last one.

26:49 Awesome.

26:52 Exhaustiveness checking with mypy.

26:54 So essentially what exhaustiveness checking is, is a feature of, like, a lot of type checkers where they guarantee that the programmer has covered all their cases.

27:06 And so with mypy, you could essentially check things, like, whether you've covered all the, like, you have written all the if statements you're supposed to write at compile time rather than figuring that out at runtime.

27:22 And, like, I really got into using mypy and trying to, like, have it save my bot a lot in the way I think about code by embracing types.

27:34 So I stumbled across this, which was, like, really interesting, where this article written by Haki Benita went into how, like, exhaustive net checking actually works.

27:46 So they start out with an enum that has order status.

27:51 And you have a function that is called handle order that takes a status, which is an instance, which should be an instance of order status.

28:01 And so in his function, he has this, like, if status is order ready, you do something.

28:07 If status is order shipped, you do something.

28:09 But then he gave this, like, added this, like, new, like, scenario where what if you wanted to check the status of something scheduled?

28:20 And so he tried to run mypy right now.

28:23 I didn't complain about it.

28:24 So it was like, okay, cool.

28:25 Yeah.

28:26 Because one of the things that's very common is if you have something like a set of cases, in this case, it's put together in an enumeration.

28:32 Yeah.

28:33 You have more cases over time.

28:35 But all these if, else if, else if, else if statements all over your code, have you exhaustively gone through and added that case check for all of them?

28:44 Probably not.

28:45 Yeah, probably not.

28:46 Unless you've got good tests.

28:46 A really good test.

28:47 Yeah.

28:48 Okay.

28:49 And so he proposed, like, one quick way of checking that you handled all cases is by adding this assert false, comma, unhandled status.

29:01 And you pass in the status using f-strings.

29:04 And so then when you try to pass a state that you have not actually handled before, you actually get assertion error, right?

29:12 Which is all right, but if you use mypy, there's this clever trick where you create a function called assert never that takes a value called no return and returns no return.

29:26 And in it, it has the assert false unhandled value.

29:29 And so then when you use that function in your handle order function, at the end case, you have this else assert never and you pass in the status.

29:41 Now when you check with mypy, mypy will know, hey, argument one to assert never has incompatible type, literal, order status schedule, expected, no return.

29:50 Oh, how interesting.

29:52 Yeah.

29:52 And this is a compile time and you can actually get this.

29:54 Yeah, yeah.

29:55 That's, I think that's the important thing because I was looking at that going, oh, I could just add the else statement and put the assert there and have nothing to do with mypy and it would catch that error.

30:03 But that catches that error when that code runs.

30:06 Like I said before, you know, hopefully there's tests, but oftentimes there's not tests for everything.

30:10 Yeah.

30:11 Yeah.

30:11 And so especially there might not be a test for the new thing you've added.

30:16 And so this is cool in that it checks all the possible types that could go in there.

30:20 That's cool.

30:20 Yeah.

30:21 Yeah.

30:21 Yeah.

30:21 And the part that really got me was that it integrates with your IDE.

30:27 So PyCharm, VS Code, or any editor that implements a language server can then like look at this and say, hey, you haven't handled all your cases.

30:37 Right.

30:38 And you get that immediate feedback rather than having to run your code and then find out, oh, dang it, I missed this case.

30:45 Right.

30:46 Yeah.

30:47 So people who are not looking at the live stream YouTube stream, which is almost all the people listening.

30:52 Nick is showing on the screen this assert function that's checking the numeration.

30:59 And there's just a red squiggly line that literally says assert never has incompatible order status that's scheduled.

31:05 That's the missed enumeration case.

31:08 I think that's incredible that actually finds this.

31:10 Yeah.

31:10 And it works because mypy uses this technique called type narrowing.

31:18 And essentially what that means is that it would, given a variable as it goes through like a control flow, like if statements, switch statements, my loop, mypy will like kind of confine or in other words, narrow down the types as it goes through those control flow.

31:39 And so it works with enumeration types, unions, literals.

31:45 So I have in the article, there are examples of how you could pass in a union of different types, strings, float, and you could still use this technique and to tell you, hey, you've missed a case.

31:57 Or you could do this with literals.

31:59 So you have like RGB and then you only implemented the, you only check for like two cases, which are R and G.

32:07 And then to tell you, hey, you did not handle the B case.

32:11 So yeah.

32:12 And so like the article goes further into different ways in which you could set this up.

32:18 Have mypy check all of the different cases for you, which is really cool.

32:23 You've even got like the, the, the various sweets for cards, like clubs, diamonds, hearts.

32:29 Yeah.

32:29 It's interesting that like to mypy, when it sees an enum that has like clubs, diamonds, hearts, and spades, all it sees is like a union of literals, which are sweets, cards, sweet clubs, sweet hearts, which is actually interesting.

32:45 That's how mypy sees it.

32:46 Yeah.

32:46 That's very interesting.

32:47 I mean, basically it's emojis.

32:49 Yeah.

32:49 It's emojis.

32:51 Right.

32:52 The one other thing I wanted to mention here is that there was a specific, oh yeah.

33:00 This feature is actually something that Guido actually thought was pretty cool.

33:07 And so I think it's part of a PEP 622, a structural pattern matching already.

33:12 So if you are matching against an enum or something that has like multiple different like states, the matching, hopefully Python 310 will give you a nice error saying, hey, you missed a particular case.

33:28 And this could really, and if you're a Django developer or you just use Django or even, yeah, you just use any ORM and the ORM provides something like choices where like yes, no, or dollar, euro, like these kinds of choices in the field.

33:45 This works pretty well.

33:46 And so in your Django code, you could actually have mypy telling you, hey, you missed handling a particular case.

33:53 Crazy.

33:54 Yeah.

33:54 That's awesome.

33:55 Yeah.

33:55 Which is really cool.

33:56 Yeah.

33:57 Sam out in the live stream was sort of on to the same thoughts you were talking about with Peter there.

34:01 I wonder if one could hack on the match mechanism to deliver this functionality at runtime using by somehow getting all the variants of the enum and checking the branches, the AST or something.

34:13 Yeah.

34:13 That's interesting because I know that part of the structural pattern matching, like any object can implement the magic method match.

34:24 And maybe that's like, yeah.

34:28 And maybe that's your gate, like that's your entry point into providing that kind of checking at runtime.

34:31 Of course, with Python, anything that is around runtime checking, there's like performance costs with that.

34:39 So be careful.

34:40 Yeah.

34:41 But having this built into mypy already would be good.

34:44 And Juergen is talking about it on the live stream.

34:48 He says, I wonder whether you could rewrite the code to not use if statements at all,

34:52 but be more polymorphic, which I agree.

34:56 It's a really interesting idea with the method overloading and stuff.

35:00 And it reminds me back a couple of weeks ago, Brian talked about function overloading

35:05 with single dispatch and multiple dispatch.

35:06 And yeah, you could kind of more or less make that happen there.

35:10 So yeah, pretty neat.

35:11 Although you still may miss a case.

35:12 I'm not entirely sure.

35:13 At least in the enumeration bit, that won't help you, right?

35:16 Because the enum will still be the same type.

35:18 It'll just have more values.

35:20 Yeah.

35:20 Awesome.

35:21 Good one, Nick.

35:22 Brian, what else we got?

35:23 Well, I've got a couple of things.

35:25 One of the things I wanted to note was that this is the second week in a row

35:30 we've featured an article by Haki and the third in this year.

35:36 So we should probably try to get him on the show or something.

35:38 Yeah, absolutely.

35:40 That sounds good.

35:41 He's doing some good writing.

35:42 So thanks.

35:43 The other thing I wanted to mention is I've got...

35:48 Oh, yeah.

35:49 By the way, my book is out.

35:50 Yay!

35:52 This is the book, too.

35:54 Yeah.

35:55 Second edition of pytest is available for beta.

35:57 So people can tell me everything that's...

36:00 I already got it.

36:01 Somebody said they have got an issue.

36:03 It's a minor issue with it already.

36:06 So thanks.

36:08 But it's just been me and my editor so far working through it.

36:11 So having more people, more eyes before we go to shipping the physical book would be great.

36:16 So, of course, this is through Pragmatic.

36:19 But if you go to pytestBook.com, it'll take you there.

36:23 So that was my extra.

36:24 Right on.

36:25 Cool.

36:25 I've got a couple as well.

36:26 Yeah, I got some neat ones here.

36:28 So how often do you maybe have like a blueprint floor plan?

36:32 Maybe you're looking at a house and you're trying to decide whether you want to buy it.

36:36 What would it be like to actually live there?

36:39 Maybe you're trying to figure out, well, I'm planning out this apartment or I have this place.

36:43 I want to remodel it like IKEA it all out or something along those lines.

36:47 I ran across this thing that uses some interesting models called plan to scene.

36:53 So the idea is it'll take what is literally a floor plan, like a blueprint floor plan that shows like swinging doors and bits.

37:01 And then you tell it what kind of room it is.

37:03 It's like a bedroom or a bathroom or whatever.

37:05 And it will generate a 3D world that has things like sinks and toilets and couches that are three dimensional, not just somehow projected in there.

37:16 So there's all of these interesting things you can see.

37:19 If you pull up the site, there's all these like spinning worlds.

37:21 And you can see that they've created these little environments just from floor plans, which I think is pretty insane.

37:27 So anyway, you can go ahead, Nick.

37:30 No, that's really cool.

37:32 And I think I wonder if like, because like Trimble, we, we own like SketchUp.

37:36 I wonder if they do this kind of stuff.

37:38 They take floor plans and then they make it 3D.

37:42 That's really cool.

37:43 Yeah.

37:44 There's a whole bunch of comparisons of how it used to be done, how you can pick like different, you know, different flooring and walls and source codes available on GitHub.

37:53 People can run with that.

37:54 So that's pretty cool.

37:55 It's called Plan to Scene.

37:56 And then just a quick shout out to this TCAS podcast I happen to be a guest of recently.

38:02 And we got to talk about Python and data science and how Python and data are sort of changing the world and stuff.

38:09 And it's really fun.

38:09 So people can check that out.

38:11 Yeah.

38:11 And that's it for the things I got.

38:12 Nick, anything else you want to throw out there?

38:14 Yeah.

38:14 Just a shameless plug.

38:16 As I said earlier on the live stream, I co-host the Clipi, which is Cleveland's area Python meetup group.

38:26 And so we have meetups every second Monday of the month.

38:31 And one of the reasons why I would encourage anybody across the world or U.S. or everywhere to still come and present is because oftentimes meetups are a great place to present talks that you are planning on giving.

38:48 And maybe like continental conferences or like other larger conferences, you know, smaller crowd.

38:56 And, you know, we show you guys a good time.

38:59 Right.

38:59 So it's a great place to come, give your talk, get feedback from that, and then, you know, take and improve on it.

39:06 So that's one.

39:07 And then the other shameless plug is that Pye Ohio has its own conference coming up on July 31st.

39:19 Registrations are open.

39:20 We have pretty cool T-shirts.

39:21 So, yeah, register.

39:23 And that's a, is that live or streaming?

39:26 Yes, that is being streamed.

39:29 Okay.

39:29 How about your meetups?

39:30 Are those being, are those streamed or live?

39:32 Those are virtual.

39:33 We used to have them like in person.

39:35 And that's, I really, that's when like.

39:37 And then it really messed things up because you have stuff like pizza over and those have a good time talking about Python.

39:43 But no, the virtual setting has given a lot more people access.

39:48 You know, we're able to have more people on.

39:51 So.

39:51 Nice.

39:52 Yeah, that's fantastic.

39:53 And Pye Ohio is definitely one of those big regional conferences that a lot of people pay attention to, even if they're not in Ohio.

39:59 Definitely.

40:00 Are you going to go back to in-person only?

40:02 Are you going to do like a hybrid stream and in-person or is it going to be, what's your plans for when the world returns to normal?

40:09 That's if it ever returns to normal.

40:11 I think we'll change forever.

40:14 But to answer your question, I think my co-organizer and I have been thinking about them.

40:20 We don't, we're not yet set yet.

40:22 Like we see the benefits of the virtual, but we also see the benefits of the live.

40:27 And there are things that have changed so much.

40:29 We don't even know whether the live person is still available.

40:33 But no, it's something we're thinking about.

40:34 Yeah.

40:35 Cool.

40:36 Well, it's a challenge.

40:37 I think all the meetups and other events are having, especially these smaller, like monthly, biweekly sort of things.

40:44 Yeah.

40:44 You know, it's one thing to say that there's going to be a big conference and we'll all go to it or not.

40:48 But you're doing it every couple of weeks and it's mostly local, but not 100% local.

40:52 Yeah, it's a challenge.

40:53 Yeah.

40:54 Fantastic.

40:55 All right.

40:55 Brian, you ready for a joke?

40:57 Definitely.

40:58 Okay.

40:58 So I've got one and then Nick has one.

41:01 So this one, the title of the joke is Root Beer Float.

41:04 Okay.

41:05 So a programmer walks into a bar.

41:07 He orders 1.000000119 root beers.

41:13 The bartender says, I'm going to have to charge you extra.

41:15 That's a root beer float.

41:17 The programmer says, well, in that case, make it a double.

41:20 It's bad, right?

41:22 That's bad.

41:24 Yeah.

41:24 All right.

41:25 And Nick, you've got one as well.

41:27 You want to do this one for us?

41:28 Yeah.

41:28 Would someone like to joke?

41:30 You want me to be the bearded person?

41:32 Yeah, I really have something going on there anyway.

41:34 All right.

41:35 So will refactoring the code improve the loading time?

41:39 Not really.

41:40 Will it improve the security then?

41:42 No.

41:42 So it's for browser compatibility?

41:45 Yeah, no, not really.

41:46 Nope.

41:47 So tell me, why is it always the same old story with you guys wanting to refactor everything

41:53 I need to know?

41:55 Because as devs, if we know, excuse me, if we know we've left behind some messy code,

42:01 we can't stop thinking about it.

42:02 We wake up in the morning at lunchtime in the evening when we go home and when we're trying

42:07 to go to sleep.

42:08 It haunts us.

42:09 You know, it haunts us.

42:11 I love it.

42:14 And it's true too.

42:15 It's totally true.

42:18 It's totally true.

42:19 All right.

42:19 I have one more joke for you guys.

42:21 Oh yeah.

42:22 Hit us.

42:22 All right.

42:23 How much does a chimney cost?

42:25 No idea.

42:26 Nothing.

42:27 It's on the house.

42:27 Very good.

42:31 That's, I have a friend that is so, so into dad jokes, which is weird because it's only

42:36 22.

42:37 Practicing.

42:41 Practicing for the future.

42:42 Yeah.

42:43 I don't think dads can be blamed for all bad jokes.

42:46 Anyway.

42:50 Yeah.

42:50 I want to highlight, Juergen, says that they cost 2,500 euros.

42:55 That's expensive.

42:56 Well, thanks a lot for joining us today.

43:00 this was a lot of fun and, thanks everybody in the stream for showing up and, we'll talk

43:05 to everybody next week.

43:07 Thanks.

43:07 Bye everyone.

Back to show page