Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #46: Spicy lecture notes and unicorn console spinners

Return to episode page view on github
Recorded on Wednesday, Oct 4, 2017.

00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.

00:05 This is episode 46, recorded October 4th, 2017. I'm Michael Kennedy.

00:10 And I'm Brian Okken.

00:10 And we've got a bunch of cool stuff lined up for you, as always.

00:14 But before we get to it, we have some kind of big news, Brian.

00:16 We do.

00:17 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.

00:24 Oh, that's awesome.

00:24 Yeah, so they want to let you guys know about this thing called Spaces, which is kind of like S3, but 10 times better.

00:30 And the audio you're listening to actually came to you over it.

00:34 So we'll talk more about that later.

00:35 I want to hear about spicy code.

00:36 Spicy? Oh.

00:37 I want to hear about SciPy lectures.

00:40 I misread that, spicy SciPy.

00:42 All the same.

00:43 Yeah, it's all the same.

00:45 You threw me off.

00:47 I'm like, what story are you looking at, man?

00:49 Anyway, SciPy lecture notes.

00:52 I saw, I hadn't come across this before, but they did an update just recently to,

00:57 it looks like they updated about once a year to make sure it's all current.

01:00 You know, for somebody that's doing just-in-time learning for scientific Python usage,

01:05 this is pretty darn cool.

01:07 Their tagline is, one document to learn numerics, science, and data with Python.

01:12 And it runs the gamut.

01:14 It starts off with a Python language tutorial if you want to take it.

01:18 You can learn about NumPy, Matplotlib, SciPy.

01:21 It's got topics like debugging and optimizing, image manipulation, and things like how to deal with statistics and machine learning even.

01:30 Yeah, this is really cool.

01:31 I think a lot of people are getting into data science and getting into Python because of it.

01:35 But also, I just think this is a great way to learn a lot of these techniques, right?

01:40 These little short, focused, IPython notebook style of examples.

01:45 Yeah, and for somebody that really needs to just jump in and find, the way they have it set up,

01:50 it's almost like a table of contents for a book or a reference book.

01:53 So you can just jump in and try to learn whatever you need today, just right away.

01:59 You know what's cool about the JIT stuff is it has prerequisites.

02:01 It says, like, for example, on the profiling part, it says a prerequisite is you must understand line profiler.

02:08 Oh, okay.

02:09 Yeah.

02:09 It's pretty cool.

02:10 I thought it was a great source for people that really aren't patient enough to go through a course

02:14 or really don't know what they need to learn yet.

02:16 What do you think?

02:16 That's like 95% of people.

02:18 Yeah, especially since, like we've talked about before, that Python is often a language that people pick up after their primary language.

02:25 Yeah, well, and also I think we're increasingly asked and expected to build

02:31 more and more complicated apps, bringing together more and more different disciplines.

02:34 So would it be unreasonable to say, I would like you to write a web application that talks to the database,

02:40 but also uses machine learning and the GPU?

02:44 Like that I can see being a totally normal request now, whereas those used to be their own specialties, right?

02:49 So this ability to jump in and pick up a little bit on demand is only going to be more required, I think.

02:54 Yeah.

02:55 And they also split up some of the Python stuff into like some of the beginner stuff

03:00 that you just kind of have to know to start with, and then they have some more advanced things a little bit later.

03:05 Yeah.

03:05 Nice.

03:06 So the first thing I want to talk about this week is desktop notifications.

03:12 And this caught my eye because I feel like, I've said this a couple times,

03:16 like one of the weaker points of Python is the whole desktop GUI type of thing, right?

03:21 I know you can do it, but it's just not as easy as it should be.

03:24 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.

03:32 Well, that's cool.

03:34 Yeah.

03:34 I don't know what you mean by toast.

03:36 Well, so you're sitting there and there's like a little thing that pops out and say on Mac,

03:41 it's in the top right and Windows, it's in the bottom right by the clock.

03:43 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.

03:52 Your boss is paging you.

03:54 They're upset.

03:55 You know, I finally get the toast reference.

03:57 Because it pops up.

03:59 At least in Windows, it pops up.

04:00 I guess if you tilt your toaster on the right, then in macOS, it's also toast.

