Pydantic Introduction - Models, Fields, Constrained Types, Validator Functions and Model Exports

  Рет қаралды 14,339

BugBytes

BugBytes

Күн бұрын

In this video, we dive into the Pydantic library in Python. This is based on the following blog post:
www.bugbytes.io/posts/introdu...
We'll learn a number of things, including:
1. How to define Pydantic model classes and fields with type-annotations.
2. How to define Optional fields and constrained fields
3. How to work with complex Python types such as UUID, Enum and date objects
4. How to define a custom validator function for a field on the model
5. How to export models to JSON and Python dictionaries
Github data: github.com/bugbytes-io/datasets
📌 𝗖𝗵𝗮𝗽𝘁𝗲𝗿𝘀:
00:00 Intro
01:13 Analysis of the structure of the data to model
02:47 Installing Pydantic and Requests packages
04:02 Defining Pydantic model class
06:22 Creating Optional fields on the Pydantic model
11:09 Constrained fields in Pydantic
15:23 Using custom validator functions in Pydantic
19:54 Using Enums as types in Pydantic models
22:22 Exporting Pydantic models to dictionaries and JSON
☕️ 𝗕𝘂𝘆 𝗺𝗲 𝗮 𝗰𝗼𝗳𝗳𝗲𝗲:
To support the channel and encourage new videos, please consider buying me a coffee here:
ko-fi.com/bugbytes
▶️ Full Playlist:
• Pydantic
𝗦𝗼𝗰𝗶𝗮𝗹 𝗠𝗲𝗱𝗶𝗮:
📖 Blog: www.bugbytes.io/posts/introdu...
👾 Github: github.com/bugbytes-io/datasets
🐦 Twitter: / bugbytesio
📚 𝗙𝘂𝗿𝘁𝗵𝗲𝗿 𝗿𝗲𝗮𝗱𝗶𝗻𝗴 𝗮𝗻𝗱 𝗶𝗻𝗳𝗼𝗿𝗺𝗮𝘁𝗶𝗼𝗻:
Pydantic Blog post: www.bugbytes.io/posts/introdu...
Github Dataset: github.com/bugbytes-io/datasets
Pydantic Models: docs.pydantic.dev/usage/models/
Pydantic Validators: docs.pydantic.dev/usage/valid...
#python #pydantic #datascience

