Hacker News new | ask | show | jobs
by Nextgrid 1658 days ago
> typing

I believe there's a third-party package "django-stubs" that provides type hints for Django code. For your own code, it's just Python in the end so you can type-hint it as you normally would.

> Pydantic models integration

There isn't as far as I know. Django has its own model layer however unlike Pydantic, Django's is purely for the DB level, it's not there to (de?)serialize JSON.

In the Django world you'd typically use Django Rest Framework serializers for that. Now you can use Pydantic and it probably won't be too much work to make them work with DRF, but whether it's worth it is a different matter - DRF gives you a lot of stuff for free such as auto-generating serializers based on DB models (including validation and everything) which you wouldn't get with Pydantic.

2 comments

There is https://django-ninja.rest-framework.com/ which would be an alternative for DRF ,heavily inspired by FastApi, that integrates with Pydantic.
Pydantic allows you to write super clean (in comparison to DRF) serializers using just type hints, as opposed to the declarative approach of DRF serializers. It's really nice and refreshing.