Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #17: Google's Python is on fire and Simon says you have CPU load Pythonically

Return to episode page view on github
Recorded on Monday, Mar 13, 2017.

00:00 Hey everyone, Michael here. Just a quick show note before we get started on this episode.

00:05 I think we have a great set of topics to cover, but unfortunately, something went crazy with my

00:12 computer and just pinned all the cores and basically made the recording of my high quality

00:17 version fall apart. And so when you listen to this, there'll be a little bit of static on my

00:22 end. And I just want to say, sorry about that. We had some backup audio, but it also got messed up.

00:27 So basically this, I've tried to make it as good as possible, but there's a little bit of issue with

00:33 the audio. If you can handle it, there's some great news. And if you want to skip this one and just wait

00:38 for next week, totally understand as well. All right. Without further ado, let's get to the news.

00:43 Thanks. This is Python Bytes, Python news delivered directly to your earbuds. It's Monday, March 13th,

00:53 2017. And this is your host, Michael Kennedy here with my co-host, Brian Okken. Hey, Brian,

00:58 you ready to share the Python news with the world?

01:00 I am very ready. Excited.

01:02 Would you say that you're on fire?

01:04 I am on fire. Yeah.

01:05 Awesome. Yeah. Google's on fire too, right?

01:08 Well, yeah. So I'm, I'm actually a little confused about where this is coming from,

01:12 but there's a, yeah, our first topic is, was suggested by several listeners. We got it through

01:17 email and through Twitter to cover a tool called Python fire from, I, I don't know where it's from.

01:24 It's, it's on the Google repo on GitHub. But it, at the bottom, it says it's not a Google product. So

01:32 I don't know what that means.

01:33 I think it means it might've been created by somebody at Google, but it's not supported in

01:38 any way. It's just, Hey, this is a cool thing we made. So we should have it.

01:42 Yeah. I downloaded it and gave it a shot. It says, so we haven't even said what it is. It's

01:47 command line interface utility and their tag, the, at the top of the repo says Python fire is a

01:53 library for automatically generating command line interfaces from absolutely any Python object.

01:59 It is pretty cool. Another thing, it says a list of the benefits, a simple way to create a command

02:06 line interface in Python, and you can use it for exploring and debugging existing Python code.

02:11 And it makes transitioning between bash and Python easier. I actually, so I tried it out,

02:17 downloaded it, wrote a couple of little tools and I actually, it was pretty fun. But I don't think

02:24 I would use it for a shippable, a shippable Python like command line interface because it's pretty big.

02:32 Yeah. And by big, you mean it has some heavyweight dependencies, right?

02:35 Yeah. Like it includes all of IPython. That's quite a bit coming with it. I mean, it also includes

02:40 six, but that's really not that big of a deal.

02:42 Yeah. Six is just like a basically one little module or whatever, but yeah.

02:46 IPython, that's, that can be one of those things that's really hard to, to even install for some people, right? Like you give that to somebody on a Windows machine,

02:56 they don't have like a compiler set up, right? That can be quite challenging.

02:59 I'll have to see. I'm going to, I'm going to install it on a Windows machine this week to try that out.

03:06 Yeah. Cool. But it does look really great. You basically have a class and you just,

03:09 for your main, you just call fire and you pass it the class and boom, that thing is, is CLI callable,

03:16 right?

03:17 Yeah. But you don't, you don't have to use a class. You can also use just,

03:20 you can have a set of functions you can put together and, and add those as the interface.

03:26 And there can be multiple, multiple entry points as well. Like I tried, I tried throwing in like two or

03:33 three functions and then listing those as all things that you can call from the command line.

03:38 And, and it actually picks up, it picks up doc strings pretty well to show you. So you

03:42 kind of have help built in as well. I'm going to, I'm going to use it for like,

03:48 we've got test instruments we try to communicate with and writing, writing to and from the instrument

03:53 from Python is really easy from the bash. Not so easy. but I'm going to think,

03:59 I think I'm going to use this to try to do that at work.

04:01 Okay. Yeah. And it sounds cool. You have to give us a report on your experience.

04:06 Cool. So the next thing I want to talk about is Simon, like Simon says, but a cool menu bar

04:13 application for macOS. So if you don't care about macOS, maybe you don't care too much about this. But

04:20 one of my pet peeves is I think we need more full on native cross platform GUI things. We've had

04:29 PI cute and PI side and the QT framework. That's one option that we've had. That's pretty good,

04:35 but there's a lot of, a lot of versioning licensing funkiness going on until maybe till the end of this

04:41 year, actually, till they come out with PI side two, then maybe, maybe that becomes a really,

04:45 really great option. But we have things like PI OBJC, similar stuff for windows, similar stuff for

