Skip to content

Commit d4afbc0

Browse files
committed
Merge branch 'master' into feat/dutch-1
2 parents ffad5ae + 9416e89 commit d4afbc0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2348
-786
lines changed

.github/workflows/latest-changes.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ jobs:
3434
if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }}
3535
with:
3636
limit-access-to-actor: true
37-
- uses: docker://tiangolo/latest-changes:0.3.0
38-
# - uses: tiangolo/latest-changes@main
37+
- uses: tiangolo/latest-changes@0.3.1
3938
with:
4039
token: ${{ secrets.GITHUB_TOKEN }}
4140
latest_changes_file: docs/en/docs/release-notes.md

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ default_language_version:
44
python: python3.10
55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.4.0
7+
rev: v4.6.0
88
hooks:
99
- id: check-added-large-files
1010
- id: check-toml
@@ -13,7 +13,7 @@ repos:
1313
- --unsafe
1414
- id: end-of-file-fixer
1515
- id: trailing-whitespace
16-
- repo: https://github.com/charliermarsh/ruff-pre-commit
16+
- repo: https://github.com/astral-sh/ruff-pre-commit
1717
rev: v0.6.1
1818
hooks:
1919
- id: ruff

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ FastAPI stands on the shoulders of giants:
132132

133133
## Installation
134134

135+
Create and activate a <a href="https://fastapi.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install FastAPI:
136+
135137
<div class="termy">
136138

137139
```console
@@ -392,7 +394,7 @@ Coming back to the previous code example, **FastAPI** will:
392394
* Check if there is an optional query parameter named `q` (as in `http://127.0.0.1:8000/items/foo?q=somequery`) for `GET` requests.
393395
* As the `q` parameter is declared with `= None`, it is optional.
394396
* Without the `None` it would be required (as is the body in the case with `PUT`).
395-
* For `PUT` requests to `/items/{item_id}`, Read the body as JSON:
397+
* For `PUT` requests to `/items/{item_id}`, read the body as JSON:
396398
* Check that it has a required attribute `name` that should be a `str`.
397399
* Check that it has a required attribute `price` that has to be a `float`.
398400
* Check that it has an optional attribute `is_offer`, that should be a `bool`, if present.

docs/en/docs/advanced/custom-response.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ By default, **FastAPI** will return the responses using `JSONResponse`.
44

55
You can override it by returning a `Response` directly as seen in [Return a Response directly](response-directly.md){.internal-link target=_blank}.
66

7-
But if you return a `Response` directly, the data won't be automatically converted, and the documentation won't be automatically generated (for example, including the specific "media type", in the HTTP header `Content-Type` as part of the generated OpenAPI).
7+
But if you return a `Response` directly (or any subclass, like `JSONResponse`), the data won't be automatically converted (even if you declare a `response_model`), and the documentation won't be automatically generated (for example, including the specific "media type", in the HTTP header `Content-Type` as part of the generated OpenAPI).
88

9-
But you can also declare the `Response` that you want to be used, in the *path operation decorator*.
9+
But you can also declare the `Response` that you want to be used (e.g. any `Response` subclass), in the *path operation decorator* using the `response_class` parameter.
1010

1111
The contents that you return from your *path operation function* will be put inside of that `Response`.
1212

docs/en/docs/advanced/response-directly.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ This gives you a lot of flexibility. You can return any data type, override any
2828

2929
## Using the `jsonable_encoder` in a `Response`
3030

31-
Because **FastAPI** doesn't do any change to a `Response` you return, you have to make sure it's contents are ready for it.
31+
Because **FastAPI** doesn't do any change to a `Response` you return, you have to make sure its contents are ready for it.
3232

3333
For example, you cannot put a Pydantic model in a `JSONResponse` without first converting it to a `dict` with all the data types (like `datetime`, `UUID`, etc) converted to JSON-compatible types.
3434

docs/en/docs/advanced/settings.md

Lines changed: 4 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -6,143 +6,25 @@ Most of these settings are variable (can change), like database URLs. And many c
66

77
For this reason it's common to provide them in environment variables that are read by the application.
88

