Monitor performance issues & errors in your code

#279: Modern Python Developer's Toolkit Transcript

Recorded on Tuesday, Jul 21, 2020.

00:00 Python is quick and easy to learn. And yet there's a massive gap between knowing the common aspects of the language, loops, variables, functions and so on. And knowing how to write a well factored application using modern tools and libraries. That's why we're learning Python is a never ending journey. Sebastian watsky is here to give us his take on a modern Python developers toolkit. There are a bunch of great tips in store for us. This is talk Python to me, Episode 279, recorded July 21 2020.

00:44 Welcome to talk Python to me, a weekly podcast on Python, the language, the libraries, the ecosystem, and the personalities. This is your host, Michael Kennedy. Follow me on Twitter where I'm at m Kennedy. Keep up with the show and listen to past episodes at talk python.fm and follow the show on Twitter via at talk Python. This episode is brought to you by linode. And us IT folks before we jump into the interview, there's so much going on over Talk Python Training that I want to share not one but four exciting announcements with you. Number one, we released a new course that has been a passion project of mine. Understanding how memory management works in Python, we don't have enough clear info out in the world to get a solid picture of how our code runs. So I dove in and created a five hour course covering all the internals of Python memory, things such as reference counting, garbage collection, and the fascinating allocation algorithms. We also touch on a bunch of simple techniques and patterns to employ which allow our code to run much faster and use only half as much memory. Check it out at talk python.fm slash meme announcement number two, Chris Moffat of escaping Excel hell Episode 200 fame has written a course to help folks escape Excel and start leveraging pythons data science stack with tools like Jupiter and pandas to solve the same type of problems and do the same type of computation. So if you're keen to use more Python and less Excel, check out that course at talk Python, FM slash Excel. announcement number three, Chris and I are putting on a free webcast pulling some of the tips and tricks out of that Excel course to help folks move from well Excel to Python. If you want to join us for that live event. It's going to be live on September 29 2020. And it will of course be available as a recording afterwards, just visit talk python.fm slash Excel dash webcast to be part of the webcast. In number four, we've crafted a unique learning experience for teams built on our courses over at talk Python, we call this team cohorts. We've already tested this for individuals. And we'll be announcing something for them shortly. But right now, we're launching this experience for teams within companies ideas to put together a digitally native experience that brings your team together and keeps everyone on track and gets them ready for that big upcoming project. These experiences include a private community, weekly video calls a clear schedule going through one or more courses of your choosing, and a lot more. Check it out at talk python.fm slash cohorts. Wow, that's a lot for just one week, isn't it? All of these links will be in your podcast player show notes. Please check them all out. This is truly the best way to support the show. Now let's talk about some modern Python.

03:31 Sebastian, welcome to talk Python to me. Hi, thanks. I'm excited to be here. Oh, it's great to have you here. I'm looking forward to exploring this idea of a modern Python developers toolkit. You put together a really nice tutorial, which you won't presented at pi Khan, like all the other folks who presented at pi con this year. And we'll talk about that. And I think it's gonna be a lot of fun to see your take on that you do have a lot of good advice in here. Before we get to it, though, let's start with your story. How'd you get into programming and Python? So you know all those cool stories about people starting to code when they were like 10. And then they learn some ancient programming language to program video game. Well, yeah, that's not me. My father had a computer. But as a kid, all I did was playing video games. And then I went to the University where I was studying automatic control and robotics. And I had three semesters of programming. And I think first semester was C, there was two semesters of C++. And boy, I hated see. I mean, it was so bad for me that I actually had to cheat on the exams to even pass it. And then I switched to C++. And it was slightly better. But so I eventually forced myself to learn C++ enough to pass all the exams that C++ is better. But yeah, still, still not Python. Exactly. Other modern languages. Yeah. And then at some point, I think I had to do website and that's when I really got interested into programming.

05:00 Let's say cuz Well, it was HTML and CSS. But just the idea that you could immediately see the results in the browser was what really piqued my interest. So I learned just making, I learned some basic CSS, some basic HTML and jQuery. And that's how I got into programming. Then I learned PHP and I started building websites for Well, I think building websites is one of those things that while it's pretty complicated, because there's HTML and CSS, in a programming language, there's a lot of moving parts. It's definitely one of those things that's more rewarding than a lot of lower level programming, because you can see it right away. It's easy to share, right? You can put it up on some site and say, Hey, everyone, check out this thing that I built. Try it. It's pretty fun. Yeah, yeah, definitely. Speaking of learning languages, that you might not want to learn when I was in college, I started out in chemical engineering, and then moved over to math. But while I was in chemical engineering for just a little bit, they said, you have to take a programming course I'm like, excellent. I've always wanted to learn C++ or something like that. They're like, No, you have to take Fortran really have to take Fortran, like, yes, you have to take Fortran, it's, if you want, you can take C++ as an elective. But Fortran is the most important programming language you're going to learn in your entire life. Don't you know, like, no, it's definitely still not true. It's I'm waiting for that to come true. But I don't think that was true. Anyway. Yeah. You got to start where they have to start, I guess. Yeah, it's nice to see that now. It's changing. And Python is more and more widely, becoming more and more popular. Yeah. And I think it makes it way more approachable to people who are not there to be programmers, exactly right, like economist or whatever. So that's how you got into programming, and found your way over to Perl and Python come into this whole story. So once I know how to make some websites, I applied for an internship at CERN. cern is this European Organization for Nuclear Research. And so they have this large hadron collider where they do a lot of cool stuff, but they hire not only physicists, so I applied for an internship as a web developer. And actually, the first day when I started, one of my senior colleagues went to pick me up from the reception. And he had this T shirt saying, I enjoyed learning Python, it was a nice afternoon. So that was my first interaction with Python. And it was hilarious. That's awesome. I had to learn Python the job, but I really enjoyed it. So I still stayed at CERN for the next six years building some really cool stuff there. Man, that's got to be awesome. Did you work remotely? Or were you in Geneva? Or where were you? I was working there. CERN doesn't at least back then then support working remotely? Yeah. That's got to be such a cool environment to be in. It was I mean, people from every country is crazy. You just go for a lunch with people from around the world.

