The chapter delves into the concept of discriminated unions in Pydantic models, where discriminators like string or callable types are crucial for efficient validation. It discusses using discriminators for nested models to enhance error handling and performance, showcasing examples like cat and dog models with pet type fields. The chapter also explores performance optimization techniques in Pydantic, such as 'skip validation' annotations and utilizing SIMD for faster JSON parsing.
You're using Pydantic and it seems pretty straightforward, right? But could you adopt some simple changes to your code that would make it a lot faster and more efficient? Chances are, you'll find a couple of the tips from Sydney Runkle that will do just that. Join us to talk about Pydantic performance tips here on Talk Python.
Episode sponsors
Sentry Error Monitoring, Code TALKPYTHON
Code Comments
Talk Python Courses
Links from the show