04:53 Linux, where you can basically somebody already has wrapped the truly native OS elements. So with this

05:02 thing called PI OBJC, you can basically create using Python what is indistinguishable from a native app,

05:09 like the controls literally are the same as if you had done it with Xcode and Objective C or Swift.

05:14 That's pretty cool, right? Yeah, it's, I hadn't heard of this. This is neat. Yeah. So the Simon

05:19 thing is not like a framework. It's just an app, right? So some guy is like, hey, I really want to

05:25 have a little thing I can click on. It'll tell me my, my network usage, my CPU usage, battery, or whatever,

05:30 something like this, right? And he did it as one of those little menu bar things, like what runs in the

05:34 top right by the clock on macOS. And you click it and it drops down info about your system. If you

05:40 look at the code, it's like, it depends on PI OBJC. But beyond that, it's like 150 lines for a full

05:46 implementation of that app. That's pretty cool. And so if you're thinking about you need just a little

05:52 simple something to run like as a menu bar app or the notification tray on windows or something like

05:58 this, you know, this is a really cool option. And I've mostly wanted to pull it out as like, hey,

06:02 here's an example. You could probably clone and tweak or just take the ideas of this

06:05 and go. So you just, you create an app, you derive from NS application, which comes from PI OBJC.

06:11 You implement a few methods and boom, you've got a nice native GUI app.

06:15 Okay. I'm going to have to try this one out too. It's neat.

06:18 It's neat, right? The final mix would be to use something like PI to app or something where you

06:23 bundle it in a distributable way. So it's not like, well, make sure you, you know, pip install this

06:27 thing before you can run it, right? Like that's probably not going to fly so well for like end users,

06:31 but still pretty excellent.

06:33 So is this a PI OBJ, what is that other one?

06:37 PI OBJC as objective C, like the Python wrappers for objective C.

06:41 Okay. So that's just a Mac only thing, right?

06:43 Yes, exactly.

06:44 Okay.

06:45 But we can do similar stuff in the other frameworks, I believe, right?

06:49 Like on the window side, you can use WPF, which is kind of way more heavyweight,

06:53 but you can build the Python stuff using Iron Python. And I'm sure there's something with

06:58 GDK and Linux as well.

07:00 Neat.

07:00 Yep. Neat. It's kind of lunchtime. I'm getting hungry. I wish I had some free food. Really,

07:05 I'm hungry.

07:06 Well, I was just amused. I don't know if these are useful or not, but I was amused by, in

07:11 reading Reddit this last week, there were a couple of things that popped up and one of

07:17 them was finding, this was actually useful, finding free food with Python. And it's actually

07:24 an article talking about using web scraping to, apparently there's a couple of places that

07:31 have like food delivery places that sometimes run specials where they're actually deliver

07:37 free food to you. And, but you have to be paying attention to have that work. And so somebody

07:42 wrote an app with web scraping and Twilio to occasionally check on this and then text him

07:50 information about the free specials. And I probably won't do this, but I think it's a nice,

07:58 a nice example of showing, combining Twilio with, with web scraping.

08:05 It's cool. Do you know what I like about it is it's taking these techie digital API type

08:10 things and it's making real stuff happen. Like, yeah, like you're, you're integrating Twilio

08:15 and screen scraping and then you have free food. Like how cool is that? Right.

08:18 Yeah. But I, so I would, yeah, you definitely real world probably have free food. I think it'd

08:24 be cool to run. I was thinking about doing a similar thing like, monitoring. So we have,

08:30 build machines and stuff and I wouldn't mind having a something that sat around and

08:36 monitored that and then, texted me the results cause I don't know how to do that.

08:41 Yeah. That's cool. Definitely some cool Twilio integration there.

08:44 And then the, the next, the next article just amused the heck out of me. It's called,

08:48 notification notification when friends order pizza. so I don't know if this is a great

08:56 thing or not for dominoes to do, but there's, apparently a way that you can plug in phone

09:03 numbers and find out, whether that phone number has ordered pizza recently. And, and so somebody

09:10 wrote a script to put in all of their friends phone numbers and, text them or let them know when

09:17 they're one of their friends is ordering pizza. I guess another way to get free food is to mooch

09:23 off your friends when they order food. Yeah. That's, I'm not sure how I feel about that. Actually.

09:27 That's a little creepy, man. It actually is creepy. I was thinking that like, I was wondering

09:34 whether or not I should include that, but it was, it amused me. So the, the, I don't think that really

09:40 it ought to be that easy to find out whether or not somebody ordered some pizza. Yeah. Well,

