You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<summary>About the command <code>fastapi dev main.py</code>...</summary>
241
+
<summary>About the command <code>fastapi dev</code>...</summary>
242
242
243
-
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).
243
+
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).
244
244
245
245
By default, `fastapi dev` will start with auto-reload enabled for local development.
246
246
@@ -459,20 +459,6 @@ You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapiclo
459
459
460
460
If you already have a **FastAPI Cloud** account (we invited you from the waiting list 😉), you can deploy your application with one command.
Copy file name to clipboardExpand all lines: docs/en/docs/fastapi-cli.md
+60-7Lines changed: 60 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
# FastAPI CLI { #fastapi-cli }
2
2
3
-
**FastAPI CLI** is a command line program that you can use to serve your FastAPI app, manage your FastAPI project, and more.
3
+
**FastAPI <abbrtitle="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.
4
4
5
-
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.
5
+
When you install FastAPI (e.g. with `pip install "fastapi[standard]"`), it comes with a command line program you can run in the terminal.
6
6
7
7
To run your FastAPI app for development, you can use the `fastapi dev` command:
<span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span> Starting development server 🚀
15
15
@@ -46,14 +46,67 @@ $ <font color="#4E9A06">fastapi</font> dev <u style="text-decoration-style:solid
46
46
47
47
</div>
48
48
49
-
The command line program called `fastapi` is **FastAPI CLI**.
49
+
/// tip
50
50
51
-
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.
51
+
For production you would use `fastapi run` instead of `fastapi dev`. 🚀
52
52
53
-
For production you would use `fastapi run` instead. 🚀
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).
58
+
59
+
But you can configure explicitly the app to use.
60
+
61
+
## Configure the app `entrypoint` in `pyproject.toml` { #configure-the-app-entrypoint-in-pyproject-toml }
62
+
63
+
You can configure where your app is located in a `pyproject.toml` file like:
64
+
65
+
```toml
66
+
[tool.fastapi]
67
+
entrypoint = "main:app"
68
+
```
69
+
70
+
That `entrypoint` will tell the `fastapi` command that it should import the app like:
71
+
72
+
```python
73
+
from main import app
74
+
```
75
+
76
+
If your code was structured like:
77
+
78
+
```
79
+
.
80
+
├── backend
81
+
│ ├── main.py
82
+
│ ├── __init__.py
83
+
```
84
+
85
+
Then you would set the `entrypoint` as:
86
+
87
+
```toml
88
+
[tool.fastapi]
89
+
entrypoint = "backend.main:app"
90
+
```
91
+
92
+
which would be equivalent to:
93
+
94
+
```python
95
+
from backend.main import app
96
+
```
97
+
98
+
### `fastapi dev` with path { #fastapi-dev-with-path }
99
+
100
+
You can also pass the file path to the `fastapi dev` command, and it will guess the FastAPI app object to use:
101
+
102
+
```console
103
+
$ fastapi dev main.py
104
+
```
105
+
106
+
But you would have to remember to pass the correct path every time you call the `fastapi` command.
107
+
108
+
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`.
109
+
57
110
## `fastapi dev` { #fastapi-dev }
58
111
59
112
Running `fastapi dev` initiates development mode.
@@ -62,7 +115,7 @@ By default, **auto-reload** is enabled, automatically reloading the server when
62
115
63
116
## `fastapi run` { #fastapi-run }
64
117
65
-
Executing `fastapi run` starts FastAPI in production mode by default.
118
+
Executing `fastapi run` starts FastAPI in production mode.
66
119
67
120
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.
<summary>About the command <code>fastapi dev main.py</code>...</summary>
238
+
<summary>About the command <code>fastapi dev</code>...</summary>
239
239
240
-
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).
240
+
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).
241
241
242
242
By default, `fastapi dev` will start with auto-reload enabled for local development.
243
243
@@ -456,20 +456,6 @@ You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapiclo
456
456
457
457
If you already have a **FastAPI Cloud** account (we invited you from the waiting list 😉), you can deploy your application with one command.
Copy file name to clipboardExpand all lines: docs/en/docs/tutorial/bigger-applications.md
+32-1Lines changed: 32 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -465,14 +465,45 @@ As we cannot just isolate them and "mount" them independently of the rest, the *
465
465
466
466
///
467
467
468
+
## Configure the `entrypoint` in `pyproject.toml` { #configure-the-entrypoint-in-pyproject-toml }
469
+
470
+
As your FastAPI `app` object lives in `app/main.py`, you can configure the `entrypoint` in your `pyproject.toml` file like this:
471
+
472
+
```toml
473
+
[tool.fastapi]
474
+
entrypoint = "app.main:app"
475
+
```
476
+
477
+
that is equivalent to importing like:
478
+
479
+
```python
480
+
from app.main import app
481
+
```
482
+
483
+
That way the `fastapi` command will know where to find your app.
484
+
485
+
/// Note
486
+
487
+
You could also pass the path to the command, like:
488
+
489
+
```console
490
+
$ fastapi dev app/main.py
491
+
```
492
+
493
+
But you would have to remember to pass the correct path every time you call the `fastapi` command.
494
+
495
+
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`.
496
+
497
+
///
498
+
468
499
## Check the automatic API docs { #check-the-automatic-api-docs }
469
500
470
501
Now, run your app:
471
502
472
503
<divclass="termy">
473
504
474
505
```console
475
-
$ fastapi dev app/main.py
506
+
$ fastapi dev
476
507
477
508
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
<span style="background-color:#009485"><font color="#D3D7CF"> FastAPI </font></span> Starting development server 🚀
17
17
@@ -143,6 +143,55 @@ And there are dozens of alternatives, all based on OpenAPI. You could easily add
143
143
144
144
You could also use it to generate code automatically, for clients that communicate with your API. For example, frontend, mobile or IoT applications.
145
145
146
+
### Configure the app `entrypoint` in `pyproject.toml` { #configure-the-app-entrypoint-in-pyproject-toml }
147
+
148
+
You can configure where your app is located in a `pyproject.toml` file like:
149
+
150
+
```toml
151
+
[tool.fastapi]
152
+
entrypoint = "main:app"
153
+
```
154
+
155
+
That `entrypoint` will tell the `fastapi` command that it should import the app like:
156
+
157
+
```python
158
+
from main import app
159
+
```
160
+
161
+
If your code was structured like:
162
+
163
+
```
164
+
.
165
+
├── backend
166
+
│ ├── main.py
167
+
│ ├── __init__.py
168
+
```
169
+
170
+
Then you would set the `entrypoint` as:
171
+
172
+
```toml
173
+
[tool.fastapi]
174
+
entrypoint = "backend.main:app"
175
+
```
176
+
177
+
which would be equivalent to:
178
+
179
+
```python
180
+
from backend.main import app
181
+
```
182
+
183
+
### `fastapi dev` with path { #fastapi-dev-with-path }
184
+
185
+
You can also pass the file path to the `fastapi dev` command, and it will guess the FastAPI app object to use:
186
+
187
+
```console
188
+
$ fastapi dev main.py
189
+
```
190
+
191
+
But you would have to remember to pass the correct path every time you call the `fastapi` command.
192
+
193
+
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`.
194
+
146
195
### Deploy your app (optional) { #deploy-your-app-optional }
147
196
148
197
You can optionally deploy your FastAPI app to [FastAPI Cloud](https://fastapicloud.com), go and join the waiting list if you haven't. 🚀
0 commit comments