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.

00:02 Before we jump into this episode, I just want to remind you that this episode is brought to you by us over at TalkBython Training and Brian through his pytest book.

00:10 So if you want to get hands on and learn something with Python, be sure to consider our courses over at TalkBython Training.

00:17 Visit them via pythonbytes.fm/courses.

00:21 And if you're looking to do testing and get better with pytest, check out Brian's book at pythonbytes.fm/pytest.

00:28 by the episode.

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

00:34 This is episode 247, recorded August 25th.

00:38 Really?

00:39 Oh, we're almost done.

00:40 And 2021.

00:42 I'm Brian Okken.

00:43 - I'm Michael Kennedy.

00:44 - And I'm Dan Taylor.

00:45 - So Dan, before we jump into things, welcome to the show.

00:49 But can you let people know kind of who you are?

00:52 - Yeah, thank you.

00:53 It's great to be here.

00:54 A big fan of the show.

00:55 So I'm Dan Taylor.

00:57 I'm a program manager manager on our Python team.

01:01 So I manage a team of program managers that work on our Python developer tools.

01:06 For example, our Python support and Visual Studio Code and Visual Studio IDE.

01:10 And we also manage some of our engagements with the Python community.

01:14 For example, our sponsorships of PyCon and the Python Software Foundation.

01:18 - That's awesome.

01:19 You know something Dan, I thought was pretty interesting.

01:21 I was just watching a talk from Brett Cannon, getting ready for an interview I did on Talk Python with Xlinga, a lot of stuff going on there.

01:28 But the talk was only from 2018 and Brett went into detail describing what VS Code was, I was like, Atom or Sublime and all these things.

01:37 It needs no introduction these days, does it?

01:38 - No, no, it's just been amazing watching just how much it's grown over the past year and it become a household name for people, especially in the Python community.

01:48 - Definitely.

01:49 - Well, Michael, how do I keep my computer awake?

01:52 - Well, first you make sure it gets eight hours of sleep a day.

01:55 You don't overwork it.

01:57 I know it's work from home, so you might be working on it, playing on it and watching TV.

02:01 Oh wait, this is not, this is a totally different thing.

02:03 So I recently was working on this project around some of the courses over at Talk Python Training, and I needed to do a bunch of video processing and re-encoding for like, take the same videos, but make them smaller.

02:16 So I wrote some really cool Python code to go through and pick the source videos and do all this analysis and re-encode it into a bunch of formats.

02:24 You know, that takes like five hours for one of our courses.

02:27 And if my computer goes to sleep, it's going to take more than five hours.

02:31 I got to go and like, keep waking the thing up again.

02:33 Right.

02:34 Well, what can I do?

02:35 I could go into the settings and say, you know what?

02:38 Don't do that.

02:39 Just don't go to sleep right now, but then maybe I'll forget.

02:42 Who knows?

02:43 It would be cool if just while my Python code was running, it would stay awake.

02:47 And then it would potentially not stay awake when it was done.

02:50 Wouldn't that be nice?

02:51 Yeah.

02:52 Yeah.

02:53 So I found this cool library called WakePi, and the implementation of using this is ridiculously easy.

03:00 You just say from WakePi import keep awake, and then you create a context manager.

03:05 With keep awake, do the stuff you want it to do while the computer doesn't go to sleep, done.

03:10 That's cool, huh?

03:11 - Seems easy.

03:12 - Yeah, it's super easy.

03:13 It works cross-platform.

03:14 It works on Windows.

03:15 It works on Linux.

03:16 It doesn't really work on macOS 'cause there's a bug, but it's supposed to work on macOS, which is where I'm running this right now.

03:22 So that's kind of unfortunate, wouldn't you say?

03:25 (laughing)

03:27 It turns out it's one of these strings versus bytes weirdness.

03:33 So I actually decided this is kind of cool.

03:36 So what I'm gonna do is I'm gonna create a PR.

03:38 There's a PR that says it doesn't work on Python 3, but you know what?

03:42 And here's like the error if anyone cares, you get this bytes like object is required, not string.

03:47 So I submitted a PR.

03:48 The PR is not yet addressed or responded to or anything.

03:53 So if you wanna use this for the time being, I can really only on macOS, to be clear, I can only recommend it off of my branch until you see that PR merge, 'cause it won't work at all.

04:03 But if you're using Windows or Linux, I think it'll just work straight away.

04:06 And it's interesting if you actually dig into it, I kind of imagined it would just be doing the same thing.

04:11 But if you dig into it, like in the Mac version, there's literally a command you can type on, this is awesome, you can type on the terminal, you can type caffeinate.

04:20 that'll keep your OS from going to sleep if you just run that on the terminal.

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

04:32 But over on say Windows, it does a bunch of tweaking with threads.