09:44 if, if all your friends start showing up every time you have dominoes, yeah, I was trying some funky stuff, man. They also have a bot. Like you can order pizza just by

09:55 like chatting with dominoes, which is also kind of funky. I want. Yeah. But, but like you could order

10:00 food for other people then or something. I don't know. It seems, it seems like they're playing with

10:05 scary interfaces, but at least they're playing with interfaces. Yeah, exactly. Exactly. Like it's,

10:09 it is pretty cool. Okay. So speaking of food, I want to talk about pi, HTT pi, which is a little utility written in Python that is kind of like w get or curl,

10:23 except for that. It's awesome. And the reason it's awesome is it runs on the command line. So if

10:30 I wanted to like call a JSON API, I could say like HTTP space. And I would, you know, give it the URL,

10:38 whatever the, that is, maybe some additional data. You can even post data from the command line and so

10:43 on. And it comes back formatted, pretty printed, color coded everything. So it is, it's quite glorious.

10:51 You can create sessions and have those like authentic sessions persist across multiple calls.

10:56 You can do XML, you can do JSON, you can do HTTP, all the, or HTML, all these different things that it

11:03 knows about. It will color code and format pretty for you on the command line.

11:08 That's great. And this is, multiple, multiple operating systems.

11:12 Yes, absolutely. Yeah. So this, this works everywhere. This is just a Python three little library.

11:18 And that's the, the pie part, right? The Python. And so I'd spoke about postman before as being a

11:23 really cool way to test, APIs and just play around with them. But this is kind of like the CLI

11:28 version. Cause if you do that with curler or even with Python and requests and then you spit it out,

11:33 like it shows you it, but it's usually not well formatted. It's usually minified. It's not color

11:38 coded. So this is, this is pretty tricky.

11:40 The color coding actually makes it really readable. That's nice.

11:44 So if you're looking, if you've been using curl or w get a lot, check out HTTP, HTTP,

11:51 the links in the show notes, it's on GitHub and it's got a, it's got a cool, a cool little

11:57 interface. I put the link to the homepage in there. Just click on that and you'll see a screenshot

12:01 comparison of that versus curl and it's night and day. It's great.

12:04 Well, the last thing I've got is, speaking of command lines and hard to pronounce packages,

12:11 it's a pip dep tree. there's a, a little utility, that you can do it with, pip install.

12:20 I think it's pip dep tree altogether. as in pip dependency tree, but just P I P D E P T R E E.

12:27 Right. Yes. And, it is a godsend for me. since for like, for this podcast,

12:33 I'm trying out stuff all the time, trying out new packages. And, also for like, right now,

12:39 I'm working on the plugin, chapter in the PI test book and I'm, I'm installing a lot of stuff

12:46 and I am using virtual environments, but I still, I don't really want to throw them away all the time.

12:52 so I want to clean them out. But, if you just do a pip list, often I see a whole bunch of

12:59 stuff that I don't remember installing and it's because of all the dependencies.

13:03 And this pip dep tree just shows all of the things you've installed and what depends on what,

13:10 when I look up and don't know what arrow is or where it came from.

13:14 pip dep tree shows me that, Oh, I installed cookie cutter and cookie cutter installed Jinja2.

13:20 And Jinja to install there. Now I know.

13:23 Yeah. So yeah, that's very cool. Right.

13:25 Yeah. And it's nice. I like it. it's kind of, I wish that was just, it should just be an option and, pip pip list, I think. So yeah, it really should be part of pip,

13:35 shouldn't it? But it's not. And so we have pipped up tree and I think that's cool. You can reverse it as well.

13:40 You can say, okay, this thing, what depends upon this? And it'll say, well, these three packages through some sort of

13:46 transitive closure of their dependency graph. These are the things that you, that, that you need this to be here for,

13:53 or you can do it the other way. And you can say, what is installed this, right? Like, or what does this thing depend upon?

13:59 Which is, it's pretty cool. So you can view it from either direction.

14:01 Oh, cool. I didn't know that.

14:04 Yeah. There's a dash R for reverse. So hit it with the dash R. Cool. Okay. So final thing we have for today is, a real testament to Python 3, to modern Python, to asynchrony.

14:17 You know, we've been hitting this async away, the power of asynchrony a couple of times. So I want to come back with a few comments from what people have talked about, but I also want to feature an article. And this is a really great article by the folks at Signet by AI, which is an AI platform that uses Python.

14:35 So basically the title that what we're going to talk about is not your father's Python, amazing Python frameworks.

14:43 They sort of went through what they had been thinking about when they created this company and said, look, we all know Python and we like Python, but it's super important that we can do crazy amounts of data processing.

14:54 Their product and investor has to handle hundreds of thousands of events per second. And, you know, they've been hearing the drumbeat that, you know, you can't scale with Python.

