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


Transcript #33: You should build an Alexa skill

Return to episode page view on github
Recorded on Wednesday, Jul 5, 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 33, recorded July 5th, 2017.

00:11 And I'm Michael Kennedy.

00:12 And I'm Brian Okken.

00:13 And we've got some pretty sweet stuff lined up for you.

00:15 But Brian, before we get into that, I just want to say this episode is brought to you by Rollbar.

00:19 They've come on to sponsor a lot of the upcoming episodes, so thank you, Rollbar.

00:22 Thank you, Rollbar, yes.

00:23 Absolutely.

00:24 You know, they would actually tell you if you had an error in your code.

00:28 But would it be better if you could actually not have errors in your production code?

00:32 It would be great to not have errors.

00:33 And so our first topic is an article titled, Linting as Lightweight Defect Detection for Python.

00:42 And it's a decent little tutorial just walking you through using how this person's workflow is using Flake 8.

00:52 And it's a pretty short discussion.

00:56 But I actually, and it has a link for, link to the PyCode style documentation.

01:02 And I wanted to bring this up because I've been trying to clean up the code examples for the book and using Flake 8 a lot.

01:13 And I was confused.

01:14 I had used it before and I was confused a little bit because something has changed.

01:19 The change is that there's a tool called Pep8 and there's a tool called Pep257.

01:25 And Pep8 checks for the Pep8 style and a few other things.

01:31 And Pep257 checks for docstring style.

01:35 But these things are now called PyCode style and PyDoc style.

01:40 I mean, the other tools still exist, but these are some new names that the community is using.

01:48 And one of the reasons why that confused me is the documentation for Flake 8 says that it uses PyCode style.

01:55 But those letters are so close together.

01:57 And I was confused because I thought it was saying it was PyDoc style and I couldn't get it to deep by default.

02:03 It doesn't care about these comments at all.

02:06 Yeah.

02:06 It doesn't check comments at all.

02:08 It's so broken.

02:09 Yeah.

02:09 And then the other thing I wanted to bring up is regarding using.

02:12 So Flake 8 is a static, a lint or a static analysis.

02:17 And highly, I think we've talked about it a little bit before.

02:20 Yeah, probably.

02:21 Highly recommended to run your code through Flake 8.

02:25 Yeah.

02:25 And what I like about this article that you put here actually is it's not just your indentation is, you know, non-standard or the number of lines is non-standard between functions or something,

02:36 but actually discovering errors as well, which is really sweet.

02:39 Yeah, definitely.

02:40 And I found problems.

02:41 There is some pickiness that I still have.

02:44 I'm kind of a curmudgeon about like having to go in and change code because there's an extra space at the end of my line.

02:52 And like, really, does that really matter that much?

02:55 But so I definitely recommend people use it.

03:00 And then also Flake 8 has plugins.

03:03 So, for instance, to do doc strings, if you install Flake 8 dash doc strings, it will check your PyDoc style as well.

03:14 Okay.

03:14 Yeah.

03:15 Yeah, yeah.

03:16 That's great.

03:16 Yeah, I like that article.

03:18 That's good.

03:18 I really do like using linters for error checking as well.

03:22 Like, hey, this variable or this parameter you're passed to a function is not used.

03:26 Maybe you intended to use it.

03:28 Yeah, things like that.

03:29 So I want to take it to another, entirely another end.

03:33 So you're down here like working on the source code.

03:35 I don't want to let you just speak like you're in Star Trek to your computer.

03:38 It'd be cool if we could do that, right?

03:40 Yeah, definitely.

03:41 Yeah.

03:42 So a friend of the show, Jacqueline Wilson, wrote, she's a teacher and she teaches, I can't remember if it's math or computer science, but she teaches people who are new to Python.

03:52 So she put together an article that's like a really friendly introduction to working with Alexa.

03:58 So this is the Amazon voice assistant thing.

04:02 And you can create these things called skills, which basically that means you can say new things to them.

04:07 So she says, let's put together one of these.

04:10 And I think the walkthrough is really simple and really straightforward.

04:13 But once you see how easy it is, if you have one of these devices available and you can do anything fun with it, you know, this should really inspire you.

04:21 Right.

04:22 So what they built or what she built in her example was a what's for dinner bot.

04:27 So you can say, hey, thing, what's for dinner?

04:31 And it'll tell you, you know, it'll pick some from things that you like and it'll tell you like randomly pick one for you basically.

04:38 So all you need are you need an Amazon developer account.

04:43 You need an AWS account and you need Python 3.

04:47 And so then you can tell it thing, you can teach it what are called utterances.

