Results of 1 - 10 of about 27 for Query (0.009 sec.)
- サブ依存関係 12179
- サブ依存関係 サブ依存関係 を持つ依存関係を作成することができます。 それらは必要なだけ 深く することができます。 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_extracto...r ), last_query : Union [ str , None ] = Cookie ( default = None ), ): if not q : return last_query return q @app . get ( "/items/" ) asyn...c def read_query ( query_or_default : str = Depends ( query_or_cookie_extractor )): return { "q_or_cookie" : query_or_default } ? Other ver... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/sub-dependencies/
- クエリパラメータと文字列の検証 11965
- クエリパラメータと文字列の検証 FastAPI ではパラメータの追加情報とバリデーションを宣言することができます。 以下のアプリケーションを例にしてみましょう: Python 3.8+ from typing import Union from fastapi import FastAPI app = FastAPI () @app . g
...す。 バリデーションの追加 q はオプショナルですが、もし値が渡されてきた場合には、 50文字を超えないこと を強制してみましょう。 Query のインポート そのために、まずは fastapi から Query をインポートします: Python 3.8+ - non-Annotated from typing import Unio...n from fastapi import FastAPI , Query app = FastAPI () @app . get ( "/items/" ) async def read_items ( q : Union [ str , None ] = Query ( default = None , max_l...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 )] =... - https://man.mtool.work/fastapi/0.115/tutorial/query-params-str-validations/
- クエリパラメータモデル 10911
- クエリパラメータモデル もし関連する 複数のクエリパラメータ から成るグループがあるなら、それらを宣言するために、 Pydanticモデル を作成できます。 こうすることで、 複数の場所 で そのPydanticモデルを再利用 でき、バリデーションやメタデータを、す
...ます。? クエリパラメータにPydanticモデルを使用する 必要な 複数のクエリパラメータ を Pydanticモデル で宣言し、さらに、それを Query として宣言しましょう: Python 3.10+ from typing import Annotated , Literal from fastapi import FastAPI , Query from pydanti...reated_at" , "updated_at" ] = "created_at" tags : list [ str ] = [] @app . get ( "/items/" ) async def read_items ( filter_query : Annotated [ FilterParams , Query ()]): return filter_query ? Other versions and variants Python 3.9+ Python 3.8+ Python...3.10+ - non-Annotated Python 3.9+ - non-Annotated Python 3.8+ - non-Annotated from fastapi import FastAPI , Query from pydantic import BaseModel , Field from typing_extensions import Annotated , Literal app = FastAPI () class FilterPara... - https://man.mtool.work/fastapi/0.115/tutorial/query-param-models/
- Advanced Dependencies 10549
- 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
...having to declare many different functions or classes. Let's imagine that we want to have a dependency that checks if the query parameter q contains some fixed content. But we want to be able to parameterize that fixed content. A "callable" instance...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_content = fixed_content def __call__ ( self , q : str =..."" ): if q : return self . fixed_content in q return False checker = FixedContentQueryChecker ( "bar" ) @app . get ( "/query-checker/" ) async def read_query_check ( fixed_content_included : Annotated [ bool ,... - https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/
- パスパラメータと数値の検証 10401
- パスパラメータと数値の検証 クエリパラメータに対して Query でより多くのバリデーションとメタデータを宣言できるのと同じように、パスパラメータに対しても Path で同じ種類のバリデーションとメタデータを宣言することができます。 Pathのインポート まず
...pi から Path をインポートします: Python 3.8+ - non-Annotated from typing import Union from fastapi import FastAPI , Path , Query app = FastAPI () @app . get ( "/items/ {item_id} " ) async def read_items ( item_id : int = Path ( title = "The ID of the...item to get" ), q : Union [ str , None ] = Query ( default = None , alias = "item-query" ), ): results = { "item_id" : item_id } if q : results . update ({ "q" : q }) retu...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 = "Th... - https://man.mtool.work/fastapi/0.115/tutorial/path-params-numeric-validations/
- SQL (Relational) Databases 10401
- 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 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 ( SQLModel , table = True ): id : int...ed ? ? 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 ( SQLModel , table = True ): id : int...eturn hero @app . get ( "/heroes/" ) def read_heroes ( session : SessionDep , offset : int = 0 , limit : Annotated [ int , Query ( le = 100 )] = 100 , ) -> list [ Hero ]: heroes = session . exec ( select ( Hero ) . offset ( offset ) . limit ( limit ))... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- Release Notes 8673
- 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
...cs/uk/docs/tutorial/debugging.md . PR #13370 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/query-params.md . PR #13362 by @valentinDruzhinin . ? Add Ukrainian translation for docs/uk/docs/tutorial/path-params.md . PR #1.../tutorial/body-multiple-params.md . PR #13408 by @valentinDruzhinin . ? Add Japanese translation for docs/ja/docs/tutorial/query-param-models.md . PR #13323 by @k94-ishi . ? Add Ukrainian translation for docs/uk/docs/tutorial/body-nested-models.md . P...that HTTPDigest only raises an exception when auto_error is True . PR #2939 by @arthurio . Refactors ✅ Simplify tests for query_params_str_validations . PR #13218 by @alv2017 . ✅ Simplify tests for app_testing . PR #13220 by @alv2017 . ✅ Simplify tes... - https://man.mtool.work/fastapi/0.115/release-notes/
- バックグラウンドタスク 8508
- バックグラウンドタスク レスポンスを返した 後に 実行されるバックグラウンドタスクを定義できます。 これは、リクエスト後に処理を開始する必要があるが、クライアントがレスポンスを受け取る前に処理を終える必要のない操作に役立ちます。 これには、たとえ
...FastAPI () def write_log ( message : str ): with open ( "log.txt" , mode = "a" ) as log : log . write ( message ) def get_query ( background_tasks : BackgroundTasks , q : Union [ str , None ] = None ): if q : message = f "found query: { q } \n " back...tion/ {email} " ) async def send_notification ( email : str , background_tasks : BackgroundTasks , q : str = Depends ( get_query ) ): message = f "message to { email } \n " background_tasks . add_task ( write_log , message ) return { "message" : "Mess...FastAPI () def write_log ( message : str ): with open ( "log.txt" , mode = "a" ) as log : log . write ( message ) def get_query ( background_tasks : BackgroundTasks , q : str | None = None ): if q : message = f "found query: { q } \n " background_tas... - https://man.mtool.work/fastapi/0.115/tutorial/background-tasks/
- WebSocket 8426
- WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム
...依存関係 WebSocketエンドポイントでは、 fastapi から以下をインポートして使用できます。 Depends Security Cookie Header Path Query これらは、他のFastAPI エンドポイント/ path operation の場合と同じように機能します。 Python 3.8+ - non-Annotated from typin...g import Union from fastapi import ( Cookie , Depends , FastAPI , Query , WebSocket , WebSocketException , status , ) from fastapi.responses import HTMLResponse app = FastAPI () html = """ <!DOC...token ( websocket : WebSocket , session : Union [ str , None ] = Cookie ( default = None ), token : Union [ str , None ] = Query ( default = None ), ): if session is None and token is None : raise WebSocketException ( code = status . WS_1008_POLICY_VI... - https://man.mtool.work/fastapi/0.115/advanced/websockets/
- Bigger Applications - Multiple Files 8031
- Bigger Applications - Multiple Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you are building an application or a web API, it's rarely the case that you
...!= "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( status_code = 400 , detail = "No Jessica token provid...!= "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( status_code = 400 , detail = "No Jessica token provid...!= "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( status_code = 400 , detail = "No Jessica token provid... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/