- Podcasts
- Python Bytes
- #244 vendorizing your Python podcast
About this episodeTopics covered in this episode: pip Environmental Variables Extra, Extra, 6x Extra, hear all about it Building and testing Python with…
- pip Environmental Variables
- Extra, Extra, 6x Extra, hear all about it
- Building and testing Python with GitHub Actions
- python-vendorize
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#244 vendorizing your Python podcast
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 244, recorded July 30th, 2021. I'm Michael Kennedy. And I'm Brian Okken. And I'm Brandon Brainer. Hey, Brandon. Welcome to the podcast. Thanks for being here. Thank you for having me.
Yeah, absolutely. So before we jump into the topics, just tell us a quick bit about yourself. Yeah. So I've been in software development for 10 years. Half of it in management, half of it as an individual contributor. About seven years of it with Python. You know, it's funny, when I first started programming, I lived in a Raspberry Pi.
I thought Python is so confusing with not having brackets and all these spaces. And so I don't understand it. And now I can't go back. It's so much easier. Yeah. Yeah. I had a similar experience coming from C# and C++ and stuff with all the symbols. And I thought, in my mind, I thought those are necessary for programming.
Like you have to have the semicolons. You have to have the curly braces and the extra parentheses. Because how else will the parser and everything? Like that's how you express stuff in programming. And then when I got into Python, I felt a little bit weird with it missing. But then when I went back, I felt even weirder.
Yeah. So I don't know. We're doing this on Friday because I wasn't here on Wednesday. I was in Florida. And so I had a jet setter. Basically, you just. Yeah. No, the first time I've traveled in like two years for a business. Was it weird? Yeah. Was it weird? No, it's like wearing a mask all the way there.
I kind of got used to no masks here in Oregon. But then now I guess they're changing all that again. We're bringing them back. But, you know, what's old is new again. But one of the things I tried to do is I tried to work on the plane and in Python, of course. So the problem with snakes on a plane is there's no Internet.
So I had this issue. I had and I've already I've already put it up on the screen, the solution. But the so my issue was I had a bunch of I had a project I wanted to work on. It's got talks set up. And when you run talks, talks creates for a fire in virtual environments and then fills those up with all your dependencies in your code using pip.
Pip goes out to PyPI to get that stuff. I mean, you can cache it and that does help. And you do that locally on your machine, but it still looks out at the Internet. And this won't work on a plane. So I reached out to the Twitterverse and and I thought I found a solution, but I'm not even going to say the wrong solution.
Paul Gansel pointed me in the direction of environmental variables and pip. You can just set find links to a local directory and then set with pip find links and then pip no index so that the pip doesn't even look out there. It looks at a local directory. So so what I did is I'm going to and I'm going to just look at I was going to go back.
I got a quick question before we go on. OK, so it'll look in that local directory for the packages, the wheels and whatnot. Yeah. How do you get them there in the first place? OK, so I got some pre work that I did. So I'm like, OK, how do I get those? And normally when I when I want to put something in a local directory or something, I'll just use a pip download.
You can do that. But that's a lot of work to try to figure out what you did. So what I did is I just before I got on the plane, I'm using the airport Internet. I which everybody can harass me later about how that's not secure. It's fine. But I ran talks. You do it at home then if you want run talks with an Internet connection.
So they can be set in the virtual environment that you were using to run talks, even though talks will generate others. It just it works right. I don't know how it works, but it works. Anyway, this super helped me out. And then when I went to. Yeah. So then grab all those, throw them in there and then use the find links and no index and it'll it'll just work great.
The the thing that the reason why I think I didn't find it at first is that the note within the pip documentation just says everything that's a flag within pip is also an environmental variable. It just so if you searched for it, you probably won't find it. It just has this comment that says all command line options can be set as environmental variables using all upper scores under uppercase and then underscores instead of dashes.
So when you do your talks runs that it needs to reinstall them. Yeah. It creates a new virtual environment. You can tell it you can run it ahead of time and you can tell it to not install those. But I was messing with my talks, my environments. So I really wanted to make sure I could clean them out.
Nice, nice tip. Especially the environment variables just for pip. Like you can change the verbosity or the mirrors or all sorts of stuff, right? Yeah. All right. So this time I have an extra, extra, how many extras? Let's see. I have eight extras. Extra, extra, six times extra. I hear all about it.
So I'll be kind of quick, but they're all kind of interesting. Okay. I just want to give a quick shout out to VBrownBag. I did a talk over there on Pydantic. So a 45 minute presentation on Pydantic and how you can do all sorts of cool stuff with that. We've already talked about why Pydantic is excellent.
So very, very neat. Check that out. And I also want to give a shout out to an episode that I did that I think is on Talk Python that I think is going to be really useful for people. It's about building little automation tools. Instead of trying to build big apps, maybe a little app with rumps that runs up in your menu or a little app that you can do a bunch of stuff and it'll generate a query for some other platform that's not like SQL, but think SQL-like type of things and so on.
So I had a bunch of cool guests. I had Rusty Gregory, Kim Van Wijk, KJ Miller, and actually Rivers Cuomo from Weezer on the show. He's doing amazing stuff. So people should check that out if that sounds interesting and inspiring. That sounds so cool. I can't wait to watch this. Yeah, this is going to be one of my favorite Talk Byland episodes in the near term, I'm pretty sure.
Okay, enough of my stuff. On to the six other things that we haven't done. Remember we had Shari Eskenes on the show a while back? Yeah. That was really fun. She talked about a bunch of great things, but she also did a day in the code, I thought, like storybook for kids. So her storybook for kids, which I know you and I both got a copy, right, Brian?
Yeah, it's actually pretty cool. Yeah, I like it. Yeah, it's cool. So think like a big, large picture book that tells a story, but about programming for kids rather than, I don't know, like a day in the park or whatever. So that book's actually out. I just want to, that'll be a link in the show notes.
If you've heard that episode and you want to check it out, you could actually get the book now. We talked about GitHub Copilot and some other things like that. I want to give a shout out to another tool that's kind of like this, but way more tamed down. And it plugs into all sorts of different IDEs called Tab9.
You want Emacs. You want RubyMind. You want Vim. Straight Vim. Yeah. Straight Vim. Yeah. And so this is a tool that you plug into your editor. Well, a Python, that's offensive to have JavaScript. Excuse me. So you can come down here and it will help basically look at your code, look at the keyword arguments.
And instead of just giving you autocomplete for the symbols, like functions and fields and stuff, it tries to kind of bring it together. It's not GitHub Copilot in the sense that it's trying to pull other people's code and inject a bar. It's not like stack overflow, copy and paste with a tab type of thing.
But yeah, I like this because as much as I like VS Code, I'm a huge JetBrains fan and the fact that you can't use it in PyCharm or anything else like that is very disappointing. So yeah, I agree with that. Yeah. Well, I think I want to get like five AI coding systems together and they can just mob program by themselves.
Yeah. Here you go. It says your code is yours and yours alone. It runs locally without sending any source code anywhere. You can even work on a plane, right? Anyway, I ran across this. I was talking to the folks from there and I thought this is pretty cool. I'll give a quick shout out to that because the AI coding assistants are all the rage right now.
Is this a paid thing or a free thing? Yeah. It costs money, but there is a free version. So you get like what they call basic. Bad suggestions for free. Yeah, exactly. Like every 10th is a bug, but the other nine are really good. No, I'm just joking about that. I don't know. But yeah, there's a free one and then you can pay for more.
Yeah. To be fair, it doesn't look expensive. So no, no, it's reasonably priced. Yeah. Yeah. It's 12 bucks a month for the paid version. I always feel like when people are like, oh, well, I'm not going to pay, you know, $10 for this thing. It's like, this is your job all day. How much can you actually make from this job?
Like if this could, you know, save you an hour, surely. Anyway, that's a different discussion. Speaking of discussions, following up on one of our episodes with Simon Willison, who talked about Apple Photos and SQLite and using dog sheep and data set to analyze it. Rhett Turnbull pointed out a project that he created that will, says macOS photo pack.
Oh, the OS X photos, Python package exposes all of your data to your Python apps. And the next release will provide the OCR stuff out of Apple's vision framework. So people have been tracking that there's some really exciting stuff coming to the Apple photo, you know, iOS, et cetera, where if you take a picture of something, then it automatically do OCR and you can actually select and copy the text out of say a sign in a picture and paste that somewhere.
The last, three things really quickly. I released three, packages to PyPI last week. two more related there around taking HTML and templates, either Jinja or chameleon, one package for each language and trying to reuse them in like really clean, simple ways. So if you've got like some fragments, say like the example have on the site is a video app and it's got like a thumbnail of a YouTube video, then the title of the author, and then the number of views.
And if you want to show that all over the place, you could either copy that code and replicate it. Or with this inside your template, you just say render template or render partial. And you point at some HTML fragment bit and it'll apply your model to that sub thing and allows you to basically create functions that return HTML inside of your templates.
That's neat. Yeah. So it's super, super simple. So like for the videos, you have like literally this little render partial, you know, quote, shared video square. And you pass the video over a really, really nice. So there's a Jinja partials for flask people and there's a chameleon partials that does exactly the same thing for pyramid.
And then last thing, adding the chameleon template language to FastAPI so you can build proper web apps. I published that. It's been around for a little while, but I finally published it to PyPI. So you just put a little decorator onto a FastAPI function and it becomes a HTML endpoint rather than a API endpoint.
Have you just, have you been using chameleon longer? Is that why you're more comfortable with it? I know. I probably have been doing more chameleon than Jinja, but I do a lot. But the thing that I really, really like about chameleon, let's see if I can find an example. It'll probably be good enough.
But what I really like about chameleon is that it is valid HTML as it is. Whereas with Jinja and the Django framework and a bunch of other frameworks, Mako and you know, you go into other areas like Razor and ASP.net, all of these are nice, but they all have HTML, HTML blocks of code, blocks of code, HTML block of code, HTML, right?
This is all driven through attributes, like view. So like here, if I want something that's a loop, I can just say talcol and repeat as an attribute. Or if I want, yeah, things like that, right? Or you do condition, you say talcol and conditional and you put it in there. So this is actually 100% still valid HTML with just attributes that don't make sense.
So to me, it just feels cleaner. That's why I like it better. Yeah. Okay. Yeah. I kind of tore through all those without giving you a lot of chance to talk about them. But anyway, that's my extra A time. Yeah. I like it. Thanks. Cool. All right, Brandon, you're up next. Yeah. So this is something I came across on Twitter and I signed up to do it.
So it's Kegel's 30 Days of Machine Learning. Basically what it is, I guess if you don't know what Kegel is, it's a place for data scientists to find and publish data sets. They have online Jupyter notebooks that allow you access to free GPUs and things like that to run your machine learning models on.
You get some certificates. So if you want to post those like you know, with your resume or something like that, you can say, hey, I did some learning with Kegel. And the cool... I haven't done any of this, but I suspect that if you ranked pretty highly on Kegel and then you put that on your LinkedIn profile or you're trying to get a job that, I mean, that speaks pretty well.
Yeah. Yeah. I would think so. And I think the cool thing is like at the end of it, there's a competition that they have with a... It's like teams up to three. And it's like only people that ran through the course. So you're not competing against people who have been doing machine learning for years and kind of give you a little bit of that taste into what machine learning competitions are like.
So I think it'll be interesting. It'll be fun. Are you going to do it? Yeah. Yeah. Nice. What I think is valuable here is the constraints, right? You know, you have... Here's your data that you're going to be working from. Here's the type of problem you're solving. And so often when you're a beginner, whether it's machine learning or web development or whatever, it's really hard to know what is the right sized problem to attack.
Yeah. It's so easy to go, well, that's too small. That's not interesting. Or wait, all of a sudden I tried to build Instagram and I got stuck or whatever, you know? Yeah. And I think it's nice, you know, if they give you the data, like, yeah, I think a lot of times the biggest part of machine learning and data science is cleaning the data and making sure you have the right data and the right attributes to look at.
It's an interesting resource for learning how to do this. Yeah, absolutely. Cool. That's a great pick. Brian, you're next, right? All right. Yeah. So been testing a lot. More testing. So one of the things, I had a project that was set up to use talks, but I also early on when GitHub Actions came about, I put it up on GitHub Actions too.
But I was trying to understand the workflow a little more. At first, there were a lot of resources. And then I came across this recently, just this weekend, this week, last week, building and testing Python. It's part of the GitHub Actions guides. And it's actually pretty great. And it goes through a whole bunch of stuff.
One of the reasons why I like it is because you can, it's kind of like a CI system, but locally, you can sort of run through making sure your installs work, your builds work, and all your extra tools that you've got hooked up. One of the problems is you just got your Python, whatever, version 3.9, 3.8, whatever installed, and you run your test, it runs on that.
But you want to kind of exhaustively go, I want to test on all the versions that I, in theory, support every time. Yeah. Or you might have an error in your PyProject.toml file or your setup.py, and you're not seeing that because you're not completely, you're not rebuilding it. But talks will do that.
But so will CI systems, but it's kind of nice to have it set up both. But if you, and the directions here are how to, it starts with directions on how to run, you know, pytest and to install dependencies and build and lint and run pytest on your project. But if you already have talks set up, this is sort of a duplicate effort.
But if you, I think you want to jump down to the talk section of this document because it shows you just how to run talks directly. And it's a, it's a smaller setup. And essentially what GetUp Actions is doing is setting up a Python or a Python environment and then installing talks and running your talks environments.
And so you're, you're, you're having that same code from your talks any file running within GetUp Actions. And it's really nice. I like it because it's going to try to do the same thing locally as it will in CI. Yeah. The one change I want to mention to flag out, and I've got, we'll have this in the show notes, as I've modified this example because hopefully I didn't, it didn't make sense to me at first.
But dev is, I think, close enough. And you don't have to muck with it all the time. Is that like the latest build 3.10 or something? I think so. I think it's just the latest 3.10 build. And then at the bottom, there's like this thing that talks E dash pi. And that dash E usually means run the environment, run a specific one.
Very nice. Very nice. Out in the live stream, we have Felix. Hey, Felix. Says, I love talks to you using it for my strong typing package. And it's awesome. And welcome, Felix. Yeah, we covered your strong typing package a few weeks ago. That's really good. Yeah. Oh, and then Oli says the machine language course sounds good.
Then when somebody runs your code, they don't have to pip install anything. No virtual environments, nothing. Right. And so with this Python-Vendorize, that's what you can do for pure Python packages. So the idea is if you've got some code that has, you know, lightweight dependencies, you know, I don't know if I'd do this with something like Flask that depends on Vixoig, that depends on who knows what, right click and so on.
Like you don't, I wouldn't necessarily go too deep, but for things that are smallish, what you can do is you can set up a vendorize.toml file. And then in here, just list the packages and you give it a location. You say, I wanted to go for my project into underscore vendor in this example, but that could be whatever.
I would, I don't know for sure. And I looked, I didn't see anything in the documentation one way or the other. It is honestly a little sparse on documentation. This is an interesting idea. And actually, and it often, like this does happen whether people like it or not. And it's a completely legitimate according to a lot of the, I mean, the licensing, right?
Yeah. And for, but for commercial projects, this is very common that I don't want to go out and pull things from pip all the time. I want to just have things local so that they're, they're just built locally. Right. And it might not be for, just to avoid the pip install. It might be that you want extreme control over what's shipped and you don't want something that might happen to that package coming down through pip and breaking your code.
Even if you pin it, you know, you might want to just have more control over it. Right. Or a decision that somebody takes the project in a completely different direction that you don't want. It's like, it's like, this is a very hard fork sometimes. Yeah. I suspect rerunning Python dash vendorize will redownload it, but I don't know for sure.
Brandon, go ahead. Can you pin versions in this? Well, it looks like the packages in the, vendorize.toml. It doesn't say that you can do versions, but I would be guessing, I was guessing here. I'm thinking that you can probably pin them, but. Yeah. I'm just guessing that it passes whatever that string is over to pip and.
Yeah. Yeah. So yeah, that's what I was thinking as well. So probably you can. We'll have to try it out. Somebody can tell us if we're wrong. Felix is right there with you, Brandon, asking, do you know when you specify a version? I don't know. Like I said, it doesn't say in the docs about it, but yeah, it's, it's a small project, but I think it's an interesting idea.
Right. But here's a more repeatable type of way. Yeah. Cool. All right. Brandon, take us out. What's your last one? Yeah. So there's a newer project out there called Supabase. I feel really weird saying the name Supabase. You got to get, you got to say it with an attitude. It sounds like a car audio product.
I'm going to go put a Supabase in my car, but basically what it is. Sorry. When you're doing a clear, it's like. But yeah, so it's, they tout themselves as an open. Open source Firebase alternative. So if you've ever like done a lot of JavaScript or been friends with JavaScript developers, a lot of people use Firebase because it provides authentication.
And then they've got different open source projects that are wrapping it. So they have the authentication part of which they have to have a wrap around the GoTrue library from Netlify for handling authentication. So if you want to have authentication for your app, you know, you can easily do first name or email password.
Just email that sends like an authentication link to the email. They have an extensive list of OAuth 2 providers. So if you want to add off to it, they handle all that for you. Yeah. So the main idea of this database is kind of like I want to have a front end JavaScript framework maybe hosted on the back end by Python.
But then I just wanted to have like a database access over an API, just like the entire CRUD story. Right. Yeah. And all of a sudden you run into all these challenges of offline, of authentication and stuff. And that's what this is mostly focused on, right? Yeah. So they have a package they call it where it gets, if you can use it, called Postgres.
Oh, I can't say it. It's a wrap around Postgres that basically gives you an API to your Postgres database that you don't have to write. And they implement that in a way that, you know, you can just, like you said, make those HTTP calls to write, read, to basically do your CRUD operations to your database.
And what's nice is whenever you update your database, they automatically generate the API documentation for you. So you're not writing any controllers, any services or anything to do that. It's just provided by them. And like you said, it looks like definitely a JavaScript thing, but they're actually just released a Python library for it they shove up right now.
Supabase.py. Py. Yeah. So your snake has base. Anyways, so it's currently, I believe, in alpha. So I wouldn't suggest using it in like, you know, enterprise application, but it's definitely something to try, you know, play around with. If you want a simple way to do authentication, access to a Postgres database.
And what's nice is, you know, if they give you the Postgres database, but you don't actually have to access it through their terminal where their UI, you can connect to it through, you know, whatever you use for your database. And yeah, going along with the no internet development, they also have a Supabase local that you can run locally.
That's, that's pretty unique, especially over a remote API. So, you know, if, if you've got some front end and you want everyone to see those changes, possibly, guess you could even do this in like a Qt or a wxPython app or even a terminal app. But you might even want to just say, I've got a FastAPI app and I'm going to fire up a WebSocket there.
Actually, do you know what the story is? So when I'm looking at over here, they talk about, okay, so here's how you specify your API endpoint at app.supabase.io. Is there, and it's in this open source thing, but there's probably some database as a service or something equivalent that I maybe sign up for or I pay for.
Do you know what the story is around that? I don't know. I mean, surely they are not running the database for the world for free. They got to charge at least bandwidth. Yeah, so that's the interesting thing. So there's a, their pricing model is a little confusing. I know that I feel like they've gotten some funding and I don't know how they, they're going to plan to make money with it because the pricing that they have is like $25 a project a month.
And that gives you unlimited API calls, real-time functionality, eight gigabytes of database space. I mean, I don't know who they're using for their database provider. I can't imagine they have a data center somewhere where they're running it, but. Yeah, it's probably on top of some cloud somewhere.
Yeah. They do have a zero over, of a zero dollars per month version. Yeah. Yeah. That's cool. So I see a project I'm going, so. Yeah, very nice. That's an excellent one. All right. Well, I think that's it for our six items. Brian, you got to think, actually, you want to throw an extra, you want to throw out there for everyone?
Yeah. I mean, we had Simon Willison on recently and he just released a post about the baked data architecture pattern. And that's, if you know what he's up to, this isn't surprising, but it's a nice write-up. Baked data is bundling a read-only copy of your data alongside the code for your application as part of the same deployment.
Interesting. Okay. Yeah. And then also on the live stream, Tim Pogue is doing real-time research for us. Thank you. It looks like you were able to do a pin similar to, as you would with pip, with the Python vendorize. So, yeah. Awesome. Thanks. Appreciate that. Brandon, anything else you want to throw out for people while we're here?
No, not really. I guess maybe do a little bit of self-promotion if I could. I'm currently working on a side project called Released. It's at released.sh. Basically, what it is, it's working on a tool to automate release notes for companies. I've noticed a lot of places, when they have releases, they need to go out and curate all these release notes and have somebody manually do this work that takes hours upon hours every release.
It was fun. Yes, thanks for having me. Yeah, it was great to have you here, Brandon and Brian. Good to chat with you all. Thank you, everyone. Bye. Right. Thanks for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S. Get the full show notes over at pythonbytes.fm.
