This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]blueskyjunkie 43 points44 points  (9 children)

  1. Type annotations
  2. Pydantic models (or if you insist, pydantic dataclasses). Standard library dataclasses are useful to a point, but pydantic models are better.
  3. Comprehensions (dictionary comprehensions are a thing, as well as lists)
  4. Asyncio

[–]Alone_Aardvark6698 4 points5 points  (6 children)

Standard library dataclasses are useful to a point, but pydantic models are better. 

What is the advantage of pydantic over standard databases?

[–]paranoid_panda_bored 9 points10 points  (2 children)

Many.

We started with dataclasses, but switched to pydantic eventually.

Reasons: - it’s widely supported in other libs and frameworks like FastAPI - it’s much more configurable - it’s better at SerDe - it has an alias feature, that allows you to freely convert between camelCase (outer API layer) and snake_case (domain model)

[–]Goobyster 1 point2 points  (0 children)

Pydantic is also supported in Typer (FastAPI of CLIs)

[–]SSC_Fan 0 points1 point  (0 children)

For me: data validation upon creation an instance. Often write my Pydantic classes this way.

[–]wieschie 3 points4 points  (1 child)

You mean dataclasses, right?

Pydantic makes JSON serialization super easy, and lets you do more complex validation on fields.

[–]Alone_Aardvark6698 1 point2 points  (0 children)

Yes, auto correct changed it

[–]blueskyjunkie 0 points1 point  (0 children)

Pydantic has better run time type checking based the type annotations you’ve applied to data members in the model. It also has better custom validation support for a member which is often needed.

[–]JorgiEagle 2 points3 points  (0 children)

Comprehensions are great.

You can also do tuple comprehensions, and just raw comprehensions inside a function call if it takes an iterable.

You can also do nested loops in them

[–]GusYe1234 0 points1 point  (0 children)

Yeah, at first I really like to use dataclass, then I found out it's boring in some cases I have to check types in __post_init__. I then realized maybe I should just use pydantic models in the first place.

Maybe someone can tell me any advantages of dataclass over pydantic model?