Results of 1 - 10 of about 21 for float (0.004 sec.)
- ボディ - ネストされたモデル 11653
- ボディ - ネストされたモデル FastAPI を使用すると、深くネストされた任意のモデルを定義、検証、文書化、使用することができます(Pydanticのおかげです)。 リストのフィールド 属性をサブタイプとして定義することができます。例えば、Pythonの list は以
...c 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 :...om pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None tags : list = [] @app . put ( "/items/ {item_id} " ) async def update_item ( item_id : int , ite...c import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : List [ str ] = [] @app . put ( "/items/ {item_id} " ) async def update_item ( i... - https://man.mtool.work/fastapi/0.115/tutorial/body-nested-models/
- ボディ - 複数のパラメータ 11298
- ボディ - 複数のパラメータ これまで Path と Query をどう使うかを見てきましたが、リクエストボディの宣言のより高度な使い方を見てみましょう。 Path 、 Query とボディパラメータを混ぜる まず、もちろん、 Path と Query とリクエストボディのパラメータ
...c 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 (...om pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None @app . put ( "/items/ {item_id} " ) async def update_item ( item_id : Annotated [ int , Path ( t...c 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 : Annotated [ int... - https://man.mtool.work/fastapi/0.115/tutorial/body-multiple-params/
- Path Operationの設定 11095
- Path Operationの設定 path operationデコレータ を設定するためのパラメータがいくつかあります。 注意 これらのパラメータは path operation関数 ではなく、 path operationデコレータ に直接渡されることに注意してください。 レスポンスステータスコード
...c 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_c...om pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None tags : set [ str ] = set () @app . post ( "/items/" , response_model = Item , status_code = stat...c 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_c... - https://man.mtool.work/fastapi/0.115/tutorial/path-operation-configuration/
- リクエストボディ 10469
- リクエストボディ クライアント (ブラウザなど) からAPIにデータを送信する必要があるとき、データを リクエストボディ (request body) として送ります。 リクエスト ボディはクライアントによってAPIへ送られます。 レスポンス ボディはAPIがクライアントに送
...tAPI 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 ): retu...import FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None app = FastAPI () @app . post ( "/items/" ) async def create_item ( item : Item ): return item デ...tAPI 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 ): retu... - https://man.mtool.work/fastapi/0.115/tutorial/body/
- ボディ - フィールド 10215
- ボディ - フィールド Query や Path 、 Body を使って path operation関数 のパラメータに追加のバリデーションやメタデータを宣言するのと同じように、Pydanticの Field を使ってPydanticモデルの内部でバリデーションやメタデータを宣言することができます。
...ption : Union [ str , None ] = Field ( default = None , title = "The description of the item" , max_length = 300 ) price : float = Field ( gt = 0 , description = "The price must be greater than zero" ) tax : Union [ float , None ] = None @app . put (...str description : str | None = Field ( default = None , title = "The description of the item" , max_length = 300 ) price : float = Field ( gt = 0 , description = "The price must be greater than zero" ) tax : float | None = None @app . put ( "/items/ {...ption : Union [ str , None ] = Field ( default = None , title = "The description of the item" , max_length = 300 ) price : float = Field ( gt = 0 , description = "The price must be greater than zero" ) tax : Union [ float , None ] = None @app . put (... - https://man.mtool.work/fastapi/0.115/tutorial/body-fields/
- スキーマの追加 - 例 10012
- スキーマの追加 - 例 JSON Schemaに追加する情報を定義することができます。 一般的なユースケースはこのドキュメントで示されているように example を追加することです。 JSON Schemaの追加情報を宣言する方法はいくつかあります。 Pydanticの schema_extra
...c import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None model_config = { "json_schema_extra" : { "examples" : [ { "name" : "Foo" , "descriptio...om pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None model_config = { "json_schema_extra" : { "examples" : [ { "name" : "Foo" , "description" : "A ve...ples = [ "Foo" ]) description : Union [ str , None ] = Field ( default = None , examples = [ "A very nice Item" ]) price : float = Field ( examples = [ 35.4 ]) tax : Union [ float , None ] = Field ( default = None , examples = [ 3.2 ]) @app . put ( "/... - https://man.mtool.work/fastapi/0.115/tutorial/schema-extra-example/
- レスポンスモデル 9742
- レスポンスモデル path operations のいずれにおいても、 response_model パラメータを使用して、レスポンスのモデルを宣言することができます: @app.get() @app.post() @app.put() @app.delete() など。 Python 3.8+ from typing import Any , List , Union
...c import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : List [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def c...om pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = None tags : list [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def create_item...c import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : list [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def c... - https://man.mtool.work/fastapi/0.115/tutorial/response-model/
- ボディ - 更新 9488
- ボディ - 更新 PUT による置換での更新 項目を更新するには HTTPの PUT 操作を使用することができます。 jsonable_encoder を用いて、入力データをJSON形式で保存できるデータに変換することができます(例:NoSQLデータベース)。例えば、 datetime を str に
...() 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" :...port BaseModel app = FastAPI () class Item ( BaseModel ): name : str | None = None description : str | None = None price : float | None = None tax : float = 10.5 tags : list [ str ] = [] items = { "foo" : { "name" : "Foo" , "price" : 50.2 }, "bar" : {...() 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" :... - https://man.mtool.work/fastapi/0.115/tutorial/body-updates/
- Lifespan Events 8067
- Lifespan Events Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define logic (code) that should be executed before the application starts up . This means t
...n 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everything_ml_model ( x : float ): return x * 42 ml_models = {} @asynccontextmanager async def lifespan ( app : FastAPI ): # Load the ML model ml_models [...the resources ml_models . clear () app = FastAPI ( lifespan = lifespan ) @app . get ( "/predict" ) async def predict ( x : float ): result = ml_models [ "answer_to_everything" ]( x ) return { "result" : result } Here we are simulating the expensive st...n 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everything_ml_model ( x : float ): return x * 42 ml_models = {} @asynccontextmanager async def lifespan ( app : FastAPI ): # Load the ML model ml_models [... - https://man.mtool.work/fastapi/0.115/advanced/events/
- Using Dataclasses 7577
- Using Dataclasses Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI is built on top of Pydantic , and I have been showing you how to use Pydantic models to d
...taclasses import dataclass from typing import Union from fastapi import FastAPI @dataclass class Item : name : str price : float description : Union [ str , None ] = None tax : Union [ float , None ] = None app = FastAPI () @app . post ( "/items/" ) a...t dataclass , field from typing import List , Union from fastapi import FastAPI @dataclass class Item : name : str price : float tags : List [ str ] = field ( default_factory = list ) description : Union [ str , None ] = None tax : Union [ float , Non... - https://man.mtool.work/fastapi/0.115/advanced/dataclasses/