Python Bytes - #375 Pointing at Countries
Episode Date: March 19, 2024Topics covered in this episode: pycountry Does Python have pointers? ingestr Make your terminal nice Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/375...
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly
to your earbuds. This is episode 375, recorded March 19th, 2024. I think I got that right.
And I am Brian Ocken.
And I'm Michael Kennedy.
And our episode today is sponsored by Scout APM. Thank you, Scout. Listen to their section
later in the show. If you'd like to connect to us, we're on Mastodon and the links are in the show notes,
but it's at mkennedy, at Brian Ocken,
and at Python Bytes, all on fastodon.org.
And if you'd like to listen to this show live,
we'd love to have you, but it's not necessary.
You can listen to us later.
But if you want to listen to us live,
go to pythonbytes.fm slash live and see all the details
and see when the upcoming episode is.
So, yeah.
Michael, what do you got for us?
Well, I would like to start off by telling you about another country.
Maybe one you haven't heard of.
Canada?
You've heard of Canada.
You've heard of the U.S.
You've heard of Germany.
You've heard of Slovakia.
You've heard of the Philippines.
Have you heard of Pi Country?
Oh, this should have a song with it
in a pie country does it involve a uh a ding uh banjo i don't know where it's called i hope not
i know i hope not too oh we should have covered this on the 14th anyway all right anyway i can't
treat pie day all the things okay so pie country is, it solves something that might not sound like a great big
problem until you try to deal with this.
And you're like, are you serious?
There are this many things.
It's similar to dealing with time zones.
You're like, ah, how complicated it can be.
What are there?
24?
No.
And what are their abbreviations and what are all the different ways in
which they can be abbreviated and so on?
This is that for country.
So it's a Python library to access ISO.
These are standards,
country, subdivision, what's a subdivision, language, currency, and script definitions,
and their translations for all the countries of the world, including deleted countries that used
to be countries, but are not. I would have considered those just former countries, but
deleted is a very digital way to think of it.
We just selected that part and we hit, you know, command backslash and it really deletes it all the way.
Yeah.
Anyway, this is, this is really interesting and it's used by 17,
19 of 17.9 thousand different projects, which is pretty cool.
So here's the deal.
So you go in here and somewhere you can just go into it and you say
PI country dot countries, and there's 249 here and you go in here and somewhere you can just go into it and you say, pike country dot countries.
And there's 249 here.
And you get these, not just a list of strings, but you get rich objects back.
Like the first one is Afghanistan.
So country, it's a class.
It has the alpha two code, which is AF, the alpha three code, AFG.
And that's the kind of stuff I'm talking about.
That's like, why are there so many variations?
You can represent, you know, the shorthand version, like just two letters,
but you can also use three letters or there's numeric versions. There's like the full name
versus the colloquial name. So Afghanistan versus the Islamic Republic of Afghanistan.
Oh, this is kind of cool. I might learn something.
Yeah, exactly. There's a lot more in here. And there, it has a dictionary-like
access for the variation. So you can say, get alpha two equals DE, and you'll get good old
Deutschland. Or you could say alpha three equals DEU, or the name equals Germany, or all these
different ways in which you can kind of query this. Or given one, you can obviously just access
all these properties. Like Brian would know that it's the Federal Republic of Germany.
It has fuzzy searching for countries.
So I can say, give me England.
It's like, yeah, there's no England.
What?
But there's this thing called United Kingdom,
which sort of has its center in England maybe.
And that's GB and so on.
So yeah, pretty neat.
You can say fuzzy search for Cote and you get cote de ivore i you
know sorry folks from there but you know you'll get uh like it'll even match when it's not exactly
the right character right like uh oh hat i don't know what that's called not an umlaut but a hat
looking thing instead but you don't have that in the search right yeah so this is more like i said
there's more to this than just like oh a list of countries and then it's historic countries these are the
ones do they since i read this did they change it from historic to deleted i don't know historic
countries uh subdivisions i'm like what is a subdivision of a country this is like states
or providences it's not nearly as strange as it sounds there's scripts also what is the script
it's written language versus spoken language.
Those might be the same thing, but they might also not be the same, like Latin, for example.
Right?
Oh, yeah.
Currencies are in here.
Languages are in here.
Locales are in here.
So if you do anything with countries, this might be worth looking at.
That's pretty cool.
Yeah.
I'm still like hung up on the england isn't a
country but okay well according to my country it's not a country okay and also um so yeah i'll have
to look into this more because is it a subdivision maybe it's a subdivision and but also like what's
where does deutsch the the word deutschland fit in for germany is that not even listed so yeah well also since it has translations
so for example german if you ask a german person where they're from they'll say deutschland unless
they're speaking english to people right like they refer to it as deutschland yeah but for some
reason we don't agree we don't call it that we call it germany right yeah so i don't know it's
it's interesting i suspect if you use the translations maybe and you said, you know, what is the official name of Germany?
It probably wouldn't say the Federal Republic of Germany.
We have that translated, right?
Interesting.
Yeah.
Like Switzerland is Schweiz.
I can't remember exactly.
But yeah, it's different.
It goes by different names and different languages.
So I think it also has those when it talks about the translations.
Cool.
Neat.
Well, we could point to countries.
I'm trying to do a transition.
Or we could point to objects.
And does Python have pointers?
You can't really point to a country.
I don't know.
Maybe.
Point to directions.
Canada's that way. Canada's that way no kim is this way oh man but we're probably we're probably pointing in
different directions anyway um so ned bachelor has a uh an article called does python have pointers
and i'm like yeah no it doesn't but kind kind of does. Anyway, I'm highlighting this because I think it's a really good article for somebody that's coming from a language that does have pointers and stuff to Python because it's a good entryway into names in Python.
So the article does Python on pointers, but it's kind of pointing to the idea of like talking about the ID function.
And I know about the ID function really well. So if you say ID of an object or a variable name,
it tells you like a number for what, like what it points to, like where the, I don't know,
it's a representation of the memory address or something. That's kind of what a pointer is, right? But you can't in C and C++ and Rust and
other things, you can dereference it. Using that, you can create a variable. Using the address,
you can create a variable that points to that thing. And you cannot do that within Python.
So it is different, but also kind of everything is a pointer in Python. And that's sort of Ned's point is that with just normal object,
we can say like my var equals 17, and then we can have,
if you do my pointer, it doesn't help you any.
But you can do another variable that points to the same thing,
and it works. It's when, it variable that points to the same thing. And it it works.
It's when it's just sort of how names work. I'm describing this very poorly. But this
is a good entry point into well how objects work. And luckily, Ned also links to an a
talk he did names that refer to objects and in so he did a talk in 2015. And still the
slides are up in the video,
but even the slides just going through it. It's really good to understand just really how
names work. We're just, in Python, we just kind of point to things. And so I'm going to link,
we're going to link also to the 2015 article, Python Names and Values. And really, this was
the trick. When I really could grok this thing
with python then i could i could understand python um everything else seems easy after this um so
good job yeah and that always has good writing i'm subscribed to his rss feed uh i think it's
interesting to consider whether python you know the article does python have pointers like boy howdy does it yeah yeah like it has more pointers than c++ which is insane it doesn't have a wider variety
of ways to like dereference them you know it starts like casting a void star star to something
else but everything literally everything in python is a pointer even numbers are pointers whereas in
c++ numbers usually are value types, right?
And you can have stuff that's on the stack that's not a pointer, just has the value.
In Python, there is no way to have just a value.
Every everything is a pointer, often pointers to pointer.
You know, you're traversing something to something, right?
It's like, I'm going to find the dictionary of the class, and then I'm following that
to where it points to, to get to the value uh so it's worth spending some time on even though you don't ever see a star or uh an ampersand in the
context of like juggling pointers in python yeah and like like uh vectors or lists in python are
not they're not the plate the start of a chunk of memory that represents all of your items. That's not what's going on.
It's something completely different.
Forget that.
So, yeah.
Indeed, indeed.
Very good.
Very good.
Well, changing gears a little bit,
we'd like to thank Scout APM for sponsoring this episode.
Yes, we would.
Let me tell you real quick about Scout APM.
They're big supporters of Python Bytes,
so we appreciate that very much.
So if you are tired of spending hours
trying to find the root cause of issues
impacting your performance,
then you owe it to yourself to check out Scout APM.
They're a leading Python application
performance monitoring tool, APM,
that helps you identify and solve
performance abnormalities faster and easier.
Scout APM ties bottlenecks such as memory leaks, slow database queries, background jobs,
and the dreaded N plus one queries that you can end up if you do lazy loading in your
ORM and then you say, oh no, why is it so slow?
Why are you doing 200 database queries for what should be one?
So you can find out things like that.
And it links it back directly to source code. So you can spend less time in the debugger and healing logs and just finding the
problems and moving on. And you'll love it because it's built for developers by developers. It makes
it easy to get set up. Seriously, you can do it in less than four minutes. So that's awesome.
And the best part is the pricing is straightforward. You only pay for the data that you use with no hidden overage fees or per seat pricing.
And I just learned this, Brian.
They also have, they provide the pro version
for free to all open source projects.
So if you're an open source maintainer
and you want to have Scout APM for that project,
just shoot them a message or something
on their pricing page about that.
So you can start your free trial
and get instant insights today.
Visit PythonBytes.fm 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.
Yes, it does.
It does. It sure does. Now, Brian, let's talk about ingestion, data them out. It really supports the show. Brian J. Yes, it does. Jeff Lerner, It does. It sure does. Now, Brian, let's
talk about ingestion, data ingestion.
Brian J. Okay.
Jeff Lerner, So here's that open source CLI tool. It's
not exactly Python focused, but certainly useful for Python
people. Ingestor, and it's straight out of the web 2.0 days
because it's dropping some of the vowels.
It says copy data between any source and any destination thinking database type things. So what you do is you just say ingester ingest, source database connection is whatever, source
table is whatever, and then the destination is where it goes. And all of a sudden, now you have that. So do you want your Postgres data to appear over in BigQuery?
Do you want your MongoDB collection to show up in Postgres?
One CLI command, done.
Oh, that's pretty cool.
It's pretty cool, right?
Yeah.
So it's a command line application that allows ingesting or copying data from any source
into any database.
I mean, it's probably should be a star on any, but there are, how about
many, many data sources.
Okay.
Yeah.
Yeah.
So if we jump over here to their docs where like their homepage is
kind of just a catch your interest.
Um, so you can copy, I'll find the sources and tell you about them in a second, but
it says there's three ways to copy stuff over.
You can do an append, which is kind of cool.
Like if you've got multiple data sources that are localized saving of data and you want
to put them all into one place.
Like if you had a bunch of SQLite files from different locations, say you've got a bunch
of, I don't know, a bunch of IOT things, or you got a bunch of i don't know a bunch of iot things or you got a
bunch of servers and they each keep some data in a sqlite file you want to put that into one big
database right you could do append or you could say merge if i'm guessing if the primary key is
the same it just skips it maybe doesn't update to that thing if the fields are different i don't
know or you can just wipe it free and insert so
like a clean replacement delete and insert yeah yeah pretty cool and then somewhere down here
supported sources here's where i was joking about the any supports postgres and it has some of them
are bi-directional source or destination some are just source some are just destination postgres
bigquery snowflake redshift databricks dip db microsoft sql server and csv
files are all bi-directional csv files bi-directional okay but mongo oracle sqlite and mysql are only
sources so i don't know why mongo db is not a destination because it's incredibly easy to just
have like a flat file a flat table no like stuff. You know, if you're copying from a relational database, but yeah, whatever.
Still pretty cool, I think, to be able to use this.
So if you got just data you want to keep in sync or migrate over,
you're thinking of writing Python code to do it,
you might not have to write any code at all.
Well, that's pretty cool.
I don't know what Snowflake is.
It's a great name.
Yeah, we're getting out of that season right now.
It's starting to be warm and summer's coming,
but it'll be back in the fall, like maybe December no that's funny cool well um yeah very interesting um uh
speaking of command lines um i ran across david lord's article make your terminal nice and this
is just sort of a little uh shout out because um so apparently david is using um he is using fish, which I haven't heard about for a while.
So a nicer prompt was Starship and a nicer shell with fish.
And this isn't really a detailed article, but it's just sort of like things can be nicer.
And I was reminded about this because I think a long time ago we were talking with,
anyway, somebody else about Starship about, uh, Starship.
And I was like, I should try Starship.
And I tried it.
And for some reason it didn't work for me, but I'm like this, I think it's time to start
again.
And so, uh, I looked into both of these.
I tried fish.
Um, and I do really appreciate that.
It says finally a command line shell for the nineties, which is awesome.
Um, and funny.
And it's also in comic sans
uh which i ironically appreciate but um the the scripting language is a little different and i've
got a lot of customizations for bash and z shell is very compatible with bash so i i usually use
either bash or z shell and i think i'm going to stick with that, but, um, Starship
Starship's amazing. And, uh, so I switched to Starship and I, the, when you go to Starship,
there's an installation guide and really it was so easy. It was, uh, there's a mat, uh, Mac OS line.
You just, uh, curl, install it, or you can homebrew. Um, I think i did the homebrew thing anyway uh but then how do you use it there's
a usage of just um so i was on z shell so you just had to add one line to your z shell rc but there's
uh there's instructions on how to do it within bash or fish or powershell or oh cool it works
with powershell that's pretty neat um for all you Windows people out there.
But so what you get, what I really like is this notion of the directory is right there listed above your command. And then listing what I really like is what my git branch is, my directory, which version of Python I'm using the example here shows a rust, but
but it shows which version of Python you're using, and then
also what virtual environment you're in. So having and I
didn't configure that at all. That's just the default. And I'm
like, that's good. I'm good with that. So I haven't configured it
at all. Just the default right out of the box. It works really
good. So I'm pretty happy so far
anyways yeah i think there's a lot of options here right there's on my z shell there's starship
there's all the different shells these days i'm using warp warp.dev which is pretty excellent i
talked about that on the show before i kind of forgot about warp i should try it yeah warp warp
is cool yeah i think the big thing the big message people should take away from this is don't just take what your operating system gives you.
It's really quite bad.
It's not just not great, it's bad.
And a lot of people who are like,
I don't really like, I'm not really a terminal person
or I'm not a CLI person.
That's because they didn't spend 30 minutes once
getting into it like, oh, actually, oh, that's nice. Like getting it to where like, oh, actually,
oh, that's nice.
And you point out like, oh, well, is there a virtual environment active?
What is its version?
And then all these other things.
Are there Git changes?
Am I in a Git repository at all?
Are there changes?
Et cetera.
Like all those little, every one of those is just, oh, that's nice too.
And it really adds up.
Well, and I've always been one to, I mean, for my career, I've been usually juggling multiple projects,
multiple branches on projects and everything.
And I've kind of been okay knowing what I'm doing.
However, recently, I just have leveled up that
of using way more branches, way more projects,
and just having that information for me right there
to make sure that I know what version of Python I'm using,
what branch I'm on,
and having that just ever-present is like,
oh my God, I don't have to think about that anymore.
Awesome, it's just right there.
So I just hit that pain point
where having that information is helping me,
and so I appreciate it.
So anyway.
Very nice.
Cool.
Very nice. how about any
extras do you have any extras for us i'm feeling extra today i got a few extras for folks first of
all i spoke about uv or no brian you spoke about uv and i just jumped on we both wanted to talk
about it but you had it first i believe yeah it was it was officially your topic on the show
however uh and you had charlie marsh on Code. And so I just published an episode
of Talk Python, having the conversation with Charlie about UV and a little bit of rough and
just life in general. But I have a big backlog of shows over there that I'm working to release
because I've recorded faster than weekly release cadence. But this seemed very timely so i put it put it to the front
of the queue so people can check that out i can't wait to listen so yeah it was fun also follow up
here is uh there's this really interesting youtube channel i don't know if it's in general
interesting just the one i watched is called dark matter and they have like highly produced video versions of what would be a podcast which
is kind of interesting so they had the one with david uh dhh talking about the leaving the cloud
cloud fusion but just like if you look at the video side of it it's like could be a documentary
sort of thing so anyway that's interesting we're checking out you want to follow up on all my
leaving the cloud talk i did uh for those who like to live out near the front of the leading edge, Python 3.13 Alpha 5 is available and people can go check that out.
So it's not quite beta.
And once it hits beta, there's no more changes.
But right now there's still potentially breaking changes.
Things could be added.
Things could be removed.
So on. changes but right now they're still potentially breaking changes things could be added things could be removed so on but in this thing i'm linking to there's a nice list of you know what's
some of the improvements like for example how exciting a preliminary experimental jit was added
by the way just like throwing that out there as if it's nothing your python will be compiled
and then finally this one comes to us from pat Decker, Target Tech. So the tech blog at Target.
This is really cool.
It said, Target posted something on their blog, which I didn't know they had a tech blog.
So that's, I guess, news.
But cool for them.
Announcing Target's open source fund.
Oh, cool.
Yeah.
And it says, we created Target's open source fund as a commitment to support open source projects we use. In short, Target now directly donates to projects through an internal process that prioritizes
representation of Target's technology team.
Perfect.
This is perfect.
It says, look, we're basing this on some of the prior work that's out there.
And in fact, the success of Sentry and Microsoft's open source funds have inspired them to go
further.
And then it lists projects like,
you just gave a shout out to Homebrew,
OpenAPI Generator, SDK Man,
Mach K for Kotlin and HTTP 4K.
So it looks like they do a lot of stuff with Kotlin.
So they're supporting that,
but whatever, right?
You support what you use.
I think that's cool.
Yeah, I think, yeah, every company.
I mean, every big company, even companies you don't even think use open source, use open source. right you support what you use i think that's cool yeah i think yeah every company i mean every
big company even companies you don't even think use open source use open source so yes exactly
yeah there was a quote they gave in here that said uh the linux foundation estimates that 90
of the code in production is of open source origin probably you know using libraries based
on open source i would imagine you know like the fact you use Flask would make your stuff of open source origin, I would imagine.
Yeah. And I know that there are some wrinkles in how the money often gets distributed, but some money getting distributed is better than none. So that's one thing.
I'll say one more thing just to encourage other companies, people within other companies to do this. We recognize that it's our responsibility to engage across a broad spectrum of activities this includes contributing our own software to open
source joining communities and patching software used by others plus funding with money the others
they mentioned that's pretty cool yeah cool um well uh the only extra i've got is that i have
been working on a side project um that i'm starting to ramp up a little bit.
And I've decided to start in a SaaS project.
And I've thought I would get a little head start
by using Corey Zhu's SaaS Pegasus.
So I talked with him just the other day.
So his interview will be on Python test.
But as I go along, I'll be reporting how it's going. And yeah, I'm just excited to get started.
Nice. You're going to live blog it? Blog the progress?
Yeah. It's just going to be slow going because there's a lot more going on in my life,
but I want to get it off the ground. Indeed. Yep.
I know the feeling.
How about something funny?
Yes.
Let's talk about something funny.
So this comes to us from DevHumor, directly submitted by admin.
It's got like a kind of a cybersecurity thing here, Brian.
Okay.
So, you know, like social engineering, like, hey, I'm from IT.
You're going to get a pop-up on your authenticator that says,
we're just checking some systems. So if you don't mind just approving that,
you know what I mean? I know it's your personal email, but we're just working on it for you. So anyway, here's the joke. If a person who tries to trick others into giving them personal or
sensitive information is a social engineer, does that mean that the person who tries to prevent that is an anti-social engineer well i mean i've met a lot of uh cyber security people and i maybe
i think it might be an over generalization but yeah yeah it's funny anyway are you an
anti-social engineer this time it's a good thing i i know just who i need to send this to this is
awesome perfect awesome thanks um well that was a fun episode um and thank you everybody for
listening and watching and everything and thank you michael yep you bet bye