04:04 I don't know.

04:06 Anyway, here's an example, a little app that says, let's write a thing that will do web scraping, I guess, a Bitcoin value location.

04:15 And it'll go to the website and pull that off and give you a periodic notification of the value of Bitcoin.

04:20 While that's not super valuable, it does show you a really interesting use case of this package called notify2,

04:26 which if you have something actually practical and interesting you want to notify people about,

04:32 that's a pretty cool little use case.

04:33 Actually, I think I might actually use this.

04:36 This would be great.

04:36 Cool.

04:36 What would you do with it?

04:37 For instance, we've got a bunch of remote machines.

04:39 For me, I've got a bunch of VMs that are dealing with builds and whatever,

04:43 and some way to keep track of them, make sure everything's alive.

04:46 Yeah, that's cool.

04:47 Like a build, pass, build, failed, machine, no longer responsive type of notifications.

04:52 Yeah, that's awesome.

04:53 That'd be really fun.

04:54 It looks like a couple lines of code and you got it going.

04:57 So that's really cool.

04:58 Would you consider performance, like if your app becomes much slower after a check-in,

05:05 like a performance degradation, like a failed build?

05:08 Well, yeah, definitely.

05:10 And how would you test for that?

05:11 Well, funny you should ask.

05:14 The next topic is a tool called pytest Benchmark.

05:18 And this actually came up because, not because of, because I'm actually looking for this.

05:22 I need to have chunks of functionality that we need to know whether or not we need to time them,

05:28 make sure they're not getting slower with successive releases of the software.

05:32 And what's interesting is the much slower or much faster or just very random timing,

05:38 people might actually notice that.

05:41 If you're dogfooding your own application and you're using it, you might notice this.

05:45 It's the subtle things like a measurement is now, it used to be two seconds and now,

05:51 and it was for like lots of releases and now it's two and a half seconds.

05:54 Normal users might not, we're not, might not notice it right then, but it sure be good to check this.

05:59 So this is a pytest Benchmark.

06:02 And it's a very easy little thing.

06:04 You can add into your code and your pytest testing to say, hey, this chunk of code,

06:09 it needs to be at least this fast.

06:11 And at first you don't know how fast it should be.

06:14 So there's a lot of tools within it to do some graphing and table driven,

06:19 showing you what the numbers are right now.

06:21 And then also an ability to have a golden, some golden numbers and save off benchmark data into a JSON file.

06:29 And then on future runs, compare against that.

06:32 So I'm going to use it.

06:34 Yeah.

06:34 That looks super interesting, actually.

06:35 And it has nice graphs over time and things like that.

06:39 Yeah.

06:40 I mean, sometimes timing doesn't matter.

06:42 But other than like how users feel about it.

06:44 But, you know, in certain types of real time systems or trading systems, there are actual numbers.

06:49 You cannot fall below.

06:51 If you're processing inbound data in real time and it's appearing every, you know, 100 milliseconds,

06:56 you have to be lower than 100 milliseconds in the processing time, right?

07:00 Or you won't be able to keep up.

07:01 Often Python's used for other things too.

07:04 Like I've heard that some people use it to control test instruments.

07:08 Yes, that's possible.

07:09 So, for instance, checking to make sure even application turn on and measurement times don't slow down.

07:16 Because these instruments are used in production lines and it'll slow down your customer's production line if you slow down.

07:23 Yeah, absolutely.

07:24 All sorts of factory automation and all kinds of things.

07:27 Cool.

07:27 All right.

07:28 So, that's really nice.

07:29 I definitely, if I had a use case for that, I would definitely use it.

07:32 I just don't have anything that I can say it must be this fast or it's a problem.

07:36 But it still would be cool to actually see the speed over time.

07:39 Now, before we get on to the next one, let me say thanks to DigitalOcean and just let you guys know about Spaces.

07:45 So, you probably heard of Amazon S3, right?

07:48 I think that was their first thing.

07:50 But, like I said, DigitalOcean just released Spaces and I definitely think it's better.

07:56 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.

08:02 So, for one, it's like nine times cheaper than AWS.

08:06 It's super predictable pricing.

08:08 There's all kinds of benefits.

