Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book


Transcript #223: Beware: A ninja is shadowing Sebastian from FastAPI

Return to episode page view on github
Recorded on Wednesday, Mar 3, 2021.

00:00 Hello and welcome to Python Bytes, where we deliver Python news and headlines directly to your earbuds.

00:05 This is episode 223, recorded March 3rd, 2021.

00:10 I'm Brian Okken.

00:11 I'm Michael Kennedy.

00:12 And I'm Sebastian Ramirez.

00:14 Cool, we did that without talking over the top.

00:16 Hey, we're getting good at this.

00:18 Welcome, Sebastian, great to see you.

00:20 Thank you very much for inviting me. It's a pleasure to be here with you.

00:23 All right, well, let's start it off.

00:26 Oh, I wanted to mention, we'll talk about them later, but thanks to Datadog for sponsoring this episode.

00:31 - Yeah, yeah.

00:32 And Sebastian, people maybe know you, but they definitely know your API framework, right?

00:38 - I hope so, at least some of them.

00:39 Yeah, should I say who I am or not yet?

00:44 - Yeah, yeah, sure, give us a quick little introduction and then we'll jump over to the items.

00:47 - Awesome, so hello everyone, I'm Sebastian Ramirez.

00:50 I'm the creator of FastAPI, which is a web API framework for Python based on type annotations.

00:58 That, yeah, well it has been used by quite a bunch of interesting organizations and products recently.

01:06 I'm a software developer at Explosion in Berlin, Germany, but I'm actually from Colombia, that's why the accent.

01:11 And yeah, that's about me.

01:12 - Fantastic, yeah, and you have the best mustache of anyone that's ever been on the show.

01:17 - Thank you very much.

01:18 - Definitely.

01:19 Well, let's jump in.

01:21 So I wanted to cover the Python Developer Survey 2020 results.

01:27 This is pretty exciting.

01:28 We'll get a little bit in a minute, talk about one of the things I wanted to talk about, of course, but let's look at it a little bit.

01:35 So the Python Developer Survey is put on by, it's the PSF, right?

01:42 Isn't it joint PSF and JetBrains?

01:44 - Yeah, I think it's put on by the PSF.

01:46 It's like hosted and analyzed by JetBrains, but it's not collected by JetBrains.

01:51 They make a point of not, you know, it's put on python.org and maybe even PyPI, but not on jetbrains.com.

01:58 So they try to not slant it in that regard.

02:01 - Yeah, so, but yeah, it's hard to, yeah, anyway, there's a whole bunch of cool stuff in here.

02:06 One of the things that, takeaways that I was confused by a little bit at first was the use, what do you use Python for?

02:13 And you've got a lot of reductions in percentages, but if you look at what increased, So you kind of see that people are using Python for more stuff, and it's spreading out.

02:23 So there's increases in education and in desktop apps.

02:28 Games increased quite a bit.

02:29 Mobile, which was interesting.

02:31 And other.

02:32 So the long tail has gotten fatter, and that's good.

02:36 We're using Python for a lot of stuff.

02:39 Another good sign is Python 3 is increased.

02:42 So last year we had 90% usage of Python 3.

02:45 Now it's up to 94%.

02:46 Not sure why it's not at 100% yet, but I think there's some probably some legacy stuff.

02:51 There's some some projects out there that are in the "please don't touch it, it's working, nobody knows how it works, just leave it alone" category, and it's probably that last 5% or so.

03:04 Yeah.

03:05 What are people using for environment isolation?

03:08 We've got virtualenv at 54%, but I assume that also includes VENV, or the built-in, - Yeah, I saw there was no mention of VNV, so just virtual ENV probably is that as well.

03:22 I had that same question, like, wait, surely somebody uses pip, you know, or Python-env, 'cause I answered that question.

03:30 - So we kind of use those interchangeably, so I guess that maybe that's what it is.

03:34 But one of the things that surprised me was that the, I've heard, I know a lot of people use Conda for data science stuff, that's at 22%, but 32% are just using Docker for isolation, which that surprised me.

03:47 That's an interesting thing.

03:48 - That's a hardcore isolation.

03:50 - Yeah.

03:51 Although I think more and more people are just using it all the time for a lot of stuff.

03:56 So I guess why not?

03:57 - Sebastian, what about you?

03:58 Are you a Poetry?

03:59 Are you a Python-M VNV?

04:01 Are you a Docker?

04:02 - I'm all over the place.

04:04 Actually, I'm quite a fan of Poetry and I think it's a great tool because it puts a lot of functionality in the same place, handling dependencies, handling environments, and handling binning versions.

04:18 When you add a new package with Poetry, it automatically detects what is the latest version and adds the right ranges of versions.

04:25 So I think that's very, very cool.

04:27 And creating a package with Poetry is super straightforward to create a package that can be later published directly.

04:34 So it's more similar to NPM in the Node.js world.

04:38 - Right, 'cause you can publish from it as well, right?

04:41 You can create the package and then publish.

04:42 - Yeah, and have all the configurations together.

04:44 But at the same time, I'm using vanilla Python VM in a bunch of projects at work and things, and a bunch of Docker as well.

04:53 So yeah, it's many different things.

04:56 I will think that for local development, it's always one type of virtual environment, being a VM for Poetry and then for deployment, sometimes it's just like pure Docker, sometimes Poetry inside of Docker, but not even using the virtual environment.

05:11 But yeah, I would think Docker for deployment and then locally virtual environments, at least for me.

05:17 - Yeah, and that was the majority.

05:18 I think most people are primarily using VNV for that, but I can't remember exactly.

05:23 Hey, Brian, quick comment.

05:24 - Yeah, what's that?

05:25 - Is VNV versus virtual ENV a Python 2 versus 3 thing?

05:30 - Oh, yeah, I guess maybe it is.

05:32 - I think, you know, VNV was added, I believe in Python 3, but, and I had kind of forgotten about virtualenv, but there's some interesting stuff.

05:40 I think we covered it a while ago, the release of version 20, 'cause it actually does a lot of interesting stuff.

