Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

Transcript #91: Will there be a PyBlazor?

Return to episode page view on github
Recorded on Thursday, Aug 2, 2018.

00:00 Hello and welcome to Python bites where we deliver Python news and headlines directly to your buds. It's episode 91 recorded August 8th 2018 I'm Michael Kennedy and I'm Brian. Okay. Hey Brian, how you doing? I'm doing great. Awesome Well as always the Python news cycle has not let us down has it no it's it's a keeping up It's good. It's definitely we got a lot of good stuff to cover before we do though Another thing not letting us down is data dog. They're definitely helping us prop up So thank you data dog for sponsoring this episode check them out at Python by Fm slash data dog They actually have some cool new announcements, which I'll get to later. But let's talk about what makes Python cool, huh?

00:36 There's a lot of stuff that makes Python cool, but there's a there was an article That came up. I think it's on medium Hacker noon, that's right. Sorry hacker noon that I thought you were medium for a second by Shankar jaw and 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.

01:15 So, he starts off with the zen of Python, with "Import this," And that's a good thing for people to look at.

01:22 And then of course, if you're looking at cool imports, import anti-gravity that redirects you to XKCD is cool.

01:29 Yeah, if people have never typed import anti-gravity in their REPL in Python, they should definitely do that.

01:35 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.

01:47 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 Yeah, I agree and then things that that he starts off right the right off the bat after that with like how to swap two variables in one line of you know in like a comma b equals b comma 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, didn't used to be able to at least. 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.

02:24 A reminder to take a look at the collections and the inner tools modules or packages because there are a whole bunch of good stuff in there.

02:32 Enumerate with the enumerate keyword is or built in whatever that is.

02:38 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 Beldervost from PyBytes with a I not a Y not Python bytes about enumerate is it takes an extra parameter that'll 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.

03:11 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.

03:22 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're 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.

03:40 So that's pretty cool.

03:41 Yeah, I actually forget that all the time.

03:42 So I'm glad that people keep putting that down, because I forget about it.

03:46 And it saves time.

03:47 The many uses and meanings of underscore.

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

03:53 Yeah, exactly.

03:54 So if I were a Django person, I'm not.

03:57 My sites are based on pyramid and flask and things like that.

04:01 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.

04:30 So you have view only permissions on models, which is pretty cool.

04:35 And they said Django two has reached the end of mainstream support, they just released 208, which is the final version you're ever going to see except for possible security fixes until April of 2019.

04:47 After that, there's going to be no more Django two, so be sure to look about upgrading.

04:52 And in terms of features, we have the model view feature, we also have the ability to customize how deletes happen.

04:59 So there's like a delete query set option.

05:02 So you can delete select objects and customize that.

05:04 There's a way to override the default admin site.

05:06 There's tons of ORM features.

05:08 I highlighted one, but there's actually a whole bunch.

05:10 Caching is pretty cool.

05:12 So caching used to kind of like store items and when it got full, it would just randomly start throwing stuff out.

05:18 And now it uses LRU, last recently used to call.

05:21 So like a better sort of the hot stuff stays in the cache, which is good.

05:25 Migrations can now be run from PYC, so compiled files.

05:29 So in frozen environments that just have the binary bytecode, you can still run migrations and tons more.

05:34 Wow, that's actually pretty cool.

05:35 Yeah, there's a lot of stuff in there.

05:37 Like, there's pages and pages of changes from Django 2, which is pretty awesome.

05:41 Yeah, actually, if I was gonna 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.

05:54 - Yeah, it's pretty cool. - Great.

05:56 - So you've got one that's a little playful, right?

05:58 - Yeah, so this is actually pretty awesome.

06:01 It's actually a GitHub repo, and I'm gonna look this person up.

06:07 It's Annalena Popkiss, which actually, I might have actually got that last name right, who knows?

06:13 But she's a computer science graduate student, or computer science graduate.

06:19 She's working as an intern right now, according to her blog.

06:22 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.

06:32 And it's really fun.

06:34 So far it's up to day 18.

06:37 So she's still working on it and hopefully we'll continue it all with it.

06:42 But this is just some really fun stuff.

06:44 And I like the idea of using a theme for going through 100 days of code system.

06:50 So it's kind of fun.

06:52 - 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.

07:00 Data classes are a cool 3-7 thing that are awesome.

07:03 And she's modeling a house, right?

07:05 When the young wizard students go off to the wizard school, they go into like Gryffindor and Slytherin and the different houses.

07:13 And so like her whole example of exploring data classes is about that.

07:16 What also I think is actually gonna 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 a full-on explanatory blog post.

07:29 This one is probably six pages of writing about it, and that's got to help understand it really well and make it stick.

07:36 Yeah, and then it's also 100 days of writing, practice writing about tech stuff.

07:42 So yeah, it'll definitely help.

07:44 It's a good idea.

07:45 Yeah, I love it.

07:46 I'm glad you brought that one in.

07:47 I saw that come up.

07:48 I'm like, "Oh, that's pretty clever." Well done, Anna.