9-
## Environment Variables
10-
11-
/// tip
12-
13-
If you already know what "environment variables" are and how to use them, feel free to skip to the next section below.
14-
15-
///
16-
17-
An <a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">environment variable</a> (also known as "env var") is a variable that lives outside of the Python code, in the operating system, and could be read by your Python code (or by other programs as well).
18-
19-
You can create and use environment variables in the shell, without needing Python:
20-
21-
//// tab | Linux, macOS, Windows Bash
22-
23-
<div class="termy">
24-
25-
```console
26-
// You could create an env var MY_NAME with
27-
$ export MY_NAME="Wade Wilson"
28-
29-
// Then you could use it with other programs, like
30-
$ echo "Hello $MY_NAME"
31-
32-
Hello Wade Wilson
33-
```
34-
35-
</div>
36-
37-
////
38-
39-
//// tab | Windows PowerShell
40-
41-
<div class="termy">
42-
43-
```console
44-
// Create an env var MY_NAME
45-
$ $Env:MY_NAME = "Wade Wilson"
46-
47-
// Use it with other programs, like
48-
$ echo "Hello $Env:MY_NAME"
49-
50-
Hello Wade Wilson
51-
```
52-
53-
</div>
54-
55-
////
56-
57-
### Read env vars in Python
58-
59-
You could also create environment variables outside of Python, in the terminal (or with any other method), and then read them in Python.
60-
61-
For example you could have a file `main.py` with:
62-
63-
```Python hl_lines="3"
64-
import os
65-
66-
name = os.getenv("MY_NAME", "World")
67-
print(f"Hello {name} from Python")
68-
```
69-
70-
/// tip
71-
72-
The second argument to <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> is the default value to return.
73-
74-
If not provided, it's `None` by default, here we provide `"World"` as the default value to use.
75-
76-
///
77-
78-
Then you could call that Python program:
79-
80-
<div class="termy">
81-
82-
```console
83-
// Here we don't set the env var yet
84-
$ python main.py
85-
86-
// As we didn't set the env var, we get the default value
87-
88-
Hello World from Python
89-
90-
// But if we create an environment variable first
91-
$ export MY_NAME="Wade Wilson"
92-
93-
// And then call the program again
94-
$ python main.py
95-
96-
// Now it can read the environment variable
97-
98-
Hello Wade Wilson from Python
99-
```
100-
101-
</div>
102-
103-
As environment variables can be set outside of the code, but can be read by the code, and don't have to be stored (committed to `git`) with the rest of the files, it's common to use them for configurations or settings.
104-
105-
You can also create an environment variable only for a specific program invocation, that is only available to that program, and only for its duration.
106-
107-
To do that, create it right before the program itself, on the same line:
108-
109-
<div class="termy">
110-
111-
```console
112-
// Create an env var MY_NAME in line for this program call
113-
$ MY_NAME="Wade Wilson" python main.py
114-
115-
// Now it can read the environment variable
116-
117-
Hello Wade Wilson from Python
118-
119-
// The env var no longer exists afterwards
120-
$ python main.py
121-
122-
Hello World from Python
123-
```
124-
125-
</div>
126-
1279
/// tip
12810

129-
You can read more about it at <a href="https://12factor.net/config" class="external-link" target="_blank">The Twelve-Factor App: Config</a>.
11+
To understand environment variables you can read [Environment Variables](../environment-variables.md){.internal-link target=_blank}.
13012

13113
///
13214

133-
### Types and validation
15+
## Types and validation
13416

13517
These environment variables can only handle text strings, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).
13618

137-
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or validation has to be done in code.
19+
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or any validation has to be done in code.
13820

13921
## Pydantic `Settings`
14022

14123
Fortunately, Pydantic provides a great utility to handle these settings coming from environment variables with <a href="https://docs.pydantic.dev/latest/concepts/pydantic_settings/" class="external-link" target="_blank">Pydantic: Settings management</a>.
14224

14325
### Install `pydantic-settings`
14426

145-
First, install the `pydantic-settings` package:
27+
First, make sure you create your [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install the `pydantic-settings` package:
14628

14729
<div class="termy">
14830

docs/en/docs/advanced/sub-applications.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ In this case, it will be mounted at the path `/subapi`:
3636

3737
### Check the automatic API docs
3838

39-
Now, run `uvicorn` with the main app, if your file is `main.py`, it would be:
39+
Now, run the `fastapi` command with your file:
4040

4141
<div class="termy">
4242

4343
```console
44-
$ uvicorn main:app --reload
44+
$ fastapi dev main.py
4545

4646
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
4747
```

docs/en/docs/advanced/templates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ There are utilities to configure it easily that you can use directly in your **F
88

99
## Install dependencies
1010

11-
Install `jinja2`:
11+
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and install `jinja2`:
1212

1313
<div class="termy">
1414

docs/en/docs/advanced/websockets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ You can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets
44

55
## Install `WebSockets`
66

7-
First you need to install `WebSockets`:
7+
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and install `websockets`:
88

99
<div class="termy">
1010

docs/en/docs/alternatives.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ It is the recommended server for Starlette and **FastAPI**.
474474

475475
The main web server to run **FastAPI** applications.
476476

477-
You can combine it with Gunicorn, to have an asynchronous multi-process server.
477+
You can also use the `--workers` command line option to have an asynchronous multi-process server.
478478

479479
Check more details in the [Deployment](deployment/index.md){.internal-link target=_blank} section.
480480

0 commit comments

Comments
 (0)