コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 33 for model (0.006 sec.)
パスパラメータ 11871
パスパラメータ Pythonのformat文字列と同様のシンタックスで「パスパラメータ」や「パス変数」を宣言できます: Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_item ( item_id ): return { ... 属性を作ります。すると、その値が使用可能な値となります: Python 3.8+ from enum import Enum from fastapi import FastAPI class ModelName ( str , Enum ): alexnet = "alexnet" resnet = "resnet" lenet = "lenet" app = FastAPI () @app . get ( "/models/ {model_n ... ame} " ) async def get_model ( model_name : ModelName ): if model_name is ModelName . alexnet : return { "model_name" : model_name , "message" : "Deep ... Learning FTW!" } if model_name . value == "lenet" : return { "model_name" : model_name , "message" : "LeCNN all the images" } return { "model_name" ...
https://man.mtool.work/fastapi/0.115/tutorial/path-params/
レスポンスモデル 11358
レスポンスモデル path operations のいずれにおいても、 response_model パラメータを使用して、レスポンスのモデルを宣言することができます: @app.get() @app.post() @app.put() @app.delete() など。 Python 3.8+ from typing import Any , List , 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 [ str ] = [] @app . post ( "/items/" , response_model = Item ) async def create_item ( item : Item ) -> Any : return item @app . get ( "/items/" , response_model = List [ Item ... versions and variants Python 3.10+ Python 3.9+ from typing import Any from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str description : str | None = None price : float tax : float | None = N ...
https://man.mtool.work/fastapi/0.115/tutorial/response-model/
ボディ - 更新 11069
ボディ - 更新 PUT による置換での更新 項目を更新するには HTTPの PUT 操作を使用することができます。 jsonable_encoder を用いて、入力データをJSON形式で保存できるデータに変換することができます(例:NoSQLデータベース)。例えば、 datetime を str に ... ing import List , Union from 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 pr ... 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 ( "/items/ {item_id} " , response_mode ... ython 3.10+ Python 3.9+ from fastapi import FastAPI from fastapi.encoders import jsonable_encoder from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str | None = None description : str | None = None price : float | None = ...
https://man.mtool.work/fastapi/0.115/tutorial/body-updates/
SQL (Relational) Databases 11069
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 ... base that you want. Here we'll see an example using SQLModel . SQLModel is built on top of SQLAlchemy and Pydantic. It was made by the same author of FastAPI to be the perfect match f ... SQL or NoSQL database library you want (in some cases called "ORMs" ), FastAPI doesn't force you to use anything. ? As SQLModel is based on SQLAlchemy, you can easily use any database supported by SQLAlchemy (which makes them also supported by SQLMod ... le and short tutorial, if you want to learn about databases in general, about SQL, or more advanced features, go to the SQLModel docs . Install SQLModel First, make sure you create your virtual environment , activate it, and then install sqlmodel : $ ...
https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
Additional Responses in OpenAPI 10299
Additional Responses in OpenAPI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Warning This is a rather advanced topic. If you are starting with FastAPI , you mig ... to make sure you return a Response like JSONResponse directly, with your status code and content. Additional Response with model You can pass to your path operation decorators a parameter responses . It receives a dict : the keys are status codes for ... 200 ), and the values are other dict s with the information for each of them. Each of those response dict s can have a key model , containing a Pydantic model, just like response_model . FastAPI will take that model, generate its JSON Schema and inclu ... de it in the correct place in OpenAPI. For example, to declare another response with a status code 404 and a Pydantic model Message , you can write: Python 3.8+ from fastapi import FastAPI from fastapi.responses import JSONResponse from pydantic ...
https://man.mtool.work/fastapi/0.115/advanced/additional-responses/
Lifespan Events 10299
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 ... and/or that you need to clean up afterwards. For example, a database connection pool, or loading a shared machine learning model. Use Case Let's start with an example use case and then see how to solve it with this. Let's imagine that you have some ma ... chine learning models that you want to use to handle requests. ? The same models are shared among requests, so, it's not one model per request, ... or one per user or something similar. Let's imagine that loading the model can take quite some time , because it has to read a lot of data from disk . So you don't want to do it for every request. ...
https://man.mtool.work/fastapi/0.115/advanced/events/
Generate Clients 8903
Generate Clients Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . As FastAPI is based on the OpenAPI specification, you get automatic compatibility with many tools, ... end Client Let's start with a simple FastAPI application: Python 3.9+ from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str price : float class ResponseMessage ( BaseModel ): message : str @ap ... p . post ( "/items/" , response_model = ResponseMessage ) async def create_item ( item : Item ): return { "message" : "item received" } @app . get ( "/items/" , ... response_model = list [ Item ]) async def get_items (): return [ { "name" : "Plumbus" , "price" : 3 }, { "name" : "Portal Gun" , "price" ...
https://man.mtool.work/fastapi/0.115/advanced/generate-clients/
Header Parameter Models 8855
Header Parameter Models Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you have a group of related header parameters , you can create a Pydantic model to decla ... re them. This would allow you to re-use the model in multiple places and also to declare validations and metadata for all the parameters at once. ? Note This is supported s ... ince FastAPI version 0.115.0 . ? Header Parameters with a Pydantic Model Declare the header parameters that you need in a Pydantic model , and then declare the parameter as Header : Python 3.10+ ... from typing import Annotated from fastapi import FastAPI , Header from pydantic import BaseModel app = FastAPI () class CommonHeaders ( BaseModel ): host : str save_data : bool if_modified_since : str | None = None trac ...
https://man.mtool.work/fastapi/0.115/tutorial/header-param-models/
Separate OpenAPI Schemas for Input and Output or Not 8679
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 ... act and correct than before. ? In fact, in some cases, it will even have two JSON Schemas in OpenAPI for the same Pydantic model, for input and output, depending on if they have default values . Let's see how that works and how to change it if you nee ... d to do that. Pydantic Models for Input and Output Let's say you have a Pydantic model with default values, like this one: Python 3.10+ from fastapi im ... port FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : str | None = None # Code below omitted ? ? Full file preview Python 3.1 ...
https://man.mtool.work/fastapi/0.115/how-to/separate-openapi-schemas/
Path Operationの設定 8647
Path Operationの設定 path operationデコレータ を設定するためのパラメータがいくつかあります。 注意 これらのパラメータは path operation関数 ではなく、 path operationデコレータ に直接渡されることに注意してください。 レスポンスステータスコード ... することができます: Python 3.8+ 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 ? Other versions and ... variants 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 = N ...
https://man.mtool.work/fastapi/0.115/tutorial/path-operation-configuration/
PREV 1 2 3 4 NEXT