Пікірлер: 42
@chitreddysairam
@chitreddysairam 2 ай бұрын
Awesome introduction to Pydantic. Will be grateful if you plan a video for Pydantic V2
@RedShipsofSpainAgain
@RedShipsofSpainAgain 9 ай бұрын
Btw, a way to display the JSON response in a much more readable way is to use the 'pprint()' function from the pprint module. Simply using pprint(response.json()) rather than print(response.json()) will give you a more legible rendering of your json response. I find it super helpful when parsing through deeply nested JSON.
@robhafemeister3100
@robhafemeister3100 Жыл бұрын
Great video, perfect timing, working on a Django-Ninja project. Really look forward to your content.
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks a lot Rob, and thanks for your support. Pydantic underpins a lot of good up-and-coming Python stuff - good to get to grips with the fundamentals! Thanks again
@je9625
@je9625 9 ай бұрын
My new favorite Python channel. Job well done !
@diegosantosmoto
@diegosantosmoto 7 ай бұрын
That's a great video. I code with javascript and I wanna learn python for web. 👍
@bugbytes3923
@bugbytes3923 7 ай бұрын
Thanks a lot!
@i-see-right-through-you
@i-see-right-through-you 6 ай бұрын
great pacing and completeness - thx!
@bugbytes3923
@bugbytes3923 6 ай бұрын
Thanks a lot!
@swelanauguste6176
@swelanauguste6176 Жыл бұрын
I really look forward to your videos. Thanks a lot
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks very much! Appreciate it!
@mercy.yerram5671
@mercy.yerram5671 3 ай бұрын
This is a great video. Thank you very much. Im working on a project using pydantic library.
@bugbytes3923
@bugbytes3923 3 ай бұрын
Thank you! All the best with your project, hope this helped.
@Profutbol576
@Profutbol576 Жыл бұрын
You are an absolute legend. Truly, between this and your playlists on Django/HTMX, you have saved me from many a headache. Cheers, man.
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks very much! Greatly appreciated - cheers :)
@AliHassan-wc6nb
@AliHassan-wc6nb Жыл бұрын
​@@bugbytes3923can we use pydanric with django?
@davidsulaberidze5978
@davidsulaberidze5978 Жыл бұрын
Great tutorial. Thank you very much
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks for watching!
@python360
@python360 Жыл бұрын
Thank you. Subscribed!
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks a lot!
@arunima2916
@arunima2916 Жыл бұрын
Great content!! Thank you!!
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thank you very much! Much appreciated.
@joaquingonzalez2297
@joaquingonzalez2297 10 ай бұрын
Your tutorial save me from several headaches. Thanks for this I appreciate it 😎
@bugbytes3923
@bugbytes3923 10 ай бұрын
Thanks a lot, glad it was helpful!
@ekkalukeksook6477
@ekkalukeksook6477 3 ай бұрын
This is awesome. You make me love Python more than usual. Much obliged.
@bugbytes3923
@bugbytes3923 3 ай бұрын
Thanks a lot!
@ProfeDuilio
@ProfeDuilio Жыл бұрын
Excellent, thanks ! Please, could you show how use websockets with HTMX and FastAPI ???
@bugbytes3923
@bugbytes3923 Жыл бұрын
Thanks for watching! WebSockets and FastAPI would be an interesting one (with some HTMX too). Will definitely add to the list.
@kavustock
@kavustock Жыл бұрын
@@bugbytes3923 One basic video on using it in isolation, then a second layering it into Django.
@kushaldotel3147
@kushaldotel3147 2 ай бұрын
Big bro we need on Pydantic V2
@rolandovillcaarias5112
@rolandovillcaarias5112 22 күн бұрын
When BaseModel is implemented in the same file, it works. But, if you define BaseModel in different file and import it, it raises Redundant Cyclic UHE
@ProfeDuilio
@ProfeDuilio Жыл бұрын
Do you think it's a good idea to use Models, Fields and Constrained Types for an ETL (extract, transform and load) process in Data Engineering?
@bugbytes3923
@bugbytes3923 Жыл бұрын
Interesting question. I can definitely imagine Pydantic helping with the transform part of the ETL process. After extracting your data from various sources, you could define validation and transformations with Pydantic - that would be a cool example. That could even be hooked up with something like Apache Airflow.
@AliHassan-wc6nb
@AliHassan-wc6nb Жыл бұрын
​@@bugbytes3923what is apache airflow 😂
@caiyu538
@caiyu538 8 ай бұрын
👍
@bugbytes3923
@bugbytes3923 8 ай бұрын
Thank you!
@SOHAILKHAN-iu8fu
@SOHAILKHAN-iu8fu Жыл бұрын
Sir make a video on django sub query please
@bugbytes3923
@bugbytes3923 Жыл бұрын
I have an ORM series I'm working on now, hoping to start releasing videos soon. Subqueries will be part of this series.
@SOHAILKHAN-iu8fu
@SOHAILKHAN-iu8fu Жыл бұрын
@@bugbytes3923 thnx Sir i am waiting
@skyhappy
@skyhappy Жыл бұрын
A lot of this functionality is already in Django, which you have videos on. Why use Pydantic when Django has this built in?
@bugbytes3923
@bugbytes3923 Жыл бұрын
Pydantic is used with other frameworks such as FastAPI. It can be used in any Python context where you are validating data from an external source, which is very useful. You would not, for example, create a Django app just to validate data. There are different tools that are good for different contexts! The channel has a focus on Django at the moment, and that will be the main thing, but there are other tools that I'd like to explore on here, too.
WHAT’S THAT?
00:27
Natan por Aí
Рет қаралды 14 МЛН
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 18 МЛН
Red❤️+Green💚=
00:38
ISSEI / いっせい
Рет қаралды 84 МЛН
Pydantic Tutorial • Solving Python's Biggest Problem
11:07
pixegami
Рет қаралды 254 М.
Liked Pydantic? You'll LOVE Msgspec
15:53
Carberra
Рет қаралды 10 М.
Do We Still Need Dataclasses? // PYDANTIC Tutorial
16:33
ArjanCodes
Рет қаралды 198 М.
Protocols vs ABCs in Python - When to Use Which One?
15:31
ArjanCodes
Рет қаралды 34 М.
Intro to Pydantic V1
1:15:31
MathByte Academy
Рет қаралды 18 М.
Pydantic is OP, here's why
18:10
Carberra
Рет қаралды 21 М.
Pydantic is all you need: Jason Liu
17:55
AI Engineer
Рет қаралды 172 М.
15 Python Libraries You Should Know About
14:54
ArjanCodes
Рет қаралды 377 М.
25 Nooby Pandas Coding Mistakes You Should NEVER make.
11:30
Rob Mulla
Рет қаралды 264 М.