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


Transcript #292: Thursday, it's always a Thursday

Return to episode page view on github
Recorded on Thursday, Jul 7, 2022.

00:00 Hello, and welcome to python bytes where we deliver Python news and headlines directly to your earbuds. This is episode 292. Recorded July 7 2022. I'm Michael Kennedy.

00:10 And I am Brian. Okay. Yeah.

00:12 Great to have you here. Brian. This episode is brought to you by us check out Brian's book. And if you want to course, check out Talk Python Training. Actually a few more topics on that at the very end, some cool stuff going on there. I want to tell people about right now. I would like to hear about your first item something rich, if you will.

00:30 Yeah. So wouldn't be wouldn't be our Python bytes. But podcast if we didn't talk about will will McKagan and his rich project. But

00:42 anyway, it's something built from rich almost always. Yes. Yeah.

00:46 So we'll tweet it out. Fantastic. Today, fantastic project from Phil, he wills, maybe it generates screenshots of commands on the fly from markdown files to keep them up to date. And this is okay, this is great. So like, let's say you got a, you want to do a, like an output from a terminal output from your command or something in your readme, it looks great in a if it's like RIT. Like, here's a kitty cat. I mean, you're probably not going to put that in your butt. But for instance, you might have your help text. And this looks beautiful. And, and wow, that can just show and

01:26 so that's a markdown file. Well, yeah, so that's just

01:29 this, you just stick this little line in your markdown file. And it runs it runs what Rich codecs does is Oh, yeah, I forgot to say what it is. The project is called Rich codecs. What it does is it looks for these, these image tags within your markdown file. And if there's backticks, it figures that you want to run that code, and it runs the code and then puts the output in this image file. And that's it. And that's enough, I

01:58 see. And then include that in your markdown as an image, right?

02:02 Well, it's already there, it's already shows up like this, it doesn't change your readme at all, it doesn't change your markdown file, it just generates the image from from the code for you. And then I say, then you have this. So this is in this right here. So this is an image I'm sure generated from here. And then, you know, you can resize it, and it just, it's an image is this, it's a vector image. So just resizes How cool is that? So, it's really cool. You so you can do these, you can run a command like this, just throw an image in there in your well in your markdown file, or wherever. You can also do code snippets. So you can give it like this, this code snippet of showing us snippet of some JSON, and it will, it'll detect this, this comment out of your code and then embedded as this, this image and show up like this. So colorize your code. So the one of the ideas around this is images are nice, and they really make a readme really easy to mean, they're colorful, it's cool. And we like them. But it's hard to keep up to date. And this way, you can have it keep up kept up to date all the time. What I really, really love about this, so you have all these things. So you can do code snippets, you can even do config files, you can have have, if you want just to generate the image in us, you're not referencing it from your readme, maybe we're referencing somewhere else or something, you can have it generated from like a config file. But the cool thing about all of this is that he's got it set up for for GitHub actions. So you just stick this, this bit of code within your GitHub actions, and it'll regenerate your images for you. It even does. If there's any changes, it even does a commit with your changes back.

03:57 So up, but that's pretty cool. Yeah, so yeah, that's fantastic. Really sweet. Do you check in your readme, the action runs, and then it rebuilds the graphics?

04:05 Yes, exactly. And then you got a nice lookin readme with just like this little tiny line of code in the readme. So nice. Pretty neat.

04:14 Yeah, that's a cool project. Very nice. All right. Well, let's jump over to this one, which is the sent into us by Roman right. And it's actually a project by Ramy. alar. And the project is called V down. That's right. Pydantic Okay, so the idea is, it says Remy says, inspired by Sebastian Ramirez is SQL model, and Roman, the rights beanie. So SQL model, we've talked about that, that is Pydantic models that are also SQL alchemy models. So basically a database layer on top of async that on SQL alchemy that you can do like async stuff and so on, that is built on Pydantic and then beanie is the same thing built on top of Moutere. But the models are Pydantic model. So here's a nother on like an elastic search ORM to do crud results in bulk operations and so on, built on Pydantic. But now talking to Elastic Search, how cool is that? Oh, that

05:16 is that is very cool. Yeah, yeah.

