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


Transcript #225: SELECT Pydantic FROM MongoDB

Return to episode page view on github
Recorded on Wednesday, Mar 17, 2021.

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

00:05 This is episode 225, recorded March 17th.

00:10 I'm Brian Okken.

00:11 - I'm Michael Kennedy.

00:12 - And I'm Sebastian Pitofsky.

00:13 - Yay, we have a special guest.

00:14 - Yay.

00:15 - Welcome, Sebastian.

00:16 - Thanks, I'm excited to be here.

00:17 Huge fan of the show.

00:19 - Thank you, thanks so much.

00:20 - Should we kick it off?

00:21 - Yeah, yeah.

00:22 Also, I wanna say thanks to Linode for sponsoring this episode.

00:24 And Brian, I've heard of people getting like smaller computers, Raspberry Pis, and things like that.

00:29 but you've got, you're taking it to some crazy extreme here.

00:31 Is that what's happening?

00:32 - Yeah. - What's going on here?

00:33 What is this thing?

00:34 - The Pico.

00:35 So actually this, I saw this announcement on Twitter.

00:39 It's actually came out in January, but we haven't covered it yet.

00:43 It's kind of exciting.

00:44 The Pico is four bucks for, and I know they have a $5 little chip also, or a little controller, but this is really like in microcontroller land, which is, it's really pretty cool.

00:57 It doesn't have a lot, like there's no wifi on it.

01:00 There's not a lot on it, but there's also not a lot on it.

01:04 So it's very low powered.

01:06 So really microcontroller size.

01:08 One of the exciting things about this is this is, I think this is the first Raspberry Pi with a chip designed by Raspberry Pi.

01:16 So this is a custom Raspberry Pi chip.

01:20 And what do they call it?

01:21 Oh, I can't remember.

01:23 RP2040 is the chip that goes in.

01:26 It means anything to anybody.

01:28 But the low power thing is what I think is fascinating.

01:32 And it's because there's some things that you can even--

01:37 you can power LED lights and stuff with it, even.

01:41 And there is enough power to do quite a bit with peripherals.

01:46 But you also can-- since it's so low power, this will be good for things like temperature sensors and other sensors that you leave alone someplace.

01:55 And a microcontroller that you can like leave somewhere and then come pick up later, and that you can control with Python is something new.

02:06 And that's pretty exciting.

02:07 - Yeah, that's super cool.

02:08 And apparently it's coming soon also is the Arduino Nano Connect, which comes with a nine axis IMU and a microphone, a powerful wifi and Bluetooth module.

02:22 and a crypto chip and stuff like that.

02:24 So that'd be kind of cool as well, right?

02:26 Like put this thing on wifi and whatnot.

02:28 - Yeah, and one of the other things I forgot to mention, this is the first Raspberry Pi product that has an ADC on it.

02:35 So with that, you can do, it isn't just like, you can do analog input, so you can, you know, more accurately hook up a temperature sensor or something.

02:47 - Oh, right.

02:48 So if you're working with, like, this is your IoT thing and you want to just work with like plug in a voltage meter or whatever, right?

02:54 Yeah, okay, super cool.

02:55 - Yeah, so that's pretty exciting.

02:56 And anything that drives people working with a combination of hardware and software together in a nice language like Python, very much appreciated.

03:07 This is an exciting part of the Python world.

03:10 I also want to mention the editor Mew that can be found at CodeWithMew.

03:17 And I don't have this up here, But they released, they're working on the 1.1 version and the beta two is out.

03:25 And one of the things that supports is this Pica board along with some of the Lego spike products and a whole bunch of new fixes.

03:33 So, especially when we're working with microcontrollers and students, that's a nice thing to have.

03:39 - Did you mention the price?

03:41 - That is $4.

03:42 - Yes. - Yeah, that's amazing.

03:44 - That is so awesome, right?

03:46 So yeah, later on in the announcement, they've got like this picture of them, like wrapped up, like a whole, like a reel of these.

03:54 I think they're trying to encourage people to buy like a whole bunch of them at a time.

03:58 - It's like a candy wrapper, but you get a computer instead.

04:01 - Yeah, that's pretty great.

04:03 - Really good, I love it.

04:04 That's as good as our jokes.

04:05 Sebastian, what do you think of this thing?

04:08 - I never actually got into Raspberry Pi and all this programming hardware.

04:13 I actually bought Raspberry Pi like years ago and it was in my drawer until one day I decided to put a pie hole on it to get rid of the ads.

04:21 And it's been working flawlessly since then.

04:23 So I have raspberry pie somewhere there, but I'm impressed to see how they are dropping the price.

04:28 Like $4, it's like extremely affordable.

04:31 - Yeah, that's really, really wild, that thing.

04:33 - Pretty awesome.

04:34 Also, Brian, a comment.

04:35 Paul Sanders in live stream says, "Can you use Ubuntu on Pico like a regular, regular raspberry pie, or is it like its own thing?" - I'm pretty sure it's its own thing.

04:44 I don't think it has a full operating system on it.

04:46 - Yeah, it describes itself as a microcontroller, right?

04:49 - Yeah.

04:50 - So it's like more like MicroPython, Adafruit, AdaCircuit Python, so on.

