Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 292, recorded July 7th, 2022.
I'm Michael Kennedy.
And I am Brian Okken.
Yeah. Great to have you here, Brian.
This episode is brought to you by us.
Check out Brian's book.
And if you want a 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.
Yeah.
So it wouldn't be our Python Bytes podcast if we didn't talk about Will, Will McCoogan and his Rich project.
But anyway.
Something built from Rich almost always, yes.
Yeah.
So Will tweeted out, fantastic today.
Fantastic project from Phil Ewells, maybe.
It generates screenshots of commands on the fly from Markdown files to keep them up to date.
And this is great.
So let's say you want to do an output from a terminal output from your command or something in your readme.
It looks great if it's like, here's a kitty cat.
I mean, you're probably not going to put that in you.
But for instance, you might have your help text.
And this looks beautiful.
And that can just show up.
And so that's a Markdown file?
Well, yeah.
So that's just this.
You just stick this little line in your Markdown file.
And it runs what Rich Codex does.
Oh, yeah.
I forgot to say what it is.
The project's called Rich Codex.
What it does is it looks for 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 see.
And then includes that in your Markdown as an image, right?
Well, it's already there.
It 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 the code for you.
And 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 can resize it.
And it's an image.
It's a vector image.
So it just resizes.
How cool is that?
That is really cool.
So you can do these.
You can run a command like this.
Just throw an image in there in your Markdown file or wherever.
You can also do code snippets.
So you can give it like this code snippet of showing a snippet of some JSON.
And it will detect this comment out of your code and then embed it as this image and show up like this.
So colorize your code.
One of the ideas around this is images are nice.
And they really make a readme really easy to...
I mean, it's colorful.
It's cool.
And we like them.
But it's hard to keep up to date.
And this way, you can have it kept up to date all the time.
What I really, really love about this is so you have all these things.
So you can do code snippets.
You can even do config files.
You can have...
If you want just to generate the image and you're not referencing it from your readme, maybe you're referencing it 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 GitHub Actions.
So you just stick 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 in.
That's pretty cool.
Yeah.
Yeah, yeah.
That's fantastic.
Really sweet.
You check in your readme, the action runs, and then it rebuilds the graphics.
Yes, exactly.
Cool.
And then you got a nice looking readme with just like this little tiny line of code in your readme.
Nice.
Pretty neat.
Yeah, that's a cool project.
Very nice.
All right.
Well, let's jump over to this one, which is sent in to us by Roman Wright.
And it's actually a project by Rami Awar.
And the project is called...
Let's see.
Scroll down.
Get this right.
Piedastic.
Okay.
So the idea is, it says, Rami says, inspired by Sebastian Ramirez's SQL model and Roman the
Wright's Beanie.
So SQL model, we've talked about that.
That is Piedantic models that are also SQLAlchemy models.
So basically a database layer on top of Async that on SQLAlchemy that you can do like Async
stuff and so on.
That is built on Piedantic.
And then Beanie is the same thing built on top of Motor, but the models are Piedantic models.
So here's another one, like an Elasticsearch ORM to do CRUD results and bulk operations and
so on.
Built on Piedantic, but now talking to Elasticsearch.
How cool is that?
Oh, that is very cool.
Yeah.
So if you're going to do an Elasticsearch 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, take a step back real quick.
So Elasticsearch is part of the Elastic stack, right?
There's the whole Elastic.co company and so on.
But the core of this is the open source Elasticsearch, 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, you know, 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 Piedantic models,
well, this Piedastic thing is the way to go.
Nice.
Kind of fun name too.
So to get, it does, these all have fun names.
So the way you do it is, you know, if you know Piedantic, you basically know how to do this.
You create a class and it derives from now an ES model, but you can bet that that's also
like a derived class from a Piedantic base model, model base.
I think it's model base.
Anyway, the base class of Piedantic.
And then you just say like name, stir, phone, optional stir.
And even you can do the Piedantic field stuff.
So you could say it's a date time, but it's a field with a default.
Factory of date time dot now, right?
All the cool stuff that you would do for a Piedantic model.
And then you can add a meta class 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 yeah, you can even create new ones, delete ones.
Pretty straightforward.
The other thing to realize is it uses the unit of work design pattern.
So it says this is based on SQLAlchemy session, which is the unit of work applied to SQLAlchemy.
So, you know, 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.
Yeah, I like that.
Yeah.
And that's pretty much it, right?
You can query.
You know what?
There is one.
I feel like this is a little bit ironic.
The one part missing.
Still haven't got 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 something to it.
I love that it just says that.
It just says in the docs.
Still haven't got an idea of how to wrap the underlying API.
Anyone got an idea?
So shoot me a thought if you've got some ideas out there.
Maybe you all can 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 Elasticsearch either.
But if you get a dictionary back or list of dictionaries, then you can just jam those into
your pridantic models anyway, right?
You can transform them back.
But yeah.
Anyway, if you're doing Elasticsearch 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,
then, you know, maybe take up that conversation.
Yeah.
Nice.
Yeah.
Cool.
Well, I'm going to stick with kind of some web stuff for a minute and talk about PyScript
again.
So we've covered PyScript several times, I think.
And so, but I ran across this article called the three things to know before building PyScript.
And I got to say one of the, I haven't played, you've made a little application with PyScript
already, right?
Yes, I have.
And I loved it.
Yeah.
It's very cool.
So 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 wrap some of your Python code in PyScript and when you print
things, it comes out.
That's pretty much it.
Yeah.
Crash course.
That's pretty easy.
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 PyOidite and PyScript
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 I think that's the PyEMV or something.
So if people are checking that out and you maybe want to pin it so it's stable or something
like that, then you can do that.
Or just make sure it's on your server so that you're not pulling it off of their server all
the time or something.
Right.
Because maybe they'll change it or who knows, right?
Right.
Exactly.
Yeah.
And I was curious about that, but for when you're just learning and playing around with
it, you can obviously use it.
Just drop the script link in there.
Yep.
Yeah.
So just a few snippets.
And I forgot to mention who wrote this.
Brandon Riggs wrote this.
And the first thing that he brings up is package indentation matters.
And I'm glad I probably would have messed this up.
So this is kind of interesting.
You can do a PyEMV and in one of those tags, HTML tags.
But 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 PyEMV.
Yeah.
It's nuts because it's, it's basically embedded YAML.
Oh, okay.
And YAML is sensitive to indentation, but white space is not supposed to matter in HTML.
So if you do auto reformat of the doc, it keeps breaking it.
So you got to be super careful with that section.
Interesting.
Yeah.
It's a pain.
So for something to watch out for, the next one is local file access, which I thought,
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 this Python thing, sort of.
So you have to set up a paths in your environment.
And then I guess, what does the slash mean?
Just the current directory or something like that?
Or I don't know.
Yeah.
I think it'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.csv, you need to be able to take that
URL and jam it into the, just the web browser and see the file.
So if it was like your server.com slash views.csv, that's the little fragment without the domain
that goes there.
Yeah.
And in this part, when I was trying it just on my own, but the first part, actually you
can, you can run a little, a PI script thing just as a file, an HTML file on your computer.
But if you're doing this, the, the, the local file thing, it needs a server.
So you need to run a little, but there's a, there's ways to do still a little Python server.
Um, easy.
Um, so that, that's interesting.
Uh, the, and his examples is using, using a CSV file here to just, like, import
pandas and use pandas to read a CSV file, which is pretty sweet.
Um, and I, the last bit is DOM manipulation, which I never, 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 can't ran across or just some things that weren't
obvious to him.
So that, I guess it's a, there's a, there for buttons, there's a Pisys on click, or
PYS 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 right 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, we're PI script, 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 a grabbing from an input field and how to deal with the click and stuff like that.
So, yeah, that's really nice.
Um, and it, can you go back really quick to where you have the, the E, the PI 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 these CSV files,
you can put Python files in there.
Yeah.
I was curious about that.
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.suchandsuch or whatever.
And that's all you got to do to kind of like register where the modules live.
Okay.
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.
You wouldn't do that with JavaScript generally.
Right.
So you shouldn't 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.
And then same thing then, would you, would your Python file have to be served so that
you could just stick it on a.
Yes.
Yeah.
Just serve it.
Yeah.
And so that part, the client side, so weird to say, the client side Python files have to
live in a static, servable section.
Okay.
Normally that's not possible.
Right.
Normally that's blocked as it should be.
Yeah.
Nice.
Anyway, interesting.
This was enough to, to get me to try it, to try a price script because it was pretty
fun.
So that's pretty cool.
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 run-in
style apps.
They don't have to be only showing graphs and data frames, you know?
Right.
And I think, I think we're going to see some interesting stuff because like you said there,
if you serve up your, like extra helper file or it may, basically it might be most of your
code actually is in, in these extra files.
Then, then we really can, I mean, it pulls some, some do most of your code and do demos and
it's all live and everything.
And that'll be pretty cool.
It'll be fantastic.
Now, when I tried this, the delay actually surprised me.
It shouldn't surprise me because it's pulling in the whole, whatever the PyScript library
and everything, but it does like this little spinny wheel thing.
And you got to wait a few seconds now for a lot of applicants.
And I think that's one of the reasons why I think data scientists could 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 going to be a while.
Yeah.
It's going to 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 internal, you know, like that kind of app where
you open it and you stay on there for a while.
Yeah, that's true.
Especially if it's an internal app.
Yeah.
Some backend stuff.
Yeah, sure.
Yeah.
After, after, you know, I got to log into this 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 it 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, then it takes a lot longer.
So anyway.
Cool.
We'll have to 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, D I S snake.
Dis snake.
And dis snake.
So dis snake is a modern.
I agree with that.
But you'll see in a second, easy to use feature rich async API wrapper in Python for that, for
discord.
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, kind of 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 focus.
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 too.
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 a 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, it doesn't get a 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.
Uh, probably the best way to understand is to just check out the quick, quick start.
So here's a minimal bot.
Here's what you do, Brian.
You import to snake and you create a client at with a dis snake dot client.
And then you call, you create some functions and you decorate them.
And then you say a client dot run and you 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 or on ready.
Here's an event on message.
So if somebody sends a message to that community, then it's going to call back into here straight
away.
Oh, interesting.
All right.
So just this function, 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, you 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, you know, 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
it.
And now all of a sudden that's a command in discord that talks to the bot.
Oh, that's cool.
Yeah.
Isn't that easy?
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, you can't 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 test.
Hello.
And the documentation bot says, hello.
And they say dollar test.
Hello world.
So yeah.
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.
Yeah.
You could totally do that.
And 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 and check this out, I haven't, haven't used
it because I haven't tried to build a bot for discord, but this looks pretty fun.
So check that out.
Definitely.
Yeah.
So that's our items for today.
Do you have any, any extras for us?
I have extras.
I do.
I do have extras and I actually came up with another extra while I was thinking about the
extras.
So yeah.
Yeah.
Okay.
So some exciting stuff.
Let me pull my screen back up here.
What's the order I want.
Let's talk about this one first.
So last time I spoke about the modern APIs with FastAPI, MongoDB, Beanie, 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 8th.
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 programming in general and who maybe also just need a hand up through
different groups there.
So if 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.
I could try and get into programming as a job.
Check out the scholarship link that I put in here and I'm saving some spots in that live
course for people who could benefit from that.
Oh, that's pretty cool.
Kudos.
Nice.
Yeah.
Thanks.
Yeah.
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 humble bundle.
So we're doing another humble bundle this year and I've got my Git course and a cutter 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 Rufin Lerner, from PyCharm 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.
That's pretty cool.
All right.
And here's the one that, yeah, thanks.
I'm pretty excited about that.
The last one is I told you about these crazy headphones that I have.
And I just want to tell people maybe quick about this.
So I got this thing called Ultimate Ear Fits, UE Fits.
And there are these fitted earplugs, earbuds, which I'm wearing now, obviously on the YouTube
channel.
And what they do is they come really soft and smushy and they're light sensitive and heat
sensitive.
You put them in your ear and you press up, you pair 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, I, I don't know.
Unusual, right?
Yeah, it sounds pretty cool.
I just don't want it to go too far and to take over my brain.
What if it's too mushy and it, yes, if it gets in there, you don't know, you can't, can't
get it out.
No, it's probably safe.
Anyway, you and I were talking about that right before we started.
So I thought I'd just give a quick shout out to that.
That's kind of fun.
So how's the 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.
Okay.
Nice.
Yeah.
Any extras from you?
I don't have any extras.
All right.
Well, let's tell the joke then.
Okay.
So this one is a proposed, more of a comment on a proposed idea, which gosh, it probably
will never happen, but I would wish it would.
It 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 28 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, how long, if you have 28 days
or, you know, 45 days from now, you know, it doesn't matter what month you're in on how
far that pushes you into the next month.
But there's one day left over.
It says the day, the one day left over is new year's day.
It isn't a weekend or a weekday.
It's magic.
And on leap years, it's a double vacation day.
The rest is easy.
Someone says, I'll see you on the 19th.
You know, it's on a Thursday.
Doesn't matter what month or anything.
What do you think of this?
I, I've always been a proposal, a proponent to the fixed calendar.
I think it's a great idea.
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.
Pretty much.
Yeah.
And I thought I read somewhere once that the people were freaked out by the number 13.
So they dropped it to 12 or something.
I'm sure somebody in the channel or somebody will.
I think we could fix it.
If you just started with zero based.
Oh, zero to 12.
Zero to 12.
That's better.
Yeah.
January zero.
Perfect.
Exactly.
Yeah.
Anyway, it's sort of a joke, but the comment about it, that's the joke.
Yeah.
You got any other jokes you want to share?
Is that a.
No, I don't.
I didn't.
All right.
Fantastic.
Good talking to you again.
Well, yeah, it's great to talk to you as always.
Thanks for being here.
Thanks everyone for being out in the audience.
Yeah.
Thank you.
Bye.