Latest / Talk Python To Me / #392: Data Science from the Command Line
Transcript
- 0:00When you think of data science, Jupyter Notebooks and associated tools probably come to mind.
- 0:04But I want to broaden your tool set a bit and encourage you to look around at other tools that
- 0:09are literally at your fingertips, the Terminal and the Shell command line tools. On this episode,
- 0:14you'll meet Joran Janssen, who wrote the book Data Science on the Command Line. And there are a bunch
- 0:19of fun and useful small utilities that will make your life simpler that you can run immediately in
- 0:25the terminal. For example, you can query a CSV file with SQL right on the command line.
- 0:30That and much more on this episode 392 of Talk Python To Me, recorded November 28th, 2022.
- 0:50Welcome to Talk Python To Me, a weekly podcast on Python. This is your host, Michael Kennedy.
- 0:55Follow me on Mastodon, where I'm @mkennedy and follow the podcast using @talkpython,
- 1:01both on fosstodon.org. Be careful with impersonating accounts on other instances. There are many.
- 1:07Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:12We've started streaming most of our episodes live on YouTube. Subscribe to our YouTube channel over
- 1:17at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:23This episode is sponsored by Sentry. Don't let those errors go unnoticed. Use Sentry. Get started
- 1:30at talkpython.fm/sentry. And it's brought to you by Microsoft for Startups Founders Hub.
- 1:36Check them out at talkpython.fm/foundershub to get early support for your startup.
- 1:42Transcripts for this episode are sponsored by Assembly AI, the API platform for state-of-the-art
- 1:48AI models that automatically transcribe and understand audio data at a large scale. To learn more,
- 1:54visit talkpython.fm/assemblyai.
- 1:57Yerun, welcome to Talk Python To Me.
- 1:59Hey, thank you. I'm very happy to be here.
- 2:02I saw your book and the title was Data Science at the Command Line. I thought, okay, that's
- 2:08different. You know, there's a lot of people that talk about data science tools and Jupyter
- 2:12Labs, amazing. And like, if you look over the fence, like our studio and those kinds of things.
- 2:17And yet, so much of what we can kind of do and orchestrate and create as a building block
- 2:22happens in the terminal. And bringing some of these data science ideas and some of these
- 2:28concepts from the terminal to support data scientists, I think is a really cool idea. So
- 2:32we're going to have a great time talking about it.
- 2:33Yeah. Yeah. I love to talk about this. And yeah, you're right. I still find it an interesting
- 2:38juxtaposition of these two terms, data science and the command line. One being, well, nowadays,
- 2:45let's say 10 years old, at least the term is. And the other one, the command line is over 50 years old.
- 2:51The command line is, it's ancient in computer terms, right? It's one of the absolute very first
- 2:58ways of interacting with computers. You've got cards where you programmed on paper,
- 3:03and then you had the shell, right? Right after that.
- 3:06Exactly. Before there were any screens, really.
- 3:08Yeah. When we all, when computers were green, they were all green. It was amazing. So I'm looking
- 3:13forward to diving into that. And it's going to be a lot of fun. And I just want to also put out there
- 3:18for people who are like, but I'm not a data scientist. So should I check out? I actually
- 3:22think there's a ton of cool ideas in there from just for people who do all sorts of Python and other
- 3:28types of programming. It's not just data scientists, right?
- 3:31No, absolutely. And I mean, even, I mean, I don't really care much for titles, but even when you're
- 3:38an engineer or a developer, you would be surprised if you really think about how much data you actually
- 3:45work with. I mean, just log files on the server. Yeah.
- 3:49That's data too. So there are still a lot of opportunities to use the command line, even if
- 3:56you don't consider yourself to be a data scientist per se.
- 4:00Yeah, I totally agree. All right. Let's start with your story. How'd you get into programming
- 4:04and data science and Python? I know you do Python and R and some other things. So how'd you get into
- 4:10programming? Yeah, it actually started when I was about 12 years old. We got this old computer. It
- 4:18was already old by then, 286. And I opened up this program. I wanted to write a story. And I was just
- 4:27typing. I was journaling. Then I got all these error messages. Turns out the program that I had opened
- 4:33was QBasic. And I didn't really like what I had to say. And then I started reading the help. And then
- 4:41I realized like, hey, I can make this computer do things. It just needs a particular language.
- 4:47And that's really how I got into programming. Yeah. And then of course, there's a whole range of
- 4:53programming languages that then come by. Visual Basic at a certain point. Pascal, Java, C.
- 5:01And you know what? I've forgotten most of it. So if this sounds intimidating,
- 5:06please don't worry. But yeah, nowadays, Python plays a big role in my professional career. Also R,
- 5:14right? And those two happen to be the most popular programming languages for doing data science and
- 5:21JavaScript, obviously, when you're doing some more front-end work.
- 5:24JavaScript finds its ways into all these little cracks. You're like, why JavaScript? Come on. I was
- 5:29just looking at programmable dynamic DNS as a service. And the way you program it is you, I know,
- 5:36and you jam in little bits of JavaScript to make a decision on how to like route a DNS query. I'm like,
- 5:41JavaScript.
- 5:42Oh, yeah. I'm now using Eleventy, which is a static site generator. And ironically enough,
- 5:50it uses JavaScript.
- 5:51Yeah, sure.
- 5:52So yeah.
- 5:53That's fantastic. I've heard really good things about Eleventy. And I just started using Hugo,
- 5:58which is also a static site generator, but that one's written in Go. And I just decided I care
- 6:03about writing in Markdown and I want a static site. And I don't care as long as I run a command on the
- 6:07terminal. Actually, I want to tell the story a little bit about sort of coordinating over the
- 6:12shell for some of these static site things. But I decided I don't care if it's the guts of it are in
- 6:17a language that I can program. It's a tool. If it's a good tool for me, I'm going to use it.
- 6:21Okay. So that's how you got into programming. How about day to day? What are you doing these days?
- 6:25Yeah. So at this very moment, as we're recording this, I have my own company called Data Science
- 6:32Workshops, where I give training at companies to developers and researchers and occasionally managers.
- 6:39But I have decided to stop with that. Okay. So in a couple of weeks, I'll actually join another company.
- 6:47So in the past six years, I have, we can talk about how that company came about. And it's probably
- 6:53related to, it's related to everything, of course. But, but I just want to say that this is actually the
- 6:59very first time that I'm talking about this, but I'm going to be a machine learning engineer.
- 7:05Okay. Two reasons why I decided to, to stop with, with my own company is that first of all, I really
- 7:11miss working with people, working with colleagues. Yeah. And secondly, I miss building things. So
- 7:18that's why I'm, I'm joining, well, January 1st, I'm joining Xomnia, a consultancy based in Amsterdam,
- 7:25the Netherlands. Excellent. Well, that sounds, that sounds really fun. I also run my own company and I'd
- 7:31really enjoy it, but I completely get what you're saying. It's sometimes it's nice to be with a team
- 7:37and you also, it makes you learn different skills or hone different skills to show up at a client
- 7:43company where they've got, you know, a million requests in an hour trying to answer something,
- 7:48which machine learning versus, you know, doing some research and talking about how to improve the
- 7:53shell, right? These are very, two very different jobs. And so it's, it's cool to sort of mix,
- 7:57mix up the career across those. Say again? It's great to mix up your career and do,
- 8:01do some of both, right? Because if all you do is work at a consultant, you'd be like,
- 8:04I can't wait to start my own company and do something else. Right, right, right. And you know,
- 8:08the company was just, just happened. That's actually thanks to the book that I wrote a long time ago.
- 8:14I, once it was done, the first edition that is in 2014, and we're talking about data science at the
- 8:21command line here, I was asked to give a workshop and I'd never given a workshop before, but I was asked by,
- 8:27a games company in Barcelona to give a one day workshop. And I liked it. And I liked it so much
- 8:34that I started doing this more often. Yeah. So I decided to do this full time. So I didn't choose
- 8:39the company life, the startup life. Although you can't really think of it as a startup, but yeah.
- 8:46Yeah, sure. Yeah. These things happen.
- 8:47The independent, the independent life. That's right.
- 8:49Yeah, exactly.
- 8:50Yeah. Cool. All right. Well, let's talk about the terminal. People on Windows might know it as the
- 8:56command prompt. Although you, as I would also recommend that people generally stay away from
- 9:01the command prompt in, at least for some of these tools, but we do have the Windows terminal,
- 9:07which is relatively new and much, much nicer, much, much closer to the way Mac.
- 9:13Yeah. Well, there's the PowerShell, but then there's also a new Windows terminal application.
- 9:20And then it can even do things like bash into Windows subsystem for Linux, right? So if you
- 9:26wanted to use some of these tools, you could fire up Windows subsystem for Linux, and then you would
- 9:29literally have the same tool chain because it's just Ubuntu or something.
- 9:32Oh, right. Yeah. I mean, I have, I'm familiar with WSL, but I haven't tried out this new Windows.
- 9:39Yeah. The new Windows terminal is pretty nice. Well, let me see if I can pull it up for everybody.
- 9:44Windows terminal, but yeah, it's just in the Windows 11 store, I guess you call it. I don't
- 9:50know, but it's, it's a lot closer to a lot closer to the other tools. So if you're on Windows,
- 9:55you owe it to yourself to not use cmd.exe, but get this instead. So what I want to talk about just
- 10:02real quickly to set the stage is I just went through a period of, oh, my computer has been
- 10:09the same setup for a couple of years. It's getting crufty. I'm going to just format it,
- 10:13not restore from some backup, but format it and reset up everything. So it's completely fresh and
- 10:19like better. Cause I really made some mistakes when I first set it up. Now it's better, but I opened up
- 10:24the terminal and it's this tiny font, dreadful white background with white, with black text. And
- 10:30it has some old version of bash. And so I kind of wanted to get your thoughts on like,
- 10:36what do you do to make your terminal better? Right. You probably do something. You probably
- 10:42install some extras and other things to make your experience on the terminal nicer.
- 10:47Yeah. I'm guessing you're on macOS then? Yes. I do macOS and I do a Linux for the servers.
- 10:53And I think some combination thereof is pretty common for most of the listeners.
- 10:58So for macOS, the biggest gain you get when you install iTerm. Okay. A different terminal,
- 11:05right? The application that would launch your shell.
- 11:08The macOS term. Yeah. The terminal emulator. I, what do they call it? The macOS terminal replacement.
- 11:15Yeah. This is, I'd say the most popular one on macOS. There are others, but yeah, that's what I start
- 11:22with. You mentioned the shell, which is it still bash? Is that still the default one on macOS?
- 11:28Yeah. It's still bash by default. Yeah. Yeah. And I think it's an old version of bash.
- 11:32So yeah, there are other shells out there. The Z shell is quite popular, largely compatible with bash.
- 11:40I've heard good things about fish. Yes. Fish is good. Yeah. Yeah. Which actually it's not really
- 11:47POSIX compliant as they say. So, so it's quite different from what you might get from bash or the
- 11:54Z shell. But from what I've seen, the syntax, especially a looping might appeal to the Python
- 12:01developer out there. It's closer to Python, but I haven't tried it myself.
- 12:06There's also the conch shell. Is that how you say it? X-O-N dot. If you're willing to give up
- 12:13POSIX, then this is like literally Python in the shell. You can just type like import JSON and do a
- 12:19for loop, right? Yeah.
- 12:21I've never, I've not gone this far. I'm still, I'm on the Z shell side of things. I really like how that
- 12:26works. But if you really wanted to embrace the sort of Python in the shell.
- 12:30Exactly. It's this trade-off of how far do you want to go? How much do you, do you want to deviate from
- 12:37what is then considered to be the default, right? Because you mentioned you also work a lot on servers.
- 12:44And there you're then presented with a completely different shell, perhaps, and set of tools.
- 12:50It's a trade-off. And also how much time do you really want to spend customizing this? Because
- 12:56yeah, our time is precious.
- 12:58Yeah. Yeah. And William out in the audience says for the, for the Windows people,
- 13:03ohmyposh, which, have you done stuff with ohmyposh? This is also really nice.
- 13:09So I guess Posh is for the, oh no, any shell. So not just the PowerShell.
- 13:14Yes. This, I think it came out of the PowerShell. So the Posh part, I think it originally was for that,
- 13:20but I use this with Z shell and Oh My ZSH together. And it's basically that controls my prompt and Z,
- 13:28Oh My Z shell is like all the plugins and, you know, complete your Git branches type of thing.
- 13:33But yeah, this, this is really, this is really pretty neat too. Works well for, for Windows people.
- 13:38I'd say then indeed the, the, so if your terminal is one thing where you can get a lot of benefit from
- 13:44customizing your prompt so that it gives you a little bit more information and context of where
- 13:51you are or what your state, in which state your Git repo is in or which virtual environment you're
- 13:57working, that can be helpful too, because that is something that you lose easily when you're working
- 14:03at the command line is, is context.
- 14:05Right. I ran this command and it's not working because actually I forgot to activate the virtual
- 14:10environment. So it doesn't have the dependencies or the environmental variables that I set up in that
- 14:15virtual environment. Right.
- 14:16Exactly.
- 14:16Let me give one more shout out for one other thing while people are thinking about making their,
- 14:21their stuff better is nerd fonts.
- 14:24I'm always eager to learn these things. There is so much out there.
- 14:28So nerd fonts, if you're going to get like, Oh, my posh and some of these other extensions that you
- 14:34want to make your shell better. So many of them depend on having what are called nerd fonts. Because
- 14:40if you look at say on the, Oh, my posh page, there's like these arrows with gaps in them. I mean,
- 14:46what font could possibly have like a Git branch symbol and as these like connecting arrows that have
- 14:53colors and are woven and all that stuff is nerd fonts. So if you're going to try to run them,
- 14:58download and install one of these nerd fonts, and then those will work. Otherwise they're like
- 15:02those, I don't understand Unicode square blocks, you know, like when emojis go bad.
- 15:08Oh, you still got to install individual fonts. Yeah. So, so it's kind of like you take Consolata or
- 15:13something or some other font and it's patched with these additional.
- 15:17Some, yeah, something like that. Yeah. So it does, you only need one, but you have to set your terminal
- 15:23to one of these to make a choice, set it to one of them and then it'll work. But if you don't,
- 15:28then you'll, you'll end up with just like these, these, a lot of these extensions don't work.
- 15:32This portion of Talk Python, I mean, is brought to you by Sentry.
- 15:37How would you like to remove a little stress from your life? Do you worry that users may be
- 15:42encountering errors, slowdowns, or crashes with your app right now? Would you even know it until
- 15:48they sent you that support email? How much better would it be to have the error or performance details
- 15:53immediately sent to you, including the call stack and values of local variables and the active user
- 15:58recorded in the report? With Sentry, this is not only possible, it's simple. In fact, we use Sentry on all
- 16:05the Talk Python web properties. We've actually fixed a bug triggered by a user and had the upgrade ready
- 16:11to roll out as we got the support email. And that was a great email to write back. Hey, we already saw
- 16:16your error and have already rolled out the fix. Imagine their surprise. Surprise and delight your
- 16:22users. Create your Sentry account at talkpython.fm/sentry. And if you sign up with the code
- 16:28Talk Python, all one word, it's good for two free months of Sentry's business plan, which will give
- 16:34you up to 20 times as many monthly events as well as other features. Create better software, delight your
- 16:40users and support the podcast. Visit talkpython.fm/sentry and use the coupon code Talk Python.
- 16:50Yeah. So when it comes to customizing your shell, then if you still want to talk about that.
- 16:55Yeah, yeah, yeah. Let's keep going.
- 16:56Right. One of the things I think everybody does most often is navigating around. So moving from one
- 17:04directory to another. And it can be quite cumbersome to keep on retyping all these long and deeply nested
- 17:11directories. So there are a number of solutions that can help with that. I use FASD. Okay.
- 17:20So that keeps track of what you've been visiting most often, most recently. So it also, I don't think if,
- 17:27I wonder if that one also allows you to set bookmarks. That's what I used to do. I would keep,
- 17:33I would have this set of custom shells, shells functions, which actually made it into a plugin,
- 17:40about nine years ago into OhMyZSH. So if you, if you have OhMyZSH and the jump plugin is still
- 17:46in there. Yeah. That's a, I see. Yep. Yep. So you can just jump around. I see.
- 17:52Yeah. You would say, you would say mark, mark this directory under this alias, although it's not really
- 17:58an alias, but it's like a bookmark. And then you say, okay, jump to this directory. So that really helps.
- 18:04Right. So maybe the source directory for Talk Python, I would just mark it as TP. And I could say on the,
- 18:09on the terminal, I could say J space TP. And it would take me this super long, complex directory,
- 18:15just bam, you're there, right? Exactly. So I like it. Okay. I might need to try this out. And it comes
- 18:20with OhMyZSH? This one? No, this one, it doesn't. It's a separate tool. Okay. I believe.
- 18:25Although it might even be a plugin. By now, I don't even know. It's been, it's been a long time since I
- 18:31installed it, but FASD. That's what you want to look for. Okay. Very, very cool. I have one that I
- 18:38use a lot called McFly. Have you, have you seen McFly? No. So it's similar. And what you do is,
- 18:44you know, if you type control R, it'll give you reverse incremental search or whatever that is.
- 18:49And I'm, so this overrides that. So if you type control R, it brings up an Emacs, like autocomplete
- 18:55type thing that has fuzzy searching. So you could type SSH and then like part of a domain name,
- 19:01and it would find you type SSH, you know, root at some that, that, that, that domain name. And it'll,
- 19:07it'll give you a list of like all these smart options looking through your history.
- 19:10Yeah. Yeah. That's amazing. And even now, as we talk, I've learned like a dozen new things.
- 19:15One thing I have noticed though, is that, you know, you may, the next time you're installing,
- 19:21you're setting up your system, you may feel very productive and, and lead like,
- 19:27right. When you're installing all these tools, but you still got to make use of them, right?
- 19:32Yeah.
- 19:32You got to turn that into some kind of a habit. And what I have noticed for me, at least what works
- 19:38best is to just take it one tool at a time, make a little cheat sheet for yourself on a piece of paper,
- 19:45and just see if that, if you like that tool, if you can, you know, if you get any benefit from it.
- 19:50Yeah, absolutely. So related to this actually is, is the concept of aliases, right? In a more generic
- 19:56sense, in the pure shell sense that you can define an alias that would then be expanded into some command
- 20:04with zero or more arguments. Yeah. So if you have, if you have commands that you would often type like
- 20:11a LS for listing your, your files, and you have all these arguments that you don't want to keep on
- 20:17typing, then aliases is the way to go. I go crazy with aliases. I absolutely love this. Yeah, I have
- 20:24probably 100, 150 aliases in my RC file. Oh, that's nice. Yeah, that's nice. So at some point,
- 20:31I, what you, well, what you may have done is go through, through your history and then see how often
- 20:36you use these aliases. Yeah. That's always a fun thing to do. Yeah. For me, it's kind of frustration.
- 20:42I'm like, God, I want to do this. Or, you know, I've got to remember, I got to type, oh no, I got
- 20:46to go into this directory. And then I got to first type this command, and then I can do this other
- 20:51thing. So for example, we talked about the static site generators. So one of the things I have to do
- 20:56in order to create new content and see how it looks in the browser is I have to go to a certain directory,
- 21:01directory, not where the content is, but a couple up, run Hugo dash D server there, and then it'll
- 21:08auto reload. And as I edit the markdown, it'll just refresh. So instead of always remembering how to find
- 21:14that directory and then go into the right sort of parent directory and run it, I just now just type
- 21:18Hugo right. And that's an alias. And just, it does that. Boom. It just, it just pops open and it's okay.
- 21:23It's, it's running. I do my thing. I'm going to, then I got to do a whole bunch of automation in Python
- 21:28on top of it and then build it and ship it to the Git and push it for a continuous deployment.
- 21:33Now I have just Hugo publish. Boom. And these are all like aliases. The other thing you talked about,
- 21:38a single commands is maybe talk about chaining commands and multiple commands.
- 21:42Yeah. Because you just mentioned automation in Python. And then I, of course, immediately go like,
- 21:47hmm, what's going on there?
- 21:49Yeah. So I've got a couple of, I guess they're go commands because they're Hugo. And then I've got
- 21:56some Python code that generates a tag cloud and then a Git command that'll publish it. So it's like,
- 22:00Hugo, Hugo, Git. No. Hugo, Git. Hugo, Python, Hugo, Git is that all in one alias, right? Which is,
- 22:09is beautiful. Oh, nice.
- 22:10Yeah. It's beautiful. You know, I don't know if we've exactly, I guess I opened a little bit talking
- 22:14about your book, but one of the really core ideas of your book is that the shell can be the integration
- 22:19environment across technologies like Go, Python, and Git.
- 22:24Exactly. Exactly. The command line doesn't care in what language something has been written. It's like a
- 22:31super glue or duct tape, more really, that binds everything together.
- 22:36Yeah.
- 22:37Yeah. To a certain extent, right? Like duct tape.
- 22:40Yeah. Well, it's, it's a, you know, loosely bound, but it's, there's a ton of flexibility in there. And
- 22:45if you think, well, I really just want to do these four things, maybe that would be a macro in Excel,
- 22:50or some kind of like scripting replay in Windows. But this is, it's on the terminal programs can run
- 22:58it. You can run it. It's clearly editable. It's not some weird specific type of macro, right? You're
- 23:03like, I want to do these four things. I just type thing and go, I'm sure many people know,
- 23:07but if you have multiple commands, you want to run one than the other, you can just say
- 23:10ampersand, ampersand between them. And it'll say, run this first thing, then run the other.
- 23:14Those are independent. You can also pipe inputs and outputs between them. Right. I see that.
- 23:19That's correct.
- 23:20You've got some really interesting ways to do that multi-line stuff in your book as well.
- 23:24Yeah. Well, yeah. So it depends on what kind of tools you want to combine, right? So you,
- 23:29you just mentioned a double ampersand. So that should be used when you only want to run the
- 23:35second command when the first one has succeeded, right? If you want to run the second one, regardless
- 23:41of what the first one did, you can just use a semi-column. Or if you only want to run the second
- 23:46command when the first one failed, there might be a situation where you want to do that. You can use
- 23:52double pipe. So for four. Interesting. Okay. And then, yeah. And then you just mentioned piping
- 23:59and that's, well, a whole nother story. That's when you want to use the output from the first command
- 24:07as input to the second command. And this is where, or data again, comes into play. And this is, so you just
- 24:15also mentioned macros, right? Another way to think of them are our functions that you then combine.
- 24:23Yeah. Incredibly powerful, but that goes a little bit beyond then of course you should be working with
- 24:29commands that produce some text that you want to then further work on. Yeah. You also talk about
- 24:36creating bash scripts, which is pretty interesting. I think many people probably know about that or shell
- 24:40scripts, .sh files. I guess it could be zshell scripts as well. Yeah. So you gave an interesting
- 24:46presentation back at the Strata conference and you had a lot of fun ideas that I think are relevant
- 24:53here. So maybe let me just throw out some one-liners and you could maybe riff on that a little bit.
- 24:57Okay. Yeah. Yeah. Sure. One of the reasons you said you gave 50 reasons that the shell was awesome.
- 25:02And I want to just point out a couple, highlight a couple, let you speak to them. So you said the
- 25:07shell is like a REPL that lets you just play with your data. We know the REPL from Python and also
- 25:13from Jupyter, but I never really thought of the shell as a REPL, but it kind of is, right?
- 25:16Yeah. I think that the shell is the mother of all REPLs. The read, eval, print loop.
- 25:22Yep. Right? Having this short feedback loop of doing things and seeing output and then elaborating on
- 25:29that I think that is tremendously valuable. And Python users, of course, may recognize this from
- 25:36Python itself, right? If you just execute Python, you get a REPL, IPython or Jupyter console. And to a
- 25:42certain extent also, Jupyter notebook or JupyterLab is there are some similarities there where you again,
- 25:49have this quick feedback loop. And it's a very different experience from writing a script from top to
- 25:54bottom or starting at the top and then executing that script from the start every time you want to test
- 26:01something. So yeah, it's a different work, different way of working. And I'm not saying one is better than
- 26:07the other. But what I do want to say is that there are situations where having such a tight feedback loop can
- 26:14be very efficient. Yeah. Especially in the exploration stage, right? Yeah, exactly. Once you go to production,
- 26:21right? Once you whatever that means, right? Once you want things to be a bit more stable,
- 26:26you don't want to just use duct tape, but you want to use a proper construction. Then, then yeah,
- 26:34then, of course, the command line can have different roles there. Yeah. Yeah. But it's kind of the,
- 26:39the, the rad GUI, the rapid application development GUI, but for data exploration, right? These,
- 26:45these REPLs and you know, that's, that's probably why Jupyter is so popular. It just lets you play and see and
- 26:50then try. And it just was that, that quick feedback loop is amazing. Another reason said,
- 26:54it's awesome. Close to the file system. Yeah. I mean, in the end, it's all files,
- 26:57right? Whether you're producing code that lives somewhere, it's in a file, or whether you're working
- 27:03with images or log files that get written to something, or you have some configuration, it's all
- 27:09files. And we got to do things with these files. We have to move them around. We have to rename them,
- 27:15delete them, put them into Git. Yeah. So you want to be close to your file system. You don't want to be
- 27:22importing a whole bunch of libraries before you can start doing things with these files.
- 27:28Also, when you're doing data science, often it starts with this kind of ingest and understanding
- 27:34files, right? CSV or text or others. Yeah. I mean, I sometimes try to immediately do read CSV in Pandas,
- 27:44but then, you know, very often I get presented, I get some Unicode error, or it turns out it's the comma
- 27:52is not the file, is not the limiter being used. And yeah, you can do that in a sort of trial and error
- 27:59way. You can fix that. But it really helps to just being able to look at a file as it is, no parsing,
- 28:06just boom, there's my file. And then, yep, once you're comfortable, once you're confident, like,
- 28:12okay, this is what my file looks like. This is its structure. Then of course, you can always move on
- 28:18to using some other package like Pandas. Okay. Another one that you've said,
- 28:23another recommendation you had or sort of way for playing with this was to use Docker. I don't know
- 28:29how many people out there who haven't done this for are really familiar, but basically when you start
- 28:34up a Docker image, you might say dash it bash or ZSH. And what you get is just you get a basic shell
- 28:41inside the Docker container. But in that space, then you can kind of go crazy and do whatever you want
- 28:46to the shell and try it out, right? Exactly. Yeah. So there are two scenarios that I can think of. So
- 28:52when you're just starting out with the command line, it's a very intimidating environment. And it's quite
- 28:57easy to wreck your system if you're not careful. So being inside an isolated environment that
- 29:04is sort of shielded off your host operating system can be comforting. So that's one recommendation
- 29:11that I would say that why I think you should use Docker. And the other one is reproducibility. Also in
- 29:17Python, right, we're dealing with packages that get updated, that get different version numbers,
- 29:23where APIs change. And being able to reproduce a certain environment so that you get consistent results
- 29:33is also very valuable. Yeah. And I'd like to sort of highlight the converse as well. You said playing
- 29:40with Docker containers is a cool way to experiment with the shell. If you care about Docker containers,
- 29:45you need to know the shell to do things to it. Because you might think, oh, I'm just going to make a Docker
- 29:49file. I don't need to know the shell. Like what goes in the Docker file, a whole bunch of commands that
- 29:54many of them look like exactly what you would run on the shell. You just put it in a certain location
- 30:00or as a command argument to some configuration thing in there. And so you really, if you're going to do
- 30:05things with containers, the way you speak to them is mostly through shell-like commands.
- 30:10This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 30:18Starting a business is hard. By some estimates, over 90% of startups will go out of business in just their first
- 30:24year. With that in mind, Microsoft for Startups set out to understand what startups need to be successful and to
- 30:31create a digital platform to help them overcome those challenges. Microsoft for Startups Founders Hub was born.
- 30:37Founders Hub provides all founders at any stage with free resources to solve their startup challenges.
- 30:44The platform provides technology benefits, access to expert guidance and skilled resources, mentorship and networking
- 30:50connections, and much more. Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be
- 30:58investor-backed or third-party validated to participate. Founders Hub is truly open to all.
- 31:04So what do you get if you join them? You speed up your development with free access to GitHub and Microsoft
- 31:10cloud computing resources and the ability to unlock more credits over time. To help your startup innovate,
- 31:16Founders Hub is partnering with innovative companies like OpenAI, a global leader in AI research and development,
- 31:22to provide exclusive benefits and discounts. Through Microsoft for Startups Founders Hub,
- 31:27Founders Hub is no longer about who you know. You'll have access to their mentorship network,
- 31:31giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation,
- 31:38fundraising, management and coaching, sales and marketing, as well as specific technical stress points.
- 31:43You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders themselves.
- 31:48So one of the cool tools that you had in that presentation was you talked about explainshell.com.
- 32:12Yeah. What is this?
- 32:13Well, you can try out. So what you see here on the screen is explainshell.com and it will break down
- 32:21a long command and start explaining. So it will, it will, what I think the authors have done is they have
- 32:30used all these manual pages and extracted bits and pieces that they then present to you in a, in an order
- 32:37that corresponds to the command that you're pasting into this. So if you see, you know, on Stack Overflow,
- 32:42you see this, this incantation and you're like, all right, what does it mean? And you don't want to go through the manual page yourself.
- 32:50Right. Okay. So what's, what does dash F mean? What is this X, Z, V, F for the tar command mean?
- 32:58Then explainshell can do this trick for you.
- 33:00Yeah. It's amazing. When I first thought, I thought, okay, well this, what this is going to be is this
- 33:04is going to be like the man page. So if you type LS, it'll show you a simple list directory contents and
- 33:10you click on it, it'll give you additional arguments you can pass. But you could then say, like you said,
- 33:16you could say dash L and it'll say the LS means list contents. The L means use the long listing format.
- 33:22And you're like, oh, okay, hold on. What if I said, get, get checkout main. And you'll say, okay,
- 33:28well get checkout does this. And then main it'll actually parse it apart. And there's some really
- 33:33wild examples on here that like right on the page that are highlighted on the homepage of that site.
- 33:39You click it and boom, it gives you this cool graph of like, what the heck? It even shows like
- 33:44the ampersand at the double ampersand and the double or combining, as you mentioned before.
- 33:49Yeah, it is. It is. It's really useful, especially when you're just, you know,
- 33:55getting started with the command line and you're overwhelmed, like we all are in the beginning,
- 33:59and sometimes still are then, you know, adding adding some context like this really helps.
- 34:04I once wrote a utility that allowed you to use explain shell.com from the command line. So you would
- 34:10just, you wouldn't leave the command line. I don't think it works any longer. But yeah, that was a fun
- 34:16exercise. Yeah. Oh, yeah. Very neat. One of the things that I learned was parallel.
- 34:23Oh, yeah. So tell us about parallel. Like this is a command you can run on the terminal. And it
- 34:30sounds like it does stuff in parallel. That sounds amazing.
- 34:32Yeah. Yeah. Like the name implies parallel is a tool. And we're talking about GNU parallel here.
- 34:37There's another version out there that is similar, but different. GNU parallel, this tool that doesn't
- 34:44doesn't do anything by itself, but it multiplies. It's a force multiplier for all the other tools.
- 34:50So what this tool is able to do is will parallelize your pipeline. It will be able to run jobs on
- 35:00multiple cores and even distribute them to other machines if you have those available. Right. So,
- 35:07Michael, you mentioned you're working on a server. Well, if you can SSH into other servers as well,
- 35:15you can leverage those. That's something that GNU parallel can do. The way it works is that you feed
- 35:20it a list of something. Could be a list of file names. Could be a list of URLs. Could be your log files.
- 35:27If you can then think of the problem that you want to solve. If you can break it down into smaller chunks,
- 35:34then GNU parallel might be able to help you out there. So these jobs should be working independently
- 35:41from each other. Yeah. There can be, yeah, it's nearly impossible to have those two jobs communicate
- 35:47with each other. But let's say you have for your blog, right? In Hugo, you have a whole bunch of
- 35:53ping files that you want to convert to to JPEGs. WebP or something. Yeah, sure. Yeah. I mean,
- 35:58it's a bad example because this particular tool that I would then use already supports doing multiple
- 36:04files. But let's just assume that this tool can only handle one file at a time. Yeah. Then you would
- 36:11specify your command and then at certain places where necessary use placeholders. Yeah. So,
- 36:17okay, this is where the file name goes and this is the file where the file name goes with a new
- 36:21extension. So it's one of my favorite tools really. Yeah. That's fantastic. So for example, if you had
- 36:27a bunch of web pages and you wanted to compute the sentiment analysis, right, as a data scientist,
- 36:32you want to download it, compute the sentiment analysis, and then save that to a CSV or pin it to a CSV.
- 36:38Yeah. You know, maybe somebody gave you that script and it's only written to talk to one thing and you
- 36:43don't want to rewrite it or touch it or get involved with it, right? This is your way to unlock the
- 36:48parallel of something, right? Yeah. In fact, let's talk a little bit more about this because I think
- 36:52this is an important point in that I'm sure that we've all come across when we're working in Python
- 36:57and you're thinking like, okay, I can speed this up. I want to do things in parallel. You know what?
- 37:03I'm going to do multi-threading or what is it that you use these days in Python?
- 37:08Yeah. Async and await maybe if it's I/O or something like that. Yeah.
- 37:11You've got your pool of workers or I don't know. Basically, you're programming it yourself from the
- 37:16ground up. Right. Multi-processing potentially.
- 37:18Probably the closest. Right. Right. Right. Right. Right.
- 37:21The trick then is to realize that there is already a tool out there that can do that for you. All that you
- 37:27need to do is make sure that your Python code becomes a command line tool. Yeah.
- 37:33And we can talk a little bit more about that, but there are just five, six steps needed to make that
- 37:38happen. Once you realize that, then you can start turning existing Python code into command line tools
- 37:44and start combining it with all the other tools that are already available, including parallel.
- 37:49Yeah. It's awesome. I think it's a really cool idea because maybe the person working with the code
- 37:55doesn't understand multi-processing and thread synchronization and all these tricky concepts.
- 38:01Like, just give me a thing that does it once with command line arguments and I got it.
- 38:05it. You know, like you, or you've, you picked it up from somewhere out in the audience. The question
- 38:10is, is there a GIL associated with this? And I mean, technically yes, but it's not interfering with the
- 38:16computation because it's multiple processes. It's not threads within a process. Right. So it should be
- 38:21able to just run. Yeah. There will be one GIL per Python process. Right. Yeah. That's right. And so it
- 38:28doesn't matter because if you say there's five jobs, you have five processes, right? There's no contention there.
- 38:33Yeah. Yeah, absolutely. All right. Oh, so yeah. Let's talk a little bit about this idea of turning Python
- 38:40scripts into command line tools. Yeah. I think that that's really valuable for people. It is. And
- 38:45we can then put it in the show notes. I might have already given a talk about this. I'm actually not
- 38:51sure if it's publicly available. Anyway, there are only a couple of steps and it's not that difficult.
- 38:58So first of all, let's assume that you have some Python code out there. Yeah. You have it in a
- 39:03file and let's just for simplicity's sake, assume it's a single file. Right. So what would you then
- 39:10need to do to turn this into a command line tool, something that can be run on the command line. So
- 39:16the way that you can currently run this is by saying, okay, Python, and then the name of the file,
- 39:21right? That doesn't really sound like it's a command line tool. So the very first thing here then is to
- 39:28add one line at the very top that would then start with a hash and an exclamation mark or a
- 39:35hash bang or a shebang as it's called. These are two special characters and they instruct the shell.
- 39:43This can be executed. What is the binary that's going to do the executing? Right. Yeah.
- 39:47Executing. Right. Yeah. Exactly. That's what then would come after that. So you would have hash bang,
- 39:53and then it would point to the Python executable. Yeah. Right. There's some details there.
- 39:58It could be a certain version. It could be out of a virtual environment, potentially. And I think it
- 40:02could go wherever, right? You don't want to overcomplicate it probably, but like you could point
- 40:06to, you could point to different versions of Python. You could point, because you, you give it a full path to
- 40:11executable. Exactly. Exactly. There's some, there's some compatibility issues there, but essentially is
- 40:17you tell your shell, okay, which program should interpret my code. And that is some Python out
- 40:23there that you have installed. So that's the first step. Then after you've done this, you no longer
- 40:29need to type Python anymore because the file itself contains which executable should be, should be run.
- 40:36But then you'll notice that you don't have the necessary permissions. What you need to do is you
- 40:40need to enable the execution bit. This would give you as the user permission to actually execute this file.
- 40:48You do that, of course, with a command line tool. It's called SHMOD, C-H-M-O-D for change mode. And then
- 40:56U plus X, the name of the file, right? These details are, if you're really interested, one place where you can
- 41:01find them is in chapter four of my book, data science at the command line, which you can read for free.
- 41:06Okay. But let's say that you've enabled these, the execution bit. Now you can,
- 41:11now you can run it. You would still need to type period and a slash because this file is presumably
- 41:20not yet on your search path. So your search path is a, is a list of directories where your shell will be
- 41:27looking for the executable that you want to run. Where is your tool located? Well, it should be
- 41:32somewhere on the search path. So either you add another path to the search path or you move the tool
- 41:39to one of the existing directories out there. That's about it for making your code executable. But then you
- 41:46want to change one or two things about the code itself. Yeah. So one thing to do is look for any
- 41:53hard coded values that you actually want to be, want to make dynamic, right? These should be turned
- 42:01into command line arguments. And actually you can take that one step further. If one portion of your file
- 42:07is doing something that can be done by another command line tool, then consider removing that. For example,
- 42:14downloading a file. Yeah. There is of course a tool for that on the command line. Why would you then
- 42:20write this yourself? Of course, there's a time and a place for that, but let's say, okay, a very
- 42:25contrived example is a Python program that would count words. Yeah. Right. Right. If your code has some
- 42:33hard coded website. Yeah. I mean, why you would make your tool more generic by getting rid of that hard
- 42:39code URL and we'll turn it into a command line argument. Okay. Which website would you like to
- 42:44download or to go one step further is to think, okay, you know what? I don't really care where the
- 42:50text is coming from. I just want to count words. Give me text somehow. Yeah. Sorry. Just give me the
- 42:56text. Don't tell me the URL. Yeah. So your tool should then be reading from standard input, which is a special
- 43:03channel from which you can receive data. And this is also where the piping would come in. Yeah. So you
- 43:09would first use a tool that would get this text, right? Maybe it's some log file. So you want to count
- 43:15your errors or it's another website and you want to do stuff to that. It doesn't really matter, but you
- 43:22would then that would write to its standard output. Yeah. And you would combine the standard output from
- 43:28the first tool with your standard input using the pipe operator. So that's then basically it for,
- 43:34I mean, of course, if you want to take this further, you can think about, you know, adding some help,
- 43:40some nice looking help. Yeah. Think about the arguments themselves. Do you want to use short options or long
- 43:46options? Exactly. Right. So something like Typer or Click or one of these formal CLI frameworks. Yeah.
- 43:53Probably really. Python, of course, has ArgParse, but there are packages out there that can really help
- 44:00you build beautiful command line tools. Typer is one of them. I'm currently using Click. Also,
- 44:07Click combination with Rich. Mm-hmm . So of course, the author of Rich was on the show a couple of episodes ago.
- 44:15Yeah. Will McGoogan. Very good stuff. Yeah. Why we're talking about that? You know,
- 44:20the other thing that's really pretty interesting is the Rich CLI. Have you played with Rich CLI?
- 44:25Which, oh, oh yeah. Okay. So that's indeed a command line tool in itself that can do a whole bunch of
- 44:31things. Yeah. You want to tell us something about that? No, I haven't done much with it,
- 44:34but you can do things like if you install the Rich CLI, then you can say things, there's lots of ways to
- 44:41install it. You could say like Rich and then a Python file or a JavaScript file or a JSON file,
- 44:46and it'll give you pretty printed color, you know, syntax highlighted printout. You can say,
- 44:51Rich, some CSV file, and it'll give you a formatted table inside your terminal with colors and everything
- 44:57of it understands markdown and like renders markdown. And there's all sorts. So if you're kind of
- 45:03exploring files and you're happy with Python things and like installing the Rich CLI is a pretty neat way
- 45:09to go as well. Yeah. It's a nifty tool, but just not to get confused. So this tool is provided by Rich
- 45:16and it uses Rich to produce, you know, nice looking output. But just imagine that you can write your own
- 45:22command line tools that would also produce this nice looking output. And for that, you can then use
- 45:28this package called Rich. Right. In combination, perhaps with things like Typer or Click. And
- 45:34DocOpt is another way you can go. There are so many tools out there. Yeah, there absolutely are. One other
- 45:42thing I would like to point out that, so just taking the script and making it executable and put it in the
- 45:47path, that's kind of a great way to take scripts that you have and make them CLI commands for you.
- 45:54If you want to like formalize this a little bit more, I recently ran across this project called
- 45:59the Twitter Archive Parser. And I don't know if you've noticed, but there's a lot of turmoil at Twitter.
- 46:04And so what you can do is you go to Twitter and download your entire history of like thousands of
- 46:10tweets or whatever as HTML file and some JSON files, and you can save them for yourself.
- 46:16But the content of like all of the links are the shortened to.co Twitter short links. And if
- 46:25Twitter were to go away, you'd have no idea what any of your links you've ever mentioned ever were.
- 46:29And also the images that you get are the low res images, and you can get the high res images if you
- 46:34know how to download them. So this guy, Tim Hutton created this really cool utility that you can
- 46:39down, you can take that downloaded archive and upgrade it to standalone with high res images and full
- 46:45full resolved links, not shortened links. Pretty cool, right? But if you look at the way to like,
- 46:50how do you use it? Okay, where does it say this? Not sure where it is. Yeah. So how do I use it? I
- 46:55download my Twitter archive and unzip it fine. And then I download the Python file to the working
- 47:01directory. And then I go in there and I type Python that file. Wouldn't it be better if I could just,
- 47:08you know, it has dependencies that has to install in order for it to run? Wouldn't it be better if I
- 47:12could just use this as a command? So what I did is I forked this. And I said, I'm going to add a
- 47:17pyproject.toml to turn this into a package. And then under the pyproject.toml, you say project.scripts,
- 47:25Twitter archive markdown, Twitter archive images, and you, you map into your package and then functions
- 47:30that you want to call. And then once you pip install this, these commands become just CLI commands.
- 47:36And it doesn't matter how that happened long as your Python packages are in the path, which they
- 47:41generally have to be anyway, because you want to do things like pytest and black, then if you just
- 47:45pip install this project, it adopts all these commands here, which is pretty cool. Nice. Is it
- 47:50then necessary to add this bin directory once to your search path? Because it lives, it would live
- 47:58somewhere on their site packages, right? Yes, exactly. And so if you have a Python installation and you try
- 48:04to pip install something, you'll get a warning that the site packages are not in the path. So you do have
- 48:08to do that. And then go one further, you could do pip x. I don't know if you played with pip x. pip x is
- 48:15awesome. So it'll generate the package environments and install the dependencies in an isolated
- 48:20environment. And it'll set up the path if you just say ensure path. Then so if you pip x install the
- 48:24thing with the commands in it, those automatically get managed and upgraded by pip x as just part of
- 48:31your CLI, which like that's a perfect chain of like a four, but you've got to have a formal package
- 48:36and like a place to install it from like get or pipe I or whatever. But it's still, it's still a,
- 48:41like a neat pro level type of thing. I think. Yeah. Yeah. You can take this pretty far,
- 48:45make it really professional. And before you know it, you start maintaining it for.
- 48:50Yeah, exactly. Why am I doing PRs on this silly thing? I don't know.
- 48:54Yeah. But just to clarify, if you say for a one off or a two off, you want to make something that is
- 49:01reproducible, right? So a reusable command line tool, not reproducible, reusable. You don't really need
- 49:07any other packages. You can use a sys.argv, right? You import sys and then you have your sys.argv.
- 49:15And I do that. I do that a fair amount of times. Yeah. It's only for me, I've created an alias. So
- 49:21it always gets the right argument. There's like, there's no ambiguity. Sys.argv bracket one, let's go.
- 49:26Exactly. Yeah. Yeah. We've talked a lot about sort of around all the cool things we can do with
- 49:31the command line. But in your book, you actually talked about a bunch of surprising tools. So like,
- 49:37one of the things you talked about is obtaining data and you hinted at this before, like you can
- 49:41just use curl for downloading those kinds of things. But if you get a little bit farther,
- 49:46like under scrubbing data, you talk about grec, rep, and awk that a lot of people maybe know.
- 49:52But then if we go a tad further over to say exploring data, then all of a sudden you can
- 49:57type things like head of some CSV file and it kind of does the same thing as Jupyter. Or there's things
- 50:05like CSV cut and SQL, CSV, CSV, SQL. Talk about some of these maybe more direct data science tools that
- 50:13people can use. Right. So let's see then where to begin. You mentioned a couple of tools, right?
- 50:20The head and awk and grep. Those are, you know, I would consider them the classic command line tools,
- 50:28right? I would too. Part of core utils, GNU core utils, right? You can, if you have a fresh install,
- 50:35then you can expect those tools to be present. Yeah. If you're not on Windows. So those tools,
- 50:42they operate on text, on plain text, and they have no notion of any other structure that might be
- 50:49present in this data. Say CSV for when you have some rectangular structure or JSON, when you can have
- 50:57a potentially deeply nested data structure. These tools know nothing about that. That doesn't make
- 51:02them entirely useless, right? There are ways to work around them, around that issue. But there are nowadays
- 51:10plenty of tools available that are able to work with this structure. Right. And one of them is actually a
- 51:18suite of tools. It's called CSV kit. And you can install it as a Python package. Okay. Through pip,
- 51:25which of course we do at the command line. CSV kit, you say? Yeah, exactly. And then you get a whole bunch of
- 51:33tools that understand that lines are rows. The first line is a header and all these fields are delimited
- 51:42by default by a comma. And then you can do things like extract columns or sort a file according to a
- 51:50certain column. Yeah. So this is more difficult for when you're working with core data utils. And of course,
- 51:57all of these things you can do in Pandas, and it might even be faster in Pandas as opposed to these
- 52:05CSV tools, not as opposed to the classic command line tools. But I mean, in order to get started with
- 52:14Pandas, right, just imagine that you're given this file by your colleague and you're asked to quickly
- 52:21to sum things together, right? And in order to just get started with Pandas, what are then the things
- 52:26that you need to do? Yeah, fire up JupyterLab, import Pandas, and maybe a bunch of other things. There is,
- 52:33of course, also a time and a place for that. Definitely, definitely. I always use the tool that gets
- 52:39the job done. Don't get me wrong here. But it's just so incredibly powerful to just, if it solves the job,
- 52:45just whip up a command on the command line using a couple of tools there. If you're going that route,
- 52:53then CSV kit is not the only suite of tools that you should know about. XSV written in Rust, but yeah,
- 53:01you shouldn't care about that because the command line doesn't care. It's generally faster. One thing
- 53:06that CSV kit can do, by the way, and I'm actually kind of proud that I have been able to contribute
- 53:12that tool to the suite of tools is CSV SQL. And it allows you to run a SQL query directly on the CSV file.
- 53:22Yeah. So if you are familiar with the SQL, then you can leverage that knowledge directly at the command
- 53:30line without first having to create a new database and import that CSV file in there and so forth.
- 53:35All right. So one of the things you can do on the command line is basically just give it,
- 53:39like, here's a SQLite file database, and now go insert all the things from the CSV file into it.
- 53:47Here in this example, it has this create table statement. Does it figure that out from the CSV,
- 53:52or do you need to write that? It figures it out. Yeah. It does some,
- 53:55it looks at the first, say, a thousand rows and then figure out like, okay, this is a number. This is text.
- 54:02I see. Yeah. Oh, cool.
- 54:04But I was actually talking about the other tool and that's SQL to CSV. I always mix those up.
- 54:11The reverse. Yeah.
- 54:11Yeah. Yes, exactly. This one. And there it still uses SQLite under the hood,
- 54:17but you don't need to worry about that. It takes care of the, of all that boilerplate for you.
- 54:21You just say, okay, you know, select these columns from standard input, order them by this column. This
- 54:28is the file or I've piped. Yeah. That's cool. Yeah. It's pretty cool. Yeah. I mean, maybe you've got
- 54:34like some production database and you want to filter out. I just need this table with this particular
- 54:40query, right? It's like, I only want to focus on my region of this data, give it to me as a CSV file,
- 54:46and then you can go work on it all you want. You don't have to be connected to the database or near it
- 54:52or any of those things, right? Potentially, if it doesn't have any sensitive data, you could share that,
- 54:56right? You would never share the connection string to your database. That'd be insane.
- 55:00Yeah. Yeah, exactly. Okay. Very cool. So what are some of the other tools? Well, if we go back,
- 55:06if I go back to the CSV kit, you can see there's some of these you talked about. There's into CSV.
- 55:14That one takes an Excel, XSL or XSLX and converts it to a CSV just on the command prompt or the terminal,
- 55:21right? Yep. Yeah. Okay. Also, I should point out that I'm not the author of CSV kit,
- 55:27right? I just contributed a small portion to it because of the ingredients that were already there.
- 55:33Still proud of it though, but it's being created by many other people.
- 55:39Sure. Of course. Some other things it has is like, CSV stat and CSV rep. Yeah. A lot of,
- 55:46a lot of cool command line options to point at these things, right? Let's see. I pulled out, some others.
- 55:53Rush. So one of the areas that they, the graph, the basically plotting to do, we're basically out of
- 55:59time, but I want to, I want to talk about two things really quick. Right. The, some of this,
- 56:03which chapter did you put it under where you have the pictures? Oops. seven. So seven,
- 56:09visualizing, exploring data and then yeah. So if you, so tell us a little bit about this,
- 56:15like you can plot stuff in your terminal. Yeah. Yeah. It's kind of crazy. I should say that rush
- 56:21is a proof of concept, right? It's one of those projects that have a lot of potential, but don't
- 56:28necessarily have enough users. And I don't necessarily have enough time to maintain it properly, but it does
- 56:35prove the concept rush the name. I mean, it's for when you're in a rush, it's R on the shell and,
- 56:43what it does, it, it leverages R under the hood and, for plotting, it leverages a particular R package,
- 56:51uh, GG plot two, which is the data visualization package for when you're working with R. Yeah.
- 56:57Kind of the sibling or where Matt plot lib is a little bit derived from that, I believe. Right.
- 57:03Well, well, well, now you're mentioning that actually map, it is very different. It's a map
- 57:10out. It is very low level and gives you a lot of flexibility, but also requires a lot of work.
- 57:15Now, if you're, if you want to visualize data in Python in a similar way that GG plot uses,
- 57:22then I can recommend plot mine. So that's a Python package that is, modeled after GG plot to API,
- 57:31but, that was a little bit, a little segue there. Now somebody else created a backend for
- 57:40GG plot that allows you to create visualizations on the command line. What I then did was create this
- 57:47interface. So something that would translate arguments and their values to the appropriate
- 57:54function call. And also does a lot of border plate when it comes to reading in the CSV file that you
- 57:59provide, right? If you were to do this in R itself, it would require, let's say about five lines of code
- 58:08in order to get started. Right. And then the same also for Python, right? So similar concept, right?
- 58:14import the appropriate packages or modules, reading in some file and there's all this setup. And you know,
- 58:21again, that is probably what you want when you want things to be a little bit more robust, but when you
- 58:26want to get stuff done quickly, yeah, it really helps to be able to do that as a one liner on a command line.
- 58:32So I make use of all this, yeah, elaborate machinery, you know, in R just to, use that at the command line.
- 58:44So a beautiful little wrapper around this complex thing, but it hides the complex complexity, right?
- 58:50Exactly. Exactly.
- 58:51Yeah. So you can do beautiful, like bar plots. There's a lot of neat stuff in here. I really like this.
- 58:57It is really nice. And, now that I see this again, I get excited again. There is
- 59:04definitely potential there, but you know, it's, it's again, yet another open source project that has to be,
- 59:10uh, maintained. And unfortunately my time is limited like, like everybody else's.
- 59:17Yeah, of course. Of course. Yeah. All right. The last, last thing we have time for is this
- 59:21polyglot data science. Tell us a little bit about this. Yeah. So polyglot data science is the idea
- 59:27that in order to get things done, you might need to use multiple tools, multiple languages really. And,
- 59:36throughout the book up until then, up until that chapter, we have mainly been focusing on using other
- 59:44languages from the command line, but this chapter considers the other way around, right? Using the
- 59:50command line from another language. So there might've been a situation where you're working in Python and
- 59:57then all of a sudden like, ah, now I got to do this, this regular expression, or I got to do some globing
- 1:00:03and, or I got to call, I have to call this, this other tool that is not written in Python, but can be
- 1:00:10called from the command line, right? You would maybe use sub process, sub process module for that. These are
- 1:00:16situations where you want to leverage the command line, where you want to break out of Python and do parts of
- 1:00:23your computation on the command line. And in that chapter, chapter 10, I demonstrate this not only for
- 1:00:31Python itself, but also in other languages and tools, including Jupyter lab, where you can pass around,
- 1:00:38say a variable as standard input or, and also retrieve the output then so that you can continue working in
- 1:00:46Python again with the output. So, and, what is still very interesting to me is that even new
- 1:00:54languages and tools somehow still offer a way to leverage the command line. So Spark, Apache Spark,
- 1:01:03has a pipe method where you can pass an entire dataset, right? RDD through a command line tool. And that,
- 1:01:12I think that is just, it is, maybe it was just a fun little hack what the authors did. I don't know.
- 1:01:18I tried to, to view it as a, as a compliment, like, okay, some, sometimes we just need to go back to the
- 1:01:25basics and, and use the command line because once you're there, you're back in this environment where
- 1:01:31you can use everything else. So everything we've spoken about so far is now accessible as a command,
- 1:01:36be it go or Python or your own script or whatever. Exactly. So let's say,
- 1:01:41you've written this, you've come across this really nice tool, but it's written in Ruby. Oh no. What
- 1:01:48you're gonna, what are you gonna do? Are you gonna all of a sudden become, you know, involved into Ruby?
- 1:01:54No. Assuming that this tool can be used from the command line, you can of course, relax, just use the
- 1:01:59sub process module and still you incorporate that Ruby tool into your own script. That's the idea.
- 1:02:06Yeah. I do want to maybe point out just really quickly here, like this has got a little bit of a,
- 1:02:12a little Bobby tables warning asterisk by it, you know?
- 1:02:15Yeah. Yeah. Yeah. Right. So for example, one of the things that's awesome here is I could run
- 1:02:20Jupyter console as you show. And then if you say exclamation mark command that pumps it straight to
- 1:02:25the shell. So you could say bang date, and it would tell you the day you go a bang pip install --upgrade
- 1:02:31request and that'll go and execute that command. Don't do that with user input. Right? Who knows
- 1:02:37what they're going to do. You can also do that within Jupyter notebooks you point out, right? So you can do,
- 1:02:43what is it? Percent percent bash and then some interesting complicated thing there, right?
- 1:02:49That's pretty. Yeah. Yeah. That's indeed the magic command that you can use in, in Jupyter notebook.
- 1:02:55Right. And then higher cell is bash. Yeah. And so then you take what's left of that and then you head
- 1:03:00over to explain shell and figure out what the heck it means. Yeah. Maybe do that before you run it. Yeah.
- 1:03:07Yeah. That's a good idea. And then also in, in Python using sub process is something that I've done
- 1:03:14several times. I need to automate generating some big import of say 150 video files across a bunch of
- 1:03:22directories to build a course that we're going to offer. Well, and to the database I have to put,
- 1:03:26how long is each one of those? I have no idea how to get the duration out of an MP4 or MOV file.
- 1:03:33You know what? There's a really cool command line program I can run. It'll tell me. So I just use
- 1:03:38sub process and call that. And then I can script out the rest in Python and it's, you know,
- 1:03:42sub process is not to be underestimated. I think. Yeah. Yeah, exactly. No, it makes a lot of sense. I mean,
- 1:03:48at a certain point, shell scripts can get a little bit too hairy to work with being able to automate
- 1:03:54your things and use Python as your super glue, right? So a little bit stronger than duct tape,
- 1:04:01I think makes a lot of sense. Yeah. We talked to the beginning about how
- 1:04:04you're in this exploration stage and you just want to just run a bunch of stuff on the command line and
- 1:04:08figure it out. But when you go to production and you said, whatever that means, like this could be one
- 1:04:12of one thing that it means we're going to write formal Python code and then use sub process to
- 1:04:17kind of bring in some of this functionality potentially. Yeah, exactly. I mean, the command
- 1:04:22line is by definition, very ad hoc in nature. Still, if you're doing things in production, meaning you're
- 1:04:29interacting with, with other environments, with, with the servers, or you have some kind of continuous
- 1:04:34integration going on, there are these places, these are places where the command line keeps popping up.
- 1:04:41Yeah. Right. So even there, so it is useful to at least be comfortable with this stark and unforgiving
- 1:04:49environment. I think it's really excellent. I think there's a lot of cool stuff that we talked about. I
- 1:04:54think there's a lot of, a lot of value for people to learn this. I guess, you know, maybe we close this
- 1:04:59out with just one comment that I remember from your Strata presentation. You said the command line is
- 1:05:05like wine. Maybe it takes a while to appreciate, but it gets better with age. I certainly, my first
- 1:05:12experience was like, okay, I'm going to go from windows and Mac dev development over to setting up and
- 1:05:17running servers over SSH. It was like, I am beyond lost. I have no idea even like just how to get started,
- 1:05:24right? Many years ago. And, and now it's like, well, of course that's a beautiful way. And it just,
- 1:05:28just you slowly build up these, these skills and it's, it's really lovely.
- 1:05:32Yeah, it is. No, it took me a long time to get comfortable with the command line actually,
- 1:05:36or Linux in a more generic sense. I, for the longest time I was running windows and Linux in a,
- 1:05:43in a dual boot machine. And so I just couldn't make the jump. And this was, over 10 years ago,
- 1:05:50but, no, it didn't definitely didn't come overnight and I wasn't born with it. So I also believe that
- 1:05:56everybody is able to, to embrace the command line, if you will, but you just gotta, you know,
- 1:06:02make yourself a little bit comfortable there as well. We talked about that in the beginning,
- 1:06:05right? The right terminal, the right aliases can get you a long way.
- 1:06:09They get you so far and tools like Oh, my Z shell and some of these others, the fast that will help
- 1:06:16you remember the thing you needed to type or, or like you said, aliases and kind of bring it all
- 1:06:21together. And like, ah, I know I did that thing. Let me just do a quick search for, yeah, there it is.
- 1:06:25Five, you know, five weeks ago I ran this and that's how I, this is how I restart the web server. Oh yeah.
- 1:06:29Now I remember. Yeah. Yeah. Yeah. I can talk about this all night. I think we're probably out of time
- 1:06:35though. Let me ask you the final two questions before you get out of here. You're going to do some
- 1:06:40editing or write some code. What editor do you choose these days? I am torn between Visual Studio Code,
- 1:06:47doom Emacs and Neo Vim. And I, but wherever I am in these editors, I always have my Vim key bindings
- 1:06:55set up. So it kind of depends on the project, but yeah, as long as I have my Vim key bindings, I'm happy.
- 1:07:01Yeah. Yeah, absolutely. And then notable, normally I ask notable PI project or library, but maybe broaden
- 1:07:11a little bit. Like if you could recommend one tool, one library people could install for the command prompt
- 1:07:17or the shell, what would you say? One tool or one command line tool for that they could install on the shell.
- 1:07:24Just something, it doesn't have to be the most popular. Something like people, if I ran across this,
- 1:07:28it was delightful. People should know about X. Yeah. Can do parallel. Let's do it. Let's say,
- 1:07:33yeah, we talked about it. So it doesn't require any further explanation. It's the tool that, that,
- 1:07:39you know, makes every other tool way cooler. Yeah. So yeah, if you have that one in your arsenal,
- 1:07:45you can become very powerful. That's a good recommendation. All right. Well, final call to action.
- 1:07:50People are excited about this. They want to learn more about it. What do you tell them?
- 1:07:53Yeah. A couple of things they can do. So my book, Data Science at the Command Line is freely available.
- 1:07:58Yeah. So the second edition came out a year ago. You can read it for free on data science at command
- 1:08:04line.com. I also offer a cohort based course that I do twice a year. The next cohort is coming up in April.
- 1:08:15And this is, yeah, there, we, we have six live sessions and then I will, I help, you know,
- 1:08:22a group of researchers and developers, you know, embracing the command line. It's a, a, a, a very
- 1:08:28different experience than reading a book. If you want to know more about that, then also data science at
- 1:08:34the command line.com has a link to that. Apart from that. Yeah. I mean, if you just follow
- 1:08:39hacker news, you'll come across now that you're aware of the, of all these tools, you'll come across
- 1:08:45quite a lot of tools every now and then there's not a week in which there's not a tool being mentioned.
- 1:08:51There are tools being developed every day, even though it's a, you know, the technology is over
- 1:08:5550 years old. It's impossible to keep up. It's only getting cooler. It is only getting cooler.
- 1:09:01Yeah, definitely. So yeah, that's my, my recommendation there. All right. Fantastic. Well,
- 1:09:06thanks for being here. It's been great. Congrats on the book and putting all this together. Yeah.
- 1:09:10Thank you very much for having me. Yeah. You bet. Bye. Bye.
- 1:09:12Bye.
- 1:09:12Bye.
- 1:09:12Bye.
- 1:09:13Bye.
- 1:09:14This has been another episode of Talk Python To Me. Thank you to our sponsors. Be sure to check
- 1:09:19out what they're offering. It really helps support the show. Take some stress out of your life. Get
- 1:09:24notified immediately about errors and performance issues in your web or mobile applications with
- 1:09:29Sentry. Just visit talkpython.fm/sentry and get started for free. And be sure to use the promo code
- 1:09:36talkpython, all one word. Starting a business is hard. Microsoft for startups, founders,
- 1:09:42hub provides all founders at any stage with free resources and connections to solve startup
- 1:09:48challenges. Apply for free today at talkpython.fm/foundershub. Want to level up your Python? We have one of the
- 1:09:56largest catalogs of Python video courses over at Talk Python. Our content ranges from true beginners
- 1:10:01to deeply advanced topics like memory and async. And best of all, there's not a subscription in sight.
- 1:10:07Check it out for yourself at training.talkpython.fm. Be sure to subscribe to the
- 1:10:11show. Open your favorite podcast app and search for Python. We should be right at the top. You can
- 1:10:16also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on
- 1:10:24talkpython.fm. We're live streaming most of our recordings these days. If you want to be part of
- 1:10:29the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at
- 1:10:34talkpython.fm/youtube. This is your host, Michael Kennedy. Thanks so much for listening. I really
- 1:10:40appreciate it. Now get out there and write some Python code.
- 1:10:45I'm out.