07:53 That guy is a Nobel Prize, of course. So he can come on.

07:58 Yeah, quite cool. And how about today? What are you doing now? So I finished working at CERN. And then I moved to freelancing. So right now, I'm a Python Freelancer based in Poland, I still do a lot of web development, because I really like it. I think that's my favorite part of programming. But I also help companies fix their workflows, set up their architecture for new projects, and I even do some custom on site trainings for that sounds like a lot of fun. And it's a nice mix. So you get a try a bunch of different things and keep your hands in a nice, alright, well, let's talk about your tutorial that you did at icon online, which was really, you know, people who I'm sure most people know now, but basically, the way that Python us handled the whole shut down lockdown. thing was they said, Okay, we're going to take tutorials and the talks, and still give people a chance to present but it was record this as a screencast, basically, and then we'll publish it to the YouTube channel. And we'll list it on the PI con page as a list. That's what you did. And I think honestly, for yours, that might be even better, because you came up with such a nice set of digital resources that people can use, that I feel it's gonna be really valuable to everyone, not just the, you know, 50 people, or however many would have taken it in person there. Yeah, I agree. I looking in the hindsight, I think that was much better than a tutorial that I would be able to give in person because I was over two hours. So I really had to time everything. Well, I did a lot of editing to remove some stuff. And still, it's almost like two and a half hour of basically only meat. Yeah, but it's engaging, you did a good job with it. So when you come up with this idea, like, we all think about what kind of tools we use, and it's easy to get stuck in doing certain things. So you know, I never really I never really wrote tests. So, you know, if I'm not using pi test, for example, or I've always just enjoyed using them, so I'm going to stick with them, even though there may be a more productive

10:00 Have editors, for example out there, and so on. So how do you come up with this idea for your, your workshop here? So I actually come up with this idea of talking with people. So I noticed that people who are learning Python, they might learn how the language works, they might know the syntax. But then when they sit down to write a Python project, they just don't know how to start. I mean, you can see a lot of people asking what's the deal with visual environments, like what they should use for testing. So I had this idea in the back of my head, like, hey, let's, let's make a tutorial how to build a simple Python project from scratch, explain what tools to use, and just show enough tools. So people can like, take this project and build something bigger on top of it. So to not overwhelm people with like, too much of different stuff. Don't toss by three, or like different styles of managing dependencies, just give them one solid approach that they can use. Yeah, and that can be one of the challenges, right? The more guidance that you give, the less generally applicable, the result is, right? If you do you have to use talks in this way, and you have to make sure you have these tests. And then you have to make sure your all your API's always look like this, and so on, and so on. Like every layer, here's your continuous integration, however, it has to be, right. Like, it just means fewer people necessarily fit that same workflow. And so I think you found a pretty good balance here. Thank you, I had to remove a lot of stuff. Because Initially, I wanted to add even more features, but then I decided to, like really narrow it down to only the essential things that you're going to need. Yeah. So you set the stage. And I think this is hard for beginners to get a lot of times to understand, sort of internalize this feeling. But you said that there's a huge gap between knowing Python, the language like I know how to do a loop, I know how to create strings, I know how to like write a function, that kind of fluency with Python, there's a huge gap between that and knowing how to write applications or create proper projects. with Python, right? Yeah, I mean, maybe huge gap is a huge word. But there is a gap. Yeah, there's definitely a gap. Yeah, let's say that. Yeah. So that's the gap that I wanted to feel with my, my workshop. Yeah. And I think it's an important one, I don't want to put words in your mouth, I'll put the huge out there for the students who are taking, say, like my beginning programming courses, I find that they all can see the syntax, they can recreate the syntax, if you say, Okay, here's the thing, I want you to loop over it. Yeah, no problem really quickly, a lot of times, they've been able to learn how to like, do that and make Python do that thing. But if you put them in front of a blank file, just open up, you know, app.pi, and come up with a solution to some kind of problem. Like, I want to use the right data structures. And I want to have the right libraries to talk to this, you know, to API's and stuff. But I feel like there's, there's a pretty big gap where they feel like they just don't know where to start. And so putting a lot of structure in there, I think will help people get sent down in the right direction. One thing that I thought was pretty neat about your presentation was you had a whole website, right? A whole dedicated domain for this tutorial. Do you want to tell us about that? Yeah, so the website is bicon.sp toschi.com. I'll link to that in the show notes. So people can just click it. I used to Hugo, the static site generator with learn template. And actually, I stole it from Nina's current course tutorial today. So some years ago, she also used this template, and I really like it. So then I found it, I think completely by accident, I saw it. And that's the website template that she was using. So I gave it a try. And it looks really good. It has a nice sidebar with all the sections. Yeah. So you have a whole bunch. Like as you go through the tutorial, you've got the website, and you've got the video on the website, which is pretty straightforward. But then you know, you for each major section, you've got like a write up about that with links. So people don't have to try to type down or search for the various things you're talking about. They've got the exercises that people can do walking through. So I think like this is this is what I was thinking of when I said I feel like this is almost better, because it was done online. It's you have this, this whole resource for people here. Yeah, I was trying to make this website independent of the video. So you can just even if you don't know the video, you should be able to go to the website and kind of follow everything. So it's complimentary to the video, but it stands on his own. Yeah. Cool. So there's a couple of exercises that you have the students do, maybe we could talk about the exercises, and then we could start going through the steps and the guidance and whatnot. Sure. So I basically have two sections of exercises. First one is done after I talk about managing Python versions and Python dependencies. So first, I explain how you can install different versions of Python how you can like install different versions of packages, and there is an exercise to make sure that people are