07:50 All right, before we move on to the next one, let me tell you about a new feature from Datadog.

07:56 So we talked about Datadog and their monitoring and stuff before.

08:00 So Brian, we've talked a little bit about machine learning and AI taking over the world, right?

08:06 Yes.

08:07 Yeah.

08:08 So here's a little bit more of it in a good way.

08:09 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.

08:21 That's cool, right?

08:22 That is really cool.

08:23 So it learns how your app normally works.

08:25 It's like, "Whoa, you know, it's pinned this thing at 100% CPU for some reason.

08:29 Something must have gone wrong." Or maybe it's totally flat.

08:32 You're processing no traffic.

08:33 Either way, you probably want to know.

08:35 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.

08:45 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

08:56 So that's pretty awesome, I'd like to check that out.

08:58 - Yeah, definitely cool.

08:59 - Yeah, we've talked about deployment once or twice, right?

09:02 - I think so.

09:03 - Along with our GUI kick.

09:06 So here's an interesting take on it.

09:08 So one of the things I think is challenging about distributing a Python application is you have to distribute your source code.

09:15 Now, maybe you distribute the PYC files so you can distribute like a bytecode version, but it's pretty easy to unbytecode that, right.

09:24 But there's not a lot of great ways to distribute your code.

09:27 If you're concerned that maybe someone will mess with it, like you could put it on to say a web server, but if somebody breaks into the web server, and they find your code, well, could change simple things like your stripe ID.

09:39 So all of a sudden, all your purchases start deposited into their bank account instead of yours or things like this, right.

09:44 So if you want to deploy your apps and protect them, that can be tricky.

09:48 And it's extra tricky in Python.

09:51 Because if we're deploying c++, or go or even dotnet, 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.

10:01 But in Python, you distribute, generally source code.

10:04 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.

10:15 So they wrote this article and created this thing called executing encrypted Python with no performance penalty.

10:22 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.

10:39 So that's pretty cool, right?

10:40 That's very cool.

10:41 Yeah.

10:42 And the way they make this work is they override the import statement.

10:45 They basically import a library that changes what import means.

10:50 So when you say import, it runs their custom code that says, oh, it's one of these encrypted files.

10:56 Well, that means grab the decryption key decrypt it.

10:58 Now we load that into memory.

11:00 And the no performance part comes from the fact that once Python has loaded a module, it's just in memory.

11:06 And so the decrypted versions in memory, you hit it again, and it's golden, right?

11:10 It just keeps running.

11:12 So basically, it maybe starts a tiny bit slower, but then it's the same.

11:15 So if this is something you're interested in, check it out.

11:18 It's pretty cool.

11:19 So is this a commercial thing?

11:20 Or is this something that...

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

11:24 That's very cool.

11:26 is from a commercial company, like a consulting company.

11:30 But I think, let me see if I can find the license.

11:33 Do they have a license?

11:33 The license is, wait for it, actually wait for GitHub.

11:37 Come on license.

11:38 Apache 2.0.

11:41 Yeah, permissive license.

11:42 Yeah, so it's free for commercial use.

11:44 - This is a very cool thing.

11:46 I have to check that out.

11:47 Yeah, nice.

11:48 - 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?

11:53 And everybody else is like, why do you want that?

11:55 I don't care about that.

11:56 But if you really wanted it, it seems like it'd be pretty cool.

11:58 So anyway, that's what I found for that one.

12:00 That's great.

12:01 - Nice.

12:02 - Yep.

12:03 What's this next one about?

12:04 I don't even know what to make of your notes here.

12:06 This is crazy.

12:07 It's cool.

12:07 (laughing)

12:09 - Well, actually, I just saw, this actually came in just this morning.

12:12 I saw a tweet from Harry Percival saying that he wrote a plugin for pytest called pytest-ICdiff.

12:21 And it's a plugin that allows you to use I see diff for asserts that are equal comparisons in pytest.

12:30 - Right, like a failure in say like, assert these are equal but then they're not.

12:36 And it'll show you like a color diff instead of just no, they're different.

12:40 - Yeah, that's pretty much it.

12:40 - I love it.

12:41 - And I never have never even heard of IC diff, but IC diff apparently is a different diff that you don't, isn't necessarily tied to pytest.

12:49 You can use it just on the command line for better diff, the color diffs.

12:54 Yeah, the IC stands for improved color diff, which is pretty cool.

12:58 And it's it's a Python project in and of itself.

13:01 And then it looks like Harry Percival's pytest defied it.

13:04 Yeah, it's cool that having some color there, highlight things.

13:08 I think it's great because so often when a test fails, you're like, Oh, what is going on?

13:13 Like, you want to look at it?

13:14 And you're like, what is that?

13:15 Is that Oh, there's that dot there, you know, like some color would really help, right?

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

13:21 Yeah, exactly.

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

13:27 Well, I don't know why you wouldn't use this if you're using pytest.

13:30 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.

13:38 Yeah, for sure.

13:39 Yeah, it's great.

13:40 Nice find there, and well done, Harry.

