Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 364, recorded December 12th, 2021. I'm Michael Kennedy.
2023, and I'm Brian Okken.
2023, and you are Brian Okken.
And this episode is brought to you by all the things that we're doing that many of you support,
and we really appreciate that. Courses over at Talk Python, mine, Brian's, other folks,
the complete pytest course over at Brian's site. Patreon supporters connect with us on Fostadon.
We're all over there, including the podcast. And many of you who are listening at this very moment know,
but many who are listening later may not. If you hear us say, hey, so-and-so said this in the audience.
If you would like to be in the audience, check out pythonbytes.fm/live,
usually Tuesdays at 11 a.m. Pacific time, just as it is now.
We typically link from each show notes on the website, not as easily in the podcast player show notes,
but on the website, you can get to the video version if you ever want to.
Yeah.
Although, certainly not intended to be required. Brian, let's kick it off.
Yeah. Let's talk about one of the things that is often around is,
this was going to be one of my extras, but I'll just bring it up anyway, is the advent of code.
So we've covered this in years past, but at adventofcode.com, there are a bunch of things you can do
to a programming exercise, and you can pick any language you want. And a lot of people do this,
and it's so much fun. But there's other ways to do advent of code. And I really liked, I saw James
Bennett is doing a Python Django advent calendar. And this is super cool. He's just decided to do
a short blog post, possibly short, some not so short blog post about Python or Django every day during the
2023 advent. And it's pretty nice. The first one is talking about enums and just a little, I mean,
it's a good reminder that Python has enums, but also you can make them nicer by making sure that you
assign values and it's easier even instead of just using enum to derive a class from enum enum.
And, and so that they're, they're like, you know, the, they're printable and stuff like that easier.
The values are good. So that's good. What I really loved seeing a couple of his posts were
around testing. So there is, this is pretty great. This is a don't mock Python's HTTPX. And I don't,
I have a plans to use HTTPX on the project, but I I'm not using it right now, but I really thought
this was a pretty cool little writeup. The, the, the, there is a discussion really about different ways
you might be able to mock mock using your HTTPX part, but there's the obvious ways are probably not
the, really the best. His recommendation is to is a, a couple of things, refactoring your code a little
bit so that you can pass in a HTTPX client, but then also using HTTPX is built in mock transport.
I didn't know HTTPX had a mock transport in there. You're grinning. Did you already know this or do
you have an opinion? I did not. I'm just thinking that Kim in the audience has identified the fact
that HTTPX is very sensitive and we should not mock or tease it. Yeah. That's why I'm laughing.
Okay. Okay. The joke. so that concludes the joke segment of the podcast. No, I didn't know this.
Actually, this is really cool. I'm all about HTTPX. It is my default go-to HTTP client these days.
When you do it request like it's like requests, but it also has async and it's, it's very fine.
And, yeah, this, this mock transport is pretty neat. anyway, it's a little over my head
right now cause I don't do this yet, but, I think it's a cool thing to point out. And also I really
think, I think it's a good idea. A cool idea. I mean, a lot of people do like, writing a novel
in November, but writing a little blog posts, during advent, that's pretty neat idea also.
So good job. Yeah. That's a very interesting idea. So I also think it's an interesting idea that library
creators may decide to provide their own mock stub API rather than just forcing you to guess what the
internals might need. That's true. Yeah. Right. Cause as a provider of the library, like, well,
really, this is the thing you need. And really there's these three things you should change,
but if you call this function, we'll do that or whatever. Right. Like they just know the
internals better and let them do it. Yeah. And there's an example of using, of having a mock
transport that just returns a, not found, and being able to do that without going out outside
of the library. I think that's a really cool idea. No, I mean, and I, and we are seeing that more,
more frameworks deciding, well, people are going to have to test this. How do they do that?
and I think it's a good trend. So nice. Tony Sherman points out, saw a similar thing in Bota three for
AWS. So very cool. Right. Okay. they, I, there's a, the other one that I thought is a short
one is test your documentation talking about, doc test. And, I love throwing stuff like
this in, you, you have little, doc string in your, in, in your code to,
to show how it's used. Why not test those? So you can use either doc test or you,
py test can run your doc test tests as well. So. Because of course it can. Yeah. It does all the
things. All right. What you got. I'm going to drop into this next one here. this next one is
drop base. Now this from what I can tell it right at the top, it has a pricing. So it's not a free
type of thing for you. However, I think it's interesting enough to talk about it anyway,
not a sponsorship, just something Michael thinks. Cool. So it says build internal tools with just
Python. So, so you can build, it says full stack. Let's call them forms over data web apps for your
internal teams, import existing Python scripts and quickly build layered UIs with gradient
permissions. So when you look at the thing itself, you're like, huh, I don't really know what this
means or if this is interesting. Like they don't have a bunch of great, screenshots or whatever
on their homepage. So what you'll see is like, you can go write a query. It's all sort of starts
from a database, which is why I'm calling it forms over data. Okay. And that is like a user interface
that lets you basically access the database with a little bit of rules and such. So the idea, if I
recall correctly, I looked at this last week is what you do is you write a SQL query against a database
like Postgres or something. Okay. And that will give you a result that looks kind of like, kind of like
Excel ish static, doesn't do anything, but then you can click and say, make this a smart table type
thing. Okay. So then it becomes sortable, editable and so on. Right. So all the results, you can just
turn that into a grid that people can edit and it goes back to the database. You can create a so-called
master detail type of view. So in the example, on the homepage, they have a workspaces and then each
user belongs to a particular, there's a bunch of users that belong to each workspace. So you can do
a relationship where you say, I'm gonna, if you click on one part of the screen, fill the other part of
the screen with say the users of that workspace. So if you like select the workspace in the top grid,
like fill it out, all the users at the bottom, you turn that into a smart thing that you can edit it
and you can do things like click a button to whatever. In their example, it says, if you assign
somebody to a workspace or change their role, you can click a button to send them an email,
like their new status in that workspace, that code is written in Python, right? And you can plug in
functions behind all this stuff and all that code there is written in Python. So you want kind of a,
a real quick way to, if you've got a little SQL skill, a little Python skill, build this cascading UI
type thing. There you go. It's pretty cool. That's pretty neat. Yeah, pretty neat. And you know, they, they also
have some widgets and stuff, I believe like sidebars, search bars, et cetera. Yeah. Then you write a bunch of
that in Python and it's, it's super cool. So I think that could be quite useful for folks if they want to go
and check that out. And you know, you're not trying to build some new super fancy looking app. You just
like, I just need to provide kind of this relationship stuff and a little bit of Python to do a little bit
of work on my UI. So people can check that out. I think there's a free tier. Let me look now. There's
a free tier that has up to three users. And then for a team, it's like, if you want teams, you can pay
more. So again, not an advertisement, but you know, UIs built with Python, even though we go on and on
about them, they're often a rarity. So when we get a chance to talk about them, it's kind of cool.
Yeah. That's neat. Yeah. And semi-related sort of, I'm going to have Samuel, remember last week we
talked about fast UI? Yeah. Samuel Coleman reached from Pydantic reached out and said, Hey, we should
talk more about this. It's a brand new thing we're trying to do interesting things with. So I'm going to
have him on talk Python technically next week, but it's going to be recorded next week and then
released later. So like in April or something like that. Yeah. Something like that. Right.
Something probably January. Okay. Anyway, well more on that over there, but drop base people and
check that out. And if people do, it'd be cool if they could like shoot us a note and see if it's like,
turns out to be cool or not. Yeah. I would love to hear back. yeah. So maybe, maybe Kim could
save some time because Kim says, the description of this tool pretty much describes my job, but
yep. Very cool. Anyway. I'd like to talk about, the structural pattern matching a little bit.
So we have covered structural pattern matching and talked about it before this came out. When in,
camera, which three, 10 brought us structural pattern matching way back in three, 10,
how young were we then Brian? So yeah, different world. Anyway, the, the tutorial is pretty
good as a, so this is from Ned Batchelder real world match case. so, the, he comments that
the tutorial is pretty good and it is however, the example is a little bit of a toy example
and, and it's nice to see, see this really in action. So here's a real world, use case.
Ned's got a GitHub bot installed as a web hook and it returns back. So every time something happens on a
repo, it sends back a payload of Jason data to the bot and the bot's got to figure out what to do with it.
And it's, so it turns out Jason into a nested set of dictionaries. and anybody that's,
that's dealt with, Jason return data. that's what you get, you get a bunch of nested
dictionaries. So how do you deal with that? Well, there, there was, his, his, this example shows
that the match case, or the structural pattern matching match case works really great to match this.
So, this example looks, for, for events that happen and for each event, they matches it just
to look to see if there's an issue and a comment. And, and so one of the cases is looking at the,
the content of that. So you've got these nested dictionaries you can, and you can deep, dig deep
into the nested here. It's just one layer down a couple layers of nested dictionaries, but still,
you could go deeper if you wanted to, to match that. And then not only matching the dictionary and pulling
out bits of the data, like he's looking at closed ad and created at and comparing those, but using a
comparison. So you grab the stuff and then say, if some, like if two things are equal and in other,
in another example of, if the, who, if the login is the bot name, that's the, that's different.
I don't want to do events that are based on my own actions. do something else,
but then proceed with it. So kind of some, a couple of cases where you doesn't want to do anything,
but other cases where some action is required. So the, these are, is a pretty cool use case of,
uh, I just wanted to highlight that it's really cool use case of using structural pattern matching to,
to make some code that might be complicated other ways, a little simpler. So this isn't too bad to read.
So much more interesting than the normal switch type statements I write with match these days.
Yeah. It's like, we're looking for multiple things within the document and then applying a conditional
on part of the matched things. And, it's pretty wild.
Yeah. I'm actually thinking about this in a, I've got sets of data where for each element I'm, I'm looking,
yeah, it's a bunch of nested if clauses to say if, if this is true, if that's true and something like
this might work really pretty good. So.
Indeed. I'm going to try to make that, the, the, the conditions here, like, the chapter art for
this, this chapter, chapter items for all their topics, right? People can use that throughout the
show. So yeah.
Very neat. Look nice.
So look down at your podcast player before now.
I love that. We, we don't mention that a lot, but a lot of people, do, appreciate the
chapters. So we jump around. We do multiple topics and you can use the chapters to get to them. So
or use them as reference. All right. Speaking of reference, Brian, I have extra, extra, extra,
extra, extra times 10. Okay.
But I know you've got a lot of things as well. So I have so many extras that my next topic is
the extra, extra, extra, rather than having some follow-up stuff. Ready for it?
Yeah. All right. Follow-up number one. We talked about switching DNS and how much of a pain that
was last time and all the hassles that we could run into. And it occurred to me, and there's some
people out there like Michael, obviously we do this all the time. I suspect many people don't though.
It occurred to me that there is your domain registrar, like GoDaddy, Hover, whatever, Namecheap.
And they often have all the DNS settings for you, but you can create, you can use, there are services
that are way better. It turns out that host your actual DNS settings that have nothing to do with
your register. What you got to do is just go to your register and say, use this. So I use bunny.net for
delivering the podcasts or the courses, all sorts of things. And they have a DNS section that is super
cool. So check this out, Brian. we've done in the last week, I set this up. We've done over half a
million DNS queries, not requests to the page, but like, Hey, tell me who this is. And we'll remember
that for a while to your, for your ISP. That's a lot of DNS queries. A lot of people want to know
what Python bytes.fm is. That's exciting. But here, why is this so, why am I so excited? Like,
look how nice and readable this is for people who, are watching the, if you're not, it's like,
it'll create a view of a TXT record. It'll like create, nested sections go, all of these records
apply to this domain or that domain and so on. And then look over here at, you can edit all these
here, but check this out. If I want to say like this, the CDN setting, maybe I'm working on it.
And you know, what's a super hassle with DNS? Like I make a change, please wait a couple hours and you
can try it. If it doesn't work, it will be broken for a few hours and then you can fix it. Right?
What a hassle. cause I don't, I migrated 25 domains. I know I messed some of them up,
not badly, but a little. So check this out. If you click here, you've got your one day,
one hour, typical time to live. It goes down to every 15 seconds. So if you're like working on
something and you want to be able to like, I try, Oh no, go ahead to quick switch it back.
Just set it to that for a while. Isn't that awesome? Yeah. The other thing you can do with this is you
can write, unfortunately JavaScript, but you can write JavaScript that runs on every DNS request.
So you can say things like, I know you asked what this is, but you're in Asia. So we're going to tell
you that it's this server rather than that server. So you get a faster local machine and all sorts of
interesting stuff here. This is free. What? Or this is free for the first 20 million DNS lookups.
And then it's like 10 cents per million. So for us, right, we're going to do, it looks like 2 million
free, right? We could be 10 times more popular before we pay a few cents. So the reason this is cool
is you can set this up and then switch your domain. And then as soon as you just change the name,
you can get it all dialed in and you don't have to have this kind of like awkward downtime in the
middle. So people can check this out. There's other ones. Cloudflare has something similar.
DigitalOcean has something similar, but this one is super, super neat.
That's pretty cool.
Yeah. And Tony says similar to what you can do in Cloudflare. Yeah. They're both CDN providers.
They both have like similar stories. Okay. I'm going to go faster now because I have more.
I wrote a cool, say blog post type thing that shows you how to use warp to hide all your terminal
secrets. Look at this, Brian. So here, welcome to Ubuntu. I'm not going to say what version.
And here's your IP addresses. We're not going to say what those are, but if, so if you're doing
presentations that somehow involve working with terminal stuff that might accidentally reveal
something like, what is an IP address that you shouldn't have? Or what is an API key or something?
If you use warp, all you got to do is check a box and say, obscure all my secrets. And now
your presentations are safer. Isn't that cool? Yeah. That's pretty neat.
Yeah. So talked about warp before, but I, that is new. I think it's a new feature, but anyway,
it's cool. We also have a supporting developer in residence. Lukash Lenga says, welcome. We have
Peter Victorin now as a supporting developer in residence working with Lukash. So we now have
two times the help over there because Lukash has been so successful keeping Python moving
forward. They're now getting more folks. So that's pretty awesome, right?
Yeah. And thank you.
They successfully cloned him.
Yeah, they did. He's now an AI. No, just kidding. Also that was sponsored by Bloomberg. So shout
out to Bloomberg for being excellent. Joe sent us two things that are pretty funny. They're almost
worthy of like a joke type of thing, but I thought I would just share them. So he decided to embody
various songs through Python. So we have the Bohemian Rhapsody and we have Money for Nothing by Dire
Straits. So remember, it's like, I just want my MTV, right? Money for Nothing, all that. So they got the
class MTV. I'm linking to the show notes. Of course you can pull up, you know, starts out with self.
Want equals nothing. Print Money for Nothing. And then it goes, all I want is my MTV. And it sort
of cycles through that. You know, look at those yo-yos. That ain't working. Maybe get a blister on
your little finger, right? It's got like working, false, do, true, money, cost of zero. It's pretty
awesome. Guy's dumb, little blister, you know, guy's dumb as false, right? So if you kind of want to
enjoy this musical melody here. Does it run? I'll have to try it out. I'm sure that it does run. Yeah.
Yeah. So, well, OS.system. Install microwave dash ovens. Oh. Echo. I mean, you know, custom kitchen
deliveries, refrigerators, moving color TVs. I don't know if I'd run it actually, but there's a
similar one from Bohemian Rhapsody. It's pretty funny. So people can check that out. Don't you
regularly just download random code and run it? Well, when I see OS move, maybe not.
PyCascades is coming to Seattle in 2024. Their call for proposals is out. So people can check that out.
It's a fun conference. If you're in the Pacific Northwest or want to go to the Pacific Northwest,
you can see the little banner wrapper thing. CFP is open. Okay. So some interesting nomenclature
coming for us in the world is free threaded Python. Have you heard this? Free threaded Python?
I didn't know we were charging for threads. I know this one is like, it's a total freemium model.
So with the no gil work, with the sub interpreter work, all these different ways in which Python runs
more concurrently, especially the no gil stuff, there's a plan to basically call it free threaded
Python, not no gil. Because no gil is how it's free threaded, but free threaded is the point. You know,
it's like, okay, yeah, I have a gas exploding mobile. Like I have a thing that drives. I don't
care about the driving, not the gas exploding, right? Similar type thing here. So Seth, Michael
Larson points out that this has been blocked on PyPI to make way for this is interesting.
This redistributions of the Python runtime compiled with the free threaded mode, i.e. no gil. So one,
we're calling it free threaded Python two, you might be able to pip install Python. I don't know.
Okay. So that's, that's that one. Next. There's a very interesting letter, open letter to the Python
South for a foundation from Python, Python, Africa. And apparently there's been a lot of, I don't know
what the right way to point it, but it is basically not that great a support for Python in Africa.
I just want to sort of put this out there. They wrote it. People can check it out and read it,
but would like, just would like to see better support for reaching out to folks in Africa and
have the PSF maybe be a little bit better supporter for it. There's been a lot of contention around it.
So check that out. It's worth knowing. Okay. And then we have, oh yeah, it's, it's not super congruent
with the mission of the PSF on a couple of levels. One, like PSF is there to promote the Python
language. And this is a lot of like, we need you to make this social change or you're not going to
have a conference in Africa. Seems a little incongruent with the mission about supporting
Python. I don't know. Python, moving on Python 3.12.1, the first major update of 3.12 is out. So
people can check that out. It contains many new features and optimizations with over more than
400 bug fixes. So we don't like bugs in our code and 400 of them. We definitely don't want that many.
Yeah. Along with that came the 3.11.7 release. Okay. All right. Update your Pythons. Update your
Pythons. Everybody gets their new Pythons. Final one. And this one could be a joke, but it's just
too visual. It's really awesome. Let me make sure I credit this one correctly. So Johannes Lippmann,
when he heard you talk about the Obfuscated Python code contest, this is the first international one,
by the way. Okay. Okay. The Obfuscated Python code contest. He's like, I got to be part of this. So not
only was he part of it, but he won. He won the most introspective of them all.
It's beautiful too. Check this out. So if we go here, it's literally the letters PY and a bunch of
insane symbols in the most wild, wild way possible. Like this, if you open it up, it's just like
ASCII art PY. Yeah. What this does when you run it, is it annotates, oops, go back. When it
annotates, there's always like, so you don't have to run it. You can just click the image. Is it
basically annotates and colorizes the Xenopython? Oh, that's so cool. Yeah. And so you can check out
other ones too, right? I haven't even looked at the most roundabout one. He's also highlighting
which, which portions of the Xenopython his code is completely ignoring. Yes, exactly. Yeah. So these
are fun and people can check them out. You got the image, but this one has a movie even. So instead of
just a picture, the first, the winner, I guess it's not the number one winner. There's just different
categories. The most puzzling is by Moshe. Oh, wow. And it's like a maze, which is,
which is amazing. That is amazing. Oh, that was well done. Very well done. Okay. So that's it for
all of my, my extras. Okay. Over to you. That's my extra, extra, extra segment, which was very extra.
I just have a couple extras. We've covered this before. Microsoft Python for VS Code has a, has a
December 23 release. Actually, we haven't covered that, but looking in the, that came out on the
7th. And the, within this December release has an announcement that, oh, there's a, oh yeah,
I had it already highlighted. The Python test adapter rewrite experiment. If you don't remember this,
it was back in, it started in June. They, they did a change where they were working on, you had to,
you had to opt in to the, the change of how VS Codes test, how test discovery was working. Anyway,
I reckon I always, I, we covered it because I recommended everybody turn it on. You, now that is
being rolled out to a hundred percent of the users. So now you have to opt out of it. If you want to,
if you don't want it, but don't opt out of it, the test discovery, just update your VS Code and
you'll have better test discovery. Now, super cool. The test discovery is so much better now than it
was before. Thank you everybody that worked on Python for VS Code or worked on this part of it. So
that's pretty cool. The other extra I wanted to, to mention was, was Daniel Roy Greenfield wrote a
little tip and I, I always, I kept meaning to do this and I've always forgotten. So now this I'm
going to do it this time is a set in my shell script RC files, set pip require virtual and to true.
And that will make it so that if you try to pip install something and you're not in a virtual
environment, it will, it will not do it. And it will just complain. So I never mean to pip install
anything unless I'm in a virtual environment. So this is, this is good. I like this.
Yeah, that's, that's cool. There's a lot of these sort of environmental settings that can control
things that are not entirely obvious, right?
Yeah. Big, good, good blog posts. So write up some of the ones you should really know about.
Absolutely. Well, there you go. Fire up your Hugo. Let's go.
Yeah. So that's, those are my extras. So would you say you got to do a lot of research to maybe
find all those particular environment variables stuff might really be overwhelming. So check out
this joke, Brian. Okay. It comes to us from Ray on Mastodon. It's a sticker and I kind of want this
sticker. It's got a bunch of tabs at the top. It says my brain has too many tabs open. Four of them
are frozen and I have no idea where the music is coming from. Oh my gosh. It's amazing. Yeah.
I have no idea where the music is coming from. That, that happens to be so, I guess it must
happen to everybody so often. It's like there's music playing and I have no idea which tab is
playing music. I know it, it, it has like a little like a speaker light icon that you can see
if it's going, but yeah, I feel like this little sticker describes both my Monday mornings and my
Friday evenings or afternoons. It's like, Oh, I can't deal. It's like, what is going on here?
Too much in life. Yeah. That's funny.
I need this sticker. I do too. So I do too. All right. Well, thank you for the episode as
always. And thank you everyone for listening. Yes. Thank you.