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


Transcript #247: Do you dare to press "."?

Return to episode page view on github
Recorded on Wednesday, Aug 25, 2021.

00:00 Hey there, thanks for listening. Before we jump into this episode, I just want to remind you

00:03 that this episode is brought to you by us over at Talk Python Training and Brian through his pytest

00:09 book. So if you want to get hands-on and learn something with Python, be sure to consider our

00:15 courses over at Talk Python Training. Visit them via pythonbytes.fm/courses. And if you're

00:21 looking to do testing and get better with pytest, check out Brian's book at pythonbytes.fm slash

00:27 pytest. Enjoy the episode. Hello and welcome to Python Bytes, where we deliver Python news and

00:32 headlines directly to your earbuds. This is episode 247, recorded August 25th. Really? Oh,

00:39 we're almost done. In 2021, I'm Brian Okken. I'm Michael Kennedy. And I'm Dan Taylor. So Dan,

00:46 before we jump into things, welcome to the show. But can you let people know kind of who you are?

00:52 Yeah, thank you. It's great to be here. A big fan of the show. So I'm Dan Taylor. I'm a program

00:58 manager manager on our Python team. So I manage a team of program managers that work on our Python

01:05 developer tools. For example, our Python support and Visual Studio Code and Visual Studio IDE. And

01:10 we also manage some of our engagements with the Python community. For example, our sponsorships of

01:15 PyCon and the Python Software Foundation. That's awesome. You know something, Dan, I thought was

01:20 pretty interesting. I was just watching a talk from Brett Cannon, getting ready for an interview I did

01:25 on Talk Python with Lenga. A lot of stuff going on there. But the talk was only from 2018. And Brett

01:31 went into detail describing what VS Code was. I was like, Adam or Sublime and all these things.

01:36 It needs no introduction these days, does it? No, no. It's just been amazing watching just how much

01:43 it's grown over the past year and become a household name for people, especially in the Python community.

01:47 Cool. Well, Michael, how do I keep my computer awake?

01:51 Well, first, you make sure it gets eight hours of sleep a day. You don't overwork it. I know it's

01:57 work from home. So you might be working on it, playing on it and watching TV. Oh, wait, this is not this is a

02:02 totally different thing. So I recently was working on this project around some of the courses over at

02:07 Talk Python training. And I needed to do a bunch of video processing and reencoding for like, take the same

02:14 videos, but make them smaller. So I wrote some really cool Python code to go through and take

02:19 the source videos and do all this analysis and reencode it into a bunch of formats. You know,

02:24 that takes like five hours for one of our courses. And if my computer goes to sleep, it's going to take

02:30 more than five hours. I got to go and like keep waking the thing up again. Right. Well, what can I do?

02:36 I could go into the settings and say, you know what? Don't do that. Just don't go to sleep right

02:40 now. But then maybe I'll forget. Who knows? It would be cool if just while my Python code was running,

02:46 it would stay awake and then it would potentially not stay awake when it was done. Wouldn't that be nice?

02:51 Yeah. Yeah. So I found this cool library called WakePy and the implementation of using this is

02:58 ridiculously easy. You just say from WakePy import, keep awake. And then you create a context manager

03:04 with keep awake, do the stuff you want it to do while the computer doesn't go to sleep. Done.

03:09 That's cool. Yeah. It's super easy. It works cross-platform. It works on windows. It works

03:15 on Linux. It doesn't really work on macOS because there's a bug, but it's supposed to work on macOS,

03:20 which is where I'm running this right now. So that's kind of unfortunate. Wouldn't you say?

03:24 It turns out it's one of these strings versus bytes weirdness. So I actually decided this is kind

03:35 of cool. So what I'm going to do is I'm going to create a PR. There's a PR that says it doesn't

03:40 work on Python three, but you know what? And here's like the error. If anyone cares, you get this,

03:45 a bytes like object is required, not string. So I submitted a PR. The PR is

03:49 not yet addressed or responded to or anything. So if you want to use this for the time being,

03:55 I can really only on macOS, to be clear, I can only recommend it off of my branch until you see

04:00 that PR merge because it won't work at all. But if you're using windows or Linux, I think it'll just

04:05 work straight away. And it's interesting if you actually dig into it, I kind of imagined it would

04:09 just be doing the same thing. But if you dig into it, like in the Mac version, there's literally a

04:14 command you can type on. This is awesome. You can type on the terminal. You can type

04:19 caffeinate. That will keep your OS from going to sleep. If you just run that on the terminal.

04:24 If you type a dash D, it'll keep the display on, things like that. It won't let the screen go to

04:31 sleep. But over on say Windows, it does a bunch of tweaking with threads. So what it'll do is like

04:37 go and set its current thread to be like continuous, system required, display required as a bunch of

04:44 bitwise flags. And then over on Linux, it uses what else? It uses something completely different.

04:50 It runs mask and unmask, which I don't actually know what that does. I suspect it keeps it awake.

04:55 So anyway, it's a pretty cool little project. It's very simple, but it also solves the problem that I

05:01 can imagine a ton of people doing data science-y like things would run into because they want to do a

05:07 bunch of processing and not have their system go to sleep. What do you all think?

05:10 I think I'm just glad that I know about caffeinate now because that's cool.

05:14 Yeah. If you want to keep your Mac awake, you literally just have to go over and type caffeinate

05:19 on the terminal. You don't have to have Python or any of those kinds of things. But if you want your

