MathByte Academy
MathByte Academy
  • 61
  • 169 462
Partially Validated Pydantic Models
#mathbyteacademy #python
In this video I want to present a really neat approach that one of my students on Udemy came up with to have Pydantic models that will still deserialize invalid data (populated with some value, such as None), as well as provide information about those fields that failed validation.
I didn't think it could be done, so I was very happy to be proved wrong by that person's very elegant solution! This is a technique that I will probably use often moving forward.
It is also a great example of a practical application of wrap validators and model validators. Even if you have no need for partially validated Pydantic models, you should still watch this to get a clear understanding of how wrap validators work and can be leveraged.
Thank you to the author for coming up with this and sharing it on GitHub!
Code for this Video
================
Available in GitHub blog repo: github.com/fbaptiste/python-blog
Direct link: tinyurl.com/52en6scd
Original author's GitHub repo: github.com/linktoad/pydantic-partial
My Python Courses
=================
- Python 3 Fundamentals (introduction to Python)
www.udemy.com/course/python3-fundamentals/?referralCode=DA09C6F40CEC38C942F6
- Pydantic V2: Essentials
www.udemy.com/course/pydantic/?referralCode=581AD0DC27E0E1EDB538
- Python 3 Deep Dive (Part 1 - Functional)
www.udemy.com/course/python-3-deep-dive-part-1/?referralCode=E46B931C71EE01845062
- Python 3 Deep Dive (Part 2 - Iteration, Generators)
www.udemy.com/course/python-3-deep-dive-part-2/?referralCode=3E7AFEF5174F04E5C8D4
- Python 3 Deep Dive (Part 3 - Hash Maps)
www.udemy.com/course/python-3-deep-dive-part-3/?referralCode=C5B0D9AB965B9BF4C49F
- Python 3 Deep Dive (Part 4 - OOP)
www.udemy.com/course/python-3-deep-dive-part-4/?referralCode=3BB758BE4C04FB983E6F
มุมมอง: 191

วีดีโอ