04:36 So what it'll do is like go and set its current thread to be like continuous system required, display required as a bunch of bitwise flags.

04:45 And then over on Linux, it uses what else?

04:48 that uses something completely different.

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

04:54 I suspect it keeps it awake.

04:55 So anyway, it's a pretty cool little project.

04:58 It's very simple, but it also solves the problem that I can imagine a ton of people doing data science-y like things would run into because they wanna do a bunch of processing and not have their system go to sleep.

05:09 What do you all think?

05:10 - I think I'm just glad that I know about Caffeinate now 'cause that's cool.

05:15 - Yeah, if you want to keep your Mac awake, you literally just have to go over and type caffeinate on the terminal.

05:20 You don't have to have Python or any of those kinds of things but if you want your 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 that, you really wouldn't want your computer to go to sleep and I always find myself messing around in all the power settings and maxing things out.

05:39 - Exactly.

05:40 - So this is nice.

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

05:43 Awesome, well, that's it for that one, Brian.

05:45 - Cool.

05:45 - Off to you.

05:46 What do we got next? We have, oh, how to create a great Stack Overflow question.

05:51 Actually, this is great.

05:52 >> Yeah, Stack Overflow just sold for like $1.4 billion. It's quite the site.

05:58 >> Really? 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:02 >> I didn't miss that.

06:03 >> Anyway, so I don't really actually, of course, when I Google stuff, I get a bunch of Stack Overflow answers and I've utilized it.

06:14 I like tried to play the whole game for a little while of like trying to get stack overflow points and stuff And then I realized yeah, this just isn't my thing, but it's a thing for a lot of people of like answering this But um the reason why I brought this up isn't just to get great answers on stack overflow But there is a good trick to that and it's good but it's also if you're asking questions really from anybody if you if you send a any sort of expert that you know, like maybe if you want to ask a pyramid question to michael or or a pytest question from me.

06:46 These sorts of things, this is the same topics apply.

06:52 Let's just jump in. This is from Kevin Markham at Data School.

06:57 Kevin's a great guy. We hang out with him sometimes at PyCons and stuff when we had those.

07:02 But the punchline of his article, which we'll link to, is you need to write a brief introduction, and you want to have self-contained code examples, and then detail the expected results and why you want those results.

07:19 Then add any other important notes linked to relevant questions, and then also write a title that summarizes the question.

07:26 These all seem obvious, so I'm really glad that Kevin went through an example.

07:32 He started with an example that one of his students asked him about pandas.

07:37 The question really was about data frames and filling in missing values, and it had a domain-specific thing that somebody was asking him.

07:46 Then Kevin goes through and rewrites the question as a good Stack Overflow question, and it's night and day.

07:54 It's amazing to see this.

07:57 I really encourage people to read the article.

07:59 But a couple of things that I really love is converting, that he didn't really talk about, but convert the example from any domain-specific stuff to a toy example.

08:13 That's a good skill to have anyway, is to say this problem that I'm having in my code, it's really a generic problem.

08:22 How do I make that using a toy example to describe the problem?

08:26 Oftentimes, actually, you can answer your own question once you get it into a toy example, and you realize, "Oh, I'm overthinking it." This is a good first step.

08:37 This is a great thing to see.

08:40 But this is a great example because it's like some architecture problem, but then he turns it into colors of toys.

08:47 It's an easier problem to see.

08:50 The other thing is making sure that the example is runnable with all the import statements and everything.

08:54 Somebody can just plop it into their own editor and run it to see if they can see the same problem and see if they can figure out.

09:04 >> That's good advice. If it's too specific or you don't have the data or it's not complete, you have to speculate rather than actually verify you can fix the problem or not.

09:13 >> Yeah. One of the things that I wouldn't have thought of is linking to other questions because there's a fear, I think, of moderators and also other people reading it is, if it's simple, it's probably already been answered. Did you already look or whatever?

09:30 the act of linking to other answers to say, this question over here doesn't really, it helps me but it's missing because of this or something.

09:41 Some reason why the other answers.

09:44 That's an interesting take on it just to so that people don't dismiss you right away as somebody that didn't do any research to begin with.

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 really good questions so you get the best answers is really important.

10:04 I really like that.

10:05 Narrowing it down to a reproducible example.

10:08 - Yeah, and people can be mean on Stack Overflow and on Reddit and on YouTube and other places on the internet.

10:14 But if you show that you've tried, I think that will disarm them somewhat.

10:19 - Totally.

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

10:23 Could anyone help?

10:24 And I get that email too.

10:25 And they're like, no, no one can help.

10:28 - No one wants to do your homework for you.

10:30 Yeah, so no one should.

10:31 But if you have a legitimate problem or you think you found a legitimate bug or there's just no documentation and it's clear you've tried, I suspect that'll disarm people.

