Skip to content
Melo Podcasts Home
CategoriesLanguagesFollowing

Episode notes

Lint the entire CPython code base from scratch. It takes 0.3 seconds. Three blinks of an eye. That is ruff, and it is written in Rust. So are Pydantic, Polars, uv, and Granian. Rust shows up in Python three ways: tools that happen to be Rust, libraries Python imports, and servers that run Python inside Rust. This is Rust for Python developers, not Rust experts. Christopher Trudeau is back on Talk Python to discuss Rust and his latest course Up and Running with Rust. The core rule is that only one thing can own a value at a time. Pass it around freely in Python and the garbage collector…

Transcript

Read the transcript · about 13,230 words, follows along as you listen

Michael Kennedy:Lent the entire CPython code base from scratch. It takes 0.3 seconds, three blinks of an eye. That is rough, and it's written in Rust. So are Pydantic, Polars, uv, and Granian. Rust shows up in Python in three ways. Tools that happen to be written in Rust, libraries Python itself imports and runs, and servers that themselves run Python inside of Rust. This episode is Rust for Python developers. And Christopher Trudeau is back on Talk Python to discuss Rust and his latest course up and running with Rust.

Michael Kennedy:The core rule is that only one thing can own a value or variable at a time. Pass it around freely in Python and the garbage collector cleans it up. Do that in Rust and you get a compiler error. This is Talk Python To Me, episode 563, recorded Wednesday, September 9th, 2026. Welcome to Talk Python To Me, the number one Python podcast for developers and data scientists. This is your host, Michael Kennedy. I'm a PSF fellow who's been coding for over 25 years.

Michael Kennedy:Let's connect on social media. You'll find me and Talk Python on Mastodon, Bluesky, and X. The social links are all in your show notes. You can find over 10 years of past episodes at talkpython.fm. And if you want to be part of the show, you can join our recording live streams. That's right. We live stream the raw uncut version of each episode on YouTube. Just visit talkpython.fm/youtube to see the schedule of upcoming events. Be sure to subscribe there and press the bell so you'll get notified anytime we're recording.

Michael Kennedy:This episode is brought to you by Sentry. You know Sentry for the error monitoring, but they now have logs too. And with Sentry, your logs become way more usable, interleaving into your error reports to enhance debugging and understanding. Get started today at talkpython.fm/sentry. And it's brought to you by the Talk Python in Production Book, an inside look at 10 years of the real-world DevOps behind the Talk Python sites and apps. Check it out at talkpython.fm/DevOpsBook.

Michael Kennedy:Christopher, welcome back to Talk Python To Me. Always nice to hang out with you.

Christopher Trudeau:Yeah, thanks for having me back.

Michael Kennedy:I feel it's going to be a little old-fashioned, a little rusty.

Christopher Trudeau:Yes, let's just start with the crap jokes and get them out of the way, yes.

Michael Kennedy:Yeah, oh yeah, this might not actually be the final Ferris joke or whatever, but no, we're going to talk about Rust for Python devs, specifically not for Rust experts, But I want to know enough Rust so that things like Pydantic, ty, if I ended up poking around them or some other extension, it would make sense, right? Or maybe write a little bit of Rust to speed up some of your Python code. It's obviously the most influential way to make Python extensions or core faster pieces, right?

Christopher Trudeau:It seems to be the new way of doing things. And in fact, I saw something in the news this morning that one of the major CPU providers is switching to Rust for a lot of their device drivers and things like that. It does seem to be having its day.

Michael Kennedy:Yeah, absolutely. My joke used to be that if you switch to Rust, you're probably going to get VC funding. That was like three or four years ago. You know, that was when Astral and Pydantic and all that stuff happened.

Christopher Trudeau:Now it needs Rust plus AI, but I think that's still true. So, yeah.

Michael Kennedy:Exactly. Now it's AI is the cornerstone, but if you could do Rust and AI, we.

Christopher Trudeau:Why not? Yep.

Michael Kennedy:Why not? Just bring them all in. No, it's a really cool foundation for Python things. So we're going to talk about that and dive into it, compare it to Python, give some examples, give some tools, all those things. But it's been a while since you've been on. Give everyone a quick introduction of who you are and what you've been up to.

Christopher Trudeau:So yeah, I'm a consultant. I mostly spend time working with teams either on architecture or technical processes. That tends to mean things like agile and lean and automation, CI/CD, all that kind of good stuff. And in my spare time, I still do a fair bit of teaching. And sometimes that's in person, sometimes that's virtual, and sometimes that's creating online courses for people. I spend a fair amount of my time in the Python space. I'm co-host of the Real Python podcast.

Christopher Trudeau:So that tends to be where people, if they know my voice, that's from where. And lately I've been getting into Rust and figured you and I could chat about that.

Michael Kennedy:A lot of really cool things you're doing. I guess let's talk about getting into Rust. First of all, what was your background? Did you do C++, C, other compiled languages? Because it's a shift, right?

Christopher Trudeau:Well, so this is it, right? You hear the rust is a hard language to grasp thing. And I don't, I didn't find it that way, but I don't want to diminish people who are saying that, right? Like this isn't because I'm so much smarter or anything along those lines. It's because I have that background. I was writing C when I was 13 or 14 years old. There weren't a lot of choices when I started out. So I have a grounding and, you know, I wrote device drivers and I wrote embedded systems uh don't haven't done it in a long time but i have that grounding that rust kind of expects you to have and it's closer to the machine there's less virtualization going on uh it's a lower level language than something like python uh in fact uh bob builder russ and i were talking about this because he's got into rust recently and he came from php and python so from that it's this whole other kind of experience and he was talking about the fact that he actually thinks it's made him a better Python developer because now he's thinking about memory and stuff like that a little more

Michael Kennedy:than you necessarily would if you've just come from Python. That's really interesting. I hadn't really thought about it because you and I are, I think, around basically the same age, at least technologically speaking. And I remember getting the C++ Primer Plus. This is so nice. C++. It's so much better. Yes. I just loved working in C++ and so on. So I've never known a world where I came to Python or JavaScript or other languages where I didn't already have that experience of, you know, void star star.

Michael Kennedy:What do I do with that? Exactly. These kinds of things. But, of course, that makes sense. You come from Python and PHP, and then you're like, whoa, why am I doing all this stuff? This is crazy.

Christopher Trudeau:Yeah. And it's, you know, a big part of it. And I think the thing that folks who are coming to it from languages like Python find difficult is that whole memory management thing. And Python basically takes care of that for you. And so if you've never had to do that before, all of a sudden it's like, I have to do what? And why do I have to do that? And it can get a little persnickety. It's concept of only one thing can own a value at a time. it has objects, but the objects belong to somebody. And in Python, you just pass those things around willy nilly and you don't worry about it. And the garbage collector takes care of it.

Christopher Trudeau:And that often turns into a compile error in Rust. And that's on one hand, it's the beauty because it makes sure that certain kinds of bugs don't happen. On the other hand, if you're not used to it, you know, there's a, there's a joke in the Rust world that there are no bugs. It's, it's all your time isn't debugging. All your time is getting it to compile. And that's because there's a lot of that, Oh, I'm just going to pass this around and wait, I can't.

Christopher Trudeau:And so, yeah, that there's a lot of upfront work there. And I think for a new developer, that could be very frustrating because, you know, you don't, you can't play as easily. There's the threshold to getting started with something is higher because you're constantly kind of fighting the compiler. The flip side of it is their compile messages are absolutely fantastic. They, so when errors happen, they're very, very explicit. they often include something like maybe you need to do this.

Christopher Trudeau:And from what I saw, they were right 80 or 90% of the time. So once you figure out the language, I mean like the, not the language of Rust, but the vocabulary they use for error messages, it's very much, oh, oh, okay. So that's kicking off the borrow checker. Now I understand that. Okay. I'll go fix it. So there's a few things you kind of have to learn to get to that, but it is fairly helpful. But again, that could just be my background and remembering days of C where the compile error was being triggered from three lines before it was actually talking about where the error was.

Christopher Trudeau:And you kind of had to zone in around roughly where it was reporting it to figure out what had gone wrong. So, yeah, there's been some advances in technology since we were tapping out bits and bytes on rocks. Yes.

Michael Kennedy:Exactly. Making sand think. So I would like to just acknowledge it. Six minutes, 57 seconds into the recording. Borrow Checker. Yeah. Borrow Checker's been shouted out.