04:55 Yeah, it would be cool, but yeah, I don't know.

04:56 It's pretty small, $4.

04:58 - Yeah, I think it is running MicroPython, but I'm not sure.

05:01 - Yeah, yeah, yeah, very cool.

05:02 All right, well, I wanna talk about something brand new for the next item here, and that is Beanie.

05:07 So I came across this yesterday, and actually I had some other thing I was gonna cover.

05:11 I'm like, no, no, no, Beanie's cool.

05:12 I wanna talk about Beanie.

05:13 I'm pretty excited about it because I was recently talking with a friend of mine about, oh, what would you use with FastAPI and MongoDB?

05:21 Well, the traditional ORMs, ODMs, they don't call them ORMs in Mongo because they don't map relations, they map documents.

05:29 So they call them ODMs, object document mappers, but same idea.

05:32 I was talking with him and saying, you know, it's like, well, what would you use with FastAPI?

05:36 'Cause you really wanna leverage the async and await nature of the views, which is so easy to do there and whatnot.

05:42 But I started looking all the old standbys that I like, Mongo engine and some of the others, the ORM, ODM side don't seem to be really supporting the async and await world.

05:54 You start looking around, well, there's motor, which is the official async library from MongoDB, the company, the organization to support this.

06:02 But the way you program there is I run a query as sort of almost like SQL syntax and I get back a Python dictionary, which is okay, but I don't really like that style.

06:12 Really like getting a class back, be able to do queries with the class, have the class have like types and constraints and whatnot.

06:18 'Cause if you're just working with dictionaries, it's so easy to like forget to set it.

06:21 I know a field you didn't remember existed or something weird like that and get inconsistent data.

06:26 So I ran across this thing called Beanie, which is an async friendly ODM for MongoDB.

06:32 And we've talked a lot about Pydantic.

06:35 Pydantic's awesome, right?

06:36 - Yeah. - Yeah.

06:37 So with Beanie, it basically takes and uses Pydantic models as the classes that map to the database.

06:44 And I think that's just super cool.

06:46 - Very cool.

06:47 - Yeah, so let me see if I can pull up some examples here.

06:50 So the idea is that with the document databases, you can embed stuff.

06:54 So I might have one class that's containing a list of other classes I define, and that just is a record in the database.

07:01 So the way it works with Beanie is you create anything that derives from base model.

07:06 that means it's a Pydantic model with all the validation and loading and stuff that you get from that world.

07:11 And then you have a top level document that derives from this beanie.document, which is really just a specialization of a Pydantic model.

07:18 So everything you do with Pydantic happens here.

07:20 And then you actually just work with the motor async driver, which is the official in quotes way to talk to MongoDB asynchronously from Python.

07:29 And then you can create a class, embed your objects, hit save, you can go and just go to your document and just say insert one as a class, insert many, you can do filters, you can do like get by ID, or you can say do a find query or something like that.

07:45 So yeah, I think it's pretty neat that it allows you to take this sort of blended, it's like half ORM, ODM, and half sort of just working directly with the MongoDB API.

07:56 And yeah, it's pretty neat.

07:58 One of the big notable things that I feel like gets kind of missing is it doesn't support creating and managing indexes through this object model.

08:07 But I was talking to the guy who created it, Roman Wright, on GitHub, and he's like, "Yeah, that's a good idea.

08:12 "It's like one of the next things I'm thinking about." So pretty cool.

08:15 If you're doing stuff with MongoDB and you like Pydantic, here's an exciting new project that people can check out.

08:21 It even has capabilities for the aggregation model, which is like map, reduce, plus sort of that kind of processing, which often doesn't show up in these ODMs.

08:31 So people can check it out.

08:32 It's growing.

08:33 It was almost brand new yesterday, and now it's up to 25 stars.

08:36 So it's not super, super popular, but it's like 25 times more popular than it was yesterday.

08:41 So that's pretty cool.

08:43 It's on a good track.

08:44 - I got a question about indexes.

08:45 So if you, even if it didn't support it, could you go around and just request them anyway?

08:50 - Yeah, no problem.

08:51 You could go to like Motor and do it in Python.

08:54 Say create index at this, you know, like it's not create, it's ensure index, like create if does not exist index during app startup, or you just literally could go to the database and actually use some management tool and create the indexes there.

09:06 So it's not like you can't use indexes.

09:08 It's just like, if you're defining the whole model, it would be cool if it could just happen as part of the class definition.

09:14 As many things do, like SQLAlchemy does that, Mongo engine does that, right?

09:18 It's a pretty standard paradigm here.

09:20 So I don't know.

09:21 What do you guys think?

09:22 - I kind of really like the idea of having an ODMB, like this hybrid model of like, it's not really taking over, hiding Mongo because Mongo's actually not that hard to deal with anyway.

09:33 It's adding some of these class wrappers and giving you a lot of the power of Mongo at the same time.

09:39 - Yeah, for sure.

09:40 And you can see like actually the document or the blog post that announces this rather than the GitHub repo has a few examples and they're all fast API.

09:47 Like you have an asynchronous API endpoint and then you await note.create, which saves it.

09:54 Or you can await like a query.

09:57 Let me see if, yeah.

