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. I think we have a great set of topics to cover but unfortunately something went crazy with my computer and just pinned all the cores and basically made the recording of my high-quality version fall apart. And so when you listen to this there'll be a little bit of static on my end and I just want to say sorry about that. We had some backup audio but it also got messed up. So basically this I've tried to make it as good as possible but there's a little bit of issue with the audio. If you can handle it there's some great news and if you want to skip this one and just wait for next week totally understand as well. All right without further ado let's get to the news. Thanks.

00:44 This is Python Bytes. Python news delivered directly to your earbuds. It's Monday March 13th 2017 and this is your host Michael Kennedy here with my co-host Brian Okken. Hey Brian, 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:06 Awesome. Yeah, Google's on fire too, right?

01:08 Well, yeah. So 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.

01:16 We got it through email and through Twitter.

01:18 To cover a tool called Python Fire from, I don't know where it's from.

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

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

01:34 I think it means it might have been created by somebody at Google, but it's not supported in any way.

01:38 It's just, "Hey, this is a cool thing we made. We all should have it." Yeah, I downloaded it and gave it a shot.

01:44 It says, so we haven't even said what it is, it's a command line interface utility.

01:48 and their tag at the top of the repo says Python fire is a library for automatically generating command-line interfaces from absolutely any Python object. It is pretty cool. Another thing it says the list of the benefits a simple way to create a command-line interface in Python and you can use it for exploring and debugging existing Python code and it makes transitioning between bash and Python easier.

02:15 I actually, so I tried it out, downloaded it, wrote a couple of little tools, and I actually, it was pretty fun, but I don't think 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.

02:37 That's quite a bit coming with it.

02:39 I mean, it also includes 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.

02:45 But yeah, I Python that's, that can be one of those things that's really hard to, to even install for some people, right?

02:53 Like you give that to somebody on a Windows machine, they don't have like a compiler setup, right?

02:58 That can be quite challenging.

02:59 I'll have to see.

03:00 I'm going to, I'm going to install it on a Windows machine this week to try that out.

03:05 Yeah, cool.

03:06 But it does look really great.

03:08 You basically have a class and you just, for your main, you just call fire and you pass it the class and boom, that thing is CLI callable, right?

03:17 - Yeah, but you don't have to use a class.

03:19 You can also use just, you can have a set of functions you can put together and add those as the interface.

03:26 And there can be multiple entry points as well.

03:29 Like I tried throwing in like two or three functions and then listing those as all things that you can call from the command line.

03:38 And it actually picks up doc strings pretty well to show you, so you kind of have help built in as well.

03:46 I'm going to use it for--

03:48 like, we've got test instruments we try to communicate with.

03:50 And writing to and from the instrument from Python is really easy.

03:55 From the Bash, not so easy.

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

04:01 OK, yeah.

04:02 Sounds cool.

04:03 to give us a report on your experience.

04:07 Cool.

04:08 So the next thing I want to talk about is Simon.

04:10 Like not Simon Says, but a cool menu bar application for macOS.

04:16 So if you don't care about macOS, maybe you don't care too much about this, but one of my pet peeves is I think we need more full on native cross platform GUI things.

04:28 We've had PyQt and PySide and the Qt framework.

04:33 That's one option that we've had that's pretty good, but there's a lot of versioning, licensing, funkiness going on until maybe till the end of this year actually, till they come out with PySide 2.

04:44 Maybe that becomes a really great option.

04:47 But we have things like PyOBJC, similar stuff for Windows, similar stuff for Linux, where you can basically somebody already has wrapped the truly native OS elements.

05:01 So with this thing called PIO BJC, you can basically create using Python what is indistinguishable from a native app 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?

05:15 Yeah, it's like I hadn't heard of this.

05:18 This is neat.

05:19 Yeah, so the Simon thing is not like a framework.

05:21 It's just an app, right?

05:22 So some guy is like, "Hey, I really want to have a little thing I can click on and it'll tell me my network usage, my CPU usage, battery or whatever, something like this, right?" And he did it as one of those little menu bar things, like what runs in the top right by the clock on macOS.

05:37 And you click and it drops down info about your system.

05:40 If you look at the code, it's like, it depends on PyOBJC, but beyond that, it's like 150 lines for a full implementation of that app.

05:48 That's pretty cool.

05:50 So if you're thinking about you need just a little simple something to run, like as a menu bar app or in the notification tray on Windows or something like this, you know, this is a really cool option.

06:00 And I've mostly wanted to pull it out as like, Hey, here's an example.

06:02 You could probably clone and tweak or just take the ideas of this and go.

06:06 So you just, you create an app, you derive from NS application, which comes from Pio BJC.

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

06:15 Okay.

06:16 I'm going to have to try this one out too.

06:17 It's neat, right?

