Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to
your earbuds. This is episode 186, recorded June 10th, 2020. And I'm Brian Okken.
And I'm Michael Kennedy.
And this episode is actually brought to you by us. And we'll talk more about some of the ways
you can support myself and Michael a little later in the show. But first, let's side table that for
a little bit.
Side table it. Yeah, let's put it to the side and talk about side table. Yeah, so side table
is something that I noticed as new project from Chris Moffitt. And longtime listeners of the show
will definitely know that I'm inspired by visuals. And this is one of those that's really nice, right?
Like not long ago, when Guido was on the show, we talked about a missing number of visualizer for
pandas. So you could have a quick view of just like, I got this data, I just need to really quickly see
kind of what it looks like what's missing correlate missing elements and whatnot.
And so side table is in this general zen of things. It's like, I've loaded up some data,
I just want to quickly ask some questions and get a sense of what's going on. Like,
I've got a pandas data frame. And I want to be able to say, you know, can you just break this down by
like, show me the top 20% of this and then group the other stuff into just like an other category.
Also, instead of just getting like a plain text output, you get a cool, like alternating row color,
nice table with extra information, and whatnot. And it's usually something really, really simple. Like, I could go to the data frame and say,
just give me the frequency of state and just, you know, group it by that or something. And it's,
it does a group on those and a whole bunch of cool stuff. So really, really neat visualization. There's a picture in the show notes that shows you without it and with it. And given that the nicer version requires even less typing than the not nice version, I kind of like it.
Yeah, and just out of the box, having just like the alternating gray and white stripes is good.
Yeah, absolutely. So basically, all you have to do is a pip install, of course, but then import side table, and it adds an STB functionality to data frames to panda data frames. And then you can ask it questions like frequency. There's other stuff that you can also ask. There's like a bunch of different functionality there.
So really nice for exploring new data sets. And it's basically a supercharged version of pandas value counts with a little crosstab mixed in. So yeah, it's easy to use. And if you're working with pandas, especially in Jupyter context, you know, that's really where this makes sense. Give it a shot. I think it looks great.
Does it look good?
Good job, Chris.
Yeah, and I
Yeah, go ahead.
No, I didn't. I totally didn't even intend to do another table one back to back. But
We're kicking it off with all the tables. Yeah, which one you got here?
So this was a suggestion from Tom McDermott. And for the tabulate package, this is not for it's not intended for Jupyter stuff. It's intended for just standard out sort of things. So you want to pretty print a tabular data in Python for command line utility. Actually, I've been using this for years. I was like, I'm sure we've covered this. And I looked it up. And I don't think we have or at least I can't find it.
I don't remember us covering either. And it's really sweet. It's like, it generates nice formatted tables, but in ASCII. So like before I said, you know, side tables awesome, if you're going to be doing this within Jupyter. But this is like if you're doing it within just a terminal command line app.
By default, you've got a list of lists or a list of tuples or something to represent the rows. And you just want to print it with tabulate. It just does it automatically. But you can also, I usually use it with headers. So you pass in the headers separate.
So header information. And by default, it just prints stuff out with prints of headers and then dashed lines and then your columns underneath. But it also like spaces it correctly because that mean actually that trying to get that right by yourself by hand is just a pain to try to figure out how wide things are supposed to be and whatever.
So this just does it. And it's great.
Not only does it do it by text, like the example that you have in the show notes really illustrates like the nuance here. So it's got a list of planets, their radius and masses.
And for the sun, it has it in scientific notation like 1.8, 1.989 times 10 to the ninth. And then for the other ones, it's like 5,973.6. It aligns the decimal places, not all to the right. I mean, it's glorious.
Yeah, the alignment is neat. I really appreciate that. So you have control over some of your number formatting and your alignment.
But also, if you're outputting for different things, there are multiple different formats, including like a simple markdown type table. But it also does GitHub flavored markdown tables and pipes that just look nice if they just kind of make it look like boxes.
And there's Jira style and MediaWiki and HTML and just plain if you don't want any sort of stuff in between, just spaces in between. It looks nice.
That's cool. So you could like output this in Jira format and like paste it into a Jira issue as like, here's what we're doing now or here's the problem or here's the data.
Yeah, definitely. It's a good one for keeping track of tables.
Yeah. Wow.
Another good thing is all the stuff that you and I have to offer people to learn more information about lots of stuff.
Yeah, absolutely. We have the podcast, but we also have other things as well.
Yeah. So if you want to support what we're doing, one of the things you can do is become a Patreon supporter. So there's a link on the page where you can throw a couple bucks at us a month if you want. But also, I've got a book.
If anybody was not aware of that, there's a pie test book.
You've written a pie test book?
Yeah, I did.
It's good. I really like it.
Another podcast called Testing Code. I'd love to have more people go check that out and suggest what you want. So I'd like to have people talk, tell me about what other topics should be covered there.
Yeah.
You also offer quite a few learning opportunities for people.
Yeah, absolutely. The main thing for me, if you want to support me, like obviously we have the Patreon and that's great. But if you want to support us and get something back, you could take one of our courses over at Talk Python Training.
We're doing all sorts of cool stuff there. We've got like 120 hours of Python courses and exercises beyond that.
But we recently just kicked off a cohort thing where people can go through as groups.
So that's something I'm trying to put together and, you know, it will probably be more opportunities to do that as well.
So, yeah, check it out if you want to learn Python. That's where I recommend people go.
Yeah. I want to bring something up about your courses. There's a lot of the courses that are, there's a lot of content there and it's wonderful information.
One of the things I really love, especially in this working from home environment where I don't often have a lot of time, is the way you've broken up all the courses into little tiny pieces.
So there's a table of contents so you can go through the course and see what you've seen and see what you haven't.
But you can keep track of what you haven't.
And there's often just, if you've got like three to five minutes, you can fit in a little extra video.
Yeah. Thank you so much. That's awesome.
And I like that you've done that.
Yeah. I really want to try to make the courses have meaning as a reference afterwards as well.
And like nobody wants to go back and scan a 30 minute video for that 30 second clip you're looking for.
Yeah. That's good.
Awesome. You know what else is really good?
Tree beards.
Yeah. For real. Tree beards are pretty awesome.
Is that like a neck beard?
But for a tree.
Okay.
Okay. Yeah.
So I actually have no idea the relationship of the neck beard to the tree beard.
But tree beard is continuous integration for notebooks, which is pretty cool, actually.
That is cool.
So this was recommended by Brian Skin.
And it's continuous integration for a particular subset of notebooks.
Those are the notebooks that are binder ready.
So if you're not familiar with binder, I recently did a Talk Python episode on this and came to appreciate binder way more than I originally did.
So binder is a place where you can basically point a GitHub repo or some repo at.
Go to binder, point it at your repo.
Say here's the notebook.
Here's the dependencies files and everything.
And then you just click a button and say, let me run this on binder.
Because if you go to GitHub, you see that possibly the output from the notebook.
But that's like cached what was run the last time.
If you want to actually run it and play with it, you can click launch a binder.
It'll fire up a little Docker image somewhere magically in the cloud.
And it'll just run it.
So you basically configure the repo to describe to binder what it needs to run successfully.
Right?
So that's how this works.
Is Treebeard basically says if there's something that can be run on binder, then it will use that same functionality to automatically install the dependencies, which could be like conda or pip or whatever.
And then it'll run the notebook using that cool library called Paper Mill, which sort of converts notebooks into kind of function type things.
It'll upload the output.
It'll upload the output and do an NB convert on the notebook to save it and create like a version stamped last run of your notebook that you can go back through your continuous integration and see the history of the outputs saved as HTML, which is pretty awesome.
And it integrates with a GitHub app that'll like push notifications back to your repo.
It integrates with Slack.
It has all kinds of interesting things like this.
So really a neat mechanism to make sure that your code just keeps running if it's a notebook.
Yeah.
It's even got like secret management.
So you can, if you have to connect with different things with passwords and stuff.
Don't you just put those in the notebook?
No.
No?
Darn it.
No.
Yeah.
No, that's really cool.
It has secret management and all kinds of stuff.
And basically, when I first saw this, I thought, okay, well, what's the criteria of success, right?
Like how do I write a test to indicate a successful notebook experience?
The way it works is basically it runs all the cells.
And if all the cells run without exceptions, then it's successful.
So it's not like it's making assertions, but it's kind of like a smoke test.
Like it didn't entirely explode.
So we think it's probably okay.
That's not bad for a starter.
I mean, conceptually, you could put asserts in there and that would throw an exception.
Exactly.
Right.
You could build in the test at like some layer in there.
Like have even a Python file that you import that like does the test.
I don't know.
Whatever.
There's a lot of options.
So you're right.
You could make your notebook report out.
Make some cells in there.
Yeah.
Make some cells that'll blow up if things go wrong for sure.
Yeah.
Somebody should get a hold of us and tell us why beard.
Yeah.
Because trees generally don't have beards.
Well, okay.
We live in Oregon, so they're often very mossy.
That's true.
They've got that little moss thing.
If it's just right, actually, it could totally do that.
You're sure?
Yeah.
Okay.
So one thing that surprises me, Brian, that seems to keep coming up and up and both of us
are talking about it next.
Like I feel like we've aligned perfectly so far.
Oh my gosh.
We are.
Dude.
We're both talking about virtual environments.
You go first.
Okay.
So there's a couple of things that we just, in episode 184, we discussed virtualenv and venv.
And actually I learned quite a bit to find out that virtualenv is still pretty cool and fast,
but that was in 184.
But we had people get a hold of us and say, hey, there's more information that you guys don't know.
And I love that.
Please keep it coming.
If we do half the story, give us the rest of it.
In Python 3.9, so venv, the built-in one, it has a cool new flag called upgrade depths for upgrading your dependencies.
It's like not all of your dependencies, but it's for virtual environments.
Every time you create one, we commented that you have to upgrade pip.
And this new flag allows it.
So when you install, create a new virtual environment, it automatically upgrades set of tools and pip for you.
Yeah, that's cool.
Which is nice.
That's in Python 3.9.
I tried it out already.
I tried it on beta 1.
Beta 3 is already out.
So you can try it out if you want.
The other news is the virtualenv is getting something new, and it's not there yet.
And I'm not sure when it's coming, but I think it's soon.
It's getting a feature called periodic update, which is super cool.
So one of the things, so virtualenv, since it's separate from your Python, or you can have it install, make virtual environments for multiple Pythons, for instance.
But it also keeps its own cache of new pip, new setup tools, and new wheel, that package you need if you're creating wheels.
And so it has those upgraded already.
But the periodic update, it will just have this extra thing that in the background goes off and checks to see if there's new ones around.
So whenever you actually need to create a new virtual environment, it'll automatically have an updated one that it can install right away, which is neat.
Yeah, that's pretty cool.
Nice.
And if you don't want it to go off and do it in the background, you can manually say, okay, right now I want you to go off and upgrade it right now.
Okay, that's a cool idea.
I like it.
So you've got a better chance of having updated stuff if you're working without an internet connection at the moment or something?
It already had kept its own version of it that would upgrade it.
So you already can, it's newer than if you're using VENV.
But I'm excited about it.
And one of the other things I wanted to mention is I kind of complained about that the prompt is different.
And I got a little bit of the skinny about why the prompt is different in virtualenv versus VENV.
And it had to do with the prompt formatting on different operating systems was different, which is weird.
But they coalesced it and made it a single prompt.
And the need for, like, sometimes you actually want to not have a space.
You might not want to have those parentheses.
So there may be reasons to not have the parentheses in space.
So there's reasoning behind it.
It just still annoys me.
But that's okay.
It's cool to actually know why, though.
That's really nice.
Yeah.
So all these things that make working with virtual environments better are great.
But how about we just don't have virtual environments, but we still do?
Wouldn't that be better?
I don't know.
So let me tell you what I'm thinking.
So a while ago, for the 3.8 timeframe, there was a proposal called PEP582.
And PEP582 is put together by a bunch of folks, Steve Dower and four or five other people.
I'm forgetting Donald Stuff.
And I know there's two other folks that I'm forgetting.
Sorry about that.
But anyway, it was put together.
And the idea is that it proposes to add a mechanism to automatically recognize a DunderPy packages and prefer importing packages installed in there over global packages.
So the idea is you just go to your project and say at the top of your project, go, here's the top of my project.
And then when you pip install stuff, it will put things there.
You won't have to activate a virtual environment because you're not changing anything outside the global system.
It's just going to drop it in right there.
Okay.
Basically, this is how Node.js works, right?
So if I'm by NPM install a thing, it just traverses up the directory until it finds a node modules.
And it's kind of like that, right?
So it says, if you have this folder here, we're going to automatically install stuff there.
And then Python will automatically know to look there.
So if you're anywhere in a subfolder without even activating the virtual environment and you type Python something to run a command, as long as you're in the folder structure, it's going to use that environment.
Oh, that's pretty cool.
Yeah, that's pretty cool, right?
So the motivation, at least, is it's like every time someone's new to Python, they're like, well, I can't install this thing.
It says access denied.
You're like, you know, permission denied.
You're like, well, okay, let me talk to you about virtual environments and why you need them.
And also to activate the environment on the different shells and the different platforms like Windows versus POSIX, you know, source versus not source and bin versus scripts is different.
And so that's kind of a pain.
So the idea also, every time you open up a new terminal or command prompt, you've got to reactivate it.
Like I've all all for all of these things.
I have aliases that make this happen, right?
Yeah.
So the idea here is that you don't have to worry about any of that stuff.
You just have to like init your Python project somehow.
It doesn't I don't remember seeing how that was supposed to happen.
But once that PyPackages folder is there, it's like, well, that's the top of the project.
We're going to install there.
And you presumably could have like a fallback one at the top of your user profile.
Or something along those lines.
Yeah, you have that.
So that's for the packages.
But what about in virtual environments?
You also have local scripts that come along entry points.
Yeah.
Do you know if it deals with that?
I don't know.
I don't know about it.
It's possible.
I didn't read like every word of it.
So it's in draft mode.
But I was a little confused because it says its version is Python 3.8.
I'm like, well, 3.8 shipped.
It should either be closed or published.
That seems weird.
So I sent a message to Steve Dower just a moment ago on Twitter.
And he said that Kushal Das, one of the folks proposing it, I think the primary guy, is still
working on it.
The text itself hasn't been updated before 3.8's release, which is why the header is still a
little bit out of date.
So it's probably more like a 3.10 thing or something.
But it's still pretty cool.
If you want to try to live in this world and see what it's like, David O'Connor has this
thing called PyFlow.
And PyFlow basically does this.
It integrates with PyProject.tom.
Well, man, we lined it up good this week.
And you go through, instead of saying pip install, you say PyFlow install.
Instead of saying Python run, you say Python script, you say PyFlow script.
Because it has to reinitialize that every time because it's not actually changing something.
Anyway, it's interesting.
I would like to see something kind of like this.
I think it's pretty neat.
There's also some interesting possibilities around DIRT ENV that I'm looking into.
Just talking to someone, Chris, who has got some cool ways to have DIRT ENV automatically
activate virtual environments, which would be kind of cool as well.
So there's a lot of stuff happening here.
It still kind of blows my mind.
There's so much action around something that feels like it's just a, I don't know, so plumbing
and foundational.
Yeah.
But like you said, it is plumbing and foundational, but it's also one of those things that's one
of those tripping things.
It's like the loose stone on the sidewalk that trips up all the new people all the time.
So far, what we've managed to do is we've managed to like spray paint a yellow line on both sides
of it.
You know?
Somebody needs to shave that bad boy down.
But right now, at least it's like got a little marker on it.
And I just want to say thanks to Louise Erbier on here.
Send that over and let me know about this whole project.
So thank you for that.
Yeah, that's nice.
Yeah.
So speaking of PyProjects.toml, I actually really love, I kind of like this.
I like awesome lists.
So awesome lists are a thing.
We've covered many of them in the past.
There's even a Python Bytes awesome list.
Yeah.
This one is awesome PyProjects.
PyProject.toml projects.
So this is one of the great things about different sorts of source code lists is to go and look at
examples.
So this is a list of other projects that are out there that already use PyProject.toml.
So you can look to see how other projects are doing it.
So if you want to figure out for your own project, this is helpful.
For instance, a lot of the testing and formatting stuff came along early.
So covers.py is in there.
pytest, Tox, Black, iSort.
I knew all of those.
Ward was a new one to me.
So Ward is apparently a way to test things without like string named test functions instead of function
names.
I haven't really played with it much other than looking at the documentation.
But it looks neat.
But there's a code analysis like PyLint and Unimport and the really long titled We Make Python
Style Guide, which is a linter and other stuff.
But it's pretty cool.
And then it has a couple links to articles about PyProject.toml.
And then what I think is also neat is a list of projects that are discussing switching to PyProject.toml.
So you can...
Oh, yeah.
That's probably pretty interesting if you're trying to decide yourself, right?
Yeah.
To figure out what sort of discussions are going on in other projects as to why to switch and
why not.
Yeah, for sure.
Very cool.
Yeah.
I think people switch.
I'm using it everywhere because it's just...
It's sort of easier.
What confused me for a little while was that it isn't...
I thought it was something you needed Flit or Poetry to be using.
But you can use PyProject.toml with setup tools projects also.
Okay.
Interesting.
Yeah.
I didn't know about that.
Yeah.
I kind of thought it was tied to some of these higher order management things like Poetry and
Flit and so on.
Yeah.
Yep.
Cool.
And like you said, there's a Python Bytes awesome list if people like awesome lists.
Sorry.
I put that at the end there.
People can check that out.
Thanks, Jack, for doing that.
Yeah.
So that's our six items, Michael.
Anything extra to share with us?
I got something for everyone.
I got two things, actually.
One follow-up and one new thing.
First of all, we had Calvin on a while ago, a couple shows ago.
Was that last show?
Show before?
I think a couple shows ago.
And we were talking about secrets.
And he also...
He's in your camp.
He doesn't put them in the notebook or in the right there in the source code.
He's doing something else.
But what he talked about is actually using 1Password as like a vault, right?
So 1Password has awesome encryption and security.
And so a lot of the challenges revolve around, well, if I'm going to put them somewhere else,
if I just put them straight in the virtual into an environment variables, well, people can
grab them there.
So maybe I want to put them some other place where it's like encrypted or something, right?
So he talked about his mechanism of finding all those environment variables at launch and
then like just as you run your virtual environment, injecting them there, but storing them in 1Password
instead of just on the file system or something like that.
So he did a blog post about how he's doing that.
And so I'm going to just link back to that.
Yeah, nice.
That looks pretty cool.
And also, I want to give a shout out to Talk Python.
Specifically, the last episode, at least the time of recording, it'll probably not be by the time we publish this.
But nonetheless, just recently, you were a guest on Talk Python where we talked about 15 awesome pytest plugins,
mostly a few extensions like using with or alongside, but mostly pytest plugins and went through things like pytest Sugar and Freeze Gun and all sorts of fun stuff.
So people can't get enough of us.
They can hear you being a guest over there talking about pytest the entire time.
Yeah, it's nice.
Yeah, that was fun.
Thanks for coming on there.
I like to hear myself talk so much that I also, we cross posted that on Testing Code as well.
Yeah, sounds good.
And one of the things, so as an extra bit, did you know that I wrote a book?
Yes.
Yeah, I've heard of that.
No, it's a great book.
I have it.
I published through Pragmatic Publishers, and I just wanted to bring up that Pragmatic has a shiny new website.
So the Pragmatic site is a little different, and there's an FAQ up there if people want to know why or what's different about it.
And for the most part, it looks a lot the same to me, but the entire backend is different.
Yeah, yeah, cool.
It's a little faster.
Faster is always nice.
Makes it nice to work with.
All right, I have a joke.
Let's pretend we're roommates.
You can be the first person, and I'll be the second person, okay?
Okay.
Stop by the store on the way home from work.
Please stop at the market and buy one bottle of milk.
If they have eggs, bring six.
I came back with six bottles of milk.
Why the hell did you buy six bottles of milk?
I just said it's just the two of us.
What do you think, man?
Because they had eggs.
Obviously, taking this programming logic a little strong, right?
Stop by the store.
If they have eggs, get a bottle of milk.
If they have eggs, get six.
Cool.
That's funny.
Pretty good one, huh?
Takes a little bit of thinking.
So, glad we have it written down for people.
Yeah, yeah.
We can go back and study it, right?
Yeah.
All right.
Well, thanks a bunch, huh?
Cool.
All right.
Thank you.
Yep.
Bye.
Thank you for listening to Python Bytes.
Follow the show on Twitter 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.
This is Brian Okken.
And on behalf of myself and Michael Kennedy, thank you for listening and sharing this podcast
with your friends and colleagues.
Bye.