Hey everyone, Michael here. I want to take a quick moment for an editorial comment before we get to
this week's show. On the last episode, we covered a story from Bloomberg about China implanting
hardware hacking devices into motherboards for servers. Since that article came out,
there's been a lot of pushback from the organizations named Amazon, Apple, and others.
And there's been a few articles that raised some doubts about the veracity of the original Bloomberg
article. I'm linking to an article in Forbes called Doubt Swirl About Bloomberg's China Tip Hack Report.
This doesn't mean the original article is false or implausible, but it may be. And because of that,
I felt like I should add this disclaimer and warning about the coverage we had on episode 98.
Sorry about that. Now, let's get on to some Python-focused topics on this episode with Brian.
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 99, recorded October 10th, 2018. I'm Michael Kennedy.
I'm Brian Okken.
Brian, we're coming up really close on episode 100.
Yeah, one more. This is 99. Wow.
Yeah, we're going to have to do something cool for that one.
But for now, I think it is super cool that DigitalOcean is sponsoring the show,
not just for today, but for the rest of the year.
That is very cool.
Yeah, thank you, DigitalOcean. Check them out at pythonbytes.fm/DigitalOcean.
Get $100 credit for new users.
I think I had said this before as a joke to you, and you didn't necessarily agree with it,
but your first item here may belial some agreement that if you have a problem and you solve it with a regular expression,
you now have two problems.
Yes. Yeah. Well, definitely.
Within code, at least you have two things to support.
Yeah, that's right.
But you've run across some library that's actually really awesome for simple, what you might think of as red jacks problems.
I got this from a tweet from Kenneth Reitz.
He said, oh, yeah, everybody, by the way, parse is a thing or something like that.
Parse is a library that the tagline is it's the opposite of format.
So in the general sense of it, there's a bunch of things you can do.
You can parse strings.
You can search inside strings.
You can find all the element patterns or whatever from a string.
But you give it both the string that you're searching and then also a instead of a regular expression for what to search for,
basically the same string, but with parts of it replaced with the curly braces or something like that to say,
if I were to have printed it with format using this string, I would have gotten this output and reverse that out.
And then you can get the results out to see all the stuff.
That's awesome.
So you could say like, this is episode curly curly of Python bytes.
And then you could actually parse it.
And that little curly curly would say, give you the number.
Well, I guess the first example would give you a string and you could put a colon D and it would actually give you an integer 99.
Yeah, definitely.
That is cool.
It has some like cool things too, because if you were going to do that and pass in elements of a dictionary,
you're going to have this thing return basically things that look like dictionaries with named elements
and both positional elements and named elements.
And it's pretty neat.
And I was playing with it like the for each or the find all.
So you can put that in a loop to say like for all the elements in and I gave it a big file,
finding a whole bunch of colon or a CSV file or something and pulling out elements.
And it works really good.
And the thing I like about it is it's more readable than a regular expression.
So if you've got something simple like that, that you've got multiple people that have to be able to support it,
I think this is a good choice.
Yeah, I love it.
It's a really cool example.
And you can tell that it's probably written by somebody who understands Regex well under the covers,
but you don't have to think about it because it has like a compiled mode and things like that,
which Regex often do.
Yeah, and you can pass in a pattern apparently, but if you're going to figure out patterns,
then why not just use Regex?
So yeah.
Yeah, quite cool.
Anyway.
I like it.
I'm going to see if I can use it next time I need something like this.
So this next one I want to talk about has to do with GUIs.
Can you believe it?
Yeah, we've covered that a few times.
I think we have.
So this one is called the Fman Build System, and it comes from the project,
which is like a dual pane file explorer for Windows and Mac and so on from Michael Herman.
So it's a pretty cool project, but I'm not interested so much in covering the desktop app that he built per se,
but the tool to build it.
So the Fman Build System, right?
So what it lets you do is it lets you create GUI apps for Windows, Mac, and Linux,
as in here is my .app file or my .exe.
Go click it.
In fact, it gives you an installer, right?
And like a proper installer for Windows, one of those, you know, drag here,
and it has like the applications folder for a .app file, disk image, and macOS.
I mean, this is nice.
Wow, that's kind of like one of the missing pieces that we've had for packaging and sending out things.
It really is, right?
It's quite cool.
So like I said, Windows, Mac, and Linux works really well.
It's what he uses for his project.
It's open source, so you can use it for free on open source projects.
It's licensed under the GPL for commercial stuff, so you can buy, basically buy a license for it.
Now, if you're using Qt, you also have to buy a license for Qt, and that's kind of a complicated story.
Looking to figure out a little bit more about that, honestly.
I don't really know the full story there.
It's sort of like I've got this commercial side and this open source side, but at least if you're doing open source stuff, I think it's a really cool option.
Yeah, I like that.
Even the idea of being able to, matching the model, similar model as what Qt's model is, is a decent idea.
Yeah, and if the point is to package Qt apps, it's almost probably unavoidable.
Yeah, definitely.
And I also like, I got to give a shout out to Michael Herman.
It's not trivial to say, take a piece of your project and pull it off, as he did with the build system, so that it can be usable for other people.
That's pretty cool.
Yeah, absolutely.
So, JSON, not a whole lot of validation there, is there?
Well, I think there's a lot of ways to validate JSON, but I don't know if everybody does.
I don't think I've ever, in all the times where I've used JSON to talk with different parts of an application, I usually just kind of assume it's all working right.
Yeah, for sure.
But there are validators out there, and this one, the one I want to cover, has been recommended by a few people.
It's, the documentation is a little light, so I think it's called Fast JSON Schema.
But the name is descriptive.
Yeah, definitely.
And I'm not sure what the, so one of the articles that I'm going to link to has got four different libraries, including Fast JSON Schema.
And I'm not sure what they were validating.
It's like way faster than everything else.
So, JSON Schema takes five seconds.
JSON Spec takes seven.
And then his was the Fast JSON Schema, 250 milliseconds.
And I'm not sure how big of a data set this is to have anything take five seconds or seven seconds.
Yeah, it must be the same size, one would hope, you know?
Yeah, it's a compiling scheme.
So, kind of the scheme is, it's a pretty simple interface.
I think, like I said, the documentation is a little slim.
But you describe a schema in terms of what the types of each element is supposed to be like.
And I think there's some optional keywords and stuff like that you can throw in there.
And then you compile it, you compile that into your own validator.
So, this is a, like we were talking about with Regex, you compile it so that it runs faster.
And that's what this does.
It just comes up, you compile your own validator.
And then you can use that to validate any strings that you want.
Yeah, it's cool.
Yeah.
So, JSON Schema is a separate specification.
And you can even learn by that json-schema.org that allows you to create a secondary JSON file that is the type system for the original data exchange.
So, if I have like an address, I could say, okay, here my schema is.
This is an object that has properties like post office box and extended address.
Those are strings and so on.
You can even have like dependencies and stuff like so.
The post office box must be a valid street address, which is defined, you know, elsewhere.
So, this is pretty cool.
You take those files, you feed it to this validator, and it'll take anything you get back from, say, a web service or something and say, yeah, this is valid or not.
And this project's been around for a while, but the big news lately is that there's multiple drafts of this JSON Schema.
And the tool we're talking about covers drafts 4, 6, and 7.
Right, which is pretty nice.
Cool.
Yeah, very cool.
So, there was other ones, and they were apparently kind of stale, didn't cover the latest drafts and things.
So, nice find.
And it's way, way faster.
Now, before we get to the next one, I want to tell you about a cool feature at DigitalOcean.
So, at DigitalOcean, you can, of course, log in and say, create me what they call a droplet, a new virtual machine, or various other things, load balancers, firewalls, and so on.
And it'll spin up your machine, and off you go.
And you get some choices, like various versions of Ubuntu and other stuff.
But what you can do, if you'd like, is you can create your own local virtual machine, whatever you want, some kind of Linux, as long as you can install a few dependencies that it needs to interact with the DigitalOcean infrastructure, and upload that.
And from then on, you can just click a button and say, create me my super special private server, as many as you want, with your API or whatever.
Very cool.
Definitely.
Yeah, pretty cool.
So, if you want more control over how your virtual machines get created and what they even look like, check them out at pythonbytes.fm/digitalocean.
New users get $100 credit.
And they've got a bunch of cool stuff that you can do with all their infrastructure.
Speaking of infrastructure, a lot of people use IPython these days in the whole data science space, right?
Yeah, very big.
And people might be tired of me going on and on about async.
I know some people are not a fan, but it's just so powerful.
And when it's used at the right time, very, very nice.
But until recently, IPython was a thing that you put Python code into.
And async was a thing that you did in files, you know, applications that executed Python code.
But they didn't really go together.
Yeah.
I'm still trying to get my head around them going together.
But yeah.
So here's the thing.
If I have an async library that I want to use, basically, the only way to use it in IPython previously, I believe, was to spin up all the infrastructure to sort of host the async loop yourself, which is like five or six lines to just call the function.
So now in IPython, you can just say, oh, wait, give it a function, and it just runs it automatically.
Oh, okay.
That's cool.
So that's, yeah.
So IPython 7 is out.
And one of the big features that it has is the interactive shell now supports async and await, which is really cool.
Yeah, that's very neat.
Yeah.
So this one came to us from Nick Spirit.
Thank you, Nick, for sending it in.
And this is written by Matthias Boussignier.
And he is the guy who originally cloned the term legacy Python for the world, as far as I can tell.
Yeah, I think you're right.
Yeah, yeah.
He wrote a cool article called Planning an Early Death for Python 2 or something, you know, friendly like that.
And talked about referring to it as legacy Python, which I think is great.
So he also wrote this, and he works on IPython and whatnot quite a bit.
Talks about how when IPython drops support for Python 2, how are they able to sort of make these features possible, right?
If you want to support these types of things, it was much harder to do so if, you know, you want to use a Python 3.5 feature, but you also want to support Python 2.
So it's cool how they talk a lot about that.
Yeah, and I also think the open source community is sort of changing.
We had this idea that kind of from, I think, other commercial applications that you should support as many platforms as possible or, like, your library should support as many versions of Python as possible.
Right.
If it could support 2.1, that'd be awesome.
But at the same time, there's the reality that if you only support the more recent versions, you can clean up your code and have it be an easier code base for other developers to work in and increase your open source contributions.
And I think that's a very real thing.
And I think that's one of the, like you said, it's one of the things that they probably addressed with IPython.
Yeah, definitely.
It sounds like it here when they talked about doing the same thing for Django was we were able to delete a bunch of code.
And the easiest way to maintain code is to not have it.
Yeah.
So, yeah, it's a great point.
And here's another example.
A lot of people are using IPython to teach Python.
And whether or not that there's a debate as to whether or not that's a good thing.
But at least now they'll be able to teach async.
Yeah, that's a good point.
Yeah, there's a lot of presentations and stuff done there.
Now it's nice and easy to call it.
Super cool.
Yeah.
All right.
What's the next one you got for us?
I have a library called Molten.
And Molten is...
Is it for studying volcanoes or what is this?
It's an API framework.
So, the link we're going to include has a little video demo on it.
But it's like a REST API framework used similar to like API Star.
And in fact, the kind of the motivation, there's a motivation page that talks about how API Star is kind of awesome.
But there's some of the implementation like a hook model for middleware that this author didn't quite like.
So, they took inspiration from API Star and Rocket, which is a REST framework, and tried to make this one.
And it's a Python 3 only because they're leveraging type hints and type annotation.
Yeah.
In a really nice way.
It's really clean looking.
There's a...
You can implement an API fairly quickly.
But there's also built in...
Speaking of schema validation, there is schema validation built into this system so that you know the code that you're writing to deal with requests or the coming in.
They're already going to be valid before it even hits you.
So, you won't be hit with invalid data, which is pretty cool.
Yeah.
There's a lot of cool validation.
So, for example, the hello world type method for a web view method is just like def hello and then name colon stir age colon int.
And it actually, you know, grabs the value, say, out of the URL or somewhere, puts it in there, converts it to an integer, and passes it.
And so, you don't have to figure out, you know, how do I go get that from the route match data or other weird data sources like that.
So, that's really cool.
And then they take it farther.
You say, okay, well, you could have like a string and an integer in the function.
Or if you've got something more interesting, you could define an actual class that has a little decorator.
It says a schema.
Like it has an ID that's an optional int.
That it has a description that has a status that can be, you know, certain values and has default values, all sorts of cool stuff.
And then you can just say, this web method takes this, like, we have a to-do example as a class, right?
It takes a to-do item and it automatically pulls it out, does the validation and check-in.
Yeah, I'm loving this.
This is great.
Yeah, and also, you can define the schema on the output as well to make sure that you're complying.
I think it's kind of neat.
And the other, there's a couple other neat features of it.
It's, or at least features of it, whether or not you like it.
The middleware is a functional programming-based middleware.
And a lot of the different pieces, like if you want to have a database management, they're all set up to allow them to be isolated easily.
So using dependency injection, it's a thing.
And it allows you to sort of test your different components by themselves or swap out new ones.
So it's fun.
Yeah, it looks really cool.
I'm, you know, well done on that project, you guys.
I think it looks like something if I was building an API, I might be pretty excited about using.
Yeah.
So I want to round out this episode with something a little fluffy but nice to just remind everybody why we're here and why we use the tools and the technology that we do.
So this last one is called a Python love letter.
Well, I love Python.
Yeah, I love it too.
So this was actually a thing posted to a Reddit thread by a guy who's pretty new to Python.
And he posted, it said, Dear Python, where have you been all my life?
Right?
And the thing he posted was pretty interesting, but also the comments, right?
There are many, many comments and just all the people either agreeing or disagreeing or whatever.
So the guy says, look, I'm not a developer, but I've been teeing with programming for, you know, Basic and Perl and whatnot.
And for some reason, he decided, you know, he's done with shell scripts.
So we've heard that before, right?
He's going to go write some Python.
And he said, look, I went and I learned Python.
And no, I didn't go from zero to production in a day.
But if my coworkers will leave me alone, I might be in production tomorrow.
Which is, you know, I think that's just like kind of sums up a lot of what happens in the Python.
That's neat.
Just kind of a fun story.
Yeah, it's definitely a fun story.
A couple of the comments that came up that I thought were interesting were one person said, welcome to the club.
I came up on C++.
My job highly trained me in C and assembly.
And every project I touch, can't we do 90% of this, 95% of this in Python?
And we do, right?
We don't need inline assembly most of the time.
Another person said, I have a chip on my shoulder.
I want to do things the hard way and understand them.
So I went C++ because that's real programming.
Dang it.
But later, after suffering a lot, I kind of learned that, you know, doing things smarter was way better than doing the hard way and whatnot.
So he loves, you know, sort of found his way to Python.
I guess one other person said, I felt exactly the same way.
I decided to learn it.
What a breath of fresh air.
Sadly, there are a few things in my life that make me feel like this.
Python and Bitcoin give me the same levels of enjoyment.
I've used Java, Groovy, Scala.
Objective C, C++, etc.
And nothing feels as good as Python does.
So definitely, definitely cool.
And then this person, this is what was notable to me, Brian.
Closed out his comment is, hell, my next two planned tattoos are Bitcoin and Python logos on my wrists.
Way to go.
That's some commitment.
The Python, fine, but you're probably going to regret the Bitcoin one.
Is there an abstract cryptocurrency that is going to encapsulate like whatever comes next?
I agree.
Anyway, I thought that was fun.
And it just reminds us, you know, what a great community and ecosystem.
Yeah, definitely.
I also just wanted to say, assembly code, real man program in bits.
That's right.
Zero, one, one, zero, baby.
Anyway.
All right.
So that's for our official items.
But I see you have one little extra one here that will also bring fun, excitement, and joy to any presentation.
If you're just sitting down with a coworker or even at like a meetup.
Right.
Yeah.
Oliver Best Walter got me excited about this.
And it's power mode.
And I'm linking to something called Power Mode 2, which is a plugin for PyCharm.
But there's power modes in a couple different.
And it started in Atom, I think.
And people have probably done it other places.
It just makes programming more fun.
This is funny.
You introduced this to me.
So let me just sort of give people a little description.
So imagine as you start typing, it's kind of like a bit like a comic book.
The faster you type, the more excited your editor gets.
If you copy and like duplicate a method, like a big bam, pow, thing will pop out.
Sparks shoot off of your cursor.
The faster you type, the more intense it gets.
Yeah.
It's super, super productive and awesome.
I've left it, I've turned off the shaking screen, which is a little unsettling to me.
And the flames.
But the rest of it, the sparks flying and everything like that.
I've been using it for like a week or a week and a half.
You leave it on all the time?
Yeah.
That's awesome.
Because I really like it when I copy and paste and it goes bam.
I know.
Bam, pow.
That's nice.
That's cool.
Yeah.
Power Mode, if you're using PyCharm, is definitely fun to check out.
Got the link in the show notes.
Cool.
Okay.
All right.
Well, that's a fun one to close it out for sure.
All right.
Thanks, Brian.
And chat with you.
Yeah.
Thank you.
Yeah.
Chat with you next time.
Bye, everyone.
Okay.
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 Okken, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.