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


Transcript #9: Walking with async coroutines, diving deep into requests, and a universe of options (for AIs)

Return to episode page view on github
Recorded on Tuesday, Jan 17, 2017.

00:00 This is Python Bytes, Python headlines and news delivered directly to your earbuds.

00:04 It's episode 9, recorded Tuesday, January 17th, 2016.

00:09 This is one of your co-hosts, Michael Kennedy.

00:11 I'm here with my other co-host, Brian Okken.

00:14 Hey Brian, how's it going, man?

00:15 It's going very good. How are you?

00:16 I'm doing well. I always look forward to our weekly chat about cool stuff going on in the Python ecosystem.

00:23 And I see that you found something quite cool for our first item.

00:27 Actually, it's a series of things.

00:29 The link that we have is to Python asynchronous I/O walkthrough.

00:35 And here's the story.

00:36 So in July, there was an open source book published called 500 Lines or Less.

00:41 The architecture of open source applications is the website.

00:45 But they do various open source free books, which is pretty cool.

00:50 Anyway, the 500 Lines or Less had one chapter in it from Jesse Giro Davis and Guido Van Rossum called a web crawler with asyncio coroutines. And it's a pretty cool chapter about explaining asynchronous networking, showing how non blocking sockets work and how Python three coroutines improve asynchronous network programs.

01:15 Yeah, that's really cool. I think that that book is amazing. There. It's not just this particular chapter. There's many chapters there. It's also not just Python, but it has that's a heavy, a lot of pieces which are Python.

01:29 And basically it's, can you show me something amazing that really, I thought was really hard, but can be explained or written in 500 lines or less and then discuss the architecture.

01:40 And there's like 20 different projects or something.

01:43 It was very cool.

01:45 - Yeah, and the series is pretty neat.

01:47 So this is 500 lines or less.

01:49 There's previous books that are like about architecture and about performance issues, and it's a neat thing they're doing.

01:59 But this particular chapter for me, since I'm kind of new to the asynchronous world, it still was a little bit heavy to get into.

02:08 And so Philip Guo, who I think he interviewed you once.

02:12 - Yeah, he's been on my show, on Talk Python to Me, on episode 22.

02:17 And I also was on his show.

02:19 He started a podcast recently.

02:21 It's got like 25 episodes or something.

02:23 And yeah, I'll be sure to link to that.

02:25 That's a really cool one as well.

02:27 He interviews people just kind of generally in the programming space.

02:31 - So what he did was it's pretty cool.

02:33 He just is walking through this article and talking about it and then also, and showing it on video, and then also going through and doing some code examples.

02:43 And he split, it's about 90 minutes total to get through this, but he split it up into eight parts.

02:49 So each one is really not that hard to get through.

02:53 And it's a pretty cool idea and I really appreciate it.

02:57 I think it's a good way to learn, to see somebody doing it, to hear them, to use all your senses.

03:04 - Really like that.

03:05 I think this is great work.

03:07 Nice work, Philip.

03:08 Way to go.

03:08 He's done stuff like that before.

03:10 Like I had him on, the reason I had him on episode 22 of Talk Python was he did this thing called CPython a 10 hour code walk, which was like an exploration through the CPython internals, which I found really enlightening.

03:25 And we actually I talked to Jesse about his article on episode 69 as well.

03:30 When we talked about writing as a developer, he's got some really cool thinking around like design patterns on technical writing and stuff.

03:38 So this is this is really cool.

03:40 I think I think seeing a problem unfold before your eyes in code is much different than seeing the finished product discussed. And I find I learn really well that way. So I'm happy this is here. I haven't had a chance to go through it, but I'm looking forward to it.

03:53 And also both Jesse and Philip are doing some cool things to help the entire community, which I appreciate. Jesse's been supportive of a lot of people, including me.

04:03 Yeah, absolutely. Jesse's doing great stuff. Do you want to think about the future of Python a little bit?

04:08 I thought I was thinking about the future of Python with switching to 3.6 recently.

04:12 But what do you think the future has in store?

04:16 We were living like right on the edge of the front wave, but there's an article I thought was pretty interesting.

04:22 I don't necessarily agree with everything, but I felt that it was certainly, you know, thought provoking.

04:28 A guy named Sardar Yagulap, I'm sorry, I'm sorry I messed up your name, wrote an article and it's called "Four Likely Future Twists for Python." And I thought that was pretty cool.

