Brought to you by DigitalOcean - grab your $100 credit and deploy your first project for free


« Return to show page

Transcript for Episode #91:
Will there be a PyBlazor?

Recorded on Thursday, Aug 2, 2018.

0:00 KENNEDY: 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.

0:08 OKKEN: And I'm Brian Okken.

0:10 KENNEDY: Hey, Brian, how you doing?

0:10 OKKEN: I'm doing great.

0:12 KENNEDY: Awesome, well, as always, the Python news cycle has not let us down, has it?

0:16 OKKEN: No, it's keeping up, it's good.

0:19 KENNEDY: 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?

0:37 OKKEN: 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 that's a good thing for people to look at, and then of course if you're looking at cool imports, import antigravity that redirects you to XKCD is cool, and he lists that.

1:29 KENNEDY: Yeah, people who've never typed import antigravity in their REPL in Python, they should definitely do that.

1:35 OKKEN: And those two things actually make it, they're not just jokes, they're, 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 there's, it's a good fun thing to have there. So I hope they never take those out.

1:54 KENNEDY: Yeah, I agree.

1:55 OKKEN: And then, things that, he starts out right off the bat after that with how to swap two variables in one line, like a, b = 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. It didn't used to be able to at least.

2:17 KENNEDY: Nope, I don't think so.

2:17 OKKEN: 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 in the itertools modules, or packages, because there're 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.

2:45 KENNEDY: Do you know what I learned from Bob Belderbos from PyBites with a I, not a Y, not Python Bytes, about enumerate, is it takes an extra parameter that'll let the index start at 1 or anything you specify, because I've always had, like equal to 0, then I'll have like index plus one, all over the place, well, you can just say, start at 1, 2, 3 as a parameter in there, it's nice.

3:03 OKKEN: Yeah, and that's a brilliant thing because, yeah, I've seen that a lot, of people adding 1, just start at 1 and it's in the right order. Easily reverse a list doing zip, a couple zip tricks. How cool comprehensions in dictionaries are, and pretty print with pprint. Anyway, it's a good article.

3:21 KENNEDY: 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.

3:39 OKKEN: 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.

3:47 KENNEDY: The many uses and meanings of underscore.

3:50 OKKEN: Yeah, and we're not even in Perl.

3:53 KENNEDY: 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 back flip 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?

4:14 OKKEN: Yeah, what do we got in 2.1?

4:16 KENNEDY: 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, it's 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. After that, there's going to be no more Django 2.0, so be sure to look about upgrading, and 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 cull, so like a better sort of, the hot stuff stays in the cache, which is good. Migrations can now be run from PYCs, so compiled files, so in frozen environments that just have the binary byte code, you can still run migrations and tons more.

5:34 OKKEN: Wow, that's actually pretty cool.

5:35 KENNEDY: Yeah, there's a lot of stuff in it, like, there's pages and pages of changes from Django 2 which is pretty awesome.

5:41 OKKEN: Yeah, I actually, if I was going to go look at Django, which is on my todo 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, so.

5:54 KENNEDY: Yeah, it's pretty cool.

5:54 OKKEN: Great!

5:55 KENNEDY: So, you've got one that's a little playful, right?

5:58 OKKEN: Yeah, so this is actually pretty awesome. There's, it's actually a GitHub repo, and I'm going to look this person up. It's Anna-Lena Popkes, 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, all in the open, and all in Harry Potter themes, and it's really fun, and it's, so far, it's up to, up to Day 18, so she's still working on it, and hopefully will continue 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.

6:52 KENNEDY: Yeah, so, to give people an idea of what you were 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, Griffindor and Slytherin and the different houses, and so, like, her whole example of exploring data classes is about that. What also what 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.

7:36 OKKEN: Yeah, and then it's also 100 days of writing, practice writing about tech stuff, so yeah, it'll definitely help, it's a good idea.

7:45 KENNEDY: Yeah, I love it, I'm glad you brought that one in. I saw that come up, you're all, 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?

8:06 OKKEN: Yes.

8:06 KENNEDY: 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?

8:22 OKKEN: That is really cool.

8:24 KENNEDY: So it learns how your app normally works, and 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.

8:57 OKKEN: Yeah, definitely, cool.

8:59 KENNEDY: Yeah, we've talked about deployment once or twice, right?

9:02 OKKEN: I think so.

9:03 KENNEDY: Along with our GUI kick, so here's an interesting take on it. 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 byte code version, but it's pretty easy to un-byte code that, right? But there's not a lot of great ways to distribute your code if you're 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 depositing 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.

10:19 OKKEN: Oh, wow, cool!

10:22 KENNEDY: So, you know we have the PYC which is the byte code thing, and that's just straight byte code, 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?

