Python Bytes - #46 Spicy lecture notes and unicorn console spinners
Episode Date: October 5, 2017Topics covered in this episode: Scipy lecture notes Building a desktop notification tool for Linux using python Alice in Python projectland How to teach technical concepts with cartoons Halo: Beaut...iful terminal spinners in Python Extras Joke See the full show notes for this episode on the website at pythonbytes.fm/46
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 46, recorded October 4th, 2017. I'm Michael Kennedy.
And I'm Brian Ocken.
And we've got a bunch of cool stuff lined up for you, as always.
But before we get to it, we have some kind of big news, Brian.
We do.
Yes, we have a new sponsor, a brand new sponsor for Python Bytes,
who's come on to actually support a bunch of the show, DigitalOcean.
Oh, that's awesome.
Yeah, so they want to let you guys know about this thing called Spaces,
which is kind of like S3, but 10 times better.
And the audio you're listening to actually came to you over it.
So we'll talk more about that later.
I want to hear about Spicy Code.
Spicy, oh.
I want to hear about SciPy Lectures.
I misread that, Spicy, SciPy.
All the same.
Yeah, it's all the same. You threw me off.
I'm like, what story are you looking at, man? Anyway, sci-fi lecture notes. I hadn't come
across this before, but they did an update just recently. It looks like they updated about once
a year to make sure it's all current. You know, for somebody that's doing just-in-time learning
for scientific Python
usage, this is pretty darn cool. Their tagline is one document to learn numerics, science, and data
with Python, and it runs the gamut. It starts off with a Python language tutorial if you want to
take it. You can learn about NumPy, Matplotlib, SciPy. It's got topics like debugging and optimizing, image manipulation, and things like how
to deal with statistics and machine learning even. Yeah, this is really cool. I think a lot of people
are getting into data science and getting into Python because of it. But also, I just think this
is a great way to learn a lot of these techniques, right? These little short focused iPython notebook
style of examples. Yeah. And for somebody that
really needs to just jump in and find the way they have it set up, it's almost like a table
of contents for a book or reference book. So you can just jump in and try to learn whatever you
need today, just right away. You know, what's cool about the JIT stuff is it has prerequisites.
It says like, for example, on the profiling part,
it says a prerequisite is you must understand line profiler.
Oh, okay.
Yeah. It's pretty cool.
Thought it was a great source for people that really aren't
patient enough to go through a course or really don't know what they need to learn yet.
What do you think? That's like 95% of people?
Yeah. Especially since like we've talked about before,
that Python is often a language that people pick up after their primary language.
Yeah, well, and also I think we're increasingly asked and expected to build more and more complicated apps,
bringing together more and more different disciplines.
So would it be unreasonable to say, I would like you to write a web application that talks to the database,
but also uses machine learning and the GPU?
Like that I can see being a totally normal request now, whereas those used to be their
own specialties, right?
So this ability to jump in and pick up a little bit on demand is only going to be more required,
I think.
Yeah.
And they also split up some of the Python stuff into some of the beginner stuff that
you just kind of have to know to start with.
And then they have some more advanced things a little bit later. So yeah. Nice. So the first thing I want to talk about this
week is desktop notifications. And this caught my eye because I feel like I've said this a couple
times, like one of the weaker points of Python is the whole desktop GUI type of thing, right? I know
you can do it, but it's just not as easy as it should be.
And so here's a real simple and easy way to build a notification, like a desktop toast type of notification for Linux using Python. Well, that's cool. Yeah. So I don't know what,
what you mean by toast. Well, so you're sitting there and there's like a little thing that pops
out and say on Mac, it's in the top, right? And windows it's in the bottom, right by the clock,
it would pop up and say, your friend just liked your thing on Twitter, or somebody invited you
to connect on LinkedIn, or your server just went down, your boss is paging you, they're upset.
I finally get the toast reference.
Because it pops up. At least in Windows, it pops up. I guess if you tilt your toaster on the right,
then in Mac OS, it's also toast. I don't
know. Anyway, the here's a an example, a little app that says let's write a thing that will do
web scraping, I guess a Bitcoin value location, and it'll go to the website and pull that off
and give you a periodic notification of the value of Bitcoin. Well, that's not super valuable. It
does show you a really interesting use case to this package called Notify2,
which if you have something actually practical
and interesting you want to notify people about,
that's a pretty cool little use case.
Actually, I think I might actually use this.
This would be great.
Cool. What would you do with it?
For instance, we've got a bunch of remote machines.
For me, I've got a bunch of VMs
that are dealing with builds and whatever
and some way to keep track of them, make sure everything's alive.
Yeah, that's cool.
Like a build pass, build failed, machine no longer responsive type of notifications.
Yeah, that's awesome.
That'd be really fun.
And it looks like a couple lines of code and you got it going.
So that's really cool.
Would you consider performance, like if your app becomes much slower after a check-in, like a performance
degradation, like a failed build? Well, yeah, definitely. And how would you test for that?
Well, funny you should ask. The next topic is a tool called PyTest Benchmark. And this actually
came up because, not because of, because I'm actually looking for this. I need to have
chunks of functionality that we need to know whether or not we need to time them,
make sure they're not getting slower
with successive releases of the software.
And what's interesting is the much slower or much faster
or just very random timing,
people might actually notice that.
If you're dogfooding your own application
and you're using it, you might notice this. It's the subtle things like a measurement is now, it used to be two seconds
and now, and it was for like lots of releases and now it's two and a half seconds. Normal users
might not, might not notice it right then, but it sure be good to check this. So this is a PyTest
benchmark and it's a very easy little thing you can add into your code in your PyTest testing to say, hey, this chunk of code, it needs to be at least this fast.
And at first, you don't know how fast it should be.
So there's a lot of tools within it to do some graphing and table-driven showing you what the numbers are right now.
And then also an ability to have some golden numbers
and save off benchmark data into a JSON file.
And then on future runs, compare against that.
So I'm going to use it.
Yeah, that looks super interesting, actually.
And it has nice graphs over time and things like that.
I mean, sometimes timing doesn't matter,
but other than like how users feel about it.
But, you know, in certain types of real-time systems or trading systems, there are actual
numbers you cannot fall below.
If you're processing inbound data in real-time and it's appearing every, you know, 100 milliseconds,
you have to be lower than 100 milliseconds in the processing time, right?
Or you won't be able to keep up.
Often Python's used for other things too, Like I've heard that some people use it
to control test instruments.
Yes, that's possible.
So for instance, checking to make sure
even application turn on and measurement times
don't slow down because these instruments
are used in production lines
and it'll slow down your customer's production line
if you slow down.
Yeah, absolutely.
All sorts of factory automation and all kinds of things.
Cool.
All right, so that's really nice.
I definitely, if I had a use case for that, I would definitely use it.
I just don't have anything that I can say,
it must be this fast or it's a problem.
But it still would be cool to actually see the speed over time.
Now, before we get on to the next one,
let me say thanks to DigitalOcean and just let you guys know about Spaces.
So you probably heard of Amazon S3, right?
I think that was their first thing.
But like I said, DigitalOcean just released Spaces, and I definitely think it's better.
Soon as I heard about it, before they even said, hey, I want to sponsor the show and have you tell the world about it, I'm like, I'm switching to this thing.
So for one, it's like nine times cheaper than AWS. It's super predictable pricing. There's all kinds of benefits. You can
use the same tools as you use to manage your S3 thing. So same APIs and everything. So for example,
I use this cool program called transmit for my Mac to manage all my files in S3, just pointed at
digital ocean spaces, and it just keeps working.
It's awesome.
So it's like $5 a month,
250 gigs for free in storage,
a terabyte for free in bandwidth.
That is quite expensive
if you pay nine cents per gigabyte at AWS,
but it's completely free here,
and it's a really nice service,
just as fast,
but much more predictable predictable and even inbound
data is 100 free so check them out it's really a super simple api it's one you're familiar with
the tools of work and you can actually get whether you're a new or existing customer you get two
months free if you just go to do.co slash python do co slashO-C-O slash Python. So check it out. That's great.
Cool.
Yeah, it's a super cool project.
I'm so happy they came out with it,
and I'm happy to be using it for this podcast and other stuff.
So we've talked, you've talked more than I have,
but we've both talked a fair amount about projects,
how they do packaging, Python packaging,
how you should structure those, and so on.
So I want to highlight an article that is a fun article,
but it's super in-depth and a deep look inside of how Python works
and how packages are built and why they're built that way.
It's an article by Vicky Boykus, and it's called Alice in Python Project Land.
So it's got some cool little graphics and stuff,
but the idea is she she's um a data scientist
learning uh data science and those things so doing a lot of java and doing a lot of python
is like look python is so much better except for it's really hard to package up things like how do
i take some code that i've written and make it so that i could give it to you and you could use it
for example so instead of just going well these are the four steps you do to create a Python package. She said, let's look at the
internals of how Python actually works and how it runs, how it understands and links things together.
And so you not just know how to put things together, but you understand why. So very,
very interesting article, pretty in depth. So if packaging has always been kind of this weird thing
that you just follow the steps and check this out. It's a good article.
Like you said, it's in-depth, which makes it kind of a long article,
but the writing is really good. So it moves along pretty fast.
Yeah, it sure does. It sure does. And it answers a lot of questions like,
should you use setup tools? Should you use pip? And what does dunder and knit.py do?
Should I mess with Python path? Should I not? And another thing that I saw that she referenced in there was pretty cool.
It's called pip rex.
Have you seen this?
No.
Yeah.
So I think pip rex,
you pointed at your code and it looks at all your imports and it then knows
what to create for your requirements.txt.
Cool.
So instead of remembering like,
oh yeah,
there was that thing that I use colorama or whatever,
and I forgot to put the requirements file.
So it's not going to work.
Like this will just discover it.
It's really cool.
So, yep, if you want to get an understanding
of how Python packaging and assembly of modules
at runtime works, definitely check out this article.
It's super approachable, but well done.
Next article, how to teach technical concepts
with cartoons.
Love technology.
So I personally, since I came from computer science, from the art,
fine arts, actually, I started out in fine arts. And I actually gave up because I was frustrated
with my ability to draw. But drawing things to help people understand concepts, it's very,
it helps. It's easier to understand things. And nobody expects you to draw really great pictures. This article
starts off, I love this, it starts off with just saying that she draws not that great. It has
really three horrible pictures of a dog, a cat, and an elephant. I don't think I can do better,
but they're not great drawings. But just then going through and talking about how people should
use drawings more when trying to teach things and some tips on making them more personable.
I think it's a really cool idea.
You certainly can personalize
and humanize technical concepts if you use pictures.
Like you said, they don't have to be super fancy.
So she has a dog, a cat, an elephant
and those sorts of things.
But not far down, she says,
oh, let's do something about a mutex and actually represents how mutexes are used to like for shared memory or something like that.
Right. And it's completely approachable.
But somehow it just makes it much more.
If you looked at the formal definition of a mutex, like, oh, my gosh, what is that thing?
But here it's like, oh, OK, well, that's totally simple.
I think you can really convey a lot
and sort of disarm people with some nice drawings.
One of the things I like about this article as well
is it itself is a mix of hand lettering,
just her normal printing,
and some simple drawings with text.
That's what the tutorial is.
And it breaks it up a lot.
And I think a lot of technical people,
when they're trying to teach something, they'll think a drawing is a good idea, but then they'll get out a tool to make all the lines straight
and draw it with vector graphics.
And sometimes I think just a pen and paper might help convey the information better.
Yeah, yeah, absolutely.
I think this is really cool and hopefully inspire some people to do a little more, a
little more freehand stuff.
It doesn't always have to be perfect.
So keeping it graphical for our last item,
I want to share the Halo with you.
So Halo is a project called Beautiful Terminal Spinners in Python,
which is what it sounds like.
It's a really simple library that will give you sort of
I'm loading or I'm working or I'm thinking type of spinners
and a lot of cool
features. So you can have the little spinner go around and you have different styles. You have
successful outcomes, failed outcomes. So like this little spinner will spin and then it'll go to like
a check mark if it succeeds or if it fails, it'll go to like a cross and you could make it red or
something like this, right? So that's really cool. We talked about progress bars where you have the progress going across.
I think one of the better ones is TQDM.
Sometimes you don't know what the progress is going to be, right?
Like I hate progress bars that go,
it's 5%, it's 5%, it's 90%, 91%,
and then it goes forever, and then finally it's done, right?
There's a great XKCD.
I'll put it in the show notes.
It's really fun about the guy who built the windows progress bar file copy progress bar but
sometimes progress bars aren't the answers there he's not bringing it up but little spinners sort
of solve that problem because it doesn't indicate progress it's just like we're busy and so here's
a really cool way to uh put that into your program it's very simple and it's it really looks nice too
yeah definitely and it has a unicorn,
a colorful unicorn.
Who doesn't want that?
I'm not sure how the unicorn displays progress though.
No, maybe in the horn.
Oh, that would be cool
if the horn had like colored.
Yes, like the horn
like flashed like rainbow.
Yeah.
I don't know if it does that or not,
but it should.
All right, but if you're looking
to add some sort of user feedback,
like, hey, we're busy, we're not locked up,
you know, Halo, super easy, very cool.
All right, that's it, Brian, for our topics.
You got anything else?
I don't think they would have made a full story,
but I wanted to let people know that the Python,
I think it's 363, is out now.
So go upgrade.
I don't know if there's anything major in it.
I haven't looked through it, but it's around. So go upgrade. I don't know if there's anything major in it. I haven't looked through it,
but it's around. So keeping current is good. And then there's also a bug fix release I noticed
in PyTest. That's around. I'm not sure what's in it, but again, it's around so people can
pay attention. Yep. Okay. Very cool. So check those out. And the last thing I wanted to mention
is I haven't been, I warned people that I was going to start podcasting again,
but it took me a while.
You warned them.
Look out, I'm going to do it.
Yeah, there are a couple.
So at the end of September and just a couple days ago,
I released a couple different test and code episodes.
One of them related to the testing pyramid.
And the last one, 32, is an excellent one by an amazing speaker.
It's with an amazing speaker named David Hussman,
and he's a brilliant man. Yeah, that's really cool, and I'm glad you got that one out. It's
awesome. How about you? Anything new going on? No, nothing new. I'm working on my courses like
crazy, but the announcement's going to have to wait until next week for anything to be actually
out for anyone to check out. Well, thanks a lot for doing this today. You bet. It was great to
catch up with you and share all these ideas with everyone.
Catch you later.
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 Ocken, this is Michael Kennedy. Thank you for listening and sharing this podcast with
your friends and colleagues.