05:18 So if you're gonna do an elastic search, and I feel like this is one of those tools that I don't use, but I'm like, oh, I should probably learn this, because it seems really useful. So let's, let's step up, take a step back real quick. So Elastic Search is part of the elastic stack, right? There's the whole elastic, Dotco company, and so on. But the core of this is the open source Elastic Search, which is a distributed restful search and analytics engine capable of a whole bunch of different things, stores your data for lasting lightning, fast search, fine tune, relevancy, ranking of your search, and so on. And basically search and analytics, right. So if you want to do that, but you want to have your models be cool Python Pydantic models, well, this Pydantic thing is the way to go.

06:03 Nice, kind of fun name to say, Hey, does

06:06 these all have fun names. So the way you do it is, you know, if you know Pydantic, you basically know how to do this, you create a class. And it derives from now in ES model, but you can bet that that's also like a derived classroom, a Pydantic base model model basically, is model base anyway, the base class of Pydantic. And then you just say like name, stir phone, optional, stir, and even, you can do the Pydantic fields stuff. So you could say it's a date time, but the fields a field with a default factory of date, time dot now, all right, all the cool stuff that you would do for Pydantic model. And then you can add a metaclass to add information over to elastic. So for example, the meta here says index is user, then you just set up a connection, you create one of these objects, and you save it, you can change its name and save again, you know, standard ORM stuff, you can get one of these objects by ID. And you can even create new ones delete ones pretty straightforward. The other thing to realize is that uses the unit of work design pattern. So it says this is based on SQL alchemy alchemy session, which is the unit of work applied to SQL alchemy, by the transitive property anyway, you create a context manager, and then you do a bunch of work, and then you commit it. So you can transactionally make changes to your data in Elasticsearch. Oh, that's cool. Like that. Yeah. And that's pretty much it. Right? You can query. There is one. I feel like this is a little bit ironic. The one part missing, still haven't gotten an idea how to wrap the underlying API productively. So how do you search Elasticsearch? I'm not really sure yet, but you could put some into it.

07:45 I love that it just says that just says in the doc still haven't gotten an idea of so to wrap it up.

07:50 I'm Anybody got an idea. So if you shoot me a thought, if you got some ideas out there, and maybe, maybe I'll figure it out. So I guess when you do a regular query, you get these results back, maybe it's a dictionary, I haven't actually tried the raw API for Elastic Search, either. But if you get a dictionary back or list of dictionaries, then you can just jam those into your Pydantic models anyway, right? You can transform the back. But yeah, anyway, if you're doing Elastic Search stuff, you know, check this out. It looks pretty cool. And if you have ideas on how to address that the final bit to do the search in a good way, and you know, maybe take up that conversation.

08:25 Yeah. Nice. Yeah. Cool. Well, I'm gonna stick with kind of some web stuff for a minute and, and talk about pi script again. So we've covered by script several times, I think. And so but I ran across this article called The three things to know before building postscript. And he had to say one of the I haven't played had, you've made a little application with postscript already, right?

08:48 Yes, I have. And I loved it. Yeah, very cool. Well, so

08:51 I hadn't played with it yet. And one of the things I love about this is it's got a little crash course. And it's really short. The crash course is yes, you got to stick this in the head. And that's it. And then in the body, you do you wrap some of your Python code and pi script. And when you print things that comes out, that's pretty much it. Yeah, Crash Course. Well, that's, that's pretty easy.

09:15 One thing I would like to throw in there about the script bit, it's not exactly obvious in a lot of the documentation, but you can host your own runtime of the PIO a diet and pi script, web assemblies and stuff. Okay, so this just downloads it off of there, which I don't think the caching works super well from there, but you can put it in your own place and cache it and so on. Okay, so So I think that's the PI EMV or something. So people are checking that out. And you maybe want to pin it so it's stable or something like that, then you can you can do that, or

09:46 just make sure it's on your server so that you're not pulling off of their server all the time or something, right,

09:51 because maybe they'll change it or who knows. Right? Exactly. Yeah. And that

09:55 was I was curious about that. But it was for when when you're just learning and playing And around with it. You can obviously

10:01 just drop drop the script, Lincoln or Yep, yeah, so a few, just a

10:05 few snippets. And I forgot to mention who wrote this. Brandon Brig. Brandon Riggs, wrote this. And one, the first thing that he brings up is package indentation matters. And I'm glad I would probably want to mess this up. So this is kind of interesting. You can do a pie EMV. And in in one of those tags, HTML tags, but the the packages have to be have dashes, and they have to be all the way to the left. So you can't have those indented with your, your buy in.

