Results of 1 - 10 of about 23 for Depends (0.012 sec.)
- SQL (Relational) Databases 10791
- 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
...? 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_engine , select class Hero ( SQ...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_engine , select class Hero ( SQ...e_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_tables () @app . post ( "... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- 依存関係としてのクラス 10338
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の 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 =...0 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async def read_users ( commons : dict = Depends ( common_p...ariants 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 | None = None , skip : int = 0 , limit : int = 100 ): ret... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- 現在のユーザーの取得 10338
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : str = Depends ( oauth2_scheme )): return { "token" : token } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import An...notated from fastapi import Depends , FastAPI from fastapi.security import OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenU...rl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): return { "token" : token } from fastapi import Depends , FastAPI from fastapi.security import OAuth2P... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- Simple OAuth2 with Password and Bearer 10204
- 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
...astAPI to handle this. OAuth2PasswordRequestForm First, import OAuth2PasswordRequestForm , 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 , HTTPE...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 = status . HTTP_40...s = { "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 = "Inactive user"... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
- OAuth2 scopes 9819
- 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
...hon 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 ( OAuth2PasswordBearer , OAuth2PasswordRequestF...= 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_scopes . scope_str }...rrent_user @app . post ( "/token" ) async def login_for_access_token ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()], ) -> Token : user = authenticate_user ( fake_users_db , form_data . username , form_data . password ) if not user : r... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
- サブ依存関係 9819
- サブ依存関係 サブ依存関係 を持つ依存関係を作成することができます。 それらは必要なだけ 深く することができます。 FastAPI はそれらを解決してくれます。 最初の依存関係「依存可能なもの」 以下のような最初の依存関係(「依存可能なもの」)を作成する
...ことができます: Python 3.8+ - non-Annotated from typing import Union from fastapi import Cookie , Depends , FastAPI app = FastAPI () def query_extractor ( q : Union [ str , None ] = None ): return q def query_or_cookie_extractor...( q : str = Depends ( query_extractor ), last_query : Union [ str , None ] = Cookie ( default = None ), ): if not q : return last_query return...q @app . get ( "/items/" ) async def read_query ( query_or_default : str = Depends ( query_or_cookie_extractor )): return { "q_or_cookie" : query_or_default } ? Other versions and variants Python 3.10+ Pyt... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/sub-dependencies/
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 9819
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ
...non-Annotated from datetime import datetime , timedelta , timezone from typing import Union import jwt from fastapi import Depends , FastAPI , HTTPException , status from fastapi.security import OAuth2PasswordBearer , OAuth2PasswordRequestForm from jwt..... encode ( to_encode , SECRET_KEY , algorithm = ALGORITHM ) return encoded_jwt async def get_current_user ( token : str = Depends ( oauth2_scheme )): credentials_exception = HTTPException ( status_code = status . HTTP_401_UNAUTHORIZED , detail = "Could...name ) if user is None : raise credentials_exception return user async def get_current_active_user ( current_user : User = Depends ( get_current_user )): if current_user . disabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) r... - https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
- 依存関係 - 最初のステップ 9735
- 依存関係 - 最初のステップ ** FastAPI** は非常に強力でありながら直感的な 依存性注入 システムを持っています。 それは非常にシンプルに使用できるように設計されており、開発者が他のコンポーネント FastAPI と統合するのが非常に簡単になるように設計され
...じパラメータを全て取ることができる関数にすぎません: Python 3.8+ - non-Annotated from typing import Union from fastapi import Depends , FastAPI app = FastAPI () async def common_parameters ( q : Union [ str , None ] = None , skip : int = 0 , limit : int =...0 ): return { "q" : q , "skip" : skip , "limit" : limit } @app . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async def read_users ( commons : dict = Depends ( common_p...ariants 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 | None = None , skip : int = 0 , limit : int = 100 ): ret... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/
- path operationデコレータの依存関係 9668
- path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、
...path operation関数 のパラメータを Depends で宣言する代わりに、 path operation decorator に dependencies の list を追加することができます。 path operationデコレータ...への dependencies の追加 path operationデコレータ はオプショナルの引数 dependencies を受け取ります。 それは Depends() の list であるべきです: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI , Header , HTTPException app =...TPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) async def read_items (): return [{ "item" : "Foo" }, { "item" : "Bar" }] ? Othe... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
- Advanced Dependencies 9383
- Advanced Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Parameterized dependencies All the dependencies we have seen are a fixed function or class. B
...nce of that class. To do that, we declare a method __call__ : Python 3.9+ from typing import Annotated from fastapi import Depends , FastAPI app = FastAPI () class FixedContentQueryChecker : def __init__ ( self , fixed_content : str ): self . fixed_cont...hecker ( "bar" ) @app . get ( "/query-checker/" ) async def read_query_check ( fixed_content_included : Annotated [ bool , Depends ( checker )]): return { "fixed_content_in_query" : fixed_content_included } ? Other versions and variants Python 3.8+ Pyth...on 3.8+ - non-Annotated from fastapi import Depends , FastAPI from typing_extensions import Annotated app = FastAPI () class FixedContentQueryChecker : def __init__ ( self ,... - https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/