Results of 1 - 10 of about 57 for typing (0.008 sec.)
- クエリパラメータと文字列の検証 12056
- クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g
...てみましょう。 Query のインポート そのために、まずは fastapi から Query をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Unio...date ({ "q" : q }) return results ? Other versions and variants Python 3.10+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q :...ts = { "items" : [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]} if q : results . update ({ "q" : q }) return results from typing import Union from fastapi import FastAPI , Query from typing_extensions import Annotated app = FastAPI () @app . get ( "/i... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- ヘッダーのパラメータ 10529
- ヘッダーのパラメータ ヘッダーのパラメータは、 Query や Path 、 Cookie のパラメータを定義するのと同じように定義できます。 Header をインポート まず、 Header をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi
...Agent" : user_agent } ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( use...r_agent : Annotated [ str | None , Header ()] = None ): return { "User-Agent" : user_agent } from typing import Annotated , Union from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_ite...ms ( user_agent : Annotated [ Union [ str , None ], Header ()] = None ): return { "User-Agent" : user_agent } from typing import Union from fastapi import FastAPI , Header from typing_extensions import Annotated app = FastAPI () @app . get ( "/... - https://man.mtool.work/fastapi/0.115/tutorial/header-params/
- 依存関係としてのクラス 10382
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr
...rs )): return commons ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : str | None = Non...get ( "/users/" ) async def read_users ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons from typing import Annotated , Union from fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : Union [...get ( "/users/" ) async def read_users ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons from typing import Union from fastapi import Depends , FastAPI from typing_extensions import Annotated app = FastAPI () async def comm... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- SQL (Relational) Databases 9809
- SQL (Relational) Databases Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI doesn't require you to use a SQL (relational) database. But you can use any data
...and versatility with multiple models below. ? Create Models Import SQLModel and create a database model: Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLM...e = Field ( default = None , index = True ) secret_name : str # Code below omitted ? ? Full file preview Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLM...variants Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated Python 3.9+ - non-Annotated Python 3.8+ - non-Annotated from typing import Annotated , Union from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Sessio... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- 現在のユーザーの取得 9560
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...: str = Depends ( oauth2_scheme )): return { "token" : token } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer app = FastAPI ()...): return { "token" : token } from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer from typing_extensions import Annotated app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/it...るのにPydanticを使用するのと同じやり方で、Pydanticを別のどんなところでも使うことができます: Python 3.8+ - non-Annotated from typing import Union from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer from pydantic import... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- クエリパラメータモデル 9457
- クエリパラメータモデル もし関連する 複数のクエリパラメータ から成るグループがあるなら、それらを宣言するために、 Pydanticモデル を作成できます。 こうすることで、 複数の場所 で そのPydanticモデルを再利用 でき、バリデーションやメタデータを、す
...する 必要な 複数のクエリパラメータ を Pydanticモデル で宣言し、さらに、それを Query として宣言しましょう: Python 3.10+ from typing import Annotated , Literal from fastapi import FastAPI , Query from pydantic import BaseModel , Field app = FastAPI () cla...non-Annotated Python 3.8+ - non-Annotated from fastapi import FastAPI , Query from pydantic import BaseModel , Field from typing_extensions import Annotated , Literal app = FastAPI () class FilterParams ( BaseModel ): limit : int = Field ( 100 , gt =.... get ( "/items/" ) async def read_items ( filter_query : Annotated [ FilterParams , Query ()]): return filter_query from typing import List from fastapi import FastAPI , Query from pydantic import BaseModel , Field from typing_extensions import Annot... - https://man.mtool.work/fastapi/0.115/tutorial/query-param-models/
- ボディ - ネストされたモデル 9149
- ボディ - ネストされたモデル FastAPI を使用すると、深くネストされた任意のモデルを定義、検証、文書化、使用することができます(Pydanticのおかげです)。 リストのフィールド 属性をサブタイプとして定義することができます。例えば、Pythonの list は以
...下のように定義できます: Python 3.8+ from typing import Union from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name :...タイプパラメータを持つリストのフィールド しかし、Pythonには型や「タイプパラメータ」を使ってリストを宣言する方法があります: typingの List をインポート まず、Pythonの標準の typing モジュールから List をインポートします: Python 3.8+ from typing import List...ync def update_item ( item_id : int , item : Item ): results = { "item_id" : item_id , "item" : item } return results from typing import Union from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name :... - https://man.mtool.work/fastapi/0.115/tutorial/body-nested-models/
- ボディ - 複数のパラメータ 9104
- ボディ - 複数のパラメータ これまで Path と Query をどう使うかを見てきましたが、リクエストボディの宣言のより高度な使い方を見てみましょう。 Path 、 Query とボディパラメータを混ぜる まず、もちろん、 Path と Query とリクエストボディのパラメータ
...フォルトの None を設定することで、ボディパラメータをオプションとして宣言することもできます: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ):...tem }) return results ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Path from pydantic import BaseModel app = FastAPI () class Item ( BaseModel...m_id" : item_id } if q : results . update ({ "q" : q }) if item : results . update ({ "item" : item }) return results from typing import Annotated , Union from fastapi import FastAPI , Path from pydantic import BaseModel app = FastAPI () class Item ( B... - https://man.mtool.work/fastapi/0.115/tutorial/body-multiple-params/
- クッキーのパラメータ 9104
- クッキーのパラメータ クッキーのパラメータは、 Query や Path のパラメータを定義するのと同じ方法で定義できます。 Cookie をインポート まず、 Cookie をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import Co
...{ "ads_id" : ads_id } ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import Cookie , FastAPI app = FastAPI () @app . get ( "/items/" ) async def read_items ( ads..._id : Annotated [ str | None , Cookie ()] = None ): return { "ads_id" : ads_id } from typing import Annotated , Union from fastapi import Cookie , FastAPI app = FastAPI () @app . get ( "/items/" ) async def read_ite...ms ( ads_id : Annotated [ Union [ str , None ], Cookie ()] = None ): return { "ads_id" : ads_id } from typing import Union from fastapi import Cookie , FastAPI from typing_extensions import Annotated app = FastAPI () @app . get ( "/... - https://man.mtool.work/fastapi/0.115/tutorial/cookie-params/
- パスパラメータと数値の検証 9104
- パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず
...初めに、 fastapi から Path をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def rea...: q }) return results ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def...= "item-query" )] = None , ): results = { "item_id" : item_id } if q : results . update ({ "q" : q }) return results from typing import Annotated , Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) a... - https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/