|
6 | 6 |
|
7 | 7 | 00:00:11 Django Ninja is highly inspired by FastAPI, but also deeply integrated into Django itself.
|
8 | 8 |
|
9 |
| -00:00:17 We have Vitaly Kucherev, the creator of Django Ninja, on the show to tell us all about it. |
| 9 | +00:00:17 We have Vitaliy Kucheryaviy, the creator of Django Ninja, on the show to tell us all about it. |
10 | 10 |
|
11 | 11 | 00:00:22 This is Talk Python to Me, episode 490, recorded December 10th, 2024.
|
12 | 12 |
|
|
144 | 144 |
|
145 | 145 | 00:03:04 Yeah.
|
146 | 146 |
|
147 |
| -00:03:04 So my name is Vitaly Kucherawe. |
| 147 | +00:03:04 So my name is Vitaliy Kucheryaviy. |
148 | 148 |
|
149 | 149 | 00:03:06 Yeah.
|
150 | 150 |
|
|
346 | 346 |
|
347 | 347 | 00:10:09 And yeah, that's, that's how, how it born.
|
348 | 348 |
|
349 |
| -00:10:11 And I guess the next part is like actually why it exists is like, yeah, so in PyDentic, there is model word is reserved for like, you know, any kind of validation. |
| 349 | +00:10:11 And I guess the next part is like actually why it exists is like, yeah, so in Pydantic, there is model word is reserved for like, you know, any kind of validation. |
350 | 350 |
|
351 | 351 | 00:10:20 Yeah.
|
352 | 352 |
|
353 |
| -00:10:21 So PyDentic uses word model for validation, but in Django world model means like tables, yeah, database tables. |
| 353 | +00:10:21 So Pydantic uses word model for validation, but in Django world model means like tables, yeah, database tables. |
354 | 354 |
|
355 |
| -00:10:29 So you cannot just bring PyDentic models. |
| 355 | +00:10:29 So you cannot just bring Pydantic models. |
356 | 356 |
|
357 | 357 | 00:10:31 It's the ORM, yeah.
|
358 | 358 |
|
359 | 359 | 00:10:31 Yeah.
|
360 | 360 |
|
361 | 361 | 00:10:32 And because people will be confused when you, okay, you speak about model and then you kind of need to think, okay, is it database or is schema?
|
362 | 362 |
|
363 |
| -00:10:39 So like for me, the main goal was to introduce class called schema, which is like a PyDentic model under the hood. |
| 363 | +00:10:39 So like for me, the main goal was to introduce class called schema, which is like a Pydantic model under the hood. |
364 | 364 |
|
365 | 365 | 00:10:46 And then it should like hide as much as possible the word model.
|
366 | 366 |
|
|
382 | 382 |
|
383 | 383 | 00:11:32 It was like really lightweight.
|
384 | 384 |
|
385 |
| -00:11:34 So way faster than Django Ress framework. |
| 385 | +00:11:34 So way faster than Django Rest framework. |
386 | 386 |
|
387 | 387 | 00:11:36 So I thought, okay, she should be something fast.
|
388 | 388 |
|
|
614 | 614 |
|
615 | 615 | 00:19:41 But yeah, so it's, it's, it's really big industry and Django like REST framework has already like lots of plugins or like tools or like, you know, community that you can rely on.
|
616 | 616 |
|
617 |
| -00:19:52 But yeah, again, like the, the, basically, I think the problem that is solved with like this pidentic validation and serialization is like, yeah, you simply rely on like latest standards. |
| 617 | +00:19:52 But yeah, again, like the, the, basically, I think the problem that is solved with like this Pydantic validation and serialization is like, yeah, you simply rely on like latest standards. |
618 | 618 |
|
619 | 619 | 00:20:04 Yeah, like, so if you never use like type annotation, this is actually first, the good way to try it out and see the benefits.
|
620 | 620 |
|
|
678 | 678 |
|
679 | 679 | 00:22:39 And people want to see the graph.
|
680 | 680 |
|
681 |
| -00:22:41 They can just visit jingo-ninja.dev and it's right there on the homepage. |
| 681 | +00:22:41 They can just visit django-ninja.dev and it's right there on the homepage. |
682 | 682 |
|
683 | 683 | 00:22:45 But yeah, if you start doing like you start, you know, doing some kind of square roots of some numbers, yeah, you will not get this performance.
|
684 | 684 |
|
|
692 | 692 |
|
693 | 693 | 00:23:01 So I never actually measured like what is the performance.
|
694 | 694 |
|
695 |
| -00:23:04 So yeah, like, but again, it's like probably like you will see the difference with Pydantic 2 when you like really, so you're in, you have inputs of like really bulky Jasons. |
| 695 | +00:23:04 So yeah, like, but again, it's like probably like you will see the difference with Pydantic 2 when you like really, so you're in, you have inputs of like really bulky JSON. |
696 | 696 |
|
697 | 697 | 00:23:14 Like, you know, let's say you have like, you know, payload that is like one megabyte and you will, you will definitely see performance.
|
698 | 698 |
|
|
806 | 806 |
|
807 | 807 | 00:26:22 There's also like for, I guess for, for the difference for folks who work with FastAPI.
|
808 | 808 |
|
809 |
| -00:26:27 The key difference is that Jenga Ninja, Jenga Ninja's operation, their function, the first argument is always request. |
| 809 | +00:26:27 The key difference is that Django- Ninja, Django-Ninja's operation, their function, the first argument is always request. |
810 | 810 |
|
811 |
| -00:26:35 Because this is like historically what Jenga, what Jenga protocol is. |
| 811 | +00:26:35 Because this is like historically what Django, what Django protocol is. |
812 | 812 |
|
813 | 813 | 00:26:39 Yeah.
|
814 | 814 |
|
|
824 | 824 |
|
825 | 825 | 00:26:58 And yeah, like there was a suggestion, so let's remove it.
|
826 | 826 |
|
827 |
| -00:27:02 But I think, yeah, we should keep it, we should keep it consistent with, with, with default Jenga view. |
| 827 | +00:27:02 But I think, yeah, we should keep it, we should keep it consistent with, with, with default Django view. |
828 | 828 |
|
829 | 829 | 00:27:07 And yeah, like, I think that, that, that, that works perfectly.
|
830 | 830 |
|
|
870 | 870 |
|
871 | 871 | 00:28:11 Another, another thing that's really nice, and you hinted at this before, is that it has automatic documentation, very, very similar to FastAPI for what you write without you doing any work, right?
|
872 | 872 |
|
873 |
| -00:28:23 You just go to slash API slash docs, and you get this nice UI, right? |
| 873 | +00:28:23 You just go to /API /docs, and you get this nice UI, right? |
874 | 874 |
|
875 | 875 | 00:28:27 You don't have any hassle of creating some UIs.
|
876 | 876 |
|
877 | 877 | 00:28:30 You just, you just have it for free, right?
|
878 | 878 |
|
879 |
| -00:28:32 So you just go to slash API slash docs, and there you have it. |
| 879 | +00:28:32 So you just go to /API/docs, and there you have it. |
880 | 880 |
|
881 | 881 | 00:28:35 And you can already like, so by default, Django Ninja comes with two, like three doc and a swagger.
|
882 | 882 |
|
|
932 | 932 |
|
933 | 933 | 00:30:40 So you can create like, you know, as, as, as many as possible ninja API instances.
|
934 | 934 |
|
935 |
| -00:30:45 So you can have like slash public API slash private slash custom slash, yeah, whatever, like version one, version two, like, and basically you can define multiple, multiple versions, reuse functions. |
| 935 | +00:30:45 So you can have like slash public API/private/custom/, yeah, whatever, like version one, version two, like, and basically you can define multiple, multiple versions, reuse functions. |
936 | 936 |
|
937 | 937 | 00:30:57 And then, you know, can continue your work while keeping the old, old, you know, version one, version two code or private public, stuff like that.
|
938 | 938 |
|
|
1042 | 1042 |
|
1043 | 1043 | 00:34:59 And you pointed out that you can have public and private APIs in this similar way.
|
1044 | 1044 |
|
1045 |
| -00:35:04 And so you could have public APIs, maybe multiple versions of them, but also a separate private API that potentially exposes more more things. |
| 1045 | +00:35:04 And so you could have public APIs, maybe multiple versions of them, but also a separate private API that potentially exposes more things. |
1046 | 1046 |
|
1047 | 1047 | 00:35:13 Right.
|
1048 | 1048 |
|
|
1198 | 1198 |
|
1199 | 1199 | 00:39:25 Like editor should do that to complete.
|
1200 | 1200 |
|
1201 |
| -00:39:28 My pie should not like scream at you and it should validate under the hood. |
| 1201 | +00:39:28 MyPy should not like scream at you and it should validate under the hood. |
1202 | 1202 |
|
1203 | 1203 | 00:39:33 So there's like a pretty, pretty like nasty kind of if typing stuff, annotations.
|
1204 | 1204 |
|
|
1248 | 1248 |
|
1249 | 1249 | 00:40:49 combinations.
|
1250 | 1250 |
|
1251 |
| -00:40:49 So if you know, maybe like a Jenga plus Python 3.6 or stuff like that was like really giving |
| 1251 | +00:40:49 So if you know, maybe like a Django plus Python 3.6 or stuff like that was like really giving |
1252 | 1252 |
|
1253 | 1253 | 00:40:55 some headaches.
|
1254 | 1254 |
|
|
1264 | 1264 |
|
1265 | 1265 | 00:41:22 So your editor works.
|
1266 | 1266 |
|
1267 |
| -00:41:24 If you use MyPi, you really like types, you have 100% type correction. |
| 1267 | +00:41:24 If you use MyPy, you really like types, you have 100% type correction. |
1268 | 1268 |
|
1269 |
| -00:41:30 And then on the hood, it does as fast as possible, whatever, like PyDentic Magic, |
| 1269 | +00:41:30 And then on the hood, it does as fast as possible, whatever, like Pydantic Magic, |
1270 | 1270 |
|
1271 | 1271 | 00:41:36 media with Rust.
|
1272 | 1272 |
|
|
1398 | 1398 |
|
1399 | 1399 | 00:45:29 You know, I have kind of the same feeling about like any, any like Python approaches to the dependency injection libraries,
|
1400 | 1400 |
|
1401 |
| -00:45:36 because I think the, the Pytonic way is actually like, like it's more kind of, because you can import from strings. |
| 1401 | +00:45:36 because I think the, the Pythonic way is actually like, like it's more kind of, because you can import from strings. |
1402 | 1402 |
|
1403 | 1403 | 00:45:43 You can, you know, pass kind of any type of arguments and just access them by like the, this quarks.
|
1404 | 1404 |
|
|
1412 | 1412 |
|
1413 | 1413 | 00:46:26 Like, okay, like let's do dependence injection or some kind of SSL protocols, like, you know, timeouts and stuff like that.
|
1414 | 1414 |
|
1415 |
| -00:46:33 But they, they really try to like make it as current Pytonic way as possible through like some quarks or like, or, or like, you know, stuff that you, you never, you never know. |
| 1415 | +00:46:33 But they, they really try to like make it as current Pythonic way as possible through like some quarks or like, or, or like, you know, stuff that you, you never, you never know. |
1416 | 1416 |
|
1417 | 1417 | 00:46:42 Okay.
|
1418 | 1418 |
|
1419 |
| -00:46:43 What's what's actually injected, but verbally, you know, what, what's, what's going on. |
| 1419 | +00:46:43 What's actually injected, but verbally, you know, what, what's, what's going on. |
1420 | 1420 |
|
1421 | 1421 | 00:46:47 Yeah, the quarks and the stargs, quarks, all that stuff is when I see that it's the function signature, I feel like, okay, the, you kind of given up on helping me know what I'm supposed to do here.
|
1422 | 1422 |
|
1423 | 1423 | 00:46:57 The only way to know is to go read the documentation, which not a big fan.
|
1424 | 1424 |
|
1425 | 1425 | 00:47:01 Let's talk about authentication.
|
1426 | 1426 |
|
1427 |
| -00:47:02 So what's the, the Jingo ninja way for authentication here? |
| 1427 | +00:47:02 So what's the, the Django ninja way for authentication here? |
1428 | 1428 |
|
1429 | 1429 | 00:47:07 It looks pretty integrated.
|
1430 | 1430 |
|
|
1452 | 1452 |
|
1453 | 1453 | 00:47:50 Off inside this function.
|
1454 | 1454 |
|
1455 |
| -00:47:51 You can also access request and like attach your request.user, which is what is in most cases are done. |
| 1455 | +00:47:51 You can also access request and like attach your request. User, which is what is in most cases are done. |
1456 | 1456 |
|
1457 | 1457 | 00:47:57 If you like, you have user in your system that is tied to some token or stuff like that, but it's kind of on purpose that yeah.
|
1458 | 1458 |
|
|
1656 | 1656 |
|
1657 | 1657 | 00:54:55 Yeah.
|
1658 | 1658 |
|
1659 |
| -00:54:55 Like whatever new version, like I saw this a lot with Pidentic when they, you know, they already like a version two for like a year in a while. |
| 1659 | +00:54:55 Like whatever new version, like I saw this a lot with Pydantic when they, you know, they already like a version two for like a year in a while. |
1660 | 1660 |
|
1661 | 1661 | 00:55:04 While if you ask LLM to implement some stuff, they, they still giving you the old, old approaches.
|
1662 | 1662 |
|
|
1668 | 1668 |
|
1669 | 1669 | 00:55:30 Yeah.
|
1670 | 1670 |
|
1671 |
| -00:55:31 But if you like listening to this podcast, you can go to LLM.jangoNinja.dev. |
| 1671 | +00:55:31 But if you like listening to this podcast, you can go to LLM.djangoNinja.dev. |
1672 | 1672 |
|
1673 | 1673 | 00:55:36 It will, it will, we'll redirect you to some ticket where I will notify when it's ready.
|
1674 | 1674 |
|
|
1788 | 1788 |
|
1789 | 1789 | 01:00:11 Try to make it for people to migrate to newer, newer versions easier.
|
1790 | 1790 |
|
1791 |
| -01:00:15 So like, I guess the hardest part was like, you know, between version zero something to 1.0, but yeah, it will, it was like dictated by the fact that, you know, Pidentic moved from one to two. |
| 1791 | +01:00:15 So like, I guess the hardest part was like, you know, between version zero something to 1.0, but yeah, it will, it was like dictated by the fact that, you know, Pydantic moved from one to two. |
1792 | 1792 |
|
1793 | 1793 | 01:00:26 So like, there was no way to make it without breaking changes.
|
1794 | 1794 |
|
|
1832 | 1832 |
|
1833 | 1833 | 01:02:09 This is like a very first way to try that to do.
|
1834 | 1834 |
|
1835 |
| -01:02:11 To just simply install Manage Jenga and you'll have Jenga in that hood, Ninja under the hood and everything you need all in one, in one file. |
| 1835 | +01:02:11 To just simply install Manage Django and you'll have Django in that hood, Ninja under the hood and everything you need all in one, in one file. |
1836 | 1836 |
|
1837 | 1837 | 01:02:18 Cool.
|
1838 | 1838 |
|
|
1878 | 1878 |
|
1879 | 1879 | 01:02:57 Just visit talkpython.fm/sentry and get started for free.
|
1880 | 1880 |
|
1881 |
| -01:03:02 And be sure to use the promo code talkpython, all one word. |
| 1881 | +01:03:02 And be sure to use the promo code TALKPYTHON, all one word. |
1882 | 1882 |
|
1883 | 1883 | 01:03:06 And this episode is brought to you by Bluehost.
|
1884 | 1884 |
|
|
1923 | 1923 | 01:04:07 Now get out there and write some Python code.
|
1924 | 1924 |
|
1925 | 1925 | 01:04:09 write some Python code.
|
1926 |
| - |
1927 |
| -01:04:10 Open arms! |
1928 |
| - |
1929 |
| -01:04:13 Open arms! |
1930 |
| - |
1931 |
| -01:04:15 Open arms! |
1932 |
| - |
1933 |
| -01:04:17 Open arms! |
1934 |
| - |
1935 |
| -01:04:19 Open arms! |
1936 |
| - |
1937 |
| -01:04:21 Open arms! |
1938 |
| - |
1939 |
| -01:04:23 Open arms! |
1940 |
| - |
1941 |
| -01:04:25 Open arms! |
1942 |
| - |
1943 |
| -01:04:27 you you Thank you. |
1944 |
| - |
1945 |
| -01:04:29 Thank you. |
1946 |
| - |
0 commit comments