Christopher Trudeau:Yes. Yeah. Maybe we should just do the quick version of that. We'll probably dig into it a little bit more.

Michael Kennedy:Before you do, I just want to wax poetic. Think back to the days of back in the 90s. I remember when I had my C++ Primer Plus book. And yes, folks, it was a book that was like the yellow pages. There was no, literally the internet did not exist. Well, the internet existed. There was Gopher, there was Telnet, but the World Wide Web did not exist at this time, like not for four or five more years. Anyway, I remember thinking, oh my gosh, this is so hard.

Michael Kennedy:This is so much work when I'm learning it. And finally, finally I got it to compile. Like, oh, we're good at compiles. Like, no, no, no, no. That's just when the actual real hard debugging, problem solving starts. But you mentioned that with Rust, that the compiler checks are a little bit stronger. They check more things like proper memory management and variable sharing and things like that. So I think while it was a eye-opener that compiling was only the beginning of my suffering when I was learning programming, I think compiling does mean more in Rust than it used to in other languages.

Christopher Trudeau:Yeah, there's a whole family of bugs that have to do with memory management. And what's worse is they tend to be a tricky set of bugs. They're the kinds of things that will crash sometimes. So if you go back to C and how it stores a piece of text in memory, it has the, you know, like, let's say we're storing the word Talk Python. Well, we take the bytes for Talk Python and then we put a null on the end of it. And the compiler, when the code is working with it, it looks for that null.

Christopher Trudeau:And that's how it knows that the string is finished. Well, if you accidentally write something longer than that, there'll be no null and it'll keep walking past that into the next chunk of memory. If you free the memory up, but you still have a pointer that points into that memory. Yep. But your computer will happily read that. And if you've got two strings in a row, what'll happen is you'll get the first string and then the lack of the null, and then you'll get the next string.

Christopher Trudeau:And you might get a wrong message on the screen, but it won't crash your program. But if you get a string and then some memory that is a little more tricky, then all of a sudden you might actually be doing something like causing your program to fall over. So rust isn't bug free, but there is a category of bugs that it just doesn't let you create. And that makes it harder to compile, but a beauty to work with in the fact that a lot of the things that you might struggle with that are harder to debug are gone.

Christopher Trudeau:Right. You know, I thought the nature of Python is the looseness of the type system and the dynamicism of it means you can get moving very, very quickly. But if you're not using a type checker, type mismatches are things you discover at runtime. All of that is very strict and very well managed in Rust. And so those kinds of problems just don't exist.

Michael Kennedy:That's awesome. It also takes it's also mind bending. It is. In some ways, right? It's the way you think the way a lot of the ways you think about solving problems in C++ or C or Python can be kind of the same in Rust. Some of these limitations sort of change the algorithms and the data structures that will work in those worlds. Yeah. Yep. Well, and, you know, take

Christopher Trudeau:something as simple as an integer in Python. They're boundless, right? And if you're doing certain kinds of math, that's fantastic. There's no upper limit. Python takes care of all of that for you. It figures it out. I actually saw an article a couple of weeks ago where somebody was building a SIMD machine based on integer, based on, doing bitwise operations on massive integers, right? Thousand byte integers, and you can get away with this. And Python just happily goes, yeah, that's a really big integer. No problem. Rust is closer to the machine. So it tends to use integers the way your CPU uses integers. So you have to be aware if you're using an eight bit integer that you can't put nine bits in it.

Christopher Trudeau:Things go wrong. Now the compiler, most of the time can catch that depends on how you're getting into that situation. And so it, it stops you from doing those things. But of course now you have to be conscious of it, right? You're making a decision when you're designing your program. How many bits am I going to store this in? And most of the time that's not a problem, but sometimes that might mean you're hitting boundaries that you wouldn't otherwise expect to hit.

Michael Kennedy:Yeah. And even weird things like it's signed or unsigned. Like now you can have negative numbers, not even negative one, not allowed. Yeah. That means 2.17, two, two, five billion.

Christopher Trudeau:And interesting, like a lot of that stuff is in Python, but it's buried further down. So you can get at some of those same concepts inside of Python, but if you're just starting out, you don't go digging for those things. Right? So if you're, you know, if you're playing with the network and you're trying to pack bytes together, Python has signed and unsigned and it has those sides pieces. And all of that is very, very important if you're constructing the perfect packet. But if you're just trying to do math on the command line, well, you don't need to think about that kind of thing. Rust doesn't give you the choice. And that's not Rust specific. That's most compiled languages. They don't give you the choice, right? And it's also where the speed comes from, right? So that beauty of Python's limitless integer means there has to be machinery inside of that to handle when you make it bigger than what the current chunk of memory is.

Christopher Trudeau:And rust doesn't have that machinery. It just says, okay, I'll crash. and so it's, it's a trade-off, right? So you don't have to care for as much, but one of the reasons Python is slower is because there's the overhead that handles these kinds of things. So one of the reasons, you know, the flip side works as well. One of the reasons rust is faster is because it's optimizing for exactly what your CPU does. And that less overhead means your code runs faster.

Michael Kennedy:Right. You're never going to get a Python integer into a CPU register. Right. Like it's just, I don't know. Maybe. I remember when I came to Python, I did C++ and C#, all languages that care about the shape and size of these variables, numbers, and for 15 years. And I came to Python, I'm like, I got to be doing something wrong. How do I tell it again how big the number is? Because what kind, like, is it just, is it a 64 bit? I couldn't figure out like, what is, how do I, it's going to be a problem.

Michael Kennedy:And then I'm like, wait, it just grows. That's crazy.

Christopher Trudeau:Yeah. Well, I think I started with Python more as a scripting glue kind of thing. And most shell languages don't have, like Python, just don't care about those things. Right. And so when you're using it loosely to glue other things together, I don't think that really kind of ever crossed my mind. And I think I got used to the idea by that time I was doing, you know, web servers and things that were bigger, more interesting projects. And I think a lot of this is where are you coming from and how are you using the tool, right? So I think for the first couple of years I was doing Python, I was writing, you know, at max 50 or a hundred line scripts to solve some immediate little problem. And it's nice not to have to worry about that kind of thing, right? So all of this really is, you know, what is the tool and how are you using it for what you're trying to accomplish?

Michael Kennedy:Yeah. And I was coming from scientific programming, like building UIs and other type of tools for scientist type of thing.

Christopher Trudeau:We care about the size of this number because science. That's all what your background is.

Michael Kennedy:This portion of Talk Python To Me is brought to you by Sentry. You know Sentry for their great error monitoring. But let's talk about logs. Logs are messy. Trying to grep through them and line them up with traces and dashboards just to understand one issue isn't easy. Did you know that Sentry has logs too? And your logs just became way more usable. Sentry's logs are trace-connected and structured, so you can follow the request flow and filter by what matters.

Michael Kennedy:And because Sentry surfaces the context right where you're debugging, the trace, relevant logs, the error, and even the session replay all land in one timeline. No timestamp matching, no tool hopping. From front-end to mobile to back-end, whatever you're debugging, Sentry gives you the context you need so you can fix the problem and move on. More than 4.5 million developers use Sentry, including teams at Anthropic and Disney+. Get started with Sentry logs and error monitoring today at talkpython.fm/sentry.

Michael Kennedy:Be sure to use our code, Talk Python26. The link is in your podcast player's show notes. Thank you to Sentry for supporting the show. I do, before we get too much farther jumping into it, I do want to point out that you wrote the Up and Running with Rust course over at Talk Python. So thank you for that. I really enjoy this course. It's both very educational and funny.

Christopher Trudeau:I try.

Michael Kennedy:Thank you for that.

Christopher Trudeau:The beauty of doing this kind of stuff with a sense of humor is you don't actually have to be a comedian. It's not like everything is a joke, but you can stick some humor in once in a while. So I do wonder occasionally whether, again, because of the similar generation, half the jokes might have been aimed specifically at you. So just because you find it funny doesn't mean other people will.

Michael Kennedy:I think they will. At least the lightheartedness. We'll see what happens. We'll come back to that at the end. This is kind of not exactly the same. It's not just that we're going to turn the course in the podcast, but it's inspired some of our concepts. Now, I want to start by talking about Rust. Just some examples before we dive into how is it compared to Python. We've touched on a little bit of that, but there's a bunch of differences and so on.

