- https://github.com/python-attrs/attrs
- https://github.com/mahmoud/glom
- https://github.com/pytoolz/toolz
- https://github.com/Suor/funcy
- https://github.com/dabeaz/curio
ps: dabaez has great educational content on writing idiomatic python, definitely worth checking out
An honorable mention of norvig's classic essays, which got me into python while I was in college, over 12y ago: https://norvig.com/spell-correct.html.Aside from reading code, _writing_ something that you know it exist (e.g glom) and then comparing it to how others have done it is also a great learning experience.
But while this was brewing, attrs ate their lunch. Data Classes just don't go far enough compared to what attrs [1] has provided for a while now. If there's a compelling reason to switch, I haven't found it yet.
Can I use Data Classes in a library supporting Python 2.7, 3.4-3.7? I don't think the answer is yes today.
import attr
@attr.s
class Key(object):
modifier = attr.ib()
key = attr.ib()
function = attr.ib()
argument = attr.ib()
keys = [
Key(MODKEY, XK_p, spawn, {'v': dmenucmd}),
Key(MODKEY|ShiftMask, XK_Return, spawn, {'v': termcmd}),
# ...
]
which gets you the concise and readable syntax of C structs, while keeping these things as actual attributes as if they were classes (e.g., [key.modifier for key in keys] will work).And you get designated initializers via Python's usual keyword-argument syntax, the ability to specify attr.ib(default=...), and a few other things.
Or if / when PEP 557 gets adopted.
I should say though, for simple POJO-style classes @attr.s (https://github.com/python-attrs/attrs) has replaced 90% of my namedtuple usage.