04:41 So let's go through the four twists.

04:43 The first one does not make me happy, but is certainly something that I can see coming into existence as a thing.

04:51 So we'll see.

04:53 But the first one that they put out there is that Python 2x may live on.

04:57 Yeah, I actually can see that this might happen.

05:00 I mean, it's an open source project, so there's nobody stopping you from doing it.

05:04 The thing that's going to make the difference is what do the core developers do, right?

05:08 So right now the core developers are all focused on making sure that we make Python 3 as great as possible and they're putting their energy into it and so on.

05:15 So I think Python 3 is certainly the right place for people to be.

05:19 But I can see like large banks, you know, you think of places like Bank of America, they've got gosh, I don't remember the exact stats, but I was talking to Mahmoud Houshemi from one of the enterprise Python episodes I did.

05:31 And it's something like the number of lines of Python 2, I don't even think it's 27.

05:36 like 2.6 or 2.5 code is in the millions.

05:39 Like five million lines of codes or something crazy like that.

05:42 I can see a company like that forking Python and just making some kind of ongoing effort.

05:49 Supporting your own Python, that just doesn't sound fun.

05:52 It sounds like a really bad idea.

05:53 I would much rather people just upgrade and we can all work together and live together and do great stuff.

06:00 Here's one of the predictions that there'll probably be somebody that forks Python 2 and tries to keep it going. Whether that turns out to be beneficial or you know, trading one set of problems for a worse set of problems, we'll see. Yeah. The other one was this one I had no visibility into this I didn't see this coming and I read the title and I said requirements.txt may be replaced with something better. What? Okay, well, maybe it turns out the guys over at the Python Packaging Authority, that's the PyPI and pip and all those, but projects, so there's a organization, a group of people that actually work on that.

06:38 They're working on this thing called pip file.

06:41 And it's like a proposed new file format that's supposed to replace requirements.txt.

06:47 That's interesting.

06:48 Isn't it?

06:49 Yeah.

06:50 And so the idea is that pip file is going to be better or superior to requirements and that has a toml syntax, which is, if I recall correctly, it's a little like YAML.

07:00 There's one pip file that can have multiple configurations in it, so you don't have like a dev requirements, a test requirements, a prod requirements, and so on.

07:08 Yeah, it's, it's cool.

07:09 You can do, you can do like a pip file freeze on it, it'll generate something that is a much richer document instead of just a txt file with a package name, like a version.

07:21 So there's a lot of configuration and stuff in there.

07:22 Like for example, one of the things you can do in these pip files is you can actually set the source of the packages, like right in your requirements file.

07:32 So you can say I want to use this version of Python, I want to use it against this source like PyPI.org, or you could create your own DevPy server thing and run it internally and that would be part of your requirements file.

07:45 So lots of cool enhancements there.

07:48 I'm interested to see where it goes, but it's out there on GitHub, you can actually check it out.

07:51 Yeah, I'd like to make sure it like sort of goes along the lines with with other packaging issues like the setup file and stuff.

08:00 Hopefully we have one thing that replaces everything.

08:03 Yeah, definitely.

08:04 Okay, so number three is Python could get more enterprise editions.

08:09 So we've got things like Anaconda and in thought, and Intel actually has their own Python implementation that is sort of a repackaging and tweaking of the Anaconda distribution, but just talking about how there may be more variations of Python distributions focused on enterprise needs. Maybe. I certainly see it happening in data science. I could see it happening elsewhere.

08:34 I could see it, especially since we have to, I mean, everybody that's relying on Anaconda or something kind of has to wait for them to release something when they're waiting for a new version.

08:45 And the last one is Python's software repository. So PyPI basically could get enterprise-friendly package management. So Christian Medina wrote a really interesting article as a follow-up to my episode 84 on the problems with PyPI and open source infrastructure funding and stuff and put together a pretty interesting article talking about something called the Python Trusted Registry or Trusted Index or something like that as a way to both fund PyPI and make it more enterprise friendly.

09:18 I'm actually thinking about this problem as well and I'm probably going to release something like an article and a proof of concept, but I'm not ready to talk about it yet.

09:27 - Okay, sounds interesting.

09:29 Well, so that was four predictions.

09:30 Are we done with the future?

09:31 - That's the future.

09:32 Let's go back to the present.

09:34 - Okay, so in the present, NumPy is used for a lot of data science, and really just science and engineering.

