Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is 394, recorded July 30th, 2024.
I am Michael Kennedy.
And I'm Brian Okken.
And this episode is brought to you by Scout APM.
Thank you, Scout APM, for sponsoring the show.
We will tell you more about them later.
If you want to connect with us on the socials, the best but not the only place is over on Mastodon,
where all the links, me, Brian, and the show, all have our accounts list at the top of the page of the show notes.
You'll see in your podcast player or the website.
Also, if you're not joining us live and you would like to, we record Tuesdays at 10 a.m. Pacific time.
Check that out, pythonbytes.fm.com.
You'll see all the older versions under the live section on our YouTube channel there.
And finally, you probably do want to also get a summary of this episode in your email.
I'm sure you do.
A handcrafted, artisanal Brian Okken special email.
So just visit pythonbytes.fm.
Click on newsletter.
Enter your information.
We won't give it away.
Share with other people.
Resell it.
Retarget you.
Do evil things.
We just will communicate with you about stuff we're up to, mostly the show.
Brian, I learned Python.
It was a good weekend.
Is that the same?
Is that what you're telling me for your first item here?
Oh, okay.
Look, where are you going with this, Michael?
Michael, I think you've known it for a while.
No, I bundled the joke a little bit, but yes.
That's all right.
I thought Python is easy, I hear.
Yeah, Python is easy now, apparently.
No, I love Python.
Anyway, what I wanted to talk about was beyond hypermodern or postmodern.
I'm not sure what the tagline is, really.
So this is an article by Chris Ardern.
Chris?
Sorry about it.
I probably mangled your last name.
But I really like the article, Chris.
So what is this?
So the title is Beyond Hypermodern, Python is Easy Now.
And this is a reference to hypermodern Python that was, he says it came out like, as a series
that came out four years ago or something.
Interesting.
But it's, what was, who was the hypermodern person again?
Can't remember.
Oh, I should have looked this up anyway.
Claude, Claudia, Claudio, Claudio, oh, I'm not going to try.
Claudio's book, Hypermodern Python Tooling, is now as a book, which is cool.
Good job.
But that's not what we're talking about.
We're talking about beyond hypermodern or from the URL postmodern.
So what is this?
Basically, it's talking about all the tooling and it's all in Rai now.
So this is what Chris's idea is, is you could do so much in Rai.
And actually, I knew Rai did a lot, but Rai actually does more than I thought you could.
So Rai is a tool that's like kind of does a lot of stuff around Python.
So there's setup.
It goes through setup, linting, typing, testing, documentation, CICD.
And then there's a bonus section on monorepo.
But I really liked just walking through, like if you wanted to try out Rai, all the different,
like the workflow, going through the entire workflow of building a Python project.
Like the setup part is setting up an initial directory, including setting up your pyproject.toml
and setting up some different directories, which is great.
Just sets up the structure for you.
There's a lot of files here that like I don't often, to tell you the truth, I don't use lock
files a lot.
Partly because I'm using, I'm often developing Python modules or packages, which I don't really
lock stuff.
Locking is more regularly around applications.
So do you have lock files for some of your application stuff, Michael?
All of them.
I use the pip compile workflow.
Okay.
So I've got like one thing that specifies the top level requirements and then another one
that is the lock file using a uv hip compile.
Okay.
One of the things that I didn't think about was like requirements for the requirements dash
dev lock.
So instead of requirements on text, these are the dependencies are in your pyproject.toml,
but there are a lot of requirements lock files.
But a dev lock file, that I might actually have even for a package to make sure all the developers
are using the same thing.
So that's kind of interesting.
It makes a lot of sense.
I was just had, when did I publish it?
This, was that this week's episode?
I can't remember.
Very, very, very recently.
David Lord from Flask on Talk Python.
Yeah.
And one of the things they're working on is creating a more repeatable environment for contributors
and developers to Flask.
So like you Flask, you don't want to just pin the versions of everything because that wrecks
everybody else's options to work with different versions.
But you do want to make sure that people who do PRs have the same setup as people who are
reviewing the PRs.
So he talked a lot about having a hind requirements for developers of the project, but not the
project itself.
Yeah.
That's a cool idea.
So that's set up.
There's, you can do linting with it.
The testing section talks about pytest.
Yay.
But the, one of the things that I thought was kind of neat was this, and I think I knew
this, but anyway, this idea of scripts.
So within your PyProject Tomo, you can set up Rai scripts.
So they're basically extra commands that do things like, so you can say like Rai run test.
And so the run command runs your script.
So you can say run in a test is a thing that you've said that just like defaults to Rai test.
But things like Rai run check might be running PyRite or for linting or for type checking
or linting is a Rai lint with a fix or something.
So all these different, if you, if you've, especially if you've got other people on the team, having
some way to do all of this is good.
And then a kind of a neat thing that I, that's probably as nice as being able to chain scripts.
So if you've got like running your form auto formatting and linting and their type checking and
also running your tests.
But then if you want to do all of them, there's a way to just chain them up within the PyProject
Tomo's, which is kind of cool.
Yeah, that's very cool.
It's kind of takes the place of where I would use either where I used to use make files.
Now I use talks commands for.
But so a lot of this around if you don't need it, I'm guessing this doesn't create a
new virtual environment, but I haven't played with it yet.
But that's where talks would do that.
So there's a discussion around documentation.
It isn't really a Rai thing, but just talking about documenting things well.
But I really kind of like this article about like, if you want to try out mostly because
I do want to try out Rai and this kind of walks through all the different things it does within
your workflow and where you might want to pull it in.
And I do, I do appreciate that Rai has some configuration.
So apparently the default packaging tool is hatch, but this person, Chris, wanted to use PDM.
So you can set that, but I'd probably leave it as hatch because I like hatch, but might do
something different.
But you can even set a dependency operator.
So whether you want it to be like approximately equal to or greater than equal or whatever, kind
of neat.
The bonus is really kind of fun.
I actually just ran into a project where I have to help support, which is a large repository
with multiple Python projects in it.
And so I'm looking forward to reading through how possibly this documentation around dealing
with monorepos in Python.
This is on my to-do route, to read next list.
That's cool.
That's next level stuff right there.
Yeah.
Well, very, very cool.
Well, I, Brian, am happy to report, I think, that the GIL has been vanquished.
But-
We are now in the epoch of free-threaded Python.
So how might you test this out and see if it's actually worth it and so on.
Okay.
So Simon Wilson, one of his Today I Learned, is trying out free-threaded Python on macOS.
Could be others as well.
But you can just go to, this is interesting.
I didn't realize that you would be able to get free-threaded Python this way from the PEP.
It's like, you've got to get a special build of it.
And it's just like its own thing.
Right?
Yeah.
But if you get the macOS installer, I don't know about the others, but presumably the Windows
one has something similar or will.
I don't know.
Go to install this.
You can set up the options, custom install.
And you can just check off a checkbox to install a separate binary for free-threaded Python 313
instead of guild Python.
Wow.
And that's just from the python.org download.
Yeah, exactly.
Wow.
Exactly.
Yeah.
Just to get that downloads beta 3 of it.
And there it is.
So you just hit customize your install and boom.
So that alone is kind of interesting.
Yeah.
And then once you do that, you get not just a Python 3.13, but a Python 3.13 T.
It's interesting.
But not FT.
I mean, the other one should have a T on it.
Come on.
If it's going to be threaded.
I don't know.
Anyway, T, whatever.
You get one that is like, that's the one you can run in the command line for free-threaded
Python.
And Simon points out, like, didn't really put this in the path because it's beta.
I don't want to mess stuff up.
But nonetheless, there it is.
So let's test it out.
It comes up with a simple little program that just does some CPU bound thing.
This is the important thing.
We've, for a long time since Python 3.4, had really good options to parallelize IO bound
or waiting types of things.
I'm talking to a network.
I'm talking to a database.
I'm talking to whatever with asyncio, right?
Yeah.
But the CPU bound stuff, the GIL would stop and go, yeah, no, I don't care how many cores
you got.
You got one, right?
Yeah.
And so this is just summing up a bunch of numbers, the squares of the numbers,
just like doing some computational busy work, right?
So it says, okay, well, let's set up a little app that'll take some parameters so we can feed
it different information and see what we'll get and then run it on a thread pool executor
with as many threads that are specified.
So it starts out just to skip ahead.
So look, I ran it once.
I get one core.
It says 99% CPU usage on macOS that it reports this as a hundred percent basis as being one
core fully busy.
So if you've got eight cores, this could go up to 800%.
It's kind of weird.
Anyway, 99% CPU if you run the regular one.
But if you run the free threaded one, he was getting some number that was a little low.
There's a bug.
It's not super relevant about him fixing the bug or not.
I don't really think that matters.
But what the takeaway is, if you run it with four threads, that whole workload ran in 1.3 seconds.
You run it with 12 threads.
It went down to one second.
I don't know how many cores he has.
I don't believe it said.
But with the gill, that's four seconds versus one second or 1.3 seconds for the basically
four times as fast.
Presumably, this is a four core system.
I'm not sure.
Anyway, pretty cool, right?
That is pretty cool.
So yes, that's faster.
Four times faster is 400%.
That's no joke.
That'll make a difference for some people.
But I think more relevant is just like, hey, look, apparently the installers have it.
Right?
That's kind of cool.
Yeah.
Okay.
I was chuckling because I said testing it out.
It says, I asked Claude 3.5 Sonnet to write me a quick test script.
But the script it come up with is something I know that he can write on his own.
Yeah, exactly.
Exactly.
Yeah.
It didn't come up with something all that interesting.
And it introduced a bug.
He should have just written it himself.
Oh, well.
But this is neat.
Actually, I saw the announcement that there were some builds of the free threader one,
but I didn't know you could just do it, like click it from the installer.
That's cool.
Yeah.
That's the big news I took away as well.
Very cool.
Neat.
Very neat.
And you know what you don't have to build yourself is an APM platform.
Right.
We could let Scout do that for you.
Let me tell you real quick about Scout APM.
They're big supporters of Python Bytes.
So we appreciate that very much.
So if you are tired of spending hours trying to find the root cause of issues impacting your
performance, then you owe it to yourself to check out Scout APM.
They're a leading Python application performance monitoring tool, APM, that helps you identify and solve performance abnormalities faster and easier.
Scout APM ties bottlenecks such as memory leaks, slow database queries, background jobs, and the dreaded N plus one queries that you can end up if you do lazy loading in your ORM.
And then you say, oh, no, why is it so slow?
Why are you doing 200 database queries for what should be one?
So you can find out things like that.
And it links it back directly to source code so you can spend less time in the debugger and healing logs and just finding the problems and moving on.
And you'll love it because it's built for developers by developers.
It makes it easy to get set up.
Seriously, you can do it in less than four minutes.
So that's awesome.
And the best part is the pricing is straightforward.
You only pay for the data that you use with no hidden overage fees or per seat pricing.
And I just learned this, Brian.
They also have they provide the pro version for free to all open source projects.
So if you're an open source maintainer and you want to have Scout APM for that project, just shoot them a message or something on their pricing page about that.
So you can start your free trial and get instant insights today.
Visit pythonbytes.fm/scout.
The link is in your podcast player show notes as well.
And please use that link.
Don't just search for them because otherwise they don't think you came from us.
And then they'd stop supporting the show.
So please use our link pythonbytes.fm/scout.
Check them out.
It really supports the show.
What's next, Brian?
I want to iterate into the next topic.
I want to talk about iteratools.
So this comes from Rodrigo from Maths.
pp.com.
And he writes a lot of great articles.
But I and I know we've covered iteratools before and people have heard of iteratools and it's built into Python.
But there's so many goodies in there that I like to have people tell me what their favorites are and reshaping.
So this is an article that groups all of the, I think there's more than 20 in there.
But anyway, 20 tools that every Python developer should be aware of from iteratools.
And it's broken into five categories.
There's reshaping iterators, filtering iterators, combinatorial, infinite, and iterators that complement other tools.
And there's, I just did a quick list of this.
And I really think there's a few of these in here that I need to use more.
So I'm glad I ran across this article.
One of them, so right off the bat, it says the three most useful iterators are product.
And what product does is it simplifies, like let's say you've got a nested loop of like width and height, for instance.
For X in range of width and for Y in range of height, you do something with X and Y.
Well, you can use iteratools product and have it just be one does a product of two ranges or product of two iterators.
And it gives you the two, like all of the combinations in order.
So that's a really cool thing that I always forget about, that I probably should write that more.
Especially if you've got more than two, when you get like three, it gets ridiculous.
And so using iteratools to simplify that, it's a really great idea.
And because, you know, with Python, every time you indent into a for loop, you're going to indent your code.
It helps you keep the horizontal width of your code a little bit more reasonable.
Flats, better than nested, all that kind of stuff.
Yeah.
Chain, I always remember about.
So Chain is a way to combine two lists and iterate through all of them.
Instead of adding the lists, adding is kind of, it creates a new one.
You might not need that.
Whereas Chain will iterate through both of them.
And I have to remind people, if you're not aware, all these really cool things within the iter tools,
they're a way to manipulate iterators such that you're not copying things.
You're not making a new list of something.
You're just iterating through existing iterators without doing the copy.
I think that I'm pretty sure that's true.
Yeah.
The third one on is everybody should know about that I thought was great was pairwise.
And I actually apparently never knew about this.
And this is a way to, like, let's say you've got the example is a bunch of names and you want to be able to make sure that everybody says hi to the person on their right.
You can go through it.
And you can go through it.
Well, this might be a silly example.
But if you want to go through an entire sequence and make sure each pair in a, like, you're just walking it down, like the first number one and number two, and then two and three and then three and four.
This is an easy way to do that.
And actually, there's an old way of using zip with the, you can, you can combine two lists and do slices.
But that's a little confusing.
Whereas pairwise just gives it to you right away.
It returns two pointers to objects.
So that's really cool.
A couple more things I wanted to bring up that I thought were great in here was zip longest, which I do remember because I use it frequently.
But if you're zipping two things together, which means you're going to go through and go through two sequences using zip, by default, zip picks the shortest.
And whereas, and it just chops it off, I think.
Actually, I don't remember what it does at the end.
But zip longest will have a fill value.
So you give it a fill value and it goes through everything and you'll have something empty.
So you make sure you go through everything.
And then the last thing is T, which is kind of neat.
It allows you to do, normally iterators are exhausted once you go through it.
So you have to like regenerate an iterator.
But T allows you to iterate through something a couple times.
It allows you to iterate without exhausting the iterator, which is interesting.
So nice.
And then at the end, a discussion of, which I think is cool that he did this.
So a discussion that there is, he wrote a book on iter tools.
So there's a little book of iter tools.
He's not paying for this ad.
I just think it's neat that somebody wrote a book about iter tools.
That's nice.
Neat.
Yeah.
Yeah, it's pretty neat.
So there's a lot of, a lot of powerful stuff there.
Yeah.
It's all a lot of simple, hard problems in simple ways.
I like, I really appreciate that he picked out those first three though, of like, even if
you're not really wanting to go through all of this, take a look at these three.
You might, you probably need them and you just don't realize it.
So, yeah.
So.
Indeed.
What do you, what do you got for us next, Michael?
You would love to know if your website was down and not up or your Docker container or
your other service.
And you would like to be notified in interesting ways.
And there are services you can pay for this or free services that have weird limitations
or I don't know, just funky stuff, right?
Some of those in order to answer really good questions, you'd have to give them pretty serious
internal access to your code or to your infrastructure potentially.
So I present to you the Uptime Kuma, which is trying hard to resist Uptime Karma, but no
Uptime Kuma, a fancy self-hosted monitoring tool.
Okay.
So this thing is pretty cool.
It comes with a Docker variant, so you can just Docker compose it into life.
And I'm thinking about setting this up for Python bytes and talk Python and other things
because I've already got that Docker cluster and all the infrastructure to run it.
So adopting it should be really easy.
It just takes one container to run.
And I believe it stores its data into a SQLite database in there.
So file copy is kind of a backup.
It's kind of the backup option.
So anyway, check this out.
Doesn't this look neat, Brian?
You tell it different things you want to do.
Like I want to check that the port is open.
I want to check that this example is, you know, some example.com website is up.
You can see that MySQL is running.
You can ping the server to see that the server is up.
All sorts of things you can put as tests in here.
And you can even have an anti-test.
Like for example, if you're ever able to directly connect to the database, that should be flagged
as an error that like a down moment, not an up moment because something's gone wrong with the infrastructure
and you need to go fix it.
But in a reverse sort of way.
So what does it say?
First of all, 54,000, 53,000 GitHub stars.
So really, really quite popular.
It has a little test, a little test server.
You can set up, point at your website for 10 minutes and play with it.
That's a really nice feature.
What it says, uptime monitoring for HTTPS, TCP, HTTP keywords, JSON query, ping, a DNS record.
You can make sure your DNS records don't go insane.
And like your MX, DCAM, or I don't know, whatever, game servers, and even check that your certain
Docker containers are still running.
So it's got a nice UI and it has notifications for telegram, discord, slack, pushover, email,
and 90 other notifications.
Can have as fine grained as every 20 seconds checking.
It comes with status pages.
So if we had a Python bytes monitor set up with this, I could set up status.pythonbytes.fm
that people could go and see if the RSS feed is live.
Is the Docker container running?
Is X, Y, and Z, right?
So it has that for you.
And it'll also, one thing I really like, because I use Let's Encrypt, but the auto renewal
is a little bit janky.
Long story, I don't want to go into it, but it's a little bit janky.
And so it works, but it requires a little fiddling.
So having it will actually check SSL certificates to see if it'll expire.
So it'll say like, your certificate is good for 29 more days.
Maybe you want to get on that before it goes like, you know, something terrible.
So all of that, isn't that sweet?
It is cool.
Yeah, there's a bunch of sponsors and it's got this nice UI.
You can bump over to the status page.
It'll prepare you a little demo app and it runs for a certain amount of time.
So how long are certificates good for?
If you do Let's Encrypt, it's a year, I believe.
Okay.
So anyway, you can go over here and create this and actually go and add a little monitor
and pick all the different kinds.
And look at all these things.
You can monitor MongoDB and SQL Server, Postgres directly.
Yeah, it's really neat.
So I'm thinking of setting this up.
And if you want to play with it, just click on that little thing.
You can see here, Brian, I clicked on it.
Now it says I have nine minutes to 21 seconds before my app gets blown away.
But I can test it out, which is pretty cool.
Anyway, it will give us potentially a really nice way to sort of monitor and get notifications
about it.
I have that from other services, but don't like it.
I could set it up once a day on the free one and make sure that my website at least is
live for 10 minutes a day.
Yeah.
Yeah, if you don't mind reconfiguring it every time.
Yeah.
Okay.
Yeah, sure.
All right.
Pretty cool.
How about some extras?
The only extra I got was last week I talked about making a new pytest course.
I've been working on that and I'm on version three because I'm a perfectionist and want to
make sure that it's smooth and quick.
So I do hope to get that out sometime soon.
I was going to say maybe next week, but you know, I don't want to put too much pressure on
myself.
Yeah.
When I go, that's, that's very exciting.
I know people are looking forward to it.
I also had to basically put DaVinci Resolve down to come record the podcast.
So I was in the middle editing some videos.
I got coming on for a new course as well.
So very exciting stuff.
All right.
There's, there's a never ending dream of things to talk about, right?
Yeah.
All right.
I've got a couple.
Kenneth writes, talks, pointed out that, you know, requests and more fame talks
about this, move that Switzerland pulled Switzerland, Switzerland now requires all government
software to be open source.
That's cool.
Cool.
Yeah.
So what does that mean?
They, you gotta read it carefully.
It doesn't mean the government has to only use open source as in Linux and Firefox, but
the thing, the software that the government makes has to be open source of what this is.
So we bump over to omnivore.
You can see my notes.
Switzerland has taken a major step forward with its federal law on the use of electronic
means for the fulfillment of government tasks.
SIM bag is the acronym.
This groundbreaking legislation mandates releasing open source software of the federal government.
The law requires all public bodies to disclose the source code of software developed by or
for them unless 30 part third party rights or security concerns prevented.
So that's pretty neat.
There's actually, there was some pushback.
For example, one of the main areas this was around is the justice system.
This, was trying to get all the software that runs, basically runs the justice system,
the court system for Switzerland open source.
But guess what?
The proprietary legal software company, web law, wasn't happy.
Right?
Yeah.
No, they weren't.
But, after a decade of fighting, it came out.
And there's one other point to make.
In addition to mandating open source software, it also requires the release of non-personal,
non-security sensitive data as open data.
So it's like open software and open, open data as well.
So pretty cool.
Interesting.
We have stuff.
Yeah, it is.
We do have some stuff like that, like over at Talk Python.
What was it?
Elections, I think if I look for that.
Yeah.
Python at the U.S. Federal Elections Commission.
I talked to Laura Beaufort.
And I believe they are open sourcing their stuff as well.
A lot of things going on there.
Like, yeah, open source at the FEC, for example.
So we have some stuff in like spotty examples of that, but not as a overall statement.
So it's pretty interesting, right?
Yeah.
I'm curious to look at some of the stuff.
Like, um.
Yeah.
How clean is your code?
Like, yeah.
How many AWS keys will be in there?
We'll find out.
Thanks indirectly, Kenneth, for that.
Uh, one more.
Remember last week I talked about the PySimple GUI and it's switching to a commercial license,
which again, I'm not super against, but sort of the rug pull aspect of it.
Like, hey, it's open source for a long time.
And I'm going to take everybody's contributions and then, you know, change the license.
That sort of thing got some people's nerves up.
Well, um.
FFalcon31415 on Mastodon pointed out, hey, check out FreeSimple GUI, which I linked to in the show notes, which is an actively maintained fork of the last release of PySimple GUI with an open source license.
So if you were like, oh, I was going to use that, you still can.
Yeah.
Actually, it's got a really good, the read me on that has some really good to, like, has some good tutorial examples of, of how to write a simple GUI on it.
So, not only is it the open source free version, but it's, it's also some pretty good documentation on there.
Cool.
All right.
How about some jokes?
Yeah.
Joke, joke time.
Singular joke.
A singular joke.
So this one is kind of a meme with Will Smith and it doesn't really have that much to do with Will Smith.
I think it's just the attitude.
I like Will Smith.
Anyway, it says, just because I know Java doesn't mean I know JavaScript.
I mean, I do, but not because I know Java.
That's good, right?
Yeah.
I was just talking, talking to, whenever you talk to kids trying to learn like software, it is, it's still confusing to people.
I mean, like, it's not confusing to us because we've been around it.
We knew that the history, but it seems weird now to tell people, yeah, the JavaScript that everybody uses, it was named that because Java was popular at the time.
Uh, so anyway, are you muted?
I was sorry.
Uh, fun episode as always, Brian.
Yeah.
And yeah, thanks, man.
Thanks for being here.