Python Bytes - #338 Scripting iOS with Python
Episode Date: May 30, 2023Topics covered in this episode: The Basics of Python Packaging in Early 2023 vecs Introducing Grasshopper - An Open Source Python Library for Load Testing memocast Extras Joke See the full show ...notes for this episode on the website at pythonbytes.fm/338
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 338, recorded May 30th, 2023.
I'm Michael Kennedy.
And I am Brian Ocken.
And this episode is brought to you by us, our courses and books and things like that.
Talk to you more about that later.
Also connect with us on Mastodon or all over on Fossadon at mkennedy
at Brian Ocken and at Python Bytes. And we love it when people join the live show. If you want to
be part of that, you can see the next scheduled upcoming one at pythonbytes.fm slash live and
click that notify me and YouTube and guess what? It'll notify you when it's live. So that's the
front matter, Brian. I think we should start it off with some basics
what do you think yeah let's go back to the basics uh basics of python packaging so actually this is
something near and dear to what i've been paying a lot of attention to lately is um is packaging
and just how it's changed and it's kind of in the most people have switched over to pyproject.toml now. And that's really what this is about.
So when you're packaging, especially a pure Python package,
well, one of the things I like about this is it's not just for pure Python,
but that's the easy part.
If we're using pure Python packaging,
you're probably using a pyproject.toml now.
And there has been several write-ups of it,
but some of them are kind of tool-centric.
So I like this write-up from Jakey, not sure, that talks about just sort of the easy,
a fairly standard setup. So it does talk about the peps in this article, but you don't really
need to know much about that.
You can just kind of skip to how do I do it.
So using the peps and using PyProject.toml, you do have to specify what your build backend is.
So in the top example of this article, it talks about using flitit core. And that's one I've used. I've used a lot of that. But then,
then what else do you put in there? So within your,
the rest of the project Tom was mostly metadata.
You can have other stuff too, like black and everything,
but for your project building the project metadata,
there's not a lot that goes in it. I mean,
it looks like a lot when you just glance, but it's really, you know, it's your name for the name of the project, the version,
description of it, your author. I will point out that this is not minimal because it includes the
email. You don't have to include the email. If you don't want to, you can just put the name
and where your license and readme and classifiers are. The thing, one of the things I want to
highlight is make sure you have the license, at the very least, have your license and readme and classifiers are. One of the things I want to highlight is make sure you have the license,
at the very least, have your license classifier listed
because that's how the license shows up on the PyPI.
So when PyPI is looking at projects, it looks at the classifier.
And try to throw in which Python is required
and then any of your dependencies that you're using. And then some
links. I mean, it's really it when you just talk about it as a
stream of conscious, it seems like a lot, but it's really not
that much. And you're pretty much done, you can do a do a
build now. With this. This is
Brian, before you move on from that, that I just noticed that I
really like if you do like a setup.py, what you've got to
put is the readme and details and the descriptions and all those kinds of things, at least a long
description. You've got to actually load the file and inject the content to the file. And here you
just put the file names for the license and for the readme, and it'll just pull those in, right?
That's cool. Yeah. It is one of the those in right that's cool yeah it is it is uh
one of the things i've harassed people about before is it's weird that the readme and license
are specified completely different so the license has this like um what the curly braces and then
file equal license area it's a dictionary whereas the readme is just a text string with the name of
the readme um it's odd i think that maybe we could have it so the license could just a text string with the name of the readme. It's odd.
I think that maybe we could have it so the license could just be a string with the license file on it also.
But anyway, there's probably reasons, I'm sure.
The thing that I also want to point out is you can put as many URLs as you want in here.
You can have like this example as homepage and bug tracker. a lot of people just list home that lists the the github link but you can have your documentation and other stuff and all these
show up in pypi also when you're if you're published to pypi and if you don't want to
publish to pypi one one extra is to that kim reminds us of is another classifier I learned about is private do not upload, which
tells PyPI to not upload it. So this is all great. And a lot of this also, if you want to watch it
in video form, is covered in the sharing is caring video. It's a talk I gave in PyCascades.
The video is now online. We'll put a link in the show notes.
But this document or this article goes through some of the different, makes sure that you understand the build step
of Python dash and build is one way to do it. There's other ways.
But then it talks about some of the
discussion around why pyproduct.toml is there instead of setup.py.
I think we're all convinced
hopefully um but then also some choices of backends so this article used flit core to start
with but there's also hatchling and setup tools and poetry core um uh so why would you choose
different ones and one of the the and it's because there's extra features. Some of them allow extra tags to go in there.
And the example they're using, and that's one of the reasons why I use Hatch a lot,
is you can have include and exclude things to say, you know,
the normal stuff that you'd probably include in a source distribution,
also add the tests, for instance, or something else. The test is one that like
distributors, redistributors, like Linux distros, like to have your tests in the source distribution.
So throwing those in there is a good idea. I'm not sure why they're in there by default. But
anyway, it's a cool discussion. One of the things i also love is it talks about what happens if
you're not just python what if you have to include c well it doesn't really discuss it too much it
just points you in the right direction so if you have c or c c plus plus extension there's a psych
kit build core that you can use i haven't tried any of these if you're into mason you can use
mason python um and then also setup tool supports it.
So there's a direction for that sort of stuff.
Yeah.
Straightforward.
Back to the basics.
I like it.
Definitely demystify some of that.
Henry points out in the audience,
the license key will likely change via PEP 649.
And currently Flit just ignores whatever you put there.
The Trove classifiers are the
canonical location for the license so just fyi thanks for for that henry he always has such
excellent extra information background information and we're so lucky to have some smart people show
up on the chat so thank you yes absolutely all right let's talk vectors. So I want to talk about VEX.
And this project comes to us from Oli,
who open sourced this, Oli Rice.
Now, before I actually tell you about what VEX is
and what it does,
let's take a step back and talk about
the PG vector extension for Postgres, the database.
So this is an open source,
because VEX has to like builds on top of this. So this is an open source because Vex builds on top of this.
So this is an open source vector similarity search
extension for Postgres.
So you can do things like
given a bunch of points in different dimensions.
This could be X, Y, it could be X, Y, Z.
It could be temperature and time.
I don't know, right?
It could be whatever you come up with. It'll give you know temperature and time i don't know right it could be whatever you come
up with it'll give you the exact and approximate nearest neighbors allow you to query that like
given some measurement what other measurement is closest or give me the five measurements or
positions that are closest to this gives you l2 distance it'll do the inner product and cosine
distance so different metrics if that makes sense.
And any language with a Postgres client can speak to it.
It's pretty cool, right?
Yeah.
Yeah.
So let me see if I can find some examples.
So I can say, get me the nearest neighbor by L2 distance.
And it says the way you would do that directly is you say select star from items order by embedding whatever the the value is is closest
to in this case the vector value three one two and then limit five just like you do in databases you
know give me the first five so order by closest to farthest and then just give me five that'll give
you the five nearest right you could do things like sort by distance. You can find exact matches. And you can also do other database things.
Let's see.
Like give me where the ID is or is not equal to some value and so on.
All right.
So pretty neat.
Now, that's the PG vector extension just for Postgres.
So you're speaking to it in a special flavor of SQL sort of.
In Python, you can talk to this using this
thing called VEX. Okay. So with VEX, you just pip install it and then you insert a bunch of vectors
and then you can write queries that are more, um, more API based, I guess, not just direct SQL
statements. So you give it the vector that you want to query against. And then, you
know, like how many you want back. If there's a filter to say, I only want the ones for a certain
year, right? Filter it down and then do that query based on distance or whatever. So pretty cool. If
people are out there doing that kind of work, I think they might find this pretty helpful.
Yeah, very. Oops. It's not something that I have exact direct use for these days.
But a lot of scientific or geospatial type of things
seem relevant.
Yeah, I've been spending more and more time in SQL queries
lately.
So anything to help with that is good.
Yeah, absolutely.
Now, one final thing.
It says in here, it says you've got to have,
I can't remember which one, talked about getting Postgres. One of them, yeah final thing it says in here, it says you've got to have, I can't remember which
one talked about getting Postgres.
One of them, yeah, this one says, if you don't have a Postgres database, see some hosting
options.
And if you're on Mac, I just want to throw out there really quick, postgresapp.com.
All you do for this one is it's super awesome.
You download it, you unzip it or undmg, whatever its packaging format is.
And it's just a Postgres.app.
You double-click it, Postgres is running.
You close it, Postgres is not running.
It auto-updates itself.
Yeah, so pretty sweet.
And it's open source too.
Cool.
Neat.
Yeah, yeah, very neat.
I'll be needing that very soon.
Yeah.
Yeah, cool.
Check it out.
Yeah, that one's, that's pretty nice.
Okay, now before we move on, Brian, brought to you by us, this episode is so I want to just remind people to, you know,
please check out the brand new TalkPython training apps. It they're rebuilt for iOS and Android,
really think it's a cool experience for people and take it has offline playback, and obviously
way better on the mobile and tablet type of things. And it comes with six free courses that
you can just tap on and join the free courses
plus anything you might've gotten.
So check that out.
And I want to shout out your book or what do you want to shout out today?
Yeah, well, there's, there's time is running out, but the, um, yeah, let's, uh, the, the
book is still on a promo.
So, um, uh, Python testing with PyTest, there is is what is the promo it is uh spring 2023 all
caps all one word and you get 50 off and it's just for like today and tomorrow i think it runs out at
the end of may um but anytime you want it uh there's a 25 that's 50. But if you want to sign up and get to their email list,
you can get 50%, 25% off normally.
So anyway, that's a good thing.
Excellent.
Also really quick follow-up.
Henry points out that it was actually PEP 639,
not 649, typo there.
Yeah, so 639 is improved license clarity
with better package metadata.
It's in draft, but hopefully there'll metadata um it's in draft but um hopefully they'll be it's a draft really anyway uh some some changes to how you specify the license
which would be good so all right let's talk about plagues next plagues like uh you know
locusts and grasshoppers. Yes, exactly. Nice.
No, I like these kind of plagues.
These are awesome tools.
So I've used Locust before.
I think you've used Locust for...
I love Locust.
Yeah, for load testing.
So good.
So there's a company, AlterX, maybe?
Anyway, they've introduced grasshoppers.
So it's a locust grasshopper.
It's a open source Python library for load testing, but it's built on, on locusts.
So what's, what's the difference.
So, uh, the, we're linking to an article that discusses the introduction and discusses why
they love locusts and everything.
Um, which is great, but they have a check like a grasshopper
what does it add what it adds a whole bunch of really cool features that you might need if you're
load testing and develop developing a package and keeping track of your load testing over time
so it has these extra checks in here and uh checks if i get this right are um things like uh special
validation functions bo Boolean functions that
can run and you can tell, you know, different checks, whether or not they're passing or
failing over time, which is based on the document had this text in it to make sure it wasn't
insane in the response or something.
Yeah, actually, I'm not quite sure.
So I'd have to dig into that more.
But one of the things I really like is these custom trends, which custom trends and timing thresholds and integration with PyTest.
Of course, that's awesome.
Time series, database integration and reporting.
This all sounds great.
One of the things I really love that's talked about in the read me a little bit more is um uh this idea of like tagging your test
suite so tag back suites so you can uh you can do see your load test results based on different
versions so if you're tagging with using version tagging on your repo you can see what the
progression is and and how well your your application is doing based on different and
different load requirements.
And you can have thresholds like with this load,
you need to have like 90% the speeds of things.
The other thing is some speed thresholds. You can have multiple timing little functions
that have multiple HTTP requests.
So an action that really is like a user action
often is several interactions,
like how fast can somebody log in or something like that,
or go through the checkout.
That's going to be a multiple sequence thing.
You can time that under load and under stress.
And that's a pretty cool addition.
Or even to load this page, we're going
to, it's probably some complicated JavaScript front end. So it's going to call this API and
that API and that API just to load this HTML page. So you kind of want to treat that as like the
page is loaded when these seven API calls finish, right? Something like that. Yeah. Because they're
not using HTPX like they should or um htmx like
they should also a nice shout out to uh sponsor there influx db so pythonbytes.fm influx tv this
is the time series database that it integrates into when i looked at this brian i'm like yeah
but locus is pretty awesome why would somebody go create another one of these for the python world
when locus exists and then i read it's like
oh we've extended locus oh and here's why and they give some pretty good reasons another um trend
that would be cool i don't know if you can actually measure it here but it talks about
custom trends is one of the things you can track things like cpu load and um memory load on the
server would be really interesting or you know maybe cpu load on the server would be really interesting. Or maybe CPU load on the database server
while we're hammering the web server.
If you could pull those kinds of things in,
that would be really cool.
Yeah, maybe you can.
Yeah, I kind of get the sense that it might be possible,
but let's see.
Not sure.
But very cool.
Yeah, this looks nice.
Some of the check functions, you might be able to like
abuse that for that purposes too if while it's while your load tester is running um check uh
cpu levels uh and stuff like that i don't know yeah utilization so anyway neat neat project
yeah that's a good project so uh grasshopper, right? Yeah. Oh, one of the things that they talk about in the,
I wasn't clear on it because I went and looked at PyPI
and looked for Grasshopper and I found the wrong one.
So it's Locust-Grasshopper.
So that's the GitHub repos under that.
And that's what you pip install also is Locust-Grasshopper.
So just to be clear.
Got it.
I wonder if it's uh
like a superset probably you know so if i have already written a bunch of locus tests could i
run them or how easy is it to i'm a matt i don't know but i imagine it's not that bad to convert
yeah it's it looks like the code is super similar so worst case you maybe change the base class but
possibly the base class
is like derived from the locus base class that you use for your test cases or test suites yeah
anyway i haven't played with it yet but it looks cool the readme's got tons of information too
good job on loading up the readme with lots of examples indeed and before we move on kim says
it could possibly hook into telemetry tooling like Prometheus, which would enable metrics from other servers and stuff like that.
Yeah, that's kind of what I was talking about, but not with actually concrete ways of doing it like Prometheus.
So, cool.
Neat.
Yeah.
And I want to talk to you about something that is near and dear to this podcast.
We talk about a lot of topics, right, Brian?
Yeah.
And if you go over to Python Bytes
and you pick a particular episode
and you scroll through here,
you can see it is chock full of links.
So one of the things you might wanna do,
you might wanna say, oh, I'm listening to this.
I wanna remember not all of them,
but just three things that I'm listening to this. I want to remember not all of them, but just three
things that I can come back to. And if you're on your iThing, your iPhone, iPad, et cetera,
or even on your Mac, technically, if you've got an Apple Silicon Mac, you can use this thing called
MemoCast. So MemoCast was created by Daniel Engvall.
It's interesting on its own,
but it's also interesting in a way to kind of script iOS with Python,
which I hadn't really thought about doing.
So first of all, let me tell you about MemoCast
and then you can think how this might apply to you.
So this is a small iOS app
that allows you to add links heard about
in a podcast as a reminder.
So you can check them off your reminder list, you know,
the at reminder app when you're done with them. So check this out.
Imagine this, this is reading the website.
Imagine you just as often as I imagine that you just as often as I do listen
to a podcast, such as Python bites, a fantastic one. Thank you.
Thank you. Using Google podcasts, walk around, you know, you're,
you're doing it while you're out and maybe
busy like mowing the lawn or something, right?
And then there's some thing talked about you wish you had more time to check out.
Thankfully, the reference in the show notes, but you'd have to look it up and go through
it and copy paste and all that.
So there's a little video here.
Notice this on this page.
And it shows all you got to do is say share go to the
podcast player say share click memo cast and it gives it a second then it has a list of all the
links that it's discovered in there isn't that cool brian that is neat yeah i can't really assume
that without the i can't really assume it without the um responsive design only making it smaller
but so how is this possible the thing you share it to
is you don't share it directly to memo cast you say run in python nista and so this is a python
script that um that daniel wrote that basically you run it through python nista python 10 on ios
it does a i'm guessing request or something call over to our website and parses out all the links
and then turns that into a ui that you can interact with cool right that's all done on the
phone then yeah that's pretty cool yeah it's pretty cool and so basically this is an example
supports python by stock python main real python as the three supported podcasts but you can
integrate new ones if you wish and you install it once you have
python nista which i think costs ten dollars us one time but then you can install it scanning the
qr code here with python nista and that will download it then you can just turn it into a
thing that you can run it also talks about how you add new podcasts if you want to add a different
one but that's somewhat interesting i think what's more interesting is he took this Python code
and the code is right here
to build kind of a scriptable GUI for iOS,
which I think is pretty cool.
Yeah, that is nice.
Cool.
So talked about like,
I did try to do this with Kivy and other stuff,
but let me tell you the build chain and code signing
and all of that is like a nightmare.
And so here you just write a Python script and just run it inside of that is like a nightmare. And so here you just write a
Python script and just run it inside of this app that already exists. And final bonus before I call
all the time on this one, Daniel also discovered that if you're on a Mac with a Apple Silicon,
then you can run Python Nista as an iOS app within macOS. So you go to the App Store, search for it on Mac,
and it doesn't come up, but then you click, say,
show me tablet, you know, iPad apps, and then it'll come up.
And then it integrates with your favorite IDE, such as PyCharm,
and you can run it.
So you can develop these little things on your Mac with a proper keyboard and everything,
and then just deploy it to Pythonista on iOS.
Yeah, that's pretty cool
so yeah people can check that out memo cast it's kind of cool that it's about our podcast in this
way but it's also more cool that it just kind of shows you how to take python and leverage python
a little bit more than maybe i realized you could like an os integration level yeah i didn't know
you could do that that's cool i did not either nice and i guess before we
jump out of here as well kim points out on android which i have some but not tons of experience with
you can run python code with q python should someone want to emulate this for android thanks
kim cool all right is that all of our topics brian that is all of our main topics yes yes of course we always have extras yeah joke any
extras for you though yeah i can kick this off so um uh just a few um uh a shout out from oh
who wrote this i'm not sure uh hugo van yeah kim and odd um wrote uh help python help test python
312 beta so 312 is in beta.
If you are a package maintainer
or just your own application,
you may as well start testing
to make sure that you don't have any surprises.
So this article does talk through
basically how to hook up your GitHub actions
so that you're testing 3.12 also.
And then whether it's the official Ubuntu latest or the Dead Snakes version,
a couple ways to do it. And then even if you're using Travis CI still, why? Anyway, you can do
that with that as well. So that's the first. Secondly, I wanted to say that at the Python
Software Foundation blog, there is a whole bunch of new articles
they basically wrote up.
There's articles writing up all the different things
that happened at the Python Language Summit.
I haven't gone through these.
They're just available.
I wanted to shout that out.
It's some interesting stuff, though.
There is.
I just interviewed Brett Cannon over on TalkPython about this.
He gave us the walkthrough of all the presentations
and thoughts at the Language Summit. Okay. over on Talk Python about this. He gave us the walkthrough of all the presentations
and thoughts at the language summit.
Okay.
And then from the news from the weird,
I don't have much information about this
other than on the Python Package Index blog,
they say, hey, PyPI was subpoenaed
and this thing happened and we complied
and talked to lawyers and it's weird,
but it's just odd
yeah so how about you any extras yeah i wonder if this has to do with some of the malware
crypto jacking maybe stuff that was uploaded to it and they're like all right we're going to try
to track down some of these people there are certain places that are not allowed to say whether
they received a request and i think this is not a subpoena this is more of a
was it fasa like the more international crime investigation laws so we'll have uh subpoena
canaries that it'll it'll be like the canary will be here unless we are subpoenaed then the
canary's gone we won't say anything but we'll just this bird won't be on the page or something
anymore so you can kind of know but yeah it's kind of cool they're they're being transparent about that yeah what is that
transparency it says right there yeah and one of the things that was interesting is that they got
asked for addresses including mailing and residential addresses but they don't collect
that they just i mean that there's that information isn't saved so it's not there yeah i'm sure it's
a form and like we would like this information well we don't have that so it's not there. Yeah, I'm sure it's a form. Like, we would like this information.
Well, we don't have that, so we'll give you what we got.
Yeah.
Okay.
Nice.
All right.
I got a couple real quick ones here.
Not Python needs to.
One, I wrote something called, you can ignore this post.
Trying to get a lot of attention, of course.
What it actually was is I just wrote about the github.com slash github slash gitignore repo, which has all, like when you go to GitHub
and you say create a new project and it says,
do you want an ignore file?
And it gives you a list.
These are all the ignore files for every language
supported there, including Python,
which is in here somewhere right there.
And so you can actually see what they all are.
You could even do a PR.
Like we really need to start ignoring,
you know, if there's a new file format
that's like a build output
of some new PyProject.toml tooling
and it starts to, you know, needs to be ignored,
you could say do a PR against this.
So every repo on GitHub starts to adopt it.
But also if you're doing, say, Python and front end stuff,
you could go look for Node,
and you could select one and then copy some stuff out of another
to kind of create a combined one, right?
So you're not like, well, is it Node or is it Python?
I really want the ignore for.
So anyway, that article is just sort of about that, really short.
People can check that out.
I use that all the time because I'm also on GitLab,
and GitLab doesn't fill those
out for you um oh yeah i hadn't really thought about it but you could nab it for other purposes
as well right yeah yep and then someone on mastodon pointed out you can do nox python ignore
and i think it'll generate that file for you and uses that as the back end i think i think so some
of the nox and some incantation will generate an ignore file for you and if we have that wrong somebody will correct
us they sure will and we appreciate it and speaking of incantations are you
ready for the joke yes okay so here's the joke for developers it says careful
where you might end up summoning a demon and it has two categories what you do in
programming and what you do in demon summoning.
So first one is you must know a language unspoken by mankind.
Programming, check.
Demon summoning, check.
Requires that you be exact or suffer dire consequences.
Programming, check.
Demon summoning, check.
Involves much cursing, swearing of oaths, and pleading with a higher power. Programming,
check. Demon summoning, check. Another one is not understanding the true power you wield or
the consequences of your actions. Programming, check. Demon summoning, check. The only differentiation,
which I think is debatable, is candles. Do you use candles to accomplish this job? Programming,
no. Demon summoning? Yes. And
if you look over on Reddit, the comments are pretty glorious. That's funny. Let me see if
I'm finding these good ones just here. Someone has said something like, I've been trying for
hours to get this demon to run and I just can't get it to work. That's what I'm writing on. Well, daemon, not daemon, right?
Of course.
And then someone else points out,
you know, there actually is a Candle app platform,
which sounds truly demonic to me.
So let me describe.
This is like a real thing.
This is not a joke.
Candlescript.org, somebody created this.
Let me lay out the beautiful technologies
that Candlescript combines. Are you ready to use the new open source platform that unifies core features
of XSLT, XQuery, XML schema, RelaxNG, BNF, and XQuery update and more into a single language
called Candle? No, please no. XSLT, no. Yeah, that sounds pretty demonic already. So
I'm a little suspicious of that one.
Yeah, and I think actual demon summoning,
they're probably worried about climate change
and probably switching to low carbon lighting.
So probably LEDs now instead of actual candles.
Yep, LEDs, got to be careful about home automation.
You might complete all the check
boxes uh yeah i think sometimes you have to execute a child uh that's funny um child process
yeah they both execute children right i mean that's one's pretty rough one uh kim i believe
maybe has done enough xslt as i have to know that it should never ever be done and says candle script has just triggered my ptsd
yeah funny oh the battle xml days
well that's it brian great show as always thank you for being here well thank you
thanks you everyone for listening and those of you who joined live it's great bye