05:45 And then Magnuson has a comment on Poetry, uses it to create the virtual environment manually into, in order to use --prompt, which is, so it's not called venv when your prompt changes, but project name in parentheses when your project changes, which is the question Gandalf had.

06:03 And then Dean is a fan of the virtual ENV wrapper as well.

06:07 So awesome.

06:08 Yeah, I haven't either.

06:10 I feel like this is one of the areas where there's just so many different ways people are doing this stuff.

06:16 But yeah, with our special guest here, Brian, but how about you touch on this one?

06:20 This is big news here.

06:21 - Yeah, so this is big news.

06:23 So frameworks and libraries under web frameworks, We've got Flask at 46%, Django at 43, and then, dun dun dun, FastAPI at 12%.

06:33 It's the first time it was on the survey, and it's already up at number three, so.

06:37 - Whoa. - Yeah.

06:39 Way to go.

06:40 The growth is super, super interesting there, and yeah, congratulations, Sebastian.

06:44 And I actually think that this is gonna grow quite a bit more.

06:47 If you look at the first derivative, it's higher for the numbers for FastAPI, like the rate of growth, or just the growth.

06:56 Also, I feel like a lot of people are not necessarily leveraging, I mean, I'd like to hear your thoughts on this, Sebastian, leveraging FastAPI's ability to deliver HTML as well.

07:07 - Yeah, absolutely, because if you're rendering HTML in the back end, the benefits of FastAPI are not as obvious.

07:15 So I guess people probably will use it more for APIs, but then there's actually a bunch of people using it for very different stuff than what I initially thought of.

07:29 - Yeah, yeah.

07:29 Yeah, I think you can basically get down to the Starlet type features and stuff, and then you can build an equivalent of Flask or Django.

07:37 And what I think's interesting about that is a lot of people are like, well, I could do this really cool API with FastAPI, and then do we use Flask or Django for the web part?

07:44 It's like, well, if you've already got the FastAPI part and you've got like 10 pages you wanna serve, just don't juggle two apps, just put them together.

07:52 It's actually not that hard.

07:53 I think there's some really interesting stuff.

07:55 And I think as people learn those and leverage those, it's only gonna grow because they're like, oh, I actually don't have to have Flask plus FastAPI, I could just have FastAPI.

08:03 - Yeah, and I think-- - Not that Flask is bad, but yeah.

08:05 - Yeah, of course, and like, FastAPI is actually, FastAPI owes and was inspired a lot by all of these frameworks that paved the way.

08:14 Like, all of these designs, all of these ideas came before FastAPI.

08:18 FastAPI just putting them together with the new type annotations from modern Python to Dialect.

08:24 It's all the work that has been done by a lot of people.

08:28 - Yeah, yeah, standing on the shoulders of giants type thing.

08:31 - Exactly, exactly.

08:32 - Yeah, yeah, awesome.

08:33 - But yeah, people are using it more.

08:34 - I've got some stuff to add to that as well for my next item, by the way.

08:37 - Oh, cool. - Nice.

08:38 - Yeah.

08:38 - No, before we move on, one of the things in the survey that was interesting to me was the use of continuous integration.

08:46 So I use CI or continuous integration all the time, but one of the, see if I can find it.

08:52 See, the CI systems in use, GitLab was top, which was interesting to me.

08:59 I mean, I use GitLab at work, but I use GitHub, or I use, I guess, GitLab CI, but I'm using GitHub Actions a lot, and I don't see GitHub Actions even here.

09:08 So I wonder if it just wasn't listed, or I'm not sure.

09:11 - That's quite interesting.

09:12 Yeah, I have noticed that GitHub Actions is not there.

09:15 - Yeah, I expected to see it as well, yeah.

09:17 But what I did not see, I just want to throw this out, like well done on building the survey.

09:21 'Cause what I didn't see is what platform are you on?

09:23 Do you use Python or do you use SQL or do you use Vue.js?

09:28 Like they did a good job of comparing apples to apples in this one.

09:33 And that was nice.

09:34 - Yeah.

09:35 - Yeah, I guess, but like, I guess what you brought up before on the web frameworks though, the like why, I mean, it depends on what you're using the web for.

09:45 So like the early use of FastAPI was just APIs.

09:50 So I don't know, that's not Apple's.

09:52 - Right, you may be doing Flask plus FastAPI.

09:55 - Yeah. - Yeah.

09:56 - And the survey allows that.

09:58 You can, if you add these numbers up, they are over a hundred.

10:02 I wanted to bring up one more thing.

10:04 I guess unit testing is at 49% for pytest.

10:07 So pytest is in the lead.

10:09 - Yeah, I also saw there's a really interesting number two in that list there.

10:13 - 28% of using unit test, yeah.

10:16 - No, that's not the one I was thinking of.

10:17 That's number three.

10:18 - Oh, was it number three?

10:19 - Number two is none. - Oh, number two.

10:21 - Number two is, so you know in Python, like a lot of languages have null or nil, but apparently people just like do stuff with the none type to test here a lot, so.

10:31 (laughing)

10:34 - None testing.

10:35 - Yeah. - Oh yeah, that is number two.

10:37 - Yeah, it's crushing it.

10:38 Yeah, none is pretty, I mean, you do get a lot of exceptions and it's easy to like fail first And then, yeah, anyway.

10:44 - So I gotta talk to--

10:44 - None type has no attributes, such and such.

10:46 - I gotta talk to the PSF and JetBrains about this because I'm not sure why they call it unit testing frameworks.

10:53 We gotta drop the unit off there.

10:56 Just call them testing frameworks.

10:57 - Yeah.

10:58 Brian, I hope you don't mind.

10:59 I'm considering writing a book on this new none framework, by the way.

11:02 - I think you should.

11:04 That would be funny.

11:06 - Actually, I--

11:07 (laughing)

11:08 - As soon as it's done.

11:09 - Yeah, it's really short.

11:11 It's really, really short.

11:12 (laughing)

11:13 All right, probably one page book, okay.

11:16 All right, next item, I gotta keep moving along or we're gonna have a two hour show here, is I like ninjas, do you like ninjas, guys?

11:22 Ninjas are cool.

11:23 - Oh yeah, well I mean I don't know any, but.

