Attrs, Pydantic, or Python Data Classes?

Published: 17 February 2023
on channel: ArjanCodes
85,231
3.8k

Data classes are a valuable tool in the Python programmer's toolkit. Despite their usefulness (I do like them a lot!), they do have limitations. In this video, I compare dataclasses with two alternative options, attrs and Pydantic, to help you decide which one to use in your code.

GitHub repository here: https://github.com/ArjanCodes/2023-attrs

✍🏻 Take a quiz on this topic: https://www.learntail.com/quiz/qgtggs

🚀 Next-Level Python Skillshare Class: https://skl.sh/3ZQkUEN

💡 Get my FREE 7-step guide to help you consistently design great software: https://arjancodes.com/designguide.

💻 ArjanCodes Blog: https://www.arjancodes.com/blog

🎓 Courses:
The Software Designer Mindset: https://www.arjancodes.com/mindset
The Software Designer Mindset Team Packages: https://www.arjancodes.com/sas
The Software Architect Mindset: Pre-register now! https://www.arjancodes.com/architect
Next Level Python: Become a Python Expert: https://www.arjancodes.com/next-level...
The 30-Day Design Challenge: https://www.arjancodes.com/30ddc

🛒 GEAR & RECOMMENDED BOOKS: https://kit.co/arjancodes.

👍 If you enjoyed this content, give this video a like. If you want to watch more of my upcoming videos, consider subscribing to my channel!

💬 Discord: https://discord.arjan.codes
🐦Twitter:   / arjancodes  
🌍LinkedIn:   / arjancodes  
🕵Facebook:   / arjancodes  
📱Instagram:   / arjancodes  

👀 Code reviewers:
- Yoriz
- Ryan Laursen
- James Dooley
- Dale Hagglund

🎥 Video edited by Mark Bacskai:   / bacskaimark  
💻 Code example by Henrique Branco:   / henriqueajnb  

🔖 Chapters:
0:00 Intro
1:34 Example explanation
4:20 Comparison
7:07 Attribute validation
11:26 Pros and cons dataclasses
13:00 Pros and cons attrs
14:14 Pros and cons Pydantic
15:58 Final thoughts
16:42 Outro

#arjancodes #softwaredesign #python

DISCLAIMER - The links in this description might be affiliate links. If you purchase a product or service through one of those links, I may receive a small commission. There is no additional charge to you. Thanks for supporting my channel so I can continue to provide you with free content each week!