]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
๐Ÿ“ Add docs for `pyproject.toml` with `entrypoint` (#15075)
authorSebastiรกn Ramรญrez <tiangolo@gmail.com>
Sat, 7 Mar 2026 09:29:03 +0000 (01:29 -0800)
committerGitHub <noreply@github.com>
Sat, 7 Mar 2026 09:29:03 +0000 (10:29 +0100)
README.md
docs/en/docs/advanced/sub-applications.md
docs/en/docs/advanced/websockets.md
docs/en/docs/fastapi-cli.md
docs/en/docs/index.md
docs/en/docs/tutorial/bigger-applications.md
docs/en/docs/tutorial/first-steps.md
docs/en/docs/tutorial/index.md
docs/en/docs/tutorial/security/first-steps.md
docs/en/docs/tutorial/sql-databases.md

index 9d7796ba30b7836752c37052fa4acb0518ac3500..0b7fcc1c514094c49fb74563a1faf687939ef492 100644 (file)
--- a/README.md
+++ b/README.md
@@ -213,7 +213,7 @@ Run the server with:
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ FastAPI CLI - Development mode โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
  โ”‚                                                     โ”‚
@@ -238,9 +238,9 @@ INFO:     Application startup complete.
 </div>
 
 <details markdown="1">
-<summary>About the command <code>fastapi dev main.py</code>...</summary>
+<summary>About the command <code>fastapi dev</code>...</summary>
 
-The command `fastapi dev` reads your `main.py` file, detects the **FastAPI** app in it, and starts a server using [Uvicorn](https://www.uvicorn.dev).
+The command `fastapi dev` reads your `main.py` file automatically, detects the **FastAPI** app in it, and starts a server using [Uvicorn](https://www.uvicorn.dev).
 
 By default, `fastapi dev` will start with auto-reload enabled for local development.
 
@@ -459,20 +459,6 @@ You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapiclo
 
 If you already have a **FastAPI Cloud** account (we invited you from the waiting list ๐Ÿ˜‰), you can deploy your application with one command.
 
-Before deploying, make sure you are logged in:
-
-<div class="termy">
-
-```console
-$ fastapi login
-
-You are logged in to FastAPI Cloud ๐Ÿš€
-```
-
-</div>
-
-Then deploy your app:
-
 <div class="termy">
 
 ```console
index cc9f67ebd092a8d1edf06ff54e03d9fdf2e9d1c8..a391c7c24569b3d6a59ed04b524133005a304391 100644 (file)
@@ -30,12 +30,12 @@ In this case, it will be mounted at the path `/subapi`:
 
 ### Check the automatic API docs { #check-the-automatic-api-docs }
 
-Now, run the `fastapi` command with your file:
+Now, run the `fastapi` command:
 
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
index f93adfd96183ff3f8f61895e06fb466006441415..50c5e89a43fd3b5e27bb8507c236503d8148e355 100644 (file)
@@ -64,12 +64,12 @@ You can receive and send binary, text, and JSON data.
 
 ## Try it { #try-it }
 
-If your file is named `main.py`, run your application with:
+Put your code in a file `main.py` and then run your application:
 
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
@@ -121,12 +121,12 @@ You can use a closing code from the [valid codes defined in the specification](h
 
 ### Try the WebSockets with dependencies { #try-the-websockets-with-dependencies }
 
-If your file is named `main.py`, run your application with:
+Run your application:
 
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
index e0b40b5000069d779ca52425973d66abf0066395..17898888f1550c4845b46d014e3ac37ace99d3fb 100644 (file)
@@ -1,15 +1,15 @@
 # FastAPI CLI { #fastapi-cli }
 
-**FastAPI CLI** is a command line program that you can use to serve your FastAPI app, manage your FastAPI project, and more.
+**FastAPI <abbr title="command line interface">CLI</abbr>** is a command line program that you can use to serve your FastAPI app, manage your FastAPI project, and more.
 
-When you install FastAPI (e.g. with `pip install "fastapi[standard]"`), it includes a package called `fastapi-cli`, this package provides the `fastapi` command in the terminal.
+When you install FastAPI (e.g. with `pip install "fastapi[standard]"`), it comes with a command line program you can run in the terminal.
 
 To run your FastAPI app for development, you can use the `fastapi dev` command:
 
 <div class="termy">
 
 ```console
-$ <font color="#4E9A06">fastapi</font> dev <u style="text-decoration-style:solid">main.py</u>
+$ <font color="#4E9A06">fastapi</font> dev
 
   <span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span>  Starting development server ๐Ÿš€
 
@@ -46,14 +46,67 @@ $ <font color="#4E9A06">fastapi</font> dev <u style="text-decoration-style:solid
 
 </div>
 
-The command line program called `fastapi` is **FastAPI CLI**.
+/// tip
 
-FastAPI CLI takes the path to your Python program (e.g. `main.py`) and automatically detects the `FastAPI` instance (commonly named `app`), determines the correct import process, and then serves it.
+For production you would use `fastapi run` instead of `fastapi dev`. ๐Ÿš€
 
-For production you would use `fastapi run` instead. ๐Ÿš€
+///
 
 Internally, **FastAPI CLI** uses [Uvicorn](https://www.uvicorn.dev), a high-performance, production-ready, ASGI server. ๐Ÿ˜Ž
 
+The `fastapi` CLI will try to detect automatically the FastAPI app to run, assuming it's an object called `app` in a file `main.py` (or a couple other variants).
+
+But you can configure explicitly the app to use.
+
+## Configure the app `entrypoint` in `pyproject.toml` { #configure-the-app-entrypoint-in-pyproject-toml }
+
+You can configure where your app is located in a `pyproject.toml` file like:
+
+```toml
+[tool.fastapi]
+entrypoint = "main:app"
+```
+
+That `entrypoint` will tell the `fastapi` command that it should import the app like:
+
+```python
+from main import app
+```
+
+If your code was structured like:
+
+```
+.
+โ”œโ”€โ”€ backend
+โ”‚ย ย  โ”œโ”€โ”€ main.py
+โ”‚ย ย  โ”œโ”€โ”€ __init__.py
+```
+
+Then you would set the `entrypoint` as:
+
+```toml
+[tool.fastapi]
+entrypoint = "backend.main:app"
+```
+
+which would be equivalent to:
+
+```python
+from backend.main import app
+```
+
+### `fastapi dev` with path { #fastapi-dev-with-path }
+
+You can also pass the file path to the `fastapi dev` command, and it will guess the FastAPI app object to use:
+
+```console
+$ fastapi dev main.py
+```
+
+But you would have to remember to pass the correct path every time you call the `fastapi` command.
+
+Additionally, other tools might not be able to find it, for example the [VS Code Extension](editor-support.md) or [FastAPI Cloud](https://fastapicloud.com), so it is recommended to use the `entrypoint` in `pyproject.toml`.
+
 ## `fastapi dev` { #fastapi-dev }
 
 Running `fastapi dev` initiates development mode.
@@ -62,7 +115,7 @@ By default, **auto-reload** is enabled, automatically reloading the server when
 
 ## `fastapi run` { #fastapi-run }
 
-Executing `fastapi run` starts FastAPI in production mode by default.
+Executing `fastapi run` starts FastAPI in production mode.
 
 By default, **auto-reload** is disabled. It also listens on the IP address `0.0.0.0`, which means all the available IP addresses, this way it will be publicly accessible to anyone that can communicate with the machine. This is how you would normally run it in production, for example, in a container.
 
index efe13ee4f46101cacb0b0c1df1d2df6db01fe1be..88fcc454562b6e475aacac455c98065c403870e0 100644 (file)
@@ -210,7 +210,7 @@ Run the server with:
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ FastAPI CLI - Development mode โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
  โ”‚                                                     โ”‚
@@ -235,9 +235,9 @@ INFO:     Application startup complete.
 </div>
 
 <details markdown="1">
-<summary>About the command <code>fastapi dev main.py</code>...</summary>
+<summary>About the command <code>fastapi dev</code>...</summary>
 
-The command `fastapi dev` reads your `main.py` file, detects the **FastAPI** app in it, and starts a server using [Uvicorn](https://www.uvicorn.dev).
+The command `fastapi dev` reads your `main.py` file automatically, detects the **FastAPI** app in it, and starts a server using [Uvicorn](https://www.uvicorn.dev).
 
 By default, `fastapi dev` will start with auto-reload enabled for local development.
 
@@ -456,20 +456,6 @@ You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapiclo
 
 If you already have a **FastAPI Cloud** account (we invited you from the waiting list ๐Ÿ˜‰), you can deploy your application with one command.
 
-Before deploying, make sure you are logged in:
-
-<div class="termy">
-
-```console
-$ fastapi login
-
-You are logged in to FastAPI Cloud ๐Ÿš€
-```
-
-</div>
-
-Then deploy your app:
-
 <div class="termy">
 
 ```console
index 73647723a93c30545a3dfdacd7e72079f16dbde2..675ec1b437687f248c6501f00e6616fd8b1fdb35 100644 (file)
@@ -465,6 +465,37 @@ As we cannot just isolate them and "mount" them independently of the rest, the *
 
 ///
 
+## Configure the `entrypoint` in `pyproject.toml` { #configure-the-entrypoint-in-pyproject-toml }
+
+As your FastAPI `app` object lives in `app/main.py`, you can configure the `entrypoint` in your `pyproject.toml` file like this:
+
+```toml
+[tool.fastapi]
+entrypoint = "app.main:app"
+```
+
+that is equivalent to importing like:
+
+```python
+from app.main import app
+```
+
+That way the `fastapi` command will know where to find your app.
+
+/// Note
+
+You could also pass the path to the command, like:
+
+```console
+$ fastapi dev app/main.py
+```
+
+But you would have to remember to pass the correct path every time you call the `fastapi` command.
+
+Additionally, other tools might not be able to find it, for example the [VS Code Extension](../editor-support.md) or [FastAPI Cloud](https://fastapicloud.com), so it is recommended to use the `entrypoint` in `pyproject.toml`.
+
+///
+
 ## Check the automatic API docs { #check-the-automatic-api-docs }
 
 Now, run your app:
@@ -472,7 +503,7 @@ Now, run your app:
 <div class="termy">
 
 ```console
-$ fastapi dev app/main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
index 578a17d2e46659af5579c3a0e71cbbf9dd5d8bfc..3355079900b38bed001be2c7e816469c3d16a961 100644 (file)
@@ -11,7 +11,7 @@ Run the live server:
 <div class="termy">
 
 ```console
-$ <font color="#4E9A06">fastapi</font> dev <u style="text-decoration-style:solid">main.py</u>
+$ <font color="#4E9A06">fastapi</font> dev
 
   <span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span>  Starting development server ๐Ÿš€
 
@@ -143,6 +143,55 @@ And there are dozens of alternatives, all based on OpenAPI. You could easily add
 
 You could also use it to generate code automatically, for clients that communicate with your API. For example, frontend, mobile or IoT applications.
 
+### Configure the app `entrypoint` in `pyproject.toml` { #configure-the-app-entrypoint-in-pyproject-toml }
+
+You can configure where your app is located in a `pyproject.toml` file like:
+
+```toml
+[tool.fastapi]
+entrypoint = "main:app"
+```
+
+That `entrypoint` will tell the `fastapi` command that it should import the app like:
+
+```python
+from main import app
+```
+
+If your code was structured like:
+
+```
+.
+โ”œโ”€โ”€ backend
+โ”‚ย ย  โ”œโ”€โ”€ main.py
+โ”‚ย ย  โ”œโ”€โ”€ __init__.py
+```
+
+Then you would set the `entrypoint` as:
+
+```toml
+[tool.fastapi]
+entrypoint = "backend.main:app"
+```
+
+which would be equivalent to:
+
+```python
+from backend.main import app
+```
+
+### `fastapi dev` with path { #fastapi-dev-with-path }
+
+You can also pass the file path to the `fastapi dev` command, and it will guess the FastAPI app object to use:
+
+```console
+$ fastapi dev main.py
+```
+
+But you would have to remember to pass the correct path every time you call the `fastapi` command.
+
+Additionally, other tools might not be able to find it, for example the [VS Code Extension](../editor-support.md) or [FastAPI Cloud](https://fastapicloud.com), so it is recommended to use the `entrypoint` in `pyproject.toml`.
+
 ### Deploy your app (optional) { #deploy-your-app-optional }
 
 You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapicloud.com), go and join the waiting list if you haven't. ๐Ÿš€
index f65fead6cd5354793bbd47c06b4ebfdeeccc2dfd..8a37756c703d81f7bf109519933aea19f8f4a7ea 100644 (file)
@@ -10,12 +10,12 @@ It is also built to work as a future reference so you can come back and see exac
 
 All the code blocks can be copied and used directly (they are actually tested Python files).
 
-To run any of the examples, copy the code to a file `main.py`, and start `fastapi dev` with:
+To run any of the examples, copy the code to a file `main.py`, and start `fastapi dev`:
 
 <div class="termy">
 
 ```console
-$ <font color="#4E9A06">fastapi</font> dev <u style="text-decoration-style:solid">main.py</u>
+$ <font color="#4E9A06">fastapi</font> dev
 
   <span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span>  Starting development server ๐Ÿš€
 
index 9c58c782ece5ff7b45a12254ffc548bbde340ca7..cf19f7dbdc9e4fb2312f44d5ae32865fd960bca6 100644 (file)
@@ -45,7 +45,7 @@ Run the example with:
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
index 69b174b2a8f878ee4425aa94fb444ae6c5cd525d..b8cbac295bc741298822dacfc942a590ab66fb9f 100644 (file)
@@ -152,7 +152,7 @@ You can run the app:
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
@@ -337,7 +337,7 @@ You can run the app again:
 <div class="termy">
 
 ```console
-$ fastapi dev main.py
+$ fastapi dev
 
 <span style="color: green;">INFO</span>:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```