Pydantic is OP, here's why

Поділитися
Вставка
  • Опубліковано 2 жов 2024

КОМЕНТАРІ • 75

  • @DuncanBooth
    @DuncanBooth 3 місяці тому +27

    The newer version of Pydantic encourages you to write validators using Annotated. For example:
    from pydantic import BaseModel, AfterValidator
    from typing import Annotated
    def validate_positive(value: int) -> int:
    assert value > 0, "must be > 0"
    PositiveInt = Annotated[int, AfterValidator(validate_positive)]
    class Order(BaseModel):
    id: int
    item_name: str
    quantity: PositiveInt
    and now you have a reusable type annotation for positive integers.

    • @Carberra
      @Carberra  3 місяці тому

      I've never much liked Annotated, just looks really messy and ugly. That looks neat though -- where in the docs did you find that? Pretty sure it's not in the Validators section.

    • @VictorOliveira-lg2qg
      @VictorOliveira-lg2qg 3 місяці тому +4

      Even better, Pydantic already provides types like that for convenience, which uses annotations. In this case, you can import PositiveInt like this:
      from pydantic import PositiveInt

    • @DuncanBooth
      @DuncanBooth 3 місяці тому +1

      @@Carberra I replied with the link but can't see my reply so perhaps youtube cut out the link. It's under concepts/validators, literally the first thing under the Validators heading.

    • @ndamu-soft
      @ndamu-soft 14 днів тому

      This is a great tip, thanks for sharing!

  • @ButchCassidyAndSundanceKid
    @ButchCassidyAndSundanceKid 3 місяці тому +37

    The new version of Pydantic is re-written in Rust, should be a lot faster than before.

    • @Carberra
      @Carberra  3 місяці тому +6

      I've seen benchmarks claiming it's about 7x as fast as V1, didn't know that was the reason though!

    • @ButchCassidyAndSundanceKid
      @ButchCassidyAndSundanceKid 3 місяці тому +1

      @@Carberra Holy crap ! I thought it was fast, I didn't know it'd be that fast. I suppose the only other framework it can beat that is the gPRC and protobuf.
      v1 was written in Python, but v2 was written in Rust which is in the same league as C++, that probably explains about the superior performance.

    • @irlshrek
      @irlshrek 3 місяці тому

      i think if people have the time they should learn Rust!

    • @ButchCassidyAndSundanceKid
      @ButchCassidyAndSundanceKid 3 місяці тому +1

      @@irlshrek The question is "IF people have the time".

    • @gabriellevesque2185
      @gabriellevesque2185 3 місяці тому

      ​@@ButchCassidyAndSundanceKid Same League as C 😅

  • @WatomaSjdob-b6o
    @WatomaSjdob-b6o 21 день тому

    Rodriguez Mary Thompson Brenda Thompson Kimberly

  • @DinaDurbin-e2v
    @DinaDurbin-e2v 18 днів тому

    Allen Robert White Jessica Hernandez Timothy

  • @santiagohal6747
    @santiagohal6747 3 місяці тому

    I love this. This is brilliant.

  • @ruslanoid
    @ruslanoid 3 місяці тому +1

    TIL about `kebab-case` (until now just called it dashes or hyphens)

  • @JerrellMerica-c8z
    @JerrellMerica-c8z Місяць тому

    Clark Jason Young Christopher Brown Amy

  • @ThomasMartin-m9x
    @ThomasMartin-m9x Місяць тому

    White Nancy Lee Joseph Brown Kimberly

  • @JoeyojHolmsop
    @JoeyojHolmsop Місяць тому

    Hall Jeffrey Jones Frank Rodriguez Susan

  • @gownerjones
    @gownerjones 3 місяці тому +2

    Isn't the whole point of it being spelled "pydantic" that you pronounce it "pie-dantic"? :D

    • @Carberra
      @Carberra  3 місяці тому

      It may well be, I actually don't know, never heard anyone else say it 😅

    • @gownerjones
      @gownerjones 3 місяці тому +3

      @@Carberra Well I'll be pedantic and pronounce it pie-dantic just for the irony lol

  • @CooperArmstrong-y4m
    @CooperArmstrong-y4m Місяць тому

    Brown Nancy Lewis Jason Miller Kenneth

  • @danielsbosworth474
    @danielsbosworth474 18 днів тому

    Davis Jose Gonzalez Donald Thomas Helen

  • @DouglasParish-w5m
    @DouglasParish-w5m Місяць тому

    Perez Jennifer Hall Daniel Allen Dorothy

  • @ayehavgunne
    @ayehavgunne 3 місяці тому +1

    I like the library called apischema which lets you use dataclasses to achieve the same thing.

  • @NicholasMichaud-u7e
    @NicholasMichaud-u7e 27 днів тому

    Young Lisa Lewis Jason Robinson Thomas

  • @MoniRina
    @MoniRina Місяць тому

    Jones Lisa Williams Jose Lewis Gary

  • @HelenLangworthy-j2t
    @HelenLangworthy-j2t 25 днів тому

    Garcia Margaret Allen Paul Martinez Michelle

  • @HerozTech
    @HerozTech 3 місяці тому +1

    I was recently learning golang and coming back to python i missed struct but pydantic more than makes up for that
    Great video👍

  • @HerozTech
    @HerozTech 3 місяці тому +1

    one more thing
    What color scheme are you using, it looks awesome

  • @pythonwithjames
    @pythonwithjames 3 місяці тому

    Really nice!

  • @mjackstewart
    @mjackstewart 2 місяці тому

    Does it include Michaelmas?

  • @aeggeska1
    @aeggeska1 23 дні тому

    What is bunting

  • @ChrisAdaline
    @ChrisAdaline 3 місяці тому +10

    Who else had to look up what bunting is?

  • @illiasukonnik9966
    @illiasukonnik9966 3 місяці тому

    Excellent video, thanks!
    Please use caching when playing with external APIs, be polite ))

  • @davidmurphy563
    @davidmurphy563 3 місяці тому +1

    3:33 It took you a month to release this video? Are they better when they age? ;)

    • @Carberra
      @Carberra  3 місяці тому +6

      Like a fine wine 🍷

  • @damonguzman
    @damonguzman 2 місяці тому

    Explainer is better than code along.

  • @konstantinub
    @konstantinub 3 місяці тому

    What's the difference between Pydantic and Marshmallow? Can they be used to accomplish the same things?

    • @Carberra
      @Carberra  3 місяці тому +1

      I'm not sure how functionally different they are, but Marshmallow is certainly designed to used to define ORM-agnostic schemas for databases and convert to and from JSON data. I believe you can do the same with Pydantic, but I haven't used enough of Marshmallow to delve into the differences.

  • @Mywifeleftme3
    @Mywifeleftme3 2 місяці тому +2

    My wife left me

  • @JohnMitchellCalif
    @JohnMitchellCalif 2 місяці тому

    super useful! Subscribed

  • @basb3603
    @basb3603 3 місяці тому

    What theme is that?

    • @Carberra
      @Carberra  3 місяці тому

      Link to setup is in the description (:

  • @roseesewinter5111
    @roseesewinter5111 Місяць тому

    Allen Timothy Miller Christopher Martinez George

  • @christianlinux8283
    @christianlinux8283 3 місяці тому +1

    I thought subclass config was deprecated

    • @Carberra
      @Carberra  3 місяці тому

      Huh, so it is. Why did they not remove that in 2.0? I just went with it cos it worked so I thought it hadn't changed.

    • @LSHDackel
      @LSHDackel 2 місяці тому

      @@Carberra The folks from pydantic put a lot of effort into making the v1 -> v2 migration as painless as possible, so many old things still work but normally give a DeprecationWarning. But DeprecationWarning's in python are by default silenced in user code and only raised in library code. There also is the bump-pydantic project (same github orga as pydantic) to make migrating even easier.

  • @ЕфросинияКуклева
    @ЕфросинияКуклева 18 днів тому

    Jackson Melissa Lopez Jeffrey Miller Timothy

  • @DennisJoanna-s3x
    @DennisJoanna-s3x 17 днів тому

    Williams Brian Miller Larry Thomas Amy

  • @NatalieMorgan-q9r
    @NatalieMorgan-q9r Місяць тому

    Harris Shirley Garcia Karen Perez Frank

  • @ChaucerGrace-r1j
    @ChaucerGrace-r1j 28 днів тому

    Lee Amy White Brian Jones Patricia

  • @CarmenMuniz-m2x
    @CarmenMuniz-m2x Місяць тому

    Lee Scott Thompson Frank Walker Brenda

  • @BealleMoriniE
    @BealleMoriniE Місяць тому

    Wilson Ruth Wilson Jeffrey Walker Timothy

  • @SusiePerez-d7o
    @SusiePerez-d7o Місяць тому

    Harris Scott Williams Donna Lopez Karen

  • @shadmansudipto7287
    @shadmansudipto7287 3 місяці тому

    Lol. Use a non scripting language.

  • @greob
    @greob 3 місяці тому +1

    Pydantic is very interesting, and this makes me want to try using it more. Thanks for sharing!

    • @Carberra
      @Carberra  3 місяці тому

      You're very welcome!