Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
bd9c681
🍱 Add new source examples with Annotated for Query Params and String …
tiangolo Mar 17, 2023
b18ef10
πŸ“ Add new docs with Annotated for Query Params and String Validations
tiangolo Mar 17, 2023
2e9fe36
🚚 Rename incorrectly named tests for Query Params and str validations
tiangolo Mar 17, 2023
1f0e421
βœ… Add new tests with Annotated for Query Params and Sring Validations…
tiangolo Mar 17, 2023
b109870
🍱 Add new examples with Annotated for Intro to Python Types
tiangolo Mar 17, 2023
cf22b45
πŸ“ Update Python Types Intro, include Annotated
tiangolo Mar 17, 2023
9558c8b
🎨 Fix formatting in Query params and string validation, and highlight
tiangolo Mar 17, 2023
b19b086
🍱 Add new Annotated source examples for Path Params and Numeric Valid…
tiangolo Mar 17, 2023
655dc8a
πŸ“ Update docs for Path Params and Numeric Validations with Annotated
tiangolo Mar 17, 2023
4fee1e3
🍱 Add new source examples with Annotated for Body - Multiple Params
tiangolo Mar 17, 2023
7b84f2a
πŸ“ Update docs with Annotated for Body - Multiple Parameters
tiangolo Mar 17, 2023
5b2a52e
βœ… Add test for new Annotated examples in Body - Multiple Parameters
tiangolo Mar 17, 2023
e83a64f
🍱 Add new Annotated source examples for Body Fields
tiangolo Mar 17, 2023
fa5b79a
πŸ“ Update docs for Body Fields with new Annotated examples
tiangolo Mar 17, 2023
8885f73
βœ… Add new tests for new Annotated examples for Body Fields
tiangolo Mar 17, 2023
55beafd
🍱 Add new Annotated source examples for Schema Extra (Example Data)
tiangolo Mar 17, 2023
f15c5f2
πŸ“ Update docs for Schema Extra with Annotated
tiangolo Mar 17, 2023
ea65f0a
βœ… Add tests for new Annotated examples for Schema Extra
tiangolo Mar 17, 2023
2429492
🍱 Add new Annnotated source examples for Extra Data Types
tiangolo Mar 17, 2023
f4e857b
πŸ“ Update docs with Annotated for Extra Data Types
tiangolo Mar 17, 2023
7d56e7f
βœ… Add tests for new Annotated examples for Extra Data Types
tiangolo Mar 17, 2023
57a2733
🍱 Add new Annotated source examples for Cookie Parameters
tiangolo Mar 17, 2023
14746ed
πŸ“ Update docs for Cookie Parameters with Annotated examples
tiangolo Mar 17, 2023
1b4f8cf
βœ… Add tests for new Annotated source examples in Cookie Parameters
tiangolo Mar 17, 2023
1ad111b
🍱 Add new Annotated examples for Header Params
tiangolo Mar 17, 2023
540e630
πŸ“ Update docs with Annotated examples for Header Parameters
tiangolo Mar 17, 2023
d8094cf
βœ… Add tests for new Annotated examples for Header Params
tiangolo Mar 17, 2023
3b09615
🍱 Add new Annotated examples for Form Data
tiangolo Mar 17, 2023
2ae1791
πŸ“ Update Annotated docs for Form Data
tiangolo Mar 17, 2023
a026a67
βœ… Add tests for new Annotated examples in Form Data
tiangolo Mar 17, 2023
1fa1db3
🍱 Add new Annotated source examples for Request Files
tiangolo Mar 17, 2023
9db3b8e
πŸ“ Update Annotated docs for Request Files
tiangolo Mar 17, 2023
6e4bfc3
βœ… Test new Annotated examples for Request Files
tiangolo Mar 17, 2023
1850669
🍱 Add new Annotated source examples for Request Forms and Files
tiangolo Mar 17, 2023
9b5d11d
βœ… Add tests for new Anotated examples for Request Forms and Files
tiangolo Mar 17, 2023
8cfb288
🍱 Add new Annotated source examples for Dependencies and Advanced Dep…
tiangolo Mar 17, 2023
66d790b
βœ… Add tests for new Annotated dependencies
tiangolo Mar 17, 2023
95fc773
πŸ“ Add new docs for using Annotated with dependencies including type a…
tiangolo Mar 17, 2023
cf1d808
πŸ“ Update docs for Classes as Dependencies with Annotated
tiangolo Mar 17, 2023
c0bce9f
πŸ“ Update docs for Sub-dependencies with Annotated
tiangolo Mar 17, 2023
00272f5
πŸ“ Update docs for Dependencies in path operation decorators with Anno…
tiangolo Mar 17, 2023
67164b9
πŸ“ Update docs for Global Dependencies with Annotated
tiangolo Mar 17, 2023
d62c0fd
πŸ“ Update docs for Dependencies with yield with Annotated
tiangolo Mar 17, 2023
798cbed
🎨 Update format in example for dependencies with Annotated
tiangolo Mar 17, 2023
17f1f37
🍱 Add source examples with Annotated for Security
tiangolo Mar 17, 2023
72e4de7
βœ… Add tests for new Annotated examples for security
tiangolo Mar 17, 2023
9ec0dac
πŸ“ Update docs for Security - First Steps with Annotated
tiangolo Mar 17, 2023
4a2e2d1
πŸ“ Update docs for Security: Get Current User with Annotated
tiangolo Mar 17, 2023
d994b1c
πŸ“ Update docs for Simple OAuth2 with Password and Bearer with Annotated
tiangolo Mar 17, 2023
280e87d
πŸ“ Update docs for OAuth2 with Password (and hashing), Bearer with JWT…
tiangolo Mar 17, 2023
d206a74
πŸ“ Update docs for Request Forms and Files with Annotated
tiangolo Mar 17, 2023
d4518da
🍱 Add new source examples for Bigger Applications with Annotated
tiangolo Mar 17, 2023
f87c84c
βœ… Add new tests for Bigger Applications with Annotated
tiangolo Mar 17, 2023
79192a3
πŸ“ Update docs for Bigger Applications - Multiple Files with Annotated
tiangolo Mar 17, 2023
69f4b04
🍱 Add source examples for background tasks with Annotated
tiangolo Mar 17, 2023
d91a7d8
πŸ“ Update docs for Background Tasks with Annotated
tiangolo Mar 17, 2023
4f18e1b
βœ… Add test for Background Tasks with Anotated
tiangolo Mar 17, 2023
6b184e1
🍱 Add new source examples for docs for Testing with Annotated
tiangolo Mar 17, 2023
4dbb3db
πŸ“ Update docs for Testing with Annotated
tiangolo Mar 17, 2023
3628f12
βœ… Add tests for Annotated examples for Testing
tiangolo Mar 17, 2023
2f12067
🍱 Add new source examples for Additional Status Codes with Annotated
tiangolo Mar 17, 2023
6da98c3
βœ… Add tests for new Annotated examples for Additional Status Codes
tiangolo Mar 17, 2023
6b1462d
πŸ“ Update docs for Additional Status Codes with Annotated
tiangolo Mar 17, 2023
75c63e9
πŸ“ Update docs for Advanced Dependencies with Annotated
tiangolo Mar 17, 2023
711b801
πŸ“ Update docs for OAuth2 scopes with Annotated
tiangolo Mar 17, 2023
9a58c49
πŸ“ Update docs for HTTP Basic Auth with Annotated
tiangolo Mar 17, 2023
b87c620
🍱 Add source examples with Annotated for WebSockets
tiangolo Mar 17, 2023
4069f4f
βœ… Add tests for new Annotated examples for WebSockets
tiangolo Mar 17, 2023
476f464
πŸ“ Update docs for WebSockets with new Annotated examples
tiangolo Mar 17, 2023
b5ad411
🍱 Add source examples with Annotated for Settings and Environment Var…
tiangolo Mar 17, 2023
c8e472a
πŸ“ Update docs for Settings and Environment Variables with Annotated
tiangolo Mar 17, 2023
db5b265
🍱 Add new source examples for testing dependencies with Annotated
tiangolo Mar 17, 2023
9ae49d0
βœ… Add tests for new examples for testing dependencies
tiangolo Mar 17, 2023
d0fe373
πŸ“ Update docs for testing dependencies with new Annotated examples
tiangolo Mar 17, 2023
b0e7274
βœ… Update and fix marker for Python 3.9 test
tiangolo Mar 17, 2023
742da53
Merge branch 'master' into annotated-docs-tests
tiangolo Mar 17, 2023
e6d5974
πŸ”§ Update Ruff ignores for source examples in docs
tiangolo Mar 17, 2023
87d56fa
βœ… Fix some tests in the grid for Python 3.9 (incorrectly testing 3.10)
tiangolo Mar 17, 2023
df130dd
πŸ”₯ Remove source examples and tests for (non existent) docs section ab…
tiangolo Mar 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
38 changes: 35 additions & 3 deletions docs/en/docs/advanced/additional-status-codes.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,41 @@ But you also want it to accept new items. And when the items didn't exist before