04:52 So like, what should I have for dinner?

04:55 Do you have an idea for dinner?

04:56 What's for dinner?

04:57 You could point all of those at the same functionality.

04:59 And that functionality is just a Python 3 function that lives at AWS Lambda.

05:06 Remember we talked about Lambda before and that's just like you go to AWS and you say here I would like to run, write a function.

05:12 It just takes an input and output.

05:14 And here the output is just like a JSON response that goes to Alexa.

05:17 Oh, that's cool.

05:18 Isn't that cool?

05:18 Yeah, I should try that.

05:19 Yeah, yeah.

05:20 I was actually thinking it might be fun and you could probably have it more nuanced.

05:24 Like one of my daughters is vegetarian.

05:25 So, you know, it could ask, well, is your vegetarian daughter here?

05:28 No.

05:29 Well, you should have steak.

05:30 Yes.

05:30 All right.

05:30 Well, you should have something that's not right.

05:33 So I bet you could do some really, really cool things with it.

05:36 And if you want to play around with these ideas but you don't have an Alexa, you can actually go to, there's like a website that'll let you test it.

05:44 Use your voice and just speak to the website instead.

05:46 That's really cool.

05:47 I like that.

05:47 Yeah, yeah.

05:48 It sounds really fun.

05:49 It's totally approachable.

05:50 Like basically if you can drive all the AWS console widgets, which are, there's a lot of them and it's kind of annoying.

05:55 But if you can do that and write a single function in AWS Lambda, you're like more or less ready to rock.

06:00 Oh, that's great.

06:01 I'll have to check this out.

06:02 Cool.

06:03 Yeah, yeah.

06:03 Cool.

06:04 Well, next we've got a tool called Rise, which is a reveal IPython slide extension.

06:10 And it is a slide extension or a tool for, a pip installable tool for using IPython or Jupyter notebooks to create slideshows.

06:23 And there's a couple videos out for how to do it, but the effect and the amount of work they have to put into a slideshow versus the, how nice it looks afterwards.

06:34 I think it's definitely something for people to look into if they use IPython or Jupyter a lot and need to do a slideshow for something.

06:42 Oh yeah.

06:42 Cool.

06:42 Awesome.

06:43 Great recommendation.

06:44 You know, if you're writing your research papers and presentation, written presentation already in IPython, it's kind of cool to just go, and now it's a presentation too, right?

06:55 It's great.

06:55 Yeah.

06:55 And then looking at the, I haven't had a chance to play with it too much, but it looks like there's, there's dropdowns for different slide transitions and stuff too.

07:05 So that's, that's neat.

07:06 Yeah.

07:06 Okay.

07:07 Yeah.

07:07 It looks, it looks really cool.

07:08 Thanks.

07:09 So before we get to the next one, I'm going to tell you about Rollbar.

07:12 So we talked about lending and we don't want errors in our code.

07:15 And if you run any sort of web application, web service, you guys should check out rollbar.com slash Python bytes.

07:22 Basically a couple of lines of code to integrate it with whatever your framework, a web framework is.

07:28 And it will send you notifications.

07:30 If there's any sort of error with things like full stack trays, what was the user who is running your code when that happened?

07:37 How many occurrences are there?

07:39 All sorts of stuff.

07:40 So real time notifications for errors in your sites.

07:44 I use this on my, on all my sites and I'm totally a fan.

07:48 So check it out.

07:49 Python bytes.com slash rollbar.

07:51 Wonderful.

07:52 Yep.

07:52 Yep.

07:52 Good stuff.

07:53 So do you ever run processes on a remote machines, Brian?

07:57 Wouldn't it be cool if like you forget to close them down and they could just like fade away and not pile up on those remote servers?

08:06 Is that, I guess I hadn't really thought about that.

08:08 Is that an issue?

08:09 I guess.

08:09 Yeah.

08:10 Well, if you start up a bunch and they like, if basically like what if you write some Python code and it itself use basically like sub process type things to create a bunch of processes.

08:20 And if those don't properly get closed down, that can be a problem.

08:24 You know, one of them hangs or something.

08:26 The next one I would cover is called closer and closer will let you run and basically control remote processes over SSH.

08:35 So the guy who created it said it was born out of the trouble of like killing the processes that he had started remotely via SSH.

08:42 So he could start them pretty easily, but then like they would keep running and he wanted to shut them down or something like that.

08:47 So this closer, you can use this within Python and basically say like I would like the lifetime of the sub processes to be tied to the lifetime of my local Python program.

08:58 Oh, neat.

08:59 Yeah.

08:59 So the program runs and you can say cleanup.