05:23 Python code to control it, this thing is basically subprost juggling that command.

05:28 Yeah. I can imagine if you're writing code that's scraping websites, looking for updates and things like

05:33 that, you really wouldn't want your computer to go to sleep. And I always find myself messing around

05:37 and all the power settings and maxing things out. Exactly. So this is nice.

05:41 Yeah. Yeah. Very cool. Very cool. Awesome. Well, that's it for that one, Brian.

05:44 Cool. Off to you.

05:46 What do we got next? We have, oh, how to create a great stack overflow question. Actually, this is,

05:52 this is great. Yeah. Stack overflow just sold for like $1.4 billion. It's quite the site.

05:58 Yeah. Who did it sell to? Do you know?

06:00 No, I don't remember. It's a company I hadn't heard of.

06:03 I didn't miss that. Anyway. So I, you know, I don't really, I actually, of course, when I Google

06:10 stuff, I get a bunch of stack overflow answers and I've utilized it. And I had, I like tried to play

06:15 the whole game for a little while of like trying to get stack overflow points and stuff. And then I

06:20 realized, yeah, this just isn't my thing, but it's a thing for a lot of people of like answering this.

06:26 But the reason why I brought this up isn't just to get great answers on stack overflow, but there is a

06:31 good trick to that and it's good. But it's also, if you're asking questions really from anybody, if you,

06:37 if you send a, any sort of expert that, you know, like maybe if you want to ask a pyramid question to

06:43 Michael or a pie test question for me, these sorts of things are, this, this is a, this, the same,

06:50 same topics apply. So let's just jump in. This is from Kevin Markham at data school. Kevin's a great

06:58 guy. We've kind of hang out with him sometimes at picons and stuff when we had those, but the punchline

07:04 of his article, which we'll link to is you need to write a brief introduction and you want to have

07:12 self-contained code examples and then detail the expected results and why you want those results.

07:18 And then add any other important notes linked to relevant questions. And then also write a title

07:24 that summarizes the question. These all seem sort of obvious. So I'm really glad that Kevin went through

07:31 kind of an example. So he started with an example that somebody, one of his students asked him about

07:36 pandas. And the question really was about data frames and filling in missing values. And it had

07:42 a domain specific thing that is somebody was asking him. And then, then Kevin goes through and

07:48 rewrites the question as a good stack overflow question. And it's night and day. It's like amazing

07:55 to see this. So I really encourage people to read the article, but what a couple of things that I really

08:02 love is converting that he doesn't really talk about, but convert the, the example from any domain

08:09 specific stuff to a toy example. And that skill of really, and that's a good skill to have anyway,

08:16 is to, to say this problem that I'm having in my code, it's really a generic problem. How do I make

08:22 that using a toy example to describe the problem? And oftentimes actually you can answer your own

08:28 question. Once you get it into a toy example and you realize, Oh, I'm just, I'm not, I'm overthinking it.

08:34 So this is a good first step. and so this is, that's a great thing to see, but, this is a great

08:41 example. Cause it's a, it's like some architecture problem, but then he turns it into colors of toys.

08:46 and it's a, it's an easier problem to see. The other thing is making sure that two examples runnable

08:53 with all the import statements and everything. So somebody can just flop it into, their own editor

08:58 and run it to see, you know, if, if, if, if they can see the same problem and see if they can figure

09:04 out. That's good advice. If it's too specific or you don't have the data or it's not complete,

09:08 you have to speculate rather than actually fix, you know, verify you can fix the problem or not. Right.

09:13 Yeah. And the part that I, one of the things that I wouldn't have thought of is linking to other

09:19 questions because there's a fear, I think of moderators and also other people reading it is,

09:24 this is probably our, it's, if it's simple, it's probably already been answered. What did you

09:28 already look or whatever? And the, the act of linking to other answers to say this question over

09:35 here doesn't really, it kind of helps me, but it's missing because of this or something, some reason

09:42 why the other answers, the, and that that's an interesting take on it just to, so that people

09:49 don't dismiss you right away as somebody that didn't do any research to begin with. So.

09:53 Yeah, for sure.

09:54 Yeah. It's cool. Usually by the time I get to stack overflow, I'm pretty desperate, for help.

09:59 And so forming a really good question. So you get the best answers and, is, is really important.

10:03 I really like that narrowing it down to a reproducible example.

10:07 Yeah. And people can be mean on stack overflow and on Reddit and on other, and on YouTube and other

10:12 places on the internet. But if you show that you've tried, I think that will disarm them somewhat.

10:18 Totally.

10:19 Right. I mean, I've seen questions like I have this homework question and I can't do

10:22 my homework. Could anyone help? And I get that email too. And like, no, no one can help. No

10:28 one wants to do your homework for you. Yeah. So no one should, but if you have a legitimate

10:33 problem or you think you found it a legitimate bug or there's just no documentation and it's

10:38 clear you've tried, I suspect that'll disarm people. They may still not be able to help you,

10:43 but at least they won't be mean. Hey, Brian, before we move on to the next one, I want to

10:46 do two quick real-time follow-ups. So one stack overflow sold to tech giant process process.

10:53 We've all heard of them for $1.8 billion. So that is not messing around. they, that's

11:00 that forum site did all right. Jill Spolsky and Jeff Atwood did okay. And then the other

11:06 one is, unfortunately Dan Heford out there in the live stream said he just ran caffeinate

11:10 three times on his Mac and he can't get it to sleep and it's acting jittery and anxious.