09:58 Anyway, you can await queries and things like that, which is the really cool thing.

10:02 So pedantic plus async and await, pretty neat.

10:04 - Yeah, that's pretty cool.

10:06 Especially the list of features that you show, it's pretty impressive for such a new project.

10:10 - Yeah, yeah, this guy Roman, apparently he comments in here, like this is something I've been using for myself for a while and it's really awesome.

10:17 So now I'm just sort of putting it out there.

10:19 Hopefully it grows from that.

10:20 So that's pretty cool.

10:21 - So you work with async more than I have.

10:24 Is this something that I could, if you want, like to start playing with it, would you have to jump into the async world or could you use Beanie without async stuff?

10:33 - You know, I hadn't really thought about it.

10:35 Looking at it, it looks like it has to be async.

10:39 Right, because the queries, like the find one, create and so on, they all are awaitable.

10:44 They're all being awaited.

10:46 And I don't see a way, just quickly glancing at it, to say, don't be that, you know what I mean?

10:51 Like I don't see how it's both at the same time.

10:53 And if it is, you probably have to use it.

10:56 So I'm guessing actually you do have to use it as NSAsync, but I don't know for sure.

11:02 I haven't tried it well enough.

11:04 It's a good question.

11:05 All right, well, speaking of good stuff, something I've talked about on Python, but not on Python Bytes.

11:11 So Sebastian is gonna tell you guys about something over there, right?

11:15 That we talked about over there.

11:16 - Yeah, so I wanted to talk about a tool that I have been using for a long time.

11:19 And I know that you, Michael, are familiar with it because you already covered-- - I'm a huge fan of code quality, refactoring, all that kind of stuff.

11:27 Having your editor tell you, "This could be better.

11:29 Press this button to make it happen." - Yeah, exactly. That's why I absolutely love this tool because it's one level above, let's say, linters.

11:38 When you're using PyLint or Flake 8, you get some warning saying, "Look, this is wrong." And then there is Sorcery that tries to make your code better.

11:47 It gives you refactoring tooltips just as you type.

11:50 So for example, if you scroll a bit down there, there is some GIF showing what it can do.

11:55 And for example, if you have like an if statement and both branches have the same statement, you will get a pop-up saying that, look, this can be moved outside.

12:05 Or for example, when you have like a for loop, you will get a recommendation saying, hey, this can be turned into a list comprehension.

12:12 So I really like it.

12:14 And it integrates, I think, with PyCharm and VS Code.

12:17 So I don't know about Vim.

12:19 I don't think there is any support right now for stuff like that.

12:22 And it's super easy to use because you just got a pop-up and you can click, "Yes, I want to have this refactoring." You can see the diff of how it will look after the refactoring.

12:33 And yeah, also, it's free to use, at least in the code editor.

12:39 I think they have the pricing tab, but I think you can pay to have analytics for your project and set it up with like continuous integration servers and stuff like that.

12:50 But for like VS Code and PyCharm, it's free to use.

12:53 Yeah, it looks like you get a couple of extra refactorings and whole project analysis for money.

12:59 Yeah, but like the basic refactorings that can already help you a lot, they are there for free.

13:04 And at least for me, I just keep getting constant pop-ups saying like this code can be refactored.

13:10 So I mean, maybe I'm a terrible programmer, but sometimes I'm like tired and I don't see something.

13:15 So it's nice to just click one thing and have like three lines of code turn into one line.

13:20 So that's pretty awesome. I don't know. Yeah. Brian, have you used it? Because I know that Michael had. I haven't used it yet, but I'm pretty excited. It looks pretty fun.

13:28 Yeah, it looks really neat. And like I said, I did interview the guys over there on the show about what they're doing. And I believe that all the like one of the things that some people have worried about is these kinds of tools sometimes, you know, especially the ones that try to use like AI ML to help you. I don't think that this is one of those. They'll end up sending and I think this is all just local stuff, which is nice.

13:49 - Yeah, I guess that was one of my questions.

13:51 I often run, you know, I often do a lot of coding on my laptop with it, with no wifi connection or anything.

13:58 Can I, does this help at all?

14:00 - I'm pretty sure, I don't think it makes any, I don't think it uses the internet to do its magic.

14:03 So I think it's all just in the editor and PyCharm or RPS code.

14:06 Yeah, I'm pretty sure that's the case.

14:08 But the one thing, so I used this for a while and I liked it.

14:11 The one thing that drove me crazy and possibly it's been fixed, is there's one or two recommendations.

14:17 Like a lot of the recommendations it makes are great, but there's one or two that I really didn't like.

14:22 I think, for example, I was using a guarding clause.

14:25 So I would say, coming in method, the very first thing is like, if something's wrong, return and there's an error, and then go do the thing I was really wanting to do.

14:32 So it's not indented.

14:33 I really like that style.

14:35 And it was suggesting that I like include, like I reverse that if, so I don't have as many, as much cycle, not cycle, as many decision points, right?

14:44 there's not as many branches as going on there.

14:47 And that's fine, I just don't have to accept it, it doesn't automatically do it.

14:50 But it constantly was highlighting that with like squiggles as if something was wrong in my editor.

14:54 And other tools like PyCharm do that.

