Results of 1 - 10 of about 38 for List (0.008 sec.)
- SQL (Relational) Databases 11541
- 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
..." ) def read_heroes ( session : SessionDep , offset : int = 0 , limit : Annotated [ int , Query ( le = 100 )] = 100 , ) -> list [ Hero ]: heroes = session . exec ( select ( Hero ) . offset ( offset ) . limit ( limit )) . all () return heroes @app . g..." ) def read_heroes ( session : SessionDep , offset : int = 0 , limit : Annotated [ int , Query ( le = 100 )] = 100 , ) -> list [ Hero ]: heroes = session . exec ( select ( Hero ) . offset ( offset ) . limit ( limit )) . all () return heroes @app . g...404 , detail = "Hero not found" ) session . delete ( hero ) session . commit () return { "ok" : True } from typing import List , Union from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLModel , cr... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- ボディ - ネストされたモデル 11446
- ボディ - ネストされたモデル FastAPI を使用すると、深くネストされた任意のモデルを定義、検証、文書化、使用することができます(Pydanticのおかげです)。 リストのフィールド 属性をサブタイプとして定義することができます。例えば、Pythonの list は以
...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" : it...API () 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 , item : Item ): results = { "item_id" : it...ラメータを持つリストのフィールド しかし、Pythonには型や「タイプパラメータ」を使ってリストを宣言する方法があります: typingの List をインポート まず、Pythonの標準の typing モジュールから List をインポートします: Python 3.8+ from typing import List , Uni... - https://man.mtool.work/fastapi/0.115/tutorial/body-nested-models/
- Header Parameter Models 10660
- 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
...s ( BaseModel ): host : str save_data : bool if_modified_since : str | None = None traceparent : str | None = None x_tag : list [ str ] = [] @app . get ( "/items/" ) async def read_items ( headers : Annotated [ CommonHeaders , Header ()]): return hea...t : str save_data : bool if_modified_since : Union [ str , None ] = None traceparent : Union [ str , None ] = None x_tag : list [ str ] = [] @app . get ( "/items/" ) async def read_items ( headers : Annotated [ CommonHeaders , Header ()]): return hea...ders from typing import List , Union from fastapi import FastAPI , Header from pydantic import BaseModel from typing_extensions import Annotated app =... - https://man.mtool.work/fastapi/0.115/tutorial/header-param-models/
- Using Dataclasses 10409
- 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
...use dataclasses in the response_model parameter: Python 3.8+ from dataclasses import 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 , None ] = None app = FastAPI () @app . get ( "/items/next...pydantic.dataclasses , which is a drop-in replacement: Python 3.8+ from dataclasses import field # (1) from typing import List , Union from fastapi import FastAPI from pydantic.dataclasses import dataclass # (2) @dataclass class Item : name : str de... - https://man.mtool.work/fastapi/0.115/advanced/dataclasses/
- Separate OpenAPI Schemas for Input and Output or Not 10047
- 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
...PI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: return [ Item ( name = "Portal Gun" , description = "Device to travel through the multi-rick-verse" , ), Item (...PI () @app . post ( "/items/" ) def create_item ( item : Item ): return item @app . get ( "/items/" ) def read_items () -> list [ Item ]: return [ Item ( name = "Portal Gun" , description = "Device to travel through the multi-rick-verse" , ), Item (...name = "Plumbus" ), ] from typing import List , Union from fastapi import FastAPI from pydantic import BaseModel class Item ( BaseModel ): name : str description : Unio... - https://man.mtool.work/fastapi/0.115/how-to/separate-openapi-schemas/
- クエリパラメータモデル 9968
- クエリパラメータモデル もし関連する 複数のクエリパラメータ から成るグループがあるなら、それらを宣言するために、 Pydanticモデル を作成できます。 こうすることで、 複数の場所 で そのPydanticモデルを再利用 でき、バリデーションやメタデータを、す
..., le = 100 ) offset : int = Field ( 0 , ge = 0 ) order_by : Literal [ "created_at" , "updated_at" ] = "created_at" tags : list [ str ] = [] @app . get ( "/items/" ) async def read_items ( filter_query : Annotated [ FilterParams , Query ()]): return..., le = 100 ) offset : int = Field ( 0 , ge = 0 ) order_by : Literal [ "created_at" , "updated_at" ] = "created_at" tags : list [ str ] = [] @app . 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 Annotated , Liter... - https://man.mtool.work/fastapi/0.115/tutorial/query-param-models/
- Request Files 9827
- 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
...l files at the same time. They would be associated to the same "form field" sent using "form data". To use that, declare a list of bytes or UploadFile : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile from fas...tapi.responses import HTMLResponse app = FastAPI () @app . post ( "/files/" ) async def create_files ( files : Annotated [ list [ bytes ], File ()]): return { "file_sizes" : [ len ( file ) for file in files ]} @app . post ( "/uploadfiles/" ) async de...f create_upload_files ( files : list [ UploadFile ]): return { "filenames" : [ file . filename for file in files ]} @app . get ( "/" ) async def main (): conte... - https://man.mtool.work/fastapi/0.115/tutorial/request-files/
- Pythonの型の紹介 9355
- Pythonの型の紹介 Python 3.6以降 では「型ヒント」オプションがサポートされています。 これらの "型ヒント" は変数の 型 を宣言することができる新しい構文です。(Python 3.6以降) 変数に型を宣言することでエディターやツールがより良いサポートを提供す
...: return item_a , item_b , item_c , item_d , item_d , item_e 型パラメータを持つジェネリック型 データ構造の中には、 dict 、 list 、 set 、そして tuple のように他の値を含むことができるものがあります。また内部の値も独自の型を持つことができます。 これらの...の型を宣言するには、Pythonの標準モジュール typing を使用します。 これらの型ヒントをサポートするために特別に存在しています。 List 例えば、 str の list の変数を定義してみましょう。 typing から List をインポートします(大文字の L を含む): Python 3.8+ fr...om typing import List def process_items ( items : List [ str ]): for item in items : print ( item ) ? Other versions and variants Python 3.9+ de... - https://man.mtool.work/fastapi/0.115/python-types/
- クエリパラメータと文字列の検証 9308
- クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g
...URL内に複数回出現するクエリパラメータ q を宣言するには以下のように書きます: Python 3.8+ - non-Annotated from typing import List , Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Union [ L...tated from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Annotated [ list [ str ] | None , Query ()] = None ): query_items = { "q" : q } return query_items from typing import Annotated , Union fro...m fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Annotated [ Union [ list [ str ], None ], Query ()] = None ): query_items = { "q" : q } return query_items from typing import List , Union from fas... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- レスポンスモデル 9182
- レスポンスモデル path operations のいずれにおいても、 response_model パラメータを使用して、レスポンスのモデルを宣言することができます: @app.get() @app.post() @app.put() @app.delete() など。 Python 3.8+ from typing import Any , List , Union
...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 ]) async def read_items () -> Any : return [ { "name" : "Portal Gun" , "price" : 42.0 }, { "name" : "Plumbus" , "pr...API () 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 ( item : Item ) -> Any : return item... - https://man.mtool.work/fastapi/0.115/tutorial/response-model/