I use Attrs instead of Pydantic
21–30 of 76 posts
Re: I use Attrs instead of Pydantic
#22Quick look and from what I can see attrs/cattrs can't generate jsonschema => game over.
The existing generators are generally terrible.
Re: I use Attrs instead of Pydantic
#23Earlier quoted context omitted.
The `attrs` authors address it in the documentation: https://www.attrs.org/en/stable/overview.html#on-the-attr-s-... At first, some people have a negative gut reaction to that; resembling the reactions to Python’s significant whitespace. And as with that, once one gets used to it, the readability and explicitness of that API prevails and delights. For those who can’t swallow that API at all, attrs comes with serious…
Yes, I know. That doesn’t redeem it. I want never to have to read those names in python code I'm working with; the documentation entry doesn't achieve that. And anyway, the library is called “attrs”, so why is it imported as “attr”?
Python packaging is terrible, and giving package authors footguns like this. It's possible that it would be imported as "da39a3ee".
Re: I use Attrs instead of Pydantic
#24 size: float = None
is syntactic sugar for size: Optional[float]Re: I use Attrs instead of Pydantic
#25Quick look and from what I can see attrs/cattrs can't generate jsonschema => game over.
It would be better in the other way. Generate sane python models with it using existing jsonschema - similar to stuff like grpc, but without extra bits. The existing generators are generally terrible.
Re: I use Attrs instead of Pydantic
#26From my understanding, size: float = None is syntactic sugar for size: Optional[float]
Re: I use Attrs instead of Pydantic
#27Earlier quoted context omitted.
Yes, I know. That doesn’t redeem it. I want never to have to read those names in python code I'm working with; the documentation entry doesn't achieve that. And anyway, the library is called “attrs”, so why is it imported as “attr”?
>And anyway, the library is called “attrs”, so why is it imported as “attr”? Python packaging is terrible, and giving package authors footguns like this. It's possible that it would be imported as "da39a3ee".
Clearly if they had chosen "da39a3ee" we wouldn't need to discuss whether they had good judgement.
Re: I use Attrs instead of Pydantic
#28Earlier quoted context omitted.
The `attrs` authors address it in the documentation: https://www.attrs.org/en/stable/overview.html#on-the-attr-s-... At first, some people have a negative gut reaction to that; resembling the reactions to Python’s significant whitespace. And as with that, once one gets used to it, the readability and explicitness of that API prevails and delights. For those who can’t swallow that API at all, attrs comes with serious…
Yes, I know. That doesn’t redeem it. I want never to have to read those names in python code I'm working with; the documentation entry doesn't achieve that. And anyway, the library is called “attrs”, so why is it imported as “attr”?
Re: I use Attrs instead of Pydantic
#29Earlier quoted context omitted.
You could have a look at Marshmallow perhaps? I use it to great effect with marshmallow-dataclass so I don't have to define the boiler-plate data classes separately to the validation/schema. Essentially the dataclass (with type-hints) becomes the data-validation specification. Links: https://pypi.org/project/marshmallow-dataclass/ https://pypi.org/project/marshmallow/
Thanks, I've had a look at Marshmallow in the past, but it's still doing the extra bits of dealing with the extra bits of serialization, it never really felt all that dissimilar to Pydantic. What I've really been looking for something that I can just use to check a data structure i'm passing in to a function call is valid. One use case is related to state machines, where I'm providing some data along with a transitio…
Also, Attrs and Pydantic both support arbitrary additional validation on fields.
Re: I use Attrs instead of Pydantic
#30I'm a bit confused, because I ultimately understood Attrs and Pydantic to be aimed at solving different problems. I may've been wrong, but my understanding was that: * Attrs - To reduce the boilerplate of defining classes, pre-dates dataclasses, but still has a bunch of capabilities that dataclasses don't. * Pydantic - A declarative data validation + [de]serialization tool, mostly to be used at the boundaries between…
You could have a look at Marshmallow perhaps? I use it to great effect with marshmallow-dataclass so I don't have to define the boiler-plate data classes separately to the validation/schema. Essentially the dataclass (with type-hints) becomes the data-validation specification. Links: https://pypi.org/project/marshmallow-dataclass/ https://pypi.org/project/marshmallow/
https://pypi.org/project/desert/