Results of 1 - 10 of about 40 for main (0.005 sec.)
- Sub Applications - Mounts 12294
- 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
...API and their own docs UIs, you can have a main app and "mount" one (or more) sub-application(s). Mounting a FastAPI application "Mounting" means adding a completely "ind...ything under that path, with the path operations declared in that sub-application. Top-level application First, create the main, top-level, FastAPI application, and its path operations : 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 (): retur... - https://man.mtool.work/fastapi/0.115/advanced/sub-applications/
- Bigger Applications - Multiple Files 11405
- 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
...k's Blueprints. An example file structure Let's say you have a file structure like this: . ├── app │ ├── __init__.py │ ├── main.py │ ├── dependencies.py │ └── routers │ │ ├── __init__.py │ │ ├── items.py │ │ └── users.py │ └── internal │ ├── __init__...one in each directory or subdirectory. This is what allows importing code from one file into another. For example, in app/main.py you could have a line like: from app.routers import items The app directory contains everything. And it has an empty fi...le app/__init__.py , so it is a "Python package" (a collection of "Python modules"): app . It contains an app/main.py file. As it is inside a Python package (a directory with a file __init__.py ), it is a "module" of that package: app.ma... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
- テスト 11327
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...+ from fastapi import FastAPI from 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 ( "/" ) as...アプリケーションは、複数のファイル/モジュールなどで構成されている場合もあります。 FastAPI アプリファイル FastAPI アプリに main.py ファイルがあるとします: Python 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 をインポートします: Python 3.8+ from fastapi.testclient import... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- Async Tests 10656
- 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,
...sider a file structure similar to the one described in Bigger Applications and Testing : . ├── app │ ├── __init__.py │ ├── main.py │ └── test_main.py The file main.py would have: Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( ".../" ) async def root (): return { "message" : "Tomato" } The file test_main.py would have the tests for main.py , it could look like this now: Python 3.8+ import pytest from httpx import ASGITranspo...rt , AsyncClient from .main import app @pytest . mark . anyio async def test_root (): async with AsyncClient ( transport = ASGITransport ( app = app )... - https://man.mtool.work/fastapi/0.115/advanced/async-tests/
- デバッグ 9470
- デバッグ Visual Studio CodeやPyCharmなどを使用して、エディター上でデバッガーと連携できます。 uvicorn の実行 FastAPIアプリケーション上で、 uvicorn を直接インポートして実行します: Python 3.8+ import uvicorn from fastapi import FastAPI app = F
...astAPI () @app . get ( "/" ) def root (): a = "a" b = "b" + a return { "hello world" : b } if __name__ == "__main__" : uvicorn . run ( app , host = "0.0.0.0" , port = 8000 ) __name__ == "__main__" について __name__ == "__main__" の主な目...下の様に実行する場合: $ python myapp.py Pythonによって自動的に作成されたファイル内の内部変数 __name__ は、値として文字列 "__main__" を持ちます。 なので、以下: uvicorn . run ( app , host = "0.0.0.0" , port = 8000 ) は実行されます。 そのモジュール (ファ...のようなもう一つのファイル importer.py がある場合: from myapp import app # Some more code myapp.py 内の自動変数には、値が "__main __" の変数 __name__ はありません。 したがって、以下の行: uvicorn . run ( app , host = "0.0.0.0" , port = 8000 ) は実行され... - https://man.mtool.work/fastapi/0.115/tutorial/debugging/
- Server Workers - Gunicorn と Uvicorn 9330
- Server Workers - Gunicorn と Uvicorn 前回のデプロイメントのコンセプトを振り返ってみましょう: セキュリティ - HTTPS 起動時の実行 再起動 レプリケーション(実行中のプロセス数) メモリ 開始前の事前ステップ ここまでのドキュメントのチュートリアルで
...ンストールされます。 UvicornのワーカーとともにGunicornを実行する Gunicornを以下のように起動させることができます: $ gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0 .0.0.0:80 [19499] [INFO] Starting gunicorn 20.1.0 [1...Waiting for application startup. [19515] [INFO] Application startup complete. それぞれのオプションの意味を見てみましょう: main:app : main は" main "という名前のPythonモジュール、つまりファイル main.py を意味します。そして app は FastAPI アプリケーシ...ョンの変数名です。 main:app はPythonの import`文と同じようなものだと想像できます: from main import app つまり、 main:app のコロンは、 from main im... - https://man.mtool.work/fastapi/0.115/deployment/server-workers/
- コンテナ内のFastAPI - Docker 9252
- コンテナ内のFastAPI - Docker FastAPIアプリケーションをデプロイする場合、一般的なアプローチは Linuxコンテナ・イメージ をビルドすることです。 基本的には Docker を用いて行われます。生成されたコンテナ・イメージは、いくつかの方法のいずれかでデプ
...rements.txt RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt COPY ./app /code/app CMD [ "uvicorn" , "app.main:app" , "--host" , "0.0.0.0" , "--port" , "80" ] # If running behind a proxy like Nginx or Traefik add --proxy-headers # CM...D ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"] コンテナとは何か コンテナ(主にLinuxコンテナ)は、同じシステ...ナ・イメージには残りません(ディスクに保存されません)。 コンテナイメージは プログラム ファイルやその内容、例えば python と main.py ファイルに匹敵します。 そして、 コンテナ 自体は( コンテナイメージ とは対照的に)イメージをもとにした実際の実行中のイン... - https://man.mtool.work/fastapi/0.115/deployment/docker/
- 最初のステップ 9252
- 最初のステップ 最もシンプルなFastAPIファイルは以下のようになります: Python 3.8+ from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) async def root (): return { "message" : "Hello World" } これを main.py にコピーします。 ライブサ
...ーバーを実行します: $ uvicorn main:app --reload <span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) <spa...pan>: Waiting for application startup. <span style="color: green;">INFO</span>: Application startup complete. 備考 uvicorn main:app は以下を示します: main : main.py ファイル (Python "module")。 app : main.py 内部で作られるobject( app = FastAPI() のよ...が、すべてのAPIを作成するための主要なポイントになります。 この app はコマンドで uvicorn が参照するものと同じです: $ uvicorn main:app --reload <span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) 以下... - https://man.mtool.work/fastapi/0.115/tutorial/first-steps/
- Behind a Proxy 8737
- 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
...ming there's just /app . Python 3.8+ from fastapi 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 p...application. Providing the root_path To achieve this, you can use the command line option --root-path like: $ fastapi run main.py --root-path /api/v1 <span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to...demonstration purposes. Python 3.8+ from fastapi 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... - https://man.mtool.work/fastapi/0.115/advanced/behind-a-proxy/
- FastAPI CLI 8659
- FastAPI CLI Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI CLI is a command line program that you can use to serve your FastAPI app, manage your FastAPI p
...u can use the fastapi dev command: $ <font color = "#4E9A06" >fastapi</font> dev <u style = "text-decoration-style:solid" >main.py</u> <span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span> Starting development server ?...nt color="#AD7FA8">awesomeapp</font> <span style="background-color:#007166"><font color="#D3D7CF"> module </font></span> ? main.py <span style="background-color:#007166"><font color="#D3D7CF"> code </font></span> Importing the FastAPI app object from...module with the following code: <u style="text-decoration-style:solid">from </u><u style="text-decoration-style:solid"><b>main</b></u><u style="text-decoration-style:solid"> import </u><u style="text-decoration-style:solid"><b>app</b></u> <span styl... - https://man.mtool.work/fastapi/0.115/fastapi-cli/