14:56 You could just say, you know what, for this thing, please don't tell me that this is the fix 'cause I really want this to be here for reason X, Y, and Z.

15:03 I couldn't find a way to do that in Sorcery and it was driving me crazy.

15:07 I'm like, no, this is not wrong, please like stop telling me it's wrong.

15:11 So I really hope, you know, if they're listening, Maybe you could hint and add like a hash ignore sorcery line type of thing like all the other editors have.

15:20 But yeah, no, I do think it's a cool tool and people should check it out if it sounds interesting.

15:25 - Yeah, it'll be nice to have this configurable, stop complaining about this refactoring.

15:30 - Right, or either I would even be happy to just say, please don't tell me about, 'cause it was like very specific, like one very small suggestion, like just don't suggest that to me ever.

15:40 Like I don't ever want that.

15:41 But everything else you do, I love you, thank you.

15:43 (laughing)

15:45 - Nice, yeah.

15:46 John Sheehan has a comment.

15:48 Some code efficiency improvements could end up obfuscating intent.

15:52 Absolutely, for sure, they definitely could.

15:54 I feel like a lot of what it's suggesting actually is a clarifying change.

15:58 It's like, look, you're duplicating this code or this is overly indented.

16:01 Here's how you change it so it's not.

16:02 So I feel like on that regard, Sourcery is really good.

16:05 - Yeah, same, I have the same feeling.

16:07 Like it doesn't try to give you like very quirky refactorings.

16:11 it's actually tries to make your code easier by like removing redundant lines and stuff like that.

16:17 - Yeah. - Very good point.

16:19 - But a tool like this that could make it more obfuscated.

16:22 Now there's something that we can find.

16:23 - There's job security right there, baby.

16:25 - Yeah, yeah.

16:26 - Command + Alt + L, reformat for.

16:28 - Reformat for Brian. - Exactly.

16:31 I know we can work on this project, but so and so.

16:34 Quickly reformat it to viewable, work on it and re-encode it.

16:37 Perfect. - Yeah, that'd be cool.

16:39 - Yeah.

16:41 Something else that's awesome is Linode.

16:43 - Thank you, Linode.

16:44 - Thank you for sponsoring the episode.

16:46 Simplify your infrastructure and cut your cloud bills in half with Linode's Linux virtual machines.

16:51 Develop, deploy, and scale your modern applications faster and easier.

16:54 Whether you're developing a personal project or managing larger workloads, you deserve simple, affordable, and accessible cloud computing solutions.

17:02 As a listener of Python Bytes, you'll get a $100 free credit.

17:06 You can find all the details at pythonbytes.fm/linode.

17:10 Linode has data centers around the world with the same simple and consistent pricing regardless of location.

17:16 That's cool.

17:17 Choose the data center nearest to your users.

17:19 You also receive 24/7/365 human support with no tiers or handoffs regardless of your plan size.

17:26 You can choose shared or dedicated compute instances, or you can use your $100 credit on an S3 compatible object storage, manage Kubernetes, and more.

17:35 If it runs on Linux, it runs on Linode.

17:37 pythonbytes.fm/linode and click on the create free account button to get started.

17:43 Absolutely. You know what I like about Linode? It's like straightforward and simple.

17:46 I go to places like AWS, I'm like, what is all this stuff? And why am I like so deep in the permissions of AIMs in order to send an email over here to connect? Like, it's just, ah, like, I just want to create a server, make it go. Let's do that.

17:58 Nice. Are we there?

18:01 We're there.

18:01 We're there.

18:02 We're there.

18:03 Okay.

18:03 We're on to your next item, I believe. Wait.

18:06 No, we're not, we're, I'm jumping ahead.

18:07 We're on to my next item.

18:08 So I'm going to feel back that.

18:10 So I'm on a database kick for some reason this week.

18:14 I mean, I love databases, which is weird because when I first learned them, they seemed so challenging and odd and I'd struggled with them, but I don't know.

18:20 I just really enjoy thinking about databases because they, they're like the magic of your application, right?

18:24 A really slow clunky database.

18:26 We'll just like bring it down.

18:27 But a really nice polished one is like, how is that so fast and smooth?

18:31 Like I really like working with this site.

18:32 So one that I haven't spoken much about, and honestly don't have a ton of experience with, but I do think is an interesting consideration, is another branch of the NoSQL world in graph databases.

18:43 So instead of modeling columns, you're really modeling entities and then their relationships.

18:49 Like the relationship thing is first class thing.

18:52 You can query by relationships, instead of querying by data and then like joining and so on.

18:56 So a popular one for this is Neo4j, and there's some nice ways to talk to it from Python and there's this, I don't even know what to call it.

19:05 Oh GM, I guess is the right.

19:06 And so I said, Oh, DM for object document mapper.

19:09 So in the graph world, it's O GM for object graph map.

19:12 So there's an object graph mapper called Neo model.

19:15 And I ran across this and I'm just like, Oh, this is super cool.

19:18 So the idea is that you can basically create these classes.

19:21 And if you look at how you do it, it's if you've ever used Django or RM or Mongo engine or something like that, it's literally the same thing.

19:29 So if you know, if you know Django or RM, you basically can do this.

19:32 which is powerful because it gives you a whole different way to work with data and a whole different option without rethinking the world.