11:25 - Well, I mean, if you are a ninja, you can't really speak about it because it's something about the secrecy.

11:30 Anyway, Sebastian was just talking about how FastAPI was inspired by many of the frameworks that were on there, and there's a cool framework called Django Ninja, Fast Django REST Framework, And I'm not a super expert in Django, but I think Django REST framework has been primarily the way to do APIs in Django these days and to layer that on.

11:49 And if you look at the very bottom of this, there's a little bit here that says, "This project was heavily inspired by FastAPI "developed by some guy named Sebastian." So that's pretty cool.

11:59 Have you checked this out, Sebastian?

12:00 - I have seen it, and actually the author was quite active in the FastAPI community.

12:05 But yeah, I haven't been able to play around with the framework itself.

12:10 Yeah, like I think it could be a very nice idea and a very nice middle ground for people that is already having a lot of work, already a lot of code with Django REST framework.

12:21 - Yeah, exactly, exactly.

12:23 So this was sent over by Marcus Sharp and Adam Perkin who goes by Codependent Coder independently.

12:29 So thank you both for sending this in.

12:31 And the idea is that it's a framework for building APIs primarily based on type hints, but also with async support.

12:38 And it makes use of Pydantic.

12:40 And those are many of the important ingredients that make FastAPI special as well.

12:44 So some of the key features are, it's pretty easy to work with.

12:48 It has a similar feel as FastAPI.

12:51 It's high performance, partly because of PyDantic, partly because it has native async support, and partly just because they did a good job there.

12:58 Also fast to code.

13:00 The type hints let you know what you're working with and automatically get conversions along with PyDantic, of course, does massive levels of like validation and conversion.

13:09 And it also has automatic docs with open API, formerly known as Swagger, similar to FastAPI in that regard.

13:16 And the reason this is interesting, I think, is because it's Django friendly.

13:20 So it has integration with Django Core, it has integration with Django ORM.

13:24 So if you're already got all of your stuff done in Django, and you were thinking, well, I really wanna have this style of API that FastAPI brings, but I don't wanna leave Django, I don't wanna have to rewrite everything in SQLAlchemy and learn the async API over there, and that kind of stuff.

13:40 Well, here's a way to kind of like layer on APIs to your Django app, but in the Zen of what Sebastian.

13:46 So yeah, I think it's pretty cool.

13:47 And if you check out the performance here, you can see it's slightly faster in the single threaded version, but once you bust out async and await and it starts just crushing it.

13:58 So here you can see like with 50 operations, 50 workers and so on.

14:02 And what's really interesting is you see like this graph at the bottom of, as you add more workers, things like Django rest framework or flask marshmallow start to catch up.

14:10 And my theory, looking at this graph, my intuition is what this means is the thing that it's talking to and the backend, like the database that it was talking to or something like that is starting to like not be able to take it anymore or the, the overall CPU level is just starting to like to hit a limit where it can't scale.

14:30 Cause it's really interesting that it's kind of just like linear number of things for flat for the Django Ninja.

14:36 And as the scale increases, it kind of gets its normalized on that.

14:40 So it would be flat, but anyway, it's a pretty interesting graph, I think there.

14:43 - Yeah.

14:44 - Yeah, and then last thing, just a super quick example of here is, all you gotta do is create a Ninja, API Ninja, and then you do an API.get, give it a URL.

14:53 You give it some parameters.

14:55 Those parameters have types like a colon int, b colon int, and then you return a dictionary and off you go.

15:00 And then you've got an API And presumably you could make this async def add, although there's really no reason to do it.

15:08 You could, right?

15:09 'Cause it supports async.

15:10 Anyway, I think this is a pretty cool thing for people already doing Django.

15:13 And like we have so much logic in the ORM and in the other parts of our app, we just wanna add in this style of API.

15:20 I think this is neat.

15:21 - Absolutely.

15:22 - Yeah, cool, cool.

15:23 All right, well, let's see.

15:24 What's your first item, Sebastian?

15:27 - So I have Pydantic 1.8 was released.

15:31 It was released one or two weeks ago.

15:34 It's the latest version.

15:35 And it has a bunch of interesting things.

15:37 It has a hypothesis plugin for doing property-based testing, which I haven't been able to try out yet a lot.

15:48 But I have heard a lot of good things about this idea of property-based testing.

15:53 And in fact, there's a package for doing this type of testing, integrating hypothesis with OpenAPI, so you can test like it was made to test FastAPI actually with these ideas.

16:05 But then now there's an integrated plugin in PyDantic.

16:09 So I think that can be quite interesting.

16:12 And also there's now support in PyDantic directly for name tuples and for type dicts.

16:18 So type dicts are these new types or type declarations to say what is the shape of a dictionary inside of Python.

16:27 If you have played with TypeScript, will be comparable to an interface, or I guess, you know, languages too.

16:34 But then these type dicts, the thing is that they are the official or standard way inside of Python, that are part of Python to define the types of dictionaries.

16:46 Because Pydantic is actually a class.

16:48 So this could be, I think these type dicts will be interesting, for example, for declaring the parameters of a function that are actually a dictionary, and declaring where the types that that dictionary should take, things like that.

17:02 And I will expect editors to be able to have support for that.

17:06 So imagine that you are passing a parameter to a dictionary--

17:10 sorry, a parameter to a function.

17:12 And the parameter is a dictionary.

17:13 And then the editor can give you completion for the dictionary inside of the parameter that you're passing, or the argument that you're passing to the function.

17:22 Things like that, I think, type dicts will help a lot.

17:24 And then now you can use them inside of Bidantic models.

17:27 and I think that's pretty cool.

17:28 And this other one is the Pydantic has support for annotated types, which is another of these types.

17:36 So annotated is one of these things that you import from typing, the same way that you will import a optional or that you will import a union or that you will import the type for lists.

17:49 - This is cool.

17:50 I was wondering how you would do stuff like this.

17:52 If you could say add a default value to a Pydantic model or to add simple constraints along with default values.

18:00 - With Pydantic and with FastAPI, you have a way to declare, before annotated existed, you had a way to declare those things by setting the default value as a call to Pydantic's field, which is a special function.

