Pydantic is OP, here's why

  Рет қаралды 24,939

Carberra

Carberra

Күн бұрын

Пікірлер
@DuncanBooth
@DuncanBooth 6 ай бұрын
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 6 ай бұрын
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 6 ай бұрын
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 6 ай бұрын
@@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 3 ай бұрын
This is a great tip, thanks for sharing!
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 6 ай бұрын
The new version of Pydantic is re-written in Rust, should be a lot faster than before.
@Carberra
@Carberra 6 ай бұрын
I've seen benchmarks claiming it's about 7x as fast as V1, didn't know that was the reason though!
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 6 ай бұрын
@@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 6 ай бұрын
i think if people have the time they should learn Rust!
@ButchCassidyAndSundanceKid
@ButchCassidyAndSundanceKid 6 ай бұрын
@@irlshrek The question is "IF people have the time".
@gabriellevesque2185
@gabriellevesque2185 6 ай бұрын
​@@ButchCassidyAndSundanceKid Same League as C 😅
@JohnMitchellCalif
@JohnMitchellCalif 5 ай бұрын
super useful! Subscribed
@Carberra
@Carberra 5 ай бұрын
Thank you!
@santiagohal6747
@santiagohal6747 6 ай бұрын
I love this. This is brilliant.
@ayehavgunne
@ayehavgunne 6 ай бұрын
I like the library called apischema which lets you use dataclasses to achieve the same thing.
@HerozTech
@HerozTech 6 ай бұрын
I was recently learning golang and coming back to python i missed struct but pydantic more than makes up for that Great video👍
@mjackstewart
@mjackstewart 5 ай бұрын
Does it include Michaelmas?
@davidmurphy563
@davidmurphy563 6 ай бұрын
3:33 It took you a month to release this video? Are they better when they age? ;)
@Carberra
@Carberra 6 ай бұрын
Like a fine wine 🍷
@HerozTech
@HerozTech 6 ай бұрын
one more thing What color scheme are you using, it looks awesome
@konstantinub
@konstantinub 6 ай бұрын
What's the difference between Pydantic and Marshmallow? Can they be used to accomplish the same things?
@Carberra
@Carberra 6 ай бұрын
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.
@illiasukonnik9966
@illiasukonnik9966 6 ай бұрын
Excellent video, thanks! Please use caching when playing with external APIs, be polite ))
@pythonwithjames
@pythonwithjames 6 ай бұрын
Really nice!
@basb3603
@basb3603 6 ай бұрын
What theme is that?
@Carberra
@Carberra 6 ай бұрын
Link to setup is in the description (:
@aeggeska1
@aeggeska1 3 ай бұрын
What is bunting
@nibblrrr7124
@nibblrrr7124 2 ай бұрын
Putting up national flags as decoration. (Had to look it up too.)
@greob
@greob 6 ай бұрын
Pydantic is very interesting, and this makes me want to try using it more. Thanks for sharing!
@Carberra
@Carberra 6 ай бұрын
You're very welcome!
@ruslanoid
@ruslanoid 6 ай бұрын
TIL about `kebab-case` (until now just called it dashes or hyphens)
@gownerjones
@gownerjones 6 ай бұрын
Isn't the whole point of it being spelled "pydantic" that you pronounce it "pie-dantic"? :D
@Carberra
@Carberra 6 ай бұрын
It may well be, I actually don't know, never heard anyone else say it 😅
@gownerjones
@gownerjones 6 ай бұрын
@@Carberra Well I'll be pedantic and pronounce it pie-dantic just for the irony lol
@christianlinux8283
@christianlinux8283 6 ай бұрын
I thought subclass config was deprecated
@Carberra
@Carberra 6 ай бұрын
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 5 ай бұрын
@@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.
@Mywifeleftme3
@Mywifeleftme3 5 ай бұрын
My wife left me
@NatalieMorgan-q9r
@NatalieMorgan-q9r 4 ай бұрын
Harris Shirley Garcia Karen Perez Frank
@MoniRina
@MoniRina 4 ай бұрын
Jones Lisa Williams Jose Lewis Gary
@ChrisAdaline
@ChrisAdaline 6 ай бұрын
Who else had to look up what bunting is?
@murphygreen8484
@murphygreen8484 6 ай бұрын
This guy
@Carberra
@Carberra 6 ай бұрын
How very unpatriotic of you! /j
@CooperArmstrong-y4m
@CooperArmstrong-y4m 4 ай бұрын
Brown Nancy Lewis Jason Miller Kenneth
@damonguzman
@damonguzman 6 ай бұрын
Explainer is better than code along.
@BealleMoriniE
@BealleMoriniE 4 ай бұрын
Wilson Ruth Wilson Jeffrey Walker Timothy
@SusiePerez-d7o
@SusiePerez-d7o 4 ай бұрын
Harris Scott Williams Donna Lopez Karen
@JoeyojHolmsop
@JoeyojHolmsop 4 ай бұрын
Hall Jeffrey Jones Frank Rodriguez Susan
@shadmansudipto7287
@shadmansudipto7287 6 ай бұрын
Lol. Use a non scripting language.
Python's contextlib is a HIDDEN GEM
14:55
Carberra
Рет қаралды 12 М.
Liked Pydantic? You'll LOVE Msgspec
15:53
Carberra
Рет қаралды 13 М.
Жездуха 42-серия
29:26
Million Show
Рет қаралды 2,6 МЛН
«Жат бауыр» телехикаясы І 30 - бөлім | Соңғы бөлім
52:59
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 340 М.
I Stopped Using Everything Else Once I Found Pydantic
13:45
Eric Roby
Рет қаралды 3,5 М.
Next Gen Hacker?
43:03
David Bombal
Рет қаралды 236 М.
Pydantic is STILL all you need: Jason Liu
15:21
AI Engineer
Рет қаралды 11 М.
The Weirdest Language I've Ever Seen (I kinda love it...)
58:11
Theo - t3․gg
Рет қаралды 74 М.
5 Useful Python Decorators (ft. Carberra)
14:34
Indently
Рет қаралды 110 М.
SAVE TIME and reduce boilerplate with dataclasses
18:58
Carberra
Рет қаралды 3,8 М.
DuckDB in Python - The Next Pandas Killer?
19:32
NeuralNine
Рет қаралды 37 М.
Pydantic is all you need: Jason Liu
17:55
AI Engineer
Рет қаралды 185 М.
The BIGGEST feature in EVERY Python release (ft. @Indently)
13:44