Best moments of the video: 7:22 the whole example of Pydantic with data and custom fields validation 9:12 the alternative built-in Python datclasses 9:33 discussing differences between Pydantic and built-in dataclasses
@cyberslot Жыл бұрын
Awesome Pydantic summary - concise and quintessential. Actually in Pydantic v2 '@validator' is deprecated and replaced with '@field_validator'. The same is valid for these three: - 'json' method is deprecated and replaced with 'model_dump_json' instead. - 'dict' method is deprecated and replaced with 'model_dump' instead. - 'parse_raw' method is deprecated and replaced with 'model_validate_json' instead. Have that in mind. Amended code snippet accordingly: user_json_str = user.model_dump_json() user_json_obj = user.model_dump() user = User.model_validate_json(user_json_str) print(f'{user_json_str} {user_json_obj} {user}')
@pixegami Жыл бұрын
I see - thank you for sharing those updates :)
@cyberslot Жыл бұрын
@@pixegami You're very welcome! :)
@aryangoyal517610 ай бұрын
@field_validator("id") def validate_id(cls, value: int) -> int: if value
@002_aarishalam8 Жыл бұрын
The pydantic model still does not do strict typechecking , for eg you can pass int to a class of pydantic model which accepts str , it'll typecast the int to str and pass the check. Although there is a solution which you can use , you can import StrictStr from pydantic for such cases
@pythonantole9892 Жыл бұрын
The explanation on the why and what problems Pydantic solves is one of the best that i have seen. I just had to subscribe!
@pipeherrera50108 ай бұрын
X2
@tuannguyenanh74663 ай бұрын
x3
@jimg82968 ай бұрын
Crap! First 4 videos of yours I watch and they all solve real world problems I have been facing. Freak'n AWESOME! Thank you. FYI I'm coming from the Typescript world. Saves a lot of custom decorators we create.
@python-for-everyone6 ай бұрын
What a great overview and comparison. Thank you for the video. By the way, the fact that variables in Python do not need to be annotated is not what makes it dynamically typed (0:11). It is what makes Python implicitly typed. As you say later (1:34) dynamic type checking more has to do with when types are checked.
@pixegami6 ай бұрын
Thank you - that is a more useful and technical explanation of what I was trying to express :)
@theintjengineer Жыл бұрын
Coming from C++ and Rust, it's not that I want to work with Types, I kinda cannot work without them haha. So, that's the first topic I looked for when I had to do some stuff in Python. Well-made video, Mate. Thanks.
@pixegami Жыл бұрын
Thanks :) I totally understand - once you've come to rely on type-defs it's harder to work without them.
@DrDeuteron5 ай бұрын
go back to C++ then, we don't need type addicts in python
@AR-ym4zhАй бұрын
@@DrDeuteron My brother in Christ. Touch grass, please.
@DrDeuteronАй бұрын
@@AR-ym4zh Touch grass on a coding video? raise EnviromentError
@TwoVera16 күн бұрын
@@DrDeuteron LOL wtf
@ChelseaSaint Жыл бұрын
You have a gift to explain complex things in a very simple to understand way.... great video Keep up the awesome work 💪
@pixegami Жыл бұрын
Thank you! Glad you enjoyed it :)
@jason6569 Жыл бұрын
This is being improved upon in 3.12. I did not use it but I saw something about it in patch notes. I could be wrong but it is nice of Python to actually fix things if this is the case!
@pixegami Жыл бұрын
Actually my biggest issue (type hinting) is already available in Python since 3.8 and I've found it good enough for the most part. If I need more, I go for @dataclass decorator. But I think overall, a lot of frameworks and teams still use Pydantic for the validation too.
@FrederikSchumacher Жыл бұрын
"One of the biggest issues is Python's lack of static typing" You got that the wrong way around. The biggest issue in most typed languages is that the typing system is static. Python does something incredibly useful: value and runtime typing. Static typing is not the end-game of programming language systems, and the assumption that static typing will make programs fault-free is flawed. Without this assumption static typing is left with: being useful for code completion in IDEs, efficiency optimization in resource-constrained environments, and documentation. Python once again does something incredibly useful here: type annotations. Type annotations support the code completion case, and support the code documentation case, while also being part of the runtime information which can be leverages at runtime to perform validation or type checking. As for resource-constraints, it's Python, an interpreted language, if resource constraints where an issue, you wouldn't be using Python or any other interpreted language. Reflect on these questions: When and where do the errors happen? And what am I doing about it? The answers are: During runtime when in use. And adding user input validation code. Notice the absence of static or "compile time typing". Most static typing can only detect faults during compile time and not during runtime, since during runtime most static typed languages don't have typing information. Either the language compiler doesn't add this typing information, or the developers prefer to remove the typing information for runtime for various "optimization" reasons. Some examples of this: TypeScript is only static typed, yet the core runtime, JavaScript, has a very loose runtime type concept, and the TypeScript static types are usually stripped in transpilation. C has static typed compilers, but assembly or hex-code itself is only minimally typed (bits, bytes, addresses). Additionally, static typing systems in the most common languages are incredibly naive and in some cases counter-productive. Classic and everyday examples of this can be found in the Java-memes. These memes are founded on the reality of regular Java code regularly requiring extensive type coupling code in the form of Interface/Adapter/Factory and the resulting coupling code, solely transforming namespaced data types from almost identical static type hierarchy to another. In professional environment, this code incurs heavy technical depths: it makes coupling two or more systems incredibly brittle, and is a great source of simple programming errors. Another feature that points to problems with static typing systems are Generics. A complex and error-fraud feature in many languages, developed to somehow improve code reusability while mostly simply increasing code base complexity. In addition to Python's type annotations, other solutions developed from these typing problems are Test Driven Development and Unit Testing. These cover the runtime problems that are not covered by static typing. Another great solution to the coupling types problem are Go Interfaces. Just to make this clear: Static typing does provide value, but it's extremely specific where and when it provides that value. And it's these specifics exactly that don't make static typing the ideal solution to programming language complexity.
@pixegami Жыл бұрын
A thoughtful deep-dive into the topic and good counter-arguments for what's claimed in the video. I appreciate you sharing these thoughts (and I don't disagree with them either - I felt my script may have been too simplified/opinionated and lost a lot of critical detail).
@FrederikSchumacher Жыл бұрын
@@pixegami I appreciate you taking time to answer in such a reflective and respectful way. Other than the premise at the very start, your video is a great introduction to validation and introduction to Pydantic. I enjoyed you including that example for email address validation, which highlights one of the issues with typing systems and validation systems very well. It's an example I use regularly when discussing typing and teaching junior developers, because it highlights the confusion of typing vs validation very well. Validation can be expressed via (static) types, but it must feature runtime code. Some languages like Python allow implementing this via typing, while others (like C/C++) cannot or only with great difficulty. And while Pydantic presents this as declarative feature looking like (static) typing, it constructs code that's pretty much pure runtime. The video title is a little provocative and click-baity, but can't say it's incorrect, as input validation is one of the most common problems developers have to solve in many applications in many languages - which includes Python. Even as viewer I understand how "the algoritm" pushes creators into doing this, I just wish they didn't have to. Here's an idea if you want to explore both validation and decorators more perhaps in a future video on advanced Python - an extension to your previous primer video on decorators and this video: You can leverage the type annotations and decorators to implement "functional" validation on function arguments to enable code like: @validate_args def cool_func(person_value: has_keys("mail"), mail_value: matches_pattern("\w+@\w+")): person_value["mail"] = mail_value This can of course be extended into less trivial and less nonsensical applications. It's mostly a more "functional" approach to the classic declarative types approach and more an exercise. Personally I mostly prefer declarative types for this sort of thing. However, I find such code examples help understand why and how several Python concepts exist in the form they do.
@jabuci Жыл бұрын
Best intro to pydantic I've seen so far. Thanks!
@pixegami Жыл бұрын
Glad you enjoyed it!
@ИльяЗуев-т9т Жыл бұрын
Mypy solves kind of a similar problem (regarding validation), though with static type checking. It is generally more useful in my opinion, but yeah, pydantic seems to be a great tool for runtime validation
@pixegami Жыл бұрын
Sure, there's a lot of tools that solve similar problems, and I'm not saying Pydantic is necessarily the best one. Definitely use what works best for you (and if Python's inbuilt features are enough, even better).
@darrenlefcoe6 ай бұрын
A really nice explanation of the difference and use cases between the two modules, pydanic vs dataclasses. Well done.
@pixegami6 ай бұрын
Thank you! Glad it was clear :)
@sheshanaturupana2481 Жыл бұрын
Thanks for the hint and this will less stress me finding solutions to what you have explained. Keep it up you have a natural gift to explain in a way that anyone can understand
@pixegami Жыл бұрын
Thank you :) I appreciate the comment!
@roberthuff312210 ай бұрын
🎯 Key Takeaways for quick navigation: 00:00 🐍 *Python's Dynamic Typing Limitation* - Discusses the limitation of Python's dynamic typing and the problems it can cause, - Highlights the risk of accidental creation of invalid objects due to loosely defined variable types, - Emphasizes the difficulties in debugging failures caused by incorrect use of dynamic typing. 01:53 🎁 *Introduction to Pydantic* - Introduces Pydantic as a powerful tool to model data, with validation capabilities for avoiding the problems caused by Python's dynamic typing, - Discusses Pydantic's use in popular Python modules and its benefits, - Explains how Pydantic improves IDE support for type-hints and allows for easy serialization. 03:19 💻 *Creating and Using Pydantic Models* - Demonstrates how to create models in Pydantic and how Pydantic ensures that only valid data is used in models, - Shows the added advantage of type hinting provided by Pydantic models in an IDE, - Illustrates custom data validation in Pydantic by enforcing that all account IDs must be a positive number. 06:36 🔄 *JSON Serialization with Pydantic* - Details how Pydantic supports JSON serialization, which proves beneficial in integrating Python code with external applications, - Provides an example of converting a Pydantic model to a JSON string using the JSON method. 08:03 📊 *Comparing Pydantic to Dataclasses* - Compares Pydantic to Python's inbuilt dataclasses module, - Evaluates both modules based on type hints, data validation, and JSON serialization, - Suggests appropriate cases of usage for both modules depending on specific programming needs. Made with HARPA AI
@GilbertoMadeira8311 ай бұрын
Amazing video, I am starting my journey in python, and pydantic appeared to me in a fastapi course, I was so confused, but now I fully understand its utility, thank you!
@pixegami10 ай бұрын
Yay, glad it was helpful!
@ReflectionOcean11 ай бұрын
- Understand the drawbacks of Python's dynamic typing at [0:04]. - Recognize the potential for creating invalid objects in Python at [1:06]. - Consider using Pydantic to solve type-related issues in Python at [1:49]. - Install Pydantic to enhance data validation and typing at [2:53]. - Create a Pydantic model by inheriting from the base model class at [2:59]. - Utilize Pydantic's type hints and autocomplete for easier coding at [3:49]. - Implement Pydantic's data validation to catch errors early at [5:03]. - Add custom validation logic to your Pydantic model at [6:43]. - Use Pydantic's JSON serialization for easy data interchange at [8:00]. - Compare Pydantic to Python's built-in dataclasses for your needs at [8:47].
@chakib237811 ай бұрын
Excellent video. Thank you for getting straight to the point with clarity.
@NikolajLepka Жыл бұрын
it's hilarious how many decades it took for python users to understand the benefit of strict typing
@pixegami Жыл бұрын
I suspect it's not native Python users bringing that change, but users of other strictly typed languages coming into Python and feeling like something is missing 😬
@OctagonalSquare11 ай бұрын
I think it’s hilarious that non-Python users think dynamic typing is a negative
@NikolajLepka11 ай бұрын
@@OctagonalSquare if it wasn't, python users wouldn't be working so hard to put static typing into the language
@shaurryabaheti11 ай бұрын
i love dynamic typing... as much as it slows my code, i can handle errors better and create my own errors and etc... ints also have no bounds (they have, virtually but you can bypass it), extremely easy data modification support, etc etc etc... so no I'm not fighting to make it static... dynamic is what makes python python @@NikolajLepka
@embracethenoise9 ай бұрын
@@NikolajLepka there's nothing inherently better, or worse for that matter, with either static or dynamic typing. Users bring their own biases and preferences.
@JohnMitchellCalif10 ай бұрын
very useful! I'll start adding Dataclass support to my code, and when it matters, Pydantic. Subscribed!
@pixegami10 ай бұрын
Thank you, glad it was useful :)
@gatorpika11 ай бұрын
Wow, never understood that stuff until I watched this and it's pretty simple the way you explain it. Thanks...subbed!
@pixegami10 ай бұрын
Awesome, thank you!
@markblumstein41692 ай бұрын
I wonder about best practices when serializing data to json and then validating how it’s read (in particular if you’re serializing it specifically to pass the data to a different system or language). In the video, for example, that specific email data type is used, but it will be mapped to a string as a json. So you lose that specific type info. I’ve been reading about frictionless data framework for storing that type of metadata but I don’t know whats popular or most useful. Would it make sense if constructing that metadata was a part of the pydantic library? Or maybe it is already?
@pixegami2 ай бұрын
You're raising a great point about serialization and cross-system data validation! Pydantic actually has built-in support for JSON serialization that preserves custom types. The `json()` method and `jsonable_encoder` function can handle this, including custom serialization logic for types like emails. For metadata and schema generation, Pydantic can produce JSON Schema, which is widely supported. This can be used to describe your data structure, including custom types, to other systems. You can access this using the `schema()` method on your models. For more details on Pydantic's serialization and schema capabilities, check out the docs: docs.pydantic.dev/latest/usage/serialization/
@DaniEIdiomas Жыл бұрын
Very nice. Had been working with some parts of dataclasses in the past and used guard clauses instead of validators. Will try to use it in the future. Thank you
@pixegami Жыл бұрын
Thanks! I hope it is useful for you :)
@brandonvolesky98672 ай бұрын
Love the content and editing!
@pixegami2 ай бұрын
Thanks! Really glad you enjoyed both the content and editing! 😊
@AdityaDodda11 ай бұрын
How do these things affect performance? I'd assume they add a good amount of overhead. If you are going to take the pain of making things statically typed, why not just used a language that is efficient with it. Kotlin is a great bet. Is the use case to have the external api typed strongly with internals relaxed so that you can stay in Python and still use it's libraries for an application? Just curious.
@pixegami11 ай бұрын
Thanks for the great question. The performance hit is not noticeable (probably a few microseconds on each request at most) - and I don't think there's any Python use-cases where that would matter (if milli-sec latency was a concern, then Python itself already isn't a good fit). As for using a (different) statically typed language - sure, if you are picking a new language to learn or starting a new project. But Python has a lot of libraries/SDKs/support that do not exist in other languages. It also has high adoption. Some people may just want to continue using Python but just want to upgrade this one part of the user experience. I think the best use-case for Pydantic is for writing Python logic that interacts with other services (or databases) via API, and you want an easy way to validate/serialize your data.
@kentuckeytom10 ай бұрын
very clear and concise, well organized, thanks.
@pixegami10 ай бұрын
Thanks!
@luftstolle Жыл бұрын
Just wanted to say I love your video! Learned something new!
@pixegami Жыл бұрын
Thank you! Glad it was helpful :)
@christophehanon83969 ай бұрын
Very clear explanation - thanks for sharing !
@pixegami9 ай бұрын
Thank you!
@LeeYeon-qv1tz11 ай бұрын
Do we really need data validation? At 5:55 ? I mean, we can change the data type of age variable when we get from user, right? Like age= int(age) . Correct me if iam wrong.
@pixegami10 ай бұрын
What you're suggesting is "casting" the data. It works if it's small transitions of things like ints to floats. But the validation becomes useful if it's something more complex like named dicts, such as (e.g. "vCPU: [1024, 2048, 9096]"), or percentages (e.g. must be between 0-100).
@LeeYeon-qv1tz10 ай бұрын
@@pixegamithanks!
@nanubalakundan982526 күн бұрын
I got all the necessary whys and whats. Thank you!
@SathishKumar-qk4hu5 ай бұрын
Nice Video @pixegami. Would have liked to hear about Conversion a bit, example Date with the variety of formats that one encounters.
@ivhacksАй бұрын
Great explanation and visually beautiful video. Thank you!
@pixegamiАй бұрын
Thanks so much! Really glad you enjoyed the explanation and the visuals.
@ZeeshaanAli6 ай бұрын
Absolutely precise and concise.
@pixegami6 ай бұрын
Thank you!
@drewsarkisian9375 Жыл бұрын
Either use a statically-typed language if you absolutely need one OR use available tools to add typedefs. Dynamic typing is a feature, not a problem.
@Holasticlogger Жыл бұрын
That's what I believe too and that's make it special too tbh !!
@pixegami Жыл бұрын
Perhaps it was unfair for me to call "lack of static typing" a problem. The real issue I'm referring to is the user experience from having type hints and validation. "Use a statically-typed language" - Although this is a nice user experience, it's rarely the top reason for choosing a language (for me anyways) - especially over say, frameworks or domain utility. "Use available tools to add typedefs" - Sure, if you only need typedefs, Python's inbuilt support is good enough. If you also want validation and deep serialisation too-well, at what point is re-implementing all those features easier/better than a pip install?
@Suto_Ko Жыл бұрын
totally agree, dynamic typing can be powerful and flexible. if you need stricter type checking, statically-typed languages or tools like typedefs can be helpful. it's all about choosing the right tool for the job.
@blackdereker4023 Жыл бұрын
@@Suto_Ko The good thing about pydantic is that it's possible to have strict type checking and validations without having to change the whole language of your Python project. A lot of times it's better to install an extra library than to refactor your entire project.
@shedrachugochukwu62457 ай бұрын
Dynamic typing for me is what makes python cool. If i need to switch data type, i just cast it to the type if the value are the same
@pixegami7 ай бұрын
Hints and validation are still good for more complex data-types that can't be casted (think nested objects), or tuples where the order matters. And if you want a field that can understand multiple data types you can also use something like "Union[str, int]" or "str | int" in the type hint.
@nulops11 ай бұрын
Excellent vidéo. What tools do you use to create this kind of content
@pixegami10 ай бұрын
Thank you! I use OBS to record the video/screen, Adobe Premiere to edit it, and I also have a couple of my own Python scripts to create slides/titles/diagrams.
@adam_fakes11 ай бұрын
Nice video, though lack of static typing is not a problem, it is a feature. It was done on purpose. Like JavaScript vs TypeScript, I would rather see Tython (Typed Python).
@catsupchutney11 ай бұрын
Yes, these bugs/features are very much a non issue, meaning it's a facet of the language that is lauded as much as it is hated. One could consider Sqlite's lack of types to be a feature, or two pass versus one pass interpreters; neither is better. Python occupies that odd zone where it might be used for a ten line convenience script, or for the basis of a serious application.
@pixegami10 ай бұрын
I think it's more of a "UX" problem for developers who are used to the nice experience that static typing or typed languages give you. So it's not really a big deal, but it does make the experience better for many people.
@deepschoolai10 ай бұрын
how do you create those code boxes? It looks so good!
@pixegami10 ай бұрын
I used a custom script in Python, using libraries like pygments.org/ and PIL :)
@nas83187 ай бұрын
If you want static typing in Python just use Numpy. It's both faster and takes less memory.
@pixegami7 ай бұрын
Numpy is excellent, but I think that's solving a different problem for people who want to add type hints and validation to their custom data types.
@TheShocobo6 ай бұрын
which shortcut key is he using at 4:20 ?
@aitools24 Жыл бұрын
00:02 Pydantic module helps solve Python's lack of static typing. 01:20 Pydantic is a data validation library in Python with powerful tools to model and validate data. 02:49 Pydantic allows you to create models in Python with type hints 04:12 Pydantic provides data validation and type hinting, making code easier to work with 05:36 Pydantic provides built-in validation for different types of data. 07:02 Pydantic provides built-in support for JSON serialization. 08:26 Pydantic provides easy integration with JSON and external applications 09:50 Pydantic is recommended for complex data models and JSON serialization. Crafted by Merlin AI.
@Nardiso Жыл бұрын
Man, awesome content like I never saw before! Really, really good! Thank you!
@pixegami Жыл бұрын
Glad you enjoyed it!
@getreadytotube2 ай бұрын
Thanks!
@pixegami2 ай бұрын
You're welcome! Glad you found it helpful :)
@Andromeda26_8 ай бұрын
Great Video! Thank you! Thank you! Keep up the great work!
@pixegami8 ай бұрын
Glad you enjoyed it!
@luis96xd11 ай бұрын
Amazing video, everything was well explained, thanks!
@pixegami10 ай бұрын
Glad you enjoyed it!
@morespinach98327 ай бұрын
Not sure what the fascination with type is. It’s a helpful feature to not have to type variables. The web in general benefits from this, if one is sensible and clever in how to use this - and when validation of specific types is needed, induce it.
@pixegami7 ай бұрын
It's think just a big "user experience" problem for a lot of people who are more comfortable working with types/validation.
@thebuggser275210 ай бұрын
Very well presented. Thanks!
@pixegami10 ай бұрын
Thanks for watching!
@ahmednfaihi9091 Жыл бұрын
Great explanation. Btw which vs code theme u r using?
@pixegami Жыл бұрын
Monokai Pro :)
@404nohandlefound Жыл бұрын
I wouldn’t call dynamic typing as an “issue”. It’s just how the language is, with its own design.
@pixegami Жыл бұрын
True, it’s not really the issue. It’s just an oversimplification of what the real issue is: the user experience.
@cjbarroso Жыл бұрын
love your explanation, as advanced programmer I don't feel I spent too much time to learn something useful. Keep it up! You have a new subscriber.
@pixegami Жыл бұрын
Glad to hear it :) Thank you!
@mohibahmed50987 ай бұрын
I love your videos man. Just a quick question. Can't we define the default types of our instances in python for example x = 10 x: int = 10
@pixegami7 ай бұрын
Thanks! Glad you enjoyed it. Yes if you just want type hints, that's exactly what I'd do. Pydantic becomes more useful if you need validation, or you need to work with APIs or databases.
@RuudJeursen11 ай бұрын
Thanks, nice & clear explanation!
@pixegami11 ай бұрын
Glad you enjoyed it!
@romsthe Жыл бұрын
I don't remember exactly why, but I prefer attrs. Could you compare both ? With custom validation, custom initialization for fields, also post init processing ? I think that's all that I'm using. I'm only deserializing from yaml though
@pixegami Жыл бұрын
I haven't used attrs myself, but I understand it's a bit more heavyweight than the inbuilt dataclasses. Not sure how it differs from Pydantic, but it's probably something I should compare and check out :)
@RavelleWourougou5 ай бұрын
Awesome! You just got a new follower
@pixegami2 ай бұрын
Thanks! Really appreciate the follow :)
@a0um Жыл бұрын
I’m wondering how it compares with the typing package included in Python. And, is the typing module the same as mypy?
@pixegami Жыл бұрын
I think for just the "typing" part, Pydantic doesn't really give you much advantage over the built-in Python type hints. The real value add of Pydantic comes from its validation and serialisation abilities-and the use case is integrating with external databases or APIs with your data :)
@dogzabob10 ай бұрын
Hey man, I love the tutorial. It's very easy to follow along with your explanations. I do have one issue in that when attempting to use your @validator function in pycharm and kaggle it does not seem to work and still allows me to enter negative numbers without raising an error. i changed the value to
@pixegami10 ай бұрын
Thank you! Glad you're enjoying the video. Hmm, maybe there's an issue with the way you've set up the validator, but it's hard to say without seeing your code. I recommend dropping your code into ChatGPT and ask to see if it can spot the bug. But the best thing to do is probably to read through the manuals directly and understand how the validators work and how to debug them: docs.pydantic.dev/latest/concepts/validators/
@kulyashdahiya25293 ай бұрын
Keep going :). I just subscribed.
@jteds711 Жыл бұрын
New here, also not a software engineer by trade. Is this essentially allowing you to create structs like you would in golang? Learning here, just seemed familiar in its use case. Any commentary is welcomed. Thanks!
@pixegami Жыл бұрын
Welcome! Yes, it's quite similar. Structs is built into Golang (which is "typed" by design). Python is dynamic (or "untyped"), so to get similar functionality you need to add it in deliberate (using something like Pydantic).
@BosonCollider Жыл бұрын
@@pixegami The other similarity is that Golang's marshalling in the standard library also provides the serialization/deserialization part (which is what pydantic actually offers as opposed to dataclass libraries like attrs).
@pixegami Жыл бұрын
@@BosonCollider Oh that’s cool, I’m not super familiar with Go and didn’t know they did JSON marshalling by default. TIL!
@balapraneeth970811 ай бұрын
Great explanation!! Thanks for creating such as amazing content
@pixegami10 ай бұрын
Thank you, glad you liked it!
@claudemirtonmacedo6639 Жыл бұрын
Awesome video. But what about including Marshmallow on your comparison matrix?
@pixegami Жыл бұрын
Thanks for the suggestion. I haven't used it before. But I'll leave a link here for anyone who is reading and is curious: marshmallow.readthedocs.io/en/stable/why.html
@ananyamahapatra65977 ай бұрын
Thank you so very much buddy 🤩 its a great help 🥳
@pixegami7 ай бұрын
Thank you, glad you liked it!
@krzysiekkrzysiek9059 Жыл бұрын
Dynamic typing is what Python stands for. I use type hints only in functions or methods parameters for better understanding to other developers.
@pixegami Жыл бұрын
I agree - I just wanted to highlight the value of having type hints and validation. Normally for my own projects, unless I need all three Pydantic features I mentioned (serialisation, validation, and typing), just the built-in type hinting is good enough.
@blackdereker4023 Жыл бұрын
When you are building an API or a CLI application, validations is a must.
@nedac279 Жыл бұрын
How is this different (or better) than dataclasses?
@pixegami Жыл бұрын
I cover this a bit towards the end of the video, but Pydantic gives you a bit more validation and serialisation capabilities. It's also generally more widely used in frameworks that deal with APIs or databases (e.g. FastAPI). But if the typing and structure is all I want, I'd go with dataclasses personally :)
@agi_lab Жыл бұрын
Thanks. U have explained very well
@pixegami11 ай бұрын
Thank you!
@alexanderzikal724411 ай бұрын
Very useful, Thank You!
@pixegami10 ай бұрын
Glad to hear that!
@reimusklinsman58763 күн бұрын
Dynamic typing is a core feature in Python. I've rarely ever had and issue with dynamic typing but the sheer overhead pedantic requires makes me heavily question someone's capabilities who uses pydantic
@thygrrr Жыл бұрын
1:24, so age is, in fact, not just a number. It's settled now.
@pixegami Жыл бұрын
It never was :P
@akrishnadevotee11 ай бұрын
Great video, thanks a lot! I hear some background noise in your audio though. Do you not use audacity to remove the background noise?
@pixegami10 ай бұрын
Thanks! I live in quite a loud area, so a lot of noise does get through. I've used software to remove it in the past, but sometimes it does make the sound a bit less crisp. Thanks for the feedback though, I'm working on it :)
@akrishnadevotee10 ай бұрын
@@pixegamiI sometimes use the app Dolby On to remove noise, it's very good.
@UTJK. Жыл бұрын
Nice presentation.
@pixegami Жыл бұрын
Glad you liked it
@feezysted Жыл бұрын
Can pydentic work with the terminal editors like vim or neovim?
@pixegami Жыл бұрын
I'm not sure, I haven't really used them. But I think all of the type hinting features in an IDE come from having a language server or linter anyway, so I think it should be possible.
@hananamar2686 Жыл бұрын
I like pydantic a lot. But when working on projects where packages size is a consideration, I couldnt understand why such lightweight functionality requires code that is so heavy. That's a bummer
@pixegami Жыл бұрын
Hmm, what do you mean by "heavy"? As in the implementation of Pydantic itself? On that note-if you just want type hinting, Python has that built-in. And if you need structs, @dataclass will do it for you (also built in). But if you need validation and serialisation that's probably when Pydantic might be useful.
@fatmasliti2161 Жыл бұрын
great explanation!
@pixegami Жыл бұрын
Thanks!
@PeterRichardsandYoureNot11 ай бұрын
Ok, I was thinking what’s the need for this if you are organized. But, when you said that the library has built in format validation for things like emails I now have a lightbulb above my head that has literally erased so many lines of code later using any type of my own format validation.
@pixegami10 ай бұрын
Thanks for sharing that lightbulb moment :) I'm glad the example helped it to click.
@guohaigao239711 ай бұрын
Thank you , like this video so much.
@pixegami11 ай бұрын
Glad you liked it!
@uLu_MuLu5 ай бұрын
Good video, great explanation (although some things work differently, when using, e.g., pydantic 2.8.2)
@pixegami2 ай бұрын
Thanks! Glad you found the explanation helpful. Yeah, Pydantic evolves pretty quickly - always good to check the docs for the latest changes in newer versions. :)
@akshatgupta16589 ай бұрын
What is your vscode theme and font?
@pixegami9 ай бұрын
I'm using Monokai Pro theme, and Roboto Mono font.
@tirsky Жыл бұрын
Это всё называется - костыли)
@OctagonalSquare11 ай бұрын
I really don’t see the actual point. If you can’t use dynamic typing without getting mixed up, then use a language with strict typing. It’s like buying an F-150 but putting a Ram’s engine in it. Just buy the Ram to begin with. If you feel a feature of a programming language is a problem, then you need to use a different language or learn to leverage the feature better
@pixegami10 ай бұрын
Hmm, I think the analogy of the "typing" being the engine doesn't really hit the mark here. It's more of a comfort feature, so in terms of car analogy, it's more like air-conditioned seats or tinted windows or a sun-roof. Maybe you want the engine of the F-150 (i.e. Python's vast libraries, ubiquity in AI/data, and wide platform/SDK support), but just want UX experience of runtime type validation.
@alexhasha Жыл бұрын
I love the production value of your videos (in addition to the content, of course!) I’m curious what tools you like for recording and editing videos?
@pixegami Жыл бұрын
Thank you! I use OBS studio to record, and I use Premiere Pro to edit. Actually my editing is really light and minimal (just direct cuts) so any editing software is fine.
@shomikhan13333 ай бұрын
Awesome video.... Thanks a lot
@fengjeremy787811 ай бұрын
Good tutorial!
@pixegami10 ай бұрын
Thanks!
@ThomasVanhelden Жыл бұрын
First of all, Python's dynamic typing is not a problem. Secondly, even if it was, it's not the problem Pydantic is trying to solve. I can't think of a problem where your Person example results in hard-to-find issues, or any issue at all, for that matter. If the age variable absolutely has to be an integer, your program will likely use it in a way that only integers can be used, and Python's duck typing will infer that you can only pass an integer to it. Pydantic is meant for data parsing. Not for validation (in the dictionary sense of the word).
@pixegami Жыл бұрын
Thanks for the thoughtful counter-point. I do admit the title/intro was a bit click-baity but I still think the data-validation and type-hinting aspects of Pydantic are extremely useful. Although truth be told, if typing is all I wanted I would use @dataclass and type hints instead (I think I mentioned that towards the end of the video too).
@lupusexperience Жыл бұрын
nice video, but for non-negatives you only declare Field(ge=0)
@pixegami Жыл бұрын
Thank you!
@programmingwiththotho46419 ай бұрын
thank you for the explanation, and please next time leave a link for donation
@pixegami8 ай бұрын
Thank you! Glad it was useful :)
@Reb-0126 ай бұрын
Thanks man
@fstemarie Жыл бұрын
If you need data typing, why not use another language that uses it? I don't understand why you would use python and then use an external library to bend it to your needs. Why not use go?
@pixegami Жыл бұрын
Hmm, as nice as data-typing is, I don't think it's a first-class criteria for language section. The most important things will probably be stuff like: 1) what frameworks/libraries are available? 2) what SDKs do the services I want to use support? 3) How popular is the language (e.g. if you wanted to hire people to work on it)? That said, it's still a commonly cited pain point amongst Python developers, and a lot of popular libraries have approached this problem using libraries like Pydantic. This is especially useful if you need to save/store the data between databases or with other apps as well.
@minciNashu Жыл бұрын
pydantic is about validation. Look at how FastAPI is using it.
@ThankYouESM9 ай бұрын
I always do user_input = int(user_input) etc after each input only where needed which prevents every such error.
@kaimildner215311 ай бұрын
I really don't understand why not just using a typed programming language? Don't get me wrong. I love python, but sometimes it is not the right tool. For small cli applications I love python. But it's not the right tool for everything. The last videos I watched about python was all about getting around it's downsides. Especially the Gil and multiprocessing. Now a way to make it typed? For me that's the wrong way. When I want a typed PL also with parallel processing I just use dotnet. When I want to have a beautiful UI with the best performance, I use c++ with Qt. When I want a small and fast to implement webservice I use python, as long as I don't need some multiprocessing. What I try to say is, that there is the right tool for every problem. You don't have to use the same tool for everything.
@pixegami10 ай бұрын
I think the difference in perspective for me here is that Python's typing system (nor multi-processing or GIL) are big enough factors to make it not the right tool for the job in a lot of use-cases. For example, it's more important that you're using a language that has the vast library selection that Python has (especially in DS/ML/AI), or has wide platform and SDK support, or maybe it's a tactical decision because your team already knows it (and it's easy to hire for). At that stage, the typing experience just kinda becomes a sharp edge that people who have already settled on Python tend to focus on. Not enough of a show stopper to migrate to Rust or GoLang, but also painful enough to look for an easy solution to.
@pym753 ай бұрын
cant use type(variable) to find out?
@anuragshas4 ай бұрын
Typing exists in python since the days of 3.5, how is it different then?
@thebatprem9271 Жыл бұрын
I have experience using Pydantic, but it's somehow wordy for me especially if I don't have a plan to do OOP. My preference would be "mypy" (or pytype) + "typedict" instead.
@pixegami Жыл бұрын
Yes. Truthfully I just stick to dataclasses since that’s good enough for 90% of my use cases too. But here I just wanted to open with a common problem as a way to introduce Pydantic.
@chriskeo392 Жыл бұрын
We can mix wit Sqlalchemy models?
@DanielHomeImprovement5 ай бұрын
great video thx and subscribed :)
@Learnbyflow11 ай бұрын
We can use it like this in normal python myvalue:str ="hello"
@kikocometa Жыл бұрын
Problem with static typing in python is not true.Theres an optional typing module for python for your information.
@pixegami Жыл бұрын
Yup, if you just want to get type hints, then I recommend just using the built-in Python features (I think I also mentioned them at the end of the video).
@youssef.elyaakoubi7 ай бұрын
Thanks Bro!
@pixegami7 ай бұрын
You're welcome!
@footflaps9 ай бұрын
Very helpful!
@bernardwodoame98502 ай бұрын
I'll use pydantic because why not enforce the types? Type hints are great but it's also good if you can catch the errors early if wrong types are used.
@pixegami2 ай бұрын
Yeah, that's exactly right! It's super helpful for catching errors early and even handles more complex data structures.
@iwatchtvwithportal53678 ай бұрын
Still easier to code using type-hinted python than to write java 😂