Skip to content
masterclass Buddy

Pydantic · Type Alias

SecretBytes

SecretStr and SecretBytes wrap sensitive strings and bytes. They hide the value in normal output and JSON, while get_secret_value() provides explicit access to the original.

Last updated

Syntax

class Model(BaseModel):
    password: SecretStr
    token: SecretBytes

In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.

Subscribe
  • SecretStr
  • SecretBytes
  • get_secret_value
  • BaseModel
  • field_serializer

Source: Secrets | Pydantic Docs. Checked 2026-11-03.