18:16 Or in FastAPI, you could call, for example, the function query, which is a special function that returns a special object that has all the information, including metadata for validation, and maybe like the title or the description of their specific parameter, things like that.

18:31 But then the issue with that approach is that we are taking the place in the declaration of the parameter inside of the function.

18:40 We are taking the place that will be used by the default value.

18:44 And we are like playing around with that default value inside of the function signature, inside of the function declaration of parameters.

18:53 So it's actually not like the most correct way to do it.

18:56 It's kind of intuitive and it works quite well with Pydantic and FastAPI, but in terms of types, it's not very explicit.

19:05 And now with these new annotated type, you can put the actual type that the parameter has, like let's say it's a string, and then you can also put the extra metadata that will go for Pydantic or for FastAPI inside of the same annotated generic type is the name.

19:25 So the same way that you will put, let's say, annotate a type that is additional, that has strings as keys, and then as values it has integers, then instead of that, you will put this annotated thing and declare the type of the parameter, and this extra metadata that will include like validation and a bunch of things, and then the default value can be kept for the actual default value of the parameter.

19:50 So that could be very useful, especially if you are calling the same functions, for example, for FastAPI dependencies, and you're calling the same functions in other places.

20:00 And I think that can be very powerful, and very useful for reusing code in even more places.

20:07 - Yeah, when I first looked at this, I thought it was this annotated thing, was the value you were setting, like SQLAlchemy would be, or Django ORM or something, where you say like name equals an annotated thing, but that's actually the type, it's name colon, this really interesting annotated thing with lots of constraints equals some potential default value or equals nothing, right?

20:26 You just don't even have to set a value.

20:28 - Yeah, yeah, I don't know.

20:30 I feel the syntax might look a little bit weird.

20:33 It's not necessarily like the most intuitive, but it's like the most correct at the same time.

20:40 So in cases where like this strict type correctness is important, I think this could be quite useful.

20:48 - Yeah, so another thing that I, this is not in the new release, but I'd like to hear your thoughts on it.

20:53 What is it called, validation?

20:55 Is that what it's?

20:57 There's a type with like runtime validation.

21:00 I think this thing here is you say at validate arguments.

21:04 Have you seen this for actually going, instead of just suggesting that it's a string and an integer, it'll actually make sure that it's a string and an integer at runtime.

21:13 Have you played with this?

21:14 What are your thoughts?

21:15 - I haven't played with it.

21:16 Like I remember when Samuel Komold was talking about it and it was super exciting because it's also a very, it's the same idea of what FastAPI is doing or similarly what Typer, which is like the equivalent of FastAPI for building command line applications.

21:32 The equivalent of what they do, which is take a signature in the, take the parameters from the function and use those parameters to do validation.

21:42 I think that's very interesting and very powerful.

21:45 I just haven't used it yet because I use PyDantic most of the time with FastAPI, and in FastAPI there's no need to add the specific decorator because FastAPI is already doing that.

21:56 But for other use cases where it's not really using FastAPI but just PyDantic standalone because PyDantic is awesome by itself, I think this will be very, very powerful.

22:07 - Yeah, yeah, totally agree.

22:08 Okay, cool.

22:09 Anything else you wanna add on this before we move on?

22:10 I kick it back to Brian.

22:11 - No, I think that was the highlight I had.

22:16 Just I think it's pretty cool.

22:16 - Well, we brushed by this quickly, but I was curious, not about this, but you mentioned a FastAPI does validation.

22:24 Just we went by that quickly, but is that true?

22:26 Can you, for FastAPI, can I say that this data or this data point that's coming in has to be in a certain range of integers or something like that?

22:35 - Absolutely.

22:36 All the validations that you can do with Pydantic, you can do them with FastAPI.

22:41 And it's actually quite extensive, the things that you can do.

22:46 You can say that you want to validate against a regular expression, or that you want to have a minimum number and a maximum number, or that you want to have--

22:54 I don't know.

22:55 You could even write custom types of validations for the things that you receive.

23:00 And because Pydantic is based on the same standard Python type annotations, you could do these validations even for deeply nested data structures.

23:08 You can say, my request of this endpoint is going to receive a list that contains dictionaries, that inside contain this key tag that contains the strings, and this other one that has sub dictionaries and sub lists, and a very complex deeply nested tree of data, and you can declare all that and have all that validated.

23:31 >> That's awesome.

23:32 >> When your code executes, when the code that you wrote executes, it's fastAPI already took care of making sure that the data that you deter is the data that you receive.

23:42 Your code will never execute with invalid data.

23:46 That's it, that's it, yeah, yeah.

23:47 - It's so nice in that regard.

23:49 You just like, by the time it gets here, I know it's all been converted and validated at least as much as the model is gonna validate it for me.

23:55 You don't have to worry about that.

23:57 So it's great to push that to somewhere else.

23:59 - Yeah, and on the other side, because which is also a great feature of Pydantic, validation shows the errors exactly in the place where they are.

24:10 And when you get that is like, yes, I can see exactly where is my data wrong.

24:16 So you can see which index in the list was incorrect.

24:19 And inside of that index, which key was incorrect.

24:22 And inside of that, what was the exact error and see like, oh, I had to put a string in another object here.

24:28 Not a JSON object.

24:29 - And what you mean is like, if I have a PyDendic model and it says it has a list of customers and there's three customers in the list, but the third customer that was submitted as part of the JSON body has an error.

24:40 It'll say in the customers in index three on this field is the problem.

24:45 Not just the name is required.

24:47 Like, oh great, what does this mean?

24:49 Right?

24:50 - Exactly, I don't know how you do to make these examples out of the book and understand them all at the same time.

24:57 It's so difficult.

24:58 (laughing)

24:59 That's such a skill.

25:01 - Yeah, we've been doing it for 223 episodes, I guess.

25:05 (laughing)

25:06 - Nice. - All right, Brian?

25:08 - Yeah, so something else that's awesome is Datadog.

25:11 So this episode of Python Bytes is brought to you by Datadog.

25:14 Are you having trouble visualizing latency, CPU, and memory bottlenecks in your app and not sure where the issue's coming from or how to solve it?