10:38 Yeah, it's nuts, because it's, it's basically embedded Yamo. Okay, and Yamo is sensitive to indentation. But whitespace is not supposed to matter in HTML. So if you do auto reformat of the doc, you know, keeps breaking us, you got to be super careful. That's actually interesting. Yeah, it's a

10:55 pain. So for something to watch out for. The next one is local file access, which I'm like, I don't believe this. And I had to try it out and play with it. You because normally you don't access local files through JavaScript, but but you can apparently through the this Python thing, sort of, so you have to set up a paths in your environment. And then I guess was the slash mean, just the current directory or something like that, or I don't know, slash. And

11:23 that's, I think what it means those have to be static files on your web server. So this says, for people listening forward slash views dot CSV, you need to be able to take that URL and jam it into the just a web browser and see the file. So if it was like your server.com/views.csv, that's the little fragment without the domain that goes there.

11:43 Yeah. And then this part when I was trying it just on my own, but the first part actually, you can, you can run a little postscript thing just as a file an HTML file on your computer. But if you're doing this, the the local file thing, it needs a server, so you need to run a little. But there's, there's ways to do so little Python server. Easy. So that that's interesting. The examples is using a CSV file here to just like, import pandas and use pandas to read a CSV file, which is pretty sweet. And yeah, the last bit is DOM manipulation, which I haven't, which, of course, you'd want to do within if you're going to stick some Python code in your, in your in your PI script. But there's just some gotchas that he ran across, or just some things that weren't obvious to him. So that I guess it's a, there's a, for buttons, there's a PI sis on click, or py S dash on click, and then there's a how you get the element, you can get an element through the document and, and then you can put it back you can, you can do pi script, right and write to an element. And there's, it's nice to have this little example to be able to see. So it's good to try this out. So like on this pi scripter, right, it's going to this out out P well, that shows up as an ID and a div somewhere. So you can grab, try to specify where you want to write to. And then yeah, and then how to get this this kind of example is kind of nice, because it has like the grabbing from grabbing from an input field and how to deal with the click and stuff like that. So

13:21 yeah, that's really nice. And it, can you go back really quick to where you have the eat the pie EMV section, and the static file, the CSV. Yeah, a little bit further, a little further back a little further. So one of the things that's really cool is you can actually, in addition to the CSV files, you can put Python files in there. That was one to the other, you can say like, if you had like a helper.py, you could say, somewhere else, import helper, and then call helper not such and such or whatever. And that's all you got to do to kind of like register where the modules live. So you can break your code up and you don't have the example here shows it all written in the HTML file, which is kind of insane. And you should put those into separate files, if you wouldn't do that with JavaScript generally. Right? So you should do it with Python either, right? So that's, it's really easy to use that path thing to break it up across Python files, you get full autocomplete and everything with

14:13 and then same thing, then would you would your Python file have to be served? So you could just stick it on?

14:18 Yes. Yeah. Just yeah. So that part, the client side, so we're to say the client side Python files have to live in a static servable. dissection. Okay, normally, that's not possible. Okay. Let's blocked as it should be.

14:32 Nice. Anyway. Interesting. This was enough to get me to try it to try price grip, because it was pretty fun. It was pretty cool.

14:42 Yeah, it's very fun. And it's, it's quite neat. All the things you can build. And I think we're just at the beginning, right? A lot of the examples are data science oriented, but some of the things you showed like the events and the DOM manipulation and whatnot, you can build full fledged JavaScript, Brennan style apps, they don't have to Be only showing graphs and data frames, you know, right. And

15:03 I think I think we're gonna see some interesting stuff because like you said there, if you serve up your, like extra helper file or in Mesa basically might be most of your code actually is in these extra files, then, then we really can, I mean, it's awesome. Some do most of your code to do demos, and it's all live and everything and pretty cool to me. Fantastic. And when I tried this, the delay actually surprised me. It shouldn't surprise me because it's pulling in the whole whatever, the PI script library and everything, but it does like this little spinny wheel thing, and you gotta wait a few seconds. Now for a lot of applicant. And I think that's one of the reasons why I think data sciences can really take off quickly is because they're not going to it's an internal thing, you're not bothered by it. It's not something I would, I don't think it's, I'd like it to be the point where you could you could really use Python instead of JavaScript in in a customer application or something, but I don't think it's gonna be

16:01 it's gonna be a while before you see it in like a landing page scenario. But you may well see it in the equivalent of Gmail, but control, you know, like that kind of Apple, you open it, and you stay on there for a while. That's true, especially if it's an internal app. Yeah,

