コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 6 of about 6 for yield (0.009 sec.)
yieldを持つ依存関係 12356
yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。 ... ger これらは FastAPI の依存関係として使用するのに有効です。 実際、FastAPIは内部的にこれら2つのデコレータを使用しています。 yield を持つデータベースの依存関係 例えば、これを使ってデータベースセッションを作成し、終了後にそれを閉じることができます。 レス ... ポンスを送信する前に yield 文を含む前のコードのみが実行されます。 Python 3.8+ async def get_db (): db = DBSession () try : yield db finally : db . cl ... 成された値は、 path operations や他の依存関係に注入されるものです: Python 3.8+ async def get_db (): db = DBSession () try : yield db finally : db . close () yield 文に続くコードは、レスポンスが送信された後に実行されます: Python 3.8+ async def get_db () ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
SQL (Relational) Databases 10254
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 ... ate_db_and_tables (): SQLModel . 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_ ... ate_db_and_tables (): SQLModel . 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_ ... ate_db_and_tables (): SQLModel . 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_ ...
https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
Lifespan Events 9432
Lifespan Events Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can define logic (code) that should be executed before the application starts up . This means t ... t that is in a second). Let's start with an example and then see it in detail. We create an async function lifespan() with yield like this: Python 3.8+ from contextlib import asynccontextmanager from fastapi import FastAPI def fake_answer_to_everythin ... lifespan ( app : FastAPI ): # Load the ML model ml_models [ "answer_to_everything" ] = fake_answer_to_everything_ml_model yield # Clean up the ML models and release the resources ml_models . clear () app = FastAPI ( lifespan = lifespan ) @app . get ( ... ration of loading the model by putting the (fake) model function in the dictionary with machine learning models before the yield . This code will be executed before the application starts taking requests , during the startup . And then, right after th ...
https://man.mtool.work/fastapi/0.115/advanced/events/
Release Notes 8426
Release Notes Latest Changes 0.115.11 Fixes ? Add docs examples and tests (support) for Annotated custom validations, like AfterValidator , revert #13440 . PR #13442 by @tiangolo . New docs: Query Parameters and String Validations - Custom ... tatic-files.md . PR #11291 by @ptt3199 . ? Add Korean translation for docs/ko/docs/tutorial/dependencies/dependencies-with-yield.md . PR #13257 by @11kkw . ? Add Vietnamese translation for docs/vi/docs/virtual-environments.md . PR #13282 by @ptt3199 . ... ve Codacy. PR #13032 by @tiangolo . 0.115.6 Fixes ? Preserve traceback when an exception is raised in sync dependency with yield . PR #5823 by @sombek . Refactors ♻️ Update tests and internals for compatibility with Pydantic >=2.10. PR #12971 by @tami ... cs/tutorial/metadata.md . PR #12773 by @Nimitha-jagadeesha . ? Update docs/en/docs/tutorial/dependencies/dependencies-with-yield.md . PR #12045 by @xuvjso . ? Update includes for docs/en/docs/tutorial/dependencies/global-dependencies.md . PR #12653 by ...
https://man.mtool.work/fastapi/0.115/release-notes/
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス 7165
カスタムレスポンス - HTML、ストリーム、ファイル、その他のレスポンス デフォルトでは、 FastAPI は JSONResponse を使ってレスポンスを返します。 レスポンスを直接返す で見たように、 Response を直接返すことでこの挙動をオーバーライドできます。 しか ... from fastapi.responses import StreamingResponse app = FastAPI () async def fake_video_streamer (): for i in range ( 10 ): yield b "some fake video bytes" @app . get ( "/" ) async def main (): return StreamingResponse ( fake_video_streamer ()) Streami ... () @app . get ( "/" ) def main (): def iterfile (): # (1) with open ( some_file_path , mode = "rb" ) as file_like : # (2) yield from file_like # (3) return StreamingResponse ( iterfile (), media_type = "video/mp4" ) 豆知識 ここでは async や await をサ ...
https://man.mtool.work/fastapi/0.115/advanced/custom-response/
ミドルウェア 7128
ミドルウェア FastAPI アプリケーションにミドルウェアを追加できます。 「ミドルウェア」は、すべての リクエスト に対して、それがあらゆる特定の path operation によって処理される前に機能する関数です。また、すべての レスポンス に対して、それを返す ... す。 その レスポンス に対して何かを実行したり、必要なコードを実行したりできます。 そして、 レスポンス を返します。 技術詳細 yield を使った依存関係をもつ場合は、終了コードはミドルウェアの 後に 実行されます。 バックグラウンドタスク (後述) がある場合は、そ ...
https://man.mtool.work/fastapi/0.115/tutorial/middleware/
PREV 1 NEXT