09:40 A lot of people use NumPy.

09:41 There's a new book, an open source book, called From Python to NumPy, and it's from, I think this is a French person, Nicolas Rogier.

09:52 The book is pretty interesting.

09:53 It takes the assumption that you already know Python, you're an intermediate developer, and you just need to get your understanding of NumPy to apply it to whatever problem you're on.

10:05 And it looks well, I haven't read a ton of it, but it looks really well formatted.

10:09 I like the topics that are in there.

10:11 Just sounds interesting.

10:13 - Yeah, it sounds really cool.

10:14 And if you're looking for scientific computation and you're thinking of like, am I gonna shell out $2,000 for MATLAB?

10:21 Well, maybe look at some of the Python tools, right?

10:23 It's definitely growing.

10:24 - Yeah.

10:25 - So it's cool for us to think about the future, but what if like machines could think about the future?

10:31 (laughing)

10:32 - Machines, yeah.

10:32 - I really feel like 2016 and 2017 is the year where AI became not something that's always five years in the future, but actually something that's starting to take shape in the present.

10:43 - Yeah, and it affects, now affects everybody with all of their speaking devices.

10:48 - Yeah, and I, you know, we could be mean and we could say, hey, Amazon thing, order us a, But we won't do that.

10:56 The thing, the item I want to talk about for number four here is something called Universe.

11:01 And it's a way to take games basically, all sorts of games, and make them available as ways for AIs to experience the world.

11:11 So here's the deal.

11:12 The thing they put together where you can build an AI, put it into a Docker image, give it to their environment, and then they will let it play literally thousands of video games.

11:23 And it can learn from playing the games.

11:25 So you can play like flash-based browser games, other types of games, a whole bunch, like I said, over a thousand environments.

11:31 And the way it plays it is the, so you don't have to integrate with like all these different games.

11:37 Your Docker image just is presented the visual screen that the humans look at, and then they send mouse and keyboard events to the games.

11:47 Yeah.

11:48 So they basically just play as if they were a person playing the game.

11:52 so they have the same experience of the game as you, but here's all these environments in which you can train and test AIs.

11:59 What do you think?

12:00 - It sounds like tic-tac-toe in global thermonuclear war to me.

12:05 - Hello, Dr. Falcon, would you like to play a game?

12:08 - So what's the, so if you have an AI that has learned a whole bunch of stuff about games, like why?

12:17 - Why would you care about this, right?

12:18 Like, well, maybe you're working on a robot and you wanna teach the robot to walk around to interact with the world, but you don't have the robot finished, you could take the smarts of the robot and let it play Counter-Strike or something for until it gets really good at not bumping into stuff, like making it through paths, and then you could just plug that into your robot.

12:39 I don't know, something like, I mean, this is me totally speculating on the spot.

12:42 I don't know.

12:43 - Yeah, just don't give your robot a gun.

12:44 - Yes, exactly, 'cause it's gonna be really good at it at that point.

12:48 - Yeah.

12:48 - All right, so another thing that I've been doing a lot with lately is working with APIs and HTTP services and stuff.

12:55 And your next item is a pretty interesting deep dive into literally the most popular Python package request, which for those of you who don't know, it's downloaded 7 million times a month.

13:06 - Yeah, and it's titled Python Request Deep Dive.

13:10 And it came from Anthony Shaw, and he put it on Medium.

13:14 And Anthony's been, I don't even know why I know Anthony.

13:18 I've just known about him for a long time.

13:20 But he's, my first thought was it's going to be just teaching people how to use requests, but it's not.

13:27 It's a really cool article.

13:29 He took, what happened was he had, he was on a project to convert a large project from HTTBlib, so he wasn't even using URL lib two or anything, HTTPlib into requests.

13:45 And this project was Apache Lib Cloud and with, I was handling stuff like HTTP, HTTPS, REST, JSON, XML, whole bunch of bizarre APIs with over, he lists over 80 client libraries to handle different cloud services and had one connection class that did the encoding and decoding of everything and converted this all.

14:12 And this article's about all the stuff he had to deal with, like dealing with sessions, dealing with authentication, how we test it, doing prepared requests, streams.

14:23 It's just a chock full of stuff and it's not even that long of an article, so I think he did a good job.

14:28 - Yeah, that sounds really cool.

14:29 I haven't had a chance to read it, but I definitely bookmarked it.

14:31 You know, Anthony Shaw is a great guy.