11:15 So, I don't really know what we can do about that, but maybe we just go to TikTok. What do you

11:19 think? Yeah, totally. So have you ever, have you ever really wanted to make a quick edit to

11:24 something you've gotten a GitHub repo? but you're kind of stuck with that, that rudimentary

11:28 feels like you're working with notepad maybe a little. Yeah. So you click the edit, there's a little

11:32 edit thing. You find the file, you edit it, and then you go in there and there's like no help. And

11:36 you just type away. Yeah, I do that. I don't love it, but I do that. It feels like

11:40 your notepad. Well, GitHub announced, GitHub code spaces, recently, which is a cloud

11:46 hosted development environments with powerful machines and you have to pay for them. But one

11:50 of the fun bonus features that they launched at the same time that we only really announced on TikTok

11:55 and other social media, is, is called github.dev. So you can actually go to any, github repo

12:03 and say, I just want to edit this github repo that I have here. And I can just press the dot key

12:09 and that will reopen this, this github repository in something called github.dev. So this is an

12:15 entirely, web browser based version of VS Code that's built right into github. It works on any

12:20 github repo. and there's no server behind it. It's serverless. So there's nothing that you need

12:25 to pay for here. and so it also has some limited functionality because there's no backend. This is all

12:30 just, front end running in your web browser. but, what's really cool is that, you can

12:37 come in here and, and you can edit, you can add new files. Like I can go in here and add, you know,

12:43 a new Python file, in the file explorer on the left, I can just click and add a new file and I can

12:47 work with this more like I'm used to working with a text editor. and as I can just say imports,

12:54 flask, for example, and because we've, there's support for different extensions that are

13:02 web enabled that, that know how to work in this new mode. So we've, we've actually added the Python

13:06 extension recently in here. So I can actually, get some autocomplete from, from, some of the

13:13 modules. So if I say from flask import, flask, I get the autocomplete for that flask object.

13:19 And I can do the typical thing where I can say flask equals name and I can type app dot,

13:27 and I get, all of this, you know, add template filter route, all those in the autocomplete. So I

13:32 can actually get a, a more real editing experience with that productivity, things like that,

13:39 that I'm used to when I'm working with text editor, but this is all using the, the storage file system

13:44 from the web browsers, local storage, as well as the files from the GitHub repo.

13:49 so if, for example, if I go in here and just, change hello world, hello Python bytes,

13:56 in this code here, and I hit save, on a piece of code, and then I see I've got source control

14:02 changes here and it's telling me that I can click on that file and I can actually see a diff of that

14:08 file, side by side. And I can just, commit that using the source control panel. And if I,

14:13 if I add this commit, it'll go directly into my GitHub repo. so that's pretty cool.

14:19 So a lot of the, that's amazing. I do see right below the source control thing, a, a play debug

14:25 thing. so, so that doesn't, that doesn't work yet. Does it? Yeah. So that, that's what there's

14:31 like continue working on code spaces at that point. You got to get a real machine for, if you want to

14:35 do things like the hosted, the real hosted version. Yeah. Yeah. But, but there is some, we're actually

14:40 pushing the boundaries of what you can do in the, in these web versions in some interesting ways. So you

14:44 can get basic syntax highlighting as, as you saw autocomplete. but there's no Python interpreter.

14:50 So when I go to definition, say, I want to go to definition on this flask module, it just brings up

14:56 type hints, the pipe, the type hints that we have. I see the type shed type hints. Okay. It's still okay

15:01 though. It's still better than like what you get with the normal editor. Yeah. It's pretty cool. One,

15:06 one kind of bonus thing I want to throw in here is that, so if you go to the extensions tab,

15:12 you'll, you'll be able to search and you'll see which extensions are web enabled. And one of the fun

15:17 ones that, somebody on our team put out is this VS Code pyiodide one. so if you actually open a

15:23 Jupyter notebook, you can, you can run a little bit of Python code from these cells, here, using

15:29 pyiodide. So that's pretty neat. Oh, wow. So this is WebAssembly for the win. Yeah. So that's

15:34 github.dev. I think it's a really cool how much more you, you can do, right from the browser

15:39 within, within github. I'm excited to see where this goes. Ryan, did you know about this? I didn't.

15:44 And I was just playing with it in the background on my own, repo. I was, I haven't, I was

15:49 looking through the extensions and maybe, you know, off the top of your head, Dan, can I get the Vim

15:54 mode in this extension? well, if you, you'll see which ones are, so if they're, if they're

16:01 highlighted here and not grayed out, so the, this Vim extension works, so you can, you

16:06 can see which ones are available. It says available in VS Code Web. You just made Brian's day. There's

16:11 a couple of Vim options. Yeah. Yeah. I can't, I just can't use any editor without Vim mode anymore.

16:17 Yeah. My brain just doesn't work without. How do you use Google Docs or like other editors or

16:22 anything like that? What's that? How do you use Google Docs or some other editor? I paste into

16:28 that after I've written the stuff in some, in somewhere else. Nice. Dan, when I first saw

16:34 this, I was, I was on my GitHub repo and I'm like, Oh, let me just hit dot because it seems

16:39 like that's too simple, but I'll try it. And then boom, it came an editor. I'm like, Oh my

16:42 God, this is awesome. And then I went into the settings and I put it into dark mode and I

16:46 changed the font size and all the font family. And I'm like, Oh, this is, this is nice. Like

