Latest / Talk Python To Me / #362: Hypermodern Python Projects
Transcript
- 0:00What would a modern Python project look like? Maybe it would use poetry rather than pip directly for
- 0:05its package management. Perhaps its test automation would be controlled by Nox.
- 0:10You might automate its release notes with release drafter. The list goes on and on,
- 0:15and that list is the topic of this episode. Join me and Claudio Jolovitz as we discuss
- 0:21his hypermodern Python project and template. This is Talk Python To Me, episode 362,
- 0:28recorded April 6th, 2022.
- 0:30Welcome to Talk Python To Me, a weekly podcast on Python. This is your host, Michael Kennedy.
- 0:48Follow me on Twitter where I'm @mkennedy and keep up with the show and listen to past episodes
- 0:53at talkpython.fm and follow the show on Twitter via at talkpython.
- 0:57We've started streaming most of our episodes live on YouTube. Subscribe to our YouTube channel over
- 1:03at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:08This episode is sponsored by Microsoft for Startups Founders Hub. Check them out at
- 1:14talkpython.fm/founders hub to get early support for your startup. And it's brought to you by
- 1:20Compiler from Red Hat. Listen to an episode of their podcast as they demystify the tech industry.
- 1:26over at talkpython.fm/compiler. Transcripts for this and all of our episodes are brought to
- 1:33you by Assembly AI. Do you need a great automatic speech to text API? Get human level accuracy in
- 1:38just a few lines of code. Visit talkpython.fm/assemblyai.
- 1:42Claudio, welcome to Talk Python To Me.
- 1:45So happy to be here.
- 1:46I'm so happy to have you here. It's great to be talking to you. And this is one of those episodes
- 1:51that's going to be so fun because what it's going to turn out to be, I'm pretty sure, is diving into
- 1:56a ton of little tools. And I can tell you, just doing a little bit of research and putting together
- 2:01some show notes for this, like, oh, there's that thing. And oh, look, this too. Oh, I didn't know
- 2:05about this. So you've assembled this conglomeration of tools and techniques that you're putting under the
- 2:13hyper modern banner. And I think it's going to be a lot of fun to talk about. So yeah, we're going to have a
- 2:18good time. Looking forward. Indeed, same. Now, before we get into that, let's talk about your
- 2:23story. How'd you get into programming and overhear to Python? I think one day my dad, that must have
- 2:27been in the 80s, came back with and said, I bought a computer and I was really excited. I imagined,
- 2:33you know, there's going to be a room filled with all these machines and ran down the corridor and
- 2:39turned out to be like some kind of keyboard as it seemed to me. So there was a Commodore 64.
- 2:45And initially we just, you know, played all those great 8-bit games. And eventually I started
- 2:51programming a little bit in basic. And I think that's kind of when I really found out how much
- 2:56fun this is. And, you know, then I think I was interested in a lot of other non-computer things
- 3:03for a long while. I went to uni, I studied law.
- 3:07As most programmers do, of course.
- 3:09And, but somehow this, the interest in formal systems always stayed with me and law, especially
- 3:16continental law, German law is very much like a little bit like a calculus tracing back to ancient
- 3:23Rome. And I got interested in logic. And there's a small research community working on applying AI and
- 3:32logics to legal theory. And that was really my gateway drug to, to get back into programming
- 3:37really logics. I think I programmed this like a little flashcard system to help me prepare for the,
- 3:43for the law exams. And yeah, eventually I decided I want to get really deep into this. And I started
- 3:51studying computer science and pretty much never, never went back to law after that. So I have a law
- 3:56degree, but yeah, working as a software engineer.
- 3:59It's interesting. I hadn't really thought about it with law. I have a friend who's a lawyer and
- 4:03in software. So I know it's, it's, it happens for sure, but thinking about the way you have to
- 4:09mentally sort of solve the problems and the constraints of like legal contracts and laws
- 4:15and stuff and how they apply. That's actually kind of a similar skill to thinking through solving a
- 4:19computer programming problem with APIs and what the computer can do and stuff. Right.
- 4:24And it's such a human way of thinking. So it's, it's really interesting from an AI point of view,
- 4:29because it's not the kind of really clear logical deductions that you have, but there's a lot of
- 4:35everyday knowledge that you need to have and the feasible rules. Yeah.
- 4:39So it's quite exciting.
- 4:41Yeah. Very neat. Now, what kind of a code and what kind of stuff are you doing these days?
- 4:45I've been working mostly on a, on cybersecurity. So I'm working for a company almost 14 years,
- 4:53that's doing cybersecurity as a service. So we're working mostly on C++ services or high performance,
- 5:01data intensive services. We're using Python mostly for, to automate the build system, testing and releases,
- 5:09processes, but also for prototyping. So algorithms, that's like really handy before you implement it in
- 5:15a high performance way.
- 5:17Yeah. I think Python is used frequently for that. Like let's prototype this. And then if
- 5:22once we completely decide it works right, then we're going to write it in C++ or Rust. That's
- 5:27not the most common use of Python, but it certainly is one that people have said, oh,
- 5:30this is really good because you can prototype so quickly. Sometimes people just decide,
- 5:34and also this will just work fine for what we're doing. It's actually, it's plenty fast. Or they
- 5:39decide, you know, maybe not, right? Maybe they need C++, but it's still a cool use case.
- 5:43Yeah.
- 5:43Now let's kick off our conversation with some thoughts from a former guest, Mahmoud Hashemi. He had a
- 5:50really interesting way of sort of presenting Python to people who are not deep in the Python language and
- 5:57said, basically, it's actually, when people say Python is great for prototyping, for example,
- 6:02well, they might be talking about one of three things or some combination of there. It could be
- 6:07when people say, oh, Python is good for this, or Python is like that. They might be talking about the
- 6:11language, or they might be talking about the standard library, or more and more these days,
- 6:16they're talking about the third party ecosystem with, I don't even know how many libraries, but I
- 6:21gotta look this up because it changes so fast. Right now at the time of recording, 368,000 libraries. So when
- 6:28people mention Python, they often mean one or more of those different things. And we're going to talk about
- 6:34hyper modern Python. So I think we should frame it a little bit in the sense of like, well, you know, what is
- 6:40modern about the language? Or what is kind of modern about the standard library? And obviously, the ecosystem
- 6:46where a lot of it's, it's happening. So from your point of view, what is modern Python?
- 6:51Before we get to hyper modern?
- 6:53Yeah, yeah, we definitely, we can talk about the language, the standard library, the ecosystem.
- 7:01I'd also add the community. I think that's something that really defines Python.
- 7:06Yeah, I agree.
- 7:07Yeah. And all that tooling that evolved in the ecosystem. So about the language, what really,
- 7:14because my, you know, my story is, I think I got into Python. Python was it like Python 2.3?
- 7:20So you've been through the journey, you've been through the great split and the rejoining.
- 7:25I pretty much missed a lot of the pain of the Python 2.3 transition. I've been busy with C++ and then
- 7:31came back to Python. And for me, it was just the enthusiasm of rediscovering all the great,
- 7:37like how expressive Python had become. One of the things that really get me excited about modern Python
- 7:43is type annotations. I just find them so helpful to structure programs, to make APIs clear,
- 7:51to help me think about my code and to keep it maintainable and readable. So I use them
- 7:56pretty much always. And I always run my Pi in strict mode. Even I'd even use it in small scripts.
- 8:03And it's, of course, very helpful in large systems. Absolutely. I don't know that I've,
- 8:09in fact, I'm, I'm pretty sure I've never gone end to end and taken a large system and completely made it
- 8:15100% my Pi checked, you know? Yeah. For me, I'm with you. I absolutely love
- 8:21the types. And I use them a lot to sort of drive the tooling intelligence. For example, like if
- 8:28you've got a data access layer, you could, you could talk about what is exchanged at the boundary there
- 8:32so that your editors are all of a sudden super smart about autocomplete. And, you know, I was just doing
- 8:38a massive overhaul to the course, Python courses website and change, change, like it was 110 commits
- 8:46in this PR. It was like ridiculous. But before I checked them all in, I went through and I said, okay,
- 8:51look for all the type warnings, look for anything that might've become like out of sync along the way.
- 8:56And I caught like one or two things before I accepted the, or merged the PR back in. So it's
- 9:02just, yeah, I absolutely think that's one of the most important additions.
- 9:05And they also, it's so nice how you can leverage them at runtime as well. It's not only that they
- 9:10allow you to check your code in a, in, in a way that doesn't require hitting every, every code path,
- 9:16but you can build a data validation on top of it. And so many more.
- 9:21Yeah, absolutely. I mean, look at libraries like Pydantic and FastAPI that are making interesting
- 9:26runtime use out of it.
- 9:28Absolutely.
- 9:28And speaking of modern Python, like there's the, there was that proposed change to make
- 9:34typing more efficient where it wouldn't actually import the things until really needed it. Or I
- 9:40can't remember the exact PEP, but it was a way to sort of delay type information imports until you're
- 9:44doing something like my PY and the Pydantic people and fast, you know, Sebastian and FastAPI. I was like,
- 9:49wait, wait, wait, wait, wait, wait, we need this. Like, this is how our thing works. If you take away the
- 9:54actual meaning other than for verification.
- 9:56Yeah. I think the stringification of the, of the types that makes it really hard for these use cases. And, and
- 10:03there's this other approach where they, where they basically lazily evaluate the types, I think, to avoid this
- 10:10string problem. Yeah. I don't know if they've, I think it's still an open question of how to, how to proceed this. They, they, they,
- 10:16we should have gotten the string types already and then decided to take some more time to,
- 10:22to find a good solution for everybody. Yeah. I think that was, was sort of delayed. I can't
- 10:27remember the total outcome, but I think it was like, we needed to think about this more and make sure all
- 10:31the use cases are covered. Right. Yeah. Cool. Okay. Well, that's the language. One thing that we could
- 10:37talk about real quick, that's pretty timely is this PEP. I just had Brett Cannon and Christian on
- 10:44to talk about PEP 594, removing dead batteries from the standard library, which, you know,
- 10:51it's pretty interesting. The idea is a lot of these libraries had been added. These core modules have
- 10:57been added to the standard library in like 1992. And they've, they might not still be relevant.
- 11:03For example, CGI is not the most common way to do web apps anymore. We've got uWSGI and
- 11:08the unicorn and all those things. Right. So does that still make sense to maintain them? Yeah.
- 11:13I think that the set of libraries to remove them was pretty non-controversial because they're just
- 11:19very, very old, obsolete, and also basically unmaintained. CPython is, has, I think like 90
- 11:27core developers and they, they have like 1,600 open PRs right now. So it's very hard to maintain a huge
- 11:35standard library with so little human resources. Yeah. So I think that was, yeah, pretty a good step.
- 11:43What I really find interesting is, is the vision behind it. Like where, where, where should the standard library go?
- 11:51How, what are the criteria in the future to, to include libraries? For example, we, I think usually,
- 11:57recently we got a Tomlip into the, standard library. Right. Yeah. To join JSON and CSV and XML and all
- 12:04those. Yeah. It's, it's, it started as a, as a PyPI library called Tomli and it's been adopted
- 12:11quickly by a lot of the tools out there. And now it's part of the, or it will be a part of the standard
- 12:16library. So this is, for example, this is something that is important to solve a, a bootstrapping
- 12:23problem in the packaging ecosystem, because we have PyProject Toml now, and how is pip going to
- 12:30pass the PyProject Toml file? For example, how are the other tools going to, to pass it? So it's,
- 12:35it's very advantageous to have it in the standard lib, but we probably don't want to have passes for
- 12:40every file format out there. I agree. So in fact, a lot of the ones that were removed
- 12:46in PEP 594 are actually having to do with file formats. So you've got like AIFC, which is an audio
- 12:53format. You have audio op, is it like the sun AU format? There's a bunch of, bunch of things like
- 12:59that. Right. So yeah. I don't want to dive too much into that because we've done a whole show on it,
- 13:04but I do think it's interesting to think about this as a modern, like the first step in a modernization
- 13:09of the standard library. Right. Yeah. And then where it really blows open. And I think an
- 13:13interesting inter, inter exchange sort of cross influence here is, as I already mentioned, the
- 13:18368,000 external packages that are building on a lot of the new language features that I think are,
- 13:25are super cool. And how much, you know, looking back, if that world existed already, how much smaller
- 13:31would the standard library be? Right? Like, would your lib ever have to be in there? Well, we got requests.
- 13:35I don't know. Maybe not. It could make a lot of sense for it actually to be there, like this
- 13:38bootstrapping problem you talked about, but maybe it doesn't, right? Like, I think different choices
- 13:42would be made, but yeah. What are your thoughts on the sort of ecosystem from the PYPI perspective?
- 13:48Mm-hmm. So if we look at the, at the 30, the third party libraries, I think for me, modern Python is a
- 13:55lot about expressive, expressive types, like Adhors for me is like the best example really to how to write
- 14:01well-structured code using Adhors just got a new API, which is really, really nice. And I can definitely
- 14:09recommend having a look at it. So it's become very easy to define immutable value objects, essentially,
- 14:18that will allow you to basically structure your domain logic in a really expressive way.
- 14:23Yeah, no, I was going to say that it did get a new API recently. I forgot that it,
- 14:26it kind of inspired data classes and then it sort of turned the tables on it a bit, right? And sort of
- 14:31rethought about how some of its stuff was offered as well, right?
- 14:34I love that we have data classes in the standard library because it's like a mini Adhors that you
- 14:40always have at your disposal, even when you don't want to take on third-party dependencies,
- 14:44but it's definitely always worth looking at Adhors. It's very fast and has a lot of features and it
- 14:50doesn't have this problem that you can only really update it once per year.
- 14:56Yeah. And that's a super interesting point. You know, they considered putting requests in the standard
- 15:01library for a while and requests is under the, I can't remember the exact organization,
- 15:05but it's under an official PSF. Maybe it is, I think it is just the PSF organization now on GitHub,
- 15:11right? It's sort of officially Python in a sense, but they decided not to put it into the standard
- 15:16library, not because it didn't fit or it wasn't good enough, but because it would actually slow down
- 15:20the development of requests and constrain it too much. And that's sort of similar here as well,
- 15:24right? Adders can come out every day with new stuff and data classes yearly, right?
- 15:29This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 15:36Starting a business is hard. By some estimates, over 90% of startups will go out of business in just their
- 15:42first year. With that in mind, Microsoft for Startups set out to understand what startups need
- 15:48to be successful and to create a digital platform to help them overcome those challenges. Microsoft for
- 15:53Startups Founders Hub was born. Founders Hub provides all founders at any stage with free resources to
- 16:00solve their startup challenges. The platform provides technology benefits, access to expert guidance and
- 16:06skilled resources, mentorship and networking connections, and much more. Unlike others in the industry,
- 16:12Microsoft for Startups Founders Hub doesn't require startups to be investor backed or third-party
- 16:18validated to participate. Founders Hub is truly open to all. So what do you get if you join them?
- 16:24You speed up your development with free access to GitHub and Microsoft Cloud computing resources
- 16:29and the ability to unlock more credits over time. To help your startup innovate, Founders Hub is
- 16:35partnering with innovative companies like OpenAI, a global leader in AI research and development,
- 16:40to provide exclusive benefits and discounts. Through Microsoft for Startups Founders Hub,
- 16:45becoming a founder is no longer about who you know. You'll have access to their mentorship network,
- 16:49giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation,
- 16:56fundraising, management and coaching, sales and marketing, as well as specific technical stress
- 17:01points. You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders
- 17:06themselves. Make your idea a reality today with the critical support you'll get from Founders Hub.
- 17:11To join the program, just visit talkpython.fm/foundershub, all one word, no links in your show notes.
- 17:17Thank you to Microsoft for supporting the show.
- 17:20I think that's an interesting aspect of like sort of modern Python as well, right? This ability to just
- 17:27continually deliver new features and adapt it as needed.
- 17:32I also really love C-Adder because you mentioned Pydantic before. What I really like about C-Adder, it has kind of a similar,
- 17:39so you can serialize and deserialize data classes and attrs. The difference between Pydantic and C-Adders is that
- 17:48Pydantic uses inheritance to give you this functionality, whereas with C-Adders, you just have your pure Python classes
- 17:57without any, they don't need to inherit from anything. You just have, you decouple serialization logic from
- 18:04your domain logic. And I think that brings a lot of advantages in structuring software.
- 18:10This is the right one I have on the screen here, this C-A-T-T-R-S.
- 18:14Right. Yeah.
- 18:14Yeah.
- 18:15Yeah. Interesting. So you can do things like put a frozen decorator onto just a regular Python class and
- 18:22hey, it's frozen. You can create an instance of it and you can say unstructure and you get a dictionary,
- 18:27you can structure it back until it would type, it parses it back, which is quite neat.
- 18:31Yeah.
- 18:31This one's new to me. Like I said, we're going to go through a lot of those,
- 18:34a lot of those different things. Anything else you want to like give a quick shout out to
- 18:38into the broader ecosystem before, like we'll dig into your hypermodern ones that you're using as well.
- 18:43If you haven't seen Rich and HTTPX, those are definitely some to check out. And HTTPX,
- 18:50basically we talked about requests. HTTPX has a very similar interface, but gives you both async and
- 18:56sync operations. Yeah.
- 18:58That's definitely a wonderful project.
- 19:00I use HTTPX a lot and it's really nice because it's so familiar if you know requests, but if you happen
- 19:06to find yourself doing cool async stuff, you're not stuck not doing async for one of the most
- 19:12important parts, which is calling services, right? So you can await doing a get or a post or whatever.
- 19:18Yeah, it's really nice. I'm not 100% switched to it instead of requests, but it's definitely one of
- 19:23my go-tos as well. Cool. All right. Well, so that's sort of some thoughts on modern Python and where things
- 19:29are going. Then you created this series, which is almost like a little mini course on how should you,
- 19:37from your perspective, how should you structure and build modern Python projects and what tools should you
- 19:42bring in? Not just should you use HTTPX over requests, but should you use Knox for testing and things like that?
- 19:50Yes, right.
- 19:50You might say yes for Knox.
- 19:52Given that you work on it, right? So you did this article, this six-part series article on it, which I'll definitely link to.
- 20:00But then also you created a cookie cutter template that'll allow people to jump into it.
- 20:06I find this to be really helpful. I do this sometimes with my classes. You're like, "Well, here's the thing we built at the end,
- 20:11but if you just want to create your own version of it, here's a cookie cutter to actually just create it with your settings and your values,
- 20:19so you don't have to go through rebuilding it from scratch." And cookie cutter has been really influential in that sense, don't you think?
- 20:25Absolutely. When I wrote the articles, there was example code on GitHub and I saw people forking the repository and I was like, "Oh, no.
- 20:34They're all going to end up with this example code that displays Wikipedia articles and you can so am I going to keep all the dependencies up to date?
- 20:44And how do I even do that?" And I was like, "No, I have to find a better way." And cookie cutter was definitely a good way to set up a project template.
- 20:54And also something that was much easier for me to keep up to date. So there's after two years, definitely quite a bit of drift between the article series, which is from January 2020,
- 21:07and the cookie cutter as it is today.
- 21:10Yeah.
- 21:10Yeah.
- 21:11Yeah.
- 21:11It's hard to keep an article or a video or a talk or whatever as a living thing that evolves as we gain more experience and stuff.
- 21:19But the cookie cutter template, that's like software.
- 21:21Yeah.
- 21:21Plastic.
- 21:21You can make it open source and have
- 21:23contributors that do some work for you, which is really, I'm extremely grateful for all the contributions I got there.
- 21:31Yeah, that's great.
- 21:32I see a bunch of contributors there.
- 21:33Now, first, let's start with the, just the term, hypermodern Python.
- 21:37What's the story with the naming here?
- 21:39I actually brought you, now this is only for those that have a camera in front of them, that this is,
- 21:44this is hypermodern Python.
- 21:45So this is not Python.
- 21:47This is a hypermodern chess game written in 1925.
- 21:51Oh, interesting.
- 21:52So this is where the name hypermodern really comes from.
- 21:56It was meant a little bit tongue in cheek.
- 21:58And also, I was very conscious that how's Python going to look like two years after I've written this article series.
- 22:06Yeah.
- 22:06The ecosystem evolves so quickly.
- 22:08I decided to stick all these images in the blog that are basically past versions of the future.
- 22:14It's a thing called retrofuturism.
- 22:16So they're basically all like images from the 1920s and so on about how people in the future may be going to fly to the opera using planes that look like little birds.
- 22:28Yeah.
- 22:29It's sort of a steampunk mechanical bird.
- 22:32People are cruising along in here.
- 22:34It's, yeah, it's a, it's a cool picture.
- 22:36It's a cool idea.
- 22:36So what is hypermodern?
- 22:38I think basically it's just whatever I was excited about and didn't know about beforehand.
- 22:44I had used some tools, like more of the standard tools, like setup tools and pip-tools and talks.
- 22:52And coming back to Python, I thought, wow, let's just check out all the things that have happened.
- 22:59And let's see how maybe that might solve a few of the problems that I had.
- 23:04Nice.
- 23:05Okay.
- 23:05So then you put together the article, which is, you know, it's a serious article.
- 23:10It's not just a couple of paragraphs, right?
- 23:12It's, it's quite a bit of writing.
- 23:14Six articles.
- 23:14Yeah.
- 23:15Six articles.
- 23:16And my little, or maybe it was your website.
- 23:18It's like 11 minutes reading for this part, that kind of, kind of thing.
- 23:21So it goes into pretty good detail with examples.
- 23:24And then you captured it in this cookie cutter because you said that to put it into practice,
- 23:28that's a pretty good way.
- 23:29Now using cookie cutter is super easy.
- 23:32You know, I'm sure people have, are familiar with this, but cookie cutter, give it the name.
- 23:36It asks a bunch of questions, right?
- 23:37Right.
- 23:38I think maybe the right way to explore this would be to talk about the features and the
- 23:44steps of the cutter that it does, right?
- 23:47There's on the page for the cookie cutter GitHub repo, there's a big section that says features.
- 23:52And that sort of talks about the different aspects and angles dimensions you decided to
- 23:57bring in and the tooling there.
- 23:59So how about we just go through these and sort of dive into them?
- 24:02I think, I think people are going to discover some cool tools here.
- 24:05So first of all, if you're going to build something meaningful, you've got to get some libraries off
- 24:11PyPI.
- 24:11Like there's very few projects that have no dependencies that are rich these days and not just rich the
- 24:17package, but you know, feature rich.
- 24:19Let's talk about the first one here.
- 24:21Okay.
- 24:21Take us through it.
- 24:22Yeah.
- 24:23So poetry really solved the problem for me because it's basically the one tool approach.
- 24:28You have one tool that does everything for you.
- 24:32It will allow you to define metadata for your package, build the package for you so you can
- 24:38publish it on PyPI.
- 24:40It can manage environments for you, install all the dependencies of your project and your project
- 24:45itself.
- 24:46And it can also manage the dependencies itself.
- 24:49So it has a resolution mechanism and it has a log file, which is for me, a really important
- 24:56feature because not only is it good for deploying services in a, in a reproducible and deterministic
- 25:03way, but it's also for running the checks on your code and making sure that the checks run exactly
- 25:10the same locally on your machine and CI with on and on the machines of your collaborators.
- 25:17Yeah.
- 25:17They're not as familiar with the poetry lock file as I should be, but basically it's like
- 25:23hitting your versions in a requirements.txt.
- 25:26Right.
- 25:26Right.
- 25:26But so often people just write, you know, here's my requirements.
- 25:29I have requests or httpx and I have FastAPI and I have SQLAlchemy or SQL model.
- 25:35And you just type those out and you pip install -r and you're good to go until you want
- 25:40to go back to an old version that might have a bug that that's the one in production.
- 25:44But the bug might be because it has the old library of whatever.
- 25:49Right.
- 25:49And you don't know.
- 25:50Right.
- 25:50So you want to be able to pin those versions.
- 25:52And then does the lock file also put the hashes in so they can't be fiddled with?
- 25:57It does.
- 25:57Yeah.
- 25:57Yeah.
- 25:58So it has the hashes and it gives you all the, basically the, all the indirect dependencies
- 26:04as well.
- 26:05So much like pip compile would do from the tools.
- 26:08Yeah.
- 26:08So, and that is tremendously useful.
- 26:11Yeah, it absolutely is.
- 26:13I'm a big fan of the pip-tools and pip compile.
- 26:16We'll get to that later when we talk.
- 26:18Yeah.
- 26:18Yeah.
- 26:18Yeah.
- 26:18When we get to, there's a section, a whole section in the cookie cutter about it.
- 26:22All right.
- 26:22So it starts by setting up with poetry, right?
- 26:25Absolutely.
- 26:26Yeah.
- 26:26I called poetry though, the one tool approach, and there has been a lot of work in the packaging
- 26:34community to introduce standards, packaging standards that make it easier for the tools to
- 26:40interoperate.
- 26:42And I think this is actually a very good way to approach things in an ecosystem like
- 26:49Python's to, to make it possible that you can define your package metadata for one tool,
- 26:55like flit, and then use poetry to build the package or PDM and so many others.
- 27:02And there has been a lot of great work that has made the packaging ecosystem more diverse.
- 27:09Yeah.
- 27:10Yeah.
- 27:10There was some separation of the architectures of certain responsibilities, right?
- 27:15Yes.
- 27:15Yeah.
- 27:15So there's perhaps six to one, which defined the metadata.
- 27:19There was also an attempt to, to standardize log files, which I think would be great, but
- 27:24that I've unfortunately has been rejected for now.
- 27:27So I'm hoping that there will be more attempts in the future, but so as great as it is to work
- 27:33with poetry, I definitely hope for the ecosystem to become even more diverse and more standardized,
- 27:39to really give us more flexibility and interoperability.
- 27:44Yeah.
- 27:44Yeah, that is great.
- 27:45Definitely seems like a lot of options are coming out around that these days.
- 27:49And then the next one here is test automation with Knox.
- 27:53What's your relationship with Knox, by the way?
- 27:55Are you the maintainer or are you just a contributor or where's this?
- 27:59I'm co-maintaining Knox.
- 28:00Okay.
- 28:00It was written by, by Thea Flowers and it has a large maintainer team.
- 28:04At the time that I wrote the article series, I was just a fan of Knox and I started contributing
- 28:10to it and I kind of ended up co-maintaining it.
- 28:13Whoops, I'm contributing more than anyone else.
- 28:16Does that make me more involved?
- 28:17All right.
- 28:18Yeah.
- 28:18So tell us what the role of Knox plays in this.
- 28:20So Knox is a great tool.
- 28:21It's not just test automation.
- 28:23It's really, it lets you automate basically all the developer tasks you have.
- 28:28So this might be tests.
- 28:30Okay.
- 28:30It might be the other checks you have like linting, or it could be building your documentation or
- 28:37building wheels.
- 28:39If that's complicated in, in any way you can just, the great thing about Knox is that it uses
- 28:45Python to let you define your, the tasks rather than basically having something like a make file
- 28:52where you use the shell or in talks, you, you have an any file where you enter your commands,
- 28:57right?
- 28:58At least talks three.
- 28:59I think talks for is also going to add Python configuration.
- 29:02So Knox, it's really, so it's really inspired by talks.
- 29:06I think so if you know talks, talks allows you to run tests on multiple versions of Python.
- 29:13Yeah.
- 29:13And it's been around for much longer.
- 29:15It's very mature tool.
- 29:16Knox is inspired by that.
- 29:18It also lets you have this matrix of Python versions or even other things.
- 29:24So you can similar to a pytest, you can parameterize your session functions and pass in,
- 29:32say like a specific dependency that you want to test against in different versions.
- 29:37So Knox is, is, is really useful if you want to have a single entry point into your, your project
- 29:45maintenance, running all the tasks that you have and running them the same locally and on CI.
- 29:50Yeah, this looks great.
- 29:51I hadn't really explored this, this Knox file thing where you have these different tasks,
- 29:57like a task, you know, task basically being a function.
- 29:59Like, so you say like tests or lint, and you can just put a session decorator on it and just
- 30:04say session dot install pytest, session dot run pytest or session install flake 8 and run it with
- 30:09the parameters.
- 30:10It's really nice and clean and it's, it's way better than a shell script.
- 30:15I think it keeps you in Python, right?
- 30:16Right.
- 30:17Which is probably where you want to be on Python project.
- 30:19And it runs on all the platforms.
- 30:20So at some point I use make files to automate these things.
- 30:24So the non-tox related things, I guess, don't work very well on windows.
- 30:29So you don't have this problem.
- 30:31Yeah, that's for sure.
- 30:33Cool.
- 30:33And then we kind of saw an example of that there, but linting with pre-commit and flake 8.
- 30:38Right.
- 30:39So it's about these two libraries.
- 30:40I love pre-commit.
- 30:41I actually, it wasn't in the first draft of the, of the article series.
- 30:47I got some reviewers who commented on that.
- 30:50I think Oni Fanchmitt from the pytest project and, and Hinnik Schlawak both mentioned that,
- 30:56you know, you have to cover pre-commit.
- 30:57And I was really skeptical.
- 30:59I had made bad experiences with these kinds of pre-commit hooks that run.
- 31:05So you make a git commit and then it doesn't work because you had some wrong white space in it.
- 31:13And I thought my, I want my commits to be really snappy.
- 31:15I'll, I just use Knox for that.
- 31:17But after hearing these comments, I thought I'm going to give it a try, you know, like it's a new
- 31:22tool, maybe it solves these problems much better.
- 31:24And it really does.
- 31:25I would really recommend anybody to give a pre-commit a try.
- 31:28Basically you drop a YAML config in your project that defines the hooks that you want to run.
- 31:38So this might be a hook that formats your code using black or that, that lints your code using
- 31:45flake eight or so much more there.
- 31:47There's an abundance of pre-commit hooks out there.
- 31:50Oh wow.
- 31:50Yeah.
- 31:51There's, there's probably 20 pages in the list of pre-commit hooks that are at the top.
- 31:56You click on supported hooks and pre-commit.com.
- 31:59Right.
- 32:00Pre-commit it's, so it's a git hook manager, but it's not just a git hook manager.
- 32:05It's also a, a linter framework and a multi-linter multi-language linter framework.
- 32:10So you can have your hooks written in, you know, Ruby, C++, you name it.
- 32:16And it's very easy to use them in a Python project or basically any, any language project.
- 32:25It works using git.
- 32:26So basically installs the tools from their git repository and you can run them as part of your
- 32:35git commits or all the other hook points that git offers, but you can also run it just in CI on your
- 32:43entire code base.
- 32:45And that's really what I, what I love about it is that it has this fail early philosophy.
- 32:50So you really get very early feedback, but it also works to, as a gatekeeper for your default
- 32:56branch and make sure that the, all the commits that go into your main branch are well-formed.
- 33:02This is interesting.
- 33:03I did have creator of pre-commit on the show quite a while ago.
- 33:08I talked about it, but I hadn't, I think maybe some of these are new or I hadn't really appreciated
- 33:11them before.
- 33:12Like one that's really cool here is check JSON as a pre-commit and it checks JSON files for
- 33:18parsable syntax.
- 33:19So basically as part of your commits, it says, well, here's, I'm guessing here's a changed
- 33:24JSON file.
- 33:24Is this, you know, can it just basically be loaded with, you know, JSON.loadf or load, give it a
- 33:30file.
- 33:30Right. And another one is, yes, you're supposed to have unit tests, but you might not have unit
- 33:35tests for everything.
- 33:36So check AST just means like, can Python parse the files?
- 33:39That's the word of like the compile, right?
- 33:41In a sense.
- 33:43Yeah.
- 33:43I mean, those are just like the first couple out of this 20 pages.
- 33:46So I'm, I need to come back to this and check Toml was another sort of similar to the check
- 33:50JSON, check YAML, check up XML and so on.
- 33:53Yes.
- 33:53There's a, this repository called pre-commit hooks, and that has lots of very small hooks that
- 33:59are tremendously useful.
- 34:01And then you have larger tools that also offer integration with pre-commit like flake eight,
- 34:07for example.
- 34:07This portion of Talk Python To Me is brought to you by the compiler podcast from Red Hat.
- 34:15Just like you, I'm a big fan of podcasts, and I'm happy to share a new one from a highly
- 34:21respected and open source company compiler and original podcast from Red Hat.
- 34:27With more and more of us working from home, it's important to keep our human connection
- 34:31with technology.
- 34:31With compiler, you'll do just that.
- 34:34The compiler podcast unravels industry topics, trends, and things you've always wanted to know
- 34:38about tech through interviews with people who know it best.
- 34:42I was a guest on Red Hat's previous podcast, Command Line Heroes, and compiler follows along in that
- 34:58excellent and polished style we came to expect from that show.
- 35:01I just listened to episode 12 of compiler, how should we handle failure?
- 35:05I really valued their conversation about making space for developers to fail so that they can learn
- 35:11and grow without fear of making mistakes or taking down the production website.
- 35:15It's a conversation we can all relate to, I'm sure.
- 35:18Listen to an episode of compiler by visiting talkpython.fm/compiler.
- 35:23The link is in your podcast player's show notes.
- 35:25You can listen to compiler on Apple Podcasts, Overcast, Spotify, Pocket Cast, or anywhere you listen to your
- 35:31podcasts.
- 35:31And yes, of course, you could subscribe by just searching for it in your podcast player,
- 35:35But do so by following talkpython.fm/compiler so that they know that you came from Talk Python To Me.
- 35:42My thanks to the compiler podcast for keeping this podcast going strong.
- 35:47On to continuous integration.
- 35:51I feel like GitHub Actions has really sort of taken hold in the Python space as a way a lot of people are doing stuff there.
- 35:58Absolutely. It feels like there was some kind of mass exodus from Travis CI to GitHub Actions.
- 36:04It's so flexible and it goes way beyond just running tests and like the normal, what you'd normally
- 36:13think of as CI. So you can automate a lot of your developer workflows centered around the collaboration with others.
- 36:21Nice. The type of stuff I work on doesn't super lend itself well to GitHub Actions.
- 36:26It does. It probably does somewhat, but it's not something I use that much.
- 36:29But it seems like if you had a package that had maybe complicated builds or something like that, you could even use it to build your wheels and stuff like that, right?
- 36:38Sure. Yeah. I mean, my the way I like to use it is to have most of the logic in Knox,
- 36:46because that means I can always just test it locally and see if everything, you know, debug it easily.
- 36:51And then I try to keep the GitHub Actions workflows pretty lightweight and just let them invoke Knox.
- 36:59I usually have a matrix with that contains the Knox sessions.
- 37:04So this might be the testing or running pre-commit or to lint the code or to build the documentations.
- 37:13If that that's all valid, then the matrix has the Python versions that I want to test on.
- 37:19Yeah.
- 37:20If I'm working on a library, it's important to support not just the latest Python version, but probably Python 3.6 onwards, maybe even the upcoming Python version.
- 37:29And then obviously platforms. So always, if you're, unless you're only working on one platform, try to have at least Linux and Windows, and then maybe, maybe macOS as well.
- 37:40Yeah. Yeah. Yeah. This is neat. You know, people talk about, well, we can't really test this on Windows because I don't have a Windows machine or vice versa. Can't test it on Mac or so easy.
- 37:49Yeah. So this here's your three platforms right here. Right.
- 37:52I'm not saying it's easy to debug it. If something goes wrong and you're only working on macOS or Linux, you probably at some point want to have a virtual machine with the running windows.
- 38:02If you don't have a physical Windows machine, but it's also not hard to get one these days, too. But otherwise, you know, it's very easy.
- 38:10To integrate Windows in your CI.
- 38:12Yeah, very cool. And then the next one has to do with documentation here.
- 38:16Right there.
- 38:17Sphinx, Mist, and Read the Docs. And one of the themes. So yeah, pretty.
- 38:22When I wrote the articles, it was just Sphinx and Read the Docs. Mist hadn't happened yet. So, well, Mist, maybe let's start with Sphinx, because I guess many people will already be familiar with it. It's a Python documentation generator. It's also used for Python's own.
- 38:40So for example, the library docs. It's been around for a long time.
- 38:46It's a very expressive language to write technical documentation.
- 38:54Sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too, sometimes too expressive. It's not the lightweight language that we know Markdown to be.
- 39:02Right.
- 39:03And Markdown has really conquered the world. And when I wrote the documentation chapter, I think I linked to an article by Eric Holcher from Read the Docs, comparing the two formats. And that was before, before Mist happened. And he said, you know, there's use restructured text. It's just so much more expressive. And it lets you have cross references. And all of these things has the powerful directives.
- 39:28Anyway, now we have Mist. And Mist allows you to do essentially the same thing in Markdown. There's an extension syntax, and you can have directives, you can have cross references. And it's a lot of fun to write documentation in Mist. So this was a recent addition to the project template to support Markdown documentation.
- 39:50And for those who don't know, I also I did have a show recently with the Mist folks, about Sphinx and Mist and so on. And there I learned that one of the things that's cool is you can inline restructured text. So if you get to a section, you're like, this is just Markdown. I want to do this. Do a little tiny bit of restructured text instead of living in it.
- 40:07You actually need to do that.
- 40:09You actually need to do that still for your generated API documentation. So Sphinx has this extension called AutoDoc that will take all the doc strings in your code and transform that into API documentation.
- 40:22And that still doesn't have a replacement. What you do is you write your doc strings, you know, using restructured text, maybe using Google style doc strings or NumPy style doc strings. And then you use the AutoDoc directive to basically quote it in line in your Markdown documentation.
- 40:42So that's a little bit of restructured text there. I think I'm working on filling this gap somewhere going on and I'm really looking forward to that feature coming because then everything will be just marked down.
- 40:54Yeah, that'd be great for sure. I do want to give a quick shout out to Paul Everitt's course that he wrote over at Doc Python on Sphinx. And listen, if you're interested, check out this free course that he put together for us over there. So that's worth checking out. Now I'll put a link in the show notes.
- 41:08Now, if you're building a Python package that goes on PyPI, like not everything people build with Python goes on PyPI or even should be structured in the shape of a package potentially. But a lot of them are right. A lot of libraries are. So you talk about automating uploads to PyPI and test PyPI. Want to talk about the story there?
- 41:28Yeah. So PyPI, the Python package index there actually has a sibling called test PyPI, which is just a separate instance. It's very useful to upload your wheels and sdiscs to test PyPI before you actually do a release because you can check them and see if everything is the way you expect it to be.
- 41:50Yeah.
- 41:51Yeah.
- 41:51And basically install the package end to end. And in CI, what I like to do is I have the switch where if it's an actual release, I upload to PyPI. But in all the other cases, I just upload to test PyPI. So every commit that goes into the main branch is going to be built and uploaded to test PyPI.
- 42:12You can't change what you put into PyPI. You can add new versions that replace it, but you can't change a version really.
- 42:19The best you can do is yank the release. It's still going to be there for those who have pinned the version, but otherwise it'll be invisible to those who just want to get the latest release. But yeah, there's no replacing.
- 42:32Yeah. So it's a nice reminder and automation to set up to remember there's test PyPI and automatically sort of have your project know and use it.
- 42:41All right. Here's another one. I want to talk about stuff I was learning. This one is definitely new to me. And this is cool. Automate release notes with release drafter.
- 42:49What's about release drafter? This is cool.
- 42:51So release drafter takes the titles of your merged PRs and it creates a draft release. So the release in this sense is the GitHub release. That is something that you can see on the right hand side of the GitHub repo page.
- 43:10You have this releases link and that basically gets you to either a list of tags or you can describe the changes. So it's essentially release notes on GitHub.
- 43:24So I think the release drafter is really handy for that. Now actually you can, so GitHub releases have an auto generate button. So some of this functionality you will actually get even without using the release drafter action.
- 43:49So I think the release drafter action is somewhat more flexible, what it gives you and basically means you're going to have to add a GitHub actions workflow for it and the configuration file.
- 44:03So you can provide a template for your release notes and some, you know, replacement marker that a placeholder that where all the PR titles go.
- 44:15I think it's cool. And it even has a draft, like you, you can see the draft release notes as well.
- 44:22Yeah.
- 44:23You can see it. And then you have a button to publish the draft release. And if you don't have a tag yet, that's also going to add a git tag to your repository.
- 44:32So that's a really lightweight approach to the release notes question.
- 44:39So I see that it has a what's changed, but I also saw in the release drafter had like bug fixes and stuff. Is there a way to teach it? Like these PRs are related to bugs and these are additions and stuff like that?
- 44:51Yes. You can do that using labels on your PRs. So if it's a bug fix and you have a label, you know, then you can put it under a separate section.
- 45:00Well, so basically just drive it with GitHub labels. Cool. All right. We got a lot to go through here. So maybe these next two are pretty quick here. Actually, the next three here.
- 45:07You talked about this sort of article and the cookie cutter drifting quite a bit apart because so many things have changed. One thing that seems to be pretty stable is like since black came out, people are all about just black.
- 45:19It hasn't seemed to gone out of style at all. I think that's pretty, pretty stable one, right?
- 45:24It really makes a huge difference for productivity. And I feel if I'm contributing to somebody else's project, it makes things so much easier to know that there's a consistent style.
- 45:35I don't need to be afraid to destroy somebody's, you know, well-crafted, handcrafted, formatted code. I can just run black. And it's also great, really helps readability. It's basically the style becomes invisible. So I love black. And black now, better status in January. So we now have like...
- 45:55Official black.
- 45:55Finally.
- 45:56Well known as hash 000000. There's no more debate.
- 46:01So yeah, I'm definitely, definitely a big fan of black.
- 46:04Indeed. I also give a shout out to Predeer as well. And then sort of related, you have import sorting with iSort.
- 46:11I've been using reorder Python imports for a long time, which is also a tool by Anthony Sotile, who wrote Precommit.
- 46:18Yes. I wanted to give Anthony a shout out, but I wasn't 100% sure that I had the name just right in my memory. So I didn't want to like misattribute it. But yeah, he also did Precommit, which I had him on the show for.
- 46:27Right. So these days, I actually like to use iSort, which is what everybody uses. It's since iSort 5, it's become much nicer to use. It uses the AST more. It has no trouble figuring out what your third party dependencies are.
- 46:42And it has an option. It has these profiles to make it really easy to be compatible with black style.
- 46:49And what I like to do is I like to put each import on a single line, which is actually what reorder Python imports does as well. And it greatly reduces the chance of merge conflicts.
- 47:03Oh, right. Okay. Yeah, of course. Cool. A quick question, stepping back to the release drafter. Michael out in the audience says his biggest hurdle is for doing regular and good release for doing regular and good releases are change logs.
- 47:16How does release drafter sort of fit into that? Basically, if you structure everything as a PR, it'll capture it?
- 47:23Yes. So release drafter only drafts the GitHub release for you. If you want to have, say, a page in your Sphinx documentation, you're going to need to pull that out. There's actually a...
- 47:37I'm sorry. That's his GitHub handle. I'm sure we should put a link later, but there's a tool that will pull the GitHub release and insert it into your Sphinx documentation. So you can do that.
- 47:50And there's also TownCryer, which really should be mentioned, and Scriv, which was written by Ned Batchelder. Those are tools that allow you to add release notes to your PRs as snippets or fragments. And that scales very well if you have an open source project with many contributors. So yeah, it's still figuring out the best way to maybe integrate all of these in some way.
- 48:16Sure. You can overdo it for sure. All right. I think a quick, just a quick shout out. Speaking of Ned Batchelder, we have pytest, Coverage.py, and CodeCov all in there is neat. And then CLI interface with Click. That's an interesting one, a popular one as well.
- 48:33Absolutely. So that's from the Palace project. So the same family of projects like Flask. There's also a nice wrapper for Click called Typer.
- 48:42Yes.
- 48:42It's written by the FastAPI author.
- 48:44Yeah. When I saw that using Click, I'm like, hmm, you're such a fan of types. Maybe Typer is also relevant here.
- 48:49Actually, I just had another look at Typer and I think I do like it after all. I actually really like it. Initially, I was like, well, it's actually not so. I kind of like how Click gives you these decorators and separates your option help texts from the actual function.
- 49:06But it is true that Typer really reduces duplication because you don't have to repeat the types of your options. They're just type annotations of your parameters. So that's really neat.
- 49:17Nice. Continuing with the typing story, we've got two things here. A static type checking with mypy. I suspect a lot of people who are really into typing know about this.
- 49:25Like the CLI, you run against your code and it'll make sure everything hangs together. If this function is calling that function with that variable, and you said that variable is one of the things that make sure that all is going to fit together.
- 49:35And if you get that working, then you might be open to having something like mypyc for optimizations and so on, which is also interesting.
- 49:42But one that maybe people haven't heard about is runtime type checking with Typeguard.
- 49:46Right. I think it's really one of the most undervalued projects out there in the typing space. Typeguard is so useful.
- 49:54When I first heard about it, I was like, why would you want to runtime type check your code?
- 49:59If you have a static type checker, you know why?
- 50:02Then you need to hit all the code paths.
- 50:05Static type checking is great because it can just basically deduce the type correctness.
- 50:11Typeguard is really useful if you're, for example, if you're interfacing with third-party libraries who may or may not have type annotations.
- 50:21If they do, great.
- 50:22But you know, how much do you trust them?
- 50:25Right.
- 50:25Yeah.
- 50:26Just because it says it, nothing enforces that where it said it returns an int.
- 50:30It could return none.
- 50:31Yeah.
- 50:31And it should have said optional int, but it didn't.
- 50:33Your code can absolutely have type correctness as far as mypyc is concerned.
- 50:37But that might be just because there are some any types or it's just kind of a loosey type because there's no way to be stricter about the actual types.
- 50:47And Typeguard will check that.
- 50:48So the way I like to use Typeguard is as a pytest plugin.
- 50:53So you're basically running your test suite.
- 50:56And if you have complete code coverage, that should give you a good chance to catch any type.
- 51:02Oh, interesting.
- 51:03So you can turn it on while your tests are running and it will runtime check everything.
- 51:07But then in production, not turn it on?
- 51:10Exactly.
- 51:10You basically specify it.
- 51:13So you install it next to pytest and then you pass an option.
- 51:17I think it's Typeguard packages and pass the name of your package.
- 51:21And then Typeguard is going to wrap every function in your code and check the parameter types and the return type.
- 51:31So that's really useful.
- 51:33It's also a library.
- 51:33So if you want to explicitly check in production, you can also use Typeguard for that.
- 51:38Nice.
- 51:38Yeah, it's got the type checked decorator, which probably you can just put that on stuff you want to make sure it's checked.
- 51:43Exactly.
- 51:43Okay.
- 51:44Well, that's a good one to learn.
- 51:45Another one is you create your project.
- 51:48You start building it.
- 51:50Two years later, you know, some feature is added.
- 51:53Some other language feature might be not the way to do things.
- 51:56So you talk about automated Python syntax upgrades with PyUp upgrade.
- 52:01Yeah.
- 52:01That's another Anthony Sotile tool.
- 52:04So it's also, you can run it from pre-commit.
- 52:08It's going to essentially pass the AST of your, so the abstract syntax tree of your code and look for things that have better ways to express them in your versions of Python.
- 52:22So basically what you say, you drop Python 3.6 and automatically you get unions like the pipe.
- 52:31Right, right.
- 52:32Like int pipe none versus optional bracket int.
- 52:35Something like that, right?
- 52:36Yeah.
- 52:37These kinds of things.
- 52:38Or yeah.
- 52:39Giving you nice set comprehensions.
- 52:42Yeah.
- 52:42Kind of like calls to the set built in.
- 52:45Those of these.
- 52:46And it's very nice if you're supporting multiple Python versions and you've been waiting to use this feature.
- 52:52And now finally you can drop the last Python version that didn't support it and you get this for free.
- 52:58I just run.
- 52:59Yeah, that is interesting.
- 53:00I hadn't really thought about that.
- 53:02You know, some of these are not language features in the sense that people are thinking, oh, well now I can use async and await, which would take like a real important, significant change.
- 53:12But it's just like, oh, you, you know, now you're able to, because of PEP 289, pass a generator directly to the min function or max or sum rather than a list comprehension, which then gets processed, right?
- 53:25And that would just be more efficient across the board.
- 53:27And so that just happens automatically, right?
- 53:29Cool.
- 53:30Yeah.
- 53:30Very neat one.
- 53:30All right.
- 53:31Next.
- 53:31Security audits.
- 53:33There's Bandit.
- 53:34Bandit is a tool that looks at your Python code and figures out if there are any things that may or may not give you a security vulnerability or any kind of security issue.
- 53:47It flags some things like just importing a subprocess and you can no QA it.
- 53:54I still find that useful because it just gives me a moment to think about all the implications of spawning other processes from our Python code.
- 54:03And, but it, it has a lot of checks in your, in your Python code base.
- 54:08So it's, it's very nice to use it to guard yourself against some.
- 54:12Right.
- 54:13Like it'll detect things like YAML dot load should be YAML dot safe load.
- 54:18And I bet there's something there about pickling.
- 54:21Yeah, for sure.
- 54:22It's caught of me.
- 54:23Could be.
- 54:24All right.
- 54:25Yeah, exactly.
- 54:26Safety is the other one.
- 54:28Yeah.
- 54:28That basically just checks your dependencies.
- 54:30So there's a, there's a curated database of security vulnerabilities and it's going to see if you have any dependency in a version that was vulnerable.
- 54:39Nice.
- 54:40And just stepping back to some moment, Nick Ma points out that hyper is amazing when it comes to the documentation in the --help option.
- 54:49Yeah.
- 54:49Pretty cool.
- 54:50Let's see.
- 54:51Going back to, yeah.
- 54:52Checking the documentation with xdoc test.
- 54:55So xdoc test is essentially a rewrite of a standard library or utility.
- 55:01It's called doc test.
- 55:02And what does it do?
- 55:04So suppose you have a doc string with an example code that shows how you, how you're supposed to use a library or a function.
- 55:11And you commonly write these with a, the Python interpreter prompt to give you like, what, what does the user type import my package?
- 55:20And underneath you have the output of whatever, you know, functions you call it and so on.
- 55:26So doc test runs these examples and sees if they produce the expected output, they don't throw a raise exceptions and so on.
- 55:34xdoc test is a rewrite that uses the AST more than regular expressions, which is nice.
- 55:41And it's also a bit more flexible.
- 55:42So has a few nice features compared to doc test.
- 55:47Right.
- 55:47Cool.
- 55:47So if you have an example in your documentation, here's a way to automatically make sure it's all good.
- 55:53Also another audience question, follow up here.
- 55:56Vasil asks, what do you think about services like Sink, S-N-Y-K, S-N-Y-K, S-N-Y-K, to check dependencies, like for security, right?
- 56:06So you depend on Flask, Flask depends on it's dangerous, it's dangerous.
- 56:12Who knows?
- 56:13Theoretically could have some issue like that kind of check.
- 56:16I'm thinking he's asking.
- 56:16I haven't used S-N-Y-K yet.
- 56:17So I'm only familiar with, with safety.
- 56:21Nice.
- 56:21Okay.
- 56:22Cool.
- 56:22Getting close to the end.
- 56:24Then I have a question about all of these taken as a whole.
- 56:26All right.
- 56:27Generating API documentation with Autodoc and Napoleon.
- 56:31Right.
- 56:31So we talked about this before.
- 56:33This takes, it takes your doc strings and generates API documentation.
- 56:36Right.
- 56:37And this is not a RESTful API, like Swagger, OpenAPI.
- 56:41This is, this is like my Python libraries function documentation, right?
- 56:45Exactly.
- 56:46Yeah.
- 56:46That's so the reference for your, the functions in your, in your package.
- 56:51Got it.
- 56:52Right.
- 56:52Right.
- 56:52Right.
- 56:53Right.
- 56:53And Napoleon is a tool that will add support for doc strings that are written Google style,
- 57:00for example, or some other conventions for doc strings.
- 57:02So Google style is pretty lightweight, which I'm a fan of that as well.
- 57:06Yeah.
- 57:07Yeah.
- 57:07Yeah.
- 57:07Declaring your arguments and, and returns.
- 57:10Okay.
- 57:10Nice.
- 57:10Generate command line reference with Sphinx click.
- 57:14So I'm guessing if you're using click might be relevant.
- 57:18Right.
- 57:19So you already have all your option help texts and, you know, command descriptions in, in click.
- 57:26So why not just use them to generate the documentation.
- 57:29And that's basically what Sphinx click does.
- 57:32So it takes, so you, when you build your documentation and you use things like autodoc or Sphinx click,
- 57:39you have to remember to install your own package.
- 57:41And then these tools can just import it and read the, read all the documentation that you have inline in your code,
- 57:47including click option up text.
- 57:50Yeah.
- 57:50Very cool.
- 57:50All right.
- 57:51You've done all the work documented it.
- 57:54You've tested it.
- 57:54It's good to go.
- 57:55How are you going to release it?
- 57:56Put it on GitHub.
- 57:57And the last one is managed project labels with GitHub labeler.
- 58:00So the idea of labeler is that you, instead of going through the web interface and then typing in all the,
- 58:10color codes and hacks and so on, you, you can just use, a file that you put in your repository to manage all your,
- 58:18all your labels for your PRs and for your issues.
- 58:21So that's really helpful and makes it really easy if you're collaborating with other people.
- 58:26Nice.
- 58:26Yeah.
- 58:27That's great.
- 58:27Okay.
- 58:28Well, that's your cookie cutter.
- 58:30And in one fail swoop, in one single CLI cookie cutter command, you get all of these.
- 58:36So when this runs, I should have just run it and played with it.
- 58:39But does it give you an option to say, you know, don't install mypy or does it just kind of give it all to you?
- 58:46What's the, I know cookie cutter has a lot of conditional behaviors and stuff.
- 58:50Like what's the experience of using this to create a project?
- 58:52I have personally resisted putting in too many options.
- 58:56It's kind of, I try to find, to kind of show one way that works and also keep it maintainable.
- 59:03So I don't have a lot of, I don't want the combinatorial explosion.
- 59:07There's a little bit of options that it gives you.
- 59:10So you can choose the license, for example, and cookie cutter allows you to hide or show parts of your file tree, depending on what the user chose.
- 59:19But basically it's not meant to be the, all the different packaging tools, all the different ways like talks, knocks, the different CIs that there was a conscious decision to basically say, okay, here's one way to do it.
- 59:32And I can really curate it and make sure that it all works.
- 59:36Sure.
- 59:36Keep it opinionated and straightforward and whatnot, right?
- 59:40I suppose if people really wanted to use talks instead of knocks and they wanted to use typer instead of click, they could fork the repo, create their own template, right?
- 59:48And roll with that.
- 59:49Yeah.
- 59:49Cool.
- 59:49All right.
- 59:50Well, very interesting.
- 59:51One more quick audience question here from Michael says, can labeler, as in GitHub labeler, export existing settings?
- 59:58It'd be great to unify labels across repos.
- 1:00:01Any idea?
- 1:00:02Right.
- 1:00:02I think there is a separate tool to do that.
- 1:00:06So I don't think that GitHub labeler does it, but I remember that that was actually a community contribution.
- 1:00:13And I remember that the contributor who added this feature first went and exported the existing configuration from whatever we had in the repository.
- 1:00:23Okay.
- 1:00:24Yeah, cool.
- 1:00:24So.
- 1:00:25Yeah, very nice.
- 1:00:25All right.
- 1:00:26Well, we are just tiny bit out of time here.
- 1:00:30So unfortunately, even though there's a bunch of other stuff I wanted to cover, I don't think we're going to be able to because we cover so many cool things.
- 1:00:37You know, I did want to just give a quick shout out to your music.
- 1:00:41And in addition to being a lawyer and a software developer and open source person, you also do like compositional stuff.
- 1:00:48Right.
- 1:00:49So you've got on your website, you've got a whole section.
- 1:00:51How many videos here?
- 1:00:52Like 10 different music videos that you've put together that are pretty neat.
- 1:00:56You want to just give a quick shout out to that?
- 1:00:58Yeah.
- 1:00:58So I spent, I think, 10 years working both as a software engineer and a touring and recording musician.
- 1:01:06Also as an arranger.
- 1:01:08So I arranged some string quartets.
- 1:01:11So I did arrangements for Naima Hussaini, who's a German indie singer.
- 1:01:17Definitely check her.
- 1:01:19Jack E.
- 1:01:20I've been on tour with her already across all of Europe and wonderful reggae inspired singer.
- 1:01:27And there are so many more.
- 1:01:29Yeah.
- 1:01:30It's, yeah.
- 1:01:32I'm very grateful for the musicians I've been able to play with.
- 1:01:36Yeah.
- 1:01:37That's fantastic.
- 1:01:37I listened to a bunch of them.
- 1:01:39My favorite is Immer Alles Kustisch im Deutschen Theater.
- 1:01:43That's the one with Naima Hussaini.
- 1:01:45That was a really good one.
- 1:01:47They're all good.
- 1:01:48But that one was really excellent.
- 1:01:49And then Michael also thinks that we should have a whole podcast about your compositional tools.
- 1:01:54Do you use Python for any of this stuff?
- 1:01:56Or is it kind of a separate world?
- 1:01:57Sadly, it's pretty much a separate word.
- 1:02:00I've been using Ableton a lot.
- 1:02:02And we didn't really get into automating all of this with Python yet.
- 1:02:07Not yet.
- 1:02:08Not yet.
- 1:02:09Also.
- 1:02:09I think Lucas Lange does this kind of stuff, though.
- 1:02:12Yeah.
- 1:02:13Cool.
- 1:02:13It can be done.
- 1:02:14Yeah.
- 1:02:14People should check out Fox.
- 1:02:15Are you familiar with Fox.
- 1:02:17And that whole programming with composition, building up music with Python?
- 1:02:22Have you seen this?
- 1:02:23I know.
- 1:02:23Oh, my gosh.
- 1:02:25I've got to check this out.
- 1:02:26Every time I search for it, Fox.
- 1:02:27I think it's Fox.
- 1:02:28Python.
- 1:02:29I think that's what it is.
- 1:02:30Check out the videos.
- 1:02:31There's some neat live coding music with Fox.
- 1:02:35And Python.
- 1:02:35Every time I just randomly pick one of these videos, it's not really necessarily the best one.
- 1:02:40But there's some really neat ones of sort of like adding instruments in with Python.
- 1:02:43It's cool.
- 1:02:44People should check that out.
- 1:02:45Yeah.
- 1:02:46All right.
- 1:02:46Well, we are out of time.
- 1:02:49Really quickly.
- 1:02:50Final two questions.
- 1:02:51You're going to write some Python code.
- 1:02:53What editor are you using these days?
- 1:02:54I use Space Max.
- 1:02:55I've been using Emacs for a long time and use it with VI bindings now.
- 1:03:00I like it.
- 1:03:00Right on.
- 1:03:01And I'm almost hesitant to ask you for a notable PyPI package because we covered so many.
- 1:03:06But maybe just like, you know, what one stands out to you?
- 1:03:08Like you want to just give a shout out to either one we covered or...
- 1:03:10I just named TypeGuard because it really deserves...
- 1:03:14Okay.
- 1:03:14TypeGuard 3 is going to come out hopefully soon, bringing new features.
- 1:03:18Cool.
- 1:03:19All right.
- 1:03:19Well, final call to action.
- 1:03:21People want to get started.
- 1:03:22This hypermodern project idea that you've created, what do they do?
- 1:03:25So just go to the cookie cutter hypermodern Python repo.
- 1:03:29Check out the contributor guide and the code of conduct.
- 1:03:32And we love contributors.
- 1:03:35So...
- 1:03:36Hold on.
- 1:03:36How relevant is going back and reading the article?
- 1:03:39Has it drifted too far or is it enough to get like some of the zen?
- 1:03:42Or if you've listened to this, are you kind of good to go?
- 1:03:44I think the article series is still fun to read.
- 1:03:47I think these days what I would recommend is that you don't just take the example code.
- 1:03:53Maybe just generate a default project from the cookie cutter and then take a look at that as well.
- 1:04:00Because some things have changed in the two years.
- 1:04:03But the article series kind of gives you the motivation for everything.
- 1:04:07And it's probably also more fun to read than the user guide for the project template, which is also there and very detailed.
- 1:04:14But yeah.
- 1:04:15Yeah.
- 1:04:15Fantastic.
- 1:04:16All right.
- 1:04:16Well, thank you so much for being on the show.
- 1:04:18And congrats on the cool project.
- 1:04:19Thank you very much.
- 1:04:20You bet.
- 1:04:21Bye.
- 1:04:21Bye-bye.
- 1:04:22Bye-bye.
- 1:04:23This has been another episode of Talk Python To Me.
- 1:04:26Thank you to our sponsors.
- 1:04:27Be sure to check out what they're offering.
- 1:04:29It really helps support the show.
- 1:04:30Starting a business is hard.
- 1:04:33Microsoft for Startups, Founders Hub, provides all founders at any stage with free resources and connections to solve startup challenges.
- 1:04:41Apply for free today at talkpython.fm/foundershub.
- 1:04:46Listen to an episode of Compiler, an original podcast from Red Hat.
- 1:04:50Compiler unravels industry topics, trends, and things you've always wanted to know about tech through interviews with the people who know it best.
- 1:04:58Subscribe today by following talkpython.fm/compiler.
- 1:05:02Want to level up your Python?
- 1:05:04We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:05:08Our content ranges from true beginners to deeply advanced topics like memory and async.
- 1:05:13And best of all, there's not a subscription in sight.
- 1:05:16Check it out for yourself at training.talkpython.fm.
- 1:05:19Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 1:05:23We should be right at the top.
- 1:05:25You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:05:34We're live streaming most of our recordings these days.
- 1:05:38If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:05:45This is your host, Michael Kennedy.
- 1:05:47Thanks so much for listening.
- 1:05:48I really appreciate it.
- 1:05:49Now get out there and write some Python code.
- 1:06:07I'll see you next time.
- 1:06:12Thank you.