Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 328, recorded March 21st, 2023.
I'm Michael Kennedy.
And I am Brian Okken.
And this episode is brought to you by Microsoft for Startups Founders Hub.
We have a really fun one for you again this time.
Something different, so be sure to check that out.
Connect with us over on Mastodon.
All of the links are in the show notes.
And if you are not hearing our voice at this moment live because you're part of the live stream,
be sure to visit pythonbytes.fm/live.
Sign up to get notified about the live streams and be part of it every now and then.
It's a lot of fun.
Speaking of fun, Brian, share with us this first thing you've discovered.
I actually, I wanted to talk about ZipApp.
Did you know about ZipApp?
I have never seen ZipApp in accent, but I have heard of ZipApp.
And it is a very interesting idea.
New in 3.5, so it's not that old, is it?
3.5 still sounds new to me.
I don't care what people say about dates.
Really?
It sounds new to me.
It has async and await.
And that's the first point where I feel like it's kind of as far back as you can go and still be modern Python.
Okay.
I think.
Don't get f-strings, but come on.
Still, it's not that old.
It's not something that's better.
You're more lenient than I am.
I'm like a 3.7 is the start of the world.
But anyway.
Okay.
So ZipApp, it's been around for a while.
So all supported Pythons use it, right?
So and but apparently there was like a flub up in the announcement when it came out.
So people didn't quite see it when it came out.
So it's anyway.
So what it is, it's in the standard library.
And it's a module that provides tools to managing the creation of zip files containing Python code.
And they can be directly interpreted by the Python interpreter.
So it's a command line interface and an API.
But the deal is you kind of take like a package or Python package you got or a file or whatever.
And it creates an executable for you.
Well, it's not really an executable because it doesn't have the Python part.
So you still have to run it with Python.
But it includes all the stuff except for Python.
It's kind of like if you could hand out just a Python script and say run this.
But it has dependencies and it has a lot of structure.
But you don't have to make people deal with that, right?
You don't have to have them create virtual environments and install stuff because it can all just take the stuff it needs.
I haven't played with it enough to know if it has.
Oh, yeah.
It has requirements too.
Install all of your applications dependencies in the app directory using PIP.
So, yeah, so there's like a there's a thing.
There's like a tutorial inside the documentation saying how to create a standalone application with zip app.
So, yes, it includes your your dependencies.
And then you just create this little thing.
So you can say you can give it to somebody and say run this on Python 5 or, you know, or whatever you support.
And that's pretty cool.
It's got all that all bundled in.
I haven't tried this yet, but I didn't even know this was here until recently.
Brett Cannon mentioned PYZ files.
And I'm like, what the heck is a PYZ file?
And I looked it up.
It's these Python zip app things.
So interesting.
Pretty neat.
There's some examples in there.
So, yeah, that's just I guess it's just if anybody was trying to think of some way,
because we have talked about like lightweight ways to ship stuff to Python stuff to people.
And I think it's fine to tell people to assume that most I mean, depending on your audience.
But there's a lot of people that it's fine to say it's it's running Python.
So you have to install Python.
But then and it's easy to send a file, but sending a bunch of stuff is a little bit harder.
I mean, you could if they're if they're developers, you can say, here's the repo.
Just download it, install requirements.
And there you go.
But for a lot for a lot of people, that's a little too much.
So this is kind of neat.
The other use case that I think is a really cool one that I've seen is using it within CI CD pipeline.
So if you have a stage that's that you want to you.
All you're doing is pulling stuff in and running it anyway.
Might as well just have it all zipped up already.
So, yeah, it's cool.
Cool.
Yeah, it's super cool.
Just a quick one.
Yeah.
Henry on the audience says Python can run zip apps files directly.
PYZ files has been supported since well before 3.5.
3.5 just makes it easier to do.
Oh, really?
OK.
Yeah.
Apparently.
Yeah, I thought that that was true.
But yeah, the zip app is really cool.
Neat.
Indeed.
Cool.
So, well, what do you have for us?
I want to tell you all about maybe a use case or a story of like how you can just take Python and solve your own interesting little problems.
So this comes unknowingly through Rhett Turnbull, who shared a blog post in sort of an interesting circular way over on Mastodon.
It says, great blog post from EQ on reverse engineering the Apple News app with Python and nerd power.
That sounds fun, right?
Mm-hmm.
So this is an article that you can check out.
And basically it says, look, one way that's awesome to do a bunch of research and gather up a bunch of news is Apple News.
And there's a way in Apple News to say read later.
But because it's Apple News, it's like tries as much as possible to keep you within its little walled garden of Apple News.
For example, if you share it with somebody, it doesn't share the original link.
It shares the Apple News link.
And, you know, if you want to access those links outside of the Apple News app, well, nope, you don't get that, right?
And so this EQ person, who is the nickname or online name of Dave Bullock, says, let's see.
I reached out to Rhett Turnbull.
Here's the circular bit about his OXX or macOS photos Python library that he had been using to extract data from photos, which have a similar issue.
And says, you seem to be familiar with like ripping stuff out of the internal of these macOS apps.
What about this one?
And it got a few hints and turned out that I was able to pull in some information to actually get the Apple News link out of a list of saved relator things hidden somewhere.
And then goes through using Python to actually Python plus beautiful soup to pull that out into something that is meaningful.
And you can actually share with folks, which is pretty cool.
And then it said, well, I shared this back with Rhett and Rhett's like, oh, that's awesome.
How about I create a whole CLI library that lets people do that and stash it into a SQLite one?
And then who knows, maybe you connect that to dataset from Simon Willison.
And, you know, like it just it can just go from there.
So there's Apple News to SQLite as a CLI that came out of this whole journey.
But I just thought it was a really cool use case of like, look, you don't need to be trying to create the next major API service or the major web app.
Here's just a fun way to like, I've got this problem.
I've got the structured data and maybe Python can solve my problem here.
Yeah, usually can.
Yeah.
Anyway, a lot of fun.
People can check this out.
And I think if you're looking for ways to get better with Python or practice with Python or do interesting little projects, maybe this will inspire you because it's it's not a ton of work for this.
Right.
Yeah.
We need nerd power t-shirts.
Nerd power.
I think.
Nerd.
Oh, yes.
I got some t-shirt stuff to share with you at the end as part of our joke.
So I don't know if there's a nerd power one out there.
Just real quickly on the audience.
Fabio asks, a while ago, I talked about a testing a paid search engine that was Kagi that I've been using.
I'm still using Kagi.
I've been enjoying Kagi a lot.
So that's the one.
Brian, we ready to tell folks about our sponsor before we move on?
I think that's a good idea.
I do as well.
And as promised, I got something fun for you this time.
So remember, this one is brought to you by Microsoft for Startup Founders Hub.
One of the really important things you get is access to the open access and credits to the OpenAI APIs and the Azure OpenAI service.
So I said, hey, let's take the boring or in the straightforward ad that we had written originally.
And I asked OpenAI to rewrite it.
So I said, hey, OpenAI, can you rewrite the Founders Hub ad as an American football coach trying to motivate his team?
So where do we get back?
Attention all startup founders.
This is a call to action.
Are you ready to reach the next level?
Then listen up.
Microsoft for Startup Founders Hub is offering a rare opportunity, a chance to get in the game with OpenAI APIs and Azure OpenAI service.
These tools that will take you to new heights with the power of generative AI at your fingertips.
But it's not just the technology.
It's the support system.
You get $150,000 in Azure credits and the richest deal from any cloud provider.
And tech support, man, it's top notch.
The team at Microsoft will give you guidance.
The guidance you need to make the big plays with one-on-one technical advisory.
And you'll get a network of mentors, seasoned players in the startup world who will be out there to help you navigate the field and make the tough calls.
You'll get expert help on product fundraising, go-to-market, and more.
This is your chance, startup founders, to get in the game and make a big impact.
There's no funding requirement whether you're in idea phase or further along.
All you do is sign up and get ready to unleash the power of AI in your startup.
So what are you waiting for?
Head over to pythonbytes.fm/foundershub 2022 and join Microsoft for Startups Founders Hub today.
The time is now.
The game is on.
You've got the tools you need to succeed.
Yeah.
Thank you, Microsoft for Startups, for sponsoring the show and OpenAI for bringing home the championship.
There we go.
Nice.
That's fun, right?
That's good.
Yeah.
Love it.
Okay.
I also love context managers.
How about you?
I do, but just an interesting suggestion from the audience of would it be different if Ted Lasso wrote it?
Oh, I bet it would.
Well, you know, there's always next week.
Yeah.
So let's talk about context managers.
So I have used, I love context managers, and I've used context lib, context manager decorator to create context managers.
And if you've never tried it, it's like the easiest way to make a context manager.
With context manager, you decorate a function with the decorator context manager, and then you put a yield in the middle of it or anywhere in it.
It can even loop.
Wait, maybe it can't loop.
No, that's something else.
That's a generator.
No, context manager, you put a yield in it, but it can be in the middle of like an exception block or tri-accept or something else.
And then, so it runs the first part, and then after the width block, it tears it down with the teardown.
It's nice.
I knew about this, but then I was reading an article from Trey Hunter.
What is a context manager?
And it's actually a really kind of nice article that talks about all the stuff.
Basically, if you didn't have it, so first off, it tells you what a context manager is.
And one of the ones that people are most familiar with maybe is open file as F.
So with open file as F or any with block, you're using a context manager, right?
So opening file is great because then it closes afterwards.
And then he talks through some things.
One of the next example he brings up is context lib change dir.
And I don't know how I didn't know this was here, but what it does is if you use with change dir, it changes your directory.
But then when you're done with the width block, it goes back.
Cool.
Somehow I missed that.
So I was going in and looking, and there's a whole bunch of other stuff.
So I did know about closing.
So like the file open thing, you can anything that has a close statement in it, you can use the context manager closing to use like for line and page.
Wait.
With closing URL open as an example, because then when you're done for URL lib, it closes it.
So anything that has a, you have to do a close command afterwards, you can use closing.
That's cool.
But there's a, there's async closing also.
Cool.
There's a bunch.
There's suppress.
So if for a part of your code, you want to suppress a particular possible exception, you can suppress it for a little bit of your code.
Super handy.
Redirect standard out, but just for a little while, you can do that.
Just there's, and then in really extended error.
And then there's, there's our changed error, but there's a bunch of stuff in here.
So I, I guess I encourage people to go through the, go look at the context lib and look at some of the stuff you can do.
Cause there's a lot of great stuff there.
So neat.
That is really neat.
I am a huge fan of these types of things.
And hold on, don't scroll anymore.
Do you see when a changed or came into existence?
3.11.
That might be why we don't know about it.
Cause that's brand new.
Yeah.
Nice.
But I love these types of things we say for this block of code, I want something to be true.
And then afterwards, I don't want to think about how it happens.
Like however I get out of here, early return, exception, done, whatever.
Just undo the thing.
Yeah.
Really, really nice.
I use some of these, I mean, not, I don't know of a built-in one for this, but that with colorama to say during this section, I want all the output to be this color.
And then no matter how I leave, roll it back, the default for like text output and things like that.
Right.
Oh, neat.
Otherwise you got to keep resetting.
Like, oh, I'm returning here.
So I got to reset here and here.
And it's just like, nope.
In this block, it's blue.
Now it's not blue.
Right.
Those kinds of things.
I just love it.
So having these built in, I didn't realize there are so many built in.
This is great.
Yeah.
That's a cool use case.
I like that.
Yeah.
Thanks.
Indeed.
So this next item here that I got for us, Brian, this is a follow-up to a question.
When you talked about Knox, somebody asked, can I use that with poetry?
And we didn't know for sure, but you can bet the audience knows.
Yeah.
So yes, in fact, there is a Knox-poetry library that you can use.
And it's super simple.
So the way Knox works, quick reminder for folks who maybe didn't listen or didn't listen that
closely or just forgot from last week is you create a session for some operation.
And you say, this session is going to run Python 3.10 or 3.9 together.
Right.
And then you just say, session install what you need to.
For example, here, the example on this page says, install pytest and install the local package
that you're working with plus its dependencies.
And then run pytest.
The problem was, there's a couple issues.
If you don't have something that understands poetry, then you end up, the package with just
the wheel metadata and not the lock file gets installed, which means you don't get the
pinned versions installed that you're hoping for, the dependency constraints that you're
hoping for.
You just get whatever the latest of those are.
pytest wouldn't be constrained.
Poetry would be installed as a build backend every time.
There's just a bunch of stuff that's a little bit lumsier.
So what you get here is you basically get a library that you say, sort of from Knox import
session, you say from Knox poetry import session.
And this is a wrapper proxy to the underlying Knox session that configures things to make
sure that poetry works.
So for example, the install will use the lock file that poetry uses and other types of things.
There's a bunch of stuff.
It'll build the wheel from the local package.
It'll install the wheel as a pytest package and then invoke pytest to run the test against
that installation.
That's pretty cool.
So it also has some other types of things that you can put on it here.
Where do they go?
There's a bunch of poetry specific things.
You can say session dot poetry dot.
There it is.
Like session dot poetry dot install root or session dot poetry dot build package as a wheel
or a disk and export requirements.
All these different things.
If you want to leverage the fact that it is actually poetry or you can just use this wrapper
and write exactly the same code, but it now works correctly with your project.
Oh, nice.
Yeah.
I like it.
This is from, came to us from not one, but two people said, hey, you guys, John Hagen and
Mark Pruitt.
So thank you both for sending in your particular use cases for that.
And it also comes to us from Claudio Jolowitz, who created the hyper modern Python project cookie
cutter.
And this is part of that to support that project.
I actually had him on Python a little while ago, back in about a year ago.
Do you want to hear way more about this?
We probably even talked about this in passing and I was like, oh, okay.
Interesting.
Like didn't really.
So yeah, there it is.
We hear so many things like sometimes, you know, it doesn't always stick the first time,
even though we try.
Yeah, that happens.
It does happen.
All right.
And it also happens that we are at the end of our main topics, but you got any extras you
want to share?
I do.
And it kind of talks about it's a little bit similar to what we're just talking about.
So I was just at Pike Cascades this weekend.
This last weekend just got back.
I took the train back yesterday.
It's a lovely ride.
How was the train ride?
Did you enjoy it?
Well, I did on the way back.
On the way there, I kind of thought I would be able to sleep, but I didn't.
I wasn't able to.
So on the way back, it's a nine hour drive or nine hour train ride from eight or nine from
here to Vancouver.
On the way back, I'm like, I'll just work.
So I just edited a bunch of audio.
So I was working the whole way back.
It's great.
But one of the things that happened to me there was a couple of people saying, oh, yeah, we
met.
I was at, you know, I was at Picon, Portland or Ohio or something like that.
We met.
I'm like, that's wonderful.
I meet so many people and I have such a bad memory.
I mean, I trust and I don't I feel bad about not remembering everybody I ran into.
Anyway, I'm sorry if I if I said hi and introduced myself and you already we already have done
that.
My apologies.
I'm bad at it.
It's not ideal.
It's also not personal.
People sometimes take it personally.
It's like, well, it's really hard when you meet 400 people.
Yeah.
And then also the questions of you talked about this one thing.
It was kind of like that.
What was that again?
Like, sorry.
That's why I have Google or search or whatever.
So I did give a talk and it's great.
The the slides are up at Python test dot com slash I cascades 2023.
And there are they are going to chop up the videos.
And I think that's what they've told me that they're going to chop up the videos.
But for now, the day one and day two is available.
If you really want to watch mine, it's about sharing pytest figure fixtures.
It's at what hour 22 hours, 40 minutes, 58 seconds approximately on day two.
But that exact link is in our show notes as well.
If you want to click through and watch 25 minutes of me talking about packaging.
So it was really fun.
I had a good time.
Do you have any extras?
Today is talk Python's birthday.
I believe you got to do math.
I think it's eight years old, which is nuts.
It's either seven or eight.
That's nuts.
But the reason I thought of that is the latest episode right now is Python tips and tricks for better testing.
That also brings into some of the stuff that you talked about your talk.
So if people are interested, they should check out this episode and they can see a cool hat.
Nice.
Cool.
All right.
That's not what I was planning on sharing, but yeah, it ties right in there.
Now, what I wanted to share was one thing.
So let me tell you about my router challenges here.
So at my, as you know, Brian, but probably almost no one else does.
I have my office above my garage.
My garage is a separate building from my house and there's no Ethernet connecting this as much as I've tried to make that happen.
I haven't been able to make it happen.
So I'm like, well, how do I make this faster?
I've been using a two node mesh network.
And it turns out that people getting stuff around us have been causing a lot of interference.
And so my wife needs one closer to her office and I need one closer to mine.
And one's got to be plugged into the internet.
And we were like kind of like disagreeing.
Like I want it closer to my office.
No closer to mine.
Mine's a separate building.
I need more.
Right.
And, and back and forth.
And so I ended up solving this with too much money.
I'm getting this thing called the Atlas Max 6E length this router.
I don't know if I recommend it because it's really expensive, but it's one of the few things that both has three nodes and it's 6E Wi-Fi, not just Wi-Fi 6.
Right.
Good combo.
So this is not really my recommendation.
What I want to tell you about.
My recommendation is I've always considered these mesh network things to be like, well, if I'm on Wi-Fi and that talks to one of the nodes and then the node talks to the main node at the house.
That's, that's just as good.
Like why would I ever say plug in ethernet to the secondary node, right?
Still Wi-Fi.
It's just one more hop, right?
Well, I was getting a little interference in the house.
I said, well, let me just try plugging in not to the thing that connects to the internet, but to the node that wirelessly across the buildings connects to the other thing that connects to the internet.
Do you know what I learned?
I learned something insane that I don't know if I can simulate it here across buildings.
I'm apparently not getting it right now.
I'm only getting a rough 570 megabit over wireless across buildings.
Earlier, I was getting 800 megabit over Wi-Fi.
Well, I mean, you're also streaming video at the same time.
Yeah, we're streaming video and doing other stuff, right?
Uploading, downloading.
But so my advice to people, if you have a mesh network, even though you're connected to one of these nodes, you think, well, that's wireless to the end anyway.
Like, is it really worth ethernet?
Yes.
It's because.net.
I'll try one more.
I was completely blown away by how much of a difference it makes.
But yeah, it's really, really impressive to plug into these wireless things.
So if you've got a mesh network, try ethernet to it, even if it doesn't matter.
That's my extra.
Cool.
Yeah.
I had to look it up.
I didn't know what Wi-Fi 6E was.
So I looked it up.
It's 11AX.
That makes sense.
So I test Wi-Fi stuff, but I'm testing it on the standard side.
So we get it before they decide what the buzzwords are going to be.
Yeah.
I see.
Okay.
Yeah.
That's really cool.
AX is really cool.
It's one of the, it's the first standard that, I mean, that is, now I'm getting nerding out
on Wi-Fi, but it's the first standard that's not bi-directional the same.
So the protocol from up from the node to your device is different than the other way.
Kind of like cellular is like that too.
But before AX, it was identical.
The same sort of protocol and traffic and speed and everything from in both directions.
But this way.
Yeah.
So anyway.
So neat.
Yeah.
Anyway, really, really cool.
Out in the audience, David Poole says, Linksys makes good stuff.
Wired is always better than wireless.
I work on Wi-Fi professionally.
Yeah, for sure.
Yeah.
All right.
Nice.
Ready for some jokes?
Yeah.
So I'm going to take us to an unexpected place.
Etsy.
You ready for this?
Now, this is pretty, I considered not putting this here because it's fairly graphical.
Like, you need to see it in nature.
So what I'm going to do is I'm going to take our favorite one and put it as a chapter art
for people to appreciate.
Okay.
So these are like tech signs that have words or sayings that don't necessarily match
with what you might expect.
So for example, here's one and it looks kind of like a RAM chip that's hot or something.
And it has a little heat wave coming up.
It says, caution, magic smoke cannot be reinserted once released.
Isn't that awesome?
Yeah.
Here's one.
This is a throwback to quantum mechanics, I believe.
It's a little wavy hexagonal lines and a bunch of question marks.
It's uncertainty.
Do not attempt to measure.
This one, I think probably all of us can relate to this.
I've created some of this myself and had to deal with it.
It's a hexagon with some piece of technology in the middle.
It says, caution, cursed technology inside.
Oh, yeah.
It's a pentagon in there.
Cool.
Nice.
Yeah.
Pentagon rather.
Thank you.
And let's see.
Maybe one more here.
If we can find it.
Oh, this one.
This will be a good one.
A Gen 2 one.
It's got a Gen 2 logo in the middle.
It says, warning, kernel may need recompiling in order to change sound volume.
All right.
Well, there you have it, folks.
That's one of my jokes.
There's a whole bunch of these.
You can click around and enjoy them for a while.
They're pretty good.
Nice.
These are great.
They are.
Cool.
Well, thanks again.
Wonderful episode.
Sure was.
Thank you, Brian, for being here.
And thank you, everyone, for listening.
Really appreciate it.