16:14 some back end stuff. Yeah, sure. Yeah. After afternoon,

16:17 I gotta log into the thing. And I sit and then like, so the video that I did last month or so was about how do you host that and then do a progressive web app. So that stores that offline, in which case, the web app startup time is like one second? Always, like it's really, really quick. If you get it off of the server, like they list here that it takes a lot longer. So anyway, cool. Let's try that next. But yeah, it's yeah, I'm super excited about this. This is great. All right, what do I have next? Let's see. Okay, we covered these. Next up more fun names. This one comes to us from Sean Koenig. And it says, Hey, this might be a good one the, you like punny names. So this is dis snake. The is Nick this Nick and dislike. So this snake is a modern, I agree with that you'll see in a second easy to use feature rich async API wrapper, and Python for debt for discord. Okay, so discord being the Yeah, like the community place, there's a lot of stuff happening there. You know, it's a little feels a slightly different role than slack and teams. But you know, more community oriented rather than company oriented, I suppose. Although you can sort of do that with Slack. It's not really like it's focused. It's more some of the people jammed it into like, for example, if you want to save the history of your community, and you're doing slack, you've got to pay per user. But it's like, if it's a public community, like everyone who randomly shows up, you're like, $8 a month for them to Oh, no, right. So for lots of reasons for gaming, and others, Discord is very popular. But what you can do is you can create bots, for your community that do fun things. And this is a way to do that fun and easily in Python. So features include modern async, and await API, one of the problems apparently you run into is you can overrun your rate limit by being too chatty. So it has built in, like rate limiting, so it doesn't destroy, he doesn't get 409 Too many requests errors. It has a really cool command extension, you'll see in a moment, object oriented and both optimized for speed and memory. Okay, so that's pretty cool. Probably the best way to understand is to just check out the quick, quick start. Here's a minimal bots. Here's what you do, Brian, you import this snake. And you create a client that with a dis snake client, and then you call, you create some functions, and you decorate them. And then you say client that running give your API token. So then you just write regular async functions. It handles the execution of the async functions, but they need to be async. And you just say, here's an event for on ready. Okay, here's an event on message. So if somebody sends a message to that community, then it's going to call back into here straightaway. Oh, interesting. All right, so just this function, and this on message function gets called every time a message happens, including if the thing itself sends a message or the account itself. So it sort of checks to make sure it doesn't go into like some sort of infinite loop where it sends out messages if you send a message, but it just checks Hey, if you send the string dollar Hello, it'll send back hello, the dollar means send this to the bot, you know what I mean? Okay, in this world, so yeah, that's pretty much how it works. It's kind of interesting, but if you look at the commands and it gets way more powerful, so the commands are what people would probably think of like what I want to do with a bot so with this minimal bot, what you do is you sync the events like on message and ready and such but with the commands you can go over here to the import the bot thing and say at decorate another async function at bot decorate command. And this one's called foo. So when that's the case, it takes arguments and so on in discord, you can write dollar foo, and then other stuff and that other stuff goes to the argument. So all you got to do is have a single function with that name and you put the decorator on And now the sudden that's a command in discord that talks to the bot. Oh, that's cool. Yeah. Isn't that easy? Yeah, yeah. So there's some other examples, you can register your bot with a prefix. So you could use, I don't know, exclamation versus Dollar versus whatever it is you want to do. And by default, the command name is the same as the function name. But you can also pass in a name like for example, if the name is list can have a function called list because it'll freak out what list means. So you can give it a name, and then use a different function name and so on. And then again, passing arguments and such. So there's some cool little examples of they're saying dollar tests. Hello, and the documentation bot says hello, they say dollar test. Hello, world. Hello, world. So

20:43 yeah, we Okay, so I was thinking stuff like you could give give people access to some of these commands. Like if you want to subscribe to my newsletter, you could give it a subscribe command with your email address and subscribe yourself something.

20:57 Yeah, you could totally do that. Or you could just on on the bot side of things, you have the command, it takes an argument, which is the email and then you just use the MailChimp or whatever API to just stick them in there. Yeah. And that's running on your server so it can do you know all sorts of things. Interesting. Yeah. Cool. So if you want to do something with discord, check this out. I haven't I haven't used it because I haven't tried to build a bot for discord. But this looks pretty fun. So

21:21 check that out. Definitely. Yeah.

21:23 So that's our items for today. Do you have any, any extras for us?

