DEV Community


Discussion on: Namedtuple in Python

orenovadia profile image

attrs (predecessor of the builtin dataclasses module), is a library that helps create data transfer objects. It has a section of why you should prefer it over namedtuples. I think it is well worth reading.

(However, they do not mention that named tuples are much faster to instantiate than attrs classes, because they run no validations and are implemented in C)

rkshrksh profile image
Rakesh Gautam Author

Yes. As mentioned on attrs docs, Namedtuples have some limitations over attrs. But for the simple use, where you just have to give names to your fields and want a faster solution, I think Namedtuples are the way to go.

Namedtuples are ultimately just Tuples, they are not supposed to be used as some replacement for classes.