Easy Progress Bars using tqdm
มุมมอง 694วันที่ผ่านมา
#mathbyteacademy #python When you have long running processes, whether in Python apps or Jupyter notebooks, don't just give your users a blank screen where things look frozen. After about 10 seconds they're going to think the app crashed or is stuck! Instead, give them visual feedback that things are running. The tqdm library gives us the ability to very easily add progress bars to our code, ev...
Simplify Debug Print Statements using IceCream
มุมมอง 1.2K21 วันที่ผ่านมา
#mathbyteacademy #python I discovered this library recently, and found it to be quite useful to replace the print statements I sometimes use for debugging or simply inspecting variables as my code is running. Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tinyurl.com/w2z9vkk9 My Python Courses - Python 3 Fundamentals (introduction to Python) www...
psycopg Row Factories - ORM-free area!
มุมมอง 602หลายเดือนก่อน
#mathbyteacademy #python This is Part 2 of a two-part set of videos that looks into how to hook up Pydantic models to data returned by queries run against a Postgres database using the `psycopg` library. In Part 1, we looked at how to run Postgres locally using docker compose, and at what SQL migrations are, and how to implement them using the YoYo library. In this second part, we'll see how we...
Postgres SQL Migrations using YoYo
มุมมอง 941หลายเดือนก่อน
#mathbyteacademy #python This is a two-part set of videos that looks into how to hook up Pydantic models to data returned by queries run against a Postgres database using the `psycopg` library. In Part 1, we'll look at how to run Postgres locally using docker compose, and at what SQL migrations are, and how to implement them using the YoYo library. In the next part, we'll see how we can load da...
Python's SimpleNamespace and JSON
มุมมอง 1.1K2 หลายเดือนก่อน
#mathbyteacademy #python Using Python's SimpleNamespaces to deserialize JSON data. A simpler approach than Pydantic, and a cleaner attribute access syntax than dictionaries. Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tinyurl.com/3u9245tx My Python Courses - Python 3 Fundamentals (introduction to Python) www.udemy.com/course/python3-fundament...
The Tenacity Library
มุมมอง 1.3K2 หลายเดือนก่อน
#mathbyteacademy #python In this video we explore the Tenacity library that provides a very easy and powerful mechanism to add retry behavior to any piece of code. Very useful in a variety of scenarios such as retrying API calls when they time out or get rate limited, retrying database calls when they fail for some reason, and much more. Content 00:00 - Introduction 02:35 - SQL Example Setup 12...
The benedict Library
มุมมอง 1.7K2 หลายเดือนก่อน
#mathbyteacademy #python A highly useful extension to Python dictionaries for simplified access to keys in dictionaries and nested dictionaries, as well as a slew of methods to traverse dictionaries, filter key/value pairs, flatten nested dictionaries, and much more. Give this library a try in your next project and let me know in the comments what you tought of it. I only recently became aware ...
The pyyaml Library
มุมมอง 8823 หลายเดือนก่อน
#mathbyteacademy #python We take a quick look at how to use the pyyaml library to read and write YAML files (as well as JSON!). Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tinyurl.com/59kc4ppn My Python Courses - Python 3 Fundamentals (introduction to Python) www.udemy.com/course/python3-fundamentals/?referralCode=DA09C6F40CEC38C942F6 - Pydan...
The wrapt Library
มุมมอง 1.3K3 หลายเดือนก่อน
#mathbyteacademy #python In this video we look at the wrapt library that has some very useful features to create decorators. We look at how to use it, how to dynamically enable and disable decorators and some additional enhancements it provides for inspection over Python's own @wraps decorator. Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tiny...
The Arrow Library
มุมมอง 1.9K4 หลายเดือนก่อน
#mathbyteacademy #python A look at at the highly useful and easy to use Arrow library for handling date times. I highly encourage you to check out this video and start using Arrow in your Python projects! Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tinyurl.com/bp5f2kn9 My Python Courses - Python 3 Fundamentals (introduction to Python) www.ude...
Python MultiProcessing: Leveraging Pools to Turbocharge your Apps
มุมมอง 2K5 หลายเดือนก่อน
Turbocharge your CPU Intensive Apps with MultiProcessing In this video I show you how to easily use Python multiprocessing capabilities to seriously boost the execution speed of your CPU-bound workloads. By default, Python is limited to a single thread and a single core on your CPU. Multiprocessing allows you to run functions on multiple cores on your machine, thereby achieving true parallelism...
Pydantic (V2) - In-depth Starter Guide
มุมมอง 12K7 หลายเดือนก่อน
In this video I show you how to use Pydantic V2, including topics such as default factories, custom serializers and custom validators. There is a whole lot more to Pydantic than what I can cover in a video such as this. If you are interested in a deeper dive into Pydantic V2, please check out my Udemy course on the subject. Here is a discount coupon link (if it has expired, just let me know in ...
Idiomatic Python: Named Arguments
มุมมอง 8198 หลายเดือนก่อน
Continuing with how to write more Pythonic code, we look at using named arguments when calling functions (callables in general). I also make the case for defining your own functions to force this using keyword-only parameters. #mathbyteacademy #python Code for this Video Available in GitHub blog repo: github.com/fbaptiste/python-blog Direct link: tinyurl.com/4smz6as4 My Python Courses - Python ...
Speed Up your Python Apps with Caching
มุมมอง 2K8 หลายเดือนก่อน
In this video we look at how to implement caching for functions, class properties and class methods to improve time performance. We also look at some of the associated caveats, and where you need to be a bit more careful. #mathbyteacademy #python Content 00:00 - Introduction 07:18 - Caching from First Principles 14:51 - Python's LRU Cache and the @lru_cache Decorator 19:08 - Python's @ache deco...
Idiomatic Python: Merging Dictionaries
มุมมอง 7439 หลายเดือนก่อน
Idiomatic Python: Merging Dictionaries
Pydantic: Migrating from V1 to V2
มุมมอง 2.2K9 หลายเดือนก่อน
Pydantic: Migrating from V1 to V2
Idiomatic Python: Counting Things with Dictionaries
มุมมอง 1K10 หลายเดือนก่อน
Idiomatic Python: Counting Things with Dictionaries
Idiomatic Python: Iterating Dictionaries
มุมมอง 1.4K11 หลายเดือนก่อน
Idiomatic Python: Iterating Dictionaries
Idiomatic Python: Decomposition & Refactoring Demo
มุมมอง 2.9K11 หลายเดือนก่อน
Idiomatic Python: Decomposition & Refactoring Demo
Idiomatic Python: Generators
มุมมอง 1.7K11 หลายเดือนก่อน
Idiomatic Python: Generators
Idiomatic Python: Custom Sorts and Leveraging Sort Stability
มุมมอง 568ปีที่แล้ว
Idiomatic Python: Custom Sorts and Leveraging Sort Stability
Idiomatic Python: Deques vs Lists
มุมมอง 1.1Kปีที่แล้ว
Idiomatic Python: Deques vs Lists
PyCharm and Virtual Environments
มุมมอง 1.5Kปีที่แล้ว
PyCharm and Virtual Environments
Idiomatic Python: Using Comprehensions
มุมมอง 819ปีที่แล้ว
Idiomatic Python: Using Comprehensions
Idiomatic Python: The `itertools` Module
มุมมอง 1.1Kปีที่แล้ว
Idiomatic Python: The `itertools` Module
A Deep Dive into Python's Dataclasses (Part 2)
มุมมอง 3.8Kปีที่แล้ว
A Deep Dive into Python's Dataclasses (Part 2)
A Deep Dive into Python's Dataclasses (Part 1)
มุมมอง 10Kปีที่แล้ว
A Deep Dive into Python's Dataclasses (Part 1)
Idiomatic Python: Iterating over Collections
มุมมอง 936ปีที่แล้ว
Idiomatic Python: Iterating over Collections
Python Tips and Tricks: Decorator Factories and Optional Arguments
มุมมอง 1.4Kปีที่แล้ว
Python Tips and Tricks: Decorator Factories and Optional Arguments

ความคิดเห็น

  • @kingalonsoiv
    @kingalonsoiv 9 ชั่วโมงที่ผ่านมา

    Wow i love that you gave options, thanks so much for this! I ran into a nested loop while building a card game (it loops through 2 lists and returns one card if it matches). Thanks!!

  • @redDuck757
    @redDuck757 12 ชั่วโมงที่ผ่านมา

    New video on the best Python channel🎉🎉🎉 Thank you

  • @szymonpiechutowski2340
    @szymonpiechutowski2340 15 ชั่วโมงที่ผ่านมา

    Can you create a video about how to use Pydantic for app config management? How to serialize/deserialize, update them etc. Everything that a standard app does with JSON or YAML config

  • @szymonpiechutowski2340
    @szymonpiechutowski2340 17 ชั่วโมงที่ผ่านมา

    Hi Fred, happy to see the new video!

  • @kmwaziri
    @kmwaziri 2 วันที่ผ่านมา

    Python 3 Deep Dive brought me to this amazing channel. Thank you for your quality content Dr. Baptiste!

  • @silver1544
    @silver1544 2 วันที่ผ่านมา

    Great lib reviews! Keep it going

  • @panayiotissiatos5592
    @panayiotissiatos5592 3 วันที่ผ่านมา

    Hi Dr. Fred Baptiste! Are you planning on releasing a course about async await (asyncio) etc on Udemy? And if yes, is there an ETA?

  • @achilpal6900
    @achilpal6900 13 วันที่ผ่านมา

    Classic Mr. Fred… always present, always useful! Thank you! 🎉

  • @Manfred_Z
    @Manfred_Z 13 วันที่ผ่านมา

    Thank you very much... It's great! You are the best!

  • @elnaghy
    @elnaghy 13 วันที่ผ่านมา

    good work :: thank you for yor efforts

  • @twilkpsu
    @twilkpsu 13 วันที่ผ่านมา

    Great work! 🎉🎉🎉

  • @johnc3455
    @johnc3455 16 วันที่ผ่านมา

    For the record, Shakespeare's nickname is "The Bard". Fred, Do you think you could make a video recommending a package structure and service pattern that uses psychopg context managers with the async rest functions in fastpi?

    • @mathbyteacademy
      @mathbyteacademy 15 วันที่ผ่านมา

      Easiest iis to probably just create a connection pool at api startup, and add it to the requests - that way it's always available in any endpoint by simply getting it from the request object. You can get more info here: fastapi.tiangolo.com/advanced/events/#lifespan-events or, specifically for psycopg, here: medium.com/@benshearlaw/asynchronous-postgres-with-python-fastapi-and-psycopg-3-fafa5faa2c08

  • @Nnnnnnnnnnnnnnnnnchf
    @Nnnnnnnnnnnnnnnnnchf 17 วันที่ผ่านมา

    👍🏻👍🏻👍🏻👍🏻👍🏻

  • @iwswordpress
    @iwswordpress 19 วันที่ผ่านมา

    So much useful info in such a short time!

  • @srinivaskalyan4313
    @srinivaskalyan4313 22 วันที่ผ่านมา

    Hi Fred, In this video you handled reading data from DB. Can you please also make a video on Postgres CRUD using pydantic models?

    • @mathbyteacademy
      @mathbyteacademy 21 วันที่ผ่านมา

      Hi @srinivaskalyan4313, there isn't much to say about it. Since no ORM is involved here, you just have to write your insert/update/delete SQL statements by hand, and run them using a cursor execute. You would use a parametrized SQL statement, using named placeholders that correspond to the Pydantic field names, and use a model dump to pass the values in the exec call. If you're looking for a more "automated" way, then you are starting to look at ORM-like functionality.

    • @srinivaskalyan4313
      @srinivaskalyan4313 21 วันที่ผ่านมา

      @@mathbyteacademy Thank you Fred.

    • @srinivaskalyan4313
      @srinivaskalyan4313 15 วันที่ผ่านมา

      @@mathbyteacademy Hi Fred, Have you used pandera for tabular data? If yes, how to mix and match pandera and pydantic? Say one for API and the other for ETL processes? Or should we not try that.

    • @mathbyteacademy
      @mathbyteacademy 15 วันที่ผ่านมา

      Never heard of it, so I have no idea.

    • @srinivaskalyan4313
      @srinivaskalyan4313 15 วันที่ผ่านมา

      @@mathbyteacademy Thank you Fred. I was wondering how to easily validate the pandas dataframes with pydantic and came across this pandera library.

  • @srinivaskalyan4313
    @srinivaskalyan4313 22 วันที่ผ่านมา

    Please do the co-pilot tutorial 👍

  • @mailsonferreira-i4n
    @mailsonferreira-i4n 22 วันที่ผ่านมา

    You do great videos! Keep them coming. I'm a senior citizen and I love your method of presentation.

    • @mathbyteacademy
      @mathbyteacademy 22 วันที่ผ่านมา

      Thank you, I'm glad you like the videos!

  • @iwswordpress
    @iwswordpress 24 วันที่ผ่านมา

    Thanks! Always very well presented and explained.

  • @pikaa-si9ie
    @pikaa-si9ie 25 วันที่ผ่านมา

    why did you archived the polymon project? 😭😭

    • @mathbyteacademy
      @mathbyteacademy 25 วันที่ผ่านมา

      That was a long time ago, and better Linux based alternatives became available, with a lot more people contributing to those projects than Polymon.

  • @MaxShapira2real
    @MaxShapira2real 26 วันที่ผ่านมา

    Great stuff Fred! You should give PySnooper a try. I think it does a better job than IceCream.

    • @mathbyteacademy
      @mathbyteacademy 23 วันที่ผ่านมา

      Interesting library, thanks for the tip!

  • @Jakub1989YTb
    @Jakub1989YTb 27 วันที่ผ่านมา

    Nice little gimmick. But I can already see the pain of trying to remove it later. When using logging, you get more mature functionality and you can (and should) keep the log calls in.

    • @mathbyteacademy
      @mathbyteacademy 27 วันที่ผ่านมา

      Agreed, this is not meant to replace logging, but rather to help debug your code as your developing it (at least that's the way I have been using it). Replaces print statements, which have to be removed anyway before getting merged into the main code base, and for cases where I don't want to log things (many of these debugging print statements I use do not belong in the event log - I only keep debug logs to log things I think might be useful when debugging once the code is in production).

  • @bilal-khan
    @bilal-khan 27 วันที่ผ่านมา

    Your video is fantastic. Please keep sharing. We are waiting for your python deep dive part 5.

    • @bilal-khan
      @bilal-khan 27 วันที่ผ่านมา

      Will you be releasing part 5 of python deep dive?

    • @mathbyteacademy
      @mathbyteacademy 27 วันที่ผ่านมา

      Thanks Bilal!

    • @mathbyteacademy
      @mathbyteacademy 27 วันที่ผ่านมา

      Nothing on the horizon yet, been busy with work.

    • @bilal-khan
      @bilal-khan 27 วันที่ผ่านมา

      Can you a video on multiple inheritance?

  • @learningenglish903
    @learningenglish903 28 วันที่ผ่านมา

    Dear Teacher, Could you tell me what the upcoming course you plan to release will be? I am hoping you will build a massive, production-ready backend project. Additionally, could you provide the estimated release time so I can be prepared both mentally and financially to purchase it?

  • @Fillmore634b
    @Fillmore634b 29 วันที่ผ่านมา

    My dear friend, could you please do a long video (or a part of your “python-deepdive” course) about nested types in Python and which ones do (not) you use in your practice? I came across a discussion of nested types on stackoverflow a long time ago, I think TH-cam will ban the link and delete the comment, but it was called ...questions/7147785/nested-dictionaries-or-tuples-for-key (Asked 12 years, 10 months ago, Viewed 9k times) And there is complex code for comparing the performance of nested types in terms of time and memory. I also read that in Python, never use nested types and keep it simple. I think this is true. What do you think about it? What do you do in your practice? Which nested types do you prefer and why? I haven't seen videos like this on TH-cam, but I think this is one of the most important topics in Python. I want this kind of analysis from you, because I admire your “python-deepdive” course so much! Thank you!!

  • @Alterme93
    @Alterme93 หลายเดือนก่อน

    Thanks for another great video 😊 I have some questions that popped up when watching: 1. How do you save your data? Do you set up a custom serializer in your pydantic model or does psycopg help you with that? 2. Isn't it going to be difficult maintaining all of the sql-statements and keeping them in sync with your migrations as your api grows? 3. I was really curious regarding how you divide your classes into service classes etc. Do you have any good advice on how to write good SOLID code? 4. How do you write tests for your migrations, ensuring everything is in order? P.S I would really like a good SQL course! Thanks for your time! All the best, Erik

  • @mehrnooshh.kashani2571
    @mehrnooshh.kashani2571 หลายเดือนก่อน

    Thank you for great content, Keep up the good work!

  • @josephomondi629
    @josephomondi629 หลายเดือนก่อน

    Dude you don't know how long I've looked for a good video on this module. Thank you so so much and may you keep up the good work

  • @pratiksen3304
    @pratiksen3304 หลายเดือนก่อน

    Hi Fred, When I type "cli " in my command prompt I get the following error message: ModeuleNotFoundError: No module named 'converters' . The error is coming from main.py- Line number 5 "from converters.cli import converters_group" Could you please help ? I have cloned the repo and did the pip install -r requirements.txt and then did the "pip install --editable ." as well and then just typed "cli" and the mentioned error appeared

    • @pratiksen3304
      @pratiksen3304 หลายเดือนก่อน

      Update- the following solution solved the issue: export PYTHONPATH=.

  • @mybuddy11
    @mybuddy11 หลายเดือนก่อน

    Thank you so much, this is a great video not only for the content but also for the way you set it up and recorded it. The aspect ratio is very clear and reasonable for easy viewing and reading.

  • @Manfred_Z
    @Manfred_Z หลายเดือนก่อน

    You speak from my heart and I agree with you wholeheartedly with ORM. I do not want to use Object relational mappers. I want to have full control with SQL.

  • @HermannWinter
    @HermannWinter หลายเดือนก่อน

    my orm problems are solved ! :-) Thanks a lot. 👍

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Hehe... Anytime I can bring someone back from the dark side! 😉

  • @draxnorex
    @draxnorex หลายเดือนก่อน

    Great video! I love how you explain eveything so i do not have to remind myself about details of some libraries

  • @ipelezikis
    @ipelezikis หลายเดือนก่อน

    Invaluable content and teaching style. Pure maths background here so twice appreciated!

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Happy to hear you liked it!

  • @shtrumj
    @shtrumj หลายเดือนก่อน

    i would like to have more sql lessons

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      You're definitely in the minority 😔 Based on a poll in this channel, out of 8,700 subscribers, 129 people voted (always motivating to see such engagement), and of those only 17% were interested in SQL... However, I still plan to do some videos on SQL (or maybe even a full Udemy course on the subject??).

  • @iwswordpress
    @iwswordpress หลายเดือนก่อน

    Worth waiting for!

  • @guitardude1019
    @guitardude1019 หลายเดือนก่อน

    Didn't even know about yoyo, really cool library! Thanks for the great content

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Glad you found it informative!

  • @macleodfura
    @macleodfura หลายเดือนก่อน

    👍

  • @HermannWinter
    @HermannWinter หลายเดือนก่อน

    awesome tutorial, looking forward for part 2.

  • @milenovdaniel
    @milenovdaniel หลายเดือนก่อน

    +1 SQL

  • @avr4dev
    @avr4dev หลายเดือนก่อน

    This video definitely deserves like and comment for better promotion.

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Thanks! That would be nice, but very few people bother to take the time to do so.

  • @iwswordpress
    @iwswordpress หลายเดือนก่อน

    Excellent as ever! Look forward to part two...

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Thanks! Coming soon...

  • @hytgohg7169
    @hytgohg7169 หลายเดือนก่อน

    Thx Fred I watched all your courses here and on Udemy You are the best and we expect more from a good man like you

  • @andrescamilomontenegroarro6235
    @andrescamilomontenegroarro6235 หลายเดือนก่อน

    Thanks for the video Fred, you are awesome as always! I really improved my python overall programming skills with your udemy courses! Keep it up!

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Glad you find the content useful, thanks!

  • @abhi.isnt.awesome
    @abhi.isnt.awesome หลายเดือนก่อน

    Hi Fred, do you plan to make a new course on udemy like on fastapi, django and flask. If yes, when may we expect the course.

    • @dhavalsavalia
      @dhavalsavalia หลายเดือนก่อน

      +1 for FastAPI ecosystem course. However, given Fred is having intermediate engineers as audience, I would like to see deeper dive on FastAPI like your Pydantic and Python deeper dive courses.

    • @abhi.isnt.awesome
      @abhi.isnt.awesome หลายเดือนก่อน

      @@dhavalsavalia I am beginner. I would love to learn as much as I can from Fred as I never had a good instructor.

  • @Angelas20
    @Angelas20 หลายเดือนก่อน

    why do we need celery then? 😕😕😕😕😕😕

    • @mathbyteacademy
      @mathbyteacademy หลายเดือนก่อน

      Celery? You mean the vegetable that leaves a bad taste in my mouth? or... the software library, that also leaves a bad taste in my mouth? 😀 Celery is OK, but not my first choice when writing a micro service type of architecture. I'd rather have complete granular control over everything. Past experiences in Celery made me look elsewhere. It's been a while so maybe things have improved, but I did run across this recent blog post that indicates they may not: docs.hatchet.run/blog/problems-with-celery

  • @sprobertson
    @sprobertson หลายเดือนก่อน

    I like these more project-based/conceptual videos a lot, make more plz!