Python Bytes - #33 You should build an Alexa skill
Episode Date: July 6, 2017Topics covered in this episode: Linting as Lightweight Defect Detection for Python You should build an Alexa skill RISE Closer Checklist for Python libraries APIs Fades Extras Joke See the full ...show notes for this episode on the website at pythonbytes.fm/33
Transcript
Discussion (0)
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.
This is episode 33, recorded July 5th, 2017. And I'm Michael Kennedy.
And I'm Brian Ocken.
And we've got some pretty sweet stuff lined up for you. But Brian, before we get into that,
I just want to say this episode is brought to you by Rollbar. They've come on to sponsor a lot of the upcoming episodes, so thank you, Rollbar.
Thank you, Rollbar. Yes. Absolutely. You know, they would actually tell you if you had an error in your code,
but would it be better if you could actually not have errors in your production code?
It would be great to not have errors. And so our first topic is a article titled
Linting as Lightweight Defect Detection for Python. And it's a decent little tutorial
just walking you through using,
using how this person's workflow is using Flake 8.
And it's a pretty short discussion,
but I actually, and it has a link for,
link to the PyCode style documentation.
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. And I was confused. I'd
used it before and I was confused a little bit because something has changed. The change is that
there's a tool called PEP 8 and there's a tool called pep257 and pep8 checks for
style the pep8 style and a few other things and pep257 checks for docstring style but these things
are now called pycode style and pydoc style i mean the other tools still exist but these are some new names that are the uh that the community
is using and um one of the reasons why that confused me is the documentation for flake 8
says that it uses pi code style but those letters are so close together and I was confused because
I thought it was saying it was pi doc style and I couldn't get it to deep by default
it doesn't care about these comments at all.
Yeah.
It doesn't check comments at all.
It's so broken.
Yeah.
And then the other thing I wanted to bring up is regarding using,
so Flake 8 is a static,
is a linter,
a static analysis and highly we've,
I think we've talked about it a little bit before.
Yeah,
probably highly recommended to run your,
run your code through Flake 8.
Yeah, and what I like about this article that you put here,
actually, is it's not just your indentation is non-standard
or the number of lines is non-standard between functions or something,
but actually discovering errors as well, which is really sweet.
Yeah, definitely.
And I found problems.
There is some pickiness that I still have.
I'm kind of a curmudgeon about having to go in and change code because there's an extra space at the end of my line.
And really, does that really matter that much?
So I definitely recommend people use it.
And then also Flake 8 has plugins so for instance uh to do doc strings you if you install
flake 8 dash doc strings it will check your uh pydoc style as well okay yeah yeah that's great
yeah i like that article that's good i really i really do like using linters for error checking
as well like hey this variable or this you're passed to a function is not used.
Maybe you intended to use it?
Yeah, things like that.
So I want to take it to another, entirely another end.
So you're down here like working on the source code.
I don't want to let you just speak
like you're in Star Trek to your computer.
It'd be cool if we could do that, right?
Yeah, definitely, yeah.
So a friend of the show Jacqueline Wilson wrote she teaches 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 so she put together an article that's like a really friendly introduction
to working with Alexa so this is the Amazon voice assistant thing And you can create these things called skills, which basically that
means you can say new things to them. So she says, let's put together one of these. And I think the
walkthrough is really simple and really straightforward. But once you see how easy it is,
if you have one of these devices available, you can do anything fun with it. You know, this,
this should really inspire you, right? So what they built or what she built in her example was a what's for dinner bot.
So you can say, hey, thing, what's for dinner?
And it'll tell you.
It'll pick some from things that you like, and it'll tell you, like, randomly pick one for you, basically.
So all you need are you need an Amazon developer account.
You need an AWS account, and you need Python 3.
And so then you can tell it things, you can teach it what are called utterances.
So like, what should I have for dinner? Do you have an idea for dinner? What's for dinner?
You can point all of those at the same functionality.
And that functionality is just a Python 3 function that lives at AWS Lambda.
Remember, we talked about Lambda before, and that's just like you go to AWS and you say,
here, I would like to run a function.
It just takes an input and output.
And here, the output is just like a JSON response that goes to Alexa.
Oh, that's cool.
Isn't that cool?
Yeah, I should try that.
Yeah, yeah.
I was actually thinking it might be fun, and you could probably have it more nuanced.
Like, one of my daughters is vegetarian,, it could ask, well, is your
vegetarian daughter here? No. Well, you should have steak. Yes. All right. Well, you should have
something that's not right. So I bet you could do some really, really cool things with it.
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.
Use your voice and just speak to the website instead.
That's really cool.
I like that.
Yeah, yeah.
It sounds really fun.
It's totally approachable.
Like if basically,
if you can drive all the AWS console widgets,
which are, there's a lot of them,
it's kind of annoying.
But if you can do that
and write a single function in AWS Lambda,
you're like more or less ready to rock.
Oh, that's great.
I'll have to check this out.
Cool.
Yeah, yeah.
Cool.
Well, next we've got a tool called Rise, which is a reveal. I Python slide extension, and it is a
slide extension or a tool for, um, pip installable tool for using I Python or Jupiter notebooks to
create slideshows. 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 how nice it looks
afterwards, 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. Oh yeah, cool. Awesome. Great
recommendation. You know, if you're writing your research papers
and written presentation already in IPython,
it's kind of cool to just go,
and now it's a presentation too, right?
It's great.
Yeah, and looking at the...
I haven't had a chance to play with it too much,
but it looks like there's drop-downs
for different slide transitions and stuff too.
So that's neat.
Yeah.
Okay.
Yeah.
It looks really cool.
Thanks.
So before we get to the next one, I want to tell you about Rollbar.
So we talked about linting.
We don't want errors in our code.
And if you run any sort of web application or web service, you guys should check out rollbar.com slash pythonbytes.
Basically, a couple lines of code to integrate it with whatever your web framework is.
And it will send you notifications if there's any sort of error with things like full stack
trace, what was the user who was running your code when that happened, how many occurrences
are there, all sorts of stuff.
So real-time notifications for errors in your sites.
I use this on all my sites and I totally am a fan.
So check it out, pythonbytes.com slash rollbar.
Wonderful.
Yep, yep, good stuff.
So do you ever run processes on remote machines, Brian?
Wouldn't it be cool if you forget to close them down
and they could just fade away
and not pile up on those remote servers.
Is that, I guess I hadn't really thought about that. Is that an issue, I guess?
Well, if you start up a bunch and they like, if basically like, what if you write some Python code
and it itself is basically like sub-process type things to create a bunch of processes.
And if those don't properly get closed down, that can be a problem. You know,
one of them hangs or something. The next one I would cover is called closer and closer will let you run
and basically control remote processes over ssh 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 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. 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. Oh, neat. Yeah. So the program runs and you can say
cleanup. Like when I start this process remotely, you can like get the output of that process back to your local machine.
But you can also say when this process exits, shut that down, right?
Automatically clean up and shut down those ones, like forcibly kill them or whatever
you need to do.
So it'll remotely kill all the processes either by choice or at the end of the project, the
calling process. It will capture the output. remotely kill all the processes either by choice or at the end of the project the the calling
process it will capture the output 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 so if it crashes before you expected somewhere along the way things like that yeah and
the examples show that it works within Jupyter Notebooks as well.
Yeah, exactly.
So yeah, basically any process.
And if you exit that one, then it's gone.
So Clojure, definitely cool.
Honestly, I don't have that much of a use for it
because I don't remotely run processes over SSH,
but I can imagine if I was doing DevOps or something,
yeah, this would be a big one.
Actually, I don't often have a need for that. And that's part of the problem is that I'm not doing
it enough to where I'm really good at it. So when I do have a need to have a couple of computers
working together to do or do a remote process, making sure that I get it all cleaned up correctly,
that'd be a good tool. Yeah. 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.
I'm like, I should probably be doing that, but I'm not.
Okay, cool.
Well, speaking of things that you probably should be doing, we've actually had this recommendation
from a lot of people, and I was surprised we haven't covered it yet.
And somebody can correct me if I'm wrong, if we actually have covered it and I've forgotten.
I don't think so.
Okay.
So there's a checklist for Python library APIs.
And I'd actually not taken a look at this for a while
because I thought it was mostly a REST API thing.
And it isn't.
It's a topic for any, like a library API.
Oh, I see.
And it's a, I'm actually not sure what the check little,
the little check marks, I'll talk about a little bit.
Yeah, they're actually check boxes.
I can actually check them.
Yeah, but I don't think it does anything when I check them off.
It makes me feel good when I click them.
But it talks about things like simplicity
and making sure you have a readme
and going through some consistency thing with naming conventions, looking at flexibility, looking at how you're doing, what your abstractions are like, type safety.
Like one of the ones to make sure that if somebody passes a wrong type into your library function to make sure you
raise a value error or something like that. There's quite a few checklist things to go down
and one of them like we've talked about before is making sure you've used pep8 and flak8.
I initially was somebody that had a whole bunch of exceptions to pep8 and flake8 but i'm doing
more vanilla flake8 now it's a good checklist look at if you are deciding to put a library up
maybe run through this and make sure you're doing some of the right things first 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. Nice. All right.
I almost told you about fades before, but I'll tell you about fades now. So fades,
fades as not closer. Fades is really cool. So the problem of Python packaging actually,
I think is still not solved. Like how do we get our Python programs to people and get them to
run those things reliably? So there's a lot of interesting takes. There's
pipinv from Kenneth Wrights. There's obviously standard pip. There's requirements.txt. There's
a ton of different things trying to solve this problem. And fades is one of them. So fades is
a cross-platform thing. And what it does is basically it will auto, given any script,
it will auto-discover, with a caveat, auto discover the dependencies of that script, see if it has a virtual environment that is previously run, or create a new virtual environment if it hasn run this with fades, and run it with Python, really.
And it will handle all of the pip install this, make sure it's that kind of version.
This one has to be greater than that, and so on.
It's really cool.
Okay.
So, yeah.
So if you're going to be passed around scripts and they've got dependencies, this is really an interesting way to take it on.
And so I said it'll auto-discover the dependencies, but with a caveat. So there's basically two ways to tell it what it needs to run a script.
You can use a comment. So like if you said import some module, you could say like,
hash as a comment fades equal equal three or fades greater than or equal to 2.1 or whatever.
And then it'll look through all the source code, find all the little fades,
annotations, I guess you could call them. And then it'll create a virtual environment with
those modules pip installed with the way you set it up, and then it'll just run.
So you could ship your code with requirements.txt, but then that's a whole nother level of experience
the person running your code has to have. Another thing I think that's cool about it is it creates these virtual environments,
but you can basically say,
run this and upgrade your virtual environment.
So,
you know,
imagine like you just say,
I'm using requests,
import requests.
Here's,
you know,
hash fades,
whatever,
no version number specified there.
And a new version of requests is released.
You can basically tell it,
go and look for updates to the dependencies that you know about before you run it.
Oh, yeah.
Okay.
Yeah, it's pretty interesting.
And you can create these configuration files.
All right.
So basically create a configuration file.
Say my default version of Python is this.
My default update behavior is that and so on.
And you can even clean up these old environments there's a way to say like delete all the ones that haven't been accessed for a couple of days
things like that it's pretty neat yeah it looks like it has some support for for non other
repositories as well yep yeah exactly so if you're pulling like out of a private get repo or something
like that to execute your code like for your pip pip install, you can pass it a git repo.
It will also, you can pass that as well
as part of your dependency statement, I guess,
your little annotation.
Yeah.
Pretty cool.
Yeah, yeah, very fun.
You can even use a different index for your pip argument
so you could come off a private PyPI server.
All right, that's it for the news,
but I wanted to cover one quick thing.
So many people know they can add comments to the show.
Just go to pythonbytes.fm slash the episode number.
So, for example, this one, pythonbytes.fm slash 33.
And at the bottom, there's a comment section, discuss section, also powered by Python.
And last time, we got a really cool comment from Jan Oglop.
And he said, hey, Michael and Brian, I wanted to thank you for the amazing work you do and let you know that you have helped me find the working place of my dreams.
My colleagues have similar hobbies and love Python as much as I do.
Thank you again.
That's really great.
That's cool.
Yeah, congratulations, Jan.
That's fantastic.
So very, very cool.
If you guys want to leave a comment, we might read it on the show as well.
All right, Brian, anything else you want to add before we put a wrap on this week's Python
announcements?
Just that next time there's a holiday, we need to not schedule super early recording
times right after the holiday.
Yeah, to be honest, last night was 4th of July in the U.S. and I was out with my kids
and I don't know about your neighborhood but my neighborhood just goes off the hook like there
was such an insane firework display down at the local elementary school and people just all
descended and set off all sorts of stuff and I thought from all the yelling with my kids I might
actually not have a voice this morning so yeah and I'm acting like I'm blaming Michael on this, but I'm the one that picked the 7 a.m. time.
So it's kind of my fault.
It helps.
I'm still partly on Dublin time.
Well, yeah, welcome back.
Yeah, thanks.
It's good to be back.
It's good to be back.
Well, thanks again for another episode.
You bet.
Thanks, Brian.
And thank you, everyone, for listening.
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 Auchin, this is Michael Kennedy.
Thank you for listening and sharing this podcast with your friends and colleagues.