15:00 understand what's the difference between virtual environment and Python version, and how they interact with each other. So I have like a set of steps, try to install, let's say this package globally, try to install, try to create a new virtual environment, create the package there, the Activate virtual environment, try to run this package and see what happened, we understand and stuff like that. And then I have the second exercise. This is a bigger one. This is basically a mini project. So at the end of the workshop, after I discuss everything, testing, documentation, and all this stuff, I have a mini project to create a to do application. So basically, you take everything that I showed you before. And your objective is to create a to do application. I wanted to make something more interesting, but everyone knows how to do Abby's. So I decided to go for DC. That's the canonical example of a like, let's build something that everyone is familiar with. That's right. It used to be blogs. But now the JavaScript people made it the to do app that everyone built. Yeah, I put a lot of thought into finding a more interesting project, but nothing.

16:06 Yeah, the problem is, the more interesting it gets, the more you get lost in the details, right? It's, yeah, anyway, yeah, that's fine. It's a cool example. All right. So there's a couple of hands on exercises that people get to do. That's good. Now, maybe the first big piece of advice, but also advice that is challenging for people who've been doing it a long time. I guess, to some degree, this is probably more focused at people who are new, so that as an agency matters less, but is to recommend a code editor, right? People are very passionate, or sticky to their code editors. Yeah, I was really hesitating if I should include this point or not. But at the end, I checked the Stack Overflow survey from last year and VS Code was used by basically every other programmer.

16:55 This portion of talk Python to me is brought to you by linode. Whether you're working on a personal project, or managing your enterprises infrastructure, linode has the pricing support and scale that you need to take your project to the next level, with 11 data centers worldwide, including their newest data center in Sydney, Australia, enterprise grade hardware, s3 compatible storage, and the next generation network will know delivers the performance that you expect, at a price that you don't get started on the node today with a $20 credit and you get access to native SSD storage, a 40 gigabit network industry leading processors, their revamped Cloud Manager cloud not linode.com root access to your server along with their newest API and a Python COI just visit talk python.fm slash linode when creating a new linode account, and you'll automatically get $20 credit for your next project. Oh, and one last thing they're hiring go to lynda.com slash careers to find out more, let them know that we sent you.

17:55 You actually at the start, you said Okay, we got to pick a code editor because you got to write some code. Let's do VS Code. And yeah, you went through the the stats from the StackOverflow developer survey. And you're like, it's like 12% in 2017. It was 30% in 2018. And 2019. It was like 50% or something like I this is a pretty safe bet a lot of people are doing this and liking it. Yeah, exactly. Yeah. So I guess first bit of advice, would you get VS Code? You don't have any Python tooling? Not really. Yeah. So when you install VS Code, it's pretty empty. And but the nice thing about VS Code is that when you install it, you have this welcome window, and it says like, oh, if you're programming in Python, check out this package. So basically, first package that you install, the install is Python package. And it's actually the most popular package on the VS Code marketplace. It's like, way above by a long ways. Yeah, it's like two or three times above even the C# and C++ one. And those are, you know, very core of Microsoft, right? Yeah, exactly. Yeah, yeah. So when you start, you basically first install Python package. And then once you have Python package, it's gonna give you some pop ups like, hey, do you want to install a code formatter? Or like, hey, do you have some tests? Do you want to install a test tool and stuff like that? So it really takes you by hand through all the steps that you need to have the basic Python ID Yeah, for sure. Have you looked at pi lance? The new language extension for VS Code for Python? So actually, no, I've heard about it from pi pi Python bytes. Yes. The podcast and then it. Got that one. Yeah, that was cool. Yeah, I thought it's gonna be like, built in into Python extension. But then I saw it's a separate extension, so I kind of forgot about it. But have you been using it? Not really, I just looked at it. When Anthony and Brian and I were speaking about it, it looks like it. It looks deeper into the Python language and more across your project more across the libraries looks at the documentation that might come with it.

20:00 To help strings and whatnot, so you actually have to have the VS Code Python plugin. And then the pylons plugin is like on top of that one. So it uses the new language server thing that they've got that I don't really know much about. But it looks I installed it. It looks like it'll be be nicer. We'll see. I haven't done a ton with it. Yeah, I will definitely check it out at some point. Yeah, not to start too much of a heated debate. But what are your thoughts on things like VS Code and pi charm, that more

20:29 dewy based helpful, trying to help anyway, editors versus some something like Emacs or vim. I know a lot of people still use Emacs and vim and the more terminal based editors, I think both are good. I mean, I'm still using vim, if I want to do some quick edits, and I'm in the terminal. So I don't really mind it. It's just VS Code or Python are more beginner friendly. So if you're new to programming, that's, you're probably gonna start with one of those. And what I really like about VS Code is that you can use it for different programming languages, you're not limited to Python. While if you started using Python, then you can use it for Python. But if you want to switch to JavaScript, it's not very useful. Yeah, yes, code can get weird how to make Yeah. Yeah, vs. Code is more general, right? It's sort of equally does Node JS as well as it does? Python. Exactly. And you can customize it with extensions. Yeah. Cool. So one of the pieces of advice you gave around is choosing a linter and not choosing the default linter. So two questions, what is a linter? And then why did you want to change what VS Code wanted you to do with one basically, a linter is a tool that if you make some mistakes in their code, it's going in your code, it's gonna shout at you and tell you that you did wrong. And so mentors are more strict, some linters are less strict. For example, for me, flake eight is the best linter that I use all the time, because it complains about forgot, for example, if you try to use a variable that you forget to define, it's going to complain about it. If you define a variable that it's not used in the function, it's gonna complain about it. So it gives you hints. It doesn't try to change your code. But it gives you hints as you're, as you're coding, while some people use pilings. And it's also a good linter. For me, it's just more strict. And sometimes it's complaining that you have too many public methods in a class and stuff like that. So that's why I didn't like it. I see. Okay, yeah, cool. So you basically go through and show how to, when you set up the Python extension, in VS Code, it says, Oh, you don't have a linter. Click here to install pilot and you're like, hold on, let's go over here and tell it that we want it to use flake eight. And then it'll say actually click here and stuff like eight, right? Yeah, exactly. Because by default VS Code tries to install everything, kind of globally. And I wanted to show people how to nicely isolate everything using virtual environment. So instead of just letting VS Code to install flake eight, I first show people how to use pip X to install flake eight, and then I point VS Code to use it. Yeah, well, let's talk about pip x just for a second, because it's it is a pretty interesting way to install these kinds of tools. I'm a big fan of pip x. I think it solves this really interesting problem. And to me, the way I think about it, it's only really, like maybe resonate with people on a Mac. But to me, it's like homebrew, for Python, utilities and library, right? Maybe chocolaty on Windows is a similar type of thing, right, some kind of central repository where I could say, install this tool, and it will just install it to my computer that works well for some things. But there's a bunch of things you would normally pip install, but then they have commands like black or pi test, or flake eight or whatever. And so pip x installs those. But usually those tools don't necessarily belong in your project, you just want to run them against your project. And so this will create pip x will create a virtual environment and install that thing in isolation and sort of manage it like it's like an application, if you will, like an app store or something. Yeah. So there are basically two types of packages that you probably want to install on your computer. One is packages for the project that you're currently working with. So for that, you would use a virtual environment, right, like requests or something. Yeah, yeah, exactly. Or like Django, you might be working on different versions of Django, and you might be switching between projects. But then there are also some packages like like a, like black, maybe cookie cutter. And for that, you probably want to have one version, preferably the most up to date version on your computer, you don't need to have five different versions of flake eight for each of your project, you just want to use the latest flake eight because you know, it's going to catch up, catch most errors. So that's where you would use be backs. So it lets you install package and it will act as a global package, but at the same time, it's installed inside a virtual environment. So PBX handles all this visual environment creation activation

