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:22 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 IO walkthrough.

00:34 And here's the story.

00:35 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:44 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.

00:59 called A Web Crawler with AsyncIO Coroutines.

01:02 And it's a pretty cool chapter about explaining asynchronous networking, showing how non-blocking sockets work,

01:11 and how Python 3 coroutines improve asynchronous network programs.

01:16 Yeah, that's really cool.

01:16 Yeah, that's really cool.

01:17 I think that that book is amazing.

01:19 It's not just this particular chapter.

01:21 There's many chapters.

01:22 It's also not just Python, but it has a heavy, a lot of pieces which are Python.

01:28 And basically, it's, can you show me something amazing that really, I thought was really hard,

01:35 how it 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:44 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.

01:55 And it's a neat thing they're doing.

01:58 But this particular chapter for me, since I'm kind of new to the asynchronous world,

02:05 it still was a little bit heavy to get into.

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

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

02:16 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:26 He interviews people just kind of generally in the programming space.

02:30 So what he did was, it's pretty cool.

02:32 He just is walking through this article and talking about it and then also,

02:38 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.

02:55 And I really appreciate it.

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

03:04 I really like that.

03:05 I think this is great work.

03:06 Nice work, Philip.

03:07 Way to go.

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

03:10 The reason I had him on episode 22 of Talk Python was he did this thing called CPython, a 10-hour code walk,

03:19 which was like an exploration through the CPython internals, which I found really enlightening.

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

03:29 when we talked about writing as a developer.

03:32 He's got some really cool thinking around, like design patterns on technical writing and stuff.

03:38 So this is really cool.

03:40 I think seeing a problem unfold before your eyes in code is much different than seeing the finished product discussed.

03:46 And I find I learn really well that way.

03:49 So I'm happy this is here.

03:50 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.

03:59 Jesse's been supportive of a lot of people, including me.

04:02 Yeah, absolutely.

04:03 Jesse's doing great stuff.

04:04 Do you want to think about the future of Python a little bit?

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

04:12 So, but what do you think the future has in store?

04:15 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 Sirdar Yagulap, I'm sorry, I'm sure I messed up your name, wrote an article and it's called Four Likely Future Twists for Python.

04:38 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:52 But the first one that they put out there is that Python 2x may live on.

04:56 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:03 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.

05:13 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.

05:21 You know, you think of places like Bank of America.

05:23 They've got, gosh, I don't remember the exact stats, but I was talking to Mahmoud Hashemi 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 2.7.

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

05:39 Like 5 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:48 Supporting your own Python, that just doesn't sound fun.

05:51 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.

06:01 That there'll probably be somebody that forks Python 2 and tries to keep it going.

06:05 Whether that turns out to be beneficial or, you know, trading one set of problems for a worse set of problems, we'll see.

06:11 Yeah.

06:12 The other one was, this one I had no visibility into.

06:16 I didn't see this coming.

06:18 And I read the title and I said, requirements.txt may be replaced with something better.

06:24 I thought, what?

06:25 Okay, well, maybe.

06:26 It turns out the guys over at the Python Packaging Authority, that's the PyPI and pip and all those projects.

06:35 So there's an organization, a group of people that actually work on that.

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

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

06:46 That's interesting.

06:48 Isn't it?

06:48 Yeah.

06:49 And so the idea is that pip File is going to be better or superior to requirements and that it has a TML 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.

07:03 So you don't have like a dev requirements, a test requirements, a prod requirements, and so on.

07:08 Yeah, it's cool.

07:09 You can do like a pip File freeze on it.

07:13 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.

07:35 I want to use it against this source, like pypi.org.

07:39 Or you could create your own devpy server thing and run it internally.

07:43 And that would be part of your requirements file.

07:45 So lots of cool enhancements there.

07:47 I'm interested to see where it goes.

07:49 But it's out there on GitHub.

07:50 You can actually check it out.

07:51 Yeah, I'd like to make sure it sort of goes along the lines 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:08 So we've got things like Anaconda and InThot.

08:12 And Intel actually has their own Python implementation that is sort of a repackaging and tweaking of the Anaconda distribution.

08:21 But just talking about how there may be more variations of Python distributions focused on enterprise needs.

08:29 Maybe.