08:10 You can use the same tools as you used to manage your S3 thing.

08:14 So, same APIs and everything.

08:16 So, for example, I use this cool program called Transmit for my Mac to manage all my files in S3.

08:21 Just point it at DigitalOcean Spaces and it just keeps working.

08:25 It's awesome.

08:25 So, it's like $5 a month, 250 gigs for free in storage, a terabyte for free in bandwidth.

08:32 That is quite expensive if you pay $0.09 per gigabyte at AWS.

08:39 But it's completely free here and it's a really nice service just as fast but much more predictable.

08:45 And even inbound data is 100% free.

08:48 So, check them out.

08:49 It's really a super simple API.

08:51 It's one you're familiar with, the tools of work.

08:53 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.

09:01 So, check it out.

09:04 That's great.

09:05 Cool.

09:05 Yeah, it's a super cool project.

09:06 I'm so happy they came out with it and I'm happy to be using it for this podcast and other stuff.

09:12 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.

09:23 So, I want to highlight an article that is, it's 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.

09:34 It's an article by Vicky Boykus and it's called Alice in Python Project Land.

09:40 So, it's got some cool little graphics and stuff, but the idea is like, she's a data scientist learning data science and those things.

09:48 So, doing a lot of Java and doing a lot of Python.

09:50 It's like, look, Python is so much better except for it's really hard to package up things.

09:56 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.

10:02 So, instead of just going, well, these are the four steps you do to create a Python package, she says, let's look at the internals of how Python actually works.

10:10 She said, how it runs, how it understands and links things together.

10:13 And so, you not just know how to put things together, but you understand why.

10:17 So, very, very interesting article.

10:20 Pretty in-depth.

10:21 So, packaging has always been kind of this weird thing that you just follow the steps.

10:25 You can check this out.

10:25 It's a good article.

10:26 Like you said, it's in-depth, which makes it kind of a long article, but the writing is really good.

10:31 So, it moves along pretty fast.

10:33 Yeah, it sure does.

10:34 It sure does.

10:34 And it answers a lot of questions like, should you use setup tools?

10:37 Should you use pip?

10:38 What does dunder init.py do?

10:41 Should I mess with Python path?

10:43 Should I not?

10:44 And another thing that I saw that she referenced in there was pretty cool.

10:47 It's called piprex.

10:48 Have you seen this?

10:49 No.

10:49 Yeah.

10:50 So, I think piprex, you pointed at your code and it looks at all your imports and it then knows what to create for your requirements.txt.

10:56 Cool.

10:57 So, instead of remembering like, oh yeah, there was that thing that I used, Colorama or whatever, and I forgot to put it in the requirements file, so it's not going to work.

11:04 Like, this will just discover it.

11:05 It's really cool.

11:06 So, yep.

11:07 If you want to get like an understanding of how Python packaging and assembly of modules at runtime works, definitely check out this article.

11:15 It's super approachable, but well done.

11:17 Next article, how to teach technical concepts with cartoons.

11:20 Love technology.

11:22 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.

11:33 But drawing things to help people understand concepts, it's very, it helps.

11:39 It's easier to understand things, and nobody expects you to draw really great pictures.

11:44 This article starts off, I love this, it starts off with just saying that she draws not that great.

11:50 It has really three horrible pictures of a dog, a cat, and an elephant.

11:54 I don't think I can do better, but they're not great drawings.

11:58 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.

12:07 I think it's a really cool idea.

12:08 You certainly can personalize and humanize technical concepts if you use pictures.

12:14 Like you said, they don't have to be super fancy, so she has a dog, a cat, and an elephant, and those sorts of things.

12:20 But you know, not far down, she says, oh, let's do something about a mutex.

12:25 And actually represents how mutexes are used to like, for shared memory, or something like that, right?

12:32 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?

12:41 But here it's like, oh, okay, well, that's totally simple.

12:43 I think you can really convey a lot and sort of disarm people with some nice drawings.

12:49 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.

13:00 That's what the tutorial is.

13:01 And it breaks it up a lot.

13:03 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.

13:13 And sometimes I think just a pen and paper might help convey the information better.

13:17 Yeah, yeah, absolutely.

