Latest / Talk Python To Me / #432: Migrating to Pydantic 2.0: Beanie for MongoDB
Transcript
- 0:00By now, surely you've heard how awesome Pydantic version 2 is.
- 0:03The team led by Samuel Colvin spent almost a year refactoring and reworking the core
- 0:07into a high-performance Rust version while keeping the public API in Python and largely unchanged.
- 0:13The main benefit of this has been massive speedups for the frameworks and devs using Pydantic.
- 0:18But just how much work is it to take a framework deeply built on Pydantic and make that migration?
- 0:24And what are some of the pitfalls?
- 0:26On this episode, we welcome back Roman Wright to talk about his experience converting Beanie,
- 0:31the popular MongoDB async framework based on Pydantic, from Pydantic 1 to 2.
- 0:36And we'll have some fun talking about MongoDB while we're at it.
- 0:39This is Talk Python To Me, episode 432, recorded August 16th, 2023.
- 0:45Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:01This is your host, Michael Kennedy.
- 1:03Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython,
- 1:08both on fosstodon.org.
- 1:10Be careful with impersonating accounts on other instances.
- 1:13There are many.
- 1:14Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:19We've started streaming most of our episodes live on YouTube.
- 1:23Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows
- 1:29and be part of that episode.
- 1:31This episode is brought to you by Studio 3T.
- 1:34Studio 3T is the IDE that gives you full visual control of your MongoDB data.
- 1:39With a drag and drop visual query builder and multi-language query code generator,
- 1:44new users will find they're up to speed in no time.
- 1:47Try Studio 3T for free at talkpython.fm/Studio 2023.
- 1:52And it's brought to you by us over at Talk Python Training.
- 1:56Did you know we have over 250 hours of Python courses?
- 2:01And we have special offers for teams as well.
- 2:03Check us out over at talkpython.fm/courses.
- 2:07Roman, welcome back to Talk Python To Me.
- 2:11Hi.
- 2:12Hey, so good to have you back on the show.
- 2:13See you again.
- 2:14Yeah, you as well.
- 2:15Thank you.
- 2:15How have you been?
- 2:16So it was a nice adventure for me.
- 2:18Like, these two years of building Python projects, of moving to other countries.
- 2:25So, yeah.
- 2:26Are you up for sharing that with people?
- 2:27What are you up to?
- 2:28Sorry?
- 2:28Are you up for sharing where you've moved to?
- 2:30Last time we spoke, you were in Berlin, I believe.
- 2:33I was in Germany.
- 2:34And now I'm in America.
- 2:35So, completely different country.
- 2:38Completely different continent.
- 2:40Yeah.
- 2:41Are you enjoying your time there?
- 2:42Yeah.
- 2:42So, I like it so much.
- 2:44Honestly, I like Germany too.
- 2:46So, Germany is a great country.
- 2:48But I like different things.
- 2:50Yeah, but you're probably looking forward to not freezing cold winters.
- 2:53I want to try.
- 2:54Honestly, I don't know if I will like it or not.
- 2:57But I want to try until just a few years, for example.
- 3:00I moved to San Diego, California a long time ago.
- 3:04I didn't really enjoy the fact that there was no winters and there was no fall.
- 3:08It was just always nice.
- 3:10Always.
- 3:10Until one day I realized, you know what?
- 3:12We just headed out mountain biking in the mountains.
- 3:15And the weather was perfect.
- 3:16And it was February.
- 3:17And we didn't even check if it was going to rain or be nice.
- 3:21Because it's always nice.
- 3:21You know what?
- 3:22That's a good trade-off.
- 3:23You could do a lot of cool stuff when you live in places like that.
- 3:26So, I'm glad to hear.
- 3:27I'm glad to hear.
- 3:28You'll have to let us know how it goes.
- 3:30And Beanie has been going really well as well.
- 3:35Right?
- 3:35So, when we first spoke, Beanie was just kind of a new project.
- 3:39And the thing that caught my eye about it was two really cool aspects.
- 3:44Asynchronous and Pydantic.
- 3:46I'm like, oh, those things together plus MongoDB sound pretty awesome.
- 3:49And so, it's been really fun to watch it grow over the last two years.
- 3:53And it's gaining quite a bit of popularity.
- 3:55I don't know.
- 3:55It's kind of popular, but not that much.
- 3:58As Pydantic itself, as FastAPI.
- 4:00But, yeah, still popular in context of MongoDB.
- 4:02I think it's a little bit different than a web framework, potentially.
- 4:05Right?
- 4:06Like, it's hard to say, you know, is it as popular as FastAPI or Flask or something like that.
- 4:11Right?
- 4:12Because those things, you know, those are the contexts in which this is used.
- 4:16But not everyone uses Mongo.
- 4:17Not everybody cares about async Mongo.
- 4:19All that, right?
- 4:19There's a lot of filters down.
- 4:21But it's, I think you've done a really great job shepherding this project.
- 4:24I think you've been really responsive to people.
- 4:27I know I've seen the issues coming back and forth.
- 4:29I've seen lots of releases on it.
- 4:31And I guess the biggest news is around, yeah, you're welcome.
- 4:35I think the biggest news is around, you know, when Pydantic 2 came out.
- 4:39That kind of changed so many things.
- 4:41You know, I spoke to Samuel Colvin about his plan there.
- 4:46I spoke to Sebastian Ramirez from FastAPI about, like, what he was thinking and where that was going.
- 4:53And it sounded like it was not too much work for people using Pydantic, but quite a bit of work for people like you that was, like, deep inside of Pydantic.
- 5:01Yeah?
- 5:01Yeah.
- 5:02So, honestly, I have a Discord channel for support Bini users.
- 5:06And there I was talking with other guys, like, probably, I'm sorry,
- 5:11but probably I will not support both versions at the same time.
- 5:14Maybe I will have two different branches of Bini with V1 and V2 supporting.
- 5:19But finally, I am ended, you know, in a single branch.
- 5:24And this was very challenging, honestly, because...
- 5:27Okay, interesting.
- 5:28I didn't realize you were going backwards in that maintainability there for the people who didn't want to move to Pydantic 2.
- 5:35Yeah, there are legacy stuff.
- 5:37It must support new features for Pydantic 2.0 also, definitely, because it may be...
- 5:44Maybe people want to move to Pydantic 2.0, but they could be stuck on other libraries that support only V1, for example.
- 5:50And it can go for a while, like, months.
- 5:53And even for me, it took, like, three weeks to make it work.
- 5:59Just so people know, pockpython.fm and pythonbytes.fm, both of those are based on MongoDB and Bini.
- 6:07And when you came out with the new one, I saw when the release for V2 came out, like, all right, how long until Bini supports this?
- 6:15You know, and I saw that you were, like, right on top of it and working on that.
- 6:18That was great.
- 6:18And then when I went to upgrade it, it was really easy, right?
- 6:23Just I use pip-tools and I use pip compile to just get all the latest versions of the dependencies and update the requirements.
- 6:29So then I installed a new one and it wouldn't run because there's not because of anything that Bini did,
- 6:35but just some changes to Pydantic 2.
- 6:37For example, if I had a, let's say there's a database field that was URL and it was an optional string.
- 6:44In Pydantic 1, you could say URL colon optional bracket str.
- 6:50That's it.
- 6:50But there's no default value explicitly set.
- 6:53So in Pydantic 2, that's not accepted, right?
- 6:56It says, no, no, no.
- 6:57If you want it to be none by default, you have to set it to be none explicitly.
- 7:01So I had to go through and, like, find all my database documents.
- 7:04Basically, anytime there's an optional something, set it equal to none.
- 7:07And then that was it.
- 7:08That was the upgrade process.
- 7:10And now the website runs faster.
- 7:11Thank you.
- 7:12Welcome.
- 7:12Yeah, I invented a middleware, like a few classes and functions that just check if you use Pydantic
- 7:201 or Pydantic 2.
- 7:22And based on this, you use a different kind of backends.
- 7:25But interface is the same for both.
- 7:28So I'm a unified interface inside of Mini.
- 7:31So before we get too far down this conversation, give us two quick bits of background information
- 7:37here.
- 7:37First of all, why MongoDB?
- 7:39There's a lot of excitement around things like MySQL, but especially Postgres, relational
- 7:46databases, MongoDBs, document database.
- 7:49Give us the elevator pitch.
- 7:50Why do you like to work with Mongo?
- 7:52Honestly, I like to work with all the databases.
- 7:54I become databases fun and nerd.
- 7:57So I like them all.
- 7:59But yeah, MongoDB is a document database.
- 8:02And it means the schema, the data scheme is much more flexible than in SQL databases.
- 8:08Because in SQL, you use tables, plain tables, while in MongoDB, you use extra documents,
- 8:14which could be nested.
- 8:16And the level of this nestedness could be really, really high.
- 8:20There are some trade-offs based on this.
- 8:23The relation system for plain tables could be implemented much simpler than for documents
- 8:30because this flexy structure is hard to make nice relations.
- 8:35But I'd say it's much more useful for if you use nested data structures in your applications,
- 8:44it's much simpler to keep this same data structure in your database.
- 8:49And this makes all the processes of development much more easy and more simple to understand
- 8:56them, I'd say.
- 8:57You don't have the so-called object relational impedance mismatch, where it's like, well,
- 9:02you break it all apart like this in the database, and you reassemble it into an object hierarchy
- 9:06over here.
- 9:07And then you do it again in the other way.
- 9:09And all that stuff, it's kind of just mirrored the same, right?
- 9:12True.
- 9:12And I really like MongoDB to make small projects.
- 9:16I mean, when I just want to play with something.
- 9:19And I play with data structures a lot.
- 9:21And using Postgres or MySQL, I have to do a lot of migrations.
- 9:26Because when I change the type of field or just the number of fields, I have to do this
- 9:31stuff.
- 9:31And this is kind of annoying, because I just want to make fun and to play.
- 9:36Yes, exactly.
- 9:36Exactly.
- 9:37For me, it's easy to make MongoDB fast.
- 9:41And it's operationally almost trivial, right?
- 9:45If I want to add a field to some collection, I just add it to the class and start using it.
- 9:50And it just, it appears, you know, it just shows up.
- 9:52And you want adding an asset object?
- 9:54You just add it.
- 9:54And it just, you don't have to keep running migrations and having server downtime and all
- 9:58that.
- 9:59It's just, it's glorious.
- 10:00Okay, so that's the background where people maybe haven't done anything with Mongo.
- 10:03What about Beanie?
- 10:04What is Beanie?
- 10:05Really quick for people.
- 10:06We're talking about it a bit.
- 10:07But give us the quick rundown on Beanie and why you built it.
- 10:10Like there were other things that talked to MongoDB and Python before.
- 10:13Yeah.
- 10:13So there's a lot of tools.
- 10:15There is MongoEngine, which is nice and which is official.
- 10:18Yeah, I like MongoEngine too.
- 10:18Yeah.
- 10:19Yeah.
- 10:19But one day I was playing again with new technologies and FastAPI was super new at
- 10:26time.
- 10:26It was like, it wasn't that famous at time, like three years ago.
- 10:30And already was super nice.
- 10:32And I wanted to play with it before I can use it in my production projects.
- 10:37And I found that there is no nice, let's say, connector to MongoDB from FastAPI because
- 10:45there is nothing that could support and Pydantic and asynchronous MongoDB driver motor.
- 10:50And I decided like, but why?
- 10:52I think I can implement it myself.
- 10:54Why not?
- 10:55And I made a very small, tiny ODM.
- 10:58I even thought it would be tiny all the time.
- 11:01It was like, you know, it could support only models of the documents.
- 11:05It could insert them.
- 11:06And all the operations of MongoDB, it wasn't hidden inside of Beanie.
- 11:13You had to use MQL, Mongo query language there.
- 11:17So I just released this.
- 11:18And somehow in one month it got not that popular, but people just came to me and like, I like what
- 11:26you did.
- 11:27Could you please add this feature and that feature?
- 11:29And this part works wrongly.
- 11:31So please fix this.
- 11:33And I was like, whoa, I didn't know, but I made an open source product.
- 11:37Wow.
- 11:38Yeah, that's cool.
- 11:38Some weird podcaster guy goes, this is great, except for where the index is.
- 11:42Yeah, this was like first or maybe second week after I published it.
- 11:46And yeah, you came to my, to GitHub issues.
- 11:49Could you add indexes?
- 11:50And I was like, I forgot about indexes.
- 11:52Yeah, I have to add them.
- 11:54Yeah, indexes are like database magic.
- 11:56They're just awesome.
- 11:57So yeah, and this was kind of playground project.
- 12:00And now this is nice.
- 12:01So damn, I'm going to be.
- 12:03It's been really, really reliable for all the work that we've been doing.
- 12:06So good work on that.
- 12:07Let's see.
- 12:08I guess there's two angles to go here.
- 12:11One, if we go over the releases, the big release is this 1.21.0, which says Pydantic V2 support.
- 12:20So I want to spend a lot of time talking to you about like, what was your experience going from Pydantic 1 to 2?
- 12:25Because as you said, there's the really famous ones like FastAPI and others.
- 12:30But there's many, many projects out there that use Pydantic.
- 12:34I wonder if we could get it to show it.
- 12:36So, you know, GitHub has that feature where it shows used by 229,000 projects.
- 12:43228,826 projects.
- 12:46Yeah, they're all the projects with Pydantic now, right?
- 12:48Exactly.
- 12:49Just on GitHub, use Pydantic.
- 12:51So, you know, many of them still haven't necessarily done this work to move to 2.
- 12:57And so I want to make that the focus of our conversation.
- 12:59However, since we had a nice episode on Beanie before, before we get into that aspect,
- 13:04let's just do a catch up on like what's happened with Beanie in the last two years.
- 13:08What are some of the cool new features and things that you want to highlight for folks?
- 13:12I added a lot of features, honestly.
- 13:14But there were a few really big.
- 13:17I really like one.
- 13:18I didn't know that it could be needed for anybody.
- 13:21But I was continuously asked about, please add, add this.
- 13:25And I didn't want to add.
- 13:26But finally, I added.
- 13:28And now I love this so much.
- 13:30This is called inheritance.
- 13:32You can inherit documents.
- 13:35So you can make a big inherited structure like car, then vehicle, then
- 13:42from here you can inherit bicycle, by car, and from car inherit something else.
- 13:47And the thing is, everything will be stored in the same collection, in the same MongoDB collection.
- 13:54And if you want to make statistics over all the types, you can do it.
- 13:59And when you need to operate only with a type or subtype, you can do it as well.
- 14:05You can choose what you want to do.
- 14:07And I know this feature is used in productions now in many projects.
- 14:12And this is nice.
- 14:13Yeah, this is really cool.
- 14:14So when I first heard about it, my first impression was, okay, so instead of deriving from beanie.document, you create some class that has some common features, maybe properties and validation and stuff.
- 14:27And then other documents can derive from it.
- 14:30So, like you said, bicycle versus car.
- 14:33But in my mind, those would still go into different collections, right?
- 14:37They would go in different collections.
- 14:38And that would just be a simpler way to have the code that would have a significant bit of reuse.
- 14:42But the fact that they all go into the same collection and the documents are kind of supersets of each other, I think that's pretty interesting.
- 14:49I hadn't really thought about how I'd use that.
- 14:51This portion of Talk Python To Me is brought to you by Studio 3T.
- 14:57Do you use MongoDB for your apps?
- 14:59As you may know, I'm a big fan of Mongo and it powers all the Talk Python web apps and APIs.
- 15:04I recently created a brand new course called MongoDB with Async Python.
- 15:08This course is an end-to-end journey on getting fully up to speed with Mongo and Python.
- 15:13When writing this course, I had to choose a GUI query and management tool to use and recommend.
- 15:18I chose Studio 3T.
- 15:20It strikes a great balance between being easy to use, very functional and remaining true to the native MongoDB shell CLI experience.
- 15:28That's why I'm really happy that Studio 3T has joined the show as a sponsor.
- 15:32Their IDE gives you full visual control of your data.
- 15:36Plus, with a drag-and-drop visual query builder and a multi-language code generator, new users will find they're up to speed in no time.
- 15:43For your team members who don't know MongoDB query syntax but are familiar with SQL,
- 15:47they can even query MongoDB directly with Studio 3T using SQL and migrate tabular data from relational databases into MongoDB documents.
- 15:57Recently, Studio 3T has made it even easier to collaborate, too.
- 16:01Their brand-new team-sharing feature allows you to drag-and-drop queries, scripts, and connections into permission-based shared folders.
- 16:08Save days of onboarding team members and tune queries faster than ever.
- 16:12Try Studio 3T today by visiting talkpython.fm/studio2023.
- 16:18The links in your podcast player show notes.
- 16:20And download the 30-day trial for free.
- 16:24Studio 3T.
- 16:24It's the MongoDB management tool I use for talkpython.
- 16:27You can do even two different...
- 16:31If you want to count all the vehicles, you can do it without making requests to each of the collections,
- 16:37because everything is in the single collection.
- 16:39And you can do this with different fields there as well.
- 16:43And you can make aggregations over all of them.
- 16:45And even over cars separately.
- 16:48This is nice.
- 16:49And yeah, I like it.
- 16:50Does the record have something, some kind of indicator of what...
- 16:53Yeah, inside there is...
- 16:55What class it is.
- 16:56It's like, I'm a car class.
- 16:57I'm a bike class.
- 16:58Yeah, yeah.
- 16:58You can specify...
- 16:59Originally, it is called class name or something like this with underscore.
- 17:04But you can specify which fields would work for this.
- 17:07So you can specify the name of this field.
- 17:09And in this field, it stores not only the name of the class, but the structure itself.
- 17:14Like for bus, it will keep vehicle, car, bus.
- 17:19Yeah.
- 17:19So in this field.
- 17:20Okay.
- 17:21That's why it will be able to...
- 17:22Even on the database level, it will understand the hierarchy of this object.
- 17:27Right.
- 17:27And so if you want to do data science-y things, you could use the aggregation framework to run a bunch of those types of queries on it.
- 17:34Right.
- 17:34Yeah.
- 17:34And it's better to do all this stuff on the database layer because Python is not that fast with iterations.
- 17:41While MongoDB is super fast.
- 17:43Yeah.
- 17:43And plus, you know, you don't need necessarily to pull all the data back just to read some field or whatever.
- 17:49Right.
- 17:50So, yeah, that's really cool.
- 17:51This is not what I expected when I first heard about it, but this is quite cool.
- 17:55First time I heard this about this feature, I was like, nobody wants this.
- 18:00Why do you try to...
- 18:02But then I found how flexible this is getting to be.
- 18:05And so, yeah, this is nice.
- 18:07The reason I guess it's a surprise to me is it leverages an aspect of MongoDB that's in document databases in general that are interesting, but that I don't find myself using very much is in that you don't have to have...
- 18:19There's not a real structured schema.
- 18:21And a lot of people say that and kind of get a sense for it.
- 18:24For me, that's always meant like, well, the database doesn't control the schema, but my code does.
- 18:28And that's probably going to be the same.
- 18:30Right.
- 18:30So there's kind of an implicit static schema at any given time that matches the code.
- 18:36But you can do things like put different records into the same collection.
- 18:41You wouldn't do it just like, well, here's a user and here's a blog post and just put them in the same collection.
- 18:46That would be insane.
- 18:48But there's, you know, if you have this commonality of this base class, I can see why you might do this.
- 18:52It's interesting.
- 18:53Yeah.
- 18:53And in this context, blog post or video post could be different by structure, but could be stored in the single collection.
- 18:59One other thing on the page here that we could maybe talk about is link.
- 19:02I want to tell people about what link.
- 19:04MongoDB is not a non-relational database, but you can force it to work with relations.
- 19:10There are even, there is a data type in MongoDB called db-ref, db-reference, which is used to work with this link type in Bini.
- 19:21So in Bini, with this generic type link, you can put inside of the link any document type.
- 19:26It can make relations based on this link.
- 19:29So you can fetch linked documents from another collections using just standard find operations in Bini.
- 19:36This is, there is kind of magic under the hood.
- 19:39I use, instead of using find operations, MongoDB find operations, I use aggregation framework of MongoDB, but it is hidden under the hood of Bini.
- 19:48And so, yeah, and you can use relations then.
- 19:51And the nice thing about new features, because link already was implemented, I think, two years ago.
- 19:57But again, I don't come up with my own features, I think.
- 20:02Every feature somebody asked me for.
- 20:04And I was asked for another feature to make backtracking, back references for these links.
- 20:11Like, if you have a link from one document to another, another document should be able to have to fetch this relation backwards.
- 20:19So in this case, you've got an owner which has a list of vehicles.
- 20:23But given a vehicle, you would like to ask who is its owner, right?
- 20:26True.
- 20:27Okay.
- 20:27And I implemented this.
- 20:28I named backlinks, backlink, and it can just fetch it in reverse direction.
- 20:34That's cool.
- 20:35And the nice thing about this is it only uses the magic of aggregations, and it doesn't store anything for backlinks fields in the collection itself.
- 20:45Okay.
- 20:45In the MongoDB document, you never will find this field for backlink, because everything you need is on the link.
- 20:52And this is nice.
- 20:53Yeah, that is really cool.
- 20:54In the queries, in the find statement, you add fetch underscore link equals true.
- 20:59And that's kind of like a join.
- 21:00Is that how that works?
- 21:01There are options.
- 21:02Eager versus lazy loading type of thing.
- 21:04When you find without this option, default it is false.
- 21:07You will see in the field, in the link at field, you will see only link itself.
- 21:11It will be linked with ID inside of the object.
- 21:15But if you put fetch, and you can fetch it manually, like with method dot fetch, it will work.
- 21:22But when you put fetch links true, it will fetch everything automatically on the database layer.
- 21:28And yeah, it will return all the link documents.
- 21:30That's really cool.
- 21:31Other one?
- 21:31Lazy parsing.
- 21:33I mean, we all want to be lazy.
- 21:34But what are we doing here?
- 21:35What is this one?
- 21:36Yeah, so this is, in some cases, Bini could be used for really high load projects.
- 21:42And sometimes you need to fetch like thousands of documents in a moment.
- 21:47And the nature of Pydantic is synchronous, not synchronous, because it uses CPU bound operations there.
- 21:55And when you fetch hundreds of documents, even thousands of documents, you completely block your system.
- 22:02Because a lot of loops to parse data, to validate data, and etc.
- 22:06And if you use it in asynchronous framework, this is not behavior that you like to have.
- 22:12And to fix this problem.
- 22:14Maybe even in a synchronous framework, it might be the behavior you don't want to have as well.
- 22:18Yeah.
- 22:19Right?
- 22:19Even then.
- 22:19Yeah, yeah.
- 22:20This is true.
- 22:20But even in asynchronous, you don't accept.
- 22:23Yeah, exactly.
- 22:24But it's totally reasonable to think, well, I'm going to do a query against this document.
- 22:28And it's got some nested stuff.
- 22:30Maybe it's a big sort of complex one.
- 22:32But you really just want three fields in this case.
- 22:35Now, you can use projections, right?
- 22:38Like that is the purpose of projections.
- 22:39But it limits the flexibility.
- 22:42Because you only have those fields that were projected.
- 22:44And in different situations, maybe you don't really know what parts you're going to use, right?
- 22:50You can have a complicated approach.
- 22:51Yeah.
- 22:52So this kind of lets the consumer of the query use only what they need, right?
- 22:56Yeah.
- 22:56And so when you use this lazy parsing, Pydantic doesn't parse anything on the initial call.
- 23:02Like you receive everything and store everything in a raw format in dictionaries, in Python dictionaries there.
- 23:07And when you call any field of the document, just parse it using Pydantic tools to parse as Pydantic do it internally.
- 23:16So is this lazy parse primarily implemented by Pydantic?
- 23:20Or is this something you've done on top of Pydantic?
- 23:22I implemented my own library for this.
- 23:24Like it's on top of Pydantic for sure.
- 23:26But it uses, in Pydantic, there are tools and different in V1 and V2.
- 23:31So the name of this tool is different, but you can parse something into type, not into base model, but just into type.
- 23:38You can provide a type and the value to be parsed into this type and it can parse it.
- 23:44So I use this.
- 23:45And additionally, I had to handle with all the validator stuff because this is a very important part of Pydantic and you have to be able to validate things.
- 23:54And with lazy parsing, if it sees that there are root validators, then it will validate it against any field.
- 24:01Or if there is a field-specific validator, it will validate it against the field if this field was called.
- 24:07So yeah, I had to do some magic with Pydantic there.
- 24:11But it, especially with Pydantic V1, which was slower than V2, significantly slower, it was very helpful for people who have to fetch really big amounts of documents and to not block their pipeline in this step.
- 24:28This is a nice feature also.
- 24:30Yeah, I think this is a really nice feature.
- 24:32What's the harm?
- 24:33And does it make certain things slower if you're going to use every field or, you know, why not just turn this on all the time, right?
- 24:41That's my question.
- 24:42Yes, for sure.
- 24:42There are trade-offs.
- 24:44If you will use this all the time, it would be like around twice slower than just Pydantic validation if you will use all the fields.
- 24:54If you will use just a few fields, it would be faster.
- 24:57But I didn't turn it on by default because in general case, when people just want to fetch 10, maybe 20 documents and use all the fields of them, it would be slower.
- 25:06That's kind of what I expected.
- 25:08But if you've got a really complicated document and you only use a few fields here and there, then it seems like a real win.
- 25:13But you're going to use everything anyway.
- 25:15And especially for Pydantic V2, when all the validation happens on the Rust layer.
- 25:21But here I cannot do this because I cannot, you know, I cannot put the logic into the Rust layer because there is no Rust layer for Beanie.
- 25:27And if you will fetch all the fields of the documents using this lazy parsing, everything will happen on the Python layer instead of the Rust layer.
- 25:35And it would be as slow as V1.
- 25:37So we will not see benefits.
- 25:39It's interesting, even in the V1 version of Pydantic, but now with Pydantic 2 being roughly 22 times faster, that all of a sudden you want to let Pydantic do its thing if it can.
- 25:49Yeah, true.
- 25:50Speaking of Pydantic getting some speed up from Rust, is any part of Beanie some other runtime compilation story than pure Python?
- 26:00Is there like a Cython thing or a Numba or any of those?
- 26:04The thing about the speed of Beanie is, Beanie is not about, so as Pydantic is very CPU bound, all the stuff happens on the CPU layer.
- 26:15While Beanie uses mostly input-output operations because it interacts with the database.
- 26:21And for this, just default, I think, await pattern of Python uses, works the best.
- 26:28And all the time, if there are any delays, it's most likely about this interaction process between application and MongoDB.
- 26:37It could be network, it could be just delay from the query and et cetera, but not Beanie because Beanie doesn't compute anything.
- 26:45Beanie doesn't do very much, I guess, right?
- 26:47It coordinates motor, the asynchronous engine from MongoDB, and it coordinates Pydantic.
- 26:54It kind of clicks those together using async and await, a nice query API that you put together.
- 27:00And so, right, it's more about letting motor be fast and letting Pydantic be fast and getting out of the way, I suppose.
- 27:07This is true, so yeah.
- 27:08Beanie is mostly about making some magic and convert Python syntax into MongoDB syntax.
- 27:14And thank you for that.
- 27:15That's really nice.
- 27:16It's super nice the way that the syntax works, right?
- 27:19The fact that you're able to use native operators, for example, right?
- 27:23You do the queries.
- 27:24I really like that.
- 27:25Yeah, it was.
- 27:25It is.
- 27:26I don't like when somebody uses this in production applications.
- 27:29I mean, when, because it's hard to find problems.
- 27:32But when we are talking about libraries, this is really nice when it supports Python syntax.
- 27:37So that's why I decided to implement it.
- 27:39People shouldn't get too crazy with overloading their own operators.
- 27:43But as an API, it's really good.
- 27:44So for example, in this case, you have a sample document and it has a number.
- 27:47And so the query is sample.find.
- 27:49And then the argument is sample.number =10, right?
- 27:54Which is exactly the way you would do it in an if statement.
- 27:57You know, contrast that with other languages or other frameworks such as MongoEngine, which I used previously and is nice.
- 28:04But you would say sample.find and then just number_eq =10, right?
- 28:10And you're like, I know what that means.
- 28:13But it's not speaking to me the same way as if I was just doing a raw database query or writing pure Python, right?
- 28:20Yeah, it sounds like you have to learn another one of English, right?
- 28:23Exactly.
- 28:23You've got to like, if you want to do a nested thing, it's the double underscore, you know, it'd be like number double underscore item underscore eq =10.
- 28:32You're like, oh, my goodness.
- 28:34So yeah, that's kind of tricky.
- 28:35Definitely true.
- 28:36Cool.
- 28:36Okay, well, let's talk about this, this upgrading story for the 22, 229,000 other folks out there who maybe haven't done this.
- 28:44So a while ago, back in 2022, almost exactly to the day, a year ago, I had Samuel Colvin on to talk about the plan to move to Pydantic v2, why he did it.
- 28:56It was really interesting.
- 28:57So that's worth listening to.
- 28:58If people want to learn more, as well as I had Sebastian Ramirez and Samuel Colvin on to talk about it live at PyCon.
- 29:04And that was fun too.
- 29:05So if people want background on what is the story of Pydantic 2, they can check that out.
- 29:10But the big announcement was on June 30th, a couple months ago, I guess that's a month and a half ago, Pydantic v2 is here after just one year of hard work.
- 29:19That was a huge project for the Pydantic folks, which, you know, they've done a great job on it.
- 29:25And I guess the big takeaway really is that Pydantic v2 is quite a bit faster.
- 29:32Maybe you could speak to that.
- 29:33And it's mostly but not exactly the same because, as you already pointed out, the core of it is rewritten in Rust for performance reasons.
- 29:40I've made a lot of tests.
- 29:41It is much faster when you talk about validation of the models itself, especially when you validate parts really nested and complicated models.
- 29:52Then it's much, much faster than Python, then v1 implementation.
- 29:56While with Bini, you still can see significant upgrade, performance upgrade, but not that much because with Bini works with MongoDB.
- 30:06And there is this input output operation, which is slow and which could not be upgraded by just by decreasing processing time.
- 30:14Sure.
- 30:15When we are talking about simple documents, it's not that visible, like 10, sometimes 20% faster.
- 30:23But when we talk about nested documents, when there are nested dictionaries or nested lists of dictionaries, then it's much, much faster.
- 30:32In my Allo test, it is twice faster, v2 against v1.
- 30:37And I was super impressed by this because I was expecting this, expecting this, that it would not be that, that faster than as a pedantic v2 itself because of this output operation.
- 30:49But yeah, this is so this crazy.
- 30:51Right.
- 30:52Because it's not just the parsing that Bini does, right?
- 30:55Bini sends the message over to Mongo.
- 30:58The network does some stuff.
- 30:59Mongo does its thing, sends it back, serialized as Bison.
- 31:03And then it's got to deserilize into objects somehow.
- 31:07And then the pedantic part kicks in.
- 31:09Right.
- 31:09And plus all the extra bits you've already talked about.
- 31:11Right.
- 31:12So it, it can only affect that part.
- 31:14But I think it, your example here shows, you know, standard computer science answer.
- 31:19It depends, right?
- 31:20As a, as a faster, it depends.
- 31:22I would guess the more complicated your document is, the bigger bonus you get, which you've already said.
- 31:28And the more documents you return.
- 31:31So if I return one record from the database, it's got five fields.
- 31:35The amount of that processing that is pydantic is small.
- 31:39But if I return a thousand records and there's all that serialization, like, you know, the database
- 31:43has kind of done more or less the same amount of work.
- 31:46It's streamed the stuff back.
- 31:47But at this, when it gets to Python, it's like, whoa, I've got a lot of stuff to validate and parse.
- 31:52And I suspect that also matters how many records are coming back.
- 31:54Yeah, this is true. That's why this affected this case for lazy parsing that was implemented for
- 31:59v1. And now, now it's not necessary for many cases, only for very extreme, extreme high load.
- 32:06That's really cool.
- 32:07What makes me smile from this is the more pydantic you use, the more awesome this upgrade to 2 becomes.
- 32:15And it's like I said, it's almost no work.
- 32:17Technically, I had to set all the optionals to be none.
- 32:20That's not a beanie thing.
- 32:21That's a pydantic thing, but it's not a big deal.
- 32:23So upgrading basically means all the parts of your frame, all the frameworks you use that are
- 32:28built on pydantic get faster.
- 32:30So for me, when I upgraded the website, it went about, I don't know, 40% faster or something like
- 32:35that, which is a huge speed up for very little work.
- 32:39It's already really fast, right?
- 32:40If you go to, you know, the podcast, you pull up an episode page.
- 32:43It's like 30 milliseconds.
- 32:44You go to the courses and you pull up a video to play.
- 32:48It's got many queries.
- 32:49It does, but it's probably 20 milliseconds.
- 32:51So now it's 15 milliseconds or 14 milliseconds.
- 32:54But still to get that much of a speed up and do basically no work on my part.
- 32:59That's awesome.
- 33:00And I'm not using a framework like FastAPI where the other side of that story is also pydantic.
- 33:06So if you're using FastAPI and beanie, which I think is probably a common combination,
- 33:11both the database side that gets you the pydantic things is faster.
- 33:14And then the outbound and inbound processing that the API itself does is a lot faster because
- 33:20of pydantic.
- 33:21And so you get this kind of multiplicative doubling of the speed on both ends, right?
- 33:26The numbers you just told about your website is like this time is only about this communication.
- 33:33I mean, how bits are going from one computer to another.
- 33:38There is no computation there probably.
- 33:40It's super, super impressive.
- 33:42You know, people say, well, Python is not fast enough.
- 33:45That may be true for a few very rare, you know, extremely high load situations, but I would bet
- 33:52it's fast enough for most people.
- 33:54You know, if your website end to end processing is responding in 15 milliseconds, like, you know,
- 34:00you've got other parts of your system like CDNs and an amount of JavaScript you send to worry about,
- 34:05not your, not your, pretty awesome.
- 34:07Because of indexes also not, don't forget your indexes.
- 34:10Yeah.
- 34:11Each time, each time when I have any requests about my things are slow and probably I have
- 34:17to switch Python to anything else.
- 34:19Usually the problem is about the data model, not about the processing because, you know, people could
- 34:24store things a bit, a bit wrongly, a bit too nested or less nested than it should be.
- 34:30And yeah, indexes.
- 34:31Okay.
- 34:32Yeah.
- 34:32Indexes.
- 34:33Or you've done a query where you return a hundred things of huge documents and you only want,
- 34:38like say the title and last updated, but you don't do a project projection.
- 34:42And so you're sending way too much data.
- 34:43It's like select star instead of select title, comma, date, you know, something like that.
- 34:47Sometimes, sometimes, sometimes also works to, to make protection on the database layer,
- 34:53like to, to make some, like to find maximum elements or minimum elements and to do this
- 34:58stuff on the database is better than in Python, because in Python, you have to iterate towards
- 35:02the objects to, to find things which is not that efficient.
- 35:06So we just have to,
- 35:06you got to pull them all back, deserialize them and validate them and then iterate over
- 35:11it rather than just let that happen on just the fields in the database.
- 35:14That's, that's a good point.
- 35:15And maybe the query is just bad as well.
- 35:16Okay.
- 35:17So what was your experience?
- 35:19You know, they, they shipped the migration guide about the things that you've got to do.
- 35:23And if you look at the scroll bar here, the migration guide is large.
- 35:28I don't know how many pages.
- 35:29Let's see if I press print, if it'll tell me how many pages.
- 35:33No, sadly, it doesn't want to tell me how many pages it would print,
- 35:35but there are many pages here, I guess, if I were to print this out,
- 35:39it was this a daunting experience.
- 35:41How did it go for you?
- 35:42It was very.
- 35:43So when I just, we should, we can install a potential tool.
- 35:47Or you're like, let's see if it just works.
- 35:48Come on.
- 35:49And just run tests and everything was.
- 35:52Firstly, it was like only one error.
- 35:56Nothing can work.
- 35:57I don't run any tests.
- 35:59So one here.
- 36:00Yeah.
- 36:01I handled this and each test was read and everything.
- 36:05It was really interesting and challenging.
- 36:07Interesting because it's kind of really computer science problem sometimes there.
- 36:12So Pydantic moved a lot of logic to the Rust layer and it got hidden for me as a user of Pydantic.
- 36:21For example, there is in Python, there is a thing called forward ref.
- 36:26What is it?
- 36:27And even you have two classes in a single module, for example, and in one class you have field of the second class.
- 36:33And in the second class, you have field of type of the first class.
- 36:37You cannot just put these names without any magic.
- 36:40You can make input from annotation or you can just write it as a string instead of the class itself.
- 36:46I see.
- 36:47But then Python will understand it as a forward ref, forward reference for another class.
- 36:52And Pydantic can resolve it and make it an actual class finally in the base model.
- 36:59And in V1, this mechanism was implemented in Python and I could use it and I could use the results of this.
- 37:06While in Pydantic V2, everything is in the Rust layer.
- 37:09And when it updates this reference, it updates inside of the Rust and I cannot see the actual class finally.
- 37:16And I had to implement my own resolver there.
- 37:18And there are a few stuff like this.
- 37:20Another one big change was about...
- 37:23That does not sound easy.
- 37:25Yeah.
- 37:26I was like, so will I?
- 37:28Oh no.
- 37:28Am I going to do this?
- 37:29Yes, exactly.
- 37:31Exactly.
- 37:32And, you know, for people who maybe haven't played with this, it's really important.
- 37:37Because Pydantic and hence Beanie depends on the types, right?
- 37:42The parsing and the validation and all of those things, you have to know exactly what type a thing is, right?
- 37:48And so if you lose access to the forward reference resolution, that's going to be bad.
- 37:53Yeah.
- 37:54Yeah.
- 37:54For example, in links or in backward links, if you don't clearly understand which document is linked to this document,
- 38:01you cannot build a query for this.
- 38:03So yeah.
- 38:04And I have made this resolver.
- 38:05Honestly, I just was reading Pydantic with one code and was...
- 38:09Hold on.
- 38:10I didn't copy paste, but I was using nearly the same algorithm.
- 38:14And another big feature was about how validation of the custom types happens.
- 38:20Yeah.
- 38:21And get Pydantic core schema.
- 38:23So everything is in the schema inside of the Rust layer now.
- 38:26And you can write instructions in the Python, which would be important to this Rust layer and would be called from there.
- 38:35That's why the whole syntax of this completely changed.
- 38:40Completely.
- 38:40And that's why I was thinking like, but so how can I have two completely different syntaxes for the same thing inside of the same class?
- 38:49And I was thinking like, maybe I have to switch branches now and have Beanie V2 after Pydantic V2 and Beanie V1 and support all the new features in both versions.
- 39:02And it was, oh no, it will be a nightmare.
- 39:04You're already busy with one project.
- 39:06Do you need...
- 39:06Because I already have Bonnet.
- 39:07Yeah.
- 39:08Do you want two projects?
- 39:09Yeah.
- 39:09And I already have Bonnet, which is a synchronous version of Beanie, which also would be split into two then.
- 39:15And I will have four projects, which is too crazy.
- 39:19Yeah.
- 39:20No kidding.
- 39:21I can split myself.
- 39:22This is a problem.
- 39:23And yeah, finally, finally, finally, I found...
- 39:26I honestly, I just went to FastAPI code and I was reading how they deal with this.
- 39:31And like, nice idea.
- 39:33I will do the same.
- 39:34Thank you guys.
- 39:35And that's the power of open source.
- 39:38Yeah, it is.
- 39:40I feel like Sebastian and FastAPI are kind of examples for a lot of different projects and different people.
- 39:45You know, people look to them for kind of an example.
- 39:49Yeah, this is true.
- 39:49And so, and finally, finally, I solved all the problems.
- 39:53It took me to solve all the problems.
- 39:55It took me like one, maybe one and a half weeks.
- 39:58But then I published a better version and there were performance problems with better version.
- 40:03There were some corner cases that I didn't catch and community found them.
- 40:09And this is great also about open sourcing, because honestly, I would not be able to find
- 40:14all of these problems myself for this short period of time.
- 40:17Definitely.
- 40:18I guess how much of this is at runtime and how much of it, I guess it's all at runtime,
- 40:23but how much of this is startup versus kind of once the app is up and running.
- 40:27So, you know, you've got your beanie init code where you pass the motor async client over and you pass the models.
- 40:34And it's got to like verify that they all click together correctly.
- 40:37You know, they all have the settings that say, you know, what database they go to and the indexes are set up correctly and whatever else is in there.
- 40:45And then once I imagine once that gets processed, it kind of just knows it and runs.
- 40:50So how much of this stuff that you're talking about was kind of the setup, get things working and how much of it is happening on every query, every insert?
- 40:59Most of this was about runtime of about every query and every, not even this way.
- 41:04Not even this way.
- 41:05Like how do I set up the document itself?
- 41:08How do I set up validators?
- 41:10Because I also have validators in the documents to make things simpler and this index changed and et cetera.
- 41:17So yeah, there are, for example, the config, there was config nested class called config before in Pedantic V1.
- 41:25And now this is a field called model config, which is, you see, it's completely different interface again, because this is not a class.
- 41:32This is just a field now.
- 41:33And I had to, and I was using and still use this config stuff.
- 41:37And I had to not only switch to the new syntax, but support config class if you use Pedantic V1.
- 41:43And that's why inside of my classes, I have conditions like which field I want to define based on the version of Pedantic.
- 41:51And yeah, most of the, most of the changes were about, about this, the tabs of the documents and the tabs of the types, but you use it not on the initialization layer, but on the runtime.
- 42:03Yeah.
- 42:03All these things.
- 42:04You also talked about the performance story.
- 42:07Do you do any profiling or have any tools like that?
- 42:12Honestly, I didn't.
- 42:13So there are P profile and, and other tools to do this stuff.
- 42:19I was measuring using just time, start, time, end, but I was doing this for, for different parts of the code, just to see what's happening there and here.
- 42:29And honestly, it was when I faced a performance problem.
- 42:33And this was because there are some methods in Pedantic V2 that they keep, but marked as deprecated.
- 42:41They keep from, from V1.
- 42:42In some cases, I just didn't switch it to the, to the new versions.
- 42:46And this was the performance problem.
- 42:48And when I found all the places where I use deprecated methods, then everything, first of all, then.
- 42:53You switch it to the new, more intended one.
- 42:56And that's got the, you know, fully optimized version or something like that.
- 43:00Yeah.
- 43:00Yeah.
- 43:01Yeah.
- 43:01True.
- 43:01Because, because Bini is, is working with a lot of internal things of Pedantic and it uses this very heavily.
- 43:08And, sometimes I just don't know that in this, I mean, don't remember that in this, specific part, there is something internal for Pedantic and, I use this also.
- 43:18And, so I had to check everything and Pedantic code basis is big already.
- 43:22So it's hard to keep everything in mind.
- 43:24Yeah.
- 43:24I feel like that's the challenge for people like you and FastAPI and others.
- 43:29You have your, your code way deeper in the internals of Pedantic than people who just consume FastAPI or consume Beanie like I do.
- 43:37This is very interesting.
- 43:39Like, I mean, this is true computer science problem.
- 43:41Like when you have to swap interfaces and, and you don't even know where all these interfaces are used and you have to detect them.
- 43:49So yeah, this is nice.
- 43:50It's super interesting.
- 43:51Yeah.
- 43:51And again, on your, your side, you've got to do that to adapt to the new Pedantic, but you've also got to present some kind of consistent forward looking view to people consuming Beanie.
- 44:01So they don't have to rewrite all their code too.
- 44:03Right?
- 44:03Yeah.
- 44:04True.
- 44:04So, and, and all the interfaces, all the,
- 44:07I didn't change any Beanie interface when I was working with this, like all the interfaces,
- 44:13still the same for Beanie and, nobody should change their code, which uses Beanie.
- 44:18I implemented kind of middleware between Pedantic and Beanie and this middleware, have static interfaces.
- 44:25And inside of this, there are these conditions like if Pedantic V2, then, and, and yeah, this kind of logic.
- 44:34Nice.
- 44:35It's pretty good question on the audience from Marwan here.
- 44:37It says, other than getting the code to execute correctly, were there any gnarly parts you had to figure out to appease type checkers and linters and that kind of stuff?
- 44:46I don't, remember any changes about this time, about these things like, mypy and, rough.
- 44:53I use rough for instead of flake eight currently.
- 44:56Mm-hmm.
- 44:57I didn't fix this stuff.
- 44:58everything was okay.
- 45:00It was, it was new Pedantic.
- 45:01I think, I think, guys made a really great job about this to, to make everything work because yeah, I have, I have other checks about my pipe and about rough and everything went smoothly about this.
- 45:12So yeah, this is, I can't imagine being Samuel and team to have to rewrite Pedantic with such a major refactoring realizing quarter million other projects depend on this.
- 45:23And then people depend on those projects, you know, and like, how are we going to do this without the world just completely breaking, you know?
- 45:29Currently they have a discord channel also for Pedantic.
- 45:33And I see, I see many people asking for, for help for, and, some questions about new, new syntax, but I see that it could be much more because so current, current syntax is, is very similar to, to the previous syntax, but the change it's completely rewritten.
- 45:51Right.
- 45:51Oh yeah.
- 45:51This is, this is very impressive work.
- 45:53Yeah.
- 45:53Completely rewritten a good part of it in another language.
- 45:56Yeah.
- 45:57Yeah.
- 45:57Broken into multiple modules and still it seems to go pretty well.
- 46:01Yeah.
- 46:01And the assumptions about the default values for, for optionals, that was the only thing that seemed to have caught me out.
- 46:06You can put in, in, in the configs that, you, you can have options, like the same, use the same logic as for V1, but you just have to mention it in the, in the config now.
- 46:17But I don't remember.
- 46:18Honestly, there was a few other things that maybe I ran across, like, and honestly, I don't know why some of these changed.
- 46:23So it used to be able to call dot JSON on an object.
- 46:26And now it's model underscore dump underscore JSON or there was dict model dump, right?
- 46:33Everything is, has prefix model currently in Pydantic.
- 46:36And I believe this is to not make conflicts with the user logic, because when you, when you have your own, suffix or prefix, then yeah.
- 46:46Then it's simpler for, for users to, to have their own methods.
- 46:50And I like this solution.
- 46:51This, this is really nice.
- 46:52I guess this is the other thing that I ran into is I have a few places I was calling dot dict, I think.
- 46:57For me as well.
- 46:58And I have like conditions.
- 46:59I see.
- 47:00Anything else you want to talk about, about the migration, like what's, go okay for you or any other thing you want to highlight about how it went?
- 47:07Honestly, I think I mentioned everything and yeah, it, it, it, it, it's when, it's when very, it's mostly thanks to, to, to Podentic team.
- 47:14And, yeah, I really, I really like, Podentic V2.
- 47:17I still really like Podentic V1 actually, like both, but this completely, this completely different libraries inside and very similar,
- 47:27libraries, I regard the interfaces.
- 47:28So I really like how, how it's.
- 47:30Yeah.
- 47:31It's not too often that you get that massive of a speed up of your code and you didn't have to do anything.
- 47:36Right.
- 47:36You just, I was using this library and it was really right in the core of all the processing and now it's a lot faster.
- 47:41So, so it was my code.
- 47:43When you read the code, the Rust part of the, of Podentic, I started to read it just to learn.
- 47:48And, this is really nice how it can interact with Python parts.
- 47:53I mean, I can, I can write Rust itself, just logic.
- 47:56I even implemented database in the Rust, but how to do all this Python stuff inside of another language.
- 48:03So this is super impressive.
- 48:05It is super impressive.
- 48:06We'll get a little short on time here.
- 48:07Let's see what, I guess I'll give a shout out to this course.
- 48:10I recently released MongoDB with async Python, which of course uses Beanie as well.
- 48:17And I created this course on Beanie one dot, something prior to the one dot 21 that switches to Pydantic two and it's all Pydantic one.
- 48:27And so I was always wondering like, well, how, you know, how tricky is it going to be to upgrade?
- 48:31And there was really either zero or very little changes.
- 48:34I think maybe the default values on optionals was also a thing I had to adjust on there.
- 48:39But if people want to learn all the stuff that we're talking about, you know, just talk Python.fm, go to courses, check out the MongoDB async course.
- 48:47It's all about Beanie and stuff like that.
- 48:49I was reading this course also and I can highly recommend it.
- 48:52They are.
- 48:53Thank you so much.
- 48:54One thing I do want to give a shout out to is I use Locus.
- 48:57Are you familiar with the Locus?
- 48:58Locus IO?
- 48:59Yeah.
- 48:59Yeah.
- 48:59What a cool, what a cool project.
- 49:01So this lets you do really nice modeling of how users interact with your site using Python.
- 49:07And then what you get is, I don't know if there's any cool pictures that show up on here in terms of the graphs,
- 49:13but you get really nice graphs that show you real time about how, you know, how many requests per second and different scenarios you get.
- 49:19And on this one, I'm pretty sure when I upgraded it to Pydantic 2 and ran it again,
- 49:25trying to think of all the variations that you knew, there could be something that has changed that I wasn't aware of.
- 49:30Like maybe, maybe I recorded on my M1 Mac mini and then ran it again on my M2 Pro Mac mini.
- 49:36So that could affect it by like a little bit as well, like 20%.
- 49:39But I think just so using Beanie and FastAPI and upgrading all those, those paths to Pydantic 2 and the respective Beanie and
- 49:49FastAPI versions.
- 49:50I think it went 50% or double fast, two times as fast, 100% faster just by making that change.
- 49:56So that was pretty awesome.
- 49:57This is great.
- 49:59Yeah.
- 49:59Yeah.
- 49:59I see, I see, I see this 50% also.
- 50:02And yeah, all I did is I just reran pip-tools to get the new versions of everything and reran the load
- 50:09tests and look how much faster they are.
- 50:11And so that's a real cool example of kind of what I was talking about.
- 50:14So yeah, if you want to see all this stuff in action, check out the MongoDB with async Python course.
- 50:19Thanks for coming on the show and updating us on Beanie and especially giving us this look into your
- 50:25journey of migrating based on Pydantic 1 to 2.
- 50:28I think that's really cool.
- 50:29Yeah.
- 50:29Thank you very much.
- 50:30Thank you very much for having me here.
- 50:31Of course.
- 50:32So before you get out of here, I got a PIPI project library to recommend to people something
- 50:38besides of course Beanie and Pydantic, which are pretty awesome and obvious.
- 50:42I would recommend to use motor. This is this is kind of by Mongo, but asynchroneous.
- 50:47Integrates with async and await perfectly, which is real, real nice.
- 50:51If you want to do something more low levels and then Beanie, then you have to at least meet with
- 50:57motor because this is really nice library. And even after that many years, it's still very actual.
- 51:04And what else? Honestly, I don't have anything.
- 51:06Yeah. Pydantic is good stuff. Awesome.
- 51:11Okay. I'll throw Locus out there for people. They can check out Locus. That's pretty cool.
- 51:15If you are going through the same process, you've got code built on Beanie or just Pydantic in general,
- 51:21and you want to see, you know, how does my system respond before and after?
- 51:26Locus is like ridiculously easy to set up, run it against your code, pip install, upgrade,
- 51:31run it again and just see what happens. I think that'll be a really good recommendation too.
- 51:36Yeah. Final call to action. People want to get started with Beanie. Maybe people out there already
- 51:40using Beanie want to upgrade their code. What do you tell them?
- 51:42Just pip install it. Everything would be, would work fine. So just try it. But at least you have to
- 51:48upgrade everything. So please write tests.
- 51:51Absolutely.
- 51:51And if something will go wrong, go to my Discord channel and me or other people will answer your
- 51:59questions. Sounds good. All right. Well, congrats on upgrading Beanie. You must be really happy to have
- 52:04it done. Yeah, I think. Thank you very much.
- 52:05Yeah, you bet. See you later. See you.
- 52:07This has been another episode of Talk Python To Me. Thank you to our sponsors. Be sure to check out
- 52:14what they're offering. It really helps support the show. Studio 3T is the IDE that gives you full
- 52:19visual control of your MongoDB data. With a drag and drop visual query builder and multi-language query
- 52:25code generator, new users will find they're up to speed in no time. You can even query MongoDB directly with
- 52:31SQL and migrate tabular data easily from relational DBs into MongoDB documents. Try Studio 3T for free
- 52:39at talkpython.fm/studio2023. Want to level up your Python? We have one of the largest catalogs of
- 52:46Python video courses over at Talk Python. Our content ranges from true beginners to deeply advanced topics
- 52:52like memory and async. And best of all, there's not a subscription in sight. Check it out for yourself
- 52:57at training.talkpython.fm. Be sure to subscribe to the show. Open your favorite podcast app and search
- 53:03for Python. We should be right at the top. You can also find the iTunes feed at /itunes, the Google Play
- 53:09feed at /play, and the direct RSS feed at /rss on talkpython.fm. We're live streaming most of our
- 53:17recordings these days. If you want to be part of the show and have your comments featured on the air,
- 53:21be sure to subscribe to our YouTube channel at talkpython.fm/youtube. This is your host,
- 53:27Michael Kennedy. Thanks so much for listening. I really appreciate it. Now get out there and write
- 53:31some Python code.
- 53:41"The RSS feed on YouTube and check out the video. I'll see you next time. I'll see you next time. I'll see you next time."
- 53:52"The RSS feed on YouTube and I'll see you next time."
- 53:52"The RSS feed on YouTube and I'll see you next time."