10:41 They may still not be able to help you, but at least they won't be mean.

10:44 Hey, Brian, before we move on to the next one, I wanna do two quick real-time follow-ups.

10:48 So one, Stack Overflow sold to tech giant ProSUS, ProSUS, we've all heard of them, for $1.8 billion.

10:56 So that is not messing around.

11:00 That forum site did all right.

11:02 Jill Spolsky and Jeff Atwood did okay.

11:05 And then the other one is, unfortunately Dan Heifert out there in the live stream said he just ran Caffeinate 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 should just go to TikTok.

11:19 What do you think?

11:20 - Yeah, totally.

11:21 So have you ever really wanted to make a quick edit to something you've got in a GitHub repo, but you're kind of stuck with that rudimentary, feels like you're working with Notepad, maybe a little.

11:30 - Yeah, so you click the edit, there's a little edit thing.

11:33 You find the file, you edit it, and then you go in there and there's like no help and you just type away.

11:38 Yeah, I do that.

11:39 I don't love it, but I do that.

11:40 - Feels like you're in Notepad.

11:41 Well, GitHub announced GitHub Codespaces recently, which is a cloud hosted development environments with powerful machines and you have to pay for them.

11:50 But one of the fun bonus features that they launched at the same time that we only really announced on TikTok and other social media is called github.dev.

11:59 So you can actually go to any GitHub repo and say, I just wanna edit this GitHub repo that I have here.

12:07 I can just press the dot key and that will reopen this GitHub repository in something called github.dev.

12:14 So this is an entirely web browser-based version of VS Code that's built right into GitHub.

12:20 It works on any GitHub repo.

12:22 And there's no server behind it, it's serverless.

12:24 So there's nothing that you need to pay for here.

12:27 And so it also has some limited functionality 'cause there's no backend.

12:30 This is all just a front end running in your web browser.

12:33 But what's really cool is that you can come in here and you can edit, you can add new files.

12:41 Like I can go in here and add a new Python file in the file explorer on the left.

12:46 I can just click and add a new file and I can work with this more like I'm used to working with a text editor.

12:51 and as I can just say, imports flask, for example.

12:56 And because we've, there's support for different extensions that are web enabled that know how to work in this new mode.

13:04 So we've actually added the Python extension recently in here, so I can actually get some autocomplete from some of the modules.

13:14 So if I say from flask import flask, I get the autocomplete for that flask object and I can do the typical thing where I can say, flask equals name, and I can type app.

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

13:32 So I can actually get a more real editing experience with the productivity, the things like that that I'm used to when I'm working with text editor.

13:41 But this is all using the storage file system from the web browser's 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 in this code here and I hit save on a piece of code and then I see I've got source control changes here and it's telling me that I can click on that file and I can actually see a diff of that file side by side and I can just commit that using the source control panel.

14:13 And if I add this commit, it'll go directly into my GitHub repo.

14:18 So that's pretty cool.

14:19 - So a lot of the-- - That's amazing.

14:21 I do see right below the source control thing, a play debug thing.

14:27 - So that doesn't-- - That doesn't work yet, does it?

14:30 - Yeah, so that's what there's like, continue working on code spaces at that point.

14:33 You gotta get a real machine for, if you wanna do things like running--

14:36 - I see, it takes you over to the hosted, the real hosted version.

14:39 - Yeah, yeah, but there is some, we're actually pushing the boundaries of what you can do in these web versions in some interesting ways.

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

14:50 So when I go to definition, say, I wanna go to definition on this Flask module, it just brings up type hints, the type hints that we have for Flask.

14:59 - I see, the TypeShed type hints, okay.

15:00 - Yeah, TypeShed type hints.

15:01 - It's still okay though, it's still better than like what you get with a normal editor.

15:05 - Yeah, it's pretty cool.

15:06 One kind of bonus thing I wanna throw in here is that, so if you go to the extensions tab, you'll be able to search and you'll see which extensions are web enabled.

15:16 And one of the fun ones that somebody on our team put out is this VS Code PyIoDyed one.

15:22 So if you actually open a Jupyter notebook, you can run a little bit of Python code from these cells here using PyIoDyed.

15:29 So that's pretty neat.

15:30 - Oh, wow.

15:31 - So this is--

15:32 - WebAssembly for the win.

15:33 - Yeah, so that's github.dev.

15:35 I think it's really cool how much more you can do right from the browser within GitHub.

15:41 I'm excited to see where this goes.

15:42 - Brian, did you know about this?

15:43 - I didn't, and I was just playing with it the background on my own repo.

15:47 I was looking through the extensions, and maybe you know off the top of your head, Dan, can I get the Vim mode in this extension?

15:56 >> Well, you'll see which ones are.

