# pydantic 2.14.2 (MIT), harvested by tools/harvest_corpus.py
=== input
A string used for storing sensitive information that you do not want to be visible in logging or tracebacks.

    When the secret value is nonempty, it is displayed as `'**********'` instead of the underlying value in
    calls to [`repr()`][repr] and [`str()`][str]. If the value _is_ empty, it is displayed as `''`.

    Two `SecretStr` types compare equal if the secret values are equal. Constant-time comparison is achieved
    (using [`secrets.compare_digest()`][secrets.compare_digest]).

    ```python
    from pydantic import BaseModel, SecretStr

    class User(BaseModel):
        username: str
        password: SecretStr

    user = User(username='scolvin', password='password1')

    print(user)
    #> username='scolvin' password=SecretStr('**********')
    print(user.password.get_secret_value())
    #> password1
    print((SecretStr('password'), SecretStr('')))
    #> (SecretStr('**********'), SecretStr(''))
    ```

    As seen above, by default, [`SecretStr`][pydantic.types.SecretStr] (and [`SecretBytes`][pydantic.types.SecretBytes])
    will be serialized as `**********` when serializing to json.

    You can use a [field serializer](../concepts/serialization.md#field-serializers) to dump the
    secret as plain-text when serializing to json.

    ```python
    from pydantic import BaseModel, SecretBytes, SecretStr, field_serializer

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

        @field_serializer('password', 'password_bytes', when_used='json')
        def dump_secret(self, v):
            return v.get_secret_value()

    model = Model(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')
    print(model)
    #> password=SecretStr('**********') password_bytes=SecretBytes(b'**********')
    print(model.password)
    #> **********
    print(model.model_dump())
    '''
    {
        'password': SecretStr('**********'),
        'password_bytes': SecretBytes(b'**********'),
    }
    '''
    print(model.model_dump_json())
    #> {"password":"IAmSensitive","password_bytes":"IAmSensitiveBytes"}
    ```
    
=== parse google
short_description: 'A string used for storing sensitive information that you do not want to be visible in logging or tracebacks.'
long_description: |
  When the secret value is nonempty, it is displayed as `'**********'` instead of the underlying value in
  calls to [`repr()`][repr] and [`str()`][str]. If the value _is_ empty, it is displayed as `''`.
  
  Two `SecretStr` types compare equal if the secret values are equal. Constant-time comparison is achieved
  (using [`secrets.compare_digest()`][secrets.compare_digest]).
  
  ```python
  from pydantic import BaseModel, SecretStr
  
  class User(BaseModel):
      username: str
      password: SecretStr
  
  user = User(username='scolvin', password='password1')
  
  print(user)
  #> username='scolvin' password=SecretStr('**********')
  print(user.password.get_secret_value())
  #> password1
  print((SecretStr('password'), SecretStr('')))
  #> (SecretStr('**********'), SecretStr(''))
  ```
  
  As seen above, by default, [`SecretStr`][pydantic.types.SecretStr] (and [`SecretBytes`][pydantic.types.SecretBytes])
  will be serialized as `**********` when serializing to json.
  
  You can use a [field serializer](../concepts/serialization.md#field-serializers) to dump the
  secret as plain-text when serializing to json.
  
  ```python
  from pydantic import BaseModel, SecretBytes, SecretStr, field_serializer
  
  class Model(BaseModel):
      password: SecretStr
      password_bytes: SecretBytes
  
      @field_serializer('password', 'password_bytes', when_used='json')
      def dump_secret(self, v):
          return v.get_secret_value()
  
  model = Model(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')
  print(model)
  #> password=SecretStr('**********') password_bytes=SecretBytes(b'**********')
  print(model.password)
  #> **********
  print(model.model_dump())
  '''
  {
      'password': SecretStr('**********'),
      'password_bytes': SecretBytes(b'**********'),
  }
  '''
  print(model.model_dump_json())
  #> {"password":"IAmSensitive","password_bytes":"IAmSensitiveBytes"}
  ```
blank_after_short_description: True
blank_after_long_description: False
style: google
=== detect
rest
=== compose google
A string used for storing sensitive information that you do not want to be visible in logging or tracebacks.

When the secret value is nonempty, it is displayed as `'**********'` instead of the underlying value in
calls to [`repr()`][repr] and [`str()`][str]. If the value _is_ empty, it is displayed as `''`.

Two `SecretStr` types compare equal if the secret values are equal. Constant-time comparison is achieved
(using [`secrets.compare_digest()`][secrets.compare_digest]).

```python
from pydantic import BaseModel, SecretStr

class User(BaseModel):
    username: str
    password: SecretStr

user = User(username='scolvin', password='password1')

print(user)
#> username='scolvin' password=SecretStr('**********')
print(user.password.get_secret_value())
#> password1
print((SecretStr('password'), SecretStr('')))
#> (SecretStr('**********'), SecretStr(''))
```

As seen above, by default, [`SecretStr`][pydantic.types.SecretStr] (and [`SecretBytes`][pydantic.types.SecretBytes])
will be serialized as `**********` when serializing to json.

You can use a [field serializer](../concepts/serialization.md#field-serializers) to dump the
secret as plain-text when serializing to json.

```python
from pydantic import BaseModel, SecretBytes, SecretStr, field_serializer

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

    @field_serializer('password', 'password_bytes', when_used='json')
    def dump_secret(self, v):
        return v.get_secret_value()

model = Model(password='IAmSensitive', password_bytes=b'IAmSensitiveBytes')
print(model)
#> password=SecretStr('**********') password_bytes=SecretBytes(b'**********')
print(model.password)
#> **********
print(model.model_dump())
'''
{
    'password': SecretStr('**********'),
    'password_bytes': SecretBytes(b'**********'),
}
'''
print(model.model_dump_json())
#> {"password":"IAmSensitive","password_bytes":"IAmSensitiveBytes"}
```
