Transcript #11: Django 2.0 is dropping Python 2 entirely, pipenv for profile functionality, and Pythonic home automation
Return to episode page view on github00:00 This is Python Bytes. Python headlines and news delivered directly to your earbuds.
00:05 It's episode 11, recorded January 30th. This is Michael Kennedy. I'm here with Brian Okken.
00:10 Hey, Brian.
00:11 Hey.
00:11 Hey, you ready to talk about Python news and some cool things that we found this week?
00:15 I am. I've got a little bit of a cold, but I think we can get through it.
00:18 Yeah, I think you're going to be just fine. You sound totally good to me.
00:21 So hang in there for a short bit while we talk about these things.
00:25 So one of the things that makes Python fabulous is this so-called batteries included story, right?
00:31 And sometimes that means standard libraries. Sometimes that means PyPI and the 97,000 packages there.
00:37 And we're not done improving how we work with those, are we?
00:41 Yeah, no, we're not. And one of the things that came up this recently, I think it was last week,
00:46 is Kenneth Reitz announced a new tool that he wrote, I guess, over the weekend.
00:54 And called PIPenv, P-I-P-E-N-V.
00:59 And we'll link to both his announcement and a Reddit thread where people are talking about it.
01:05 Because there are other projects out there that do the same thing, or similar things.
01:10 This is a way to bring pip and virtual environments together in the same tool chain and also pip file,
01:20 which since we talked about pip file, I think it was last week.
01:25 Yeah, I think it was last time, yeah.
01:26 But I wanted to...
01:29 This is something I've just started using.
01:31 I just started using this PIPenv.
01:33 And so far, the normal...
01:37 Even just the simple environment of, you know, setting up a new directory for a project
01:44 and setting up a virtual environment, this has helped me just make that faster with just PIPenv install something,
01:53 and it creates a virtual environment.
01:54 And I like the PIPenv script, which...
01:59 Or PIPenv shell, which brings you into a shell terminal in that environment.
02:05 And that works with my workflow pretty good.
02:09 So supposedly, it automatically finds your project home recursively by looking for a pip file.
02:15 Yeah, so one of the things that's really cool about that is it will create a virtual directory in one of these pip files.
02:21 And if I'm reading this right, that means you don't have to activate your virtual environment to manage it in the particular shell, right?
02:28 You just have to be in the subdirectory somewhere, and then your package management commands with PIPenv
02:34 will apply to that virtual environment dedicated to that project.
02:38 Yes.
02:39 Which is really nice.
02:40 Yeah, and in order to...
02:42 Well, the magic of virtual environments where it switches out a different Python for you and different paths,
02:52 you still have to be activated with that, but that's where the PIPenv shell command comes in handy.
03:01 But you also don't actually have to be in that environment, like you said, to update the pip file.
03:06 And there's a run command where you can not go into the environment with your shell,
03:12 but just run a command within the environment.
03:15 Yeah, that's pretty sweet.
03:16 And it automatically adds basically to what would be the equivalence of your requirements.txt when you install a package
03:23 and automatically removes that requirement from the pip file, the new replacement for requirements.txt.
03:29 When you uninstall it and keeps your pip up to date, yeah, it's very cool.
03:33 And leave it to Kenneth to say, instead of watching television this weekend,
03:38 I completely rewrote how you manage packages in Python.
03:41 Yeah, well, we still depend on...
03:44 We're not...
03:45 The entire tool chain for Python hasn't gone over to pip file yet.
03:49 So we...
03:51 I mean, I don't know.
03:52 We still have to deal with requirements.txt.
03:55 So I'm not sure how...
03:56 I'm still not sure how this fits together, but I'll give it some more playing and we'll work on it.
04:03 So...
04:03 Yeah, sounds good.
04:04 It definitely looks promising, and I'm excited to start using it myself.
04:09 You know, one of the continuous messages that I think we are getting known for probably
04:14 is our advocacy of everybody moving forward to Python 3.
04:19 Yes.
04:20 You know, that's where all the core developers are focusing their effort.
04:24 That's where Guido Van Rossum is focusing his effort.
04:28 And, you know, to say we're all going to stay on Python 2 is really just kind of silly, I think.
04:33 We just got to kind of suck it up and go.
04:35 And there have been some interesting watershed moments that have made, like, big step changes
04:40 in the percentage of adoption of Python 3.
04:42 Obviously, the wall of superpowers and a lot of the packages there becoming Python 3 supported
04:48 or even having Python 3 only as an option for some of those is a big one.
04:52 Another one that comes to mind is something that Django did.
04:55 I can't remember when it was.
04:56 It was like a couple years ago where they switched the default instructions
05:00 in their getting started docs and tutorials to Python 3.
05:04 So they just, you know, said, okay, well, what you do is you start Python 3,
05:07 do the step, step, step, step, right?
05:09 That actually made, I was looking for the article and I couldn't find it.
05:12 I think Donald Stuff wrote an article, but it made something like a 7% difference
05:16 or some significant difference in the amount of Python 3 deployments just by switching the tutorial
05:24 in the getting started docs, the Python 3 as default, which I thought was really, really cool.
05:29 And so my next item is something from the Django team as well.
05:33 And this is like that turn to 11.
05:35 It's one thing to say the default documentation is to be in Python 3.
05:40 And yeah, you can do Python 2 as well if you want.
05:43 But the next major release of Django, Django 2.0, is dropping support for legacy Python.
05:50 There will not be support for Python 2 at all.
05:54 And they're actually cutting out the code to support it.
05:56 And they've said that that actually makes the code more maintainable, easier to evolve,
06:00 because there's not like these two worlds they're living in.
06:03 They're just doing Python 3 and it's going to be great.
06:05 Yeah, I think that's a good, actually, I think that's a good call.
06:08 I'm not sure how long they will support the 1x branch.
06:12 They send, the next release is Django 1.11, and that's an LTS, long-term support release.
06:20 And they say that's the last one to support Python 2.7.
06:24 And they have a support policy for the various versions of LTS versions.
06:30 And I believe that it's on the page that we're linking to from the show notes.
06:35 But I think the statement is like, we're willing to support one month longer
06:39 than Python, the Python version that we're aiming for.
06:42 Oh, okay.
06:43 So there's one LTS that was targeted at Python 3.3, and that drops security fix support
06:50 in February, but sometime in 2017.
06:53 So that's when they're dropping support for that version of LTS Django.
06:58 Okay.
06:59 And so there is a policy.
07:00 I don't remember exactly what it is.
07:02 And it's like, so this would be something to the effect of 2020, because that's when Python 2
07:07 is stopping its support and security fixes and so on.
07:12 Well, that totally makes sense.
07:13 This is good news though, right?
07:14 I mean, this is a major, major step in the right direction.
07:17 Yeah, I think it is.
07:18 Some of the code I've seen that try to support both 2.3 sometimes just don't make sense.
07:23 So I think it'll actually help the readability of the Django code.
07:27 Yeah, absolutely.
07:28 And if you want to add a feature, there's less to do.
07:30 You want to evolve it, there's less to do.
07:32 It's going to be good news all around.
07:34 Yeah.
07:35 Speaking of readability, one of the things I came across was I was reading an article.
07:40 Actually, it was an article, blog article about requests.
07:43 And since we've talked about that a lot, I'm going to skip that article.
07:47 But we all, we all love Kenneth.
07:51 So we know that.
07:52 But there was a, the article referenced, and it had some code that referenced a package
07:57 called ATTRS.
07:59 Atters?
08:00 It's from, do you want to try to attempt this name?
08:02 Hynek Shalawak.
08:04 Very good person in the Python community.
08:07 He's helped out, done quite a bit of good things.
08:09 But this, I hadn't run across this before.
08:12 And since I come from, what it is, is it's a library that helps you write objects
08:17 and classes.
08:19 I guess a more natural way, you can have small, tight classes, and it doesn't take up
08:24 a ton of code and they act normal.
08:27 Things like adding a whole bunch of attributes to a class that have default values.
08:33 So if they're, if the class is constructed without any, any parameters, the,
08:38 some of the values just show up already with some default values without,
08:43 and you don't have to write all the Dunder methods.
08:45 Since I come from C++ background, this seems very natural.
08:49 And I'm, like, similar to PIPenv, PIPenv.
08:53 I'm just starting to use this, but it's a, it's pretty clean.
08:56 I wanted to highlight it.
08:57 Yeah, it's really nice.
08:58 I've definitely heard people rave about how effective it's been for their projects.
09:03 A couple of things that it does, you know, you can easily say class person,
09:08 colon, you know, DunderNet, self.name, self.age, whatever, right?
09:12 And you pass those in, you can store them.
09:14 That's fine.
09:15 But then there's a bunch of other stuff that you might need to do.
09:18 So what if you want a human readable representation?
09:22 Well, you've got to implement repr and maybe stir as well.
09:26 If you want to take two of those things and compare them to see if they're,
09:30 they're equal or not, right?
09:32 By comparing the values.
09:33 That's another thing you've got to write.
09:34 Well, once you write the, the comparers, you also probably need to have a,
09:37 a not equals.
09:38 And then you've got to do the hashing and you've got to do all sorts of,
09:41 there's just so many different things.
09:43 You have to have an initializer to set all of them.
09:44 And all of that stuff is handled by adders, which is pretty slick.
09:48 Yeah.
09:48 And it also, it does all those methods and it's the, the time cost is at construction time.
09:54 And so there's runtime.
09:57 There's not really any, your objects are just as fast as not using this.
10:03 That's pretty cool.
10:03 Yeah.
10:03 That's really, that's really, really cool.
10:05 Excellent.
10:05 So speaking of going fast, there's an article that I ran across that is called
10:11 Go Faster Python.
10:13 And we all want our Python to go faster.
10:16 In fact, I think it's, it's really interesting that some of the core developers
10:20 coming back to Python 3, we're talking about, well, what is the thing that we could primarily do
10:24 to like absolutely make people say, okay, fine, I'll, I'll do the extra work
10:29 to switch my project over to Python 3.
10:31 And making you code faster was one of the things that they were focused on.
10:34 Python 3.6 goes a lot faster, uses less memory than, than previously, you know,
10:38 through five and before that and so on.
10:40 So people are really interested in making their Python code go faster.
10:44 And so this article is kind of an introduction article.
10:47 It's not super deep, but it shows you how to do profiling for your Python code
10:52 and benchmarking and timing and stuff, both for regular Python code and then code that's executing
11:00 inside Jupyter Notebooks.
11:01 Oh, wow.
11:02 So there's like special commands like percent time it that you can run to time a little block of code
11:07 in a Jupyter Notebook or you can run time it, you know, directly and things like that.
11:11 So they also talk about, you know, how do you figure out how long an overall set of code
11:15 is taking with benchmarking?
11:16 How do you, you know, do function profiling to say which ones you're spending your time in actually?
11:22 And then you can actually get down to line profiling with an external package
11:25 called line profiler.
11:26 And all that is cool.
11:28 And I think, you know, the reason I put this in here is I feel like it's,
11:32 it's good to remind ourselves that we should use these tools and we should look
11:38 at how fast our code runs.
11:39 It's, it's not, it's not intuitive sometimes.
11:42 And we always tell, a regular thing to tell people now is to not do premature optimization,
11:48 write code that looks clean and is easy to maintain.
11:51 And then after you've got things working, then look at, profile it and see where you can speed things up
11:58 and where things are surprising to you.
11:59 And that's great advice.
12:01 Yeah.
12:01 And so, but it's not obvious how to do that.
12:05 So I, I welcome all tutorials like this to help people with this.
12:08 Yeah.
12:09 And I think the takeaway is it's like a few commands and it's not major,
12:12 right?
12:13 You can totally do this.
12:14 And things like PyCharm have like graphical profilers built into them.
12:17 So you can, it kind of does the same thing, but like, you know, gives you a slightly different representation.
12:22 Yeah.
12:22 I mean, I've certainly worked on projects where I thought, okay, this thing right here,
12:26 this is the part of my code that is too slow.
12:29 And thankfully, before I tried to optimize it, I've run a profiler against it
12:34 and like, wow, that part's actually really fast.
12:36 Good thing.
12:37 didn't make it unreadable.
12:38 You know, it's, it's, it's definitely worth measuring before you make changes.
12:43 Yeah, definitely.
12:44 So, you know, one of the things that I think is a challenge for us around Python 3
12:50 and getting, getting things moved forward in that space, we're going to keep beating that drum
12:55 for a few years, I suspect.
12:56 Yes.
12:56 But, you know, Django, the newest, most awesome version of Django that's coming out
13:01 is only going to support Python 3.
13:03 but, what if we want to run that on like Red Hat Enterprise Linux or something like this?
13:09 Yeah, and actually, so that's, somebody contacted us and said he's really grateful
13:14 for what we're doing here and wants to be part of the community but he feels like
13:19 we're creating a community that's just Python 3 and, because he can't, in his environment,
13:24 use Python 3 yet.
13:26 And, yeah, so that's really what we want to highlight right now is just to say
13:31 that we know that some people, it's not, it's not their choice to run Python 3.
13:35 They, they have to run 2.7 right now because of their environment.
13:38 I guess, I kind of feel like since I'm, I'm somebody that writes tutorials also about Python,
13:44 I try to focus on, I'm trying to focus on 3 now but I think it's similar
13:48 to the Django model.
13:50 It's not, I'm, I will try to write, make sure, like the book I'm writing,
13:54 I'm going to try to make sure it runs on 2.7 also.
13:56 the wanting tutorials by default to show 3 is to try to encourage people
14:01 to use 3.
14:01 It's not up to people sometimes.
14:03 So, I'm hoping that everybody like the people at Red Hat and everywhere else
14:08 that does a distribution will try to give those choices to users and ship with both of them
14:13 at the very least.
14:14 Yeah, absolutely.
14:15 At least have, you know, Python 3 as not the main option but as an option,
14:21 right?
14:21 Yeah.
14:22 And I know there's, there's, there's tutorials out there to try it out on how you can get 3 running
14:28 on some of these environments and I just hope that people that, the right people,
14:34 the sysadmins or whoever's in charge of what the development environments are
14:38 to try to get that figured out and so that some of the projects can be on 3 also.
14:43 Yeah, I think that's a great, great message and the more that we can at least move those things forward,
14:49 I mean, I hear a lot from people like, hey, we just finished upgrading from 2.6 to 2.7,
14:54 right?
14:54 What is this Python 3 business you're talking about?
14:57 Yeah.
14:57 So, yeah, like more options, definitely, definitely better.
15:01 I don't think that we've really covered that much stuff in this podcast so far
15:06 in all of our episodes that really is 3 only.
15:10 We have covered it a lot, but a lot of the things like the, for instance,
15:14 the ATTRS, the adders, that's 2.7.
15:17 Yep, absolutely.
15:18 So, the next thing I'm going to talk about, I think actually is Python 3 only.
15:23 Yeah, it is.
15:25 Okay.
15:25 So, it's pretty cool.
15:27 Now, this is a project that you can take and you can make part of your smart home
15:34 or you can actually make it the hub of your smart home.
15:37 So, we're all getting more devices that are living in our house.
15:41 We can, you know, we maybe have a Nest or maybe we have some Arduino or we have a Chromecast
15:47 or, you know, things like that, right?
15:49 Well, there's this place at home-assistant.io and what this is, is this is a web application
15:58 that you can run and it will, written in Python 3, and it will let you track
16:03 and control all of your devices and home automation.
16:06 That's neat.
16:06 Isn't that cool?
16:07 So, instead of saying like, well, the way I work with my home automation
16:10 is I open up like my iPhone and in there I've got my home kit or whatever that thing is called.
16:16 I don't have a smart home so I don't really mess with that.
16:18 But, you know, it's got the few things that it can do.
16:20 Like, here's a full-on open source Python web app that does all sorts of cool things.
16:25 So, it says you can install it in less than a minute.
16:27 You can track the state of all of your devices in your house.
16:31 Like, so things like smart lights, garage doors, television, cameras, you name it.
16:38 You control them all from like a mobile-friendly little web app you can do.
16:42 So, you set up automation.
16:44 So, you can do things like have your lights turn on when the sun sets and you're home.
16:48 Oh, well.
16:49 or have them turn on when somebody comes up and it's dark, comes to your house.
16:53 Or, you can have them automatically dim when you start watching a movie on your Chromecast.
16:59 And all sorts of stuff like that.
17:00 Isn't that sweet?
17:01 Yeah, it's like, if this, then that, but for your house.
17:04 Yes, exactly.
17:05 For all your smart things.
17:06 And it's written in Python and that's cool.
17:08 You can, you know, to get a sense of what it's like, there's a demo, home-assistant.io
17:12 slash demo and you can just go straight there and check it out.
17:15 And there's some pretty cool stuff you can play with there and get a sense.
17:17 The other notable thing, well, many notable things here, but one of the things
17:21 that is notable to me is this is based on AIO HTTP.
17:26 So, that's an asynchronous HTTP client server framework in Python.
17:32 All the cool async.io, the async and await stuff, you can apply that to things like
17:38 Flask and Pyramid and so on because basically the WSGI protocol doesn't really,
17:44 you know, it was built before this concept of asynchrony.
17:47 This framework is built on top of that.
17:50 So, it's an interesting implementation of this modern Python web server framework as well.
17:56 So, you know, even if you're not interested in like home automation, it's still kind of cool
18:00 to look through the source code on GitHub for that reason alone.
18:02 Yeah, definitely.
18:03 I want to look through this because I do see the Arduino's part of it, but I haven't seen
18:08 so far if you can hook up Raspberry Pi stuff for it.
18:11 I don't know either, but definitely something I'd like to start playing with.
18:14 It looks cool.
18:15 Yeah, very neat.
18:16 So, it's open source.
18:17 You guys can all check it out.
18:19 All right, well, that's it for the news this week, Brian.
18:21 Anything else you got going on you want to chat about?
18:24 No, just trying to get over this cold.
18:27 How about you?
18:27 I was on a mission this weekend.
18:30 I'm on a mission to get my next course done.
18:32 So, my Python for Entrepreneurs course, I kind of, I've done as much work
18:36 as I can do and I've handed it off.
18:37 It's now in the pipeline to be finished and so now I'm writing a new course
18:41 called Consuming Services in Python for like REST services and SOAP services
18:47 and working with all sorts of data on the wire basically from Python.
18:50 Wow, that'll be interesting.
18:52 Yeah, it's fun.
18:53 So, I worked on that all weekend and I'm making good progress.
18:55 Now, didn't you announce like some extra thing that you were, you guys were given
19:00 away with the last course?
19:01 Oh, yeah, with the Python for Entrepreneurs course.
19:03 Yeah, we're partnering with Digital Ocean and PyCharm and so everybody who takes
19:08 the Python for Entrepreneurs course gets $50 of credit for Digital Ocean
19:14 for new customers and about something to the effect of $25 worth of PyCharm licenses.
19:19 So, it's pretty cool.
19:21 Like, the course costs $59 but you get like $70, $75 worth of stuff for free
19:27 just by signing up.
19:28 So, it's really cool.
19:29 I'm super happy to be able to, you know, partner with those guys.
19:32 And I like that you've started to do like a highlight page to highlight projects
19:36 that people have finished that have gone through the course.
19:39 yeah, I had a day, yeah, so what I want to do is like all the students that are taking classes
19:43 with me, I want to make sure that if they build something they're proud of
19:46 they can share it with other people and let everyone know.
19:49 So, I think it's training. talkpython.fm/showcase and people are starting,
19:53 I got a few more submissions now, starting to submit things and I got to
19:57 get them entered there so people are creating their websites or their businesses
20:00 or just open source projects and those will be featured there.
20:03 And if anybody's curious, this wasn't a canned plug, I'm actually just interested
20:07 in what Michael's up to.
20:08 Thanks, Brian.
20:10 Yeah, I appreciate it.
20:10 It's cool stuff.
20:11 It's really fun to be working on this.
20:13 You know, it's like, you know, my life is a dream.
20:15 I get to work on all these things all day long.
20:17 It's fabulous.
20:17 Well, I enjoyed talking with you again this week.
20:20 Yeah, as always and we will be back next week with another round of Python goodness
20:25 for everyone.
20:26 Thanks a lot.
20:27 Yeah, bye Brian, bye everyone.
20:28 Thank you for listening to Python Bytes.
20:31 Follow the show on Twitter via at Python Bytes.
20:34 That's Python Bytes as in B-Y-T-E-S and get the full show notes at pythonbytes.fm.
20:40 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
20:44 We're always on the lookout for sharing something cool.
20:47 On behalf of myself and Brian Okken, this is Michael Kennedy.
20:50 Thank you for listening and sharing this podcast with your friends