09:01 Like when I start this process remotely, you can like get the output of that process back to your local machine.

09:09 But you can also say when this process exits, shut that down.

09:13 Right.

09:13 Automatically clean up and shut down those ones like forcibly kill them or whatever you need to do.

09:18 So it'll remotely kill all the processes either by choice or at the end of the project, the calling process.

09:25 It will capture the output.

09:28 You can do live monitoring so you can start a remote process and have it be doing a thing and basically set up a callback for like its output, a callback for when it dies.

09:38 So if it crashes before you expected somewhere along the way, things like that.

09:42 Yeah.

09:43 And the examples show that it works within Jupyter Notebooks as well.

09:47 Yeah, exactly.

09:48 So yeah, basically any process.

09:50 And if you exit that one, then it's gone.

09:52 So Closer, definitely cool.

09:55 Honestly, I don't have that much of a use for it because I don't remotely run processes over SSH.

10:00 But I can imagine like if I was doing DevOps or something, yeah, this would be a big one.

10:04 Actually, I don't often have a need for that.

10:07 And that's part of the problem is that I'm not doing it enough to where I'm really good at it.

10:13 So when I do have a need to have a couple computers working together to do or do a remote process, making sure that I get it all cleaned up correctly, that would be a good tool.

10:22 Yeah.

10:23 Well, it basically makes me think as well, like I should probably be thinking about how I could use these types of features and functionality.

10:29 I'm like, I should probably be doing that, but I'm not.

10:32 Okay, cool.

10:32 Well, speaking of things that you probably should be doing, we've actually had this recommendation from a lot of people.

10:39 And I was surprised we haven't covered it yet.

10:41 And somebody can correct me if I'm wrong, if we actually have covered it and I've forgotten.

10:45 I don't think so.

10:46 Okay, so there's a checklist for Python library APIs.

10:50 And I'd actually not taken a look at this for a while because I thought it was mostly a REST API thing.

10:59 And it isn't.

11:01 It's a topic for any, like a library API.

11:06 Oh, I see.

11:06 And it's, I'm actually not sure what the little check marks I'll talk about a little bit.

11:12 Yeah, they're actually check boxes.

11:13 I can actually check them.

11:15 Yeah, but I don't think it does anything when I check them off.

11:17 It makes me feel good when I click them.

11:19 But it talks about things like simplicity and making sure you have a readme and going through some consistency thing with naming conventions,

11:29 looking at flexibility, looking at how you're doing, what your abstractions are like, type safety,

11:38 like one of the ones to make sure that if somebody passes a wrong type into your library function,

11:45 to make sure you throw, raise a value error or something like that.

11:49 There's quite a few checklist things to go down.

11:53 And one of them, like we've talked about before, is making sure you've used PEP 8 and FLAC8.

11:59 I initially was somebody that had a whole bunch of exceptions to PEP 8 and FLAC8, but I'm doing more vanilla FLAC8 now.

12:07 It's a good checklist to look at if you are deciding to put a library up.

12:13 Maybe run through this and make sure you're doing some of the right things first.

12:17 Sure, this sort of goes along with some of your guidance on your open source package organization and some of those other types of things as well.

12:24 Nice.

12:25 All right.

12:25 I almost told you about Fades before, but I'm going to tell you about Fades now.

12:28 So Fades is not closer.

12:30 Fades is really cool.

12:31 So the problem of Python packaging actually I think is still not solved.

12:36 How do we get our Python programs to people and get them to run those things reliably?

12:42 So there's a lot of interesting takes.

12:45 There's pipinv from Kenneth Writes.

12:48 There's obviously standard pip.

12:50 There's requirements.txt.

12:52 There's a ton of different things trying to solve this problem, and Fades is one of them.

12:57 So Fades is a cross-platform thing, and what it does is basically it will auto, given any script,

13:04 it will auto-discover, with a caveat, auto-discover the dependencies of that script,

13:09 see if it has a virtual environment that has previously run, or create a new virtual environment if it hasn't for this script,

13:16 and install all those dependencies, and then run it.

13:20 So basically you can give a script to somebody and say, run this with Fades, and run it with Python, really.

13:26 And it will handle all of the pip install this, make sure it's that kind of version,

13:31 this one has to be greater than that, and so on.

13:33 It's really cool.

13:34 Hmm.

13:34 Okay.

13:35 So, yeah, so if you're going to be passed around scripts, and they've got dependencies,

13:39 this is really an interesting way to take it on.

13:42 So I said it'll auto-discover the dependencies, but with a caveat.

13:45 So there's basically two ways to tell it what it needs to run a script.