Michael Kennedy:But let's just appreciate some of the things like Pydantic, Ruff. Give me your thoughts on the last five years of these tools. have kind of supplanted a lot of things that were very well established in Python.

Christopher Trudeau:So there's, there's, there's kind of three ways that Rust intersects with the Python world. And one has almost nothing to do with Python. It's they've used Rust to build tools that are Python tools. The, they could have just as easily done that for any other language, right? So when you talk about things like the linters and those kinds of things, they're, they're useful because they're fast. they are not, they're not really integrating with Python.

Christopher Trudeau:They're a third party tool that you're using to make your Python better. And I think so some of the, some of the popularity in that has come out of the fact that a lot of the tools we've been using historically in the Python world have been written in Python. And so they've been very slow. And most of the time that doesn't matter. You know, there's that, you know, that programming world of, oh, I'll just go get another cup of coffee and it'll be done when it comes back.

Christopher Trudeau:But your world shifts when you start seeing, you know, orders of magnitude, right? Like 10% faster, you're not going to notice it when you're starting to talk multiple zeros times faster, this changes things. And I think there were a couple of key libraries that started doing this and everyone kind of went, oh, wait a second. There's some, there's some value to this. And so I think there's been this real spring up of things written in Rust that make Python development easier.

Michael Kennedy:Yeah, I think the one that was most stark to me was Ruff because it was just unreasonably fast. Yes. I remember running on the Talk Python training, all the courses, like that app. And that app is much bigger than people think from the outside. It's 170,000 lines of Python or something, which is not huge, but it's not a toy, right? And so I remember running Ruff on it and it goes, found these four hours. I'm like, yeah, no, you didn't. Wait, wait.

Michael Kennedy:Did I not tell it to like go into the subject?

Christopher Trudeau:It's like, did you stop after you found four errors? I don't understand.

Michael Kennedy:How can you be finished? You like literally parse the entire thing for a hundred rules. And it was like, enter answer. I'm like, what? I just don't understand.

Christopher Trudeau:Yeah.

Michael Kennedy:And then there's something different here, you know?

Christopher Trudeau:Yep. I also, I tend to be fairly slow to upgrade my machines. So I'm often a couple of generations out processor wise, and it's just that much more, right? Because like when you're, when you're operating on a slow machine to begin with, and then you're trying to do something like lint a couple hundred thousand lines of code. Yeah. It makes a huge difference.

Michael Kennedy:It does. So one of the categories is rough, which is really tooling. And you can kind of forget that it's rust. Like it just doesn't even really, it might as well have been written in some. It could have been.

Christopher Trudeau:Yeah. And I think that's kind of the key to this category, right? whether it's written in rust or C or anything else is kind of indifferent. It's, it's a tool. they, they're particularly with things like linters, you know, the, the, description of the Python language is publicly available. There are tools out there for compiling, for compiling language parsers. So like you can, you could have taken something, else and use that to take the definition of Python and built a thing that parses Python in any other language. It's just that Rust seems to be, has, has become the thing that is now the way to

Michael Kennedy:do some of this stuff. Yeah, absolutely. And just give like other numbers, you know, instead of my own personal example that people can't exactly relate to for parsing for linting and pars, evaluating this, the entire CPython code base from scratch is a 0.3 seconds. Yeah. That's, that's like enter the three blinks of an eye. Yeah. You know, that's pretty ridiculous. Yeah. So that's one category. The other category is closer to our hearts with things like Pydantic and so on.

Christopher Trudeau:So like I said, there's kind of three modes. The second mode, and I think it's the most common one, is because Py... And this isn't really... Again, this is one of those things that's not quite Rust-specific. Python was designed from the get-go to integrate well with lower-level languages. And in fact, there's a good chunk of the Python standard library, which is really just a thin wrapper on top of the C standard library. And in fact, the older stuff in the standard library, you can actually see it.

Christopher Trudeau:It's a little creaky in some of the naming and stuff before they kind of got consistent about how to name things. And you look at it and if you're a C programmer, you're just like, oh, I know exactly what that is.

Michael Kennedy:At least they don't use Hungarian notation. There is that.

Christopher Trudeau:S, Z.

Michael Kennedy:What is going on here?

Christopher Trudeau:So Python has been designed to be able to do this. And it just turns out that I think a lot of people are coding in rust have found it easier to code than encoding in c that same interface that c extensions can use can be used by rust and so as a result libraries like pydantic libraries like polars they have written their library in rust and then with a very very thin veneer there doesn't take it doesn't take a lot of effort to expose that up and then python inside of python you can treat that like any other python module so you don't actually have to be conscious of how they And as a result of this, you end up with a lot of speed up because you use that same speed that you were talking about with rough.

Christopher Trudeau:But now Python, which tends to be a slower language, can now access this kind of stuff. So something like Polars or Pydantic, where you're doing a lot of crunching and you want them to be fast and performative, this marriage between the dynamic library on the hard drive that is a compiled thing as a Python module, that integration has been very, very handy. And I think this is the place where Rust is starting to shine because it's a cleaner, although it can be a little frustrating, it's a cleaner language than C.

Christopher Trudeau:There's a learning curve, but there are a lot of things it doesn't let you do. There's fewer foot guns. And as a result, it's a nice marriage between a low-level language and some higher-level concepts, right? So it has things like iterators and collections in it. And so if you're coming from Python, that's like, oh, how do I deal with that? Oh, it's the same kind of for in loop and it's the exact same thing, right? So there's enough similarity to more modern languages that this is becoming a nice sort of collection of pieces that worked well together.

Christopher Trudeau:And in the cases of things that need to be really fast, this is a real answer.

Michael Kennedy:Yeah, absolutely it is. And taking your Rust code and exposing it as a Python package with the tools like Pyotr3 maturing that we're going to talk about obviously they they make it super easy it comes down to just okay well you need to build more variants of your wheels rather than just a source only one yeah i think i have an analogy for these types of things so we have one third uh category i guess which i would put as granian and other things which is a web application server that runs that is built and runs in rust but then your code and python still runs so i have i have an analogy chris tell me what think here we've got the caramel dipped apple where it's caramel is python okay so we've got the caramel dipped apple where python is on the outside with like a rusty core yep that would be pydantic we have maybe python maybe it's the way anyway we've got Granian and other things where it's like more like a caramel m&m on the outside it's like a

Christopher Trudeau:hard shell of rust and then the side it's like some sort of crunchy nugget on the outside and

Michael Kennedy:the caramel's inside yeah the protective hard outside is the rust which is granian and those types of things and then we've got the tools which i'm thinking of is just like a solid piece of caramel but that's maybe a little bit backwards i i would go with the tools are like when

Christopher Trudeau:you've got a slices of apples and a bowl of caramel that you can dip it in so it's a separate thing but you can mix and match so yeah i think we're stretching we're officially stretching this

Michael Kennedy:analogy and now i'm hungry but i know i know we were stretching but with your your slices of apple You've, you've perfected it. Okay.

Christopher Trudeau:So yeah, so that third category is within rust code, you can embed the Python interpreter. And so from a rust, program, you can now use an access Python. So you can kind of use Python as a scripting or, or configuration language within a larger, mechanism and something like granian where you want to actually run Python code for a web framework, that, you know, so that, that inverts the relationship we were talking about before. So yeah, so that's our three, right? So it's separate tools, the using Rust as a module inside of Python. And then the third one is using Python as a compiled library, using the interpreter as a compiled library inside of the

Michael Kennedy:Rust object itself. Yeah, I think that sums it up pretty well. Let's talk differences. I think kind of language differences, you know, syntax differences. It feels pretty familiar, honestly.

Christopher Trudeau:Yeah. And I was about to say, you know, to start with differences, it might actually be easier to start with what's not different. The language itself, there are some things, obviously, if you've never, if you've never seen it before, it takes a little, and that's the same with any language, but it's not going to be completely out of nowhere. If, if I hand a Python developer some fairly clean Rust, you're probably going to have an idea of what it's doing. The loop mechanisms are the same.

Christopher Trudeau:The if else is similar. There's no L if you actually use if else. I always scratched my head

Michael Kennedy:with L if in Python. I never understood it. Why you need a new keyword. It's such a verbose language. And then it's like, well, no, this we're going to. Yes. Yeah. Why that one? I have a sneaking