16:00 If they're highlighted here and not grayed out, so this Vim extension works.

16:05 You can see which ones are available.

16:08 It says available in VS Code Web.

16:10 >> You just made Brian's day.

16:11 There's a couple of Vim options.

16:13 >> Yeah.

16:13 >> Yeah. I just can't use any editor without Venmo anymore.

16:17 >> Yeah.

16:17 >> My brain just doesn't work without.

16:19 >> How do you use Google Docs or other editors or anything like that?

16:23 >> What's that?

16:24 >> How do you use Google Docs or some other editor?

16:27 >> I paste into that after I've written the stuff in somewhere else.

16:32 >> Nice. Dan, when I first saw this, I was on my GitHub repo and I'm like, "Oh, let me just hit dot because it seems like that's too simple, but I'll try it." Then boom, it became an editor.

16:42 I'm like, oh my God, this is awesome.

16:43 And then I went into the settings and I put it into dark mode and I changed the font size and all the font family.

16:48 And I'm like, oh, this is nice.

16:51 Like this is a really cool.

16:52 - Yeah, I'm excited about it.

16:54 Let me throw one more bonus in here.

16:56 So if I change this to say, edit this a Jupyter notebook cell here.

17:02 And if I go into the diff of, if I go into the source control panel after editing this Jupyter notebook cell, I can actually see a real diff side by side with those cells.

17:13 So that's something cool you can do without having to install a full editor and things locally.

17:21 - Very cool.

17:22 Yeah, and it's a nice diff of the cell contents, not like the JSON crazy diff.

17:27 - Yeah, you get the left, right with red, green, add, remove.

17:32 Yeah, and the outputs are squashed.

17:34 So you're not seeing a bunch of, if you diff a notebook, you'll see a bunch of XML and JSON being removed and added.

17:40 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 diff that.

17:49 That's fun.

17:50 Yeah, no, this is awesome.

17:51 This is a great view.

17:52 - Click it, I'm gonna use it.

17:54 - Indeed.

17:55 - So one of the things that I don't really edit on in GitHub very much, what happens like once you're done?

18:01 Does it create a merge request or just edit it in place?

18:04 - It makes a commit directly to the repository.

18:07 So I can just throw that right in there.

18:10 And--

18:11 - So you have to have, obviously you have to have permissions.

18:14 You have to be one of the people that can commit directly to that branch, right?

18:18 - Yeah, this is great.

18:19 I was so delighted when I saw it.

18:21 So I'm gonna definitely use this.

18:22 - Yeah.

18:23 - Nice.

18:24 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.

18:28 Okay, I'm resisting the temptation to hit dot and play around with the wake pie.

18:33 Instead, let me take you over here.

18:35 So we go to Python.

18:37 That's not Python bytes.

18:38 Close, but not exactly.

18:40 Gosh, man, don't even, why did I type com?

18:42 I've never, hold on.

18:44 Python bytes.fm, that's our domain.

18:47 So we're live streaming right now, by the way, if you didn't notice.

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

18:55 And almost anything you go to, man, I wanna go to a news site, but let's go to CNN.

19:00 And you'll come over here, and you'll see a bunch of stuff up here getting blocked, like social media trackers, tracking content, like look at that.

19:09 That's a ridiculous amount of gross Google Analytics, Google Tag Services, Rubicon Project, US East apparently, like that's bad, right?

19:19 So I've done a lot of work, get us away from retargeting and tracking, and we have no known trackers.

19:26 Now I'm running a VPN, which probably blocked a bunch of the ones off of CNN.

19:29 So that was the ones that got through the blocking and stuff.

19:33 So it's really nice to not have all that stuff and let people come visit the site and know that we're not retargeting them, we're not tracking them, we're not doing stuff.

19:42 We're just giving them a podcast or same thing over on Talk Python Training or Talk Python or whatever.

19:48 You go there, you get the content.

19:50 We offer things like a podcast with ads that people can take and that's enough.

19:54 We don't need to like follow you around for all sorts of creepy reasons, right?

19:59 The drawback is we don't have a lot of analytics, right?

20:02 We can get a sense about like download numbers and things like that, but we can't report like, well, in the last hour, since we talked about this thing, here's the traffic, can we?

20:12 Or would we?

20:14 So Junction Apps over on Twitter said, "Hey, you know what?

20:18 I heard you going on and on about the retargeting of all these places and how you dropped it.

20:24 Have you heard about GoAccess.io?

20:26 Have either of you heard about this thing?" - No, I hadn't either, but check it out is super cool.

20:32 So what it is, is it is a Google Analytics like service that you install on your server.

20:39 And what it does, if I can put this image in a tab so it doesn't go away.

20:43 What it does is it looks and tails your logs and gives you real time analytics on your logs rather than by looking at going through JavaScript and hooking into people's browsers.