19:38 So I could create, say, for example, a country, which is derived from structured node, and then just like Django, you would say code equals instead of string column, you would say string property, and it has a, an index, the index is uniqueness, the field is required, boom, that's it.

19:52 Like one line field and it's defined.

19:54 Then a person person might have a relationship back to a country and so on, and really, really neat the way you just sort of define this, and then you can do interesting queries on it.

20:04 You can ask like, give me the nodes where, the person nodes where the name is Jim.

20:10 And that's pretty simple.

20:12 Or you can say, give me the nodes where the age is greater than three or whatever.

20:15 But also you can ask things like, give me the country.

20:19 So go Jim.country.

20:21 Is that connected to Germany?

20:22 Yes or no.

20:23 If it is, then Jim is from Germany.

20:25 Or you can go to Germany and say, give me all the inhabitants.

20:28 And it'll tell you all the people in there.

20:30 And you can even say things like, I would like all the people in Germany whose name is Jim.

20:35 So Germany.inhabitant.search name equals Jim.

20:37 Like an incredibly simple programming model to work with these graph databases.

20:42 So if you've got like really structured related data, but you wanna like follow those relationships around, you know, maybe Postgres is not the best option for that kind of data.

20:51 And this would be a good one.

20:52 Cool, huh?

20:53 Takes a bit of a mind bending getting used to it, but pretty neat.

20:57 - Yeah.

20:58 - Yeah, Sebastian, have you ever had to do anything with graph databases?

21:00 - No, but when I was looking at your code examples, I was thinking why there is Django code, and then you started saying, yeah, it looks similar to Django, and I was like, okay.

21:09 - Yeah, exactly, why is there Django code in my graph database?

21:12 But I think that's a huge benefit for the Python world, right?

21:15 Like a lot of people know the Django ORM model, or it's also the same as Mongo engine, which obviously is also inspired by Django's ORM.

21:23 And so a really straightforward way, like I think you could get up to speed in an hour if you knew Django, working with this thing.

21:29 It seems real straightforward.

21:31 >> So it might be cool to see somebody do an example where they did the toy example in a graph database relational in a document to see what the trade-offs and benefits and things that are.

21:46 >> Right. We've got that silly to-do app that everyone has used for JavaScript front-end frameworks to show like, here's how you build to-do in VueJS, here's how you build it in React.

21:58 I think having like this canonical database represent it like side by side, like here's the Postgres version, here's the Neo4j version, all in Python, that would be an awesome article.

22:06 Somebody had a bunch of time and desire.

22:09 - Yeah.

22:10 - Yeah, pretty cool, pretty cool.

22:11 Now you can talk about your item.

22:13 I didn't mean to shoot you too far ahead there.

22:16 - No, so I lost my window.

22:20 There it is.

22:21 So I've been thinking about, I don't mock much.

22:25 I, when I test, I try to test everything whenever I can, but I've been learning about mocks a little bit and mocking just because in some cases you kind of want to.

22:35 So as I got into it, I didn't get very far before I realized that specking was like, like something that people found out about later, but sounds sort of magical and I wanted to know more.

22:47 And I, and so I asked the Twitterverse, whoever follows me and stuff, If speccing is something that you should do always or avoid it, is there downsides?

22:58 And then one of the things that I got back was a Stargirlflowers article called my Python Testing Style Guide, which includes this incredible section on mocking.

23:10 And her section is, the section is called a mock must always have a spec.

23:15 And it's just a really, if you've ever wondered about this, It's a really good discussion about mocking because it's not their evil, and it's also not go run out and use them.

23:28 The recommendations really are use real objects for collaborators whenever possible.

23:34 But if you must mock, always use auto spec.

23:37 And so the idea around speccing or not speccing is if I create a mock object, it can be anything.

23:43 I can ask it for the date, I can ask it for the temperature of my coffee, I can ask it for anything or I can pass it anything and it'll accept it.

23:52 That's kind of what mocks do.

23:53 But if you say auto spec, you say, I want this thing to mock this other class and have auto spec be true.

24:01 It means I can't do anything to that class, that mocked class that I couldn't do to the real thing.

24:07 So all the interface is identical.

24:10 You can't do functions that aren't there.

24:12 And that's where I thought, well, that seems like a good thing and apparently it is.

24:17 - I think it's a good thing because you would like your test to at least require a thing behaves like the real thing, right?

24:23 It might not give the real data back, but you shouldn't be able to call functions that don't exist or access fields that don't exist and so on.

24:29 - And more importantly, one of the things that's highlighted in this article is, even if you could manually get it just right, later you might change the interface.

24:39 You might change the API call, add a function or add a parameter that's required or remove a parameter that's not needed anymore.

24:46 And your tests that use the mock that are custom built are still passing, but they shouldn't be.

24:53 And with AutoSpec, your test will fail at that point when the interface's break happens.

25:02 - Wait, you run your tests more than once?

25:04 (laughing)

25:05 No, of course, obviously, this is why you, one of the main values is this thing is locked down, I wanna be able to make dramatic changes to it and see that it hangs together.

25:15 And if things like rename a function has no effect on the test path, that's not so good.