14:33 He's doing cool stuff.

14:34 He talked about LibCloud on PodcastInit.

14:37 I'm afraid I don't remember the number, but you can listen to him there and that's really cool.

14:41 It's a cool project and this sounds like pretty serious real world upgrade from one library to another sort of example.

14:49 And I think there's probably a lot of lessons people can get from this.

14:52 And one of the one of the neat things he has in here is he uses a tool called requests mock.

14:59 And I looked through this, the API for this, and it really is pretty cool.

15:05 So my my philosophy on mocks is to to really only mark what you absolutely have to have to do.

15:12 Not everything, but some of your testing should be using mocks when you're dealing with outside resources and you know, an HTTP request clearly is dealing with an outside resource.

15:24 But the API for this is very, very simple and very powerful and I got to try it out.

15:30 Yeah, I hadn't heard of request mock requests mock and that sounds like super useful because you're right, that's one of the places if you're doing testing, you really don't want to have to set up the service and configure it in test mode or whatever.

15:42 Now that was dealing with APIs on the internet.

15:46 How about desktop applications?

15:48 Yeah, so let's talk about Python and desktop applications.

15:52 Certainly you can build interesting desktop applications.

15:56 You know, Dropbox is a real world example of, you know, probably the most widely deployed Python desktop app in the world because that client thing that I see spinning right now in my little notification bar, that is all Python.

16:10 Okay, Python 2.7, I believe they're working on upgrading to Python 3.

16:14 But right now it's 2.7.

16:15 And that's interesting, you can use a lot of different technologies.

16:18 But I kind of feel like there's just something missing to make Python a first class environment for building desktop applications.

16:28 So we've had TKender for a long time.

16:31 And that's sort of built in.

16:32 But I always feel like that looks, I don't know, super out of place, especially on like Mac or Windows.

16:37 It looks much more like it belongs in sort of a Unix/Linux space, but even there it doesn't look super fabulous.

16:44 It looks like the TK stuff that I was using with TCL when I was in college a long time ago.

16:50 Yes, exactly.

16:51 And it totally works and you can do it and so on.

16:53 So the thing I want to highlight is a Reddit conversation.

16:57 It's not a link, it's just a back and forth on Reddit.

17:00 What's the community's favorite for developing OS X applications with Python?

17:05 So there's a couple people that weighed in.

17:06 By far, I think PyQt came in as the most highly voted up.

17:14 And have you done anything with Qt?

17:16 I did a small project with it a long time ago.

17:18 Yeah.

17:19 The thing I like about Qt is the stuff that comes out of it looks native.

17:25 It's based on C++, so it starts super fast.

17:28 It feels like an app that belongs wherever it's running.

17:31 And I think that's cool.

17:32 The challenge with this is you've got PyQt, the package, and you've got PySide.

17:37 And these have been sort of competing, not entirely compatible ways of writing this code.

17:43 I think PySide is the better licensing model, but it's, if I recall correctly, it only supports Qt4 and Qt is on Qt5.

17:52 And so there's just all this sort of like, it almost works.

17:54 It's kind of hard to deploy Qt, like on the various machines.

17:58 It's sort of a heavyweight install and so on.

18:00 This should be getting better.

18:01 I think Qt, the company that runs Qt is bringing PySide back in and gonna modernize it, but that's not coming out until the end of this year, probably.

18:12 So one vote was for Qt, that was cool.

18:14 Another one was for TK, simple voice dependencies, but like we already talked about that.

18:19 Kivi, Kivi definitely got a vote, but Kivi is much more, it's not sort of desktop app feeling, it's more like, like almost like games.

18:28 I think its origins were in games.

18:30 So what you get is it doesn't really have a native feel, right?

18:34 So that's not that great.

18:35 I think some people are using it for kiosks and stuff.

18:39 Yeah, yeah.

18:40 And that's not bad. I know it does a great thing, great stuff on mobile as well.

18:44 There's some debate whether that was the right choice.

18:46 There's Toga, which is really cool, Toga from the B-Ware guys.

18:49 But it's also Toga is like real early, doesn't have support for all the APIs and stuff.

18:54 So I kind of want to point this out to just say like, you know, to keep raising the issue like, "Hey, Python community, it would be awesome "if there was something that was really clearly fantastic "for building apps where people say, "of course you should use this.

19:10 "It's as good as Swift for OS 10 apps.