20:54 So no tracking, none of that stuff, but you can come over here and in your terminal, run it and get a real time view of your traffic, your visitors, all the kind of stuff you would expect from Google Analytics, visually as a graph like thing in your terminal.

21:10 Interesting, huh?

21:11 - It's really cool.

21:12 - Yes, what kind of information are you getting?

21:14 - 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.

21:23 So there's not like a web server type thing.

21:25 But you go over here and click.

21:26 It says here, I'll give you the features real quick, then open up the demo.

21:29 It says fast real-time millisecond based, you know, latency updates written in C, only uses in cursors as dependencies, works on almost all the formats, Nginx amongst the others.

21:41 Just set the log format and run it on your log, got the terminal and the UI, the web UI bit.

21:46 So if you go over here, you can see, like look at this off of just the log files.

21:50 So you can see things like here, I'll pull them up.

21:53 So you can go over and say, well, what are the referring URLs?

21:57 Let me make that small so you can kind of see in here.

22:01 Unfortunately, here's the referring URLs.

22:03 So you can see in this example, they were, you know, shop, internet, whatever, right?

22:07 These little, it's a fake site, but you can come over here and like actually see graphs as well as like grids and pages.

22:14 So like think Google Analytics, but if you run a site and you 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 pretty neat.

22:26 - And so do you have to install anything or do 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.

22:35 So there's a getting started and it says the way to get started probably to use a package manager for your Linux machine if you're running on Linux, or you can get a Docker image and you run it.

22:47 And then what you do is you just simply run the command against your log file and tell it what format and boom, off it goes.

22:55 So you could set it up as a like a cron job or something that will then generate the HTML file and you could just refresh that, you know, however often you want to, or run the terminal one.

23:05 - You could run it once a day too and save the report.

23:10 - Exactly, yeah, you don't need real time, real time.

23:13 You need just, yeah, sort of how's the day going or something like that.

23:16 How was yesterday?

23:18 - Right, so like one of the things that I use information like this about is I don't really wanna track users.

23:23 I don't care about individual users, but I do wanna know, like I've got putting out different content on my blog or on a podcast, which ones are resonating with people?

23:35 - Yes, exactly. - And maybe do more of that.

23:38 - Yep.

23:39 So you can see, like there's a little bunch of options here.

23:43 Burn signs, host, requested files, they call it, but it's really just URLs.

23:48 So you go over here, and this would tell you sort of the traffic across your various pages, right?

23:55 So this would be like your list, this requested files URL, so the one you'd want.

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

24:05 - Neat.

24:06 - And I guess even you could download your logs and not install it on your server if you really wanted, right?

24:11 You want this view, but you don't actually wanna put it on your server because putting stuff on the server, well, you know.

24:18 So you could download it and then just run it against your logs locally.

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

24:25 - Yeah, exactly.

24:26 You could push the logs out instead of running it there.

24:29 So a bunch of cool ways to use this, but if people are running web apps and they want more visibility into it, this looks like a cool thing.

24:35 So thanks, Junction, for sending that over.

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

24:39 - I want to talk about keyboards a little bit.

24:41 So this was a topic recommended by somebody named Blaze, Blaze, I think.

24:49 There's a package called kmk.

24:53 It's actually a collection of pieces of software, but we're linking to the kmk firmware.

25:01 This is firmware for computer keyboards written and configured in CircuitPython.

25:07 Got super excited about this.

25:09 I'm still excited about it.

25:11 The gist of it is, if you've got a keyboard that runs a run circuit Python, and it's powerful enough to handle your keyboard and stuff.

25:26 So there's a couple of tips in here.

25:29 There's a couple available through Adafruit of different boards that would work.

25:35 We'll get into the details a little bit more.

25:37 But basically, you can configure a keyboard with a single Python file.

25:44 It controls both split keyboards, two-piece keyboards, and single keyboards.

25:49 You can hook up macros, things like chainable macros, you can have key sequences built into one key, or you can hook it up so that a key hitting multiple time, you can hit a particular key three times in a row, and you'll have one action versus something else.

26:08 Even controlling under glow and LEDs, and backlights, and all that stuff, Totally would be fun. I want to use this.

26:16 I don't know how. It seems like a lot of work though.

26:20 We're linking to the project and there's some information here.

26:26 There's some guides on how to get started.

26:28 Then we're also going to run, I found somebody that ran this and he's got a video that walks through doing it.

26:38 But the gist of it is, is there any keywords that do this right away?

26:42 You've got to take an existing keyboard, rip out the existing circuit board and replace it with one of the Adafruit boards, and then reprogram it.

26:53 If you're the kind of person that's okay with ripping the circuit board out of your keyboard and replacing it with something else, that'd be great.