25:20 - Yeah, and then there's a whole bunch of other great advice that she gives around mocking, talks about, consider using stubs and fakes, and even gives an example of what those are.

25:29 And basically it's like writing your own little tiny thing to substitute for the real thing.

25:36 And spies, which are cool, spies are like a mock wrapper around a real object.

25:40 So it behaves the same as it always did, but you can interrogate like how it was called.

25:44 That's kind of a neat thing.

25:46 And some advice that I didn't really consider before is to, the code, test code is way cleaner if you don't give the mocks special names.

25:54 Like a lot of people, if I wanted to mock Foo, I might kind of title it mock Foo.

25:59 And she says, don't do that.

26:01 Just name it Foo, then your code looks a lot cleaner.

26:04 And I tried it out and it does really great.

26:06 - Nice. - It does help out.

26:07 Anyway, great advice on mocking.

26:09 So if you're considering mocking, go read that.

26:11 - And if you're doing unit testing and you want to not test all of your dependencies, basically, if you don't want to do integration tests, you probably should be doing something like this.

26:19 - Yeah, I mean, I hardly ever use them.

26:21 I do things like rerouting my code through, like any, I kind of design it into my code if I have a chance.

26:28 Like for instance, if I need to have a, I know anything with a database, I know I'm gonna have to redirect the database during testing, so that's just built into the design of the system to be able to reroute that somewhere.

26:40 - Yeah, Sebastian, what do you think?

26:42 - Yeah, that's a bunch of good advice.

26:44 So that's a very good article.

26:47 And I kind of agree with you.

26:48 Like I also prefer to kind of like mock a specific method of a real object, not to create a mock and then add stuff around.

26:56 Although I think it's a different word for mocking a method.

26:59 It's a stab or one of those words.

27:01 I could never remember which one is which.

27:04 - Yeah, yeah, for sure.

27:05 And then Robert Robertson is getting philosophical here.

27:09 Says a mock must always have a spec.

27:12 Will they add that to the Zen of Python?

27:13 I don't know.

27:14 - In Python 4.0.

27:16 - Yeah, exactly.

27:16 These are two things that are very unlikely.

27:19 - Zen is not extensible.

27:22 - Yeah, possibly.

27:23 Oh, also Dean was asking if the episode started, the live stream started early today.

27:27 Hey Dean, daylight savings mismatched by a few weeks with the rest of the world, at least with Europe.

27:34 Yeah, exactly.

27:35 That's the story.

27:36 All right, speaking of time zones and stuff that's challenging, Speaking at conferences can be tricky 'cause it's virtual, you're not actually there.

27:44 So when does it really start?

27:46 Well, maybe at least we can know which ones are out there and when the call for proposals are done, huh, Sebastian?

27:50 - Yeah, so yeah, as you said, since the PyCon call for proposal acceptance emails will be sent this week, I was thinking about conferences.

27:59 And since it's 2021, most conferences are moving online, which is really cool 'cause, well, they are cheaper.

28:07 Well, first of all, tickets are cheaper.

28:09 A lot of them are free, then you don't have to pay for the accommodation, you don't have to pay for the ticket, you don't have to fly, so you don't have to take holidays.

28:16 So a lot of benefits.

28:18 And I was wondering, how do you find conferences to attend?

28:22 There is this list at python.org that lists some conferences, but it doesn't have the smaller local events, and you also don't have dates.

28:32 So you only have links to all the global, countrywide conferences, but you don't know when they are starting.

28:38 So I found this tool called Conference Radar, and it's a PyPI package that you can install, and then you get a command line tool that you can run to get a list of upcoming conferences, which is pretty cool, especially that you can have some parameters, like you can get a list of conferences that have opened the call for proposals.

28:59 So if you want to submit a talk, you can see which conferences are accepting those.

29:04 And I really like it that you get this nice ASCII table in the terminal, since I love CLI tools, this is really cool for me to use.

29:12 - Yeah, yeah.

29:13 I think these integrate some rich, even like fancier tables, but yeah, it's really nice.

29:17 - Yeah, but the downside is that they don't have that many conferences because it's using only a few data sources.

29:24 So when I was running it today, I couldn't find that many conferences.

29:28 And actually there was no call for proposal open, like no date was there.

29:33 So I hope it will improve, but so far this is my best tool to like find the upcoming conferences.

29:39 - Yeah, and if people are out there listening, they have a conference, they wanna get the word out about it, you know, might as well go add it to the data source that these things are using.

29:46 - Yeah, that would be awesome.

29:47 - Yeah, this thing's cool.

29:49 I checked it out.

29:49 One bit of confusion for me is if you look at the description, it says installation, you can simply use pip to install Conrad for conference radar.

29:58 So you can use pip to install Conrad, but you cannot pip install Conrad.

30:03 That will not work.

30:04 It may work.

30:05 If it does, you should maybe be concerned because someone heard the show and put something in.

30:09 You have to pip install conference-radar.

30:11 So I don't know, maybe just a little clarification for people who want to check this out.

30:15 But the command, the CLI is Conrad show, Conrad refresh, Conrad call for proposals, things like that.

30:22 You can even set reminders, right?

30:24 It'll like remind you when the call for proposal is closing.

30:26 - Oh, cool. I didn't see that.

