- Podcasts
- Python Bytes
- #376 Every dunder method in a Python Lockbox
About this episodeTopics covered in this episode: 🤖 On Robots.txt niquests Every dunder method in Python Lockbox Extras Joke See the full show notes for…
- 🤖 On Robots.txt
- niquests
- Every dunder method in Python
- Lockbox
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#376 Every dunder method in a Python Lockbox
So he wrote up a blog post called onrobots.txt. So the idea was robots.txt is to stop search engines and stuff like that. But I don't actually want to stop search engines. I want search engines to find my stuff. I just don't want the AI stuff. So Jeff's been thinking about this. I've been thinking about it also.
But there's also an article, go ahead and block rub callers, discussing why you might. And then a dark visitors. I think this is going to be one to keep track of, that it might hopefully they keep it up. But there's a big list of known AI bots to block. And so maybe keeping up on this might be a good idea if you care about it.
Jeff's note was that he added it to the website. Django. There's a couple different articles about adding robots.txt to a Django website. There's one by Will Vincent and one by Adam Johnson, both biggies in the Django community. So we'll link to those. And like I said at the beginning, Jeff said he went with a plugin called Django robots to populate that and control it through his admin interface.
And I guess I wanted to ask some questions before we moved on. One is as a community, I think that there should be an easier way to say don't scrape this if you're an AI. Other than listing each one, we should have a standard for that. But what do you think of this? Should, as a content creator, should I care about that?
What does Talk Python think about this? Or, you know, write me a summary of this in the style of a Talk Python interview. Like, is that harming me? No, probably not. Is it creating some cool aspect, like Halo, of the content creation side? The fact that ChatGPT knows about those kind of things, that's kind of cool.
Kind of on the plus side. I don't know. I mean, we have... For you, a lot of your content is, I mean, your open content is open. But a lot of your content's behind a paywall with Talk Python training. If somebody were to throw all of those trainings into an AI model... Yeah, that would be different, right?
Yeah. So, yeah. I mean, I certainly have a no robot, no index settings on certain aspects of the site there. It's also behind accounts and logins. So, somebody would have to be kind of maliciously doing that, which I imagine that's probably already been done. But it is... Yeah, that's a different kind of deal.
You know what I mean? Maybe the biggest case of this is the link tax that Australia, Spain, and Canada all tried to put onto the search engines and Facebook and social platforms. Right? Like, I'm getting this right. I think it's Canada. They all blur together. But, you know, Canada is the most recent one of these, for sure.
I think it's Australia. I think it was Facebook. I'm sorry, folks, if I'm like crossing over companies and stuff. But I think Facebook just declined to renew their agreements with the Australian newspapers and saying, you know what? We're not going to send any more traffic and we're not going to allow any links to you whatsoever.
And they're not going to be in a better place because of that either. So, it's really this, you know, damned if you do, damned if you don't type of thing is what I'm trying to get at. And, like, the biggest example that play now is with these news organizations and the social media and search engines.
Yeah. Yeah. Except for, I don't know, the AIs aren't, I don't think they're linking back to the original content. No, you got a good point there that at least search engines and stuff and social media, they credit you. They send traffic to you. Whereas, we're going to have to reckon with the AI stuff in some way because it just says, here's the answer.
And how did I get it? I don't know. Maybe that's your answer, repurposed. Yeah. But you get zero credit for that. Right. Anyway. That's a good point. We're probably going to solve that today. Maybe next week. Want to come back and solve it next week? Yeah, sure. Well, if you were to be automating requests to these websites, what is the most popular way to do that?
Well, it's right in the name, requests. And requests by Kenneth Reitz has been migrated over. It's, like, so popular. It's migrated over to the PSF itself, right? I don't remember where it said. Yeah. It actually still has it says. Request is one of the most downloaded Python packages today, pulling in around 30 million downloads a week.
And it's used by over a million repositories on GitHub. You can probably trust it. But there are things that it doesn't do. Things that it's not necessarily wanting to, like, lead the pleading edge on. I mean, just with that amount of usage, you've got to be careful, right? So I'm going to point you at a fork of requests.
So if you're downloading, you could create multiple connections to the server and download multiple streams. I think that's what that means. System certificate authorities, certificate revocation. So if you want to control what certificates you trust, maybe there's some that have been known to be doing bad things or you just don't want to allow access to certain parts of the internet.
You can revoke those certificates and their authorities and so on. DNS over HTTPS, TLS, and quick. So if you want to have better control over how DNS works, if you want to escape what DNS is happening on your server and explicitly control it from your application, you can do that securely, which is awesome.
It has async and await, DNS security, and does much pain removed, which is cool. So anyway, this is a pretty interesting thing. If you know requests, you basically know this, except for that it also has async versions, which is kind of cool. But yeah, it's got like a great long feature list and why they did this.
Yeah. I think it's, I think, my guess is that the name is based on the Knights of Knee. So it'd be KneeQuest, I think. KneeQuest. All right, let's go with it. KneeQuest. Yeah, because of course we have those themes, right? Yeah. Of course we do. Now, Brian, we do have a sponsor for this episode, right?
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 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 by them by set of him 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 by them by set of him slash Scout. Check them out. It really supports the show. Indeed. Indeed. Thank you, Brian. Yeah. Let's talk about underscore has some underscore has some funky meanings in Python. It's good. We love it. We love the underscore. Yeah. Like I'm going to get a new keyboard where I like on my keyboard here.
It has two independent buttons for the space key. I'm going to make this one just the underscore. Okay. Sure. You can do that. And you'll probably need it. What can I do with it? You could because of all of the Dunder methods. We have so many underscores that we call two underscores Dunders in Python.
So and what are all these Dunder methods for? So Trey Hunter has actually put together this really cool resource. Every Dunder method in Python. And actually, I mean, I thought I knew quite a few. And I use probably rep and stir probably the most to make sure that my objects are representable or convertible to strings.
And then repper that converts to rep. And it's also used with stir if you didn't have a stir method. But you can have those be separate. So the other one that's common is __init__() for how you initialize classes, which, you know, to be honest, I use probably attrs and data classes more than custom data classes.
Why do you care about that? You care about hashability because that means your objects can be used. If they're hashable, they can be used for. I think there's some other rules, too, but you can use them for keys to dictionaries. And there's tons of dictionaries in Python. So we've got- Maybe also sets.
You don't think about type conversions that much, right? Because you don't think about testing and all that stuff in Python as much. Right. But it is kind of cool. I didn't know that. I guess I knew you could do this, but I kind of forgot that you can. So if you say like int of something or bool of something, if that makes sense for your data type, you can write your own dunder method so that people can just use the built-in type conversion, which is pretty cool.
I think you can take your own format specifier there. I think that's what that's for. Okay. I'll have to research that a little bit more. Anyway, the dunder methods around context managers, which is actually kind of a funny thing. I think that I've read a lot of tutorials around context managers and sometimes they like try to tell you how to build one up from scratch.
I've never built one up from scratch. I always use like some of the wrappers and stuff to do context managers. Anyway, containers and collections. If you're going to do a container that you want length to work with or to iterate through, you need some dunder methods for that. Callability is one I've used frequently.
Oh, wait, I take it back. It is Python, 100%. But also, even if it weren't, it's the kind of thing that you would use as a Python person, not necessarily make it part of your app. So this takes a bit of, it takes a moment to get your head around. So lockbox is a forward proxy for making third-party API calls.
And you're like, okay, keep talking. Maybe it'll make sense eventually. So here's the deal. If you're going to integrate with some third-party thing, think Zapier, if that, if this, then that, et cetera, et cetera. And those things are making API calls on your behalf. You have to give them the API calls for the destination thing they're integrating with.
So the example they give is if you want to do a Zapier thing over to Slack or Jira or whatever, you give Zapier your Slack API key or your Jira API key. Which may be fine. I mean, Zapier is certainly a trustworthy company. I've had the CEO on Talk Python a few times. He's great. But just on principle, you might not want to do that.
You know what I mean? Yeah. So that's what this thing is for. So instead of giving that third-party, like Zapier, if this, then that, your tokens, what you can do is you can set up this lockbox thing. And it's like an intermediary for this whole process. So you can register an app in your lockbox and it gets its own just for this one purpose API key.
You give that to Zapier. So Zapier calls lockbox, lockbox calls Slack or lockbox calls Jira or whatever. And it has a couple of advantages. So you can do things like you can audit what actual traffic is being done. So you can see exactly what, let's just keep with Zapier, what Zapier is doing on your behalf, exactly what data is passed.
And if something's going wrong, you could see that. It's still playing. Zapier is charging you for too many zaps, you can say, I didn't use this many. Exactly. Here's how many zaps exactly you used. Yeah. Some of these are planned. So you should be able to restrict access to external APIs in a more fine-grained manner.
You know. Ooh, rate limiting. Yeah. Rate limiting on third-party API calls. But the primary purpose of it is that the API keys are not exposed to anyone else. They just live in this lockbox thing that you control. And then you can, of course, throw them away. Right. Drawbacks are, well, you got to run your lockbox.
My password's the letter A. I don't see any problem here. This is way more secure than that. Good thing we made all passwords password. Exactly. That way I never forget it. It just says, what's your password? And I'm like, well, you gave me the hint right there. Perfect. Well, that's our items, our main items.
What else you got there? I got a couple extra. Since I covered Django a little bit earlier, I ran across Adam Johnson's Django Join the Community on Mastodon. I'm also working with Django a lot lately. So trying to follow some of the Django people on Mastodon is good. So he's got a good resource for people that want to.
If you're a Django person, you want to get started on Mastodon, there's some good people to follow. Some projects, official accounts around Django. And reminders to do a welcome post, which I still have forgotten to do. So sorry, people out there that don't know who I am. Anyway, yeah, the introductory post is a good idea.
And to hit through it. So the other one extra got sent in just this morning from Kim Van Wyk. And it's a website called unmaintained.tech. And essentially, the idea is there's a badge and there's some description. So basically, if you have some open source stuff that you're just kind of done with and nobody wants to take it over, you can just link to this to tell people that you're not intending to maintain it.
People can still use it as a reference and read it, but no promises as to whether it's going to work because I'm done. So interesting. Yeah. Some things are done. They're just done. Yeah. Some things are done. And it's okay. So you don't have to take them down. Just tell people that you're not working on it anymore.
Okay. Yeah. I think that was pre-Microsoft takeover. Yeah. That might have. You know what? I think it probably was when they were like, how are we going to pay for this stuff? We need to start getting rid of some of the storage of things that just abandoned. And now they don't want to do that because there's all that AI meat in there to eat.
That's right. Well, speaking of takeovers, US sues Apple for illegal monopoly over smartphones, says The Verge. Now, I think the monopoly angle is a little bit of interesting here. I had some conversations on Mastodon. People were like, oh, they only have 20% of the market. In the US, they have over 60%, 68%, 60%, something like that.
But I think the real problem is there's nowhere else to go. Where do you go? There's literally one other option in the entire world. I know technically there's some Kickstarter that somebody could have a hundred other phones. But in practice, as an adult, you need a smartphone to live these days to function in society.
Like, well, you get this app to do this thing. Like, well, how do I get it on my phone? I have to hit to get C. I press number one three times. Like, oh, you can't do this part of the world. You're done. And I think Apple, I think it's, I don't know. It's a little bit, a little bit of a silly lawsuit in some senses that people don't really, the people writing the lawsuit seem to be not very connected technically or deeply understand the problems here.
I think there's some really legitimate causes and I'm here for this. I hope this makes a change because Apple is just such a bully. I have had such insanely bad experiences working with them, getting apps in the app store, which is crazy because you're like, I spent, me and Lauren spent months writing the latest Talk Python app.
To just try to make the iPhone a little bit better, to make people who want to do our stuff, enjoy doing it more on the iPhone. They're like, nope, we're rejecting that. And we have these rules. We need more money from you, even though you're already paying us a hundred dollars a month and making the platform better.
You know, for example, I'm sure people think I'm cranky about this, but I just want to give a little background for people who haven't heard me rant about this. Like we submitted it and they said, well, it doesn't have in-app purchases. I said, that's okay. I don't really want to sell anything through here.
It says, if you bought material on the web, like a book, audio, or video, you're allowed to consume that on the phone. And there's no in-app purchase required. Like we don't care. You don't count as that. You're something else. You're not as big as Amazon. So you can't. Yeah. You don't get any special treatment.
So what you're going to do is you're going to spend two weeks for two people full-time developing the in-app purchase so that you can sell a couple of courses a month, even though it costs you thousands and thousands of dollars to do it. Or you can't be part of this. The majority of your customers in the United States can't have your app, right?
Like it's incredibly frustrating how they're just doing this. Well, does this even talk about that? Because when I read this, I was thinking, I was thinking, I mean, I've felt this. I love Apple. I've got two or three computers. I got the phone watch. But I've thought, hey, I want to try a different watch.
Oh, it doesn't work with anything else. I can't really. So I feel the customer lock-in part. I'm not really happy about that. But the other part that I, is that part. And I don't know if the lawsuit covers that. Is this whole 30% tax that they want to apply to everything? Yeah, I think it does cover the lack of ability of using other payment processors and stuff.
Other payment processing, other delivery methods, all that kind of stuff. Like another really creepy thing that Apple is doing is they're going to allow only the big companies to install apps over the web directly and use their own payment processor directly. But only in Europe and only for companies that have had over a million downloads previously.
So there's no way to get started ever. If you created a popular app now, you have to have done it last year. But if you don't have it yet, how do you? But then they're charging 27% for their fee for delivering your app. But if they're not doing the processing and it doesn't go over their servers, what is the 27% for again?
This is the one I just talked about with some of those weird fees and other stuff, right? Company could be fined 10% of global revenue, 20% if they don't fix it after that. And so it's just one thing after another coming down on this company that's just, you know, they make 85% of their money off in-app purchases from games.
It's just, it's too high. Yeah. You know, and honestly, I don't even mind the 30%. What I mind is that they say that these kinds of apps can't exist or your app has to be completely rewritten so that you do start selling even if you don't want to or we won't accept it. Right. It's if I wanted to sell it, I'd be like, all right, look, 30%.
I promise. The PSF is looking to hire somebody, which is awesome for PyPI support specialist. How cool is that? That is cool. Yeah. I read about that. It's kind of nuts that all the PyPI with, you know, you think of the infrastructure, the amount of bandwidth flowing through that thing and how much traffic there is in that website and that there's nobody whose job is to keep it running.
We're going to do a VS Code Ask Me Anything with Brian Clark, not Brian Okken, Brian Clark and Cecil Phillip and me in 21 days. So if you want to be part of that YouTube only event, then the link is in the show notes. Check that out. You can submit questions ahead of time. So if you've got one, please, please do that.
And lastly, a quick conference thing. Gareth Thomas said, hey, just let you all know, PyData Eindhoven 2024 will take place on the 11th of July and there's a call for proposals open. So if you're interested in that, check it out. Okay, I've got one extra, extra thing. An extra, you have an extra, extra, extra, extra.
And partly it's an apology. So I've been doing the emails for the show, but I kind of forgot last week. So I'll get the, this week you'll get two or we'll combine them into one or something like that. But how do you get the email? So if you go to Python Bytes and click on Friends, you can fill out your name there and get the show notes into your inbox if you want.
So, yeah. Yeah, exactly. Only if something goes wrong, do I bother looking at it? All right. Well, that's, let's, let's wrap this up with a joke. Okay. So, you know, the Windows, some of these different operating systems and ecosystems have more certifications than others. Like there's the network certifications for network engineers and Windows has got a lot, right?
There's like a super excited guy with a toolbox ready to take on the Windows blue screen of death and hack the registry. Can you be a Windows certified engineer? It's the latest, it's the hottest game of Dave and Busters this year. Okay. But look, look at the controls. You got to be a Windows engineer with a trackpad and three buttons.
Yeah. But look at the labels and the buttons. I didn't, there's four buttons. You missed an important one. There's a big giant rollerball, like trackpad. What is that? Trackball. Trackball. Then there's three buttons, control, alt, and delete. But down at the bottom, there's another one that says reboot.
