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