30:28 That's nice.

30:28 - I think there's a remind feature in here.

30:30 I can't remember exactly how it works, but yeah, yeah, pretty cool.

30:33 - I'm glad that you mentioned that 'cause I just tried to pip install Conrad and I'm like, it didn't work, man.

30:38 - It's broken, what is this thing?

30:40 Yeah, I just think the documentation's a little unclear 'cause the CLI and the package name are not the same.

30:45 - At least you didn't get some malicious package.

30:47 - Exactly.

30:48 - Mining bitcoins right now.

30:50 - Exactly, why is my computer hot?

30:52 That's weird.

30:53 Oh well.

30:54 - Suddenly my camera turned on.

30:56 Oh no, we're doing a live stream, that's why.

30:58 - Yep, yep.

30:59 Oh, and also Dean has a quick comment for you there, Sebastian, oh, this is perfect and I think I maintain a Google calendar for conferences.

31:06 - Oh, cool.

31:07 - Yeah, that's a good idea.

31:09 - Yeah, I was looking for different sources where to get the conference information.

31:14 And so far the most reliable one is my friend Miro on Twitter who is submitting and speaking at a lot of conferences.

31:20 So I'm just following him and he's always speaking.

31:24 He's always tweeting.

31:25 So that's my best bet so far.

31:27 - I met him at PyCon Slovakia.

31:29 So yeah, I know he's at conferences often.

31:31 - Yeah.

31:32 Brian, is that it?

31:33 - That's it for me.

31:34 Do you have anything you want to share?

31:36 - Oh yeah, I almost have an extra, extra, extra, extra here all about it section to share, but not quite.

31:41 So I'll keep it a little bit quick here, but I'll go through some things.

31:44 First of all, quick announcement, Sebastian and I have been working for, as he hinted at, I don't know if this was on the recording or before we started, but for like six months on a project called Modern Python Projects, which is a follow-on sort of course version of the Modern Python Developers Toolkit thing we did over at Talk Python episode 279, I think.

32:03 So we've got this awesome course out at talkpython.fm/modern-python-projects or just click the link in the show notes and you can check it out.

32:12 That's been out for an hour and 10 minutes.

32:14 So not very long.

32:15 - This looks really cool.

32:16 I am excited about this.

32:17 - Yeah, a lot of neat stuff that Sebastian, this is all Sebastian's work that he put into it here.

32:21 So it's really cool. - Oh, you helped a lot as well.

32:23 - Thanks.

32:24 What would you like to, maybe, what do you think, quick thing to share, tell people about this course that you built.

32:30 Yeah, so basically my idea was to give you an overview of everything you need to know, even if you don't have Python installed on your computer, all the way up to actually building and publishing your project.

32:44 So basically we start by installing Python.

32:46 I show you how to manage dependencies.

32:48 I also show you how to set up VS Code for programming with Python.

32:51 Then we add test, then we add tools like linters, formatters, some static code analysis.

32:57 and we add the test documentation, obviously.

32:59 We talk about continuous integration.

33:02 There are like three sections where we build different projects and actually each of them is done in a different manner.

33:08 So for one, I use Poetry, for the other one, I don't use Poetry, so we have a comparison.

33:12 And all the way up to deploying, where I show you how to deploy, for example, to Heroku and how to create a Docker image.

33:18 And yeah, all spectrum.

33:20 - Yeah, that's cool.

33:21 I definitely like it.

33:22 So people can check that out.

33:23 That's a quick item there, just that we launched that recently.

33:26 And also Brian, our PythonBytes.fm looks very bright right now.

33:30 What do you think?

33:31 - Yeah, neat.

33:32 - So one thing I wanted to do, people have been contacting us and saying, "Hey, I heard you mentioned like, "oh, we just mentioned Dean's name on the live stream.

33:39 "What is this live stream?

33:40 "When is it?

33:41 "How do I find it?" So what I've done is I've updated the PythonBytes website and Talk Python for its live stream.

33:46 But for PythonBytes, if you go to PythonBytes.fm, if we're live streaming at that very moment, there's like a big red banner across the top.

33:53 Like we're live streaming right now, come be part of the show.

33:55 And then there's also a live stream menu item that'll take you over and show you like the live stuff that's happening.

34:01 And it'll basically show you the live playing stream but you can open that up on YouTube to be part of the live chat and so on.

34:06 So live stream now on the podcast page, if it's a podcast site, if you visit it and it's called Bright, you know, and you got a moment, go check out the live stream.

34:12 - Yeah, and then also if Michael's up to date on it, which he does all the work on this, I appreciate that.

34:20 We announced when the next one's gonna be.

34:23 So if you're not sure, you can just check it out anyway.

34:26 And there should be a link there to say when.

34:28 - Yeah, that's right.

34:29 So normally what I try to do is schedule the next one when we're done with this one.

34:33 So if people go there, they'll see the, like here's the next live streaming and YouTube has a button to say, set a reminder, tell me when this is happening.

34:39 Last time, I think I said, is Python on Mars?

34:43 Because that F plane, that flight overview system, it was using Python to train the models, but I think it's using C++ to fly the little helicopter thing.

34:51 And I just mentioned, if anybody knows Python's on Mars, that would be awesome because this is really cool and related, but it's not the same as Python on Mars.

