Python Bytes - #373 Changing Directories
Episode Date: March 5, 2024Topics covered in this episode: zoxide Smart CLIs with Typer Python recommended officially by the US Government Textual tutorials at Mouse vs Python Extras Joke See the full show notes for this ...episode on the website at pythonbytes.fm/373
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 373, recorded March 5th, 2024.
And I'm Brian Ocken.
And I'm Michael Kennedy.
And you're just back from, where were you last week?
I was in the Philippines, hanging out in warm weather, meeting some new people, experiencing new places.
It was excellent.
Nice to have you back.
Yeah, thanks. Good to be back.
This episode is sponsored by Scout APM.
We'll hear more about them later.
If you want to connect with us or the show, we're on Fostodon.
You can go to mkennedy at Brian Ocken or at pythonbytes at fostodon.org.
And if you're listening to us later, you can join us live if you want.
Go to pythonbytes.fm slash live and join the
audience there. So, Michael, what do you got for us first?
Well, I have some super fun stuff. This one is not purely a Python thing, but it sure
is helpful for Python developers. Brian, would you say that you use the terminal fair amount?
Yes. In your amount? Yes.
In your world?
Yes.
As do I.
And navigating the terminal is always a bit of a hassle.
I'm like, Michael, did you really need to have it that deep of a directory tree folder structure for this thing?
Because you're CD and this, CD and that.
Did you need to name them the same?
So tab complete doesn't really help you as much
as you would want and so on so i want to tell you about z oxide so z oxide is like cd you know the
command one of the very first things you learn when you learn about terminals command prompts
and so on but it's way better uh the oxide is because it's written in rust so that probably
means it has a vc funding or something no just kidding. But it is backed by Warp, which I've talked about before,
which is also written in Rust, and I believe does.
Anyway, the idea is that there's a little graphical animation.
So the idea is once you install it into your terminal,
and whatever terminal you're using, it pretty much supports that.
Once you install it, it will start to remember all of your directory changes, at least if you use it.
And I'll tell you more about that in a second.
But if you use it to move around, like imagine you've got a directory.
The example they're using on the screen here is something like, let's see, some long path slash foo, you know, some slash long slash
path slash foo, right?
Like a big directory structure.
You could just say cd foo, and it'll just take you into that structure because it's
like, all right, well, if the only directory structure I've ever seen that you actually
cared to go into that involves the word foo is this one.
You can say cd long and it would take
you just some slash long once there's more than one there's like a conflict then you can do a
couple of things you can hit space and then tab and it'll pull up like a little autocomplete
or you can instead of like the hotkey they show or the command they show is Z. You could Z for some of our folks. You could type ZI for interactive,
and it'll show you like a fuzzy completion search deal of all the history you've ever had. So you
can go into kind of an interactive way to go and find the files or the paths that you've
looked for before. So isn't that cool? That is cool. I definitely need to check this out.
Yeah, I've been using it for a few days and I really like it. So a lot that cool? That is cool. I definitely need to check this out. Yeah. I've been using it
for a few days and I really like it. So a lot of what you know about CD is, is the same as Z. So
you can say Z dot dot, you can say Z minus to go to the previous directory, not necessarily up one,
but just wherever you were before. Like I said, you do the Z I for the interactive or type a
little bit and just space tab to pull up autocomplete and you
can get it in a bunch of ways like look at all these platforms linux mac os windows bsd even
android and on mac you can do a bunch of ways you can conda forge it you can asdf it you can home
brew it all those and then look at all the different shells here wow yeah even conch the the
python based one but uh it's got the z, which is what I'm doing these days.
And then if you want that interactive version, you need to install FZF, which is a command line fuzzy finder thing that you can do.
And then the thing that's interesting is, like, when I did this, there's no way, no way I'm going to remember to type Z.
I'm just going to
type cd and then after a while i'll be like oh i should have used z but it won't be in the history
so let me just swap it out for z for cd you know swap those and so what you can do when you install
it uh does it say on here it probably maybe it does oh it's up under the in the configuration
so in the shell configuration but you have to do this
eval z oxide init z sh but then you can also say dash dash command cmd is some other character if
you don't want to use z and if you say command is cd then just cd becomes this the this thing
instead and of course if you don't like it right you just comment it out it goes away
okay that's what that's what i did that ends up showing up in your one of your dot files or
something and then you can yeah you just i put it in my zshrc dot file for me and just put that at
the bottom you know if i ever decide you know i just want my cd back i could take that part out
or if i don't like this i just comment that thing out it's pretty cool yeah i was just thinking i
don't know if i want to type c because that's with my pinky whereas cd's with my middle
finger i'll probably map it to something else like e or c or something yeah yeah i switch it to cd
and then if you want to do the interactive you do cdi but i think this is cool it's uh it's not
going to change your life but it's also... Little extra things that make your life a little faster.
It's good.
I find it really interesting that on both Windows and Mac,
Linux to some degree, but Windows and Mac even more,
especially Mac, you open up the default terminal experience
and it is bad, bad.
It's like they want you to stay out of it.
You know what I mean?
Yeah. So it opens
up it's white, white background, which I don't know, for some reason, terminals, it just seems
wrong for that. But then also it's, it's like the wrong font. The fonts are incredibly small.
There's, there's not hardly anything installed to help you, right? Like it's just so many levels of,
you can add on these little tools that just make it so much nicer. So anyway, I'm a big fan of this.
Before we move on, one question from the chat was, does it remember directories across terminal sessions?
It does remember across terminal sessions.
I think it must keep a little hidden folder file or something like that.
I didn't pay attention.
But yeah, it's just you need to have interacted with it.
I'm pretty sure it does it across sessions, though.
Okay, cool.
Yeah, definitely check it out.
Speaking of command line interfaces,
I'd like to talk about building them.
Oh, yeah.
So smart, there's an article called from Raul Pai, I think,
Smart CLIs with Typer.
And I was just excited to see this because I love Typer and been using both Typer and
arg parse a lot, actually.
When I guess for me, I use Typer if I'm already importing other stuff.
But if it's a package or a project that doesn't have any external dependencies, then I'll
try to use arg parse because I don't want to pull in an external dependency just for typer sort of thing. However, but typer is really fun. This is a cool
article. And what I was surprised by was there's a whole bunch of stuff I learned in this, even
though I've been using it for years. There's some great things that I didn't know about. So there's
great article, check it out. But first thing i want to say is like right off the
bat it just talks about sort of a comparison between an arg parse um version and a typer
version uh it's not hugely different but it just talks about how typer you don't have to like
declare your arguments you you just have a function you can just have it discover it you
can just have a function like main and and um
typer figures out that all of your uh type hinted arguments to that function are now arguments to
your script which is cool um but i want to hop to the things that i didn't maybe i knew about and
forgot or just never knew about like how easy it is to do help um so well help is actually a little
easier in arg parse but it's not that bad in hyper,
you have to have to do a type or argue annotated thing with argument with help on it. It's
a little clunkier, I guess just not that bad. But it's a lot different than the if you don't
want to help you just have to, it's a little bit more work anyway uh prompting for input i did not know you
could do this so if you have a like like you like you would add help you add a prompt instead if
it's if it's left out what happens is typer will prompt the user for it so like in the example it
gives a a name and an age uh for the this little example script if you forgot to put an age for this little example script. If you forgot to put an age, it'll pop up and say,
how old are you? That's pretty cool that you can add a prompt. That's really cool. Yeah. I really
like that, actually. I'm definitely going to have to try this because there's a lot of times where
it's good to have some defaults, but also, yeah, speaking of defaults, you can also add an
environmental variable so that if the default doesn't have to be hard-coded, but it could be an environmental variable that you set.
And then if you didn't add the argument, it'll pull it from an environmental variable.
So very cool there.
What else?
It talks about explicit apps versus is it kind of a different way to do it?
There's a couple ways to do our typer.
And explicit app one is one of the ways.
One of the neat things you get with that is multiple commands.
And so there's an example of doing multiple commands.
I love that feature of typer.
And then as a comparison, a similar sort of a thing with argparks would have been uh sub commands so um uh kind of
a fun article and then i kind of got lost in the whole reusable command thing but yeah yeah this
looks great yeah i didn't know about the input one or the environment variable one these are both
awesome yeah cool things if you're if you're making your own command line interfaces and i
i also appreciated the the shout out to argpars,
not like, because that is the other one
most people should consider,
either type or argpars, I think.
So for sure.
Andrew out there says that,
yes, ZOxide does have a persistent database,
as I thought.
And also asked whether Typer supports
the union operator, the pipe operator for types.
Not sure.
It said it didn't use to.
I'm not sure if it does.
I don't know.
I think you could run into issues.
Like if you said this is pipe int or pipe date time, like it could try to parse as a date time, but then see the number as like a timestamp.
I can see.
I don't know.
I can see how it can be tricky.
So maybe it's by design.
I'm guessing not yet, but I guess just maybe based on the last time i tried it because one of the things
is optional so you if one of the things i love about uh the the bar for for um for types is uh
to be able to say int or none as an optional thing but that's not how you do it with type
or you have to say option like at at least the last time I tried it,
you had to say optional int equals none. But actually this is even, yeah,
optional makes it so that it's like int or none. So yeah, cool. Cool.
Awesome. Awesome. What else is awesome? Michael, our sponsor,
our sponsor is awesome.
Let's take a moment and thank them and tell you about them and then
i'll get back to it let me tell you real quick about doubt 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
thorium, then you say, oh 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 slash 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 slash scout.
Check them out.
It really supports the show.
Awesome, awesome.
Brian, have you looked into like buffer overflows
and how all that kind of bad stuff happens?
It's the first time I learned about it,
it was just fascinating about how you could abuse computers.
Yeah, yeah.
Well, I'm in C++, so a lot of the time. So you basically create abuse computers. Yeah. Yeah. Well, I'm, I'm in C plus plus. So a lot of the time.
So you basically create buffer overflow. Yeah. Like commonly. Yeah.
Well, you know, C plus plus got the, like the, not just the, the print F,
but like the safe print Fs and other things.
Like there was additional like checking wants to help prevent that. Right.
But the, our very nsa who knows something
about buffer overflows i suppose recommended something pretty interesting it says this was
actually a shout out to samuel colvin who put this on twitter i don't know i think twitter needs to
decide what it is is it x or is it twitter i mean i know they use the word x and the symbol x but
what's the domain it's not x..com. It's Twitter.com.
Come on.
So what are you?
All right.
Back to the topic.
Exeter.
Exeter.
I think X Twitter is the best we can do.
Anyway, he pointed out something with some interesting commentary here.
He said the U.S. government, specifically the NSA, looking to say, hey, maybe we should have it harder to break into our systems.
The government explicitly recommends six memory-safe languages.
Okay.
And then he also creates a bit of a juxtaposition here.
C Sharp, created by Microsoft.
And there's usually like one or two people behind this, right?
For example, C Sharp was Anders Hallsberg, who also did TypeScript.
Go, created by Google.
Java, created by Sun, bought by Oracle. Rust created by Mozilla. Swift by Apple. And Python created by one genius on his own Christmas holiday. The Python is an extraordinary demonstration of the impact one person and the group that they build can have on the world, which I think brings together two interesting ideas here, right?
Like that Python is officially one of the memory safe languages recommended that we should be using by the NSA.
And then just the effect that Guido has had.
Yeah.
Yeah.
It's pretty wild.
I think it's interesting that i didn't really realize that
rust was memory safe but yeah that's interesting too isn't it it's it's i think that's part of its
magic right how it's it's kind of a low-level systems language but it's way more uh memory
safe as well with its ownership and all that but and then oh my gosh this really took off
must be why i saw 781 000 views but then if you look if you look at the comments
oh the comments i can't see it because i'm not logged in but there are many many comments and
the commentary is varied and interesting down there let me just tell you but yeah i think this
is interesting like just one more reason to use python or you know other memory safe languages
as well but for example in the comments people pulling out well rust was created by one person while they were at mozilla but i you know it gets maybe a little bit
different to say you know you were funded by this big tech company to create this thing and you know
you did it yeah uh well i mean you have to we have to we're not really i mean i don't think samuel's
intending to diss all the other languages others No, he was more props to Guido.
But if you look at all the comments,
it does what you would expect a post like this to do
as people get their baby not quite loved.
It's highly notable in its absence as JavaScript here.
Yeah.
Yeah, interesting.
Yep.
All right, well, we'll leave it there.
People can check it out,
but that's...
Yeah.
So we'll also have to...
I haven't looked at the recommendation,
the NSA recommendation either.
So we'll have to check that out as well.
Yeah.
NSA says use Python.
Use Python.
Yes.
I mean, you know,
and we all listen to the NSA.
That's right.
In this case too, though.
Yeah.
I thought it was the other way around.
Didn't the NSA listen to us?
Oh, yeah, right.
Okay, so I'm going to go back to the command line world for a moment
and talk about Textual.
So we've talked about Textual before.
Will McCugan's child came from Rich, then Textual.
But Textual's over at textual.textualize.io so
that's um a great place to look for uh demonstrations and stuff so if you go there
there's some some cool demos of what other people are doing with it and some other pocket projects
these are great wow the dolphy looks cool anyway um so what i wanted to cover was that it does have
its own tutorials um so if you go go to was that it does have its own tutorials.
So if you go to the main page, you can go in tutorials,
and there's a great tutorial for how to use it.
There's a little timer tutorial.
It's nice.
But maybe the way that they're teaching there just doesn't fit you.
So I was really glad to see that Mike Driscoll over at Mouse vs. Python
has some textual tutorials that he's started.
And what caught my attention was the creating
a modal dialogue for your two E's in textual.
But he's got like four different blog posts
around tutorials around textual right now.
So Mike's done some great work teaching people before.
So I wanted to shout out to Mike for this.
The modal dialogue's kind of fun.
It goes through a little fairly simple example,
but the code's really just not complicated to follow along with.
So really kind of fun talking about how to do a modal dialogue
because that's something you're –
Are you sure you want to quit?
I love it.
Are you sure you want to quit?
But there's other things like,
are you sure you want to quit? I love it. Are you sure you want to quit? But there's other things like, are you sure you want to delete your entire repository?
We recommend a where clause in your delete statement
against the database.
Yeah.
So anyway, good job, Mike, for jumping on this
and helping to teach textual.
So cool.
Yeah, that's really cool.
Textual is very, very interesting.
So cool.
All right.
Well, those are our topics. Do you have any extras for us?
I have just a couple of extras I'd like to go through here.
So one, you know, ngrok. We've talked about ngrok before.
If you need to let people access services, typically HTTP, but it could honestly be anything on your system.
You can run ngrok.
It's super cool.
I'll use it.
I'll pay for it.
You know, so like I'm working on a web app and I want somebody to be able to actually interact with it. But I'm behind a firewall somewhere else.
You can just run ngrok, get an SSL backed URL.
That's kind of some random thing that people go to.
So that's the CLI and all that.
But they've released a little while ago,
in December, they released an Ngrok Python SDK.
So if you want to write apps
that basically temporarily spin up ways
for people to get into systems,
like maybe you're on a Raspberry Pi
or you're on some IoT thing
and it's locked away somewhere,
but you need for it to be able to,
people to get to it under certain
circumstances or whatever.
Right.
Then here you go,
write some code and you plug into all that infrastructure.
It's pretty cool.
That is pretty handy.
Yeah.
Yep.
I don't have a particular use case for it,
but cause I just use ngrok directly,
but I'm a big fan of ngrok and I think,
you know,
I'm sure there's going to be some interesting things.
You can even do a Unix sockets, like Unix dot sock thing, which is pretty wild.
So it gets, it gets quite, uh, quite advanced.
All right.
What else?
Let's see.
I recently, we talked, you brought up Django knots a while ago.
And so I recently had, uh, Sarah Boyce and Tushar Gupta from the Django knot program
on talk Python.
That was, I think, released last week, recorded a while ago, but released last week.
And so I just want to give a shout out to that since we brought it up first on the show.
Nice.
Cool.
Yeah.
Then Sarah was very excited to hear you mention it when you brought it up.
It said on the show, this show on our on talk Python.
She mentioned that she was excited to hear it here.
So that's cool.
Also, I had an interesting experience with my phone brain. on our on talk python she mentioned that she was excited to hear it here so that's cool also i i
had a re interesting experience with my phone brain i was looking at my phone going i'm not
sure i really like the color anymore and i've had it for a little while maybe i'll get a new phone
and then like what is wrong with you oh it's an iphone 13 so i've had it for a while but you're
just going to put a black case on it anyway maybe you just get a different case and you know it kind
of doesn't hold his charge long so maybe just get a new battery for it.
It's like, depending on the one you got,
69 bucks, 89 bucks for a new battery,
instead of like $1,000 for a new phone,
$5 for a new case, 90 bucks for a new battery,
drop by the Apple store, they'll switch it.
It would encourage people like,
hey, you might be able to just improve your phone
or, you know, give it a different color
without going over the top.
Yeah, what do I got?
I got an eight plus that I'm using.
It still works fine.
It just changes the battery every couple of years.
Yeah, exactly.
And it's it seems pretty trustworthy to do it at Apple, right?
They use the same battery or better.
They might not have the same old battery.
Sorry, you got to get a better one.
OK, take it.
Nice.
Cool.
Anyway, that's that's my public service announcement
for people out there applies to android as well you get a new case for android as well okay well
i have a couple extras one of them is a public service thing but the first one is just a shout
out to uh hinnick's new video um we talked about um uv a couple weeks ago i think or last week i
can't remember um and there's a video called
Is UV the Future of Python Packaging?
And it's like 20 minutes, 17 minutes,
but it's really kind of a nice look at the background
of really what's going on here.
The speed ups might not seem,
the speed, everything's fast.
Faster is great, right?
But there's more to it than that.
And kind of about some of the
future that they might be putting together after this is is important um so interesting interesting
discussion i encourage people to check it out the other public service announcement that i wanted to
say was i use venmo occasionally mostly to send money to and from my daughter.
But I didn't notice, and I don't want to show off too much, but that's Venmo, you know.
But I was surprised when I looked at my old transactions and found that there's a feed feature where everybody that's connected to you or even not connected to you can see everything that you've spent money on.
And I'm like, what the heck is this for?
Not just money, but like why the little message to the person and all sorts of stuff. I don't think you can see them out, but you see that somebody paid somebody else.
And then you can click on the other person and follow their feed and follow other people.
And this doesn't make sense for finances.
So I would
encourage everybody to go into your settings and just turn that to private. Nobody needs to see
that. I don't know why there's a social feature for a money sharing app. It's horrible. It's
weird. It's horrible. I ended up using Venmo as well because my kids are like, dad, I'm going to
Venmo you. How about PayPal? Venmo? I'm like, all right. But yeah, it's, it drives me nuts that I could see people that I was even, you know, friends with like 15 years ago, I still see what
they're buying and who they shared lunch with. It's just like that it doesn't belong in this
space. I just don't think so. Yeah. Turn, turn the feed off, turn the feed off. And also I don't
think it shouldn't be on by default. And also people don't know about it. So other people,
you know, that use Venmo, let them know that their feed's public so yeah anyway cool well that was kind of serious but do we have something
funny oh this is very serious too no jokes all right so here's a developer and a project manager
speaking the developer starts out and says i can ship this feature that you want in four weeks
because listen i need to write maintainable code we can't just have like this tech debt piling up and all this junk, right? Like this is a professional organization.
The PM says, what if we delegate maintenance to someone else? Oh, I can release that in three days.
Exactly. No test, Brian. We don't need tests. Come on.
Well, yeah. So optional. So optional about someone else's problem just kidding
well is is uh is done when like when all the defects are done or that you don't report that
to the other person the api is frozen as yeah anyway exactly well three days i'm gonna hack
that in three days yeah no no problem we got problem. We got it. You got it covered. Yeah.
My favorite is when somebody asks like one person on the team, how long to take this, can you get this to get it done?
And, uh, and like one stage says like a week, so they promise a customer a week.
And, uh, there's like so many other people that need to work on it.
Yes.
Uh, oh yeah.
Did, oh, did you want documentation?
No,
you want that?
You want that written up as well?
Oh, I see a user interface for that also.
Oh,
that's going to be,
nobody pointed that out.
So yeah.
Tests or none.
Yeah.
Anyway,
wait,
we got to close it out with a comment from Alvaro test pipe.
None tests or none in the typing system.
Yeah.
Optional tests are optional. That's typing system. Yeah. Optional.
Tests are optional.
Tests are optional.
Yeah.
Anyway, again, thanks for the wonderful episode, Michael.
We'll talk to you next week.