Brought to you by DigitalOcean - grab your $50 credit and deploy your first project for free


« Return to show page

Transcript for Episode #133:
Github sponsors - The model open source has been waiting for?

Recorded on Thursday, May 30, 2019.

0:00 KENNEDY: Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is Episode 133. Recorded May 30th, 2019. I'm Michael Kennedy.

0:10 OKKEN: And I'm Brian Okken.

0:11 KENNEDY: And this episode is brought to you by Digital Ocean. Check them out at pythonbytes.fm/digitalocean. More on that later. Brian, how you been?

0:18 OKKEN: I am doing well. How about you?

0:19 KENNEDY: I am as well. The summer is here. The weather's nice, getting to finally emerge from being stuck by the rain inside for all these years, or all these months I guess in Portland, so very, very happy. Everyone's got a little bit of a smile from the weather I think.

0:34 OKKEN: Yeah, definitely, it's nice.

0:36 KENNEDY: You know what I think also might make you smile, is knowing that a bunch of cool features are already included in Python before you have to even go grab a library.

0:44 OKKEN: Yep, there are a whole bunch of built-ins, and I'm highlighting an article from Trey Hunner called Python built-ins worth learning, and this comes from, he does a lot of training new people a lot into Python, and some people sometimes feel a little overwhelmed about all the stuff they need to learn. This is an interesting quote he has, he said there's 69 built-in keywords or built-in functions with Python. There's more keywords, but anyway, he said he estimates that most developers only need about 30 of 'em, but the 30 that you need is different depending on what you're doing, and I think that's probably fair. So he split all of these 69 keywords into a bunch of categories. I guess there's five categories, commonly known, overlooked by beginners, learn it later, and maybe learn it eventually, and you'll likely not need these, and for the most part I agreed with him. I think it's kind of a fun thing to look at especially somebody new to the language or if you're helping somebody out. I'm not going to go through the entire list, it's a big list, but I wanted to highlight a couple of 'em. The ones that he said are often overlooked by beginners are sum, enumerate, zip, bool, reversed, sorted, min, max, any, and all, and of those I think people will figure out that there's probably a way to do this but the zip feature is something that people don't get right away and so practicing that a little bit is good. Enumerate also, but be careful.

2:20 KENNEDY: Yeah, enumerate stands out as like a super important one that you could have a lot of non-Pythonic patterns, like if I want to do a loop over some collection and I want to print out number one is this, number two is that, kind of like generating this ordered list that he has right here in his article, right? You might go, well, the for in loop doesn't work because I don't get the index, or whatever, right? There's a bunch of nice little cases where enumerate really, really helps.

2:45 OKKEN: Yeah, and this is a good list for somebody to read through. He's also got descriptions of all of them, it's a fairly lengthy article but it reads pretty quick. All the stuff you already know you'll just skim past and the stuff that you don't stands out. I didn't know about any and all at first, for if there's any values in a list that are true or are making sure that all of them are true. Those sometimes were useful. And then I wanted to jump to a little bit, in his category of learn it later, there's a bunch of 'em but one of the things in there is getattr, for get attribute, I kind of disagree. I think that you got to learn that a little bit earlier because the behavior of getting an attribute and then defaulting to a different value is very important and it's hard to do otherwise. If you're going to get, yeah, attribute of an object and it might not have that attribute, but you know what value you want anyway, getattr is great.

3:41 KENNEDY: Yeah, I like using, overloading getattr for basically nicer dictionaries maybe with default values, so we have DefaultDict and we have some other things like regular dicts and so on, but if you want to kind of treat them like JavaScript type of objects where you can just say object.value, you can't do that with normal dictionaries. And even with default dictionaries you can't make it give the default value, but if you say derive from dictionary but then also implement getattr you could actually add it so it has that nice little cleaner syntax, I think.

4:15 OKKEN: Yeah, you can. I often just use dictionaries but then I use the get accessor,

4:21 KENNEDY: Yeah, exactly.

4:21 OKKEN: that you can get a default for.