16:51 this is a really cool. Yeah. I'm, I'm excited about it. Let me throw one more bonus in here.

16:55 So if I change this to say, edit this, a Jupyter notebook cell here. And if I go into the diff of,

17:05 if I go into the source control panel, after editing this Jupyter notebook cell, I can actually see a

17:10 real, a real diff side-by-side with those, with those cells. So that's, that's something cool you can

17:16 do without having to install a full editor and things locally.

17:20 Very cool. Yeah. And it's a nice diff of the cell contents, not like the JSON crazy diff.

17:26 Yeah. You get the left, red, right, left, right with red, green, add, remove. Yeah. And outputs are

17:33 squashed. So you're not seeing a bunch of, if you diff a notebook, you'll see a bunch of XML and JSON

17:38 being removed and added. This is, this is more of that rich.

17:42 Take all of the various encoding language storage formats and then jam them all together and then

17:49 diff that. That's fun. Yeah. No, this is awesome. This is a great view.

17:51 Click it. I'm going to use it.

17:53 Indeed.

17:54 So one of the things that I don't really edit on and get very much, what happens like once you're

18:00 done, does it create a merge request or just edit it in place or?

18:03 It makes a commit directly to the repository. So I can just throw that right in there.

18:10 And so you have to have, you obviously have to have permissions. You have to be one of the people

18:15 that can commit directly to that branch. Right. Yeah. Yeah. This is great. I was so delighted when

18:20 I saw it. So I'm going to definitely use this. Nice. All right, Brian, am I up on the next one?

18:25 You are.

18:26 All right on. Let's move on to it. Okay. I'm resisting the temptation to hit dot and play around with the

18:32 wake pie. Instead, let me take you over here. So we go to Python. That's, that's not Python bytes.

18:38 Close, but not exactly. Gosh. And they don't even, why did I type com? I've never, hold on.

18:43 Python bytes.fm. That's our domain. So we're live streaming right now, by the way, if you didn't

18:49 notice. If you go over here, notice I've got Firefox that I'm using and it has this little shield and

18:55 almost anything you go to, man, I want to go to a new site, but let's go to CNN and you'll come over

19:01 here and you'll see a bunch of stuff up here getting blocked, like social media trackers,

19:07 tracking content. Like, look at that. That's a ridiculous amount of gross Google analytics,

19:13 Google tag services, Rubicon project, US East, apparently like that's bad. Right. So I've done

19:20 a lot of work. Get us away from retargeting tracking. And we have no known trackers.

19:25 And I'm running a VPN, which probably blocked a bunch of the ones off of CNN. So that was the

19:30 ones that got through the blocking and stuff. So it's really nice to not have all that stuff and

19:37 let people come visit the site and know that we're not retargeting them. We're not tracking them. We're

19:41 not doing stuff. We're just giving them a podcast or same thing over on talk by then training or talk

19:47 Python or whatever. Right. You go there, you get the content. We offer things like a podcast with ads

19:53 that people can take. And that's enough. We don't need to like follow you around for all sorts of

19:57 creepy reasons. Right. The drawback is we don't have a lot of analytics. Right. We can get a sense

20:04 about like download numbers and things like that, but we can't report like, well, in the last hour,

20:09 since we talked about this thing, here's the traffic. Can we, or would we? So, junction apps

20:16 over on Twitter said, Hey, you know what? I heard you going on and on about, the retargeting of all

20:22 these places and how you dropped it. Have you heard about go access.io? Have either of you heard

20:27 about this thing? No, no, I hadn't either, but check it out is super cool. So what it is it is a

20:34 Google analytics like service that you install on your server. And what it does, if I put this image

20:41 in a tab, so it doesn't go away. What it does is it looks and tails your logs and gives you real-time

20:47 analytics on your logs rather than by looking at, going through JavaScript and hooking into

20:54 people's browsers. So no tracking, none of that stuff, but you can come over here and in your

20:59 terminal, run it and get a real-time view of your traffic, your visitors, all the kind of stuff you

21:05 would expect from Google analytics visually as a graph-like thing in your terminal. Interesting,

21:11 huh? It's really cool.

21:12 Yes. What kind of information are you getting?

21:13 Well, probably the easiest way to find out is they have a web view and have the terminal view

21:18 and the web view is really generate a HTML file and then just request it. So there's not like a web

21:23 server type thing, but you go over here and click, it says here, I'll give the, give you the features

21:28 real quick. Then open up the demo. It says fast real-time millisecond, based, you know,

21:33 latency updates written in C only uses in cursors of the dependencies works on almost all the formats

21:38 engine X amongst the others. just set the log format and run it on your log, got the terminal and

21:44 the UI, the web UI bit. So if you go over here, you can see like, look at this off of just the log

21:50 files. So you can see things like here, I'll pull them up. So you can go over and say, well, what are the

21:55 referring URLs? let me make that small. So you can kind of see in here, unfortunately,

22:01 here's the referring URLs. So you can see in this example, they were, you know, shop internet,

22:06 whatever, right? At least it'll, it's a fake site, but you can come over here and like actually see

22:10 graphs as well as like grids and pages. So like think Google analytics, but if you run a site and you

22:18 can point this against your logs and get real time information in the terminal or as in this web view.

22:24 And yeah, it's, it's pretty neat. And so do you, you don't, do you have to install anything or do

22:28 you just run this and it finds the logs on your system and pulls it all together?

22:32 Yeah, you do have to install. Let's see here. so there's a getting started and it says the way to