10:39 OKKEN: That's very cool.

10:41 KENNEDY: 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, maybe it 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.

11:18 OKKEN: So is this a commercial thing, or is it something they're...

11:20 KENNEDY: I think it's open source on GitHub as far as I can tell.

11:24 OKKEN: That's very cool.

11:26 KENNEDY: 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.

11:44 OKKEN: This is a very cool thing. I'll have to check that out, yeah, nice.

11:48 KENNEDY: 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? And 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 would be pretty cool, so anyway, that's what I found for that one, that's great.

12:01 OKKEN: Nice.

12:01 KENNEDY: Yep. What's this next one about? I don't even know what to make of your notes here. This is crazy, it's cool.

12:09 OKKEN: Well, actually, I just saw that was, this actually came in just this morning, I saw a tweet from Harry Percival, saying that he wrote a plugin for PyTest called pytest-icdiff, and it's a plugin that allows you to use icdiff for asserts that are equal comparisons, in PyTest.

12:31 KENNEDY: 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.

12:39 OKKEN: Yeah, that's pretty much it.

12:41 KENNEDY: I love it!

12:41 OKKEN: And I had never even heard of icdiff, but icdiff apparently is a different diff that you don't, isn't necessarily tied to PyTest. You can use it just on the command line for better diff. The colored diffs, so.

12:55 KENNEDY: The 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.

13:04 OKKEN: Yeah, it's cool having some color there, I like things.

13:08 KENNEDY: I think it's great, because so often when a test fails, you're like, oh, what is going on? And like, you want to look at it, and you're like, what is that, is that, oh, there's that dot there, or you know, like some color would really help, right?

13:18 OKKEN: Yeah, to highlight exactly which part of it's different.

13:21 KENNEDY: Yeah, exactly.

13:22 OKKEN: So that's a pretty short section, just a new tool that I thought was neat, I thought I'd share, so.

13:26 KENNEDY: Well, I don't know why you wouldn't use this if you're using PyTest.

13:29 OKKEN: Yeah, that won't help you for other types of asserts, but it's the equality of why is it not equal that it really gets, trips people up sometimes.

13:38 KENNEDY: Yeah, for sure, it's great, nice find there, and well done, Harry. All right, the last one is a bit of a musing, and this was sent to use by one of our listeners, so thank you for sending this, 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 of what we could do in Python, this would make me do a back flip. 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 really a 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 a stack-based VM that runs inside of web browsers, and it's designed as a portable target of 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++?

15:25 OKKEN: Yeah, CPython.

15:25 KENNEDY: 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.

15:38 OKKEN: That's cool.

15:39 KENNEDY: That's awesome, and it even has what's called Ahead 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. They even created, like, 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.

16:06 OKKEN: So, what, I still don't, I'm kind of, I hope people do try and provide that, I think that would 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?

16:21 KENNEDY: You could be doing client, so the real use of this is, if you were thinking about using AngularJS, Vue.js, React, React Native, any of these Javascript front end frameworks where most of your app lives on the client side in a 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.

16:51 OKKEN: Oh, okay.

16:51 KENNEDY: 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, I 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.

17:35 OKKEN: Yeah, that'd be cool, okay.

17:37 KENNEDY: So that's really cool, and I linked to his YouTube video that is of 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, ASM as in assembly.js. That's an interesting project that preceded it that would 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 his 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 super insightful on how, like, asm.js and WebAssembly can bring things into this, so like, he has something insane like, a Mac OS running Firefox and in Firefox, there's, like, Windows running, which is running Chrome, or something super Inception-like, based on just this asm.js and Web Assembly could go farther, so it's really cool.

18:43 OKKEN: Nice.

18:44 KENNEDY: 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.

18:54 OKKEN: Yeah, and then we'll have to hit you up on that back flip.

18:56 KENNEDY: 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'd be cool. Anything else you want to share with us, Brian, while we're all here?

19:12 OKKEN: No, I'm good.

19:13 KENNEDY: Nice.

19:13 OKKEN: How about you?

19:14 KENNEDY: I want to share two things, one, we, 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 in 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 the Python 3 Retrospective, and so, just highlighting, here's his last official, as BDFL, presentation. Might be interesting to some people. Yeah, it was a good talk, I was there.

19:53 OKKEN: Okay, I'll have to check that out, I haven't seen it, so.

19:56 KENNEDY: Yeah, yeah, it's pretty good. All right, well, Brian, thanks for being here and sharing everything you have.

20:01 OKKEN: Uh-huh, yeah, thank you.

20:01 KENNEDY: Yep, bye.

20:02 OKKEN: Bye.

20:03 KENNEDY: Thank you for listening to Python Bytes. Follow the show on Twitter via @pythonbytes, 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.

Back to show page