25:22 Well, Datadog seamlessly correlates logs and traces at the level of individual requests, allowing you to quickly troubleshoot your Python application.

25:31 Plus their continuous profiler allows you to find the most resource consuming parts in your production code all the time at scale, at any scale with minimal overhead.

25:40 Be the hero that got the app back on track at your company.

25:43 Get started today with a free trial at pythonbytes.fm/datadog or just click the link in your podcast player show notes.

25:50 Yes, check out our show notes and thank you Datadog.

25:53 - Yeah, thanks Datadog and get a cool little Datadog t-shirt as well.

25:57 Speaking of cool, let me talk about the next item here.

26:00 I guess I'm next up on this, on the list here.

26:02 So this item comes to us partially from Will Shanks.

26:06 He sent me the Python side, but I wanted to highlight this sort of broader thing because I think it's pretty interesting.

26:12 The first part, well, let me just tell you the title of the article, the piece of news is Google and Microsoft back Python and Rust programming languages.

26:19 And they both, I believe do stuff with each, but it's primarily Google backs Python, Microsoft backs Rust, but the overall trend is part of the story that I think is interesting.

26:30 So they both come along to make significant contributions to the various languages.

26:36 And part of the trade-off I believe there is that they'll have some say or some ability to influence where the direction of these projects are going.

26:45 Like, hey, for example, Google donated $350,000 or it's not quite the right way to put it.

26:51 That's what the article says.

26:52 Google sponsored the PSF at the visionary sponsor level which has a price tag of $350,000.

27:00 And the goal is, this is the first company to do so, by the way.

27:04 And so they're investing in improved IPI malware detection and better foundational tools and services like pip type of things and so on.

27:13 And they're hiring a CPython developer in residence for 2021.

27:17 I don't know if that position is still open or if there's applications, but anyway, I think that's pretty awesome.

27:22 So yeah, I'm really happy for this.

27:26 I do feel like there's a hundred other companies that should be doing the same thing.

27:30 You know, Bank of America, hello?

27:32 5,000 people working on a Python project there.

27:36 5,000 Python developers, surely some of their wellbeing depends on the wellbeing of Python.

27:40 And you know, banks and places like that have at least $300,000 to spend on IT per year, I'm pretty sure.

27:46 - You know what I find funny about that?

27:49 That, you know, like these huge companies, these huge corporations, they are depending on Python and all this stuff.

27:56 And they, for example, they are for sure running Python in CI and pip install a bunch of things.

28:03 They are probably having some issues with the new resolver and pip install and taking a bunch of time and having a lot of time by their developers waiting for their solver to handle things.

28:15 And the resolver is having to download all the packages that match some range to be able to extract the metadata to be able to compute and to be able to do all the backtracking and all that stuff.

28:27 And if the PSF was better funded, they already have the feature request and they already have the idea and the objective to include the metadata of those packages in PyPI so that people could ask the API, what are the versions, instead of downloading all the packages.

28:47 So it's like--

28:49 - That seems more efficient, like a 100 byte JSON document instead of megs of packages.

28:55 - Exactly, and it's just like, you know, like it will probably just be like a little funding, just, I don't know, a couple of full-time developers working a lot more on that than a lot of volunteering and like, yeah, like I feel if it was better funded, they will save a ton of money and time spent by their developers if the whole PSF was performance.

29:24 - Absolutely.

29:25 I mean, that's just one small example, right?

29:27 - Yeah, yeah.

29:28 - Another one is maybe we want higher performance.

29:30 Like the survey that Brian covered was one of the top requested features was better performance.

29:36 Well, if we had 20 companies each donate a million dollars, I bet we could get a pretty awesome JIT built.

29:42 Or something like that, right?

29:44 I mean, there's clear links back to the well-being.

29:48 So anyway, awesome Google and Microsoft as well for the Rust side of things.

29:53 - Absolutely.

29:54 - But it's, I think part of the story is that this is a story, you know?

29:59 Like that this is big news, it's awesome, but it should be like, oh yeah, and the other 20, or the other 100 companies, right?

30:06 - Yeah.

30:06 - So the people that listen to, I mean, Microsoft and Google know that they use Python and Rust.

30:13 But I think there's a lot of people listening to this podcast that know there's a need there, but they're just engineers, and there's the people at the top of the company really might not know how much their company depends on these languages.

30:26 And so I actually, nice, I actually would like to, I'd like to have some sort of how to start that conversation document.

30:35 Something like, if I'm at a company, how do I start that conversation with my leaders to say how, you know, how do I talk to that?

30:45 To say, hey, we use Python a lot, can we contribute to the PSO?

30:49 - Yeah, I spoke to, I think it was Peter Yang about this.

30:53 No, sorry, Peter Wing from Anaconda.

30:56 And he has such a good insight and ideas on this whole topic.

31:01 One of the challenges is, I think it was he, him who said this, like they don't have, there's not a place on a profits and loss accounting system for charity.

31:12 There's a place for sponsorship where you get something back.

31:15 There's a place for advertising.

31:16 There's a place for IT.

31:18 but just charity alone doesn't quite work.

31:20 So I don't know, I think that's part of the story is like kind of got to fit into that world where like, well, we could support it.

31:26 And in this sense that we've been talking about, yeah, you'll get something back, but we need a tangible, we get something back.

31:31 I don't know what that is, but I think there's a little bit of a mismatch there.

31:35 Anyway, just a couple of shout outs to some more.

31:37 We got Salesforce, we got Fastly, Bloomberg, Azure, Microsoft, Capital One, you'll even find TalkByThon training down near the bottom of that list, sponsoring the PSF over there.

31:47 That's cool.

31:48 But also just to round this out, Microsoft is doing interesting stuff with Rust around using it to basically replace where they're using C and low level stuff like that.

31:58 So they've joined Mozilla, AWS, Huawei, and Google as founding members of the Rust Foundation as well.

32:05 And I think they donated something.

32:07 And I don't know the numbers there, what that means.

32:09 But anyway, thanks Will Shanks for sending that over and thank you Google and Microsoft and other companies we gave a shout out to for supporting these projects and communities.