22:39 get started probably to use a package manager for your Linux machine. If you're running on Linux,

22:44 or you can get a Docker image and you run it. And then the, what you do is you just simply run the

22:49 command against your log file and, and tell it what format and boom, off it goes. So you could

22:56 set it up as a, like a cron job or something that will then generate the HTML file. And you could just

23:01 refresh that, you know, however often you want to, or run the terminal one.

23:05 You could run it once a day too.

23:07 And yeah, you don't need, save the report.

23:10 Exactly. Yeah. You don't need real time, real time. You need just sort of how's the day going

23:16 or something like that. How was yesterday?

23:17 Right. So like one of the things that I use information like this about is I don't really

23:22 want to track users. I don't care about individual users, but I do want to know,

23:26 like I've got putting out different content on my blog or on a podcast, which ones, which,

23:33 which ones are resonating with people and maybe do more of that. yep. So,

23:38 so you can see like, there's a little bunch of options here for insights, hosts, requested

23:45 files, they call it, but it's really just URLs. so you go over here and this would tell

23:51 you sort of the traffic, you know, across your various, pages, right? So this would be

23:56 like your list, this, requested files, URLs are the one you'd want. Yeah. Yeah. So anyway,

24:01 I haven't set this up yet, but it looks pretty neat and it could be worth checking out.

24:04 Yeah. Neat. And I guess even you could download your logs.

24:08 And not install it on your server. If you really wanted, right? You want this view,

24:12 but you don't actually want to put it on your server because putting stuff on the server.

24:16 Well, you know, so you could download it and then just run against your logs locally.

24:20 And you might be uploading your logs to a storage account somewhere too, on a cron job.

24:25 Yeah, exactly. You could push the logs out instead of, running it there. So

24:29 a bunch of cool ways to use this, but if people are running web apps and they want more visibility

24:33 into it, this, this looks like a cool thing. So thanks, junction for sending that over.

24:37 All right. Off to you, Brian.

24:38 I want to talk about keyboards a little bit. So this was a topic and talk a topic recommended by

24:45 somebody named blaze blaze, I think. so there's a, a package called KMK. It's actually a collection of,

24:55 collection of pieces of software, but it's, the, we're linking to the KMK firmware.

25:00 So this is firmware for computer keyboards written and configured in circuit Python.

25:07 So got super excited about this. I'm still kind of excited about it. the gist of it is,

25:12 is, you've got, if there's, if you've got a keyboard that, that runs a, run circuit Python

25:21 and it's powerful enough to, to run, to handle your keyboard and stuff. So there's,

25:27 there's a couple of tips in here. There's a couple available through Adafruit, of different,

25:32 different boards that would work. We'll get into the details a little bit more, but, I,

25:38 basically you can configure a keyboard with a single file, single Python file. You can, it controls

25:45 both, split keyboards, two pieces, keyboards, and single keyboards. You can, hook up macros,

25:51 things like, chainable macros, to, so you can, have key sequences built into one,

25:57 one key, or you can hook it up so that a key hitting multiple times, you can hit like a particular key

26:04 three times in a row and you'll have one action versus something else. So, even controlling

26:09 under glow and LEDs and backlights and all that sort of stuff totally would be fun. I want to use this.

26:15 I don't know how it seems like a lot of work though. So, so we're linking to the, the,

26:22 the, the project and there's some information here. There's some guides on how to get started.

26:28 And then we're also going to run, I, I found somebody that ran this, and, and the, he's

26:34 got a video that walks through, doing it. But the gist of it is, is there aren't any keyboards

26:41 that do this right away. So you've got to take an existing keyboard, rip out the existing circuit

26:46 board and replace it with one of the 80 fruit board, 80 fruit boards, and then, and then reprogram

26:52 it. So if you're the kind of person that's okay with ripping the circuit, circuit board out of

26:58 your keyboard and replacing it with something else, that'd be great. And I actually wouldn't mind doing

27:02 this. I think that'd be fun, but I'd kind of like to know which keyboards I can do this with and which

27:07 ones I can't. I know there's a huge list of keyboards out there, but even just a couple

27:11 like starter kits would be great to hear.

27:14 It really works well with this one. And here's where the circuit Python board fits in there easily

27:20 rather than, yeah, it doesn't really go back in.

27:22 Yeah. So one of the reasons why I'm bringing this up is I'd love somebody from Adafruit or from,

27:27 work, anybody working on circuit Python or the came came K team or somebody to, maybe put a couple more

27:34 tutorials out to just say, Hey, this is how you do it for like, I'd love it to have like an off the

27:41 shelf full keyboard, even if it's small or whatever that it said, okay, here's, here's,

27:46 here's how you do it. You pull this circuit board out, put this other one in, it's like $40 on Adafruit.

27:52 And there you go. You can, you can try it. And here's a sample of file that you would run it,

27:59 run just a normal keyboard, usage. And now, now you can customize it because the, just getting back

28:07 to a workable keyboard seems already like a lot of work, but it still looks fun. I'd love to be able

28:12 to hack a keyboard with Python. Very cool. Dan, what kind of keyboard do you use? well, I use,

28:19 I'm a big fan of the thin keys, right? The very, the very light travel keys, but I got the ergonomic

28:25 keyboard. so thin ergonomic Logitech, not into the, I've got the, I've got the, Microsoft

28:32 sculpt ergonomic, which I absolutely love. I know Brian's got even more exotic stuff that he's

