Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 385, recorded May 27th, 2024. Did I get that right?
Yeah.
I am Brian Okken.
And I am Michael Kennedy.
This week's episode is sponsored by Mailtrap. More about them later.
If you want to connect with us, we're all on Fostadon, the show, and Michael and I.
We're Fosstodonians.
Fosstodonians, yeah.
So those links are on the show notes.
Also, in the show notes or at pythonbytes.fm, you can go to live if you want to join us.
Join the audience.
Usually, it's Tuesdays at 10 a.m. Pacific time.
You can also use that link to get older videos, too, if you want to watch what happens live.
And finally, if you'd like to receive an email a day or two after the show to find out all of the links and to have a link to the show.
But make sure if you listen to this and you want to make sure that you don't miss any links and be able to go check those out later, you can become a friend of our show.
And we'll send you those emails.
So you had an announcement before we get started.
I do.
Well, I just wanted to say, Brian, the reason that we're not just doing this at a normal time, we're just kind of late.
And I got some messages from folks in places like New Zealand.
Like, awesome.
This is the perfect time.
So there's always a perfect time somewhere in the world.
But you've got this thing going on tomorrow.
And then for the rest of the week, I'm going to this thing called the Giant Loop Ride.
This off-road rally that's at a hot springs and maybe 300 other off-road riders out in the southeast desert of Oregon.
And riding the mountains and the desert and open bar, live music, all sorts of shenanigans going on.
Anyway, if somebody...
Like a swimming pool?
Yeah, that swimming pool is a hot springs, by the way.
How crazy is that?
If anyone is listening out there and is also going, just come say hi.
That's all I'm saying.
But also why we're doing this in the middle of the night for some places.
So I would say if you have a podcast that kind of runs late, sometimes it'll make you tired, wouldn't you think?
Would you have to rest a little?
Yeah, yeah.
Let's talk about Postgres, PostG, rest, as in Postgres, rest API.
So this one comes to us from Mark Little.
So thanks, Mark, for sending us over.
It's a good one.
This is basically a web server, web front end for your database.
So you've got Postgres.
And you might think, all right, well, I would just like to expose the tables as endpoints with, you know, ability to do queries over HTTP endpoints.
You somehow pass the query over.
You want to have security, things like that.
So this is an app that you can run and it automatically, with zero API work for you, turns your Postgres instance into a somewhat restricted API, basically.
Cool, right?
Yeah.
Now, obviously, these things, I don't know, I always have mixed feelings when I talk about these things.
On one hand, if you just say, I would like, say, my view front end or something, or even my Python code to just have access to the database as an API, just read, you know, the crud things of all the tables, you're good to go.
This is what you want, right?
On the other hand, sometimes I want to have more specific things.
Instead of just, I want to go through the user, the create new user API endpoint that uses, I don't know, argon2 for memory hard, password hashing and other checks.
And maybe, you know, like every time I come up against these things, I'm like, oh, they're really cool.
But at the same time, I kind of want a little more specific control over how it works.
So if you're just like, I just have a database, I just want to be able to expose it real quick, let's go.
Postgres rest sort of thing.
Cool, right?
So the way it works is it's written in Haskell, which you may, and it's 4% Python, so I guess there's a little Python in there.
But, you know, it doesn't really matter what it's written in.
It's just a thing you run, and then you talk to it from your Python or from your JavaScript or whatever it is, okay?
So there's a couple of things you care about.
One, you probably care about performance.
I'm not super familiar with the performance of Haskell, but I believe it runs on top of the JVM.
Sorry if I get that wrong, but I think so, which makes it pretty quick.
It says it'll do 2,000 requests per second on the Heroku free tier, which is pretty fast, actually, right?
That's a pretty wimpy server.
And 2,000 requests per second is pretty high end.
Three reasons for that.
Haskell, and it's written used in the Warp HTTP server, a compiled language with lightweight threads.
I also learned about Warp, so I'm learning about all sorts of things.
It delegates as much as it can to the database, so it's like a really thin layer over the database, as I was describing.
So serializing JSON responds directly in SQL.
It does the data validation, the authorization, combining row count and retrieval, data post in a single command.
All those different things are happening in the database, not in this thing, right?
And finally, it uses the Haskell, instead of SQL, it's the Haskell library, which manages database connections, a binary protocol for talking to it, and is stateless for horizontal scaling.
Also, very important for security, you don't want to just go, and the whole thing is read-write on the internet.
How could you get, you know, a little Bobby Tables doesn't find it?
So it uses JSON web tokens, and basically what you do is you create a user in the database, and then you set authentication, like, this user can only read, and they can only read these tables.
But they can write to that table, I don't know.
And then that's what you can do when you authenticate over this, right?
So it basically leverages database users and their implicit permissions to control what you can do with the API.
There's ways to version the API, which is kind of interesting.
As the database changes, you could keep it stable, it seems like, and it documents itself through OpenAPI.
Well, this thing's pretty neat.
So if you have a Postgres database, and you're like, look, we really just need read, write, update, you know, maybe even an internal app, and you just want to have it real simple, check this out.
It's kind of cool.
Cool.
I didn't know that Heroku had a free tier anymore.
But it is.
Let's check out.
Let's go back here and do a little.
It may have been from previous times.
Yeah, that statement, it must be from previous times, because this was updated a month ago, but it didn't.
Yeah, I think that's just whatever the wimpy free tier was, that's giving you a sense of what you can do.
Okay, cool.
Neat.
I want to talk about AsyncIO a little bit.
So there's an article called from Jacob Padilla, how Python AsyncIO works, recreating it from scratch.
And I kind of like this idea, because I mean, I love AsyncIO, but sometimes it just feels magical.
And to sort of walk through some of the, how it might be working in the background is kind of cool.
So it goes through generators review, talks about the event loop, talks about sleeping, then yielding to await and await with AsyncIO.
And I just kind of like the format that this is written in to just sort of get your, get a good mental model of how AsyncIO works.
So this is, I guess I highly recommend this article.
Looked really fun.
The colors are nice too.
I, you know, I got a sucker for a good webpage that's easy to read, but, but this is good.
Uh, I skimmed it briefly already.
And like, yeah, this kind of goes through how awake Async works.
Async just sort of feels mad too magical sometimes, but.
It is pretty magical.
And at the heart of it is generators, right?
So generators themselves feel super magical.
And once you kind of understand how those work, you understand, well, okay, well, that's how you kind of partition the work.
And then you just run it in, in steps, each, each fragment of the generator and off you go.
But yeah, it seems pretty wild.
Yeah.
So it kind of walks through all the little steps and then it shows what the, so it has like the, the final bit.
And then it rewrites the whole thing in actual AsyncIO so that we can see what it looks like.
Um, so that's great.
Uh, along with that, when I noticed the link that some, there was, camera where I got it from, but there was a comment also about if you want to like learn AsyncIO from trying to recreate it from scratch.
There was also a, David Beasley talk from the, from, I think it's from PyCon.
Yeah.
PyCon India from 2019.
I hadn't watched this.
I still haven't watched this, but it's on my list now.
Um, build your own Async, from David Beasley.
Awesome instructor.
So I'm sure this is a good video as well.
So we'll link, we'll link to that.
Um, so some, some learning AsyncIO.
Awesome.
Good stuff.
Indeed.
What, what else is good is our sponsor Mailtrap.
All right.
Let's talk about them.
This episode is sponsored by Mailtrap, an email delivery platform that developers love.
An email sending solution with industry best analytics, SMTP and email API, as well as SDKs for major programming languages and 24 seven human support.
Try for free at Mailtrap.io.
Thank you.
Mailtrap.
Let's move on to something in a little higher order.
Shall we, Brian?
Sure.
Perfect.
Follow on from what you were talking about.
AsyncIO, parallel programming.
It's basically scales the weighting.
Now this, this is going to be a dated statement, I believe, but at the moment, Python is not super good at doing computational parallelism.
Right.
But you know what is GPUs.
GPUs are awesome at doing parallel programming.
So, you know, your typical Python program has one thread, or if you don't do anything in most languages, they have one thread.
If you scale out your CPUs, maybe you got 16.
My Alienware gaming PC has that.
My M2 MacBook Pro, I think, has 10 threads, you know, but there's way more.
It's get a lot more work done if you scale those out, right?
But if you scale their GPUs, they have 16,384 threads, things like that, right?
Incredible.
So I ran across this thing called Bend, B-E-N-D, and it comes from a higher order company, which has a couple of, it's like a runtime for Bend and then has Bend the language.
And it's all about taking things and running them in parallel and making them basically be Python.
So it says, with Bend, you can write parallel code for multi-core CPUs and GPUs without being a C or CUDA, respectively, expert with 10 years experience.
And it feels just like Python.
So they give us this example.
Here's a function called sum.
Not the best example because it shadows a built-in, but whatever.
Let's get rolling with it, right?
And so it says, def sum, take a depth.
And there's some value that it starts with and then adds them all up, right?
So it says sum all the numbers from 0 till 2 to the end and 2 to the depth, right?
It has a switch statement that once it gets to the end, it stops and then sort of recurses down as it would.
And there's nothing that looks parallel about this whatsoever.
But what happens is this code actually runs in parallel potentially on those thousands of GPU cores.
Oh, wow.
Wild, right?
Yeah.
So the way it does that is, there's a picture here, is it breaks these things up into what are called computational graphs instead of work.
And then it just, it goes and processes them to see if that part of the graph can be parallelized, which is kind of nuts.
So you don't even write the parallel code.
It just looks at your code and goes, oh, that loop that we just saw or that recursion type of thing we just saw, that actually could be done.
Recursively by just changing the parameters or something, right?
So pretty wild.
And so, yeah, they have this HVM, highly massively parallel runtime that achieves near ideal speedups as a function across the available cores.
And then Ben is the programming language that runs in parallel, powered by this thing.
Looks like Python.
I don't know how compatible, say, its standard library is or things like that.
Yeah.
And then they have this thing called Kind, which is a parallel proof checker.
Have no idea about that.
I just said it's coming soon.
So this is available on GitHub.
And you come over and you can find their language.
And guess what?
It has 15,000 stars.
I'd never even heard of it until recently.
Yeah.
It's pretty popular.
Written in Rust, not that that's super relevant, but it's like powers a language that looks like Python.
That's pretty cool.
I'm cautiously optimistic about that.
It could be good.
So it looks like the real implementation for it is here, although it looks pretty short.
I don't know.
Updated a couple of days ago.
But here it says, yeah.
I don't know.
We'll have to see how large of a thing is it.
I guess that's just some pretty big scroll bars.
So maybe the whole runtime is here.
We'll see.
Maybe the number of files might be lower, but could have tons of stuff in there.
Yeah, that's true.
Anyway, is it going to be a thing?
I'm not sure.
Maybe.
Maybe not.
But it's cool to see people being creative for this kind of stuff.
You know?
Yeah.
Actually, it sounds pretty cool.
Yeah, it does.
To, I guess, simplify the way you get your code ready for massive parallel running.
If it can just look at your code and go, yeah, I got it.
Yeah, if it can look and say, this is what's often referred to as embarrassingly parallel,
right?
There's like no state shared.
You could just take the pieces and break them up and run them on cores.
Yeah.
If it just finds those automatically and does that, which is what it claims to do.
Yeah, that's great.
That's really great.
Yeah.
That's really great.
All right.
Next up, I've got regular expressions.
So we're getting all sorts of deep topics today.
We are.
We sure are.
So I ran across, I was looking at Reddit.
And so this book is an older book, about a year, I think it's a year old.
It's called The Smartest Way to Learn Python Regular Expressions.
And I don't normally pitch other people's books or anything on the show, but I thought it was
kind of nice that it's a LeanPub thing.
So they're doing their own thing.
And I guess I'll get into why I think this is kind of neat.
But the minimum price is free.
So if, and since they're allowing that, I encourage everybody to throw a few bucks their way if they
can, because why not?
It's good to have people teaching things.
Anyway, ran across it on Reddit.
And the topics sound neat.
So they go through an introduction of regular expressions.
They do an application.
I talk about puzzle learning and stuff.
And then I skimmed the rest.
But it looks like great stuff.
And some Python related thing to teach regular expressions would be good.
And then I went and watched their video.
And now I am even more intrigued.
So the idea around this book is that modern ways to learn are different than possibly people
my age might be used to, just reading a book and trying things out.
But this is set up.
There's a little video introduction to the book.
They're using the book itself as a long form teaching people.
But it's also, there's a video, there's a video course attached to it.
So if you, like, you get the book and you're reading through it, there's links to the different
course chapters within the book, which is kind of a neat idea.
And then there's puzzle solvers for each thing you're learning.
So you can go apply it in a puzzle environment.
And they're using a thing called Finfinkster.
It's an awful name, actually, I think, but F-I-N-X-T-E-R.
But it looks like there's a whole bunch of other people using it, too.
And I've never tried it.
But it's this kind of an online trying out some code platform, I think.
So I'm going to try this out.
I'm curious about the whole idea of reading a book and clicking on it and doing that as
well.
Mileage vary for me because I'm probably going to download this onto a Kindle.
And I can't click on anything with the Kindle, but at least the one I'm using.
But anyway, it might be fun to go through.
Yeah.
Looks excellent.
Give us a report when you get back.
Sure.
Yeah.
See how it went.
Yeah.
And, you know, not enough regular expression material out there for just deep, diving deep
and really getting your head around it.
Yeah.
They're very powerful if you're good at them.
Yeah.
Big if.
Those are our items.
Do we have any extras?
I have one.
That's quite interesting.
And I don't.
Somebody gave me a bit of a tip towards this.
I don't remember who it was.
So I think it was on Mastodon.
But thank you.
And sorry about forgetting who to credit here.
On Wikipedia, we have the Python Conference, aka PyCon.
And what does it say about it?
It says, the Python Conference, also called PyCon, is the largest annual convention for the discussion
and promotion of the Python language.
Scroll down a little bit, Brian.
You see things like, where was it?
In 2003, it was in D.C.
It had 200 attendees.
2012 was in Santa Clara.
2,300.
Oh, 2016.
Yeah, baby.
Portland.
3,391.
Almost.
The record.
Almost.
3,393.
Two more people beat that number, came over that number from Cleveland, Ohio in the before
days.
And then COVID hit, knocked it down, and it's slowly building back.
Like in Pittsburgh, it was up to 2,500 again.
So what is that?
It's still got about 50% more to add or a third looking backwards.
It's down.
That's not what I want to talk about.
I want to show you what is in this Wikipedia table right below it.
Where we're going next.
The Long Beach, baby.
Going to California.
Let's go.
Going to the beach.
Going to some warm weather.
Going to a vacation spot.
I will bet you that this significantly beats those numbers because it's just a destination,
right?
People want to just go there to be there, right?
Well, it's kind of nice to see it on the West Coast.
I mean, nothing against Pittsburgh, but it's only two hours away from, where was it?
Cleveland.
Yeah.
So we did have Salt Lake City in the intermission times, but Salt Lake City was still under a
lot of funk.
It was the first one that came back in person after COVID.
So it was kind of funky.
I went to the 2023 one.
I know that, and I guess I'm going to go on the record of saying, I think that there's
a lot more cool destination things, destination places on the coasts.
Yeah.
And Midwest, obviously.
But I think doing it kind of in the middle of the country makes sense so that people can
get easy flights from anywhere in the country.
Just saying.
Yeah.
And what are you optimizing for, right?
Are you trying to move it around?
Are you trying to make it as centrally located?
Are you trying to make it as cheap as possible?
Are you trying to make it a destination?
All these different things play into this.
And this is the biggest funding for the PSF.
So it's not just like a curiosity, right?
This is the funding for the PSF to a significant degree.
It's interesting, though, that Portland was way back in 2017.
And this in 2026 is going to be the next time that it's going to be on the West Coast.
I don't think that I know that everybody on the East Coast thinks that Salt Lake is in
the West, but it's not really.
Not even the same time zone, Brian.
Not even the same time zone.
Mountain time, Pacific time.
Let's go.
Anyway, this is my extra.
Planned tentatively, the PyCon after Pittsburgh.
So next year is still Pittsburgh.
It's round two.
But then Long Beach, California.
And I'm here for it, Brian.
Also, I've always been curious about it.
Sometimes I'm curious about the numbers of how many people showed up in Montreal.
And it's cool to see.
You can just look it up on Wikipedia.
Yeah, yeah.
It's all right here.
I've got something completely random.
Prince of Persia was a video game from 89.
I remember it.
Oh, not only was it a video game.
It was one of the best video games.
It was so good.
Yeah.
Well, it was like this.
One of these cool, like, you know, racer through all sorts of stuff.
We had like the little runner thing and had to jump over all sorts of stuff.
It was a fun game.
And then there was a bunch of different permutations of it.
And it's still going strong.
I think still stuff going on.
There's a anyway.
Cool game.
But I ran across this.
There's a book about it.
So Jordan Mechner is a person that wrote it and originally wrote the Prince of Persia game.
And he wrote a book called Replay.
It's a memoir of an uprooted family.
And apparently it goes back to 1938 when somebody in his family, his parents fled Austria to escape the Nazi persecution.
And then, you know, they traveled to the U.S.
Eventually they went to France.
Then they went to eventually, I think, actually, I'm just making this up.
I don't know if we ever made it to the U.S.
I think so.
But then he goes back eventually.
Yeah, because he goes back eventually and works in France for a little while.
But then did this book about his life, his family and his life story and about the Prince of Persia.
So I'm kind of excited to read this.
I really like these looks inside the storytelling of the history of some of these famous games and famous platforms.
Yeah, they're very interesting.
Yeah.
And apparently his dad wrote the music for the original video game.
Okay.
It's kind of cool.
On a, I think, anyway, one of the older computers in the 80s.
So that's it.
That's my extra.
Awesome.
Let's close it out with a work hack joke.
I don't know what you call this, Brian.
So we have this woman developer sitting here, pretty happy.
And this boss comes in, manager says, I don't like this bash script you created.
Write it in Python instead, commands the boss.
Import subprocess.
Subprocess call work.sh.
Well, that's a day's work done.
Nice.
How about that?
Just if you want me to write in Python, I'll just call the script from Python.
Let's go.
Yeah.
Well, one of the times where I'm like, where early on, I guess not early on.
Anyway, 20 years ago or so, I find myself in a new job.
And they've got all these builds, make scripts for C++ code.
And I can't remember.
They were in batch files and bash and all sorts of stuff.
And I said, can you rewrite this?
Because it's kind of a mess.
So I rewrote it in a combination of, I had a combination of bash, Perl, Python, said, a whole
bunch of things, whatever I wanted to, to what I thought was an elegant solution.
And the team was horrified.
They're like, we're not learning that many languages.
I'm like, okay.
So I rewrote it all in Python.
And that was the first time I really grabbed Python for do whatever I want as a shell script
language.
Yeah, that's very cool.
Yeah.
I love it.
It's a subprocess call.
Yeah.
Subprocess.call.
That's right.
Yeah.
Nice.
Yeah.
Don't wait for it to complete.
Just let it go.
Well, yeah.
Works.
No error handling needed.
Let's just let it run.
No, it's a good joke.
And that comes from your credit where credit's due.
That comes from Linux handbook.
Linux handbook.
Nice.
Cool.
Well, thanks, Michael, for another wonderful episode.
As always, thanks for everyone for listening.