コンテンツにスキップ
per page, with , order by , clip by
Results of 1 - 10 of about 18 for dependency (0.002 sec.)
Testing Dependencies with Overrides 13177
Testing Dependencies with Overrides Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Overriding dependencies during testing There are some scenarios where you might ... want to override a dependency during testing. You don't want the original dependency to run (nor any of the sub-dependencies it might have). Instead, yo ... u want to provide a different dependency that will be used only during tests (possibly only some specific tests), and will provide a value that can be used where t ... he value of the original dependency was used. Use cases: external service An example could be that you have an external authentication provider that you need ...
https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
yieldを持つ依存関係 13177
yieldを持つ依存関係 FastAPIは、いくつかの 終了後の追加のステップ を行う依存関係をサポートしています。 これを行うには、 return の代わりに yield を使い、その後に追加のステップを書きます。 豆知識 yield は必ず一度だけ使用するようにしてください。 ... ことができます。 FastAPI は、 yield を持つ各依存関係の「終了コード」が正しい順番で実行されていることを確認します。 例えば、 dependency_c は dependency_b と dependency_b に依存する dependency_a に、依存することができます: Python 3.8+ - non-Annotated from fas ... tapi import Depends async def dependency_a (): dep_a = generate_dep_a () try : yield dep_a finally : dep_a . close () async def dependency_b ( dep_a = Depends ( de ... pendency_a )): dep_b = generate_dep_b () try : yield dep_b finally : dep_b . close ( dep_a ) async def dependency_c ( dep_b = Depends ( dependency_b )): dep_c = generate_dep_c () try : yield dep_c finally : dep_c . close ( dep_b ) ? Oth ...
https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-with-yie...
Settings and Environment Variables 9625
Settings and Environment Variables Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In many cases your application could need some external settings or configuratio ... per_user , } Tip You would also need a file __init__.py as you saw in Bigger Applications - Multiple Files . Settings in a dependency In some occasions it might be useful to provide the settings from a dependency, instead of having a global object with set ... tings that is used everywhere. This could be especially useful during testing, as it's very easy to override a dependency with your own custom settings. The config file Coming from the previous example, your config.py file could look like: Pyth ... er : int = 50 Notice that now we don't create a default instance settings = Settings() . The main app file Now we create a dependency that returns a new config.Settings() . Python 3.9+ from functools import lru_cache from typing import Annotated from fasta ...
https://man.mtool.work/fastapi/0.115/advanced/settings/
Advanced Dependencies 9179
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 ... ut there could be cases where you want to be able to set parameters on the dependency, without having to declare many different functions or classes. Let's imagine that we want to have a dependency that check ... the instance And now, we can use __init__ to declare the parameters of the instance that we can use to "parameterize" the dependency: Python 3.9+ from typing import Annotated from fastapi import Depends , FastAPI app = FastAPI () class FixedContentQueryCh ... ( checker )): return { "fixed_content_in_query" : fixed_content_included } And that way we are able to "parameterize" our dependency, that now has "bar" inside of it, as the attribute checker.fixed_content . Use the instance as a dependency Then, we could ...
https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/
Background Tasks - BackgroundTasks 8098
Background Tasks - BackgroundTasks You can declare a parameter in a path operation function or dependency function with the type BackgroundTasks , and then you can use it to schedule the execution of background tasks after the response is s ...
https://man.mtool.work/fastapi/0.115/reference/background/
Response class 8098
Response class You can declare a parameter in a path operation function or dependency to be of type Response and then you can set data for the response like headers or cookies. You can also use it directly to create an instance of it and re ...
https://man.mtool.work/fastapi/0.115/reference/response/
FastAPI class 8064
FastAPI class Here's the reference information for the FastAPI class, with all its parameters, attributes and methods. You can import the FastAPI class directly from fastapi : from fastapi import FastAPI ::: fastapi.FastAPI options: members ... : - openapi_version - webhooks - state - dependency_overrides - openapi - websocket - include_router - get - put - post - delete - options - head - patch - trace - on_event - ...
https://man.mtool.work/fastapi/0.115/reference/fastapi/
Request class 8064
Request class You can declare a parameter in a path operation function or dependency to be of type Request and then you can access the raw request object directly, without any validation, etc. You can import it directly from fastapi : from ...
https://man.mtool.work/fastapi/0.115/reference/request/
Request Parameters 8012
Request Parameters Here's the reference information for the request parameters. These are the special functions that you can put in path operation function parameters or dependency functions with Annotated to get data from the request. It i ...
https://man.mtool.work/fastapi/0.115/reference/parameters/
Bigger Applications - Multiple Files 7892
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 ... aces of the application. So we put them in their own dependencies module ( app/dependencies.py ). We will now use a simple dependency to read a custom X-Token header: Python 3.9+ Python 3.8+ Python 3.8+ non-Annotated app/dependencies.py from typing import ... he same: Path prefix : /items . tags : (just one tag: items ). Extra responses . dependencies : they all need that X-Token dependency we created. So, instead of adding all that to each path operation , we can add it to the APIRouter . app/routers/items.py ... the dependencies This code lives in the module app.routers.items , the file app/routers/items.py . And we need to get the dependency function from the module app.dependencies , the file app/dependencies.py . So we use a relative import with .. for the dep ...
https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
PREV 1 2 NEXT