shot of post - πŸ’­ Fields - Pydantic

Here's my thought on πŸ’­ Fields - Pydantic


exclude=True and repr=False is a good pydantic combination for secret attributes such as user passwords, or hashed passwords. exclude keeps it out of model_dumps, and repr keeps it out of the logs.

from pydantic import BaseModel, Field

class User(BaseModel): name: str = Field(repr=True)
age: int = Field(repr=False)

user = User(name='John', age=42) print(user) #> name='John'


!!! note This post is a thought. It's a short note that I make about someone else's content online. Learn more about the process [[ thoughts ]]

{.text-opacity-80} This post was a thought by Waylon Walker see all my thoughts at https://waylonwalker.com/thoughts