fastapi 0.128.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. fastapi/__init__.py +25 -0
  2. fastapi/__main__.py +3 -0
  3. fastapi/_compat/__init__.py +41 -0
  4. fastapi/_compat/shared.py +206 -0
  5. fastapi/_compat/v2.py +568 -0
  6. fastapi/applications.py +4669 -0
  7. fastapi/background.py +60 -0
  8. fastapi/cli.py +13 -0
  9. fastapi/concurrency.py +41 -0
  10. fastapi/datastructures.py +183 -0
  11. fastapi/dependencies/__init__.py +0 -0
  12. fastapi/dependencies/models.py +193 -0
  13. fastapi/dependencies/utils.py +1021 -0
  14. fastapi/encoders.py +346 -0
  15. fastapi/exception_handlers.py +34 -0
  16. fastapi/exceptions.py +246 -0
  17. fastapi/logger.py +3 -0
  18. fastapi/middleware/__init__.py +1 -0
  19. fastapi/middleware/asyncexitstack.py +18 -0
  20. fastapi/middleware/cors.py +1 -0
  21. fastapi/middleware/gzip.py +1 -0
  22. fastapi/middleware/httpsredirect.py +3 -0
  23. fastapi/middleware/trustedhost.py +3 -0
  24. fastapi/middleware/wsgi.py +1 -0
  25. fastapi/openapi/__init__.py +0 -0
  26. fastapi/openapi/constants.py +3 -0
  27. fastapi/openapi/docs.py +344 -0
  28. fastapi/openapi/models.py +438 -0
  29. fastapi/openapi/utils.py +567 -0
  30. fastapi/param_functions.py +2369 -0
  31. fastapi/params.py +755 -0
  32. fastapi/py.typed +0 -0
  33. fastapi/requests.py +2 -0
  34. fastapi/responses.py +48 -0
  35. fastapi/routing.py +4508 -0
  36. fastapi/security/__init__.py +15 -0
  37. fastapi/security/api_key.py +318 -0
  38. fastapi/security/base.py +6 -0
  39. fastapi/security/http.py +423 -0
  40. fastapi/security/oauth2.py +663 -0
  41. fastapi/security/open_id_connect_url.py +94 -0
  42. fastapi/security/utils.py +10 -0
  43. fastapi/staticfiles.py +1 -0
  44. fastapi/templating.py +1 -0
  45. fastapi/testclient.py +1 -0
  46. fastapi/types.py +11 -0
  47. fastapi/utils.py +164 -0
  48. fastapi/websockets.py +3 -0
  49. fastapi-0.128.0.dist-info/METADATA +645 -0
  50. fastapi-0.128.0.dist-info/RECORD +53 -0
  51. fastapi-0.128.0.dist-info/WHEEL +4 -0
  52. fastapi-0.128.0.dist-info/entry_points.txt +5 -0
  53. fastapi-0.128.0.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,2369 @@