08:30 I certainly see it happening in data science.

08:32 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.

08:49 So PyPI basically could get enterprise-friendly package management.

08:53 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.

09:05 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.

09:20 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.

09:27 Sounds interesting.

09:28 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.

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

09:39 A lot of people use NumPy.

09:41 There's a new book, an open source book called From Python to NumPy.

09:47 And it's from, I think this is a French person, Nicolas Rogier.

09:51 The book is pretty interesting.

09:53 It takes the assumption that you already know Python.

09:56 You're an intermediate developer.

09:57 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.

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

10:08 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 going to shell out $2,000 for MATLAB?

10:20 Well, you know, maybe look at some of the Python tools, right?

10:23 It's definitely growing.

10:24 Yeah.

10:24 You know, it's cool for us to think about the future, but what if like machines could think about the future?

10:30 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,

10:40 but actually something that's starting to take shape in the present.

10:43 Yeah.

10:44 And it now affects everybody with all of their speaking devices.

10:47 Yeah.

10:48 And, you know, we could be mean and we could say, hey, Amazon thing, order us.

10:54 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:00 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:10 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,

11:18 and then they will let it play literally thousands of video games.

11:22 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.

11:30 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.

11:42 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.

11:54 But here's all these environments in which you can train and test AIs.

11:58 What do you think?

11:59 It sounds like tic-tac-toe and global thermonuclear war to me.

12:05 Hello, Dr. Falcon.

12:06 Would you like to play a game?

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

12:16 Why would you care about this, right?

12:18 Like, well, maybe you're working on a robot and you want to teach the robot to walk around and interact with the world.

12:23 But you don't have the robot finished.

12:26 You could take the smarts of the robot and let it play Counter-Strike or, you know, something for until it gets really good at like not bumping into stuff, like making it through paths.

12:37 And then you could just plug that into your robot.

12:38 I don't know.

12:39 Something like, I mean, this is, this is me totally speculating on the spot.

12:42 I don't know.

12:42 Yeah.

12:43 Just don't give your robot a gun.

12:44 Yes, exactly.

12:45 Because it's going to be really good at it at that point.

12:47 Yeah.

12:48 All right.

12:49 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 don't know, is downloaded 7 million times a month.

13:05 Yeah.

13:06 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:17 I've just known about him for a long time.

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

13:26 But it's not.

13:27 It's, 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 HTTP lib.

13:38 So he wasn't even using URL lib2 or anything.

13:42 HTTP lib into requests.

13:45 And this project was Apache lib cloud.

13:49 with, it 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.

14:05 And had one connection class that did the encoding and decoding of everything.

14:10 And converted this all.

14:12 And this article is about all the stuff he had to deal with.

14:15 Like dealing with sessions, dealing with authentication, how we test it, doing prepared requests, streams.

14:22 It's just a chock full of stuff.

14:25 And it's not even that long of an article.

14:26 So I think he did a good job.

14:27 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 lib cloud on podcast init.

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

14:40 And that's, that's really cool.

14:41 It's a cool project.

14:42 And this sounds like a 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:58 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 mock 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.

15:18 And, you know, an HTTP request clearly is dealing with an outside resource.

15:23 But the API for this is very, very simple and very powerful.

15:29 And I got to try it out.

15:30 Looks neat.

15:30 I hadn't heard of request mock, requests mock.

15:33 And that sounds like super useful.

15:35 Cause you're right.

15:35 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:41 Now that was dealing with APIs on the internet.

15:45 How about desktop applications?

15:48 Yeah.

15:48 So let's talk about Python and desktop applications.

15:51 I certainly, you can build interesting desktop applications.

15:55 You know, Dropbox is a real world example of, you know, probably the most widely deployed Python desktop app in the world.

16:03 Cause that client thing that I see spending right now in my little notification bar, that is all Python.

16:10 Okay.

16:11 Python two, seven, I believe they're working on upgrading to Python three, but right now it's two, seven.

16:15 And that's interesting.

16:16 You can use a lot of different technologies, 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 TK Ender for a long time and that's sort of built in, 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 a, and 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 Exactly.

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

16:53 So there's what the thing I want to highlight is a Reddit conversation.

16:56 It's not a link.

16:57 It's just a back and forth on Reddit.