28:38 running over there. I don't know if I can get mine up here. I'll, I'll, I'll do the camera.

28:42 It's like, it's mounted to the, no. Oh, my junk too. I've got a Kinesis.

28:47 Yeah. The Kinesis inverted ones. Those are super interesting. What I would like to see would be

28:53 some keyboard manufacturer saying we're shipping a keyboard to you. Oh, and you can program it with

28:58 Python and basically do this for you as a package thing and just, you know, build it out of these

29:03 components. That'd be fantastic. Yeah. That'd be great. Well, I think it'd be fun with, with everyone

29:08 decking out their home offices these days. If you could do a little bit of magic light show while

29:13 you're presenting or talking on a call, that would be really cool. That'd be fantastic. Yeah. Hey,

29:19 Brett Cannon's out there in the live stream. Danny may have heard of this guy, Pablo,

29:23 Pablo, Delgado has programmed his keyboard RGB lights to color code the build bot status for

29:32 CPython. I don't know which library uses. That's awesome. So like it's green if everything's good,

29:36 but it turns red if CI fails or something like that. Oh, that's awesome, Brett. Thanks for sharing.

29:40 That'd be cool. You know, I never really, I mean, when I first saw the, the LEDs under the keyboards,

29:46 I thought, you know, yeah, gamers like it, but I don't think I would probably have a use for it,

29:51 but now I'm jealous. I want, I want, I want to light up things on my keyboard. It'd be fun.

29:55 Yeah. Especially if you could program them, right? Like this, this example here, my mouse

30:00 sits here and pulsates and changes color, but because it's on a Mac, the software doesn't work

30:06 and I can't do anything with it. So it's, it just annoys me there. It's a good mouse otherwise,

30:10 but anyway. So is it a windows only thing or what? No, the mouse is perfect on Mac,

30:16 but the software that lets you customize it and do interesting things to the colors doesn't work

30:21 on the Mac. Lame. Super lame. Super lame. All right. What is not lame is this last thing that Dan has

30:28 got here. Cause this thing has been blowing up on Twitter. It's all of a day old with like 2000

30:33 GitHub stars. And I was like, Oh, this has got to be covered. And then Dan, you were on it.

30:37 Yeah. I just saw it yesterday and I was like, I have to talk about this.

30:40 So I, I know that when I've built web apps in the past, one of the big frustrations I have is

30:46 that when you want to add something new to your database, you need to add it to the SQL queries.

30:51 You need to add something to the backend code. You need to add a piece to the API that, that then

30:57 returns that, that new object to users. And then in your client code, you need to consume it. And so

31:02 there's all this repetition that you're doing across your web app every time you need to

31:07 make a change to your data or add a new object. And that's very error prone as well.

31:13 And so things like SQL, SQL, SQLAlchemy, you can use to write code that interacts with your

31:20 database. And then things like FastAPI, you can use Pydantic to return models to your users,

31:28 to the, to your APIs. But then that now, now we had this thing where, where you have SQLAlchemy

31:35 models and Pydantic models, where, and then you're translating back and forth between them.

31:39 And so, Sebastian Ramirez, who just, just released yesterday, this new SQL model library, which looks

31:48 just awesome because it actually combines the schema for talking to the database and speaking to your API

31:55 into one, one schema object that you write. So, what's really cool about this is that, so the way you work

32:03 with this is that you define your objects. For example, he's got in the GitHub repo, this hero class

32:10 with an ID name, secret name, age. And it's, it's got some of the SQLAlchemy type things like it's your

32:17 primary key is the, the ID is optional, but it's defaults to not its primary key. So what's really cool about it,

32:24 this class is both a SQLAlchemy model and a Pydantic model. I don't know how he did that. He said there's

32:30 some magic that's going on behind the scenes. And so what's really cool is that you can use this to

32:36 instantiate your database. So you can, you can, so you've got this hero class, you can create objects in

32:43 the database by going hero one, hero two, hero three equals hero bracket and pass the name, secret name,

32:49 all the fields to the object. And, you can also return those same objects. You can use that same hero

32:57 class and use it in your FastAPI. So you can, accept hero objects. you can, return hero objects. And so that's,

33:06 that's one, you write that one schema and you, and you use it in multiple places. Yeah. What you have on the screen here for a FastAPI is

33:13 response model equals the database entity, which that then drives the open API documentation

33:20 in addition to just driving. Yeah, exactly. You got it right there. So you can go there and

33:25 it's sort of end to end the same model, which I think is really great. Yeah. And so you can look at your

33:30 in, with FastAPI, if you go to slash docs, you get the, the swagger, UI. And so you can see that same

33:38 schema with the ID name, secret name age. And, what's really cool about that is that it also has,

33:44 this generates the open API.json. And so you can use tools like open API generator to even generate

33:50 client code and all the, any different language that you're using like Python, JavaScript, Lua. And,

33:57 so, so you can, if you just went back to that original hero class and added a new field, you could

34:03 potentially have it in all different layers of your application, with one, including the consuming

34:09 clients. Cause they could regen off of the, the JSON schema. Yeah. Yeah. So I think that's really cool.

34:14 And, and one other really nice thing that, that Sebastian did here is that he really emphasized

34:20 making sure that in the editors that you have a good experience with autocomplete because,

34:26 in the past stuff like the Django ORM and the SQLAlchemy ORM, the editors have had to write

34:32 custom code to be able to have a good autocomplete experience for that. and so Sebastian used,