4:23 KENNEDY: Yeah, cool, so this is a good one. I definitely think it's worth skimming over, even as somebody who's not a beginner it's kind of like all right, well, here, let's try this. So here's the ones I likely don't need or maybe I don't really know, let me go through and see what I know. Well there's round, I know that one, there's abs and hash and object, okay, all those, oh wait, there's divmod, what is divmod, and for example, right? So it was kind of fun to just go through and see which ones did you know, 'cause there's certainly some I don't.

4:48 OKKEN: Yeah, and it's also, I think it's a fun article for people to bookmark and just as they're learning come back to every couple months and learn somethin' new.

4:56 KENNEDY: Yeah, absolutely. So a while ago, Brian, we spoke about GitHub being acquired by Microsoft, and that actually created quite the kerfuffle. A lot of folks saw that as an ominous sign. I personally didn't see it that dark, I thought it was actually kind of a mixed bag, but looking more into it, the state of GitHub, I feel like this is probably a pretty positive thing in the end. Right, do you remember that? We're starting to see consequences, outcomes, benefits, however you want to perceive this next round of announcements, but there's actually two announcements that I'm going to highlight in the show about that and the first one is, I think is really cool. So for example, we have a Patreon for Python Bytes, and the way that works is people can say, "I would like to support you guys doing this, we'll donate a dollar or two a month.", whatever, right, something small like that, and there's been a lot of failed attempts for this in open-source. So like, "Hey, on my open-source Read the Docs I'm going to put a PayPal button that says Donate.", and it probably reaped like a massive $39 that year or something, right? It's not a way in which people do those types of things, but I think Patreon legitimately works, at least for folks who are really, creators who are really focused on that, I've seen some really successful people there. So GitHub has just launched this thing called Sponsors. Have you heard of this?

6:21 OKKEN: Yeah, and I'm pretty excited about it.

6:22 KENNEDY: I'm pretty excited about it too, and at first when I first heard the news, I thought okay, GitHub Sponsors is a way to sponsor open-source projects. So maybe I'm a big fan of Flask, so I go to Flask, and I can give money to them, or maybe I'd like to see Pyramid doing more, so I'll go donate some money to Pyramid, or something like that, but it turns out it is like this Patreon model for GitHub, but it's not just for projects, it's also for people, which I thought was pretty cool. So anyone who contributes to open-source, whether through code, documentation, leadership, mentorship, design, is eligible to be sponsored.

6:56 OKKEN: Yeah, that's pretty cool. Isn't it in a beta or something?

7:00 KENNEDY: You can't just go sign up, you've got to request early access or I don't know what the terminology they used there was, but yeah, it's not fully open, but it's getting started.

7:08 OKKEN: There's also some things about their matching funds and the fees.

7:12 KENNEDY: Yeah, that's pretty sweet. So they said there will be no fees charged. Like Patreon, I don't know what they take, like 7%, 10%, something like that to run Patreon as part of what they donate, so GitHub says 100% of the fees go to developers, or 100% of the money that's given goes to developers. There's no fees other than credit card fees which the world just has to accept 3% on all transactions apparently, but I believe there's a little star, in the first year, or something like that, I don't thing that's a permanent thing. Also a little star, in the first year, maybe not the first year of the program but the first year of your sponsorship, is GitHub will match. So suppose you get $6000, no that's not, yeah, let's suppose you get $6000, GitHub will match up to $5000 of whatever you've got so you would actually get $11,000 in contributions that year.

8:03 OKKEN: That's really cool, and it also encourages people to even donate a small amount to a developer that they depend on because they know that that money's going to get doubled, so that's pretty cool.

8:15 KENNEDY: Yeah, I'm pretty excited about this. I think we need to wait 'til it becomes a little more public. I haven't seen anywhere I can go sponsor somebody, it's more like, hey, sign up, and I think they're building the list of people to be sponsored, but yeah, this is super cool news and I'm excited about it. I wonder how this will, if this will make open-source even more viable in countries that don't have the same cost of living, but also not the same income levels as, say, the US and Europe, the Western world. So if I live somewhere where the average monthly income is 500 bucks, if I can get 500 bucks in contributions on GitHub, maybe that's a better way to spend my time, I don't know. It could be really interesting there.

8:54 OKKEN: Yeah. There should probably be a list of Python people that are available for this so we could find 'em or somethin'.