27:01 I actually wouldn't mind doing this.

27:03 I think that'd be fun, but I'd like to know which keyboards I can do this with and which ones I can't.

27:08 I know there's a huge list of keyboards out there, but even just a couple starter kits would be great to hear.

27:14 >> It really works well with this one and here's where the CircuitPython board fits in there easily, rather than it doesn't really go back in.

27:23 >> Yeah. One of the reasons why I'm bringing this up is I'd love somebody from Adafruit or from anybody working on CircuitPython, or the KMK team or somebody to maybe put a couple more tutorials out to just say, "Hey, this is how you do it." I'd love it to have an off-the-shelf full keyboard, even if it's small or whatever, that it said, "Okay, here's how you do it.

27:47 Pull this circuit board out, put this other one in, it's like $40 on Adafruit, and there you go.

27:54 You can try it and here's a sample of file that you would run it, run just a normal keyboard usage.

28:03 Now, you can customize it.

28:05 because just getting back to a workable keyboard seems already like a lot of work, but it still looks fun.

28:11 I'd love to be able to hack a keyboard with Python.

28:14 >> Very cool. Dan, what kind of keyboard do you use?

28:17 >> Well, I'm a big fan of the thin keys, the very light travel keys, but I got the ergonomic keyboard.

28:26 Thin ergonomic Logitech, not into the mechanical ones.

28:31 >> I've got the Microsoft Sculpt ergonomic, which I absolutely love.

28:35 I know Brian's got even more exotic stuff that he's running over there.

28:39 I don't know if I can get mine up here.

28:40 I'll, I'll, I'll do the camera.

28:42 It's like it's mounted to the, no, Oh, my junk too.

28:46 I've got a kinesis.

28:47 Yeah.

28:47 The kinesis inverted ones.

28:49 Those are super interesting.

28:50 What I would like to see would be some keyboard manufacturer saying we're shipping a keyboard to you.

28:57 Oh, and you can program it with Python and basically do this for you as a package thing and just, you know, build it out of these components.

29:04 That'd be fantastic.

29:05 Yeah, that'd be great.

29:06 Well, I think it'd be fun with, with everyone decking out their home offices these days, if you could do a little bit of magic light show while you're presenting or talking on a call, that would be really cool.

29:17 That'd be fantastic.

29:18 Yeah.

29:18 Hey, Brett Cannon's out there in the live stream.

29:20 Dan, you may have heard of this guy.

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

29:33 I don't know which library uses.

29:34 That's awesome.

29:35 So like it's green if everything's good, but it turns red if CI fails or something like that.

29:39 Oh, that's awesome, Brett.

29:40 Thanks for sharing.

29:41 - That'd be cool.

29:42 You know, I never really, I mean, when I first saw the LEDs under the keyboards, 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.

29:52 I want to light up things on my keyboard.

29:55 It'd be fun.

29:56 - Yeah, especially if you could program them, right?

29:58 Like this example here.

29:59 My mouse sits here and pulsates and changes color, but because it's on a Mac, the software doesn't work and I can't do anything with it.

30:07 So it's just annoys me there.

30:08 It's a good mouse otherwise, but anyway.

30:10 So is it a windows only thing or what?

30:13 No, the mouse is perfect on Mac, but the software that lets you customize and do interesting things to the colors doesn't work on the Mac.

30:21 Lame.

30:22 Super lame.

30:23 Super lame.

30:24 All right.

30:25 What is not lame is this last thing that Dan has got here.

30:29 because this thing has been blowing up on Twitter is all of a day old with like 2000 GitHub stars.

30:34 And I was like, oh, this has got to be covered.

30:36 And then Dan, you were on it.

30:37 - Yeah, I just saw it yesterday.

30:38 And I was like, I have to talk about this.

30:41 So I know that when I've built web apps in the past, one of the big frustrations I have is 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.

30:54 You need to add a piece to the API that then returns that new object to users.

31:00 And then in your client code, you need to consume it.

31:02 And so there's all this repetition that you're doing across your web app every time you need to make a change to your data or add a new object.

31:10 And that's very error prone as well.

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

31:21 And then things like FastAPI, you can use Pydantic to return models to your users, to your APIs, but then now we had this thing where you have SQLAlchemy models and Pydantic models, and then you're translating back and forth between them.

31:40 And so Sebastian Ramirez, who just released yesterday this new SQL model library, which looks just awesome because it actually combines the schema for talking to the database and speaking to your API into one schema object that you write.

31:58 So what's really cool about this is that, so the way you work with this is that you define your objects, for example, he's got in the GitHub repo, this hero class with an ID name, secret name, age, and it's got some of the SQL alchemy type things like it's your primary key, the ID is optional, but it's defaults to non, it's primary key.