25:00 You just see this package as normal as if you normally install it with people. It's super cool. I really like the way that that works. And it manages and lets you upgrade those things separately. So you might use that to install like eight or various tools that you're gonna do set that up in VS Code. And then another thing you talked about is by default, probably, code is not installed in the path. So you can run VS Code. But if you're on the terminal and you want to edit something, you might want to be able to type like code space file name, or code space directory name and open those up. Right? So you've got to go and take an extra step to install that. Yep. And I think right now, VS Code will even give me a pop up saying that, hey, you can actually do this. And there is a command in the command palette to add VS Code to your shell. So it's getting even more and more beginner friendly. Yeah, vs. Code is interesting. In that it, it does so many things. And yet, it's not obvious what it's capable of. Right? It's, you know, if I go into pi charm, there's a button, you know, go this button, what does it say? Oh, that means it's gonna do like a profile. And if my code if I click that button, but there's no button for so many of these things in VS Code, instead, it uses this idea of a command palette, right? Yeah. As you said, that's the thing. For example, with testing, there is like no sidebar for tests. But once you set up testing tool, you have a sidebar. Yeah, you talked about some of the commands that are useful there. And unfortunately, I only have these for Mac, people have to translate properly command equals control. And that's pretty much it, open the command palette, so you hit command, shift P. And then you can type all sorts of stuff in this is kind of how you get to all those features that we're talking about. Go to files, command p, go to assemble, command, shift p or Command Shift o or you just Command click thing, go to symbol control t go to line control g command space, or sorry, Ctrl Space to trigger the IntelliSense. But you couldn't get that to work. Right? If for some reason you had to like use them alternate, like shift escape or something to make that come up. Yeah, I don't know, what was the problem? Yeah. So there's a bunch of cool commands that I think anytime people switch into an editor, that's not the one that they're used to using, it's really worthwhile to sit down and just maybe even make a list of Here are the top 20 most common hotkeys, right, because just because you're in a GUI doesn't mean you should be using the mouse all day. Yeah. And it's interesting that you mentioned it because before VS Code, I was a heavy Sublime Text user. And when I switched to VS Code, my muscle memory was still with sublime. And actually, for VS Code, you have those extensions that will bring the keyboard bindings from other text editors. So there is an extension that will rebind some comments to commands from sublime there is an extension for atom and stuff like that. So for a long time, I was using the sublime key binding. And even now, I recently reinstalled everything from scratch, I still had to manually remap some commands, because my muscle memory was just not fixable. Yeah, yeah, sometimes it's like, no, this is I'm just gonna always type this. So we're just gonna make it do that. And that's okay. Now, another thing that's not obvious, I think in VS Code, especially to beginners is how do you run your project, right, like running a single file, maybe it's not too hard, right? You can, there's a little button for that. But if you open up a flask app, and you want to use flask run, rather than, you know, just running the app.pi, or whatever, or you want to run some tests or so on, that can be tricky. You want to talk people through that experience

28:37 of a run configuration. As you mentioned, if you want to run the single file, you can use it from the command palette, or you can press this green arrow button, everything is fine. And you can actually even use it for a flask server, you just run the file that starts the flask server and it's going to be fine. But actual power, better idea is to use the debug configuration, or how is it called I don't have VS Code of something. Yeah, launch of maybe launch configuration? I'm not sure it's something like that, anyway, yeah, yeah. So it's under the sidebar for debugging. And if you don't have any launch configuration configure, you're gonna have like a button there saying configure launch file or something like that. Once you click it, you can select what you can select one of the popular frameworks that are there. So you can select a Django or flask or parameter of duration. And that's going to create a launch file for you with some predefined commands. And for most cases, you should be good. But if you want to modify, for example, some parameter that you specify up at the brand server command, you can do this there. Once you have this launch file, you can actually launch a web server. And now the cool thing is that if you put some breakpoints in your code, so you can click Next to the line number in the gutter and it's gonna put a breakpoint. This will trigger the breakpoint in yourself.

