Differences between revisions 1 and 2
Revision 1 as of 2021-06-13 06:09:16
Size: 459
Editor: PieterSmit
Comment:
Revision 2 as of 2021-06-13 06:12:44
Size: 562
Editor: PieterSmit
Comment:
Deletions are marked like this. Additions are marked like this.
Line 17: Line 17:
 * [[Python/FastApi]] also uses pydantic + types to auto validate incoming data when building an api.

Python/Types

  • Indicate the type of a variable, is optional.
  • Benefits, is warnings from editors if used wrong, or passing wrong type.
  • Use pydantic to validate incoming data, by creating a basemodel class.

    # e.g.
    from pydantic import BaseModel
    
    
    class User(BaseModel):
        id: int
        name = "John Doe"
        signup_ts: Optional[datetime] = None
        friends: List[int] = []
  • https://fastapi.tiangolo.com/python-types/

  • Python/FastApi also uses pydantic + types to auto validate incoming data when building an api.

Python/Types (last edited 2021-06-13 06:12:44 by PieterSmit)