32:23 So what's really cool about it, this class is both a SQL alchemy model and a Bidantic model.

32:28 I don't know how he did that.

32:31 He said there's some magic that's going on behind the scenes and so what's really cool is that you can use this to instantiate your database.

32:38 So you've got this hero class, you can create objects in the database by going hero one, hero two, hero three, equals hero bracket and pass the name, secret name, all the fields to the object.

32:52 And you can also return those same objects.

32:57 You can use that same hero class and use it in your fast API.

33:00 So you can accept hero objects, you can return hero objects.

33:06 And so that's one, you write that one schema and you use it in multiple places.

33:10 - Yeah, what you have on the screen here for fast API is response model equals the database entity, which that then drives the OpenAPI documentation in addition to just driving, yeah, exactly.

33:23 You got it right there.

33:24 So you can go there and it's sort of end to end the same model, which I think is really great.

33:29 - Yeah, and so you can look at your, with FastAPI, if you go to slash docs, you get the Swagger UI.

33:37 And so you can see that same schema with the ID name, secret name, age.

33:41 And what's really cool about that is that it also has, This generates the openAPI.json.

33:47 And so you can use tools like OpenAPI Generator to even generate client code in any different language that you're using, like Python, JavaScript, Lua.

33:56 And so if you just went back to that original hero class and added a new field, you could potentially have it show up in all different layers of your application with one--

34:07 - Right, including the consuming clients, because they could regen off of the JSON schema, right?

34:12 - Yeah.

34:13 Yeah.

34:13 I think that's really cool. And one other really nice thing that Sebastian did here is that he really emphasized making sure that in the editors that you have a good experience with autocomplete because in the past, stuff like the Django ORM and the SQLAlchemy ORM, the editors have had to write custom code to be able to have a good autocomplete experience for that. And so, Sebastian used type hints really well throughout the design of this so that as you're returning objects from the database, you actually get, you can, once you return that object from the database, you actually get 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 that returns, I can go hero. -- sorry.

35:11 >> Put it at the end of the line, maybe. Or the next line.

35:15 >> Yeah. So, I can access all the properties on the hero object. One cool thing about how he did this, he used a proposal from Eric Trout, the author of PyRite, called the data the class transform that it's this proposal that basically you can annotate various objects to say that they behave like data classes.

35:40 And so that's kind of the magic that allows some of this dynamic behavior to show up in type checkers.

35:46 - I love it because so often you'll do a SQL alchemy query or something and what you get back, it's so many layers, it's lost what that type is.

35:53 - Yeah.

35:54 - It's like, ah, now I gotta like re-annotate it again.

35:56 - Like a search for everything, look at all the different source code in my code base and stuff like that.

36:00 This is really cool.

36:01 >> We've got some great comments in the chat.

36:04 Here's one. I swear Sebastian spends as much time on his docs as he does his code.

36:11 Amazing talent.

36:13 We were talking about type hints in the Azure experience as well.

36:17 Sebastian does a great job with the onboarding experience as well as the developer experience and a lot of large companies could pay attention to what this one person is doing, making it easy for people to pick up a new tool. It's amazing.

36:31 >> I mean, look at the docs here.

36:33 This looks like a professional team wrote all this stuff.

36:36 This is incredible.

36:38 >> Instead, one very productive guy.

36:42 >> Then Brett, good question.

36:44 I want to know how Sebastian manages to release a new very cool project every single year.

36:49 No kidding, man. He has a powerhouse.

36:52 He's changing how we do web development, and it's just one person.

36:58 - Yeah, you know, I think I can speak to that just a little bit, by the way.

37:01 If you look at the magic of FastAPI, you look at what's happening here, these are really nice things to work with, but they're not from the ground recreations of what they are.

37:14 This takes Pydantic plus SQLAlchemy and makes it better.

37:17 FastAPI takes Starlet and Pydantic and makes them better.

37:21 Right, it's like the recombining of things that are already really good into something better.

37:25 - Yeah, and some cool things that come as a result of that repackaging.

37:30 So according to Sebastian, this should support async database sessions out of the box because that's something that SQLAlchemy supports, Alembic migrations as well.

37:40 And in theory, it should be possible to integrate with PostGIS and TS vectors for doing geo stuff and full-text search with Postgres, but he says he hasn't tested it yet.

37:52 - Yeah, I have no idea, but potentially, async and await as well, now that SQLAlchemy supports that.

37:57 - Yep.

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

38:01 I wanna highlight just a couple more comments.

38:03 Savannah on the livestream says, "Sebastian's attention to developer experience "is so awesome." Yeah, I agree.

38:08 Keep it up, Sebastian.

38:09 And Rehan says, "It looks great for a toy case, "but people make professional interior systems.

38:15 "Do they really wanna share the same types "between their database and their REST API?" That's a good question.