Christopher Trudeau:suspicion. It might've made something early in the early days easier to parse, but rather than parsing two keywords, it gives you a keyword. A lot of the built-in mechanisms, like it's got tuples and arrays, it's got iterables and collections. So a lot of the declaration looks like typed Python. So because it is a strictly typed language and you have to specify what everything is, you do have things like the arrow that this function returns something of this type, right? So you've got that little arrow designator. But if you're used to coding in typed python which i'm not uh then you uh then then it's readable from that perspective it is yeah

Michael Kennedy:the types are quite quite similar uh as they you know um for the way you define them right if you have like a function or something then you just say like arrow goes to i always read that as goes to pool if it like returns a pool the variables are variable name colon type right yeah yeah and

Christopher Trudeau:And I suspect that's probably because Python type libraries was inspired by some of this stuff. I think it probably flowed the other direction, but I'm not sure about that.

Michael Kennedy:So yeah, it's a lot of mixing in this, in the later, the things that got created later and typed later, like TypeScript is similar. Yes. Python types are similar. Swift is similar.

Christopher Trudeau:I think it's the same that everybody stole from C, you know, C is the granddaddy of most of the languages we use. And then I think people started adding these kinds of concepts to it. And it's like, well, if you've come from that other language, this makes it simple. So yeah, there seems to be a sort of family of how this stuff works now.

Michael Kennedy:Yeah. And someone decided all the types go after. Yes. Right. And see, you would say like int function.

Christopher Trudeau:Yeah. That, that, that has taken me a little bit to get used to. Yes.

Michael Kennedy:I presume it me it's meant to be making it more readable and you see the essence, like the function name and the variable names, and then the stuff describes it after. But yeah, it's always caught me off guard.

Christopher Trudeau:I'm guessing it's because it's optional.

Michael Kennedy:It's optional in Python, but it's not optional in Rust. True. Or Swift, right?

Christopher Trudeau:Yeah, true.

Michael Kennedy:And I'm pretty sure that Swift was inspired by, like much of Swift was inspired by Python as well. Swift's an interesting thing to look at as well, like the Playgrounds, the REPL, a lot of the stuff there. But okay, let's keep going. Some more similarities, all right?

Christopher Trudeau:No, I think we've hit the limit of the similarities. So it doesn't take long. It's relatively readable in the same fashion, but it doesn't take long before you have to kind of peel the top layer of that onion and then you're going to get into your differences. At the heart of it, one of the fundamental concepts is it is a compiled language. This is one of those things that I think I always find sometimes frustrates students because you end up with the, well, Python compiles.

Christopher Trudeau:I can see the code right there. Python is a interpreted language that interprets a binary file. So when Python is compiling, it's creating a binary target. That binary target is not platform specific. It is just a, you can think of it as a data file the same way, like Excel is a data file, right? So when you, when you write a formula in Excel, you don't think of that. It's not quite compiling that formula. It's storing it in binary. And then Excel is running that formula.

Christopher Trudeau:By contrast, Rust actually compiles to machine code for your platform. So when I come, unlike a collection of Python bytecode, I can hand you that. And I don't have to worry about what platform you're running on because your interpreter is specific for you. The bytecode is not. If I hand you my binary, if you're on the same kind of platform I am, it'll run. But if you're not, it won't. And so what Rust is actually doing there is creating a binary, tight binary file that is specific to your platform.

Michael Kennedy:And you know what? I'm jealous. I'm jealous from a Rust and Python perspective. You can compile it and hear, hey, I'll give you a file. You can run it. You know what I mean? Yes. I know there's a lot of reasons and it's not easy, but wow, would I love a Python --build thing and outcomes just, I don't care what's in the inner core, right? You know, back to the like caramel M&Ms, but just a thing that I could put on a server, I could give to a person, I could put in Docker, and it doesn't have to have a bunch of other stuff there to make it possible.

Christopher Trudeau:Yeah, it's a pros and cons thing, right? So your distribution is way easier, but it's very specific distribution, right? So you end up, if you're trying to aim at multiple platforms, you have to compile across all of those platforms, but the distribution of it is basically, here's the execution file, go nuts, and that's it, you're done. Or the collection of them, if you've got dynamically loading libraries. So that is definitely easier. the flip side of it is things like repls aren't technically possible because it needs to compile stuff and in fact there's some hacks out there that are kind of hilarious that are essentially repl like things that are in the background are basically recompiling a program every single time you enter a line in the repl exactly so it's actually somewhere in there yeah it's actually maintaining this program for you in order to make it look repl like and as fast as rust is i found painful i played with it once in a while and i sort of gave up and just went back to i'll have

Michael Kennedy:my foo.rs file and i'll do it that way so yeah i could just see the background that there's like there's a fn main curly you know brace brace curly exactly and every line of rubble is jammed and

Christopher Trudeau:then there's a cargo build cargo run yeah that's exactly what it's doing that's exactly what it's

Michael Kennedy:doing this portion of talk python in me is brought to you by us i'm excited to talk about my first solo book, Talk Python in Production. It's an inside look at how we host all the Talk Python sites, APIs, mobile apps, and way more. Here's the thing. I believe most hosting stories sold to developers and data scientists are way overcomplicated and overpriced. You've heard me say you're not Google, you're not Netflix, so you shouldn't run your infrastructure the way they do. But if not that, then what? This book is both a blueprint for what I chose for Talk Python and a story arc of 10 years of running my own infrastructure from a complete newbie, apprehensive to Linux, to some pretty neat infrastructures code DevOps. It covers Docker, Nginx, Let's Encrypt, self-hosted analytics and monitoring, CDN setup, framework migrations, and a whole philosophy that I've termed stack native, keeping things streamlined, powerful, and free of cloud lock-in. And it's more than just your standard tech book. It comes with code and figure galleries on GitHub, a discussion forum, and something unique, over an hour of audio readers briefs, short conversations that bookend each chapter to prime your focus or broaden your

Michael Kennedy:takeaways. Oh, and 0% of this book was written by AI. Every word is mine, written over the course in high months, for better or worse. I've made the first third of the book available for free online. After that, you can grab the DRM-free EPUB and Kindle editions, and I'm working on a paperback edition as well. Please check it out at talkpython.fm/devops, or just click book in the nav bar on the website. It's a great way to support the podcast, and I hope it changes a bit how you

Christopher Trudeau:think about running your apps in production. Okay, and so I guess, and that kind of, and we were already sort of talking about this, but this leads us to this idea of the strict typing mechanism, and that really comes out of this idea of the hardware, right? So your CPU has an idea of what an integer is. Your CPU has an idea of what a float is. There are different sized integers. How much memory is that integer going to be stored in? How much memory is that float going to be stored in? So not only is Rust specific about having these things, and you have to declare them when you're using them, but it also has that mapping to what your hardware does. So you have to make a decision between a signed integer versus an unsigned integer. So if you've never played with this kind of stuff before, when you stick a number in memory, that number represents just some bytes and your CPU is interpreting those bytes to mean something. And if you could have it, you could have it represent a positive number. And in the case of a single byte to it, that's from zero to 255. But if you want to also have negative numbers and store it in the same amount of space, well, then now you have to sort of map something from 0 to 255 into the negative space. And so you

Christopher Trudeau:end up with like minus 127 to a positive 127 or 128. Let's not get into that. But essentially, the computer is interpreting those same eight bytes in a different way to represent a mix of negative and positive numbers. The downside of that is you can store less. You can only store up to was half the size of a positive number. In Python, you don't care about any of this, again, unless you're doing packets, but in Rust and C and other languages like it, you have to actually explicitly decide which of these you are using.

Michael Kennedy:The upside is in Python, you don't care, but there is so much indirection. Yes, there's a lot of overhead.

Christopher Trudeau:Yes. And all of that overhead goes away, yeah.

Michael Kennedy:Not only is it indirection and that overhead goes away, But can you put a bunch of Python, if I have an array of Python numbers, how are they going to land on like L1 cache?

Christopher Trudeau:Yes.

Michael Kennedy:They're not going, they're all random places out in the heap. So, I mean, there's arenas and blocks and all that stuff to try to like get them closer together, but they're still just out there rather than I've got an array of 10 numbers. Well, guess what? Those numbers are contiguous in memory sort of thing, right?

