Pydantic is OP, here's why

  Рет қаралды 23,343

Carberra

Carberra

Күн бұрын

Пікірлер: 75
@DuncanBooth
@DuncanBooth 3 ай бұрын
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 ай бұрын
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 ай бұрын
@@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 ай бұрын
The new version of Pydantic is re-written in Rust, should be a lot faster than before.
@Carberra
@Carberra 3 ай бұрын
I've seen benchmarks claiming it's about 7x as fast as V1, didn't know that was the reason though!
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 3 ай бұрын
@@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 ай бұрын
@@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
@JerrellMerica-c8z
@JerrellMerica-c8z Ай бұрын
Clark Jason Young Christopher Brown Amy
@ThomasMartin-m9x
@ThomasMartin-m9x Ай бұрын
White Nancy Lee Joseph Brown Kimberly
@ruslanoid
@ruslanoid 3 ай бұрын
TIL about `kebab-case` (until now just called it dashes or hyphens)
@HerozTech
@HerozTech 3 ай бұрын
one more thing What color scheme are you using, it looks awesome
@JoeyojHolmsop
@JoeyojHolmsop Ай бұрын
Hall Jeffrey Jones Frank Rodriguez Susan
@roseesewinter5111
@roseesewinter5111 Ай бұрын
Allen Timothy Miller Christopher Martinez George
@gownerjones
@gownerjones 3 ай бұрын
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 ай бұрын
@@Carberra Well I'll be pedantic and pronounce it pie-dantic just for the irony lol
@santiagohal6747
@santiagohal6747 3 ай бұрын
I love this. This is brilliant.
@CooperArmstrong-y4m
@CooperArmstrong-y4m Ай бұрын
Brown Nancy Lewis Jason Miller Kenneth
@HelenLangworthy-j2t
@HelenLangworthy-j2t 24 күн бұрын
Garcia Margaret Allen Paul Martinez Michelle
@danielsbosworth474
@danielsbosworth474 18 күн бұрын
Davis Jose Gonzalez Donald Thomas Helen
@DouglasParish-w5m
@DouglasParish-w5m Ай бұрын
Perez Jennifer Hall Daniel Allen Dorothy
@NicholasMichaud-u7e
@NicholasMichaud-u7e 27 күн бұрын
Young Lisa Lewis Jason Robinson Thomas
@mjackstewart
@mjackstewart 2 ай бұрын
Does it include Michaelmas?
@ayehavgunne
@ayehavgunne 3 ай бұрын
I like the library called apischema which lets you use dataclasses to achieve the same thing.
@HerozTech
@HerozTech 3 ай бұрын
I was recently learning golang and coming back to python i missed struct but pydantic more than makes up for that Great video👍
@MoniRina
@MoniRina Ай бұрын
Jones Lisa Williams Jose Lewis Gary
@pythonwithjames
@pythonwithjames 3 ай бұрын
Really nice!
@ChrisAdaline
@ChrisAdaline 3 ай бұрын
Who else had to look up what bunting is?
@murphygreen8484
@murphygreen8484 3 ай бұрын
This guy
@Carberra
@Carberra 3 ай бұрын
How very unpatriotic of you! /j
@Mywifeleftme3
@Mywifeleftme3 2 ай бұрын
My wife left me
@aeggeska1
@aeggeska1 23 күн бұрын
What is bunting
@davidmurphy563
@davidmurphy563 3 ай бұрын
3:33 It took you a month to release this video? Are they better when they age? ;)
@Carberra
@Carberra 3 ай бұрын
Like a fine wine 🍷
@illiasukonnik9966
@illiasukonnik9966 3 ай бұрын
Excellent video, thanks! Please use caching when playing with external APIs, be polite ))
@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 ай бұрын
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.
@JohnMitchellCalif
@JohnMitchellCalif 2 ай бұрын
super useful! Subscribed
@Carberra
@Carberra 2 ай бұрын
Thank you!
@basb3603
@basb3603 3 ай бұрын
What theme is that?
@Carberra
@Carberra 3 ай бұрын
Link to setup is in the description (:
@ЕфросинияКуклева
@ЕфросинияКуклева 18 күн бұрын
Jackson Melissa Lopez Jeffrey Miller Timothy
@NatalieMorgan-q9r
@NatalieMorgan-q9r Ай бұрын
Harris Shirley Garcia Karen Perez Frank
@DennisJoanna-s3x
@DennisJoanna-s3x 17 күн бұрын
Williams Brian Miller Larry Thomas Amy
@ChaucerGrace-r1j
@ChaucerGrace-r1j 28 күн бұрын
Lee Amy White Brian Jones Patricia
@BealleMoriniE
@BealleMoriniE Ай бұрын
Wilson Ruth Wilson Jeffrey Walker Timothy
@CarmenMuniz-m2x
@CarmenMuniz-m2x Ай бұрын
Lee Scott Thompson Frank Walker Brenda
@christianlinux8283
@christianlinux8283 3 ай бұрын
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.
@SusiePerez-d7o
@SusiePerez-d7o Ай бұрын
Harris Scott Williams Donna Lopez Karen
@shadmansudipto7287
@shadmansudipto7287 3 ай бұрын
Lol. Use a non scripting language.
@greob
@greob 3 ай бұрын
Pydantic is very interesting, and this makes me want to try using it more. Thanks for sharing!
@Carberra
@Carberra 3 ай бұрын
You're very welcome!
Python's contextlib is a HIDDEN GEM
14:55
Carberra
Рет қаралды 11 М.
Liked Pydantic? You'll LOVE Msgspec
15:53
Carberra
Рет қаралды 12 М.
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 138 МЛН
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 2,9 МЛН
Life hack 😂 Watermelon magic box! #shorts by Leisi Crazy
00:17
Leisi Crazy
Рет қаралды 25 МЛН
Are metaclasses the HARDEST thing in Python?
20:41
Carberra
Рет қаралды 2,3 М.
Being Competent With Coding Is More Fun
11:13
TheVimeagen
Рет қаралды 86 М.
Python 3.13's new REPL is AMAZING
10:21
Carberra
Рет қаралды 56 М.
*Next-door 10x Software Engineer* [FULL]
4:50
Programmers are also human
Рет қаралды 657 М.
Avoid These BAD Practices in Python OOP
24:42
ArjanCodes
Рет қаралды 56 М.
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 275 М.
Are descriptors the most MISUNDERSTOOD part of Python?
16:42
Carberra
Рет қаралды 11 М.
Why I prefer attrs over dataclasses
6:21
mCoding
Рет қаралды 64 М.
Generics are VITAL in typed Python
16:54
Carberra
Рет қаралды 9 М.
How Strong is Tin Foil? 💪
00:26
Preston
Рет қаралды 138 МЛН