30:00 server. So now if you go to your website, it's actually going to stop at that breakpoint. And you can use VS Code to do debugging. Yeah. Yeah, that really unlocks the power if you set up the debug whatever configuration to launch those things, and yeah, cuz then you could do the breakpoints, watch the variables, the inspections, all that kind of stuff. And again, the reason I think that's valuable to talk about these kind of things is it's not obvious that this is what you should be doing to get the debugging support to work, right. There's a lot of like implicit stuff, but once you know, it's fine. Another thing that's pretty cool is code snippets. Yeah. So VS Code comes with some code snippets by default. But if you install some extensions, for example, if you install Python extensions, you're going to get even more extension, you're going to get even more snippets like a snippet to create a class to create a main function that's called like that. And then for example, if you install a Django extension, you're going to get even more snippets like Django template tags, and stuff like that. And on top of that, you can define your own snippets. So just create, you just select the command, create a snippet, and you're going to get a nice scaffolding with some information, what do you have to put in each place, basically, that's a JSON JSON file. So you define what's the abbreviation to trigger the snippet, you define the description, and then you just define the code that you want to put there. And what's also interesting is that you will have some placeholders that if you press tab, your mouse will will move there. So if you want to pre fill some values in a function, you can press stop, and you will be moving between those places. And there are some special variables that will insert, for example, the current date, or the current folder. So VS Code has this nicely documented in the documentation you can build, it's almost like a little scripting language. So that's super cool. And if you find yourself just doing the same thing over and over again, maybe it should be a snippet. And then the last thing on the vs. Code topic, before we move on, is you talked about a bunch of interesting extensions for VS Code. And some of these I hadn't heard about, or plugins, let's maybe just talk about a couple of your favorite because obviously, the Python and the PI Lance ones are there. But there's other ones that people maybe haven't tried out like there's a Django one, and there's intellicode, you want to hit the highlights there? Sure. So apart from the obvious Python, then if you're working in Django, or in flask, then there are some plugins that will add additional snippets. And for example, for Django, it will also add some syntax highlighting support for Django HTML files. But apart from the obvious things, there is, for example, a plugin called intelli code that will try to predict it will try to make the auto suggestion a bit more smarter. So it will try to predict what's the item from the autocomplete list that you are most likely to choose. And it will move this item to the top of this list and add this nice star. And it actually works pretty well, from what I noticed. So I can actually highly recommend it. Yeah, cool. Yeah, uses machine learning across a bunch of open source libraries to say, well, using SQL alchemy, these are the most common functions to be called in these situations, and it tries to understand the context rather than just, here's the whole list. Whatever. Yeah, from other interesting stuff, there is, for example, auto doc string. So if you define your function, you can just press enter at triple quote, then press Enter again, and it will put some scaffolding for the documentation. It will also take the arguments from the function signature and put it in the documentation. So it will make your life much easier. If you're using type hints, it will also detect that it was detected type hints and put them in the correct place. Oh, yeah, that's cool. That's also nice. From non Python specific extensions, I really like bookmarks. Because it makes my it makes moving around the code much easier. So you just put a bookmark in different files, and you can easily switch between them. And yeah, get lots of nice, I had good lens is a massive extension. I mean, the amount of features it has, it's incredible. And just using a very small subset, but really gives you a really good overview of what's going on in your project. You can open repositories, comments, branches, marriage requests, whatever you want in the Git lab, GitHub. It has everything. Yeah, I remember looking at some c Python source code, with gotlands installed in VS Code. And it had something like this file change from really long ago by either van Rossum or something like that. And I go, Okay, this is still like some of the original code right here. This is cool.

34:35 Talk Python to me is partially supported by our training courses. How does your team keep their Python skills sharp? How do you make sure new hires Get Started fast and learn the pythonic way? If the answer is a series of boring videos that don't inspire, or a subscription service you pay way too much for and use way too little. Listen up. A Talk Python Training. We have enterprise tiers for all of our courses, get just the one question

35:00 Do you need for your team with full reporting and monitoring, or ditch that unused subscription for our course bundles, which include all the courses and you pay about the same price as a subscription? Once? For details, visit training, talk python.fm slash business or just email sales at talk python.fm.

35:21 Yeah, also the error lens. Yeah, so error lens, you can use it to customize how you want to see the errors. So by default, you're gonna have like a separate tab in VS Code that lists all the errors. But I I like to see the squiggly brackets, the squiggly underscore, whenever an error happens, it will also let you customize. If you don't want to see the info or hints you can put the font size to zero and it will completely make them disappear. So it's a nice way to customize your errors. Yeah, very cool. And maybe the last one to just give a shout out to his jumpy. Hi, this is a really cool one. Basically, how Giambi works is that you define a keyboard shortcut, you press it, and then it will show like a two letter, small two letter snippets, basically at every word in your current screen. And then if you press those two letters, your cursor will jump to that place. So it's like incredibly convenient way to move around your code, as long as you remember to use it, because I always forget. Yes, and we were talking before, like, I always forget this as well, I've Ace jump installed in Python. And I can hit Ctrl, semicolon and then type a few characters. And it's kind of like find, it'll highlight all the stuff that would match that substring. But as you said, it puts a one or two characters next to those things, if you want to go to the third, like if you're doing request, get, you could do the Quick Search for G and you want to go to the third get, it would highlight that there might be like you might press like y or something to get there and just immediately take you there with no mouse, it's beautiful. And I never use it. I hardly ever use it. Let's say that's my new my new thing. I'm gonna try to start using this more because it's awesome. All right, well, that's probably enough for the editor. But this is a whole lot of stuff, a whole lot of customization and specialization to really get the editor and the tools and the stuff more than just Hey, you should use VS Code, but really just set it up the way that you like. So that's good advice, then another problem, especially beginners are going to hit straight away. And this one is is tricky, because it varies on the platform is do a Python, what version of Python? Is it? Is it the right version? Can you install packages into it? Should you install packages into it? and so on? and so on. Right? Yeah. So that's the next topic I talk about after the VS Code, basically how to manage different Python versions and packages. And why the first point is why you should not use the system version of Python, because once you mess it up, you're gonna mess a lot of things on your computer, one of one of the first things that you want to do is to install some custom Python manager and switch Python version to this, this custom version. I think, yeah, back in the days when I was still using Linux, and I was still a beginner programmer, I tried to update the global Python version, my operating system, and that broke a lot of stuff. Yeah, I can imagine it does. Yeah, these days when I am on virtual machines, I will set up a virtual environment. Usually the virtual machines meant to run one app anyway. So I'll set up a virtual environment for that app. And then in my RC file, when I log in, I'll have it activate that virtual environment. So if I accidentally type pip install something or mess with it, it's just going to mess with that virtual environment. It's very rare. I want to log in and change the system, Python, it's very common, I want to log in and change the virtual environment for that particular app that servers dedicated to actually there is a setting for pip that will prevent people running outside of the virtual environment. There isn't really I guess, yeah, I know. That's cool. I don't remember it by heart. But I actually have it on my blog. I discovered it some time ago. And I was super happy about it. Nice. Yeah, that's really cool. A couple of suggestions that you have here. Obviously, we have V and V, like Python three dash, m, v, and v type of thing, the built in, which is nice that it's built in. But you didn't start there. You started with PI end. Tell us about why you chose that and what you're doing with it. Yeah, so I wanted to show first how you can manage different Python versions, and then how we can manage different Python dependencies. So basically, pi envy is a tool that lets you install different Python versions on your computer. So let's say you have you're on a Mac so your system Python is 2.7 for whatever reason, it's still there. That's crazy. And they're gonna take it away in the next version. The but they're not replacing with three they're just gonna take Python away or something to that effect. I remember them announcing Oh, cool, so I don't know if that's better or worse but anyway, it's it's not gonna Python to at some point, it's probably gonna break a lot of stuff. Yeah, I think it probably well.

