Live data from Hacker News

I use Attrs instead of Pydantic

threeofwands.com

71–76 of 76 posts

Re: I use Attrs instead of Pydantic

#71

Pyantic and Cattrs both suffer with unacceptable issues and footguns. I have used Pydantic in production a lot and have played around with Cattrs. I've also looked at similar libraries like Dacite and marshmallow-dataclasses but none seem to be well thought out and mature. * Neither Pydantic nor Cattrs handle unions like how I'd expect (although Cattrs has stronger guarantees in converting Unions) >>> class Y(BaseMod…

You can tell pydantic not to mutate the field value in its definition when using Field

Re: I use Attrs instead of Pydantic

#72
post #17

Quick 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.

I wish json-schema was nicer to write and if it was I would do that. However its way too unfriendly, so using something like PyDantic models as the "source of truth" is much easier, and at least lets other clients generate definitions and validate their inputs / outputs even if the generated schemas aren't perfect.

Re: I use Attrs instead of Pydantic

#73

Earlier quoted context omitted.

As of 2021, there is now a complete Pydantic "CRUD stack" (ODMantic/SQLModel + FastAPI) that is ridiculously easy to get up and running with, and it has all of the features one might want in a brave new type safe world. By comparison, the system of tools around Attrs and Cattrs is a bit scattered and underdeveloped. I don't think there's a technical reason for it, that's just how it happened. It would be great to see…

SQLModel is brand new? why not just use sqlalchemy which is more mature?

The former wraps the latter, I think.

Re: I use Attrs instead of Pydantic

#74
post #17

Quick 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.

That's what warlock does.

Re: I use Attrs instead of Pydantic

#75
post #21

Having run into these issues with Pydantic, we've been using Mashumaro[1], which, while not having all the bells and whistles of Pydantic, has served us pretty well. 1: https://github.com/Fatal1ty/mashumaro

Wait so there is a Marshmallow and a Mashumaro which is the romanisation of the Japanese translation of marshmallow!? Talking about giving projects confusing names…

Re: I use Attrs instead of Pydantic

#76

Earlier quoted context omitted.

If it is a problem, import attr as attrs which is probably what I would do for consistency.

I want never to see the names attr.ib and attr.s in code that I am working on. So I don't understand how your suggestion solves the problem: it might not be me writing the code.

I never want to see Javascript code either, but being annoyed at Brendan Eich all the time is a bit futile.
Post reply on HN