Christopher Trudeau:And you've kind of hit on something that is also very explicit in Rust. Now, you can start Rust programming without fully understanding this, but you're not going to get very far without it. It's fairly explicit about what goes on the stack and what goes on the heap. So again, if these are new concepts for you, when your program is written, the stack is where function calls happen. So when you move from one place in code into another in memory, what happens is the new address, the place you're going to, gets put onto a stack.

Christopher Trudeau:The old address is there before. So when your function returns, it pops off the old stuff and then knows, oh, that's now the thing at the top of the stack. That's now the address I'm going to run at. And so when you add variables into, when you add parameters to your function, those are also getting put on the stack. So you end up with this little stack frame, which is the place you're going to be running and the data that goes with that function. By contrast, the heap is sort of a general space, and that is where you allocate things from memory. And longer lived things or things that you're passing around between functions tend to end up being created in the heap. And how Rust does memory management, we'll gloss over it for now, we'll get into it a little more later, I think, but how Rust does manage memory management differentiates between these two kinds of things and so again this is one of those things you you know you only think about the stack in python when it fails because you get the stack trace but otherwise you more or less ignore it whereas here once you start playing around with passing objects around whether or not you're being explicit about it that concept of am

Christopher Trudeau:i in the stack or am i in the heap and who owns it becomes very very important and and this isn't new to Rust. This has been there in compiled languages. This is a fundamental way how modern computing machines work, but it's more exposed in Rust than it is in Python. You know, the thing I

Michael Kennedy:think is such, to me, it was a little ironic is Python, you don't worry about pointers. You don't worry about that. You just work. And then like other languages like C, Rust, C#, you talk stack, you talk heap, you talk pointers, you can dereference. Python is more pointer heavy than any of those languages because literally everything is in the heap. There's nothing that's even a

Christopher Trudeau:number is a pointer to a thing in the heap, right? Well, this is how Python got away with not having pointers. It was everything's a pointer, so we don't have to differentiate. Yeah. Yeah, exactly.

Michael Kennedy:That's like, if everything is a pointer, we can just treat them all like variables, right? And that made the programming simple and you don't have to think about it. But conceptually, Python, everything is in the heap. Everything is a pointer. Even the number one, it's a flywheel pattern. I

Christopher Trudeau:And even that's insane, right? Like that, yeah. I have three copies of 254, but I only have one copy of two. Sure.

Michael Kennedy:That is really.

Christopher Trudeau:Don't stop to think about it because, yeah.

Michael Kennedy:Yeah. For people listening are like, okay, they've gone off a rail. Like they're a little, what are they talking about? An optimization in CPython is the numbers, I think maybe negative five to 255, some range like that.

Christopher Trudeau:Yeah.

Michael Kennedy:They're pre-allocated. And every time you type a literal number like 72, it's the same number. It just all points at the immutable number 72 rather than creating, you know, like whatever the eight byte or four byte chunk of it is on the stack.

Christopher Trudeau:Yeah.

Michael Kennedy:I appreciate it makes it faster, but it's just funky. Yeah, it's weird.

Christopher Trudeau:Yeah, it's something you don't want to think about too much. A couple sort of cosmetic things, which again, if you're from Python and Python's your first language might take a little to get used to. one is brace brackets so uh like most programming languages space is not important uh and that takes i i remember it taking me a while to get used to that switching to python so i have uh patience and sympathy for people who started in python and have to go the other way this is pretty typical of most programming languages uh the it makes the parser's life easier um and i think after having coded in Python for almost two decades, I think I've come down on the side of screw the parser.

Christopher Trudeau:So it's a little bit taking a little used to for me to get back to it. But yeah, you, you put things in brace brackets to denote them.

Michael Kennedy:Yeah. I mean, look, the job of the parser is to make your life easy. Not the other way around. So I get, but I have run into situations where some little bit of formatting has been off. Yes. On my indentation and a reformat the code broke the code because maybe I had three indentations, three spaces instead of four for who knows, maybe I hit the delete button on accident or something weird like that. And I said, oh, well, look, this didn't line up right.

Michael Kennedy:Like I'll just hit like reformat code. And it's like, oh, well, that needs to go back to the left. And it's like changed actually how it works.

Christopher Trudeau:Yep. So copy and paste is problematic in Python. Yeah.

Michael Kennedy:It's really problematic. And with the braces, like it could just have no indentation. It could be all gnarly. It could be minified, whatever. You just hit reformat and boom, it's reliably put back together well. So I'm going to give Python an 80% plus, 20% minus. I agree that it's nice. It's not there, but it's not just there is value to it. Structural correctness value to it.

Christopher Trudeau:Yep. I also, you know, it forces programmers to behave themselves, which if you don't get your spacing right, your code doesn't work. It kind of makes the spacing consistent.

Michael Kennedy:Yes, exactly. That was what it was optimized for is like, you're going to make your code readable because you have to write it in a way that its structure and its readability match. And that's beautiful. But it is a little, it can have problems.

Christopher Trudeau:Yeah. And being a veteran of the tabs versus spaces war of the nineties, eliminating that at the, at the syntax level is kind of interesting.

Michael Kennedy:It really is like, and you know what, there was a gosh, what PyCon was it? I think it was one Cleveland, maybe three, four years ago, there was a PyCon where one of the vendors clearly came. It was a tool vendor that came from all the, they weren't Python specific, but they made tools for Python people. and I would even maybe shout them out, or I'd call them out, but I don't even remember what it was. But they were giving away t-shirts that said tabs versus spaces.

Michael Kennedy:And you had to pick, I'm team tab, I'm team spaces. I'm like, what are you doing? Does nobody know that this literally is not even a choice in this language? Why are you here? It's a fun gag, but anyone on not team spaces is not going to run. What is wrong with you?

Christopher Trudeau:Yeah. That's a team spaces versus teams. My code won't compile. Yeah. Yeah. An interesting side effect of this that I kind of like in this language. I don't know if I've seen it elsewhere. So like most languages, it has this rust has this concept of a statement versus an expression. Most things are expressions. And in fact, your brace bracket is the definition of a new expression. And as a result of that, the end of the brace bracket can return something. So you can do an assignment to a collection of code in a brace bracket. So this ends up being kind of like an inline function. and so that's kind of interesting to me and it, it, compiles down beautifully. it's, it's got that, and then it does this weird thing where it's got implicit

Michael Kennedy:returns. And so I really wish they had not done the implicit return. I am never ever going to be on team implicit return. I just can't. It drives me nuts. and, but the idea of having,

Christopher Trudeau:arbitrary expressions through the brace brackets is kind of elegant. So, so yeah, one point up, one point down, whatever. and then, you know, there's some odd odds and ends, right? It's, it's, uh, FN instead of def, which quite frankly, as soon as I saw it was like, yeah, that actually makes an awful lot more sense. That tells me what it is. Def for define, define what? What am I

Michael Kennedy:defining? FN? It's a function. That makes sense. And then one of the other things that I kind of

Christopher Trudeau:liked a lot is, so they release a lot more frequently in Rust. So it's, there's a new, a new version coming out every six weeks, which when you come from the Python world, that sounds insane, right? Like how do you stay on top of this? But they've got this separate concept from versions that they call additions. And an addition is a three-year cycle and things stay compatible within the addition. And what's more, not only do they do that, but the compiler is able to compile to older additions. So when you compile the code, you can actually say, I want to be using an older addition. And so they have basically this forever concept of backward compatibility. So now it's still a young enough language. I suspect at some point they may give up on that. cause this, this to me smells of maintenance hell. It's fine when there's three

Michael Kennedy:editions. What if there were 35? Yeah. but for the, for the time being, although there's been a

Christopher Trudeau:fair amount of change in the language, in the last few years, you're not screwed by it. And it's not this constant race to stay on top of it. You can just change the edition target and you're fine. So I kind of like the idea. I think it would be kind of neat if the Python compiler, maybe, you know, if I was, I guess the changes in Python aren't as bad, so maybe it's not as extreme,

Michael Kennedy:but I don't know. This just sort of appealed to me. Yeah, it does to me as well. I love the freshness of it. I just got a new version of Rust this morning. I was trying to update my libraries and tools, and it said there's a new version of Rust. Yes. Okay. So I think that might be a good good time to maybe talk about like getting started and so on as maybe start by installing yeah uh so

Christopher Trudeau:uh the good news is if you're in the unix world uh some sort of Linux or mac os this is uh this is a breeze you go off to the website you copy and paste the command onto the terminal and you're