9:01 KENNEDY: Yeah, it'd be really cool if there is some kind of list, or some people could maybe send it in or put it in the comments or somethin', that would be great.

9:07 OKKEN: Yeah, cool.

9:07 KENNEDY: All right, yeah. What's next Brian?

9:09 OKKEN: One of the things I wanted to do was play with some REST frameworks, and so I ran across this article called Build a REST API in 30 minutes with Django REST Framework, and that sounds like it'll fit within my lunch break, so this is nice. It's from Bennett Garner, and it includes from the very beginning. Setting up a virtual environment, setting up Django, and then creating a model in a database with the Django ORM. Is it ORM or O-R-M? How do people normally say that?

9:41 KENNEDY: I think it goes either way, like SQL and S-Q-L, but I think O-R-M is a little more popular, at least in the spaces I've heard people talk about it.

9:48 OKKEN: And then setting up, installing and setting up the Django REST framework, and then serializing the model. Okay, see, I haven't read the article yet completely, so I'm not sure what this means, but then creating URI endpoints, is that universal resource, I don't know what that is. And how to serialize the data, but it's got pretty pictures and it goes through a little example of a hero database with a hero name and alias, so it's a fairly simple toy model, but I'm going to use it to try to learn Django REST framework rather quickly.

10:19 KENNEDY: Yeah, and that's cool, yeah, Django REST framework looks nice. I haven't done a whole lot with it, but it definitely seems nice, and this is a really good introduction, so well done Bennett. Speaking of well done, before we move on to the next news about GitHub, let me just tell you a little bit more about DigitalOcean. So DigitalOcean has now made their Kubernetes, their managed Kubernetes cluster generally available, so if you're trying to do Docker and containers and basically run your containers in production, Kubernetes is a super good option for that. And so all you got to do is go over to DigitalOcean, sign up, fire up their cluster, and it'll, within a minute or two you'll have your cluster up and running, and you can just start issuing Kubernetes commands to it, running your containers over there and get yourself all working. So definitely give that a shot. Check them out at pythonbytes.fm/digitalocean, get a $50 credit for new users, so help support the show and they're doing good stuff, we can definitely recommend it. I told you I have two pieces of news on GitHub, and the second one is that, have you heard of Dependabot?

11:22 OKKEN: I have not.

11:23 KENNEDY: So, Dependabot is interesting. The idea is that most open-source stuff is built upon layers and layers and layers of little libraries. In Python we have PyPI, and if you pip install a thing, that thing may pip install three other things as dependencies, and those may have two other ones. So if I pip install requests, it's going to install five or six other little things that it needs to do its job, for example. So knowing, is there some kind of security problem, or is there even just a new version that maybe I would like to have of that? Would be really nice to know. If I could say, somehow put it in my requirements files, pin the versions in your requirement files which is a good idea for apps, maybe not for libraries, but definitely for apps to say these are the versions I'm working with in my website or whatever. If GitHub could say, "Hey, you know, there's a new version of the Stripe API, the Stripe package, and here's its changes.", and help us automatically upgrade to that, that would be super cool. So that's basically what Dependabot does. It looks at your requirements, and I believe it's not just for Python, it could look at your npm for your static JavaScript and all that kind of stuff, so sort of spanning all of the different dependencies that you might have across even programming languages. It could say, "Hey, this week there's a whole bunch of changes.", and it will actually create a pull request. So, checks for updates, then it'll create a pull request for stuff that's out of date, individual pull requests for each dependency. That's kind of cool I guess, if you can just check 'em all off. And then basically that should trigger your CI, as it does for normal PRs. Verify everything's working. You can check that in, accept, merge it, and keep rollin'. So that's pretty cool, huh?

13:11 OKKEN: Yeah, definitely. If you got your CI set up to test all merge requests then it'll just go ahead and run your tests against it and make sure that...

13:17 KENNEDY: Right, right, and the probably the first step of your test is to create a virtual environment and pip install the requirements, or npm inits, or npm install them, or whatever you're going to do. So that's all good, what does this have to do with GitHub? Well, GitHub has now bought Dependabot, which used to be a commercial, paid service, and now it's a free service of GitHub.

