Python Bytes - #133 Github sponsors - The model open source has been waiting for?

Episode Date: June 5, 2019

Topics covered in this episode: Python built-ins worth learning Github sponsors and match Build a REST API in 30 minutes with Django REST Framework Dependabot has been acquired by GitHub spoof “N...ew features planned for Python 4.0” BlackSheep web framework Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/133

Transcript
Discussion (0)
Starting point is 00:00:00 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. And I'm Brian Ocken. And this episode is brought to you by DigitalOcean. Check them out at pythonbytes.fm slash DigitalOcean. More on that later. Brian, how you been? I'm doing well. How about you? I am as well. The summer is here. The weather is 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.
Starting point is 00:00:32 Everyone's got a little bit of a smile from the weather, I think. Yeah, definitely. It's nice. 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. Yep. There are a whole bunch of built-ins. And I'm highlighting an article from Trey Hunter called Python Built-ins Worth Learning. And this comes from, he does a lot of training new people into Python.
Starting point is 00:00:58 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 them, 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. And I think it's kind of a fun thing to look at
Starting point is 00:01:45 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 them 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 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 yeah enumerate stands out as like a super important one that you can You can have a lot of non-Pythonic patterns. Like if I want to do a loop over some collection and I want to print out like number one is this, number two is that. Kind of like generating this ordered list that he has right here on his article, right?
Starting point is 00:02:37 You might go, well, the for in loop doesn't work because I don't get the index or, you know, whatever, right? There's a bunch of nice little cases where enumerate really, really helps. Yeah, and there's a good list for somebody to read through. He 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.
Starting point is 00:02:58 I didn't know about any and all at first for if there's any values in a list that are true or making sure that all of them are true. Those sometimes are useful. And then I wanted to jump to a little bit. There's in his category of learn it later. There's a bunch of them, but one of the things in there is a get atter for get attribute. I kind of disagree. I think that you ought 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. Yeah.
Starting point is 00:03:32 Attribute of an object and it might not have that attribute, but you know what value you want anyway, getAtter is great. Yeah, I like using overloading getAtter for basically nicer dictionaries, maybe with default values. So we have default dict, 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 dot value, right, 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, like, dictionary, but then also implement git adder, you could actually add it so it has that nice little cleaner syntax, I think. Yeah, you can. I often just use dictionaries, but then I use the git accessor.
Starting point is 00:04:20 Yeah, exactly. That you can get a default for. Yeah, cool. So this is a good one. I definitely think it's 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
Starting point is 00:04:40 objects okay all those oh wait there's div mod what is div mod and for example right so it's kind of fun to just go through and see which ones like you do know because there's certainly some i don't yeah and it's also i think it's a fun article for people to bookmark and that's just as they're learning come back to every couple months and learn something new 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 like an ominous sign. I personally didn't see it that dark. I thought it was actually kind of a mixed bag.
Starting point is 00:05:15 But looking more into it, like the state of GitHub, I feel like this is probably a pretty positive thing in the end. Right? Do you remember that? Yeah. 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 how i would like to support you guys doing this we'll donate a dollar to a month
Starting point is 00:05:44 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 a massive 39 that year or something right like it just it's not a way in which people do those types of things. But I think Patreon legitimately works, right? At least for folks who are really like creators who are really like focused on that. I've seen some really successful people there. So GitHub has just launched this thing called Sponsors.
Starting point is 00:06:20 Have you heard of this? Yeah, and I'm pretty excited about it. I'm pretty excited about it too. And 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.
Starting point is 00:06:37 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 yeah that's pretty cool isn't it like a beta or something you can't just go sign up you've got to like 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. There's also some things about their matching funds and the fees.
Starting point is 00:07:12 Yeah, that's pretty sweet. So they said there will be no fees charged. All right. 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 like the world just has to accept 3% on all transactions apparently.
Starting point is 00:07:37 But I believe there's a little like star in the first year or something like that. Like I don't think that's a permanent thing. Also a little star in the first year, maybe not that like i don't think that's a permanent thing also a little star in the first year maybe not the first year of the program but first year of your sponsorship is github will match so suppose you get six thousand dollars uh no that's not yeah let's suppose you get six thousand dollars github will match up to five thousand of whatever you've gotten so you would actually get eleven thousand000 contributions that year. 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 is going to get doubled. So that's pretty cool. Yeah, I'm pretty excited about this. I think we need to wait till it becomes a little more public.
Starting point is 00:08:20 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 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, right? Like the Western world, right? So if I live somewhere where the average monthly income is 500 bucks, if I can get 500 bucks in contributions on GitHub, right, maybe that's like a better way to spend my time. I don't know. It could be really interesting there. Yeah. There should probably be like a list of Python people that are available for this so we could find them or something. Yeah, it'd be really cool if like, if there's some kind of list or
Starting point is 00:09:03 some people could maybe send it in or put it in the comments or something. That would be great. Yeah, what's next, Brian? One of the things I wanted to do is 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 it sounds like it'll fit within my lunch break so this is nice so it's been at garner and it includes like from the very beginning setting up a virtual environment setting up django then creating a model in a database with the django orm is it orm or orm
Starting point is 00:09:39 how do people normally say that i think it goes either way like sql and sql but i think i think orm is a little more popular at least in the spaces I've heard people talk about. 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?
Starting point is 00:10:05 I don't know what that is and how to serialize the data, but it's got pretty pictures and it goes through it in 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
Starting point is 00:10:17 to try to learn Django REST framework rather quickly. Yeah, 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 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
Starting point is 00:10:52 DigitalOcean, sign up, fire up their cluster, and it'll, you know, within a minute or two, you'll have your cluster up and running and you could just start issuing Kubernetes commands to it, running your containers over there and get your stuff all working. So definitely give that a shot. Check them out at pythonbytes.fm slash digital ocean, 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? I so dependabot is interesting the idea is that most open source stuff is built upon layers and layers and layers of little libraries right in python we have pi pi and if you pip install a thing you know that thing may pip
Starting point is 00:11:41 install three other things as dependencies and those may have two other ones right so if i pip install requests it's going to install even like five or six other little things that it needs to do its job for example right 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 right if i could say somehow put in my requirements files you know 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
Starting point is 00:12:22 and here's its changes and help us automatically upgrade to that that would be super cool yeah so that's basically what dependent bot does it looks at your requirements and it's not i believe it's not just for python like it could look at your npm for your static javascript and all that kind of stuff right so sort of spanning all the the different dependencies that you might have across even programming languages, you could say, hey, this week, there's a whole bunch of changes, and it will actually create a pull request. So check for updates, then it'll create a pull request for stuff that's out of date, individual pull requests for each dependency, right? That's kind of cool, I guess, if you can check them all off. And then basically, that should trigger your CI, right, as it does for
Starting point is 00:13:04 normal PRs, verify everything's working, you can check that should trigger your CI, right, as it does for normal PRs. Verify everything's working. You can check that in, accept, you know, merge it, and keep rolling. So that's pretty cool, huh? 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. Right, right. And probably the first step of your test is to create a virtual environment and pip install the requirements or npm in it or npm install them
Starting point is 00:13:25 or whatever you're going to do right 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 yeah that's actually pretty cool yeah so i think it's pretty awesome basically 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, right? 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.
Starting point is 00:14:05 But the service that both of these are providing is really valuable. Like on Monday mornings, I wake up, I go check my email, and I see all the changes. Sometimes they're super minor, like BodoCore has been updated. Like, okay, I don't really care that much, but I guess I'll accept that, right? But other times there's been some bug fixed or there was a security vulnerability that's been fixed and it's really helpful so just you know you get in the habit of just like accepting the merge the pull requests once a week or whatever and it's good 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 yeah pretty easily yeah Yeah, absolutely. And then the act of actually quickly rolling back
Starting point is 00:14:45 is just to revert requirements.txt or the pyproject.toml or whatever it is. It's a minor, minor change. Cool. We've talked a lot about legacy Python, modern Python, Python 2 versus Python 3. We've kind of moved beyond
Starting point is 00:15:01 that debate, or have we? Well, I don't know i was wondering questioning whether it was too painful still but you know the transition's been going on for a while so i think it's okay to joke about it and uh i think it's a guy named charles lifer he's the the person behind the peewee orm or i am but he wrote an article called New Features Planned for Python 4, 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.
Starting point is 00:15:38 He has a long list of things that are humorously going in 4.0 that are not really. So PEP 8 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 a half. Nice. You can only put skinny characters on the last part, like an exclamation or a dot, but definitely not like a zero. Yeah, no. Or a capital Z dot, but definitely not like a zero. Yeah, no, no.
Starting point is 00:16:05 Or a capital Z. You can't do that. Nope. So all new libraries and standard lib modules must include the phrase for humans somewhere in their title. I agree. Type hinting has been extended to provide even fewer tangible benefits and will be called type whispering.
Starting point is 00:16:22 I do like that name. 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 notable items left out of 4.0 still no switch statement and absolutely no improvements to packaging that's pretty funny i like it i like it yeah that's uh that's a good article yeah i don't know 89 and type whispering a type whispering is pretty sweet all right so last item i want to cover for us today is something called black sheep now i felt like for a long time like the web framework story in Python was fairly stable.
Starting point is 00:17:06 Django, Flask, Pyramid, some of the other stuff, Bottle, and a few things had kind of been around. 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's just like unleashed all these little web frameworks, right? So we've got Molten, Sanic, Gepronto, 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 micro framework. So it has both the server side and the client side.
Starting point is 00:17:50 So it's both like trying to be kind of a replacement for Flask, but also for requests. Okay. Yeah. And it's built on AsyncIO and Cython, which we talked about last week, UV loop and HTTP tools. 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. And this, I think, is one of the more interesting parts of just thinking about these web frameworks. If somebody were to ask
Starting point is 00:18:18 you, Brian, which one is more popular, Django or Flask? I don't know. Do you have a sense of where that might land? No no i think the latest stats put it just pretty much even right both of them at like 40 or something like this right and i think actually flask is like growing faster than django so i think flask is maybe a little more it's maybe a little bit more of a vote in that because it's both like it's raw numbers are matching but now it's also i think growing quickly. But what is really interesting here is so many of these new little frameworks basically take the flask API and give it like 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 equals application or black sheep dot application,
Starting point is 00:19:06 black sheep dot server dot application, I guess. And then I say at app dot route on some web function, right? But there's a couple of differences, right? Also, so I could say async def function, because it's async enabled natively based on UV loop, which is probably the best option. And you also pass in the request objects instead of not. So what I think is really interesting is like 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's like could be better deficient or we
Starting point is 00:19:43 just like this better over and over and over. So's like all these little flask like api so in that sense i think flask is sort of winning the api side of the the world 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 application 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 all right right so yeah i think you're right i think that that is generally the trend that people people use django for larger stuff they probably
Starting point is 00:20:30 appreciate the back-end admin section and things like that all right so for black sheep let me just talk about a few interesting things so it has like built-in support for multi-processing which is cool it has like its own middleware uh 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 like bits of response over time so like it can come down progressively to the browser or the consumer it uses the yield keyword for that that's pretty killer right yeah it has special strategies for handling exceptions automatic binding of route and career 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
Starting point is 00:21:19 ssl behavior by default and it uses HTTP connection pooling. So much like async or AIO HTTP client rather than it is like requests. So it's kind of like your joke. You have to create async with block to create a client and then you can call like get, post, put, all that kind
Starting point is 00:21:40 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 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. Yeah, and it'll be interesting to watch. We're in an interesting place
Starting point is 00:21:52 where we can just see how many of these are going to be still around in two or three years. That's a real challenge. I think about like, would it make sense to create content around some of these various libraries or write articles or just, you know, whatever, use them potentially. It's great that a thousand little flowers are blooming, but you know, the lawnmower is coming, right? They won't all exist. They won't all be
Starting point is 00:22:16 kept up. And you know, if there's 20 little web frameworks, each with a hundred or a thousand GitHub stars, like what ones are going to last? So I don't know. I don't even know if they have to last, right? Like, I think some of these ideas could be really interesting. Like, okay, 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.
Starting point is 00:22:37 And eventually, like, well, it's not different enough from Flask anymore that we'll just keep using Flask, right? But I think these little experimentations are super cool, and that's why I wanted to highlight it. Yeah, I think so too. And I do look forward to seeing what the Flask equivalent of like the efficient, if it's Flask or whether it's something else that's sort of the de facto standard for if you want something like Flask but asynchronous, what do you use? Yeah, it's definitely cool to see a lot of options out there. Well, that's it for
Starting point is 00:23:03 our main items, right? Anything else you want to touch on? I don't have anything extra. How about you? 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.
Starting point is 00:23:24 So you can suggest uh nominate people uh now you can submit a nomination and on june 7th the election will actually begin so until june yeah until june 1st you can nominate anyone and i believe they've changed the rules around who can be nominated to just like 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. Neat. So also on that same page, I realized that I knew about this before, but it kind of pointed out it says you can contribute to the PSF by purchasing a PyCharm license
Starting point is 00:24:01 and all proceeds benefit to the PSF. So I think this is like 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 because they got to pay people and whatnot. That's neat. Yeah, that's a pretty good deal. So yay JetBrains for doing that. That's great. And then I guess two other really quick ones. Just want to remind people that if they want to take some of my classes,
Starting point is 00:24:33 they can go to training.talkpython.fm slash 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 10 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,
Starting point is 00:25:05 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. Is that one of those things where if I sign up and get emails about it, but I can't actually watch it during the webcast, can I watch it later? Yeah, you should be able to. And actually, honestly, it should just be – I'm doing this with a collaboration with Wintelect, it just should be on their youtube channel like a couple days
Starting point is 00:25:28 later even if you don't sign up but yeah sign up and you'll get notified yeah cool thanks yep you bet well that was all serious but we also have some jokes yeah so you know how i like to pick on you because you're a fan of him yeah but in a very uh nice and uh warm-hearted way so i've chosen a couple of things that I feel like might touch on that theme. Yeah, they're good. In programming, how do you generate a random string? Use the random module. One option. Or you put a first-year computer science student in Vim and ask them to save and exit. This is funny. So another one is, imagine you're at a restaurant. Some guy falls over. He starts choking.
Starting point is 00:26:05 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. That doesn't make any sense. It's the programming equivalent of how do you know if someone is a marathon runner? I don't know. Don't worry, they'll tell you. Okay. one is a marathon runner uh i don't know don't worry they'll tell you okay so i was chuckling about these uh the other day and i tried to describe it to my daughter my nine-year-old
Starting point is 00:26:31 daughter i knew that i had to like get some backstory and i said so this is sort of funny because in vim if especially you're in your you're in terminal mode you save an exit by doing escape colon WQ. And if you're really serious about it, an exclamation point also. She's like, that's a terrible interface. She has a good sense. How interesting. Funny, funny. Cool.
Starting point is 00:26:59 All right. Well, thanks for the laughs and covering all these items as always. Yeah. Thank you. Yeah. Thank you for listening to Python Bytes. Follow the show on Twitter via at Python Bytes. That's Python Bytes as in B-Y-T-E-S.
Starting point is 00:27:12 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 Ocken, this is Michael Kennedy. Thank you for listening and sharing this podcast with your friends and colleagues.

There aren't comments yet for this episode. Click on any sentence in the transcript to leave a comment.