Michael Kennedy:more or less done uh we do the thing that we normally do we run arbitrary code from the internet that's right as root on our machine i'm sure it's fine yeah it's fine uh if you go off to

Christopher Trudeau:So rest up, rustling.org. there is right on the front page. There is a little shell command that you install. This actually installs a tool called rust up rust up is kind of like pie M and that it handles installation updates of the language. It install, it installs, rust C, which is the compiler and more importantly, cargo, which is the tool. That's kind of like uv that is what you actually use. You almost never call rust C directly. So rust up handles the version management of all that kind of stuff.

Christopher Trudeau:And once you've got that going, then you use cargo to create a new project. Again, very uv-esque here. So you would say, you know, if I'm doing hello world, it would be cargo new hello. That creates a cargo.toml, which is the equivalent of pyproject.toml. It creates a source directory. By default, it creates a git repo and a git ignore file, which drives me nuts. And I turned that off as soon as I could. I want to be in control of that. Don't do it for me.

Christopher Trudeau:And it creates a little stub main file, which actually has a function in it. So you actually can run cargo new hello and you get a compilable program. Then you write your rest and you run cargo run and cargo run builds and runs the code for you. Now, because it's a compiled language, the result is a target that goes into the target directory. You could run that explicitly, but it's buried like three directories down. So rather than do that, you just call run and it does it for you.

Christopher Trudeau:And there are flags you can use it to go from debug mode to release version. Your debug tends to be about 30% larger because it includes debug information.

Michael Kennedy:While the production mode... That's par for the course for people who use those things.

Christopher Trudeau:Yeah. And in fact, on Windows, it produces... I think in Windows, it's packaged as a separate file. The debug info is in a separate file, which is, again, a standard sort of Windows thing to do.

Michael Kennedy:Yeah, Windows often you can put, I forgot what they're called, but there's like a debug symbols that is a file that you can put like next to a DLL or an exe and it'll pull that in.

Christopher Trudeau:And so it handles all of that kind of good stuff for you. And then this is then the thing that you would distribute if you were trying to distribute it. There's a command for building on its own and then the command for run both builds it and runs it. One of the things I'm still not quite used to is it outputs some information from the build before it actually runs the code. So you get two or three lines of info before you actually see the output from your program, which drives me nuts.

Christopher Trudeau:But there is a dash queue to tell it not to do that so that if I'm running it, I don't want to see your compiler stuff. I want to actually have it run unless something went wrong. So yeah, cargo really is the key to doing all of this kind of stuff. Like uv, it also manages what they call crates, which are the Rust equivalent of wheels. There is a crates.io is the equivalent of PyPI. And you can write libraries and upload them there. And like with Python, this is a fairly robust community that's writing and trading code here.

Michael Kennedy:331,019 crates in stock. We look at PyPI.

Christopher Trudeau:think we're at 750 the last time I looked.

Michael Kennedy:I haven't looked for either. 889,000, 890,000. So there are more, but I don't think that is necessarily the core metric.

Christopher Trudeau:No, and it's also not a fair comparison because proportionately the number in crates would actually seem smaller to a Python developer. And what I mean by that is if when you're coming from the batteries included world, yeah, there aren't a lot of batteries in Rust. So something as simple as like a random number, that's a crate. And they've done this to try and keep the footprint small, which I kind of understand. For somebody who's starting out, this can be a little, so like I had this, I'm paranoid, right?

Christopher Trudeau:So I want to know where my code is coming from. If I'm in the Python world, I trust the standard library. If I stick to the standard library, I know I have a degree of safety. Once I step outside of the standard library, I want somebody to tell me they've used it and they trust it. And, you know, for certain kinds of libraries, there's enough press that you can kind of get the idea. I haven't yet quite figured out how to get that information in the Rust world.

Christopher Trudeau:And because things like random, which you use all the time, are actually crates, you kind of have to do a little bit of the, there's a little more rolling the dice on do I trust this code to use it kind of thing going on there. But I suspect that's still my newness to the community.

Michael Kennedy:Yeah, perhaps. You know, Chris, just because you're paranoid doesn't mean they're not after you.

Christopher Trudeau:Yep, that's right. That's exactly right.

Michael Kennedy:And with the supply chain stuff, it means, I mean, it's crazy.

Christopher Trudeau:In the world of the internet, they are out to get you. Yes, without a doubt.

Michael Kennedy:Oh my gosh. And sometimes you hear the pounding on the door. You're like, oh my gosh, go away, please don't do that. Let's just like reflect for a minute. We talked about like cargo crates and all all these things, we've seen a big revolution in Python packaging, deployment, flexibility, project management, all of those things. And much of that has actually come from the Rust side. A lot of the tools like uv and others are seriously inspired by cargo, the crates, and these types of things. But this was built in a world where PyPI already existed and npm already existed. And they could go really good. Ooh, that's not good. Let's do it this way. Right. So there's like this sort of interplay or this circling of these two worlds. Yeah. It's, you know, without,

Christopher Trudeau:I'm not trying to start a flame war, but the decision that the PSF made that, managing packages wasn't really part of the language and that we should have this plethora of third-party tools to do that. I think that was a mistake. And I think the Rust people recognize that and decided to bundle this in. it's, it's a lot cleaner and there's a lot less wondering of what's going on. and, now in defense of rust, sorry, in defense, I don't know who I'm defending. Nevermind. I'm not sure whatever I'm going to defend. I'm not going to defend. Uh, the, I think the target for rust is simpler. And, part of the thing that happened in the python world is because of that dynamicism it creates all these other kinds of complications

Michael Kennedy:um so yeah it's right my package also requires a fortran compiler exactly yeah right whereas

Christopher Trudeau:because you're compiling these things down you some of that stuff goes away so so yeah it's it's

Michael Kennedy:it's a challenge i agree but also wheels do exist now yep in the python world created them and they didn't before and that was like a super hard problem because yeah everything needed like all these bespoke tools just to install something interesting. And then they said, no, no, no, let's just make wheels. You can just have like, why do we have to make everyone recompile everything from source? So they kind of got there. Another thing I think- They're making progress. Yeah, no, they're making progress. Yeah. Another thing I think is interesting around this is you talked about the sparseness of the standard library equivalent of Rust. I feel like Python batteries included the richer standard library. It is that way because PyPI didn't exist.

Michael Kennedy:The concept of a package manager didn't exist when Python, you know, and honestly, like what was 91? Like the web didn't exist. Like getting stuff afterwards was really, really hard. If it were easier, they may have made different choices.

Christopher Trudeau:Yeah. It's, it's a consequence of this language being around since the nineties. Right. So the decisions up front were, and what, and what it was designed for versus what it's grown into. you know, that's, we should all be, as software developers, we should all be so lucky as having our initial designs become questionable because 35 years later, people are still using our software all over the planet. Yeah. If people want to criticize mine because it's so popular in 30

Michael Kennedy:years, I'd be happy as well. Yeah, exactly. All right. We've got a little bit of time left, but it's not a ton. I think let's focus on one more section and that would be, how do I go from Rust land to Python land. So there are different libraries for doing this. The most common one out

Christopher Trudeau:there is a crate called Py03. And essentially what this does is provide you with the tools to align your Rust code as if they are Python objects. And then there are a couple other tools that you can use to actually do the packaging part. So what Py03 does is it defines the interface the compiled object, which is a dynamic library, so a.so file or a.dll, and then does that in compliance with Python's ABI. And then there are tools out there that you can use, which will put those inside of a virtual environment so that Python can see them. And then in Python, you can load that code that you wrote as if it were a regular Python module written in Python.

Christopher Trudeau:The how Py03 does this is a couple different things. One, it has Rust objects that are compatible with the Python objects. So as an example, Pyint is a Rust object that represents a Python integer. So if you need access inside of your Rust code to the integer inside of the Python space, this acts as a mechanism to get at it. It will also map Rust concepts. So rather than using pyint, you can just use, say, a int32, and py03 will take care of mapping that up to the Python integer when Python's using it in the Python side of the world.

Christopher Trudeau:The other thing that it does is Rust has a mechanism that is macros for changing how things get compiled. And py03 ships with a bunch of macros that essentially you attach to something like a function. So if you want the function or a class to be available to Python, you wrap it with one of these macros. It's just a regular Rust function, but the macro is what does the mapping and makes it available. So with the right use of the macro, you can say things like, you know, this is my function.