13:48 You can use a comment.

13:51 So, like, if you said import some module, you could say, like, hash as a comment, fades equal equal three,

13:58 or fades greater than or equal to 2.1, or whatever.

14:00 And then it'll look through all the source code, find all the little fades annotations, I guess you could call them.

14:07 And then it'll create a virtual environment with those modules pip installed with the way you set it up,

14:12 and then it'll just run.

14:13 So you could ship your code with requirements.txt, but then that's a whole other level of experience

14:19 the person running your code has to have.

14:21 Yeah.

14:22 Another thing I think that's cool about it is it creates these virtual environments,

14:25 but you can basically, say, run this and upgrade your virtual environment.

14:31 So, you know, imagine, like, you just say, I'm using requests, import requests, here's, you know, hash fades, whatever.

14:37 No version number specified there.

14:39 And a new version of requests is released.

14:42 You can basically tell it, go and look for updates to the dependencies that you know about before you run it.

14:49 Oh, yeah.

14:49 Okay.

14:50 Yeah, it's pretty interesting.

14:51 And you can create these configuration files.

14:55 All right.

14:56 So basically, create a configuration file, say, my default version of Python is this,

15:00 my default update behavior is that, and so on.

15:03 And you can even clean up these old environments.

15:05 There's a way to say, like, delete all the ones that haven't been accessed for a couple of days.

15:09 Things like that.

15:10 It's pretty neat.

15:11 Yeah, it looks like it has some support for non-other repositories as well.

15:16 Yep.

15:16 Yeah, exactly.

15:17 So if you're pulling, like, out of a private Git repo or something like that to execute your code,

15:22 like for your pip install, you know, you can pass it a Git repo.

15:25 It will also, you can pass that as well as part of your dependency statement, I guess.

15:31 Cool.

15:31 In your little annotation.

15:32 Yeah.

15:32 Pretty cool.

15:33 Yeah.

15:33 Yeah, very fun.

15:34 You can even use a different index for your pip argument.

15:37 So you could come off a private PyPI server.

15:39 All right.

15:40 That's it for the news.

15:41 But I wanted to cover one quick thing.

15:43 So many people know they can add comments to the show.

15:47 Just go to pythonbytes.fm/the episode number.

15:52 So for example, this one, pythonbytes.fm/33.

15:55 And at the bottom, there's a comment section, discuss section, also powered by Python.

15:59 And last time, we got a really cool comment from Jan Oglop.

16:06 And he said, hey, Michael and Brian, I wanted to thank you for the amazing work you do and

16:10 let you know that you have helped me find the working place of my dreams.

16:14 My colleagues have similar hobbies and love Python as much as I do.

16:18 Thank you again.

16:18 That's really great.

16:19 How about that?

16:19 That's cool.

16:20 Yeah.

16:20 Congratulations, Jan.

16:21 That's fantastic.

16:22 So very, very cool.

16:23 If you guys want to leave a comment, we might read it on the show as well.

16:26 All right, Brian, anything else you want to add before we put a wrap on this week's Python

16:31 announcements?

16:32 Just that next time there's a holiday, we need to not schedule like super early recording

16:38 times right after the holiday.

16:40 Yeah, to be honest, like, you know, last night was 4th of July in the US and I was out with

16:47 my kids.

16:47 And I don't know about your neighborhood, but my neighborhood just goes off the hook.

16:51 Like there was such an insane firework display down at the local elementary school.

16:55 People just all descended and set off all sorts of stuff.

16:59 And I thought from all the yelling with my kids, I might actually not have a voice this

17:03 morning.

17:03 So yeah, and I'm acting like I'm blaming Michael on this, but I'm the one that picked the 7 a.m.

17:09 time.

17:09 So it's kind of my fault.

17:10 So it helps.

17:11 I'm still partly on Dublin time.

17:13 Well, yeah, welcome back.

17:14 So yeah, thanks.

17:16 It's good to be back.

17:17 It's good to be back.

17:18 Well, thanks again for another episode.

17:19 You bet.

17:20 Thanks, Brian.

17:20 And thank you everyone for listening.

17:21 Bye.

17:24 Thank you for listening to Python Bytes.

17:25 Follow the show on Twitter via at Python Bytes.

17:28 That's Python Bytes as in B-Y-T-E-S.

17:31 And get the full show notes at pythonbytes.fm.

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

17:38 We're always on the lookout for sharing something cool.

17:41 On behalf of myself and Brian Okken, this is Michael Kennedy.

17:44 Thank you for listening and sharing this podcast with your friends and colleagues.

Back to show page