- Podcasts
- Python Bytes
- #338 Scripting iOS with Python
About this episodeTopics covered in this episode: The Basics of Python Packaging in Early 2023 vecs Introducing Grasshopper - An Open Source Python Library…
- The Basics of Python Packaging in Early 2023
- vecs
- Introducing Grasshopper - An Open Source Python Library for Load Testing
- memocast
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#338 Scripting iOS with Python
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 Okken. And this episode is brought to you by us, our courses and books and things like that. Talk to you more about that later.
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. 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 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.
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 a flit core.
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. 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 then 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, 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 build now with this.
This is- I think, Brian, before you move on from that, that I just noticed that I really like. If you do 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. It is 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, what, curly braces and then file equals license.
Dictionary-ish. Yeah, it's a dictionary. Whereas the readme is 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 GitHub link. But you can have your documentation and other stuff. And all these show up in PyPI also if you're published to PyPI. And if you don't want to publish to PyPI, 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 carrying 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, make sure that you understand the build step of Python-M 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. 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.
So why would you choose different ones? And one of 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.
I haven't tried any of these. If you're into Mason, you can use Mason Python. 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. Yeah. Definitely demystify some of that. Henry points out in the audience, the license key will likely change via PEP 649.
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 Olly, who open sourced this, Olly 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 pgvector extension for Postgres, the database.
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.
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 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.
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, 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.
And it's open source, too. Cool. Neat. Yeah. Yeah, very neat. I'll be needing that very soon. Yeah. So. 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 wanted to remind people to, you know, please check out the brand new Talk Python training apps.
They're rebuilt for iOS and Android. I really think it's a cool experience for people to take it. 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 have gotten.
Excellent. Also really quick follow up. Henry points out that it was actually PEP 639, not 649. Not a typo there. Yeah. So 639 is improved license clarity with better package metadata. It's in draft, but hopefully there'll be, it's in draft really? Anyway, some changes to how you specify the license, which would be good.
So there's a company, AlterX, maybe? Anyway, they've introduced grasshoppers. So it's a locust grasshopper. It's an open source Python library for load testing, but it's built on locusts. So what's the difference? So we're linking to an article that discusses the introduction and discusses why they love locusts and everything, which is great.
But they have a check, like grasshopper, what does it add? Well, it adds a whole bunch of really cool features that you might need if you're load testing and developing a package and keeping track of your load testing over time. So it has these extra checks in here. And checks, if I get this right, are things like special validation functions, Boolean functions that can run.
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 readme a little bit more is this idea of, like, tagging your test suite.
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. Yeah, sure. 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 HTTPX like they should or HTMX like they should.
Also, a nice shout out to a sponsor there, InfluxDB. So pythonbyes.fm slash InfluxDB. 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. It's like, oh, we've extended Locus. Oh, and here's why. And they give some pretty good reasons. Another 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 memory load on the server would be really interesting.
Yeah, this looks nice. It's definitely worth checking out. Some of the check functions, you might be able to, like, abuse that for that purposes, too. While your load tester is running, check CPU levels and stuff like that. I don't know. Yeah, exactly. So anyway, neat project. Yeah, that's a good project.
So 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 like a superset, probably. Yeah. So if I have already written a bunch of locust tests, could I run them, or how easy is it to... I don't know, but I imagine it's not that bad to convert. Yeah. It looks like the code is super similar. So worst case, you maybe change the base class, but possibly the base class is derived from the locust 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 want to do, you might want to say, oh, 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 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 is reading the website. Imagine you just as often as I do listen to a podcast such as Python Bytes, a fantastic one.
Thank you. Thank you. Using Google Podcasts, walk around, you know, 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.
Yeah. I can't really zoom that without the. I can't really zoom it without the 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 MemoCast. You say run in Pythonista. And so this is a Python script that that Daniel wrote that basically you run it through Pythonista Python 10 on iOS.
It does a guessing request or something called 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, I mean, real Python as the three supportive podcasts.
But you can integrate new ones if you wish. And you install it once you have Pythonista, which I think costs $10 US one time. But then you can install it scanning the QR code here with Pythonista 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 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 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 Pythonista as an iOS app within macOS.
So you go to the App Store, search for it on Mac and it doesn't come up. So 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, MemoCast. 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 Pythonista a little bit more than maybe I realized you could, like an OS integration level.
Hugo Van Kimenad. Wrote, help test Python 3.12 beta. So 3.12 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, bye. 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.
I 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. Wanted to shout that out. It's some interesting stuff, though. There is. I just interviewed Brett Cannon over on Talk Python about this.
And we complied and talked to lawyers. And it's weird. But, you know, 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, what is it, FASA? Like the more international crime investigation laws. So we'll have a subpoena canaries. It'll be like the canary will be here unless we are subpoenaed.
Then the canary is 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 being transparent about that. Yeah. One of the things that was interesting is that they got asked for addresses, including mailing and residential addresses.
Not Python. 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/github slash git ignore 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.tominal 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.
I hadn't really thought about it, but you could nab it for other purposes as well, right? Yeah. Yep. And then someone on Masset, I'll point out, you can do nox Python ignore. And I think it'll generate that file for you and uses that as the backend. 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.
Yep, LEDs. Got to be careful about home automation. You might complete all the checkboxes. Yeah, I think sometimes you have to execute a child. That's funny. Child processes. Yeah, they both execute children, right? I mean, that's a pretty rough one. Kim, I believe, maybe has done enough XSLT as I have to know that it should never, ever be done.
