When should I use dataclasses instead of regular classes in Python?

Gihin Oha
Member
Joined: 2025-02-16 08:26:47
2025-02-16 08:51:49

Hi everyone,
I recently discovered the dataclasses module in Python and it seems like a great way to handle classes that are mainly used for storing data. But I’m unsure when it's the right choice. I’ve been writing regular classes for years, so what’s the benefit of switching to dataclasses?

Is it best to use dataclasses when you’re just storing attributes, or are there scenarios where regular classes are still better? Also, I’ve heard about @dataclass(frozen=True)—what does that do exactly?

Would love to hear some use cases!