コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 9 of about 9 for size (0.002 sec.)
追加のステータスコード 13517
追加のステータスコード デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。その JSONResponse の中には、 path operation が返した内容が入ります。 それは、デフォルトのステータスコードか、 path operation でセットしたものを利用 ... , FastAPI , status from fastapi.responses import JSONResponse app = FastAPI () items = { "foo" : { "name" : "Fighters" , "size" : 6 }, "bar" : { "name" : "Tenders" , "size" : 3 }} @app . put ( "/items/ {item_id} " ) async def upsert_item ( item_id : ... str , name : Union [ str , None ] = Body ( default = None ), size : Union [ int , None ] = Body ( default = None ), ): if item_id in items : item = items [ item_id ] item [ "name" ] = name ... item [ "size" ] = size return item else : item = { "name" : name , "size" : size } items [ item_id ] = item return JSONResponse ( statu ...
https://man.mtool.work/fastapi/0.115/advanced/additional-status-codes/
Request Files 10191
Request Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define files to be uploaded by the client using File . Info To receive uploaded files, first ... le app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . post ( "/uploadfile/" ) async def create_upload_file ( file : UploadFile ): return { "filename" : ... ed app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . post ( "/uploadfile/" ) async def create_upload_file ( file : UploadFile ): return { "filename" : ... le , UploadFile app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : bytes = File ()): return { "file_size" : len ( file )} @app . post ( "/uploadfile/" ) async def create_upload_file ( file : UploadFile ): return { "filename" : ...
https://man.mtool.work/fastapi/0.115/tutorial/request-files/
パスパラメータと数値の検証 9023
パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず ... ) async def read_items ( * , item_id : int = Path ( title = "The ID of the item to get" , ge = 0 , le = 1000 ), q : str , size : float = Query ( gt = 0 , lt = 10.5 ), ): results = { "item_id" : item_id } if q : results . update ({ "q" : q }) if size ... : results . update ({ "size" : size }) return results ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi ... read_items ( * , item_id : Annotated [ int , Path ( title = "The ID of the item to get" , ge = 0 , le = 1000 )], q : str , size : Annotated [ float , Query ( gt = 0 , lt = 10.5 )], ): results = { "item_id" : item_id } if q : results . update ({ "q" : ...
https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/
リクエストフォームとファイル 9023
リクエストフォームとファイル File と Form を同時に使うことでファイルとフォームフィールドを定義することができます。 情報 アップロードされたファイルやフォームデータを受信するには、まず python-multipart をインストールします。 例えば、 pip inst ... /" ) async def create_file ( file : bytes = File (), fileb : UploadFile = File (), token : str = Form () ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } ? Other versions and variants Python 3. ... tated [ bytes , File ()], fileb : Annotated [ UploadFile , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } from fastapi import FastAPI , File , Fo ... tated [ bytes , File ()], fileb : Annotated [ UploadFile , File ()], token : Annotated [ str , Form ()], ): return { "file_size" : len ( file ), "token" : token , "fileb_content_type" : fileb . content_type , } File と Form のパラメータの定義 ファイル ...
https://man.mtool.work/fastapi/0.115/tutorial/request-forms-and-files/
Advanced Middleware 8160
Advanced Middleware Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In the main tutorial you read how to add Custom Middleware to your application. And then you al ... astAPI from fastapi.middleware.gzip import GZipMiddleware app = FastAPI () app . add_middleware ( GZipMiddleware , minimum_size = 1000 , compresslevel = 5 ) @app . get ( "/" ) async def main (): return "somebigcontent" The following arguments are sup ... ported: minimum_size - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to 500 . compresslevel - Used during GZ ... mpression. It is an integer ranging from 1 to 9. Defaults to 9 . Lower value results in faster compression but larger file sizes, while higher value results in slower compression but smaller file sizes. Other middlewares There are many other ASGI mid ...
https://man.mtool.work/fastapi/0.115/advanced/middleware/
UploadFile class 7855
UploadFile class You can define path operation function parameters to be of the type UploadFile to receive files from the request. You can import it directly from fastapi : from fastapi import UploadFile ::: fastapi.UploadFile options: memb ... ers: - file - filename - size - headers - content_type - read - write - seek - close ...
https://man.mtool.work/fastapi/0.115/reference/uploadfile/
モデル - より詳しく 7819
モデル - より詳しく 先ほどの例に続き、複数の関連モデルを持つことが一般的です。 これはユーザーモデルの場合は特にそうです。なぜなら: 入力モデル にはパスワードが必要です。 出力モデル はパスワードをもつべきではありません。 データベースモデル は ... ription : str type : str class CarItem ( BaseItem ): type : str = "car" class PlaneItem ( BaseItem ): type : str = "plane" size : int items = { "item1" : { "description" : "All my friends drive a low rider" , "type" : "car" }, "item2" : { "descriptio ... n" : "Music is my aeroplane, it's my aeroplane" , "type" : "plane" , "size" : 5 , }, } @app . get ( "/items/ {item_id} " , response_model = Union [ PlaneItem , CarItem ]) async def read_item ( item ... ription : str type : str class CarItem ( BaseItem ): type : str = "car" class PlaneItem ( BaseItem ): type : str = "plane" size : int items = { "item1" : { "description" : "All my friends drive a low rider" , "type" : "car" }, "item2" : { "descriptio ...
https://man.mtool.work/fastapi/0.115/tutorial/extra-models/
エラーハンドリング 7729
エラーハンドリング APIを使用しているクライアントにエラーを通知する必要がある状況はたくさんあります。 このクライアントは、フロントエンドを持つブラウザ、誰かのコード、IoTデバイスなどが考えられます。 クライアントに以下のようなことを伝える必要が ... content = jsonable_encoder ({ "detail" : exc . errors (), "body" : exc . body }), ) class Item ( BaseModel ): title : str size : int @app . post ( "/items/" ) async def create_item ( item : Item ): return item ここで、以下のような無効な項目を送信して ... みてください: { "title" : "towel" , "size" : "XL" } 受信したボディを含むデータが無効であることを示すレスポンスが表示されます: { "detail" : [ { "loc" : [ "body" , "s ... ize" ], "msg" : "value is not a valid integer" , "type" : "type_error.integer" } ], "body" : { "title" : "towel" , "size" : "XL" } } FastAPIの HTTPException とStarletteの HTTPException FastAPI は独自の HTTPException を持っています。 また、 Fas ...
https://man.mtool.work/fastapi/0.115/tutorial/handling-errors/
Custom Response Classes - File, HTML, Redirect, Streaming, etc. 7513
Custom Response Classes - File, HTML, Redirect, Streaming, etc. There are several custom response classes you can use to create an instance and return them directly from your path operations . Read more about it in the FastAPI docs for Cust ... rs - headers - set_cookie - delete_cookie Starlette Responses ::: fastapi.responses.FileResponse options: members: - chunk_size - charset - status_code - media_type - body - background - raw_headers - render - init_headers - headers - set_cookie - de ...
https://man.mtool.work/fastapi/0.115/reference/responses/
PREV 1 NEXT