Results of 1 - 10 of about 67 for async (0.015 sec.)
- Request Files 9986
- 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
...9+ from typing import Annotated from fastapi import FastAPI , File , UploadFile app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . post ( "/uploadfile/"...) async def create_upload_file ( file : UploadFile ): return { "filename" : file . filename } ? Other versions and variants Python...tapi import FastAPI , File , UploadFile from typing_extensions import Annotated app = FastAPI () @app . post ( "/files/" ) async def create_file ( file : Annotated [ bytes , File ()]): return { "file_size" : len ( file )} @app . post ( "/uploadfile/"... - https://man.mtool.work/fastapi/0.115/tutorial/request-files/
- OAuth2 scopes 9944
- 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
...date ({ "exp" : expire }) encoded_jwt = jwt . encode ( to_encode , SECRET_KEY , algorithm = ALGORITHM ) return encoded_jwt async def get_current_user ( security_scopes : SecurityScopes , token : Annotated [ str , Depends ( oauth2_scheme )] ): if secur...01_UNAUTHORIZED , detail = "Not enough permissions" , headers = { "WWW-Authenticate" : authenticate_value }, ) return user async def get_current_active_user ( current_user : Annotated [ User , Security ( get_current_user , scopes = [ "me" ])], ): if c...sabled : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login_for_access_token ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()], ) -> Token : user = authenti... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
- Simple OAuth2 with Password and Bearer 9673
- 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
...# This doesn't provide any security 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 us..._UNAUTHORIZED , detail = "Invalid authentication credentials" , headers = { "WWW-Authenticate" : "Bearer" }, ) return user async def get_current_active_user ( current_user : Annotated [ User , Depends ( get_current_user )], ): if current_user . disabl...ed : raise HTTPException ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login ( form_data : Annotated [ OAuth2PasswordRequestForm , Depends ()]): user_dict = fake_users_db . get ( form_data... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
- 依存関係 - 最初のステップ 9602
- 依存関係 - 最初のステップ ** 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 = 100 ): 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_u...thon 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 ): return { "q" : q , "skip" : skip , "... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/
- path operationデコレータの依存関係 9432
- path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、
...であるべきです: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI , Header , HTTPException app = FastAPI () async def verify_token ( x_token : str = Header ()): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code...= 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : str = Header ()): if x_key != "fake-super-secret-key" : raise HTTPException ( status_code = 400 ,...eader invalid" ) return x_key @app . get ( "/items/" , dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) async def read_items (): return [{ "item" : "Foo" }, { "item" : "Bar" }] ? Other versions and variants Python 3.9+ Python 3.8+ f... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
- 現在のユーザーの取得 9432
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...OAuth2PasswordBearer app = FastAPI () 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...OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): return { "token" : token } from fastapi import Dep...ons import Annotated app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): return { "token" : token } しかし、それはまだそんな... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 9432
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ
...date ({ "exp" : expire }) encoded_jwt = 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 = sta...= get_user ( fake_users_db , username = token_data . username ) 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 HTTP...Exception ( status_code = 400 , detail = "Inactive user" ) return current_user @app . post ( "/token" ) async def login_for_access_token ( form_data : OAuth2PasswordRequestForm = Depends (), ) -> Token : user = authenticate_user ( f... - https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
- 依存関係としてのクラス 9360
- 依存関係としてのクラス 依存性注入 システムを深く掘り下げる前に、先ほどの例をアップグレードしてみましょう。 前の例の 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 . get ( "/items/" ) async def read_items ( commons : dict = Depends ( common_parameters )): return commons @app . get ( "/users/" ) async def read_u...thon 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 ): return { "q" : q , "skip" : skip , "... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/classes-as-dependenci...
- クエリパラメータと文字列の検証 9360
- クエリパラメータと文字列の検証 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" }]}...n results ? Other versions and variants Python 3.10+ from fastapi import FastAPI app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : str | None = None ): results = { "items" : [{ "item_id" : "Foo" }, { "item_id" : "Bar" }]} if q : res....8+ - non-Annotated from typing import Union from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Union [ str , None ] = Query ( default = None , max_length = 50 )): results = { "items" : [{ "item_id... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- Async Tests 9147
- Async Tests Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You have already seen how to test your FastAPI applications using the provided TestClient . Up to now,
...you have only seen how to write synchronous tests, without using async functions. Being able to use asynchronous functions in your tests could be useful, for example, when you're querying your...database asynchronously. Imagine you want to test sending requests to your FastAPI application and then verify that your backend successf...ully wrote the correct data in the database, while using an async database library. Let's look at how we can make that work. pytest.mark.anyio If we want to call asynchronous functions in... - https://man.mtool.work/fastapi/0.115/advanced/async-tests/