1
+ from collections.abc import Sequence
2
+ from typing import Annotated, Any, Callable, Optional, Union
3
+
4
+ from annotated_doc import Doc
5
+ from fastapi import params
6
+ from fastapi._compat import Undefined
7
+ from fastapi.openapi.models import Example
8
+ from pydantic import AliasChoices, AliasPath
9
+ from typing_extensions import Literal, deprecated
10
+
11
+ _Unset: Any = Undefined
12
+
13
+
14
+ def Path( # noqa: N802
15
+ default: Annotated[
16
+ Any,
17
+ Doc(
18
+ """
19
+ Default value if the parameter field is not set.
20
+
21
+ This doesn't affect `Path` parameters as the value is always required.
22
+ The parameter is available only for compatibility.
23
+ """
24
+ ),
25
+ ] = ...,
26
+ *,
27
+ default_factory: Annotated[
28
+ Union[Callable[[], Any], None],
29
+ Doc(
30
+ """
31
+ A callable to generate the default value.
32
+
33
+ This doesn't affect `Path` parameters as the value is always required.
34
+ The parameter is available only for compatibility.
35
+ """
36
+ ),
37
+ ] = _Unset,
38
+ alias: Annotated[
39
+ Optional[str],
40
+ Doc(
41
+ """
42
+ An alternative name for the parameter field.
43
+
44
+ This will be used to extract the data and for the generated OpenAPI.
45
+ It is particularly useful when you can't use the name you want because it
46
+ is a Python reserved keyword or similar.
47
+ """
48
+ ),
49
+ ] = None,
50
+ alias_priority: Annotated[
51
+ Union[int, None],
52
+ Doc(
53
+ """
54
+ Priority of the alias. This affects whether an alias generator is used.
55
+ """
56
+ ),
57
+ ] = _Unset,
58
+ validation_alias: Annotated[
59
+ Union[str, AliasPath, AliasChoices, None],
60
+ Doc(
61
+ """
62
+ 'Whitelist' validation step. The parameter field will be the single one
63
+ allowed by the alias or set of aliases defined.
64
+ """
65
+ ),
66
+ ] = None,
67
+ serialization_alias: Annotated[
68
+ Union[str, None],
69
+ Doc(
70
+ """
71
+ 'Blacklist' validation step. The vanilla parameter field will be the
72
+ single one of the alias' or set of aliases' fields and all the other
73
+ fields will be ignored at serialization time.
74
+ """
75
+ ),
76
+ ] = None,
77
+ title: Annotated[
78
+ Optional[str],
79
+ Doc(
80
+ """
81
+ Human-readable title.
82
+ """
83
+ ),
84
+ ] = None,
85
+ description: Annotated[
86
+ Optional[str],
87
+ Doc(
88
+ """
89
+ Human-readable description.
90
+ """
91
+ ),
92
+ ] = None,
93
+ gt: Annotated[
94
+ Optional[float],
95
+ Doc(
96
+ """
97
+ Greater than. If set, value must be greater than this. Only applicable to
98
+ numbers.
99
+ """
100
+ ),
101
+ ] = None,
102
+ ge: Annotated[
103
+ Optional[float],
104
+ Doc(
105
+ """
106
+ Greater than or equal. If set, value must be greater than or equal to
107
+ this. Only applicable to numbers.
108
+ """
109
+ ),
110
+ ] = None,
111
+ lt: Annotated[
112
+ Optional[float],
113
+ Doc(
114
+ """
115
+ Less than. If set, value must be less than this. Only applicable to numbers.
116
+ """
117
+ ),
118
+ ] = None,
119
+ le: Annotated[
120
+ Optional[float],
121
+ Doc(
122
+ """
123
+ Less than or equal. If set, value must be less than or equal to this.
124
+ Only applicable to numbers.
125
+ """
126
+ ),
127
+ ] = None,
128
+ min_length: Annotated[
129
+ Optional[int],
130
+ Doc(
131
+ """
132
+ Minimum length for strings.
133
+ """
134
+ ),
135
+ ] = None,
136
+ max_length: Annotated[
137
+ Optional[int],
138
+ Doc(
139
+ """
140
+ Maximum length for strings.
141
+ """
142
+ ),
143
+ ] = None,
144
+ pattern: Annotated[
145
+ Optional[str],
146
+ Doc(
147
+ """
148
+ RegEx pattern for strings.
149
+ """
150
+ ),
151
+ ] = None,
152
+ regex: Annotated[
153
+ Optional[str],
154
+ Doc(
155
+ """
156
+ RegEx pattern for strings.
157
+ """
158
+ ),
159
+ deprecated(
160
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
161
+ ),
162
+ ] = None,
163
+ discriminator: Annotated[
164
+ Union[str, None],
165
+ Doc(
166
+ """
167
+ Parameter field name for discriminating the type in a tagged union.
168
+ """
169
+ ),
170
+ ] = None,
171
+ strict: Annotated[
172
+ Union[bool, None],
173
+ Doc(
174
+ """
175
+ If `True`, strict validation is applied to the field.
176
+ """
177
+ ),
178
+ ] = _Unset,
179
+ multiple_of: Annotated[
180
+ Union[float, None],
181
+ Doc(
182
+ """
183
+ Value must be a multiple of this. Only applicable to numbers.
184
+ """
185
+ ),
186
+ ] = _Unset,
187
+ allow_inf_nan: Annotated[
188
+ Union[bool, None],
189
+ Doc(
190
+ """
191
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
192
+ """
193
+ ),
194
+ ] = _Unset,
195
+ max_digits: Annotated[
196
+ Union[int, None],
197
+ Doc(
198
+ """
199
+ Maximum number of allow digits for strings.
200
+ """
201
+ ),
202
+ ] = _Unset,
203
+ decimal_places: Annotated[
204
+ Union[int, None],
205
+ Doc(
206
+ """
207
+ Maximum number of decimal places allowed for numbers.
208
+ """
209
+ ),
210
+ ] = _Unset,
211
+ examples: Annotated[
212
+ Optional[list[Any]],
213
+ Doc(
214
+ """
215
+ Example values for this field.
216
+ """
217
+ ),
218
+ ] = None,
219
+ example: Annotated[
220
+ Optional[Any],
221
+ deprecated(
222
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
223
+ "although still supported. Use examples instead."
224
+ ),
225
+ ] = _Unset,
226
+ openapi_examples: Annotated[
227
+ Optional[dict[str, Example]],
228
+ Doc(
229
+ """
230
+ OpenAPI-specific examples.
231
+
232
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
233
+
234
+ Swagger UI (that provides the `/docs` interface) has better support for the
235
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
236
+ use case for this.
237
+
238
+ Read more about it in the
239
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
240
+ """
241
+ ),
242
+ ] = None,
243
+ deprecated: Annotated[
244
+ Union[deprecated, str, bool, None],
245
+ Doc(
246
+ """
247
+ Mark this parameter field as deprecated.
248
+
249
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
250
+ """
251
+ ),
252
+ ] = None,
253
+ include_in_schema: Annotated[
254
+ bool,
255
+ Doc(
256
+ """
257
+ To include (or not) this parameter field in the generated OpenAPI.
258
+ You probably don't need it, but it's available.
259
+
260
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
261
+ """
262
+ ),
263
+ ] = True,
264
+ json_schema_extra: Annotated[
265
+ Union[dict[str, Any], None],
266
+ Doc(
267
+ """
268
+ Any additional JSON schema data.
269
+ """
270
+ ),
271
+ ] = None,
272
+ **extra: Annotated[
273
+ Any,
274
+ Doc(
275
+ """
276
+ Include extra fields used by the JSON Schema.
277
+ """
278
+ ),
279
+ deprecated(
280
+ """
281
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
282
+ """
283
+ ),
284
+ ],
285
+ ) -> Any:
286
+ """
287
+ Declare a path parameter for a *path operation*.
288
+
289
+ Read more about it in the
290
+ [FastAPI docs for Path Parameters and Numeric Validations](https://fastapi.tiangolo.com/tutorial/path-params-numeric-validations/).
291
+
292
+ ```python
293
+ from typing import Annotated
294
+
295
+ from fastapi import FastAPI, Path
296
+
297
+ app = FastAPI()
298
+
299
+
300
+ @app.get("/items/{item_id}")
301
+ async def read_items(
302
+ item_id: Annotated[int, Path(title="The ID of the item to get")],
303
+ ):
304
+ return {"item_id": item_id}
305
+ ```
306
+ """
307
+ return params.Path(
308
+ default=default,
309
+ default_factory=default_factory,
310
+ alias=alias,
311
+ alias_priority=alias_priority,
312
+ validation_alias=validation_alias,
313
+ serialization_alias=serialization_alias,
314
+ title=title,
315
+ description=description,
316
+ gt=gt,
317
+ ge=ge,
318
+ lt=lt,
319
+ le=le,
320
+ min_length=min_length,
321
+ max_length=max_length,
322
+ pattern=pattern,
323
+ regex=regex,
324
+ discriminator=discriminator,
325
+ strict=strict,
326
+ multiple_of=multiple_of,
327
+ allow_inf_nan=allow_inf_nan,
328
+ max_digits=max_digits,
329
+ decimal_places=decimal_places,
330
+ example=example,
331
+ examples=examples,
332
+ openapi_examples=openapi_examples,
333
+ deprecated=deprecated,
334
+ include_in_schema=include_in_schema,
335
+ json_schema_extra=json_schema_extra,
336
+ **extra,
337
+ )
338
+
339
+
340
+ def Query( # noqa: N802
341
+ default: Annotated[
342
+ Any,
343
+ Doc(
344
+ """
345
+ Default value if the parameter field is not set.
346
+ """
347
+ ),
348
+ ] = Undefined,
349
+ *,
350
+ default_factory: Annotated[
351
+ Union[Callable[[], Any], None],
352
+ Doc(
353
+ """
354
+ A callable to generate the default value.
355
+
356
+ This doesn't affect `Path` parameters as the value is always required.
357
+ The parameter is available only for compatibility.
358
+ """
359
+ ),
360
+ ] = _Unset,
361
+ alias: Annotated[
362
+ Optional[str],
363
+ Doc(
364
+ """
365
+ An alternative name for the parameter field.
366
+
367
+ This will be used to extract the data and for the generated OpenAPI.
368
+ It is particularly useful when you can't use the name you want because it
369
+ is a Python reserved keyword or similar.
370
+ """
371
+ ),
372
+ ] = None,
373
+ alias_priority: Annotated[
374
+ Union[int, None],
375
+ Doc(
376
+ """
377
+ Priority of the alias. This affects whether an alias generator is used.
378
+ """
379
+ ),
380
+ ] = _Unset,
381
+ validation_alias: Annotated[
382
+ Union[str, AliasPath, AliasChoices, None],
383
+ Doc(
384
+ """
385
+ 'Whitelist' validation step. The parameter field will be the single one
386
+ allowed by the alias or set of aliases defined.
387
+ """
388
+ ),
389
+ ] = None,
390
+ serialization_alias: Annotated[
391
+ Union[str, None],
392
+ Doc(
393
+ """
394
+ 'Blacklist' validation step. The vanilla parameter field will be the
395
+ single one of the alias' or set of aliases' fields and all the other
396
+ fields will be ignored at serialization time.
397
+ """
398
+ ),
399
+ ] = None,
400
+ title: Annotated[
401
+ Optional[str],
402
+ Doc(
403
+ """
404
+ Human-readable title.
405
+ """
406
+ ),
407
+ ] = None,
408
+ description: Annotated[
409
+ Optional[str],
410
+ Doc(
411
+ """
412
+ Human-readable description.
413
+ """
414
+ ),
415
+ ] = None,
416
+ gt: Annotated[
417
+ Optional[float],
418
+ Doc(
419
+ """
420
+ Greater than. If set, value must be greater than this. Only applicable to
421
+ numbers.
422
+ """
423
+ ),
424
+ ] = None,
425
+ ge: Annotated[
426
+ Optional[float],
427
+ Doc(
428
+ """
429
+ Greater than or equal. If set, value must be greater than or equal to
430
+ this. Only applicable to numbers.
431
+ """
432
+ ),
433
+ ] = None,
434
+ lt: Annotated[
435
+ Optional[float],
436
+ Doc(
437
+ """
438
+ Less than. If set, value must be less than this. Only applicable to numbers.
439
+ """
440
+ ),
441
+ ] = None,
442
+ le: Annotated[
443
+ Optional[float],
444
+ Doc(
445
+ """
446
+ Less than or equal. If set, value must be less than or equal to this.
447
+ Only applicable to numbers.
448
+ """
449
+ ),
450
+ ] = None,
451
+ min_length: Annotated[
452
+ Optional[int],
453
+ Doc(
454
+ """
455
+ Minimum length for strings.
456
+ """
457
+ ),
458
+ ] = None,
459
+ max_length: Annotated[
460
+ Optional[int],
461
+ Doc(
462
+ """
463
+ Maximum length for strings.
464
+ """
465
+ ),
466
+ ] = None,
467
+ pattern: Annotated[
468
+ Optional[str],
469
+ Doc(
470
+ """
471
+ RegEx pattern for strings.
472
+ """
473
+ ),
474
+ ] = None,
475
+ regex: Annotated[
476
+ Optional[str],
477
+ Doc(
478
+ """
479
+ RegEx pattern for strings.
480
+ """
481
+ ),
482
+ deprecated(
483
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
484
+ ),
485
+ ] = None,
486
+ discriminator: Annotated[
487
+ Union[str, None],
488
+ Doc(
489
+ """
490
+ Parameter field name for discriminating the type in a tagged union.
491
+ """
492
+ ),
493
+ ] = None,
494
+ strict: Annotated[
495
+ Union[bool, None],
496
+ Doc(
497
+ """
498
+ If `True`, strict validation is applied to the field.
499
+ """
500
+ ),
501
+ ] = _Unset,
502
+ multiple_of: Annotated[
503
+ Union[float, None],
504
+ Doc(
505
+ """
506
+ Value must be a multiple of this. Only applicable to numbers.
507
+ """
508
+ ),
509
+ ] = _Unset,
510
+ allow_inf_nan: Annotated[
511
+ Union[bool, None],
512
+ Doc(
513
+ """
514
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
515
+ """
516
+ ),
517
+ ] = _Unset,
518
+ max_digits: Annotated[
519
+ Union[int, None],
520
+ Doc(
521
+ """
522
+ Maximum number of allow digits for strings.
523
+ """
524
+ ),
525
+ ] = _Unset,
526
+ decimal_places: Annotated[
527
+ Union[int, None],
528
+ Doc(
529
+ """
530
+ Maximum number of decimal places allowed for numbers.
531
+ """
532
+ ),
533
+ ] = _Unset,
534
+ examples: Annotated[
535
+ Optional[list[Any]],
536
+ Doc(
537
+ """
538
+ Example values for this field.
539
+ """
540
+ ),
541
+ ] = None,
542
+ example: Annotated[
543
+ Optional[Any],
544
+ deprecated(
545
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
546
+ "although still supported. Use examples instead."
547
+ ),
548
+ ] = _Unset,
549
+ openapi_examples: Annotated[
550
+ Optional[dict[str, Example]],
551
+ Doc(
552
+ """
553
+ OpenAPI-specific examples.
554
+
555
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
556
+
557
+ Swagger UI (that provides the `/docs` interface) has better support for the
558
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
559
+ use case for this.
560
+
561
+ Read more about it in the
562
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
563
+ """
564
+ ),
565
+ ] = None,
566
+ deprecated: Annotated[
567
+ Union[deprecated, str, bool, None],
568
+ Doc(
569
+ """
570
+ Mark this parameter field as deprecated.
571
+
572
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
573
+ """
574
+ ),
575
+ ] = None,
576
+ include_in_schema: Annotated[
577
+ bool,
578
+ Doc(
579
+ """
580
+ To include (or not) this parameter field in the generated OpenAPI.
581
+ You probably don't need it, but it's available.
582
+
583
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
584
+ """
585
+ ),
586
+ ] = True,
587
+ json_schema_extra: Annotated[
588
+ Union[dict[str, Any], None],
589
+ Doc(
590
+ """
591
+ Any additional JSON schema data.
592
+ """
593
+ ),
594
+ ] = None,
595
+ **extra: Annotated[
596
+ Any,
597
+ Doc(
598
+ """
599
+ Include extra fields used by the JSON Schema.
600
+ """
601
+ ),
602
+ deprecated(
603
+ """
604
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
605
+ """
606
+ ),
607
+ ],
608
+ ) -> Any:
609
+ return params.Query(
610
+ default=default,
611
+ default_factory=default_factory,
612
+ alias=alias,
613
+ alias_priority=alias_priority,
614
+ validation_alias=validation_alias,
615
+ serialization_alias=serialization_alias,
616
+ title=title,
617
+ description=description,
618
+ gt=gt,
619
+ ge=ge,
620
+ lt=lt,
621
+ le=le,
622
+ min_length=min_length,
623
+ max_length=max_length,
624
+ pattern=pattern,
625
+ regex=regex,
626
+ discriminator=discriminator,
627
+ strict=strict,
628
+ multiple_of=multiple_of,
629
+ allow_inf_nan=allow_inf_nan,
630
+ max_digits=max_digits,
631
+ decimal_places=decimal_places,
632
+ example=example,
633
+ examples=examples,
634
+ openapi_examples=openapi_examples,
635
+ deprecated=deprecated,
636
+ include_in_schema=include_in_schema,
637
+ json_schema_extra=json_schema_extra,
638
+ **extra,
639
+ )
640
+
641
+
642
+ def Header( # noqa: N802
643
+ default: Annotated[
644
+ Any,
645
+ Doc(
646
+ """
647
+ Default value if the parameter field is not set.
648
+ """
649
+ ),
650
+ ] = Undefined,
651
+ *,
652
+ default_factory: Annotated[
653
+ Union[Callable[[], Any], None],
654
+ Doc(
655
+ """
656
+ A callable to generate the default value.
657
+
658
+ This doesn't affect `Path` parameters as the value is always required.
659
+ The parameter is available only for compatibility.
660
+ """
661
+ ),
662
+ ] = _Unset,
663
+ alias: Annotated[
664
+ Optional[str],
665
+ Doc(
666
+ """
667
+ An alternative name for the parameter field.
668
+
669
+ This will be used to extract the data and for the generated OpenAPI.
670
+ It is particularly useful when you can't use the name you want because it
671
+ is a Python reserved keyword or similar.
672
+ """
673
+ ),
674
+ ] = None,
675
+ alias_priority: Annotated[
676
+ Union[int, None],
677
+ Doc(
678
+ """
679
+ Priority of the alias. This affects whether an alias generator is used.
680
+ """
681
+ ),
682
+ ] = _Unset,
683
+ validation_alias: Annotated[
684
+ Union[str, AliasPath, AliasChoices, None],
685
+ Doc(
686
+ """
687
+ 'Whitelist' validation step. The parameter field will be the single one
688
+ allowed by the alias or set of aliases defined.
689
+ """
690
+ ),
691
+ ] = None,
692
+ serialization_alias: Annotated[
693
+ Union[str, None],
694
+ Doc(
695
+ """
696
+ 'Blacklist' validation step. The vanilla parameter field will be the
697
+ single one of the alias' or set of aliases' fields and all the other
698
+ fields will be ignored at serialization time.
699
+ """
700
+ ),
701
+ ] = None,
702
+ convert_underscores: Annotated[
703
+ bool,
704
+ Doc(
705
+ """
706
+ Automatically convert underscores to hyphens in the parameter field name.
707
+
708
+ Read more about it in the
709
+ [FastAPI docs for Header Parameters](https://fastapi.tiangolo.com/tutorial/header-params/#automatic-conversion)
710
+ """
711
+ ),
712
+ ] = True,
713
+ title: Annotated[
714
+ Optional[str],
715
+ Doc(
716
+ """
717
+ Human-readable title.
718
+ """
719
+ ),
720
+ ] = None,
721
+ description: Annotated[
722
+ Optional[str],
723
+ Doc(
724
+ """
725
+ Human-readable description.
726
+ """
727
+ ),
728
+ ] = None,
729
+ gt: Annotated[
730
+ Optional[float],
731
+ Doc(
732
+ """
733
+ Greater than. If set, value must be greater than this. Only applicable to
734
+ numbers.
735
+ """
736
+ ),
737
+ ] = None,
738
+ ge: Annotated[
739
+ Optional[float],
740
+ Doc(
741
+ """
742
+ Greater than or equal. If set, value must be greater than or equal to
743
+ this. Only applicable to numbers.
744
+ """
745
+ ),
746
+ ] = None,
747
+ lt: Annotated[
748
+ Optional[float],
749
+ Doc(
750
+ """
751
+ Less than. If set, value must be less than this. Only applicable to numbers.
752
+ """
753
+ ),
754
+ ] = None,
755
+ le: Annotated[
756
+ Optional[float],
757
+ Doc(
758
+ """
759
+ Less than or equal. If set, value must be less than or equal to this.
760
+ Only applicable to numbers.
761
+ """
762
+ ),
763
+ ] = None,
764
+ min_length: Annotated[
765
+ Optional[int],
766
+ Doc(
767
+ """
768
+ Minimum length for strings.
769
+ """
770
+ ),
771
+ ] = None,
772
+ max_length: Annotated[
773
+ Optional[int],
774
+ Doc(
775
+ """
776
+ Maximum length for strings.
777
+ """
778
+ ),
779
+ ] = None,
780
+ pattern: Annotated[
781
+ Optional[str],
782
+ Doc(
783
+ """
784
+ RegEx pattern for strings.
785
+ """
786
+ ),
787
+ ] = None,
788
+ regex: Annotated[
789
+ Optional[str],
790
+ Doc(
791
+ """
792
+ RegEx pattern for strings.
793
+ """
794
+ ),
795
+ deprecated(
796
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
797
+ ),
798
+ ] = None,
799
+ discriminator: Annotated[
800
+ Union[str, None],
801
+ Doc(
802
+ """
803
+ Parameter field name for discriminating the type in a tagged union.
804
+ """
805
+ ),
806
+ ] = None,
807
+ strict: Annotated[
808
+ Union[bool, None],
809
+ Doc(
810
+ """
811
+ If `True`, strict validation is applied to the field.
812
+ """
813
+ ),
814
+ ] = _Unset,
815
+ multiple_of: Annotated[
816
+ Union[float, None],
817
+ Doc(
818
+ """
819
+ Value must be a multiple of this. Only applicable to numbers.
820
+ """
821
+ ),
822
+ ] = _Unset,
823
+ allow_inf_nan: Annotated[
824
+ Union[bool, None],
825
+ Doc(
826
+ """
827
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
828
+ """
829
+ ),
830
+ ] = _Unset,
831
+ max_digits: Annotated[
832
+ Union[int, None],
833
+ Doc(
834
+ """
835
+ Maximum number of allow digits for strings.
836
+ """
837
+ ),
838
+ ] = _Unset,
839
+ decimal_places: Annotated[
840
+ Union[int, None],
841
+ Doc(
842
+ """
843
+ Maximum number of decimal places allowed for numbers.
844
+ """
845
+ ),
846
+ ] = _Unset,
847
+ examples: Annotated[
848
+ Optional[list[Any]],
849
+ Doc(
850
+ """
851
+ Example values for this field.
852
+ """
853
+ ),
854
+ ] = None,
855
+ example: Annotated[
856
+ Optional[Any],
857
+ deprecated(
858
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
859
+ "although still supported. Use examples instead."
860
+ ),
861
+ ] = _Unset,
862
+ openapi_examples: Annotated[
863
+ Optional[dict[str, Example]],
864
+ Doc(
865
+ """
866
+ OpenAPI-specific examples.
867
+
868
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
869
+
870
+ Swagger UI (that provides the `/docs` interface) has better support for the
871
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
872
+ use case for this.
873
+
874
+ Read more about it in the
875
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
876
+ """
877
+ ),
878
+ ] = None,
879
+ deprecated: Annotated[
880
+ Union[deprecated, str, bool, None],
881
+ Doc(
882
+ """
883
+ Mark this parameter field as deprecated.
884
+
885
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
886
+ """
887
+ ),
888
+ ] = None,
889
+ include_in_schema: Annotated[
890
+ bool,
891
+ Doc(
892
+ """
893
+ To include (or not) this parameter field in the generated OpenAPI.
894
+ You probably don't need it, but it's available.
895
+
896
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
897
+ """
898
+ ),
899
+ ] = True,
900
+ json_schema_extra: Annotated[
901
+ Union[dict[str, Any], None],
902
+ Doc(
903
+ """
904
+ Any additional JSON schema data.
905
+ """
906
+ ),
907
+ ] = None,
908
+ **extra: Annotated[
909
+ Any,
910
+ Doc(
911
+ """
912
+ Include extra fields used by the JSON Schema.
913
+ """
914
+ ),
915
+ deprecated(
916
+ """
917
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
918
+ """
919
+ ),
920
+ ],
921
+ ) -> Any:
922
+ return params.Header(
923
+ default=default,
924
+ default_factory=default_factory,
925
+ alias=alias,
926
+ alias_priority=alias_priority,
927
+ validation_alias=validation_alias,
928
+ serialization_alias=serialization_alias,
929
+ convert_underscores=convert_underscores,
930
+ title=title,
931
+ description=description,
932
+ gt=gt,
933
+ ge=ge,
934
+ lt=lt,
935
+ le=le,
936
+ min_length=min_length,
937
+ max_length=max_length,
938
+ pattern=pattern,
939
+ regex=regex,
940
+ discriminator=discriminator,
941
+ strict=strict,
942
+ multiple_of=multiple_of,
943
+ allow_inf_nan=allow_inf_nan,
944
+ max_digits=max_digits,
945
+ decimal_places=decimal_places,
946
+ example=example,
947
+ examples=examples,
948
+ openapi_examples=openapi_examples,
949
+ deprecated=deprecated,
950
+ include_in_schema=include_in_schema,
951
+ json_schema_extra=json_schema_extra,
952
+ **extra,
953
+ )
954
+
955
+
956
+ def Cookie( # noqa: N802
957
+ default: Annotated[
958
+ Any,
959
+ Doc(
960
+ """
961
+ Default value if the parameter field is not set.
962
+ """
963
+ ),
964
+ ] = Undefined,
965
+ *,
966
+ default_factory: Annotated[
967
+ Union[Callable[[], Any], None],
968
+ Doc(
969
+ """
970
+ A callable to generate the default value.
971
+
972
+ This doesn't affect `Path` parameters as the value is always required.
973
+ The parameter is available only for compatibility.
974
+ """
975
+ ),
976
+ ] = _Unset,
977
+ alias: Annotated[
978
+ Optional[str],
979
+ Doc(
980
+ """
981
+ An alternative name for the parameter field.
982
+
983
+ This will be used to extract the data and for the generated OpenAPI.
984
+ It is particularly useful when you can't use the name you want because it
985
+ is a Python reserved keyword or similar.
986
+ """
987
+ ),
988
+ ] = None,
989
+ alias_priority: Annotated[
990
+ Union[int, None],
991
+ Doc(
992
+ """
993
+ Priority of the alias. This affects whether an alias generator is used.
994
+ """
995
+ ),
996
+ ] = _Unset,
997
+ validation_alias: Annotated[
998
+ Union[str, AliasPath, AliasChoices, None],
999
+ Doc(
1000
+ """
1001
+ 'Whitelist' validation step. The parameter field will be the single one
1002
+ allowed by the alias or set of aliases defined.
1003
+ """
1004
+ ),
1005
+ ] = None,
1006
+ serialization_alias: Annotated[
1007
+ Union[str, None],
1008
+ Doc(
1009
+ """
1010
+ 'Blacklist' validation step. The vanilla parameter field will be the
1011
+ single one of the alias' or set of aliases' fields and all the other
1012
+ fields will be ignored at serialization time.
1013
+ """
1014
+ ),
1015
+ ] = None,
1016
+ title: Annotated[
1017
+ Optional[str],
1018
+ Doc(
1019
+ """
1020
+ Human-readable title.
1021
+ """
1022
+ ),
1023
+ ] = None,
1024
+ description: Annotated[
1025
+ Optional[str],
1026
+ Doc(
1027
+ """
1028
+ Human-readable description.
1029
+ """
1030
+ ),
1031
+ ] = None,
1032
+ gt: Annotated[
1033
+ Optional[float],
1034
+ Doc(
1035
+ """
1036
+ Greater than. If set, value must be greater than this. Only applicable to
1037
+ numbers.
1038
+ """
1039
+ ),
1040
+ ] = None,
1041
+ ge: Annotated[
1042
+ Optional[float],
1043
+ Doc(
1044
+ """
1045
+ Greater than or equal. If set, value must be greater than or equal to
1046
+ this. Only applicable to numbers.
1047
+ """
1048
+ ),
1049
+ ] = None,
1050
+ lt: Annotated[
1051
+ Optional[float],
1052
+ Doc(
1053
+ """
1054
+ Less than. If set, value must be less than this. Only applicable to numbers.
1055
+ """
1056
+ ),
1057
+ ] = None,
1058
+ le: Annotated[
1059
+ Optional[float],
1060
+ Doc(
1061
+ """
1062
+ Less than or equal. If set, value must be less than or equal to this.
1063
+ Only applicable to numbers.
1064
+ """
1065
+ ),
1066
+ ] = None,
1067
+ min_length: Annotated[
1068
+ Optional[int],
1069
+ Doc(
1070
+ """
1071
+ Minimum length for strings.
1072
+ """
1073
+ ),
1074
+ ] = None,
1075
+ max_length: Annotated[
1076
+ Optional[int],
1077
+ Doc(
1078
+ """
1079
+ Maximum length for strings.
1080
+ """
1081
+ ),
1082
+ ] = None,
1083
+ pattern: Annotated[
1084
+ Optional[str],
1085
+ Doc(
1086
+ """
1087
+ RegEx pattern for strings.
1088
+ """
1089
+ ),
1090
+ ] = None,
1091
+ regex: Annotated[
1092
+ Optional[str],
1093
+ Doc(
1094
+ """
1095
+ RegEx pattern for strings.
1096
+ """
1097
+ ),
1098
+ deprecated(
1099
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
1100
+ ),
1101
+ ] = None,
1102
+ discriminator: Annotated[
1103
+ Union[str, None],
1104
+ Doc(
1105
+ """
1106
+ Parameter field name for discriminating the type in a tagged union.
1107
+ """
1108
+ ),
1109
+ ] = None,
1110
+ strict: Annotated[
1111
+ Union[bool, None],
1112
+ Doc(
1113
+ """
1114
+ If `True`, strict validation is applied to the field.
1115
+ """
1116
+ ),
1117
+ ] = _Unset,
1118
+ multiple_of: Annotated[
1119
+ Union[float, None],
1120
+ Doc(
1121
+ """
1122
+ Value must be a multiple of this. Only applicable to numbers.
1123
+ """
1124
+ ),
1125
+ ] = _Unset,
1126
+ allow_inf_nan: Annotated[
1127
+ Union[bool, None],
1128
+ Doc(
1129
+ """
1130
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
1131
+ """
1132
+ ),
1133
+ ] = _Unset,
1134
+ max_digits: Annotated[
1135
+ Union[int, None],
1136
+ Doc(
1137
+ """
1138
+ Maximum number of allow digits for strings.
1139
+ """
1140
+ ),
1141
+ ] = _Unset,
1142
+ decimal_places: Annotated[
1143
+ Union[int, None],
1144
+ Doc(
1145
+ """
1146
+ Maximum number of decimal places allowed for numbers.
1147
+ """
1148
+ ),
1149
+ ] = _Unset,
1150
+ examples: Annotated[
1151
+ Optional[list[Any]],
1152
+ Doc(
1153
+ """
1154
+ Example values for this field.
1155
+ """
1156
+ ),
1157
+ ] = None,
1158
+ example: Annotated[
1159
+ Optional[Any],
1160
+ deprecated(
1161
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
1162
+ "although still supported. Use examples instead."
1163
+ ),
1164
+ ] = _Unset,
1165
+ openapi_examples: Annotated[
1166
+ Optional[dict[str, Example]],
1167
+ Doc(
1168
+ """
1169
+ OpenAPI-specific examples.
1170
+
1171
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
1172
+
1173
+ Swagger UI (that provides the `/docs` interface) has better support for the
1174
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
1175
+ use case for this.
1176
+
1177
+ Read more about it in the
1178
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
1179
+ """
1180
+ ),
1181
+ ] = None,
1182
+ deprecated: Annotated[
1183
+ Union[deprecated, str, bool, None],
1184
+ Doc(
1185
+ """
1186
+ Mark this parameter field as deprecated.
1187
+
1188
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
1189
+ """
1190
+ ),
1191
+ ] = None,
1192
+ include_in_schema: Annotated[
1193
+ bool,
1194
+ Doc(
1195
+ """
1196
+ To include (or not) this parameter field in the generated OpenAPI.
1197
+ You probably don't need it, but it's available.
1198
+
1199
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
1200
+ """
1201
+ ),
1202
+ ] = True,
1203
+ json_schema_extra: Annotated[
1204
+ Union[dict[str, Any], None],
1205
+ Doc(
1206
+ """
1207
+ Any additional JSON schema data.
1208
+ """
1209
+ ),
1210
+ ] = None,
1211
+ **extra: Annotated[
1212
+ Any,
1213
+ Doc(
1214
+ """
1215
+ Include extra fields used by the JSON Schema.
1216
+ """
1217
+ ),
1218
+ deprecated(
1219
+ """
1220
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
1221
+ """
1222
+ ),
1223
+ ],
1224
+ ) -> Any:
1225
+ return params.Cookie(
1226
+ default=default,
1227
+ default_factory=default_factory,
1228
+ alias=alias,
1229
+ alias_priority=alias_priority,
1230
+ validation_alias=validation_alias,
1231
+ serialization_alias=serialization_alias,
1232
+ title=title,
1233
+ description=description,
1234
+ gt=gt,
1235
+ ge=ge,
1236
+ lt=lt,
1237
+ le=le,
1238
+ min_length=min_length,
1239
+ max_length=max_length,
1240
+ pattern=pattern,
1241
+ regex=regex,
1242
+ discriminator=discriminator,
1243
+ strict=strict,
1244
+ multiple_of=multiple_of,
1245
+ allow_inf_nan=allow_inf_nan,
1246
+ max_digits=max_digits,
1247
+ decimal_places=decimal_places,
1248
+ example=example,
1249
+ examples=examples,
1250
+ openapi_examples=openapi_examples,
1251
+ deprecated=deprecated,
1252
+ include_in_schema=include_in_schema,
1253
+ json_schema_extra=json_schema_extra,
1254
+ **extra,
1255
+ )
1256
+
1257
+
1258
+ def Body( # noqa: N802
1259
+ default: Annotated[
1260
+ Any,
1261
+ Doc(
1262
+ """
1263
+ Default value if the parameter field is not set.
1264
+ """
1265
+ ),
1266
+ ] = Undefined,
1267
+ *,
1268
+ default_factory: Annotated[
1269
+ Union[Callable[[], Any], None],
1270
+ Doc(
1271
+ """
1272
+ A callable to generate the default value.
1273
+
1274
+ This doesn't affect `Path` parameters as the value is always required.
1275
+ The parameter is available only for compatibility.
1276
+ """
1277
+ ),
1278
+ ] = _Unset,
1279
+ embed: Annotated[
1280
+ Union[bool, None],
1281
+ Doc(
1282
+ """
1283
+ When `embed` is `True`, the parameter will be expected in a JSON body as a
1284
+ key instead of being the JSON body itself.
1285
+
1286
+ This happens automatically when more than one `Body` parameter is declared.
1287
+
1288
+ Read more about it in the
1289
+ [FastAPI docs for Body - Multiple Parameters](https://fastapi.tiangolo.com/tutorial/body-multiple-params/#embed-a-single-body-parameter).
1290
+ """
1291
+ ),
1292
+ ] = None,
1293
+ media_type: Annotated[
1294
+ str,
1295
+ Doc(
1296
+ """
1297
+ The media type of this parameter field. Changing it would affect the
1298
+ generated OpenAPI, but currently it doesn't affect the parsing of the data.
1299
+ """
1300
+ ),
1301
+ ] = "application/json",
1302
+ alias: Annotated[
1303
+ Optional[str],
1304
+ Doc(
1305
+ """
1306
+ An alternative name for the parameter field.
1307
+
1308
+ This will be used to extract the data and for the generated OpenAPI.
1309
+ It is particularly useful when you can't use the name you want because it
1310
+ is a Python reserved keyword or similar.
1311
+ """
1312
+ ),
1313
+ ] = None,
1314
+ alias_priority: Annotated[
1315
+ Union[int, None],
1316
+ Doc(
1317
+ """
1318
+ Priority of the alias. This affects whether an alias generator is used.
1319
+ """
1320
+ ),
1321
+ ] = _Unset,
1322
+ validation_alias: Annotated[
1323
+ Union[str, AliasPath, AliasChoices, None],
1324
+ Doc(
1325
+ """
1326
+ 'Whitelist' validation step. The parameter field will be the single one
1327
+ allowed by the alias or set of aliases defined.
1328
+ """
1329
+ ),
1330
+ ] = None,
1331
+ serialization_alias: Annotated[
1332
+ Union[str, None],
1333
+ Doc(
1334
+ """
1335
+ 'Blacklist' validation step. The vanilla parameter field will be the
1336
+ single one of the alias' or set of aliases' fields and all the other
1337
+ fields will be ignored at serialization time.
1338
+ """
1339
+ ),
1340
+ ] = None,
1341
+ title: Annotated[
1342
+ Optional[str],
1343
+ Doc(
1344
+ """
1345
+ Human-readable title.
1346
+ """
1347
+ ),
1348
+ ] = None,
1349
+ description: Annotated[
1350
+ Optional[str],
1351
+ Doc(
1352
+ """
1353
+ Human-readable description.
1354
+ """
1355
+ ),
1356
+ ] = None,
1357
+ gt: Annotated[
1358
+ Optional[float],
1359
+ Doc(
1360
+ """
1361
+ Greater than. If set, value must be greater than this. Only applicable to
1362
+ numbers.
1363
+ """
1364
+ ),
1365
+ ] = None,
1366
+ ge: Annotated[
1367
+ Optional[float],
1368
+ Doc(
1369
+ """
1370
+ Greater than or equal. If set, value must be greater than or equal to
1371
+ this. Only applicable to numbers.
1372
+ """
1373
+ ),
1374
+ ] = None,
1375
+ lt: Annotated[
1376
+ Optional[float],
1377
+ Doc(
1378
+ """
1379
+ Less than. If set, value must be less than this. Only applicable to numbers.
1380
+ """
1381
+ ),
1382
+ ] = None,
1383
+ le: Annotated[
1384
+ Optional[float],
1385
+ Doc(
1386
+ """
1387
+ Less than or equal. If set, value must be less than or equal to this.
1388
+ Only applicable to numbers.
1389
+ """
1390
+ ),
1391
+ ] = None,
1392
+ min_length: Annotated[
1393
+ Optional[int],
1394
+ Doc(
1395
+ """
1396
+ Minimum length for strings.
1397
+ """
1398
+ ),
1399
+ ] = None,
1400
+ max_length: Annotated[
1401
+ Optional[int],
1402
+ Doc(
1403
+ """
1404
+ Maximum length for strings.
1405
+ """
1406
+ ),
1407
+ ] = None,
1408
+ pattern: Annotated[
1409
+ Optional[str],
1410
+ Doc(
1411
+ """
1412
+ RegEx pattern for strings.
1413
+ """
1414
+ ),
1415
+ ] = None,
1416
+ regex: Annotated[
1417
+ Optional[str],
1418
+ Doc(
1419
+ """
1420
+ RegEx pattern for strings.
1421
+ """
1422
+ ),
1423
+ deprecated(
1424
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
1425
+ ),
1426
+ ] = None,
1427
+ discriminator: Annotated[
1428
+ Union[str, None],
1429
+ Doc(
1430
+ """
1431
+ Parameter field name for discriminating the type in a tagged union.
1432
+ """
1433
+ ),
1434
+ ] = None,
1435
+ strict: Annotated[
1436
+ Union[bool, None],
1437
+ Doc(
1438
+ """
1439
+ If `True`, strict validation is applied to the field.
1440
+ """
1441
+ ),
1442
+ ] = _Unset,
1443
+ multiple_of: Annotated[
1444
+ Union[float, None],
1445
+ Doc(
1446
+ """
1447
+ Value must be a multiple of this. Only applicable to numbers.
1448
+ """
1449
+ ),
1450
+ ] = _Unset,
1451
+ allow_inf_nan: Annotated[
1452
+ Union[bool, None],
1453
+ Doc(
1454
+ """
1455
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
1456
+ """
1457
+ ),
1458
+ ] = _Unset,
1459
+ max_digits: Annotated[
1460
+ Union[int, None],
1461
+ Doc(
1462
+ """
1463
+ Maximum number of allow digits for strings.
1464
+ """
1465
+ ),
1466
+ ] = _Unset,
1467
+ decimal_places: Annotated[
1468
+ Union[int, None],
1469
+ Doc(
1470
+ """
1471
+ Maximum number of decimal places allowed for numbers.
1472
+ """
1473
+ ),
1474
+ ] = _Unset,
1475
+ examples: Annotated[
1476
+ Optional[list[Any]],
1477
+ Doc(
1478
+ """
1479
+ Example values for this field.
1480
+ """
1481
+ ),
1482
+ ] = None,
1483
+ example: Annotated[
1484
+ Optional[Any],
1485
+ deprecated(
1486
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
1487
+ "although still supported. Use examples instead."
1488
+ ),
1489
+ ] = _Unset,
1490
+ openapi_examples: Annotated[
1491
+ Optional[dict[str, Example]],
1492
+ Doc(
1493
+ """
1494
+ OpenAPI-specific examples.
1495
+
1496
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
1497
+
1498
+ Swagger UI (that provides the `/docs` interface) has better support for the
1499
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
1500
+ use case for this.
1501
+
1502
+ Read more about it in the
1503
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
1504
+ """
1505
+ ),
1506
+ ] = None,
1507
+ deprecated: Annotated[
1508
+ Union[deprecated, str, bool, None],
1509
+ Doc(
1510
+ """
1511
+ Mark this parameter field as deprecated.
1512
+
1513
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
1514
+ """
1515
+ ),
1516
+ ] = None,
1517
+ include_in_schema: Annotated[
1518
+ bool,
1519
+ Doc(
1520
+ """
1521
+ To include (or not) this parameter field in the generated OpenAPI.
1522
+ You probably don't need it, but it's available.
1523
+
1524
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
1525
+ """
1526
+ ),
1527
+ ] = True,
1528
+ json_schema_extra: Annotated[
1529
+ Union[dict[str, Any], None],
1530
+ Doc(
1531
+ """
1532
+ Any additional JSON schema data.
1533
+ """
1534
+ ),
1535
+ ] = None,
1536
+ **extra: Annotated[
1537
+ Any,
1538
+ Doc(
1539
+ """
1540
+ Include extra fields used by the JSON Schema.
1541
+ """
1542
+ ),
1543
+ deprecated(
1544
+ """
1545
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
1546
+ """
1547
+ ),
1548
+ ],
1549
+ ) -> Any:
1550
+ return params.Body(
1551
+ default=default,
1552
+ default_factory=default_factory,
1553
+ embed=embed,
1554
+ media_type=media_type,
1555
+ alias=alias,
1556
+ alias_priority=alias_priority,
1557
+ validation_alias=validation_alias,
1558
+ serialization_alias=serialization_alias,
1559
+ title=title,
1560
+ description=description,
1561
+ gt=gt,
1562
+ ge=ge,
1563
+ lt=lt,
1564
+ le=le,
1565
+ min_length=min_length,
1566
+ max_length=max_length,
1567
+ pattern=pattern,
1568
+ regex=regex,
1569
+ discriminator=discriminator,
1570
+ strict=strict,
1571
+ multiple_of=multiple_of,
1572
+ allow_inf_nan=allow_inf_nan,
1573
+ max_digits=max_digits,
1574
+ decimal_places=decimal_places,
1575
+ example=example,
1576
+ examples=examples,
1577
+ openapi_examples=openapi_examples,
1578
+ deprecated=deprecated,
1579
+ include_in_schema=include_in_schema,
1580
+ json_schema_extra=json_schema_extra,
1581
+ **extra,
1582
+ )
1583
+
1584
+
1585
+ def Form( # noqa: N802
1586
+ default: Annotated[
1587
+ Any,
1588
+ Doc(
1589
+ """
1590
+ Default value if the parameter field is not set.
1591
+ """
1592
+ ),
1593
+ ] = Undefined,
1594
+ *,
1595
+ default_factory: Annotated[
1596
+ Union[Callable[[], Any], None],
1597
+ Doc(
1598
+ """
1599
+ A callable to generate the default value.
1600
+
1601
+ This doesn't affect `Path` parameters as the value is always required.
1602
+ The parameter is available only for compatibility.
1603
+ """
1604
+ ),
1605
+ ] = _Unset,
1606
+ media_type: Annotated[
1607
+ str,
1608
+ Doc(
1609
+ """
1610
+ The media type of this parameter field. Changing it would affect the
1611
+ generated OpenAPI, but currently it doesn't affect the parsing of the data.
1612
+ """
1613
+ ),
1614
+ ] = "application/x-www-form-urlencoded",
1615
+ alias: Annotated[
1616
+ Optional[str],
1617
+ Doc(
1618
+ """
1619
+ An alternative name for the parameter field.
1620
+
1621
+ This will be used to extract the data and for the generated OpenAPI.
1622
+ It is particularly useful when you can't use the name you want because it
1623
+ is a Python reserved keyword or similar.
1624
+ """
1625
+ ),
1626
+ ] = None,
1627
+ alias_priority: Annotated[
1628
+ Union[int, None],
1629
+ Doc(
1630
+ """
1631
+ Priority of the alias. This affects whether an alias generator is used.
1632
+ """
1633
+ ),
1634
+ ] = _Unset,
1635
+ validation_alias: Annotated[
1636
+ Union[str, AliasPath, AliasChoices, None],
1637
+ Doc(
1638
+ """
1639
+ 'Whitelist' validation step. The parameter field will be the single one
1640
+ allowed by the alias or set of aliases defined.
1641
+ """
1642
+ ),
1643
+ ] = None,
1644
+ serialization_alias: Annotated[
1645
+ Union[str, None],
1646
+ Doc(
1647
+ """
1648
+ 'Blacklist' validation step. The vanilla parameter field will be the
1649
+ single one of the alias' or set of aliases' fields and all the other
1650
+ fields will be ignored at serialization time.
1651
+ """
1652
+ ),
1653
+ ] = None,
1654
+ title: Annotated[
1655
+ Optional[str],
1656
+ Doc(
1657
+ """
1658
+ Human-readable title.
1659
+ """
1660
+ ),
1661
+ ] = None,
1662
+ description: Annotated[
1663
+ Optional[str],
1664
+ Doc(
1665
+ """
1666
+ Human-readable description.
1667
+ """
1668
+ ),
1669
+ ] = None,
1670
+ gt: Annotated[
1671
+ Optional[float],
1672
+ Doc(
1673
+ """
1674
+ Greater than. If set, value must be greater than this. Only applicable to
1675
+ numbers.
1676
+ """
1677
+ ),
1678
+ ] = None,
1679
+ ge: Annotated[
1680
+ Optional[float],
1681
+ Doc(
1682
+ """
1683
+ Greater than or equal. If set, value must be greater than or equal to
1684
+ this. Only applicable to numbers.
1685
+ """
1686
+ ),
1687
+ ] = None,
1688
+ lt: Annotated[
1689
+ Optional[float],
1690
+ Doc(
1691
+ """
1692
+ Less than. If set, value must be less than this. Only applicable to numbers.
1693
+ """
1694
+ ),
1695
+ ] = None,
1696
+ le: Annotated[
1697
+ Optional[float],
1698
+ Doc(
1699
+ """
1700
+ Less than or equal. If set, value must be less than or equal to this.
1701
+ Only applicable to numbers.
1702
+ """
1703
+ ),
1704
+ ] = None,
1705
+ min_length: Annotated[
1706
+ Optional[int],
1707
+ Doc(
1708
+ """
1709
+ Minimum length for strings.
1710
+ """
1711
+ ),
1712
+ ] = None,
1713
+ max_length: Annotated[
1714
+ Optional[int],
1715
+ Doc(
1716
+ """
1717
+ Maximum length for strings.
1718
+ """
1719
+ ),
1720
+ ] = None,
1721
+ pattern: Annotated[
1722
+ Optional[str],
1723
+ Doc(
1724
+ """
1725
+ RegEx pattern for strings.
1726
+ """
1727
+ ),
1728
+ ] = None,
1729
+ regex: Annotated[
1730
+ Optional[str],
1731
+ Doc(
1732
+ """
1733
+ RegEx pattern for strings.
1734
+ """
1735
+ ),
1736
+ deprecated(
1737
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
1738
+ ),
1739
+ ] = None,
1740
+ discriminator: Annotated[
1741
+ Union[str, None],
1742
+ Doc(
1743
+ """
1744
+ Parameter field name for discriminating the type in a tagged union.
1745
+ """
1746
+ ),
1747
+ ] = None,
1748
+ strict: Annotated[
1749
+ Union[bool, None],
1750
+ Doc(
1751
+ """
1752
+ If `True`, strict validation is applied to the field.
1753
+ """
1754
+ ),
1755
+ ] = _Unset,
1756
+ multiple_of: Annotated[
1757
+ Union[float, None],
1758
+ Doc(
1759
+ """
1760
+ Value must be a multiple of this. Only applicable to numbers.
1761
+ """
1762
+ ),
1763
+ ] = _Unset,
1764
+ allow_inf_nan: Annotated[
1765
+ Union[bool, None],
1766
+ Doc(
1767
+ """
1768
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
1769
+ """
1770
+ ),
1771
+ ] = _Unset,
1772
+ max_digits: Annotated[
1773
+ Union[int, None],
1774
+ Doc(
1775
+ """
1776
+ Maximum number of allow digits for strings.
1777
+ """
1778
+ ),
1779
+ ] = _Unset,
1780
+ decimal_places: Annotated[
1781
+ Union[int, None],
1782
+ Doc(
1783
+ """
1784
+ Maximum number of decimal places allowed for numbers.
1785
+ """
1786
+ ),
1787
+ ] = _Unset,
1788
+ examples: Annotated[
1789
+ Optional[list[Any]],
1790
+ Doc(
1791
+ """
1792
+ Example values for this field.
1793
+ """
1794
+ ),
1795
+ ] = None,
1796
+ example: Annotated[
1797
+ Optional[Any],
1798
+ deprecated(
1799
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
1800
+ "although still supported. Use examples instead."
1801
+ ),
1802
+ ] = _Unset,
1803
+ openapi_examples: Annotated[
1804
+ Optional[dict[str, Example]],
1805
+ Doc(
1806
+ """
1807
+ OpenAPI-specific examples.
1808
+
1809
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
1810
+
1811
+ Swagger UI (that provides the `/docs` interface) has better support for the
1812
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
1813
+ use case for this.
1814
+
1815
+ Read more about it in the
1816
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
1817
+ """
1818
+ ),
1819
+ ] = None,
1820
+ deprecated: Annotated[
1821
+ Union[deprecated, str, bool, None],
1822
+ Doc(
1823
+ """
1824
+ Mark this parameter field as deprecated.
1825
+
1826
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
1827
+ """
1828
+ ),
1829
+ ] = None,
1830
+ include_in_schema: Annotated[
1831
+ bool,
1832
+ Doc(
1833
+ """
1834
+ To include (or not) this parameter field in the generated OpenAPI.
1835
+ You probably don't need it, but it's available.
1836
+
1837
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
1838
+ """
1839
+ ),
1840
+ ] = True,
1841
+ json_schema_extra: Annotated[
1842
+ Union[dict[str, Any], None],
1843
+ Doc(
1844
+ """
1845
+ Any additional JSON schema data.
1846
+ """
1847
+ ),
1848
+ ] = None,
1849
+ **extra: Annotated[
1850
+ Any,
1851
+ Doc(
1852
+ """
1853
+ Include extra fields used by the JSON Schema.
1854
+ """
1855
+ ),
1856
+ deprecated(
1857
+ """
1858
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
1859
+ """
1860
+ ),
1861
+ ],
1862
+ ) -> Any:
1863
+ return params.Form(
1864
+ default=default,
1865
+ default_factory=default_factory,
1866
+ media_type=media_type,
1867
+ alias=alias,
1868
+ alias_priority=alias_priority,
1869
+ validation_alias=validation_alias,
1870
+ serialization_alias=serialization_alias,
1871
+ title=title,
1872
+ description=description,
1873
+ gt=gt,
1874
+ ge=ge,
1875
+ lt=lt,
1876
+ le=le,
1877
+ min_length=min_length,
1878
+ max_length=max_length,
1879
+ pattern=pattern,
1880
+ regex=regex,
1881
+ discriminator=discriminator,
1882
+ strict=strict,
1883
+ multiple_of=multiple_of,
1884
+ allow_inf_nan=allow_inf_nan,
1885
+ max_digits=max_digits,
1886
+ decimal_places=decimal_places,
1887
+ example=example,
1888
+ examples=examples,
1889
+ openapi_examples=openapi_examples,
1890
+ deprecated=deprecated,
1891
+ include_in_schema=include_in_schema,
1892
+ json_schema_extra=json_schema_extra,
1893
+ **extra,
1894
+ )
1895
+
1896
+
1897
+ def File( # noqa: N802
1898
+ default: Annotated[
1899
+ Any,
1900
+ Doc(
1901
+ """
1902
+ Default value if the parameter field is not set.
1903
+ """
1904
+ ),
1905
+ ] = Undefined,
1906
+ *,
1907
+ default_factory: Annotated[
1908
+ Union[Callable[[], Any], None],
1909
+ Doc(
1910
+ """
1911
+ A callable to generate the default value.
1912
+
1913
+ This doesn't affect `Path` parameters as the value is always required.
1914
+ The parameter is available only for compatibility.
1915
+ """
1916
+ ),
1917
+ ] = _Unset,
1918
+ media_type: Annotated[
1919
+ str,
1920
+ Doc(
1921
+ """
1922
+ The media type of this parameter field. Changing it would affect the
1923
+ generated OpenAPI, but currently it doesn't affect the parsing of the data.
1924
+ """
1925
+ ),
1926
+ ] = "multipart/form-data",
1927
+ alias: Annotated[
1928
+ Optional[str],
1929
+ Doc(
1930
+ """
1931
+ An alternative name for the parameter field.
1932
+
1933
+ This will be used to extract the data and for the generated OpenAPI.
1934
+ It is particularly useful when you can't use the name you want because it
1935
+ is a Python reserved keyword or similar.
1936
+ """
1937
+ ),
1938
+ ] = None,
1939
+ alias_priority: Annotated[
1940
+ Union[int, None],
1941
+ Doc(
1942
+ """
1943
+ Priority of the alias. This affects whether an alias generator is used.
1944
+ """
1945
+ ),
1946
+ ] = _Unset,
1947
+ validation_alias: Annotated[
1948
+ Union[str, AliasPath, AliasChoices, None],
1949
+ Doc(
1950
+ """
1951
+ 'Whitelist' validation step. The parameter field will be the single one
1952
+ allowed by the alias or set of aliases defined.
1953
+ """
1954
+ ),
1955
+ ] = None,
1956
+ serialization_alias: Annotated[
1957
+ Union[str, None],
1958
+ Doc(
1959
+ """
1960
+ 'Blacklist' validation step. The vanilla parameter field will be the
1961
+ single one of the alias' or set of aliases' fields and all the other
1962
+ fields will be ignored at serialization time.
1963
+ """
1964
+ ),
1965
+ ] = None,
1966
+ title: Annotated[
1967
+ Optional[str],
1968
+ Doc(
1969
+ """
1970
+ Human-readable title.
1971
+ """
1972
+ ),
1973
+ ] = None,
1974
+ description: Annotated[
1975
+ Optional[str],
1976
+ Doc(
1977
+ """
1978
+ Human-readable description.
1979
+ """
1980
+ ),
1981
+ ] = None,
1982
+ gt: Annotated[
1983
+ Optional[float],
1984
+ Doc(
1985
+ """
1986
+ Greater than. If set, value must be greater than this. Only applicable to
1987
+ numbers.
1988
+ """
1989
+ ),
1990
+ ] = None,
1991
+ ge: Annotated[
1992
+ Optional[float],
1993
+ Doc(
1994
+ """
1995
+ Greater than or equal. If set, value must be greater than or equal to
1996
+ this. Only applicable to numbers.
1997
+ """
1998
+ ),
1999
+ ] = None,
2000
+ lt: Annotated[
2001
+ Optional[float],
2002
+ Doc(
2003
+ """
2004
+ Less than. If set, value must be less than this. Only applicable to numbers.
2005
+ """
2006
+ ),
2007
+ ] = None,
2008
+ le: Annotated[
2009
+ Optional[float],
2010
+ Doc(
2011
+ """
2012
+ Less than or equal. If set, value must be less than or equal to this.
2013
+ Only applicable to numbers.
2014
+ """
2015
+ ),
2016
+ ] = None,
2017
+ min_length: Annotated[
2018
+ Optional[int],
2019
+ Doc(
2020
+ """
2021
+ Minimum length for strings.
2022
+ """
2023
+ ),
2024
+ ] = None,
2025
+ max_length: Annotated[
2026
+ Optional[int],
2027
+ Doc(
2028
+ """
2029
+ Maximum length for strings.
2030
+ """
2031
+ ),
2032
+ ] = None,
2033
+ pattern: Annotated[
2034
+ Optional[str],
2035
+ Doc(
2036
+ """
2037
+ RegEx pattern for strings.
2038
+ """
2039
+ ),
2040
+ ] = None,
2041
+ regex: Annotated[
2042
+ Optional[str],
2043
+ Doc(
2044
+ """
2045
+ RegEx pattern for strings.
2046
+ """
2047
+ ),
2048
+ deprecated(
2049
+ "Deprecated in FastAPI 0.100.0 and Pydantic v2, use `pattern` instead."
2050
+ ),
2051
+ ] = None,
2052
+ discriminator: Annotated[
2053
+ Union[str, None],
2054
+ Doc(
2055
+ """
2056
+ Parameter field name for discriminating the type in a tagged union.
2057
+ """
2058
+ ),
2059
+ ] = None,
2060
+ strict: Annotated[
2061
+ Union[bool, None],
2062
+ Doc(
2063
+ """
2064
+ If `True`, strict validation is applied to the field.
2065
+ """
2066
+ ),
2067
+ ] = _Unset,
2068
+ multiple_of: Annotated[
2069
+ Union[float, None],
2070
+ Doc(
2071
+ """
2072
+ Value must be a multiple of this. Only applicable to numbers.
2073
+ """
2074
+ ),
2075
+ ] = _Unset,
2076
+ allow_inf_nan: Annotated[
2077
+ Union[bool, None],
2078
+ Doc(
2079
+ """
2080
+ Allow `inf`, `-inf`, `nan`. Only applicable to numbers.
2081
+ """
2082
+ ),
2083
+ ] = _Unset,
2084
+ max_digits: Annotated[
2085
+ Union[int, None],
2086
+ Doc(
2087
+ """
2088
+ Maximum number of allow digits for strings.
2089
+ """
2090
+ ),
2091
+ ] = _Unset,
2092
+ decimal_places: Annotated[
2093
+ Union[int, None],
2094
+ Doc(
2095
+ """
2096
+ Maximum number of decimal places allowed for numbers.
2097
+ """
2098
+ ),
2099
+ ] = _Unset,
2100
+ examples: Annotated[
2101
+ Optional[list[Any]],
2102
+ Doc(
2103
+ """
2104
+ Example values for this field.
2105
+ """
2106
+ ),
2107
+ ] = None,
2108
+ example: Annotated[
2109
+ Optional[Any],
2110
+ deprecated(
2111
+ "Deprecated in OpenAPI 3.1.0 that now uses JSON Schema 2020-12, "
2112
+ "although still supported. Use examples instead."
2113
+ ),
2114
+ ] = _Unset,
2115
+ openapi_examples: Annotated[
2116
+ Optional[dict[str, Example]],
2117
+ Doc(
2118
+ """
2119
+ OpenAPI-specific examples.
2120
+
2121
+ It will be added to the generated OpenAPI (e.g. visible at `/docs`).
2122
+
2123
+ Swagger UI (that provides the `/docs` interface) has better support for the
2124
+ OpenAPI-specific examples than the JSON Schema `examples`, that's the main
2125
+ use case for this.
2126
+
2127
+ Read more about it in the
2128
+ [FastAPI docs for Declare Request Example Data](https://fastapi.tiangolo.com/tutorial/schema-extra-example/#using-the-openapi_examples-parameter).
2129
+ """
2130
+ ),
2131
+ ] = None,
2132
+ deprecated: Annotated[
2133
+ Union[deprecated, str, bool, None],
2134
+ Doc(
2135
+ """
2136
+ Mark this parameter field as deprecated.
2137
+
2138
+ It will affect the generated OpenAPI (e.g. visible at `/docs`).
2139
+ """
2140
+ ),
2141
+ ] = None,
2142
+ include_in_schema: Annotated[
2143
+ bool,
2144
+ Doc(
2145
+ """
2146
+ To include (or not) this parameter field in the generated OpenAPI.
2147
+ You probably don't need it, but it's available.
2148
+
2149
+ This affects the generated OpenAPI (e.g. visible at `/docs`).
2150
+ """
2151
+ ),
2152
+ ] = True,
2153
+ json_schema_extra: Annotated[
2154
+ Union[dict[str, Any], None],
2155
+ Doc(
2156
+ """
2157
+ Any additional JSON schema data.
2158
+ """
2159
+ ),
2160
+ ] = None,
2161
+ **extra: Annotated[
2162
+ Any,
2163
+ Doc(
2164
+ """
2165
+ Include extra fields used by the JSON Schema.
2166
+ """
2167
+ ),
2168
+ deprecated(
2169
+ """
2170
+ The `extra` kwargs is deprecated. Use `json_schema_extra` instead.
2171
+ """
2172
+ ),
2173
+ ],
2174
+ ) -> Any:
2175
+ return params.File(
2176
+ default=default,
2177
+ default_factory=default_factory,
2178
+ media_type=media_type,
2179
+ alias=alias,
2180
+ alias_priority=alias_priority,
2181
+ validation_alias=validation_alias,
2182
+ serialization_alias=serialization_alias,
2183
+ title=title,
2184
+ description=description,
2185
+ gt=gt,
2186
+ ge=ge,
2187
+ lt=lt,
2188
+ le=le,
2189
+ min_length=min_length,
2190
+ max_length=max_length,
2191
+ pattern=pattern,
2192
+ regex=regex,
2193
+ discriminator=discriminator,
2194
+ strict=strict,
2195
+ multiple_of=multiple_of,
2196
+ allow_inf_nan=allow_inf_nan,
2197
+ max_digits=max_digits,
2198
+ decimal_places=decimal_places,
2199
+ example=example,
2200
+ examples=examples,
2201
+ openapi_examples=openapi_examples,
2202
+ deprecated=deprecated,
2203
+ include_in_schema=include_in_schema,
2204
+ json_schema_extra=json_schema_extra,
2205
+ **extra,
2206
+ )
2207
+
2208
+
2209
+ def Depends( # noqa: N802
2210
+ dependency: Annotated[
2211
+ Optional[Callable[..., Any]],
2212
+ Doc(
2213
+ """
2214
+ A "dependable" callable (like a function).
2215
+
2216
+ Don't call it directly, FastAPI will call it for you, just pass the object
2217
+ directly.
2218
+ """
2219
+ ),
2220
+ ] = None,
2221
+ *,
2222
+ use_cache: Annotated[
2223
+ bool,
2224
+ Doc(
2225
+ """
2226
+ By default, after a dependency is called the first time in a request, if
2227
+ the dependency is declared again for the rest of the request (for example
2228
+ if the dependency is needed by several dependencies), the value will be
2229
+ re-used for the rest of the request.
2230
+
2231
+ Set `use_cache` to `False` to disable this behavior and ensure the
2232
+ dependency is called again (if declared more than once) in the same request.
2233
+ """
2234
+ ),
2235
+ ] = True,
2236
+ scope: Annotated[
2237
+ Union[Literal["function", "request"], None],
2238
+ Doc(
2239
+ """
2240
+ Mainly for dependencies with `yield`, define when the dependency function
2241
+ should start (the code before `yield`) and when it should end (the code
2242
+ after `yield`).
2243
+
2244
+ * `"function"`: start the dependency before the *path operation function*
2245
+ that handles the request, end the dependency after the *path operation
2246
+ function* ends, but **before** the response is sent back to the client.
2247
+ So, the dependency function will be executed **around** the *path operation
2248
+ **function***.
2249
+ * `"request"`: start the dependency before the *path operation function*
2250
+ that handles the request (similar to when using `"function"`), but end
2251
+ **after** the response is sent back to the client. So, the dependency
2252
+ function will be executed **around** the **request** and response cycle.
2253
+ """
2254
+ ),
2255
+ ] = None,
2256
+ ) -> Any:
2257
+ """
2258
+ Declare a FastAPI dependency.
2259
+
2260
+ It takes a single "dependable" callable (like a function).
2261
+
2262
+ Don't call it directly, FastAPI will call it for you.
2263
+
2264
+ Read more about it in the
2265
+ [FastAPI docs for Dependencies](https://fastapi.tiangolo.com/tutorial/dependencies/).
2266
+
2267
+ **Example**
2268
+
2269
+ ```python
2270
+ from typing import Annotated
2271
+
2272
+ from fastapi import Depends, FastAPI
2273
+
2274
+ app = FastAPI()
2275
+
2276
+
2277
+ async def common_parameters(q: str | None = None, skip: int = 0, limit: int = 100):
2278
+ return {"q": q, "skip": skip, "limit": limit}
2279
+
2280
+
2281
+ @app.get("/items/")
2282
+ async def read_items(commons: Annotated[dict, Depends(common_parameters)]):
2283
+ return commons
2284
+ ```
2285
+ """
2286
+ return params.Depends(dependency=dependency, use_cache=use_cache, scope=scope)
2287
+
2288
+
2289
+ def Security( # noqa: N802
2290
+ dependency: Annotated[
2291
+ Optional[Callable[..., Any]],
2292
+ Doc(
2293
+ """
2294
+ A "dependable" callable (like a function).
2295
+
2296
+ Don't call it directly, FastAPI will call it for you, just pass the object
2297
+ directly.
2298
+ """
2299
+ ),
2300
+ ] = None,
2301
+ *,
2302
+ scopes: Annotated[
2303
+ Optional[Sequence[str]],
2304
+ Doc(
2305
+ """
2306
+ OAuth2 scopes required for the *path operation* that uses this Security
2307
+ dependency.
2308
+
2309
+ The term "scope" comes from the OAuth2 specification, it seems to be
2310
+ intentionally vague and interpretable. It normally refers to permissions,
2311
+ in cases to roles.
2312
+
2313
+ These scopes are integrated with OpenAPI (and the API docs at `/docs`).
2314
+ So they are visible in the OpenAPI specification.
2315
+ )
2316
+ """
2317
+ ),
2318
+ ] = None,
2319
+ use_cache: Annotated[
2320
+ bool,
2321
+ Doc(
2322
+ """
2323
+ By default, after a dependency is called the first time in a request, if
2324
+ the dependency is declared again for the rest of the request (for example
2325
+ if the dependency is needed by several dependencies), the value will be
2326
+ re-used for the rest of the request.
2327
+
2328
+ Set `use_cache` to `False` to disable this behavior and ensure the
2329
+ dependency is called again (if declared more than once) in the same request.
2330
+ """
2331
+ ),
2332
+ ] = True,
2333
+ ) -> Any:
2334
+ """
2335
+ Declare a FastAPI Security dependency.
2336
+
2337
+ The only difference with a regular dependency is that it can declare OAuth2
2338
+ scopes that will be integrated with OpenAPI and the automatic UI docs (by default
2339
+ at `/docs`).
2340
+
2341
+ It takes a single "dependable" callable (like a function).
2342
+
2343
+ Don't call it directly, FastAPI will call it for you.
2344
+
2345
+ Read more about it in the
2346
+ [FastAPI docs for Security](https://fastapi.tiangolo.com/tutorial/security/) and
2347
+ in the
2348
+ [FastAPI docs for OAuth2 scopes](https://fastapi.tiangolo.com/advanced/security/oauth2-scopes/).
2349
+
2350
+ **Example**
2351
+
2352
+ ```python
2353
+ from typing import Annotated
2354
+
2355
+ from fastapi import Security, FastAPI
2356
+
2357
+ from .db import User
2358
+ from .security import get_current_active_user
2359
+
2360
+ app = FastAPI()
2361
+
2362
+ @app.get("/users/me/items/")
2363
+ async def read_own_items(
2364
+ current_user: Annotated[User, Security(get_current_active_user, scopes=["items"])]
2365
+ ):
2366
+ return [{"item_id": "Foo", "owner": current_user.username}]
2367
+ ```
2368
+ """
2369
+ return params.Security(dependency=dependency, scopes=scopes, use_cache=use_cache)