MENU

Fun & Interesting

Which Python @dataclass is best? Feat. Pydantic, NamedTuple, attrs...

mCoding 113,928 lượt xem 3 years ago
Video Not Working? Fix It Now

Get rid of boilerplate in writing classes.

Which dataclass alternative should you use though? In this video we test dataclasses, attrs, tuple, namedtuple, NamedTuple, dict, SimpleNamespace, and Pydantic BaseModel for speed, memory efficiency, and features.

― mCoding with James Murphy (https://mcoding.io)

Source code: https://github.com/mCodingLLC/VideosSampleCode
Previous dataclasses video: https://youtu.be/vBH6GRJ1REM

dataclasses: https://docs.python.org/3/library/dataclasses.html
attrs: https://www.attrs.org/en/stable/examples.html
namedtuple: https://docs.python.org/3/library/collections.html#collections.namedtuple
NamedTuple: https://docs.python.org/3/library/typing.html#typing.NamedTuple
SimpleNamespace: https://docs.python.org/3/library/types.html#types.SimpleNamespace
Pydantic: https://pydantic-docs.helpmanual.io/usage/models/

SUPPORT ME ⭐
---------------------------------------------------
Patreon: https://patreon.com/mCoding
Paypal: https://www.paypal.com/donate/?hosted_button_id=VJY5SLZ8BJHEE
Other donations: https://mcoding.io/donate

Top patrons and donors: Jameson, Laura M, Dragos C, Vahnekie, John Martin, Casey G, Pieter G, Krisztian M, Sigmanificient

BE ACTIVE IN MY COMMUNITY 😄
---------------------------------------------------
Discord: https://discord.gg/Ye9yJtZQuN
Github: https://github.com/mCodingLLC/
Reddit: https://www.reddit.com/r/mCoding/
Facebook: https://www.facebook.com/james.mcoding

CHAPTERS
---------------------------------------------------
0:00 Intro
1:04 dataclass
1:24 attrs
2:13 tuple, namedtuple, NamedTuple
4:05 dict
4:39 SimpleNamespace
4:58 Pydantic
6:39 Speed comparison
8:41 Memory comparison
9:15 Feature matrix and winners

Comment