21:29 I have extras? I do. I do have extras. And I actually came up with another extra. Okay, while I was thinking about the extra, so yeah, yeah. Okay. So some exciting stuff. Let me pull my screen back up here. What's the order? I want to talk about this one first. So last time, I spoke about the monitor API's with FastAPI MongoDB Bini Python as a in person live course that runs for two weeks that I'm teaching. And people can check that out starts on August 8. So I'll link to that. But that's not my item. Because that's what I talked about last time, what I decided to do is I'm opening up a scholarship program for people who are underrepresented in the Python space and program in general, and who maybe also just need a hand up different groups there. So you're a woman in tech or a person of color, or maybe you lost your job. And you're like I'm trying to get into programming. Maybe this course will help me do that, like trying to get in programming as a job. Check out this scholarship link that I put in here. And I'm saving some spots in that live course for people who benefit from that.

22:28 Oh, that's pretty cool. Kudos. Nice. Thanks. Yeah,

22:31 thanks. Okay. Now, just this is fresh, hot off the presses, as in is one hour and 30 minutes old. We have operation Python 2022 software bundle from hunt Humble Bundle. So we're doing another Humble Bundle this year. And I've got my Git course. And I've got a course and a Pythonic code course that I put in there for people to take. But there's also 24. Other topics, like some stuff from real Python, some stuff from Raven learner, pi charm, and so on. So people can look through there and check that out. It's certainly a good way to get a deal on Python. educational stuff. Nice. Cool.

23:11 That's pretty cool. All right. And

23:11 here's the one that that Yeah, thanks. I'm pretty excited about that. Last one was I told you about these crazy headphones that I have. And I just want to tell people quick about this. So I got this thing called Ultimate ear fits up fit. And there are these fitted earplugs ear buds, which I'm wearing now, obviously, on the YouTube channel. And what they do is they come really soft and mushy. And they're light sensitive and heat sensitive. You put them in your ear and you press a you pay them to your phone, you press a button, they start blazing out light and heat and they form to the shapes of your ears. So Brian, what do you think of that? That's,

23:46 I don't know. All right. Yeah, that

23:48 sounds pretty cool. I just don't want it to go too far and take over my brain.

23:52 What if it's too much in it? Yes. If it gets in there, and you don't know you can't, can't get it out. That's probably why you and I were talking about that right before we started. So I thought I'd just give a quick shout out to that. So how's that sound? So far? It sounds great. It's kind of like you're wearing earplugs. So the sound is a little bit blocked out. But then there's a speaker on the inside. Yeah. Any extras from you?

24:13 I don't have any extras. All right. Well, let's tell the joke then. Okay.

24:17 So this one is a proposed more of a comment on a proposed idea which, gosh, it probably will never happen. But I wish it would says if we're going to unionize and forget wage, increased wages and that kind of stuff. I want this instead as a software developer. And what it is, is it's a proposed new standard year, which breaks up the year into 13 different months. Yeah, they're all 20 days, which almost exactly rounds out the year. So every single month, the first is Sunday. The fifth is Thursday. The 26th is a Thursday, it's always the same year after year after year. So you know about the days you know how many months it is yeah, how long I If you have 28 days or 45 days from now, you know, doesn't matter what month you're in on how far that pushes you until the next month, but there's one day leftover, it says, The Day The one day leftover is New Year's Day. It isn't a weekend or a weekday. It's magic and only beers. It's a double vacation day. The rest is easy. If someone says I'll see you on the 19th. You know, it's on a Thursday doesn't matter what month. What do you think of this?

25:24 I? I've always been a proposal proponent to the fixed calendar. I think it's great. Yeah. And I'm I don't remember the history, but I'm pretty sure that we probably started out this way. Because it's the it's the lunar calendar, essentially. Yeah, yeah, pretty much. Yeah. And I thought I read somewhere once that people were freaked out by the number 13. So they dropped 12 or something. I'm sure somebody in the chat or somebody.

25:49 I think we could fix it if you just started with zero base.

25:54 That's better. Yeah. January zero. Perfect. Exactly.

26:01 Yeah, anyway, it's sort of a joke, but the comment about it, that's the joke. Yeah, like you got any other jokes you want to share? Is that no, I

26:10 don't. All right. Fantastic. Good talking to you again. Well, yeah. It's

26:14 great to talk to you as always. Thanks for being here. And thanks, everyone, for being on the audience. Yeah.

26:19 Thank you. Bye. Cheers. Bye.

Back to show page