06:19 The final mix would be to use something like Py2App or something where you bundle it in a distributable way so it's not like, well, make sure you pip install this thing before you can run it, right?

06:28 Like that's probably not gonna fly so well for like end users, but still pretty excellent.

06:33 - So is this PyOBJ, what is that other one?

06:37 - PyOBJC as Objective-C, like the Python wrappers for Objective-C.

06:41 - Okay, so that's just a Mac only thing, right?

06:44 - Yes, exactly.

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

06:49 Like on the Windows side, you can use WPF, which is kind of way more heavyweight, but you can build the Python stuff using Iron Python.

06:57 And I'm sure there's something with GDK and Linux as well.

07:00 - Neat.

07:01 - Yep, neat.

07:02 It's kind of lunchtime, I'm getting hungry.

07:04 I wish I had some free food.

07:05 Really, I'm hungry.

07:06 - Well, I was just amused.

07:08 I don't know if these are useful or not, but I was amused by in reading Reddit this last week, there were a couple of things that popped up.

07:16 And one of them was finding, this was actually useful, finding free food with Python.

07:22 And it's actually an article talking about using web scraping to-- apparently, there's a couple of places that have food delivery places that sometimes run specials where they actually deliver free food to you.

07:39 But you have to be paying attention to have that work.

07:42 And so somebody wrote an app with web scraping and Twilio to occasionally check on this and then text him information about the free specials.

07:55 And I probably won't do this, but I think it's a nice example of showing combining Twilio with web scraping.

08:05 It's cool.

08:06 Do you know what I like about it?

08:07 It's taking these techie digital API type things and it's making real stuff happen.

08:12 Yeah.

08:13 - Yeah.

08:14 - Like you're integrating Twilio and screen scraping and then you have free food.

08:17 Like how cool is that, right?

08:19 - Yeah, but I, so I would, you definitely real world probably have free food.

08:23 I think it'd be cool to run, I was thinking about doing a similar thing, like monitoring.

08:30 So we have build machines and stuff and I wouldn't mind having something that sat around and monitored that and then texted me the results 'cause I don't know how to do that.

08:41 - Yeah, that's cool.

08:42 Definitely some cool Twilio integration there.

08:44 - And then the next article just amused the heck out of me.

08:48 It's called "Notification When Friends Order Pizza." So I don't know if this is a great thing or not for Domino's to do, but there's apparently a way that you can plug in phone numbers and find out whether that phone number has ordered pizza recently.

09:07 And so somebody wrote a script to put in all of their friends' phone numbers and text them or let them know when one of their friends is ordering pizza.

09:20 I guess another way to get free food is to mooch off your friends when they order food.

09:24 - Yeah, that's, I'm not sure how I feel about that, actually, that's a little creepy, man.

09:29 - It actually is creepy.

09:30 I was thinking that, like, I was wondering whether or not I should include that, but it amused me.

09:39 I don't think that really it ought to be that easy to find out whether or not somebody ordered some pizza.

09:44 Yeah, well, if all your friends start showing up every time you have Domino's.

09:48 Yeah. Domino's is trying some funky stuff, man.

09:52 They also have a bot, like you can order pizza just by like chatting with Domino's, which is also kind of funky.

09:58 I want, yeah, but but like you could order food for other people then or something.

10:02 I don't know. It seems, seems like they're playing with scary interfaces, but at least they're playing with interfaces.

10:08 >> Yeah, exactly.

10:09 It is pretty cool.

10:11 Okay, so speaking of food, I want to talk about Pi.

10:15 [laughter]

10:16 Httpi, which is a little utility written in Python that is kind of like Wget or curl, except for that it's awesome.

10:26 The reason it's awesome is it runs on the command line.

10:30 command line. So if I wanted to like call a JSON API, I could say like HTTP space and I would you know give it the URL whatever the that is maybe some additional data you can even post data from the command line and so on and it comes back formatted pretty printed color-coded everything. So it's quite glorious. You can create sessions and have those like authentic sessions persist across multiple calls. You can do XML, you can do JSON, you can do HTTP, or HTML, all these different things that it knows about, it will color code and format pretty for you on the command line. That's great, and this is multiple operating systems. Yes, absolutely. Yeah, so this works everywhere. This is just a Python 3 little library, and that's the the Pi part, right, the Python. And so I spoke about Postman before, it's been a really cool way to test APIs and just play around with them.

11:27 But this is kind of like the CLI version, because if you do that with curl or even with Python and request and then you spit it out, it shows you it, but it's usually not well formatted.

11:37 It's usually minified.

11:38 It's not color-coded.

11:39 So this is pretty tricky.

11:41 The color-coding actually makes it really readable.

11:44 That's nice.

11:45 So if you've been using curl or Wget a lot, check out HTTP, HTTPie.

