Why You Should Use Pydantic in 2024 | Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 1 ต.ค. 2024

ความคิดเห็น • 94

  • @ArjanCodes
    @ArjanCodes  6 หลายเดือนก่อน +1

    💡 Get my FREE 7-step guide to help you consistently design great software: arjancodes.com/designguide.

  • @ticket-vision
    @ticket-vision หลายเดือนก่อน +3

    By utilizing `BeforeValidator`, `AfterValidator`, and `WrapValidator`, you can construct an Extract, Transform, and Load (ETL) pipeline directly within an 'Annotated' type hint. Additionally, you can achieve aggregated entity resolution by mapping known keys to a JSON field using `AliasChoices`, and serialize the parsed response within a single model from as many data sources as you need. Create trigger conditions using discriminated unions and fully automate processing procedures like OpenAI Vector Stores. 🐍🐍

  • @wesleydevries7415
    @wesleydevries7415 6 หลายเดือนก่อน +20

    Arjan, as a Dutchy but also as a human being: thank you for all of these videos, including this one.
    However, I am still looking for a video where you properly explain how to use the debug tools in an IDE properly rather than just printing everything and using "if self.debug=true: print(f"Beautiful variable in this method"{variable}").
    Do you perhaps have something in the pipeline for this?

    • @mytelevisionisdead
      @mytelevisionisdead 6 หลายเดือนก่อน

      @wesleydevries7415 check out mCoding's recent video on debugging python in IDE's. I would specifically recommend using Pycharm for advanced debugging, it's unparalleled imho. Groeten!

    • @AndreaDalseno
      @AndreaDalseno 6 หลายเดือนก่อน

      😊

    • @verwindle-aka-Celeron
      @verwindle-aka-Celeron 6 หลายเดือนก่อน +1

      If talking about python, why not to use built-in IDE debugger. For instance, in vs code you'll find debugger shipped with python microsoft extension. I believe it's there. Which is triggered via F5 key. If there's no option to run debugger or you prefer to use prints, logging can be the solution. The minimal logging level to print during runtime (debug, info, warning) can be set by its config. IMO the loguru lib is the easiest solution to use for logging

    • @mytelevisionisdead
      @mytelevisionisdead 6 หลายเดือนก่อน

      Wow 😲 my comment referring to a video from another youtuber (mCoding) that has an excellent introduction to IDE python debugging got removed (by you(r team), @ArjanCodes? That doesn't sound like you at all somehow...)
      Anyway, make sure to check that out! And use Pycharm, it's awesome 😎

    • @juanjosefarina
      @juanjosefarina 6 หลายเดือนก่อน

      Using breakpoints and the debug console of VS Code ? That gives you pretty much full control over runtime code and what is going on

  • @Kaassap
    @Kaassap 6 หลายเดือนก่อน +12

    Im currently making a datavalidation script using pydantic. Combining custom constrained annotations with the dynamic model creation per variable works like a charm!

  • @Michael201078
    @Michael201078 6 หลายเดือนก่อน +11

    Every time I see your video, I get new ideas about the code structure. Thanks a lot for your great job.

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Thank you for the kind comment, Michael :)

  • @nogamenolife9182
    @nogamenolife9182 6 หลายเดือนก่อน +12

    Pydantic is a lifesaver when dealing with messy/nested JSON data. I love it.

    • @coladock
      @coladock 6 หลายเดือนก่อน

      Does dataclass provide same functionality with json?

    • @superuser8636
      @superuser8636 6 หลายเดือนก่อน

      @@coladockuse sqlmodel. Thank me later

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Totally agree!!

  • @ButchCassidyAndSundanceKid
    @ButchCassidyAndSundanceKid 6 หลายเดือนก่อน +14

    I eagerly await the release of a new upload from Arjan every week. Never disappoints me.

  • @ammadkhan4687
    @ammadkhan4687 14 วันที่ผ่านมา

    Hi Arjan I have a question regarding python processes. I am diving in to learn elixir. But I am wonderung if the similar functionality we can achieve from python? Especially all processes are like having individual dashboard to monitor the performance and self healing concept. Thanks in advance.

  • @nickeldan
    @nickeldan 6 หลายเดือนก่อน +4

    pydantic is one of the best Python packages I've ever used.

    • @stints
      @stints 6 หลายเดือนก่อน

      I know I sound like a broken record in these comments but I really wish msgspec would gain the same traction. Does everything pydantic does but better.

  • @ESPViper100
    @ESPViper100 6 หลายเดือนก่อน +2

    Pydantic would be better, if it would have 1) proper serialising and deserialising and b) If it would have a proper way to convert to and from snake_case and CamelCase for python/JSON stuff.

    • @santoshmagadum7086
      @santoshmagadum7086 6 หลายเดือนก่อน +1

      You can use the field method alias parameter to assign the different field name types

    • @ESPViper100
      @ESPViper100 6 หลายเดือนก่อน

      @@santoshmagadum7086 I know, but that's a workaround, not a good design.

  • @BealleMoriniE
    @BealleMoriniE หลายเดือนก่อน

    Miller Kenneth Jackson Brenda Brown Timothy

  • @DouglasParish-w5m
    @DouglasParish-w5m 29 วันที่ผ่านมา

    Jackson Timothy White Gary Taylor Deborah

  • @EdenTyrone-g5t
    @EdenTyrone-g5t 28 วันที่ผ่านมา

    Young Brenda Brown Melissa Lopez Jennifer

  • @00xero
    @00xero 6 หลายเดือนก่อน +1

    Good video! The North face is racist

  • @DrGreenGiant
    @DrGreenGiant 6 หลายเดือนก่อน +1

    Can you create your own types, like the EmailStr, so that they can be used in multiple classes? I feel like this would help reduce the massive class bloat for the final data container and help reusability. (Particularly my use case which would be laden with numpy fields!)
    Also, is pydantic still really slow when compared like for like against dataclasses and attrs?

    • @juanjosefarina
      @juanjosefarina 6 หลายเดือนก่อน

      That's what the BaseModel stands for, doesn't it ? You can create your own custom string type, or int type, or anything else you wish, and change every behaviour of the type (and also its validation, thanks to pydantic)

    • @DrGreenGiant
      @DrGreenGiant 6 หลายเดือนก่อน

      @@juanjosefarina ah so you'd basically nest types and it's solved recursively?? Ty! Definitely going to take a look and see how it runs on my embedded stuff. I'm using dataclasses at the moment which are nice and quick, even though I'm locked on 3.8 so no slots.

  • @JusticeNDOU
    @JusticeNDOU หลายเดือนก่อน

    Thanks was having a problem upgrading from pydantic 1.9 to 2.8 seeminly some of the modules i wanted to use needed 2.8 - the headache was i could not understand why optional no longer worked - now i get it i had to specifically set the Field Value of all Optional Fields to None

  • @NicholasMichaud-u7e
    @NicholasMichaud-u7e 25 วันที่ผ่านมา

    Williams Shirley Harris Melissa Davis Sarah

  • @timothytanner29
    @timothytanner29 6 หลายเดือนก่อน +1

    Love pydantic, makes life much easier

  • @magno5157
    @magno5157 3 หลายเดือนก่อน

    Can a field be a descriptor?

  • @JusticeNDOU
    @JusticeNDOU หลายเดือนก่อน

    your discord is not loading

  • @StinkyCatFarts
    @StinkyCatFarts 6 หลายเดือนก่อน

    For some reason making compositions and accessing attributes from nested models just doesn’t seem to work the way it’s supposed to. I know my models work because I can query them in any other validation library.

  • @hodiks
    @hodiks 6 หลายเดือนก่อน

    Hello, @ArjanCodes,
    can I ask you use, classmethod decorator in validator methods even if you don't need need class instance in code ("cls")?? Wouldn't it be better to use staticmethod?

  • @CoentraDZ
    @CoentraDZ 6 หลายเดือนก่อน

    Pydantic 2 is much easier and cleaner than version 1, and thanks for clarifying this

  • @SundarR-g4g
    @SundarR-g4g 5 หลายเดือนก่อน

    What about the Marshmallow library In python, can you please post a video about that!!..

  • @GBOAC
    @GBOAC 4 หลายเดือนก่อน

    6:43 line 58 why use a list comprehension when you can just provide a generator expression to join()?

  • @devanshkanda9618
    @devanshkanda9618 6 หลายเดือนก่อน +1

    Thanks arjan! Again a great video. I didn't knew about pydantic before and after watching this video, i will surely use this in my projects and make this an addon to my dev toolkit.
    Again thanks for this awesome knowledge! 😀

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน +1

      I'm really glad to hear the video had a positive impact on your journey, Devan! Best wishes :)

  • @delayedd
    @delayedd 6 หลายเดือนก่อน

    Do you have an example of after creation there is a change in the value? To Validate or change the information. Example: set a new password in example2

  • @stopznak86
    @stopznak86 6 หลายเดือนก่อน

    Very informative. Can you/did you use pydantic for validation of sql queries?

  • @erfanlab3728
    @erfanlab3728 6 หลายเดือนก่อน

    I think you should make a video about django-ninja
    It is django with pydantic and it's mind-blowing

  • @ИванИваныч-н3у
    @ИванИваныч-н3у 6 หลายเดือนก่อน +3

    7:02 my teamlead will "kill" me for code like on lines 53-55, it's unreadable. Why do not you use a match statement?

  • @UNgineering
    @UNgineering 6 หลายเดือนก่อน

    The new pydantic version is deprecating example field, now you need to use json_schema_extra={"example": "123"}

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Good to know!

  • @AndreNitschke
    @AndreNitschke 6 หลายเดือนก่อน

    How you handle uniques validations in combination with database in fastapi?

  • @rhbvkleef
    @rhbvkleef 6 หลายเดือนก่อน +1

    Ninja is also interesting to know about, in my opinion. It really is a life-saver for those of us who live in the Django world.

    • @matis9783
      @matis9783 6 หลายเดือนก่อน

      Is django a right tool for making web APIs?

    • @fiimii77
      @fiimii77 6 หลายเดือนก่อน

      @@matis9783 I recommend you use FastAPI instead of Django for APIs

    • @rhbvkleef
      @rhbvkleef 6 หลายเดือนก่อน

      @@matis9783 if you ask me: with Ninja it is.

  • @astronemir
    @astronemir 4 หลายเดือนก่อน

    Miss your more long form, typing the code included videos 😊. The click clack is unbeatable.
    But it feels like those videos stick way more!

    • @ArjanCodes
      @ArjanCodes  4 หลายเดือนก่อน

      I actually also miss doing those myself. We’re making a few changes at the moment to (partly) return to the style of the older videos. So stay tuned 😊.

  • @markokraljevic1590
    @markokraljevic1590 5 หลายเดือนก่อน

    you should had made analogy with zod

  • @vlntsolo
    @vlntsolo 6 หลายเดือนก่อน

    Just saw for the first time that it's possible to use python primitive types in the dictionary as keys... Learning never ends. That's neat, thanks!

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Glad you found it helpful!

  • @kunalmundada8754
    @kunalmundada8754 6 หลายเดือนก่อน

    Pydantic is epic, if it was fighting elections. He would win single handedly, cause there's no opposition.

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 2 หลายเดือนก่อน

      why use pydantic when you can... just check the types with the isinstance() function?

  • @mraviteja22
    @mraviteja22 6 หลายเดือนก่อน

    What about schematics for python

  • @MikeDeltgen
    @MikeDeltgen 6 หลายเดือนก่อน

    used it recently to get environment variables.

  • @agaxardev
    @agaxardev 6 หลายเดือนก่อน

    I would like to know your opinion about SQLmodel for fastapi

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน +1

      I like the idea of the library, but I’m waiting to do a video about it until it catches up to the latest version of SQLAlchemy and Pydantic.

  • @brunosompreee
    @brunosompreee 6 หลายเดือนก่อน

    Awesome explanation as always Arjan! Thank you!!!

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Thank you for the kind comment, Bruno! Glad you liked it :)

  • @priteshsingh4055
    @priteshsingh4055 6 หลายเดือนก่อน

    i use attrs !

  • @TNeulaender
    @TNeulaender 6 หลายเดือนก่อน

    With lots of models and some even nested ones pedantic is extremely slowing down our cold start time in the lambdas. Also with 3.12 + pydantic2 + fastapi and debug mode it sometimes takes up to a minute to start the application:/

    • @TNeulaender
      @TNeulaender 6 หลายเดือนก่อน

      12:11 Oh and ellipses are no longer necessary for required fields. I think they're even discouraged

    • @youtubeenjoyer1743
      @youtubeenjoyer1743 2 หลายเดือนก่อน

      i suggest compiled fastjsonschema for deeply nested messy data

  • @juanantonionavarrojimenez2966
    @juanantonionavarrojimenez2966 6 หลายเดือนก่อน

    Fantastic video. Thank you.

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Glad you liked it, Juan!

  • @hubstrangers3450
    @hubstrangers3450 6 หลายเดือนก่อน

    Thank you....

  • @smwaqarulhaq
    @smwaqarulhaq 6 หลายเดือนก่อน

    how you gonna write the test cases for them ?

    • @juanjosefarina
      @juanjosefarina 6 หลายเดือนก่อน

      What do you mean how ? One way was pretty much everything he showed in the video, but you should be using pytest or other testing library.

  • @davidl3383
    @davidl3383 6 หลายเดือนก่อน

    Thank you Arjan ! I love pydantic with FatsApi, my only fault was putting too much business logic into it and not knowing where the data transformation was taking place :)

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      I'm glad to hear that the video was useful, David!

  • @frd85
    @frd85 6 หลายเดือนก่อน

    nice video as always👍🏻

    • @ArjanCodes
      @ArjanCodes  6 หลายเดือนก่อน

      Thank you so much!

  • @gardnmi
    @gardnmi 6 หลายเดือนก่อน +2

    But you shouldn't be using poetry.

  • @tembelg.gr.4486
    @tembelg.gr.4486 6 หลายเดือนก่อน

    If you use data from mongodb is there better way to create instances of pydatic classes then getting binary json as dictionary and dictionary unpack into pydantic instance? I looked into creating pandas dataframes with PyMongoArrow but I'm not sure I need that clunk.

    • @urknidoj422
      @urknidoj422 6 หลายเดือนก่อน

      you can try beanie-odm☺