Results of 1 - 10 of about 24 for Hello (0.002 sec.)
- Testing Dependencies with Overrides 14328
- 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
...t ( "/items/" ) async def read_items ( commons : Annotated [ dict , Depends ( common_parameters )]): return { "message" : "Hello Items!" , "params" : commons } @app . get ( "/users/" ) async def read_users ( commons : Annotated [ dict , Depends ( comm...on_parameters )]): return { "message" : "Hello Users!" , "params" : commons } client = TestClient ( app ) async def override_dependency ( q : str | None = None ): return...(): response = client . get ( "/items/" ) assert response . status_code == 200 assert response . json () == { "message" : "Hello Items!" , "params" : { "q" : None , "skip" : 5 , "limit" : 10 }, } def test_override_in_items_with_q (): response = client... - https://man.mtool.work/fastapi/0.115/advanced/testing-dependencies/
- 環境変数 10208
- 環境変数 Tip もし、「環境変数」とは何か、それをどう使うかを既に知っている場合は、このセクションをスキップして構いません。 環境変数( env var とも呼ばれる)はPythonコードの 外側 、つまり OS に存在する変数で、Pythonから読み取ることができます。
...create an env var MY_NAME with $ export MY_NAME = "Wade Wilson" // Then you could use it with other programs, like $ echo "Hello $MY_NAME " Hello Wade Wilson // Create an env var MY_NAME $ $Env :MY_NAME = "Wade Wilson" // Use it with other programs, l...ike $ echo "Hello $Env :MY_NAME" Hello Wade Wilson Pythonで環境変数を読み取る 環境変数をPythonの 外側 、ターミナル(や他の方法)で作成し、 P...きます。 例えば、以下のような main.py ファイルを用意します: import os name = os . getenv ( "MY_NAME" , "World" ) print ( f "Hello { name } from Python" ) Tip os.getenv() の第2引数は、デフォルトで返される値を指定します。 この引数を省略するとデフォルト値... - https://man.mtool.work/fastapi/0.115/environment-variables/
- Testing WebSockets 10091
- Testing WebSockets Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use the same TestClient to test WebSockets. For this, you use the TestClient in a with s
...ent from fastapi.websockets import WebSocket app = FastAPI () @app . get ( "/" ) async def read_main (): return { "msg" : "Hello World" } @app . websocket ( "/ws" ) async def websocket ( websocket : WebSocket ): await websocket . accept () await webso...cket . send_json ({ "msg" : "Hello WebSocket" }) await websocket . close () def test_read_main (): client = TestClient ( app ) response = client . get ( "/"...) assert response . status_code == 200 assert response . json () == { "msg" : "Hello World" } def test_websocket (): client = TestClient ( app ) with client . websocket_connect ( "/ws" ) as websocket : data... - https://man.mtool.work/fastapi/0.115/advanced/testing-websockets/
- Sub Applications - Mounts 10024
- Sub Applications - Mounts Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you need to have two independent FastAPI applications, with their own independent Open
...s : Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/app" ) def read_main (): return { "message" : "Hello World from main app" } subapi = FastAPI () @subapi . get ( "/sub" ) def read_sub (): return { "message" : "Hello World fro...d": Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/app" ) def read_main (): return { "message" : "Hello World from main app" } subapi = FastAPI () @subapi . get ( "/sub" ) def read_sub (): return { "message" : "Hello World fro...i : Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/app" ) def read_main (): return { "message" : "Hello World from main app" } subapi = FastAPI () @subapi . get ( "/sub" ) def read_sub (): return { "message" : "Hello World fro... - https://man.mtool.work/fastapi/0.115/advanced/sub-applications/
- Including WSGI - Flask, Django, others 9841
- Including WSGI - Flask, Django, others Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can mount WSGI applications as you saw with Sub Applications - Mounts ,
...lask ( __name__ ) @flask_app . route ( "/" ) def flask_main (): name = request . args . get ( "name" , "World" ) return f "Hello, { escape ( name ) } from Flask!" app = FastAPI () @app . get ( "/v2" ) def read_main (): return { "message" : "Hello Worl...rest will be handled by FastAPI . If you run it and go to http://localhost:8000/v1/ you will see the response from Flask: Hello, World from Flask! And if you go to http://localhost:8000/v2 you will see the response from FastAPI: { "message" : "Hello... - https://man.mtool.work/fastapi/0.115/advanced/wsgi/
- Behind a Proxy 9407
- Behind a Proxy Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In some situations, you might need to use a proxy server like Traefik or Nginx with a configuration
...import FastAPI , Request app = FastAPI () @app . get ( "/app" ) def read_main ( request : Request ): return { "message" : "Hello World" , "root_path" : request . scope . get ( "root_path" )} And the proxy would be "stripping" the path prefix on the fl...import FastAPI , Request app = FastAPI () @app . get ( "/app" ) def read_main ( request : Request ): return { "message" : "Hello World" , "root_path" : request . scope . get ( "root_path" )} Then, if you start Uvicorn with: $ fastapi run main.py --roo...pan>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) The response would be something like: { "message" : "Hello World" , "root_path" : "/api/v1" } Setting the root_path in the FastAPI app Alternatively, if you don't have a way to prov... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- 最初のステップ 9341
- 最初のステップ 最もシンプルなFastAPIファイルは以下のようになります: Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def root (): return { "message" : "Hello World" } これを main.py にコピーします。 ライブサ
...示しています。 チェック ブラウザで http://127.0.0.1:8000 を開きます。 次のようなJSONレスポンスが表示されます: { "message" : "Hello World" } 対話的APIドキュメント 次に、 http://127.0.0.1:8000/docs にアクセスします。 自動生成された対話的APIドキュメントが表...ポート Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def root (): return { "message" : "Hello World" } FastAPI は、APIのすべての機能を提供するPythonクラスです。 技術詳細 FastAPI は Starlette を直接継承するクラスです。...を生成 Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def root (): return { "message" : "Hello World" } ここで、 app 変数が FastAPI クラスの「インスタンス」になります。 これが、すべてのAPIを作成するための主要なポイント... - https://man.mtool.work/fastapi/0.115/tutorial/first-steps/
- Custom Docs UI Static Assets (Self-Hosting) 8590
- Custom Docs UI Static Assets (Self-Hosting) Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . The API docs use Swagger UI and ReDoc , and each of those need some Jav
...oc.standalone.js" , ) @app . get ( "/users/ {username} " ) async def read_user ( username : str ): return { "message" : f "Hello { username } " } Include the custom docs Now you can create the path operations for the custom docs. You can reuse FastAPI...oc.standalone.js" , ) @app . get ( "/users/ {username} " ) async def read_user ( username : str ): return { "message" : f "Hello { username } " } Tip The path operation for swagger_ui_redirect is a helper for when you use OAuth2. If you integrate your...oc.standalone.js" , ) @app . get ( "/users/ {username} " ) async def read_user ( username : str ): return { "message" : f "Hello { username } " } Test it Now, you should be able to go to your docs at http://127.0.0.1:8000/docs , and reload the page, i... - https://man.mtool.work/fastapi/0.115/how-to/custom-docs-ui-assets/
- Response Headers 8106
- Response Headers Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Use a Response parameter You can declare a parameter of type Response in your path operation funct
...) def get_headers ( response : Response ): response . headers [ "X-Cat-Dog" ] = "alone in the world" return { "message" : "Hello World" } And then you can return any object you need, as you normally would (a dict , a database model, etc). And if you d...api.responses import JSONResponse app = FastAPI () @app . get ( "/headers/" ) def get_headers (): content = { "message" : "Hello World" } headers = { "X-Cat-Dog" : "alone in the world" , "Content-Language" : "en-US" } return JSONResponse ( content = c... - https://man.mtool.work/fastapi/0.115/advanced/response-headers/
- Bigger Applications - Multiple Files 8106
- 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
...)], responses = { 418 : { "description" : "I'm a teapot" }}, ) @app . get ( "/" ) async def root (): return { "message" : "Hello Bigger Applications!" } Import the APIRouter Now we import the other submodules that have APIRouter s: app/main.py from fa...)], responses = { 418 : { "description" : "I'm a teapot" }}, ) @app . get ( "/" ) async def root (): return { "message" : "Hello Bigger Applications!" } As the files app/routers/users.py and app/routers/items.py are submodules that are part of the sam...)], responses = { 418 : { "description" : "I'm a teapot" }}, ) @app . get ( "/" ) async def root (): return { "message" : "Hello Bigger Applications!" } Include the APIRouter s for users and items Now, let's include the router s from the submodules us... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/