Skip to main content

Query

Declare a query parameter for a path operation. Query parameters are the key-value pairs that appear after the ? in a URL.

Signature

Parameters

Any
default:"Undefined"
Default value if the parameter field is not set. If not provided, the query parameter will be required.
str | None
default:"None"
An alternative name for the parameter field. This will be used to extract the data and for the generated OpenAPI. Particularly useful when you can’t use the name you want because it is a Python reserved keyword.
str | None
default:"None"
Human-readable title for the parameter.
str | None
default:"None"
Human-readable description for the parameter.
float | None
default:"None"
Greater than validation. If set, the value must be greater than this. Only applicable to numbers.
float | None
default:"None"
Greater than or equal validation. If set, the value must be greater than or equal to this. Only applicable to numbers.
float | None
default:"None"
Less than validation. If set, the value must be less than this. Only applicable to numbers.
float | None
default:"None"
Less than or equal validation. If set, the value must be less than or equal to this. Only applicable to numbers.
int | None
default:"None"
Minimum length for strings.
int | None
default:"None"
Maximum length for strings.
str | None
default:"None"
RegEx pattern for strings.
str | None
default:"None"
Parameter field name for discriminating the type in a tagged union.
bool | None
default:"None"
If True, strict validation is applied to the field.
float | None
default:"None"
Value must be a multiple of this. Only applicable to numbers.
bool | None
default:"None"
Allow inf, -inf, nan. Only applicable to numbers.
int | None
default:"None"
Maximum number of allowed digits for numbers.
int | None
default:"None"
Maximum number of decimal places allowed for numbers.
list[Any] | None
default:"None"
Example values for this field.
bool | str | None
default:"None"
Mark this parameter field as deprecated. It will affect the generated OpenAPI (visible at /docs).
bool
default:"True"
Whether to include this parameter field in the generated OpenAPI.
dict[str, Any] | None
default:"None"
Any additional JSON schema data.

Examples

Optional Query Parameter

Required Query Parameter

A query parameter is required when there is no default value.

Query Parameter with Default Value

String Validations

Pattern Validation

Query Parameter with Alias

Use alias when the query parameter name in the URL needs to be different from the Python variable name (e.g., for kebab-case parameters).

Deprecating Parameters

Exclude from OpenAPI

Setting include_in_schema=False hides the parameter from the auto-generated API documentation.

List Query Parameters

This allows multiple values for the same query parameter: /items/?q=foo&q=bar