Results of 1 - 10 of about 41 for annotated (0.011 sec.)
- クエリパラメータと文字列の検証 10024
- クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g
...いこと を強制してみましょう。 Query のインポート そのために、まずは fastapi から Query をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_item...: results . update ({ "q" : q }) return results ? Other versions and variants Python 3.10+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_...items ( q : Annotated [ str | None , Query ( max_length = 50 )] = None ): results = { "items" : [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]}... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- SQL (Relational) Databases 9636
- 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
...y with multiple models below. ? Create Models Import SQLModel and create a database model: Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLModel , create_eng...fault = None , index = True ) secret_name : str # Code below omitted ? ? Full file preview Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , Query from sqlmodel import Field , Session , SQLModel , create_eng...del . metadata . create_all ( engine ) def get_session (): with Session ( engine ) as session : yield session SessionDep = Annotated [ Session , Depends ( get_session )] app = FastAPI () @app . on_event ( "startup" ) def on_startup (): create_db_and_table... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- 現在のユーザーの取得 9403
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...ds ( oauth2_scheme )): return { "token" : token } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer app = FastAPI () oauth2_scheme = O...Auth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): return { "token" : token } from fastapi import Depends , FastAPI from fastapi.securit...y import OAuth2PasswordBearer from typing_extensions import Annotated app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- 依存関係としてのクラス 9372
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の dict 前の例では、依存関係("dependable")から dict を返していました: Python 3.8+ - non-Annotated from typing import Union fr
...common_parameters )): return commons ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : str...nt = 100 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return commons @app . get ( "/users/" ) async def read_users ( commons : Annotat...ed [ 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 ] = No... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- サブ依存関係 9341
- サブ依存関係 サブ依存関係 を持つ依存関係を作成することができます。 それらは必要なだけ 深く することができます。 FastAPI はそれらを解決してくれます。 最初の依存関係「依存可能なもの」 以下のような最初の依存関係(「依存可能なもの」)を作成する
...ことができます: Python 3.8+ - non-Annotated from typing import Union from fastapi import Cookie , Depends , FastAPI app = FastAPI () def query_extractor ( q : Union [...{ "q_or_cookie" : query_or_default } ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import Cookie , Depends , FastAPI app = FastAPI () def query_extractor ( q : str...| None = None ): return q def query_or_cookie_extractor ( q : Annotated [ str , Depends ( query_extractor )], last_query : Annotated [ str | None , Cookie ()] = None , ): if not q : return last_... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/sub-dependencies/
- パスパラメータと数値の検証 9341
- パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず
...初めに、 fastapi から Path をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) a...update ({ "q" : q }) return results ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} "...) async def read_items ( item_id : Annotated [ int , Path ( title = "The ID of the item to get" )], q : Annotated [ str | None , Query ( alias = "item-query" )] = None... - https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/
- Request Files 9341
- 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
...loaded files are sent as "form data". Import File Import File and UploadFile from fastapi : Python 3.9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile app = FastAPI () @app . post ( "/files/" ) async def create_file ( file :...( file : UploadFile ): return { "filename" : file . filename } ? Other versions and variants Python 3.8+ Python 3.8+ - non-Annotated from fastapi import FastAPI , File , UploadFile from typing_extensions import Annotated app = FastAPI () @app . post ( "/f...iles/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . post ( "/uploadfile/" ) async def create_upload_file ( fi... - https://man.mtool.work/fastapi/0.115/tutorial/request-files/
- ヘッダーのパラメータ 9263
- ヘッダーのパラメータ ヘッダーのパラメータは、 Query や Path 、 Cookie のパラメータを定義するのと同じように定義できます。 Header をインポート まず、 Header をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi
...return { "User-Agent" : user_agent } ? Other versions and variants Python 3.10+ Python 3.9+ Python 3.8+ Python 3.10+ - non-Annotated from typing import Annotated from fastapi import FastAPI , Header app = FastAPI () @app . get ( "/items/" ) async def read..._items ( user_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 : Annotated [ Union [ str , None ], Header ()] = None ): return { "User-Agent" : user_agent } from typing import Union from fastapi im... - https://man.mtool.work/fastapi/0.115/tutorial/header-params/
- Simple OAuth2 with Password and Bearer 9263
- Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have
...rdRequestForm , and use it as a dependency with Depends in the path operation for /token : Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , status from fastapi.security import OAuth2PasswordBearer , OAuth2P...at all # Check the next version user = get_user ( fake_users_db , token ) return user async def get_current_user ( token : Annotated [ str , Depends ( oauth2_scheme )]): user = fake_decode_token ( token ) if not user : raise HTTPException ( status_code =...edentials" , headers = { "WWW-Authenticate" : "Bearer" }, ) return user async def get_current_active_user ( current_user : Annotated [ User , Depends ( get_current_user )], ): if current_user . disabled : raise HTTPException ( status_code = 400 , detail =... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
- OAuth2 scopes 9201
- 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
...JWT tokens . Now using OAuth2 scopes: Python 3.10+ from datetime import datetime , timedelta , timezone from typing import Annotated import jwt from fastapi import Depends , FastAPI , HTTPException , Security , status from fastapi.security import ( OAuth2...T_KEY , algorithm = ALGORITHM ) return encoded_jwt async def get_current_user ( security_scopes : SecurityScopes , token : Annotated [ str , Depends ( oauth2_scheme )] ): if security_scopes . scopes : authenticate_value = f 'Bearer scope=" { security_scop..., headers = { "WWW-Authenticate" : authenticate_value }, ) return user async def get_current_active_user ( current_user : Annotated [ User , Security ( get_current_user , scopes = [ "me" ])], ): if current_user . disabled : raise HTTPException ( status_c... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/