Python Bytes - #91 Will there be a PyBlazor?
Episode Date: August 15, 2018Topics covered in this episode: 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 See the full show notes for this episode on the website at pythonbytes.fm/91
Transcript
Discussion (0)
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 Ocken.
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 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 data dog for sponsoring this episode check
them out at pythonbytes.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 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 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 it's a good thing for people to look at.
And then, of course, if you're 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 like how to swap two variables in one line of, you know, 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 uh you didn't used to be able to at least i don't think so and
it's a fun extra thing um how fast you can spin up a web server just with one line. 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. 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 Belderbos 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 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 uh doing zip a couple zip
tricks how cool comprehensions and dictionaries are and uh pretty print with p print anyway it's
a good article yeah absolutely i really uh 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'd 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 inferring.
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 208, 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 20. 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 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.
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 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 100 Days of Code system.
So it's kind of fun.
Yeah.
So to give people an idea 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.
They're 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 100 days of writing, 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. 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, 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 slash 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 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.
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 versions 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 something that... 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 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? 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'd be pretty cool. So anyway, that's what I found for that one. That's great.
Nice.
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. Well, actually, I just saw that was a this actually
came in just this morning, I saw a tweet from Harry Percival, saying that he wrote a plugin
for PyTest called PyTest dash IC diff. And it's a plugin that allows you to use icdiff for asserts that are equal comparisons
in pytest right like a failure in say like a certain 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 never have never even heard of IC diff, but I see diff apparently is a,
a different diff that you don't,
isn't necessarily tied to PyTest.
You can use it just on the command line for,
for better diff,
the colored diffs.
Yeah.
The IC stands for improved color diff,
which is pretty cool.
And it's,
it's a Python project in and of itself.
And then it looks like Harry Percival's PyTestified it.
Yeah.
It's cool.
That having some color there,
I like things.
I think it's great because so often when a test fails,
you're like,
ah,
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, I don't know why you wouldn't use this if you're using pie 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. That'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 us by one of our listeners. So thank you for sending this in. And I wasn't sure whether we should 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 a compilation for high level languages like C, C++ and Rust. 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 WebAssembly stuff that is an executed more
or less natively in Firefox, Edge, Safari and Chrome. So all the browsers that really matter.
So coming back to this project blazer.
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, 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, C Python. C Python. So know what else is written entirely in C and C++?
Yeah, C Python.
C Python.
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 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 I still don't
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.
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,
Vue.js, 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 Sharp
and execute it natively at a much higher
performance.
So that's being accomplished
by them and 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 CPython, we need CPy Python 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, 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.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 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 Asm.jsjs and web assembly can bring things
in to 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 like inception like
based on just asm.js and web assembly couldsembly 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, 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?
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.
So 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.
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 Auchin,
this is Michael Kennedy.
Thank you for listening and sharing this podcast
with your friends and colleagues.