13:36 OKKEN: Yeah, that's actually pretty cool.

13:37 KENNEDY: Yeah, so I think it's pretty awesome. Basically it said, if you already have an account at Dependabot, well, that's free, and if you're not using it, you should definitely think about something to this effect. Think about using something like this, because I use something called PyUp, at pyup.io, and it's been around, a little more Python-focused, since maybe even before Dependabot, and I definitely like it. I'm not sure what this announcement means for it, it could be negative news for the PyUp folks, I would imagine, but the service that the both of these are providing is really valuable. On Monday mornings, I wake up, I go check my email, and I see all the changes. Sometimes they're super minor, like botocore has been updated, okay, I don't really care that much, but I guess I'll accept that, but other times there's been some bug fix or there was a security vulnerability that's been fixed and it's really helpful. So you know you get in the habit of just accepting the merge, the pull requests once a week or whatever, and it's good.

14:32 OKKEN: As you said, as they're coming in one at a time, and you're accepting them, if something goes through and starts breaking stuff you can roll back pretty easily.

14:42 KENNEDY: Yeah, yeah, absolutely. And then the act of actually quickly rolling back is just to revert requirements.txt or the pyproject.toml, or whatever it is, it's a minor, minor change. Cool. So we've talked a lot about legacy Python, modern Python, Python 2 versus Python 3. We've kind of moved beyond that debate, or have we?

15:00 OKKEN: Well, I don't know. I was wondering, questioning whether it was too painful still, but the transition's been going on for a while so I think it's okay to joke about it. And I think it's a guy named Charles Leifer, he's the person behind the peewee ORM, or O-R-M, but he wrote an article called New features planned for Python 4.0, and this is totally a spoof article, it's not real, but it's funny, and it made me laugh. So one of my favorites, I just pulled out a few of the favorites, he has a long list of things that are humorously going in 4.0 that are not really. So, PEP8 has been updated, there's the long, or will be updated, the long debate between whether or not you should have 79 characters or 100 characters. They're compromising at 89 and 1/2.

15:56 KENNEDY: Nice. You can only put skinny characters on the last part, like an exclamation, or a dot, but definitely not like a zero.

16:04 OKKEN: Yeah, nah, no. Or a capital Z, you can't do that.

16:07 KENNEDY: Nope.

16:07 OKKEN: So, all new libraries and standard lib modules must include the phrase "for humans" somewhere in their title.

16:13 KENNEDY: I agree.

16:15 OKKEN: Type-hinting has been extended to provide even fewer tangible benefits and will be called type whispering.

16:23 KENNEDY: I do like that name.

16:24 OKKEN: And you can make stuff go faster by adding async before every other keyword, including if, when, if, and all those things. You can just add async before everything. It'll make it go faster. And then notable items left out of 4.0, still no switch statement, and absolutely no improvements to packaging.

16:45 KENNEDY: That's pretty funny. I like it, I like it. Yeah, that's a good article. I don't know.

16:50 OKKEN: And type whispering.

16:51 KENNEDY: Type whispering is pretty sweet. All right, so last item I want to cover for us today is something called BlackSheep. Now, I felt like for a long time, the web framework story in Python was fairly stable. Django, Flask, Pyramid. Some of that other stuff, Bottle, and a few things had kind of been around and they were kind of doing their thing, but this whole need for modern asynchronous framework involving, say, maybe type-hinting for validation, or the async keyword, it's just unleashed all these little web frameworks. So we've got molten, Sanic, Japronto, a whole bunch of others. API Star, well, there's another one called BlackSheep that is here, and people can check that one out. So BlackSheep looks pretty cool, it is a fast HTTP server and client microframework. So it has both the server side and the client side, so it's both trying to be kind of a replacement for Flask, but also for Requests.

17:54 OKKEN: Oh, okay.

17:54 KENNEDY: Yeah, and it's built on asyncio and Cython, which we talked about last week, uvloop, and httptools, so it's kind of bringing in a lot of good stuff and one of the things you'll notice really quickly when you work with it is it's Flask-like. This I think is one of the more interesting parts of just thinking about these web frameworks. If somebody were to ask you, Brian, which one is more popular, Django or Flask? I don't know, do you, do you have a sense of where that might land?

