Skip to main content

StringConstraints

A field metadata class to apply constraints to str types. Use this class as an annotation via Annotated, as seen below.

Attributes

AttributeTypeDescription
strip_whitespace`boolNone` = None
to_upper`boolNone` = None
to_lower`boolNone` = None
strict`boolNone` = None
min_length`intNone` = None
max_length`intNone` = None
pattern`strPattern[str]
ascii_only`boolNone` = None

Constructor

Signature

def StringConstraints(
strip_whitespace: bool | None = None,
to_upper: bool | None = None,
to_lower: bool | None = None,
strict: bool | None = None,
min_length: int | None = None,
max_length: int | None = None,
pattern: str | Pattern[str]| None = None,
ascii_only: bool | None = None
) - > null

Parameters

NameTypeDescription
strip_whitespace`boolNone` = None
to_upper`boolNone` = None
to_lower`boolNone` = None
strict`boolNone` = None
min_length`intNone` = None
max_length`intNone` = None
pattern`strPattern[str]
ascii_only`boolNone` = None