Do We Still Need Dataclasses? // PYDANTIC Tutorial

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

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

  • @anuruddhabandara3540
    @anuruddhabandara3540 2 ปีที่แล้ว +207

    In TH-cam there are lot of python contents. But 99% are for beginners. You are the only guy who teach python advance concepts very clearly. You are doing a such a amazing job sir. Keep it up. Good Luck! 🙌

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +13

      Thank you - glad you like the videos!

    • @jakobullmann7586
      @jakobullmann7586 ปีที่แล้ว +6

      Check out mCoding

    • @theultimatereductionist7592
      @theultimatereductionist7592 ปีที่แล้ว +1

      How you feel about Python TH-cam videos is EXACTLY how I feel about all MATH videos. I specialize in differential algebra. There exist literally ZERO videos about differential Galois theory, for example! Or differential rings.
      I know less about Python now in January 2023 than 8 years ago when I began studying it. In fact, I know less about programming now than I did in Summer 1981 when I took my first computer coding class: Fortran at local community college.

    • @theultimatereductionist7592
      @theultimatereductionist7592 ปีที่แล้ว +1

      Yes, there SHOULD be MANY more ADVANCED TOPIC videos for non-beginners.
      However, 99% of all Python creators/coders are beginners. Extreme beginners.
      That is why 99% of the videos are for beginners.

    • @broccoloodle
      @broccoloodle ปีที่แล้ว +1

      You gave him at least one new subscription for your comment

  • @Newascap
    @Newascap 3 ปีที่แล้ว +80

    I was just looking up fast api, with tortoise and this. You are literally reading my brain like an open book. Thanks for uploading as always.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +4

      Thank you, glad to be service again ;)

  • @mei2654
    @mei2654 2 ปีที่แล้ว +51

    In my opinion Pydantic serves a very specific purpose, which is parsing and validating data. If you know what data you are working with and are sure what type of data you have, there is just no reason to use pydantic as the instance creation time is higher for a pydantic model compared to a dataclass

    • @ALIENdrifter66
      @ALIENdrifter66 ปีที่แล้ว +5

      Well, that's not really an opinion, data validation is something you must do when you can't trust the input data. If you 100% know that it's well formed and conforming data validation is redundant and thus, not efficient. That's exactly why you have booth option with Python dataclasses and Pydantic dataclasses, they're not substitutes but complements

  • @Luca1993x
    @Luca1993x 3 ปีที่แล้ว +59

    After watching and rewatching your content for just 2 weeks I can already let you know that you have made me a better Software -Engineer.
    Your creative work matters to many!
    Thank you a lot!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +5

      Great to hear! I'm happy that the videos are helpful to you.

    • @atahirince
      @atahirince 3 ปีที่แล้ว

      me need to learn automatic doc creation :D and be better developer

  • @NoxMar9Personal
    @NoxMar9Personal 2 ปีที่แล้ว +13

    Great video. Things to note about the difference vs dataclasses. By doing runtime (i.e. on every object of your class creation and every change to validated field) you are taking quite a considerable performance hit. So don't use pydantic on classes you don't need to. If your data comes from the outside (user input, file, HTTP request and so on) you should absolutely validate it but don't do that for data-focused class. Also pydantic offers a module called `pydantic.dataclasses` that lets you use dataclasses with validation. Note that BaseModel provides another functionality as well but if you don't need it and want some validation for your datalcasses you can use this with minial changes to your dataclass-using code.

  • @luizhenriquelongo1485
    @luizhenriquelongo1485 3 ปีที่แล้ว +19

    Oh Man, I'm from Brazil and for a long time I've been looking for this kind of content. With this whole technology bubble I've just seen superficial content about technology "how to create a crud in Django" and it has its own value but when you decide to go deep into the technology that you use most part of time we needed to get a book and try to extract as much as possible from it, but now we have you buddy, it's so nice to hear this deep content about python and it's like you've said "if you want to become a better software developer" you should probably go with arjan codes hahaha. Thank you for your content.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +4

      Thank you so much! I’m happy you’re enjoying the videos and that they help you. Ultimately, having a proper background in software design principles and patterns, knowing them through and through is one of the most important skills to have as a software developer. And that’s why I’m doing these kinds of videos instead of highly specific recipes. Feel free to spread the word to anyone who you think might be interested in this as well!

  • @LucasNaruto8107
    @LucasNaruto8107 3 ปีที่แล้ว +16

    Just fell in love with pydantic. I was poking around the code and noticed that pydantic solves the problem for nested dataclasses, for this matter I modified the title and subtitle to support mult lang (each field was now a list of text and lang pair), i created an extra class called MultLangStr and modified the json, pydantic identified the nested information and used the proper class whilst built-in dataclass ignored it and keept the dict format.

  • @raccoonteachesyou
    @raccoonteachesyou 3 ปีที่แล้ว +87

    Thank you very much for choosing topics that are not only for beginners but for more advanced users. This kind of topics are really enjoyable.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Thank you very much!

  • @pinakadhara7650
    @pinakadhara7650 2 ปีที่แล้ว +2

    One of my favourite things with Pydantic is that it supports nested objects i.e an object as an attribute for another object. Really helpfull when dealing with related objects.

  • @silkogelman
    @silkogelman 2 ปีที่แล้ว +5

    Thank you so much for this very interesting Pydantic example with both validation levels Arjan! 🙏😀
    I'm hoping you'll blend in more Pydantic in your tutorials in the future.
    FYI: for the price field you can use Decimal or condecimal with max_digits and decimal_places to more accurately represent money.

  • @zarakolagar7068
    @zarakolagar7068 3 ปีที่แล้ว +4

    wow, i was just searching for a tutorial on pydantic. As a newbie, i can say that your videos have single handedly upgraded my knowledge of the field. thank you very much and please keep up the good work 😊

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +2

      Thank you Zara! I’m happy that the videos are helpful!

  • @stifferdoroskevich1809
    @stifferdoroskevich1809 3 ปีที่แล้ว +10

    Wow! Beautiful coding... And Pydantic, very powerful! love that dict(exclude/include feature), remembers me a NoSql DB style query.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Thank you - glad you liked it!

  • @srdjan780
    @srdjan780 2 ปีที่แล้ว +6

    Good video!
    TBH pandas could have been used here as well.
    As someone who often works with immutable data, what I would love to see from you would be an OOP vs FP in python and when to use which, as thats a question that gets raised often :)

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +1

      Great suggestion, thank you!

  • @Sycord
    @Sycord 2 ปีที่แล้ว +5

    Really helpful video! Even just finding out dataclass is the better fit for my project and seeing some good clean code is always a chance to learn. I really like that you put emphasis on the small things of nice code like adding docstrings.
    Do you have a video on what class methods are?

  • @CharanThakur655
    @CharanThakur655 3 ปีที่แล้ว +1

    videos are getting better and better. Thanks a lot for your time and effort, much appreciated.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Thank you so much!

  • @rafael_tg
    @rafael_tg 3 ปีที่แล้ว +8

    Looking at this guy coding makes me feel noob in python again

  • @ArjanCodes
    @ArjanCodes  3 ปีที่แล้ว

    Also check out my original dataclasses video if you haven't seen that yet: th-cam.com/video/vRVVyl9uaZc/w-d-xo.html.

  • @amitkumarSaveSoil
    @amitkumarSaveSoil 2 ปีที่แล้ว

    I really needed your videos to get on next level no other channel covers what your channel covers.
    thankyou so much

  • @maxwell2201
    @maxwell2201 3 ปีที่แล้ว +1

    Really awesome video, I feel like I'm learning a lot about best practices really quickly watching these.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Glad you enjoyed it!

  • @user-hk3ej4hk7m
    @user-hk3ej4hk7m 3 ปีที่แล้ว +3

    This looks really nice, I'm interested in seeing how it will integrate with typing.Annotated coming with python 3.10

  • @slaweksx1564
    @slaweksx1564 ปีที่แล้ว

    Very useful and interesting. Than you Arjan. Small correction to custom exception, there should be inheritance from ValueError. Otherwise FastAPI generates status 500 without Pedantic validation message.

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

    I want to thank you from my bottom of my heart! You have made me a better Data professional!

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

      I'm glad my content has been helpful! :)

  • @alvin_paul
    @alvin_paul ปีที่แล้ว

    You are one of the best if not the best Python Channels that I know of. I am learning a lot from you 😊 Keep up the interesting topics and good work 👍👍👍

  • @Kinnoshachi
    @Kinnoshachi 3 ปีที่แล้ว +1

    You are a treasure in innumerable universes

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Thank you - you’re so kind!

  • @vikas416
    @vikas416 2 ปีที่แล้ว +4

    Thanks Arjan for awesome video on pydantic and its uses. I was wondering if we need to add '@classmethod' after validator and root_validator while defining a class, as according to documentation both validator and root_validator are classmethods themselves.

  • @ahmedtremo
    @ahmedtremo 2 ปีที่แล้ว

    Best Pydantic tutorial on the youtube

  • @theultimatereductionist7592
    @theultimatereductionist7592 ปีที่แล้ว

    There exist many MANY ideas I would love to code, but I know they are not worth it: no matter in what language I code them.
    They are all math ideas. A lot (not all) are coding the solutions to PDEs and ODEs. Some are for papers I wish to publish.
    Python is the only language I know, and just barely. Used to know C++, a little Java, and Fortran.
    I realize now that the mathematical ideas are simply too complex to be coded.
    For example in 2020 I attempted to code computing all infinitely many solutions for a trinomial w=C*z-z^A
    where w, C, A are complex numbers. Got close, but there was no way to get roots, z, that are within error limits when plugged back into the trinomial. Had hoped to publish it. But I had to leave it unfinished.
    Definitely a HUGE lesson about NOT coding anything deep or complicated:
    OTHER than the simplest of calculations, say, with a for loop. In other words, Python is my extension of a handheld calculator.

  • @bryancole1886
    @bryancole1886 3 ปีที่แล้ว +8

    It kinda annoys me that after about 15 years of writing declarative class with python Traits package (and more recently using the Atom package) offering validation, notification and visualisation, people are talking about data classes as if they are new and exciting (but only offer validation?). Pydantic still only offers a few of the features in Traits.

    • @astronemir
      @astronemir 2 ปีที่แล้ว

      Interesting 🤔

  • @cosmic_Robot
    @cosmic_Robot ปีที่แล้ว

    Great video Arjan. Subscribed.

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Thank you, glad you enjoyed the video!

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

    Another great video. I thought pedantic is just for validation but I know more now. It is great tool to deal with json object like book = [(**list) for list in json]

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

      Glad it was helpful!

  • @neilmurphy7064
    @neilmurphy7064 3 ปีที่แล้ว

    Was just randomly poking around... Trying to get smart, Eating popcorn when oh bam, this exactly solves today's problem! Thanks!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      You're most welcome :).

  • @josephlyons3393
    @josephlyons3393 3 ปีที่แล้ว

    Hey Arjan, quick tip. If you are in Python 3.9+, you no longer have to import the List to do type hints with lists.... so in your example, you can just do list[book], and kill the List import.

    • @josephlyons3393
      @josephlyons3393 3 ปีที่แล้ว

      I guess I don't know if Pydantic provides support for this or not yet...

    • @josephlyons3393
      @josephlyons3393 3 ปีที่แล้ว

      Also, really getting into your videos. Super well done.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Thanks Joseph! Yeah, I noticed that too. Same for dict actually, so I'll stick to those from now on.

  • @paracha3
    @paracha3 2 ปีที่แล้ว

    When you are typing or coding can you please zoom in because most of us watch your videos on the phone screens. Love your content. Thanks

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks! In my more recent videos, I've zoomed in more on the code!

  • @Mike-ol4ng
    @Mike-ol4ng 3 ปีที่แล้ว +1

    what is the cls in the isbn_10_valid function?

  • @sukanyar4373
    @sukanyar4373 ปีที่แล้ว

    Excellent tutorial on pydantic ! :) Thank you! :) 🙌

  • @michaellohier
    @michaellohier 2 ปีที่แล้ว +1

    Hi Arjan, great video. I often watch your content and I love it. I have a simple question though: does your ISBN10FormatError really need its “value” attribute?

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +2

      Thanks, Michael! It can be useful sometimes to have extra information in an Error object that you can do something with. For example, if you want to parse the value and then do something else with it to respond to the error.

  • @stoic1987
    @stoic1987 2 ปีที่แล้ว +1

    would you be able to reveal your setup (hardware etc. mouse keyboard) for your work as well?

  • @typinowly
    @typinowly 3 ปีที่แล้ว +2

    Why not simply define an array of validation methods for a dataclass (und treat dataclass like simple c-structs, without additional methods). This way all our components are neatly separated and we don't need to overpopulate our "Book" data type with a million methods. This also would make modification simpler, because then we simply add or remove validation callbacks as needed and have no need to modify the Book class. This, imho, would be way more SOLID (and thus maintainable), than what was presented in this video.

    • @rozarioagro5532
      @rozarioagro5532 3 ปีที่แล้ว +3

      or use a separate library, such as cerberus. You will then get a clean, fast code and separation of concerns. I don’t understand all this hype about pydantic. You get hard to extend classes bloated with unnecessary methods that do everything but nothing of good quality.

  •  ปีที่แล้ว

    @ArjanCodes I'd love to see an updated version using the new Pydantic v2, your thoughts on it, and how it sits now in the pydanticV2 vs dataclasses p3.11 vs attrs

  • @berkistayn
    @berkistayn ปีที่แล้ว

    Decent tutorial. However, the title is misleading: I was expecting an in-depth comparison and pros cons with respect to dataclasses in code.

  • @AnyaSheven
    @AnyaSheven 2 ปีที่แล้ว

    this video just kinda changed my life))

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Hopefully in a good way 😊

  • @machinimaaquinix3178
    @machinimaaquinix3178 2 ปีที่แล้ว

    Great tutorial, you earned a new sub.

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thanks Machinima, happy you’re enjoying the content! and Thanks for subscribing!!

  • @brahimboughanam1662
    @brahimboughanam1662 ปีที่แล้ว

    oh thank you arjan

  • @yunes7305
    @yunes7305 3 ปีที่แล้ว +1

    I guess it is much easier with R in dealing with json format; otherwise it is a professional tutorial thank you

  • @ruizdani3016
    @ruizdani3016 2 ปีที่แล้ว

    hi, into the documentation where explain about how pydantic type more than 2 dates like return example () -> int, str .....

  • @dr.mikeybee
    @dr.mikeybee 2 ปีที่แล้ว

    Thanks! Good stuff.

  • @italo.buitron
    @italo.buitron ปีที่แล้ว

    We need a Guide with Pydantic and ABC or Protocol

  • @AustrianAnalyst
    @AustrianAnalyst 3 ปีที่แล้ว +1

    Just found your channel. Awesome stuff :)

  • @mohamedtarek8899
    @mohamedtarek8899 2 ปีที่แล้ว

    it's really better for parsing like you what you have done, However if this data is internally, i mean inside my application, i will lose a lot of resources within dynamic checking, although i might use attr class or dataclass for that task...
    thanks for sharing your ideas with us...

  • @SeamusHarper1234
    @SeamusHarper1234 3 ปีที่แล้ว

    The text in the background

  • @olegpopov3180
    @olegpopov3180 3 ปีที่แล้ว

    Thank you for the clear explanation!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Glad it was helpful!

  • @sharifahmed1925
    @sharifahmed1925 2 ปีที่แล้ว

    Hi Arian
    Love your videos 👍🏽
    I wanted to ask if you have any videos explaining how and when to use the __init__ function and the super() function as well as the **kwargs?
    I’ve seen you use them in your videos
    Are these explained in your course on your website?

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

    this is helpful, thanks for sharing.

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

      Glad you enjoyed the content, Lawrence!

  • @tranthanhbao9978
    @tranthanhbao9978 3 ปีที่แล้ว +2

    Please make a video compare Pydantic vs marshmallow

  • @TheWolverine1984
    @TheWolverine1984 2 ปีที่แล้ว +1

    Thank you! I learn some useful stuff from this. Can you define a custom parser for one of the fields? For example if your data is a list of songs with that have a title datafield that is actually both artist and song title separated by ' = '. For example "Metalica - Nothing Else Matters'. Can you define a custom parser that splits this into two separate fields in your model?

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว +2

      I think the root_validation method returns the value to be set in the object, so you can modify the value that you receive there - haven’t tried it though.

    • @TheWolverine1984
      @TheWolverine1984 2 ปีที่แล้ว

      @@ArjanCodes Thanks for the tip!!

  • @charlesking4291
    @charlesking4291 2 ปีที่แล้ว

    When defining the root_validator check (10:00 - 13:00) why do you go to the trouble of adding the "title" field to "check_isbn10_or_isbn13" when it doesn't appear in the output message/error (12:59) ?? Seems like this was a minor bug glossed over ? I think it would be helpful to know which record was incorrect, as referenced by the title field ? Was that the intention ??

  • @valk9819
    @valk9819 2 ปีที่แล้ว

    Will we see Pydantic vs Marshmallow?

  • @nickhodgskin
    @nickhodgskin 3 ปีที่แล้ว +1

    In the custom exception class for "ISBN not provided", what's the benefit of doing self.title = title? It seems awesome for debugging but I didn't see it in the traceback
    Also, awesome video!! I consider myself a bit of a python noob, so I'm always learning new stuff from your videos 😍. Just started a small project using MVC architecture and working with classes. It's been awesome to implement some stuff that I've seen here

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      Thank you Nick! At the moment, that title field is indeed not doing much, but I do think this is really useful, because it allows you to pass better information in the Exception, which you can then later use for debugging, or taking other actions in you application depending on those values. You could add a repr method to the Exception class to print a better message, or it might be possible to turn the ISBN exception into a dataclass, which adds that automatically.

    • @mr7clay
      @mr7clay 3 ปีที่แล้ว

      @@ArjanCodes Is it considered bad form to store a reference to the object in the Exception?

  • @i701Dev
    @i701Dev 3 ปีที่แล้ว

    Subscribed. Thanks for the video!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      You’re welcome. And welcome onboard 😉

  • @sillytechy
    @sillytechy 3 ปีที่แล้ว +1

    Can you do a video on Type hinting in python.

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      Great idea, thank you.

  • @НиколайКостров-ц7с
    @НиколайКостров-ц7с 3 ปีที่แล้ว

    Great video! Thanks for video and link of your Git repository !

  • @MrWorshipMe
    @MrWorshipMe 3 ปีที่แล้ว +2

    I wonder what is the runtime cost for all these extra options...

    • @pointerish
      @pointerish 3 ปีที่แล้ว

      Negligible if any.

    • @MrWorshipMe
      @MrWorshipMe 3 ปีที่แล้ว

      @@pointerish unless you create many instances in a tight loop...

    • @rozarioagro5532
      @rozarioagro5532 3 ปีที่แล้ว +2

      @@pointerish compared to attrs and dataclass, it is very slow, especially when serializing many objects. I don't recommend using it where speed is important. stefan.sofa-rockers.org/2020/05/29/attrs-dataclasses-pydantic/

    • @spotlight-kyd
      @spotlight-kyd 3 ปีที่แล้ว

      @@rozarioagro5532 Thanks for the link to that article. Pretty insightful. And it shows that you should not take claims about speed made by the project itself unquestingly.

  • @RatafakRatafak
    @RatafakRatafak 3 ปีที่แล้ว

    Hi, can you please tell us which VSCode color scheme you are using? Thanks!

  • @glibmar
    @glibmar 2 ปีที่แล้ว

    Hi @ArjabCodes, Thank you for your videos. They are very helpful. Once problem which I'm trying to solve. During the running pydantic model a lot of validation happen. Do you know the way how we can display/print/report these validations? I understand that if data is not valid we will get the error, but I want to see what was validated during the run time. Do you know how to do this?

  • @digitig
    @digitig 2 ปีที่แล้ว

    Of course, in the real world it's annoying that programs dealing with books insist there has to be an ISBN. I have quite a few books from before the introduction of ISBNs (the oldest is from 1711), and I rejected quite a few cataloguing systems because they wouldn't accept some of my books.

  • @vitoanania6042
    @vitoanania6042 2 ปีที่แล้ว

    can you set an order for the objects in pydantic as for dataclasses?

  • @ArachnidAbby
    @ArachnidAbby 2 ปีที่แล้ว

    I just noticed that you look at the keyboard while typing.

  • @abteyeb7969
    @abteyeb7969 2 ปีที่แล้ว

    i dont understood This but u are able in coding thinks

  • @anindyasundarmanna6683
    @anindyasundarmanna6683 3 ปีที่แล้ว

    At 11:15, is writing the condition like this better?
    if not ("isbn_10" in values or "isbn_13" in values):
    Btw Love your content. I was thinking of pydantic when watching your dataclasses video, and then found this. I used pydantic in FastAPI and it's absolutely awesome!

  • @layerabstraction2321
    @layerabstraction2321 3 ปีที่แล้ว

    excuse me , I have a many-to-many sqlalchemy models but how can I create nested ones in Pydantic in order to implement crud?

  • @louieatkins-turkish1349
    @louieatkins-turkish1349 9 หลายเดือนก่อน

    What is pydantic actually doing in these cases? You can do these checks and raise custom exceptions already without pydantic

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

    00:03 Pydantic offers data validation, conversion, and sanitizing features.
    01:44 Using Pydantic to work with data, add validation and sanitation
    03:46 Pydantic is helpful for unpacking data items into keyword arguments and easily printing data.
    05:27 The video discusses the usage of dataclasses and the validation of ISBN 10 field.
    07:53 Using Pydantic to add validation functions to ensure data cleanliness and conformance to defined rules.
    10:01 Adding a root validator to check if a book has either an ISBN 10 or an ISBN 13
    12:39 Using Pydantic to create immutable objects and perform data processing.
    14:46 Pydantic is a good solution for importing and validating data.
    Crafted by Merlin AI.

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

      Was this timestamped TOC created by AI?

  • @Yupppi
    @Yupppi 3 ปีที่แล้ว +1

    2 months ago: If you're not using python data classes yet, you should
    3 weeks ago: Do we still need data classes?

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      The answer to the second question was yes ;).

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

    Pydantic's requirement that the values can only be set from dictionaries is a bit annoying. In some cases reading in an array from JSON is good enough to initialize an object. Not sure why it's so inflexible in this.

  • @ChrisHalden007
    @ChrisHalden007 3 ปีที่แล้ว

    Great video!!!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Glad you liked it, Chris!

  • @sekus
    @sekus 3 ปีที่แล้ว

    Can you post the link for your code that you stated in this video on Github? I can't seem it in the description. Thank you!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      I somehow forgot to add that. I put the link in the description.

  • @jval7
    @jval7 2 ปีที่แล้ว

    amazing!

    • @ArjanCodes
      @ArjanCodes  2 ปีที่แล้ว

      Thank you - glad you liked it!

  • @alexforget
    @alexforget 9 หลายเดือนก่อน +1

    how is he able to type that fast?

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

      The video speeds up

  • @bluebabboon
    @bluebabboon ปีที่แล้ว

    Bro what is your keyboard? It's so soothng to hear and type i guess?

    • @ArjanCodes
      @ArjanCodes  ปีที่แล้ว

      Keychron K3 :)

    • @bluebabboon
      @bluebabboon ปีที่แล้ว

      @@ArjanCodes cherry mx silver? or red?

  • @adamlasry1691
    @adamlasry1691 3 ปีที่แล้ว

    Thank you

  • @jesnajames2151
    @jesnajames2151 3 ปีที่แล้ว

    Is it possible to use validator to check if either isbn_10 or isbn_13 is provided? Since we check two fields, is root_validator necessary?

    •  2 ปีที่แล้ว

      As a class method it looks like the validator has access to only the single attribute value. Or did you mean combining the two attributes into one?

  • @aruniyer1833
    @aruniyer1833 3 ปีที่แล้ว

    Is there any course available for purchase

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      Thanks for asking. Not yet, but I am working on something.

  • @xiopode1
    @xiopode1 3 ปีที่แล้ว

    In python3.9, you no longer need typing.List, do you ?

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      Correct! I’ve recently switched to using the built-in list in my videos.

    •  2 ปีที่แล้ว

      If you add "from ___future___ import annotations" you can use the built-in classes (with some exceptions) in Python 3.7+ ------ Note: I am not able to find the specification of the TH-cam markup to prevent turning "future" between underscores into " _future_ " (italics).

  • @jeancerrien3016
    @jeancerrien3016 3 ปีที่แล้ว +1

    Great video, as usual! 👍 The construct sum(foo for bar in baz) is new to me (cf. weighted_sum calculation in line 43). I expected a pair of parentheses for the generator, as in 'g = (foo ... baz), and another pair for the call to sum. Indeed, putting in the second pair yields the same result. Why can one get away with just one pair?

    • @traal
      @traal 3 ปีที่แล้ว +2

      A generator expression is valid as long as it's the only thing inside any pair of parentheses. In the case of a function call, it becomes the one and only argument to the function. And many standard functions accept a single iterable as an argument, such as min(), max() and sum().
      For more info see PEP 289 -- Generator Expressions. 😊

  • @lospaturno
    @lospaturno 3 ปีที่แล้ว

    Can you make just SOME attributes static?

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Can you clarify what you mean?

    • @lospaturno
      @lospaturno 3 ปีที่แล้ว

      @@ArjanCodes sorry: I wondered if you can make just some of the attributes frozen, as you did with allow_mutation = False, instead of the whole instance. Say that I want to have some unmutable attributes (name, ISBN) and some mutable (e.g. counter of books in my library). is it possible?

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +1

      As far as I can see, that’s not possible with Pydantic unfortunately.

    • @lospaturno
      @lospaturno 3 ปีที่แล้ว

      @@ArjanCodes ah darn. thank you for taking the time to check, tho. :)

  • @Daniel_Zhu_a6f
    @Daniel_Zhu_a6f 3 ปีที่แล้ว

    Doesn't look any different from dataclasses. it just has slightly different syntaxis.

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

    Hall Scott Thompson Kevin Rodriguez Patricia

  • @MariuszWoloszyn
    @MariuszWoloszyn 3 ปีที่แล้ว

    One shall NOT store price as float.

    • @RatafakRatafak
      @RatafakRatafak 3 ปีที่แล้ว

      why?

    • @MariuszWoloszyn
      @MariuszWoloszyn 3 ปีที่แล้ว

      @@RatafakRatafak Try `0.1+0.2` and you'll get `0.30000000000000004` which is clearly wrong. Floats are not suitable for prices because they do not have absolute precision (it does not matter if you use 32, 64 or even 128 or 256 floats for that matter). Floats are great for engineering and many other purposes but not for prices.

    • @RatafakRatafak
      @RatafakRatafak 3 ปีที่แล้ว

      @@MariuszWoloszyn Yes, makes sense. So which python type would you recommend to use instead of float?

    • @MariuszWoloszyn
      @MariuszWoloszyn 3 ปีที่แล้ว +1

      @@RatafakRatafak most commonly it's just int. Depending on the precision that you require you just store cents or fractions of cents (like pips or even less) and scale the value when presenting. There's also the Decimal type but it's more expensive thus more often used for precise mathematical computations than finance.

  • @connienashasa2745
    @connienashasa2745 24 วันที่ผ่านมา

    Garcia Matthew Rodriguez William Johnson Patricia

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

    Miller Barbara Anderson Angela Gonzalez Jennifer

  • @rajveersingh2056
    @rajveersingh2056 3 ปีที่แล้ว +1

    You look like ashish chanchlani

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว

      Ha, I had to look him up :).

  • @apoorvsrivastava9677
    @apoorvsrivastava9677 2 ปีที่แล้ว

    bro u look like Ashish Chanchalani look him up 🙂

  • @tcratius1748
    @tcratius1748 3 ปีที่แล้ว

    This is how university should be, free until you get me a job.

  • @mishmohd
    @mishmohd 2 ปีที่แล้ว

    I thought I knew how to define classes and methods 🥲

  • @tmmrtn
    @tmmrtn 3 ปีที่แล้ว +46

    3:21 Python 3.9 deprecated typing.List in favor of built-in type list (or dict, set. tuple, etc), which is much nicer because you don't need to import anything. (Additionally, there were many other deprecations from the typing module in favor of their collections.abc counterparts, so make sure to check that out too). Really these days, I only go to typing for "type theory" kind of stuff, like Any and Optional. Great video nonetheless! I'm a big user of attrs, which fills a a similar, but different, void, and didn't really know how they compared until I watched this video. Thanks!

    • @ArjanCodes
      @ArjanCodes  3 ปีที่แล้ว +13

      Thank Tim! I learn something new every day, thanks for pointing that out. I’ll look at it and switch over to the built-in types in my videos.

    • @Kevin-jm1go
      @Kevin-jm1go 2 ปีที่แล้ว

      True that you dont need to import anything, but with typing.List you can also specify whats inside the list.

    • @tmmrtn
      @tmmrtn 2 ปีที่แล้ว +5

      @@Kevin-jm1go That also works with the built-ins. For example, `foo: list[str] = ['hi', 'there']` works as you'd expect. Try it out!

    • @JGnLAU8OAWF6
      @JGnLAU8OAWF6 ปีที่แล้ว +2

      And now Optional[something] can be replaced with something | None

    • @_DRMR_
      @_DRMR_ ปีที่แล้ว +1

      if you want your code to run on multiple version of python it's still useful to use the import

  • @NatalieMorgan-q9r
    @NatalieMorgan-q9r หลายเดือนก่อน

    Moore Eric Gonzalez Jessica Young Ronald

  • @AndreNitschke
    @AndreNitschke ปีที่แล้ว +1

    When not write a Rest API, why not using attrs instead of pydantic? Is faster and not so resource hungry.

  • @songokussj4cz
    @songokussj4cz 3 ปีที่แล้ว +1

    Very nice, I didn't know about that. Is it good for filtering data too? For example: return all books that have title starting with xxx (but without for-cycle, more like JSONPath?

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

    Dataclasses wouldn't ignore any additional attribute in the dataset used to initialize an instance of the class, it will always raise an Exception, another beautiful thing about pydantic, pydantic will just ignore any extras. Which comes in very handy when using them to model third-party response for syntax highlighting rather then just relying on dictionaries.

  • @CarmenMuniz-m2x
    @CarmenMuniz-m2x 27 วันที่ผ่านมา

    Martin Richard Thompson Donna Wilson Christopher