To achieve that, import `JSONResponse`, and return your content there directly, setting the `status_code` that you want:

```Python hl_lines="4 25"
{!../../../docs_src/additional_status_codes/tutorial001.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="4 26"
{!> ../../../docs_src/additional_status_codes/tutorial001_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001_an_py39.py!}
```

=== "Python 3.10 and above"

```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001_an_py310.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="4 25"
{!> ../../../docs_src/additional_status_codes/tutorial001.py!}
```

=== "Python 3.10 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="2 23"
{!> ../../../docs_src/additional_status_codes/tutorial001_py310.py!}
```

!!! warning
When you return a `Response` directly, like in the example above, it will be returned directly.
Expand Down
92 changes: 80 additions & 12 deletions docs/en/docs/advanced/advanced-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,80 @@ Not the class itself (which is already a callable), but an instance of that clas

To do that, we declare a method `__call__`:

```Python hl_lines="10"
{!../../../docs_src/dependencies/tutorial011.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="11"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="12"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="10"
{!> ../../../docs_src/dependencies/tutorial011.py!}
```

In this case, this `__call__` is what **FastAPI** will use to check for additional parameters and sub-dependencies, and this is what will be called to pass a value to the parameter in your *path operation function* later.

## Parameterize the instance

And now, we can use `__init__` to declare the parameters of the instance that we can use to "parameterize" the dependency:

```Python hl_lines="7"
{!../../../docs_src/dependencies/tutorial011.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="8"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="9"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="7"
{!> ../../../docs_src/dependencies/tutorial011.py!}
```

In this case, **FastAPI** won't ever touch or care about `__init__`, we will use it directly in our code.

## Create an instance

We could create an instance of this class with:

```Python hl_lines="16"
{!../../../docs_src/dependencies/tutorial011.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="17"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="18"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="16"
{!> ../../../docs_src/dependencies/tutorial011.py!}
```

And that way we are able to "parameterize" our dependency, that now has `"bar"` inside of it, as the attribute `checker.fixed_content`.

Expand All @@ -56,9 +107,26 @@ checker(q="somequery")

...and pass whatever that returns as the value of the dependency in our *path operation function* as the parameter `fixed_content_included`:

```Python hl_lines="20"
{!../../../docs_src/dependencies/tutorial011.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="21"
{!> ../../../docs_src/dependencies/tutorial011_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="22"
{!> ../../../docs_src/dependencies/tutorial011_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="20"
{!> ../../../docs_src/dependencies/tutorial011.py!}
```

!!! tip
All this might seem contrived. And it might not be very clear how is it useful yet.
Expand Down
69 changes: 60 additions & 9 deletions docs/en/docs/advanced/security/http-basic-auth.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,26 @@ Then, when you type that username and password, the browser sends them in the he
* It returns an object of type `HTTPBasicCredentials`:
* It contains the `username` and `password` sent.

```Python hl_lines="2 6 10"
{!../../../docs_src/security/tutorial006.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="2 7 11"
{!> ../../../docs_src/security/tutorial006_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="4 8 12"
{!> ../../../docs_src/security/tutorial006_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="2 6 10"
{!> ../../../docs_src/security/tutorial006.py!}
```

When you try to open the URL for the first time (or click the "Execute" button in the docs) the browser will ask you for your username and password:

Expand All @@ -42,9 +59,26 @@ To handle that, we first convert the `username` and `password` to `bytes` encodi

Then we can use `secrets.compare_digest()` to ensure that `credentials.username` is `"stanleyjobson"`, and that `credentials.password` is `"swordfish"`.

```Python hl_lines="1 11-21"
{!../../../docs_src/security/tutorial007.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="1 12-24"
{!> ../../../docs_src/security/tutorial007_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="1 12-24"
{!> ../../../docs_src/security/tutorial007_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="1 11-21"
{!> ../../../docs_src/security/tutorial007.py!}
```

This would be similar to:

Expand Down Expand Up @@ -108,6 +142,23 @@ That way, using `secrets.compare_digest()` in your application code, it will be

After detecting that the credentials are incorrect, return an `HTTPException` with a status code 401 (the same returned when no credentials are provided) and add the header `WWW-Authenticate` to make the browser show the login prompt again:

```Python hl_lines="23-27"
{!../../../docs_src/security/tutorial007.py!}
```
=== "Python 3.6 and above"

```Python hl_lines="26-30"
{!> ../../../docs_src/security/tutorial007_an.py!}
```

=== "Python 3.9 and above"

```Python hl_lines="26-30"
{!> ../../../docs_src/security/tutorial007_an_py39.py!}
```

=== "Python 3.6 and above - non-Annotated"

!!! tip
Try to use the main, `Annotated` version better.

```Python hl_lines="23-27"
{!> ../../../docs_src/security/tutorial007.py!}
```
Loading