32:17 - Semantic versions, let's talk about that.

32:19 So yeah, so I actually don't know if FastAPI is using SemVer or CalVer.

32:26 Sebastian, what do you got?

32:27 - I think FastAPI will match in what Henrik describes as the YOLO zone in that article.

32:36 - Okay, so what version are you on?

32:39 - So it's 0.something.

32:41 The thing is that I'm managing it as if it was like very strict same version where I'm handling the bumps in the versions, but it's all zero point something still.

32:56 Because I want to add some features and do some, the freedom to do some changes to the API to have like the best design possible.

33:05 Also because I want to release the one version after Ubicorn and Starlet have the one version.

33:12 Yeah, I think he's right.

33:15 - So yeah, so what we're talking about is an article from Hinnick saying semantic versioning will not save you.

33:22 So the idea with semantic, with versions is you've got like a three digit number and there's a major, minor, micro.

33:33 And the idea is if the, as long as the major number doesn't change and you're using this package or this library or this tool, it's not gonna break you if it goes up.

33:44 So if you go from 1.9 to 1.10, you can upgrade, it's fine, and nothing will break.

33:51 But there's a whole bunch of problems with that.

33:55 For one, that implication is just, it's not really true all the time.

34:01 You don't really know, it's often there's no new features, but there'll be something fixes, there'll be fixes and things, and you might actually depend on the broken behaviors.

34:09 So there's, in practice, you can't really just upgrade willy-nilly.

34:14 So in practice, you have to be, like if you're depending on a package and it changes its version, you have to test and have good coverage for your own code to start with.

34:24 And you should pin your dependencies so you don't just automatically update to the newest one.

34:29 But you should also try to regularly keep updated to the new changes.

34:34 And you have to do it in a try and a try basis.

34:38 So you like update the new version and then try it and run your tests.

34:43 And if they pass, then repin the new versions.

34:45 And if they don't pass, well, you've got to have to either, you know, in below it or block that version or something.

34:54 There are messy things that happen.

34:56 - Yeah, and it's getting more complicated with the new resolver.

34:58 Like if you say, I must have, you know, pedantic below some version and then FastAPI comes along and says, I must have pedantic above a higher version.

35:06 well, whatever that other thing needed can't be used with FastAV.

35:08 Like there's these intervals that no longer intersect that can become challenging.

35:12 >> Yes. Let's say you've got an application, your end application, you're the only user of it or other people are, but nobody's importing it.

35:21 Then you can pin directly all of your dependencies and you can test it and it's great.

35:25 But if you're a library and somebody is going to import you, you can't really just actually just pin everything because somebody might, like, let's say I'm pulling in requests.

35:38 Somebody else might be pulling in me and requests.

35:42 So you pinning it hardcore is, you're like you said, with the dependency manager or the dependency resolver, that'll break.

35:50 So you've got to be a little bit broad so that these overlaps happen.

35:55 But okay, so the consequences of this just nightmare is mayhem and version conflicts, like we described.

36:02 Let's say my package says I have to have request something and somebody else X and somebody else says, oh, well I need to request version Y in mine.

36:11 And that's just gonna be a mess.

36:13 So all of these promises, the other subheading for the promises for SemVer is that if you're on zero at the beginning, you can change it all you want.

36:25 So there's no promises on zero over.

36:27 If it's zero dot something, all bets are off.

36:30 You can change the API.

36:31 You can completely break things.

36:33 You can completely change the API.

36:35 So nothing before work.

36:38 And in practice, that doesn't happen, but there are times where in the, there's a lot of people are stuck in the zero-ver, but you, in reality, the first few releases really are up in the air.

36:53 You're not sure what's gonna work and what's gonna not work.

36:56 But after a while, zero-ver just starts to be just there.

37:00 and you really should have been at one because everybody's using it.

37:04 But anyway, so.

37:06 - Yeah, and we covered that whole thing, I think it was Mamutush, I mean, I can't remember about the whole zero over thing.

37:11 - Yeah.

37:12 - And calling places out.

37:14 Yeah, I mean, it's fine to have it, but like some of these projects had been out for 15 years and they're still zero dot something, right?

37:20 - Yeah, like React was used by everyone before they released the first one beta.

37:25 - Exactly, exactly, interesting, yeah.

37:28 - You know, it's quite fun that, I don't know, some months ago, I updated a little bit, a little piece in FastAPI of some corner case that I had for some specific workaround for SQLAlchemy that didn't import SQLAlchemy but excluded so much with some little thing over there.

37:47 And it was like deprecated, not used in the latest versions and not anything, and I just removed it because it was there for a long time.

37:56 And hell break loose.

37:57 I have an issue that had like, I don't know, tens of thumbs up.

38:05 I tracked the issue connected to the repository and Netflix that was using FastAPI for the, yeah.

38:14 Anyway, I had to release something quickly to get the book back because people were already depending on that.

38:21 And it's like, yeah.

38:22 - Yeah, well you have this problem that you have so many consumers of, I mean, 12% of all web frameworks are FastAPI at the moment.

38:30 That's a lot of people using your library, touching the corners.

38:33 - Yeah, absolutely.

38:35 - Yeah.

38:35 - So the last thing I wanted to touch on with this is I do like Hennig's instructions on what you should do about this, of testing.

38:43 But one of the things that we didn't bring up yet so far is if you test something against an update and it doesn't work, it might not be an intentional break in the API or the behavior.

38:54 look into it and maybe notify the maintainers that you are depending on some behavior that it broke.

39:01 - Almost all the stuff is on GitHub and you can file an issue potentially or something like that.

39:06 - And don't just get mad.

39:07 People didn't break you on purpose, so be nice.

39:11 - That is a start out with a generosity in your thought.

39:15 So there's a whole bunch of comments in the live stream.

39:16 Thank you.

39:17 I'm gonna just try to circle back on a few things.

39:19 One, Magnus asks, how do you say or talk about verbally the square brackets in PyDentic or even typing just iterable, square bracket, int, bracket.

39:28 I've always said interval of int, just like you would use for generics or templates in C++, like iterable of int.

39:35 I don't know, what do you guys say?