13:18 I think this is really cool and hopefully inspire some people to do a little more freehand stuff.

13:23 It doesn't always have to be perfect.

13:25 So keeping it graphical for our last item, I want to share the Halo with you.

13:30 So Halo is a project called Beautiful Terminal Spinners in Python, which is what it sounds like.

13:37 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.

13:46 So you can have the little spinner go around and you have different styles.

13:49 You have successful outcomes, failed outcomes.

13:53 So like this little spinner will spin and then it'll go to like a check mark if it succeeds.

13:57 Or if it fails, it'll go to like a cross and you could make it red or something like this, right?

14:01 So that's really cool.

14:03 We talked about progress bars where you have the progress going across.

14:07 You know, I think one of the better ones is TQDM.

14:10 Sometimes you don't know what the progress is going to be, right?

14:14 Like I hate progress bars that go it's 5%, it's 5%.

14:17 It's 90%, 91% and then it goes forever and then finally it's done, right?

14:22 There's a great XKCD.

14:23 I'll put it in the show notes.

14:25 It's really fun about the guy who built the Windows progress bar, file copy progress bar.

14:28 But sometimes progress bars aren't the answers.

14:31 There are reasons why I'm bringing it up.

14:31 But little spinners sort of solve that problem because it doesn't indicate progress.

14:35 It's just like we're busy.

14:36 And so here's a really cool way to put that into your program.

14:40 It's very simple and it really looks nice too.

14:43 Yeah, definitely.

14:43 And it has a unicorn, a colorful unicorn.

14:46 He doesn't want that.

14:47 I'm not sure how the unicorn displays progress though.

14:51 No, maybe in the horn.

14:52 Oh, that would be cool if the horn had like colored.

14:55 Yes, like the horn like flashed like rainbow.

14:59 Yeah.

15:00 I don't know if it does that or not, but it should.

15:03 All right.

15:04 But if you're looking to add some sort of user feedback like, hey, we're busy.

15:06 We're not locked up.

15:07 You know, Halo, super easy.

15:09 Very cool.

15:10 All right.

15:10 That's it, Brian, for our topics.

15:12 You got anything else?

15:13 I don't think they would have made a full story, but I wanted to let people know that the Python,

15:18 I think it's 363, is out now.

15:21 So go upgrade.

15:22 I don't know if there's anything major in it.

15:24 I haven't looked through it, but it's around.

15:26 So keeping current is good.

15:28 And then there's also a bug fix release I noticed in pytest.

15:32 That's around.

15:32 I'm not sure what's in it, but again, it's around so people can pay attention.

15:36 Yep.

15:37 Okay.

15:37 Very cool.

15:38 So check those out.

15:39 And the last thing I wanted to mention is I haven't been, I warned people that I was going

15:44 to start podcasting again, but it took me a while.

15:46 You warned them.

15:47 Look out.

15:47 I'm going to do it.

15:48 Yeah.

15:48 There are a couple.

15:49 So at the end of September and just a couple of days ago, I released a couple different test

15:54 and code episodes.

15:56 One of them related to the testing pyramid.

15:58 And the last one, 32, is an excellent one by an amazing speaker.

16:02 It's with an amazing speaker named David Hussman.

16:05 And he's a brilliant man.

16:07 Yeah.

16:07 That's really cool.

16:08 And I'm glad you got that one out.

16:09 That's awesome.

16:09 How about you?

16:10 Anything new going on?

16:11 No, nothing new.

16:12 I'm working on my courses like crazy, but the announcement's going to have to wait until

16:16 next week for anything to be actually out for anyone to check out.

16:20 Well, thanks a lot for doing this today.

16:21 You bet.

16:22 It was great to catch up with you and share all these ideas with everyone.

16:24 Catch you later.

16:25 Thank you for listening to Python Bytes.

16:28 Follow the show on Twitter via at Python Bytes.

16:30 That's Python Bytes as in B-Y-T-E-S.

16:33 And get the full show notes at pythonbytes.fm.

16:36 If you have a news item you want featured, just visit pythonbytes.fm and send it our way.

16:41 We're always on the lookout for sharing something cool.

16:44 On behalf of myself and Brian Okken, this is Michael Kennedy.

16:47 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page