Python Bytes - #287 Surprising ways to use Jupyter Notebooks
Episode Date: June 7, 2022Topics covered in this episode: auto-py-to-exe 8 surprising ways how to use Jupyter Notebook piptrends Is it a class or a function? It's a callable! Extras Joke See the full show notes for this ...episode on the website at pythonbytes.fm/287
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 287, recorded June 7th, and I am Brian Ocken.
I'm Michael Kennedy.
Good to talk to you, Michael.
Yeah, good to see you again, Brian.
Yeah.
Again, we've got our wardrobe matching our background here, which is fantastic.
Yeah, we like, you know, texted each other in the morning to make sure.
Feeling purple, I'm going to get a new shirt. No, it's great. Good to see you as always.
Lots of fun Python things to talk about here.
Yeah. Yeah. Well, let's jump into the first one.
The first thing that I want to talk about here is distributing Python applications. Now,
this is a little bit in the Python GUIs side of thing, something you just can't get enough of in terms of like,
hey, could we have more ways to do this that are like awesome?
How about if we had ways that were automatic?
Yeah.
So I want to talk about this thing by Brent Bolle-Bergret
called autopy2exe.
And it basically does what it says right in the name there,
converts a.py file to a.exe
using a simple graphical interface.
Now, this GitHub description is a bit of a Windows bias
because it'll also create it to Mac apps as well,
to.app files.
So it's not just a Windows thing.
Cool.
It's pretty popular.
It has 2000 stars, 400 forks.
And what it is, is a UI on top of things like PyTab or PyInstaller, specifically PyInstaller.
So what you do is you fire this thing up and out pops this user interface that if you're
watching the YouTube stream, you can see there's a user interface here and it just says, pick
the starting Python file for your application.
And you can say, what do you want the output to be?
One file or one directory.
I think we all want it to be one file, probably generally, but maybe a directory.
I don't know what else you're going to, maybe you want to do some other things there.
But what I did is I tried this against my URLify little appy thing, which let me pull that up. This is
something I built a while ago with rumps. It's fantastic, ridiculously uncomplicated menu bar
apps or something like that for Mac. And all it is, is a little thing that goes up in your Mac bar
and it has like, you know, slugify text or trim it or
lower cases. Just I'm constantly taking names of like file names and turning them into something
I could put as a URL or like a title of a video or something and turning it into something that
would be a good URL. So that's what this little app is for. But here's the thing is it's a Python
app that runs in the menu bar of my Mac with no
terminal view.
And I wanted to be able to distribute it to people.
And so the way you get it is you just download a zip file, which is just the zip up dot app
executable, right?
So I had done a bunch of stuff with the setup and all those kinds of things with PyInstaller
to build this.
So my test case was, well, let me take this auto-py2exe thing
and just point it at that and see what happens.
And what happened was good things.
It was really interesting.
There's an app.py,
but there's dependent Python files that it uses.
I mean, I'm not a beast.
I don't write my entire application in one file.
Like there's other things broken apart in there and
that gets bundled up and it somehow discovered that, pulled those all in. So I just picked the
top level file and it found the dependencies, you know, the requirements.txt type dependencies and
so on. And it created a.app file that as far as I could tell ran just fine.
That's cool.
Isn't that cool?
Yeah, I like it.
You can decide if it's a window-based application.
So hide the console, which is what I said,
because I want it to run in the menu bar.
But if it was a console-based app,
but you just wanted to distribute it
as a single thing with no Python,
well, no Python requirements,
you could create a console-based app.
You set the icon, you can add in additional files.
So if there's like you know json configuration
files or yaml files or images or something like that you need to take along you can configure
that there and then there's an advanced section that expands out to be like pages of stuff that
i don't remember same thing for settings and then you just click the big convert to pi to exe button
and you get ironically not an exe but a dot app file and there you go that's
cool isn't that cool so for people who are playing around with this i think they you know they even
have and they must be listening to us here they even have a little animated gif of how this all
works right on uh the github that's pretty if you want to see how it works i guess there's not a
whole lot but you browse for the icon you go go in there, you check off some things, and then you just hit build.
And it takes a little while, but, you know, that's Pi 2.0 XE.
That's how it goes.
And it just sits there and it cranks away for a while, bundles it all up, and, yeah, got a little executable.
So if this is something you want to play with, but you're like, ah, it's kind of a real pain to go and figure out, you know, all the setup Py commands in order to get it to do
the PyInstaller commands and whatnot,
then, you know, you can definitely
give this a shot.
I think it's pretty neat.
I think with mine, I didn't use Py to installer.
I think I used Py to app.
Yeah, that's what I used.
So pretty neat.
Yeah, check that out.
I think people will find it helpful
for ways to distribute Python apps.
Yeah, and I like that.
It looks pretty professional looking.
And then also,
especially,
I mean,
especially with internal,
like internal company stuff,
there's that happens a lot where you want to share something around.
Yeah.
Like just download this and run it.
Please don't ask me how to set up a path so that your Python,
that's not Python three,
three or whatever,
right.
Is the one that runs it. Nobody needs to know that it's Python underneath.3. Yeah. Or whatever, right? It's the one that runs it.
Nobody needs to know that it's Python underneath.
Yeah, exactly.
So, oh, cool.
I really like it.
Oh, one other thing, by the way,
it's a GUI application.
It's self-written in Python.
So you may wonder, well, what is it doing, right?
Maybe it's bundled itself.
Obviously, that'd be very meta, right?
Like if autopy2xc could deliver an autopy2xc
itself, that's obviously lovely. It reminded me that I have Chrome installed when I ran it.
So what it does is it runs something in the background, then it fires up Chrome,
which becomes the UI in this kind of Windows-looking Chrome window. this it's not quite an electron app but it's electron in a style
so anyway it's it's an interesting little ui app itself i'm not sure what it's doing but
okay it works nice all right well i'd like to talk about jupiter so jupiter notebooks oh yeah
yeah so this is how do you use it how do use it. So like, I was just fascinated by the clickbaitiness of this, but it's okay. Eight surprising ways to eight, eight surprising ways how to use Jupyter notebooks. And I gotta say, I didn't know you could do some of this stuff with Jupyter. So it's pretty cool. So the first one package development, why would you I don't know why but you know some people that are more comfortable
in jupiter than they are an ide or something maybe it's good so there's a package called mb dev
that you can use uh to um uh and it's by a company called fast ai that um that you can use to help
help with package development uh including you know, trying to get your CI working and your tests all in one place
and demos and documentation and stuff.
So that's kind of neat.
I like that idea.
I definitely should try to play with that to see how that works.
Apparently there's a video.
Somebody gave a talk around it, I guess.
Lovely.
Yeah.
Build a web app.
So building a web app with uh
with with jupiter i think that's that's actually a pretty cool idea there's uh several suggestions
using voila i think we covered that um i think yeah we've covered that before but the other one
i don't think we have pi widgets i i'm not sure what that one is um so i haven't looked at the
widgets thing but you know more widgets within your window.
Sure.
Why not?
Why are there no, it's a widgets thing.
You think there'd be images on the readme, but, uh, anyway, um, and then a framework
called Mercury and this shows up several times in this.
So, um, Mercury is, uh, is, does a lot of stuff, um, around Jupyter notebooks and doing
extra things.
So this shows up several times in this list.
So for one, for creating a web app,
which is kind of neat,
especially if you're sharing data
and have interactive stuff,
you might have doing stuff with a web application
be cool.
Slide deck, gotta love it.
I definitely didn't want to try this out because
using nb convert um or mercury apparently mercury does that too uh uses reveal js i think a lot of
people have tried reveal js before for slides but having building it within notebooks building your
slide decks within notebooks and then uh and then having that just run that,
that's cool. Uh, building a book. This is something else that sounds pretty interesting.
I'd like to try, uh, doing some code, uh, a notebook, a book like thing. Now I don't have,
I'm curious about this. So the book, you build a website that looks like a book,
but that's not a book. Um, so it says it can be exported to a pdf file uh but i don't
see anywhere you're exporting to an epub or mobi so you know i call i call bs on whether that this
is a book um this is a website that holds book contents as far as i can tell still cool though
uh running a blog this is something i had no idea nicola could do so nicola nicola
i don't know how to pronounce that um i've ran across it before i'm not sure what we
if we've covered it but it's a static site generator um and it apparently can take uh
notebooks files and just run notebooks as a blog so that's's pretty cool. Notebooks as a blog.
Oh, that's interesting.
Well, yeah, especially if you're going to write about
like some Python technique or something,
you just do a little demo of it
and then publish that as a text thing.
Or I don't know if it outputs.
I didn't read it close enough.
Outputs the exports every notebook to an HTML file
and then publish all the files on a static website.
That's pretty neat.
Doing reports and dashboards, that's kind of like Jupyter would rock at that. And I think we've covered
stuff like this before, but, uh, one of the things in the dashboard section that I thought was neat
was, uh, this mercury tool has a schedule option. So once you set up the report, you can schedule
it to execute, uh, you know, like once a day or every hour or something like that.
And that's pretty neat to not have it do constantly, but update, you know, update your dashboard timeline.
I do like that.
That's really cool.
So you could have some kind of dashboard instead of creating it in the full web app.
You just publish this, but obviously you want it to refresh, right?
Yeah.
Yep.
So anyway, that, oh, last one, REST API. you just published this but obviously you want it to refresh right so yeah yep so uh anyway that
oh last one uh rest api this is this this is a interesting i wouldn't have thought to build a
rest api with jupiter um so i guess you can do all this stuff whether or not you should i guess
it's up to you but um anyway yeah for sure anth Anthony on the audience says, Nicola works well as a static blog generator,
preferred over Pelican.
Well, that's saying something.
Nice.
That is.
Yeah.
Brian, wouldn't it be good to know
which ones are more popular,
which ones maybe you should depend upon?
Yeah.
All right.
Well, Al.
I took it over.
That's all right.
So this one is from...
Let me get it right here.
This is from Tankala Ashok.
And they built this thing called Pip Trends.
It's modeled a little bit after NPM Trends.
And it just lets you compare the popularity of packages
based on their GitHub statistics.
So GitHub statistics, you know, that's one metric of popularity, but let's give it a
bit of a run.
So what about if we type Flask?
It says, it immediately pulls up a nice little autocomplete that says Flask, a simple web
framework for building complex web applications.
But then all the other ones like Flask to Postman and so on.
It's kind of interesting.
I didn't really, didn't really know about Flask to Postman.
Maybe we'll talk about that next time.
But let's pick Flask.
And then it immediately says, well, what else might you consider along with this?
Like, well, how about FastAPI and Django?
And what do we have?
It also suggested Bottle for a little while.
So we'll throw Bottle in there maybe.
And let's do a search.
And it comes up with a graph that honestly surprised me a fair amount. There's different
levels of popularity, but that's not the first thing that surprised me. The first thing that
surprised me is the regular cycles that all of these packages seem to go through. Does that
seem strange to you? Well, I've noticed it before and I don't really know what's going on. Is it the weekends?
Yes, it's very good.
So four or five was the weekend,
six, four, six, five.
And that's where the dip is.
So people download stuff less on the weekends
because there's less,
create me a new environment,
create me a new project,
check it out, set it up, right?
All that kind of stuff, which is healthy,
but there's still a decent number of downloads
going on the weekend there.
Yeah, I kind of wish that I'd like to see
like a sevenday moving window,
moving average for PyPI.
Yeah, like a different window averaging or projecting function.
Anyway, what we get here is we see that Flask, sorry,
FastAPI and Django are super similar,
like almost tied according to GitHub statistics.
And these are downloads. I don't
think you get downloads from GitHub. I think this is probably from PyPI or BigQuery or something.
I'm not sure where those numbers are coming from because I don't know where those are on these
like time series download numbers are on GitHub. So they're probably coming from somewhere else.
But yeah, you can throw different projects in here and say, oh, this one's relatively popular compared to that or whatever. What do you think? I think it's kind of neat, especially
with comparing. I mean, I've used, there's other ways to get the stats, but having, being able to
grab a few related ones, having suggestions is kind of neat too. Yeah. Yeah. So it looks,
it also has some more information about the package. Like if you go to Flask, it's 12 years old. It has 45 versions.
Its last release was one month ago.
Its dev status is stable.
It requires Python 3.7.
It gives a license and who it's intended for.
And you can see similarly for FastAPI, for Django, and Bottle, and so on.
Oh, cool.
Also down here in the GitHub stats, you can you can see like flask there's 59 000 stars
for django there's 64 000 stars number of open prs wow fast api has a lot of open prs and issues
that's crazy when it was last updated and so on so yeah and it also gives you more comparisons
down here like well that was fun what about flask versus django versus fast api which is what we did but
or numpy versus pandas for example you can see them and so on that's pretty neat i like it yeah
yeah so piptrends.com you can check it out so um i want to talk about we're going to talk about
class being classy um actually uh being callable so treyrey Hunter put this blog post out called,
is it a class or a function?
It's a callable.
And this is actually something that I guess I realized
I just sort of got used to with Python.
It's a lot more, if you call something,
like as if you would call a function,
it might not be a function.
It might be a class.
It might be an object that's call function. It might be a class. It might be an object that's callable.
It might be a class object.
All sorts of stuff you could do.
Just to be clear, we were talking about,
or he talks about classes are callables.
So in like JavaScript or C++, you'd have to say new something.
So you'd have to say like a new data object or something.
But in Python, you just call datetime with some parameters
and you get back a datetime object.
That's neat.
But so it's just, I guess,
this is a good article to go through
just to realize that you don't really have to care.
There's a whole bunch of stuff that act like functions,
and it's okay if they're not functions.
You just have to know if it's callable.
And he talks a little bit about using a knit,
a dunder knit to make something callable.
That works.
Properties are like decorators are a thing
that are a callable item.
There's some,
there's,
it's just a good discussion, um,
about,
about all of this.
I thought this was a fascinating article and I,
I'm not sure.
Um,
I ever really thought about partials before,
like a partial function is a,
is a,
like a function that,
uh,
creates a,
almost creates an object and then you call it with some more stuff and then
it creates a, the rest of it or creates an anyway, maybe you call it with some more stuff and then it creates a
the rest of it or creates an anyway maybe i got that interesting yeah from func tools i'd never
used partial before okay yeah um and then uh there's a there's a call decorator or a call
dunder method that you can use that is helps out with making partials. Um, uh, and, and,
uh,
talks about iterators and decorators and all sorts of stuff like that,
that actually act like callables,
but they're not,
they're like objects.
The thing that I don't know where this is,
but the thing,
there's a,
uh,
a statement in here that I thought was amazing.
So there's a,
there's a page on,
uh,
the pipe,
the documentation of the built-in functions
it's within python and uh and trey points out that of the 69 there's 69 listed built-in functions
um within python only 42 are actually implemented as functions 26 of them are wow 26 are classes and uh and one is a instance of a callable class so like and some of
them have in python 2 there were more and some of the some of them got converted like um uh map and
filter and range and zip used to be functions and now they're objects um or classes or something
uh the len function they use that all the time right it's not a function
right it's a callable class um okay zip uh the uh like reversed enumerate range filter use those
all the time they're not functions uh but they're callable so anyway i just thought that was an
interesting take on python is different than other languages it's's different. Yeah, a lot of languages,
you would never have that ambiguity, right?
But it's the kind of ambiguity
that you don't need to know or be aware of.
So maybe ignore this article.
No, no, no.
I mean, it's interesting to know.
I'm just saying like,
it's not necessarily a problem
that it's not super clear
whether it's a class or function
because you call it
and it does the thing you want it to do.
So you're good to go. Yeah sam um sam morley pointed out here um
partial is useful i think i think it can be pickled unlike typical closures that can't
might be wrong but it just made me think about we in other languages they really do talk about
closures a lot and and things like that and we just don't have to care. It just works.
I don't know.
It just works.
Yep.
Yep.
Very nice.
Very nice.
Well, we're at the... Well, Brian, we flew through those.
We did fly through them.
And we forgot to plug our stuff.
We did.
So instead of a sponsor today, we're sponsored by us.
So I want to make sure that everybody that is thinking about trying to learn something new in Python, first check out TalkPython training because Michael has a whole
bunch of awesome courses and I'm sure you can learn something for just a few bucks. So good
prices. And a new book, version two, edition two. Yeah. I've had a lot of good feedback.
I love, one of the things I love is getting pictures.
I don't know why, but having somebody take a picture either of themselves holding the Python testing with PyTest, second edition.
Heck, you can do the first edition too if that's what you got.
But either holding it somewhere unique, like out in a park or near a monument or something.
That would be so cool.
I love it when people send me pictures.
Yeah, that's awesome.
Got any extras for us?
I have some extras.
Yes, you know that I do.
All right, so this first one here,
let's check this out.
So this is interesting.
This comes by way of Dan Bader
and it's the Orion browser.
Just when you thought there was no more room
for new browsers, here's a new browser.
This one is different.
So you can see I'm running Vivaldi these days.
I'm loving that.
Other people are using Brave, right?
And so all of those browsers take the Chromium engine, strip off the Google stuff, and then
put their own shell, many times more privacy protecting and so on around them, right?
And we've got Firefox, which is awesome.
It's got its own engine.
It doesn't do that.
But almost every other browser is, let's take Chrome and Chromium and wrap it up in our
own flavor of our thing with our own philosophy on how the web should be.
So this Orion browser is that, but for Safari.
Okay.
Interesting.
So if you're into Safari, you know, it has things like on your Mac, it has better battery
life and so on.
But think of it as like, I think Brave is probably the closest analogy.
It's like Brave for Safari without the crypto, but it's, you know, got built in ad blocking.
It's got built in tracker blocking and all that. One of the big drawbacks of Safari is
you don't get access to the Firefox or the Chrome extensions, right? You just get the Safari ones,
but this one has compatibility both for Firefox and Chrome extensions in there. So you can,
isn't that cool? So you can run this privacy-protecting anti-tracker Safari with Chrome extensions.
So it's just out in beta, I believe.
Yeah, it's out in beta right now.
So I'm not sure where it is or where it's going to go.
But it's a pretty interesting take, isn't it?
Yeah.
It's certified snappy.
Certified snappy.
I like it.
And I really like its privacy aspect so i think
the privacy space and you brought this up the privacy space is is there's convenience and
there's speed but i think that's the place where people can we can open up the browser wars again
um yes because in a good way uh to try to um yeah limit limit
some of the privacy concerns or minimize them so yeah nobody at mozilla asked me but i'll give it
you know firefox is having trouble sort of keeping its market share i think if it could
triple down as the browser that you cannot be tracked with, the browser that will absolutely
preserve your privacy and then add services around that. I think that would be great.
The big challenge is, well, I guess, you know, they're 99, 90% funded by Google,
an ad company who doesn't want that. So there's this, this interesting tension, but I think,
you know, that's a path that I firefox should be taking as well but i guess i forgot about that that note that google was so such a big stake in firefox right i think that
limits their their playbook i think they can't do things like we're going to make it so we're
invisible if you use firefox basically because their biggest supporter you know would not totally
love that would they so anyway this is a zero telemetry
telemetry browser and whatnot and you can go and download it apparently it works on um apple
silicon and intel but obviously being a safari rapper i believe it only works on i i think mac
i think and ios things i things ios ipad andOS. But if you're on those, it's a pretty interesting take.
And just from the browser wars in general,
I think it's pretty interesting to track.
Yeah, definitely.
It's cool.
All right.
One more quick extra and then off to you.
So last year we all did the PSF plus JetBrains developer survey,
which is supported by and analyzed by JetBrains,
but is really a PSF
survey. And we had 23,000 Python developers and enthusiasts participate. Well, the results are
out, so people can go check those out. Now I've got a whole lot more analysis that I'd like to do
before I talk about it, but they're already out. So people can start looking around there and I'll
give you more details next week.
Yeah, cool.
Yeah, we should definitely cover it next week.
That'd be fun.
Absolutely.
All right, how about you?
I've got a small thing.
I'm not sure it really needed an entire section,
but Ned Batchelder did What's in Which Python?
So it's a page that has uh basically it's everything from from uh
what did he have from 2.1 to 3.11 all just a hand not like everything that's in every version
but some of the big hitters that you might you know you might know uh so like 310 has union types
and structural pattern matching and uh what what do you get with 311 well we know
it's faster but do we get like how much and it's 10 to 60 faster than 310 that's amazing um and
then exactly that's really amazing that after 30 years they're like oh you know this year we're
going to make it 50 faster like that's that incredible. I'm glad that's happening. Yeah. And then a new module Tomalib is coming.
So like,
which is interesting that we've got pipe project at Tomal and it's,
it wasn't part of the standard library yet.
So,
but a whole bunch of things,
like if you,
if you can't remember,
like if for some reason you forgot F strings came in and what was it?
Three,
six,
apparently I forgot. So they came in and what was it uh three six apparently i forgot so
they came in in three six because it's on the list unless unless ned got it wrong which probably
didn't um so no i think three six i think that's the biggest mover for three six there yeah yep
and data classes in three seven yeah so lots of cool stuff fantastic henry schreiner out the
audience says it's the the top features from each of the versions since 3.0.
So not everything, not extensive, but like sort of the big hitters.
Yeah.
I wasn't going to say top because, you know, there's a lot of people that worked on a whole bunch of other stuff that are on the list.
And I appreciate them as well.
Yeah, absolutely.
And some of it's just setting the groundwork for the next amazing thing.
Yeah.
Well, let's wrap up the show with something funny.
All right.
Ready for a joke?
All right.
This is a joke by Jen Gentleman, but called to our attention by Luke Morley.
And it says, Jen says, a programmer had a problem.
He thought, I know, I'll solve it with Async.
Has problems now, period, too he.
Because of race conditions, of course.
Yeah, I like it.
I like it too.
Quick and simple, but yeah.
There's a lot of variations on that joke and they're all good.
Yeah.
Most of them are good, I guess.
Anyway, well, thanks again, Michael, for joining me today.
And it's a great episode.
Yeah, as always.