Latest / Talk Python To Me / #415: Future of Pydantic and FastAPI
Transcript
- 0:00The release of Pydantic 2.0, its partial rewrite in Rust, and its refactoring into Pydantic Core and top-level Pydantic in Python is big news.
- 0:09In fact, the alpha of Pydantic 2 was just released.
- 0:12Of course, these changes will have potentially wide-ranging and positive effects on the libraries that are built upon Pydantic, such as FastAPI, Beanie, and others.
- 0:22That's why this chance I had to catch up with Samuel Colvin from Pydantic and Sebastian Ramirez from FastAPI together, live from PyCon 2023, was really timely.
- 0:32It's a super fun and wide-ranging interview I'm sure you'll enjoy.
- 0:36Plus, there's a bit of an Easter egg in the middle.
- 0:38This is Talk Python To Me, episode 415, recorded on location at PyCon in Salt Lake City on April 23rd, 2023.
- 0:47Welcome to Talk Python To Me, a weekly podcast on Python.
- 1:02This is your host, Michael Kennedy.
- 1:04Follow me on Mastodon, where I'm @mkennedy, and follow the podcast using @talkpython, both on fosstodon.org.
- 1:12Be careful with impersonating accounts on other instances.
- 1:14There are many.
- 1:15Keep up with the show and listen to over seven years of past episodes at talkpython.fm.
- 1:20We've started streaming most of our episodes live on YouTube.
- 1:24Subscribe to our YouTube channel over at talkpython.fm/youtube to get notified about upcoming shows and be part of that episode.
- 1:31This episode is sponsored by Sentry.
- 1:34Don't let those errors go unnoticed.
- 1:36Use Sentry.
- 1:36Get started today at talkpython.fm/sentry.
- 1:39And it's brought to you by InfluxDB.
- 1:42InfluxDB is a database purpose-built for handling time series data at a massive scale for real-time analytics.
- 1:49Try it for free at talkpython.fm/InfluxDB.
- 1:53Samuel, Sebastian, super nice to see you here at PyCon.
- 1:56Welcome to the show.
- 1:57Thank you very much for having us.
- 1:59It's strange and exciting to do this live and to see you.
- 2:03Yes, I know.
- 2:04Normally it's remote over screen share over half the world or something like that.
- 2:09Yeah, I've been able to talk with you directly.
- 2:11Also with Samuel here.
- 2:12It's super cool, super cool to hear you.
- 2:14Yeah, thank you very much.
- 2:15Yes, it's great to be here.
- 2:16It's really fun being at PyCon and then doing this is like, yeah, even more fun.
- 2:19I've done my talk, so I'm much more relaxed than I would have been if it had been this time yesterday.
- 2:23I was just thinking, talking to someone else, like one of the best parts about giving a talk is that when it's over, you can really relax.
- 2:30You know what I mean? You're like, okay, now I can enjoy the conference.
- 2:33Absolutely, yeah.
- 2:34And the parties, because you can't go too big on the parties if you've got to talk.
- 2:36I feel like all the best ones were last night.
- 2:38I'm afraid. We were at a pretty good one last night, weren't we?
- 2:41Yeah.
- 2:41Yeah.
- 2:42But that was excellent.
- 2:43All right, well, really good to have you both at the show.
- 2:46I guess you hardly need introductions.
- 2:49You both are doing such cool work.
- 2:51We've had you on the show several times each.
- 2:53So maybe just let's start with a catch up.
- 2:55Like you both have lots of big news.
- 2:57Don't want to necessarily spoil too much, but you know.
- 3:00What have you been up to?
- 3:01Yeah, so I raised money earlier this year.
- 3:03Well, it was all sorted last year.
- 3:05Money came in in January this year.
- 3:06Started a company around Pydantic.
- 3:08So I've been busy hiring.
- 3:10Got a team of seven now.
- 3:12One more going to join in June.
- 3:13And yeah, currently we're working full-time on Pydantic version 2, getting that released.
- 3:18And then after that, we're going to move on to the commercial plans,
- 3:21which I'm not talking about too much, mostly because they're up in the air a bit.
- 3:25Also because if you start talking about them, you have to finish talking about them.
- 3:28And then that's like, I'll just like take over the whole podcast.
- 3:30So I'll say that, yeah, working on Pydantic V2 for now and then moving on soon.
- 3:35Well, first from the whole community, congratulations.
- 3:36You must be really thrilled.
- 3:38Yeah, it's amazing.
- 3:39It's very surreal, right?
- 3:41Because I was going to say, did you see this coming?
- 3:43No, I didn't.
- 3:44My plan had been to start a different company once Pydantic V2 was done.
- 3:49And then in November, Bogomil from Sequoia, who Sebastian knew, Sebastian recommended,
- 3:55he chatted to me.
- 3:56We had a call.
- 3:57We had another call two weeks later.
- 3:58And then he said, let's have the final meeting with like a few more partners to decide whether
- 4:02to invest in two weeks time.
- 4:03So I thought, oh, I should probably go and speak to some other VCs.
- 4:07So Sebastian very kindly got me lots of intros.
- 4:08My girlfriend also got me some intros.
- 4:10I had like five meetings lined up.
- 4:12And then the like floodgates opened and I got another like 20 or so VCs emailing me being
- 4:17like, please, can I call?
- 4:17Starting to hear about, oh, why are we not part of this?
- 4:20Right.
- 4:21And then I got COVID.
- 4:23So I spent a week like locked in the bedroom upstairs doing VC calls.
- 4:27Most of them with the like camera off feeling absolutely horrific.
- 4:29And yeah, and then came back full circle back and had the big call with Sequoia and took
- 4:35their money.
- 4:35They've been amazing.
- 4:36So it was Sequoia that invested.
- 4:37Yeah.
- 4:37Wow.
- 4:38Awesome.
- 4:38That's a big name to have behind you.
- 4:40So Sequoia and Partec who are the smaller VC who are like French American and then Irregular
- 4:45Expression, which is this really cool CTO network based kind of again, like New York and Paris.
- 4:51And then a bunch of angels.
- 4:52Yeah.
- 4:53Last time we spoke, it was about Pydantic V2 and then all of this broke.
- 4:56Yeah.
- 4:57Yeah.
- 4:57So I feel like I'm just back up to, as in problem was, although I was doing it to speed
- 5:02up, that was there were then two months of basically doing meetings and doing legals.
- 5:06So I think I've now got a team sufficiently that I'm like caught up to where I would have
- 5:09been if I had just sat there and written code all along.
- 5:11Yeah.
- 5:12That's how it goes, right?
- 5:14Yeah.
- 5:15You got to put a little more sand in the gears to grow, I guess.
- 5:19And Sebastian, how about you?
- 5:21What do you, what have you been up to?
- 5:22How have you been?
- 5:22Oh, I've been good.
- 5:24I've been good.
- 5:24Yeah.
- 5:25Very excited about like what they are doing at Pydantic is like the team they are assembling
- 5:29is like just amazing.
- 5:30And like, yeah, just like recently working a bunch in FastAPI and like Typer and actually
- 5:36like in also some of the low level things of FastAPI and also not just FastAPI, but like
- 5:43the things that go underneath.
- 5:44Right now, like one of the things that I am pushing for is having documentation of the
- 5:50API reference of the reference of the, each one of the parameters for what it is for each
- 5:54one of the methods, like all that stuff.
- 5:56Yeah.
- 5:56And I want to do it in a, in a better way that is more maintainable and that I can test
- 6:01the actual documentation for those parameters and consistency between like, there's a bunch
- 6:06of things that I'm trying to do.
- 6:08And like, it also goes to the low levels of like typing and interacting with the people
- 6:12that is handling typing and like all the stuff that is super cool, super exciting.
- 6:16But like, I think it can work and it can, it can make these things have like, you know,
- 6:21like the API reference for the tools is something that a lot of people have been requesting and
- 6:26like being able to have that in a way that is easy to maintain and that can work well and
- 6:31that I can handle.
- 6:32Like, I think that's, that's super exciting on that side.
- 6:34And on the other side, of course, like the integration with Pydantic V2 is super exciting
- 6:38now that they have like the first alpha available.
- 6:41It is.
- 6:42I mean, here you are going along working on FastAPI.
- 6:45Everyone I talked to was just universally impressed with it.
- 6:49You know, honestly, like I've never heard a bad thing about FastAPI and people are really
- 6:54enjoying it.
- 6:54And then here comes Samuel just changing the foundation, changing up Pydantic.
- 7:00No, no, no.
- 7:02I'm just teasing.
- 7:03So how much work is that actually going to be to kind of make the change?
- 7:07Is it kind of nothing or is it some work?
- 7:09No, like there will be some working FastAPI.
- 7:11The thing is for final users, it will be like almost transparent.
- 7:15Right.
- 7:15They will probably like, if they are doing like weird stuff, complex things like that touches
- 7:21the corner cases or things like that, like they will probably have to update some things.
- 7:25But for most of the use cases, it will be pretty much transparent for people.
- 7:29And they will just like get like the, like, I don't know, like 10, 20x performance from
- 7:33Pydantic v2.
- 7:33And also like the...
- 7:35I was going to say, just on the performance, I'm sorry to interrupt you.
- 7:37One of the big things that we will be able to, you'll be able to drop from FastAPI is the,
- 7:42I'm going to call it a hack, but it's not your fault.
- 7:44It's my fault.
- 7:44Of like, don't ask the type problem of serialization.
- 7:48So I think that the like speed up on serialization in FastAPI could exceed, like, you know,
- 7:54could be even bigger than that.
- 7:54I don't know that yet, but I'm really hopeful for some like massive improvements because of
- 7:59fixes in Pydantic that make FastAPI simpler and more elegant.
- 8:03Yeah.
- 8:03And since they're turning up the lights, we'll see how long we last here.
- 8:07We'll stay as long as we can.
- 8:10If you hear any noise in the background, that's because they're trying to tear down PyCon,
- 8:13but we're going to...
- 8:14They're tearing down PyCon around us, it seems.
- 8:16We will not let it be torn out.
- 8:17It will live on.
- 8:19It's not because of Pydantic V2.
- 8:20So, yeah, we may have to pause and move, but we'll find out.
- 8:24Anyway, from a user for Pydantic, Samuel, if you haven't gone to like deeply gone into like
- 8:32root object validation and all that kind of stuff, it's probably you won't even know, right?
- 8:36So I think the hardest thing...
- 8:38Yeah, you're right.
- 8:38The vast majority of your code will either continue to work or we'll have a...
- 8:44If you get run over by a forklift, it's going to really slow down the development of Pydantic,
- 8:49by the way.
- 8:49We're going to have a mod tool to change the name of methods.
- 8:55So with luck, the vast majority of the changes should be automated.
- 9:00I suspect that, and I was saying this earlier in the open space, the hardest thing is probably
- 9:05going to be where your API subtly changes in its restrictions because of effectively edge
- 9:11cases that Pydantic has fixed.
- 9:13So for example, in Pydantic v1, we would coerce a int to a string.
- 9:17If you passed a string to an int to a string field, we would coerce it.
- 9:21I think that that's wrong and we shouldn't have done it.
- 9:23And so now we don't.
- 9:24But I was saying in the example, if for some reason you stored your IDs as strings and therefore
- 9:29your API had the ID field as a string, but your user was just like pumping them into your
- 9:34API as integers because that seemed to make sense to them, that's going to break.
- 9:38And you probably haven't gotten a unit test that test that because you know your ID field
- 9:41is a string.
- 9:42So I feel sorry for those people.
- 9:44And my biggest request would be if you're a user, try Pydantic v2 as soon as possible.
- 9:50I know if you use it via FastAPI, you can't yet, but like all the other libraries.
- 9:54But the sooner you can try it, the sooner you can tell us and the more easily we can fix things.
- 9:59And we are prepared to add compatibility shims.
- 10:02Okay.
- 10:03Well, there, I mean, in Python, we have sort of a from futures import.
- 10:06Well, there'd be from a, from history import type of like reverse thing.
- 10:10Just slow that down or is it going to be a deprecation or is it just...
- 10:14So we're doing deprecation warnings everywhere we can or deprecation errors saying this has
- 10:19gone away.
- 10:19You probably want to replace it with this thing.
- 10:20We're working really hard on that.
- 10:22We haven't got a like from future import or a compact layer yet for actual like validation
- 10:28logic.
- 10:29But if we have to, we will.
- 10:30Yeah.
- 10:31Okay.
- 10:31You'll see, right?
- 10:32See how much screaming...
- 10:34What we didn't want to do was try and guess at what the problems were and build a compatibility
- 10:38layer that people didn't need.
- 10:39Yeah, of course.
- 10:40So that's why we're doing it this way.
- 10:41Yeah.
- 10:42That makes a lot of sense.
- 10:43You want to go as minimal backwards trying to fill those gaps as possible, right?
- 10:48And if I'm brutal about it, if insert name of big bank that use Pydantic locks and never
- 10:53engage with the open source community, get stung by this, they never paid me a penny and they've
- 10:57never engaged, then like, I'm sorry for them, but I'm not as sorry as I would be if they
- 11:02had like come and reported an issue and tried to like help along the way.
- 11:05Yeah.
- 11:06Yeah.
- 11:06Like, can we work with you to just like smooth this over?
- 11:08And, you know, worst case, can it be, you know, equal, equal, Pydantic, equal, equal,
- 11:131.10?
- 11:14I think we'll carry on supporting critical security fixes for a year.
- 11:18Okay.
- 11:19So there's something of an LTS type of thing you're thinking?
- 11:21Yeah.
- 11:21For a while.
- 11:22We have to, right?
- 11:23For a while.
- 11:24And yeah, we'll see.
- 11:25Look at the download numbers and play it by ear.
- 11:27Yeah.
- 11:27All right.
- 11:28Cool.
- 11:28While we're talking about compatibility, if people are like doing a lot of the overriding
- 11:33functions and stuff in their Pydantic models, like what do they, what should they expect?
- 11:37Too many changes are pretty similar.
- 11:38One of the biggest changes is that the init method of a model is now no longer called when
- 11:45you're, unless you literally call init.
- 11:47So if you call model validate, or if your model is nested inside another model, init is no longer
- 11:53called.
- 11:53The solution for that is to use a wrap validator or a model validator, but that's going to
- 11:58be one of the pain points for people.
- 12:00But there's just, it turns out with the Rust API, it's literally impossible without a massive
- 12:04performance hit to do that.
- 12:07This portion of Talk Python To Me is brought to you by Sentry.
- 12:10You know that Sentry captures the errors that would otherwise go unnoticed.
- 12:14Of course, they have incredible support for basically any Python framework.
- 12:18They have direct integrations with Flask, Django, FastAPI, and even things like AWS Lambda and
- 12:25Celery.
- 12:26But did you know they also have native integrations with mobile app frameworks?
- 12:30Whether you're building an Android or iOS app, or both, you can gain complete visibility into
- 12:36your application's correctness both on the mobile side and server side.
- 12:40We just completely rewrote Talk Python's mobile apps for taking our courses, and we massively
- 12:46benefited from having Sentry integration right from the start.
- 12:50We used Flutter for our native mobile framework, and with Sentry, it was literally just two
- 12:55lines of code to start capturing errors as soon as they happen.
- 12:58Of course, we don't love errors, but we do love making our users happy.
- 13:02Solving problems as soon as possible with Sentry on the mobile Flutter code and the Python server
- 13:08side code together made understanding error reports a breeze.
- 13:12So whether you're building Python server side apps or mobile apps or both, give Sentry a try
- 13:19to get a complete view of your app's correctness.
- 13:22Thank you to Sentry for sponsoring the show and helping us ship more reliable mobile apps
- 13:27to all of you.
- 13:27Do you already have a roadmap?
- 13:30Have you already tried the alpha on FastAPI?
- 13:33Like, what's the story for you guys?
- 13:35So, like...
- 13:36Pedantic-wise.
- 13:37Yeah, yeah, yeah.
- 13:37So, like, we have actually been interacting a lot, like, with what are the changes that are
- 13:42needed?
- 13:42Like, what is it going to be?
- 13:43And like, as someone was saying, like, I have a lot of code that is quite hacky.
- 13:48I was actually surprised it didn't break much.
- 13:51It just, like, really worked.
- 13:52And like, it's for this particular use case where you can have, like, they are so loud.
- 13:58They really want to tear us down.
- 13:59I know.
- 14:00We might have to be weird to say it.
- 14:02But let's go ahead.
- 14:02Let's finish this up.
- 14:03Yeah.
- 14:03So, like, validation error.
- 14:08Can it concentrate?
- 14:09So, imagine this use case where you have user model.
- 14:13And then this, you want to return this user model.
- 14:16But then you have an authenticated user model, as you were showing in the talk, in the PyCon talk.
- 14:22And then this authenticated user model has a field that is a password.
- 14:26If you return that use, the authenticated user directly, FastAPI does a lot of tricks to make
- 14:33sure that what you receive in the client side is the actual user without the password.
- 14:38That is the thing that you declared that you were going to return.
- 14:41But by default, if you don't do it through FastAPI, but you do it with just plain Pydantic,
- 14:46it will just check, like, hey, is this an instance of the other?
- 14:48And then it will include the field.
- 14:50Because, like, you know, because in thinking about types, it makes sense.
- 14:54Like, oh, this is a subclass of that.
- 14:56So, it makes sense that it's valid.
- 14:58But when you think about data in an API, it doesn't make sense that it will include more
- 15:02data than what it should.
- 15:03Right, right, right.
- 15:04Because you don't want to either have a mass injection attack on the inbound data or an
- 15:10over-exposure on the way out, right?
- 15:12You know, give away the password from users.
- 15:14Is that bad?
- 15:15I think it's pretty bad.
- 15:16Okay, yeah, all right.
- 15:18Like, you know, for example, like, some months ago or years or something, like, I remember
- 15:23that Kaggle, the Kaggle API was returning, like, some of the hashes of the experiments.
- 15:28So, like, you know, it's like, it's a mistake and a bit, but it's sad that it will end up
- 15:33just, like, filtering more data than what it should be returning.
- 15:36And it's something that can happen very easily.
- 15:38It can happen very easily to FastAPI applications if people don't specify what is the response
- 15:43model, the thing that they want to return.
- 15:45And they just return a bunch of data directly.
- 15:47So FastAPI does a lot of things to make sure that when you declare a response model that
- 15:52should filter this data, the data is filtered.
- 15:55But that's a lot of code in FastAPI to make it compatible.
- 15:58With the new Pydantic V2, that's going to be pretty much transparent.
- 16:02So that's amazing.
- 16:03That is amazing.
- 16:04Yeah.
- 16:04There's going to be, like, a bunch of things that require, like, some refactoring and
- 16:08also making sure that the Pydantic V1 and V2 are compatible at the same time in some way
- 16:14so that people can have, like, a migration path.
- 16:16But yeah, like, we have been making sure that, like, all the things that need to be changed
- 16:21or that need to be updated or, like, all the things that need to be exposed from the Pydantic
- 16:25side are actually available.
- 16:26Yeah, it's awesome that you guys are working so closely together on this.
- 16:29I mean, it's going to make it.
- 16:30Yeah, absolutely.
- 16:31So in my mind, these two projects are pretty closely tied.
- 16:34I know that they're not, but that's a big use case.
- 16:36Yeah, I think that's true.
- 16:37And we know that FastAPI is by far our biggest dependent.
- 16:41But also Django Ninja, which is, I think, now second or third, maybe third after SQL model
- 16:46by Starz, is, like, Vitaly, who maintains that, has been engaging a lot with us on V2.
- 16:51So yeah, lots of other projects are interested in it.
- 16:54And I think, yeah, lots of people will be able to remove messy code because of that problem.
- 16:57Because, yeah, like, the invariance of the response interface problem.
- 17:01That's fantastic.
- 17:02Coming back to your previous question about...
- 17:04Before we go to that, I think we should probably find it.
- 17:06What do you think?
- 17:07Yeah, I think you might be right.
- 17:08Not even necessarily, I think the audio may be okay, but just for a concentration, it's
- 17:11very loud with the trucks around us.
- 17:13I feel like I'm on the deck of that aircraft carrier, so I throw things off the side.
- 17:16Yeah, okay, let's pause this for a moment.
- 17:17We'll be back.
- 17:18Hold on.
- 17:18So we have survived the disassembly.
- 17:22We have returned to continue.
- 17:24We were talking about the integration of FastAPI and Pydantic, and that was really cool.
- 17:29I think something I'd like to kind of move to real quick is this big announcement, alpha
- 17:34of version two.
- 17:35Samuel, last time you were on the show, we spoke about the plan for version two, and
- 17:40now you're released in an alpha stage.
- 17:41Tell people where we are with this.
- 17:43Yeah, so we're, yeah, we've had two alphas, maybe three alphas now out.
- 17:47We're basically pretty close to a feature freeze, and the plan is to release the package, release
- 17:54a beta, and effectively, we hope that we can then release the full release, say two weeks
- 17:58after that.
- 17:59But there'll be bugs, and we'll fix them, and we'll have more betas.
- 18:01But effectively, once we get to beta, the plan is that active development is stopping
- 18:06bar fixing bugs.
- 18:07Now it's performance and bugs, right?
- 18:09Yeah.
- 18:10And obviously, one of the big things will be once that's out, there'll be a lot more work
- 18:13on, say, FastAPI, Django Ninja, et cetera, et cetera.
- 18:16And that might come back with, we really need this thing.
- 18:18Either this is broken, or we really need that to make it, you know, to reduce the overhead
- 18:23of upgrading.
- 18:24One of the things I did for Pydantic 1.10, which was super valuable in beta, was to go
- 18:30through packages that use Pydantic, initially sorting by star, but then looking at what they
- 18:35actually do, and trying to upgrade them.
- 18:37And that, like, found me a bunch of bugs in either libraries or in Pydantic.
- 18:41So we're not promising we're going to go and upgrade the whole of GitHub to Pydantic V2,
- 18:46but we'll do a bit of that mostly to try and find bugs.
- 18:50One of the things that would be really useful is if anyone has an application that uses Pydantic,
- 18:54preferably without FastAPI or another library, that they would like help upgrading, we would
- 18:59love to come and help.
- 19:00And it might be a really powerful way of us, again, seeing the real pain points and identifying
- 19:05bugs before we get to V2.
- 19:07Yeah.
- 19:07And I guess another thing to mention that is a real headline, and I also want to get your
- 19:12thoughts on this, Sebastian, is the performance numbers, right?
- 19:15I mean, you put out some pretty impressive performance numbers, and Sebastian gets to
- 19:19piggyback on that, right?
- 19:20Yeah.
- 19:20I mean, yeah, I'm really proud of it, right?
- 19:23Yeah, you should be.
- 19:24I think to go in a change of release, in a bump of release, to be in the ballpark of 22
- 19:30times faster, not 22%, but 22 times faster, I don't know of another package that's made
- 19:35an upgrade of that kind of order of magnitude.
- 19:37What's crazy is it's not numerical computing, right?
- 19:41It's general purpose.
- 19:42If you look at the example I gave in my talk earlier, it's a completely standard Pynantic
- 19:46model with four fields.
- 19:47And that's where we're seeing that kind of like 22 times speed up.
- 19:50So I think it's going to be massive.
- 19:51I have my own cynicism about people who hype about performance as being the most important
- 19:57thing.
- 19:57I don't think most applications, it's actually the thing that matters most.
- 20:01But I think it matters.
- 20:02A, it matters to everyone, and everyone wants it to go in the same direction.
- 20:05And two, it matters to the whole world and to the whole community that we effectively reduce
- 20:10the energy that we consume, like doing compute, basically.
- 20:14Right.
- 20:14That's absolutely true.
- 20:15And also, even if people don't actually need it, there's a group of people who are like,
- 20:20well, I'm going to leave for Go because it's not fast enough.
- 20:22I can't do enough concurrency or whatever.
- 20:24And if they don't have that feeling, even if they didn't actually need that percentage
- 20:28increase, that's still really good for the Python community.
- 20:30Even me, I was saying I had a gigabyte of data from web analytics that I needed to load
- 20:36into a Polars data frame.
- 20:38And for that, I needed to A, extract some attributes from nested fields and B, parse dates and things
- 20:43like that.
- 20:44And I used Pynantic V2.
- 20:45And it was vastly faster with V2.
- 20:49It went from like toodling, what's the word I'm looking for?
- 20:51Twiddling your thumbs to like it happens virtually instantly, right?
- 20:56And that's fantastic.
- 20:57And that'll be even more true when you have an order of magnitude or two orders of magnitude
- 21:01more data.
- 21:02Yeah, for sure.
- 21:03Sebastian, how about you?
- 21:04What's the knock-on effect for FastAPI?
- 21:06So I think one of the coolest things is that people won't have to change the code to get
- 21:11that performance benefit.
- 21:12It's just going to be like a bump suddenly.
- 21:13And because of the new ways that Pynantic can handle the data, we're going to be able
- 21:19to, there's something that needs to be done in FastAPI, but we're going to
- 21:21be able to let the parsing of the data, let Pynantic handle that in the Rust site.
- 21:28So Pynantic will be able to just read the JSON bytes instead of reading them in the Python
- 21:34site and let Pynantic do that.
- 21:35And then Pynantic give the models back to the rest of the code of FastAPI.
- 21:39That alone will boost performance a lot.
- 21:41But the fact that it's being done in Rust, in the Rust site, it's just going to be amazing.
- 21:45Yeah.
- 21:46Like one of the other things that I want to do that is on the plans is to let users
- 21:50define how they want to serialize data and not have like, this is just like by default,
- 21:55it's just like Pynantic models and like it converts automatically to JSON.
- 21:59But I want to allow users to decide how to serialize the objects and the data so that
- 22:03they can just...
- 22:04Like data classes or something like that?
- 22:06Yeah.
- 22:06For example, they can say like, oh, I don't want to serialize with the standard JSON serializer.
- 22:10I want to serialize with our JSON, which is like the...
- 22:13I see.
- 22:14Rust based implementation to serialize JSON.
- 22:17Or they can say like, I want Pynantic to be the one that serializes this because I know
- 22:21that this is just a model that can handle that.
- 22:22They can also like...
- 22:23And this is one of the things that I think is super cool.
- 22:25They can also create...
- 22:27They will be able to create a way to say, I want to serialize this response to XML or something
- 22:33like that or to YAML and to let Pynantic handle the validation, but then like do the serialization
- 22:38in a way that they can customize the whole thing without having to do it directly in the code.
- 22:43Maybe even some of these crazy stream buffer type of protocols.
- 22:47You know, like, yeah, like protocol buffers with GRPC or like even message pack or like,
- 22:51you know, like a bunch of these things that there's no obvious way and there's no native
- 22:56way to have support for that, for reading the data and for exporting the data.
- 23:00And like, that's one of the things that I have like implants.
- 23:02I like, I'm probably saying too much and then I'm going to account all the pieces of the code.
- 23:06And now they're like, you know what?
- 23:07You promised this.
- 23:08You did promise it.
- 23:09Well.
- 23:10Can I just come back on serialization for a minute?
- 23:12Yeah, please.
- 23:12Yeah, please.
- 23:13Yeah.
- 23:13So what we've, I've worked from October, quite like putting to one side, the whole funding
- 23:19round in the middle of it was working solidly on serialization.
- 23:21So we have, there's almost as much code in Pynantic core now for serialization as there
- 23:26is for validation.
- 23:26Yeah.
- 23:27Well, we can serialize directly to, to Jason using the same underlying library that, or Jason
- 23:32uses using Serdi, but one, and also we can, you can customize how your serialization
- 23:38goes on a per field basis rather than on a per type basis, which is like incredibly powerful.
- 23:42But we also allow you to effectively serialize to Python.
- 23:46So not just what used to be the dict method, but basically do JSONable Python.
- 23:51So you effectively set the mode when serializing to Python, to Jason, and you will only get the
- 23:55like, whatever it is, seven primitive Jason types in Python, which is super valuable if you
- 24:00want your output to be XML, because then you know your XML encoder only needs to bother,
- 24:04needs to take in dictionaries, list, ints, floats, none, bool.
- 24:08Yeah.
- 24:08Rather than whatever complex data you have.
- 24:11So there's an, or I, yeah, I'm like super proud of lots of the advantages of serialization.
- 24:15My 45 minute talk earlier, I was able to touch about half of the big new features, which
- 24:20kind of talks about quite how much has changed.
- 24:23Yeah.
- 24:23That's really exciting.
- 24:24I think we definitely, I was saying earlier, if I had known how long it was going to take,
- 24:28I would never have set out on this journey.
- 24:30So the best thing about it is I didn't, I didn't think about how long it was going to
- 24:33take because we didn't try and do a bit more.
- 24:36We tried to do everything or I tried to do everything.
- 24:38And that's how it's disadvantaged.
- 24:40It's taken longer than we had hoped, but.
- 24:41But here you are.
- 24:42You're pretty much here.
- 24:43That's really good.
- 24:43That's really good.
- 24:44And so when you think about performance, right, obviously the 22 times faster is awesome.
- 24:49The FastAPI speedup is awesome.
- 24:51But if you do something like SQL model and FastAPI or Beanie and FastAPI, you're getting
- 24:58on both ends, you're getting that Beanie or the Pydantic benefits with the Beanie integration
- 25:03and the fast.
- 25:04So you, you're kind of putting Pydantic in both those layers.
- 25:08And so those speedups are like twice as good or something like that.
- 25:11Yeah.
- 25:12Right.
- 25:12I think you, well, they're probably, yeah, they're like, they're the same relatively,
- 25:16but more in absolute terms.
- 25:17Yeah.
- 25:18Yeah.
- 25:18Yeah, absolutely.
- 25:19So, yeah, I think it's, you know, the fact that it's a lot of people,
- 25:21so many things have been built upon Pydantic means you've just sped up a bunch of projects
- 25:26without them doing too much.
- 25:28Yeah.
- 25:29We get the, like the win.
- 25:30It's like CPython itself getting faster, helps everyone.
- 25:32This is like the next layer down, but we, you know, as a dependency of lots of packages,
- 25:36we get to speed up lots of the community with one package, like one person devoting a year
- 25:41to it.
- 25:41Does this surprise you to see all these projects coming out?
- 25:44Like here's another project based on Pydantic plus, you know, name your other thing that
- 25:48it's been crazy, particularly in the like machine learning space where,
- 25:51you know, LangChain, who are one of the like big names right now in these like big language
- 25:56models, large language models, all based on Pydantic, right?
- 25:59Yeah.
- 25:59You were saying, I think on Twitter, that OpenAPI use a bunch of FastAPI, right?
- 26:04OpenAI?
- 26:04Sorry.
- 26:05Yeah.
- 26:06OpenAI, not OpenAPI.
- 26:08Marvin from, I think from Prefect is built on Pydantic again.
- 26:11So like the wave of machine learning stuff seems to have leveraged Pydantic a whole lot.
- 26:16Docker array being another, another big example.
- 26:18Some for Elastic and some other things as well.
- 26:24This portion of Talk Python To Me is brought to you by Influx Data, the makers of Influx
- 26:28DB.
- 26:28Influx DB is a database purpose built for handling time series data at a massive scale for real
- 26:35time analytics.
- 26:36Developers can ingest, store, and analyze all types of time series data, metrics, events,
- 26:42and traces in a single platform.
- 26:44So dear listener, let me ask you a question.
- 26:46How would boundless cardinality and lightning fast SQL queries impact the way that you develop
- 26:51real-time applications?
- 26:52Influx DB processes large time series data sets and provides low latency SQL queries, making
- 26:58it the go-to choice for developers building real-time applications and seeking crucial insights.
- 27:04For developer efficiency, Influx DB helps you create IoT analytics and cloud applications
- 27:10using timestamped data rapidly and at scale.
- 27:13It's designed to ingest billions of data points in real-time with unlimited cardinality.
- 27:18Influx DB streamlines building once and deploying across various products and environments from
- 27:24the edge, on-premise, and to the cloud.
- 27:27Try it for free at talkpython.fm/influxDB.
- 27:31The link is in your podcast player show notes.
- 27:33Thanks to Influx Data for supporting the show.
- 27:36I'm sure one of the big things you're thinking going forward with FastAPI is like how do you
- 27:42guys work together and make this a seamless change?
- 27:44What else you got?
- 27:45What else are you working on?
- 27:46What else do you see in the future?
- 27:48I have a bunch of things.
- 27:49Are they secret or can you tell us?
- 27:51No, no, no.
- 27:52I can't tell.
- 27:52Most of it I can't tell.
- 27:54I just feel the accountability.
- 27:57But I can't tell.
- 27:59So like I have a bunch of projects and like the funny thing is that in some way it's kind
- 28:04of a dependency graph of things that I should work on.
- 28:07So for example, I have this project generator for FastAPI to generate a project with a SQL
- 28:12database.
- 28:12I haven't updated it in a long time and it uses SQLAlchemy.
- 28:16I built SQL model for that project to use it there.
- 28:19But I haven't updated it there because first I want to upgrade more things in SQL model.
- 28:23I want to finish the documentation, finish the story about migration.
- 28:26But then for the story about migration, I need typer for SQL model.
- 28:30So I need to update things in typer.
- 28:32And then for typer, I want to add support for annotated, which is actually one of the big
- 28:36things.
- 28:36One of the recent big things in FastAPI is that now there's support for annotated.
- 28:41So annotated is this feature from Python.
- 28:44It's like standard Python typings.
- 28:46You import from typing, from typings import annotated, and then you can use that to meet
- 28:52information to the types that you define for parameters.
- 28:54Like what?
- 28:55I haven't used this.
- 28:56I love typing.
- 28:56I use it all the time.
- 28:57And here I'm learning more about typing.
- 28:59The thing is it exists there in the standard library, but it doesn't have like a canonical
- 29:04use in Python itself.
- 29:05It's there mainly for FastAPI and Pydantic to use it.
- 29:09You know, like it's just that like I haven't, I hadn't pushed for that before.
- 29:13But the thing is you import from typings, import annotated, and then you create a function that
- 29:19takes like a username.
- 29:20And then this function will normally be of type string.
- 29:23So it will be like the parameter of the function will be username colon str.
- 29:28Now you can say username colon annotated, and then open square brackets as if it was like
- 29:33a list or like a dict or something.
- 29:35Open square brackets.
- 29:36And then the first thing that you put there, that's the actual type.
- 29:38So you will say annotated string.
- 29:40Ah, okay.
- 29:41And then you can pass additional metadata afterwards.
- 29:43And the additional metadata is the thing that you will use to tell FastAPI this will be extracted
- 29:48from the query parameters or from the cookies or from headers.
- 29:51Before, and like up to recently in FastAPI, the only way to do that was using the default value of the parameter.
- 29:57Right.
- 29:57You would set the default to like a depends or...
- 29:59Yeah, to depends or equals a cookie or equals header or something like that.
- 30:04And then FastAPI can take the information from that to give you the data in your function.
- 30:08But the thing is, if you call that function manually somewhere else, the editor and Python
- 30:13won't complain that you are not passing some parameter that is required.
- 30:16And then you're going to end up with some strange value internally that is just for FastAPI.
- 30:20Right.
- 30:21Or the type checker complains, you're not passing a depends.
- 30:24Like, no, I'm passing a string.
- 30:25That's what it's supposed to be.
- 30:26But that's...
- 30:26Yeah, exactly.
- 30:27Some weird thing like that.
- 30:28Exactly.
- 30:28Yeah, okay.
- 30:29So for those cases, having annotated, like all the type is exactly what it is.
- 30:32And if it has a default value, it's the actual default value instead of like some strange
- 30:37internal concept in FastAPI.
- 30:40And having support for that allows having like much better support for typings, for editors,
- 30:45autocompletion, inline errors, all these things.
- 30:47It's reusing the same functions in other places.
- 30:49And it will also, having support for that in typer, will allow users to have the same
- 30:54function being used for FastAPI and typer, having the custom metadata necessary for each
- 31:01one of the parameters for FastAPI and for typer and things like that.
- 31:04So it's something that is super powerful and super interesting.
- 31:06Yeah.
- 31:07I'm going to come in on annotated because I'm excited about it too.
- 31:09So Pydantic V2, we use annotated for all of our custom types.
- 31:13So for example, positive int type is just annotated of int.
- 31:17And then we use the annotated types package, which is some reusable metadata for annotated.
- 31:22So we would use like positive int is annotated of int and then greater than zero.
- 31:28And what's even cooler is that will be used by Pydantic, of course.
- 31:33Hypothesis is going to get support for that really soon.
- 31:36So it will only pass a positive value in if it sees greater than zero there.
- 31:40And then typer, I guess, could like, even if it's still based on click, it can go and take
- 31:44that greater than and infer it as, you know, must be greater than zero.
- 31:47So I think it was one of the things that typing guys, when they first created annotated, hoped
- 31:52was going to build a rich network of libraries that interchanged metadata.
- 31:56It's taken a bit longer than they expected, but we're getting there.
- 31:59Here the two of you are kind of doing that a little bit, right?
- 32:02That's cool.
- 32:02That's really cool.
- 32:03One of the areas where I feel like typing is a little janky is on ORMs and ODMs.
- 32:08When you define a class, you say, for example, it's like a SQLAlchemy column, or it's a beanie
- 32:15column or something like that.
- 32:17And the type is it's a string column, but really it's a string.
- 32:21It's not a string column.
- 32:22And so there's this weirdness of using types to kind of drive behavior.
- 32:28That's a perfect case for using annotated.
- 32:31That's what I was thinking.
- 32:31Yeah.
- 32:31What it doesn't do is the other case where there is a context where you'd want to get the
- 32:36column object of some sort rather than the integer in a row.
- 32:40So it does mean two different things, the kind of dot objects in the Django context.
- 32:44But yeah, absolutely.
- 32:45Yeah.
- 32:46It's there precisely to solve this kind of problem.
- 32:48And it's also because like currently, as far as I remember, there's no way.
- 32:52So the thing is that this is all based on something called descriptors.
- 32:55And it's that when you call like, I don't know, class user dot name, it's actually the
- 33:01attribute in the class.
- 33:02But when you create an instance of that user and then say user dot name, that is the attribute
- 33:07on the actual instance.
- 33:08And the way that these ODMs or ORMs or these things work is that they have a special way
- 33:14to say like when someone calls the actual class, this is a different thing than when someone
- 33:18calls an instance attribute.
- 33:20Right.
- 33:20And there's sort of two behaviors.
- 33:22Yeah.
- 33:22Yeah.
- 33:23And like it's super powerful.
- 33:24That's how SQLAlchemy works.
- 33:26And it's super powerful because then like all the queries and all the stuff is actually
- 33:29like consistent with how Python works.
- 33:32And you can say like greater than or equals to using Python syntax, which is great.
- 33:36But then currently, as far as I know, there's no way to define that with type annotations
- 33:41in a standard way.
- 33:42I think it's something that will probably be improvable.
- 33:45But I think there's currently no way.
- 33:46There will probably be a way at some point.
- 33:47But to be able to say like, hey, this SQLAlchemy column is a column when it's accessed
- 33:53at the class level.
- 33:54But this is going to be a string when it's accessed at the instance level.
- 33:57A scope level in the annotated, you know, the class is this and this.
- 34:01And it's the instance is that and that.
- 34:03Yeah.
- 34:03That's really interesting.
- 34:04While we're talking types, and I know you both are really big fans because it's such a
- 34:09central part, both your libraries.
- 34:11What do you want to see coming?
- 34:13It feels like this is an area of Python changing fast.
- 34:15But is there something like they just if they could just and I have another question on types
- 34:19by the way after that.
- 34:20If I remember.
- 34:20So I gave a talk at the typing summit asking for certain things.
- 34:23So now we're going to test my can I remember PEP numbers challenge, which I'm going to fail
- 34:28in.
- 34:28But pep472 is that keyword args to so one option would be to allow keyword arguments to get
- 34:36item, which would make annotated even more powerful because then you could use keyword arguments
- 34:40to describe the meaning of your metadata, rather than having to have these kind of identifier
- 34:44types like greater than one of the big things that I hope we're going to persuade.
- 34:49So I think one of the things that's happened recently is that everyone gets that runtime
- 34:52use of type hints is a legitimate thing.
- 34:54They might not want to do it themselves, but they get that like, it's a legitimate thing
- 34:58to do.
- 34:58How much pushback was there when you first came out by Tandic there?
- 35:01I think we were like the black sheep of Python.
- 35:03I was a black sheep of Python.
- 35:04This is supposed to have no meaning.
- 35:05What are you doing?
- 35:06You're doing it wrong.
- 35:07And I think nowadays that's changed and everyone gets it's a real thing.
- 35:10But so for example, the hash of a union is independent of the order of the members of the union.
- 35:16That makes sense in the context of static typing, where the union of int float is exactly the
- 35:21same as a union of float int.
- 35:23It turns out in static typing, particularly when you're doing coercion, there are some cases
- 35:27where that is not the case.
- 35:28And so it's really difficult right now that effectively when you unions are fine on their
- 35:34own.
- 35:34But if you have a union, say within a string, the capital string square brackets, it will
- 35:40the order will be match the order that the first time you call that not what you actually call
- 35:45unless you use lowercase string when it is the right order, except there's a PR open right
- 35:49now to break it on string to string as well.
- 35:53So anyway, we are on lowercase lists as well.
- 35:58Anyway, so things like that, where I do think that we'll see what happens on that particular
- 36:02case.
- 36:02But I feel like the voice of people doing runtime use of types, we're not the only people, are
- 36:07being heard better.
- 36:08And yeah, I think things are going to continue to improve.
- 36:11Yeah, there was a PEP that proposed an optimization for typing that kind of broke the runtime behaviors
- 36:17of it a little bit for both of y'all.
- 36:18Yeah, it did in some edge cases.
- 36:20And that's going to be fixed soon by the successor PEP.
- 36:24Absolutely.
- 36:24So that's really good.
- 36:26Generic alias is another thing that kills us internally in Pydantic.
- 36:30I won't go into all of the details of it.
- 36:31But yeah, the high-level takeaway is that the typing community seemed happy with the idea
- 36:38that they might make a change to typing to make it easier for us.
- 36:41And I think that's also for the Pydantic team to engage better.
- 36:44And instead of spending ages...
- 36:46Problem is, right?
- 36:46You have a problem.
- 36:47You see a solution in typing.
- 36:49You submit the PR.
- 36:50Even if it gets accepted in a week, which it won't, you wait five years before we can
- 36:54remove the code that deals with the other case.
- 36:56So it's very tempting not to engage with typing, but just go and write the work around where
- 37:00we should be better Python citizens and go and submit the PR to see Python to try and fix
- 37:04it properly.
- 37:05Yeah.
- 37:05What's your wish list for typing?
- 37:07So, well, the first thing is like this thing that I have been trying to work on and like
- 37:11trying to do to have like better ways to do documentation of the APIs that's also related
- 37:15to typing and to the annotations.
- 37:17Like, let's see if I can pull it off.
- 37:19The other thing is like, it's actually not that necessarily that related to the things
- 37:23that we have been talking about, but it's quite relevant for the data science and machine
- 37:28learning community.
- 37:28That is that there are many, many APIs for many libraries that decorate in some way, some
- 37:35function.
- 37:36And then the function is expected to give some types of values to the body of the function
- 37:41internally, but to be able to receive different types of values.
- 37:45That sounds a bit abstract, but like that's the core idea that is like replicated across
- 37:51several libraries.
- 37:52And this will apply to, for example, to Ray, the distributed machine learning or computing
- 37:56system, to Dask, to, I think, Dagster also uses something like that.
- 38:00Monad, this system for deploying workloads and machine learning and things like that, also uses
- 38:06these types of ideas.
- 38:07So there are many of these libraries that like the way that they are designed is that you create
- 38:12some function and then you are going to tell something to call this function.
- 38:16And then in the function, you say, I want to expect this value.
- 38:19And instead of you calling all the functions that will generate that value, you tell it like,
- 38:23hey, distributed system, blah, blah, blah.
- 38:25Give me this value.
- 38:26Execute this for me.
- 38:27But that means that you will have or no type annotations or invalid type annotations or red
- 38:34squiggly lines in some places or no auto completion or auto completion for the wrong things, just
- 38:39because there's currently no way to define this specific thing of saying, hey, this function after
- 38:45being decorated is going to be able to receive a different type.
- 38:49Oh, yeah.
- 38:50Than what it's going to give to internal.
- 38:52So I think that's something that, and it's probably quite challenging and like a big thing to tackle,
- 38:57but it's something that is replicated across several libraries, in particular for these things
- 39:01that do distributed processing of data.
- 39:04I think that's something that will be great to improve.
- 39:07Does paramspec fix some of that?
- 39:10It's very close, but the paramspec only does it for being able to sort of copy the params
- 39:18that come from one function to another.
- 39:20And actually, I use all that for, for example, for async and for other things to be able to
- 39:24get like auto completion for the decorated function or for the generated function or things like
- 39:30that.
- 39:30And it will probably like the change will probably be somewhere around paramspec to
- 39:35be able to say like, not just the paramspec, but like this function will not only have the
- 39:40paramspec, but will receive a modification like this of the parameters.
- 39:45Almost making paramspec generic.
- 39:50All right.
- 39:50One more typing question.
- 39:52Do you all think typing is going too far with like the generic stuff?
- 39:56And is it going too much like C++ and C# and Java?
- 39:59Or is it, is it still, still good?
- 40:02I think it's, I think the way Python is growing is super interesting because like,
- 40:07we all have to agree that Python 3.12 is not the same Python 2.7.
- 40:12Yeah.
- 40:12It's quite different.
- 40:13And I think it's a different in a good way.
- 40:15The users are different and the light, the focus of the runtime is different.
- 40:20And like the things that we can do with types now, and like the fact that in Python, we can
- 40:26access these types at runtime, which means like, I don't know, I was always confused with the
- 40:31term runtime.
- 40:32It's like, what does that mean?
- 40:33And it's like, when you execute Python, the same Python code can inspect and like see what
- 40:38are those types.
- 40:39That's what FastAPI and Pydantic do.
- 40:40It's just like seeing like, what are those types?
- 40:42We can do that in Python.
- 40:43You cannot do that in things like TypeScript, or you cannot do it in Java.
- 40:48You cannot do it in many other languages.
- 40:49You get access to this typing information to be able to do additional things with that, like
- 40:53validation, data serialization, documentation, all that stuff.
- 40:56So I think that's, to start, that's super powerful in Python.
- 41:00The language in Python for typings is not as powerful as, for example, TypeScript.
- 41:06That is just like so much stuff that you can do with that.
- 41:09Nevertheless, I feel that in Python is just like, is growing and is growing organically.
- 41:14And like, we have growing pains, you know?
- 41:16Like, there are some things that is like, oh, this little thing here is slightly incorrectly
- 41:21named.
- 41:22Yeah.
- 41:23But like, now there's a better way to do that in Python 3.10.
- 41:26So we don't care much about that slightly incorrect name.
- 41:29Things like that.
- 41:30Yeah, I feel like there's some tensions of people who are in the mypy side, and they want
- 41:34perfect validation of, I want to prove my code hangs together like a static compiler.
- 41:39And folks like you all who are like, we want to leverage typing to make it behave in interesting
- 41:46ways.
- 41:46And maybe that behavior expression doesn't exactly match what it looks statically like, but
- 41:51it is.
- 41:52Everybody wants it, but it might trip up mypy.
- 41:55And I feel like there's this tension between those two things.
- 41:57That's kind of what I was thinking when I asked that question.
- 41:59I guess there's a little bit of that, but at the same time, there's, is much less than
- 42:04you could imagine.
- 42:05There are so many people that are so close to, you know, core mypy and these things that are
- 42:11actually very excited about the things that we are doing.
- 42:13So they're like, you know, like the, it's actually quite friendly, all the communication.
- 42:17It's just that there is some people that just don't really care about runtime types and
- 42:22that's fine.
- 42:22But like, I feel like it's much more, you know, much more closer together and like much more
- 42:28stronger the relationship, I think.
- 42:30Yeah.
- 42:30Yeah.
- 42:30That's great.
- 42:30Yeah.
- 42:31I think actually we've gone in the, we've, typing's got better for someone who's not
- 42:35like, it's actually got less verbose, cleaner, easier to understand.
- 42:38You don't have to import union.
- 42:40You can do pipe operator.
- 42:41You don't have to import list from typing.
- 42:44You can use list, which makes complete sense.
- 42:46Any is an unfortunate one, but I also understand why the any function might, it would not make
- 42:51sense.
- 42:52I give up.
- 42:52I just, I can't deal with this part.
- 42:54So yeah.
- 42:54No, in general, I think it's got much better.
- 42:57I do think that the interchange between runtime, so there's a PEP open now to add to data class
- 43:03transforms, a converter function.
- 43:06I forget exactly how it works, but I think that is awareness in the static typing space
- 43:11that data gets converted when you construct something that looks like a data class.
- 43:15So no, I think, I think it's really positive.
- 43:18I think we're incredibly lucky that we're like, I could say TypeScript is the other, is in some
- 43:23ways the best untyped language typing system.
- 43:25But the fact that they're not available at runtime means we're, we're killing it.
- 43:29I think I spoke to someone who maintains a library that does a type analysis at runtime in
- 43:35TypeScript and all his types are strings and like they're valid TypeScript, but they're
- 43:40strings.
- 43:40And that's, you know, he was saying that doesn't matter and it's all fine.
- 43:44I tend to feel like it probably does a bit.
- 43:46We're really lucky to have them at runtime.
- 43:48Then you go to the other end where I've been writing a lot of Rust.
- 43:51I am like, Rust's great.
- 43:52It has many advances, but if you want to just get something done and not have to,
- 43:55think too hard about what the types are, it's really nice.
- 43:58I write a lot of Python that's untyped when I'm just trying to get something to, something
- 44:01to work.
- 44:01I'm not a like, everything must have a type on it kind of person.
- 44:05So no, I think we're in a really great place.
- 44:06And I think most of the advantages are actually cleaning it up.
- 44:09So the new six something, 649, the new generics syntax to me, 695.
- 44:18There are people who know the names of their numbers of their peps and there's everyone
- 44:25everyone's saying.
- 44:26That for me, it cleans up generics, right?
- 44:30Yes, it's a fundamental change to the language.
- 44:32Yes, it makes the syntax of a function look a bit more like Rust or something.
- 44:36But like, if you look at it independently of our experience, it's a heck of a lot more elegant
- 44:41than importing type var.
- 44:42All right.
- 44:43Yeah.
- 44:43Yeah.
- 44:44Let me ask you one that's, this is purely theoretical because I don't think it'll get adopted,
- 44:48but we have int, pipe, none.
- 44:50We have optional of int.
- 44:51A lot of languages have question mark for nullable types.
- 44:55Like it'd be int.
- 44:56You could even say it like int.
- 44:57I'm not sure.
- 44:58Is it an int?
- 44:59It could be an int.
- 44:59It might be nullable.
- 45:00I don't know.
- 45:01Right?
- 45:01Or use int as an int.
- 45:03You just know.
- 45:03There's no question mark.
- 45:04And those types, what are your thoughts about null, call us, annual care?
- 45:08I'm really happy with the new situation and not having the optional that isn't optional.
- 45:12That's been a problem for a long time.
- 45:14So not needing to use optional is being able to use pipe none is great.
- 45:19I actually think one of the things that's going to happen with, particularly with the advent
- 45:23of the match syntax and with increased use of type dict, we're going to need a new union
- 45:29type that operates much more like an enum in Rust.
- 45:32So basically a union that keeps track of which member of the enum you have an instance of.
- 45:38I keep meaning to build a package to demonstrate what I mean.
- 45:40And I haven't got around to it, but like if you have a union.
- 45:44Type dict, which is a legitimate thing to do.
- 45:46It's effectively impossible without starting to do effectively validation to work out which
- 45:50member you're on.
- 45:51So I think we need, and it would be really neat if you could use a match expression to process
- 45:55each branch of your union.
- 45:57Sebastian?
- 45:57You already said everything.
- 45:58No, but like, you know, like I feel, I feel that way, I was saying that like, I feel
- 46:04Python is just like growing and like the typing system is growing.
- 46:08I feel it's growing in a very healthy way because it's not, you know, it's not like just some,
- 46:12some, some academics hidden in some corners somewhere saying like, this is how it should
- 46:17be done.
- 46:17I did my thesis on this type system and here we are.
- 46:19Yeah.
- 46:19And then like everyone should just use it.
- 46:21It's just like a lot of hearing everyone and just receiving the feedback from everyone
- 46:26and just like growing in the ways that it should grow.
- 46:29I think that's amazing.
- 46:30I think like we are, you know, it's like a kind of renaissance of like typing in Python
- 46:35and like how we can build all these things.
- 46:37I think that's amazing.
- 46:38I think it absolutely is.
- 46:39All right.
- 46:39I think we're pretty much out of time.
- 46:41We've used up all the various places we've escaped to at a shutting down conference here.
- 46:44Final question for you both.
- 46:46Just, you know, what's your big takeaway?
- 46:47What's the experience like here at PyCon?
- 46:49Like how's it been 2023?
- 46:51For me, it's been amazing.
- 46:52It's my first PyCon in the US.
- 46:55Oh, it is.
- 46:55Yeah.
- 46:55Like I have never been in a PyCon in the US.
- 46:57I have been in PyCons in like many other places, but not in the US.
- 47:00And like I got to see, I got to put faces to so many handles in Twitter and GitHub.
- 47:06I got to meet you in person.
- 47:08That's amazing.
- 47:09Wow.
- 47:09It's great.
- 47:09Like a bunch of other people that I only knew, you know, just like on the internet,
- 47:14a bunch of core developers and like, that's so cool.
- 47:16They are so cool.
- 47:16Like I knew they were super cool, but just like, you know, talking on Twitter and like
- 47:20didn't see me in person.
- 47:21That's amazing.
- 47:23It's my favorite part of the whole conference.
- 47:25It's just the people and the getting together.
- 47:27Definitely.
- 47:28I think I attended like two talks.
- 47:31I was just on the hallways talking to everyone.
- 47:34You feel the hallway track.
- 47:35Yeah.
- 47:35I was all the way on the hallway track.
- 47:38Awesome.
- 47:38Well, that's great.
- 47:38Yeah.
- 47:39I absolutely love it.
- 47:40I remember Sebastian and I joined the Language Summit remotely two years ago, the year when
- 47:44there was no PyCon.
- 47:44And the most interesting bit of the like four hours Zoom call was the five minutes between
- 47:49talks when people just chatted.
- 47:50And I remember then thinking how cool PyCon must be to have that same group of people
- 47:54like in a room rather than on a Zoom call.
- 47:57So no, I love it.
- 47:58I think it's, I've really enjoyed it.
- 48:00Last year was my first year.
- 48:01This year is even more fun.
- 48:03Yeah.
- 48:03I really enjoy it.
- 48:03Awesome.
- 48:04Yeah.
- 48:04It's been great to meet you both in person.
- 48:06Meeting you has been the best bit of all.
- 48:07Thank you very much.
- 48:08No, no.
- 48:08It's been really great to spend some time with you all here.
- 48:10Thanks for coming on the podcast.
- 48:12Part two now here to wrap things up.
- 48:14So it's, thanks for taking the time and congrats both on the success of your projects.
- 48:18They're amazing.
- 48:19Thanks so much.
- 48:20Thank you very much.
- 48:21Thanks for having us.
- 48:21Thanks for seeing us.
- 48:23Yeah.
- 48:23Bye guys.
- 48:24This has been another episode of Talk Python To Me.
- 48:26Thank you to our sponsors.
- 48:27Be sure to check out what they're offering.
- 48:29It really helps support the show.
- 48:30Take some stress out of your life.
- 48:32Get notified immediately about errors and performance issues in your web or mobile applications with
- 48:38Sentry.
- 48:38Just visit talkpython.fm/sentry and get started for free.
- 48:43And be sure to use the promo code talkpython, all one word.
- 48:46InfluxData encourages you to try InfluxDB.
- 48:49InfluxDB is a database purpose built for handling time series data
- 48:53at a massive scale for real-time analytics.
- 48:56Try it for free at talkpython.fm/InfluxDB.
- 49:00Want to level up your Python?
- 49:01We have one of the largest catalogs of Python video courses over at Talk Python.
- 49:05Our content ranges from true beginners to deeply advanced topics like memory and async.
- 49:10And best of all, there's not a subscription in sight.
- 49:13Check it out for yourself at training.talkpython.fm.
- 49:16Be sure to subscribe to the show, open your favorite podcast app, and search for Python.
- 49:20We should be right at the top.
- 49:22You can also find the iTunes feed at /itunes, the Google Play feed at /play,
- 49:26and the direct RSS feed at /rss on talkpython.fm.
- 49:31We're live streaming most of our recordings these days.
- 49:33If you want to be part of the show and have your comments featured on the air,
- 49:37be sure to subscribe to our YouTube channel at talkpython.fm/youtube.
- 49:41This is your host, Michael Kennedy.
- 49:43Thanks so much for listening.
- 49:44I really appreciate it.
- 49:45Now get out there and write some Python code.
- 49:47I'll see you next time.
- 49:48Bye.
- 49:48Bye.
- 49:48Bye.
- 49:48Bye.
- 49:49Bye.
- 49:50Bye.
- 49:50Bye.
- 49:50Bye.
- 49:51Bye.
- 49:52Bye.
- 49:52Bye.
- 49:52Bye.
- 49:53Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:54Bye.
- 49:55Bye.
- 49:55Bye.
- 49:55Bye.
- 49:55Bye.
- 49:56Bye.
- 49:57Bye.
- 49:58Bye.
- 49:59Bye.
- 50:00Bye.
- 50:01you
- 50:02you
- 50:02Thank you.