Latest / Talk Python To Me / #376: Pydantic v2 - The Plan
Transcript
- 0:00Pydantic has become a core building block for many Python projects.
- 0:03After five years, it's time for a remake.
- 0:06With version 2, the plan is to rebuild the internals,
- 0:09with benchmarks already showing a 17 times performance improvement,
- 0:14and cleanup of the API.
- 0:16This sounds great, but what does it mean for us?
- 0:18Well, Samuel Colvin, the creator of Pydantic,
- 0:21is here to share his plan for Pydantic version 2.
- 0:24This is Talk Python To Me, episode 376,
- 0:28recorded August 4th, 2022.
- 0:30Welcome to Talk Python To Me, a weekly podcast on Python.
- 0:47This is your host, Michael Kennedy.
- 0:49Follow me on Twitter, where I'm @mkennedy,
- 0:51and keep up with the show and listen to past episodes at talkpython.fm.
- 0:55And follow the show on Twitter via at talkpython.
- 0:58We've started streaming most of our episodes live on YouTube.
- 1:02Subscribe to our YouTube channel over at talkpython.fm/youtube
- 1:05to get notified about upcoming shows and be part of that episode.
- 1:10This episode of Talk Python To Me is brought to you by Compiler from Red Hat.
- 1:14Listen to an episode of their podcast to demystify the tech industry over at talkpython.fm/compiler.
- 1:21And it's brought to you by Microsoft for Startups Founders Hub.
- 1:25Get early stage support for your startup and build that startup you've been dreaming about.
- 1:29Visit talkpython.fm/foundershub to apply for free.
- 1:34Transcripts for this and all of our episodes are brought to you by Assembly AI.
- 1:37Do you need a great automatic speech-to-text API?
- 1:40Get human-level accuracy in just a few lines of code.
- 1:43Visit talkpython.fm/assemblyai.
- 1:45Samuel, welcome back to Talk Python To Me.
- 1:49It's great to be back.
- 1:50It was, when was it?
- 1:51It was in the middle of, it was in COVID, wasn't it?
- 1:52I seem to remember.
- 1:53It was core COVID, yes.
- 1:55It was just 15 months ago.
- 1:57Yeah.
- 1:58Yeah, I think it was sometime last year.
- 1:59Yeah, I was in my attic in the, yeah, I'm now in the office.
- 2:02It's a representative.
- 2:03Exactly.
- 2:05Locked down in the house.
- 2:06And it's great to have you back.
- 2:08We talked about Pydantic back then.
- 2:10Obviously, we're talking about Pydantic now as well.
- 2:13I would say it's grown tremendously since then.
- 2:16It was already quite popular then.
- 2:18Yeah, I think it's, I don't have right now off the top of my head, good metrics on, you
- 2:22know, insofar as you can quantify the growth of these things.
- 2:25I think it, yeah, it's grown a lot, but I think the feeling for me is it's become a lot of,
- 2:30a lot more companies and a lot more people have started to rely on it.
- 2:32And it's become a kind of core tool that they expect to work in the way you expect pytest
- 2:37or Django to work.
- 2:38Not quite perhaps at those levels, but moving in that direction.
- 2:41And yeah, I guess I'm probably jumping the gun, but at the beginning of this year, I was
- 2:46thinking about it and I was obviously super proud of what, of how many people were using
- 2:50Pydantic and how useful it was being, but I wasn't quite so proud of its internals, which
- 2:54is why I started thinking about what it would look like to, to kind of start again.
- 2:59Cause obviously V2 was an opportunity to, to break stuff.
- 3:02Not that we haven't broken things in minor releases when we shouldn't have done, but like to formally
- 3:06break things and do it right where it was obviously, I guess, wrong from the beginning.
- 3:10The goal I'm sure is not to go out and break things, but sometimes in order to take years
- 3:15of, of learning and experience and usage and turn that into the way you think it should
- 3:20be, some things may have to break, right?
- 3:22Yeah. I think that when I first released Pydantic, it wasn't, I've subsequently built projects.
- 3:26I thought we're going to be really popular and there's be, you know, varied in their success,
- 3:30but I literally built Pydantic for me and put it on, you know, put it on PyPy and then put it on
- 3:36Hacker News to see what would happen. But because of that, I thought about the work, there was some
- 3:40esoteric design decisions that were the stuff I wanted, but in reflect on reflection, they're not
- 3:45right for a popular library used by lots of people. strictness being, I guess, the most obvious
- 3:49example, but a bunch of other stuff. talk about strictness. We'll talk about a lot of these
- 3:53changes, but why do you think it was popular? I think it came along at the right time.
- 3:58I think it came along when tight pins were just getting popular in Python. They had been around
- 4:02in some guys for like ever, right? You could do something with them in two seven, but they were
- 4:06just beginning to become a thing. mypy was coming out, but I suppose I was not the only person
- 4:11who, who was frustrated by the idea that they didn't have teeth that they were there, but,
- 4:15but it seemed kind of weird, right? If you came from a, a rust or a C++ or a C background,
- 4:22you know, types are everything. And the idea that they were there, but they meant nothing
- 4:25was a bit of an anathema to me. And I just started off with a, can I, can I make them work a bit? And
- 4:30that was five years ago and here we are.
- 4:32Yeah. I agree that coming along at the right time was probably part of the magic. I think
- 4:37there was just some, some libraries and some frameworks who decided these types should have
- 4:44meaning. Like you said, there was a couple of web frameworks, obviously most notably FastAPI,
- 4:49but there were other ones as well who are taking the ideas of here's some type definitions and Python.
- 4:56And what could we, what could we do with that? Can we actually make that mean something to help
- 5:00the developer experience? I think that's true. And I, you know, I guess I got some stuff right in doing,
- 5:04doing documentation quite well, quite early on. I know that like it wasn't perfect, but you know,
- 5:09it did the job at the time FastAPI and Sebastian's, you know, Sebastian's amazing in lots of things,
- 5:14but his, his capacity to write documentation that is almost a story that almost leads you,
- 5:18you know, it's enjoyable to read in the way that documentation normally isn't, obviously
- 5:22yeah. Being adopted by FastAPI, like strapped rockets to Pydantic. But I think the other thing that
- 5:27made an enormous difference is that I came to Pydantic as a developer, not a, not a typing
- 5:34academic. And I know there's a lot of debate about whether or not the typing world of Python get moves
- 5:38too far into the world of, of like the theoretical, but I always wanted it for me, it was always obvious
- 5:45that a string of one, two, three should be coerced to an int. And there's a lot of people who will say
- 5:50that's not useful. And then there's a million different ways in which they use it. And they don't even
- 5:54realize because you think it's really obvious when you have ID equals one, two, three in a URL,
- 5:58that that one, two, three is, is an integer. But obviously when you're passing a URL, there's,
- 6:02there's no, no way to say that is actually definitely an int. So some of the, some of the lax stuff,
- 6:08the coercion, I think has been the thing that sets Pydantic apart from some of the other libraries that
- 6:12were perhaps more formally correct, but I would argue less useful in lots of contexts.
- 6:17Well, I also think the more that you work on the web, where what you're accepting is out of your
- 6:23control, you want more help and you want more validation and you want more guardrails.
- 6:27People are posting JSON documents of who knows what to you there. There's the query strings and the URL
- 6:33parameters that are always strings, no matter what they're supposed to be and stuff. So yeah, I think
- 6:38Pydantic especially fit well in the API side of things.
- 6:41I also think there's a, there's the risk of getting a bit kind of like fuzzy and cod philosophy about this.
- 6:47There's a like, there's a value in remembering what it was like to not be that good a developer and
- 6:52making it easy to use for beginners. And there's definitely a world of developers who,
- 6:58who want to, whose primary interest it feels is proving how much they know rather than making it
- 7:04easy for people. And Sebastian is even better at this than I am, but I think Pydantic does a good job
- 7:09of it, of being easy to use. And if you're new to developing, you know, you and I know that I've seen
- 7:12bytes and string, and obviously we would, you know, laugh through our nose at anyone who got them
- 7:16confused. But the fact is that when you're new, they look like two identical things and one's got a B at the
- 7:21beginning and the other one's got an F at the beginning. And what's the, what does any of that
- 7:24mean? Right? Like, yeah. And so, ignore that part. Yeah.
- 7:26Right. And so the fact that, that you can pass bytes to us, to a string field saves people a lot of
- 7:32head scratching.
- 7:32Yeah. It certainly has taken on a life, quite, quite a life in the Python space and many,
- 7:38many different frameworks and libraries are depending upon it, which is great. Some stats
- 7:43that you put in this article, we're going to talk, or this plan that we're going to talk about,
- 7:47it's for 72,000 public repos that I'm guessing are expressing some kind of dependency on.
- 7:53Yeah.
- 7:54And then 10,000 GitHub stars. Yeah. That's coming up on 11. That's, that's pretty amazing.
- 7:59And the, yeah. And the download count, I think it was 24,000 when I, a month to, sorry,
- 8:0424 million a month when I last looked from, from PyPy. And that doesn't include distributions.
- 8:09Pydantic is distributed with, I think every major Linux distribution. So downloads in those contexts
- 8:16won't, won't be included in that. So yeah, it's, it's like, it's being, it's widely adopted and it
- 8:21seems to be getting more widely adopted as, as time goes on.
- 8:23Just to back up what you're saying to an army captain out there says, Pydantic is very easy
- 8:28to onboard. Yeah. It's just because it, it does what you would expect it to do, what you would want
- 8:32it to do. So let's see. One thing I wanted to sort of touch on a little bit before we got into the plan
- 8:41officially is let's just highlight some of the frameworks that are making core use of Pydantic.
- 8:46Obviously we talked about FastAPI, right? For people who don't know, maybe tell them real quick,
- 8:51what is FastAPI? FastAPI is a amazing web framework that allows you to, I think if you
- 8:56scroll down, I think that probably pictures will be better than words. you use Pydantic and,
- 9:02and types generally to define what, what data people can pass to your, to your endpoints primarily as
- 9:07per the name for designing, for developing APIs. and yeah, it makes it super simple. I think there's
- 9:12an example down, down somewhere a bit further down on the, on the homepage. maybe there isn't,
- 9:16maybe it's on getting started, but, there we are. yeah, you see here, whether it be URL
- 9:21parameters like, item ID, or query parameters, or obviously the body, they're all
- 9:28validated with, with Pydantic, which like cuts out enormous amount of the work of building, building
- 9:33APIs. Absolutely. And then there's a couple of things that are interesting. You have Pydantic
- 9:37models, which are Python classes with type, you know, a field colon type. So you express the type
- 9:42information about it. And then you can say this API function just takes one of these and it'll
- 9:48automatically pull that data in and validate it using Pydantic through like the body. But then also
- 9:53you can express that that is the response model or the input model, and it'll use open API to actually
- 10:01generate the documentation. So there's all these different ways in which FastAPIs made better.
- 10:05Yeah. So the powerful thing about FastAPI is that by defining a relatively small amount here,
- 10:12we just defined it as like three line function to define our, our endpoint, we get JSON schema for,
- 10:17for the input we get, so then we get docs built off, off that. when we get obviously docs on the
- 10:23return type, if we, if we annotated it with, with what's returned. so yeah, from,
- 10:29um, and obviously the value and I can see from your, from your tabs where you're going to go next,
- 10:34it's like you define something in one place and you can then use it for your input and for your
- 10:38return type and then in your database. Yeah. And so yeah, here's the, this is the most well-known
- 10:44example for using it on the API layer, the web layer, but there's also some cool examples of databases
- 10:50as you pointed out there, right? Yeah. So did this surprise you when you saw these? I mean,
- 10:55you probably had the API stuff in mind, but did the database surprise you? It did a bit. I mean,
- 10:59I, I like, I haven't looked at Beanie in lots of detail, but like, yeah, it's, it's, it's like,
- 11:04yeah, it's amazing that these things are coming along and being built and, leveraging, like,
- 11:09yeah, leveraging what Pydantic can do. I'm not a big ORM fan myself. I'm a bit old fashioned.
- 11:15I like to write my SQL. not, sorry. I like to write SQL, not my SQL.
- 11:22so I haven't actually used, used them. I have to say, but FastAPI I've used a lot and I've,
- 11:26I've found absolutely amazing, but I won't, can't talk about, Beanie or SQL model beyond,
- 11:32uh, beyond having had a quick, quick look. Yeah. So I just want to give a quick sort of,
- 11:38uh, awareness shout out to Beanie, which is an async ODM object document mapper from MongoDB,
- 11:44like an ORM, but there's no R. So B for document based on, on motor. So it's pretty cool. It takes
- 11:49the asynchronous driver from MongoDB and then Pydantic. You just express your models,
- 11:55your documents as Pydantic models, which map really well because you can have hierarchies of
- 12:01Pydantic classes and models, which maps perfectly to document databases. So yeah, this is actually
- 12:06what Talk Python, the Python Bytes websites are built on, which has been really nice. And then
- 12:11obviously Sebastian Ramirez created SQL model, which is the same idea, but for SQL, right? It's built on
- 12:18top of SQLAlchemy, but you actually define your classes as Pydantic models. And then that finds a
- 12:24way to sort of work with SQLAlchemy to still do the same stuff that it traditionally has done. So.
- 12:29Yeah. I think there was one of the complaint, one of the complaints people had was that I,
- 12:32they were having to define their data twice. They would have a Pydantic model and then they would
- 12:35have a SQLAlchemy model. And so, yeah, it's, it's not very surprising in a way that we found a way to,
- 12:40to combine them into one. again, I, I'm not, I'm not an expert on the internals of SQL model,
- 12:45but it, yeah, the two things look similar enough that like at a, at a first pass, you would think
- 12:49it would make kind of sense to squish them together.
- 12:51And one interesting thought about this is if you're going to work in SQL model, or you're
- 12:57going to work in Beanie or something like that, and you decide, no, I actually want to switch to a
- 13:01relational database, or I want to switch from a relational database over to MongoDB or something
- 13:06like that. If it's all expressed as Pydantic models, like how close are you? You know what I mean? Like
- 13:11it's, it's, it's very little work to sort of make that transition. So it's, it's cool that Pydantic
- 13:15is this kind of like, and there's a, that's a cool project. There's a cool project that I was
- 13:19discussing with, Adrian, I think it's Garcia yesterday, which is using Pydantic models to define,
- 13:25uh, data coming in from already, Google, Google PubSub and from AWS SQS and potentially from
- 13:36Redis. So again, it's the same idea that like, once you define your models in Python, it wouldn't be that
- 13:41hard to switch from AWS to, to Google or even to like a database type, tool like Redis.
- 13:47Teddy out in the audience says, we use data model code generator to generate our Pydantic models from
- 13:52JSON schemas. Are you familiar with that?
- 13:54Yeah. Yeah. So, so obviously just as you can generate a JSON schema from, from a Pydantic model,
- 14:00there's a third party tool that lets you, you go the other way and generate Pydantic models. I
- 14:05obviously won't do everything for you, validators and stuff, but it gives you the first, first start.
- 14:09Let me throw one more out there before we dive into the plan, which is where we're going. How about
- 14:14JSON to Pydantic converter? Have you seen this website?
- 14:17I had, I did not know that existed, until now, but, but I guess it's using that same tool under
- 14:23the hood, is it? Or we'll watch it. Maybe it's not. It may, it may be, I'm not actually sure. I
- 14:28haven't seen it mentioned it, but it doesn't really say so. I'd say not because it doesn't, that's not
- 14:32JSON schema, right? That's just, no, what you do is you give it an example. that's very cool.
- 14:38You give it an example, JSON document. I'm a, till 27. So you give it a JSON document and it will
- 14:44actually, when I first heard about this, well, Pydantic will already generate JSON. Like, no,
- 14:48no, no, no. The other way you give it a JSON result and it will generate the data model
- 14:54by looking at, and it actually, even if you have like hierarchical stuff, it'll create multiple
- 14:59base model derived classes and all sorts. This thing is, this is, this is pretty sweet right here.
- 15:04This thing.
- 15:05That's pretty powerful. Kudos to whoever built it. Yeah. I hadn't heard of it, but.
- 15:08Yeah. And I've thrown massively complicated JSON documents at it. And it says like, well,
- 15:12it's going to take eight classes, but here you go. And it just writes them all. It's, it's fantastic.
- 15:17This portion of Talk Python To Me is brought to you by the compiler podcast from Red Hat.
- 15:24Just like you, I'm a big fan of podcasts and I'm happy to share a new one from a highly respected
- 15:31and open source company compiler, an original podcast from Red Hat with more and more of us
- 15:37working from home. It's important to keep our human connection with technology with compiler.
- 15:42You'll do just that. The compiler podcast unravels industry topics, trends, and things you've
- 15:47always wanted to know about tech through interviews with people who know it best. These conversations
- 15:52include answering big questions like what is technical debt? What are hiring managers actually
- 15:57looking for? And do you have to know how to code to get started in open source? I was a guest on Red
- 16:03Hat's previous podcast, command line heroes in compiler follows along in that excellent and polished
- 16:08style. We came to expect from that show. I just listened to episode 12 of compiler. How should we handle
- 16:14failure? I really valued their conversation about making space for developers to fail so that they
- 16:19can learn and grow without fear of making mistakes or taking down the production website. It's a
- 16:25conversation we can all relate to. I'm sure. Listen to an episode of compiler by visiting talkpython.fm
- 16:31slash compiler. The link is in your podcast player show notes. You can listen to compiler on Apple
- 16:36podcasts, overcast, Spotify, pocket gas, or anywhere you listen to your podcasts. And yes, of course,
- 16:42you could subscribe by just searching for it in your podcast player, but do so by following
- 16:46talkpython.fm/compiler so that they know that you came from talkpython to me. My thanks to the
- 16:53compiler podcast for keeping this podcast going strong. Let's talk about the plan. First of all,
- 17:01before we get into the plan, I just want to say well done on this. You know, we covered this on the
- 17:07Python bytes podcast three or four weeks ago, something like that. And the response was,
- 17:12oh my gosh, this is incredibly detailed, incredibly well thought out. I think somebody audience commented
- 17:18like there are companies that have been created and founded with less thought about the future and
- 17:23doing that. So yeah, nicely done. Thank you. Yeah. I spent a lot of, a lot of time,
- 17:29quite a lot of PyCon talking about this, to people and say, you know, talking about little bits of it.
- 17:35There was a lot of it in my brain and Sebastian, who is kind enough to sponsor me, but also obviously
- 17:40is maintaining FastAPI. It's kind of asking me what it was going to do. And I kept being like,
- 17:44oh, it'll do that thing. And it'll do this thing. And then I got to the point of realizing,
- 17:47and probably about 70% of issues on PyLantix issue tracker, I reply with, don't worry,
- 17:52it'll work in V2. And I realized I got to the point where I really owed the community an answer to,
- 17:57to some of these questions. in fact, the first bit of feedback I got from it was I'm dyslexic,
- 18:02and I'm quite slow at reading and I, those, red time, notes never make any sense to me.
- 18:07So I just put 10 minutes in at the very beginning and then, forgot about it as I extended it and
- 18:11extended it. And the first feedback was great article, but how the hell is anyone reading that
- 18:15in 10 minutes? And so I pulled a new number out of thin air, but.
- 18:18Yeah. So yeah, it's 25 minutes reading time, which I think is actually fairly accurate,
- 18:23depending on how thoughtful you think about these, these various things.
- 18:27Someone had, I've got to, I've got to have a shout out to one joke on Twitter. Someone was like,
- 18:31when it said 10 minutes, they were like 10 minutes to parse two days to validate, which I thought.
- 18:35Oh yes. Well done. Very, very, Pydantic. Like, okay. Why do we need this plan? What's,
- 18:42why do we need to start?
- 18:44So I think, I mean, like stepping back a bit, most projects, once they're mature and in, in widespread use,
- 18:49like people don't sit down and tear them to pieces, right? they mostly stick with the
- 18:54same kind of warts and people polish the edges, but like that, that, that there's not a like
- 18:59from scratch rebuild. And often when there is from scratch rebuild, it, it offends a lot of people
- 19:03because they don't know what's happening. And you know, they're like the, the, you know, the cost of
- 19:08migrating is quite high and they're, they're turned off it. So, but I thought that there was,
- 19:12there was enough wrong with the internals of Pydantic and there was enough opportunity to do stuff
- 19:16way better. And there was enough, like, there was enough reason to do that because there were
- 19:20enough people using it that it was worth me sitting down and spending six months, but we've passed six
- 19:25months building it. Right. and like I say, this is, you know, there was one of the, one of the,
- 19:30like not stats, but one of the, my observations was, looking at, so there was a, it was a stack
- 19:36overflow, survey of what, of what technology people are using and FastAPI had, I don't know what
- 19:42percentage, but like 6%, market share. Right. And then below it, they were
- 19:46talking about clouds and which clouds had what market share. Now, if you assume the same number
- 19:50of people are using web frameworks as they're using clouds, which is an approximate approximation,
- 19:54but not a mad approximation, then you would say the FastAPI and therefore Pydantic have a bigger
- 19:58market share than Oracle and IBM combined in slightly different markets. And obviously without the,
- 20:03without the revenue to go with it, but like, it makes you realize that like getting this right
- 20:08has a massive effect on, on lots of people and on, yeah. And, and secondly, that I don't have a clue
- 20:15how many, how many times Pydantic validates data a day between, you know, Netflix and, Facebook
- 20:21and Amazon and Microsoft and everyone else, but it's a high number, right? And so the environmental
- 20:27impact of making Pydantic 10 times faster and therefore consume 10 times less CO2 to, to do a
- 20:34validation is I suspect not trivial. It's virtually impossible to, to get an accurate number, but
- 20:39something real.
- 20:39That's a really interesting way to think of it with, you know, almost having a responsibility
- 20:44to lessen the compute load. And when, you know, you're running your own website and it does a
- 20:50couple of users an hour or whatever, like who cares, right? But when you're talking a million requests
- 20:55a second or whatever it is across all the different people using all the different frameworks across,
- 21:00right? That actually, that's what I suspect. And like, think about, think about, a web server,
- 21:06assuming your database is doing all of the heavy lifting, that it should be doing. What's the
- 21:11next biggest thing? Well, there's, TLS termination that's expensive, but like, again,
- 21:17that's done by some optimized C and Nginx or probably outside your code completely. If you're using a
- 21:22platform provider, what's the next biggest thing that your code is doing CPU wise? Well, it's,
- 21:26it's data validation basically. Yeah. Conversion, serialization,
- 21:31deserialization, validation, and all that was in the Pydantic realm. Yeah. Also I talked about two
- 21:36frameworks and I know there are others, like Pydastic for Elasticsearch where the validation
- 21:43and the data exchange is the database exchange as well. Right. That's, that could be very important
- 21:49for if you make this much faster, I don't know the numbers for Beanie precisely, but I know that a lot
- 21:56of those ORM ODMs, if you go and query and get like 10,000 rows back, the vast majority of that
- 22:02time is how do I construct and fill out 10,000 objects in memory? Right. And if you make Pydantic
- 22:10faster and Pydantic is that object, well, there's a huge bonus. It's more than just, and I think the
- 22:15other thing to say is we've talked about, web applications and, you know, from FastAPI being the
- 22:19kind of most high profile user of, of Pydantic. We talk about that a lot, but a lot of its usage,
- 22:25if you look at, stuff that Explosion AI are doing, it's in data science and AI and it's, yeah,
- 22:30it's exactly that. It's like data sanitization into and out of, models or into and out of databases.
- 22:36And there you are talking about like, you know, really massive amounts of data.
- 22:40Absolutely. All right, let's get into it. So we talked about the plan. How about the,
- 22:45the roadmap, the timeline, things like that?
- 22:48So we're behind a bit, but we're not too far behind. I released, version 0.1 of Pydantic core
- 22:53yesterday. So that, I'll come to what that means in a minute, but, but that's, that was the,
- 22:58that's the first step of the plan. I'm about, I think I've either closed or merged 25 PRs today,
- 23:05trying to get through Pydantic and get, get version, V 1.10 out. So I'm, I'm halfway,
- 23:11I'm not halfway through. I'm some bit of the way through two to be, to be precise.
- 23:15right. And so what, what are you were talking about in the plan? As you said, there's a bunch
- 23:19of open PRs, a bunch of open issues. Let's merge in as much of that as possible to sort of capture it
- 23:26and then move forward in this, this rewrite that we'll talk about.
- 23:29Right. Yeah, exactly. So get, get 1.10 out, which is, which is the same, same basic code base with a
- 23:35bunch more stuff added that I've, because I had a, had a job and was really busy earlier in the year,
- 23:39I kind of dropped the ball on reviewing those PRs and they, they kind of got out of control.
- 23:44like get them, dealt with and then get to a kind of clean slate and then, and then, make
- 23:50the big move from, yeah, from V 1.10 to, to V 2. You do talk about there being breaking changes.
- 23:56We'll get into some specific details there, but probably the most relevant to this entire rewrite
- 24:02is this thing you're calling the Pydantic dash core. Yeah. So, this started off as a,
- 24:08as a kind of small experiment with me saying what would kind of thought experiment, what would,
- 24:12what would Pydantic's, what would Pydantic look like if it was implemented in Rust? What would its,
- 24:17uh, internals look like if they were implemented in Rust? And that experiment effectively worked.
- 24:22And sure enough, Pydantic core is, is written in Rust and does all of the core data validation.
- 24:28and it will do a lot of the serialization. I haven't built that yet, but that I intend to build
- 24:33into Rust. So there's an awful lot that will stay in Python. but, yeah, Pydantic core is
- 24:39written, written in Rust and uses the amazing Py03, library to bindings to, to write Rust code that,
- 24:46that, that's callable from Python. yeah.
- 24:50Maybe tell people about Py03 real quick, because this is how you write it and write the code in Rust,
- 24:55but then expose it to the rest of the Python aspects of Pydantic, right?
- 25:00Yeah. Py03, I'm not a good C developer and I'm going to use the wrong terminology and be
- 25:04shy to that, but like it takes the Python ABI for C. So how you would write C codes to be used from
- 25:11Python and effectively makes that available in Rust. Rust has, has great interop with C.
- 25:18and so, yeah, it basically takes all those types and exposes them all in a type safe or type safe way
- 25:25that you can then consume. So if we look, we stop here and we look at like, Summers,
- 25:30uh, a string, right? Where, Py03 is taking care of all the hard work of you passing two,
- 25:37ints from Python into this function, converting them to u-size. Then the logic inside is pure Rust.
- 25:43It's adding to u-sizes and, converting the result to a string. And then again,
- 25:49Py03 is taking care of returning it. And in particular, using this PyResult,
- 25:53result type in Rust without going too far down the rabbit hole of how Rust works. Rust has an amazing
- 25:59model for how to deal with errors that basically stops you from ever ignoring an exception or what they
- 26:04call an error. and that is, that's these results, which are basically, they would call it
- 26:08an enum, but from Python world, think of it like a union, which is either okay. It went well or error.
- 26:13It was an error. And so you have to return an okay, or you have to return an error. And when you consume
- 26:18that in Rust, you have to have to deal with the error case. it won't let you ignore it.
- 26:23but that, that maps really nicely into Python exceptions. So here we're returning. Okay. So we'll get a result.
- 26:29But if we use py error and return that, then you would get an exception when you, when you call the function.
- 26:34Mm-hmm. Interesting.
- 26:35The, so the powerful thing about Rust, obviously it's faster. Everyone knows that. And it does,
- 26:41it does mean that Pydantic core is much faster than Pydantic and Pydantic 2 will be much faster than
- 26:47Pydantic 1. I think it's probably quite rare to see a library in a version update, get, get significantly
- 26:53faster, let alone like 10 to 50 times faster as Pydantic 2 will be. So that's been achieved, but there are
- 26:59other advantages that you get, which are perhaps less obvious. one of them is like recursion
- 27:04without a performance penalty. That means that Pydantic, core data validation is, is truly
- 27:12recursive all the way down and allows you to build effectively any crazy combination of different
- 27:17validators, into each other. Cause yeah, validators are this basically pile of, think of them as
- 27:22think of them as classes in Python. They're not that, not classes in Rust, but that call each other
- 27:27recursively all the way down. and you can, one of the other advantages is like tiny functions,
- 27:33which allow you to split code up and make it easier to edit one thing without breaking other things.
- 27:37because in Python, it's not entirely obvious to people coming from languages like C, C#, Rust,
- 27:44and so on that just calling a function itself is pretty expensive relatively speaking in Python.
- 27:49Yeah. I I I'm on the edge. I'm on the like wing of people who would say,
- 27:54if you're worrying about the overhead of calling a function, you're probably not writing the right
- 27:58language most of the time, right? Like it's, yes, it's, yes, it's a big number, but it's a tiny number
- 28:03in, in most, in most contexts. But I think there's definitely a world in which like end users,
- 28:08people building web apps in Python definitely for companies should and will be using Python.
- 28:14But the libraries that underpin that, that they use super, there's big value value is a complex
- 28:20term in open source in itself, but let's use the word value and ignore that what it might mean
- 28:24in, in implementing those libraries, the second step down. So the Pydantic, the HTTP,
- 28:31framework, in, in Rust or in, in, I think in Rust basically, because those are the,
- 28:36well, there are three libraries that have real bindings for Python. C, I don't want to be writing
- 28:41lots of C and I don't think many people do. well, I'll say that, Rust obviously. And then
- 28:47there's C++ and Boost. And I think the developers of, Py03 came from using Boost and
- 28:53they basically built Py03 to be better. and I, yeah, I've used Boost a bit, but I found Py03 to be,
- 28:59to be really impressive.
- 29:00I think your comment about, should you be worrying about those loops is super relevant. There's
- 29:05certain libraries where Pydantic is certainly among them. It's used so much that these little tiny
- 29:11portions, you know, probably just a very small slice of the code that is applicable is actually
- 29:16a pretty significant hit in terms of overall performance. You know, you think like SQLAlchemy
- 29:21and like the serialization deserialization bit, right? That's a small part of the library,
- 29:25but that's something that just is ever, you know, omnipresent, right? And this internal
- 29:30validation and stuff that you're thinking about doing in Py03 or in Rust, combine it with Py03,
- 29:35it makes a big difference, even if it's only a small, relatively small portion of the part that
- 29:39people perceive it to be, you know?
- 29:41Exactly. And coming back to my environmental point, you know, the environment doesn't care if you take
- 29:45a flight or I take a flight or I miss a flight, but like, obviously the environment does care if we
- 29:50can reduce the number of flights taken worldwide by 10, worldwide by 10%. And because of Pydantic's
- 29:54widespread use, that's why I'm saying getting Pydantic to be 10% faster, you probably won't notice.
- 30:00But overall, we will hopefully make computation in the cloud a tiny bit faster.
- 30:07Absolutely. Question from the audience. Magnus says, will users be able to write data validators in
- 30:13Rust for Pydantic too? That is a difficult and complex question. There is an open issue on Pydantic
- 30:19Core's issue tracker about it. And I have proposed a way that it might be possible. I would, the story of
- 30:27shared libraries, DLLs in Rust is not quite as pretty as it could be. And I really don't want
- 30:33to build basically another way of sharing dependencies beyond PyPy where you're like, okay, you need to
- 30:39install Pydantic from PyPy, then you need to install this other package, perhaps from PyPy, and then you
- 30:43need to use this other code to link the DLL so that we can dynamically link those libraries. That sounds
- 30:50like an enormous maintenance overhead for me and for people doing it because people find it hard enough to
- 30:57share code and use code from PyPy. So PyPI. So yeah, then how do you deploy that and how do you get it
- 31:05compiled? Right. So very briefly, my theory for an answer is actually, I'm not going to go down that
- 31:11rabbit hole right now. But there's an issue that I think explains it and I'm happy to talk about it there.
- 31:15And I can, I'll finally link to it. If you don't add it now, you don't have to live with the consequences of
- 31:19choosing that. That's the other thing, right? That like someone comes along and has a really bright idea and in
- 31:2210 years time, I'm still answering questions about how to make it work. Yeah, exactly. Okay.
- 31:27You already mentioned the performance, but just working our way through the plan here, the next
- 31:30step is to say, hey, the benchmarks indicate this is four to 50 times faster. And in general,
- 31:3717x is kind of what you're guessing for something reasonable.
- 31:40Not guessing, as in just the benchmarks on Pydantic Core that are run on every commit,
- 31:48a lot of them have alternate equivalents in Pydantic 1.9. And so that's the speed up that we're seeing.
- 31:56There are a few more optimizations I can make. There are a few, it'll get a tiny bit slower,
- 32:03I guess, when it's wrapped in Python, but a tiny amount. So yeah, I think those are realistic numbers.
- 32:09Yeah, that's a huge difference. Now you say, when validating a model,
- 32:14how does that performance compare to treating a Pydantic class instance? How much faster does
- 32:21using it in Python get versus... 17 times faster, doing the validation. You should get your model
- 32:27back. So that is going from a Python object, a Python dict, let's say, of your input data to a
- 32:36instantiated class instance of your model.
- 32:40David Miller: Next up is strict mode. One of the things I really like about Pydantic is how
- 32:45it will take data that could be the right thing, but it's not actually the right thing. Like you said,
- 32:51the string one, two, three, but you really want an integer, the actual number one, two, three. And it just
- 32:56says, "This is what we would do if I had to do it myself. I would parse the string and convert it
- 33:02over and so on." That just happens. But some people don't want this clever behavior, right?
- 33:08Yeah, exactly. And I think that there are legitimate cases for that. I think there are
- 33:14some people who are wanting it whose cases I don't think are entirely legitimate, but I totally get
- 33:19why in some contexts it's valuable. And so, yeah. So it's built in. You have that switch from the word go.
- 33:26David Miller: One of the really cool things that this solves,
- 33:28David Miller: kind of not by mistake, but as a side effect is validating unions. We basically run
- 33:37through every member of the union in strict mode first and try and validate in strict mode and then
- 33:42validate in lax mode. And therefore, for example, if you had a union of int and string, and then you passed
- 33:50it the string one, two, three, it wouldn't get converted to int as it would do in historically
- 33:57in Pydantic. Pydantic now has smart union, but it's not perfect, but this solves some edge cases like
- 34:04that and some much more confusing ones than that. Nice. Related to that, I would say, is this conversion
- 34:10table that you're putting out, right? What's the story here?
- 34:13David Miller: Yeah. So there's two things. There's this, I kind of called it cod philosophy the other
- 34:17day, this rule for when you would convert something and when you wouldn't. And actually,
- 34:23it's come out to be really useful in us thinking about when we shouldn't convert things,
- 34:27because to take an example, we have been in Pydantic v1, you can coerce a set to a list.
- 34:35And that mostly seems to make sense. And it's something that you might want to do in lots of
- 34:38contexts, but actually you go up a bit, the single and intuitive means we can't converse,
- 34:43convert a set to a list because you don't always get the same output when you convert a set to a list
- 34:49because the order of things can change. And so using this rule has been helpful in trying to be
- 34:54more consistent about what we convert. But I'm the first to put my hand up and say,
- 34:58this rule is not perfect. There are always going to have to be exceptions to it. And at the bottom of this
- 35:03blog post, but then properly on the docs completed, will be a full on table of everything and what gets
- 35:10converted and what doesn't in max mode. So you can look it up rather than having to guess.
- 35:15This portion of Talk Python To Me is brought to you by Microsoft for Startups Founders Hub.
- 35:21Starting a business is hard. By some estimates, over 90% of startups will go out of business in just
- 35:27their first year. With that in mind, Microsoft for Startups set out to understand what startups need
- 35:33to be successful and to create a digital platform to help them overcome those challenges. Microsoft
- 35:39for Startups Founders Hub was born. Founders Hub provides all founders at any stage with free
- 35:45resources to solve their startup challenges. The platform provides technology benefits,
- 35:50access to expert guidance and skilled resources, mentorship and networking connections, and much more.
- 35:56Unlike others in the industry, Microsoft for Startups Founders Hub doesn't require startups to be
- 36:02investor backed or third party validated to participate. Founders Hub is truly open to all.
- 36:08So what do you get if you join them? You speed up your development with free access to GitHub and
- 36:13Microsoft Cloud computing resources and the ability to unlock more credits over time. To help your startup
- 36:19innovate, Founders Hub is partnering with innovative companies like OpenAI, a global leader in AI research
- 36:24and development to provide exclusive benefits and discounts. Through Microsoft for Startups Founders Hub,
- 36:31becoming a founder is no longer about who you know. You'll have access to their mentorship network,
- 36:35giving you a pool of hundreds of mentors across a range of disciplines and areas like idea validation,
- 36:41fundraising, management and coaching, sales and marketing, as well as specific technical stress
- 36:46points. You'll be able to book a one-on-one meeting with the mentors, many of whom are former founders
- 36:51themselves. Make your idea a reality today with the critical support you'll get from Founders Hub. To
- 36:57join the program, just visit talkpython.fm/foundershub, all one word, no links in your show notes.
- 37:03Thank you to Microsoft for supporting the show.
- 37:05Before we move off strict mode, well, Clutch just has some kind things to say about Pythonics as it's
- 37:13one of the most useful packages ever. Congrats.
- 37:15That's really cool. Magnus asks, is strict mode a global or a per model setting? Or is it a usage
- 37:25when you actually do the parsing? Where do you set this?
- 37:27It's actually more powerful than that. It is either on a field or on an entire model. And you can set
- 37:36it at validation time. So you can configure it in config and configure it on a particular field,
- 37:41and then you can override it when you're effectively calling the validator.
- 37:45I see. Maybe there's some situation where you're loading old bad data or something,
- 37:50and you want to say, go ahead and do this, but in the future we're not accepting it. Something like that.
- 37:54Right. And actually, one of the reasons I built that was to use it in the union because we go through
- 37:58the validators the first time at validation time insisting on strict mode. But yeah, one of the other
- 38:05cases which will come up somewhere down here is we now have a isInstance or a like pseudo isInstance
- 38:10method which confirms whether data matches our model. And there we automatically use strict
- 38:16mode because for me it's kind of obvious that if you're doing isInstance, you want that to be checked,
- 38:21want that to be strict. Moving on to the next part of the plan is built-in JSON support.
- 38:26Yeah, so this is super. What are we talking about here? Yeah.
- 38:29So we're talking about parsing JSON in Rust and parsing that JSON object straight internally within the
- 38:36library to the validator to then do the validation. One of the big advantages that has is it solves the
- 38:43strict mode problem. So if you looked above, let's say we have the string of a date, let's say, you know,
- 38:49an iso 8601 date of year month day. In JSON, it's obvious that that should be validated as a date. But if
- 38:57you pass that in from a Python object, it's not valid in strict mode, right? That's not, that doesn't look
- 39:01anything like a date. The problem if we had strict mode before without the built-in JSON validation
- 39:07is you can't parse JSON with a date in it because there's no date representation. There's no scenario
- 39:11where directly going from JSON works because JSON, for odd reasons, has no concept. It doesn't have date,
- 39:17but it also doesn't have sets or bytes or loads of stuff that you want to use in Python, right? So
- 39:22what one of the things that built-in JSON support gives us as well as obviously a performance premium is
- 39:29is that we can be sensible and say the iso 8601 date is a valid date in strict mode if it's coming
- 39:37from JSON, but not from Python. Okay. Yeah. And also just makes it faster, right? Because
- 39:42probably parsing JSON and Rust is pretty quick. It's really, it's fast. But also we don't have to
- 39:49create a Python dict on a Python list and all those Python types. Creating Python strings has like some
- 39:56significant overhead compared to creating a string in Rust. And in future, once I've got V2 out, I intend
- 40:05to build a custom JSON parser, which is even faster and will give us line numbers in errors, which would
- 40:10be really nice because we don't have that now and we can't do that in V2 because so JSON, which I'm using,
- 40:16doesn't provide line numbers. But I hope in V2.1 or something, we will be able to add that.
- 40:21Amazing. Really quick on the strict stuff as well. Manaj asks, what about strict int as a type? Is it
- 40:28going to be still around? That can stay around because that will just be, that'll be effectively.
- 40:32So it's probably worth this stage for people. If we, if you could just go to Pydantic cores repo and we'll
- 40:38have a really brief look at what it looks like. Yeah. And then just in the read me, you'll see
- 40:45a example. So you see here, right? We, up a bit, up a bit. You don't need to go into all the details of
- 40:52it, but the way that we define the model in Pydantic core is with this kind of like micro schema,
- 40:58which is defining in this case, a type dict with a bunch of fields in it. And here on a particular
- 41:04field, we could say strict true. So let's say on the int field, we could say strict true.
- 41:08And that field will be strict while the rest isn't. So obviously what strict int, the Python,
- 41:13the Pydantic type will do when it becomes a schema, it will set a strict true on that particular field.
- 41:20Got it. So it effectively is a synonym for the more general way to say,
- 41:25use strict mode, but only on this field, right? Yeah, exactly. It's just a market effectively set
- 41:30strict on this field. Yeah, exactly. So in Pydantic, you can say I have, say,
- 41:35an age, which is an int, and you can set it to a default value like zero, or you could say it's
- 41:40optional, set it to none, but you can also set it to a field, right? Where you have additional
- 41:44information. Is that how you set strict mode? You set it to a field and say strict mode equals true
- 41:49or something like that. It's not built yet. So it's up for debate, but yeah, effectively strict will be
- 41:54a setting on field and obviously on config as well. And there will be these types, which basically
- 42:00contain some extra information like strict int will just like set that strict to true for that field.
- 42:04Right, exactly. And for people who are not aware, config is an inner class of the Pydantic model that
- 42:10has a bunch of settings you can set, right? Yeah. And people do some unholy stuff of like modifying the
- 42:15base version of config and therefore doing global stuff, which I've never done. People seem to make it
- 42:20work. I don't know it'll work in V2. I don't promise it will. Yeah, absolutely. One of the things
- 42:25that's interesting with this Pydantic core is now this is a dependency of Pydantic, right? And people
- 42:32could use it directly if they wanted, right? Like validating without a model, you don't have to define
- 42:36a class or any of those things. 100%. You don't have to define the class. If we look in the example we were
- 42:41using there, we didn't have a class. We were just validating to a type dict. So we would get back a dict,
- 42:48which obviously means we have full support for typings type dict type. It's also a little bit
- 42:54faster than creating a model because we don't have to create the class instance. We just create the
- 43:00dict that goes inside it. Yeah, people could use it without. The only concern obviously is whether or not
- 43:07obviously it's now compiled and you have to be able to run that Rust code to be able to use Pydantic.
- 43:14We, with the V0.1 release of Pydantic core yesterday, we have, I think off the top of my
- 43:19head, 56 different binaries that we released for different environments. The team of the guys at
- 43:25Py03 and at Maturin, which is their way of building, have been super helpful and will continue to support.
- 43:32So it doesn't worry me. We already have the full Pydantic core set of unit tests running in the browser
- 43:40via WebAssembly. So obviously Python moving into the browser with WebAssembly is like the big new thing.
- 43:45I'm really excited about it. I wanted Pydantic core to work. And so Hood, who's one of the
- 43:50Pyodide maintainers, I met at PyCon. He's been super helpful actually with Pydantic core in general,
- 43:57but particularly with getting it to work. And at the risk of running a live demo, if you just go back
- 44:01to Pyodantic core, I know we're slightly changing subject, but I have to show you this because it
- 44:06makes me really excited. We go up and you go into WASM preview, which is one of the directories.
- 44:10Yeah, WASM preview. Okay. And then if you click here, which just basically renders that index file,
- 44:18I hope it works. This is... Gotta work. Gotta work.
- 44:22It's gotta work. This is it downloading the binary, downloading all the unit tests,
- 44:28extracting them in Python and running the full test suite in the browser.
- 44:32Let me try it one more time. Do it a second time. Yeah. So what we're seeing, if you click on this link,
- 44:38which I'll put in the show notes, is it downloads the CPython runtime in WebAssembly based on Pyodide,
- 44:45I'm guessing. And then... Then it downloads the archive zip, sends that to Python. Obviously,
- 44:53we're running full CPython in the browser, so we can use the zip package to extract zip,
- 44:59extract that into the virtual file system that Inscription gives us. Then we install the WASM32 wheel.
- 45:08We basically do pip install, well, micro pip, which is the way of installing stuff. And then we just call
- 45:13pytest and off it goes and it runs the test. And you see the test come by, standard colorized
- 45:18pytest output, 1465 tests pass in five seconds. Pretty fantastic.
- 45:24Yeah. So it is a bit slower this than full CPython, but I'm still really stoked for what this is going
- 45:31to mean to the future of Python and particularly to stuff like the context where you might use
- 45:36Pydantic of data processing and stuff. I don't think Python is going to replace React. And I think it's
- 45:41a bit daft of people to suggest it will because that's just going to lead to disappointment. But in
- 45:44contexts like this, it's going to be super valuable. One of the things I'm really looking forward to is
- 45:50Pydantic 2's documentation. Every single example is going to be executable. So you can edit it and you
- 45:55can press run right inside the browser, which I think should help a lot.
- 45:58Have you been tracking PyScript?
- 46:00Yeah, I have been tracking PyScript. It's obviously, it's very cool. It's wrapping Pyodide,
- 46:06which is where all the genius work is going on. I'm using Pyodide directly and I think I can continue
- 46:11to do that. But yeah, it's providing a bit of a super helpful wrapper for those who need a bit more
- 46:19help and it's simple as a script tag.
- 46:22A question from David out in the audience asks, "With at least two of your projects switching to Rust,
- 46:27Pydantic and watch files, do you see it as a general trend in the Python ecosystem,
- 46:31you know, in things like PyScript, which I just pulled out?"
- 46:34I have a third one actually, rtoml, which is a wrapper around the Rust-toml library,
- 46:39which is a bit less necessary now when there is better tomml support in Python. But a couple of years ago,
- 46:43when the main tomml package was not working for me, I wrapped that. Yes, I do. I was saying earlier
- 46:49that I think lots of the low-level tools should be written in Rust. There is a massive space for
- 46:56someone to go out and build a raging fast ASGI framework in Rust and obviously use a Rust web
- 47:03framework and just provide ASGI interface. I'm looking forward to someone doing that to replace
- 47:10the likes of uvehicorn. Not that uvehicorn is great. It uses watch files, in fact, so not to
- 47:16criticize them, but like, yeah, there are a bunch of low-level stuff where performance matters,
- 47:20which totally and I think should and will end up being more in Rust.
- 47:25You're suggesting something like what you have for Flask, but everything is Rust except for just
- 47:31your view methods happen to be Python and click that together with PyO3 or something like that.
- 47:35That's the ultimate place to go to. I think that the
- 47:39place to start would be, so we have WSGI, which many of you will have heard of, which Flask and
- 47:44Django run on. We have ASGI, which is the async equivalent, which is basically, it's great because
- 47:50it means that to build a web framework, you don't have to deal with HTTP. You deal with ADDICT, which
- 47:56has basically got fields and body and stuff like that, right? And some function to get the rest of the
- 48:00body in the async case. And that's what we have now. And we have like Starlette and uvehicorn,
- 48:05which are both built by ENCODE and are both great, but they have a separation by using this
- 48:09consistent protocol in between. And that allows really cool innovation on both sides. My suggestion
- 48:16is we don't have to get rid of the Starlette or the FastAPI or that level, but we could do lots of the
- 48:22low-level HTTP parsing in Rust. Before I get shouted down, I'm sure that uvehicorn and other such
- 48:30libraries are in turn using some Optimize-C for parsing some of the HTTP requests. So I don't have
- 48:37a number for the speed up. Right. Okay. But yeah, that's a very interesting idea.
- 48:42One thing I did want to sort of touch on here is you have, you talk about how there's not going to be
- 48:47a pure Python implementation of the Pydantic core because it's already this complex, specialized thing
- 48:54in Rust. And why do it again in Python just so there might be some edge case of where it'll run.
- 48:59Talk about many of the platforms really quick that supported for the WebAssembly one we just spoke
- 49:03about, which is fantastic. And I think that's going to open up a lot of possibilities the more
- 49:07stuff we have in WebAssembly. But there shouldn't be a big problem with this, right?
- 49:11There shouldn't. I think with what we have there, we've covered the 99%. We're probably into the 99.9%
- 49:18of platforms covered where people actually want to use this. The only place where I know that there's a
- 49:23slight challenge is on Raspberry Pi, where the normal install of Raspberryan or whatever it's called
- 49:30uses their own wheelhouse effectively for installing wheels, which doesn't yet support
- 49:36build of Rust. I'm sure it will one day and you can just tell it to use PyPI and it will work.
- 49:42Again, this is the kind of thing where having built watch files and distributed that, I've worked through
- 49:46a lot of these problems and I'm pretty confident we're not going to find some really important
- 49:50framework, sorry, really important environment where it's just not going to work. And again,
- 49:55as more packages adopt Rust, we'll smooth out those problems, we'll learn from them and we'll be able
- 50:00to fix the edge cases.
- 50:01One benefit of that is previously Pydantic itself had some Cython and other things where it needed to be
- 50:10faster, but because now it can just use the Pydantic core, what's left over is pure Python, right?
- 50:15Right. And one of the big problems, well, there were two problems with that. It made the development
- 50:19process a bit slow because we basically took vanilla Python, we compiled it with Cython and we got a kind
- 50:25of 50% speed up and we have to like do some slightly weird things. So occasionally you have to return
- 50:29union of just string to prevent Cython from casting that string to a native string and losing sub strings,
- 50:36stuff like that. Some weird edge cases that bite people occasionally. But the biggest problem is that
- 50:42that means that the Pydantic binaries are massive because the Cython compiled versions of Python code get
- 50:49really big and obviously moving the performance critical bit into Pydantic core gets rid of that
- 50:55concern and Pydantic itself becomes a pure Python package, easier to hack on, CI will run faster,
- 51:00whole process should be sped up and it'll be much smaller.
- 51:02Let's go, I jumped around because I did want to talk about this compiled stuff,
- 51:06but you'll just get that as a wheel. Almost everybody, they won't really know or care, right?
- 51:12They just pip install it. It doesn't matter that it's Rust, it just downloads as a binary, right?
- 51:15Right, exactly. Same as loads of packages you use now.
- 51:18Now Pydantic included are compiled, right? They're all compiled, right? And if there is no wheel
- 51:23available, then pip will do its very best to try and compile that for you. So in the case of Pydantic
- 51:29core, if you were in some crazy environment where we didn't have a binary, you need Rust installed,
- 51:35and then pip will take care of compiling it for you. But like I say, that's going to be super rare.
- 51:40And realistically, if you have that problem, come and create an issue and we'll add the binary for you.
- 51:44Picking up back on the plan here, you have required versus nullable changes.
- 51:49We missed out one of the really cool things above. I don't know if I'm sorry if we're moving order,
- 51:54which is the removing of the necessity for a model. So as we saw earlier in the Pydantic core
- 52:00example, we can validate. So in Pydantic 1, everything was in the end of Pydantic model. So we looked
- 52:08earlier at like FastAPI, passing parameters. In the background, FastAPI is creating a model,
- 52:13doing a validation against that, then extracting stuff from the model and passing it to the function
- 52:18or whatever else. Similarly, if you wanted to pass a type dict, you basically somewhere in the background,
- 52:23there's a model, we validate against that model, then we take the dict from that model and pass it
- 52:27back to the user. That had some really confusing and annoying edge cases. But obviously, the main thing
- 52:33was it did have a performance impact. Now, there is no fundamental kind of base type in Pydantic core.
- 52:40You can validate an int or a string or union of different stuff or a model or a data class or a type dict,
- 52:47and you just create your schema and off you go. Fantastic. So basically, there's this low level,
- 52:53fast engine that'll just validate all sorts of things if you want to use it directly, right?
- 52:58Yeah. And the one thing important to add just while we're on that is there is stuff that's not going to be in Pydantic core.
- 53:03I don't think we'll add the URL type, for example. There'll be some, you know, there'll be some custom types that we don't add.
- 53:09And obviously, if you want to implement your own types, then the way that we get around that is that
- 53:14Pydantic core has a basically a function validator, which is basically call a function, either having
- 53:19done some validation before or after and return the result. So that's how we're going to we're going to
- 53:25provide a way to build validators without writing without writing Rust.
- 53:29Required versus nullable?
- 53:31Yeah, probably like hangover from again, me building Pydantic on my own for what I needed.
- 53:37And also from, you know, it's kind of predated data classes, at least in some of the work.
- 53:42And so there was the real problem for me was the word optional and the idea that you had a field that
- 53:47was required, but was literally called optional. Obviously, I'm not, Pydantic is not the only library that has that problem.
- 53:55And the real solution is, is the pipe operator, which is the new way of doing unions. None involves not using
- 54:02the word optional. You can obviously also get around it by using union of string int. But the point is that
- 54:09if you just have a field that is optional int, it is required but can be none. And that's just that's really
- 54:16just to match data classes and other contexts.
- 54:19Yeah, the new way to express optional for like string pipe none versus optional string. Yeah, that that kind of
- 54:27set you free to think about this differently.
- 54:30Yeah, also, I mean, I literally asked we do about it at PyCon. And he was like, he didn't say yes,
- 54:35we made a mistake. He said that's fixed by having having pipe none, which is a roundabout way of
- 54:41saying we kind of made a mistake back then. But you know, typing has come a massively long way since
- 54:45someone settled on the word optional. So I get it. But it has been a source of confusion that's now
- 54:49being like cleared up. Yeah, for sure. And there's other things that have been
- 54:53changed as well, right? Used to have to say from typing import capital L list to return a lowercase
- 55:00list, but it'd be a capital L list. And now it's like, you know what lowercase list works too.
- 55:03Right. You have to now we just have the weird side case of any where there isn't any function,
- 55:08but you can't use it. But we won't. We won't go down that line.
- 55:10Yeah, for sure. Want to talk about validated functions?
- 55:15Yeah, I touched on them just now. And like I said, we have, we have the idea of before. So we do a
- 55:22validation before and then we pass the result of that validation to a function. We have validate afterwards
- 55:26and plane, which doesn't doesn't do any validation, just calls the function. The most exciting thing,
- 55:31probably the one of the things I'm most stoked for in Pydantic V2 is these wrap validators. So you'll
- 55:37have, you'll have read about middleware in Django or, or any web framework. We have this idea of an onion
- 55:42where we call a validator, sorry, call a function, which takes a handler to call the next function.
- 55:47We have the same, same thing here in, in, I'd antic V2 where we have these, I've called them
- 55:52wrap validators. They take a handler to a function and then they call that the power here is obviously
- 55:58we can, we can do some logic before the validator. We can do some logic after we can catch errors.
- 56:03We can return a default value. It gives us like loads of flexibility to do, to do more powerful stuff.
- 56:09Yeah. You basically can do whatever you want and decide to delegate down to the chain of
- 56:14handlers if you want, or skip it, right? You say that this, this looks good to me. We're just gonna
- 56:19return a value here.
- 56:20In particular with, with Pynantic one, there was no way to skip, yeah, to skip validation if you
- 56:26had a validator. So, which obviously caused a slowdown. If let's say you had date time now,
- 56:30you still had to call the validator, which sure enough, got a date time and was happy,
- 56:34but you had to go through that logic. Whereas here, we know it's a date time because we've,
- 56:37we've written that code. there is a, there is the potential for people to make mistakes and not
- 56:42call, the handler. if they wanted to return the raw value, then, we can't break,
- 56:47we can't stop them, but that's Python. There aren't, there aren't always guard rails.
- 56:50That's right. Yeah. Some of the power is in the flexibility. All right. But that, that lets you
- 56:56do bad things as well. Yeah. I mean, we could, so sorry to interrupt. we could theoretically do
- 57:01some crazy thing where we checked if the handler was called and raised an error or a warning. But
- 57:05I think, I think at this point we let people make their own mistakes if they, if they insist.
- 57:09Well, and you also would pay a performance price for all the places where it's used correctly.
- 57:13Yep. More powerful aliases.
- 57:15Aliases. Yeah, this is a features that I saw.
- 57:17It's helping what the alias are. And then, yeah, then what's the use here?
- 57:20Aliases are the idea that we, we have a name for what we want to want to call a variable in our code,
- 57:25but we know that in the real world where the data is coming from, say on the front end,
- 57:29it's got a different name. Often it's camel case, on the front end, because it's JavaScript and we want to
- 57:33use, state case, in Python, but also, you know, we're using some API and we want to,
- 57:40it has to be called something when the data is coming in. and so we had that in Pydantic,
- 57:44uh, V1, the idea that you could have a field that was called something else externally.
- 57:48but this is actually a feature I'd saw in, the rust third library, which is that the main
- 57:54validation library, this idea of flatten. So basically take a value, not just from the top
- 57:59level decks, but from deep down in some object, we pass it and use that for the field. And so again,
- 58:04this is one of the things kind of stuff. Yeah, sorry. I see this stuff all the time where you'll
- 58:08get some huge response from an API, but you're like, I just really want this little part here.
- 58:13And so what you end up having to do is say, okay, capture that result. It's a dictionary,
- 58:17then navigate down to the three levels and get the sub object and then pass that to Pydantic. And here,
- 58:22you could just say the alias is sort of traverse that down and start from there. Right?
- 58:26Exactly. And we get nice advances. Like if that thing's not there, we don't get an error because
- 58:30the, the get, you know, none has no, you know, get method or whatever it might be. Pydantic will take
- 58:36care of just saying that feels missing. If let's say, as was a, was a string. So therefore,
- 58:42couldn't get as second element, you know, quarks, whatever that is. Yeah. So in the case you have here,
- 58:49you, you say the alias is a list and the list is baz and then two and quarks. These are things that are
- 58:55appearing in this JSON document. Yeah. The dictionary. So, so that list is, is effectively
- 58:59some location, but it, what you'll notice again is there's actually another outer list because we can
- 59:04have more than one of these. we can have it as deep as we like, I'm sorry, as many different
- 59:09aliases to try as you want. Yeah. So this actually traverses down and the two means go to the third
- 59:15item because it's zero based in the list and then look for that, that element. That's pretty powerful.
- 59:19Yeah. And again, this is the kind of thing that we can do because Pydantic calls in Rust and the,
- 59:24the overhead of, having aliases of, of multiple different types is basically absolutely
- 59:29minimal because it's a, in Rust, it's an, it's a single enum lookup. And if we have a simple alias
- 59:34of a string, we don't need to worry about any of that crazy logic to recurse down. We just take the
- 59:38top, you know, an element out of the top level dictionary and move on.
- 59:41Jonas asks, would this solve when my app gets Pascal case, I want to work with snake case and then return
- 59:46a camel case. Is there some way to express that kind of stuff with aliases?
- 59:51This does not, but we had, there was a pull request, for Pydantic two, Pydantic one,
- 59:56that where we had load alias and dump alias. So a different alias when we were exporting.
- 1:00:01and I do intend to support that. So this particular feature is kind of related, but won't
- 1:00:05solve it on its own. But yeah, I do intend to allow two different aliases.
- 1:00:08Speaking of loading and getting back out, improvements to dumping, serialization, export.
- 1:00:13Yeah. There's been, there's a bunch of stuff here that people have wanted for a long time,
- 1:00:18in particular, being able to create a, like a JSON compliant dictionary. but also people wanting
- 1:00:23to do their own customization. Again, my hope is that because that, that dumping logic will be
- 1:00:29implemented in rust, we can get like, I'm going to call it kind of zero cost
- 1:00:33extra features because in the end it's like, should be just an enum lookup, to, to do the complex stuff.
- 1:00:39And if we're not doing the complex stuff, we go the, we go the optimized path. yeah, there's,
- 1:00:43there's what, what we've realized is there's a, there are a whole bunch of different things that
- 1:00:47people might want. They might want the raw data, including, including sub models. They might want
- 1:00:52what DICT does now, which is recursively convert, models into dictionaries, but otherwise keep stuff
- 1:00:58unchanged. They might want to JSON compliant, DICT as I was saying, or they might want full
- 1:01:04serialization to JSON. And obviously that last one in particular, we want to be quite well optimized.
- 1:01:08Well, we want them all to be, but yeah, effectively.
- 1:01:10Last one's the most important. Yeah.
- 1:01:12Yeah. We, we want a, we want to be able to provide someone complete flexibility without it
- 1:01:17harming a performance in the case where they're not using that. And that's, that's why I think,
- 1:01:21Pydantic Core has allowed already on validation and I hope will allow on, on serialization.
- 1:01:27All right. We're getting a little short on time. So let's maybe, let's, why don't you pick
- 1:01:32out some of the remaining stuff that you want to focus on? I think maybe the most important is a model
- 1:01:36namespace cleanup. What do you think?
- 1:01:37I mean, I think context that I was just going to mention here, that's going to be another
- 1:01:41amazingly powerful, escape hatch for some of the, some of the things people want to do.
- 1:01:46obviously the main use of it is for, is for allowing validation against some dynamic data,
- 1:01:51but you can also update that thing. It's just a Python object. So if you wanted some case that we
- 1:01:56were talking about rapid validators earlier, where you've got errors and you want to raise a warning,
- 1:01:59you could append to context the warnings. so that is another super powerful escape hatch
- 1:02:05without, without harming performance for everyone else. How it's going to work with FastAPI,
- 1:02:09where the model, where you do the validation before, calling user code. I don't know yet,
- 1:02:15but I'm sure.
- 1:02:16Yeah. How do you provide that data that is the context, right?
- 1:02:19You have another dependency, I guess, in FastAPI, lingo that generates your context for that
- 1:02:25particular call.
- 1:02:25Yeah. I was thinking some of the dependency injection stuff, which is not very popular
- 1:02:29in Python in general, but that might be the way you might register. Here's how to get the context for
- 1:02:35these types of models or something. Yeah. I mean, Sebastian will decide, but that's what
- 1:02:40we'll find a way to do. Yeah, for sure. One quick question just on usage here. Like I see that you're
- 1:02:45saying user and then model validate JSON with this data. And you could also just say user star,
- 1:02:51star data. I know you're doing this different here, so you can pass the context, but what,
- 1:02:55what would you say is the best way to create these objects?
- 1:03:00So, so, so, so model validate.json is going to be there and it's going to be named that or something
- 1:03:06close to that. And the point is that's taking a string of Jason or in this, in this case,
- 1:03:10a bytes of Jason and validating it directly. We talked about that earlier on. so that's not
- 1:03:15the same as user star star, right? Right. Because it's bytes. there's also model validate
- 1:03:20Python, which is effectively the same as model, star star data, except that because obviously we
- 1:03:26basically don't trust anything you pass to it. That's all external data. You can't pass context
- 1:03:30that way. Okay. Yeah. which I think comes onto your, your question about the cleanup of the,
- 1:03:35of the namespace. There are some breaking changes and there's a decent number about sort of renaming
- 1:03:41some of these, these model methods and stuff, right? Yeah. I'm not too worried about these because
- 1:03:45we're going to leave the old functions there with a, with a depreciation warning on all of them.
- 1:03:49So that will be quite easy. The stuff that's going to be really hard in terms of breaking changes is like
- 1:03:54where, for example, I've talked earlier about sets no longer being coercible to a list.
- 1:03:59There's no way to give a warning about that really without absolutely peppering Pydantic core with,
- 1:04:03with like warning logic that, that would be horrific. so there are going to be the things that are
- 1:04:08going to be most difficult for people are going to be like silent breaking changes. I'm not particularly
- 1:04:12worried about functions that give you a warning when you call them and say, use the new name,
- 1:04:16it's going to be the silent stuff or the, you know, the fundamental changes in behavior that are going to be
- 1:04:20hard. But again, I, I, I, I, there's no way to make Pydantic better without doing that.
- 1:04:24Yeah.
- 1:04:25Fair. I think it's worth pointing out the error descriptions now have a documentation link.
- 1:04:29That's kind of interesting.
- 1:04:30Yeah. I think that's going to be super powerful for people. I don't know anyone who's ever used a cargo,
- 1:04:37and Clippy, which are the rust tools for, for broadly speaking, linting and compiling. whenever you get an
- 1:04:42error, there's a, there's a link basically to give you more information. And obviously a lot of these,
- 1:04:46a lot of these links will be being shown to developers through APIs, and we can't provide all the information we might like in a,
- 1:04:52like one sentence message. And so we're going to have these, have, a bit of Pydantic's,
- 1:04:58docs dedicated to information on every single warning, every single error message and what can happen.
- 1:05:04it leads to another interesting question about Pydantic two and what we do with the documentation
- 1:05:09and the licensing of it. So Pydantic is definitely going to stay MIT licensed, might be dual licensed Apache
- 1:05:15two, if someone can tell me why that's necessary, but it's going to stay, you know, permissively licensed,
- 1:05:20but I'm, I'm kind of becoming aware that the documentation, which is valuable and will get
- 1:05:25better and more valuable. It's currently MIT licensed and some company could, could take it
- 1:05:29all and bang it on their, their, their domain totally legally. So I might change the documentation
- 1:05:35license to something a bit more restrictive to say, for example, you can't take all of these, error
- 1:05:40message, documentation and just put them on your own domain. Or at least we have, we have some way of
- 1:05:46making that possible without make allowing people to commercialize that mostly because it would get
- 1:05:50really confusing if there was Pydantic documentation is up to date and Fubar company who published the
- 1:05:56whole same thing, but leave it out of date. And they both come up on Goop.
- 1:05:58It's interesting to think about having this mixed model in your repo, because obviously you want
- 1:06:04Pydantic, the library to be wide open for people, but then there's this supporting stuff.
- 1:06:08And I mean, I treat differently.
- 1:06:10Yeah. And I know that the unit, the Linux distributions are going to be super spiky. If any
- 1:06:16of that stuff that's not MIT licensed got distributed, right? Because they're, they're, package managers
- 1:06:22have to have stuff that's, that's, you know, correctly licensed. I mean, obviously they allow
- 1:06:25stuff that's, like GPL or something, but I I'm, I'm thinking about something from is GPL doesn't
- 1:06:31stop you publishing documentation. So yeah, it's an open question. I don't want to have a separate repo
- 1:06:36for documentation because it will make creating a PR that much, you know, higher friction. But,
- 1:06:40I think I need to talk to an IP lawyer before I say anything authoritative on this is what I guess I'm
- 1:06:44getting to. Yeah. I'm, I'm feeling entirely unqualified to, to give any advice on this,
- 1:06:50but it's tricky, right? As we were talking before you hit record, like if you have a sub light,
- 1:06:55a license in a sub folder, does that license override the more broad one? I do you have to go
- 1:07:01and change your broad license, your MIT license, say, here's the MIT license, except for this section
- 1:07:06of the repo. This doesn't apply to see it's license. You know, that's weird.
- 1:07:11I presume that the big projects, the Django's of this world and the num
- 1:07:14NumPy must've, must've thought about this stuff. So probably worth doing some research on them,
- 1:07:18but I'm thinking out loud and I probably need to come up with a conclusive answer before.
- 1:07:21Sure. Well, it's called a plan, not a release, right? Okay. we talked about the
- 1:07:27identity becoming its own license. One that I want to talk about is the from ORM and friends,
- 1:07:34I guess. yeah, maybe talk about this, these sections here.
- 1:07:38So there's a whole bunch of improvements here that we could talk about for, for an hour,
- 1:07:42probably on each one, let alone, let alone full, but, but the from ORM was a, was a,
- 1:07:47was a bit of a strange case where it was, you had to have a conflict flag and then there was a method
- 1:07:51on a, on a model. pydantic-core has this built in from attributes power, which basically allows
- 1:07:57it to recurse through some Python object that is not a dictionary instead of a dictionary, if you switch
- 1:08:03that on. So we talked earlier about aliases and about hunting down through some complex objects,
- 1:08:07normally of dictionaries, if that came in from JSON, but like in lots of contexts and ORM in particular,
- 1:08:12it's, it's not right. So from attributes, it lets you basically do that same finding things in an
- 1:08:18object from something that's not a dictionary via basically get atro, not get item effectively.
- 1:08:23Yeah. And that makes a lot of sense. Cause then you could just pass any class that you got from
- 1:08:27anywhere. You don't have to find a way to get it to a dictionary.
- 1:08:30Yeah, exactly. And, Pydantic should, should take care of that and give you nice warnings when
- 1:08:35it, when like the third level, it gets a, it gets the right error or it gets a, it gets a type error.
- 1:08:39It'll tell you type error. And if it's an attribute error, it'll say not found.
- 1:08:41So yeah.
- 1:08:42Got it. Yeah. So from ORM to me, that felt like, well, here's a thing, a way to integrate it with
- 1:08:47SQLAlchemy or something like that. But this is just more general to say, we're moving to something
- 1:08:51that just says given any object, just go get it.
- 1:08:54Yeah. I mean, from ORM was a dumb name. You're quite right. It came exactly from,
- 1:08:58from, compatibility with ORMs and SQLAlchemy, but in particular, but yeah, in what we're actually
- 1:09:04doing is taking stuff from attributes. So the new name makes more sense. And the new functionality is
- 1:09:08like a lot more powerful.
- 1:09:09Would from attributes work on properties in addition to fields?
- 1:09:13It should do. Yeah. Yes, it does. There's a unit test for it. It does.
- 1:09:16Okay. Oh, fantastic. That's really cool. Cause your, your class might have computed elements,
- 1:09:22but you want them to show up in your JSON, right? Or something like that. So yeah.
- 1:09:25Yeah. Cool. All right. I think, I think that might be, I want to know one more question I have for you.
- 1:09:32When I was doing C, C++ C#, I remember thinking about numerical types a lot. Is it sufficient
- 1:09:40to have an end here? Do I need a long? Is it an unsigned long? How much data could it be? What happens
- 1:09:47if I have an end and I increment it now it's negative 2.1 billion or whatever? Like there's
- 1:09:53all these weird scenarios that go away in Python because Python uses a slower, but way more flexible
- 1:10:00numerical type, right? All this stuff happening in rust. I feel like you might need to think about
- 1:10:04that a little bit. Yeah. So it's, it's all, I 32 in the case of, in the case of ints. So we're
- 1:10:09limited to whatever, so I 64, sorry, I 64. So whatever the limit is on, on I 64, that does
- 1:10:16mean that you can't pass in. Yeah. You had it there. Whatever, whatever two to the 64 is. There we are.
- 1:10:21There's the number. I don't know how to say that number, but it's like a million trillion times
- 1:10:27nine or something. Yeah. you would have trouble with, you could use a, you could use a,
- 1:10:33functional validator. You could find a way around it if you had to, but yeah, I think that's a price
- 1:10:37worth, worth paying for the fact that we can do internet integer, stuff really quickly. Right.
- 1:10:43And we can do bounds checks much more, much more quickly. yeah. And we have, obviously we have
- 1:10:48nice errors in there. If you do pass in something bigger than that, or if you pass, float inf,
- 1:10:53uh, again, we'll get infinity same as we would, if you've got a number above that or float nan,
- 1:10:58again, you'll get it. You know, that's not allowed. So those cases are all taken care of and they give
- 1:11:02you a nice error and there would be an escape, escape hatch if you really had to. Right. So the escape
- 1:11:07patch could be, you might write a validator that checks is the number in Python. It checks,
- 1:11:12is the number bigger than this limit. If it is race and exception, say number two bigger,
- 1:11:17something like that. Yeah. I mean, there isn't actually an escape hatch in the case of Jason,
- 1:11:21because we have to do the, we have to do the parsing before we get there. So you'd have to,
- 1:11:25you'd have to pass your Jason externally and then pass it in as a Python object and do something weird,
- 1:11:29but it's uncommon that you get insanely large numbers like this. I think that the insanely large
- 1:11:35numbers like that come up when people try and break things almost. Yeah. They try to break things or
- 1:11:39they're trying to do some, some odd math problem where like, I'm trying to use recursion to compute
- 1:11:45and see how many prime, you know, something like that. But in the general day to day of I'm accepting
- 1:11:50like user input over an API, you know. What I would say is that as a Unix
- 1:11:56timestamp in milliseconds is beyond 999 in years, right? It's, it's beyond the date that anyone's ever
- 1:12:02going to want to use. So I'm, I don't see that being a problem really. I don't either.
- 1:12:07Actually, I think there's probably, I don't know how to make it happen, but there's probably some
- 1:12:11interesting performance story for Python getting faster. If it could work with real numerical
- 1:12:17types rather than these super flexible numerical types, you know, a lot of times you'll see examples
- 1:12:22of math and it's like, well, okay, this, this, you know, pie, long object thing, instead of working
- 1:12:28just with, you know, true ints and floats and stuff really slows it down. So I don't know. I see a
- 1:12:33future maybe someday where Python actually adopts in these sort of limited types like this potentially,
- 1:12:38but isn't that what kind of libraries like number are doing? They're allowing you to selectively
- 1:12:43compile a function without going completely off on a tangent. I think that's one approach.
- 1:12:46And there you explicitly say whether it's an, an, an, or, or stuff like that. Right.
- 1:12:50I think the other option would be like, you know, another way would be to say,
- 1:12:54you don't want to be writing Python at that point, because you want to be able, you want all the tools
- 1:12:58available in Rust syntax to allow you to, to say all the stuff you want to be able to say and do
- 1:13:03integer overflow nicely. So the other option would be some point there'll be a way to basically write
- 1:13:08Rust even more easily than now inside Python. Those of us who are using PyCharm and are, you know,
- 1:13:13really lucky that we get PyCharm and we can get basically syntax highlighting in any random string.
- 1:13:17That doesn't seem too crazy. and obviously even more so if you were porting a file. So I think there are
- 1:13:22lots of ways around it. yeah. Yeah. We'll see. Maybe more stuff to come together with the
- 1:13:26WebAssembly future. Who knows? Anyway, a lot, a lot of stuff to think about. I think this is this,
- 1:13:31I didn't bring this up because I feel like this is a problem or anything. I brought it up just because
- 1:13:34I wanted people to be maybe aware that there are some slightly different data types at play here.
- 1:13:40Yeah. Since it's going through Rust. Yeah. I think it's important to see that under the
- 1:13:42hood we are doing. Yeah. Yeah, exactly. And, and so I've, we can talk about date, time, date, time,
- 1:13:49time, time delta validation, but I've built a library in Rust for doing that.
- 1:13:54a bit faster than all the ones I could find that is for me, makes the right compromise called
- 1:13:58speed date. and that, that is having to deal with exactly those overflow problems. And I fuzz
- 1:14:04this library a great deal and found a whole bunch of overflow issues by fuzzing it because yeah,
- 1:14:09when you're doing raw parsing in, in Rust, you have to think about that stuff that those of us who come
- 1:14:15come from a Python background haven't even thought about, you know, the idea that adding two numbers
- 1:14:19is scary and might result in a panic is, is, is, is. Yeah. I honestly, I hadn't thought about it for
- 1:14:24while. It's kind of nice to just not have to worry about those things. You used to just always have to
- 1:14:28consider, you know, is it, is it okay to add, is it okay to multiply these things? Because even if that's
- 1:14:33just an intermediate value, something insane might happen along the way. Right. Yeah. Cool. All right.
- 1:14:38Well, thank you so much for working on Pydantic putting out there. I know it's made my code
- 1:14:43and my projects much nicer. 72,000 other people agree. It seems like. No problem. Thank you very
- 1:14:49much. And thank you so much to all of the people who, who help with Pydantic in, in every way from,
- 1:14:53from like Eric and Sebastian and people who, who work, like work on it quite a lot, but also to like
- 1:14:59all the people who create issues and, and submit one pull request that like makes my job a lot more
- 1:15:03fun that it's not just me sitting in a, sitting in an ivory tower, doing it on my own.
- 1:15:06It's much more fun to work on projects with people. Absolutely.
- 1:15:09Magnus says, thanks to the great show and all the work on Pydantic. Looking forward to Pydantic too.
- 1:15:14Right on. Now, before we get out of here, final two questions. If you're going to write some Python
- 1:15:17code, work on Pydantic, what editor do you pull up? I pull up PyCharm. I'm a complete convert. I
- 1:15:23completely rely on it. Yeah. Right on. And notable IPI or even a cargo package, I suppose, whatever,
- 1:15:31whatever you want to shout out to some external library out there that you think is pretty cool.
- 1:15:34It's not going to be, it's not going to be particularly interesting because we've talked
- 1:15:39about it already, but Py03, I'm like forever impressed by what those guys have done. And
- 1:15:42obviously they've made what I'm working on here possible. And they've been really helpful for
- 1:15:45me when I've asked dumb Rust questions. So yeah, thank you to them. And yeah, if you're ever thinking
- 1:15:50about getting into Rust, doing it from Python is a really, really neat way where when you can't
- 1:15:54work out what the hell's going on, you can kind of fall back to Python sometimes.
- 1:15:57There's an audience question a while back about any resources that you might recommend
- 1:16:01for learning Rust or on the journey to getting to Py03 and so on.
- 1:16:06No, I'm like, people always ask me, what, how did I learn to code and where did I do it? And I
- 1:16:11basically smashed my head against the wall until it compiled.
- 1:16:13Yeah, I hear that. That's a pretty common way. Okay. Final call to action. People are
- 1:16:19interested, excited. They have feedback, something like that. They want to try out
- 1:16:23Pydantic 2. Particularly if you're using an unusual environment, install Pydantic Core right now.
- 1:16:29PIP install Pydantic Core and just run the simple example as one, for example, on the release.
- 1:16:35Check it compiles. And if you find an environment where it doesn't work, so it not compiles, but runs,
- 1:16:39let me know because that'll be easier to fix sooner rather than later. And then most of all,
- 1:16:43once we get to the betas and alphas of Pydantic V2, please come and try it then because,
- 1:16:49again, it'll be a lot easier to fix it before it's released and after.
- 1:16:52Yeah, absolutely.
- 1:16:53And I'll do a lot of shouting on Twitter about that when the time comes.
- 1:16:55Perfect. All right, Samuel, thank you so much for being here.
- 1:16:59Thank you very much, Michael. It's been a pleasure.
- 1:17:01Yeah, you bet. As always. See you later.
- 1:17:02Cheers. Bye bye.
- 1:17:03This has been another episode of Talk Python To Me.
- 1:17:07Thank you to our sponsors. Be sure to check out what they're offering. It really helps support the show.
- 1:17:12Listen to an episode of Compiler, an original podcast from Red Hat. Compiler unravels industry topics,
- 1:17:18trends, and things you've always wanted to know about tech,
- 1:17:21through interviews with the people who know it best. Subscribe today by following talkpython.fm/compiler.
- 1:17:28Starting a business is hard. Microsoft for startups, Founders Hub provides all founders at any stage
- 1:17:34free resources and connections to solve startup challenges. Apply for free today at talkpython.fm/foundershub.
- 1:17:41Want to level up your Python? We have one of the largest catalogs of Python video courses over at Talk Python.
- 1:17:47Our content ranges from true beginners to deeply advanced topics like memory and async. And best of all,
- 1:17:54there's not a subscription in sight. Check it out for yourself at training.talkpython.fm.
- 1:17:59Be sure to subscribe to the show. Open your favorite podcast app and search for Python. We should be right at the top.
- 1:18:05You can also find the iTunes feed at /itunes, the Google Play feed at /play, and the direct RSS feed at /rss on talkpython.fm.
- 1:18:14We're live streaming most of our recordings these days. If you want to be part of the show and have your comments featured on the air, be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 1:18:25This is your host, Michael Kennedy. Thanks so much for listening. I really appreciate it. Now get out there and write some Python code.
- 1:18:31Thank you.