11:53 links in the show notes it's on GitHub and it's got a got a cool cool little interface. I put the link to the home page in there just click on that and you'll see a screenshot comparison of that versus curl and it's night and day it's great. Well the last thing I've got is speaking of command lines and hard to pronounce packages it's pipdeptry. There's a little utility you can do it with pip install, I think it's pip dep tree altogether.

12:22 >> Yeah.

12:23 >> But-

12:23 >> As in pip dependency tree, but just P-I-P-D-E-P-T-R-E-E, right?

12:28 >> Yes.

12:28 And it is a godsend for me.

12:32 Since for, like for this podcast, I'm trying out stuff all the time, trying out new packages.

12:37 And also for, like right now, I'm working on the plug-in chapter in the pytest book, and I'm installing a lot of stuff.

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

12:53 So I want to clean them out.

12:55 But if you just do a pip list, often I see a whole bunch of 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, pip dep tree shows me that, oh, I installed cookie cutter, and cookie cutter installed Jinja 2, and Jinja 2 installed Arrow.

13:22 Now I know.

13:24 - Yeah, that's very cool, right?

13:25 - Yeah, and it's nice, I like it.

13:28 It's kind of, I wish that was just, it should just be an option in pip list, I think.

13:34 - Yeah, it really should be part of pip, shouldn't it?

13:36 But it's not, and so we have pipteptree, and I think that's cool.

13:39 You can reverse it as well.

13:40 You can say, okay, this thing, what depends upon this?

13:43 And it'll show, say, well, these three packages, through some sort of transitive closure of their dependency graph, these are the things that you need this to be here for, or you can do it the other way, and you can say what is installed this, right?

13:57 Or what does this thing depend upon?

13:59 Which is pretty cool.

14:00 So you can view it from either direction.

14:02 - Oh, cool.

14:03 I didn't know that.

14:04 - Yeah, there's a dash R for reverse.

14:06 So hit it with the dash R.

14:08 Cool, okay.

14:09 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/await, the power of asynchrony, a couple of times.

14:23 So I want to come back with a few comments from what people have talked about, but I also want to feature an article.

14:27 And this is a really great article by the folks at Signet by AI, which is an AI platform that uses Python.

14:36 So basically the title of 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:55 Their product and editor has to handle hundreds of thousands of events per second.

14:59 And they've been hearing the drumbeat that, you know, you can't scale with Python, you need to switch to Go, et cetera, et cetera, et cetera.

15:07 And they said, "All right, well, let's have a look "and let's see how this is gonna work out." They evaluated Go and what the good and the bad of it was.

15:14 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." So we've covered, I think, at least two out of three of them.

15:27 So there's UVLoop, which is pretty awesome.

15:31 There's Sanic and there's Gepronto, okay?

15:35 So Sanic and Gepronto, these are the web things that we've talked about tons and they're built on async I/O just like this UV loop is but UV loop is actually a re-implementation in Cython, so the compiled version of Python that's more than twice as fast as what's built into Python itself.

15:50 Interesting, right?

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

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

16:05 we all know about the gill, is this a real problem? 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 j s, in terms of performance, keeping up with I think go on some some use cases faster, some slower, but really very, very high performance. And so after this really detailed write up with like numbers and everything, graphs and analysis.

16:34 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 async IO 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, "it turns out the GIL probably doesn't really "get in the way of speed that much for most use cases." - That's cool.

16:59 - Isn't that cool?

16:59 They said, look, it's working out great for us, Python 3, and we've got the scalability we need, no problem, and we're happy we didn't abandon it, because traditionally it hadn't been fast enough.

17:09 - So somehow I'm missing this, which they looked at Gepronto and Sanic and UVloop.

17:16 Are they deciding on anything here?

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

17:20 I think UVloop is a little more established.

17:23 And UVloop is actually the foundation for Gepronto and Sanic.

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

17:28 like Pronto and Sanic are extending these and insert.

17:31 It's pretty cool.

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

17:37 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 3 thing, which is cool.

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

17:50 And he said basically, hey, Michael, hey, Brian, I have this example where I was doing a bunch of HTTP client stuff.

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

18:04 And he said, "That's cool." 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:21 - 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 Of course, you drew the correct conclusion from this conversation.

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

18:36 - Yeah, yes, definitely.

18:38 - All right.

18:40 - You can save your company money too by listening to us.

18:43 - Absolutely, all right.

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

18:46 You got anything finally you wanna share personally?

18:48 - Nope, nope, just plugging away at the book.

18:51 - Same here, plugging away at 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:03 Thank you, Michael.

19:04 Yep.

19:05 See you later.

19:06 Thank you for listening to Python Bytes.

19:08 Follow the show on Twitter via @PythonBytes.

19:11 That's Python Bytes as in B-Y-T-E-S.

19:14 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:22 We're always on the lookout for sharing something cool.

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

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

Back to show page