←back to thread

Parse, Don't Validate (2019)

(lexi-lambda.github.io)
389 points melse | 3 comments | | HN request time: 0.627s | source
Show context
kortex ◴[] No.27642049[source]
This principle is how pydantic[0] utterly revolutionized my python development experience. I went from constantly having to test functions in repls, writing tons of validation boilerplate, and still getting TypeErrors and NoneTypeErrors and AttributeErrors left and right to like...just writing code. And it working! Like one time I wrote a few hundred lines of python over the course of a day and then just ran it... and it worked. I just sat there shocked, waiting for the inevitable crash and traceback to dive in and fix something, but it never came. In Python! Incredible.

[0] https://pydantic-docs.helpmanual.io/

replies(8): >>27642308 #>>27642664 #>>27643276 #>>27643474 #>>27644758 #>>27645737 #>>27646367 #>>27647141 #
1. dnadler ◴[] No.27642308[source]
We've had a similar experience using pydantic. We integrated it quite tightly with a django project and it's been awesome.
replies(1): >>27643187 #
2. theptip ◴[] No.27643187[source]
Where did you find it valuable to wire in to Django?
replies(1): >>27665028 #
3. dnadler ◴[] No.27665028[source]
We effectively use them as serializers, and also as a way to allow users to interact with the models in a controlled manner.

In our app, django essentially sits between a compute cluster and a front end. The pydantic objects are used to define the work to be done on the compute cluster.