Pydantic is OP, here's why
22,096
Publicado 2024-07-01
00:00 - Intro
00:44 - Installing Pydantic [1]
01:12 - Creating models [2]
04:15 - Validating inputs [3]
08:10 - Using Pydantic with an API [4-5]
17:33 - Outro
[1] docs.pydantic.dev/latest/install
[2] docs.pydantic.dev/latest/concepts/models
[3] docs.pydantic.dev/latest/concepts/validators
[4] https:://www.gov.uk/bank-holidays.json
[5] docs.pydantic.dev/latest/api/aliases
—
If you want to see more of me, join my Discord server!
discord.gg/5vVgQpK
I get a lot of people asking, so here's my setup!
• Visual Studio Code: • My Visual Studio Code setup! (2024)
• Terminal: • Make your terminal look AMAZING
• Desk/recording gear: kit.co/Carberra
• PC build: uk.pcpartpicker.com/list/TmzGYN
Affiliations (I may earn a commission):
• Codecrafters -- 40% off any plan: app.codecrafters.io/join?via=parafoxia
• Keeper Password Manager -- 30% off your first year: keeper.io/r/EX4FB1C
—
If you have any questions, don't hesitate to ask in the comments! I'll try and answer as soon as I can, providing someone else hasn't already done so.
#python #coding #howto
Todos los comentarios (21)
-
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.
-
The new version of Pydantic is re-written in Rust, should be a lot faster than before.
-
I like the library called apischema which lets you use dataclasses to achieve the same thing.
-
I was recently learning golang and coming back to python i missed struct but pydantic more than makes up for that Great video👍
-
I love this. This is brilliant.
-
Whats the plugin that autofills your variables and stuff? Thats awesome
-
Does it include Michaelmas?
-
super useful! Subscribed
-
Really nice!
-
Excellent video, thanks! Please use caching when playing with external APIs, be polite ))
-
one more thing What color scheme are you using, it looks awesome
-
What's the difference between Pydantic and Marshmallow? Can they be used to accomplish the same things?
-
3:33 It took you a month to release this video? Are they better when they age? ;)
-
TIL about `kebab-case` (until now just called it dashes or hyphens)
-
Pydantic is very interesting, and this makes me want to try using it more. Thanks for sharing!
-
What theme is that?
-
Isn't the whole point of it being spelled "pydantic" that you pronounce it "pie-dantic"? :D
-
I thought subclass config was deprecated
-
Who else had to look up what bunting is?
-
My wife left me