16:59 What's the community's favorite for developing OS 10 applications with Python?

17:04 So there's a couple of people that weighed in by far.

17:07 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 him a long time ago.

17:18 Yeah.

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

17:24 It's based on C++.

17:26 So it starts super fast.

17:27 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,

17:48 it only supports Qt4 and Qt is on Qt5.

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

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

17:58 You've got to, 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 going to modernize it.

18:08 But that's not coming out until the end of this year, probably.

18:11 So one vote was for Qt.

18:13 That was cool.

18:14 Another one was for TK.

18:15 Simple, avoids dependencies, but like we already talked about that.

18:19 Kivy, Kivy definitely got a vote.

18:21 But Kivy is much more, it's not sort of a desktop app feeling.

18:25 It's more like, like almost like games.

18:27 I think its origins were in games.

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

18:34 So that's, that's not that great.

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

18:39 Yeah, yeah.

18:39 And that's not bad.

18:40 I know it does a great thing, great stuff on, 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.

18:47 Toga from the Beware guys, 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, like it would be awesome if there was something that was really clearly fantastic for building apps.

19:08 It's where, where people say, of course you should use this.

19:11 It's as good as Swift for OS X apps.

19:13 It's as good as WPF for Windows apps or whatever.

19:17 It just, it 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 Beware guys are the closest to it.

19:25 It was an interesting conversation.

19:26 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.

19:33 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 .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:05 There's a few projects that almost do this on 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:19 You know, I don't really want my app to say, do you want this app to act as a server?

20:25 Yeah.

20:26 When I try to run it and they'd be like, this is not supposed to be a server app.

20:29 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.

20:39 One step that's a 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 redistributable.

20:50 And that just released version 501 in January.

20:53 So that's cool to see that coming along.

20:55 So that's one of the important building blocks at least.

20:57 Okay.

20:58 That's cool.

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

21:05 It is.

21:06 It's interesting that I don't really think about that that much.

21:09 But the, I mean, you spend so much time in interacting with elements on a desktop, even though we don't develop them very often.

21:18 Not to say it can't be done.

21:20 I just think it could go up a couple levels and it would make a really big difference in the adoption of Python.

21:25 Definitely.

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

21:31 Yeah.

21:32 Maybe you should do that, Michael.

21:33 You can take it off.

21:34 Yeah.

21:35 I have so much time.

21:35 That seems like a great idea.

21:36 Yeah.

21:37 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:47 It's sort of at the top of my mind, but I'm not ready to announce anything yet.

21:51 But cool, cool projects that I'm working on and I'm, I'm working on a special episode of

21:57 Talk Python to Me.

21:58 We've got episode 100 coming up.

22:00 So I have a special guest.

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

22:04 I can't believe it's been a hundred already.

22:06 I know.

22:06 Two years.

22:07 I'm amazing.

22:08 Yeah.

22:08 Speaking of, so podcasts, I, I've got a couple coming up, hopefully pretty soon.

22:14 They just need edited.

22:15 Talk to some really great people.

22:17 And then I was interviewed on a podcast called, reflection as a service.

22:22 And, and that was really fun to talk with, somebody else about, test driven

22:28 development.

22:28 And, and, I think I, I talked about the, testing column that I, I, I think I made

22:34 up on the fly while I was talking with you one day.

22:36 We're going to make that a thing.

22:38 So yeah, that's, and then I'm still writing.

22:42 So that's what I'm up to.

22:43 Awesome.

22:43 Yeah.

22:44 You, you got some good reviewers for your book, right?

22:46 Yeah, definitely that most of the, a lot, a big chunk of the pytest, core team has

22:50 helped, agreed to help out and make sure I don't say something stupid.

22:54 So I appreciate that.

22:55 Yeah.

22:56 That's, that's really excellent.

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

23:00 Definitely.

23:01 It's good.

23:02 And pretty drama free.

23:03 So that's always nice.

23:05 Yeah.

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

23:09 You bet.

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

23:14 Thank you for listening to Python Bytes.

23:15 Follow the show on Twitter via at Python Bytes.

23:18 That's Python Bytes as in B-Y-T-E-S.

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

23:24 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:31 On behalf of myself and Brian Okken, this is Michael Kennedy.

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

Back to show page