fastapi 0.118.3__py3-none-any.whl → 0.119.1__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.

Potentially problematic release.


This version of fastapi might be problematic. Click here for more details.

fastapi/utils.py CHANGED
@@ -23,10 +23,12 @@ from fastapi._compat import (
23
23
  Undefined,
24
24
  UndefinedType,
25
25
  Validator,
26
+ annotation_is_pydantic_v1,
26
27
  lenient_issubclass,
28
+ may_v1,
27
29
  )
28
30
  from fastapi.datastructures import DefaultPlaceholder, DefaultType
29
- from pydantic import BaseModel, create_model
31
+ from pydantic import BaseModel
30
32
  from pydantic.fields import FieldInfo
31
33
  from typing_extensions import Literal
32
34
 
@@ -60,50 +62,74 @@ def get_path_param_names(path: str) -> Set[str]:
60
62
  return set(re.findall("{(.*?)}", path))
61
63
 
62
64
 
65
+ _invalid_args_message = (
66
+ "Invalid args for response field! Hint: "
67
+ "check that {type_} is a valid Pydantic field type. "
68
+ "If you are using a return type annotation that is not a valid Pydantic "
69
+ "field (e.g. Union[Response, dict, None]) you can disable generating the "
70
+ "response model from the type annotation with the path operation decorator "
71
+ "parameter response_model=None. Read more: "
72
+ "https://fastapi.tiangolo.com/tutorial/response-model/"
73
+ )
74
+
75
+
63
76
  def create_model_field(
64
77
  name: str,
65
78
  type_: Any,
66
79
  class_validators: Optional[Dict[str, Validator]] = None,
67
80
  default: Optional[Any] = Undefined,
68
81
  required: Union[bool, UndefinedType] = Undefined,
69
- model_config: Type[BaseConfig] = BaseConfig,
82
+ model_config: Union[Type[BaseConfig], None] = None,
70
83
  field_info: Optional[FieldInfo] = None,
71
84
  alias: Optional[str] = None,
72
85
  mode: Literal["validation", "serialization"] = "validation",
86
+ version: Literal["1", "auto"] = "auto",
73
87
  ) -> ModelField:
74
88
  class_validators = class_validators or {}
75
- if PYDANTIC_V2:
89
+
90
+ v1_model_config = may_v1.BaseConfig
91
+ v1_field_info = field_info or may_v1.FieldInfo()
92
+ v1_kwargs = {
93
+ "name": name,
94
+ "field_info": v1_field_info,
95
+ "type_": type_,
96
+ "class_validators": class_validators,
97
+ "default": default,
98
+ "required": required,
99
+ "model_config": v1_model_config,
100
+ "alias": alias,
101
+ }
102
+
103
+ if (
104
+ annotation_is_pydantic_v1(type_)
105
+ or isinstance(field_info, may_v1.FieldInfo)
106
+ or version == "1"
107
+ ):
108
+ from fastapi._compat import v1
109
+
110
+ try:
111
+ return v1.ModelField(**v1_kwargs) # type: ignore[no-any-return]
112
+ except RuntimeError:
113
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
114
+ elif PYDANTIC_V2:
115
+ from ._compat import v2
116
+
76
117
  field_info = field_info or FieldInfo(
77
118
  annotation=type_, default=default, alias=alias
78
119
  )
79
- else:
80
- field_info = field_info or FieldInfo()
81
- kwargs = {"name": name, "field_info": field_info}
82
- if PYDANTIC_V2:
83
- kwargs.update({"mode": mode})
84
- else:
85
- kwargs.update(
86
- {
87
- "type_": type_,
88
- "class_validators": class_validators,
89
- "default": default,
90
- "required": required,
91
- "model_config": model_config,
92
- "alias": alias,
93
- }
94
- )
120
+ kwargs = {"mode": mode, "name": name, "field_info": field_info}
121
+ try:
122
+ return v2.ModelField(**kwargs) # type: ignore[return-value,arg-type]
123
+ except PydanticSchemaGenerationError:
124
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
125
+ # Pydantic v2 is not installed, but it's not a Pydantic v1 ModelField, it could be
126
+ # a Pydantic v1 type, like a constrained int
127
+ from fastapi._compat import v1
128
+
95
129
  try:
96
- return ModelField(**kwargs) # type: ignore[arg-type]
97
- except (RuntimeError, PydanticSchemaGenerationError):
98
- raise fastapi.exceptions.FastAPIError(
99
- "Invalid args for response field! Hint: "
100
- f"check that {type_} is a valid Pydantic field type. "
101
- "If you are using a return type annotation that is not a valid Pydantic "
102
- "field (e.g. Union[Response, dict, None]) you can disable generating the "
103
- "response model from the type annotation with the path operation decorator "
104
- "parameter response_model=None. Read more: "
105
- "https://fastapi.tiangolo.com/tutorial/response-model/"
106
- ) from None
130
+ return v1.ModelField(**v1_kwargs) # type: ignore[no-any-return]
131
+ except RuntimeError:
132
+ raise fastapi.exceptions.FastAPIError(_invalid_args_message) from None
107
133
 
108
134
 
109
135
  def create_cloned_field(
@@ -112,7 +138,13 @@ def create_cloned_field(
112
138
  cloned_types: Optional[MutableMapping[Type[BaseModel], Type[BaseModel]]] = None,
113
139
  ) -> ModelField:
114
140
  if PYDANTIC_V2:
115
- return field
141
+ from ._compat import v2
142
+
143
+ if isinstance(field, v2.ModelField):
144
+ return field
145
+
146
+ from fastapi._compat import v1
147
+
116
148
  # cloned_types caches already cloned types to support recursive models and improve
117
149
  # performance by avoiding unnecessary cloning
118
150
  if cloned_types is None:
@@ -122,17 +154,18 @@ def create_cloned_field(
122
154
  if is_dataclass(original_type) and hasattr(original_type, "__pydantic_model__"):
123
155
  original_type = original_type.__pydantic_model__
124
156
  use_type = original_type
125
- if lenient_issubclass(original_type, BaseModel):
126
- original_type = cast(Type[BaseModel], original_type)
157
+ if lenient_issubclass(original_type, v1.BaseModel):
158
+ original_type = cast(Type[v1.BaseModel], original_type)
127
159
  use_type = cloned_types.get(original_type)
128
160
  if use_type is None:
129
- use_type = create_model(original_type.__name__, __base__=original_type)
161
+ use_type = v1.create_model(original_type.__name__, __base__=original_type)
130
162
  cloned_types[original_type] = use_type
131
163
  for f in original_type.__fields__.values():
132
164
  use_type.__fields__[f.name] = create_cloned_field(
133
- f, cloned_types=cloned_types
165
+ f,
166
+ cloned_types=cloned_types,
134
167
  )
135
- new_field = create_model_field(name=field.name, type_=use_type)
168
+ new_field = create_model_field(name=field.name, type_=use_type, version="1")
136
169
  new_field.has_alias = field.has_alias # type: ignore[attr-defined]
137
170
  new_field.alias = field.alias # type: ignore[misc]
138
171
  new_field.class_validators = field.class_validators # type: ignore[attr-defined]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastapi
3
- Version: 0.118.3
3
+ Version: 0.119.1
4
4
  Summary: FastAPI framework, high performance, easy to learn, fast to code, ready for production
5
5
  Author-Email: =?utf-8?q?Sebasti=C3=A1n_Ram=C3=ADrez?= <tiangolo@gmail.com>
6
6
  Classifier: Intended Audience :: Information Technology
@@ -198,7 +198,7 @@ If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be
198
198
 
199
199
  FastAPI stands on the shoulders of giants:
200
200
 
201
- * <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a> for the web parts.
201
+ * <a href="https://www.starlette.dev/" class="external-link" target="_blank">Starlette</a> for the web parts.
202
202
  * <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> for the data parts.
203
203
 
204
204
  ## Installation
@@ -304,7 +304,7 @@ INFO: Application startup complete.
304
304
  <details markdown="1">
305
305
  <summary>About the command <code>fastapi dev main.py</code>...</summary>
306
306
 
307
- The command `fastapi dev` reads your `main.py` file, detects the **FastAPI** app in it, and starts a server using <a href="https://www.uvicorn.org" class="external-link" target="_blank">Uvicorn</a>.
307
+ The command `fastapi dev` reads your `main.py` file, detects the **FastAPI** app in it, and starts a server using <a href="https://www.uvicorn.dev" class="external-link" target="_blank">Uvicorn</a>.
308
308
 
309
309
  By default, `fastapi dev` will start with auto-reload enabled for local development.
310
310
 
@@ -545,7 +545,7 @@ Used by Starlette:
545
545
 
546
546
  Used by FastAPI:
547
547
 
548
- * <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application. This includes `uvicorn[standard]`, which includes some dependencies (e.g. `uvloop`) needed for high performance serving.
548
+ * <a href="https://www.uvicorn.dev" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application. This includes `uvicorn[standard]`, which includes some dependencies (e.g. `uvloop`) needed for high performance serving.
549
549
  * `fastapi-cli[standard]` - to provide the `fastapi` command.
550
550
  * This includes `fastapi-cloud-cli`, which allows you to deploy your FastAPI application to <a href="https://fastapicloud.com" class="external-link" target="_blank">FastAPI Cloud</a>.
551
551
 
@@ -1,19 +1,25 @@
1
- fastapi-0.118.3.dist-info/METADATA,sha256=ohgvM1p79CKb9b7MWSbCq5SmCcyR4xlsvEYKeYNOi_0,28186
2
- fastapi-0.118.3.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
- fastapi-0.118.3.dist-info/entry_points.txt,sha256=GCf-WbIZxyGT4MUmrPGj1cOHYZoGsNPHAvNkT6hnGeA,61
4
- fastapi-0.118.3.dist-info/licenses/LICENSE,sha256=Tsif_IFIW5f-xYSy1KlhAy7v_oNEU4lP2cEnSQbMdE4,1086
5
- fastapi/__init__.py,sha256=LmVb1lKosa22IaZFC9pm5Jxn41U6-SxtveBq3a_VEqM,1081
1
+ fastapi-0.119.1.dist-info/METADATA,sha256=rY8zpZZCl9O5sa04bbHX9LNu4OzUSNK_wFz5Q_bw0us,28187
2
+ fastapi-0.119.1.dist-info/WHEEL,sha256=9P2ygRxDrTJz3gsagc0Z96ukrxjr-LFBGOgv3AuKlCA,90
3
+ fastapi-0.119.1.dist-info/entry_points.txt,sha256=GCf-WbIZxyGT4MUmrPGj1cOHYZoGsNPHAvNkT6hnGeA,61
4
+ fastapi-0.119.1.dist-info/licenses/LICENSE,sha256=Tsif_IFIW5f-xYSy1KlhAy7v_oNEU4lP2cEnSQbMdE4,1086
5
+ fastapi/__init__.py,sha256=zO_apwJ-xWFAMpLy76jnXPRx1spS5KMoM7cF7mk8bgA,1081
6
6
  fastapi/__main__.py,sha256=bKePXLdO4SsVSM6r9SVoLickJDcR2c0cTOxZRKq26YQ,37
7
- fastapi/_compat.py,sha256=gK1ZeDQYNr6gBYY0Hefr2HZiEawOCuDqm021uU1xOTs,25041
8
- fastapi/applications.py,sha256=nLbGcVdmCxXsl4aTSuP0WVS_XGY7wXBL3vC7nqlplmA,180276
7
+ fastapi/_compat/__init__.py,sha256=8fa5XmM6_whr6YWuCs7KDdKR_gZ_AMmaxYW7GDn0eng,2718
8
+ fastapi/_compat/main.py,sha256=WDixlh9_5nfFuwWvbYQJNi8l5nDZdfbl2nMyTriG65c,10978
9
+ fastapi/_compat/may_v1.py,sha256=uiZpZTEVHBlD_Q3WYUW_BNW24X3yk_OwvHhCgPwTUco,2979
10
+ fastapi/_compat/model_field.py,sha256=SrSoXEcloGXKAqjR8UDW2869RPgLRFdWTuVgTBhX_Gw,1190
11
+ fastapi/_compat/shared.py,sha256=KPOKDRBmM4mzGLdRZwDyrTIph6Eud9Vb2vil1dxNdV0,7030
12
+ fastapi/_compat/v1.py,sha256=v_YLzo8uyr0HeA7QxNbgaSb332kCcBK9-9PZmOHGkq8,10325
13
+ fastapi/_compat/v2.py,sha256=AcWbeOlPPFwxj0bRXtVe-A4Lio9ovCR7STd-qS5aqOk,15838
14
+ fastapi/applications.py,sha256=loHPnnTLs4mkV5Cbeota0_MnYMGHaepU4HR9VDdrwUQ,180278
9
15
  fastapi/background.py,sha256=rouLirxUANrcYC824MSMypXL_Qb2HYg2YZqaiEqbEKI,1768
10
16
  fastapi/cli.py,sha256=OYhZb0NR_deuT5ofyPF2NoNBzZDNOP8Salef2nk-HqA,418
11
17
  fastapi/concurrency.py,sha256=MirfowoSpkMQZ8j_g0ZxaQKpV6eB3G-dB5TgcXCrgEA,1424
12
- fastapi/datastructures.py,sha256=b2PEz77XGq-u3Ur1Inwk0AGjOsQZO49yF9C7IPJ15cY,5766
18
+ fastapi/datastructures.py,sha256=hM5DM_PtV7rL54VHtLk0dA9RHeAm9IzBd5TrRqc9tSs,5788
13
19
  fastapi/dependencies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
20
  fastapi/dependencies/models.py,sha256=Pjl6vx-4nZ5Tta9kJa3-RfQKkXtCpS09-FhMgs9eWNs,1507
15
- fastapi/dependencies/utils.py,sha256=WVgX-cF_H318wOlsZSiAP2mX6-puEsx_MAQ6AHSzITE,36814
16
- fastapi/encoders.py,sha256=r_fOgMylrlnCDTh3W9u2W0ZsHTJqIhLpU6QipHMy0m8,11119
21
+ fastapi/dependencies/utils.py,sha256=weAsXzD81nWm5U0LEa3xnXo9VWMmcFfttQ73vC1M0kw,38633
22
+ fastapi/encoders.py,sha256=nv7xTKPQOFTziC85lTHxO0WwuKugpUjEc26HXO-QHHo,11318
17
23
  fastapi/exception_handlers.py,sha256=YVcT8Zy021VYYeecgdyh5YEUjEIHKcLspbkSf4OfbJI,1275
18
24
  fastapi/exceptions.py,sha256=taNixuFEXb67lI1bnX1ubq8y8TseJ4yoPlWjyP0fTzk,4969
19
25
  fastapi/logger.py,sha256=I9NNi3ov8AcqbsbC9wl1X-hdItKgYt2XTrx1f99Zpl4,54
@@ -28,13 +34,13 @@ fastapi/openapi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
28
34
  fastapi/openapi/constants.py,sha256=adGzmis1L1HJRTE3kJ5fmHS_Noq6tIY6pWv_SFzoFDU,153
29
35
  fastapi/openapi/docs.py,sha256=zSDv4xY6XHcKsaG4zyk1HqSnrZtfZFBB0J7ZBk5YHPE,10345
30
36
  fastapi/openapi/models.py,sha256=m1BNHxf_RiDTK1uCfMre6XZN5y7krZNA62QEP_2EV9s,15625
31
- fastapi/openapi/utils.py,sha256=ZI-nwdT2PtX8kaRPJylZo4LJHjYAcoVGxkd181P75x4,23997
37
+ fastapi/openapi/utils.py,sha256=2DkhvMHoHLI58vK4vai_7v9WZ3R5RMB6dGDIAx3snGo,23255
32
38
  fastapi/param_functions.py,sha256=JHNPLIYvoAwdnZZavIVsxOat8x23fX_Kl33reh7HKl8,64019
33
39
  fastapi/params.py,sha256=SnkGa4nNdmRek6oOELBHcSieRGjYvDPTla3EOl5Zlis,28413
34
40
  fastapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
35
41
  fastapi/requests.py,sha256=zayepKFcienBllv3snmWI20Gk0oHNVLU4DDhqXBb4LU,142
36
42
  fastapi/responses.py,sha256=QNQQlwpKhQoIPZTTWkpc9d_QGeGZ_aVQPaDV3nQ8m7c,1761
37
- fastapi/routing.py,sha256=tK_d2K_0kP-rcbAmjjlR0mZMR170QkBITvwHWPq7eiQ,178409
43
+ fastapi/routing.py,sha256=oyDRSG8sOL53dDlduKwJXIb_i0_1TeQduQpKu00T5SU,178480
38
44
  fastapi/security/__init__.py,sha256=bO8pNmxqVRXUjfl2mOKiVZLn0FpBQ61VUYVjmppnbJw,881
39
45
  fastapi/security/api_key.py,sha256=di-0gQ8MKugi2YfmlMoDHk-QMF_vnLGJRFOA6tcZ7fA,9016
40
46
  fastapi/security/base.py,sha256=dl4pvbC-RxjfbWgPtCWd8MVU-7CB2SZ22rJDXVCXO6c,141
@@ -43,9 +49,10 @@ fastapi/security/oauth2.py,sha256=rKHIUHq29367Qpe0Ez5Gcu1yIIM6SMw7nEfh15gBNIQ,22
43
49
  fastapi/security/open_id_connect_url.py,sha256=8vizZ2tGqEp1ur8SwtVgyHJhGAJ5AqahgcvSpaIioDI,2722
44
50
  fastapi/security/utils.py,sha256=bd8T0YM7UQD5ATKucr1bNtAvz_Y3__dVNAv5UebiPvc,293
45
51
  fastapi/staticfiles.py,sha256=iirGIt3sdY2QZXd36ijs3Cj-T0FuGFda3cd90kM9Ikw,69
52
+ fastapi/temp_pydantic_v1_params.py,sha256=c9uTBAryfdbgEmAiuJ9BmnmFzYiFZK52z3dDKX4PSRY,26530
46
53
  fastapi/templating.py,sha256=4zsuTWgcjcEainMJFAlW6-gnslm6AgOS1SiiDWfmQxk,76
47
54
  fastapi/testclient.py,sha256=nBvaAmX66YldReJNZXPOk1sfuo2Q6hs8bOvIaCep6LQ,66
48
55
  fastapi/types.py,sha256=nFb36sK3DSoqoyo7Miwy3meKK5UdFBgkAgLSzQlUVyI,383
49
- fastapi/utils.py,sha256=S59stPvKPUJ7MSkke3FaegSyig_4Uwhd32jnLiMF1jE,8032
56
+ fastapi/utils.py,sha256=Nedm_1OJnL12uHJ85HTPCO-AHfwxCtXObFpBi_0X4xQ,9010
50
57
  fastapi/websockets.py,sha256=419uncYObEKZG0YcrXscfQQYLSWoE10jqxVMetGdR98,222
51
- fastapi-0.118.3.dist-info/RECORD,,
58
+ fastapi-0.119.1.dist-info/RECORD,,