39:51 That's Apple, I'm sorry, anyway, didn't mean to derail you. So you got the wrong version of Python. If you're on Mac, if you're on Windows these days, they have the Windows Store, little pop up thing, which is great.

40:00 But also confusing to people. And on Linux, who knows, it depends on your version, right? Yeah, for example, if you want to install a different version of Python, you can install it using, well, just some standard Python installation. But Python is much better because it lets you easily switch between versions. So if you're using just the latest byte on all the time, it might not be as big of a deal for you. But for example, I'm working on different projects, one project is using Python 3.61 is using Python 3.8. And I want to find a way to easily switch between those two versions, that's what I would use pi n for. So we install pi n. And then you say, pi n, installed 3.8 point three, and that's going to install this version of Python. And then I say pi pi and installed 2.7. And it's going to install 2.7 as well, it's going to be different than the system one, it's going to be managed by pi f. And now let's say I'm working on a project with Python 2.7, all I have to do is to say pi n global 2.7. And just like that, my global Python version is 2.7. Yeah, I wasn't aware of this feature pi envy, where you can basically shadow what Python means on your machine, and cyclists. So with pineview, install the different pythons, you could have, you know, 373839, maybe if you get if it'll pull the beta version to seven, but then you can say, pi envy, global Python, three, six, pi envy global Python, three, eight. And then if you just type the word Python, that means that version you set it to, which is pretty awesome, actually. Yeah, it is. And it's actually done in a pretty clever way. So it's using the system of shims, or how's it pronounced, that basically it prepends to your PATH variable, this pi and Python versions. So whenever you type Python, your computer is gonna look for Python, binary. And it's going to find on your path, this shamed version, this child version is going to use this one. But the nice non intrusive version two that lets you get some version that the version that you want onto your system. And then then you went on, I think you were using virtual just V and V, not the built in virtual environment capabilities up height. And I showed how to use the V and V module from Python, because well, it's built in Python. So that's the easiest way, but I'm not using this in my daily work. And so I wanted to show, I think I'm using visual fish right now, which is a rapid over which one vironment right. But it works in the fish shell? Yeah, yeah, it's the same as visual and when visual and wrapper for non fish shells. And what I really like about this is that it has a set of commands to list all your virtual environments to create them to remove them. And so it's much easier to manage those environments. And I prefer it to have like one separate folder for all of those. Yeah. And I also wanted to show people that are different tools than the building Python module, because I see a lot of people who are teaching Python, they show the built in Python tools, but there's a lot of other cool tools that you can use, and maybe you like them more. Yeah, for sure. And then the last thing you talked about here was pip x, which we already covered. So I don't want to spend too much time on it really. Although I do want to throw out one tip for people that cuz something that was been driving me crazy about pip x is I installed Python through homebrew, which is the best way maybe I should be using pi m. But for whatever reason, that's what I've been doing. So it's it's that way. And when the homebrew upgrades Python, pip x, virtual environments become invalid for some reason, I don't know why. But with pip x, you can just do a pip x, reinstalled dash, reinstall all that reinstall dash all and it'll basically tear them all down or recreate them. So that'll kind of fix when these these like shims get out of sync with pip x and whatnot. So maybe that'll help some folks out there. But yeah, that's a cool tool. Next up, we've got our runtime, here's pythons picked. We've got our editor all set up. Now it's time to start creating projects. And you already mentioned cookie cutter, but cookie cutter was what came to mind here, right? Yeah. So I was thinking, because people are wondering what's the people are often asking, what's the best way to structure Python project? And pretty much there is no no best way. But if you really don't know where to start, there is this tool called cookie cutter. And basically what it does is you provide it with some templates that someone created before you, and it's gonna generate a scaffolding of the project for you. But it's gonna actually ask you some questions on the way so if someone was giving you the option of different databases cookie cutter, it's gonna ask you do you want to use MySQL? Do you want to use Postgres? Do you want to use SQL lite? And depending on what your answer is, cookie cutter will define a different config file. So all those things have to be first defined by the person who created the template. So cookie cutter doesn't do