39:36 - I have no idea.

39:38 I will ask Ivan Levinsky or maybe Luca Lange could say like, what is the actual term?

39:44 I think it's one of those down there that doesn't have a name yet.

39:47 I don't know.

39:48 - Yeah, yeah.

39:49 And then Dean has an interesting comment on versioning, Brian.

39:54 Talking about versioning.

39:55 Why is Brian not updating his Chrome?

39:56 There's a big update button right there.

39:59 And then this one for you, Sebastian.

40:01 Although I believe we touched on this RJL a little bit ago.

40:05 Any chance to ask a FastAPI question?

40:07 Will it ever become a web server like Django or Flask more than API engine?

40:11 Yeah, absolutely.

40:12 - So the FastAPI, you can use, you can do everything that you can do with Flask or Django with FastAPI.

40:20 you can render Jinja templates in the backend if you want.

40:23 FastAPI will not include an ORM by default because that will compromise on tying it to a database and to a type of database.

40:33 - Well, Flask doesn't as well, right?

40:35 Like Flask says, go pick Mongo.

40:37 - You're right, you're right.

40:38 - Go pick SQLAlchemy, something like that.

40:40 - You're right.

40:41 Actually, I don't know, comparing to Flask, FastAPI will be pretty much comparable, I think.

40:47 - I think it's super comparable.

40:48 And I also, I created the decorators that you can put on the templates to, on the API endpoints.

40:56 They have like a chameleon template or a flat, sorry, Jinja2 template.

41:00 And then, yeah, I'm actually working on a course.

41:02 I haven't told you, Sebastian.

41:03 The course I'm gonna release is building proper web apps with FastAPI plus APIs, like sort of factoring that stuff in and like doing forums and stuff like that.

41:12 - Nice, that's very cool.

41:14 - Yeah, it'll be fun.

41:15 Yeah, all right, so cool.

41:16 RJL likes the ORM news.

41:19 Yeah, you can pick that.

41:20 And then also, Sebastian, you had such a good tweet a while ago, and Robert Robinson wants to just touch on that.

41:26 When will it be possible to have four years of experience with FastAPIs, as companies are still yearning for it?

41:32 Tell people about your tweet.

41:33 (Robert laughs)

41:34 - You know, it's fun that I tweeted something, for those that maybe probably didn't see it.

41:39 I tweeted something half a year ago, and it was saying, "I saw a job post requiring four plus years of experience of FastAPI.

41:48 I couldn't apply because I only have 1.5 years of experience since I created the thing.

41:53 So maybe it's time to reevaluate the experience is equal to skillset.

42:00 But a bunch of people seem to have learned it because they tweeted it like crazy.

42:06 My Twitter app broke.

42:09 And now recently, I don't know why they started with tweeting it again.

42:13 I'm sharing screenshots of it on LinkedIn and tagging me.

42:18 By this point, I have two years of experience with FastAPI.

42:22 So that is no longer true.

42:24 - So now it'll be like 20, what, 2023?

42:28 - Yeah, 2023, these things will be legit.

42:30 Then you could apply for that job, that'd be fantastic.

42:32 - Yeah. - Show us what you want.

42:33 - I will get a job there, hey.

42:35 - All right, we're getting long in the show, so maybe our next two items should be kind of short, but Sebastian, the next one's yours.

42:41 - Yeah, this will be short.

42:42 OpenAPI 3.1.0 was released recently.

42:47 FastAPI is based on OpenAPI, so it's important for FastAPI and for whoever are using FastAPI.

42:54 OpenAPI 3.1.0 doesn't change much.

42:57 It adds more compatibility underneath.

43:00 So now it's based on the latest version of JSON schema, which means that if you do things like, for example, automatic react components based on JSON schema, now they will be able to share the same schema as OpenAPI.

43:14 The previous OpenAPI was based on a very old version of JSON schema and the new one is based on the latest version.

43:21 So we will have like all the compatibility all around the place in all the different tools.

43:27 So that's great.

43:29 And it will allow like a lot of interoperability and integration with other tools.

43:35 - Yeah, yeah.

43:35 For people who don't know, if you run a FastAPI site and you go to /docs, it'll generate a whole form that gives you information about the Pydantic models that are exchanged, the validation that happens, even lets you try it out, right?

43:48 - Yeah.

43:48 - That's related to this, yeah?

43:50 - Yeah, and OpenAPI is an open standard that is held by the Linux Foundation and it uses JSON schema, which is another open standard, which is a in-progress RFC, an internet standard.

44:03 And OpenAPI also uses OAuth2, which is another standard.

44:07 So it's all based on standards.

44:08 When you build an application with FastAPI, it's all based on standards and you get an application built on standards.

44:14 Having this compatibility between these different standards and having all them synchronized now, will improve a lot all that interaction between those different things.

44:25 - Yeah, that's really cool.

44:27 Awesome, very nice.

44:28 So Brian, that's our items, right?

44:30 Anything you wanna throw out there?

44:32 I am wearing this lovely Noah shirt from National Oceanic and Atmospheric Administration.

44:39 Thanks to Matthew Kisari and Noah for the great shirt.

44:43 Sent it as a thank you for speaking to them a couple of weeks ago, and that's really cool.

44:48 They also sent a couple of shirts for my daughters, and that was nice, thanks.

44:50 - Yeah, fantastic.

44:52 That's really cool.

44:53 I'm sure there's neat Python stuff there.

44:54 - Yeah, so anybody want me to speak at their company and send me a shirt, I'll wear it online.

45:01 (laughing)

45:02 - Fantastic, Sebastian, we always throw out just little extra items if people, if you got anything extra you wanna let people know about, anything you wanna share?

45:09 - I just got curious recently about item, which is a kind of React in Python, and you can use it through Jupyter.

45:16 That's, it seemed quite interesting.

45:18 I haven't played much with it.

45:20 I know I just checked the first day that it works.

45:24 It's a bit mind-bending, but it's quite an interesting experiment.

45:28 - Yeah, awesome, okay, very cool.

45:29 People should check that out.

45:31 And Brian, it's true.

45:33 Everyone has a price, everyone has a price.

