- Podcasts
- Python Bytes
- #476 Common themes
About this episodeTopics covered in this episode: Migrating from mypy to ty: Lessons from FastAPI Oxyde ORM Typeshedded CPython docs Raw+DC Database…
- Migrating from mypy to ty: Lessons from FastAPI
- Oxyde ORM
- Typeshedded CPython docs
- Raw+DC Database Pattern: A Retrospective
- Extras
- Joke
Transcript
From the publisherThis transcript comes from the podcast’s own feed, shown as the publisher wrote it.
#476 Common themes
Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds. This is episode 476, recorded April 6th, 2026. So many sixes, Brian. I'm Michael Kennedy. And I'm Brian Okken. And this episode is brought to you by us. We have all sorts of awesome things to help you get better at Python, testing and so on.
Check the show notes. Subscribe to the newsletter. We've got a bunch of cool things we're sending out there. And every week, one of them, every week is a nice, extra rich summary of what we talked about, what we're covering, but also additional places to find more materials. So you can get a little bit of the background information.
I think Firefly is Rust. It is, I believe. Yes. Okay. But it's not, Firefly is not noticeably laggy. But mypy is. And mypy is definitely something I use in CI. But anyway, well, I'm bringing this up because there was a post by Sebastian Ramirez, and I just went away from it, that all of his Python projects like FastAPI, Typer, SQL Model, Async, or all of that stuff.
It's all just using, it's all using Ty now for the primary type checker. And so I'm thinking, and I had tried on for a couple of projects, and it was a little bit pickier than I expected. So I tried it again. So I went ahead and migrated pytestCheck to use Ty, and I'm kind of doing a similar model, and it's going well.
So anyway, he migrated that stuff, and then Tim Hopper wrote a blog post called Migrating from mypy to Ty, Lessons from FastAPI. And it's a pretty fun walkthrough of some of the things because it's really pretty easy to migrate. So the idea around it, I'm going to skip down to the end because he's like, well, if you want to do this yourself, what should you do?
Add Ty alongside of mypy. And that's what I'm doing with pytestCheck, doing both mypy and Ty. Actually, I've got them as two different talks, runs, sections to run them separately. But locally, I'm just running Ty because it's so fast. It's like it runs and it's done, whereas mypy, I have to wait a few seconds.
I want to have it completely clean with no warnings. So you can set error on warning is true. If there's parts where you have to comment out, like you have to ignore certain lines for some reason, the annoying part right now is that you have, and I'll go back up to this discussion up here, is that you have to do two.
But support's a better way to say ignore these sets of things. Apparently that works. So anyway, check out the model if you want to have ignores. I don't actually have, I think I have a few ignores, but not too many. And a lot of them are because I intentionally try to do something bad to simulate an error.
So drop mypy when the noise exceeds the signal. So, right. So the SQL model had too many, like it wasn't worth having supporting both because of all the different ignores and all that stuff. I'm currently, I've had so many people request mypy support for pytest check. So I'm not planning on dropping it anytime soon.
And for a lot of packages, I believe that's probably going to be the case of people just supporting both for a long time. And one of the really unfortunate things about how Python typing works, there's a lot of good things about it. So don't call me a hater. But one of the really unfortunate things is even amongst ty and Pyrefly, there are different conventions and warnings and things that count as errors and things that don't count as errors.
But somebody was doing something with flask. And when you put the decorator onto a view that the web framework calls, it changed the signature in a very subtle way. And the signature is extremely complicated at the definition level. I mean, it's like multiple lines of what the warrant of the signature problem was, you know, not just like expected in, but it was really a lot of like stuff going on there.
And it said that that was wrong. I'm like, who cares? No one's ever calling it. Like no one calls a view function. It didn't, nobody gave it a definition that it's this big complicated thing, but somehow the framework, you know, like it was just, I think the something about the app.get decorator expressed a type and then it changed that type.
That's dumb. But people were using it. They would just get like loads of error. Like every viewpoint in their Flask function would have an error in Pyrite. Right now I have stuff in my code where it's got ignore statements for Pyrefly. But if I load it up in ty, ty gives me a warning that the ignore statement is unneeded.
I'm like, it's not unneeded for you, but it's unneeded for that. Like, are you, anyway, this is why I say that. Like, it's just, it's a, it's a struggle. And if you create a library to your point, then you've got to put yourself in the situation where like, you don't have to work for a type checker that you choose.
You work for everyone's type, all the type checkers. Cause whatever anyone may choose will become applied to your usage. Right. In their project, which is anyway. Rant over. Yeah. Luckily I haven't had too many issues with, after, after supporting my Pi, that was the big one. I think more people are using my Pi than anything else, but I think we'll see a shift.
One of the things that I did want to call out also related to this is ty, ty, whatever you call it. Charlie says it's pronounced ty. TY. TY did catch one problem in pytest-check that I was like, oh, this, this, well, it's a hidden possible problem. And I just, this is quick, but I have support for pytest versions and, but I have runtime behavior that changes based on version because of, because of when pytest added features.
so I was expecting, this version tuple to be integers and just comparing like, you know, is seven Oh three seven Oh, less than or equal seven Oh, sort of a thing. But the version tuple can be a string and ty caught that. And so I have, some code that I've converted to using, a thing called packaging.
It's right here. It's supported. use it. So anyway, very nice. Okay. Next topic. Next topic. I want to talk about a ORM built in rust. Very interesting. So this is basically an instead of Django ORM, which I think is really interesting. There's a lot of ORMs out there that are like, this is a great ORM.
You can use it for anything except for you can't use it for Django. Sorry. Bye now. Why can't you use it for Django? Because Django so deeply cares about the models using the models to drive other things. The models generate forms. The models generate the admin. The, like the models and the way that ORM works in Django is kind of like what makes Django, Django.
Like if you don't care about any of that stuff. Why are you using Django? Pick a micro framework, you know, whatever. Right. The reason you choose Django is because it has all these Lego blocks that you can use. Right. Okay. So this one called Oxide ORM, believe it is a, it's got to be written in Rust given that name.
But what it is, it is a type safe, Pydantic centric async ORM with a high performance Rust core. And it's inspired by Django. It's not necessarily, it doesn't necessarily sell itself explicitly replacing Django, but I will tell you why I made this call back in a second. So, Hey, this is a young project.
So like one of the things you got to do is, okay, you gave me a model called customers, which is a Pydantic class. What does that mean in terms of a SQL query when you say dot city equal equal, whatever, right? That kind of stuff. Multi-database support, of course, transactions, migrations, Django style migrations and a migrate CLI.
Piccolo, 930. Django, 730. So just almost exactly 2x of Django and 4x of SQLAlchemy, 4x of SQL Model. I mentioned, you know, tie back there. And holy moly, PeeWee is at 80 versus 1,400. So that's pretty wild. And then obviously all the type checking, you know, they've got this query of like, hey, here's how you would do a really long, complicated query in both in Django and Oxide.
The only difference, literally the only difference in these, you know, probably a 90 line, 90 character 90 column rather, same thing, 90 column query on the ORM. The only difference is the await keyword because it's async, which is pretty sweet. So yeah, good stuff. Now back to Django a little bit more.
Very cool. She says a very cool project, which realizes something I've wanted for a long time, documentation for Python with type shed types. So what are we talking about? I did a comparison of side by side. So if we take a look at like the function, the docs.python.org at the built-in functions, you get like ABS, like absolute for absolute.
And it takes a number. But what type is number? Well, this new project has, has the same, it's basically the Python docs, but with types. So how, how that function signature would look with types. And this is all from type shed. So, the project, that we're shouting out to is, well, it's a, it's a GitHub.io thing, but, it's an open source called type shedding CPython docs, a tool for, to find missing type shed stubs and generate type annotated CPython docs.
That's pretty, that's pretty much it. just as, if you want to look at anything in the docs, but with types, there you go. like what is a slice take? Oh, slice takes, you know, well, it's going to be like. It's an any, any, not too much. Any, any. that. But there's somewhere probably, interval of or something.
Read the docs or check this out or I'm going to, you know, and if it has type information that really gives it a lot more to work with. Yeah. And also because like, that, that the docs, the Python docs are really for us, but type shed is really not for us. So the kind of the idea to combine the information in type shed and present it as the docs, it's pretty kind of, it's kind of a clever thing.
So. Yeah. It's very clever. And also if you're doing something kind of like something built in, you can look at, you know, look at what the types are with that and try to match it. Yeah. Definitely. All right. Shall we keep with our theme or yeah, of, of theme swapping. So yeah, like to just keeping the theme going.
So I want to talk about databases some more. Okay. And, and ORMs, but from a different perspective this time a little bit in the sense that I wrote an article, the article I want to talk about is raw plus DC database pattern, a retrospective. This is, this is pretty interesting, but in order to talk about, let me just talk about the design pattern that I published real quick.
So people maybe didn't read that article or they didn't listen a couple episodes ago or something. Right. So my thesis is there's a couple of reasons why depending on maybe smaller ORM libraries, it's not that great of an idea necessarily. One is if that thing goes unsupported, you've got a good chunk of your application and a foundational portion of it that is tied to this potentially unsupported thing.
So make that concrete Talk Python Training. When I created it, it was based on Mongo engine and that was a up and coming super nice query syntax. Also models exactly the Django ORM by the way, by oxide, like oxide ORM. So a lot of the queries in there looked very much like they were Django, but they were object-based going to MongoDB.
Right. So that's great. But fast forward 10 years and that thing's had a couple of releases that like changed the read me in five years. Like, and for reasons, maybe I'll get to later, like another episode is I wanted to switch this to async. I wanted to switch Talk Python Training to async, but this older ORM library was not ever, ever going to move to adopt an async model.
Yeah. And it's a, it's also probably a scratch your own itch sort of thing. If they, if the current project does what they needed to do, why, why update it? Yeah. And they're not obligated to, but I'm also not obligated to keep using it. Right. Yeah. So that was, that's number one is like, is there a more stable base and the stable basis, whatever the core database driver package is.
In this case, it's PyMongo, but you know, could be just the core one from the Postgres team talking to Postgres with Python. Right. Like that's what all these ORMs are based on often anyway. I mean, oxide ORM is not quite, probably based on the Rust version that the Postgres team provides or whatever.
Right. So something like that. So that's one. The other one, the raw part has to do with this theory that I have that talking to, when you're working with agentic AI, they know frameworks, but what they really know super well is the foundational stuff. Like they probably know SQL model, but they really know SQL, you know?
Yeah. They probably know Mongo engine a little bit, but they really know just queer, like raw MongoDB queries. And so that's the idea is like, like, what if we just had a data access layer that was just raw queries and it returned some kind of rich classes like data classes. Now, before people email me, cause I've talked about this on Reddit and like three fourths of the comments were, why aren't you using Pydantic?
You could use Pydantic here. Do you know that you're using data classes when you could use Pydantic? You have no type. Like, yes, sure. You want to call it raw plus Pydantic and use Pydantic instead is literally the same thing. You're totally welcome to do that. Right. I just wanted something simple.
Okay. So all that's so I can tell you about my retrospective. So I wrote up this thing where I rewrote Talk Python training. Now Python Bytes is already using this, so it already gets this benefit. But I did this for Talk Python training, the courses. I said, well, let me just put it into practice and see how it goes and if it's any better.
So I came with pictures, Brian, look at these pictures. MongoEngine, the raw plus DC pattern. It's almost 2x more requests per second for the same hardware, the same everything else. Just switching this out. And the bonus is you get a much more stable library to program against. And AI is really good.
If you say, hey, AI, hey, Claude, create me an update function to do this thing. And it can do that better, right? It has a more, much, much, much, much more training information to do that with. And you get 2x performance. And even when you're doing 2x the number of requests, you still get quite a bit faster response time.
That's pretty cool. Yeah. Pretty neat, right? Yeah. And you scroll down. Another bonus is actually about 10% less memory usage as well. That's good. Because apparently the ORM and the classes that it uses and the tracking and whatever just hangs on to junk more. I don't know. I mean, I'm still using classes, right?
So for this kind of stuff, I'm like, if I need to read and parse and validate data, I'm doing data class of wizards along with data classes. But people are certainly welcome to choose attrs. They're welcome to choose Pydantic. They all work good in this model. Well, and especially to give other people their due for projects that already have Pydantic for other reasons, that makes sense also.
Yeah, yeah. Absolutely. Absolutely. All right. All right. How extra are you feeling? I've got one extra. All right. Tell us. Just this weekend, I released a 0.5 release of the, I know I haven't talked about this much lately, the Lean TDD book that I was working over the fall and over, I guess, over Christmas.
I think it's a good resource to go ahead and run with. But I'm doing a third pass through right now with some comments from some trusted readers. And, yeah, anyway, there'll be some expansion, but not, I don't think, a huge direction shift in the future. Because I really want to get this done and wrapped up.
You know, you've got some files. It tells you how to build things or test things or whatever, right? Like, was syntax inspired by Make? There you go. So Make is kind of long and gnarly and Just is more YAML-ish and cleaner, I think. I don't know. Anyway, it's a cool way to sort of structure automation for your projects, right?
So it lets you test, like, really nice things like just assert there exists a CI, a CI section. And that CI has a test. And it depends on test following the transitive dependencies of it and so on. So anyway, I thought that was kind of cool. So if you do stuff with Just and pytest, check out pytest-Just.
Cool. All right, this next one needs a disclaimer before I go into it. I was not going to put... I was not going to talk about this, Brian, because I don't want to... You know, it's just not like TMZ bytes. Python bytes. There's a lot of drama here. But I think it's pervasive enough that I think we should put it on people's radar.
So I'm not here... What I'm about to describe, I'm not here to take sides in. I'm not here to, like, bad light on anybody. But there's a mad level of turmoil around the encode projects. HTTPX, Django REST Framework, uvicorn, Starlette, which is the foundation of FastAPI, MKDoc. I mean, that is a mega set of dependencies that people depend upon.
Maintainer of HTTPX closed off access to issues and discussions last week. Hasn't had a release in a year. I wonder what's going on. Michelle says, I forked HTTPX to HTTPXXY. Talks about why. Transfer of uvicorn and Starlette causes a great bunch of stirs. There's an article called The Slow Collapse of MKDocs.
Yeah. And that ties into Zensical, right? Yeah, exactly. And so basically this documents over time all the stuff that is going on that has led to Martin and his co-founder creating Zensical, which was Material for MkDocs. But they found like, yeah, basically that this was becoming something they couldn't continue to work with.
So they had to do something else. And Django REST framework is there's an inspiration to somebody's proposed that it gets taken into Django Commons. And Django Commons is this project to basically find and maintain packages that are important to Django that are kind of going unmaintained in a sense.
And so in this conversation I'm linking to, there's a bunch of people like, this is kind of a good idea. But the people who are actually maintaining like, but I'm not really sure I'm going to come over and become the main maintainer. So it's sort of stalled out. Anyway, again, not trying to throw shade or call anyone out, but there's enough going on there with enough important projects that it's worth being at least awareness.
Yeah. Yeah. Sad. Okay. Not sad. Something awesome. This is very awesome. This one I like quite a bit is announcing course completion certificates over at Talk Python. So I don't work in a big company, so that's not super relevant to me. So I have not really maybe given it as much love and attention as people want me to.
So now I have. So what I've done is I have a nice dashboard that I released maybe a month ago and talked about that, I think, that shows you what courses you're working on, how far you are through them, which ones you recently have most recently taken at Talk Python and so on. But also, and if you have a bundle of like 50 courses, which a lot of people do, then it's like, well, here's a huge long list.
Which one was I doing again? You know, it really helps like solve that problem. But now for the completed courses, it has a certificate section and you click that, it gives you a standard old PDF certificate that you can use if you have like continuing education requirements or something like that, where you need to submit an official certificate to your company or whatever.
So that's kind of fun. But more importantly, more fun, I think, is there's an option to say, publish this as an official certificate on LinkedIn to my profile. So like one button click from Talk Python in your account, boom, takes you over, populates and fills an official certificate, even with a show your credential, which takes you back to an official.
Yes, this credential is valid, verified for you page on LinkedIn. So that's pretty cool. Yeah. So if you take a bunch of courses, you know, and you want to have those there. So people go, oh yeah, they did actually take that flask class. That's right. They know a little bit more than, you know, maybe just flask is like a skill or something.
So. Can I print it out and like pin it to my cubicle wall? You know what? You could print it out and get that on like a matte finish. Yes. Yeah. You can't even get the PDF. You could print it out. It's actually, it's actually like letter, US letter size. That's awesome. If it prints, like I had to get the DPIs of the image exactly right to fit for that.
So it just. Nice. I had a joke also, but I think let's save mine for next week and let's just use yours. Okay. Here's the funny things. I don't even remember what the joke is, but I'm going to look and then we're going to find out together. Oh yeah. Here we go. It's about AI. So this, I entitled this Noya Rich, the new rich in the eighties.
Think Don Johnson. Think standing by a big mansion in Florida and Miami, Ferrari Testarossa in the back. Like this is rich in the eighties. Rich in 2026 in modal change the button color to green. Opus six, four, six. Yeah. It's which model are you using there? Yeah. And just like do like the completely most simple, a find and replaced or just a find and a type, the letter, the word green would take care of it.
But you've been there before. Well, yeah. I've lived here for 15 years now and I, but still, I can't, I don't carry a plastic map or anything like that with me. So. Yeah. I don't know if I even have an Atlas in the car anymore. Like if for some reason my device broke and I was on a trip, I might just be there.