18:23 OKKEN: No, no.

18:24 KENNEDY: I think the latest stats put it just pretty much even, right? Both admit 40% or something like this. All right, and I think actually Flask is growing faster than Django, so I think Flask is maybe a little more, it gets maybe a little bit more of a vote in that because it's both, its raw numbers are matching but now it's also I think growing more quickly. But what is really interesting here is so many of these new little frameworks basically take the Flask API and give it a solid hat tip, but then try to do their own thing. So for example, to create a web app in BlackSheep, I say app = application, or BlackSheep.application, BlackSheep.server.application I guess, and then I say @app.route on some web function. But there's a couple of differences also, so I could say async def function, because it's async enabled natively based on uvloop, which is probably the best option, and you also pass in the request object instead of not. So what I think is really interesting is Flask and Django, they're kind of neck and neck doing their battling, but all these other little frameworks seem to be like, "We're going to take Flask and change it a tiny bit in ways that we feel it could be better or deficient or we just like this better.", over and over and over. So there's all these little Flask-like APIs. So in that sense I think Flask is sort of winning the API side of the world.

19:52 OKKEN: Yeah, I don't even know if it's a fair comparison. I know you can do lightweight things in Django, and you can do large applications in Flask. But in general, they are in a different realm. Generally, I think that people are writing larger applications, more people are writing larger applications in Django and for the lightweight stuff you're going to use Flask or some of these other things. For instance there's probably a lot of Flask applications that absolutely have no front-end, they're REST-only.

20:22 KENNEDY: Right. Yeah, I think you're right, I think that is generally the trend that people use Django for larger stuff, they probably appreciate the back-end admin section and things like that. All right, so for BlackSheep, let me just talk about a few interesting things. So it has built-in support for multi-processing, which is cool, it has its own middleware. It has routing, much like Flask does. It uses some really interesting features, so for example you can have chunked encoding, where if I'm going to send bits of response over time, so it can come down progressively to the browser or the consumer.

20:56 OKKEN: Oh, that's cool.

20:58 KENNEDY: It uses the yield keyword for that. That's pretty cool right? It has special strategies for handling exceptions, automatic binding of route and query parameters, pass to the methods, automatic reloading, all sorts of stuff. And then like I said it also has this client option. So, it has user-friendly SSL behavior by default and it uses HTTP connection pooling. So much like aysnc, or AIOHTTP clients, rather than it is like Requests. So it's kind of like your joke, you have create an async with block to create a client, and then you can call on GET, POST, PUT, all that kind of stuff. But yeah, it's pretty cool. So it has sort of both sides of the story, and I guess you could just use only the server or only the client but they're kind of all together there.

21:50 OKKEN: Yeah, and it'll be interesting to watch. We're in an interesting place where we can just see how many of these are going to be still around in two or three years or.

21:58 KENNEDY: That's the real challenge. I think about would it make sense to create content around some of these various libraries, or write articles, or just, whatever, use them potentially. It's great that a thousand little flowers are blooming, but you know the lawn mower is coming. Right, they won't all exist, they won't all be kept up, and if there's 20 little web frameworks each with a hundred or a thousand GitHub stars, what ones are going to last? So, I don't know. I don't even know if they have to last. I think some of these ideas could be really interesting and maybe something that they're doing that's really cool here around like chunked encoding makes its way into Flask, and the async stuff makes its way into Flask, and eventually, well, it's not different enough from Flask anymore that we'll just keep using Flask, but I think these little experimentations are super cool and that's why I wanted highlight it.

22:46 OKKEN: Yeah, I think so too, and I do look forward to seeing what the Flask equivalent of the official, if it's Flask or whether it's something else that's sort of the defacto standard for if you want something like Flask but asynchronous, what do you use?

23:00 KENNEDY: Yeah, it's definitely cool to see a lot of options out there. Well, that's it for our main items, right? Anything else that you want to touch on?

23:06 OKKEN: I don't have anything extra, how about you?