13:43 All right, the last one is a bit of amusing, and this was sent to us by one of our listeners, so thank you for sending this in.

13:50 And I wasn't sure whether we should cover it, but I kind of feel like we should.

13:54 So what they sent into us is highlighting a dotnet project, C# dotnet.

14:00 And you might think, Michael, why do we care about a dotnet project?

14:03 We don't really but the parallels for what we could do in Python, this would make me do a backflip.

14:09 I don't even know how to do it.

14:10 But I'd give it a shot, even though it might hurt.

14:12 So they said, Hey, there's this project called blazer by the dotnet guys.

14:17 And it was created by this guy by the name of Steve Sanderson, who's a really brilliant web guy.

14:21 So what they're doing is they're using WebAssembly.

14:26 And if you're unfamiliar with that, it's a new, it's kind of like JavaScript, but in binary compiled form.

14:33 So it's a binary instruction format for stack based VM that runs inside of web browsers.

14:39 And it's designed as a portable target a compilation for high level languages like C, C++ and Rust.

14:46 So instead of writing in JavaScript and then running that in, you know, JavaScript engine, like V8 or whatever, you compile something like rust or c++ or C into this web assembly stuff that is an executed more or less natively in Firefox, Edge, Safari and Chrome.

15:00 So all the browsers that really matter.

15:03 So coming back to this project blazer.

15:05 So what this is, is the dotnet people and Steve Sanderson have found a way to take the the entire dotnet runtime, known as the CLR and compile it to WebAssembly. And, you know, 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.

15:39 That's awesome. And it even has what's called a head of time compile mode. So you can take your in their case dotnet 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 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 So what I still don't kind of I hope people do try it for Python. I think that'd be great I'm trying to even blazer itself. I'm trying to understand the use model is it's not at that point You're not doing client server stuff with blazer I'm assuming or is it you could be doing client?

16:23 So the real use of this is if you were thinking about using angularjs Vue JS react react native any of these like JavaScript front-end frameworks where most of your Apple lives on the client side in the browser like Gmail or Google Docs or Dropbox paper or something like that.

16:41 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 Oh, okay.

16:52 Yeah, so that's being accomplished by them and it's already they have working models. It's not like a theory that's already working. So when we were at PyCon 2018 in Cleveland this year, one of the very first keynotes, a guy named Dan And Callahan, I believe, may have misremembered his last name, but worked for Mozilla.

17:11 And they basically laid this path out for Python and called for this to exist.

17:16 Said, look, there's WebAssembly.

17:18 There's C code, CPython.

17:20 We need CPython in the browser.

17:24 Obviously, it can't do things like connect to databases or do other weird stuff that the browser won't allow.

17:29 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 - Yeah, that'd be cool, okay.

17:37 - So that's really cool, and I linked to his YouTube video that is the keynote where he lays this out.

17:42 It's like a 45 minute talk.

17:44 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 J-S.

17:55 That's an interesting project that preceded it that will let you take C code and run it in the browser by compiling it to JavaScript.

18:02 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.

18:14 So that's the proper pronunciation in his fake world.

18:18 And I linked to that video as well.

18:20 And it's just, it's super insightful on how like asm.js and WebAssembly can bring things in to this.

18:27 So like he has something insane, like a macOS running Firefox and in Firefox, there's Windows running, which is running Chrome or something super like Inception-like based on just as Asm.js and WebAssembly could go farther.

18:43 So it's really cool.

18:43 >> Nice.

18:44 >> Yeah. Anyway, just wanted to give a highlight to that project.

18:47 I think actually creating this myself is probably beyond my understanding of CPython, but I would love for this to exist.

18:54 >> Yeah, and then we'll have to hit you up on that backslip.

18:56 >> Yeah, exactly. I will do it maybe on something soft, maybe in a gymnastics place, but yeah, I'll definitely do it.

19:03 All right.

19:04 So very cool project.

19:05 It's not directly relevant, but it has massive parallels in the Python space.

19:09 So that'd be cool.

19:10 Anything else you want to share with us, Brian, while we're all here?

19:13 - No, I'm good.

19:13 - Nice.

19:14 - How about you?

19:15 - I want to share two things.

19:16 One, we talking before about my building data-driven web apps course that's being well-received.

19:20 If you want to learn about building data-driven web apps in Python, check that out.

19:24 Put the link at the bottom.

19:25 Another one, someone sent in on Twitter to us, just highlighting Guido van Rossum's final presentation.

19:33 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.

19:45 And so just highlighting like here's his last official as BDFL presentation might be interesting to some people.

19:52 - Yeah. - Yeah, it was a good talk.

19:53 I was there. - Okay.

19:54 I'll just check that out. I haven't seen it. Yeah, it's pretty good. All right. Well, Brian, thanks for being here and sharing everything you have. Oh, yeah. Thank you. Yep. Bye. Bye.

20:02 Thank you for listening to Python bites. Follow the show on Twitter via at Python bites. That's Python bites as in b y t s. And get the full show notes at If you have a news item you want featured, just visit 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.

20:25 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page