34:59 So Bojack Norseman sent a tweet over and said, "Hey, Python Bytes, you guys asked for a confirmation.

35:06 "Linux Unplugged," the Linux podcast, has an interview with Tim Canham at JPL, where he talks about running various machines and mentions Python.

35:15 So the thing that he talked about is, remember when the thing was landing and there was the sky crane that like lowered perseverance and there were all these different camera views.

35:25 You could see the bottom flying away.

35:27 You could see it like shooting up dust and coming down.

35:29 There's all these views, like these onboard cameras.

35:31 Apparently all those were controlled and collected and like processed with Python on Mars.

35:35 So yes, Python is on Mars.

35:37 - Sweet.

35:38 - Following up on your item, Sebastian Gidevan Rassam has sent out, said that signups for the Python Language Summit at PyCon online only are now open.

35:47 If you represent a third party package want to have a say in Python's future, please sign up.

35:52 So if you have a third party package and you want to be part of this, please sign up, I'll put the link in the show notes.

35:56 Oh, wait.

35:57 Does a single pack, there's a single developer package qualifies a third party package.

36:02 Do you, do you want to have a say in Python's future?

36:05 They might not listen to you.

36:06 They're like, well, I'm going to talk to the guys that do flask and Jenga.

36:09 You can go get a seat in the court.

36:10 And I don't think people should listen to me.

36:12 Robert Robertson has a very nice, meme.

36:16 The snake has landed instead of the Eagle, right?

36:19 The snake has landed. Beautiful for the Python thing.

36:21 All right, Sebastian, anything else you want to throw out there real quick?

36:23 Yeah, I have a kind of a curiosity because I started using VS Code in a browser recently.

36:29 I started a new project and everyone on the team is using VS Code in the browser.

36:33 And it's working surprisingly well.

36:37 I would never try to use a code editor in a browser, like out of myself, never, because I need to have everything installed locally.

36:44 But now that I have to use it, I'm like super impressed.

36:46 Everything works smoothly and my experience is amazing.

36:49 So it made me think like, well, is this the future of programming?

36:53 It's definitely nice to have everything on the same page because it's like super easy to set up the same plugins, the same configuration for the whole team.

37:01 People don't have to install anything.

37:03 So, yeah, I'm wondering to see in which direction it will go.

37:06 Yeah, it's super interesting.

37:07 You know, I haven't done a lot of it, but it's probably using that thing where they said, well, this is an Electron app.

37:13 Let's take the UI bit and just move the back end farther away and put that in a Docker container or something.

37:19 I'm guessing that's how it ran, right?

37:20 It wasn't pure all JavaScript.

37:22 - Yeah, I think so.

37:23 But I was expecting some latency and nothing like that.

37:25 I mean, my only concern is that the browser is interrupting some keyboard shortcuts.

37:30 So whenever I want to close a tab in the VS Code, I'm closing the browser window because that's the same combination.

37:36 - That drives me crazy about the browser editors.

37:39 It's like, I'm editing, I'm editing, I wanna make this tab go away.

37:42 Oh, why is the whole thing gone again?

37:44 - Yeah.

37:45 - Yeah, I didn't know what to do about that.

37:46 - Yeah, I know that that's really cool.

37:47 And you know, it's really applicable for, like if you've got a class full of students and they have Chromebooks, and they can't install Python and VS Code on their Chromebook but they have Chrome, they're good.

37:56 They're good to go, right?

37:57 Or things like that, or an iPad that doesn't allow it.

38:00 So really neat possibilities there.

38:02 - Exactly, we have some custom libraries and they are already available on those virtual machines with VS Code.

38:07 So that's super easy to use.

38:09 - Yep, absolutely.

38:10 So Brian, I put together a joke for us, but we'll have to clean it up just a little bit for the air.

38:14 - Okay, I'm not reading it.

38:16 - I'll read it, I'll read it, I'll read it.

38:18 So I'll put it up here.

38:20 So it's a picture of some birds on a power line, right?

38:23 And they sort of often sit together in little groups, like I don't know why, they're hanging out on the power line, they've got incredible balance, and they're all just sitting there.

38:31 And there's one bird that's outside of the power line, it's like where the power line stops and goes down, the bird's just sitting there floating in midair.

38:38 And the other birds are looking, and they're like, how is he just, his wings aren't flapping, how is he just sitting there in midair, And they go, oh, he has a wifi.

38:45 But then the bird comes crashing down and he goes, the falling bird screams, oh, darn router.

38:51 I love it, I thought it was good.

38:54 It might not be totally safe for it, but it's good.

38:56 - Yeah, there's a lot of routers that aren't properly tested with Rogen Shorts equipment.

39:00 - Yeah, yeah, I mean, if you were floating suspended in midair by your wifi, then it stops.

39:05 That's a little risky.

39:06 - That's good.

39:08 Well, thanks Sebastian for stopping by and doing the show with us.

39:10 - Thank you for having me.

39:11 - It was quite a lot of fun.

39:12 Yeah, it was fun.

39:13 Thanks for coming.

39:14 Thanks, Brian.

39:15 Thanks for being here.

39:16 Thank you.

Back to show page