Christopher Trudeau:It's got three arguments. These arguments need to map to this, et cetera. And essentially what happens when you compile it is all of this gets put into a.so. And then you use tools like Maturin or others that then put that into a virtual environment and to handle the packaging side of things so that your Python code can use it. And from Python's perspective, once that's installed in the right place, you just import foo from bar as you would with any other module and you've got access to it all.

Michael Kennedy:Interesting. Now, it doesn't have to be all or nothing as well. For example, remind me how to do this because I forgot how to do it. but you can create a project that has some Rust code and some Python code and then build that into a wheel. But you could say only part of my code is gonna be Rust and the rest of it that's not performance critical, that's all Python all day long.

Christopher Trudeau:Yeah, so for example, if you look at, if you pay close attention when you install Polars, you're actually getting two wheels, one of which is a universal wheel, which is because it's universal, it only contains Python code. And the other of which is it's figured out what platform you're on and gives you the actual compiled Rust version of the Polars library. So they've kind of got these two things going on. Now, I don't know Polars well enough. I've never looked at their source code, so I don't know what they've got in each one of those packages, but they've built something that is comprised of both of those things. In their case, it's in two separate wheels. It doesn't have to be. And essentially, you're using a tool like Mature and it takes care of this for you. So if you're after a, if you're after building a library where there's a part of it that has to be very performant, but you want to write most of it in Python because, you know, it's easier to code in, then there's, you basically do that and Maturin will let you bundle all of that up.

Christopher Trudeau:And this is no different than any other plugin mechanism. It's just that these are the tools that Rust provides to build those kinds of plugins. So if you think of tools like Polars or NumPy or any others that do this kind of concept where some of it's written in a lower level language, I O three just lets you do that.

Michael Kennedy:I think there's a lot of, a lot of low hanging fruit for people to go apply a profiler to their code and say, no, it really only matters at least 20 lines of code here. Yeah. What if?

Christopher Trudeau:Yeah. The challenge you have to pay is every time you do this, you're crossing a boundary and there is a cost to crossing that boundary. So, there, if you're writing the code in such a fashion that you're constantly going back and forth or your objects are constantly going back and there's overhead to that so writing in and rust doesn't guarantee that it will be faster could make it slower it could make it slower like with everything uh but if you're doing something you know it's something like polar's where you're doing big number crunching uh and you're you know you're calling into the api and then letting it crunch and then it spit another answer out then

Michael Kennedy:yeah you can you can see a significant speed up yeah or pydantic where it comes in as json anyway and it's got to be transformed to something, let that happen in Rust and then talk to it. So yeah, this is really good. I'm going to have Pablo and Laszlo on to talk about the new profiler that's in 3.15. That's really interesting, the profiling module. One of the things that's fascinating about that, I don't have anything in production in 3.15. All my stuff's in 3.14 or lower, like older.

Michael Kennedy:Now, one of the things that's cool about the new profiler is you can attach it to stuff running in production, profile it, and then walk away. You know, like, hey, let's just go, it's running. A bunch of people are using this app, like it's an API or something. Let's just hook onto it for 30 seconds, get some data and step back. And then maybe you could look at, oh, actually, if we could just make this one part faster, that would really be a big deal.

Michael Kennedy:So I think the possibility for this is just getting easier.

Christopher Trudeau:Yeah, well, and, you know, the general advice I give folks when I talk about optimization is don't and then measure, right? So when you're trying to figure it out upfront, it doesn't matter how good you are at this. You tend to make the wrong assumptions eventually. And so, yeah, build something, then profile it, and then figure out where you're spending all your time.

Michael Kennedy:Yeah, I've had a couple of experiences. I won't go into the details of it, but I've told it a time or two way, way back in the day where I was so wrong. Yep. So wrong about what was slow and what was fast. And if I had just pursued my intuition, it would have been months of bad choices.

Christopher Trudeau:Yeah. And there's a concept called Amdahl's Law, which is essentially, I'm going to oversimplify it, but if your code is spending 10% of its time in that place, speeding that up by 2x is only ever going to get you a 10% gain because your code's spending the other 90. There's a diminishing return aspect to it as well. And as programmers, I think we often get tied up in the, oh, wouldn't it be cool if I made this code three times harder to read and it'll be, you know, half a millisecond faster.

Christopher Trudeau:And how often do you call that? Once a year. Oh, okay. Well, there's a month of your life you got back in order to optimize by a millisecond, right? Where you got to find the stuff that is actually causing the problem.

Michael Kennedy:Yeah. You gave a 50% speed up example. Like, let's take it to an insane level. 20% of your code, 20% of time you spend in some bit of code. If you could make it infinitely faster, the best you're going to achieve is your program is going to be 20% faster. You know, maybe, oh, I was running this on a single CPU thread. I'm going to actually get a GPU machine with a crazy thing and do a bunch of GPU programming. And I can parallelize this and I'll get it down to a thousand times faster.

Michael Kennedy:Is that worth a 20% speed up? If it takes five milliseconds, you've saved one millisecond. hooray look how much harder your life and how much more expensive deployment is and so on right yeah yeah so it's certainly uh something that people should keep in mind all right well i think let's let's wrap things up here rust is super interesting i think it's got a place in python and even if you don't want to write rust a lot of these really important libraries are somewhat backed by rust so you want to read them and maybe contribute to the to the caramely shell or the noogity inner, but you still kind of want to understand the bits. I think maybe a quick shout out to your course. People should definitely give this a listen or a watch. Just talkpython.fm, click on course at the top. Rust will be, the Rust course will be right at the top of that list.

Christopher Trudeau:Yeah, it was fun to build. I hope people enjoy it.

Michael Kennedy:Yeah, I think they will. And more importantly, more broadly, I suppose, people want to get started with Rust. You've inspired them, Chris. They're ready. What do you tell them?

Christopher Trudeau:Rustlang.org is pretty much the place to start. It's remarkably well documented. There's a lot of good guides and things out there. The documentation right on that site, they've got the Rust book right there. It's quite easy to follow. It has a lot of really, really good examples in it. So that's definitely a place to go. The other space, just a bit of a shout out would be, there's a awesome list called Awesome Python RS. And it's just a massive list of the tools and libraries that use Rust in the Python space.

Christopher Trudeau:So if you're looking for, rather than like education book examples, you're looking for places that actually use it and you want to, and you want to troll through some code, that's a great place to go looking for interesting libraries to take a look at. Yeah. I second that. I'm,

Michael Kennedy:I'm such a sucker for awesome lists. Yes. That could be, you want to watch a movie? I found a new awesome list. I'm just going to poke around this for like the next half hour, if you don't

Christopher Trudeau:mind, you know? Yeah. And, you know, there's some very classic examples on this list of like drop-in replacement for speed things, right? So there's a cryptography library and there's a JSON library, both of which are basically drop-in replacements for stuff from the standard library. And because they're written in Rust, they're screamingly faster. So, you know, that example of looking for the thing that you need to optimize, there's some good ideas in there that you can dig into.

Michael Kennedy:Yeah. And you know, I gave you the example of like, well, we could just rewrite this bit of your slow code and rust. It might already be written as a library.

Christopher Trudeau:Someone else may have done it as well. Yes.

Michael Kennedy:Yeah. Just swap, swap your JSON parsing library or whatever. Right.

Christopher Trudeau:And, and a lot of the, Python things that are like Python libraries that use rust, a lot of them are actually just thin wrappers to existing rust libraries. So that somebody is rather than writing something from scratch, they're like, Hey, there's this neat library in Rust that does this thing that I like, and I wish it was in Python. And they write like four lines of code that are essentially the API wrapper down to make it, expose it as a module.

Christopher Trudeau:And now we can take advantage of the fact that there's this whole other community that's trying to do these efficient things.

Michael Kennedy:And we don't have to trust the suitability and correctness of somebody saying, hey, I spent a weekend rewriting the JSON parsing.

Christopher Trudeau:Like, ah, brightening. These are things with thousands of stars and many contributors because the Rust community themselves are using them, right?

Michael Kennedy:Right, right. And if you just wrap it, you're pretty safe.

Christopher Trudeau:Polars is an example, right? Polars is a Rust library for Rust programmers. And then there's a Python thing on top of it, right? So you're getting not just the Python people using it, but the Rust people using it as well.

