- Podcasts
- Python Bytes
- #91 Will there be a PyBlazor?
About this episodeTopics covered in this episode: What makes the Python Cool Django 2.1 released Awesome Python Features Explained Using Harry Potter…
- What makes the Python Cool
- Django 2.1 released
- Awesome Python Features Explained Using Harry Potter
- Executing Encrypted Python with no Performance Penalty
- icdiff and pytest-icdiff
- Will there be a PyBlazor?
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#91 Will there be a PyBlazor?
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?
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.
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.
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.
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.
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?
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?
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.
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.
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.
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++.
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.
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.
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.
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.