34:39 type hints, really well throughout the design of this so that as you're, returning objects from

34:45 the database, you actually get, you can, once you return that object from the database, you actually get,

34:51 autocomplete on it. I can show that here.

34:54 Yeah. That's really cool because a lot of times you just get star, star KWR, you know, like, oh, thanks.

35:00 Yeah. So I got this statement, select hero, where hero name equals hero name, and then the object

35:07 that returns, I can go hero dot, and then, sorry, that was working.

35:11 Put it at the very end of the line, maybe. Yeah.

35:13 Or in the next line. Yeah. Yeah. yeah, I can, so I can access all the, the properties on,

35:19 on the hero object. one, one cool thing about, how he did this. He used a, a proposal from, Eric Trout, the author of PyRite called the data class transform

35:31 that, it's this proposal that basically you can annotate various objects to say that they behave

35:38 like data classes. And so that that's kind of the magic that allows some of this dynamic behavior to

35:44 show up in, in type checkers.

35:45 I love it because so often you'll do a SQLAlchemy query or something and what you get back, it's

35:50 so many layers. It's lost what that type is.

35:52 Yeah.

35:53 It's like, ah, now I got to like re-annotate it again.

35:55 I got to search for everything. Look at all the different source code in my code base and stuff

35:59 like that. So this is really cool.

36:01 We've got some great comments in the chat. here's, here's one. I swear Sebastian spends as

36:09 much time on his docs as he does his code. Amazing talent. I got it. And we were talking about

36:14 type hints and the editor experience as well. Sebastian does a great job with the onboarding

36:20 experience as well as the, youth, the developer experience. And a lot of large companies could pay

36:26 attention to what this one person is doing, making it easy for people to pick up a new tool. It's amazing.

36:31 Yeah. I mean, look at the docs here. These are, this looks like a professional team wrote all this

36:36 stuff, right? This is, this is incredible. Instead of one, a very productive guy.

36:42 And then, Brett, good question. I want to know how Sebastian manages to release a new,

36:47 very cool project every single year. No kidding, man. He has a powerhouse. He's like changing how we

36:53 do web development. and, and it's just one person. But yeah, you know, I, I think I can,

36:59 speak to that just a little bit, by the way, if you look at the magic of FastAPI, you look at

37:05 what's happening here. These are really nice things to work with, but they're not from the ground

37:11 recreations of what they are. This takes Pydantic plus SQLAlchemy and makes it better. FastAPI

37:18 takes Starlette and Pydantic and makes them better, right? It's like the recombining of things that are

37:23 already really good into something better. Yeah. And some cool things that, that come as a result of

37:29 that repackaging. So according to Sebastian, this should support async database sessions out of the

37:34 box, because that's something that SQLAlchemy supports, Alembic migrations as well.

37:40 and in theory it should be possible to integrate with post gists and TS vectors, for doing

37:46 geo stuff and full text search with, with, with Postgres, but he says he hasn't tested it yet.

37:51 Yeah. I have no idea, but potentially async and await as well. Now that SQLAlchemy supports that.

37:57 Yep.

37:57 But again, this is a day old, so we haven't really had a chance to dig in it too much. I want to highlight

38:01 just a couple more comments. Savannah on the live stream says, Sebastian's attention to developer

38:05 experience is so awesome. Yeah, I agree. Keep it up, Sebastian. And Rehan says, it looks great for a

38:11 toy case, but people make professional interior systems. do they really want to share the same

38:16 types between their database and their rest API? That's a good question. I, I was thinking about

38:22 that as well. One of the challenges that you can run into when you just sort of say, oh, here's my

38:26 data model out onto the internet as JSON. And then take, especially taking it back as you can run into

38:31 like situations where you overexpose information or you run and run into a mass assignment type of bugs

38:38 where values get set or you didn't expect them to be set. So with Pydantic, you can do things like

38:44 call, you have to call to JSON, but you can also, or to dict, I can't remember. I think the dict,

38:49 but you explicitly opt in or opt out certain fields. So you could do things like that about

38:55 bringing those in. so pretty neat, but yeah, you gotta be a little bit careful about that.

39:01 but yeah, very cool stuff. You don't want your password hashes on your user object.

39:06 Exactly. If you're going to return your user, you don't necessarily want to exactly return,

39:09 say the password hash or God forbid, not just the straight password.

39:14 If you're not hashing it, but that's a bigger problem, but still.

39:18 Oh, I wanted to bring up one more thing is, his, his choice of heroes in his example.

39:24 Love these. we've got dead pond, spider boy, and rusty man. hilarious.

39:31 Love it. Yeah. Those are great.

39:33 Well, so those are our six items. do we have, any extras? Do you got anything to share?

39:40 Right. sometimes I have extra, extra nine times here all about it. I got none this time. How about you?

39:45 really? I've got like two.

39:47 So I bring one.

39:49 so, first one I wanted to bring up was, really fun episode. people know I also do a podcast called testing code episode 163. does, it's a talk with, Stefan Bedul about, pip install of local directory.

40:07 And, so if you're, if you're doing anything where you, do the pip install of a local directory, definitely check that out. Or especially if you never knew that you could do that. it's a good episode. the other thing I wanted to bring up, is, it's been like five episodes since I plugged my book, but no, I, there's a chapter 12 is up.

40:32 So chapter 12, the first, one of the things I got, questions about for the first edition was it's the whole book is talking about testing packages and there's a lot more in the Python world than just packages.

