- Podcasts
- Python Bytes
- #254 Do Excel things, get notebook Python code with Mito
#254 Do Excel things, get notebook Python code with Mito
Python Bytes
- October 13, 2021
- 31 min
- Episode 254
About this episodeTopics covered in this episode: yaml, GH Actions, and Python 3.10 Beating C and Java, Python Becomes the #1 Most Popular Programming…
- yaml, GH Actions, and Python 3.10
- Beating C and Java, Python Becomes the #1 Most Popular Programming Language, Says TIOBE
- Newspaper3k: Article scraping & curation
- PEP 660, pip 21.3, flit 3.4 -> easy editable installs
- Mito - a JupterLab Extension - generates Python code while you work on your analysis
- troposphere
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#254 Do Excel things, get notebook Python code with Mito
Hey there, thanks for listening. Before we jump into this episode, I just want to remind you that this episode is brought to you by us over at Talk Python Training and Brian through his pytest book. So if you want to get hands-on and learn something with Python, be sure to consider our courses over at Talk Python Training. Visit them via pythonbytes.fm/courses. And if you're looking to do testing and get better with pytest, check out Brian's book at pythonbytes.fm slash pytest. Enjoy the episode. Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 254, recorded on October 13th, 2021. I'm Michael Kennedy. And I'm Brian Okken. I'm Mohamed Raza. Yeah. Hey, Mohamed. Welcome. It's great to have you here. Good to have you on the show. Hi, Michael and Brian. I'm really excited to be on the show.
It's been one of my goals. I started listening to podcasts when I was in college back as an undergrad. Wow. And your podcast, that was one of the reasons I developed a love for Python. So that's super amazing. Tell people a bit about yourself before we jump into this. I currently work at AWS, Amazon Web Services, as a professional service consultant. So my job is to help our customers in their cloud journey. So we basically do help them with our...
We help them with different cloud services, such as if they want to do cloud migration or if they want like put some service on AWS cloud. So that's where professional services comes in to like implement and help them with their cloud journey. You must see a lot of different implementations and configurations and teams and types of software. You get exposed to a lot of things quickly like this, right? Yep. So it's pretty, it's pretty fun job. Like you work with different, wide, different customers. Like any customer has a different problem. So like you get to touch upon like different problems. So as a consultant, so it's a really amazing job.
Yeah, that's awesome. That's one of the things I think, you know, for people who are early in their career to help them go fast and level up is get a lot of exposure to a lot of different things. Yep. And I totally agree with you. Awesome. Well, I think maybe Brian should kick us off with the first item. What do you think, Brian?
So Python 310, we talked about this last week. Python 310 is out. It came out October 4th, it looks like. And I've been using it and a lot of people have been using it. But one of the things we do is we update our, with a project. If you support a package, you want to make sure to go and change your, your testing, your CI testing to make sure that you're using Python 310 instead of Python 3 dev, 310 dev. That's what I was testing before. So as, but there's an issue. So Python or Anthony Shaw brought it up on Twitter, a bunch of other people did too.
But I'm grabbing his, his tweet. It says basically, you can use 310 on GitHub actions now, but you need to make sure that you quote the 310. So this is... So you don't test on 3.1? Yeah, exactly. That's insane. The zero at the end matters. So I'm going to just grab my, one of my projects. I went and changed mine. And, and I just went ahead and put quotes on all of the versions on three, you don't have to do 3.7, 3.8, 3.9. Those are fine by themselves. But 3.10, if you, if you go from, if I had dash dot dev or dash dev, YAML convert, like thinks of it as a string. But as soon as I go to 3.10, it's 3.1. So yeah, you want to make sure to quote those. That's really it. And that's really what I wanted to cover is to make sure that people change their CI system to be testing with 3.10, but do it with quotes. If you're using YAML.
Doesn't YAML understand significant digits? Come on. It's an interesting find though. Like, like YAML reading a 3.1, but it should read as 3.10. Yeah. I mean, I could see how you get there. Yeah. But at the same time, if you're talking versions and not just floating points, obviously the dots are not, you know, not, not decimal separators. They're separating full whole numbers, right?
Which obviously then the zero matters. Interesting. That's a good find and good advice. I have a quick real-time follow-up for you, Brian. Remember I had complained about not being able to deploy to 3.10 in production. Yeah. Well, guess what? This is all 3.10. Woo. Oh, sweet. Yeah. I managed to get it working. MicroWSGI got updated so that it will now work on 3.10 install, building a wheel locally on Linux. And there was another dependency I couldn't make work, but then I realized, oh my gosh, I'm not even using this anymore. So I just took it out and then it works. So I put it on Talk Python, the podcast page for now. And if it doesn't freak out or cause problems, I'll roll out across like Talk Python training and Python bytes and stuff. So this is the guinea pig or the canary out there just hanging around. But so far it's perfect.
Nice. Yeah. A couple of live stream thoughts here. Sam Morley. Hey, Sam. Says, oh my, that is interesting about 3.10. And Henry Schreiner. Hey, Henry. Henry and I are going to be talking on Talk Python really soon, by the way. Many YAML projects choose to accept floats and then just convert them to strings. Not specific to YAML. You could disallow floats here if you wrote that, if you wrote the action. Okay. Interesting. I didn't realize you could do that. Very cool.
Beating C and Java, Python becomes the number one most popular programming language. Boom. Says Tobe. So, the Tobe index is interesting. To me, it feels like a little bit more of a lagging indicator. And it's also a bit more of a enterprise-focused indicator. So, that's why Java and C have been popular for so long. But apparently, Python has sort of made its way into that world as well.
And they're quoting this article over here on ZDNet. And this is the thing I'm linking to. And it says, For the first time in more than 20 years, we have a new leader of the pack. The longstanding hegemi of Java and C is over. It's pretty good, right? It is. And I think it's one of the reasons that, like you said, the business community is using it a lot more in large companies.
That might also be why we're seeing the numbers in surveys of Windows users using Python. Oh, yeah. Staying really high. Maybe it's because of that. I think one of the big reasons is, like, the entry to the language, the barrier entry is, like, pretty easy. Like, anybody could learn the language and get into the language.
So very, very cool. So, yeah, super neat. I'm thinking this is just another sign that, you know, focusing on Python is good. Muhammad, I think you touched on a lot of reasons why, you know, people get attracted to it because it's easy and it's simple and it's clean and they just want to do a small thing.
But then your small thing, as everyone knows, just gets slightly more complicated and more complicated. And a lot of times the thing you start with as something simple, it can't do, it can't grow to become the thing it eventually needs to become. But Python allows you to build way more complex software.
So you don't get injected into like, well, I have to leave because, you know, I want to use threads and I'm using VB6 and it doesn't have threads. So I guess I'll go learn C or like, there's not that kind of story that happens around Python nearly as often. So people just stick in it, like accumulates like a snowball going downhill.
And the best thing is like it also does the summary of the article. Like it's not to like 100%, right? But it's just like extractive summary of the article, which is pretty useful. Like if you like doing newspaper creation articles and stuff like that for like auditors I was doing this week, they found it really useful.
Yeah. I'm totally going to use this. Yeah. I'm still one of those RSS readers. So, yeah. Yeah. Yeah. Super cool. So the API is basically you give it a URL and you say download and then parse and then you have article.authors, article.publishdate, article.text, top image, movies. If it contains any embedded video, you can even do keyword analysis on it.
Keywords in summary. Yeah. Nice. But you can do all sorts of things that might be useful to you. So I can see that this is a cool input into other things, right? Like not just straight consuming the information, but if you're trying to understand trends and stuff, right? You could go around and just hit all the main websites and go and say, okay, show us the keywords and show us anything that's new or that is new and also appearing more frequently.
If I remember correctly with this, there's also things you can do where you can follow, you can point it at a homepage and it'll give you like categories and all the articles in the categories. Like you could point it at CNN.com or something like that. Yeah. Yeah. Yeah. You can do all sorts of things with this.
All right. Well, I'm going to cover something I'm like super excited about, but it's a little niche. Anyway, so editable install. So when you're working with a package, Python package and developing it, one of the things that I do a lot is I have it open in my editor, but I also have like a window open where I'm running pytest and stuff.
So I need to, I want the package to be installed and it really helps if you're editable. It's editable so that when I make changes in the code, it's instantly appears in my, you know, my test window or whatever. And so pip supports this. It's a, you say pip install dash E and then give it a path to your local project.
I mean, installing from a Git does clone it first, but I don't know what the point would be because you're still, you're not editing it on Git. Anyway, I used it for local directory. It's a cool feature. It's a cool feature. It's a cool feature. But it didn't. And I also like Flit, but Flit, but Flit uses PyProject.automal and pip installable dash E install dash.
She didn't work with, with PyProject Intel last, this week, last week, really recently. So a workaround for Flit was you would have to install a PTH file or with a dash and you have to do, you have to install Flit first then. And this is a, if somebody's helping you, but they're not, they're not used to Flit, this is a weird thing to tell them about.
However, now we have it. So, just recently, oh, let's jump back. Pip 21.3 came out. When was it? October 11th. Yeah, very recently. Flit 3.4 came out October 10th. And with these two things in place, you can now, you have to, you have to regenerate your project file or change it to use 3.4 for Flit.
But, but editable installs work. and so I was playing with it. I'm like, this is so cool. I love doing this. but I was like, how do I get my, dependencies in there? So one of the things that, Flit allows and PyProject.automal allows is optional dependencies. So the normal dependencies, your project dependencies automatically get installed when you do a, install dashi.
But the optional ones don't. So you have to give it a bracket. you know, you have to say like install the, my thing with the optional like test or doc or something. Well, the way you do that with, with a local directories, you have to just make sure you put it in quotes. So quote dot bracket test, close bracket, close quote.
It's, it's really hard to work with BS4. BS4 is great for what it's for, but it's like assembly language is great. It doesn't mean I should write in it all the time. Right? No, I agree. And plus, I don't think BS4 does like scraping of dynamic pages for that. You like have to use, I forgot the package name.
Selenium for that. Yeah. Yeah, you do. Okay. So the next one I want to talk about here is, is pretty cool. And it's, it's an unusual project because if you're going to go work on some Python data science, you usually want to go do that in notebooks, but you might just want to think about it as kind of like an Excel spreadsheet.
Right? So what we've got here, this one comes to us from, let me make sure to give attribution from Tomas Rolo. Thank you for sending that in. So it's this thing called Mido and Mido is a spreadsheet that helps you complete your Python analysis. What you do is you create the Mido sheet, which is like an embedded Excel thing, like thing or Google sheets thing into your notebook.
You play around with that. And then the cell below, it writes the code. So let me see if I can show you an example here. So there's this spreadsheet up at the top. And as you interact with it, you can see there's this cell down here that says import Pandas is PD, Netflix titles equals PD dot read CSV.
And it gives it a file because you clicked a button and said open CSV for your data source in that spreadsheet. And then they said, I want to, what do they say? They remove some of the columns like rating and type and so on. And then create a pivot table off of that. And it just writes all the Python code for you below.
Yeah, I think right in the notebook. I kind of really like this library. Like it's going to make a lot of stuff easy for like people who are just doing data analysis because like what they do most of the time is like they're browsing Stack Overflow to like write the find and find the right answer to like solve their problem.
So like this is going to save them a lot of time. I totally agree. And if you go and play with it, you'll see a section that says Mido code start. Do not edit. Mido code end. Do not edit. A totally reasonable use case for this, which might not be what Mido themselves recommend because they want to promote their tool and sort of be part of the story.
But a reasonable thing to do would be to like embed this, play around with it to get just the right thing and then strip out the Mido bits and just leave the fragments that it wrote in there. Yeah, that would be amazing though. Yeah. Yeah. I mean, you don't have to tell anybody. He's just read you to do it.
Yeah. Yeah. Yeah. No, that would be amazing. Yeah. And it even does really cool comments on the section. So it puts it all into one cell, right? Instead of a whole bunch of cells, which I think is reasonable. But it does like the comments that it writes are imported Netflix title CSV, pivoted Netflix title CSV into data frame two, flattened the column headers, reset the column name and indexes.
No, no doubt. I think Pandas is great, but I don't know it super well. And if I know, like I kind of want to do this thing, but I don't really know how I can select select to do that. Yeah. Okay. Yeah. That's, that's the thing about Pandas. Like Pandas is amazing, but there's like so much stuff in Pandas that you don't know top of your head.
Yeah. Super cool. The other thing worth pointing out is you don't have to start your notebook this way. You can actually hand it an existing data frame. So you could do your work down until you get some data frame generated from who knows where and then hand that off to Mito and then have it write the, you know, the next fragment of code that you're going to write.
It'll give you a really good sense of what's happening there. The other thing worth pointing out is when you see plans at the top, that means it costs money, but there's a individual one that's just totally free forever. Works with JupyterLab 2 and 3. But if you want like team support, there's a paid thing.
Also, ZDocs says edible installs. We probably said editable. Yeah. Editable. When we say editable. Editable. Indeed. Indeed. All right. Let's see. So, Mohamed, you got yours. You're up next, right? Yep. So, I have this library called TroposWriter. It's an amazing library and helps you generate CloudFormation templates writing Python.
And then you'd be, like, hunting down where did I add extra space. So, this library solves a specific problem, like, helping you write templates using Python language. So, like, this is an amazing library. If you like writing a lot of CloudFormation template, I would definitely recommend using this.
I see. So, normally you use an AWS CloudFormation JSON. Yeah. Most people use JSON and some people, like, so, it's, like, it's up to you. Like, it's, you can either write in JSON or write in, like, YAML. But let's say you're writing in JSON and, like, say you mess up the format. Like, let's say you mess up a bracket or a comma somewhere.
Then you might be, like, if you don't have the right linter, then you might be, like, hunting down the files looking for, like, where did I miss the comma to fix this? So, like, when you, like, having large templates, it gets harder to, like, I would say, debug them. Yeah. Another thing that's nice is JSON is static, right?
But Python code executes. So, you could, like, loop over stuff and say, I'm going to need 10 of these. So, let's call it this one, you know, one, two, three, you know, machine one, machine two, machine three, or whatever, right? Yeah. I was going to actually point that out. But, like, thank you for pointing that out.
That's awesome. Yeah. It just makes stuff so much easier. Yeah. Yeah. You know, you hear all the time with cloud stuff, infrastructure as code or. Yeah. You know, that kind of stuff. And it's just, it's like another layer, right? Yeah. No, I agree. I agree. Yeah. Very cool. Brian, you guys do anything with cloud stuff in your world?
No. It's all hardware. Yeah. All behind the scenes. Well, I mean, we use them. We've got a lot of servers and stuff, and we've got a lot of services running, but they're all internal. We don't use a lot of cloud services. Some things are easing up a little bit that we're using because there's a lot of things that are just so much easier when you go into the open cloud.
But there's security issues. Yeah. Yeah. For sure. All right. Awesome. Well, another good one for people doing AWS stuff. There's also the AWS cloud SDK or something like that. Yeah. Cloud SDK. What's the relationship with these two things? It's pretty similar. But it also has support for TypeScript.
It also has support for Python and TypeScript. But it's more like a personal preference. So I prefer this library because it's pretty much supported in Python. From the start, it was built for Python. So that's why I like this library more than AWS cloud CDKs. But they both do the same job, basically.
The only missing part is whenever the cloud CDK generates a template for you, it also allows you to deploy directly using the CDKs. But what Troposphere does, it allows you to generate the template, but it doesn't allow you to deploy it directly on the cloud. So you basically have to take the template and put it onto CloudFormation to deploy the resources.
Hopefully, if I can. Yeah. I definitely have plans to. I can't wait to see everybody in person again. Yeah. It's so interesting to think about where we are with conferences and stuff. So, I was just at PyBay, which is really cool. And I'll pull up that on the screen here. Like, this is where the PyBay conference was held.
Like, literally in this outdoor food cart area where there's a bunch of cabanas. And each cabana had its own TV and its audio video feed. So, you could be in groups of like six or seven outside. But there was like hundreds of people there, right? Which is really cool. And I think that that's kind of a template for going forward for a lot of things happening these days.
Would you be awesome? Maybe like a theme park? Like, I'm going to watch this one from the roller coaster. Yeah. Awesome. Yeah. So, Jose out there says, looking forward to attending my first PyCon. Yeah. It's super fun. And Teddy, hey, Teddy says, whoop, whoop, whoop, whoop, whoop, whoop, whoop, whoop, whoop, for the PyCon announcement.
So, my extra is like how to learn Linux. So, I read this article a long time ago, but like it's an amazing article for especially people who are like getting to Linux world and like learning command lines. So, like it talks about how you can use tools like using man pages and like help flags with the tool.
So, like it gives you like info and insights about how do you actually use the tool and like exploring wikis and like stack of questions. I think it was an amazing article for like beginners who want to like, we're just getting into like command line or Linux world. That's cool. That's my experience.
I find, I found the Linux command line macOS a little bit less because there's often an alternative, but certainly the Linux where the sole access to it was through an SSH. I found it intimidating when I first got into it. No, I actually, I actually got into Linux right after my first semester of college.
I was just trying it. It was fun. And when I just took command line, I was like, wow, you can do so much in command line. And that rest is history. Like I've been using Linux for like, I would say five years now, but now I'm recently switched to macOS because of my work and I'm having hard time managing windows now.
I guess I had trouble switching to PCs because I, oh my, it was in Solaris when I was in college. Oh, interesting. I remember walking by the Solaris going, oh, those are different. Very interesting. Yeah, cool. But no, this will be super helpful, especially to a lot of folks out there who don't work with a lot.
We did this at PyCon in Portland with the Portland Art Museum there. It was really fun. And it's the classic programmer paintings. I love these. Yeah. Yeah. So the idea is you take a legitimate historical, maybe 400 year old piece of fine art, and then you ignore the actual name and you put your own sort of techie interpretation upon it.
So here, this one, we've got this balloon taking off into like a dark, cloudy red sky, and two wolves just like sort of forlorn watching it go. The ground is kind of on fire, but it's also snowy. I don't really understand that. Yeah. But that, you know, this is some proper painting that who knows what it is, right?
But if you look at the title, the title is Alphabet Cancels Loon, right? Loon was their project where they'd put balloons up over places without much internet, and that would beam down internet. So here's like the final balloon balloon going off into the smoky sky. It's in Ziedislaw Besinski, 1979, oil on Masonite.
Beautiful. Alphabet Cancels Loon. So we used to go around to the art museum there, and we would like at the conference or it would have like a dinner there or something. We'd just go around and like try to one-up each other on doing this to like real paintings. It was fun. But this whole classicprogrammerpaintings.com, endless joy right there.
I'm definitely going to check these guys out. Yeah, you can spend a long time going through. It's been around for a while, so it's good stuff. I'm chuckling at some right now. I got to stop looking at it. Yeah, exactly. I'm strongly resisting the urge to just scroll through them because we're doing a show.
If you want to join us for the live recording, just visit the website and click Livestream to get notified of when our next episode goes live. That's usually happening at noon Pacific on Wednesdays over at YouTube. On behalf of myself and Brian Okken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.
