Results of 1 - 10 of about 12 for call (0.002 sec.)
- Advanced Dependencies 14044
- 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
...checks if the query parameter q contains some fixed content. But we want to be able to parameterize that fixed content. A "callable" instance In Python there's a way to make an instance of a class a "callable". Not the class itself (which is already...a callable), but an instance of that class. To do that, we declare a method __call__ : Python 3.9+ from typing import Annotated f...) 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"... - https://man.mtool.work/fastapi/0.115/advanced/advanced-dependencies/
- ミドルウェア 10152
- ミドルウェア FastAPI アプリケーションにミドルウェアを追加できます。 「ミドルウェア」は、すべての リクエスト に対して、それがあらゆる特定の path operation によって処理される前に機能する関数です。また、すべての レスポンス に対して、それを返す
...middleware("http") を使用します。 ミドルウェア関数は以下を受け取ります: request 。 パラメータとして request を受け取る関数 call_next 。 この関数は、対応する path operation に request を渡します。 次に、対応する path operation によって生成された respo...rt FastAPI , Request app = FastAPI () @app . middleware ( "http" ) async def add_process_time_header ( request : Request , call_next ): start_time = time . perf_counter () response = await call_next ( request ) process_time = time . perf_counter () -...rt FastAPI , Request app = FastAPI () @app . middleware ( "http" ) async def add_process_time_header ( request : Request , call_next ): start_time = time . perf_counter () response = await call_next ( request ) process_time = time . perf_counter () -... - https://man.mtool.work/fastapi/0.115/tutorial/middleware/
- Async Tests 9816
- 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,
...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 our tests, our test functions have to be asynchronous. AnyIO provides a neat plugin for this, th...at allows us to specify that some test functions are to be called asynchronously. HTTPX Even if your FastAPI application uses normal def functions instead of async def , it is still an a...sync application underneath. The TestClient does some magic inside to call the asynchronous FastAPI application in your normal def test functions, using standard pytest. But that magic doesn't work... - https://man.mtool.work/fastapi/0.115/advanced/async-tests/
- Testing Dependencies with Overrides 8808
- 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
...s used. Use cases: external service An example could be that you have an external authentication provider that you need to call. You send it a token and it returns an authenticated user. This provider might be charging you per request, and calling it...ime than if you had a fixed mock user for tests. You probably want to test the external provider once, but not necessarily call it for every test that runs. In this case, you can override the dependency that calls that provider, and use a custom depe...the original dependency (a function), and as the value, your dependency override (another function). And then FastAPI will call that override instead of the original dependency. Python 3.10+ from typing import Annotated from fastapi import Depends ,... - https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
- 環境変数 8384
- 環境変数 Tip もし、「環境変数」とは何か、それをどう使うかを既に知っている場合は、このセクションをスキップして構いません。 環境変数( env var とも呼ばれる)はPythonコードの 外側 、つまり OS に存在する変数で、Pythonから読み取ることができます。
...lue Hello World from Python // But if we create an environment variable first $ export MY_NAME = "Wade Wilson" // And then call the program again $ python main.py // Now it can read the environment variable Hello Wade Wilson from Python // Here we do...alue Hello World from Python // But if we create an environment variable first $ $Env :MY_NAME = "Wade Wilson" // And then call the program again $ python main.py // Now it can read the environment variable Hello Wade Wilson from Python 環境変数はコー...同じコマンドライン上の、起動コマンド直前で環境変数を作成してください。 // Create an env var MY_NAME in line for this program call $ MY_NAME = "Wade Wilson" python main.py // Now it can read the environment variable Hello Wade Wilson from Python // The... - https://man.mtool.work/fastapi/0.115/environment-variables/
- Virtual Environments 8207
- Virtual Environments Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . When you work in Python projects you probably should use a virtual environment (or a similar m
...ou can use the venv module that comes with Python. $ python -m venv .venv What that command means python : use the program called python -m : call a module as a script, we'll tell it which module next venv : use the module called venv that normally c...can use it to create a virtual environment. $ uv venv Tip By default, uv will create a virtual environment in a directory called .venv . But you could customize it passing an additional argument with the directory name. That command creates a new vi...rtual environment in a directory called .venv . .venv or other name You could create the virtual environment in a different directory, but there's a convention... - https://man.mtool.work/fastapi/0.115/virtual-environments/
- OpenAPI Callbacks 7959
- OpenAPI Callbacks Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You could create an API with a path operation that could trigger a request to an external API cre
...ted by someone else (probably the same developer that would be using your API). The process that happens when your API app calls the external API is named a "callback". Because the software that the external developer wrote sends a request to your AP...I and then your API calls back , sending a request to an external API (that was probably created by the same developer). In this case, you could wa...ook like. What path operation it should have, what body it should expect, what response it should return, etc. An app with callbacks Let's see all this with an example. Imagine you develop an app that allows creating invoices. These invoices will hav... - https://man.mtool.work/fastapi/0.115/advanced/openapi-callbacks/
- OpenAPI Webhooks 7959
- OpenAPI Webhooks Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . There are cases where you want to tell your API users that your app could call their app (sending
...your API, it's your API (or your app) that could send requests to their system (to their API, their app). This is normally called a webhook . Webhooks steps The process normally is that you define in your code what is the message that you will send,... - https://man.mtool.work/fastapi/0.115/advanced/openapi-webhooks/
- Configure Swagger UI 7959
- Configure Swagger UI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can configure some extra Swagger UI parameters . To configure them, pass the swagger_ui_pa
...enapi_url : Annotated [ str , Doc ( """ The OpenAPI URL that Swagger UI should load and use. This is normally done automatically by FastAPI using the default URL `/openapi.json`. """ ), ], title : Annotated [ str , Doc ( """ The HTML `<title>` conten...vicon.png" , oauth2_redirect_url : Annotated [ Optional [ str ], Doc ( """ The OAuth2 redirect URL, it is normally automatically handled by FastAPI. """ ), ] = None , init_oauth : Annotated [ Optional [ Dict [ str , Any ]], Doc ( """ A dictionary wit...nerate and return the HTML that loads Swagger UI for the interactive API docs (normally served at `/docs`). You would only call this function yourself if you needed to override some parts, for example the URLs to use to load Swagger UI's JavaScript a... - https://man.mtool.work/fastapi/0.115/how-to/configure-swagger-ui/
- Settings and Environment Variables 7782
- 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
...tice is common enough that it has a name, these environment variables are commonly placed in a file .env , and the file is called a "dotenv". Tip A file starting with a dot ( . ) is a hidden file in Unix-like systems, like Linux and macOS. But a dote...⚠️ But as we are using the @lru_cache decorator on top, the Settings object will be created only once, the first time it's called. ✔️ Python 3.9+ from functools import lru_cache from fastapi import Depends , FastAPI from typing_extensions import Anno...p_name , "admin_email" : settings . admin_email , "items_per_user" : settings . items_per_user , } Then for any subsequent call of get_settings() in the dependencies for the next requests, instead of executing the internal code of get_settings() and... - https://man.mtool.work/fastapi/0.115/advanced/settings/