23:08 KENNEDY: I got a couple of things. One, kick it off I guess with the PSF. So the PSF board elections, not to be confused with the steering council which is like the core developer management stuff, this is the PSF board itself. Those elections are starting to get going, so you can suggest, nominate people now. You can submit a nomination, and on June 7th, the election will actually begin, so, yeah, until June 1st you can nominate anyone, and I believe they've changed the rules around who can be nominated to just pretty much anyone that people want to nominate. So I think there might have been rules of how you had to participate previously to be eligible, but it seems like it's pretty wide open at this point.

23:51 OKKEN: Mm, neat.

23:52 KENNEDY: So, also on that same page, I realize that I knew about this before but it kind of put it out, it says, "You can contribute to the PSF by purchasing a PyCharm license and all proceeds benefit to the PSF". So I think this is a one month thing going on here, but if you buy a copy of PyCharm, you'll get apparently 30% off and all the profit, I'm guessing, goes to the PSF. Probably not revenue, 'cause they got to pay people and whatnot.

24:19 OKKEN: That's neat.

24:20 KENNEDY: Yeah, that's a pretty good deal. So. Yay JetBrains for doing that, that's great. And I guess two other really quick ones, just want to remind people that if they want to take some of my classes they can go to training.talkpython.fm/apps. Install one of the mobile apps, iOS or Android, and there's a couple of free courses in there, so people can check that out. And then one more reminder before it kicks off next week, I'm doing my webcast next week called Ten Tools and Techniques Python Web Developers Should Explore. So it has a bunch of ideas of things that maybe you've heard about, maybe you haven't, but if you're doing stuff on the web, you definitely should think about. So cool stuff like ngrok, or async, or database migrations, or Let's Encrypt, all those little things, a bunch of cool little tips. Some of the stuff we even found on the show, so that's free and that's around for next week.

25:12 OKKEN: Is that one of those things where if I sign up and get emails about it but I don't actually, can't actually watch it during the webcast, can I watch it later?

25:20 KENNEDY: Yeah, you should be able to. And actually, honestly, it should just be, I'm doing this with collaboration with Wintellect, and it just should be on their YouTube channel a couple days later even if you don't sign up. But yeah, sign up and you'll get notified, yeah.

25:31 OKKEN: Cool, thanks.

25:32 KENNEDY: Yep, you bet. Well that was all serious, but we also have some jokes. So. You know how I like to pick on you 'cause you're a fan of Vim? But in a very nice and warm-hearted way. So I've chosen a couple of things that I feel like might touch on that theme.

25:47 OKKEN: Yeah, they're good.

25:48 KENNEDY: In programming, how do you generate a random string?

25:51 OKKEN: Use the random module.

25:52 KENNEDY: One option, or you put a first-year computer science student in Vim and ask them to save and exit.

25:59 OKKEN: This is funny.

26:00 KENNEDY: So another one is imagine you're at a restaurant. Some guy falls over, he starts choking and the waiter runs over and goes, "Oh my gosh, he's choking! Is anyone here a doctor?" Some programmer stands up and goes, "Hey, I'm a Vim user."

26:15 OKKEN: It doesn't make any sense.

26:17 KENNEDY: It's the programming equivalent of how do you know if someone is a marathon runner?

26:21 OKKEN: I don't know.

26:22 KENNEDY: Don't worry, they'll tell you.

26:25 OKKEN: Okay. So I was chuckling about these the other day, and I tried to describe it to my daughter, my nine year old daughter. I knew that I had to give some backstory, and I said, "So this is sort of funny because in Vim, especially when you're in terminal mode, you save and exit by doing Escape, colon, W, Q, and if you're really serious about it, an exclamation point also." And she's like, "That's a terrible interface!"

26:55 KENNEDY: Ah, she has a good sense. How interesting. Funny funny, cool, all right, well, thanks for the laughs and covering all these items, as always.

27:03 OKKEN: Yeah, thank you. Bye.

27:05 KENNEDY: Thank you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes. That's pythonbytes as in B-Y-T-E-S. And get the full show notes at pythonbytes.fm. If you have a news item you want featured, just visit pythonbytes.fm and send it our way. We're always on the lookout for sharing something cool. On behalf of myself and Brian Okken, this is Michael Kennedy, thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page