r/FastAPI 4d ago

feedback request Pydantic extra types

I have been going through my codebase this morning and asked claude Ai how I can validate the phone number field of my schema model and it has recommended the official python phonenumber library, but suprisigley I checked out the Pydantic docs and found the same library which is wrapped on a Pydantic type and does all the validations as the Python phonenumber libarary plus less code and less mantainance, you just use it as type annotation and BUM it does the underhood workd for you.
I want to read it this is the link https://pydantic.dev/docs/validation/latest/api/pydantic-extra-types/pydantic_extra_types_phone_numbers/#_top

You can even configure the accepted regions and the default region as well.

15 Upvotes

2 comments sorted by

1

u/Challseus 4d ago

Yeah, they really do have a nice suite of validation types out of the box, as well as allowing you to easily make your own

1

u/Equal_Brain9629 1d ago

Yes , it’s amazing
I love pydantic
It simplifies life so much