Skip to content

Parameters

Request parameters are functions returning an object used to provide the parameter metadata before request, such as param type, validation, alias, etc.

These functions include:

  • Query
  • Body
  • Path
  • Form
  • File
  • Header
  • Cookie

Import them directly from sensei

from sensei import Query, Body, Path, Form, File, Header, Cookie

There are two ways how to use them:

@router.get('/users/{id_}')
def get_user(id_: Annotated[int, Path()]) -> User:
    pass
@router.get('/users/{id_}')
def get_user(id_: int = Path()) -> User:
    pass

sensei.Query

Query(default=Undefined, *, default_factory=_Unset, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a query parameter for a path operation.

Example
@router.get('/search')
def search_users(cls, query: Annotated[str, Query()] = "") -> list[User]:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Query

Query parameter for a path operation

TYPE: Query

Source code in sensei/_internal/_core/params_functions.py
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
def Query(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> _params_Query:
    """
    Declare a query parameter for a **path operation**.

    Example:
        ```python
        @router.get('/search')
        def search_users(cls, query: Annotated[str, Query()] = "") -> list[User]:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_Query: Query parameter for a **path operation**
    """
    return _params_Query(
        default=default,
        default_factory=default_factory,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )

sensei.Body

Body(default=Undefined, *, default_factory=_Unset, embed=True, media_type='application/json', alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a body parameter for a path operation

Example
@router.post('/create_user')
def create_user(cls, user: Annotated[User, Body()]) -> User:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

embed

If True, the parameter will be expected in a JSON body as a key, instead of being the JSON body itself.

TYPE: bool DEFAULT: True

media_type

The media type of this parameter field, e.g., "application/json".

TYPE: str DEFAULT: 'application/json'

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Body

Body parameter for a path operation

TYPE: Body

Source code in sensei/_internal/_core/params_functions.py
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
def Body(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        embed: bool = True,
        media_type: str = "application/json",
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> _params_Body:
    """
    Declare a body parameter for a **path operation**

    Example:
        ```python
        @router.post('/create_user')
        def create_user(cls, user: Annotated[User, Body()]) -> User:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        embed (bool):
            If `True`, the parameter will be expected in a JSON body as a key, instead
            of being the JSON body itself.
        media_type (str):
            The media type of this parameter field, e.g., "application/json".
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_Body: Body parameter for a **path operation**
    """
    return _params_Body(
        default=default,
        default_factory=default_factory,
        embed=embed,
        media_type=media_type,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )

sensei.Path

Path(default=..., *, default_factory=_Unset, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a path parameter for a path operation.

Example
@router.get('/posts/{id_}')
def get_post(cls, id_: Annotated[int, Path()]) -> Post:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: ...

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

alias

Alternative name for the parameter field, used for data extraction, useful when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema. This argument is deprecated in favor of json_schema_extra.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Path

Path parameter for a path operation

TYPE: Path

Source code in sensei/_internal/_core/params_functions.py
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
def Path(
        default: Any = ...,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> _params_Path:
    """
    Declare a path parameter for a **path operation**.

    Example:
        ```python
        @router.get('/posts/{id_}')
        def get_post(cls, id_: Annotated[int, Path()]) -> Post:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        alias (Optional[str]):
            Alternative name for the parameter field, used for data extraction,
            useful when parameter name conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema. This argument is deprecated in favor of `json_schema_extra`.

    Returns:
        _params_Path: Path parameter for a **path operation**
    """
    return _params_Path(
        default=default,
        default_factory=default_factory,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        example=_Unset,
        examples=examples,
        **extra,
    )

sensei.Form

Form(default=Undefined, *, default_factory=_Unset, embed=True, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a form parameter for a path operation.

Example
@router.post('/login')
def login_user(cls, username: Annotated[str, Form()], password: Annotated[str, Form()]) -> str:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

embed

If True, the parameter will be expected in a JSON body as a key, instead of being the JSON body itself.

TYPE: bool DEFAULT: True

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Form

Form parameter for a path operation

TYPE: Any

Source code in sensei/_internal/_core/params_functions.py
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
def Form(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        embed: bool = True,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> Any:
    """
    Declare a form parameter for a **path operation**.

    Example:
        ```python
        @router.post('/login')
        def login_user(cls, username: Annotated[str, Form()], password: Annotated[str, Form()]) -> str:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        embed (bool):
            If `True`, the parameter will be expected in a JSON body as a key, instead
            of being the JSON body itself.
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_Form: Form parameter for a **path operation**
    """
    media_type = "application/x-www-form-urlencoded"
    return _params_Form(
        default=default,
        default_factory=default_factory,
        embed=embed,
        media_type=media_type,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )

sensei.File

File(default=Undefined, *, default_factory=_Unset, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a file parameter for a path operation.

Example
@router.post('/upload')
def upload_image(cls, image: Annotated[bytes, File()]) -> str:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_File

File parameter for a path operation

TYPE: Any

Source code in sensei/_internal/_core/params_functions.py
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
def File(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> Any:
    """
    Declare a file parameter for a **path operation**.

    Example:
        ```python
        @router.post('/upload')
        def upload_image(cls, image: Annotated[bytes, File()]) -> str:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_File: File parameter for a **path operation**
    """
    media_type = "multipart/form-data"
    return _params_File(
        default=default,
        default_factory=default_factory,
        media_type=media_type,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )

sensei.Header

Header(default=Undefined, *, default_factory=_Unset, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a header parameter for a path operation.

Example
@router.get('/download')
def download_file(cls, x_token: Annotated[str, Header()]) -> bytes:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Header

Header parameter for a path operation

TYPE: Header

Source code in sensei/_internal/_core/params_functions.py
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
def Header(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> _params_Header:
    """
    Declare a header parameter for a **path operation**.

    Example:
        ```python
        @router.get('/download')
        def download_file(cls, x_token: Annotated[str, Header()]) -> bytes:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_Header: Header parameter for a **path operation**
    """
    return _params_Header(
        default=default,
        default_factory=default_factory,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )

sensei.Cookie

Cookie(default=Undefined, *, default_factory=_Unset, alias=None, title=None, description=None, gt=None, ge=None, lt=None, le=None, min_length=None, max_length=None, pattern=None, discriminator=None, strict=_Unset, multiple_of=_Unset, allow_inf_nan=_Unset, max_digits=_Unset, decimal_places=_Unset, examples=None, **extra)

Declare a cookie parameter for a path operation.

Example
@router.get('/verify')
def verify_user(cls, session_id: Annotated[str, Cookie()]) -> bool:
    pass
PARAMETER DESCRIPTION
default

Default value if the parameter field is not set.

TYPE: Any DEFAULT: Undefined

default_factory

Callable to generate the default value.

TYPE: Union[Callable[[], Any], None] DEFAULT: _Unset

alias

Alternative name for the parameter field, used when parameter name conflicts with reserved words.

TYPE: Optional[str] DEFAULT: None

title

Human-readable title for the parameter.

TYPE: Optional[str] DEFAULT: None

description

Human-readable description for the parameter.

TYPE: Optional[str] DEFAULT: None

gt

Specifies that the value must be greater than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

ge

Specifies that the value must be greater than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

lt

Specifies that the value must be less than this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

le

Specifies that the value must be less than or equal to this value, applicable only to numbers.

TYPE: Optional[float] DEFAULT: None

min_length

Minimum length for string values.

TYPE: Optional[int] DEFAULT: None

max_length

Maximum length for string values.

TYPE: Optional[int] DEFAULT: None

pattern

Regular expression pattern for string values.

TYPE: Optional[str] DEFAULT: None

discriminator

Field name for discriminating the type in a tagged union.

TYPE: Union[str, None] DEFAULT: None

strict

Enables strict validation if set to True.

TYPE: Union[bool, None] DEFAULT: _Unset

multiple_of

Specifies that the value must be a multiple of this value, applicable only to numbers.

TYPE: Union[float, None] DEFAULT: _Unset

allow_inf_nan

Allows values inf, -inf, and nan, applicable only to numbers.

TYPE: Union[bool, None] DEFAULT: _Unset

max_digits

Maximum number of digits allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

decimal_places

Maximum number of decimal places allowed for numeric values.

TYPE: Union[int, None] DEFAULT: _Unset

examples

Example values for the parameter.

TYPE: Optional[List[Any]] DEFAULT: None

**extra

Extra fields for JSON Schema.

TYPE: Any DEFAULT: {}

RETURNS DESCRIPTION
_params_Cookie

Cookie parameter for a path operation.

TYPE: Cookie

Source code in sensei/_internal/_core/params_functions.py
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
def Cookie(
        default: Any = Undefined,
        *,
        default_factory: Union[Callable[[], Any], None] = _Unset,
        alias: Optional[str] = None,
        title: Optional[str] = None,
        description: Optional[str] = None,
        gt: Optional[float] = None,
        ge: Optional[float] = None,
        lt: Optional[float] = None,
        le: Optional[float] = None,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        pattern: Optional[str] = None,
        discriminator: Union[str, None] = None,
        strict: Union[bool, None] = _Unset,
        multiple_of: Union[float, None] = _Unset,
        allow_inf_nan: Union[bool, None] = _Unset,
        max_digits: Union[int, None] = _Unset,
        decimal_places: Union[int, None] = _Unset,
        examples: Optional[List[Any]] = None,
        **extra: Any,
) -> _params_Cookie:
    """
    Declare a cookie parameter for a **path operation**.

    Example:
        ```python
        @router.get('/verify')
        def verify_user(cls, session_id: Annotated[str, Cookie()]) -> bool:
            pass
        ```

    Args:
        default (Any):
            Default value if the parameter field is not set.
        default_factory (Union[Callable[[], Any], None]):
            Callable to generate the default value.
        alias (Optional[str]):
            Alternative name for the parameter field, used when parameter name
            conflicts with reserved words.
        title (Optional[str]):
            Human-readable title for the parameter.
        description (Optional[str]):
            Human-readable description for the parameter.
        gt (Optional[float]):
            Specifies that the value must be greater than this value, applicable only to numbers.
        ge (Optional[float]):
            Specifies that the value must be greater than or equal to this value, applicable only to numbers.
        lt (Optional[float]):
            Specifies that the value must be less than this value, applicable only to numbers.
        le (Optional[float]):
            Specifies that the value must be less than or equal to this value, applicable only to numbers.
        min_length (Optional[int]):
            Minimum length for string values.
        max_length (Optional[int]):
            Maximum length for string values.
        pattern (Optional[str]):
            Regular expression pattern for string values.
        discriminator (Union[str, None]):
            Field name for discriminating the type in a tagged union.
        strict (Union[bool, None]):
            Enables strict validation if set to `True`.
        multiple_of (Union[float, None]):
            Specifies that the value must be a multiple of this value, applicable only to numbers.
        allow_inf_nan (Union[bool, None]):
            Allows values `inf`, `-inf`, and `nan`, applicable only to numbers.
        max_digits (Union[int, None]):
            Maximum number of digits allowed for numeric values.
        decimal_places (Union[int, None]):
            Maximum number of decimal places allowed for numeric values.
        examples (Optional[List[Any]]):
            Example values for the parameter.
        **extra (Any):
            Extra fields for JSON Schema.

    Returns:
        _params_Cookie: Cookie parameter for a *path operation*.
    """
    return _params_Cookie(
        default=default,
        default_factory=default_factory,
        alias=alias,
        title=title,
        description=description,
        gt=gt,
        ge=ge,
        lt=lt,
        le=le,
        min_length=min_length,
        max_length=max_length,
        pattern=pattern,
        discriminator=discriminator,
        strict=strict,
        multiple_of=multiple_of,
        allow_inf_nan=allow_inf_nan,
        max_digits=max_digits,
        decimal_places=decimal_places,
        examples=examples,
        **extra,
    )