45:00 In the magic, but if you're new, you can go to cookie cutter website, and you will find some very popular templates that say, for a Django project or for a Python package or for a flask project, you can take the most popular one provided to the cookie cutter, and it will generate base for your project that many, many people before you has have used that is usually very well documented. It has some hints, like, well, how to set up ci, or how to deploy some stuff. Yeah, those are really, really nice. And I guess it depends on what you're building. But often, you know, if you're building a package, you want to have a setup, py, and various other things that go along with that, right. And it'll automatically pre populate that when you just run cookie cutter, you know, create me a package, a Python package thing that's called this. Yeah, it's really nice. I like it quite a bit. Again, those are super, they can be super opinionated. So depending on how, how much you align with what they're trying to do, it may work well or not. But there's many, many different templates. So you can even just search GitHub for them. And just point cookie cutter at a GitHub repo long as that repo is public, and has, basically is a template. Yep, exactly. And as you heard, they are very opinionated, but in my opinion, it's opinionated, it's much easier to find a cookie cutter template and actually remove stuff then to start from scratch. And when you're staring at your blank editor, trying to come up with some ideas, how to set up things. Yeah, absolutely. I totally agree. Find a good v cutter template and roll with that as well. Maybe even sets up things like black and pre commit hooks and so on for you. Yeah, exactly. Many templates already follow some good practices for installing some linting and formatting tools for you. Yeah, another thing that you spoke about is the repple, the read eval print loop, you know, what you get when you just type Python, and just type in Python is okay, but honestly, it's, it leaves a lot to be desired. Like, even just up arrow in through your history, it repeats the line, if you wrote a block of three, three lines, like you got to like re arrow through them to get to if you want to go back to that group, right, that's kind of annoying. So there's other options that you can use for your rebels that you suggest you're talking about, at least, I noticed that a lot of people who do some tutorials or show some presentations about Python, they use the default python repple. And if Imagine you're a new person who doesn't know their different Python repple, so you're gonna get stuck with Python repple. And as you mentioned, it's not the most user friendly repple I mean, it's there, it's fine to use it. And it's not Python core developers job to improve it. But there's different tools that you can that are basically a drop in replacement. For example, one of them and my favorite one is ipython. Basically, that's the Python repple on steroids. So you just install it. And instead of typing Python, you just type ipython. And so there is like almost no change for you. And out of the box, you got like syntax highlighting, you got that auto completion, you it's much smarter about when you press enter, because when you start typing a function definition, and you press Enter is going to actually in then the next line, and it's gonna detect that you're still typing this function, not that you just finished typing. And for example, you can append a question mark. So you will see the signature of a function, or you can append two question marks, you will see the whole whole code source code of a given function. So I'm actually using ipython to read the documentation. Also, the time is really cool. Yeah, I didn't know about this feature. This is really cool. So if I had a variable, like x equals a string, let me just quote something right. Then I hit Enter, then I could say x question mark, it'll say this is a string. It's string form is whatever the string is, is length is what it is. And it will list out the doc string. And yeah, that's super nice that you could just ask it questions about what it can do. Very nice. Yeah. And there's a lot of cool things that you can do. For example, you can edit the file. And for example, you can tell it to edit command or function. And the ipython will try to figure out where this function is defined. And if it's from like, some package installed with Pip, it will actually open the file in this vitran environment that contains this given function, and it will let you edit it at it. Oh, wow. That's pretty awesome. Cool. So ipython it's definitely there. And it's got this kind of Jupiter feel, right? It's like, basically a little bit like Jupiter in in the terminal command prompt. But you also talked about two other ones, PT, Python and be Python. Yeah. So there is PT, Python. I think the name stands for prompt toolkit, Python, and B Python. They are both much lightweight approach than ipython. So there between ipython and Python, they have syntax highlighting, they have some tab completion, but they don't have as many features of as ipython but

50:00 For example, they have different features. I think it's B Python that lets you rewind code. So if you type something and you realize you made a mistake, and you can act, and you want to actually undo the last command, because I don't know, you close the file, or you just deleted something from the array, you can actually undo this, there is a keyboard shortcut to undo the last command, and then you can continue working on the file, or whatever. So both of them are much better than the built in Python. repple. Yeah, I totally agree. And if you pull up PT, Python, you can have it in Emacs mode, you can have it in vi mode, you can go and pull up all sorts of things like enable fuzzy completion and all sorts of stuff syntax highlighting, really, really nice. I haven't done as much with B Python, but they both seem, you know, much nicer to me, in that you get autocomplete, and you get better editing and whatnot. Yeah, so certainly good recommendations there. I guess, PES probably not quite as much to discuss with tests in some regard, right. Like you said, Okay, well, people are using pi tests, you should probably use PI test that seems to be pretty good consensus these days. Yes, it's a pretty solid choice. I also explain why it's better to spiders than the built in unit test library. I mean, the unit test libraries is pretty good. But it also suffers from the same problem as the python repple. So it's kind of basic. And at the same time, I find it a bit over complicated because you have all those different assert types, while with biters, you just have one asset. And basically, that's all you need for most of the time. Yeah, one thing that maybe is not as obvious is how to get the test to run in VS Code. So that's pretty cool feature of vs. Code, is, I think, when you install Python extension, it's going to ask you what test framework we want to use. So you select by test, and then you will have the sidebar with test. And then you can just click discover test, and it will go through all through your project and try to find all the tests, all the files and all the functions that are matching the PI test convention. And then in the sidebar, you will see all those tests, you can run them, and you will see if it's passing or if it's failing, you can debug them. So if the test was failing, it will actually stop in the place where the assertion is failing, or when there is some problem. And then actually, if you open this file, in the VS Code, you will see like a small text above each test function that will tell you, you can run it or you can debug it. So you don't even have to go to the sidebar, you can just click in your text in your code editor, and you can run the test directly from the test file. Yeah, that's super cool. And it just runs that one test, right? Yeah, exactly. Alright. Another thing that you suggest that people do is that they write documentation. And I guess this, this probably varies depending on what the goal of the project is, if the goal is just like a small little app for just you, maybe doesn't need documentation, but a lot of times it will. What was your advice? there? You already sort of mentioned auto dock. I know, that was for that was a plugin for the extensions. But there's also auto dock for API's, right? Yeah. So for documentation, I recommend pretty standard Sphinx is a very good tool used by many projects. And even with the read the doc project, if your project is open source, then you can house your documentation for free. So this is really nice. So you have documentation I was you, I would use things. And then as you mentioned, there is this auto doc plugin that you can add to things and it will automatically generate the documentation for your API, which is really cool. because it saves you a lot of repetitive cult, yeah, right. If you're already gonna write it for the help string, in your library, you might as well just get it to write, you know, copy it over there. Exactly. And there are also some other cool, there are also some other cool plugins like there is one that will actually run tests in your doc strings. So if you have a TED, if you have an example of code in your doc string, quite often it can get out of date, because I mean, documentation is often well outdated. So we can actually install a plugin that will try to detect code snippets inside the documentation. And it will actually run those code snippets comparing it to the next line in the documentation. And if it's not matching, it's gonna report you an error. Yeah, that's cool. So if you've got an example, in your doc string, like, here's how it's supposed to work, and if it doesn't do that, at the problem. Nice. So one other thing that you did talk about in this section that I thought was worth mentioning is, what should you put into your documentation? And you talked about someone Danielle, I don't remember what the last name was, who talks about four different categories? You might have like tutorials, how to guides, explanations and references, to help give you some structure to think about what you might write. Yeah, so I saw this really good talk from Daniella placida. And he