38:22 I was thinking about that as well.

38:23 One of the challenges that you can run into when you just sort of say, well, here's my data model out onto the internet as JSON, and then especially taking it back, is you can run into like situations where you overexpose information or you run into a mass assignment type of bugs where values get set or you didn't expect them to be set.

38:42 So with Pydantic, you can do things like, you have to call to JSON, but you can also, or to dict, I can't remember, I think to dict, but you explicitly opt in or opt out certain fields.

38:53 So you could do things like that about bringing those in.

38:56 So pretty neat, but yeah, you gotta be a little bit careful about that.

39:02 But yeah, very cool stuff.

39:03 - You don't want your password hashes on your user object.

39:06 - Exactly, if you're gonna return your user, you don't necessarily wanna exactly return, say, the password hash, or God forbid, not just the straight password.

39:13 You're not hashing it.

39:17 But that's a bigger problem, but still.

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

39:24 Love these.

39:25 We've got Dead Pond, Spider Boy, and Rusty Man.

39:29 Hilarious.

39:30 Love it.

39:31 Yeah, those are great.

39:33 Well, so those are our six items.

39:37 Do we have any extras?

39:39 Got anything to share?

39:40 Ryan, sometimes I have extra, extra nine times here all about it.

39:43 I got none this time.

39:44 How about you?

39:45 Really?

39:46 I've got like two.

39:47 >> Bring on.

39:50 >> First one I wanted to bring up was a really fun episode.

39:55 People know I also do a podcast called Testing Code.

39:58 Episode 163, it's a talk with Stefan Badul about pip install of local directory.

40:08 If you're doing anything where you do the pip install of the local directory, definitely check that out, or especially if you never knew that you could do that.

40:19 It's a good episode. The other thing I wanted to bring up is, it's been like five episodes since I plug my book, but Chapter 12 is up.

40:33 One of the things I got questions about for the first edition was, 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.

40:45 It's testing scripts and applications.

40:48 So it's not a pivot.

40:49 If you don't have a pivot, installable package, you can still use bytest to test it in chapter 12 directly addresses that.

40:55 So when you bring that up.

40:57 Awesome.

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

41:01 Yeah.

41:01 It looks like chapter 12 is coming along.

41:03 Well done.

41:03 You're basically done, right?

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.

41:13 it's going to come out in hard copy early next year.

41:18 So super.

41:19 I have one extra you, Dan.

41:21 Yep.

41:21 So one, one cool library that I wanted to share is a type for PI.

41:26 So we've been talking about types a lot lately.

41:29 Seems like it's a, it's a regular topic of conversation and, they, they can provide a lot of benefits to your code base and to text editors, like VS code or PyCharm.

41:41 But what happens if you want to retrofit or add a bunch of types to a code base that's not typed already?

41:46 That's a big, daunting task.

41:48 And so I came across this library shared amongst our team.

41:52 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:01 So 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 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 attempts from different researchers to create a good machine learning model for inferring types.

42:25 What I like about it is not only is it sort of best in class in terms of its accuracy, is that the author of this machine learning model, open sourced the training data set with 4.3 million type annotations in it, the training code.

42:43 So you can go in and actually use--

42:46 train this on your own code following some of these very simple commands to train the model and pre-process the data with your own code base.

42:54 Open sourced a VS Code extension, so you can actually have developers using it.

42:57 It's not just some, hey, this is our results, QAD, go read the paper.

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

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

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

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

43:32 - Yeah, that's a good bit of warning, - Oh, this looks super cool.

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

43:42 You could even go to Pydantic and use the validate decorator and put that on all the things and then run your tests.

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

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

43:55 Excellent. - Cool.

43:56 - Brian, did you think that was funny?

43:59 - No, no, not funny at all.

44:01 - This might be funny.

44:02 Wait, 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 and woman developer pair and they're just looking like perplexed at each other.

44:34 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 - Take it a bit literal.

44:51 - Very literal.

44:51 All right, well, hopefully that was more funny.

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

45:01 It was shared to us.

45:03 It was first from Carla, not a robot, it's a great handle, and told to us by Blue Fiddle Guy also.

45:12 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. Definitely passed by reference.

45:25 Definitely. Well, this has been fun. So thanks everybody. Thanks Dan for showing up. Thank you for having me. Yeah. Thanks, Brian. Thanks guys Thanks everyone out there. Bye. Bye Thanks for listening to Python bites follow the show on Twitter via at Python bites That's Python bites as in BYTES get the full show notes over at Python bytes FM If you have a news item, we should cover just visit Python bytes FM and click submit in the nav bar We're always on the lookout for sharing something cool 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.

46:00 That's usually happening at noon Pacific on Wednesdays over at YouTube.

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

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

Back to show page