# pydantic 2.14.2 (MIT), harvested by tools/harvest_corpus.py
=== input

    !!! warning "Discouraged"
        This function is **discouraged** in favor of using
        [`Annotated`](https://docs.python.org/3/library/typing.html#typing.Annotated) with
        [`StringConstraints`][pydantic.types.StringConstraints] instead.

        This function will be **deprecated** in Pydantic 3.0.

        The reason is that `constr` returns a type, which doesn't play well with static analysis tools.

        === ":x: Don't do this"
            ```python
            from pydantic import BaseModel, constr

            class Foo(BaseModel):
                bar: constr(strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$')
            ```

        === ":white_check_mark: Do this"
            ```python
            from typing import Annotated

            from pydantic import BaseModel, StringConstraints

            class Foo(BaseModel):
                bar: Annotated[
                    str,
                    StringConstraints(
                        strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$'
                    ),
                ]
            ```

    A wrapper around `str` that allows for additional constraints.

    ```python
    from pydantic import BaseModel, constr

    class Foo(BaseModel):
        bar: constr(strip_whitespace=True, to_upper=True)

    foo = Foo(bar='  hello  ')
    print(foo)
    #> bar='HELLO'
    ```

    Args:
        strip_whitespace: Whether to remove leading and trailing whitespace.
        to_upper: Whether to turn all characters to uppercase.
        to_lower: Whether to turn all characters to lowercase.
        strict: Whether to validate the string in strict mode.
        min_length: The minimum length of the string.
        max_length: The maximum length of the string.
        pattern: A regex pattern to validate the string against.
        ascii_only: Whether the string should contain only ASCII characters.

    Returns:
        The wrapped string type.
    
=== parse google
short_description: '!!! warning "Discouraged"'
long_description: |
      This function is **discouraged** in favor of using
      [`Annotated`](https://docs.python.org/3/library/typing.html#typing.Annotated) with
      [`StringConstraints`][pydantic.types.StringConstraints] instead.
  
      This function will be **deprecated** in Pydantic 3.0.
  
      The reason is that `constr` returns a type, which doesn't play well with static analysis tools.
  
      === ":x: Don't do this"
          ```python
          from pydantic import BaseModel, constr
  
          class Foo(BaseModel):
              bar: constr(strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$')
          ```
  
      === ":white_check_mark: Do this"
          ```python
          from typing import Annotated
  
          from pydantic import BaseModel, StringConstraints
  
          class Foo(BaseModel):
              bar: Annotated[
                  str,
                  StringConstraints(
                      strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$'
                  ),
              ]
          ```
  
  A wrapper around `str` that allows for additional constraints.
  
  ```python
  from pydantic import BaseModel, constr
  
  class Foo(BaseModel):
      bar: constr(strip_whitespace=True, to_upper=True)
  
  foo = Foo(bar='  hello  ')
  print(foo)
  #> bar='HELLO'
  ```
blank_after_short_description: False
blank_after_long_description: True
style: google
- DocstringParam
  description: 'Whether to remove leading and trailing whitespace.'
  kind: param
  key: 'param'
  arg_name: 'strip_whitespace'
  is_optional: False
- DocstringParam
  description: 'Whether to turn all characters to uppercase.'
  kind: param
  key: 'param'
  arg_name: 'to_upper'
  is_optional: False
- DocstringParam
  description: 'Whether to turn all characters to lowercase.'
  kind: param
  key: 'param'
  arg_name: 'to_lower'
  is_optional: False
- DocstringParam
  description: 'Whether to validate the string in strict mode.'
  kind: param
  key: 'param'
  arg_name: 'strict'
  is_optional: False
- DocstringParam
  description: 'The minimum length of the string.'
  kind: param
  key: 'param'
  arg_name: 'min_length'
  is_optional: False
- DocstringParam
  description: 'The maximum length of the string.'
  kind: param
  key: 'param'
  arg_name: 'max_length'
  is_optional: False
- DocstringParam
  description: 'A regex pattern to validate the string against.'
  kind: param
  key: 'param'
  arg_name: 'pattern'
  is_optional: False
- DocstringParam
  description: 'Whether the string should contain only ASCII characters.'
  kind: param
  key: 'param'
  arg_name: 'ascii_only'
  is_optional: False
- DocstringReturns
  description: 'The wrapped string type.'
  kind: returns
  key: 'returns'
  is_generator: False
=== detect
google
=== compose google
!!! warning "Discouraged"
    This function is **discouraged** in favor of using
    [`Annotated`](https://docs.python.org/3/library/typing.html#typing.Annotated) with
    [`StringConstraints`][pydantic.types.StringConstraints] instead.

    This function will be **deprecated** in Pydantic 3.0.

    The reason is that `constr` returns a type, which doesn't play well with static analysis tools.

    === ":x: Don't do this"
        ```python
        from pydantic import BaseModel, constr

        class Foo(BaseModel):
            bar: constr(strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$')
        ```

    === ":white_check_mark: Do this"
        ```python
        from typing import Annotated

        from pydantic import BaseModel, StringConstraints

        class Foo(BaseModel):
            bar: Annotated[
                str,
                StringConstraints(
                    strip_whitespace=True, to_upper=True, pattern=r'^[A-Z]+$'
                ),
            ]
        ```

A wrapper around `str` that allows for additional constraints.

```python
from pydantic import BaseModel, constr

class Foo(BaseModel):
    bar: constr(strip_whitespace=True, to_upper=True)

foo = Foo(bar='  hello  ')
print(foo)
#> bar='HELLO'
```

Args:
    strip_whitespace: Whether to remove leading and trailing whitespace.
    to_upper: Whether to turn all characters to uppercase.
    to_lower: Whether to turn all characters to lowercase.
    strict: Whether to validate the string in strict mode.
    min_length: The minimum length of the string.
    max_length: The maximum length of the string.
    pattern: A regex pattern to validate the string against.
    ascii_only: Whether the string should contain only ASCII characters.

Returns:
    The wrapped string type.