40:43 So chapter 12 is a reaction to that. It's testing scripts and applications. So it's not a pivot. If you don't have a pip installable package, you can still use pytest to test it. And chapter 12 directly addresses that. So I wanted to bring that up.

40:57 Awesome. Alvaro out in the live stream says, how is the second edition testing mode going?

41:01 Yeah. It looks like chapter 12 is coming along. Well done. You're basically done, Brian.

41:05 You're on vacation.

41:06 Well, there were less than 10 chapters in the first book, but now I'm, I'm working on chapter 13, planning on 17 altogether. it's going to come out in hard copy early next year.

41:18 So super.

41:19 I have one extra.

41:20 How about you, Dan?

41:21 Yep. So one, one cool library that I wanted to share is a type for pie. So we've been talking about types a lot lately. Seems like it's a, it's a regular topic of conversation.

41:31 And, they, they can provide a lot of benefits to your code base and to text editors, like VS Code or, or PyCharm. And, but what happens if you want to retrofit or add a bunch of types to a code base that's not typed already? That's, that's a big daunting task.

41:48 And so I, I came across this library, you know, shared amongst our team. And what I thought was really cool about it is that, it's a state of the art machine learning model for inferring types.

42:02 So we've, we've talked about before, Hey, wouldn't it be cool if we could just go generate all the types for all the packages out there so that we could have great autocomplete on everything.

42:09 But it turns out you can't because you can't do that until you actually run the code and have the objects to bind it to.

42:14 And so, this machine learning model is sort of the latest in a line of, of attempts, from different researchers to create a good machine learning model for inferring types.

42:24 what, what I like about it is not only is it, it sort of best in class in terms of its, accuracy is that the, the author of this machine learning model,

42:35 open-sourced the training data set with, with 4.3 million type annotations in it, the training code.

42:43 So you can go in and actually, use, train this on your own code, following some of these very simple commands to, to train the model and pre-processed, process the data with your own code base, open source to a VS Code extension.

42:55 So you can actually have developers using it.

42:57 It's not just some, Hey, this is our results.

43:00 QAD, go read the paper.

43:01 It's, it's actually something that you can use.

43:04 and so if you're looking at trying to retrofit a bunch of types into your code base, this is something you might want to try out.

43:11 just one sort of quick caveat that, that the sample VS Code extension uses the machine learning model that's hosted on type4py.com.

43:20 And so if, if you're not working on an open source project, you, you probably want to, fork the extension and, stand up the machine learning model, using the web server that, that he links to.

43:31 Yeah, that's a good bit of warning.

43:33 But this looks super cool.

43:34 it seems like one of those things you could do a first pass, retrofit it, and then go back and check it out, run my pie against it.

43:41 you could even go to Pydantic and use the validate decorator and put that on all the things and make it, then run your tests.

43:48 The validate actually verifies the type annotations really match the runtime behavior.

43:53 so yeah, a lot, a lot of neat things.

43:55 Excellent.

43:55 Brian, did you think that was funny?

43:57 No, no, not funny at all.

44:00 This might be funny.

44:02 We, we need something funny.

44:03 Yeah.

44:04 So we've been doing a lot of geek and poke lately and, yeah, this is a really good one.

44:08 So, you know, we talk about testing and we talk about continuous integration.

44:13 If you want to take that, like you go from testing to CI to the next level, we're talking continuous delivery, right?

44:19 I'm going to get pushed to the production branch.

44:21 That's going to kick off the CI, which is going to kick off a deployment.

44:24 Glorious, right?

44:25 Yeah.

44:26 Well, we've got a cartoon around it.

44:28 So there's this, man, a woman developer pair, and they're just looking like perplexed at each other.

44:34 It says for five days, I've been doing nothing else than trying to deploy this blinking application on our production environment.

44:42 Title continuous deployment.

44:44 That's one way to interpret that.

44:49 Literal.

44:49 Very literal.

44:51 Yeah.

44:52 All right.

44:53 Well, hopefully that was more funny.

44:55 Yeah.

44:56 So I've got a not very good joke, but I thought it was funny anyway.

45:00 it was, shared to us.

45:02 it was first from, Carla, not a robot.

45:06 It's a great handle and, told to us by blue fiddle guy also.

45:11 So, joke is if a programmer gets an interview because of a recommendation from a friend, are they being passed by reference instead of value?

45:21 I love it.

45:22 Definitely passed by reference.

45:25 Definitely.

45:25 Well, this has been fun.

45:27 So thanks everybody.

45:28 Thanks Dan for showing up.

45:29 Thank you for having me.

45:30 Yeah.

45:30 Thanks Brian.

45:31 Thanks guys.

45:31 Thanks everyone out there.

45:32 Bye.

45:33 Bye.

45:34 Thanks for listening to Python bytes.

45:35 Follow the show.

45:36 Follow the show on Twitter via at Python bytes.

45:39 That's Python bytes.

45:40 That's Python bytes as in B Y T E S.

45:41 Get the full show notes over at Python bytes.

45:44 If you have a news item we should cover, just visit by the bytes.

45:48 And click submit in the nav bar.

45:50 We're always on the lookout for sharing something cool.

45:52 If you want to join us for the live recording, just visit the website and click live stream to get notified of when our next episode goes live.

45:59 That's usually happening at noon Pacific on Wednesdays over at YouTube.

46:04 On behalf of myself and Brian Okken, this is Michael Kennedy.

46:07 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page