45:34 Some people it's just a t-shirt, that's awesome.

45:36 All right, I got four things I wanna throw out there and then joke, I'll make these all super, super quick.

45:41 So first of all, I wrote, I've been, with all of my courses, it's always like, oh, do you need Python?

45:46 Do you have the right version of Python?

45:47 Are you on Windows?

45:48 Oh, then here's what you're gonna need to do to get, here's how you check it.

45:51 You don't type Python three, that will never work.

45:53 You type Python.

45:54 Unless you are on a certain version of Windows 10, then it'll report that it's not there.

45:57 But like, there's just like, oh my God, what is happening?

45:59 I just couldn't take it anymore.

46:00 So I finally broke down and wrote a, I don't have Python, I need Python, what do I do?

46:04 Oh, I'm on macOS, okay, so then here's how you find out if you have Python, and it's a good version.

46:09 If not, here's three or four options for each OS, the benefits, pros, and the cons of potentially, say, using Homebrew, and then how you install if you wanna go down that path.

46:17 And so, anyway, I'll put a link in the show notes if people care about that.

46:21 - Nice, thanks for doing that.

46:23 - Yeah, you're absolutely welcome.

46:25 And last time I was so excited, still am excited, about Boto3 type annotations.

46:29 But someone pointed out that this, you noticed the last updated two years ago, there's a deprecated, oh, there's a fork over here.

46:34 And if you go to that, it goes, you go down like, oh, no, no, no, this is deprecated.

46:38 It's over here.

46:38 Eventually you end up at this mypy boto3 builder that uses mypy to dynamically generate the type stubs for that are compatible with VS Code and PyCharm and so on for the Boto library.

46:51 So if you're really super interested in that thing I covered last time, you know, check this out, follow the GitHub thing.

46:56 - But use it fast before it's deprecated.

46:58 - Yes, exactly, exactly.

47:00 And that comes from Dean Langsom, who is also on the livestream, so thank you for that, Dean.

47:04 That's awesome.

47:05 We had Brett Cannon on the show.

47:06 Was that last time or time before?

47:08 That was last time, right?

47:10 Very, very recently we had Brett Cannon come talk about various things, including the pattern matching stuff.

47:15 He also talked about Python Launcher, and we threw out, like, "Hey, if I'm in a subdirectory of some project, "then somewhere up there's a virtual environment, "and I just try to run it, "it should automatically find the whole project's sort of ambient virtual environment.

47:28 So he apparently added that for us.

47:30 - Yeah, I just tried it this morning.

47:31 It's awesome.

47:32 - Yeah, fantastic.

47:33 - Nice.

47:34 - And then last thing, I'm thinking of doing an Ask Me Anything Talk Python episode, where I get some people in the audience to interview me and ask the questions of the audience just about the show.

47:43 So I'll put a link in the show notes.

47:44 If you have a question you would like to ask on Talk Python and make it part of the Ask Me Anything, we'll do that and we'll live stream it on YouTube as well.

47:51 All right, so that's all my extra items.

47:53 - We need a joke.

47:54 - We need a joke.

47:55 All right.

47:56 I really enjoyed this one.

47:57 So I thought the funny code comments.

48:01 So I thought we might come back to this.

48:02 So I think I'll kick it off, I guess, and then Brian, you're next, and then Sebastian, you can pick up the third one.

48:09 How's that sound?

48:10 - Sure.

48:11 - Awesome, all right.

48:12 So here's a comment that kind of misunderstands exception handling constructs.

48:17 So try finally comment in the finally block should never happen.

48:23 - I'm sure they meant try exception never happen.

48:26 No, no, no, try finally.

48:27 That probably almost always happens.

48:29 - Yeah.

48:32 - That's a good one, right?

48:33 All right, Brian, you're up next.

48:34 - Oh, okay.

48:35 So comment that says, looks like C code 'cause of the comment style, but you may think you know what's the following code does, but you don't.

48:44 Trust me, fiddle with it, and you'll spend many a sleepless night cursing the moment you thought you'd be clever enough to optimize the code below.

48:51 Now close this file and go play with something else.

48:54 (laughing)

48:56 - All right, Sebastian, the next one's yours.

48:58 - So there's this declaration of a constant integer with a name of capitals T-E-N, so 10, and the value is the number 10.

49:09 And the comment says, as if the value of 10 will fluctuate.

49:12 (laughing)

49:14 - You know, you don't want magic numbers in your code, like blue might be better than some hexadecimal number or like max limit might be 10, but just the word 10, there's no reason for that, that's awesome.

49:26 All right, I'll do the next one here.

49:28 I'm not responsible for this code.

49:30 They made me write it against my will.

49:32 (laughing)

49:34 Is it going right?

49:37 - I like the last, it's the next one.

49:38 So if this code works, it was written by Paul.

49:42 If not, we don't know who wrote it.

49:44 (laughing)

49:46 - All right.

49:50 And then the last one says, option, so is a declaration of options, dot batch size is equal to 300.

49:57 And then the comment says, madness.

49:59 And then screams, this is Sparta!

50:02 - This is Sparta!

50:03 That from the movie 300, fantastic.

50:05 Oh my goodness.

50:08 - Nice.

50:09 - That's great.

50:09 - Awesome, well those are some really good, important comments, all of them.

50:13 I think the Sparta one kind of inspires.

50:15 You're like, we're gonna go to batch size 300, let's do this.

50:18 I don't know about them so much.

50:20 - No, I'm gonna start doing the, if this code works, it was written by me.

50:25 But you know, we have version control.

50:27 You can just look it up.

50:28 - Yeah, that's true.

50:29 There is a blame.

50:30 - Well, that was fun.

50:32 We're done.

50:32 Thanks everybody for joining us.

50:34 Thank you, Sebastian, for joining us.

50:37 This was great.

50:38 - Thank you for the invitation.

50:39 Thanks everyone for listening to my weird voice.

50:42 - Thanks for having us.

50:43 - Sebastian, it was great to have you here.

50:44 Thank you.

50:45 - It was awesome, thank you.

50:46 - Yep, bye everyone, bye Brian.

Back to show page