Results of 1 - 10 of about 18 for World (0.002 sec.)
- Sub Applications - Mounts 11787
- 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
...thon 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 from sub...thon 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 from sub...thon 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 from sub... - https://man.mtool.work/fastapi/0.115/advanced/sub-applications/
- Including WSGI - Flask, Django, others 11496
- 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 ,
...scape flask_app = Flask ( __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 { "mes...sage" : "Hello World" } app . mount ( "/v1" , WSGIMiddleware ( flask_app )) Check it Now, every request under the path /v1/ will be handled by...ill 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 World"... - https://man.mtool.work/fastapi/0.115/advanced/wsgi/
- Behind a Proxy 10775
- 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
...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 fly befo...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 --root-path...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 provide a... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- Response Headers 10672
- 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
...get ( "/headers-and-object/" ) 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 datab...sponses 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 = content... - https://man.mtool.work/fastapi/0.115/advanced/response-headers/
- 最初のステップ 10672
- 最初のステップ 最もシンプルな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 を直接継承するクラスです。 Fast...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/
- Testing WebSockets 9265
- 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
...om 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 websocket ....( 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 = webs... - https://man.mtool.work/fastapi/0.115/advanced/testing-websockets/
- 環境変数 9059
- 環境変数 Tip もし、「環境変数」とは何か、それをどう使うかを既に知っている場合は、このセクションをスキップして構いません。 環境変数( env var とも呼ばれる)はPythonコードの 外側 、つまり OS に存在する変数で、Pythonから読み取ることができます。
...内で読み取る こともできます。 例えば、以下のような main.py ファイルを用意します: import os name = os . getenv ( "MY_NAME" , "World" ) print ( f "Hello { name } from Python" ) Tip os.getenv() の第2引数は、デフォルトで返される値を指定します。 この引数を省...略するとデフォルト値として None が返されますが、ここではデフォルト値として "World" を指定しています。 次に、このPythonプログラムを呼び出します。 Linux, macOS, Windows Bash Windows PowerShell // Here we do...n't set the env var yet $ python main.py // As we didn't set the env var, we get the default value Hello World from Python // But if we create an environment variable first $ export MY_NAME = "Wade Wilson" // And then call the progra... - https://man.mtool.work/fastapi/0.115/environment-variables/
- Advanced Middleware 8356
- Advanced Middleware Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In the main tutorial you read how to add Custom Middleware to your application. And then you al
...tAPI () app . add_middleware ( HTTPSRedirectMiddleware ) @app . get ( "/" ) async def main (): return { "message" : "Hello World" } TrustedHostMiddleware Enforces that all incoming requests have a correctly set Host header, in order to guard against H..., allowed_hosts = [ "example.com" , "*.example.com" ] ) @app . get ( "/" ) async def main (): return { "message" : "Hello World" } The following arguments are supported: allowed_hosts - A list of domain names that should be allowed as hostnames. Wild... - https://man.mtool.work/fastapi/0.115/advanced/middleware/
- テスト 7944
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...m fastapi.testclient import TestClient app = FastAPI () @app . get ( "/" ) async def read_main (): return { "msg" : "Hello World" } client = TestClient ( app ) def test_read_main (): response = client . get ( "/" ) assert response . status_code == 200...assert response . json () == { "msg" : "Hello World" } 豆知識 テスト関数は async def ではなく、通常の def であることに注意してください。 また、クライアントへの呼び出しも通常の...ython 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def read_main (): return { "msg" : "Hello World" } テストファイル 次に、テストを含む test_main.py ファイルを作成し、 main モジュール ( main.py ) から app をインポートしま... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- FastAPI 7738
- FastAPI FastAPI framework, high performance, easy to learn, fast to code, ready for production ドキュメント : https://fastapi.tiangolo.com ソースコード : https://github.com/fastapi/fastapi FastAPI は、Pythonの標準である型ヒントに基づいてPyt
...のコードを入力します: from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) def read_root (): return { "Hello" : "World" } @app . get ( "/items/ {item_id} " ) def read_item ( item_id : int , q : str = None ): return { "item_id" : item_id , "q...ef を使います: from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def read_root (): return { "Hello" : "World" } @app . get ( "/items/ {item_id} " ) async def read_item ( item_id : int , q : str = None ): return { "item_id" : item_i...em ( BaseModel ): name : str price : float is_offer : bool = None @app . get ( "/" ) def read_root (): return { "Hello" : "World" } @app . get ( "/items/ {item_id} " ) def read_item ( item_id : int , q : str = None ): return { "item_id" : item_id , "q... - https://man.mtool.work/fastapi/0.115/