user id123 name john doe signuptsdatetime datetime2017 6 1 12 22 friends1 2 3 123 user id 123 name john doe signup_ts datetime datetime 2017 6 1 12 22 friends 1 2 3 123
from datetime import datetime
from typing import List, Union

from pydantic import BaseModel


class User(BaseModel):
    id: int
    name: str = "John Doe"
    signup_ts: Union[datetime, None] = None
    friends: List[int] = []


external_data = {
    "id": "123",
    "signup_ts": "2017-06-01 12:22",
    "friends": [1, "2", b"3"],
}
user = User(**external_data)
print(user)

print(user.id)