7 ms·
I have been using python library Pydantic with FastApi for input and output data validation for Rest API and it solves some of the problems. I wanted to check
by ringofchaos 3y ago
I have been using python library Pydantic with FastApi for input and output data validation for Rest API and it solves some of the problems.
I wanted to check if the use case can be generalized for all situations.
For example, the code below will throw a runtime error
* Input should be a valid integer, unable to parse string as an integer [type=int_parsing, input_value='A', input_type=str] *
```
from pydantic import BaseModel
class User(BaseModel):
id: int
name: str
def print_user(user: User):
print(user.name, user.id)
user_1 = User(id="A", name="John")
print_user(user_1)
```
I have also been using typescript with React Application and really find it better compared to python due to type checking.
But I can still imagine a future when type-checking gets incorporated in native python, unlike javascript/typescript. The groundwork has been laid already with type hints.