Michael Kennedy:What is that? A caramel dipped apple equivalent version or something like that?

Christopher Trudeau:Yes. I don't know. There's caramel everywhere by the time we're done. So it's a messy, messy kitchen.

Michael Kennedy:It was delicious. It was a delicious episode, Chris. Thank you for being here. That's all right.

Christopher Trudeau:Happy to be here.

Michael Kennedy:Yeah, bye-bye. This has been another episode of Talk Python To Me. Thank you to our sponsors. Be sure to check out what they're offering. It really helps support the show. This episode is brought to you by Sentry. You know Sentry for the error monitoring, but they now have logs too. And with Sentry, your logs become way more usable, interleaving into your error reports to enhance debugging and understanding. Get started today at talkpython.fm/sentry.

Michael Kennedy:And it's brought to you by the Talk Python in Production Book, an inside look at 10 years of the real-world DevOps behind the Talk Python sites and apps. Check it out at talkpython.fm/DevOps book. If you or your team needs to learn Python, we have over 270 hours of beginner and advanced courses on topics ranging from complete beginners to async code, Flask, Django, HTML, and even LLMs. Best of all, there's no subscription in sight. Browse the catalog at talkpython.fm.

Michael Kennedy:And if you're not already subscribed to the show on your favorite podcast player, what are you waiting for? Just search for Python in your podcast player. We should be right at the top. If you enjoyed that geeky rap song, you can download the full track. The link is actually in your podcast blur show notes. This is your host, Michael Kennedy. Thank you so much for listening. I really appreciate it. I'll see you next time.

Christopher Trudeau:I think is the norm. Продолжение следует...

Transcript supplied by the publisher with the episode.

Talk Python To Me

by Michael Kennedy · English · Tech & Science

Talk Python to Me is a weekly podcast hosted by developer and entrepreneur Michael Kennedy. We dive deep into the popular packages and software developers, data scientists, and incredible hobbyists doing amazing things with Python. If you're new to Python, you'll quickly learn the ins and outs…

More from Talk Python To Me

  1. E565 · 2 Oct 2026 · 1 hr 28 min

    #565: Tachyon, Python 3.15's Built-in Sampling Profiler

    Do you know what's actually slow in your Python app? Or are you guessing? Until now, profiling Python meant a tracing profiler that made your code 2 to 3 times slower. Or a third-party tool that broke with every new release. Python 3.15 fixes that. It ships Tachyon, a sampling profiler built into the standard library. It attaches to live production apps with almost zero overhead. My guests are Pablo Galindo Salgado, CPython core developer and Steering Council member, and László Kiss Kollár from Bloomberg's Python infrastructure team. Their first prototype ran at two samples a second. Now it…

  2. E564 · 22 Sep 2026 · 1 hr 8 min

    #564: EVE Online Departs for Python 3

    Every ship in EVE Online eventually undocks and leaves the station. This time, it's the whole game. EVE has run on Python 2 since it launched in 2003, all 2.4 million lines of it, on a custom Stackless interpreter that stopped at 3.8 and was archived last year. Destination: Python 3.12. The route runs through 6,500 lines of division that decide who wins a fight, and 100 gigabytes of pickled Python objects that have to survive the jump intact. Kristinn Sigurbergsson was on this show ten years ago. He's back, with Jamie Bannister, who is flying the EVE Online migration right now, and Thomas…

  3. E562 · 10 Sep 2026 · 1 hr 11 min

    #562: DuckLake: The Lakehouse That's Just SQL and Parquet

    How many files does your query read before it reads any data? On some data lakes, you go through JSON and metadata files first, just to learn which Parquet files matter. DuckLake asks one SQL question instead. The metadata lives in a real database. The data stays in plain Parquet. That's the entire format. Pedro Holanda joined DuckDB in 2018, when it was still a research prototype at CWI. He's the lead DuckLake developer. Guillermo Sanchez Dionis works on DuckLake and the new Quack protocol. With Quack as the catalog, DuckLake handles 200 transactions a second under heavy contention. No…

  4. E561 · 4 Sep 2026 · 1 hr 16 min

    #561: TonIO, a Multi-threaded Async Runtime for Python

    How many cores does your machine have, 10, 18? Your async Python code uses just one of them. That isn't a bug in asyncio. That's the design, and optimizing event loops to be faster by 20% doesn't change it. So Giovanni Barillari started over. Joe is the creator of Granian, the Rust-based server that powers Talk Python. His new project is TonIO, an async runtime written from scratch for free-threaded Python. Real threads, a handful of primitives instead of asyncio's pile of them, and it flat out refuses to start if the GIL is on.

  5. E560 · 26 Aug 2026 · 1 hr 3 min

    #560: Building a Research OS: From Django to 30,000 Samples

    In 2020, a gastroenterologist in Glasgow did the math on his new research study and came up with 30,000 samples, arriving over two years from three cities and a dozen hospitals. He asked around about how researchers keep track of that. The answer was Microsoft Excel. Shaun Chuah had written some HTML by hand in Notepad back in high school and that was about the whole of his programming experience, so he opened the Django tutorial and started reading. Six years later that app is Foundry120, holding 10 terabytes of clinical and genomics data with an agentic AI running on top of it.

  6. E559 · 19 Aug 2026 · 1 hr 8 min

    #559: 12 Things You Should (and Shouldn't) Do in AWS

    Your site is down. It's 3am. Is it a bug, a bill, or a breach? You can't tell yet, and everyone is watching you find out. Matt Lea has spent fifteen years being the person companies call when an outage is costing them real money per hour, and his whole argument is that everything you'd want in that moment gets decided months earlier, on ordinary afternoons, when someone chose the convenient thing. We walk his top twelve dos and don'ts in AWS - infrastructure as code, IAM roles instead of access keys, private subnets, no wildcards, no public buckets - and I push on which of them actually…

  7. E558 · 10 Aug 2026 · 1 hr 2 min

    #558: Hyper-Personal Software with Python

    Every company has one. The little internal tool that Jane built back in 2021, and then Jane left. Nobody understands it, nobody will touch it. There are two unwritten rules around it: don't change it, it's working. And if you break it, you bought it. That's dark-matter enterprise software. For every app you can actually see, there are ten of these sitting in the shadows, frozen. Michael Booth thinks that just changed. He read my article on hyper-personal software and ran with it, writing about hyper-team software: small teams inside big companies finally building the tools that were never…

  8. E557 · 2 Aug 2026 · 1 hr 8 min

    #557: Security of everything at PyCon 2026

    Security has always been the vegetables of software. Everyone agrees it matters, and somehow it never quite makes it onto the plate. At PyCon US this year, that changed. For the first time ever, security got its own dedicated, day-long track, one of just two at the whole conference, sitting right next to AI. And the room was packed to the back wall. On this episode, I'm joined by the three people at the center of it. Seth Larson, Security Developer in Residence at the Python Software Foundation and, very recently, a CPython core developer. Juanita Gomez, a PhD researcher at UC Santa Cruz in…

  9. E556 · 26 Jul 2026 · 1 hr 5 min

    #556: Updates on Django's Async Story

    For years, "Django and async" came with an asterisk. The docs themselves warned you off it. Scary performance notes, a story that felt half-finished. Well, that story just got rewritten, literally, and the person who rewrote it is here to tell you why the old framing was wrong. Carlton Gibson is a former Django Fellow, sat on the security team for eight years, and he's on the steering council. On this episode we get into the async topic doc rewrite, what actually remains versus what was just fear, the new Tasks framework in 6.0, DB-level cascades and fetch modes landing in 6.1, and why…

  10. E555 · 13 Jul 2026 · 1 hr 5 min

    #555: Marimo Pair - A Canvas for Agent + Developers Collaboration

    Coding agents have gotten really good at one kind of work. You scope a feature, edit some files, run the tests, ship it. It all happens on disk. But that is not how data work feels. You load something, you look at it, you run a cell, you watch how it responds, and you decide the next move from whatever is sitting in memory. And until now, your agent couldn't see any of that. It only saw the files. Never the live state. This episode, that wall comes down. marimo pair drops a coding agent right inside a running notebook, with full access to every variable Python is holding in memory. The…

Every episode of Talk Python To Me →

Take it with you

The Melo app keeps playing with the screen off, works in the car and on your watch, wakes you to your station, and browses the whole catalogue offline. Free, no ads, no account.

Get it on Google Play