19:13 "It's as good as WPF for Windows apps." Or whatever, it just feels native.

19:18 It's really all coherent.

19:20 And I just don't see that existing yet.

19:22 I think the B-Ware guys are the closest to it.

19:25 It was an interesting conversation.

19:27 - And you've brought it up before that it would, I think you brought it up on Twitter, that it'd be cool if we had something kind of like Electron.

19:32 - Yeah, for those of you who don't know what Electron is, Electron.js is a way to write apps that ship entirely bundled.

19:41 There's just a single thing you run.

19:43 It's an exe or a binary on Linux or a .app on Mac.

19:47 There's zero dependencies, and it runs Node.js as the sort of smarts, and it embeds its own copy of Chromium, the UI.

19:56 So it's basically you use HTML, JavaScript, and CSS to build your UI, and you can use frameworks that make it look native.

20:02 And then you've got Node as the backend to keep this all going.

20:06 There's a few projects that almost do this in Python.

20:08 Like there's one about Django that will let you like ship Django sort of backends that will create GUI-looking things where you're doing it with basically Django running locally.

20:20 you know, I don't really want my app to say, to you know, do you want this app to act as a server?

20:25 When I try to run it, and they'd be like, this is not supposed to be a server app, like, what kind of weird thing have I got a hold of here, right?

20:32 I want something that feels like it drops in, and it's basically indistinguishable from a native app.

20:37 And we can dream one, one step.

20:40 And that's a good good step in that direction is CX freeze, which lets you take Python code plus its dependencies and the Python implementation, and everything and package it into a real distributable and that just released version 501 in January. So that's cool to see that coming along. So that's one of the important building blocks at least.

20:57 Okay, that's cool.

20:59 Someday I dream of a future where, I don't know, there's some whizzy UI framework with a visual designer for Python.

21:06 It's interesting that I don't really think about that that much. But the, I mean, I spent, you spend so much time in interacting with elements on a desktop, even, even though we don't develop them very often.

21:19 Not to say it can't be done, I just think it could go up a couple levels and it would make a really big difference in the adoption of Python.

21:26 It's already growing super well, but if you could take over the desktop market with it as well, then who knows where it would go.

21:32 Maybe you should do that, Michael.

21:33 You could take it on.

21:34 Yeah, I have so much time.

21:36 It seems like a great idea.

21:37 Yeah, okay.

21:38 So, if you don't have time for that, what are you doing?

21:41 I'm working on my classes.

21:43 I'm actually working on some stuff that has these things we were talking about in mind.

21:48 sort of at the top of my mind, but I'm not ready to announce anything yet.

21:51 But cool projects that I'm working on, and I'm working on a special episode of Talk Python to Me.

21:58 We've got episode 100 coming up, so I have a special guest.

22:01 I'm not going to announce it until I release it, but that one's gonna be big.

22:04 - I can't believe it's been 100 already.

22:06 - I know, two years, amazing.

22:08 - Yeah, speaking of podcasts, I've got a couple coming up, hopefully pretty soon.

22:14 They just need edited.

22:16 Talk to some really great people.

22:17 And then I was interviewed on a podcast called Reflection as a Service.

22:23 And that was really fun to talk with somebody else about test-driven development.

22:28 And I think I talked about the testing column that I think I made up on the fly while I was talking with you one day.

22:37 - We're gonna make that a thing.

22:38 (laughing)

22:40 - So yeah, and then I'm still writing, so that's what I'm up to.

22:43 - Awesome, yeah, you got some good reviewers for your book, right?

22:46 - Yeah, definitely, a big chunk of the pytest core team has agreed to help out and make sure I don't say something stupid, so I appreciate that.

22:56 - Yeah, that's really excellent.

22:57 I feel like we've definitely given people a lot of information this week.

23:01 - Definitely, it's good.

23:02 - And pretty drama-free, so that's always nice.

23:05 - Yeah.

23:06 Well, thanks a lot for talking to me today.

23:09 - You bet, it was great to share this with you, Brian, and I'll catch up with you next week.

23:13 Thank you for listening to Python Bytes.

23:16 Follow the show on Twitter via @pythonbytes, that's Python Bytes as in B-Y-T-E-S.

23:21 And get the full show notes at pythonbytes.fm.

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

23:29 We're always on the lookout for sharing something cool.

23:32 On behalf of myself and Brian Auchin, this is Michael Kennedy.

23:35 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page