Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
It's episode 91, recorded August 8th, 2018. I'm Michael Kennedy.
And I'm Brian Okken.
Hey, Brian. How are you doing?
I'm doing great.
Awesome. Well, as always, the Python news cycle has not let us down, has it?
No, it's keeping up. It's good.
It's definitely. We've got a lot of good stuff to cover.
Before we do, though, another thing not letting us down is Datadog.
They're definitely helping us prop up.
So thank you, Datadog, for sponsoring this episode.
Check them out at pythonbytes.fm.datadog.
They actually have some cool new announcements, which I'll get to later.
But let's talk about what makes Python cool, huh?
There's a lot of stuff that makes Python cool.
But there was an article that came up.
I think it's on Medium.
HackerNoon. That's right.
Sorry, HackerNoon, that I thought you were Medium for a second.
By Shankar Jha.
And I probably mispronounced his last name. Apologies.
But an article called What Makes Python Cool.
And my first reaction is like, oh, yet another rah-rah.
Python is awesome.
But it is actually kind of a neat article because it talks about some of the things that a lot of people that are just starting out or starting to learn Python or they have to might not stumble around.
They might not run into for a while.
And they're good things to note.
So he starts off with the Zen of Python with import this.
And it's a good thing for people to look at.
And then, of course, if you're looking at cool imports, import anti-gravity that redirects you to XKCD is cool.
Yeah, if people have never typed import anti-gravity in their REPL in Python, they should definitely do that.
And those two things actually make it – they're not just jokes.
It kind of indoctrinates you into the fact that the Python community doesn't take itself too awfully seriously.
It's all serious work and we do a lot of important things.
But it's a good, fun thing to have there.
So I hope they never take those out.
Yeah, I agree.
And then things that he starts off right off the bat after that with how to swap two variables in one line.
Like A, B equals B, A.
We're just used to that now.
But when you first see this – or a lot of people don't think they can do that because you can't do that in C, I don't think.
You didn't used to be able to at least.
Nope, I don't think so.
And it's a fun extra thing.
How fast you can spin up a web server just with one line.
A reminder to take a look at the collections and iter tools modules or packages because there are a whole bunch of good stuff in there.
Enumerate with the enumerate keyword is – or built in, whatever that is.
It's a really cool thing and it keeps people from keeping track of their own indices when they're going through lists.
Do you know what I learned from Bob Beldervos from PyBytes with an I, not a Y, not Python bytes, about enumerate?
Is it takes an extra parameter that will let the index start at one or anything you specify.
Because I've always had like it go at zero, then I'll have like index plus one all over the place.
Well, you can just say start at one, two, three.
That's a parameter in there.
It's nice.
Yeah, and that's a brilliant thing because, yeah, I've seen that a lot of people adding one.
Just start at one and then it's in the right order.
Easily reverse a list, doing zip, a couple zip tricks, how cool comprehensions and dictionaries are, and pretty print with pprint.
Anyway, it's a good article.
Yeah, absolutely.
I really – I think it covers a lot of nice stuff.
And if you're kind of new to Python, there are some cool things in here that you'll be like,
oh, I didn't know when I was working in the REPL that if I forgot to assign some computation to a variable,
I can still access it one time quickly as an underscore.
So that's pretty cool.
Yeah, I actually forget that all the time.
So I'm glad that people keep putting that down because I forget about it and it saves time.
The many uses and meanings of underscore.
Yeah, and we're not even in Perl.
Yeah, exactly.
So if I were a Django person, I'm not.
My sites are based on Pyramid and Flask and things like that.
But if I were a Django person, I'd be doing a bit of a backflip right now because there's a brand new major Django release.
And this is the first major release after Django kicked Legacy Python out the door.
So Django 2.1 is out.
Pretty cool, huh?
Yeah.
What do we got in 2.1?
Well, there's actually a ton of features.
I think the one that the team highlights the most is this thing called model view permissions.
So Django comes with its ORM, right?
Its own ORM.
And in there, you have models that map to the database.
And now you can set it up so you have view-only permissions on models, which is pretty cool.
And they said Django 2 has reached the end of mainstream support.
They just released 2.0.8, which is the final version you're ever going to see except for possible security fixes until April of 2019.
But after that, there's going to be no more Django 2.0.
So be sure to look about upgrading.
And then in terms of features, we have the model view feature.
We also have the ability to customize how deletes happen.
So there's like a delete query set option.
So you can delete select objects and customize that.
There's a way to override the default admin site.
There's tons of ORM features.
I highlighted one, but there's actually a whole bunch.
Caching is pretty cool.
So caching used to kind of like store items.
And when it got full, it would just randomly start throwing stuff out.
And now it uses LRU, last recently used to call.
So like a better sort of the hot stuff stays in the cache, which is good.
Migrations can now be run from PYC, so compiled files.
So in frozen environments that are just have the binary bytecode, you can still run migrations and tons more.
Wow, that's actually pretty cool.
Yeah, there's a lot of stuff in there.
Like there's pages and pages of changes from Django 2, which is pretty awesome.
Yeah, actually, if I was going to go look at Django, which is on my to-do list, the ability to overwrite the default admin site, that sounds kind of neat.
Because I'm not really a fan of the look of the default admin site.
Yeah, it's pretty cool.
Great.
So you've got one that's a little playful, right?
Yeah.
So this is actually pretty awesome.
It's actually a GitHub repo.
And I'm going to look this person up.
It's Annalena Popkis, which actually I might have actually got that last name right.
Who knows?
But she's a computer science graduate student or computer science graduate.
She's working as an intern right now, according to her blog.
But it's like the whole 100 days of code thing.
But she's doing it all in the open and all in Harry Potter themes.
And it's really fun.
And so far, it's up to day 18.
So she's still working on it.
And hopefully, we'll continue it all with it.
But this is just some really fun stuff.
And I like the idea of using a theme for going through a 100 days of code system.
So it's kind of fun.
Yeah.
So to give people an idea of what you're describing and what she's doing is like, for example, on
days 16, 17, 18, she worked with data classes.
Data classes are a cool 3-7 thing that are awesome.
And she's modeling a house, right?
When the young wizard students go off to the wizard school, they go into like Gryffindor
and Slytherin and the different houses.
And so like her whole example of exploring data classes is about that.
What also I think is actually going to pay off pretty big time for her is every one of these,
she's not just writing the code and putting it in a separate section in GitHub.
But she's also doing like a full-on explanatory blog post.
Like this one is probably six pages of writing about it.
And that's got to help understand it really well and make it stick.
Yeah.
And then it's also, you know, 100 days of writing, you know, practice writing about text stuff.
So yeah, it'll definitely help.
It's a good idea.
Yeah.
I love it.
I'm glad you brought that one in.
I saw that come up.
I'm like, wow, that's pretty clever.
Well done, Anna.
Nice.
All right.
Before we move on to the next one, let me tell you about a new feature from Datadog.
So we talked about Datadog and their monitoring and stuff before.
So Brian, we've talked a little bit about machine learning and AI taking over the world, right?
Yes.
Yeah.
So here's a little bit more of it in a good way.
So Datadog has their APM application performance monitoring stuff has a new watchdog auto detection engine that uses machine learning to alert you about performance anomalies in your application.
That's cool, right?
That is really cool.
So it learns how your app normally works.
It's like, whoa, you know, it's pinned this thing at 100% CPU for some reason.
Something must have gone wrong.
Or maybe it's totally flat.
You're processing no traffic.
Either way, you probably want to know.
So with Datadog's new watchdog thing, you can explore and analyze all your app performance data, navigate between correlated metrics, traces, logs, all that kind of stuff in real time.
So if you want to start optimizing your Python apps with machine learning, you can get a 14-day free trial and Datadog will send you a free t-shirt at pythonbytes.fm/Datadog.
So that's pretty awesome.
I'd like to check that out.
Yeah, definitely cool.
Yeah.
We've talked about deployment once or twice, right?
I think so.
Along with our GUI kick.
So here's an interesting take on it.
So one of the things I think is challenging about distributing a Python application is you have to distribute your source code.
Now, maybe you distribute the PYC files so you can distribute like a bytecode version, but it's pretty easy to unbytecode that, right?
But there's not a lot of great ways to distribute your code if you are concerned that maybe someone will mess with it.
Like you could put it onto, say, a web server, but if somebody breaks into the web server and they find your code, well, they could change simple things like your Stripe ID.
So all of a sudden, all your purchases start deposited into their bank account instead of yours or things like this, right?
So if you want to deploy your apps and protect them, that can be tricky.
And it's extra tricky in Python because if we're deploying C++ or Go or even .NET, there's like compiled binaries and you can sign those so that they don't get, they can't run basically if they're not properly signed and things like that.
But in Python, you distribute generally source code.
So this next thing is there's this like consulting group company and they wanted to come up with a way to protect Python code for the people they work for.
So they wrote this article and created this thing called Executing Encrypted Python with No Performance Penalty.
Oh, wow.
Cool.
So, you know, we have the PYC, which is the bytecode thing.
And that's just straight bytecode.
But what they've created is what they're calling a PYCE file.
And the PYCE file is an encrypted Python byte file, which until you decrypt it, can't be executed.
So that's pretty cool, right?
That's very cool.
Yeah, and the way they make this work is they override the import statement.
They basically import a library that changes what import means.
So when you say import, it runs their custom code that says, oh, it's one of these encrypted files.
Well, that means grab the decryption key, decrypt it.
Now we load that into memory.
And the no performance part comes from the fact that once Python has loaded a module, it's just in memory.
And so the decrypted version's in memory, you hit it again, and it's golden, right?
It just keeps running.
So basically, it maybe starts a tiny bit slower, but then it's the same.
So if this is something you're interested in, check it out.
It's pretty cool.
So is this a commercial thing or is it something there?
I think it's open source on GitHub as far as I can tell.
That's very cool.
It is from a commercial company, like a consulting company.
But I think, let me see if I can find the license.
Do they have a license?
The license is, wait for it.
Actually, wait for GitHub.
Come on, license.
Apache 2.0.
Yeah, permissive license.
Yeah, so it's free for commercial use.
This is a very cool thing.
I'll have to check that out.
Yeah, nice.
Yeah, it's not being used by a lot of people, but it seems to me like the people who want this really want this.
You know what I mean?
Everybody else is like, why do you want that?
I don't care about that.
But if you really wanted it, it seems like it'd be pretty cool.
So anyway, that's what I found for that one.
That's great.
Nice.
Yeah.
What's this next one about?
I don't even know what to make of your notes here.
This is crazy.
It's cool.
Well, actually, I just saw, this actually came in just this morning.
I saw a tweet from Harry Percival saying that he wrote a plug-in for pytest called pytest-ICDiff.
And it's a plug-in that allows you to use ICDiff for asserts that are equal comparisons in pytest.
Right, like a failure in, say, like, assert these are equal, but then they're not.
And it'll show you like a color diff instead of just, no, they're different.
Yeah, that's pretty much it.
I love it.
And I have never even heard of ICDiff, but ICDiff apparently is a different diff that isn't necessarily tied to pytest.
You can use it just on the command line for better diff, colored diffs.
Yeah, IC stands for improved color diff, which is pretty cool.
And it's a Python project in and of itself.
And then it looks like Harry Percival's pytest-ified it.
Yeah, it's cool that having some color there, highlight things.
I think it's great because so often when a test fails, you're like, oh, what is going on?
Like, you want to look at it and you're like, what is that?
Is that, oh, there's that dot there.
You know, like some color would really help, right?
Yeah, to highlight exactly which part of it's different.
Yeah, exactly.
So that's a pretty short section, just a new tool that I thought was neat.
I thought I'd share.
Well, I don't know why you wouldn't use this if you're using pytest.
Yeah, that won't help you for other types of asserts.
But it's the equality of why is it not equal that really trips people up sometimes.
Yeah, for sure.
Yeah, it's great.
Nice find there.
And well done, Harry.
All right, the last one is a bit of a amusing.
And this was sent to us by one of our listeners.
So thank you for sending this in.
And I wasn't sure whether we should cover it, but I kind of feel like we should.
So what they sent in to us is highlighting a .NET project, C#.NET.
And you might think, Michael, why do we care about a .NET project?
We don't really.
But the parallels for what we could do in Python, this would make me do a backflip.
I don't even know how to do it, but I'd give it a shot, even though it might hurt.
So they said, hey, there's this project called Blazor by the .NET guys.
And it was created by this guy by the name of Steve Sanderson, who's a really brilliant
web guy.
So what they're doing is they're using WebAssembly.
And if you're unfamiliar with that, it's a new, it's kind of like JavaScript, but in binary
compiled form.
So it's a binary instruction format for stack-based VM that runs inside of web browsers.
And it's designed as a portable target compilation for high-level languages like C, C++, and Rust.
So instead of writing in JavaScript and then running that in JavaScript engine, like V8
or whatever, you compile something like Rust or C++ or C into this WebAssembly stuff that
is then executed more or less natively in Firefox, Edge, Safari, and Chrome.
So all the browsers that really matter.
So coming back to this project, Blazor.
So what this is, is the .NET people and Steve Sanderson have found a way to take the entire
.NET runtime, known as the CLR, and compile it to WebAssembly.
And what's interesting about that is it's written entirely in C and C++.
You know what else is written entirely in C and C++?
Yeah, CPython.
CPython.
So what they've done is they've taken this thing, which is a native OS compiled thing,
and they've turned it into something that runs on the client side in the browser natively by
using WebAssembly.
That's cool.
That's awesome.
And it even has what's called a head-of-time compile mode.
So you can take your, in their case, .NET, my hope for the world Python code,
and pre-compile that into WebAssembly binaries that you ship instead of JavaScript or source code
or anything like that.
And they even created a single-page app front-end framework with routing and unit testing and
all sorts of stuff.
So this is a really cool project that I think may inspire people to try it for Python.
So what I still don't, I'm kind of, I hope people do try it for Python.
I think that'd be great.
I'm trying to, even Blazor itself, I'm trying to understand the use model.
Is it, it's not, at that point, you're not doing client-server stuff with Blazor, I'm assuming, or is it?
You could be doing client, so the real use of this is if you were thinking about using AngularJS,
VueJS, React, React Native, any of these, like, JavaScript front-end frameworks where most of your app
lives on the client side in the browser, like Gmail or Google Docs or Dropbox Paper or something like that.
Instead of writing that in tons of JavaScript and executing through a JavaScript engine, Blazor lets you write that in C# and execute it natively at a much higher performance.
Oh, okay.
Yeah.
So that's being accomplished by them.
And it's already, they have working models.
It's not like a theory.
This is already working.
So when we were at PyCon 2018 in Cleveland this year, one of the very first keynotes, a guy named Dan Callahan, I believe, may have misremembered his last name,
but worked for Mozilla.
And they basically laid this path out for Python and called for this to exist, said, look, there's WebAssembly, there's C code, CPython.
We need CPython in the browser.
Obviously, it can't do things like connect to databases or do other weird stuff that the browser won't allow.
But a vast majority of what you want to do in Python or JavaScript could be done in Python and faster and better.
Yeah.
Oh, that'd be cool.
Okay.
So that's really cool.
And I linked to his YouTube video that is the keynote where he lays this out.
It's like a 45-minute talk.
And the foundations of it, he actually references this in the video.
A lot of the foundations for WebAssembly itself come from this thing called ASM.js, A-S-M as in assembly, dot JS.
That's an interesting project that preceded it that will let you take, like, C code and run it in the browser by compiling it to JavaScript.
So Gary Bernhardt has this amazing fictional presentation that is very educational.
And the tech part it teaches is real, but it has, like, a story around it called The Birth and Death of JavaScript.
So that's the proper pronunciation in his fake world.
And I linked to that video as well.
And it's just, it's super insightful on how, like, ASM.js and WebAssembly can bring things in to this.
So, like, he has something insane, like, a macOS running Firefox.
And in Firefox, there's, like, Windows running, which is running Chrome.
Or something super, like, Inception-like based on just this ASM.js.
And WebAssembly could go farther.
So it's really cool.
Nice.
Yeah.
Anyway, just wanted to give sort of a highlight to that project.
I think actually creating this myself is probably beyond my understanding of CPython.
But I would love for this to exist.
Yeah.
And then we'll have to hit you up on that backflip.
Yeah, exactly.
I will do it maybe on something soft.
Maybe in a gymnastics place.
But, yeah, I'll definitely do it.
All right.
So very cool project.
It's not directly relevant, but it has massive parallels in the Python space.
So that would be cool.
Anything else you want to share with us, Brian, while we're all here?
No, I'm good.
Nice.
How about you?
I want to share two things.
One, we were talking before about my Building Data-Driven Web Apps course that's being well-received.
If you want to learn about building data-driven web apps in Python, check that out.
Put the link at the bottom.
Another one, someone sent in on Twitter to us just highlighting Guido Van Rossum's final presentation.
At the time, I don't think that he knew that it was his final presentation, but he gave a sort of closing the conference talk at PyCascades called a Python 3 retrospective.
And so just highlighting, like, here's his last official as BDFL presentation might be interesting to some people.
Yeah.
Yeah, it was a good talk.
I was there.
Okay.
I'll have to check that out.
I haven't seen it.
Yeah, yeah.
It's pretty good.
All right.
Well, Brian, thanks for being here and sharing everything you have.
Oh, yeah.
Thank you.
Yep.
Bye.
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.