Results of 1 - 10 of about 41 for item (0.004 sec.)
- ボディ - 更新 10071
- ボディ - 更新 PUT による置換での更新 項目を更新するには HTTPの PUT 操作を使用することができます。 jsonable_encoder を用いて、入力データをJSON形式で保存できるデータに変換することができます(例:NoSQLデータベース)。例えば、 datetime を str に
...fastapi import FastAPI from fastapi.encoders import jsonable_encoder from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : Union [ str , None ] = None description : Union [ str , None ] = None price : Union [ float , None ]...= None tax : float = 10.5 tags : List [ str ] = [] items = { "foo" : { "name" : "Foo" , "price" : 50.2 }, "bar" : { "name" : "Bar" , "description" : "The bartenders" , "price" :...: 20.2 }, "baz" : { "name" : "Baz" , "description" : None , "price" : 50.2 , "tax" : 10.5 , "tags" : []}, } @app . get ( "/items/ {item_id} " , response_model = Item ) async def read_item ( item_id : str ): return items [ item_id ] @app . put ( "/ite... - https://man.mtool.work/fastapi/0.115/tutorial/body-updates/
- ボディ - 複数のパラメータ 10056
- ボディ - 複数のパラメータ これまで Path と Query をどう使うかを見てきましたが、リクエストボディの宣言のより高度な使い方を見てみましょう。 Path 、 Query とボディパラメータを混ぜる まず、もちろん、 Path と Query とリクエストボディのパラメータ
...nnotated from typing import Union from fastapi import FastAPI , Path from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None @app.... put ( "/items/ {item_id} " ) async def update_item ( * , item_id : int = Path ( title = "The ID of the item to get" , ge = 0 , le = 100...0 ), q : Union [ str , None ] = None , item : Union [ Item , None ] = None , ): results = { "item_id" : item_id } if q : results . update ({ "q" : q }) if item : resu... - https://man.mtool.work/fastapi/0.115/tutorial/body-multiple-params/
- ボディ - ネストされたモデル 9916
- ボディ - ネストされたモデル 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 : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags...: list = [] @app . put ( "/items/ {item_id} " ) async def update_item ( item_id : int , item : Item ): results = { "item_id" : item_id , "item" : item } r...Other versions and variants Python 3.10+ from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None tags : list = [] @app .... - https://man.mtool.work/fastapi/0.115/tutorial/body-nested-models/
- Path Operationの設定 9620
- Path Operationの設定 path operationデコレータ を設定するためのパラメータがいくつかあります。 注意 これらのパラメータは path operation関数 ではなく、 path operationデコレータ に直接渡されることに注意してください。 レスポンスステータスコード
...from typing import Set , Union from fastapi import FastAPI , status from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags...: Set [ str ] = set () @app . post ( "/items/" , response_model = Item , status_code = status . HTTP_201_CREATED ) async def create_item ( item : Item ): return item...riants Python 3.10+ Python 3.9+ from fastapi import FastAPI , status from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None tags : set [ str ] = set... - https://man.mtool.work/fastapi/0.115/tutorial/path-operation-configuration/
- Separate OpenAPI Schemas for Input and Output or Not 9605
- Separate OpenAPI Schemas for Input and Output or Not Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When using Pydantic v2 , the generated OpenAPI is a bit more e
...ic model with default values, like this one: Python 3.10+ from fastapi import FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None # Code below omitted ? ? Full file preview Python 3.10+ from fas...tapi import FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None app = FastAPI () @app . post ( "/items/" ) def create_item ( ite...m : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: return [ Item ( name = "Portal Gun" , descript... - https://man.mtool.work/fastapi/0.115/how-to/separate-openapi-schemas/
- ボディ - フィールド 9605
- ボディ - フィールド Query や Path 、 Body を使って path operation関数 のパラメータに追加のバリデーションやメタデータを宣言するのと同じように、Pydanticの Field を使ってPydanticモデルの内部でバリデーションやメタデータを宣言することができます。
...from typing import Union from fastapi import Body , FastAPI from pydantic import BaseModel , Field app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = Field ( default = None , title = "The description of the it...Field ( gt = 0 , description = "The price must be greater than zero" ) tax : Union [ float , None ] = None @app . put ( "/items/ {item_id} " ) async def update_item ( item_id : int , item : Item = Body ( embed = True )): results = { "item_id" : item..._id , "item" : item } return results ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated f... - https://man.mtool.work/fastapi/0.115/tutorial/body-fields/
- スキーマの追加 - 例 9558
- スキーマの追加 - 例 JSON Schemaに追加する情報を定義することができます。 一般的なユースケースはこのドキュメントで示されているように example を追加することです。 JSON Schemaの追加情報を宣言する方法はいくつかあります。 Pydanticの schema_extra
...ます: Python 3.8+ from typing import Union from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None mode...l_config = { "json_schema_extra" : { "examples" : [ { "name" : "Foo" , "description" : "A very nice Item" , "price" : 35.4 , "tax" : 3.2 , } ] } } @app . put ( "/items/ {item_id} " ) async def update_item ( item_id : int , item...: Item ): results = { "item_id" : item_id , "item" : item } return results ? Other versions and variants Python 3.10+ from fastap... - https://man.mtool.work/fastapi/0.115/tutorial/schema-extra-example/
- パスパラメータと数値の検証 9527
- パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず
...n 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : int = Path ( title = "The ID of the item to get" ), q : Union [ str , Non...e ] = Query ( default = None , alias = "item-query" ), ): results = { "item_id" : item_id } if q : results . update ({ "q" : q }) return results ? Other versions and v...0+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : Annotated [ int , Path ( title = "The ID of the item to get" )], q : Anno... - https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/
- 追加のステータスコード 9372
- 追加のステータスコード デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。その JSONResponse の中には、 path operation が返した内容が入ります。 それは、デフォルトのステータスコードか、 path operation でセットしたものを利用
...のステータスコードを返したい場合は、 Response ( JSONResponse など) に追加のステータスコードを設定して直接返します。 例えば、itemを更新し、成功した場合は200 "OK"のHTTPステータスコードを返す path operation を作りたいとします。 しかし、新しいitemも許可した...いです。itemが存在しない場合は、それらを作成して201 "Created"を返します。 これを達成するには、 JSONResponse をインポートし、 status_code...yping import Union from fastapi import Body , FastAPI , status from fastapi.responses import JSONResponse app = FastAPI () items = { "foo" : { "name" : "Fighters" , "size" : 6 }, "bar" : { "name" : "Tenders" , "size" : 3 }} @app . put ( "/items/ {ite... - https://man.mtool.work/fastapi/0.115/advanced/additional-status-codes/
- リクエストボディ 9372
- リクエストボディ クライアント (ブラウザなど) からAPIにデータを送信する必要があるとき、データを リクエストボディ (request body) として送ります。 リクエスト ボディはクライアントによってAPIへ送られます。 レスポンス ボディはAPIがクライアントに送
...トする必要があります: Python 3.8+ from typing import Union from fastapi import FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None app...= FastAPI () @app . post ( "/items/" ) async def create_item ( item : Item ): return item ? Other versions and variants Python 3.10+ from fastapi import Fas...tAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None app = FastAPI () @app .... - https://man.mtool.work/fastapi/0.115/tutorial/body/