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
Akin. 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.
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. 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,
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 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.
Yeah.
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? You might go, well, the foreign 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'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 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 attr 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. If you're going to get an attribute of an object and it might not have that
attribute, but you know what value you want anyway, get attr is great. Yeah. I like using overloading get
attr for basically nicer dictionaries, maybe with default values. So we have default dict and we have
some other things like regular dicks 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 get attr, 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 get
accessor. Yeah, exactly. You can get a default for. 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 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 it'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. But and looking
more into it, like the state of GitHub, I feel like this is a 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 gonna 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 will donate a dollar to 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 says donate. And it probably reaped like 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 are
really like 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? 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. 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. Is 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.
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. 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 the first year of the program, but first year of your sponsorship is
GitHub will match. So suppose you get $6,000. No, that's not. Yeah, let's suppose you get $6,000.
GitHub will match up to $5,000 of whatever you've gotten. So you would actually get $11,000 in
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.
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,
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 some people could maybe send it in
or put it in the comments or something. That would be great.
Yeah, cool.
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
within my lunch break. So this is nice. So it's Bennett 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? 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 Django REST framework, and then serializing the model.
Okay, I 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 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 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 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, 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/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?
I have not.
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 PyPI. And if you pip install a thing,
you know, that thing may pip 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 it 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. So 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. Yeah.
So that's basically what Dependabot does. It looks at your requirements. And it's not 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 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 just check them all off. And then basically, 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, 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, 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. 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 Bodo Core 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 pretty easily.
Yeah, yeah, absolutely. And then like, yeah, the act of actually quickly rolling back is just to like,
requirements.txt, or the pyproject.toml, or whatever it is, right? 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?
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 I think it's
a guy named Charles Leifer. He's the person behind the PeeWee ORM, but he wrote an article called
New Features Plan 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 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.5.
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 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.
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 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 a good article.
Yeah.
I don't know.
89 and type whispering.
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.
Django, flask, pyramid, some of the other stuff, bottle, and a few things had kind of been around
and they, 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 has just like unleashed all these
little web frameworks, right? So we've got molten, Sanic, Jepronto, a whole bunch of others,
API star. Well, there's another one called black sheep that is here and people can check that one out.
So black sheep looks pretty cool. It is a fast HTTP server and client micro framework. So it has both the server side and the client side. 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, like, and I, 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?
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 more 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 black sheep, I get, I say app equals application or black sheep dot application, 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 just like this better over and over and over.
So there's like all these little flask like API. So in that sense, I think flask is sort of winning the API side of 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 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.
Right, right.
Yeah, I think you're right. I think that 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 like built in support for multi processing, which is cool. It has like its own middleware, 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 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 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 it like 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.
Yeah. And it'll be interesting to watch. We're in an interesting place where we can like 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 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. 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 official, 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.
Yeah.
What do you use?
Yeah, it's definitely cool to see a lot of options out there. Well, that's it for 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. So you can suggest, nominate people now. You can submit a nomination. And on June 7th, the election will actually begin.
So 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 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, 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 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 ingrok 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.
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?
Yeah, I should be able to. And actually, honestly, it should just be I'm doing this with the collaboration with Wentelect and it just should be on their YouTube channel like a couple days 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 Vim?
Yeah.
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.
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. 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. 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 like get some backstory. And I said, so this is sort of funny because in Vim, if especially you're in terminal mode, you save and exit by doing escape, colon, WQ.
And if you're really serious about an exclamation point also. And she's like, that's a terrible interface.
She has a good sense. How interesting. Funny, funny. Cool. 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. 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.