55:00 He splits the documentation into four parts. First is tutorials. So people who are like complete beginner can come to your project and see okay, how I can start using it, then you have how to guides, so recipes for solving a specific problem. So if you have, like, very specific problem, you can find it probably there, then you have explanations. So this part actually explains how your project works, how each parts interact with each other. And then finally, you have reference, which is like a Wikipedia page for your project. So all the terms, all the classes, whatever they are defined there, maybe the why, like, why did we put this here? Or what the history of it or something? Yeah, yeah. Okay, that's really helpful. And then last thing on the documentation side, you mentioned that you can get aim. You know, normally you would write this in restructured text. But markdown is the current thing that people like to use the most, I think, and there's a markdown extension you can get as well. Yep, there is a markdown extension for Sphinx that you can install, and it will let you write documentation in markdown. Yeah, we even have ipi.org supports markdown these days. Yeah. And then I also mentioned that if you're writing some rest API's, there are tools like swagger, or Redux that you can use. And they will also generate, like, really nice documentation for your API. Yeah. If you use frameworks like FastAPI, it's like basically built in and stuff like that, which is really, really cool as well. It depends on what you've got. underneath the covers, they're cool. So last thing, got everything set up. You got your package structure, you got your documentation, presumably written some code. Last thing, you've got to deploy your app. Yeah, so I was hesitating, if I should include this section. But since it's, it was pre recorded, I still have some time. So I decided to give people like a very simple Docker file that they can use to take this project that we are building and to deploy it as a Docker container. So I explained like, very briefly what Docker is, I started by showing how to make a Docker file, which is intentionally kind of bad Docker file. Then I explained what the problems of this Docker file. And then finally I show them like a much better Docker file that they can use. But it's still very basic one, yeah, cool. Then you could put it in presumably in like a Kubernetes cluster or something like that, if you want. Yeah, there's even this website played with Docker. So at the end of the workshop, I'm showing how to use this website to actually deploy our application. It's, it's deployed in this like, terrible URL that it's gonna end the container. It's only there for four hours, but it's, it's it's there. It's online, you can share it with somebody idea. Yeah, exactly. That's awesome. Well, that's quite a whirlwind tour, all the tools that you might use, but I think it's these a lot of good advice exposes people who are maybe a little bit new to putting together these projects and closes that gap from I know the language to now I know how to actually create and ship applications in a more professional way. Yeah, yeah. Yeah. Pretty neat. So thanks for putting that tutorial together. And because it's on icon online, people can go take the workshop, right? It's two and a half hours. And it's easy to follow along. And yeah, nicely produced. All right. Well, before we call it wraps, even though we are getting along on time here. Two final questions. First, maybe this is a hint, I'm not sure how much time we spend on VS Code. But if you can write some Python code, what editor do you use? Hmm, that's a good question.

58:30 Now, so it's VS Code. And for like, some short edits, it's been right, right on. And then notable pipe package, you know, something that maybe you've run across recently, that it's really cool that people don't know about. So I'm pretty sure you already know what I'm gonna say. It's ipython. So another console, contributor or anything, but I really love it. And actually, I was writing a blog post a few weeks ago, and I put an introduction, something along the lines along those lines that I really like I Python. And if I ever got invited to your podcast, not that I have anything to talk about, I will mention like bytom. So I'm here. And I mentioned the guy, Python. But now seriously, so this is a really great package. And I use it all the time. Yeah, it's super cool. And I really have not used it enough as a repple. So I should definitely be thinking more about that as well. Awesome. All right. Well, final call to action. People are excited about this. All the ideas we talked about in the tutorial, what are they? What should they do now we'll start building so you can just you can follow this tutorial. And this will give you a pretty solid base for any projects that you want to build on, built from it. And if you know someone who's learning Python, and who's not sure how to start building stuff, or who wants to build something in Python, just please tell them about this video. I mean, it's quite long, but it's free. And at the end, you will have a very solid scaffolding of a bytom project that you can use. Yeah. Good advice. Thanks for being on the show and sharing it with everyone. Thank you very much. Thank you for

01:00:00 gotten here. Bye bye.

01:00:02 This has been another episode of talk Python to me. Our guests on this episode was Sebastian wood watsky. And it's been brought to you by linode. In us over at Talk Python Training, start your next Python project on the nodes state of the art cloud service. Just visit talk python.fm slash linode li n o d, you'll automatically get a $20 credit when you create a new account. Want to level up your Python. If you're just getting started, try my Python jumpstart by building 10 apps course. Or if you're looking for something more advanced, check out our new async course the digs into all the different types of async programming you can do in Python. And of course, if you're interested in more than one of these, be sure to check out our everything bundle. It's like a subscription that never expires. Be sure to subscribe to the show, open your favorite pod catcher and search for Python. We should be right at the top. You can also find the iTunes feed at slash iTunes. The Google Play feed is slash play in the direct RSS feed at slash RSS on talk python.fm. This is your host Michael Kennedy. Thanks so much for listening. I really appreciate it. Get out there and write some Python code

Back to show page
Talk Python's Mastodon Michael Kennedy's Mastodon