15:04 You need to switch to Go, et cetera, et cetera, et cetera. And they said, all right, well, let's, let's have a look and let's see how this is going to work out.

15:11 They evaluated Go and what the good and the bad of it was. They evaluated Python and said, let's look not at traditional Python, like the way, the sort of synchronous style of programming, but there's a number of really powerful async frameworks that we've covered, I think, at least two out of three of them.

15:27 So there's UV loop, which is pretty awesome. There's Sanic and there's Jepronto.

15:34 Okay. So Sanic and Jepronto, these are the web things that we've talked about tons and they're built on asyncio, just like this UV loop is, but UV loop is actually a re-implementation in Cython.

15:45 So the compiled version of Python, that's more than twice as fast as what's built into Python itself. Interesting, right?

15:51 So like maybe, maybe we should just like bring that feature into Python itself in some way to make asyncio twice as fast.

15:58 So they said, let's, let's look at this and evaluate it and decide if this scalability thing's going to work.

16:03 All right. And they said, we all know about the GIL. Is this a real problem?

16:08 So they ran, they ran some comparisons and did some work and it turns out like they've got some graphs of UV loop and the other frameworks, just like blowing away things like Node.js in terms of performance, keeping up with, I think, go on some, some use cases faster, some slower, but really very, very high performance.

16:28 And so after this really detailed write up with like numbers and everything, you know, graphs and analysis, they said, look, the future of Python is here.

16:36 Overall, it looks like fast asynchronous Python might be here to stay.

16:39 Now that asyncio really seems to be the default way that people are willing to work in Python and async and await has really caught on because of the non-blocking network and disk IO is usually the problem.

16:53 It turns out the GIL probably doesn't really get in the way of speed that much for most use cases.

16:58 It's cool.

16:58 Isn't that cool?

16:59 So they said, look, it's, it's working out great for us, Python three, and we've got the scalability we need.

17:04 No problem.

17:05 And we're happy we didn't abandon because traditionally hadn't been fast enough.

17:09 So I missed, somehow I'm missing this, which they looked at Jepranto and Sanic and UV loop.

17:15 Are they deciding on anything?

17:18 I don't know which one they decided upon.

17:20 I think UV loop is a little more established.

17:23 And UV loop is actually the foundation for Jepranto and Sanic.

17:27 So there's a bit of a mixing, right?

17:28 Like Jepranto and Sanic are extending these and certain.

17:31 It's pretty cool.

17:32 There's a nice comment, which I linked in the show notes for this section.

17:36 And there's somebody in there saying, hey, we went through the same basic thinking and here's how it worked out for us.

17:43 And they said, we're also doing this Async Python three thing, which is cool.

17:46 On Twitter, we got a message from Sasha Kurta.

17:50 And he said, basically, hey, Michael, hey, Brian.

17:52 I have this example where I was doing a bunch of HTTP client stuff.

17:58 And remember, we talked about AIO HTTP, the client side stuff, how much faster that can make it.

18:03 And he said, that's cool.

18:05 I was doing some scraping and whatnot.

18:06 And my particular project went from eight minutes, over eight minutes, doing requests to less than 45 seconds using the Async and await stuff with AIO HTTP.

18:19 Basically, the same code.

18:20 He was blown away.

18:20 Yeah, that's really cool.

18:22 And I'm glad that he shared that with us.

18:23 Yeah, I am too.

18:24 And of course, you drew the correct conclusion from this conversation.

18:28 That look at the, what is that, like 10-time increase in productivity you get by listening to Python bytes?

18:36 Yeah.

18:37 Yes, definitely.

18:38 All right.

18:39 You can save your company money, too, by listening to us.

18:42 Absolutely.

18:43 All right.

18:43 Well, that's it for this week's news.

18:46 You got anything, finally, you want to share personally?

18:48 Nope.

18:49 Nope.

18:49 Just plugging away at the book.

18:50 Same here.

18:51 Plugging away the courses.

18:52 So thank you, everyone, for supporting all of our work, not just this podcast, but Brian's other podcast, his book, my courses, my other podcasts.

19:00 It's great to be doing this for everyone.

19:02 So thank you.

19:02 And thank you, Michael.

19:03 Yep.

19:04 See you later.

19:06 Thank you for listening to Python bytes.

19:08 Follow the show on Twitter via at Python bytes.

19:10 That's Python bytes as in B-Y-T-E-S.

19:13 And get the full show notes at pythonbytes.fm.

19:17 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.

19:21 We're always on the lookout for sharing something cool.

19:24 On behalf of myself and Brian Okken, this is Michael Kennedy.

19:27 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page