Transcript #91: Will there be a PyBlazor?
Return to episode page view on github00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
00:04 It's episode 91, recorded August 8th, 2018. I'm Michael Kennedy.
00:09 And I'm Brian Ockin.
00:10 Hey, Brian. How are you doing?
00:11 I'm doing great.
00:12 Awesome. Well, as always, the Python news cycle has not let us down, has it?
00:16 No, it's keeping up. It's good.
00:19 It's definitely. We've got a lot of good stuff to cover.
00:21 Before we do, though, another thing not letting us down is Datadog.
00:24 They're definitely helping us prop up.
00:27 So thank you, Datadog, for sponsoring this episode.
00:29 Check them out at pythonbytes.fm.datadog.
00:31 They actually have some cool new announcements, which I'll get to later.
00:33 But let's talk about what makes Python cool, huh?
00:36 There's a lot of stuff that makes Python cool.
00:38 But there was an article that came up.
00:41 I think it's on Medium.
00:43 HackerNoon. That's right.
00:45 Sorry, HackerNoon, that I thought you were Medium for a second.
00:47 By Shankar Jha.
00:49 And I probably mispronounced his last name. Apologies.
00:52 But an article called What Makes Python Cool.
00:55 And my first reaction is like, oh, yet another rah-rah.
00:58 Python is awesome.
00:59 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.
01:11 They might not run into for a while.
01:13 And they're good things to note.
01:15 So he starts off with the Zen of Python with import this.
01:19 And it'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.
01:39 It kind of indoctrinates you into the fact that the Python community doesn't take itself too awfully seriously.
01:46 It's all serious work and we do a lot of important things.
01:50 But it's a good, fun thing to have there.
01:52 So I hope they never take those out.
01:54 Yeah, I agree.
01:55 And then things that he starts off right off the bat after that with how to swap two variables in one line.
02:02 Like A, B equals B, A.
02:07 We're just used to that now.
02:08 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.
02:16 You didn't used to be able to at least.
02:18 Nope, I don't think so.
02:19 And it's a fun extra thing.
02:20 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 iter 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.
02:45 Do you know what I learned from Bob Beldervos from PyBytes with an I, not a Y, not Python bytes, about enumerate?
02:51 Is it takes an extra parameter that will let the index start at one or anything you specify.
02:56 Because I've always had like it go at zero, then I'll have like index plus one all over the place.
03:00 Well, you can just say start at one, two, three.
03:02 That's a parameter in there.
03:03 It's nice.
03:03 Yeah, and that's a brilliant thing because, yeah, I've seen that a lot of people adding one.
03:08 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.
03:20 Anyway, it's a good article.
03:22 Yeah, absolutely.
03:22 I really – I think it covers a lot of nice stuff.
03:24 And if you're kind of new to Python, there are some cool things in here that you'll be like,
03:29 oh, I didn't know when I was working in the REPL that if I forgot to assign some computation to a variable,
03:35 I can still access it one time quickly as an underscore.
03:39 So that's pretty cool.
03:40 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 and it saves time.
03:47 The many uses and meanings of underscore.
03:49 Yeah, and we're not even in Perl.
03:52 Yeah, exactly.
03:53 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.
04:07 And this is the first major release after Django kicked Legacy Python out the door.
04:12 So Django 2.1 is out.
04:13 Pretty cool, huh?
04:14 Yeah.
04:14 What do we got in 2.1?
04:16 Well, there's actually a ton of features.
04:17 I think the one that the team highlights the most is this thing called model view permissions.
04:22 So Django comes with its ORM, right?
04:24 Its own ORM.
04:26 And in there, you have models that map to the database.
04:29 And now you can set it up so you have view-only permissions on models, which is pretty cool.
04:35 And they said Django 2 has reached the end of mainstream support.
04:39 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.
04:47 But after that, there's going to be no more Django 2.0.
04:49 So be sure to look about upgrading.
04:51 And then in terms of features, we have the model view feature.
04:54 We also have the ability to customize how deletes happen.
04:59 So there's like a delete query set option.
05:01 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:09 Caching is pretty cool.
05:12 So caching used to kind of like store items.
05:15 And when it got full, it would just randomly start throwing stuff out.
05:17 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:24 Migrations can now be run from PYC, so compiled files.
05:29 So in frozen environments that are 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 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.
05:49 Because I'm not really a fan of the look of the default admin site.
05:54 Yeah, it's pretty cool.
05:55 Great.
05:55 So you've got one that's a little playful, right?
05:58 Yeah.
05:59 So this is actually pretty awesome.
06:02 It's actually a GitHub repo.
06:04 And I'm going to look this person up.
06:07 It's Annalena Popkis, which actually I might have actually got that last name right.
06:12 Who knows?
06:12 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.
06:25 But she's doing it all in the open and all in Harry Potter themes.
06:31 And it's really fun.
06:33 And so far, it's up to day 18.
06:37 So she's still working on it.
06:39 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 a 100 days of code system.
06:50 So it's kind of fun.
06:51 Yeah.
06:52 So to give people an idea of what you're describing and what she's doing is like, for example, on
06:57 days 16, 17, 18, she worked with data classes.
07:00 Data classes are a cool 3-7 thing that are awesome.
07:02 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
07:11 and Slytherin and the different houses.
07:12 And so like her whole example of exploring data classes is about that.
07:16 What also I think is actually going to pay off pretty big time for her is every one of these,
07:21 she's not just writing the code and putting it in a separate section in GitHub.
07:25 But she's also doing like a full-on explanatory blog post.
07:29 Like this one is probably six pages of writing about it.
07:33 And that's got to help understand it really well and make it stick.
07:35 Yeah.
07:36 And then it's also, you know, 100 days of writing, you know, practice writing about text stuff.
07:41 So yeah, it'll definitely help.
07:43 It's a good idea.
07:44 Yeah.
07:45 I love it.
07:45 I'm glad you brought that one in.
07:46 I saw that come up.
07:47 I'm like, wow, that's pretty clever.
07:49 Well done, Anna.
07:50 Nice.
07:50 All right.
07:51 Before we move on to the next one, let me tell you about a new feature from Datadog.
07:55 So we talked about Datadog and their monitoring and stuff before.
07:59 So Brian, we've talked a little bit about machine learning and AI taking over the world, right?
08:05 Yes.
08:06 Yeah.
08:07 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:23 That is really cool.
08:24 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.
08:30 Or maybe it's totally flat.
08:32 You're processing no traffic.
08:34 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 pythonbytes.fm/Datadog.
08:55 So that's pretty awesome.
08:57 I'd like to check that out.
08:58 Yeah, definitely cool.
08:59 Yeah.
08:59 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:23 But there's not a lot of great ways to distribute your code if you are concerned that maybe someone will mess with it.
09:29 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.
09:38 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 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.
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:21 Oh, wow.
10:21 Cool.
10:22 So, you know, we have the PYC, which is the bytecode thing.
10:25 And that's just straight bytecode.
10:26 But what they've created is what they're calling a PYCE file.
10:30 And the PYCE file is an encrypted Python byte file, which until you decrypt it, can't be executed.
10:38 So that's pretty cool, right?
10:40 That's very cool.
10:41 Yeah, 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:55 Well, that means grab the decryption key, decrypt it.
10:58 Now we load that into memory.
10:59 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 version's in memory, you hit it again, and it's golden, right?
11:10 It just keeps running.
11:11 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:18 So is this a commercial thing or is it something there?
11:21 I think it's open source on GitHub as far as I can tell.
11:24 That's very cool.
11:26 It is from a commercial company, like a consulting company.
11:29 But I think, let me see if I can find the license.
11:32 Do they have a license?
11:33 The license is, wait for it.
11:36 Actually, wait for GitHub.
11:37 Come on, license.
11:38 Apache 2.0.
11:40 Yeah, permissive license.
11:42 Yeah, so it's free for commercial use.
11:44 This is a very cool thing.
11:46 I'll 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.
11:53 You know what I mean?
11:53 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:00 Nice.
12:01 Yeah.
12:02 What's this next one about?
12:03 I don't even know what to make of your notes here.
12:06 This is crazy.
12:06 It's cool.
12:07 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 plug-in for pytest called pytest-ICDiff.
12:21 And it's a plug-in that allows you to use ICDiff for asserts that are equal comparisons in pytest.
12:31 Right, like a failure in, say, like, assert these are equal, but then they're not.
12:35 And it'll show you like a color diff instead of just, no, they're different.
12:39 Yeah, that's pretty much it.
12:40 I love it.
12:41 And I have never even heard of ICDiff, but ICDiff apparently is a different diff that isn't necessarily tied to pytest.
12:49 You can use it just on the command line for better diff, colored diffs.
12:54 Yeah, IC stands for improved color diff, which is pretty cool.
12:58 And it's a Python project in and of itself.
13:00 And then it looks like Harry Percival's pytest-ified 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:12 Like, you want to look at it and you're like, what is that?
13:15 Is that, oh, there's that dot there.
13:16 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:21 So that's a pretty short section, just a new tool that I thought was neat.
13:25 I thought I'd share.
13:26 Well, I don't know why you wouldn't use this if you're using pytest.
13:29 Yeah, that won't help you for other types of asserts.
13:33 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.
13:41 And well done, Harry.
13:42 All right, the last one is a bit of a amusing.
13:45 And this was sent to us by one of our listeners.
13:47 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:53 So what they sent in to us is highlighting a .NET project, C#.NET.
14:00 And you might think, Michael, why do we care about a .NET project?
14:03 We don't really.
14:04 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, but I'd give it a shot, even though it might hurt.
14:12 So they said, hey, there's this project called Blazor by the .NET guys.
14:17 And it was created by this guy by the name of Steve Sanderson, who's a really brilliant
14:20 web guy.
14:20 So what they're doing is they're using WebAssembly.
14:25 And if you're unfamiliar with that, it's a new, it's kind of like JavaScript, but in binary
14:31 compiled form.
14:32 So it's a binary instruction format for stack-based VM that runs inside of web browsers.
14:38 And it's designed as a portable target compilation for high-level languages like C, C++, and Rust.
14:45 So instead of writing in JavaScript and then running that in JavaScript engine, like V8
14:51 or whatever, you compile something like Rust or C++ or C into this WebAssembly stuff that
14:56 is then executed more or less natively in Firefox, Edge, Safari, and Chrome.
15:00 So all the browsers that really matter.
15:01 So coming back to this project, Blazor.
15:05 So what this is, is the .NET people and Steve Sanderson have found a way to take the entire
15:11 .NET runtime, known as the CLR, and compile it to WebAssembly.
15:16 And what's interesting about that is it's written entirely in C and C++.
15:22 You know what else is written entirely in C and C++?
15:24 Yeah, CPython.
15:26 CPython.
15:27 So what they've done is they've taken this thing, which is a native OS compiled thing,
15:32 and they've turned it into something that runs on the client side in the browser natively by
15:38 using WebAssembly.
15:38 That's cool.
15:39 That's awesome.
15:40 And it even has what's called a head-of-time compile mode.
15:43 So you can take your, in their case, .NET, my hope for the world Python code,
15:49 and pre-compile that into WebAssembly binaries that you ship instead of JavaScript or source code
15:54 or anything like that.
15:55 And they even created a single-page app front-end framework with routing and unit testing and
16:01 all sorts of stuff.
16:02 So this is a really cool project that I think may inspire people to try it for Python.
16:06 So what I still don't, I'm kind of, I hope people do try it for Python.
16:11 I think that'd be great.
16:12 I'm trying to, even Blazor itself, I'm trying to understand the use model.
16:16 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 You could be doing client, so the real use of this is if you were thinking about using AngularJS,
16:28 VueJS, React, React Native, any of these, like, JavaScript front-end frameworks where most of your app
16:35 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.
16:52 So that's being accomplished by them.
16:54 And it's already, they have working models.
16:56 It's not like a theory.
16:57 This is already working.
16:59 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,
17:09 but worked for Mozilla.
17:10 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.
17:20 We need CPython in the browser.
17:23 Obviously, it can't do things like connect to databases or do other weird stuff that the browser won't allow.
17:28 But a vast majority of what you want to do in Python or JavaScript could be done in Python and faster and better.
17:34 Yeah.
17:35 Oh, that'd be cool.
17:36 Okay.
17:36 So that's really cool.
17:38 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:43 And the foundations of it, he actually references this in the video.
17:47 A lot of the foundations for WebAssembly itself come from this thing called ASM.js, A-S-M as in assembly, dot JS.
17:55 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.
18:02 So Gary Bernhardt has this amazing fictional presentation that is very educational.
18:07 And the tech part it teaches is real, but it has, like, a story around it called The Birth and Death of JavaScript.
18:13 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.
18:32 And in Firefox, there's, like, Windows running, which is running Chrome.
18:37 Or something super, like, Inception-like based on just this ASM.js.
18:41 And WebAssembly could go farther.
18:42 So it's really cool.
18:43 Nice.
18:44 Yeah.
18:44 Anyway, just wanted to give sort of a highlight to that project.
18:47 I think actually creating this myself is probably beyond my understanding of CPython.
18:53 But I would love for this to exist.
18:54 Yeah.
18:54 And then we'll have to hit you up on that backflip.
18:56 Yeah, exactly.
18:57 I will do it maybe on something soft.
19:00 Maybe in a gymnastics place.
19:02 But, yeah, I'll definitely do it.
19:03 All right.
19:03 So very cool project.
19:05 It's not directly relevant, but it has massive parallels in the Python space.
19:09 So that would be cool.
19:10 Anything else you want to share with us, Brian, while we're all here?
19:12 No, I'm good.
19:13 Nice.
19:13 How about you?
19:14 I want to share two things.
19:15 One, we were 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.
19:52 Yeah, it was a good talk.
19:53 I was there.
19:53 Okay.
19:54 I'll have to check that out.
19:55 I haven't seen it.
19:55 Yeah, yeah.
19:56 It's pretty good.
19:57 All right.
19:57 Well, Brian, thanks for being here and sharing everything you have.
20:01 Oh, yeah.
20:01 Thank you.
20:02 Yep.
20:02 Bye.
20:02 Bye.
20:03 Thank you for listening to Python Bytes.
20:05 Follow the show on Twitter via at Python Bytes.
20:07 That's Python Bytes as in B-Y-T-E-S.
20:10 And get the full show notes at pythonbytes.fm.
20:14 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.
20:18 We're always on the lookout for sharing something cool.
20:21 On behalf of myself and Brian Okken, this is Michael Kennedy.
20:24 Thank you for listening and sharing this podcast with your friends and colleagues.