3 ms·
Really like Pydantic - assuming you’re happy to step outside the standard library. It does have a few sharp edges, but out of the box it includes all the stuff
by darkteflon 2y ago
Really like Pydantic - assuming you’re happy to step outside the standard library. It does have a few sharp edges, but out of the box it includes all the stuff you eventually end up needing anyway. attrs is the other big Python parsing / validation library. I know nothing about it other than it’s also popular and that it distinguishes itself philosophically from Pydantic in a number of ways.
Don’t forget to use ‘ConfigDict(frozen=True)’ absolutely everywhere!
- richrichie 2y agoI looked up the docs as to what frozen does: > whether or not models are faux-immutable, i.e. whether __setattr__ is allowed (default: True) Seems everything is “faux” in Python world when it comes to typing ;)
- stavros 2y agoUnfortunately I can't downvote, but this comment is just flamebait.
- richrichie 2y agoAh, sensitive type you are! Read my reply above.
- Spivak 2y agoPython very much lives up to its goal of being a language for consenting adults. It's part of the culture that you don't write code that tries to forbid users of your code from doing "wrong" things and such efforts are mostly futile anyway. You can reach right into a Python object's internal data and modify it directly, taking away __setattr__ is just a suggestion. It's the same as in C where you can modify const variables if you're determined enough.
- richrichie 2y agoI love Python and use it extensively. I just find the extensive typing rituals a bit funny. If one needs this much bandaid (essentially for code editors), then Python is not a good choice for the task.
- ddejohn 2y agoHuge proponent of Pydantic. That said, there's also msgspec [1], which I've not used yet but plan to for my next project. It is supposedly quite a bit faster than Pydantic in de/serialization. [1] https://jcristharif.com/msgspec/ https://jcristharif.com/msgspec/