Results of 1 - 10 of about 41 for Union (0.012 sec.)
- SQL (Relational) Databases 10258
- 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
...n 3.8+ Python 3.10+ - non-Annotated Python 3.9+ - non-Annotated Python 3.8+ - non-Annotated from typing import Annotated , Union from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLModel , create_eng...ine , select class Hero ( SQLModel , table = True ): id : Union [ int , None ] = Field ( default = None , primary_key = True ) name : str = Field ( index = True ) age : Union [ int , Non...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 , create_eng... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- ボディ - ネストされたモデル 10180
- ボディ - ネストされたモデル 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 descripti...on : Union [ str , None ] = None price : float tax : Union [ float , None ] = None tags : list = [] @app . put ( "/items/ {item_id} "...ist をインポート まず、Pythonの標準の typing モジュールから List をインポートします: Python 3.8+ from typing import List , Union from fastapi import FastAPI from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str descripti... - https://man.mtool.work/fastapi/0.115/tutorial/body-nested-models/
- ボディ - 複数のパラメータ 10087
- ボディ - 複数のパラメータ これまで Path と Query をどう使うかを見てきましたが、リクエストボディの宣言のより高度な使い方を見てみましょう。 Path 、 Query とボディパラメータを混ぜる まず、もちろん、 Path と Query とリクエストボディのパラメータ
...を設定することで、ボディパラメータをオプションとして宣言することもできます: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str de...scription : Union [ str , None ] = None price : float tax : Union [ float , None ] = None @app . put ( "/items/ {item_id} " ) async def upda...te_item ( * , item_id : int = Path ( title = "The ID of the item to get" , ge = 0 , le = 1000 ), q : Union [ str , None ] = None , item : Union [ Item , None ] = None , ): results = { "item_id" : item_id } if q : results . update... - https://man.mtool.work/fastapi/0.115/tutorial/body-multiple-params/
- 現在のユーザーの取得 9978
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...を使用するのと同じやり方で、Pydanticを別のどんなところでも使うことができます: Python 3.8+ - non-Annotated from typing import Union from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer from pydantic import BaseModel app...= FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) class User ( BaseModel ): username : str email : Union [ str , None ] = None full_name : Union [ str , None ] = None disabled : Union [ bool , None ] = None def fake_decode_toke..._me ( current_user : Annotated [ User , Depends ( get_current_user )]): return current_user from typing import Annotated , Union from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer from pydantic import BaseModel app... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- クエリパラメータと文字列の検証 9714
- クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g
...et ( "/items/" ) async def read_items ( q : Union [ str , None ] = None ): results = { "items" : [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]} if q : results . update ({...uery のインポート そのために、まずは fastapi から Query をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Union [ str , Non...: [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]} if q : results . update ({ "q" : q }) return results from typing import Union from fastapi import FastAPI , Query from typing_extensions import Annotated app = FastAPI () @app . get ( "/items/" ) asyn... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- OAuth2 scopes 9683
- OAuth2 scopes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use OAuth2 scopes directly with FastAPI , they are integrated to work seamlessly. This would
...-Annotated Python 3.8+ - non-Annotated from datetime import datetime , timedelta , timezone from typing import Annotated , Union import jwt from fastapi import Depends , FastAPI , HTTPException , Security , status from fastapi.security import ( OAuth2...ed" : True , }, } class Token ( BaseModel ): access_token : str token_type : str class TokenData ( BaseModel ): username : Union [ str , None ] = None scopes : list [ str ] = [] class User ( BaseModel ): username : str email : Union [ str , None ] = N...one full_name : Union [ str , None ] = None disabled : Union [ bool , None ] = None class UserInDB ( User ): hashed_password : str pwd_context =... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
- Header Parameter Models 9651
- 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
...n 3.8+ Python 3.10+ - non-Annotated Python 3.9+ - non-Annotated Python 3.8+ - non-Annotated from typing import Annotated , Union from fastapi import FastAPI , Header from pydantic import BaseModel app = FastAPI () class CommonHeaders ( BaseModel ): ho...st : str save_data : bool if_modified_since : Union [ str , None ] = None traceparent : Union [ str , None ] = None x_tag : list [ str ] = [] @app . get ( "/items/" ) async d...ef read_items ( headers : Annotated [ CommonHeaders , Header ()]): return headers from typing import List , Union from fastapi import FastAPI , Header from pydantic import BaseModel from typing_extensions import Annotated app = FastAPI... - https://man.mtool.work/fastapi/0.115/tutorial/header-param-models/
- Path Operationの設定 9543
- Path Operationの設定 path operationデコレータ を設定するためのパラメータがいくつかあります。 注意 これらのパラメータは path operation関数 ではなく、 path operationデコレータ に直接渡されることに注意してください。 レスポンスステータスコード
...のためのものか覚えていない場合は、 status のショートカット定数を使用することができます: 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/...l = Item , status_code = status . HTTP_201_CREATED ) async def create_item ( item : Item ): return item from typing import Union from fastapi import FastAPI , status from pydantic import BaseModel app = FastAPI () class Item ( BaseModel ): name : str... - https://man.mtool.work/fastapi/0.115/tutorial/path-operation-configuration/
- ヘッダーのパラメータ 9512
- ヘッダーのパラメータ ヘッダーのパラメータは、 Query や Path 、 Cookie のパラメータを定義するのと同じように定義できます。 Header をインポート まず、 Header をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi
...import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Union [ str , None ] = Header ( default = None )): return { "User-Agent" : user_agent } ? Other versions and variants Python 3.1..._agent : Annotated [ str | None , Header ()] = None ): return { "User-Agent" : user_agent } from typing import Annotated , Union from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read_items ( user_agent : Annotat...ed [ Union [ str , None ], Header ()] = None ): return { "User-Agent" : user_agent } from typing import Union from fastapi import Fas... - https://man.mtool.work/fastapi/0.115/tutorial/header-params/
- 依存関係としてのクラス 9247
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr
...om fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : Union [ str , None ] = None , skip : int = 0 , limit : int = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app ....f read_users ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons from typing import Annotated , Union from fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : Union [ str , None ] = None , ski..." ) async def read_users ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons from typing import Union from fastapi import Depends , FastAPI from typing_extensions import Annotated app = FastAPI () async def common_parameters... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...