mirror of https://github.com/tiangolo/fastapi.git
Compare commits
76 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
272204c0c7 | |
|
|
818ce0fa2f | |
|
|
ed20bf6bf3 | |
|
|
58bc4a15ac | |
|
|
9be5063396 | |
|
|
4a6a87674a | |
|
|
01bb87275b | |
|
|
9a03503542 | |
|
|
e5d0e78bd4 | |
|
|
c4fb93f9c2 | |
|
|
98bee09a6a | |
|
|
c68dc2d419 | |
|
|
ec287a329b | |
|
|
c0e4b9cd67 | |
|
|
c98485514c | |
|
|
6281f8721a | |
|
|
75ad0a0f8c | |
|
|
da83d79546 | |
|
|
f43cba7e78 | |
|
|
cbbb11f4df | |
|
|
532ba725a5 | |
|
|
886b367a8c | |
|
|
41d1b84bd5 | |
|
|
5da1cb0792 | |
|
|
f9397e93b5 | |
|
|
2e7aaea524 | |
|
|
4414cd849d | |
|
|
c548348386 | |
|
|
61ffa3eb82 | |
|
|
59917ab679 | |
|
|
1163dbd17f | |
|
|
435d839c72 | |
|
|
b1d9769f97 | |
|
|
89157a803c | |
|
|
d86c47477e | |
|
|
3fe6522aae | |
|
|
80d1f732e5 | |
|
|
c0556ac3a5 | |
|
|
1fcec88ad2 | |
|
|
f8b216df30 | |
|
|
4b905b614c | |
|
|
6c54bcefd3 | |
|
|
475ce41268 | |
|
|
564a4ac1b8 | |
|
|
931e80f20c | |
|
|
a7ba9932ba | |
|
|
009c8af7fe | |
|
|
4c4d520198 | |
|
|
1cf7cd8af0 | |
|
|
4a9f13763d | |
|
|
30747a69c8 | |
|
|
cd9d093f60 | |
|
|
4a98a66778 | |
|
|
442cb306f6 | |
|
|
7b0b915749 | |
|
|
96bdde376f | |
|
|
7ba042e069 | |
|
|
60699f306b | |
|
|
ae7af59c6d | |
|
|
42b250d14d | |
|
|
71a17b5932 | |
|
|
9475024640 | |
|
|
5b28a04d55 | |
|
|
8cedb742cb | |
|
|
320e7ce8fd | |
|
|
81517f66cc | |
|
|
b5ca13249e | |
|
|
a2cef707e3 | |
|
|
5b6245666b | |
|
|
dbd34f1578 | |
|
|
e1117f7550 | |
|
|
08b09e5236 | |
|
|
e7d7038dfa | |
|
|
da0ffab0b2 | |
|
|
516169428d | |
|
|
812a1926f0 |
|
|
@ -13,7 +13,6 @@ env:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
smokeshow:
|
smokeshow:
|
||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
|
@ -24,12 +23,10 @@ jobs:
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- uses: actions/setup-python@v6
|
- uses: actions/setup-python@v6
|
||||||
with:
|
with:
|
||||||
python-version: '3.9'
|
python-version: '3.13'
|
||||||
- name: Setup uv
|
- name: Setup uv
|
||||||
uses: astral-sh/setup-uv@v7
|
uses: astral-sh/setup-uv@v7
|
||||||
with:
|
with:
|
||||||
version: "0.4.15"
|
|
||||||
enable-cache: true
|
|
||||||
cache-dependency-glob: |
|
cache-dependency-glob: |
|
||||||
requirements**.txt
|
requirements**.txt
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
|
|
|
||||||
|
|
@ -31,35 +31,54 @@ jobs:
|
||||||
- name: Setup uv
|
- name: Setup uv
|
||||||
uses: astral-sh/setup-uv@v7
|
uses: astral-sh/setup-uv@v7
|
||||||
with:
|
with:
|
||||||
version: "0.4.15"
|
|
||||||
enable-cache: true
|
|
||||||
cache-dependency-glob: |
|
cache-dependency-glob: |
|
||||||
requirements**.txt
|
requirements**.txt
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: uv pip install -r requirements-tests.txt
|
run: uv pip install -r requirements-tests.txt
|
||||||
- name: Install Pydantic v2
|
|
||||||
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
|
|
||||||
- name: Lint
|
- name: Lint
|
||||||
run: bash scripts/lint.sh
|
run: bash scripts/lint.sh
|
||||||
|
|
||||||
test:
|
test:
|
||||||
runs-on: ubuntu-latest
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
python-version:
|
os: [ windows-latest, macos-latest ]
|
||||||
- "3.14"
|
python-version: [ "3.14" ]
|
||||||
- "3.13"
|
pydantic-version: [ "pydantic>=2.0.2,<3.0.0" ]
|
||||||
- "3.12"
|
include:
|
||||||
- "3.11"
|
- os: macos-latest
|
||||||
- "3.10"
|
python-version: "3.8"
|
||||||
- "3.9"
|
pydantic-version: "pydantic>=1.10.0,<2.0.0"
|
||||||
- "3.8"
|
- os: windows-latest
|
||||||
pydantic-version: ["pydantic-v1", "pydantic-v2"]
|
python-version: "3.8"
|
||||||
exclude:
|
pydantic-version: "pydantic>=2.0.2,<3.0.0"
|
||||||
- python-version: "3.14"
|
coverage: coverage
|
||||||
pydantic-version: "pydantic-v1"
|
- os: ubuntu-latest
|
||||||
|
python-version: "3.9"
|
||||||
|
pydantic-version: "pydantic>=1.10.0,<2.0.0"
|
||||||
|
coverage: coverage
|
||||||
|
- os: macos-latest
|
||||||
|
python-version: "3.10"
|
||||||
|
pydantic-version: "pydantic>=2.0.2,<3.0.0"
|
||||||
|
- os: windows-latest
|
||||||
|
python-version: "3.11"
|
||||||
|
pydantic-version: "pydantic>=1.10.0,<2.0.0"
|
||||||
|
- os: ubuntu-latest
|
||||||
|
python-version: "3.12"
|
||||||
|
pydantic-version: "pydantic>=2.0.2,<3.0.0"
|
||||||
|
- os: macos-latest
|
||||||
|
python-version: "3.13"
|
||||||
|
pydantic-version: "pydantic>=1.10.0,<2.0.0"
|
||||||
|
- os: windows-latest
|
||||||
|
python-version: "3.13"
|
||||||
|
pydantic-version: "pydantic>=2.0.2,<3.0.0"
|
||||||
|
coverage: coverage
|
||||||
|
- os: ubuntu-latest
|
||||||
|
python-version: "3.14"
|
||||||
|
pydantic-version: "pydantic>=2.0.2,<3.0.0"
|
||||||
|
coverage: coverage
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- name: Dump GitHub context
|
- name: Dump GitHub context
|
||||||
env:
|
env:
|
||||||
|
|
@ -80,12 +99,8 @@ jobs:
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
- name: Install Dependencies
|
- name: Install Dependencies
|
||||||
run: uv pip install -r requirements-tests.txt
|
run: uv pip install -r requirements-tests.txt
|
||||||
- name: Install Pydantic v1
|
- name: Install Pydantic
|
||||||
if: matrix.pydantic-version == 'pydantic-v1'
|
run: uv pip install "${{ matrix.pydantic-version }}"
|
||||||
run: uv pip install "pydantic>=1.10.0,<2.0.0"
|
|
||||||
- name: Install Pydantic v2
|
|
||||||
if: matrix.pydantic-version == 'pydantic-v2'
|
|
||||||
run: uv pip install --upgrade "pydantic>=2.0.2,<3.0.0"
|
|
||||||
# TODO: Remove this once Python 3.8 is no longer supported
|
# TODO: Remove this once Python 3.8 is no longer supported
|
||||||
- name: Install older AnyIO in Python 3.8
|
- name: Install older AnyIO in Python 3.8
|
||||||
if: matrix.python-version == '3.8'
|
if: matrix.python-version == '3.8'
|
||||||
|
|
@ -96,10 +111,12 @@ jobs:
|
||||||
env:
|
env:
|
||||||
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
|
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
|
||||||
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
|
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
|
||||||
|
# Do not store coverage for all possible combinations to avoid file size max errors in Smokeshow
|
||||||
- name: Store coverage files
|
- name: Store coverage files
|
||||||
|
if: matrix.coverage == 'coverage'
|
||||||
uses: actions/upload-artifact@v5
|
uses: actions/upload-artifact@v5
|
||||||
with:
|
with:
|
||||||
name: coverage-${{ matrix.python-version }}-${{ matrix.pydantic-version }}
|
name: coverage-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/coverage/.coverage.*') }}
|
||||||
path: coverage
|
path: coverage
|
||||||
include-hidden-files: true
|
include-hidden-files: true
|
||||||
|
|
||||||
|
|
@ -133,7 +150,6 @@ jobs:
|
||||||
merge-multiple: true
|
merge-multiple: true
|
||||||
- run: ls -la coverage
|
- run: ls -la coverage
|
||||||
- run: coverage combine coverage
|
- run: coverage combine coverage
|
||||||
- run: coverage report
|
|
||||||
- run: coverage html --title "Coverage for ${{ github.sha }}"
|
- run: coverage html --title "Coverage for ${{ github.sha }}"
|
||||||
- name: Store coverage HTML
|
- name: Store coverage HTML
|
||||||
uses: actions/upload-artifact@v5
|
uses: actions/upload-artifact@v5
|
||||||
|
|
@ -141,6 +157,7 @@ jobs:
|
||||||
name: coverage-html
|
name: coverage-html
|
||||||
path: htmlcov
|
path: htmlcov
|
||||||
include-hidden-files: true
|
include-hidden-files: true
|
||||||
|
- run: coverage report --fail-under=100
|
||||||
|
|
||||||
# https://github.com/marketplace/actions/alls-green#why
|
# https://github.com/marketplace/actions/alls-green#why
|
||||||
check: # This job does nothing and is only used for the branch protection
|
check: # This job does nothing and is only used for the branch protection
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
name: Translate
|
name: Translate
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: "0 5 15 * *" # Run at 05:00 on the 15 of every month
|
||||||
|
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
debug_enabled:
|
debug_enabled:
|
||||||
|
|
@ -16,7 +19,7 @@ on:
|
||||||
- update-outdated
|
- update-outdated
|
||||||
- add-missing
|
- add-missing
|
||||||
- update-and-add
|
- update-and-add
|
||||||
- remove-all-removable
|
- remove-removable
|
||||||
language:
|
language:
|
||||||
description: Language to translate to as a letter code (e.g. "es" for Spanish)
|
description: Language to translate to as a letter code (e.g. "es" for Spanish)
|
||||||
type: string
|
type: string
|
||||||
|
|
@ -32,16 +35,12 @@ env:
|
||||||
UV_SYSTEM_PYTHON: 1
|
UV_SYSTEM_PYTHON: 1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
job:
|
langs:
|
||||||
if: github.repository_owner == 'fastapi'
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
permissions:
|
outputs:
|
||||||
contents: write
|
langs: ${{ steps.show-langs.outputs.langs }}
|
||||||
|
commands: ${{ steps.show-langs.outputs.commands }}
|
||||||
steps:
|
steps:
|
||||||
- name: Dump GitHub context
|
|
||||||
env:
|
|
||||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
|
||||||
run: echo "$GITHUB_CONTEXT"
|
|
||||||
- uses: actions/checkout@v6
|
- uses: actions/checkout@v6
|
||||||
- name: Set up Python
|
- name: Set up Python
|
||||||
uses: actions/setup-python@v6
|
uses: actions/setup-python@v6
|
||||||
|
|
@ -50,8 +49,45 @@ jobs:
|
||||||
- name: Setup uv
|
- name: Setup uv
|
||||||
uses: astral-sh/setup-uv@v7
|
uses: astral-sh/setup-uv@v7
|
||||||
with:
|
with:
|
||||||
version: "0.4.15"
|
cache-dependency-glob: |
|
||||||
enable-cache: true
|
requirements**.txt
|
||||||
|
pyproject.toml
|
||||||
|
- name: Install Dependencies
|
||||||
|
run: uv pip install -r requirements-github-actions.txt -r requirements-translations.txt
|
||||||
|
- name: Export Language Codes
|
||||||
|
id: show-langs
|
||||||
|
run: |
|
||||||
|
echo "langs=$(python ./scripts/translate.py llm-translatable-json)" >> $GITHUB_OUTPUT
|
||||||
|
echo "commands=$(python ./scripts/translate.py commands-json)" >> $GITHUB_OUTPUT
|
||||||
|
env:
|
||||||
|
LANGUAGE: ${{ github.event.inputs.language }}
|
||||||
|
COMMAND: ${{ github.event.inputs.command }}
|
||||||
|
|
||||||
|
translate:
|
||||||
|
if: github.repository_owner == 'fastapi'
|
||||||
|
needs: langs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
lang: ${{ fromJson(needs.langs.outputs.langs) }}
|
||||||
|
command: ${{ fromJson(needs.langs.outputs.commands) }}
|
||||||
|
permissions:
|
||||||
|
contents: write
|
||||||
|
steps:
|
||||||
|
- name: Dump GitHub context
|
||||||
|
env:
|
||||||
|
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||||
|
run: echo "$GITHUB_CONTEXT"
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
with:
|
||||||
|
fetch-depth: 0
|
||||||
|
- name: Set up Python
|
||||||
|
uses: actions/setup-python@v6
|
||||||
|
with:
|
||||||
|
python-version: "3.11"
|
||||||
|
- name: Setup uv
|
||||||
|
uses: astral-sh/setup-uv@v7
|
||||||
|
with:
|
||||||
cache-dependency-glob: |
|
cache-dependency-glob: |
|
||||||
requirements**.txt
|
requirements**.txt
|
||||||
pyproject.toml
|
pyproject.toml
|
||||||
|
|
@ -68,10 +104,11 @@ jobs:
|
||||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||||
- name: FastAPI Translate
|
- name: FastAPI Translate
|
||||||
run: |
|
run: |
|
||||||
python ./scripts/translate.py ${{ github.event.inputs.command }}
|
python ./scripts/translate.py ${{ matrix.command }}
|
||||||
python ./scripts/translate.py make-pr
|
python ./scripts/translate.py make-pr
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.FASTAPI_TRANSLATIONS }}
|
GITHUB_TOKEN: ${{ secrets.FASTAPI_TRANSLATIONS }}
|
||||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||||
LANGUAGE: ${{ github.event.inputs.language }}
|
LANGUAGE: ${{ matrix.lang }}
|
||||||
EN_PATH: ${{ github.event.inputs.en_path }}
|
EN_PATH: ${{ github.event.inputs.en_path }}
|
||||||
|
COMMAND: ${{ matrix.command }}
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,7 @@ Sie können denselben `responses`-Parameter verwenden, um verschiedene Medientyp
|
||||||
|
|
||||||
Sie können beispielsweise einen zusätzlichen Medientyp `image/png` hinzufügen und damit deklarieren, dass Ihre *Pfadoperation* ein JSON-Objekt (mit dem Medientyp `application/json`) oder ein PNG-Bild zurückgeben kann:
|
Sie können beispielsweise einen zusätzlichen Medientyp `image/png` hinzufügen und damit deklarieren, dass Ihre *Pfadoperation* ein JSON-Objekt (mit dem Medientyp `application/json`) oder ein PNG-Bild zurückgeben kann:
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial002.py hl[19:24,28] *}
|
{* ../../docs_src/additional_responses/tutorial002_py310.py hl[17:22,26] *}
|
||||||
|
|
||||||
/// note | Hinweis
|
/// note | Hinweis
|
||||||
|
|
||||||
|
|
@ -237,7 +237,7 @@ Mit dieser Technik können Sie einige vordefinierte Responses in Ihren *Pfadoper
|
||||||
|
|
||||||
Zum Beispiel:
|
Zum Beispiel:
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial004.py hl[13:17,26] *}
|
{* ../../docs_src/additional_responses/tutorial004_py310.py hl[11:15,24] *}
|
||||||
|
|
||||||
## Weitere Informationen zu OpenAPI-Responses { #more-information-about-openapi-responses }
|
## Weitere Informationen zu OpenAPI-Responses { #more-information-about-openapi-responses }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ FastAPI basiert auf **Pydantic**, und ich habe Ihnen gezeigt, wie Sie Pydantic-M
|
||||||
|
|
||||||
Aber FastAPI unterstützt auf die gleiche Weise auch die Verwendung von <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a>:
|
Aber FastAPI unterstützt auf die gleiche Weise auch die Verwendung von <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a>:
|
||||||
|
|
||||||
{* ../../docs_src/dataclasses/tutorial001.py hl[1,7:12,19:20] *}
|
{* ../../docs_src/dataclasses/tutorial001_py310.py hl[1,6:11,18:19] *}
|
||||||
|
|
||||||
Das ist dank **Pydantic** ebenfalls möglich, da es <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">`dataclasses` intern unterstützt</a>.
|
Das ist dank **Pydantic** ebenfalls möglich, da es <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">`dataclasses` intern unterstützt</a>.
|
||||||
|
|
||||||
|
|
@ -32,7 +32,7 @@ Wenn Sie jedoch eine Menge Datenklassen herumliegen haben, ist dies ein guter Tr
|
||||||
|
|
||||||
Sie können `dataclasses` auch im Parameter `response_model` verwenden:
|
Sie können `dataclasses` auch im Parameter `response_model` verwenden:
|
||||||
|
|
||||||
{* ../../docs_src/dataclasses/tutorial002.py hl[1,7:13,19] *}
|
{* ../../docs_src/dataclasses/tutorial002_py310.py hl[1,6:12,18] *}
|
||||||
|
|
||||||
Die Datenklasse wird automatisch in eine Pydantic-Datenklasse konvertiert.
|
Die Datenklasse wird automatisch in eine Pydantic-Datenklasse konvertiert.
|
||||||
|
|
||||||
|
|
@ -48,7 +48,7 @@ In einigen Fällen müssen Sie möglicherweise immer noch Pydantics Version von
|
||||||
|
|
||||||
In diesem Fall können Sie einfach die Standard-`dataclasses` durch `pydantic.dataclasses` ersetzen, was einen direkten Ersatz darstellt:
|
In diesem Fall können Sie einfach die Standard-`dataclasses` durch `pydantic.dataclasses` ersetzen, was einen direkten Ersatz darstellt:
|
||||||
|
|
||||||
{* ../../docs_src/dataclasses/tutorial003.py hl[1,5,8:11,14:17,23:25,28] *}
|
{* ../../docs_src/dataclasses/tutorial003_py310.py hl[1,4,7:10,13:16,22:24,27] *}
|
||||||
|
|
||||||
1. Wir importieren `field` weiterhin von Standard-`dataclasses`.
|
1. Wir importieren `field` weiterhin von Standard-`dataclasses`.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ Sie verfügt über eine *Pfadoperation*, die einen `Invoice`-Body empfängt, und
|
||||||
|
|
||||||
Dieser Teil ist ziemlich normal, der größte Teil des Codes ist Ihnen wahrscheinlich bereits bekannt:
|
Dieser Teil ist ziemlich normal, der größte Teil des Codes ist Ihnen wahrscheinlich bereits bekannt:
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[9:13,36:53] *}
|
{* ../../docs_src/openapi_callbacks/tutorial001_py310.py hl[7:11,34:51] *}
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ Wenn Sie diese Sichtweise (des *externen Entwicklers*) vorübergehend übernehme
|
||||||
|
|
||||||
Erstellen Sie zunächst einen neuen `APIRouter`, der einen oder mehrere Callbacks enthält.
|
Erstellen Sie zunächst einen neuen `APIRouter`, der einen oder mehrere Callbacks enthält.
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[3,25] *}
|
{* ../../docs_src/openapi_callbacks/tutorial001_py310.py hl[1,23] *}
|
||||||
|
|
||||||
### Die Callback-*Pfadoperation* erstellen { #create-the-callback-path-operation }
|
### Die Callback-*Pfadoperation* erstellen { #create-the-callback-path-operation }
|
||||||
|
|
||||||
|
|
@ -101,7 +101,7 @@ Sie sollte wie eine normale FastAPI-*Pfadoperation* aussehen:
|
||||||
* Sie sollte wahrscheinlich eine Deklaration des Bodys enthalten, die sie erhalten soll, z. B. `body: InvoiceEvent`.
|
* Sie sollte wahrscheinlich eine Deklaration des Bodys enthalten, die sie erhalten soll, z. B. `body: InvoiceEvent`.
|
||||||
* Und sie könnte auch eine Deklaration der Response enthalten, die zurückgegeben werden soll, z. B. `response_model=InvoiceEventReceived`.
|
* Und sie könnte auch eine Deklaration der Response enthalten, die zurückgegeben werden soll, z. B. `response_model=InvoiceEventReceived`.
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[16:18,21:22,28:32] *}
|
{* ../../docs_src/openapi_callbacks/tutorial001_py310.py hl[14:16,19:20,26:30] *}
|
||||||
|
|
||||||
Es gibt zwei Hauptunterschiede zu einer normalen *Pfadoperation*:
|
Es gibt zwei Hauptunterschiede zu einer normalen *Pfadoperation*:
|
||||||
|
|
||||||
|
|
@ -169,7 +169,7 @@ An diesem Punkt haben Sie die benötigte(n) *Callback-Pfadoperation(en)* (diejen
|
||||||
|
|
||||||
Verwenden Sie nun den Parameter `callbacks` im *Pfadoperation-Dekorator Ihrer API*, um das Attribut `.routes` (das ist eigentlich nur eine `list`e von Routen/*Pfadoperationen*) dieses Callback-Routers zu übergeben:
|
Verwenden Sie nun den Parameter `callbacks` im *Pfadoperation-Dekorator Ihrer API*, um das Attribut `.routes` (das ist eigentlich nur eine `list`e von Routen/*Pfadoperationen*) dieses Callback-Routers zu übergeben:
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[35] *}
|
{* ../../docs_src/openapi_callbacks/tutorial001_py310.py hl[33] *}
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ Das Hinzufügen eines `\f` (ein maskiertes „Form Feed“-Zeichen) führt dazu,
|
||||||
|
|
||||||
Sie wird nicht in der Dokumentation angezeigt, aber andere Tools (z. B. Sphinx) können den Rest verwenden.
|
Sie wird nicht in der Dokumentation angezeigt, aber andere Tools (z. B. Sphinx) können den Rest verwenden.
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial004.py hl[19:29] *}
|
{* ../../docs_src/path_operation_advanced_configuration/tutorial004_py310.py hl[17:27] *}
|
||||||
|
|
||||||
## Zusätzliche Responses { #additional-responses }
|
## Zusätzliche Responses { #additional-responses }
|
||||||
|
|
||||||
|
|
@ -155,13 +155,13 @@ In der folgenden Anwendung verwenden wir beispielsweise weder die integrierte Fu
|
||||||
|
|
||||||
//// tab | Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007.py hl[17:22, 24] *}
|
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_py39.py hl[15:20, 22] *}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
//// tab | Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py hl[17:22, 24] *}
|
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1_py39.py hl[15:20, 22] *}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
@ -179,13 +179,13 @@ Und dann parsen wir in unserem Code diesen YAML-Inhalt direkt und verwenden dann
|
||||||
|
|
||||||
//// tab | Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007.py hl[26:33] *}
|
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_py39.py hl[24:31] *}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
//// tab | Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1.py hl[26:33] *}
|
{* ../../docs_src/path_operation_advanced_configuration/tutorial007_pv1_py39.py hl[24:31] *}
|
||||||
|
|
||||||
////
|
////
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ Sie können beispielsweise kein Pydantic-Modell in eine `JSONResponse` einfügen
|
||||||
|
|
||||||
In diesen Fällen können Sie den `jsonable_encoder` verwenden, um Ihre Daten zu konvertieren, bevor Sie sie an eine Response übergeben:
|
In diesen Fällen können Sie den `jsonable_encoder` verwenden, um Ihre Daten zu konvertieren, bevor Sie sie an eine Response übergeben:
|
||||||
|
|
||||||
{* ../../docs_src/response_directly/tutorial001.py hl[6:7,21:22] *}
|
{* ../../docs_src/response_directly/tutorial001_py310.py hl[5:6,20:21] *}
|
||||||
|
|
||||||
/// note | Technische Details
|
/// note | Technische Details
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,7 @@ Dies könnte besonders beim Testen nützlich sein, da es sehr einfach ist, eine
|
||||||
|
|
||||||
Ausgehend vom vorherigen Beispiel könnte Ihre Datei `config.py` so aussehen:
|
Ausgehend vom vorherigen Beispiel könnte Ihre Datei `config.py` so aussehen:
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/config.py hl[10] *}
|
{* ../../docs_src/settings/app02_an_py39/config.py hl[10] *}
|
||||||
|
|
||||||
Beachten Sie, dass wir jetzt keine Standardinstanz `settings = Settings()` erstellen.
|
Beachten Sie, dass wir jetzt keine Standardinstanz `settings = Settings()` erstellen.
|
||||||
|
|
||||||
|
|
@ -174,7 +174,7 @@ Und dann können wir das von der *Pfadoperation-Funktion* als Abhängigkeit einf
|
||||||
|
|
||||||
Dann wäre es sehr einfach, beim Testen ein anderes Einstellungsobjekt bereitzustellen, indem man eine Abhängigkeitsüberschreibung für `get_settings` erstellt:
|
Dann wäre es sehr einfach, beim Testen ein anderes Einstellungsobjekt bereitzustellen, indem man eine Abhängigkeitsüberschreibung für `get_settings` erstellt:
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/test_main.py hl[9:10,13,21] *}
|
{* ../../docs_src/settings/app02_an_py39/test_main.py hl[9:10,13,21] *}
|
||||||
|
|
||||||
Bei der Abhängigkeitsüberschreibung legen wir einen neuen Wert für `admin_email` fest, wenn wir das neue `Settings`-Objekt erstellen, und geben dann dieses neue Objekt zurück.
|
Bei der Abhängigkeitsüberschreibung legen wir einen neuen Wert für `admin_email` fest, wenn wir das neue `Settings`-Objekt erstellen, und geben dann dieses neue Objekt zurück.
|
||||||
|
|
||||||
|
|
@ -217,7 +217,7 @@ Und dann aktualisieren Sie Ihre `config.py` mit:
|
||||||
|
|
||||||
//// tab | Pydantic v2
|
//// tab | Pydantic v2
|
||||||
|
|
||||||
{* ../../docs_src/settings/app03_an/config.py hl[9] *}
|
{* ../../docs_src/settings/app03_an_py39/config.py hl[9] *}
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
@ -229,7 +229,7 @@ Das Attribut `model_config` wird nur für die Pydantic-Konfiguration verwendet.
|
||||||
|
|
||||||
//// tab | Pydantic v1
|
//// tab | Pydantic v1
|
||||||
|
|
||||||
{* ../../docs_src/settings/app03_an/config_pv1.py hl[9:10] *}
|
{* ../../docs_src/settings/app03_an_py39/config_pv1.py hl[9:10] *}
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ FastAPI enthält einige Defaultkonfigurationsparameter, die für die meisten Anw
|
||||||
|
|
||||||
Es umfasst die folgenden Defaultkonfigurationen:
|
Es umfasst die folgenden Defaultkonfigurationen:
|
||||||
|
|
||||||
{* ../../fastapi/openapi/docs.py ln[8:23] hl[17:23] *}
|
{* ../../fastapi/openapi/docs.py ln[9:24] hl[18:24] *}
|
||||||
|
|
||||||
Sie können jede davon überschreiben, indem Sie im Argument `swagger_ui_parameters` einen anderen Wert festlegen.
|
Sie können jede davon überschreiben, indem Sie im Argument `swagger_ui_parameters` einen anderen Wert festlegen.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ Wenn der Header kein `gzip` enthält, wird nicht versucht, den Body zu dekomprim
|
||||||
|
|
||||||
Auf diese Weise kann dieselbe Routenklasse gzip-komprimierte oder unkomprimierte Requests verarbeiten.
|
Auf diese Weise kann dieselbe Routenklasse gzip-komprimierte oder unkomprimierte Requests verarbeiten.
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial001.py hl[8:15] *}
|
{* ../../docs_src/custom_request_and_route/tutorial001_an_py310.py hl[9:16] *}
|
||||||
|
|
||||||
### Eine benutzerdefinierte `GzipRoute`-Klasse erstellen { #create-a-custom-gziproute-class }
|
### Eine benutzerdefinierte `GzipRoute`-Klasse erstellen { #create-a-custom-gziproute-class }
|
||||||
|
|
||||||
|
|
@ -54,7 +54,7 @@ Diese Methode gibt eine Funktion zurück. Und diese Funktion empfängt einen <ab
|
||||||
|
|
||||||
Hier verwenden wir sie, um aus dem ursprünglichen Request einen `GzipRequest` zu erstellen.
|
Hier verwenden wir sie, um aus dem ursprünglichen Request einen `GzipRequest` zu erstellen.
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial001.py hl[18:26] *}
|
{* ../../docs_src/custom_request_and_route/tutorial001_an_py310.py hl[19:27] *}
|
||||||
|
|
||||||
/// note | Technische Details
|
/// note | Technische Details
|
||||||
|
|
||||||
|
|
@ -92,18 +92,18 @@ Wir können denselben Ansatz auch verwenden, um in einem Exceptionhandler auf de
|
||||||
|
|
||||||
Alles, was wir tun müssen, ist, den Request innerhalb eines `try`/`except`-Blocks zu handhaben:
|
Alles, was wir tun müssen, ist, den Request innerhalb eines `try`/`except`-Blocks zu handhaben:
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial002.py hl[13,15] *}
|
{* ../../docs_src/custom_request_and_route/tutorial002_an_py310.py hl[14,16] *}
|
||||||
|
|
||||||
Wenn eine Exception auftritt, befindet sich die `Request`-Instanz weiterhin im Gültigkeitsbereich, sodass wir den Requestbody lesen und bei der Fehlerbehandlung verwenden können:
|
Wenn eine Exception auftritt, befindet sich die `Request`-Instanz weiterhin im Gültigkeitsbereich, sodass wir den Requestbody lesen und bei der Fehlerbehandlung verwenden können:
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial002.py hl[16:18] *}
|
{* ../../docs_src/custom_request_and_route/tutorial002_an_py310.py hl[17:19] *}
|
||||||
|
|
||||||
## Benutzerdefinierte `APIRoute`-Klasse in einem Router { #custom-apiroute-class-in-a-router }
|
## Benutzerdefinierte `APIRoute`-Klasse in einem Router { #custom-apiroute-class-in-a-router }
|
||||||
|
|
||||||
Sie können auch den Parameter `route_class` eines `APIRouter` festlegen:
|
Sie können auch den Parameter `route_class` eines `APIRouter` festlegen:
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial003.py hl[26] *}
|
{* ../../docs_src/custom_request_and_route/tutorial003_py310.py hl[26] *}
|
||||||
|
|
||||||
In diesem Beispiel verwenden die *Pfadoperationen* unter dem `router` die benutzerdefinierte `TimedRoute`-Klasse und haben in der Response einen zusätzlichen `X-Response-Time`-Header mit der Zeit, die zum Generieren der Response benötigt wurde:
|
In diesem Beispiel verwenden die *Pfadoperationen* unter dem `router` die benutzerdefinierte `TimedRoute`-Klasse und haben in der Response einen zusätzlichen `X-Response-Time`-Header mit der Zeit, die zum Generieren der Response benötigt wurde:
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial003.py hl[13:20] *}
|
{* ../../docs_src/custom_request_and_route/tutorial003_py310.py hl[13:20] *}
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ GitHub-Repository: <a href="https://github.com/tiangolo/full-stack-fastapi-templ
|
||||||
- 💾 [PostgreSQL](https://www.postgresql.org) als SQL-Datenbank.
|
- 💾 [PostgreSQL](https://www.postgresql.org) als SQL-Datenbank.
|
||||||
- 🚀 [React](https://react.dev) für das Frontend.
|
- 🚀 [React](https://react.dev) für das Frontend.
|
||||||
- 💃 Verwendung von TypeScript, Hooks, [Vite](https://vitejs.dev) und anderen Teilen eines modernen Frontend-Stacks.
|
- 💃 Verwendung von TypeScript, Hooks, [Vite](https://vitejs.dev) und anderen Teilen eines modernen Frontend-Stacks.
|
||||||
- 🎨 [Chakra UI](https://chakra-ui.com) für die Frontend-Komponenten.
|
- 🎨 [Tailwind CSS](https://tailwindcss.com) und [shadcn/ui](https://ui.shadcn.com) für die Frontend-Komponenten.
|
||||||
- 🤖 Ein automatisch generierter Frontend-Client.
|
- 🤖 Ein automatisch generierter Frontend-Client.
|
||||||
- 🧪 [Playwright](https://playwright.dev) für End-to-End-Tests.
|
- 🧪 [Playwright](https://playwright.dev) für End-to-End-Tests.
|
||||||
- 🦇 Unterstützung des Dunkelmodus.
|
- 🦇 „Dark-Mode“-Unterstützung.
|
||||||
- 🐋 [Docker Compose](https://www.docker.com) für Entwicklung und Produktion.
|
- 🐋 [Docker Compose](https://www.docker.com) für Entwicklung und Produktion.
|
||||||
- 🔒 Sicheres Passwort-Hashing standardmäßig.
|
- 🔒 Sicheres Passwort-Hashing standardmäßig.
|
||||||
- 🔑 JWT-Token-Authentifizierung.
|
- 🔑 JWT (JSON Web Token)-Token-Authentifizierung.
|
||||||
- 📫 E-Mail-basierte Passwortwiederherstellung.
|
- 📫 E-Mail-basierte Passwortwiederherstellung.
|
||||||
- ✅ Tests mit [Pytest](https://pytest.org).
|
- ✅ Tests mit [Pytest](https://pytest.org).
|
||||||
- 📞 [Traefik](https://traefik.io) als Reverse-Proxy / Load Balancer.
|
- 📞 [Traefik](https://traefik.io) als Reverse-Proxy / Load Balancer.
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,3 @@
|
||||||
# Ressourcen { #resources }
|
# Ressourcen { #resources }
|
||||||
|
|
||||||
Zusätzliche Ressourcen, externe Links, Artikel und mehr. ✈️
|
Zusätzliche Ressourcen, externe Links und mehr. ✈️
|
||||||
|
|
|
||||||
|
|
@ -85,9 +85,7 @@ Sie können die *Pfadoperationen* für dieses Modul mit `APIRouter` erstellen.
|
||||||
|
|
||||||
Sie importieren ihn und erstellen eine „Instanz“ auf die gleiche Weise wie mit der Klasse `FastAPI`:
|
Sie importieren ihn und erstellen eine „Instanz“ auf die gleiche Weise wie mit der Klasse `FastAPI`:
|
||||||
|
|
||||||
```Python hl_lines="1 3" title="app/routers/users.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/routers/users.py hl[1,3] title["app/routers/users.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/routers/users.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### *Pfadoperationen* mit `APIRouter` { #path-operations-with-apirouter }
|
### *Pfadoperationen* mit `APIRouter` { #path-operations-with-apirouter }
|
||||||
|
|
||||||
|
|
@ -95,9 +93,7 @@ Und dann verwenden Sie ihn, um Ihre *Pfadoperationen* zu deklarieren.
|
||||||
|
|
||||||
Verwenden Sie ihn auf die gleiche Weise wie die Klasse `FastAPI`:
|
Verwenden Sie ihn auf die gleiche Weise wie die Klasse `FastAPI`:
|
||||||
|
|
||||||
```Python hl_lines="6 11 16" title="app/routers/users.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/routers/users.py hl[6,11,16] title["app/routers/users.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/routers/users.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
Sie können sich `APIRouter` als eine „Mini-`FastAPI`“-Klasse vorstellen.
|
Sie können sich `APIRouter` als eine „Mini-`FastAPI`“-Klasse vorstellen.
|
||||||
|
|
||||||
|
|
@ -121,35 +117,7 @@ Also fügen wir sie in ihr eigenes `dependencies`-Modul (`app/dependencies.py`)
|
||||||
|
|
||||||
Wir werden nun eine einfache Abhängigkeit verwenden, um einen benutzerdefinierten `X-Token`-Header zu lesen:
|
Wir werden nun eine einfache Abhängigkeit verwenden, um einen benutzerdefinierten `X-Token`-Header zu lesen:
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
{* ../../docs_src/bigger_applications/app_an_py39/dependencies.py hl[3,6:8] title["app/dependencies.py"] *}
|
||||||
|
|
||||||
```Python hl_lines="3 6-8" title="app/dependencies.py"
|
|
||||||
{!> ../../docs_src/bigger_applications/app_an_py39/dependencies.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python hl_lines="1 5-7" title="app/dependencies.py"
|
|
||||||
{!> ../../docs_src/bigger_applications/app_an/dependencies.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | Tipp
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python hl_lines="1 4-6" title="app/dependencies.py"
|
|
||||||
{!> ../../docs_src/bigger_applications/app/dependencies.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
@ -181,9 +149,7 @@ Wir wissen, dass alle *Pfadoperationen* in diesem Modul folgendes haben:
|
||||||
|
|
||||||
Anstatt also alles zu jeder *Pfadoperation* hinzuzufügen, können wir es dem `APIRouter` hinzufügen.
|
Anstatt also alles zu jeder *Pfadoperation* hinzuzufügen, können wir es dem `APIRouter` hinzufügen.
|
||||||
|
|
||||||
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/routers/items.py hl[5:10,16,21] title["app/routers/items.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
Da der Pfad jeder *Pfadoperation* mit `/` beginnen muss, wie in:
|
Da der Pfad jeder *Pfadoperation* mit `/` beginnen muss, wie in:
|
||||||
|
|
||||||
|
|
@ -242,9 +208,7 @@ Und wir müssen die Abhängigkeitsfunktion aus dem Modul `app.dependencies` impo
|
||||||
|
|
||||||
Daher verwenden wir einen relativen Import mit `..` für die Abhängigkeiten:
|
Daher verwenden wir einen relativen Import mit `..` für die Abhängigkeiten:
|
||||||
|
|
||||||
```Python hl_lines="3" title="app/routers/items.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/routers/items.py hl[3] title["app/routers/items.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Wie relative Importe funktionieren { #how-relative-imports-work }
|
#### Wie relative Importe funktionieren { #how-relative-imports-work }
|
||||||
|
|
||||||
|
|
@ -315,9 +279,7 @@ Wir fügen weder das Präfix `/items` noch `tags=["items"]` zu jeder *Pfadoperat
|
||||||
|
|
||||||
Aber wir können immer noch _mehr_ `tags` hinzufügen, die auf eine bestimmte *Pfadoperation* angewendet werden, sowie einige zusätzliche `responses`, die speziell für diese *Pfadoperation* gelten:
|
Aber wir können immer noch _mehr_ `tags` hinzufügen, die auf eine bestimmte *Pfadoperation* angewendet werden, sowie einige zusätzliche `responses`, die speziell für diese *Pfadoperation* gelten:
|
||||||
|
|
||||||
```Python hl_lines="30-31" title="app/routers/items.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/routers/items.py hl[30:31] title["app/routers/items.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip | Tipp
|
/// tip | Tipp
|
||||||
|
|
||||||
|
|
@ -343,17 +305,13 @@ Sie importieren und erstellen wie gewohnt eine `FastAPI`-Klasse.
|
||||||
|
|
||||||
Und wir können sogar [globale Abhängigkeiten](dependencies/global-dependencies.md){.internal-link target=_blank} deklarieren, die mit den Abhängigkeiten für jeden `APIRouter` kombiniert werden:
|
Und wir können sogar [globale Abhängigkeiten](dependencies/global-dependencies.md){.internal-link target=_blank} deklarieren, die mit den Abhängigkeiten für jeden `APIRouter` kombiniert werden:
|
||||||
|
|
||||||
```Python hl_lines="1 3 7" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[1,3,7] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Den `APIRouter` importieren { #import-the-apirouter }
|
### Den `APIRouter` importieren { #import-the-apirouter }
|
||||||
|
|
||||||
Jetzt importieren wir die anderen Submodule, die `APIRouter` haben:
|
Jetzt importieren wir die anderen Submodule, die `APIRouter` haben:
|
||||||
|
|
||||||
```Python hl_lines="4-5" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[4:5] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
Da es sich bei den Dateien `app/routers/users.py` und `app/routers/items.py` um Submodule handelt, die Teil desselben Python-Packages `app` sind, können wir einen einzelnen Punkt `.` verwenden, um sie mit „relativen Imports“ zu importieren.
|
Da es sich bei den Dateien `app/routers/users.py` und `app/routers/items.py` um Submodule handelt, die Teil desselben Python-Packages `app` sind, können wir einen einzelnen Punkt `.` verwenden, um sie mit „relativen Imports“ zu importieren.
|
||||||
|
|
||||||
|
|
@ -416,17 +374,13 @@ würde der `router` von `users` den von `items` überschreiben und wir könnten
|
||||||
|
|
||||||
Um also beide in derselben Datei verwenden zu können, importieren wir die Submodule direkt:
|
Um also beide in derselben Datei verwenden zu können, importieren wir die Submodule direkt:
|
||||||
|
|
||||||
```Python hl_lines="5" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[5] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### Die `APIRouter` für `users` und `items` inkludieren { #include-the-apirouters-for-users-and-items }
|
### Die `APIRouter` für `users` und `items` inkludieren { #include-the-apirouters-for-users-and-items }
|
||||||
|
|
||||||
Inkludieren wir nun die `router` aus diesen Submodulen `users` und `items`:
|
Inkludieren wir nun die `router` aus diesen Submodulen `users` und `items`:
|
||||||
|
|
||||||
```Python hl_lines="10-11" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[10:11] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info | Info
|
/// info | Info
|
||||||
|
|
||||||
|
|
@ -466,17 +420,13 @@ Sie enthält einen `APIRouter` mit einigen administrativen *Pfadoperationen*, di
|
||||||
|
|
||||||
In diesem Beispiel wird es ganz einfach sein. Nehmen wir jedoch an, dass wir, da sie mit anderen Projekten in der Organisation geteilt wird, sie nicht ändern und kein `prefix`, `dependencies`, `tags`, usw. direkt zum `APIRouter` hinzufügen können:
|
In diesem Beispiel wird es ganz einfach sein. Nehmen wir jedoch an, dass wir, da sie mit anderen Projekten in der Organisation geteilt wird, sie nicht ändern und kein `prefix`, `dependencies`, `tags`, usw. direkt zum `APIRouter` hinzufügen können:
|
||||||
|
|
||||||
```Python hl_lines="3" title="app/internal/admin.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/internal/admin.py hl[3] title["app/internal/admin.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/internal/admin.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
Aber wir möchten immer noch ein benutzerdefiniertes `prefix` festlegen, wenn wir den `APIRouter` einbinden, sodass alle seine *Pfadoperationen* mit `/admin` beginnen, wir möchten es mit den `dependencies` sichern, die wir bereits für dieses Projekt haben, und wir möchten `tags` und `responses` hinzufügen.
|
Aber wir möchten immer noch ein benutzerdefiniertes `prefix` festlegen, wenn wir den `APIRouter` einbinden, sodass alle seine *Pfadoperationen* mit `/admin` beginnen, wir möchten es mit den `dependencies` sichern, die wir bereits für dieses Projekt haben, und wir möchten `tags` und `responses` hinzufügen.
|
||||||
|
|
||||||
Wir können das alles deklarieren, ohne den ursprünglichen `APIRouter` ändern zu müssen, indem wir diese Parameter an `app.include_router()` übergeben:
|
Wir können das alles deklarieren, ohne den ursprünglichen `APIRouter` ändern zu müssen, indem wir diese Parameter an `app.include_router()` übergeben:
|
||||||
|
|
||||||
```Python hl_lines="14-17" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[14:17] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
Auf diese Weise bleibt der ursprüngliche `APIRouter` unverändert, sodass wir dieselbe `app/internal/admin.py`-Datei weiterhin mit anderen Projekten in der Organisation teilen können.
|
Auf diese Weise bleibt der ursprüngliche `APIRouter` unverändert, sodass wir dieselbe `app/internal/admin.py`-Datei weiterhin mit anderen Projekten in der Organisation teilen können.
|
||||||
|
|
||||||
|
|
@ -497,9 +447,7 @@ Wir können *Pfadoperationen* auch direkt zur `FastAPI`-App hinzufügen.
|
||||||
|
|
||||||
Hier machen wir es ... nur um zu zeigen, dass wir es können 🤷:
|
Hier machen wir es ... nur um zu zeigen, dass wir es können 🤷:
|
||||||
|
|
||||||
```Python hl_lines="21-23" title="app/main.py"
|
{* ../../docs_src/bigger_applications/app_an_py39/main.py hl[21:23] title["app/main.py"] *}
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
und es wird korrekt funktionieren, zusammen mit allen anderen *Pfadoperationen*, die mit `app.include_router()` hinzugefügt wurden.
|
und es wird korrekt funktionieren, zusammen mit allen anderen *Pfadoperationen*, die mit `app.include_router()` hinzugefügt wurden.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ Ihre API hat jetzt die Macht, ihre eigene <abbr title="Das ist ein Scherz, nur f
|
||||||
|
|
||||||
Sie können die Modellkonfiguration von Pydantic verwenden, um `extra` Felder zu verbieten (`forbid`):
|
Sie können die Modellkonfiguration von Pydantic verwenden, um `extra` Felder zu verbieten (`forbid`):
|
||||||
|
|
||||||
{* ../../docs_src/cookie_param_models/tutorial002_an_py39.py hl[10] *}
|
{* ../../docs_src/cookie_param_models/tutorial002_an_py310.py hl[10] *}
|
||||||
|
|
||||||
Wenn ein Client versucht, einige **zusätzliche Cookies** zu senden, erhält er eine **Error-<abbr title="Response – Antwort: Daten, die der Server zum anfragenden Client zurücksendet">Response</abbr>**.
|
Wenn ein Client versucht, einige **zusätzliche Cookies** zu senden, erhält er eine **Error-<abbr title="Response – Antwort: Daten, die der Server zum anfragenden Client zurücksendet">Response</abbr>**.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -127,7 +127,7 @@ Um diesen zu überschreiben, importieren Sie den `RequestValidationError` und ve
|
||||||
|
|
||||||
Der Exceptionhandler erhält einen `Request` und die Exception.
|
Der Exceptionhandler erhält einen `Request` und die Exception.
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial004.py hl[2,14:16] *}
|
{* ../../docs_src/handling_errors/tutorial004.py hl[2,14:19] *}
|
||||||
|
|
||||||
Wenn Sie nun zu `/items/foo` gehen, erhalten Sie anstelle des standardmäßigen JSON-Fehlers mit:
|
Wenn Sie nun zu `/items/foo` gehen, erhalten Sie anstelle des standardmäßigen JSON-Fehlers mit:
|
||||||
|
|
||||||
|
|
@ -149,36 +149,17 @@ Wenn Sie nun zu `/items/foo` gehen, erhalten Sie anstelle des standardmäßigen
|
||||||
eine Textversion mit:
|
eine Textversion mit:
|
||||||
|
|
||||||
```
|
```
|
||||||
1 validation error
|
Validation errors:
|
||||||
path -> item_id
|
Field: ('path', 'item_id'), Error: Input should be a valid integer, unable to parse string as an integer
|
||||||
value is not a valid integer (type=type_error.integer)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `RequestValidationError` vs. `ValidationError` { #requestvalidationerror-vs-validationerror }
|
|
||||||
|
|
||||||
/// warning | Achtung
|
|
||||||
|
|
||||||
Dies sind technische Details, die Sie überspringen können, wenn sie für Sie jetzt nicht wichtig sind.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
`RequestValidationError` ist eine Unterklasse von Pydantics <a href="https://docs.pydantic.dev/latest/concepts/models/#error-handling" class="external-link" target="_blank">`ValidationError`</a>.
|
|
||||||
|
|
||||||
**FastAPI** verwendet diesen so, dass, wenn Sie ein Pydantic-Modell in `response_model` verwenden und Ihre Daten einen Fehler haben, Sie den Fehler in Ihrem Log sehen.
|
|
||||||
|
|
||||||
Aber der Client/Benutzer wird ihn nicht sehen. Stattdessen erhält der Client einen „Internal Server Error“ mit einem HTTP-Statuscode `500`.
|
|
||||||
|
|
||||||
Es sollte so sein, denn wenn Sie einen Pydantic `ValidationError` in Ihrer *Response* oder irgendwo anders in Ihrem Code haben (nicht im *Request* des Clients), ist es tatsächlich ein Fehler in Ihrem Code.
|
|
||||||
|
|
||||||
Und während Sie den Fehler beheben, sollten Ihre Clients/Benutzer keinen Zugriff auf interne Informationen über den Fehler haben, da das eine Sicherheitslücke aufdecken könnte.
|
|
||||||
|
|
||||||
### Überschreiben des `HTTPException`-Fehlerhandlers { #override-the-httpexception-error-handler }
|
### Überschreiben des `HTTPException`-Fehlerhandlers { #override-the-httpexception-error-handler }
|
||||||
|
|
||||||
Auf die gleiche Weise können Sie den `HTTPException`-Handler überschreiben.
|
Auf die gleiche Weise können Sie den `HTTPException`-Handler überschreiben.
|
||||||
|
|
||||||
Zum Beispiel könnten Sie eine Klartext-Response statt JSON für diese Fehler zurückgeben wollen:
|
Zum Beispiel könnten Sie eine Klartext-Response statt JSON für diese Fehler zurückgeben wollen:
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial004.py hl[3:4,9:11,22] *}
|
{* ../../docs_src/handling_errors/tutorial004.py hl[3:4,9:11,25] *}
|
||||||
|
|
||||||
/// note | Technische Details
|
/// note | Technische Details
|
||||||
|
|
||||||
|
|
@ -188,6 +169,14 @@ Sie könnten auch `from starlette.responses import PlainTextResponse` verwenden.
|
||||||
|
|
||||||
///
|
///
|
||||||
|
|
||||||
|
/// warning | Achtung
|
||||||
|
|
||||||
|
Beachten Sie, dass der `RequestValidationError` Informationen über den Dateinamen und die Zeile enthält, in der der Validierungsfehler auftritt, sodass Sie ihn bei Bedarf mit den relevanten Informationen in Ihren Logs anzeigen können.
|
||||||
|
|
||||||
|
Das bedeutet aber auch, dass, wenn Sie ihn einfach in einen String umwandeln und diese Informationen direkt zurückgeben, Sie möglicherweise ein paar Informationen über Ihr System preisgeben. Daher extrahiert und zeigt der Code hier jeden Fehler getrennt.
|
||||||
|
|
||||||
|
///
|
||||||
|
|
||||||
### Verwenden des `RequestValidationError`-Bodys { #use-the-requestvalidationerror-body }
|
### Verwenden des `RequestValidationError`-Bodys { #use-the-requestvalidationerror-body }
|
||||||
|
|
||||||
Der `RequestValidationError` enthält den empfangenen `body` mit den ungültigen Daten.
|
Der `RequestValidationError` enthält den empfangenen `body` mit den ungültigen Daten.
|
||||||
|
|
|
||||||
|
|
@ -122,63 +122,13 @@ Sie verfügt über eine `POST`-Operation, die mehrere Fehler zurückgeben könnt
|
||||||
|
|
||||||
Beide *Pfadoperationen* erfordern einen `X-Token`-Header.
|
Beide *Pfadoperationen* erfordern einen `X-Token`-Header.
|
||||||
|
|
||||||
//// tab | Python 3.10+
|
{* ../../docs_src/app_testing/app_b_an_py310/main.py *}
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/app_testing/app_b_an_py310/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.9+
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/app_testing/app_b_an_py39/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/app_testing/app_b_an/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.10+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | Tipp
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/app_testing/app_b_py310/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Python 3.8+ nicht annotiert
|
|
||||||
|
|
||||||
/// tip | Tipp
|
|
||||||
|
|
||||||
Bevorzugen Sie die `Annotated`-Version, falls möglich.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/app_testing/app_b/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### Erweiterte Testdatei { #extended-testing-file }
|
### Erweiterte Testdatei { #extended-testing-file }
|
||||||
|
|
||||||
Anschließend könnten Sie `test_main.py` mit den erweiterten Tests aktualisieren:
|
Anschließend könnten Sie `test_main.py` mit den erweiterten Tests aktualisieren:
|
||||||
|
|
||||||
{* ../../docs_src/app_testing/app_b/test_main.py *}
|
{* ../../docs_src/app_testing/app_b_an_py310/test_main.py *}
|
||||||
|
|
||||||
|
|
||||||
Wenn Sie möchten, dass der Client Informationen im Request übergibt und Sie nicht wissen, wie das geht, können Sie suchen (googeln), wie es mit `httpx` gemacht wird, oder sogar, wie es mit `requests` gemacht wird, da das Design von HTTPX auf dem Design von Requests basiert.
|
Wenn Sie möchten, dass der Client Informationen im Request übergibt und Sie nicht wissen, wie das geht, können Sie suchen (googeln), wie es mit `httpx` gemacht wird, oder sogar, wie es mit `requests` gemacht wird, da das Design von HTTPX auf dem Design von Requests basiert.
|
||||||
|
|
|
||||||
|
|
@ -1,247 +0,0 @@
|
||||||
# 🌖 📨 🗄
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👉 👍 🏧 ❔.
|
|
||||||
|
|
||||||
🚥 👆 ▶️ ⏮️ **FastAPI**, 👆 💪 🚫 💪 👉.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 💪 📣 🌖 📨, ⏮️ 🌖 👔 📟, 🔉 🆎, 📛, ♒️.
|
|
||||||
|
|
||||||
👈 🌖 📨 🔜 🔌 🗄 🔗, 👫 🔜 😑 🛠️ 🩺.
|
|
||||||
|
|
||||||
✋️ 👈 🌖 📨 👆 ✔️ ⚒ 💭 👆 📨 `Response` 💖 `JSONResponse` 🔗, ⏮️ 👆 👔 📟 & 🎚.
|
|
||||||
|
|
||||||
## 🌖 📨 ⏮️ `model`
|
|
||||||
|
|
||||||
👆 💪 🚶♀️ 👆 *➡ 🛠️ 👨🎨* 🔢 `responses`.
|
|
||||||
|
|
||||||
⚫️ 📨 `dict`, 🔑 👔 📟 🔠 📨, 💖 `200`, & 💲 🎏 `dict`Ⓜ ⏮️ ℹ 🔠 👫.
|
|
||||||
|
|
||||||
🔠 👈 📨 `dict`Ⓜ 💪 ✔️ 🔑 `model`, ⚗ Pydantic 🏷, 💖 `response_model`.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ✊ 👈 🏷, 🏗 🚮 🎻 🔗 & 🔌 ⚫️ ☑ 🥉 🗄.
|
|
||||||
|
|
||||||
🖼, 📣 ➕1️⃣ 📨 ⏮️ 👔 📟 `404` & Pydantic 🏷 `Message`, 👆 💪 ✍:
|
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial001.py hl[18,22] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
✔️ 🤯 👈 👆 ✔️ 📨 `JSONResponse` 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`model` 🔑 🚫 🍕 🗄.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ✊ Pydantic 🏷 ⚪️➡️ 📤, 🏗 `JSON Schema`, & 🚮 ⚫️ ☑ 🥉.
|
|
||||||
|
|
||||||
☑ 🥉:
|
|
||||||
|
|
||||||
* 🔑 `content`, 👈 ✔️ 💲 ➕1️⃣ 🎻 🎚 (`dict`) 👈 🔌:
|
|
||||||
* 🔑 ⏮️ 📻 🆎, ✅ `application/json`, 👈 🔌 💲 ➕1️⃣ 🎻 🎚, 👈 🔌:
|
|
||||||
* 🔑 `schema`, 👈 ✔️ 💲 🎻 🔗 ⚪️➡️ 🏷, 📥 ☑ 🥉.
|
|
||||||
* **FastAPI** 🚮 🔗 📥 🌐 🎻 🔗 ➕1️⃣ 🥉 👆 🗄 ↩️ ✅ ⚫️ 🔗. 👉 🌌, 🎏 🈸 & 👩💻 💪 ⚙️ 👈 🎻 🔗 🔗, 🚚 👻 📟 ⚡ 🧰, ♒️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🏗 📨 🗄 👉 *➡ 🛠️* 🔜:
|
|
||||||
|
|
||||||
```JSON hl_lines="3-12"
|
|
||||||
{
|
|
||||||
"responses": {
|
|
||||||
"404": {
|
|
||||||
"description": "Additional Response",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/Message"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"200": {
|
|
||||||
"description": "Successful Response",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/Item"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"422": {
|
|
||||||
"description": "Validation Error",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/HTTPValidationError"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
🔗 🔗 ➕1️⃣ 🥉 🔘 🗄 🔗:
|
|
||||||
|
|
||||||
```JSON hl_lines="4-16"
|
|
||||||
{
|
|
||||||
"components": {
|
|
||||||
"schemas": {
|
|
||||||
"Message": {
|
|
||||||
"title": "Message",
|
|
||||||
"required": [
|
|
||||||
"message"
|
|
||||||
],
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"message": {
|
|
||||||
"title": "Message",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"Item": {
|
|
||||||
"title": "Item",
|
|
||||||
"required": [
|
|
||||||
"id",
|
|
||||||
"value"
|
|
||||||
],
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"id": {
|
|
||||||
"title": "Id",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"value": {
|
|
||||||
"title": "Value",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ValidationError": {
|
|
||||||
"title": "ValidationError",
|
|
||||||
"required": [
|
|
||||||
"loc",
|
|
||||||
"msg",
|
|
||||||
"type"
|
|
||||||
],
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"loc": {
|
|
||||||
"title": "Location",
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"msg": {
|
|
||||||
"title": "Message",
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"type": {
|
|
||||||
"title": "Error Type",
|
|
||||||
"type": "string"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"HTTPValidationError": {
|
|
||||||
"title": "HTTPValidationError",
|
|
||||||
"type": "object",
|
|
||||||
"properties": {
|
|
||||||
"detail": {
|
|
||||||
"title": "Detail",
|
|
||||||
"type": "array",
|
|
||||||
"items": {
|
|
||||||
"$ref": "#/components/schemas/ValidationError"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌖 🔉 🆎 👑 📨
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 👉 🎏 `responses` 🔢 🚮 🎏 🔉 🆎 🎏 👑 📨.
|
|
||||||
|
|
||||||
🖼, 👆 💪 🚮 🌖 📻 🆎 `image/png`, 📣 👈 👆 *➡ 🛠️* 💪 📨 🎻 🎚 (⏮️ 📻 🆎 `application/json`) ⚖️ 🇩🇴 🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial002.py hl[19:24,28] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈 👆 ✔️ 📨 🖼 ⚙️ `FileResponse` 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🚥 👆 ✔ 🎏 📻 🆎 🎯 👆 `responses` 🔢, FastAPI 🔜 🤔 📨 ✔️ 🎏 📻 🆎 👑 📨 🎓 (🔢 `application/json`).
|
|
||||||
|
|
||||||
✋️ 🚥 👆 ✔️ ✔ 🛃 📨 🎓 ⏮️ `None` 🚮 📻 🆎, FastAPI 🔜 ⚙️ `application/json` 🙆 🌖 📨 👈 ✔️ 👨💼 🏷.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌀 ℹ
|
|
||||||
|
|
||||||
👆 💪 🌀 📨 ℹ ⚪️➡️ 💗 🥉, 🔌 `response_model`, `status_code`, & `responses` 🔢.
|
|
||||||
|
|
||||||
👆 💪 📣 `response_model`, ⚙️ 🔢 👔 📟 `200` (⚖️ 🛃 1️⃣ 🚥 👆 💪), & ⤴️ 📣 🌖 ℹ 👈 🎏 📨 `responses`, 🔗 🗄 🔗.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 🚧 🌖 ℹ ⚪️➡️ `responses`, & 🌀 ⚫️ ⏮️ 🎻 🔗 ⚪️➡️ 👆 🏷.
|
|
||||||
|
|
||||||
🖼, 👆 💪 📣 📨 ⏮️ 👔 📟 `404` 👈 ⚙️ Pydantic 🏷 & ✔️ 🛃 `description`.
|
|
||||||
|
|
||||||
& 📨 ⏮️ 👔 📟 `200` 👈 ⚙️ 👆 `response_model`, ✋️ 🔌 🛃 `example`:
|
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial003.py hl[20:31] *}
|
|
||||||
|
|
||||||
⚫️ 🔜 🌐 🌀 & 🔌 👆 🗄, & 🎦 🛠️ 🩺:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/additional-responses/image01.png">
|
|
||||||
|
|
||||||
## 🌀 🔢 📨 & 🛃 🕐
|
|
||||||
|
|
||||||
👆 💪 💚 ✔️ 🔁 📨 👈 ✔ 📚 *➡ 🛠️*, ✋️ 👆 💚 🌀 👫 ⏮️ 🛃 📨 💚 🔠 *➡ 🛠️*.
|
|
||||||
|
|
||||||
📚 💼, 👆 💪 ⚙️ 🐍 ⚒ "🏗" `dict` ⏮️ `**dict_to_unpack`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
old_dict = {
|
|
||||||
"old key": "old value",
|
|
||||||
"second old key": "second old value",
|
|
||||||
}
|
|
||||||
new_dict = {**old_dict, "new key": "new value"}
|
|
||||||
```
|
|
||||||
|
|
||||||
📥, `new_dict` 🔜 🔌 🌐 🔑-💲 👫 ⚪️➡️ `old_dict` ➕ 🆕 🔑-💲 👫:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{
|
|
||||||
"old key": "old value",
|
|
||||||
"second old key": "second old value",
|
|
||||||
"new key": "new value",
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 👈 ⚒ 🏤-⚙️ 🔢 📨 👆 *➡ 🛠️* & 🌀 👫 ⏮️ 🌖 🛃 🕐.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/additional_responses/tutorial004.py hl[13:17,26] *}
|
|
||||||
|
|
||||||
## 🌖 ℹ 🔃 🗄 📨
|
|
||||||
|
|
||||||
👀 ⚫️❔ ⚫️❔ 👆 💪 🔌 📨, 👆 💪 ✅ 👉 📄 🗄 🔧:
|
|
||||||
|
|
||||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responsesObject" class="external-link" target="_blank">🗄 📨 🎚</a>, ⚫️ 🔌 `Response Object`.
|
|
||||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#responseObject" class="external-link" target="_blank">🗄 📨 🎚</a>, 👆 💪 🔌 🕳 ⚪️➡️ 👉 🔗 🔠 📨 🔘 👆 `responses` 🔢. ✅ `description`, `headers`, `content` (🔘 👉 👈 👆 📣 🎏 🔉 🆎 & 🎻 🔗), & `links`.
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
# 🌖 👔 📟
|
|
||||||
|
|
||||||
🔢, **FastAPI** 🔜 📨 📨 ⚙️ `JSONResponse`, 🚮 🎚 👆 📨 ⚪️➡️ 👆 *➡ 🛠️* 🔘 👈 `JSONResponse`.
|
|
||||||
|
|
||||||
⚫️ 🔜 ⚙️ 🔢 👔 📟 ⚖️ 1️⃣ 👆 ⚒ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
## 🌖 👔 📟
|
|
||||||
|
|
||||||
🚥 👆 💚 📨 🌖 👔 📟 ↖️ ⚪️➡️ 👑 1️⃣, 👆 💪 👈 🛬 `Response` 🔗, 💖 `JSONResponse`, & ⚒ 🌖 👔 📟 🔗.
|
|
||||||
|
|
||||||
🖼, ➡️ 💬 👈 👆 💚 ✔️ *➡ 🛠️* 👈 ✔ ℹ 🏬, & 📨 🇺🇸🔍 👔 📟 2️⃣0️⃣0️⃣ "👌" 🕐❔ 🏆.
|
|
||||||
|
|
||||||
✋️ 👆 💚 ⚫️ 🚫 🆕 🏬. & 🕐❔ 🏬 🚫 🔀 ⏭, ⚫️ ✍ 👫, & 📨 🇺🇸🔍 👔 📟 2️⃣0️⃣1️⃣ "✍".
|
|
||||||
|
|
||||||
🏆 👈, 🗄 `JSONResponse`, & 📨 👆 🎚 📤 🔗, ⚒ `status_code` 👈 👆 💚:
|
|
||||||
|
|
||||||
{* ../../docs_src/additional_status_codes/tutorial001.py hl[4,25] *}
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
🕐❔ 👆 📨 `Response` 🔗, 💖 🖼 🔛, ⚫️ 🔜 📨 🔗.
|
|
||||||
|
|
||||||
⚫️ 🏆 🚫 🎻 ⏮️ 🏷, ♒️.
|
|
||||||
|
|
||||||
⚒ 💭 ⚫️ ✔️ 📊 👆 💚 ⚫️ ✔️, & 👈 💲 ☑ 🎻 (🚥 👆 ⚙️ `JSONResponse`).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import JSONResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃. 🎏 ⏮️ `status`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🗄 & 🛠️ 🩺
|
|
||||||
|
|
||||||
🚥 👆 📨 🌖 👔 📟 & 📨 🔗, 👫 🏆 🚫 🔌 🗄 🔗 (🛠️ 🩺), ↩️ FastAPI 🚫 ✔️ 🌌 💭 ⏪ ⚫️❔ 👆 🚶 📨.
|
|
||||||
|
|
||||||
✋️ 👆 💪 📄 👈 👆 📟, ⚙️: [🌖 📨](additional-responses.md){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
# 🏧 🔗
|
|
||||||
|
|
||||||
## 🔗 🔗
|
|
||||||
|
|
||||||
🌐 🔗 👥 ✔️ 👀 🔧 🔢 ⚖️ 🎓.
|
|
||||||
|
|
||||||
✋️ 📤 💪 💼 🌐❔ 👆 💚 💪 ⚒ 🔢 🔛 🔗, 🍵 ✔️ 📣 📚 🎏 🔢 ⚖️ 🎓.
|
|
||||||
|
|
||||||
➡️ 🌈 👈 👥 💚 ✔️ 🔗 👈 ✅ 🚥 🔢 🔢 `q` 🔌 🔧 🎚.
|
|
||||||
|
|
||||||
✋️ 👥 💚 💪 🔗 👈 🔧 🎚.
|
|
||||||
|
|
||||||
## "🇧🇲" 👐
|
|
||||||
|
|
||||||
🐍 📤 🌌 ⚒ 👐 🎓 "🇧🇲".
|
|
||||||
|
|
||||||
🚫 🎓 ⚫️ (❔ ⏪ 🇧🇲), ✋️ 👐 👈 🎓.
|
|
||||||
|
|
||||||
👈, 👥 📣 👩🔬 `__call__`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial011.py hl[10] *}
|
|
||||||
|
|
||||||
👉 💼, 👉 `__call__` ⚫️❔ **FastAPI** 🔜 ⚙️ ✅ 🌖 🔢 & 🎧-🔗, & 👉 ⚫️❔ 🔜 🤙 🚶♀️ 💲 🔢 👆 *➡ 🛠️ 🔢* ⏪.
|
|
||||||
|
|
||||||
## 🔗 👐
|
|
||||||
|
|
||||||
& 🔜, 👥 💪 ⚙️ `__init__` 📣 🔢 👐 👈 👥 💪 ⚙️ "🔗" 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial011.py hl[7] *}
|
|
||||||
|
|
||||||
👉 💼, **FastAPI** 🏆 🚫 ⏱ 👆 ⚖️ 💅 🔃 `__init__`, 👥 🔜 ⚙️ ⚫️ 🔗 👆 📟.
|
|
||||||
|
|
||||||
## ✍ 👐
|
|
||||||
|
|
||||||
👥 💪 ✍ 👐 👉 🎓 ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial011.py hl[16] *}
|
|
||||||
|
|
||||||
& 👈 🌌 👥 💪 "🔗" 👆 🔗, 👈 🔜 ✔️ `"bar"` 🔘 ⚫️, 🔢 `checker.fixed_content`.
|
|
||||||
|
|
||||||
## ⚙️ 👐 🔗
|
|
||||||
|
|
||||||
⤴️, 👥 💪 ⚙️ 👉 `checker` `Depends(checker)`, ↩️ `Depends(FixedContentQueryChecker)`, ↩️ 🔗 👐, `checker`, 🚫 🎓 ⚫️.
|
|
||||||
|
|
||||||
& 🕐❔ ❎ 🔗, **FastAPI** 🔜 🤙 👉 `checker` 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
checker(q="somequery")
|
|
||||||
```
|
|
||||||
|
|
||||||
...& 🚶♀️ ⚫️❔ 👈 📨 💲 🔗 👆 *➡ 🛠️ 🔢* 🔢 `fixed_content_included`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial011.py hl[20] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🌐 👉 💪 😑 🎭. & ⚫️ 💪 🚫 📶 🆑 ❔ ⚫️ ⚠.
|
|
||||||
|
|
||||||
👫 🖼 😫 🙅, ✋️ 🎦 ❔ ⚫️ 🌐 👷.
|
|
||||||
|
|
||||||
📃 🔃 💂♂, 📤 🚙 🔢 👈 🛠️ 👉 🎏 🌌.
|
|
||||||
|
|
||||||
🚥 👆 🤔 🌐 👉, 👆 ⏪ 💭 ❔ 👈 🚙 🧰 💂♂ 👷 🔘.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
# 🔁 💯
|
|
||||||
|
|
||||||
👆 ✔️ ⏪ 👀 ❔ 💯 👆 **FastAPI** 🈸 ⚙️ 🚚 `TestClient`. 🆙 🔜, 👆 ✔️ 🕴 👀 ❔ ✍ 🔁 💯, 🍵 ⚙️ `async` 🔢.
|
|
||||||
|
|
||||||
➖ 💪 ⚙️ 🔁 🔢 👆 💯 💪 ⚠, 🖼, 🕐❔ 👆 🔬 👆 💽 🔁. 🌈 👆 💚 💯 📨 📨 👆 FastAPI 🈸 & ⤴️ ✔ 👈 👆 👩💻 ⏪ ✍ ☑ 💽 💽, ⏪ ⚙️ 🔁 💽 🗃.
|
|
||||||
|
|
||||||
➡️ 👀 ❔ 👥 💪 ⚒ 👈 👷.
|
|
||||||
|
|
||||||
## pytest.mark.anyio
|
|
||||||
|
|
||||||
🚥 👥 💚 🤙 🔁 🔢 👆 💯, 👆 💯 🔢 ✔️ 🔁. AnyIO 🚚 👌 📁 👉, 👈 ✔ 👥 ✔ 👈 💯 🔢 🤙 🔁.
|
|
||||||
|
|
||||||
## 🇸🇲
|
|
||||||
|
|
||||||
🚥 👆 **FastAPI** 🈸 ⚙️ 😐 `def` 🔢 ↩️ `async def`, ⚫️ `async` 🈸 🔘.
|
|
||||||
|
|
||||||
`TestClient` 🔨 🎱 🔘 🤙 🔁 FastAPI 🈸 👆 😐 `def` 💯 🔢, ⚙️ 🐩 ✳. ✋️ 👈 🎱 🚫 👷 🚫🔜 🕐❔ 👥 ⚙️ ⚫️ 🔘 🔁 🔢. 🏃 👆 💯 🔁, 👥 💪 🙅♂ 📏 ⚙️ `TestClient` 🔘 👆 💯 🔢.
|
|
||||||
|
|
||||||
`TestClient` ⚓️ 🔛 <a href="https://www.python-httpx.org" class="external-link" target="_blank">🇸🇲</a>, & ↩️, 👥 💪 ⚙️ ⚫️ 🔗 💯 🛠️.
|
|
||||||
|
|
||||||
## 🖼
|
|
||||||
|
|
||||||
🙅 🖼, ➡️ 🤔 📁 📊 🎏 1️⃣ 🔬 [🦏 🈸](../tutorial/bigger-applications.md){.internal-link target=_blank} & [🔬](../tutorial/testing.md){.internal-link target=_blank}:
|
|
||||||
|
|
||||||
```
|
|
||||||
.
|
|
||||||
├── app
|
|
||||||
│ ├── __init__.py
|
|
||||||
│ ├── main.py
|
|
||||||
│ └── test_main.py
|
|
||||||
```
|
|
||||||
|
|
||||||
📁 `main.py` 🔜 ✔️:
|
|
||||||
|
|
||||||
{* ../../docs_src/async_tests/main.py *}
|
|
||||||
|
|
||||||
📁 `test_main.py` 🔜 ✔️ 💯 `main.py`, ⚫️ 💪 👀 💖 👉 🔜:
|
|
||||||
|
|
||||||
{* ../../docs_src/async_tests/test_main.py *}
|
|
||||||
|
|
||||||
## 🏃 ⚫️
|
|
||||||
|
|
||||||
👆 💪 🏃 👆 💯 🐌 📨:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pytest
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## ℹ
|
|
||||||
|
|
||||||
📑 `@pytest.mark.anyio` 💬 ✳ 👈 👉 💯 🔢 🔜 🤙 🔁:
|
|
||||||
|
|
||||||
{* ../../docs_src/async_tests/test_main.py hl[7] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🗒 👈 💯 🔢 🔜 `async def` ↩️ `def` ⏭ 🕐❔ ⚙️ `TestClient`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⤴️ 👥 💪 ✍ `AsyncClient` ⏮️ 📱, & 📨 🔁 📨 ⚫️, ⚙️ `await`.
|
|
||||||
|
|
||||||
{* ../../docs_src/async_tests/test_main.py hl[9:12] *}
|
|
||||||
|
|
||||||
👉 🌓:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
response = client.get('/')
|
|
||||||
```
|
|
||||||
|
|
||||||
...👈 👥 ⚙️ ⚒ 👆 📨 ⏮️ `TestClient`.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🗒 👈 👥 ⚙️ 🔁/⌛ ⏮️ 🆕 `AsyncClient` - 📨 🔁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🎏 🔁 🔢 🤙
|
|
||||||
|
|
||||||
🔬 🔢 🔜 🔁, 👆 💪 🔜 🤙 (& `await`) 🎏 `async` 🔢 ↖️ ⚪️➡️ 📨 📨 👆 FastAPI 🈸 👆 💯, ⚫️❔ 👆 🔜 🤙 👫 🙆 🙆 👆 📟.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ⚔ `RuntimeError: Task attached to a different loop` 🕐❔ 🛠️ 🔁 🔢 🤙 👆 💯 (✅ 🕐❔ ⚙️ <a href="https://stackoverflow.com/questions/41584243/runtimeerror-task-attached-to-a-different-loop" class="external-link" target="_blank">✳ MotorClient</a>) 💭 🔗 🎚 👈 💪 🎉 ➰ 🕴 🏞 🔁 🔢, ✅ `'@app.on_event("startup")` ⏲.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,359 +0,0 @@
|
||||||
# ⛅ 🗳
|
|
||||||
|
|
||||||
⚠, 👆 5️⃣📆 💪 ⚙️ **🗳** 💽 💖 Traefik ⚖️ 👌 ⏮️ 📳 👈 🚮 ➕ ➡ 🔡 👈 🚫 👀 👆 🈸.
|
|
||||||
|
|
||||||
👫 💼 👆 💪 ⚙️ `root_path` 🔗 👆 🈸.
|
|
||||||
|
|
||||||
`root_path` 🛠️ 🚚 🔫 🔧 (👈 FastAPI 🏗 🔛, 🔘 💃).
|
|
||||||
|
|
||||||
`root_path` ⚙️ 🍵 👫 🎯 💼.
|
|
||||||
|
|
||||||
& ⚫️ ⚙️ 🔘 🕐❔ 🗜 🎧-🈸.
|
|
||||||
|
|
||||||
## 🗳 ⏮️ 🎞 ➡ 🔡
|
|
||||||
|
|
||||||
✔️ 🗳 ⏮️ 🎞 ➡ 🔡, 👉 💼, ⛓ 👈 👆 💪 📣 ➡ `/app` 👆 📟, ✋️ ⤴️, 👆 🚮 🧽 🔛 🔝 (🗳) 👈 🔜 🚮 👆 **FastAPI** 🈸 🔽 ➡ 💖 `/api/v1`.
|
|
||||||
|
|
||||||
👉 💼, ⏮️ ➡ `/app` 🔜 🤙 🍦 `/api/v1/app`.
|
|
||||||
|
|
||||||
✋️ 🌐 👆 📟 ✍ 🤔 📤 `/app`.
|
|
||||||
|
|
||||||
& 🗳 🔜 **"❎"** **➡ 🔡** 🔛 ✈ ⏭ 📶 📨 Uvicorn, 🚧 👆 🈸 🤔 👈 ⚫️ 🍦 `/app`, 👈 👆 🚫 ✔️ ℹ 🌐 👆 📟 🔌 🔡 `/api/v1`.
|
|
||||||
|
|
||||||
🆙 📥, 🌐 🔜 👷 🛎.
|
|
||||||
|
|
||||||
✋️ ⤴️, 🕐❔ 👆 📂 🛠️ 🩺 🎚 (🕸), ⚫️ 🔜 ⌛ 🤚 🗄 🔗 `/openapi.json`, ↩️ `/api/v1/openapi.json`.
|
|
||||||
|
|
||||||
, 🕸 (👈 🏃 🖥) 🔜 🔄 🏆 `/openapi.json` & 🚫🔜 💪 🤚 🗄 🔗.
|
|
||||||
|
|
||||||
↩️ 👥 ✔️ 🗳 ⏮️ ➡ 🔡 `/api/v1` 👆 📱, 🕸 💪 ☕ 🗄 🔗 `/api/v1/openapi.json`.
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph LR
|
|
||||||
|
|
||||||
browser("Browser")
|
|
||||||
proxy["Proxy on http://0.0.0.0:9999/api/v1/app"]
|
|
||||||
server["Server on http://127.0.0.1:8000/app"]
|
|
||||||
|
|
||||||
browser --> proxy
|
|
||||||
proxy --> server
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📢 `0.0.0.0` 🛎 ⚙️ ⛓ 👈 📋 👂 🔛 🌐 📢 💪 👈 🎰/💽.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🩺 🎚 🔜 💪 🗄 🔗 📣 👈 👉 🛠️ `server` 🔎 `/api/v1` (⛅ 🗳). 🖼:
|
|
||||||
|
|
||||||
```JSON hl_lines="4-8"
|
|
||||||
{
|
|
||||||
"openapi": "3.0.2",
|
|
||||||
// More stuff here
|
|
||||||
"servers": [
|
|
||||||
{
|
|
||||||
"url": "/api/v1"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
// More stuff here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 🖼, "🗳" 💪 🕳 💖 **Traefik**. & 💽 🔜 🕳 💖 **Uvicorn**, 🏃♂ 👆 FastAPI 🈸.
|
|
||||||
|
|
||||||
### 🚚 `root_path`
|
|
||||||
|
|
||||||
🏆 👉, 👆 💪 ⚙️ 📋 ⏸ 🎛 `--root-path` 💖:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --root-path /api/v1
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ Hypercorn, ⚫️ ✔️ 🎛 `--root-path`.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🔫 🔧 🔬 `root_path` 👉 ⚙️ 💼.
|
|
||||||
|
|
||||||
& `--root-path` 📋 ⏸ 🎛 🚚 👈 `root_path`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ✅ ⏮️ `root_path`
|
|
||||||
|
|
||||||
👆 💪 🤚 ⏮️ `root_path` ⚙️ 👆 🈸 🔠 📨, ⚫️ 🍕 `scope` 📖 (👈 🍕 🔫 🔌).
|
|
||||||
|
|
||||||
📥 👥 ✅ ⚫️ 📧 🎦 🎯.
|
|
||||||
|
|
||||||
{* ../../docs_src/behind_a_proxy/tutorial001.py hl[8] *}
|
|
||||||
|
|
||||||
⤴️, 🚥 👆 ▶️ Uvicorn ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --root-path /api/v1
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
📨 🔜 🕳 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"message": "Hello World",
|
|
||||||
"root_path": "/api/v1"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### ⚒ `root_path` FastAPI 📱
|
|
||||||
|
|
||||||
👐, 🚥 👆 🚫 ✔️ 🌌 🚚 📋 ⏸ 🎛 💖 `--root-path` ⚖️ 🌓, 👆 💪 ⚒ `root_path` 🔢 🕐❔ 🏗 👆 FastAPI 📱:
|
|
||||||
|
|
||||||
{* ../../docs_src/behind_a_proxy/tutorial002.py hl[3] *}
|
|
||||||
|
|
||||||
🚶♀️ `root_path` `FastAPI` 🔜 🌓 🚶♀️ `--root-path` 📋 ⏸ 🎛 Uvicorn ⚖️ Hypercorn.
|
|
||||||
|
|
||||||
### 🔃 `root_path`
|
|
||||||
|
|
||||||
✔️ 🤯 👈 💽 (Uvicorn) 🏆 🚫 ⚙️ 👈 `root_path` 🕳 🙆 🌘 🚶♀️ ⚫️ 📱.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🚶 ⏮️ 👆 🖥 <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000/app</a> 👆 🔜 👀 😐 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"message": "Hello World",
|
|
||||||
"root_path": "/api/v1"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
, ⚫️ 🏆 🚫 ⌛ 🔐 `http://127.0.0.1:8000/api/v1/app`.
|
|
||||||
|
|
||||||
Uvicorn 🔜 ⌛ 🗳 🔐 Uvicorn `http://127.0.0.1:8000/app`, & ⤴️ ⚫️ 🔜 🗳 🎯 🚮 ➕ `/api/v1` 🔡 🔛 🔝.
|
|
||||||
|
|
||||||
## 🔃 🗳 ⏮️ 🎞 ➡ 🔡
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🗳 ⏮️ 🎞 ➡ 🔡 🕴 1️⃣ 🌌 🔗 ⚫️.
|
|
||||||
|
|
||||||
🎲 📚 💼 🔢 🔜 👈 🗳 🚫 ✔️ 🏚 ➡ 🔡.
|
|
||||||
|
|
||||||
💼 💖 👈 (🍵 🎞 ➡ 🔡), 🗳 🔜 👂 🔛 🕳 💖 `https://myawesomeapp.com`, & ⤴️ 🚥 🖥 🚶 `https://myawesomeapp.com/api/v1/app` & 👆 💽 (✅ Uvicorn) 👂 🔛 `http://127.0.0.1:8000` 🗳 (🍵 🎞 ➡ 🔡) 🔜 🔐 Uvicorn 🎏 ➡: `http://127.0.0.1:8000/api/v1/app`.
|
|
||||||
|
|
||||||
## 🔬 🌐 ⏮️ Traefik
|
|
||||||
|
|
||||||
👆 💪 💪 🏃 🥼 🌐 ⏮️ 🎞 ➡ 🔡 ⚙️ <a href="https://docs.traefik.io/" class="external-link" target="_blank">Traefik</a>.
|
|
||||||
|
|
||||||
<a href="https://github.com/containous/traefik/releases" class="external-link" target="_blank">⏬ Traefik</a>, ⚫️ 👁 💱, 👆 💪 ⚗ 🗜 📁 & 🏃 ⚫️ 🔗 ⚪️➡️ 📶.
|
|
||||||
|
|
||||||
⤴️ ✍ 📁 `traefik.toml` ⏮️:
|
|
||||||
|
|
||||||
```TOML hl_lines="3"
|
|
||||||
[entryPoints]
|
|
||||||
[entryPoints.http]
|
|
||||||
address = ":9999"
|
|
||||||
|
|
||||||
[providers]
|
|
||||||
[providers.file]
|
|
||||||
filename = "routes.toml"
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 💬 Traefik 👂 🔛 ⛴ 9️⃣9️⃣9️⃣9️⃣ & ⚙️ ➕1️⃣ 📁 `routes.toml`.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👥 ⚙️ ⛴ 9️⃣9️⃣9️⃣9️⃣ ↩️ 🐩 🇺🇸🔍 ⛴ 8️⃣0️⃣ 👈 👆 🚫 ✔️ 🏃 ⚫️ ⏮️ 📡 (`sudo`) 😌.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔜 ✍ 👈 🎏 📁 `routes.toml`:
|
|
||||||
|
|
||||||
```TOML hl_lines="5 12 20"
|
|
||||||
[http]
|
|
||||||
[http.middlewares]
|
|
||||||
|
|
||||||
[http.middlewares.api-stripprefix.stripPrefix]
|
|
||||||
prefixes = ["/api/v1"]
|
|
||||||
|
|
||||||
[http.routers]
|
|
||||||
|
|
||||||
[http.routers.app-http]
|
|
||||||
entryPoints = ["http"]
|
|
||||||
service = "app"
|
|
||||||
rule = "PathPrefix(`/api/v1`)"
|
|
||||||
middlewares = ["api-stripprefix"]
|
|
||||||
|
|
||||||
[http.services]
|
|
||||||
|
|
||||||
[http.services.app]
|
|
||||||
[http.services.app.loadBalancer]
|
|
||||||
[[http.services.app.loadBalancer.servers]]
|
|
||||||
url = "http://127.0.0.1:8000"
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 📁 🔗 Traefik ⚙️ ➡ 🔡 `/api/v1`.
|
|
||||||
|
|
||||||
& ⤴️ ⚫️ 🔜 ❎ 🚮 📨 👆 Uvicorn 🏃♂ 🔛 `http://127.0.0.1:8000`.
|
|
||||||
|
|
||||||
🔜 ▶️ Traefik:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ ./traefik --configFile=traefik.toml
|
|
||||||
|
|
||||||
INFO[0000] Configuration loaded from file: /home/user/awesomeapi/traefik.toml
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
& 🔜 ▶️ 👆 📱 ⏮️ Uvicorn, ⚙️ `--root-path` 🎛:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --root-path /api/v1
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
### ✅ 📨
|
|
||||||
|
|
||||||
🔜, 🚥 👆 🚶 📛 ⏮️ ⛴ Uvicorn: <a href="http://127.0.0.1:8000/app" class="external-link" target="_blank">http://127.0.0.1:8000/app</a>, 👆 🔜 👀 😐 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"message": "Hello World",
|
|
||||||
"root_path": "/api/v1"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 ✋️ 👆 🔐 ⚫️ `http://127.0.0.1:8000/app` ⚫️ 🎦 `root_path` `/api/v1`, ✊ ⚪️➡️ 🎛 `--root-path`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& 🔜 📂 📛 ⏮️ ⛴ Traefik, ✅ ➡ 🔡: <a href="http://127.0.0.1:9999/api/v1/app" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/app</a>.
|
|
||||||
|
|
||||||
👥 🤚 🎏 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"message": "Hello World",
|
|
||||||
"root_path": "/api/v1"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 👉 🕰 📛 ⏮️ 🔡 ➡ 🚚 🗳: `/api/v1`.
|
|
||||||
|
|
||||||
↗️, 💭 📥 👈 👱 🔜 🔐 📱 🔘 🗳, ⏬ ⏮️ ➡ 🔡 `/app/v1` "☑" 1️⃣.
|
|
||||||
|
|
||||||
& ⏬ 🍵 ➡ 🔡 (`http://127.0.0.1:8000/app`), 🚚 Uvicorn 🔗, 🔜 🎯 _🗳_ (Traefik) 🔐 ⚫️.
|
|
||||||
|
|
||||||
👈 🎦 ❔ 🗳 (Traefik) ⚙️ ➡ 🔡 & ❔ 💽 (Uvicorn) ⚙️ `root_path` ⚪️➡️ 🎛 `--root-path`.
|
|
||||||
|
|
||||||
### ✅ 🩺 🎚
|
|
||||||
|
|
||||||
✋️ 📥 🎊 🍕. 👶
|
|
||||||
|
|
||||||
"🛂" 🌌 🔐 📱 🔜 🔘 🗳 ⏮️ ➡ 🔡 👈 👥 🔬. , 👥 🔜 ⌛, 🚥 👆 🔄 🩺 🎚 🍦 Uvicorn 🔗, 🍵 ➡ 🔡 📛, ⚫️ 🏆 🚫 👷, ↩️ ⚫️ ⌛ 🔐 🔘 🗳.
|
|
||||||
|
|
||||||
👆 💪 ✅ ⚫️ <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/behind-a-proxy/image01.png">
|
|
||||||
|
|
||||||
✋️ 🚥 👥 🔐 🩺 🎚 "🛂" 📛 ⚙️ 🗳 ⏮️ ⛴ `9999`, `/api/v1/docs`, ⚫️ 👷 ☑ ❗ 👶
|
|
||||||
|
|
||||||
👆 💪 ✅ ⚫️ <a href="http://127.0.0.1:9999/api/v1/docs" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/docs</a>:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/behind-a-proxy/image02.png">
|
|
||||||
|
|
||||||
▶️️ 👥 💚 ⚫️. 👶 👶
|
|
||||||
|
|
||||||
👉 ↩️ FastAPI ⚙️ 👉 `root_path` ✍ 🔢 `server` 🗄 ⏮️ 📛 🚚 `root_path`.
|
|
||||||
|
|
||||||
## 🌖 💽
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👉 🌅 🏧 ⚙️ 💼. 💭 🆓 🚶 ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔢, **FastAPI** 🔜 ✍ `server` 🗄 🔗 ⏮️ 📛 `root_path`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 🚚 🎏 🎛 `servers`, 🖼 🚥 👆 💚 *🎏* 🩺 🎚 🔗 ⏮️ 🏗 & 🏭 🌐.
|
|
||||||
|
|
||||||
🚥 👆 🚶♀️ 🛃 📇 `servers` & 📤 `root_path` (↩️ 👆 🛠️ 👨❤👨 ⛅ 🗳), **FastAPI** 🔜 📩 "💽" ⏮️ 👉 `root_path` ▶️ 📇.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/behind_a_proxy/tutorial003.py hl[4:7] *}
|
|
||||||
|
|
||||||
🔜 🏗 🗄 🔗 💖:
|
|
||||||
|
|
||||||
```JSON hl_lines="5-7"
|
|
||||||
{
|
|
||||||
"openapi": "3.0.2",
|
|
||||||
// More stuff here
|
|
||||||
"servers": [
|
|
||||||
{
|
|
||||||
"url": "/api/v1"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://stag.example.com",
|
|
||||||
"description": "Staging environment"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://prod.example.com",
|
|
||||||
"description": "Production environment"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"paths": {
|
|
||||||
// More stuff here
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 🚘-🏗 💽 ⏮️ `url` 💲 `/api/v1`, ✊ ⚪️➡️ `root_path`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🩺 🎚 <a href="http://127.0.0.1:9999/api/v1/docs" class="external-link" target="_blank">http://127.0.0.1:9999/api/v1/docs</a> ⚫️ 🔜 👀 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/behind-a-proxy/image03.png">
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🩺 🎚 🔜 🔗 ⏮️ 💽 👈 👆 🖊.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ❎ 🏧 💽 ⚪️➡️ `root_path`
|
|
||||||
|
|
||||||
🚥 👆 🚫 💚 **FastAPI** 🔌 🏧 💽 ⚙️ `root_path`, 👆 💪 ⚙️ 🔢 `root_path_in_servers=False`:
|
|
||||||
|
|
||||||
{* ../../docs_src/behind_a_proxy/tutorial004.py hl[9] *}
|
|
||||||
|
|
||||||
& ⤴️ ⚫️ 🏆 🚫 🔌 ⚫️ 🗄 🔗.
|
|
||||||
|
|
||||||
## 🗜 🎧-🈸
|
|
||||||
|
|
||||||
🚥 👆 💪 🗻 🎧-🈸 (🔬 [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}) ⏪ ⚙️ 🗳 ⏮️ `root_path`, 👆 💪 ⚫️ 🛎, 👆 🔜 ⌛.
|
|
||||||
|
|
||||||
FastAPI 🔜 🔘 ⚙️ `root_path` 🎆, ⚫️ 🔜 👷. 👶
|
|
||||||
|
|
@ -1,303 +0,0 @@
|
||||||
# 🛃 📨 - 🕸, 🎏, 📁, 🎏
|
|
||||||
|
|
||||||
🔢, **FastAPI** 🔜 📨 📨 ⚙️ `JSONResponse`.
|
|
||||||
|
|
||||||
👆 💪 🔐 ⚫️ 🛬 `Response` 🔗 👀 [📨 📨 🔗](response-directly.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 📨 `Response` 🔗, 📊 🏆 🚫 🔁 🗜, & 🧾 🏆 🚫 🔁 🏗 (🖼, 🔌 🎯 "📻 🆎", 🇺🇸🔍 🎚 `Content-Type` 🍕 🏗 🗄).
|
|
||||||
|
|
||||||
✋️ 👆 💪 📣 `Response` 👈 👆 💚 ⚙️, *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
||||||
🎚 👈 👆 📨 ⚪️➡️ 👆 *➡ 🛠️ 🔢* 🔜 🚮 🔘 👈 `Response`.
|
|
||||||
|
|
||||||
& 🚥 👈 `Response` ✔️ 🎻 📻 🆎 (`application/json`), 💖 💼 ⏮️ `JSONResponse` & `UJSONResponse`, 💽 👆 📨 🔜 🔁 🗜 (& ⛽) ⏮️ 🙆 Pydantic `response_model` 👈 👆 📣 *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 📨 🎓 ⏮️ 🙅♂ 📻 🆎, FastAPI 🔜 ⌛ 👆 📨 ✔️ 🙅♂ 🎚, ⚫️ 🔜 🚫 📄 📨 📁 🚮 🏗 🗄 🩺.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚙️ `ORJSONResponse`
|
|
||||||
|
|
||||||
🖼, 🚥 👆 ✊ 🎭, 👆 💪 ❎ & ⚙️ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a> & ⚒ 📨 `ORJSONResponse`.
|
|
||||||
|
|
||||||
🗄 `Response` 🎓 (🎧-🎓) 👆 💚 ⚙️ & 📣 ⚫️ *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
||||||
⭕ 📨, 📨 `Response` 🔗 🌅 ⏩ 🌘 🛬 📖.
|
|
||||||
|
|
||||||
👉 ↩️ 🔢, FastAPI 🔜 ✔ 🔠 🏬 🔘 & ⚒ 💭 ⚫️ 🎻 ⏮️ 🎻, ⚙️ 🎏 [🎻 🔗 🔢](../tutorial/encoder.md){.internal-link target=_blank} 🔬 🔰. 👉 ⚫️❔ ✔ 👆 📨 **❌ 🎚**, 🖼 💽 🏷.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🎯 👈 🎚 👈 👆 🛬 **🎻 ⏮️ 🎻**, 👆 💪 🚶♀️ ⚫️ 🔗 📨 🎓 & ❎ ➕ 🌥 👈 FastAPI 🔜 ✔️ 🚶♀️ 👆 📨 🎚 🔘 `jsonable_encoder` ⏭ 🚶♀️ ⚫️ 📨 🎓.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial001b.py hl[2,7] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🔢 `response_class` 🔜 ⚙️ 🔬 "📻 🆎" 📨.
|
|
||||||
|
|
||||||
👉 💼, 🇺🇸🔍 🎚 `Content-Type` 🔜 ⚒ `application/json`.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 📄 ✅ 🗄.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
`ORJSONResponse` ⏳ 🕴 💪 FastAPI, 🚫 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🕸 📨
|
|
||||||
|
|
||||||
📨 📨 ⏮️ 🕸 🔗 ⚪️➡️ **FastAPI**, ⚙️ `HTMLResponse`.
|
|
||||||
|
|
||||||
* 🗄 `HTMLResponse`.
|
|
||||||
* 🚶♀️ `HTMLResponse` 🔢 `response_class` 👆 *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial002.py hl[2,7] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🔢 `response_class` 🔜 ⚙️ 🔬 "📻 🆎" 📨.
|
|
||||||
|
|
||||||
👉 💼, 🇺🇸🔍 🎚 `Content-Type` 🔜 ⚒ `text/html`.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 📄 ✅ 🗄.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 📨 `Response`
|
|
||||||
|
|
||||||
👀 [📨 📨 🔗](response-directly.md){.internal-link target=_blank}, 👆 💪 🔐 📨 🔗 👆 *➡ 🛠️*, 🛬 ⚫️.
|
|
||||||
|
|
||||||
🎏 🖼 ⚪️➡️ 🔛, 🛬 `HTMLResponse`, 💪 👀 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial003.py hl[2,7,19] *}
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
`Response` 📨 🔗 👆 *➡ 🛠️ 🔢* 🏆 🚫 📄 🗄 (🖼, `Content-Type` 🏆 🚫 📄) & 🏆 🚫 ⭐ 🏧 🎓 🩺.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
↗️, ☑ `Content-Type` 🎚, 👔 📟, ♒️, 🔜 👟 ⚪️➡️ `Response` 🎚 👆 📨.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 📄 🗄 & 🔐 `Response`
|
|
||||||
|
|
||||||
🚥 👆 💚 🔐 📨 ⚪️➡️ 🔘 🔢 ✋️ 🎏 🕰 📄 "📻 🆎" 🗄, 👆 💪 ⚙️ `response_class` 🔢 & 📨 `Response` 🎚.
|
|
||||||
|
|
||||||
`response_class` 🔜 ⤴️ ⚙️ 🕴 📄 🗄 *➡ 🛠️*, ✋️ 👆 `Response` 🔜 ⚙️.
|
|
||||||
|
|
||||||
#### 📨 `HTMLResponse` 🔗
|
|
||||||
|
|
||||||
🖼, ⚫️ 💪 🕳 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial004.py hl[7,21,23] *}
|
|
||||||
|
|
||||||
👉 🖼, 🔢 `generate_html_response()` ⏪ 🏗 & 📨 `Response` ↩️ 🛬 🕸 `str`.
|
|
||||||
|
|
||||||
🛬 🏁 🤙 `generate_html_response()`, 👆 ⏪ 🛬 `Response` 👈 🔜 🔐 🔢 **FastAPI** 🎭.
|
|
||||||
|
|
||||||
✋️ 👆 🚶♀️ `HTMLResponse` `response_class` 💁♂️, **FastAPI** 🔜 💭 ❔ 📄 ⚫️ 🗄 & 🎓 🩺 🕸 ⏮️ `text/html`:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/custom-response/image01.png">
|
|
||||||
|
|
||||||
## 💪 📨
|
|
||||||
|
|
||||||
📥 💪 📨.
|
|
||||||
|
|
||||||
✔️ 🤯 👈 👆 💪 ⚙️ `Response` 📨 🕳 🙆, ⚖️ ✍ 🛃 🎧-🎓.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import HTMLResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `Response`
|
|
||||||
|
|
||||||
👑 `Response` 🎓, 🌐 🎏 📨 😖 ⚪️➡️ ⚫️.
|
|
||||||
|
|
||||||
👆 💪 📨 ⚫️ 🔗.
|
|
||||||
|
|
||||||
⚫️ 🚫 📄 🔢:
|
|
||||||
|
|
||||||
* `content` - `str` ⚖️ `bytes`.
|
|
||||||
* `status_code` - `int` 🇺🇸🔍 👔 📟.
|
|
||||||
* `headers` - `dict` 🎻.
|
|
||||||
* `media_type` - `str` 🤝 📻 🆎. 🤶 Ⓜ. `"text/html"`.
|
|
||||||
|
|
||||||
FastAPI (🤙 💃) 🔜 🔁 🔌 🎚-📐 🎚. ⚫️ 🔜 🔌 🎚-🆎 🎚, ⚓️ 🔛 = & 🔁 = ✍ 🆎.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_directly/tutorial002.py hl[1,18] *}
|
|
||||||
|
|
||||||
### `HTMLResponse`
|
|
||||||
|
|
||||||
✊ ✍ ⚖️ 🔢 & 📨 🕸 📨, 👆 ✍ 🔛.
|
|
||||||
|
|
||||||
### `PlainTextResponse`
|
|
||||||
|
|
||||||
✊ ✍ ⚖️ 🔢 & 📨 ✅ ✍ 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial005.py hl[2,7,9] *}
|
|
||||||
|
|
||||||
### `JSONResponse`
|
|
||||||
|
|
||||||
✊ 💽 & 📨 `application/json` 🗜 📨.
|
|
||||||
|
|
||||||
👉 🔢 📨 ⚙️ **FastAPI**, 👆 ✍ 🔛.
|
|
||||||
|
|
||||||
### `ORJSONResponse`
|
|
||||||
|
|
||||||
⏩ 🎛 🎻 📨 ⚙️ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a>, 👆 ✍ 🔛.
|
|
||||||
|
|
||||||
### `UJSONResponse`
|
|
||||||
|
|
||||||
🎛 🎻 📨 ⚙️ <a href="https://github.com/ultrajson/ultrajson" class="external-link" target="_blank">`ujson`</a>.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
`ujson` 🌘 💛 🌘 🐍 🏗-🛠️ ❔ ⚫️ 🍵 📐-💼.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial001.py hl[2,7] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⚫️ 💪 👈 `ORJSONResponse` 💪 ⏩ 🎛.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `RedirectResponse`
|
|
||||||
|
|
||||||
📨 🇺🇸🔍 ❎. ⚙️ 3️⃣0️⃣7️⃣ 👔 📟 (🍕 ❎) 🔢.
|
|
||||||
|
|
||||||
👆 💪 📨 `RedirectResponse` 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial006.py hl[2,9] *}
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
⚖️ 👆 💪 ⚙️ ⚫️ `response_class` 🔢:
|
|
||||||
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial006b.py hl[2,7,9] *}
|
|
||||||
|
|
||||||
🚥 👆 👈, ⤴️ 👆 💪 📨 📛 🔗 ⚪️➡️ 👆 *➡ 🛠️* 🔢.
|
|
||||||
|
|
||||||
👉 💼, `status_code` ⚙️ 🔜 🔢 1️⃣ `RedirectResponse`, ❔ `307`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `status_code` 🔢 🌀 ⏮️ `response_class` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial006c.py hl[2,7,9] *}
|
|
||||||
|
|
||||||
### `StreamingResponse`
|
|
||||||
|
|
||||||
✊ 🔁 🚂 ⚖️ 😐 🚂/🎻 & 🎏 📨 💪.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial007.py hl[2,14] *}
|
|
||||||
|
|
||||||
#### ⚙️ `StreamingResponse` ⏮️ 📁-💖 🎚
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 📁-💖 🎚 (✅ 🎚 📨 `open()`), 👆 💪 ✍ 🚂 🔢 🔁 🤭 👈 📁-💖 🎚.
|
|
||||||
|
|
||||||
👈 🌌, 👆 🚫 ✔️ ✍ ⚫️ 🌐 🥇 💾, & 👆 💪 🚶♀️ 👈 🚂 🔢 `StreamingResponse`, & 📨 ⚫️.
|
|
||||||
|
|
||||||
👉 🔌 📚 🗃 🔗 ⏮️ ☁ 💾, 📹 🏭, & 🎏.
|
|
||||||
|
|
||||||
```{ .python .annotate hl_lines="2 10-12 14" }
|
|
||||||
{!../../docs_src/custom_response/tutorial008.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
1️⃣. 👉 🚂 🔢. ⚫️ "🚂 🔢" ↩️ ⚫️ 🔌 `yield` 📄 🔘.
|
|
||||||
2️⃣. ⚙️ `with` 🍫, 👥 ⚒ 💭 👈 📁-💖 🎚 📪 ⏮️ 🚂 🔢 🔨. , ⏮️ ⚫️ 🏁 📨 📨.
|
|
||||||
3️⃣. 👉 `yield from` 💬 🔢 🔁 🤭 👈 👜 🌟 `file_like`. & ⤴️, 🔠 🍕 🔁, 🌾 👈 🍕 👟 ⚪️➡️ 👉 🚂 🔢.
|
|
||||||
|
|
||||||
, ⚫️ 🚂 🔢 👈 📨 "🏭" 👷 🕳 🙆 🔘.
|
|
||||||
|
|
||||||
🔨 ⚫️ 👉 🌌, 👥 💪 🚮 ⚫️ `with` 🍫, & 👈 🌌, 🚚 👈 ⚫️ 📪 ⏮️ 🏁.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 📥 👥 ⚙️ 🐩 `open()` 👈 🚫 🐕🦺 `async` & `await`, 👥 📣 ➡ 🛠️ ⏮️ 😐 `def`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `FileResponse`
|
|
||||||
|
|
||||||
🔁 🎏 📁 📨.
|
|
||||||
|
|
||||||
✊ 🎏 ⚒ ❌ 🔗 🌘 🎏 📨 🆎:
|
|
||||||
|
|
||||||
* `path` - 📁 📁 🎏.
|
|
||||||
* `headers` - 🙆 🛃 🎚 🔌, 📖.
|
|
||||||
* `media_type` - 🎻 🤝 📻 🆎. 🚥 🔢, 📁 ⚖️ ➡ 🔜 ⚙️ 🔑 📻 🆎.
|
|
||||||
* `filename` - 🚥 ⚒, 👉 🔜 🔌 📨 `Content-Disposition`.
|
|
||||||
|
|
||||||
📁 📨 🔜 🔌 ☑ `Content-Length`, `Last-Modified` & `ETag` 🎚.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial009.py hl[2,10] *}
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `response_class` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial009b.py hl[2,8,10] *}
|
|
||||||
|
|
||||||
👉 💼, 👆 💪 📨 📁 ➡ 🔗 ⚪️➡️ 👆 *➡ 🛠️* 🔢.
|
|
||||||
|
|
||||||
## 🛃 📨 🎓
|
|
||||||
|
|
||||||
👆 💪 ✍ 👆 👍 🛃 📨 🎓, 😖 ⚪️➡️ `Response` & ⚙️ ⚫️.
|
|
||||||
|
|
||||||
🖼, ➡️ 💬 👈 👆 💚 ⚙️ <a href="https://github.com/ijl/orjson" class="external-link" target="_blank">`orjson`</a>, ✋️ ⏮️ 🛃 ⚒ 🚫 ⚙️ 🔌 `ORJSONResponse` 🎓.
|
|
||||||
|
|
||||||
➡️ 💬 👆 💚 ⚫️ 📨 🔂 & 📁 🎻, 👆 💚 ⚙️ Orjson 🎛 `orjson.OPT_INDENT_2`.
|
|
||||||
|
|
||||||
👆 💪 ✍ `CustomORJSONResponse`. 👑 👜 👆 ✔️ ✍ `Response.render(content)` 👩🔬 👈 📨 🎚 `bytes`:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial009c.py hl[9:14,17] *}
|
|
||||||
|
|
||||||
🔜 ↩️ 🛬:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{"message": "Hello World"}
|
|
||||||
```
|
|
||||||
|
|
||||||
...👉 📨 🔜 📨:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"message": "Hello World"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
↗️, 👆 🔜 🎲 🔎 🌅 👍 🌌 ✊ 📈 👉 🌘 ❕ 🎻. 👶
|
|
||||||
|
|
||||||
## 🔢 📨 🎓
|
|
||||||
|
|
||||||
🕐❔ 🏗 **FastAPI** 🎓 👐 ⚖️ `APIRouter` 👆 💪 ✔ ❔ 📨 🎓 ⚙️ 🔢.
|
|
||||||
|
|
||||||
🔢 👈 🔬 👉 `default_response_class`.
|
|
||||||
|
|
||||||
🖼 🔛, **FastAPI** 🔜 ⚙️ `ORJSONResponse` 🔢, 🌐 *➡ 🛠️*, ↩️ `JSONResponse`.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_response/tutorial010.py hl[2,4] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 🔐 `response_class` *➡ 🛠️* ⏭.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌖 🧾
|
|
||||||
|
|
||||||
👆 💪 📣 📻 🆎 & 📚 🎏 ℹ 🗄 ⚙️ `responses`: [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
# ⚙️ 🎻
|
|
||||||
|
|
||||||
FastAPI 🏗 🔛 🔝 **Pydantic**, & 👤 ✔️ 🌏 👆 ❔ ⚙️ Pydantic 🏷 📣 📨 & 📨.
|
|
||||||
|
|
||||||
✋️ FastAPI 🐕🦺 ⚙️ <a href="https://docs.python.org/3/library/dataclasses.html" class="external-link" target="_blank">`dataclasses`</a> 🎏 🌌:
|
|
||||||
|
|
||||||
{* ../../docs_src/dataclasses/tutorial001.py hl[1,7:12,19:20] *}
|
|
||||||
|
|
||||||
👉 🐕🦺 👏 **Pydantic**, ⚫️ ✔️ <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/#use-of-stdlib-dataclasses-with-basemodel" class="external-link" target="_blank">🔗 🐕🦺 `dataclasses`</a>.
|
|
||||||
|
|
||||||
, ⏮️ 📟 🔛 👈 🚫 ⚙️ Pydantic 🎯, FastAPI ⚙️ Pydantic 🗜 📚 🐩 🎻 Pydantic 👍 🍛 🎻.
|
|
||||||
|
|
||||||
& ↗️, ⚫️ 🐕🦺 🎏:
|
|
||||||
|
|
||||||
* 💽 🔬
|
|
||||||
* 💽 🛠️
|
|
||||||
* 💽 🧾, ♒️.
|
|
||||||
|
|
||||||
👉 👷 🎏 🌌 ⏮️ Pydantic 🏷. & ⚫️ 🤙 🏆 🎏 🌌 🔘, ⚙️ Pydantic.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🎻 💪 🚫 🌐 Pydantic 🏷 💪.
|
|
||||||
|
|
||||||
, 👆 5️⃣📆 💪 ⚙️ Pydantic 🏷.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 ✔️ 📚 🎻 🤥 🤭, 👉 👌 🎱 ⚙️ 👫 🏋️ 🕸 🛠️ ⚙️ FastAPI. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🎻 `response_model`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `dataclasses` `response_model` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/dataclasses/tutorial002.py hl[1,7:13,19] *}
|
|
||||||
|
|
||||||
🎻 🔜 🔁 🗜 Pydantic 🎻.
|
|
||||||
|
|
||||||
👉 🌌, 🚮 🔗 🔜 🎦 🆙 🛠️ 🩺 👩💻 🔢:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/dataclasses/image01.png">
|
|
||||||
|
|
||||||
## 🎻 🔁 📊 📊
|
|
||||||
|
|
||||||
👆 💪 🌀 `dataclasses` ⏮️ 🎏 🆎 ✍ ⚒ 🐦 📊 📊.
|
|
||||||
|
|
||||||
💼, 👆 💪 ✔️ ⚙️ Pydantic ⏬ `dataclasses`. 🖼, 🚥 👆 ✔️ ❌ ⏮️ 🔁 🏗 🛠️ 🧾.
|
|
||||||
|
|
||||||
👈 💼, 👆 💪 🎯 💱 🐩 `dataclasses` ⏮️ `pydantic.dataclasses`, ❔ 💧-♻:
|
|
||||||
|
|
||||||
```{ .python .annotate hl_lines="1 5 8-11 14-17 23-25 28" }
|
|
||||||
{!../../docs_src/dataclasses/tutorial003.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
1️⃣. 👥 🗄 `field` ⚪️➡️ 🐩 `dataclasses`.
|
|
||||||
|
|
||||||
2️⃣. `pydantic.dataclasses` 💧-♻ `dataclasses`.
|
|
||||||
|
|
||||||
3️⃣. `Author` 🎻 🔌 📇 `Item` 🎻.
|
|
||||||
|
|
||||||
4️⃣. `Author` 🎻 ⚙️ `response_model` 🔢.
|
|
||||||
|
|
||||||
5️⃣. 👆 💪 ⚙️ 🎏 🐩 🆎 ✍ ⏮️ 🎻 📨 💪.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 📇 `Item` 🎻.
|
|
||||||
|
|
||||||
6️⃣. 📥 👥 🛬 📖 👈 🔌 `items` ❔ 📇 🎻.
|
|
||||||
|
|
||||||
FastAPI 🎯 <abbr title="converting the data to a format that can be transmitted">✍</abbr> 💽 🎻.
|
|
||||||
|
|
||||||
7️⃣. 📥 `response_model` ⚙️ 🆎 ✍ 📇 `Author` 🎻.
|
|
||||||
|
|
||||||
🔄, 👆 💪 🌀 `dataclasses` ⏮️ 🐩 🆎 ✍.
|
|
||||||
|
|
||||||
8️⃣. 👀 👈 👉 *➡ 🛠️ 🔢* ⚙️ 🥔 `def` ↩️ `async def`.
|
|
||||||
|
|
||||||
🕧, FastAPI 👆 💪 🌀 `def` & `async def` 💪.
|
|
||||||
|
|
||||||
🚥 👆 💪 ↗️ 🔃 🕐❔ ⚙️ ❔, ✅ 👅 📄 _"🏃 ❓" _ 🩺 🔃 <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank" class="internal-link">`async` & `await`</a>.
|
|
||||||
|
|
||||||
9️⃣. 👉 *➡ 🛠️ 🔢* 🚫 🛬 🎻 (👐 ⚫️ 💪), ✋️ 📇 📖 ⏮️ 🔗 💽.
|
|
||||||
|
|
||||||
FastAPI 🔜 ⚙️ `response_model` 🔢 (👈 🔌 🎻) 🗜 📨.
|
|
||||||
|
|
||||||
👆 💪 🌀 `dataclasses` ⏮️ 🎏 🆎 ✍ 📚 🎏 🌀 📨 🏗 📊 📊.
|
|
||||||
|
|
||||||
✅-📟 ✍ 💁♂ 🔛 👀 🌅 🎯 ℹ.
|
|
||||||
|
|
||||||
## 💡 🌅
|
|
||||||
|
|
||||||
👆 💪 🌀 `dataclasses` ⏮️ 🎏 Pydantic 🏷, 😖 ⚪️➡️ 👫, 🔌 👫 👆 👍 🏷, ♒️.
|
|
||||||
|
|
||||||
💡 🌅, ✅ <a href="https://docs.pydantic.dev/latest/concepts/dataclasses/" class="external-link" target="_blank">Pydantic 🩺 🔃 🎻</a>.
|
|
||||||
|
|
||||||
## ⏬
|
|
||||||
|
|
||||||
👉 💪 ↩️ FastAPI ⏬ `0.67.0`. 👶
|
|
||||||
|
|
@ -1,163 +0,0 @@
|
||||||
# 🔆 🎉
|
|
||||||
|
|
||||||
👆 💪 🔬 ⚛ (📟) 👈 🔜 🛠️ ⏭ 🈸 **▶️ 🆙**. 👉 ⛓ 👈 👉 📟 🔜 🛠️ **🕐**, **⏭** 🈸 **▶️ 📨 📨**.
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 🔬 ⚛ (📟) 👈 🔜 🛠️ 🕐❔ 🈸 **🤫 🔽**. 👉 💼, 👉 📟 🔜 🛠️ **🕐**, **⏮️** ✔️ 🍵 🎲 **📚 📨**.
|
|
||||||
|
|
||||||
↩️ 👉 📟 🛠️ ⏭ 🈸 **▶️** ✊ 📨, & ▶️️ ⏮️ ⚫️ **🏁** 🚚 📨, ⚫️ 📔 🎂 🈸 **🔆** (🔤 "🔆" 🔜 ⚠ 🥈 👶).
|
|
||||||
|
|
||||||
👉 💪 📶 ⚠ ⚒ 🆙 **ℹ** 👈 👆 💪 ⚙️ 🎂 📱, & 👈 **💰** 👪 📨, &/⚖️ 👈 👆 💪 **🧹 🆙** ⏮️. 🖼, 💽 🔗 🎱, ⚖️ 🚚 🔗 🎰 🏫 🏷.
|
|
||||||
|
|
||||||
## ⚙️ 💼
|
|
||||||
|
|
||||||
➡️ ▶️ ⏮️ 🖼 **⚙️ 💼** & ⤴️ 👀 ❔ ❎ ⚫️ ⏮️ 👉.
|
|
||||||
|
|
||||||
➡️ 🌈 👈 👆 ✔️ **🎰 🏫 🏷** 👈 👆 💚 ⚙️ 🍵 📨. 👶
|
|
||||||
|
|
||||||
🎏 🏷 🔗 👪 📨,, ⚫️ 🚫 1️⃣ 🏷 📍 📨, ⚖️ 1️⃣ 📍 👩💻 ⚖️ 🕳 🎏.
|
|
||||||
|
|
||||||
➡️ 🌈 👈 🚚 🏷 💪 **✊ 🕰**, ↩️ ⚫️ ✔️ ✍ 📚 **💽 ⚪️➡️ 💾**. 👆 🚫 💚 ⚫️ 🔠 📨.
|
|
||||||
|
|
||||||
👆 💪 📐 ⚫️ 🔝 🎚 🕹/📁, ✋️ 👈 🔜 ⛓ 👈 ⚫️ 🔜 **📐 🏷** 🚥 👆 🏃♂ 🙅 🏧 💯, ⤴️ 👈 💯 🔜 **🐌** ↩️ ⚫️ 🔜 ✔️ ⌛ 🏷 📐 ⏭ 💆♂ 💪 🏃 🔬 🍕 📟.
|
|
||||||
|
|
||||||
👈 ⚫️❔ 👥 🔜 ❎, ➡️ 📐 🏷 ⏭ 📨 🍵, ✋️ 🕴 ▶️️ ⏭ 🈸 ▶️ 📨 📨, 🚫 ⏪ 📟 ➖ 📐.
|
|
||||||
|
|
||||||
## 🔆
|
|
||||||
|
|
||||||
👆 💪 🔬 👉 *🕴* & *🤫* ⚛ ⚙️ `lifespan` 🔢 `FastAPI` 📱, & "🔑 👨💼" (👤 🔜 🎦 👆 ⚫️❔ 👈 🥈).
|
|
||||||
|
|
||||||
➡️ ▶️ ⏮️ 🖼 & ⤴️ 👀 ⚫️ ℹ.
|
|
||||||
|
|
||||||
👥 ✍ 🔁 🔢 `lifespan()` ⏮️ `yield` 💖 👉:
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial003.py hl[16,19] *}
|
|
||||||
|
|
||||||
📥 👥 ⚖ 😥 *🕴* 🛠️ 🚚 🏷 🚮 (❌) 🏷 🔢 📖 ⏮️ 🎰 🏫 🏷 ⏭ `yield`. 👉 📟 🔜 🛠️ **⏭** 🈸 **▶️ ✊ 📨**, ⏮️ *🕴*.
|
|
||||||
|
|
||||||
& ⤴️, ▶️️ ⏮️ `yield`, 👥 🚚 🏷. 👉 📟 🔜 🛠️ **⏮️** 🈸 **🏁 🚚 📨**, ▶️️ ⏭ *🤫*. 👉 💪, 🖼, 🚀 ℹ 💖 💾 ⚖️ 💻.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
`shutdown` 🔜 🔨 🕐❔ 👆 **⛔️** 🈸.
|
|
||||||
|
|
||||||
🎲 👆 💪 ▶️ 🆕 ⏬, ⚖️ 👆 🤚 🎡 🏃 ⚫️. 🤷
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔆 🔢
|
|
||||||
|
|
||||||
🥇 👜 👀, 👈 👥 ⚖ 🔁 🔢 ⏮️ `yield`. 👉 📶 🎏 🔗 ⏮️ `yield`.
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial003.py hl[14:19] *}
|
|
||||||
|
|
||||||
🥇 🍕 🔢, ⏭ `yield`, 🔜 🛠️ **⏭** 🈸 ▶️.
|
|
||||||
|
|
||||||
& 🍕 ⏮️ `yield` 🔜 🛠️ **⏮️** 🈸 ✔️ 🏁.
|
|
||||||
|
|
||||||
### 🔁 🔑 👨💼
|
|
||||||
|
|
||||||
🚥 👆 ✅, 🔢 🎀 ⏮️ `@asynccontextmanager`.
|
|
||||||
|
|
||||||
👈 🗜 🔢 🔘 🕳 🤙 "**🔁 🔑 👨💼**".
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial003.py hl[1,13] *}
|
|
||||||
|
|
||||||
**🔑 👨💼** 🐍 🕳 👈 👆 💪 ⚙️ `with` 📄, 🖼, `open()` 💪 ⚙️ 🔑 👨💼:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
with open("file.txt") as file:
|
|
||||||
file.read()
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ ⏬ 🐍, 📤 **🔁 🔑 👨💼**. 👆 🔜 ⚙️ ⚫️ ⏮️ `async with`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
async with lifespan(app):
|
|
||||||
await do_stuff()
|
|
||||||
```
|
|
||||||
|
|
||||||
🕐❔ 👆 ✍ 🔑 👨💼 ⚖️ 🔁 🔑 👨💼 💖 🔛, ⚫️❔ ⚫️ 🔨 👈, ⏭ 🛬 `with` 🍫, ⚫️ 🔜 🛠️ 📟 ⏭ `yield`, & ⏮️ ❎ `with` 🍫, ⚫️ 🔜 🛠️ 📟 ⏮️ `yield`.
|
|
||||||
|
|
||||||
👆 📟 🖼 🔛, 👥 🚫 ⚙️ ⚫️ 🔗, ✋️ 👥 🚶♀️ ⚫️ FastAPI ⚫️ ⚙️ ⚫️.
|
|
||||||
|
|
||||||
`lifespan` 🔢 `FastAPI` 📱 ✊ **🔁 🔑 👨💼**, 👥 💪 🚶♀️ 👆 🆕 `lifespan` 🔁 🔑 👨💼 ⚫️.
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial003.py hl[22] *}
|
|
||||||
|
|
||||||
## 🎛 🎉 (😢)
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👍 🌌 🍵 *🕴* & *🤫* ⚙️ `lifespan` 🔢 `FastAPI` 📱 🔬 🔛.
|
|
||||||
|
|
||||||
👆 💪 🎲 🚶 👉 🍕.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
📤 🎛 🌌 🔬 👉 ⚛ 🛠️ ⏮️ *🕴* & ⏮️ *🤫*.
|
|
||||||
|
|
||||||
👆 💪 🔬 🎉 🐕🦺 (🔢) 👈 💪 🛠️ ⏭ 🈸 ▶️ 🆙, ⚖️ 🕐❔ 🈸 🤫 🔽.
|
|
||||||
|
|
||||||
👫 🔢 💪 📣 ⏮️ `async def` ⚖️ 😐 `def`.
|
|
||||||
|
|
||||||
### `startup` 🎉
|
|
||||||
|
|
||||||
🚮 🔢 👈 🔜 🏃 ⏭ 🈸 ▶️, 📣 ⚫️ ⏮️ 🎉 `"startup"`:
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial001.py hl[8] *}
|
|
||||||
|
|
||||||
👉 💼, `startup` 🎉 🐕🦺 🔢 🔜 🔢 🏬 "💽" ( `dict`) ⏮️ 💲.
|
|
||||||
|
|
||||||
👆 💪 🚮 🌅 🌘 1️⃣ 🎉 🐕🦺 🔢.
|
|
||||||
|
|
||||||
& 👆 🈸 🏆 🚫 ▶️ 📨 📨 ⏭ 🌐 `startup` 🎉 🐕🦺 ✔️ 🏁.
|
|
||||||
|
|
||||||
### `shutdown` 🎉
|
|
||||||
|
|
||||||
🚮 🔢 👈 🔜 🏃 🕐❔ 🈸 🤫 🔽, 📣 ⚫️ ⏮️ 🎉 `"shutdown"`:
|
|
||||||
|
|
||||||
{* ../../docs_src/events/tutorial002.py hl[6] *}
|
|
||||||
|
|
||||||
📥, `shutdown` 🎉 🐕🦺 🔢 🔜 ✍ ✍ ⏸ `"Application shutdown"` 📁 `log.txt`.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`open()` 🔢, `mode="a"` ⛓ "🎻",, ⏸ 🔜 🚮 ⏮️ ⚫️❔ 🔛 👈 📁, 🍵 📁 ⏮️ 🎚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 👉 💼 👥 ⚙️ 🐩 🐍 `open()` 🔢 👈 🔗 ⏮️ 📁.
|
|
||||||
|
|
||||||
, ⚫️ 🔌 👤/🅾 (🔢/🔢), 👈 🚚 "⌛" 👜 ✍ 💾.
|
|
||||||
|
|
||||||
✋️ `open()` 🚫 ⚙️ `async` & `await`.
|
|
||||||
|
|
||||||
, 👥 📣 🎉 🐕🦺 🔢 ⏮️ 🐩 `def` ↩️ `async def`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌅 🔃 👫 🎉 🐕🦺 <a href="https://www.starlette.dev/events/" class="external-link" target="_blank">💃 🎉' 🩺</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `startup` & `shutdown` 👯♂️
|
|
||||||
|
|
||||||
📤 ↕ 🤞 👈 ⚛ 👆 *🕴* & *🤫* 🔗, 👆 💪 💚 ▶️ 🕳 & ⤴️ 🏁 ⚫️, 📎 ℹ & ⤴️ 🚀 ⚫️, ♒️.
|
|
||||||
|
|
||||||
🔨 👈 👽 🔢 👈 🚫 💰 ⚛ ⚖️ 🔢 👯♂️ 🌅 ⚠ 👆 🔜 💪 🏪 💲 🌐 🔢 ⚖️ 🎏 🎱.
|
|
||||||
|
|
||||||
↩️ 👈, ⚫️ 🔜 👍 ↩️ ⚙️ `lifespan` 🔬 🔛.
|
|
||||||
|
|
||||||
## 📡 ℹ
|
|
||||||
|
|
||||||
📡 ℹ 😟 🤓. 👶
|
|
||||||
|
|
||||||
🔘, 🔫 📡 🔧, 👉 🍕 <a href="https://asgi.readthedocs.io/en/latest/specs/lifespan.html" class="external-link" target="_blank">🔆 🛠️</a>, & ⚫️ 🔬 🎉 🤙 `startup` & `shutdown`.
|
|
||||||
|
|
||||||
## 🎧 🈸
|
|
||||||
|
|
||||||
👶 ✔️ 🤯 👈 👫 🔆 🎉 (🕴 & 🤫) 🔜 🕴 🛠️ 👑 🈸, 🚫 [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,238 +0,0 @@
|
||||||
# 🏗 👩💻
|
|
||||||
|
|
||||||
**FastAPI** ⚓️ 🔛 🗄 🔧, 👆 🤚 🏧 🔗 ⏮️ 📚 🧰, 🔌 🏧 🛠️ 🩺 (🚚 🦁 🎚).
|
|
||||||
|
|
||||||
1️⃣ 🎯 📈 👈 🚫 🎯 ⭐ 👈 👆 💪 **🏗 👩💻** (🕣 🤙 <abbr title="Software Development Kits">**📱**</abbr> ) 👆 🛠️, 📚 🎏 **🛠️ 🇪🇸**.
|
|
||||||
|
|
||||||
## 🗄 👩💻 🚂
|
|
||||||
|
|
||||||
📤 📚 🧰 🏗 👩💻 ⚪️➡️ **🗄**.
|
|
||||||
|
|
||||||
⚠ 🧰 <a href="https://openapi-generator.tech/" class="external-link" target="_blank">🗄 🚂</a>.
|
|
||||||
|
|
||||||
🚥 👆 🏗 **🕸**, 📶 😌 🎛 <a href="https://github.com/hey-api/openapi-ts" class="external-link" target="_blank">🗄-📕-🇦🇪</a>.
|
|
||||||
|
|
||||||
## 🏗 📕 🕸 👩💻
|
|
||||||
|
|
||||||
➡️ ▶️ ⏮️ 🙅 FastAPI 🈸:
|
|
||||||
|
|
||||||
{* ../../docs_src/generate_clients/tutorial001.py hl[9:11,14:15,18,19,23] *}
|
|
||||||
|
|
||||||
👀 👈 *➡ 🛠️* 🔬 🏷 👫 ⚙️ 📨 🚀 & 📨 🚀, ⚙️ 🏷 `Item` & `ResponseMessage`.
|
|
||||||
|
|
||||||
### 🛠️ 🩺
|
|
||||||
|
|
||||||
🚥 👆 🚶 🛠️ 🩺, 👆 🔜 👀 👈 ⚫️ ✔️ **🔗** 📊 📨 📨 & 📨 📨:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image01.png">
|
|
||||||
|
|
||||||
👆 💪 👀 👈 🔗 ↩️ 👫 📣 ⏮️ 🏷 📱.
|
|
||||||
|
|
||||||
👈 ℹ 💪 📱 **🗄 🔗**, & ⤴️ 🎦 🛠️ 🩺 (🦁 🎚).
|
|
||||||
|
|
||||||
& 👈 🎏 ℹ ⚪️➡️ 🏷 👈 🔌 🗄 ⚫️❔ 💪 ⚙️ **🏗 👩💻 📟**.
|
|
||||||
|
|
||||||
### 🏗 📕 👩💻
|
|
||||||
|
|
||||||
🔜 👈 👥 ✔️ 📱 ⏮️ 🏷, 👥 💪 🏗 👩💻 📟 🕸.
|
|
||||||
|
|
||||||
#### ❎ `openapi-ts`
|
|
||||||
|
|
||||||
👆 💪 ❎ `openapi-ts` 👆 🕸 📟 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ npm install @hey-api/openapi-ts --save-dev
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
#### 🏗 👩💻 📟
|
|
||||||
|
|
||||||
🏗 👩💻 📟 👆 💪 ⚙️ 📋 ⏸ 🈸 `openapi-ts` 👈 🔜 🔜 ❎.
|
|
||||||
|
|
||||||
↩️ ⚫️ ❎ 🇧🇿 🏗, 👆 🎲 🚫🔜 💪 🤙 👈 📋 🔗, ✋️ 👆 🔜 🚮 ⚫️ 🔛 👆 `package.json` 📁.
|
|
||||||
|
|
||||||
⚫️ 💪 👀 💖 👉:
|
|
||||||
|
|
||||||
```JSON hl_lines="7"
|
|
||||||
{
|
|
||||||
"name": "frontend-app",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"generate-client": "openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "",
|
|
||||||
"devDependencies": {
|
|
||||||
"@hey-api/openapi-ts": "^0.27.38",
|
|
||||||
"typescript": "^4.6.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ ✔️ 👈 ☕ `generate-client` ✍ 📤, 👆 💪 🏃 ⚫️ ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ npm run generate-client
|
|
||||||
|
|
||||||
frontend-app@1.0.0 generate-client /home/user/code/frontend-app
|
|
||||||
> openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
👈 📋 🔜 🏗 📟 `./src/client` & 🔜 ⚙️ `axios` (🕸 🇺🇸🔍 🗃) 🔘.
|
|
||||||
|
|
||||||
### 🔄 👅 👩💻 📟
|
|
||||||
|
|
||||||
🔜 👆 💪 🗄 & ⚙️ 👩💻 📟, ⚫️ 💪 👀 💖 👉, 👀 👈 👆 🤚 ✍ 👩🔬:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image02.png">
|
|
||||||
|
|
||||||
👆 🔜 🤚 ✍ 🚀 📨:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image03.png">
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 ✍ `name` & `price`, 👈 🔬 FastAPI 🈸, `Item` 🏷.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 🔜 ✔️ ⏸ ❌ 📊 👈 👆 📨:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image04.png">
|
|
||||||
|
|
||||||
📨 🎚 🔜 ✔️ ✍:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image05.png">
|
|
||||||
|
|
||||||
## FastAPI 📱 ⏮️ 🔖
|
|
||||||
|
|
||||||
📚 💼 👆 FastAPI 📱 🔜 🦏, & 👆 🔜 🎲 ⚙️ 🔖 🎏 🎏 👪 *➡ 🛠️*.
|
|
||||||
|
|
||||||
🖼, 👆 💪 ✔️ 📄 **🏬** & ➕1️⃣ 📄 **👩💻**, & 👫 💪 👽 🔖:
|
|
||||||
|
|
||||||
|
|
||||||
{* ../../docs_src/generate_clients/tutorial002.py hl[23,28,36] *}
|
|
||||||
|
|
||||||
### 🏗 📕 👩💻 ⏮️ 🔖
|
|
||||||
|
|
||||||
🚥 👆 🏗 👩💻 FastAPI 📱 ⚙️ 🔖, ⚫️ 🔜 🛎 🎏 👩💻 📟 ⚓️ 🔛 🔖.
|
|
||||||
|
|
||||||
👉 🌌 👆 🔜 💪 ✔️ 👜 ✔ & 👪 ☑ 👩💻 📟:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image06.png">
|
|
||||||
|
|
||||||
👉 💼 👆 ✔️:
|
|
||||||
|
|
||||||
* `ItemsService`
|
|
||||||
* `UsersService`
|
|
||||||
|
|
||||||
### 👩💻 👩🔬 📛
|
|
||||||
|
|
||||||
▶️️ 🔜 🏗 👩🔬 📛 💖 `createItemItemsPost` 🚫 👀 📶 🧹:
|
|
||||||
|
|
||||||
```TypeScript
|
|
||||||
ItemsService.createItemItemsPost({name: "Plumbus", price: 5})
|
|
||||||
```
|
|
||||||
|
|
||||||
...👈 ↩️ 👩💻 🚂 ⚙️ 🗄 🔗 **🛠️ 🆔** 🔠 *➡ 🛠️*.
|
|
||||||
|
|
||||||
🗄 🚚 👈 🔠 🛠️ 🆔 😍 🤭 🌐 *➡ 🛠️*, FastAPI ⚙️ **🔢 📛**, **➡**, & **🇺🇸🔍 👩🔬/🛠️** 🏗 👈 🛠️ 🆔, ↩️ 👈 🌌 ⚫️ 💪 ⚒ 💭 👈 🛠️ 🆔 😍.
|
|
||||||
|
|
||||||
✋️ 👤 🔜 🎦 👆 ❔ 📉 👈 ⏭. 👶
|
|
||||||
|
|
||||||
## 🛃 🛠️ 🆔 & 👍 👩🔬 📛
|
|
||||||
|
|
||||||
👆 💪 **🔀** 🌌 👫 🛠️ 🆔 **🏗** ⚒ 👫 🙅 & ✔️ **🙅 👩🔬 📛** 👩💻.
|
|
||||||
|
|
||||||
👉 💼 👆 🔜 ✔️ 🚚 👈 🔠 🛠️ 🆔 **😍** 🎏 🌌.
|
|
||||||
|
|
||||||
🖼, 👆 💪 ⚒ 💭 👈 🔠 *➡ 🛠️* ✔️ 🔖, & ⤴️ 🏗 🛠️ 🆔 ⚓️ 🔛 **🔖** & *➡ 🛠️* **📛** (🔢 📛).
|
|
||||||
|
|
||||||
### 🛃 🏗 😍 🆔 🔢
|
|
||||||
|
|
||||||
FastAPI ⚙️ **😍 🆔** 🔠 *➡ 🛠️*, ⚫️ ⚙️ **🛠️ 🆔** & 📛 🙆 💪 🛃 🏷, 📨 ⚖️ 📨.
|
|
||||||
|
|
||||||
👆 💪 🛃 👈 🔢. ⚫️ ✊ `APIRoute` & 🔢 🎻.
|
|
||||||
|
|
||||||
🖼, 📥 ⚫️ ⚙️ 🥇 🔖 (👆 🔜 🎲 ✔️ 🕴 1️⃣ 🔖) & *➡ 🛠️* 📛 (🔢 📛).
|
|
||||||
|
|
||||||
👆 💪 ⤴️ 🚶♀️ 👈 🛃 🔢 **FastAPI** `generate_unique_id_function` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/generate_clients/tutorial003.py hl[8:9,12] *}
|
|
||||||
|
|
||||||
### 🏗 📕 👩💻 ⏮️ 🛃 🛠️ 🆔
|
|
||||||
|
|
||||||
🔜 🚥 👆 🏗 👩💻 🔄, 👆 🔜 👀 👈 ⚫️ ✔️ 📉 👩🔬 📛:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image07.png">
|
|
||||||
|
|
||||||
👆 👀, 👩🔬 📛 🔜 ✔️ 🔖 & ⤴️ 🔢 📛, 🔜 👫 🚫 🔌 ℹ ⚪️➡️ 📛 ➡ & 🇺🇸🔍 🛠️.
|
|
||||||
|
|
||||||
### 🗜 🗄 🔧 👩💻 🚂
|
|
||||||
|
|
||||||
🏗 📟 ✔️ **❎ ℹ**.
|
|
||||||
|
|
||||||
👥 ⏪ 💭 👈 👉 👩🔬 🔗 **🏬** ↩️ 👈 🔤 `ItemsService` (✊ ⚪️➡️ 🔖), ✋️ 👥 ✔️ 📛 🔡 👩🔬 📛 💁♂️. 👶
|
|
||||||
|
|
||||||
👥 🔜 🎲 💚 🚧 ⚫️ 🗄 🏢, 👈 🔜 🚚 👈 🛠️ 🆔 **😍**.
|
|
||||||
|
|
||||||
✋️ 🏗 👩💻 👥 💪 **🔀** 🗄 🛠️ 🆔 ▶️️ ⏭ 🏭 👩💻, ⚒ 👈 👩🔬 📛 👌 & **🧹**.
|
|
||||||
|
|
||||||
👥 💪 ⏬ 🗄 🎻 📁 `openapi.json` & ⤴️ 👥 💪 **❎ 👈 🔡 🔖** ⏮️ ✍ 💖 👉:
|
|
||||||
|
|
||||||
{* ../../docs_src/generate_clients/tutorial004.py *}
|
|
||||||
|
|
||||||
⏮️ 👈, 🛠️ 🆔 🔜 📁 ⚪️➡️ 👜 💖 `items-get_items` `get_items`, 👈 🌌 👩💻 🚂 💪 🏗 🙅 👩🔬 📛.
|
|
||||||
|
|
||||||
### 🏗 📕 👩💻 ⏮️ 🗜 🗄
|
|
||||||
|
|
||||||
🔜 🔚 🏁 📁 `openapi.json`, 👆 🔜 🔀 `package.json` ⚙️ 👈 🇧🇿 📁, 🖼:
|
|
||||||
|
|
||||||
```JSON hl_lines="7"
|
|
||||||
{
|
|
||||||
"name": "frontend-app",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios"
|
|
||||||
},
|
|
||||||
"author": "",
|
|
||||||
"license": "",
|
|
||||||
"devDependencies": {
|
|
||||||
"@hey-api/openapi-ts": "^0.27.38",
|
|
||||||
"typescript": "^4.6.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ 🏭 🆕 👩💻, 👆 🔜 🔜 ✔️ **🧹 👩🔬 📛**, ⏮️ 🌐 **✍**, **⏸ ❌**, ♒️:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/generate-clients/image08.png">
|
|
||||||
|
|
||||||
## 💰
|
|
||||||
|
|
||||||
🕐❔ ⚙️ 🔁 🏗 👩💻 👆 🔜 **✍** :
|
|
||||||
|
|
||||||
* 👩🔬.
|
|
||||||
* 📨 🚀 💪, 🔢 🔢, ♒️.
|
|
||||||
* 📨 🚀.
|
|
||||||
|
|
||||||
👆 🔜 ✔️ **⏸ ❌** 🌐.
|
|
||||||
|
|
||||||
& 🕐❔ 👆 ℹ 👩💻 📟, & **♻** 🕸, ⚫️ 🔜 ✔️ 🙆 🆕 *➡ 🛠️* 💪 👩🔬, 🗝 🕐 ❎, & 🙆 🎏 🔀 🔜 🎨 🔛 🏗 📟. 👶
|
|
||||||
|
|
||||||
👉 ⛓ 👈 🚥 🕳 🔀 ⚫️ 🔜 **🎨** 🔛 👩💻 📟 🔁. & 🚥 👆 **🏗** 👩💻 ⚫️ 🔜 ❌ 👅 🚥 👆 ✔️ 🙆 **🔖** 📊 ⚙️.
|
|
||||||
|
|
||||||
, 👆 🔜 **🔍 📚 ❌** 📶 ⏪ 🛠️ 🛵 ↩️ ✔️ ⌛ ❌ 🎦 🆙 👆 🏁 👩💻 🏭 & ⤴️ 🔄 ℹ 🌐❔ ⚠. 👶
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
# 🏧 👩💻 🦮
|
|
||||||
|
|
||||||
## 🌖 ⚒
|
|
||||||
|
|
||||||
👑 [🔰 - 👩💻 🦮](../tutorial/index.md){.internal-link target=_blank} 🔜 🥃 🤝 👆 🎫 🔘 🌐 👑 ⚒ **FastAPI**.
|
|
||||||
|
|
||||||
⏭ 📄 👆 🔜 👀 🎏 🎛, 📳, & 🌖 ⚒.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⏭ 📄 **🚫 🎯 "🏧"**.
|
|
||||||
|
|
||||||
& ⚫️ 💪 👈 👆 ⚙️ 💼, ⚗ 1️⃣ 👫.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✍ 🔰 🥇
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🏆 ⚒ **FastAPI** ⏮️ 💡 ⚪️➡️ 👑 [🔰 - 👩💻 🦮](../tutorial/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
& ⏭ 📄 🤔 👆 ⏪ ✍ ⚫️, & 🤔 👈 👆 💭 👈 👑 💭.
|
|
||||||
|
|
||||||
## 🏎.🅾 ↗️
|
|
||||||
|
|
||||||
🚥 👆 🔜 💖 ✊ 🏧-🔰 ↗️ 🔗 👉 📄 🩺, 👆 💪 💚 ✅: <a href="https://testdriven.io/courses/tdd-fastapi/" class="external-link" target="_blank">💯-💾 🛠️ ⏮️ FastAPI & ☁</a> **🏎.🅾**.
|
|
||||||
|
|
||||||
👫 ⏳ 🩸 1️⃣0️⃣ 💯 🌐 💰 🛠️ **FastAPI**. 👶 👶
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
# 🏧 🛠️
|
|
||||||
|
|
||||||
👑 🔰 👆 ✍ ❔ 🚮 [🛃 🛠️](../tutorial/middleware.md){.internal-link target=_blank} 👆 🈸.
|
|
||||||
|
|
||||||
& ⤴️ 👆 ✍ ❔ 🍵 [⚜ ⏮️ `CORSMiddleware`](../tutorial/cors.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👉 📄 👥 🔜 👀 ❔ ⚙️ 🎏 🛠️.
|
|
||||||
|
|
||||||
## ❎ 🔫 🛠️
|
|
||||||
|
|
||||||
**FastAPI** ⚓️ 🔛 💃 & 🛠️ <abbr title="Asynchronous Server Gateway Interface">🔫</abbr> 🔧, 👆 💪 ⚙️ 🙆 🔫 🛠️.
|
|
||||||
|
|
||||||
🛠️ 🚫 ✔️ ⚒ FastAPI ⚖️ 💃 👷, 📏 ⚫️ ⏩ 🔫 🔌.
|
|
||||||
|
|
||||||
🏢, 🔫 🛠️ 🎓 👈 ⌛ 📨 🔫 📱 🥇 ❌.
|
|
||||||
|
|
||||||
, 🧾 🥉-🥳 🔫 🛠️ 👫 🔜 🎲 💬 👆 🕳 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from unicorn import UnicornMiddleware
|
|
||||||
|
|
||||||
app = SomeASGIApp()
|
|
||||||
|
|
||||||
new_app = UnicornMiddleware(app, some_config="rainbow")
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ FastAPI (🤙 💃) 🚚 🙅 🌌 ⚫️ 👈 ⚒ 💭 👈 🔗 🛠️ 🍵 💽 ❌ & 🛃 ⚠ 🐕🦺 👷 ☑.
|
|
||||||
|
|
||||||
👈, 👆 ⚙️ `app.add_middleware()` (🖼 ⚜).
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from unicorn import UnicornMiddleware
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
app.add_middleware(UnicornMiddleware, some_config="rainbow")
|
|
||||||
```
|
|
||||||
|
|
||||||
`app.add_middleware()` 📨 🛠️ 🎓 🥇 ❌ & 🙆 🌖 ❌ 🚶♀️ 🛠️.
|
|
||||||
|
|
||||||
## 🛠️ 🛠️
|
|
||||||
|
|
||||||
**FastAPI** 🔌 📚 🛠️ ⚠ ⚙️ 💼, 👥 🔜 👀 ⏭ ❔ ⚙️ 👫.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
⏭ 🖼, 👆 💪 ⚙️ `from starlette.middleware.something import SomethingMiddleware`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 📚 🛠️ `fastapi.middleware` 🏪 👆, 👩💻. ✋️ 🌅 💪 🛠️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## `HTTPSRedirectMiddleware`
|
|
||||||
|
|
||||||
🛠️ 👈 🌐 📨 📨 🔜 👯♂️ `https` ⚖️ `wss`.
|
|
||||||
|
|
||||||
🙆 📨 📨 `http` ⚖️ `ws` 🔜 ❎ 🔐 ⚖ ↩️.
|
|
||||||
|
|
||||||
{* ../../docs_src/advanced_middleware/tutorial001.py hl[2,6] *}
|
|
||||||
|
|
||||||
## `TrustedHostMiddleware`
|
|
||||||
|
|
||||||
🛠️ 👈 🌐 📨 📨 ✔️ ☑ ⚒ `Host` 🎚, ✔ 💂♂ 🛡 🇺🇸🔍 🦠 🎚 👊.
|
|
||||||
|
|
||||||
{* ../../docs_src/advanced_middleware/tutorial002.py hl[2,6:8] *}
|
|
||||||
|
|
||||||
📄 ❌ 🐕🦺:
|
|
||||||
|
|
||||||
* `allowed_hosts` - 📇 🆔 📛 👈 🔜 ✔ 📛. 🃏 🆔 ✅ `*.example.com` 🐕🦺 🎀 📁. ✔ 🙆 📛 👯♂️ ⚙️ `allowed_hosts=["*"]` ⚖️ 🚫 🛠️.
|
|
||||||
|
|
||||||
🚥 📨 📨 🔨 🚫 ✔ ☑ ⤴️ `400` 📨 🔜 📨.
|
|
||||||
|
|
||||||
## `GZipMiddleware`
|
|
||||||
|
|
||||||
🍵 🗜 📨 🙆 📨 👈 🔌 `"gzip"` `Accept-Encoding` 🎚.
|
|
||||||
|
|
||||||
🛠️ 🔜 🍵 👯♂️ 🐩 & 🎥 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/advanced_middleware/tutorial003.py hl[2,6] *}
|
|
||||||
|
|
||||||
📄 ❌ 🐕🦺:
|
|
||||||
|
|
||||||
* `minimum_size` - 🚫 🗜 📨 👈 🤪 🌘 👉 💯 📐 🔢. 🔢 `500`.
|
|
||||||
|
|
||||||
## 🎏 🛠️
|
|
||||||
|
|
||||||
📤 📚 🎏 🔫 🛠️.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
* <a href="https://github.com/encode/uvicorn/blob/master/uvicorn/middleware/proxy_headers.py" class="external-link" target="_blank">Uvicorn `ProxyHeadersMiddleware`</a>
|
|
||||||
* <a href="https://github.com/florimondmanca/msgpack-asgi" class="external-link" target="_blank">🇸🇲</a>
|
|
||||||
|
|
||||||
👀 🎏 💪 🛠️ ✅ <a href="https://www.starlette.dev/middleware/" class="external-link" target="_blank">💃 🛠️ 🩺</a> & <a href="https://github.com/florimondmanca/awesome-asgi" class="external-link" target="_blank">🔫 👌 📇</a>.
|
|
||||||
|
|
@ -1,186 +0,0 @@
|
||||||
# 🗄 ⏲
|
|
||||||
|
|
||||||
👆 💪 ✍ 🛠️ ⏮️ *➡ 🛠️* 👈 💪 ⏲ 📨 *🔢 🛠️* ✍ 👱 🙆 (🎲 🎏 👩💻 👈 🔜 *⚙️* 👆 🛠️).
|
|
||||||
|
|
||||||
🛠️ 👈 🔨 🕐❔ 👆 🛠️ 📱 🤙 *🔢 🛠️* 📛 "⏲". ↩️ 🖥 👈 🔢 👩💻 ✍ 📨 📨 👆 🛠️ & ⤴️ 👆 🛠️ *🤙 🔙*, 📨 📨 *🔢 🛠️* (👈 🎲 ✍ 🎏 👩💻).
|
|
||||||
|
|
||||||
👉 💼, 👆 💪 💚 📄 ❔ 👈 🔢 🛠️ *🔜* 👀 💖. ⚫️❔ *➡ 🛠️* ⚫️ 🔜 ✔️, ⚫️❔ 💪 ⚫️ 🔜 ⌛, ⚫️❔ 📨 ⚫️ 🔜 📨, ♒️.
|
|
||||||
|
|
||||||
## 📱 ⏮️ ⏲
|
|
||||||
|
|
||||||
➡️ 👀 🌐 👉 ⏮️ 🖼.
|
|
||||||
|
|
||||||
🌈 👆 🛠️ 📱 👈 ✔ 🏗 🧾.
|
|
||||||
|
|
||||||
👉 🧾 🔜 ✔️ `id`, `title` (📦), `customer`, & `total`.
|
|
||||||
|
|
||||||
👩💻 👆 🛠️ (🔢 👩💻) 🔜 ✍ 🧾 👆 🛠️ ⏮️ 🏤 📨.
|
|
||||||
|
|
||||||
⤴️ 👆 🛠️ 🔜 (➡️ 🌈):
|
|
||||||
|
|
||||||
* 📨 🧾 🕴 🔢 👩💻.
|
|
||||||
* 📈 💸.
|
|
||||||
* 📨 📨 🔙 🛠️ 👩💻 (🔢 👩💻).
|
|
||||||
* 👉 🔜 🔨 📨 🏤 📨 (⚪️➡️ *👆 🛠️*) *🔢 🛠️* 🚚 👈 🔢 👩💻 (👉 "⏲").
|
|
||||||
|
|
||||||
## 😐 **FastAPI** 📱
|
|
||||||
|
|
||||||
➡️ 🥇 👀 ❔ 😐 🛠️ 📱 🔜 👀 💖 ⏭ ❎ ⏲.
|
|
||||||
|
|
||||||
⚫️ 🔜 ✔️ *➡ 🛠️* 👈 🔜 📨 `Invoice` 💪, & 🔢 🔢 `callback_url` 👈 🔜 🔌 📛 ⏲.
|
|
||||||
|
|
||||||
👉 🍕 📶 😐, 🌅 📟 🎲 ⏪ 😰 👆:
|
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[9:13,36:53] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
`callback_url` 🔢 🔢 ⚙️ Pydantic <a href="https://docs.pydantic.dev/latest/concepts/types/#urls" class="external-link" target="_blank">📛</a> 🆎.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🕴 🆕 👜 `callbacks=messages_callback_router.routes` ❌ *➡ 🛠️ 👨🎨*. 👥 🔜 👀 ⚫️❔ 👈 ⏭.
|
|
||||||
|
|
||||||
## 🔬 ⏲
|
|
||||||
|
|
||||||
☑ ⏲ 📟 🔜 🪀 🙇 🔛 👆 👍 🛠️ 📱.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 🎲 🪀 📚 ⚪️➡️ 1️⃣ 📱 ⏭.
|
|
||||||
|
|
||||||
⚫️ 💪 1️⃣ ⚖️ 2️⃣ ⏸ 📟, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
callback_url = "https://example.com/api/v1/invoices/events/"
|
|
||||||
httpx.post(callback_url, json={"description": "Invoice paid", "paid": True})
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 🎲 🏆 ⚠ 🍕 ⏲ ⚒ 💭 👈 👆 🛠️ 👩💻 (🔢 👩💻) 🛠️ *🔢 🛠️* ☑, 🛄 💽 👈 *👆 🛠️* 🔜 📨 📨 💪 ⏲, ♒️.
|
|
||||||
|
|
||||||
, ⚫️❔ 👥 🔜 ⏭ 🚮 📟 📄 ❔ 👈 *🔢 🛠️* 🔜 👀 💖 📨 ⏲ ⚪️➡️ *👆 🛠️*.
|
|
||||||
|
|
||||||
👈 🧾 🔜 🎦 🆙 🦁 🎚 `/docs` 👆 🛠️, & ⚫️ 🔜 ➡️ 🔢 👩💻 💭 ❔ 🏗 *🔢 🛠️*.
|
|
||||||
|
|
||||||
👉 🖼 🚫 🛠️ ⏲ ⚫️ (👈 💪 ⏸ 📟), 🕴 🧾 🍕.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
☑ ⏲ 🇺🇸🔍 📨.
|
|
||||||
|
|
||||||
🕐❔ 🛠️ ⏲ 👆, 👆 💪 ⚙️ 🕳 💖 <a href="https://www.python-httpx.org" class="external-link" target="_blank">🇸🇲</a> ⚖️ <a href="https://requests.readthedocs.io/" class="external-link" target="_blank">📨</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✍ ⏲ 🧾 📟
|
|
||||||
|
|
||||||
👉 📟 🏆 🚫 🛠️ 👆 📱, 👥 🕴 💪 ⚫️ *📄* ❔ 👈 *🔢 🛠️* 🔜 👀 💖.
|
|
||||||
|
|
||||||
✋️, 👆 ⏪ 💭 ❔ 💪 ✍ 🏧 🧾 🛠️ ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
👥 🔜 ⚙️ 👈 🎏 💡 📄 ❔ *🔢 🛠️* 🔜 👀 💖... 🏗 *➡ 🛠️(Ⓜ)* 👈 🔢 🛠️ 🔜 🛠️ (🕐 👆 🛠️ 🔜 🤙).
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🕐❔ ✍ 📟 📄 ⏲, ⚫️ 💪 ⚠ 🌈 👈 👆 👈 *🔢 👩💻*. & 👈 👆 ⏳ 🛠️ *🔢 🛠️*, 🚫 *👆 🛠️*.
|
|
||||||
|
|
||||||
🍕 🛠️ 👉 ☝ 🎑 ( *🔢 👩💻*) 💪 ℹ 👆 💭 💖 ⚫️ 🌅 ⭐ 🌐❔ 🚮 🔢, Pydantic 🏷 💪, 📨, ♒️. 👈 *🔢 🛠️*.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ✍ ⏲ `APIRouter`
|
|
||||||
|
|
||||||
🥇 ✍ 🆕 `APIRouter` 👈 🔜 🔌 1️⃣ ⚖️ 🌅 ⏲.
|
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[3,25] *}
|
|
||||||
|
|
||||||
### ✍ ⏲ *➡ 🛠️*
|
|
||||||
|
|
||||||
✍ ⏲ *➡ 🛠️* ⚙️ 🎏 `APIRouter` 👆 ✍ 🔛.
|
|
||||||
|
|
||||||
⚫️ 🔜 👀 💖 😐 FastAPI *➡ 🛠️*:
|
|
||||||
|
|
||||||
* ⚫️ 🔜 🎲 ✔️ 📄 💪 ⚫️ 🔜 📨, ✅ `body: InvoiceEvent`.
|
|
||||||
* & ⚫️ 💪 ✔️ 📄 📨 ⚫️ 🔜 📨, ✅ `response_model=InvoiceEventReceived`.
|
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[16:18,21:22,28:32] *}
|
|
||||||
|
|
||||||
📤 2️⃣ 👑 🔺 ⚪️➡️ 😐 *➡ 🛠️*:
|
|
||||||
|
|
||||||
* ⚫️ 🚫 💪 ✔️ 🙆 ☑ 📟, ↩️ 👆 📱 🔜 🙅 🤙 👉 📟. ⚫️ 🕴 ⚙️ 📄 *🔢 🛠️*. , 🔢 💪 ✔️ `pass`.
|
|
||||||
* *➡* 💪 🔌 <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#key-expression" class="external-link" target="_blank">🗄 3️⃣ 🧬</a> (👀 🌖 🔛) 🌐❔ ⚫️ 💪 ⚙️ 🔢 ⏮️ 🔢 & 🍕 ⏮️ 📨 📨 *👆 🛠️*.
|
|
||||||
|
|
||||||
### ⏲ ➡ 🧬
|
|
||||||
|
|
||||||
⏲ *➡* 💪 ✔️ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md#key-expression" class="external-link" target="_blank">🗄 3️⃣ 🧬</a> 👈 💪 🔌 🍕 ⏮️ 📨 📨 *👆 🛠️*.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ `str`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
"{$callback_url}/invoices/{$request.body.id}"
|
|
||||||
```
|
|
||||||
|
|
||||||
, 🚥 👆 🛠️ 👩💻 (🔢 👩💻) 📨 📨 *👆 🛠️* :
|
|
||||||
|
|
||||||
```
|
|
||||||
https://yourapi.com/invoices/?callback_url=https://www.external.org/events
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ 🎻 💪:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"id": "2expen51ve",
|
|
||||||
"customer": "Mr. Richie Rich",
|
|
||||||
"total": "9999"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
⤴️ *👆 🛠️* 🔜 🛠️ 🧾, & ☝ ⏪, 📨 ⏲ 📨 `callback_url` ( *🔢 🛠️*):
|
|
||||||
|
|
||||||
```
|
|
||||||
https://www.external.org/events/invoices/2expen51ve
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ 🎻 💪 ⚗ 🕳 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"description": "Payment celebration",
|
|
||||||
"paid": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ⚫️ 🔜 ⌛ 📨 ⚪️➡️ 👈 *🔢 🛠️* ⏮️ 🎻 💪 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"ok": true
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 ❔ ⏲ 📛 ⚙️ 🔌 📛 📨 🔢 🔢 `callback_url` (`https://www.external.org/events`) & 🧾 `id` ⚪️➡️ 🔘 🎻 💪 (`2expen51ve`).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🚮 ⏲ 📻
|
|
||||||
|
|
||||||
👉 ☝ 👆 ✔️ *⏲ ➡ 🛠️(Ⓜ)* 💪 (1️⃣(Ⓜ) 👈 *🔢 👩💻* 🔜 🛠️ *🔢 🛠️*) ⏲ 📻 👆 ✍ 🔛.
|
|
||||||
|
|
||||||
🔜 ⚙️ 🔢 `callbacks` *👆 🛠️ ➡ 🛠️ 👨🎨* 🚶♀️ 🔢 `.routes` (👈 🤙 `list` 🛣/*➡ 🛠️*) ⚪️➡️ 👈 ⏲ 📻:
|
|
||||||
|
|
||||||
{* ../../docs_src/openapi_callbacks/tutorial001.py hl[35] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 👆 🚫 🚶♀️ 📻 ⚫️ (`invoices_callback_router`) `callback=`, ✋️ 🔢 `.routes`, `invoices_callback_router.routes`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ✅ 🩺
|
|
||||||
|
|
||||||
🔜 👆 💪 ▶️ 👆 📱 ⏮️ Uvicorn & 🚶 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 👆 🩺 ✅ "⏲" 📄 👆 *➡ 🛠️* 👈 🎦 ❔ *🔢 🛠️* 🔜 👀 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/openapi-callbacks/image01.png">
|
|
||||||
|
|
@ -1,172 +0,0 @@
|
||||||
# ➡ 🛠️ 🏧 📳
|
|
||||||
|
|
||||||
## 🗄 {
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
🚥 👆 🚫 "🕴" 🗄, 👆 🎲 🚫 💪 👉.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 💪 ⚒ 🗄 `operationId` ⚙️ 👆 *➡ 🛠️* ⏮️ 🔢 `operation_id`.
|
|
||||||
|
|
||||||
👆 🔜 ✔️ ⚒ 💭 👈 ⚫️ 😍 🔠 🛠️.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial001.py hl[6] *}
|
|
||||||
|
|
||||||
### ⚙️ *➡ 🛠️ 🔢* 📛 {
|
|
||||||
|
|
||||||
🚥 👆 💚 ⚙️ 👆 🔗' 🔢 📛 `operationId`Ⓜ, 👆 💪 🔁 🤭 🌐 👫 & 🔐 🔠 *➡ 🛠️* `operation_id` ⚙️ 👫 `APIRoute.name`.
|
|
||||||
|
|
||||||
👆 🔜 ⚫️ ⏮️ ❎ 🌐 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial002.py hl[2,12:21,24] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ❎ 🤙 `app.openapi()`, 👆 🔜 ℹ `operationId`Ⓜ ⏭ 👈.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
🚥 👆 👉, 👆 ✔️ ⚒ 💭 🔠 1️⃣ 👆 *➡ 🛠️ 🔢* ✔️ 😍 📛.
|
|
||||||
|
|
||||||
🚥 👫 🎏 🕹 (🐍 📁).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🚫 ⚪️➡️ 🗄
|
|
||||||
|
|
||||||
🚫 *➡ 🛠️* ⚪️➡️ 🏗 🗄 🔗 (& ➡️, ⚪️➡️ 🏧 🧾 ⚙️), ⚙️ 🔢 `include_in_schema` & ⚒ ⚫️ `False`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial003.py hl[6] *}
|
|
||||||
|
|
||||||
## 🏧 📛 ⚪️➡️ #️⃣
|
|
||||||
|
|
||||||
👆 💪 📉 ⏸ ⚙️ ⚪️➡️ #️⃣ *➡ 🛠️ 🔢* 🗄.
|
|
||||||
|
|
||||||
❎ `\f` (😖 "📨 🍼" 🦹) 🤕 **FastAPI** 🔁 🔢 ⚙️ 🗄 👉 ☝.
|
|
||||||
|
|
||||||
⚫️ 🏆 🚫 🎦 🆙 🧾, ✋️ 🎏 🧰 (✅ 🐉) 🔜 💪 ⚙️ 🎂.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial004.py hl[19:29] *}
|
|
||||||
|
|
||||||
## 🌖 📨
|
|
||||||
|
|
||||||
👆 🎲 ✔️ 👀 ❔ 📣 `response_model` & `status_code` *➡ 🛠️*.
|
|
||||||
|
|
||||||
👈 🔬 🗃 🔃 👑 📨 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👆 💪 📣 🌖 📨 ⏮️ 👫 🏷, 👔 📟, ♒️.
|
|
||||||
|
|
||||||
📤 🎂 📃 📥 🧾 🔃 ⚫️, 👆 💪 ✍ ⚫️ [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
## 🗄 ➕
|
|
||||||
|
|
||||||
🕐❔ 👆 📣 *➡ 🛠️* 👆 🈸, **FastAPI** 🔁 🏗 🔗 🗃 🔃 👈 *➡ 🛠️* 🔌 🗄 🔗.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🗄 🔧 ⚫️ 🤙 <a href="https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#operation-object" class="external-link" target="_blank">🛠️ 🎚</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⚫️ ✔️ 🌐 ℹ 🔃 *➡ 🛠️* & ⚙️ 🏗 🏧 🧾.
|
|
||||||
|
|
||||||
⚫️ 🔌 `tags`, `parameters`, `requestBody`, `responses`, ♒️.
|
|
||||||
|
|
||||||
👉 *➡ 🛠️*-🎯 🗄 🔗 🛎 🏗 🔁 **FastAPI**, ✋️ 👆 💪 ↔ ⚫️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 🔅 🎚 ↔ ☝.
|
|
||||||
|
|
||||||
🚥 👆 🕴 💪 📣 🌖 📨, 🌅 🏪 🌌 ⚫️ ⏮️ [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 💪 ↔ 🗄 🔗 *➡ 🛠️* ⚙️ 🔢 `openapi_extra`.
|
|
||||||
|
|
||||||
### 🗄 ↔
|
|
||||||
|
|
||||||
👉 `openapi_extra` 💪 👍, 🖼, 📣 [🗄 ↔](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.3.md#specificationExtensions):
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial005.py hl[6] *}
|
|
||||||
|
|
||||||
🚥 👆 📂 🏧 🛠️ 🩺, 👆 ↔ 🔜 🎦 🆙 🔝 🎯 *➡ 🛠️*.
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-advanced-configuration/image01.png">
|
|
||||||
|
|
||||||
& 🚥 👆 👀 📉 🗄 ( `/openapi.json` 👆 🛠️), 👆 🔜 👀 👆 ↔ 🍕 🎯 *➡ 🛠️* 💁♂️:
|
|
||||||
|
|
||||||
```JSON hl_lines="22"
|
|
||||||
{
|
|
||||||
"openapi": "3.0.2",
|
|
||||||
"info": {
|
|
||||||
"title": "FastAPI",
|
|
||||||
"version": "0.1.0"
|
|
||||||
},
|
|
||||||
"paths": {
|
|
||||||
"/items/": {
|
|
||||||
"get": {
|
|
||||||
"summary": "Read Items",
|
|
||||||
"operationId": "read_items_items__get",
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Successful Response",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"x-aperture-labs-portal": "blue"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🛃 🗄 *➡ 🛠️* 🔗
|
|
||||||
|
|
||||||
📖 `openapi_extra` 🔜 🙇 🔗 ⏮️ 🔁 🏗 🗄 🔗 *➡ 🛠️*.
|
|
||||||
|
|
||||||
, 👆 💪 🚮 🌖 💽 🔁 🏗 🔗.
|
|
||||||
|
|
||||||
🖼, 👆 💪 💭 ✍ & ✔ 📨 ⏮️ 👆 👍 📟, 🍵 ⚙️ 🏧 ⚒ FastAPI ⏮️ Pydantic, ✋️ 👆 💪 💚 🔬 📨 🗄 🔗.
|
|
||||||
|
|
||||||
👆 💪 👈 ⏮️ `openapi_extra`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial006.py hl[20:37,39:40] *}
|
|
||||||
|
|
||||||
👉 🖼, 👥 🚫 📣 🙆 Pydantic 🏷. 👐, 📨 💪 🚫 <abbr title="converted from some plain format, like bytes, into Python objects">🎻</abbr> 🎻, ⚫️ ✍ 🔗 `bytes`, & 🔢 `magic_data_reader()` 🔜 🈚 🎻 ⚫️ 🌌.
|
|
||||||
|
|
||||||
👐, 👥 💪 📣 📈 🔗 📨 💪.
|
|
||||||
|
|
||||||
### 🛃 🗄 🎚 🆎
|
|
||||||
|
|
||||||
⚙️ 👉 🎏 🎱, 👆 💪 ⚙️ Pydantic 🏷 🔬 🎻 🔗 👈 ⤴️ 🔌 🛃 🗄 🔗 📄 *➡ 🛠️*.
|
|
||||||
|
|
||||||
& 👆 💪 👉 🚥 💽 🆎 📨 🚫 🎻.
|
|
||||||
|
|
||||||
🖼, 👉 🈸 👥 🚫 ⚙️ FastAPI 🛠️ 🛠️ ⚗ 🎻 🔗 ⚪️➡️ Pydantic 🏷 🚫 🏧 🔬 🎻. 👐, 👥 📣 📨 🎚 🆎 📁, 🚫 🎻:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007.py hl[17:22,24] *}
|
|
||||||
|
|
||||||
👐, 👐 👥 🚫 ⚙️ 🔢 🛠️ 🛠️, 👥 ⚙️ Pydantic 🏷 ❎ 🏗 🎻 🔗 💽 👈 👥 💚 📨 📁.
|
|
||||||
|
|
||||||
⤴️ 👥 ⚙️ 📨 🔗, & ⚗ 💪 `bytes`. 👉 ⛓ 👈 FastAPI 🏆 🚫 🔄 🎻 📨 🚀 🎻.
|
|
||||||
|
|
||||||
& ⤴️ 👆 📟, 👥 🎻 👈 📁 🎚 🔗, & ⤴️ 👥 🔄 ⚙️ 🎏 Pydantic 🏷 ✔ 📁 🎚:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_advanced_configuration/tutorial007.py hl[26:33] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📥 👥 🏤-⚙️ 🎏 Pydantic 🏷.
|
|
||||||
|
|
||||||
✋️ 🎏 🌌, 👥 💪 ✔️ ✔ ⚫️ 🎏 🌌.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
# 📨 - 🔀 👔 📟
|
|
||||||
|
|
||||||
👆 🎲 ✍ ⏭ 👈 👆 💪 ⚒ 🔢 [📨 👔 📟](../tutorial/response-status-code.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
✋️ 💼 👆 💪 📨 🎏 👔 📟 🌘 🔢.
|
|
||||||
|
|
||||||
## ⚙️ 💼
|
|
||||||
|
|
||||||
🖼, 🌈 👈 👆 💚 📨 🇺🇸🔍 👔 📟 "👌" `200` 🔢.
|
|
||||||
|
|
||||||
✋️ 🚥 💽 🚫 🔀, 👆 💚 ✍ ⚫️, & 📨 🇺🇸🔍 👔 📟 "✍" `201`.
|
|
||||||
|
|
||||||
✋️ 👆 💚 💪 ⛽ & 🗜 💽 👆 📨 ⏮️ `response_model`.
|
|
||||||
|
|
||||||
📚 💼, 👆 💪 ⚙️ `Response` 🔢.
|
|
||||||
|
|
||||||
## ⚙️ `Response` 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 🔢 🆎 `Response` 👆 *➡ 🛠️ 🔢* (👆 💪 🍪 & 🎚).
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 ⚒ `status_code` 👈 *🔀* 📨 🎚.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_change_status_code/tutorial001.py hl[1,9,12] *}
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
|
||||||
|
|
||||||
& 🚥 👆 📣 `response_model`, ⚫️ 🔜 ⚙️ ⛽ & 🗜 🎚 👆 📨.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚙️ 👈 *🔀* 📨 ⚗ 👔 📟 (🍪 & 🎚), & 🔜 🚮 👫 🏁 📨 👈 🔌 💲 👆 📨, ⛽ 🙆 `response_model`.
|
|
||||||
|
|
||||||
👆 💪 📣 `Response` 🔢 🔗, & ⚒ 👔 📟 👫. ✋️ ✔️ 🤯 👈 🏁 1️⃣ ⚒ 🔜 🏆.
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
# 📨 🍪
|
|
||||||
|
|
||||||
## ⚙️ `Response` 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 🔢 🆎 `Response` 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 ⚒ 🍪 👈 *🔀* 📨 🎚.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_cookies/tutorial002.py hl[1,8:9] *}
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
|
||||||
|
|
||||||
& 🚥 👆 📣 `response_model`, ⚫️ 🔜 ⚙️ ⛽ & 🗜 🎚 👆 📨.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚙️ 👈 *🔀* 📨 ⚗ 🍪 (🎚 & 👔 📟), & 🔜 🚮 👫 🏁 📨 👈 🔌 💲 👆 📨, ⛽ 🙆 `response_model`.
|
|
||||||
|
|
||||||
👆 💪 📣 `Response` 🔢 🔗, & ⚒ 🍪 (& 🎚) 👫.
|
|
||||||
|
|
||||||
## 📨 `Response` 🔗
|
|
||||||
|
|
||||||
👆 💪 ✍ 🍪 🕐❔ 🛬 `Response` 🔗 👆 📟.
|
|
||||||
|
|
||||||
👈, 👆 💪 ✍ 📨 🔬 [📨 📨 🔗](response-directly.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
⤴️ ⚒ 🍪 ⚫️, & ⤴️ 📨 ⚫️:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_cookies/tutorial001.py hl[10:12] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🚥 👆 📨 📨 🔗 ↩️ ⚙️ `Response` 🔢, FastAPI 🔜 📨 ⚫️ 🔗.
|
|
||||||
|
|
||||||
, 👆 🔜 ✔️ ⚒ 💭 👆 💽 ☑ 🆎. 🤶 Ⓜ. ⚫️ 🔗 ⏮️ 🎻, 🚥 👆 🛬 `JSONResponse`.
|
|
||||||
|
|
||||||
& 👈 👆 🚫 📨 🙆 📊 👈 🔜 ✔️ ⛽ `response_model`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🌅 ℹ
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import Response` ⚖️ `from starlette.responses import JSONResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
& `Response` 💪 ⚙️ 🛎 ⚒ 🎚 & 🍪, **FastAPI** 🚚 ⚫️ `fastapi.Response`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👀 🌐 💪 🔢 & 🎛, ✅ <a href="https://www.starlette.dev/responses/#set-cookie" class="external-link" target="_blank">🧾 💃</a>.
|
|
||||||
|
|
@ -1,65 +0,0 @@
|
||||||
# 📨 📨 🔗
|
|
||||||
|
|
||||||
🕐❔ 👆 ✍ **FastAPI** *➡ 🛠️* 👆 💪 🛎 📨 🙆 📊 ⚪️➡️ ⚫️: `dict`, `list`, Pydantic 🏷, 💽 🏷, ♒️.
|
|
||||||
|
|
||||||
🔢, **FastAPI** 🔜 🔁 🗜 👈 📨 💲 🎻 ⚙️ `jsonable_encoder` 🔬 [🎻 🔗 🔢](../tutorial/encoder.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
⤴️, ⛅ 🎑, ⚫️ 🔜 🚮 👈 🎻-🔗 💽 (✅ `dict`) 🔘 `JSONResponse` 👈 🔜 ⚙️ 📨 📨 👩💻.
|
|
||||||
|
|
||||||
✋️ 👆 💪 📨 `JSONResponse` 🔗 ⚪️➡️ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
⚫️ 💪 ⚠, 🖼, 📨 🛃 🎚 ⚖️ 🍪.
|
|
||||||
|
|
||||||
## 📨 `Response`
|
|
||||||
|
|
||||||
👐, 👆 💪 📨 🙆 `Response` ⚖️ 🙆 🎧-🎓 ⚫️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
`JSONResponse` ⚫️ 🎧-🎓 `Response`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& 🕐❔ 👆 📨 `Response`, **FastAPI** 🔜 🚶♀️ ⚫️ 🔗.
|
|
||||||
|
|
||||||
⚫️ 🏆 🚫 🙆 💽 🛠️ ⏮️ Pydantic 🏷, ⚫️ 🏆 🚫 🗜 🎚 🙆 🆎, ♒️.
|
|
||||||
|
|
||||||
👉 🤝 👆 📚 💪. 👆 💪 📨 🙆 📊 🆎, 🔐 🙆 💽 📄 ⚖️ 🔬, ♒️.
|
|
||||||
|
|
||||||
## ⚙️ `jsonable_encoder` `Response`
|
|
||||||
|
|
||||||
↩️ **FastAPI** 🚫 🙆 🔀 `Response` 👆 📨, 👆 ✔️ ⚒ 💭 ⚫️ 🎚 🔜 ⚫️.
|
|
||||||
|
|
||||||
🖼, 👆 🚫🔜 🚮 Pydantic 🏷 `JSONResponse` 🍵 🥇 🏭 ⚫️ `dict` ⏮️ 🌐 📊 🆎 (💖 `datetime`, `UUID`, ♒️) 🗜 🎻-🔗 🆎.
|
|
||||||
|
|
||||||
📚 💼, 👆 💪 ⚙️ `jsonable_encoder` 🗜 👆 📊 ⏭ 🚶♀️ ⚫️ 📨:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_directly/tutorial001.py hl[6:7,21:22] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import JSONResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🛬 🛃 `Response`
|
|
||||||
|
|
||||||
🖼 🔛 🎦 🌐 🍕 👆 💪, ✋️ ⚫️ 🚫 📶 ⚠, 👆 💪 ✔️ 📨 `item` 🔗, & **FastAPI** 🔜 🚮 ⚫️ `JSONResponse` 👆, 🏭 ⚫️ `dict`, ♒️. 🌐 👈 🔢.
|
|
||||||
|
|
||||||
🔜, ➡️ 👀 ❔ 👆 💪 ⚙️ 👈 📨 🛃 📨.
|
|
||||||
|
|
||||||
➡️ 💬 👈 👆 💚 📨 <a href="https://en.wikipedia.org/wiki/XML" class="external-link" target="_blank">📂</a> 📨.
|
|
||||||
|
|
||||||
👆 💪 🚮 👆 📂 🎚 🎻, 🚮 ⚫️ `Response`, & 📨 ⚫️:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_directly/tutorial002.py hl[1,18] *}
|
|
||||||
|
|
||||||
## 🗒
|
|
||||||
|
|
||||||
🕐❔ 👆 📨 `Response` 🔗 🚮 📊 🚫 ✔, 🗜 (🎻), 🚫 📄 🔁.
|
|
||||||
|
|
||||||
✋️ 👆 💪 📄 ⚫️ 🔬 [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👆 💪 👀 ⏪ 📄 ❔ ⚙️/📣 👉 🛃 `Response`Ⓜ ⏪ ✔️ 🏧 💽 🛠️, 🧾, ♒️.
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
# 📨 🎚
|
|
||||||
|
|
||||||
## ⚙️ `Response` 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 🔢 🆎 `Response` 👆 *➡ 🛠️ 🔢* (👆 💪 🍪).
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 ⚒ 🎚 👈 *🔀* 📨 🎚.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_headers/tutorial002.py hl[1,7:8] *}
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 📨 🙆 🎚 👆 💪, 👆 🛎 🔜 ( `dict`, 💽 🏷, ♒️).
|
|
||||||
|
|
||||||
& 🚥 👆 📣 `response_model`, ⚫️ 🔜 ⚙️ ⛽ & 🗜 🎚 👆 📨.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚙️ 👈 *🔀* 📨 ⚗ 🎚 (🍪 & 👔 📟), & 🔜 🚮 👫 🏁 📨 👈 🔌 💲 👆 📨, ⛽ 🙆 `response_model`.
|
|
||||||
|
|
||||||
👆 💪 📣 `Response` 🔢 🔗, & ⚒ 🎚 (& 🍪) 👫.
|
|
||||||
|
|
||||||
## 📨 `Response` 🔗
|
|
||||||
|
|
||||||
👆 💪 🚮 🎚 🕐❔ 👆 📨 `Response` 🔗.
|
|
||||||
|
|
||||||
✍ 📨 🔬 [📨 📨 🔗](response-directly.md){.internal-link target=_blank} & 🚶♀️ 🎚 🌖 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_headers/tutorial001.py hl[10:12] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import Response` ⚖️ `from starlette.responses import JSONResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
& `Response` 💪 ⚙️ 🛎 ⚒ 🎚 & 🍪, **FastAPI** 🚚 ⚫️ `fastapi.Response`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🛃 🎚
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🛃 © 🎚 💪 🚮 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">⚙️ '✖-' 🔡</a>.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 (✍ 🌅 [⚜ (✖️-🇨🇳 ℹ 🤝)](../tutorial/cors.md){.internal-link target=_blank}), ⚙️ 🔢 `expose_headers` 📄 <a href="https://www.starlette.dev/middleware/#corsmiddleware" class="external-link" target="_blank">💃 ⚜ 🩺</a>.
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
# 🇺🇸🔍 🔰 🔐
|
|
||||||
|
|
||||||
🙅 💼, 👆 💪 ⚙️ 🇺🇸🔍 🔰 🔐.
|
|
||||||
|
|
||||||
🇺🇸🔍 🔰 🔐, 🈸 ⌛ 🎚 👈 🔌 🆔 & 🔐.
|
|
||||||
|
|
||||||
🚥 ⚫️ 🚫 📨 ⚫️, ⚫️ 📨 🇺🇸🔍 4️⃣0️⃣1️⃣ "⛔" ❌.
|
|
||||||
|
|
||||||
& 📨 🎚 `WWW-Authenticate` ⏮️ 💲 `Basic`, & 📦 `realm` 🔢.
|
|
||||||
|
|
||||||
👈 💬 🖥 🎦 🛠️ 📋 🆔 & 🔐.
|
|
||||||
|
|
||||||
⤴️, 🕐❔ 👆 🆎 👈 🆔 & 🔐, 🖥 📨 👫 🎚 🔁.
|
|
||||||
|
|
||||||
## 🙅 🇺🇸🔍 🔰 🔐
|
|
||||||
|
|
||||||
* 🗄 `HTTPBasic` & `HTTPBasicCredentials`.
|
|
||||||
* ✍ "`security` ⚖" ⚙️ `HTTPBasic`.
|
|
||||||
* ⚙️ 👈 `security` ⏮️ 🔗 👆 *➡ 🛠️*.
|
|
||||||
* ⚫️ 📨 🎚 🆎 `HTTPBasicCredentials`:
|
|
||||||
* ⚫️ 🔌 `username` & `password` 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial006.py hl[2,6,10] *}
|
|
||||||
|
|
||||||
🕐❔ 👆 🔄 📂 📛 🥇 🕰 (⚖️ 🖊 "🛠️" 🔼 🩺) 🖥 🔜 💭 👆 👆 🆔 & 🔐:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/security/image12.png">
|
|
||||||
|
|
||||||
## ✅ 🆔
|
|
||||||
|
|
||||||
📥 🌅 🏁 🖼.
|
|
||||||
|
|
||||||
⚙️ 🔗 ✅ 🚥 🆔 & 🔐 ☑.
|
|
||||||
|
|
||||||
👉, ⚙️ 🐍 🐩 🕹 <a href="https://docs.python.org/3/library/secrets.html" class="external-link" target="_blank">`secrets`</a> ✅ 🆔 & 🔐.
|
|
||||||
|
|
||||||
`secrets.compare_digest()` 💪 ✊ `bytes` ⚖️ `str` 👈 🕴 🔌 🔠 🦹 (🕐 🇪🇸), 👉 ⛓ ⚫️ 🚫🔜 👷 ⏮️ 🦹 💖 `á`, `Sebastián`.
|
|
||||||
|
|
||||||
🍵 👈, 👥 🥇 🗜 `username` & `password` `bytes` 🔢 👫 ⏮️ 🔠-8️⃣.
|
|
||||||
|
|
||||||
⤴️ 👥 💪 ⚙️ `secrets.compare_digest()` 🚚 👈 `credentials.username` `"stanleyjobson"`, & 👈 `credentials.password` `"swordfish"`.
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial007.py hl[1,11:21] *}
|
|
||||||
|
|
||||||
👉 🔜 🎏:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
if not (credentials.username == "stanleyjobson") or not (credentials.password == "swordfish"):
|
|
||||||
# Return some error
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ ⚙️ `secrets.compare_digest()` ⚫️ 🔜 🔐 🛡 🆎 👊 🤙 "🕰 👊".
|
|
||||||
|
|
||||||
### ⏲ 👊
|
|
||||||
|
|
||||||
✋️ ⚫️❔ "⏲ 👊"❓
|
|
||||||
|
|
||||||
➡️ 🌈 👊 🔄 💭 🆔 & 🔐.
|
|
||||||
|
|
||||||
& 👫 📨 📨 ⏮️ 🆔 `johndoe` & 🔐 `love123`.
|
|
||||||
|
|
||||||
⤴️ 🐍 📟 👆 🈸 🔜 🌓 🕳 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
if "johndoe" == "stanleyjobson" and "love123" == "swordfish":
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ ▶️️ 🙍 🐍 🔬 🥇 `j` `johndoe` 🥇 `s` `stanleyjobson`, ⚫️ 🔜 📨 `False`, ↩️ ⚫️ ⏪ 💭 👈 📚 2️⃣ 🎻 🚫 🎏, 💭 👈 "📤 🙅♂ 💪 🗑 🌅 📊 ⚖ 🎂 🔤". & 👆 🈸 🔜 💬 "❌ 👩💻 ⚖️ 🔐".
|
|
||||||
|
|
||||||
✋️ ⤴️ 👊 🔄 ⏮️ 🆔 `stanleyjobsox` & 🔐 `love123`.
|
|
||||||
|
|
||||||
& 👆 🈸 📟 🔨 🕳 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish":
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
🐍 🔜 ✔️ 🔬 🎂 `stanleyjobso` 👯♂️ `stanleyjobsox` & `stanleyjobson` ⏭ 🤔 👈 👯♂️ 🎻 🚫 🎏. ⚫️ 🔜 ✊ ➕ ⏲ 📨 🔙 "❌ 👩💻 ⚖️ 🔐".
|
|
||||||
|
|
||||||
#### 🕰 ❔ ℹ 👊
|
|
||||||
|
|
||||||
👈 ☝, 👀 👈 💽 ✊ ⏲ 📏 📨 "❌ 👩💻 ⚖️ 🔐" 📨, 👊 🔜 💭 👈 👫 🤚 _🕳_ ▶️️, ▶️ 🔤 ▶️️.
|
|
||||||
|
|
||||||
& ⤴️ 👫 💪 🔄 🔄 🤔 👈 ⚫️ 🎲 🕳 🌖 🎏 `stanleyjobsox` 🌘 `johndoe`.
|
|
||||||
|
|
||||||
#### "🕴" 👊
|
|
||||||
|
|
||||||
↗️, 👊 🔜 🚫 🔄 🌐 👉 ✋, 👫 🔜 ✍ 📋 ⚫️, 🎲 ⏮️ 💯 ⚖️ 💯 💯 📍 🥈. & 🔜 🤚 1️⃣ ➕ ☑ 🔤 🕰.
|
|
||||||
|
|
||||||
✋️ 🔨 👈, ⏲ ⚖️ 📆 👊 🔜 ✔️ 💭 ☑ 🆔 & 🔐, ⏮️ "ℹ" 👆 🈸, ⚙️ 🕰 ✊ ❔.
|
|
||||||
|
|
||||||
#### 🔧 ⚫️ ⏮️ `secrets.compare_digest()`
|
|
||||||
|
|
||||||
✋️ 👆 📟 👥 🤙 ⚙️ `secrets.compare_digest()`.
|
|
||||||
|
|
||||||
📏, ⚫️ 🔜 ✊ 🎏 🕰 🔬 `stanleyjobsox` `stanleyjobson` 🌘 ⚫️ ✊ 🔬 `johndoe` `stanleyjobson`. & 🎏 🔐.
|
|
||||||
|
|
||||||
👈 🌌, ⚙️ `secrets.compare_digest()` 👆 🈸 📟, ⚫️ 🔜 🔒 🛡 👉 🎂 ↔ 💂♂ 👊.
|
|
||||||
|
|
||||||
### 📨 ❌
|
|
||||||
|
|
||||||
⏮️ 🔍 👈 🎓 ❌, 📨 `HTTPException` ⏮️ 👔 📟 4️⃣0️⃣1️⃣ (🎏 📨 🕐❔ 🙅♂ 🎓 🚚) & 🚮 🎚 `WWW-Authenticate` ⚒ 🖥 🎦 💳 📋 🔄:
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial007.py hl[23:27] *}
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
# 🏧 💂♂
|
|
||||||
|
|
||||||
## 🌖 ⚒
|
|
||||||
|
|
||||||
📤 ➕ ⚒ 🍵 💂♂ ↖️ ⚪️➡️ 🕐 📔 [🔰 - 👩💻 🦮: 💂♂](../../tutorial/security/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⏭ 📄 **🚫 🎯 "🏧"**.
|
|
||||||
|
|
||||||
& ⚫️ 💪 👈 👆 ⚙️ 💼, ⚗ 1️⃣ 👫.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✍ 🔰 🥇
|
|
||||||
|
|
||||||
⏭ 📄 🤔 👆 ⏪ ✍ 👑 [🔰 - 👩💻 🦮: 💂♂](../../tutorial/security/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👫 🌐 ⚓️ 🔛 🎏 🔧, ✋️ ✔ ➕ 🛠️.
|
|
||||||
|
|
@ -1,274 +0,0 @@
|
||||||
# Oauth2️⃣ ↔
|
|
||||||
|
|
||||||
👆 💪 ⚙️ Oauth2️⃣ ↔ 🔗 ⏮️ **FastAPI**, 👫 🛠️ 👷 💎.
|
|
||||||
|
|
||||||
👉 🔜 ✔ 👆 ✔️ 🌖 👌-🧽 ✔ ⚙️, 📄 Oauth2️⃣ 🐩, 🛠️ 🔘 👆 🗄 🈸 (& 🛠️ 🩺).
|
|
||||||
|
|
||||||
Oauth2️⃣ ⏮️ ↔ 🛠️ ⚙️ 📚 🦏 🤝 🐕🦺, 💖 👱📔, 🇺🇸🔍, 📂, 🤸♂, 👱📔, ♒️. 👫 ⚙️ ⚫️ 🚚 🎯 ✔ 👩💻 & 🈸.
|
|
||||||
|
|
||||||
🔠 🕰 👆 "🕹 ⏮️" 👱📔, 🇺🇸🔍, 📂, 🤸♂, 👱📔, 👈 🈸 ⚙️ Oauth2️⃣ ⏮️ ↔.
|
|
||||||
|
|
||||||
👉 📄 👆 🔜 👀 ❔ 🛠️ 🤝 & ✔ ⏮️ 🎏 Oauth2️⃣ ⏮️ ↔ 👆 **FastAPI** 🈸.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👉 🌅 ⚖️ 🌘 🏧 📄. 🚥 👆 ▶️, 👆 💪 🚶 ⚫️.
|
|
||||||
|
|
||||||
👆 🚫 🎯 💪 Oauth2️⃣ ↔, & 👆 💪 🍵 🤝 & ✔ 👐 👆 💚.
|
|
||||||
|
|
||||||
✋️ Oauth2️⃣ ⏮️ ↔ 💪 🎆 🛠️ 🔘 👆 🛠️ (⏮️ 🗄) & 👆 🛠️ 🩺.
|
|
||||||
|
|
||||||
👐, 👆 🛠️ 📚 ↔, ⚖️ 🙆 🎏 💂♂/✔ 📄, 👐 👆 💪, 👆 📟.
|
|
||||||
|
|
||||||
📚 💼, Oauth2️⃣ ⏮️ ↔ 💪 👹.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 💭 👆 💪 ⚫️, ⚖️ 👆 😟, 🚧 👂.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## Oauth2️⃣ ↔ & 🗄
|
|
||||||
|
|
||||||
Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.
|
|
||||||
|
|
||||||
🎚 🔠 👉 🎻 💪 ✔️ 🙆 📁, ✋️ 🔜 🚫 🔌 🚀.
|
|
||||||
|
|
||||||
👫 ↔ 🎨 "✔".
|
|
||||||
|
|
||||||
🗄 (✅ 🛠️ 🩺), 👆 💪 🔬 "💂♂ ⚖".
|
|
||||||
|
|
||||||
🕐❔ 1️⃣ 👫 💂♂ ⚖ ⚙️ Oauth2️⃣, 👆 💪 📣 & ⚙️ ↔.
|
|
||||||
|
|
||||||
🔠 "↔" 🎻 (🍵 🚀).
|
|
||||||
|
|
||||||
👫 🛎 ⚙️ 📣 🎯 💂♂ ✔, 🖼:
|
|
||||||
|
|
||||||
* `users:read` ⚖️ `users:write` ⚠ 🖼.
|
|
||||||
* `instagram_basic` ⚙️ 👱📔 / 👱📔.
|
|
||||||
* `https://www.googleapis.com/auth/drive` ⚙️ 🇺🇸🔍.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
Oauth2️⃣ "↔" 🎻 👈 📣 🎯 ✔ ✔.
|
|
||||||
|
|
||||||
⚫️ 🚫 🤔 🚥 ⚫️ ✔️ 🎏 🦹 💖 `:` ⚖️ 🚥 ⚫️ 📛.
|
|
||||||
|
|
||||||
👈 ℹ 🛠️ 🎯.
|
|
||||||
|
|
||||||
Oauth2️⃣ 👫 🎻.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌐 🎑
|
|
||||||
|
|
||||||
🥇, ➡️ 🔜 👀 🍕 👈 🔀 ⚪️➡️ 🖼 👑 **🔰 - 👩💻 🦮** [Oauth2️⃣ ⏮️ 🔐 (& 🔁), 📨 ⏮️ 🥙 🤝](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. 🔜 ⚙️ Oauth2️⃣ ↔:
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[2,4,8,12,46,64,105,107:115,121:125,129:135,140,156] *}
|
|
||||||
|
|
||||||
🔜 ➡️ 📄 👈 🔀 🔁 🔁.
|
|
||||||
|
|
||||||
## Oauth2️⃣ 💂♂ ⚖
|
|
||||||
|
|
||||||
🥇 🔀 👈 🔜 👥 📣 Oauth2️⃣ 💂♂ ⚖ ⏮️ 2️⃣ 💪 ↔, `me` & `items`.
|
|
||||||
|
|
||||||
`scopes` 🔢 📨 `dict` ⏮️ 🔠 ↔ 🔑 & 📛 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[62:65] *}
|
|
||||||
|
|
||||||
↩️ 👥 🔜 📣 📚 ↔, 👫 🔜 🎦 🆙 🛠️ 🩺 🕐❔ 👆 🕹-/✔.
|
|
||||||
|
|
||||||
& 👆 🔜 💪 🖊 ❔ ↔ 👆 💚 🤝 🔐: `me` & `items`.
|
|
||||||
|
|
||||||
👉 🎏 🛠️ ⚙️ 🕐❔ 👆 🤝 ✔ ⏪ 🚨 ⏮️ 👱📔, 🇺🇸🔍, 📂, ♒️:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/security/image11.png">
|
|
||||||
|
|
||||||
## 🥙 🤝 ⏮️ ↔
|
|
||||||
|
|
||||||
🔜, 🔀 🤝 *➡ 🛠️* 📨 ↔ 📨.
|
|
||||||
|
|
||||||
👥 ⚙️ 🎏 `OAuth2PasswordRequestForm`. ⚫️ 🔌 🏠 `scopes` ⏮️ `list` `str`, ⏮️ 🔠 ↔ ⚫️ 📨 📨.
|
|
||||||
|
|
||||||
& 👥 📨 ↔ 🍕 🥙 🤝.
|
|
||||||
|
|
||||||
/// danger
|
|
||||||
|
|
||||||
🦁, 📥 👥 ❎ ↔ 📨 🔗 🤝.
|
|
||||||
|
|
||||||
✋️ 👆 🈸, 💂♂, 👆 🔜 ⚒ 💭 👆 🕴 🚮 ↔ 👈 👩💻 🤙 💪 ✔️, ⚖️ 🕐 👆 ✔️ 🔁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[156] *}
|
|
||||||
|
|
||||||
## 📣 ↔ *➡ 🛠️* & 🔗
|
|
||||||
|
|
||||||
🔜 👥 📣 👈 *➡ 🛠️* `/users/me/items/` 🚚 ↔ `items`.
|
|
||||||
|
|
||||||
👉, 👥 🗄 & ⚙️ `Security` ⚪️➡️ `fastapi`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `Security` 📣 🔗 (💖 `Depends`), ✋️ `Security` 📨 🔢 `scopes` ⏮️ 📇 ↔ (🎻).
|
|
||||||
|
|
||||||
👉 💼, 👥 🚶♀️ 🔗 🔢 `get_current_active_user` `Security` (🎏 🌌 👥 🔜 ⏮️ `Depends`).
|
|
||||||
|
|
||||||
✋️ 👥 🚶♀️ `list` ↔, 👉 💼 ⏮️ 1️⃣ ↔: `items` (⚫️ 💪 ✔️ 🌅).
|
|
||||||
|
|
||||||
& 🔗 🔢 `get_current_active_user` 💪 📣 🎧-🔗, 🚫 🕴 ⏮️ `Depends` ✋️ ⏮️ `Security`. 📣 🚮 👍 🎧-🔗 🔢 (`get_current_user`), & 🌖 ↔ 📄.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🚚 ↔ `me` (⚫️ 💪 🚚 🌅 🌘 1️⃣ ↔).
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👆 🚫 🎯 💪 🚮 🎏 ↔ 🎏 🥉.
|
|
||||||
|
|
||||||
👥 🔨 ⚫️ 📥 🎦 ❔ **FastAPI** 🍵 ↔ 📣 🎏 🎚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[4,140,169] *}
|
|
||||||
|
|
||||||
/// info | 📡 ℹ
|
|
||||||
|
|
||||||
`Security` 🤙 🏿 `Depends`, & ⚫️ ✔️ 1️⃣ ➕ 🔢 👈 👥 🔜 👀 ⏪.
|
|
||||||
|
|
||||||
✋️ ⚙️ `Security` ↩️ `Depends`, **FastAPI** 🔜 💭 👈 ⚫️ 💪 📣 💂♂ ↔, ⚙️ 👫 🔘, & 📄 🛠️ ⏮️ 🗄.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 🗄 `Query`, `Path`, `Depends`, `Security` & 🎏 ⚪️➡️ `fastapi`, 👈 🤙 🔢 👈 📨 🎁 🎓.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚙️ `SecurityScopes`
|
|
||||||
|
|
||||||
🔜 ℹ 🔗 `get_current_user`.
|
|
||||||
|
|
||||||
👉 1️⃣ ⚙️ 🔗 🔛.
|
|
||||||
|
|
||||||
📥 👥 ⚙️ 🎏 Oauth2️⃣ ⚖ 👥 ✍ ⏭, 📣 ⚫️ 🔗: `oauth2_scheme`.
|
|
||||||
|
|
||||||
↩️ 👉 🔗 🔢 🚫 ✔️ 🙆 ↔ 📄 ⚫️, 👥 💪 ⚙️ `Depends` ⏮️ `oauth2_scheme`, 👥 🚫 ✔️ ⚙️ `Security` 🕐❔ 👥 🚫 💪 ✔ 💂♂ ↔.
|
|
||||||
|
|
||||||
👥 📣 🎁 🔢 🆎 `SecurityScopes`, 🗄 ⚪️➡️ `fastapi.security`.
|
|
||||||
|
|
||||||
👉 `SecurityScopes` 🎓 🎏 `Request` (`Request` ⚙️ 🤚 📨 🎚 🔗).
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[8,105] *}
|
|
||||||
|
|
||||||
## ⚙️ `scopes`
|
|
||||||
|
|
||||||
🔢 `security_scopes` 🔜 🆎 `SecurityScopes`.
|
|
||||||
|
|
||||||
⚫️ 🔜 ✔️ 🏠 `scopes` ⏮️ 📇 ⚗ 🌐 ↔ ✔ ⚫️ & 🌐 🔗 👈 ⚙️ 👉 🎧-🔗. 👈 ⛓, 🌐 "⚓️"... 👉 💪 🔊 😨, ⚫️ 🔬 🔄 ⏪ 🔛.
|
|
||||||
|
|
||||||
`security_scopes` 🎚 (🎓 `SecurityScopes`) 🚚 `scope_str` 🔢 ⏮️ 👁 🎻, 🔌 👈 ↔ 👽 🚀 (👥 🔜 ⚙️ ⚫️).
|
|
||||||
|
|
||||||
👥 ✍ `HTTPException` 👈 👥 💪 🏤-⚙️ (`raise`) ⏪ 📚 ☝.
|
|
||||||
|
|
||||||
👉 ⚠, 👥 🔌 ↔ 🚚 (🚥 🙆) 🎻 👽 🚀 (⚙️ `scope_str`). 👥 🚮 👈 🎻 ⚗ ↔ `WWW-Authenticate` 🎚 (👉 🍕 🔌).
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[105,107:115] *}
|
|
||||||
|
|
||||||
## ✔ `username` & 💽 💠
|
|
||||||
|
|
||||||
👥 ✔ 👈 👥 🤚 `username`, & ⚗ ↔.
|
|
||||||
|
|
||||||
& ⤴️ 👥 ✔ 👈 📊 ⏮️ Pydantic 🏷 (✊ `ValidationError` ⚠), & 🚥 👥 🤚 ❌ 👂 🥙 🤝 ⚖️ ⚖ 📊 ⏮️ Pydantic, 👥 🤚 `HTTPException` 👥 ✍ ⏭.
|
|
||||||
|
|
||||||
👈, 👥 ℹ Pydantic 🏷 `TokenData` ⏮️ 🆕 🏠 `scopes`.
|
|
||||||
|
|
||||||
⚖ 📊 ⏮️ Pydantic 👥 💪 ⚒ 💭 👈 👥 ✔️, 🖼, ⚫️❔ `list` `str` ⏮️ ↔ & `str` ⏮️ `username`.
|
|
||||||
|
|
||||||
↩️, 🖼, `dict`, ⚖️ 🕳 🙆, ⚫️ 💪 💔 🈸 ☝ ⏪, ⚒ ⚫️ 💂♂ ⚠.
|
|
||||||
|
|
||||||
👥 ✔ 👈 👥 ✔️ 👩💻 ⏮️ 👈 🆔, & 🚥 🚫, 👥 🤚 👈 🎏 ⚠ 👥 ✍ ⏭.
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[46,116:128] *}
|
|
||||||
|
|
||||||
## ✔ `scopes`
|
|
||||||
|
|
||||||
👥 🔜 ✔ 👈 🌐 ↔ ✔, 👉 🔗 & 🌐 ⚓️ (🔌 *➡ 🛠️*), 🔌 ↔ 🚚 🤝 📨, ⏪ 🤚 `HTTPException`.
|
|
||||||
|
|
||||||
👉, 👥 ⚙️ `security_scopes.scopes`, 👈 🔌 `list` ⏮️ 🌐 👫 ↔ `str`.
|
|
||||||
|
|
||||||
{* ../../docs_src/security/tutorial005.py hl[129:135] *}
|
|
||||||
|
|
||||||
## 🔗 🌲 & ↔
|
|
||||||
|
|
||||||
➡️ 📄 🔄 👉 🔗 🌲 & ↔.
|
|
||||||
|
|
||||||
`get_current_active_user` 🔗 ✔️ 🎧-🔗 🔛 `get_current_user`, ↔ `"me"` 📣 `get_current_active_user` 🔜 🔌 📇 ✔ ↔ `security_scopes.scopes` 🚶♀️ `get_current_user`.
|
|
||||||
|
|
||||||
*➡ 🛠️* ⚫️ 📣 ↔, `"items"`, 👉 🔜 📇 `security_scopes.scopes` 🚶♀️ `get_current_user`.
|
|
||||||
|
|
||||||
📥 ❔ 🔗 🔗 & ↔ 👀 💖:
|
|
||||||
|
|
||||||
* *➡ 🛠️* `read_own_items` ✔️:
|
|
||||||
* ✔ ↔ `["items"]` ⏮️ 🔗:
|
|
||||||
* `get_current_active_user`:
|
|
||||||
* 🔗 🔢 `get_current_active_user` ✔️:
|
|
||||||
* ✔ ↔ `["me"]` ⏮️ 🔗:
|
|
||||||
* `get_current_user`:
|
|
||||||
* 🔗 🔢 `get_current_user` ✔️:
|
|
||||||
* 🙅♂ ↔ ✔ ⚫️.
|
|
||||||
* 🔗 ⚙️ `oauth2_scheme`.
|
|
||||||
* `security_scopes` 🔢 🆎 `SecurityScopes`:
|
|
||||||
* 👉 `security_scopes` 🔢 ✔️ 🏠 `scopes` ⏮️ `list` ⚗ 🌐 👫 ↔ 📣 🔛,:
|
|
||||||
* `security_scopes.scopes` 🔜 🔌 `["me", "items"]` *➡ 🛠️* `read_own_items`.
|
|
||||||
* `security_scopes.scopes` 🔜 🔌 `["me"]` *➡ 🛠️* `read_users_me`, ↩️ ⚫️ 📣 🔗 `get_current_active_user`.
|
|
||||||
* `security_scopes.scopes` 🔜 🔌 `[]` (🕳) *➡ 🛠️* `read_system_status`, ↩️ ⚫️ 🚫 📣 🙆 `Security` ⏮️ `scopes`, & 🚮 🔗, `get_current_user`, 🚫 📣 🙆 `scope` 👯♂️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⚠ & "🎱" 👜 📥 👈 `get_current_user` 🔜 ✔️ 🎏 📇 `scopes` ✅ 🔠 *➡ 🛠️*.
|
|
||||||
|
|
||||||
🌐 ⚓️ 🔛 `scopes` 📣 🔠 *➡ 🛠️* & 🔠 🔗 🔗 🌲 👈 🎯 *➡ 🛠️*.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌖 ℹ 🔃 `SecurityScopes`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `SecurityScopes` 🙆 ☝, & 💗 🥉, ⚫️ 🚫 ✔️ "🌱" 🔗.
|
|
||||||
|
|
||||||
⚫️ 🔜 🕧 ✔️ 💂♂ ↔ 📣 ⏮️ `Security` 🔗 & 🌐 ⚓️ **👈 🎯** *➡ 🛠️* & **👈 🎯** 🔗 🌲.
|
|
||||||
|
|
||||||
↩️ `SecurityScopes` 🔜 ✔️ 🌐 ↔ 📣 ⚓️, 👆 💪 ⚙️ ⚫️ ✔ 👈 🤝 ✔️ 🚚 ↔ 🇨🇫 🔗 🔢, & ⤴️ 📣 🎏 ↔ 📄 🎏 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👫 🔜 ✅ ➡ 🔠 *➡ 🛠️*.
|
|
||||||
|
|
||||||
## ✅ ⚫️
|
|
||||||
|
|
||||||
🚥 👆 📂 🛠️ 🩺, 👆 💪 🔓 & ✔ ❔ ↔ 👆 💚 ✔.
|
|
||||||
|
|
||||||
<img src="/img/tutorial/security/image11.png">
|
|
||||||
|
|
||||||
🚥 👆 🚫 🖊 🙆 ↔, 👆 🔜 "🔓", ✋️ 🕐❔ 👆 🔄 🔐 `/users/me/` ⚖️ `/users/me/items/` 👆 🔜 🤚 ❌ 💬 👈 👆 🚫 ✔️ 🥃 ✔. 👆 🔜 💪 🔐 `/status/`.
|
|
||||||
|
|
||||||
& 🚥 👆 🖊 ↔ `me` ✋️ 🚫 ↔ `items`, 👆 🔜 💪 🔐 `/users/me/` ✋️ 🚫 `/users/me/items/`.
|
|
||||||
|
|
||||||
👈 ⚫️❔ 🔜 🔨 🥉 🥳 🈸 👈 🔄 🔐 1️⃣ 👫 *➡ 🛠️* ⏮️ 🤝 🚚 👩💻, ⚓️ 🔛 ❔ 📚 ✔ 👩💻 🤝 🈸.
|
|
||||||
|
|
||||||
## 🔃 🥉 🥳 🛠️
|
|
||||||
|
|
||||||
👉 🖼 👥 ⚙️ Oauth2️⃣ "🔐" 💧.
|
|
||||||
|
|
||||||
👉 ☑ 🕐❔ 👥 🚨 👆 👍 🈸, 🎲 ⏮️ 👆 👍 🕸.
|
|
||||||
|
|
||||||
↩️ 👥 💪 💙 ⚫️ 📨 `username` & `password`, 👥 🎛 ⚫️.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🏗 Oauth2️⃣ 🈸 👈 🎏 🔜 🔗 (➡, 🚥 👆 🏗 🤝 🐕🦺 🌓 👱📔, 🇺🇸🔍, 📂, ♒️.) 👆 🔜 ⚙️ 1️⃣ 🎏 💧.
|
|
||||||
|
|
||||||
🌅 ⚠ 🔑 💧.
|
|
||||||
|
|
||||||
🏆 🔐 📟 💧, ✋️ 🌖 🏗 🛠️ ⚫️ 🚚 🌅 📶. ⚫️ 🌅 🏗, 📚 🐕🦺 🔚 🆙 ✔ 🔑 💧.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
⚫️ ⚠ 👈 🔠 🤝 🐕🦺 📛 👫 💧 🎏 🌌, ⚒ ⚫️ 🍕 👫 🏷.
|
|
||||||
|
|
||||||
✋️ 🔚, 👫 🛠️ 🎏 Oauth2️⃣ 🐩.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
**FastAPI** 🔌 🚙 🌐 👫 Oauth2️⃣ 🤝 💧 `fastapi.security.oauth2`.
|
|
||||||
|
|
||||||
## `Security` 👨🎨 `dependencies`
|
|
||||||
|
|
||||||
🎏 🌌 👆 💪 🔬 `list` `Depends` 👨🎨 `dependencies` 🔢 (🔬 [🔗 ➡ 🛠️ 👨🎨](../../tutorial/dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}), 👆 💪 ⚙️ `Security` ⏮️ `scopes` 📤.
|
|
||||||
|
|
@ -1,396 +0,0 @@
|
||||||
# ⚒ & 🌐 🔢
|
|
||||||
|
|
||||||
📚 💼 👆 🈸 💪 💪 🔢 ⚒ ⚖️ 📳, 🖼 ㊙ 🔑, 💽 🎓, 🎓 📧 🐕🦺, ♒️.
|
|
||||||
|
|
||||||
🏆 👫 ⚒ 🔢 (💪 🔀), 💖 💽 📛. & 📚 💪 🚿, 💖 ㊙.
|
|
||||||
|
|
||||||
👉 🤔 ⚫️ ⚠ 🚚 👫 🌐 🔢 👈 ✍ 🈸.
|
|
||||||
|
|
||||||
## 🌐 🔢
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ⏪ 💭 ⚫️❔ "🌐 🔢" & ❔ ⚙️ 👫, 💭 🆓 🚶 ⏭ 📄 🔛.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
<a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">🌐 🔢</a> (💭 "🇨🇻 {") 🔢 👈 🖖 🏞 🐍 📟, 🏃♂ ⚙️, & 💪 ✍ 👆 🐍 📟 (⚖️ 🎏 📋 👍).
|
|
||||||
|
|
||||||
👆 💪 ✍ & ⚙️ 🌐 🔢 🐚, 🍵 💆♂ 🐍:
|
|
||||||
|
|
||||||
//// tab | 💾, 🇸🇻, 🚪 🎉
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
// You could create an env var MY_NAME with
|
|
||||||
$ export MY_NAME="Wade Wilson"
|
|
||||||
|
|
||||||
// Then you could use it with other programs, like
|
|
||||||
$ echo "Hello $MY_NAME"
|
|
||||||
|
|
||||||
Hello Wade Wilson
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🚪 📋
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
// Create an env var MY_NAME
|
|
||||||
$ $Env:MY_NAME = "Wade Wilson"
|
|
||||||
|
|
||||||
// Use it with other programs, like
|
|
||||||
$ echo "Hello $Env:MY_NAME"
|
|
||||||
|
|
||||||
Hello Wade Wilson
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### ✍ 🇨🇻 {🐍
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌐 🔢 🏞 🐍, 📶 (⚖️ ⏮️ 🙆 🎏 👩🔬), & ⤴️ ✍ 👫 🐍.
|
|
||||||
|
|
||||||
🖼 👆 💪 ✔️ 📁 `main.py` ⏮️:
|
|
||||||
|
|
||||||
```Python hl_lines="3"
|
|
||||||
import os
|
|
||||||
|
|
||||||
name = os.getenv("MY_NAME", "World")
|
|
||||||
print(f"Hello {name} from Python")
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🥈 ❌ <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> 🔢 💲 📨.
|
|
||||||
|
|
||||||
🚥 🚫 🚚, ⚫️ `None` 🔢, 📥 👥 🚚 `"World"` 🔢 💲 ⚙️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⤴️ 👆 💪 🤙 👈 🐍 📋:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
// Here we don't set the env var yet
|
|
||||||
$ python main.py
|
|
||||||
|
|
||||||
// As we didn't set the env var, we get the default value
|
|
||||||
|
|
||||||
Hello World from Python
|
|
||||||
|
|
||||||
// But if we create an environment variable first
|
|
||||||
$ export MY_NAME="Wade Wilson"
|
|
||||||
|
|
||||||
// And then call the program again
|
|
||||||
$ python main.py
|
|
||||||
|
|
||||||
// Now it can read the environment variable
|
|
||||||
|
|
||||||
Hello Wade Wilson from Python
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
🌐 🔢 💪 ⚒ 🏞 📟, ✋️ 💪 ✍ 📟, & 🚫 ✔️ 🏪 (💕 `git`) ⏮️ 🎂 📁, ⚫️ ⚠ ⚙️ 👫 📳 ⚖️ ⚒.
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌐 🔢 🕴 🎯 📋 👼, 👈 🕴 💪 👈 📋, & 🕴 🚮 📐.
|
|
||||||
|
|
||||||
👈, ✍ ⚫️ ▶️️ ⏭ 📋 ⚫️, 🔛 🎏 ⏸:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
// Create an env var MY_NAME in line for this program call
|
|
||||||
$ MY_NAME="Wade Wilson" python main.py
|
|
||||||
|
|
||||||
// Now it can read the environment variable
|
|
||||||
|
|
||||||
Hello Wade Wilson from Python
|
|
||||||
|
|
||||||
// The env var no longer exists afterwards
|
|
||||||
$ python main.py
|
|
||||||
|
|
||||||
Hello World from Python
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌅 🔃 ⚫️ <a href="https://12factor.net/config" class="external-link" target="_blank">1️⃣2️⃣-⚖ 📱: 📁</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🆎 & 🔬
|
|
||||||
|
|
||||||
👫 🌐 🔢 💪 🕴 🍵 ✍ 🎻, 👫 🔢 🐍 & ✔️ 🔗 ⏮️ 🎏 📋 & 🎂 ⚙️ (& ⏮️ 🎏 🏃♂ ⚙️, 💾, 🚪, 🇸🇻).
|
|
||||||
|
|
||||||
👈 ⛓ 👈 🙆 💲 ✍ 🐍 ⚪️➡️ 🌐 🔢 🔜 `str`, & 🙆 🛠️ 🎏 🆎 ⚖️ 🔬 ✔️ 🔨 📟.
|
|
||||||
|
|
||||||
## Pydantic `Settings`
|
|
||||||
|
|
||||||
👐, Pydantic 🚚 👑 🚙 🍵 👫 ⚒ 👟 ⚪️➡️ 🌐 🔢 ⏮️ <a href="https://docs.pydantic.dev/latest/concepts/pydantic_settings/" class="external-link" target="_blank">Pydantic: ⚒ 🧾</a>.
|
|
||||||
|
|
||||||
### ✍ `Settings` 🎚
|
|
||||||
|
|
||||||
🗄 `BaseSettings` ⚪️➡️ Pydantic & ✍ 🎧-🎓, 📶 🌅 💖 ⏮️ Pydantic 🏷.
|
|
||||||
|
|
||||||
🎏 🌌 ⏮️ Pydantic 🏷, 👆 📣 🎓 🔢 ⏮️ 🆎 ✍, & 🎲 🔢 💲.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🌐 🎏 🔬 ⚒ & 🧰 👆 ⚙️ Pydantic 🏷, 💖 🎏 📊 🆎 & 🌖 🔬 ⏮️ `Field()`.
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/tutorial001.py hl[2,5:8,11] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 💚 🕳 ⏩ 📁 & 📋, 🚫 ⚙️ 👉 🖼, ⚙️ 🏁 1️⃣ 🔛.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⤴️, 🕐❔ 👆 ✍ 👐 👈 `Settings` 🎓 (👉 💼, `settings` 🎚), Pydantic 🔜 ✍ 🌐 🔢 💼-😛 🌌,, ↖-💼 🔢 `APP_NAME` 🔜 ✍ 🔢 `app_name`.
|
|
||||||
|
|
||||||
⏭ ⚫️ 🔜 🗜 & ✔ 💽. , 🕐❔ 👆 ⚙️ 👈 `settings` 🎚, 👆 🔜 ✔️ 📊 🆎 👆 📣 (✅ `items_per_user` 🔜 `int`).
|
|
||||||
|
|
||||||
### ⚙️ `settings`
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ⚙️ 🆕 `settings` 🎚 👆 🈸:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/tutorial001.py hl[18:20] *}
|
|
||||||
|
|
||||||
### 🏃 💽
|
|
||||||
|
|
||||||
⏭, 👆 🔜 🏃 💽 🚶♀️ 📳 🌐 🔢, 🖼 👆 💪 ⚒ `ADMIN_EMAIL` & `APP_NAME` ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ ADMIN_EMAIL="deadpool@example.com" APP_NAME="ChimichangApp" uvicorn main:app
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⚒ 💗 🇨🇻 {👁 📋 🎏 👫 ⏮️ 🚀, & 🚮 👫 🌐 ⏭ 📋.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& ⤴️ `admin_email` ⚒ 🔜 ⚒ `"deadpool@example.com"`.
|
|
||||||
|
|
||||||
`app_name` 🔜 `"ChimichangApp"`.
|
|
||||||
|
|
||||||
& `items_per_user` 🔜 🚧 🚮 🔢 💲 `50`.
|
|
||||||
|
|
||||||
## ⚒ ➕1️⃣ 🕹
|
|
||||||
|
|
||||||
👆 💪 🚮 👈 ⚒ ➕1️⃣ 🕹 📁 👆 👀 [🦏 🈸 - 💗 📁](../tutorial/bigger-applications.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
🖼, 👆 💪 ✔️ 📁 `config.py` ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app01/config.py *}
|
|
||||||
|
|
||||||
& ⤴️ ⚙️ ⚫️ 📁 `main.py`:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app01/main.py hl[3,11:13] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 🔜 💪 📁 `__init__.py` 👆 👀 🔛 [🦏 🈸 - 💗 📁](../tutorial/bigger-applications.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚒ 🔗
|
|
||||||
|
|
||||||
🍾 ⚫️ 5️⃣📆 ⚠ 🚚 ⚒ ⚪️➡️ 🔗, ↩️ ✔️ 🌐 🎚 ⏮️ `settings` 👈 ⚙️ 🌐.
|
|
||||||
|
|
||||||
👉 💪 ✴️ ⚠ ⏮️ 🔬, ⚫️ 📶 ⏩ 🔐 🔗 ⏮️ 👆 👍 🛃 ⚒.
|
|
||||||
|
|
||||||
### 📁 📁
|
|
||||||
|
|
||||||
👟 ⚪️➡️ ⏮️ 🖼, 👆 `config.py` 📁 💪 👀 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/config.py hl[10] *}
|
|
||||||
|
|
||||||
👀 👈 🔜 👥 🚫 ✍ 🔢 👐 `settings = Settings()`.
|
|
||||||
|
|
||||||
### 👑 📱 📁
|
|
||||||
|
|
||||||
🔜 👥 ✍ 🔗 👈 📨 🆕 `config.Settings()`.
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/main.py hl[5,11:12] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👥 🔜 🔬 `@lru_cache` 🍖.
|
|
||||||
|
|
||||||
🔜 👆 💪 🤔 `get_settings()` 😐 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& ⤴️ 👥 💪 🚚 ⚫️ ⚪️➡️ *➡ 🛠️ 🔢* 🔗 & ⚙️ ⚫️ 🙆 👥 💪 ⚫️.
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/main.py hl[16,18:20] *}
|
|
||||||
|
|
||||||
### ⚒ & 🔬
|
|
||||||
|
|
||||||
⤴️ ⚫️ 🔜 📶 ⏩ 🚚 🎏 ⚒ 🎚 ⏮️ 🔬 🏗 🔗 🔐 `get_settings`:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app02/test_main.py hl[9:10,13,21] *}
|
|
||||||
|
|
||||||
🔗 🔐 👥 ⚒ 🆕 💲 `admin_email` 🕐❔ 🏗 🆕 `Settings` 🎚, & ⤴️ 👥 📨 👈 🆕 🎚.
|
|
||||||
|
|
||||||
⤴️ 👥 💪 💯 👈 ⚫️ ⚙️.
|
|
||||||
|
|
||||||
## 👂 `.env` 📁
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 📚 ⚒ 👈 🎲 🔀 📚, 🎲 🎏 🌐, ⚫️ 5️⃣📆 ⚠ 🚮 👫 🔛 📁 & ⤴️ ✍ 👫 ⚪️➡️ ⚫️ 🚥 👫 🌐 🔢.
|
|
||||||
|
|
||||||
👉 💡 ⚠ 🥃 👈 ⚫️ ✔️ 📛, 👫 🌐 🔢 🛎 🥉 📁 `.env`, & 📁 🤙 "🇨🇻".
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📁 ▶️ ⏮️ ❣ (`.`) 🕵♂ 📁 🖥-💖 ⚙️, 💖 💾 & 🇸🇻.
|
|
||||||
|
|
||||||
✋️ 🇨🇻 📁 🚫 🤙 ✔️ ✔️ 👈 ☑ 📁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
Pydantic ✔️ 🐕🦺 👂 ⚪️➡️ 👉 🆎 📁 ⚙️ 🔢 🗃. 👆 💪 ✍ 🌖 <a href="https://docs.pydantic.dev/latest/concepts/pydantic_settings/#dotenv-env-support" class="external-link" target="_blank">Pydantic ⚒: 🇨🇻 (.🇨🇻) 🐕🦺</a>.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 👷, 👆 💪 `pip install python-dotenv`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `.env` 📁
|
|
||||||
|
|
||||||
👆 💪 ✔️ `.env` 📁 ⏮️:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
ADMIN_EMAIL="deadpool@example.com"
|
|
||||||
APP_NAME="ChimichangApp"
|
|
||||||
```
|
|
||||||
|
|
||||||
### ✍ ⚒ ⚪️➡️ `.env`
|
|
||||||
|
|
||||||
& ⤴️ ℹ 👆 `config.py` ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app03/config.py hl[9:10] *}
|
|
||||||
|
|
||||||
📥 👥 ✍ 🎓 `Config` 🔘 👆 Pydantic `Settings` 🎓, & ⚒ `env_file` 📁 ⏮️ 🇨🇻 📁 👥 💚 ⚙️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
`Config` 🎓 ⚙️ Pydantic 📳. 👆 💪 ✍ 🌖 <a href="https://docs.pydantic.dev/latest/api/config/" class="external-link" target="_blank">Pydantic 🏷 📁</a>
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🏗 `Settings` 🕴 🕐 ⏮️ `lru_cache`
|
|
||||||
|
|
||||||
👂 📁 ⚪️➡️ 💾 🛎 ⚠ (🐌) 🛠️, 👆 🎲 💚 ⚫️ 🕴 🕐 & ⤴️ 🏤-⚙️ 🎏 ⚒ 🎚, ↩️ 👂 ⚫️ 🔠 📨.
|
|
||||||
|
|
||||||
✋️ 🔠 🕰 👥:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
Settings()
|
|
||||||
```
|
|
||||||
|
|
||||||
🆕 `Settings` 🎚 🔜 ✍, & 🏗 ⚫️ 🔜 ✍ `.env` 📁 🔄.
|
|
||||||
|
|
||||||
🚥 🔗 🔢 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
def get_settings():
|
|
||||||
return Settings()
|
|
||||||
```
|
|
||||||
|
|
||||||
👥 🔜 ✍ 👈 🎚 🔠 📨, & 👥 🔜 👂 `.env` 📁 🔠 📨. 👶 👶
|
|
||||||
|
|
||||||
✋️ 👥 ⚙️ `@lru_cache` 👨🎨 🔛 🔝, `Settings` 🎚 🔜 ✍ 🕴 🕐, 🥇 🕰 ⚫️ 🤙. 👶 👶
|
|
||||||
|
|
||||||
{* ../../docs_src/settings/app03/main.py hl[1,10] *}
|
|
||||||
|
|
||||||
⤴️ 🙆 🏁 🤙 `get_settings()` 🔗 ⏭ 📨, ↩️ 🛠️ 🔗 📟 `get_settings()` & 🏗 🆕 `Settings` 🎚, ⚫️ 🔜 📨 🎏 🎚 👈 📨 🔛 🥇 🤙, 🔄 & 🔄.
|
|
||||||
|
|
||||||
#### `lru_cache` 📡 ℹ
|
|
||||||
|
|
||||||
`@lru_cache` 🔀 🔢 ⚫️ 🎀 📨 🎏 💲 👈 📨 🥇 🕰, ↩️ 💻 ⚫️ 🔄, 🛠️ 📟 🔢 🔠 🕰.
|
|
||||||
|
|
||||||
, 🔢 🔛 ⚫️ 🔜 🛠️ 🕐 🔠 🌀 ❌. & ⤴️ 💲 📨 🔠 👈 🌀 ❌ 🔜 ⚙️ 🔄 & 🔄 🕐❔ 🔢 🤙 ⏮️ ⚫️❔ 🎏 🌀 ❌.
|
|
||||||
|
|
||||||
🖼, 🚥 👆 ✔️ 🔢:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
@lru_cache
|
|
||||||
def say_hi(name: str, salutation: str = "Ms."):
|
|
||||||
return f"Hello {salutation} {name}"
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 📋 💪 🛠️ 💖 👉:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
|
|
||||||
participant code as Code
|
|
||||||
participant function as say_hi()
|
|
||||||
participant execute as Execute function
|
|
||||||
|
|
||||||
rect rgba(0, 255, 0, .1)
|
|
||||||
code ->> function: say_hi(name="Camila")
|
|
||||||
function ->> execute: execute function code
|
|
||||||
execute ->> code: return the result
|
|
||||||
end
|
|
||||||
|
|
||||||
rect rgba(0, 255, 255, .1)
|
|
||||||
code ->> function: say_hi(name="Camila")
|
|
||||||
function ->> code: return stored result
|
|
||||||
end
|
|
||||||
|
|
||||||
rect rgba(0, 255, 0, .1)
|
|
||||||
code ->> function: say_hi(name="Rick")
|
|
||||||
function ->> execute: execute function code
|
|
||||||
execute ->> code: return the result
|
|
||||||
end
|
|
||||||
|
|
||||||
rect rgba(0, 255, 0, .1)
|
|
||||||
code ->> function: say_hi(name="Rick", salutation="Mr.")
|
|
||||||
function ->> execute: execute function code
|
|
||||||
execute ->> code: return the result
|
|
||||||
end
|
|
||||||
|
|
||||||
rect rgba(0, 255, 255, .1)
|
|
||||||
code ->> function: say_hi(name="Rick")
|
|
||||||
function ->> code: return stored result
|
|
||||||
end
|
|
||||||
|
|
||||||
rect rgba(0, 255, 255, .1)
|
|
||||||
code ->> function: say_hi(name="Camila")
|
|
||||||
function ->> code: return stored result
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
💼 👆 🔗 `get_settings()`, 🔢 🚫 ✊ 🙆 ❌, ⚫️ 🕧 📨 🎏 💲.
|
|
||||||
|
|
||||||
👈 🌌, ⚫️ 🎭 🌖 🚥 ⚫️ 🌐 🔢. ✋️ ⚫️ ⚙️ 🔗 🔢, ⤴️ 👥 💪 🔐 ⚫️ 💪 🔬.
|
|
||||||
|
|
||||||
`@lru_cache` 🍕 `functools` ❔ 🍕 🐍 🐩 🗃, 👆 💪 ✍ 🌅 🔃 ⚫️ <a href="https://docs.python.org/3/library/functools.html#functools.lru_cache" class="external-link" target="_blank">🐍 🩺 `@lru_cache`</a>.
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 ⚙️ Pydantic ⚒ 🍵 ⚒ ⚖️ 📳 👆 🈸, ⏮️ 🌐 🏋️ Pydantic 🏷.
|
|
||||||
|
|
||||||
* ⚙️ 🔗 👆 💪 📉 🔬.
|
|
||||||
* 👆 💪 ⚙️ `.env` 📁 ⏮️ ⚫️.
|
|
||||||
* ⚙️ `@lru_cache` ➡️ 👆 ❎ 👂 🇨🇻 📁 🔄 & 🔄 🔠 📨, ⏪ 🤝 👆 🔐 ⚫️ ⏮️ 🔬.
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
# 🎧 🈸 - 🗻
|
|
||||||
|
|
||||||
🚥 👆 💪 ✔️ 2️⃣ 🔬 FastAPI 🈸, ⏮️ 👫 👍 🔬 🗄 & 👫 👍 🩺 ⚜, 👆 💪 ✔️ 👑 📱 & "🗻" 1️⃣ (⚖️ 🌅) 🎧-🈸(Ⓜ).
|
|
||||||
|
|
||||||
## 🗜 **FastAPI** 🈸
|
|
||||||
|
|
||||||
"🗜" ⛓ ❎ 🍕 "🔬" 🈸 🎯 ➡, 👈 ⤴️ ✊ 💅 🚚 🌐 🔽 👈 ➡, ⏮️ _➡ 🛠️_ 📣 👈 🎧-🈸.
|
|
||||||
|
|
||||||
### 🔝-🎚 🈸
|
|
||||||
|
|
||||||
🥇, ✍ 👑, 🔝-🎚, **FastAPI** 🈸, & 🚮 *➡ 🛠️*:
|
|
||||||
|
|
||||||
{* ../../docs_src/sub_applications/tutorial001.py hl[3,6:8] *}
|
|
||||||
|
|
||||||
### 🎧-🈸
|
|
||||||
|
|
||||||
⤴️, ✍ 👆 🎧-🈸, & 🚮 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👉 🎧-🈸 ➕1️⃣ 🐩 FastAPI 🈸, ✋️ 👉 1️⃣ 👈 🔜 "🗻":
|
|
||||||
|
|
||||||
{* ../../docs_src/sub_applications/tutorial001.py hl[11,14:16] *}
|
|
||||||
|
|
||||||
### 🗻 🎧-🈸
|
|
||||||
|
|
||||||
👆 🔝-🎚 🈸, `app`, 🗻 🎧-🈸, `subapi`.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🔜 📌 ➡ `/subapi`:
|
|
||||||
|
|
||||||
{* ../../docs_src/sub_applications/tutorial001.py hl[11,19] *}
|
|
||||||
|
|
||||||
### ✅ 🏧 🛠️ 🩺
|
|
||||||
|
|
||||||
🔜, 🏃 `uvicorn` ⏮️ 👑 📱, 🚥 👆 📁 `main.py`, ⚫️ 🔜:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
& 📂 🩺 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🛠️ 🩺 👑 📱, 🔌 🕴 🚮 👍 _➡ 🛠️_:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/sub-applications/image01.png">
|
|
||||||
|
|
||||||
& ⤴️, 📂 🩺 🎧-🈸, <a href="http://127.0.0.1:8000/subapi/docs" class="external-link" target="_blank">http://127.0.0.1:8000/subapi/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🛠️ 🩺 🎧-🈸, ✅ 🕴 🚮 👍 _➡ 🛠️_, 🌐 🔽 ☑ 🎧-➡ 🔡 `/subapi`:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/sub-applications/image02.png">
|
|
||||||
|
|
||||||
🚥 👆 🔄 🔗 ⏮️ 🙆 2️⃣ 👩💻 🔢, 👫 🔜 👷 ☑, ↩️ 🖥 🔜 💪 💬 🔠 🎯 📱 ⚖️ 🎧-📱.
|
|
||||||
|
|
||||||
### 📡 ℹ: `root_path`
|
|
||||||
|
|
||||||
🕐❔ 👆 🗻 🎧-🈸 🔬 🔛, FastAPI 🔜 ✊ 💅 🔗 🗻 ➡ 🎧-🈸 ⚙️ 🛠️ ⚪️➡️ 🔫 🔧 🤙 `root_path`.
|
|
||||||
|
|
||||||
👈 🌌, 🎧-🈸 🔜 💭 ⚙️ 👈 ➡ 🔡 🩺 🎚.
|
|
||||||
|
|
||||||
& 🎧-🈸 💪 ✔️ 🚮 👍 📌 🎧-🈸 & 🌐 🔜 👷 ☑, ↩️ FastAPI 🍵 🌐 👉 `root_path`Ⓜ 🔁.
|
|
||||||
|
|
||||||
👆 🔜 💡 🌅 🔃 `root_path` & ❔ ⚙️ ⚫️ 🎯 📄 🔃 [⛅ 🗳](behind-a-proxy.md){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
# 📄
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🙆 📄 🚒 👆 💚 ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
⚠ ⚒ Jinja2️⃣, 🎏 1️⃣ ⚙️ 🏺 & 🎏 🧰.
|
|
||||||
|
|
||||||
📤 🚙 🔗 ⚫️ 💪 👈 👆 💪 ⚙️ 🔗 👆 **FastAPI** 🈸 (🚚 💃).
|
|
||||||
|
|
||||||
## ❎ 🔗
|
|
||||||
|
|
||||||
❎ `jinja2`:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install jinja2
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## ⚙️ `Jinja2Templates`
|
|
||||||
|
|
||||||
* 🗄 `Jinja2Templates`.
|
|
||||||
* ✍ `templates` 🎚 👈 👆 💪 🏤-⚙️ ⏪.
|
|
||||||
* 📣 `Request` 🔢 *➡ 🛠️* 👈 🔜 📨 📄.
|
|
||||||
* ⚙️ `templates` 👆 ✍ ✍ & 📨 `TemplateResponse`, 🚶♀️ `request` 1️⃣ 🔑-💲 👫 Jinja2️⃣ "🔑".
|
|
||||||
|
|
||||||
{* ../../docs_src/templates/tutorial001.py hl[4,11,15:18] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈 👆 ✔️ 🚶♀️ `request` 🍕 🔑-💲 👫 🔑 Jinja2️⃣. , 👆 ✔️ 📣 ⚫️ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📣 `response_class=HTMLResponse` 🩺 🎚 🔜 💪 💭 👈 📨 🔜 🕸.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.templating import Jinja2Templates`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.templating` `fastapi.templating` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃. 🎏 ⏮️ `Request` & `StaticFiles`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✍ 📄
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ✍ 📄 `templates/item.html` ⏮️:
|
|
||||||
|
|
||||||
```jinja hl_lines="7"
|
|
||||||
{!../../docs_src/templates/templates/item.html!}
|
|
||||||
```
|
|
||||||
|
|
||||||
⚫️ 🔜 🎦 `id` ✊ ⚪️➡️ "🔑" `dict` 👆 🚶♀️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{"request": request, "id": id}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📄 & 🎻 📁
|
|
||||||
|
|
||||||
& 👆 💪 ⚙️ `url_for()` 🔘 📄, & ⚙️ ⚫️, 🖼, ⏮️ `StaticFiles` 👆 📌.
|
|
||||||
|
|
||||||
```jinja hl_lines="4"
|
|
||||||
{!../../docs_src/templates/templates/item.html!}
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 🖼, ⚫️ 🔜 🔗 🎚 📁 `static/styles.css` ⏮️:
|
|
||||||
|
|
||||||
```CSS hl_lines="4"
|
|
||||||
{!../../docs_src/templates/static/styles.css!}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ↩️ 👆 ⚙️ `StaticFiles`, 👈 🎚 📁 🔜 🍦 🔁 👆 **FastAPI** 🈸 📛 `/static/styles.css`.
|
|
||||||
|
|
||||||
## 🌅 ℹ
|
|
||||||
|
|
||||||
🌅 ℹ, 🔌 ❔ 💯 📄, ✅ <a href="https://www.starlette.dev/templates/" class="external-link" target="_blank">💃 🩺 🔛 📄</a>.
|
|
||||||
|
|
@ -1,53 +0,0 @@
|
||||||
# 🔬 🔗 ⏮️ 🔐
|
|
||||||
|
|
||||||
## 🔑 🔗 ⏮️ 🔬
|
|
||||||
|
|
||||||
📤 😐 🌐❔ 👆 💪 💚 🔐 🔗 ⏮️ 🔬.
|
|
||||||
|
|
||||||
👆 🚫 💚 ⏮️ 🔗 🏃 (🚫 🙆 🎧-🔗 ⚫️ 💪 ✔️).
|
|
||||||
|
|
||||||
↩️, 👆 💚 🚚 🎏 🔗 👈 🔜 ⚙️ 🕴 ⏮️ 💯 (🎲 🕴 🎯 💯), & 🔜 🚚 💲 👈 💪 ⚙️ 🌐❔ 💲 ⏮️ 🔗 ⚙️.
|
|
||||||
|
|
||||||
### ⚙️ 💼: 🔢 🐕🦺
|
|
||||||
|
|
||||||
🖼 💪 👈 👆 ✔️ 🔢 🤝 🐕🦺 👈 👆 💪 🤙.
|
|
||||||
|
|
||||||
👆 📨 ⚫️ 🤝 & ⚫️ 📨 🔓 👩💻.
|
|
||||||
|
|
||||||
👉 🐕🦺 5️⃣📆 🔌 👆 📍 📨, & 🤙 ⚫️ 💪 ✊ ➕ 🕰 🌘 🚥 👆 ✔️ 🔧 🎁 👩💻 💯.
|
|
||||||
|
|
||||||
👆 🎲 💚 💯 🔢 🐕🦺 🕐, ✋️ 🚫 🎯 🤙 ⚫️ 🔠 💯 👈 🏃.
|
|
||||||
|
|
||||||
👉 💼, 👆 💪 🔐 🔗 👈 🤙 👈 🐕🦺, & ⚙️ 🛃 🔗 👈 📨 🎁 👩💻, 🕴 👆 💯.
|
|
||||||
|
|
||||||
### ⚙️ `app.dependency_overrides` 🔢
|
|
||||||
|
|
||||||
👫 💼, 👆 **FastAPI** 🈸 ✔️ 🔢 `app.dependency_overrides`, ⚫️ 🙅 `dict`.
|
|
||||||
|
|
||||||
🔐 🔗 🔬, 👆 🚮 🔑 ⏮️ 🔗 (🔢), & 💲, 👆 🔗 🔐 (➕1️⃣ 🔢).
|
|
||||||
|
|
||||||
& ⤴️ **FastAPI** 🔜 🤙 👈 🔐 ↩️ ⏮️ 🔗.
|
|
||||||
|
|
||||||
{* ../../docs_src/dependency_testing/tutorial001.py hl[28:29,32] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 ⚒ 🔗 🔐 🔗 ⚙️ 🙆 👆 **FastAPI** 🈸.
|
|
||||||
|
|
||||||
⏮️ 🔗 💪 ⚙️ *➡ 🛠️ 🔢*, *➡ 🛠️ 👨🎨* (🕐❔ 👆 🚫 ⚙️ 📨 💲), `.include_router()` 🤙, ♒️.
|
|
||||||
|
|
||||||
FastAPI 🔜 💪 🔐 ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ⏲ 👆 🔐 (❎ 👫) ⚒ `app.dependency_overrides` 🛁 `dict`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
app.dependency_overrides = {}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 💚 🔐 🔗 🕴 ⏮️ 💯, 👆 💪 ⚒ 🔐 ▶️ 💯 (🔘 💯 🔢) & ⏲ ⚫️ 🔚 (🔚 💯 🔢).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,5 +0,0 @@
|
||||||
# 🔬 🎉: 🕴 - 🤫
|
|
||||||
|
|
||||||
🕐❔ 👆 💪 👆 🎉 🐕🦺 (`startup` & `shutdown`) 🏃 👆 💯, 👆 💪 ⚙️ `TestClient` ⏮️ `with` 📄:
|
|
||||||
|
|
||||||
{* ../../docs_src/app_testing/tutorial003.py hl[9:12,20:24] *}
|
|
||||||
|
|
@ -1,13 +0,0 @@
|
||||||
# 🔬 *️⃣
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 `TestClient` 💯*️⃣.
|
|
||||||
|
|
||||||
👉, 👆 ⚙️ `TestClient` `with` 📄, 🔗*️⃣:
|
|
||||||
|
|
||||||
{* ../../docs_src/app_testing/tutorial002.py hl[27:31] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🌅 ℹ, ✅ 💃 🧾 <a href="https://www.starlette.dev/testclient/#testing-websocket-sessions" class="external-link" target="_blank">🔬 *️⃣ </a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
# ⚙️ 📨 🔗
|
|
||||||
|
|
||||||
🆙 🔜, 👆 ✔️ 📣 🍕 📨 👈 👆 💪 ⏮️ 👫 🆎.
|
|
||||||
|
|
||||||
✊ 📊 ⚪️➡️:
|
|
||||||
|
|
||||||
* ➡ 🔢.
|
|
||||||
* 🎚.
|
|
||||||
* 🍪.
|
|
||||||
* ♒️.
|
|
||||||
|
|
||||||
& 🔨, **FastAPI** ⚖ 👈 💽, 🏭 ⚫️ & 🏭 🧾 👆 🛠️ 🔁.
|
|
||||||
|
|
||||||
✋️ 📤 ⚠ 🌐❔ 👆 💪 💪 🔐 `Request` 🎚 🔗.
|
|
||||||
|
|
||||||
## ℹ 🔃 `Request` 🎚
|
|
||||||
|
|
||||||
**FastAPI** 🤙 **💃** 🔘, ⏮️ 🧽 📚 🧰 🔛 🔝, 👆 💪 ⚙️ 💃 <a href="https://www.starlette.dev/requests/" class="external-link" target="_blank">`Request`</a> 🎚 🔗 🕐❔ 👆 💪.
|
|
||||||
|
|
||||||
⚫️ 🔜 ⛓ 👈 🚥 👆 🤚 📊 ⚪️➡️ `Request` 🎚 🔗 (🖼, ✍ 💪) ⚫️ 🏆 🚫 ✔, 🗜 ⚖️ 📄 (⏮️ 🗄, 🏧 🛠️ 👩💻 🔢) FastAPI.
|
|
||||||
|
|
||||||
👐 🙆 🎏 🔢 📣 🛎 (🖼, 💪 ⏮️ Pydantic 🏷) 🔜 ✔, 🗜, ✍, ♒️.
|
|
||||||
|
|
||||||
✋️ 📤 🎯 💼 🌐❔ ⚫️ ⚠ 🤚 `Request` 🎚.
|
|
||||||
|
|
||||||
## ⚙️ `Request` 🎚 🔗
|
|
||||||
|
|
||||||
➡️ 🌈 👆 💚 🤚 👩💻 📢 📢/🦠 🔘 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
👈 👆 💪 🔐 📨 🔗.
|
|
||||||
|
|
||||||
{* ../../docs_src/using_request_directly/tutorial001.py hl[1,7:8] *}
|
|
||||||
|
|
||||||
📣 *➡ 🛠️ 🔢* 🔢 ⏮️ 🆎 ➖ `Request` **FastAPI** 🔜 💭 🚶♀️ `Request` 👈 🔢.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🗒 👈 👉 💼, 👥 📣 ➡ 🔢 ⤴️ 📨 🔢.
|
|
||||||
|
|
||||||
, ➡ 🔢 🔜 ⚗, ✔, 🗜 ✔ 🆎 & ✍ ⏮️ 🗄.
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 📣 🙆 🎏 🔢 🛎, & ➡, 🤚 `Request` 💁♂️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## `Request` 🧾
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌅 ℹ 🔃 <a href="https://www.starlette.dev/requests/" class="external-link" target="_blank">`Request` 🎚 🛂 💃 🧾 🕸</a>.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.requests import Request`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 ⚫️ 🔗 🏪 👆, 👩💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,186 +0,0 @@
|
||||||
# *️⃣
|
|
||||||
|
|
||||||
👆 💪 ⚙️ <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API" class="external-link" target="_blank"> *️⃣ </a> ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
## ❎ `WebSockets`
|
|
||||||
|
|
||||||
🥇 👆 💪 ❎ `WebSockets`:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install websockets
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## *️⃣ 👩💻
|
|
||||||
|
|
||||||
### 🏭
|
|
||||||
|
|
||||||
👆 🏭 ⚙️, 👆 🎲 ✔️ 🕸 ✍ ⏮️ 🏛 🛠️ 💖 😥, Vue.js ⚖️ 📐.
|
|
||||||
|
|
||||||
& 🔗 ⚙️ *️⃣ ⏮️ 👆 👩💻 👆 🔜 🎲 ⚙️ 👆 🕸 🚙.
|
|
||||||
|
|
||||||
⚖️ 👆 💪 ✔️ 🇦🇸 📱 🈸 👈 🔗 ⏮️ 👆 *️⃣ 👩💻 🔗, 🇦🇸 📟.
|
|
||||||
|
|
||||||
⚖️ 👆 5️⃣📆 ✔️ 🙆 🎏 🌌 🔗 ⏮️ *️⃣ 🔗.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
✋️ 👉 🖼, 👥 🔜 ⚙️ 📶 🙅 🕸 📄 ⏮️ 🕸, 🌐 🔘 📏 🎻.
|
|
||||||
|
|
||||||
👉, ↗️, 🚫 ⚖ & 👆 🚫🔜 ⚙️ ⚫️ 🏭.
|
|
||||||
|
|
||||||
🏭 👆 🔜 ✔️ 1️⃣ 🎛 🔛.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🙅 🌌 🎯 🔛 💽-🚄 *️⃣ & ✔️ 👷 🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/websockets/tutorial001.py hl[2,6:38,41:43] *}
|
|
||||||
|
|
||||||
## ✍ `websocket`
|
|
||||||
|
|
||||||
👆 **FastAPI** 🈸, ✍ `websocket`:
|
|
||||||
|
|
||||||
{* ../../docs_src/websockets/tutorial001.py hl[1,46:47] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.websockets import WebSocket`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `WebSocket` 🔗 🏪 👆, 👩💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⌛ 📧 & 📨 📧
|
|
||||||
|
|
||||||
👆 *️⃣ 🛣 👆 💪 `await` 📧 & 📨 📧.
|
|
||||||
|
|
||||||
{* ../../docs_src/websockets/tutorial001.py hl[48:52] *}
|
|
||||||
|
|
||||||
👆 💪 📨 & 📨 💱, ✍, & 🎻 💽.
|
|
||||||
|
|
||||||
## 🔄 ⚫️
|
|
||||||
|
|
||||||
🚥 👆 📁 📛 `main.py`, 🏃 👆 🈸 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
📂 👆 🖥 <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🙅 📃 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/websockets/image01.png">
|
|
||||||
|
|
||||||
👆 💪 🆎 📧 🔢 📦, & 📨 👫:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/websockets/image02.png">
|
|
||||||
|
|
||||||
& 👆 **FastAPI** 🈸 ⏮️ *️⃣ 🔜 📨 🔙:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/websockets/image03.png">
|
|
||||||
|
|
||||||
👆 💪 📨 (& 📨) 📚 📧:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/websockets/image04.png">
|
|
||||||
|
|
||||||
& 🌐 👫 🔜 ⚙️ 🎏 *️⃣ 🔗.
|
|
||||||
|
|
||||||
## ⚙️ `Depends` & 🎏
|
|
||||||
|
|
||||||
*️⃣ 🔗 👆 💪 🗄 ⚪️➡️ `fastapi` & ⚙️:
|
|
||||||
|
|
||||||
* `Depends`
|
|
||||||
* `Security`
|
|
||||||
* `Cookie`
|
|
||||||
* `Header`
|
|
||||||
* `Path`
|
|
||||||
* `Query`
|
|
||||||
|
|
||||||
👫 👷 🎏 🌌 🎏 FastAPI 🔗/*➡ 🛠️*:
|
|
||||||
|
|
||||||
{* ../../docs_src/websockets/tutorial002.py hl[66:77,76:91] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👉 *️⃣ ⚫️ 🚫 🤙 ⚒ 🔑 🤚 `HTTPException`, ↩️ 👥 🤚 `WebSocketException`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 📪 📟 ⚪️➡️ <a href="https://tools.ietf.org/html/rfc6455#section-7.4.1" class="external-link" target="_blank">☑ 📟 🔬 🔧</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔄 *️⃣ ⏮️ 🔗
|
|
||||||
|
|
||||||
🚥 👆 📁 📛 `main.py`, 🏃 👆 🈸 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
📂 👆 🖥 <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
|
|
||||||
|
|
||||||
📤 👆 💪 ⚒:
|
|
||||||
|
|
||||||
* "🏬 🆔", ⚙️ ➡.
|
|
||||||
* "🤝" ⚙️ 🔢 🔢.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 🔢 `token` 🔜 🍵 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⏮️ 👈 👆 💪 🔗 *️⃣ & ⤴️ 📨 & 📨 📧:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/websockets/image05.png">
|
|
||||||
|
|
||||||
## 🚚 🔀 & 💗 👩💻
|
|
||||||
|
|
||||||
🕐❔ *️⃣ 🔗 📪, `await websocket.receive_text()` 🔜 🤚 `WebSocketDisconnect` ⚠, ❔ 👆 💪 ⤴️ ✊ & 🍵 💖 👉 🖼.
|
|
||||||
|
|
||||||
{* ../../docs_src/websockets/tutorial003.py hl[81:83] *}
|
|
||||||
|
|
||||||
🔄 ⚫️ 👅:
|
|
||||||
|
|
||||||
* 📂 📱 ⏮️ 📚 🖥 📑.
|
|
||||||
* ✍ 📧 ⚪️➡️ 👫.
|
|
||||||
* ⤴️ 🔐 1️⃣ 📑.
|
|
||||||
|
|
||||||
👈 🔜 🤚 `WebSocketDisconnect` ⚠, & 🌐 🎏 👩💻 🔜 📨 📧 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
Client #1596980209979 left the chat
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📱 🔛 ⭐ & 🙅 🖼 🎦 ❔ 🍵 & 📻 📧 📚 *️⃣ 🔗.
|
|
||||||
|
|
||||||
✋️ ✔️ 🤯 👈, 🌐 🍵 💾, 👁 📇, ⚫️ 🔜 🕴 👷 ⏪ 🛠️ 🏃, & 🔜 🕴 👷 ⏮️ 👁 🛠️.
|
|
||||||
|
|
||||||
🚥 👆 💪 🕳 ⏩ 🛠️ ⏮️ FastAPI ✋️ 👈 🌖 🏋️, 🐕🦺 ✳, ✳ ⚖️ 🎏, ✅ <a href="https://github.com/encode/broadcaster" class="external-link" target="_blank">🗜/📻</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌅 ℹ
|
|
||||||
|
|
||||||
💡 🌅 🔃 🎛, ✅ 💃 🧾:
|
|
||||||
|
|
||||||
* <a href="https://www.starlette.dev/websockets/" class="external-link" target="_blank"> `WebSocket` 🎓</a>.
|
|
||||||
* <a href="https://www.starlette.dev/endpoints/#websocketendpoint" class="external-link" target="_blank">🎓-⚓️ *️⃣ 🚚</a>.
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# ✅ 🇨🇻 - 🏺, ✳, 🎏
|
|
||||||
|
|
||||||
👆 💪 🗻 🇨🇻 🈸 👆 👀 ⏮️ [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}, [⛅ 🗳](behind-a-proxy.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👈, 👆 💪 ⚙️ `WSGIMiddleware` & ⚙️ ⚫️ 🎁 👆 🇨🇻 🈸, 🖼, 🏺, ✳, ♒️.
|
|
||||||
|
|
||||||
## ⚙️ `WSGIMiddleware`
|
|
||||||
|
|
||||||
👆 💪 🗄 `WSGIMiddleware`.
|
|
||||||
|
|
||||||
⤴️ 🎁 🇨🇻 (✅ 🏺) 📱 ⏮️ 🛠️.
|
|
||||||
|
|
||||||
& ⤴️ 🗻 👈 🔽 ➡.
|
|
||||||
|
|
||||||
{* ../../docs_src/wsgi/tutorial001.py hl[2:3,22] *}
|
|
||||||
|
|
||||||
## ✅ ⚫️
|
|
||||||
|
|
||||||
🔜, 🔠 📨 🔽 ➡ `/v1/` 🔜 🍵 🏺 🈸.
|
|
||||||
|
|
||||||
& 🎂 🔜 🍵 **FastAPI**.
|
|
||||||
|
|
||||||
🚥 👆 🏃 ⚫️ ⏮️ Uvicorn & 🚶 <a href="http://localhost:8000/v1/" class="external-link" target="_blank">http://localhost:8000/v1/</a> 👆 🔜 👀 📨 ⚪️➡️ 🏺:
|
|
||||||
|
|
||||||
```txt
|
|
||||||
Hello, World from Flask!
|
|
||||||
```
|
|
||||||
|
|
||||||
& 🚥 👆 🚶 <a href="http://localhost:8000/v2" class="external-link" target="_blank">http://localhost:8000/v2</a> 👆 🔜 👀 📨 ⚪️➡️ FastAPI:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"message": "Hello World"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,485 +0,0 @@
|
||||||
# 🎛, 🌈 & 🔺
|
|
||||||
|
|
||||||
⚫️❔ 😮 **FastAPI**, ❔ ⚫️ 🔬 🎏 🎛 & ⚫️❔ ⚫️ 🇭🇲 ⚪️➡️ 👫.
|
|
||||||
|
|
||||||
## 🎶
|
|
||||||
|
|
||||||
**FastAPI** 🚫🔜 🔀 🚥 🚫 ⏮️ 👷 🎏.
|
|
||||||
|
|
||||||
📤 ✔️ 📚 🧰 ✍ ⏭ 👈 ✔️ ℹ 😮 🚮 🏗.
|
|
||||||
|
|
||||||
👤 ✔️ ❎ 🏗 🆕 🛠️ 📚 1️⃣2️⃣🗓️. 🥇 👤 🔄 ❎ 🌐 ⚒ 📔 **FastAPI** ⚙️ 📚 🎏 🛠️, 🔌-🔌, & 🧰.
|
|
||||||
|
|
||||||
✋️ ☝, 📤 🙅♂ 🎏 🎛 🌘 🏗 🕳 👈 🚚 🌐 👫 ⚒, ✊ 🏆 💭 ⚪️➡️ ⏮️ 🧰, & 🌀 👫 🏆 🌌 💪, ⚙️ 🇪🇸 ⚒ 👈 ➖🚫 💪 ⏭ (🐍 3️⃣.6️⃣ ➕ 🆎 🔑).
|
|
||||||
|
|
||||||
## ⏮️ 🧰
|
|
||||||
|
|
||||||
### <a href="https://www.djangoproject.com/" class="external-link" target="_blank">✳</a>
|
|
||||||
|
|
||||||
⚫️ 🌅 🌟 🐍 🛠️ & 🛎 🕴. ⚫️ ⚙️ 🏗 ⚙️ 💖 👱📔.
|
|
||||||
|
|
||||||
⚫️ 📶 😆 🔗 ⏮️ 🔗 💽 (💖 ✳ ⚖️ ✳),, ✔️ ☁ 💽 (💖 🗄, ✳, 👸, ♒️) 👑 🏪 🚒 🚫 📶 ⏩.
|
|
||||||
|
|
||||||
⚫️ ✍ 🏗 🕸 👩💻, 🚫 ✍ 🔗 ⚙️ 🏛 🕸 (💖 😥, Vue.js & 📐) ⚖️ 🎏 ⚙️ (💖 <abbr title="Internet of Things">☁</abbr> 📳) 🔗 ⏮️ ⚫️.
|
|
||||||
|
|
||||||
### <a href="https://www.django-rest-framework.org/" class="external-link" target="_blank">✳ 🎂 🛠️</a>
|
|
||||||
|
|
||||||
✳ 🎂 🛠️ ✍ 🗜 🧰 🏗 🕸 🔗 ⚙️ ✳ 🔘, 📉 🚮 🛠️ 🛠️.
|
|
||||||
|
|
||||||
⚫️ ⚙️ 📚 🏢 ✅ 🦎, 🟥 👒 & 🎟.
|
|
||||||
|
|
||||||
⚫️ 🕐 🥇 🖼 **🏧 🛠️ 🧾**, & 👉 🎯 🕐 🥇 💭 👈 😮 "🔎" **FastAPI**.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
✳ 🎂 🛠️ ✍ ✡ 🇺🇸🏛. 🎏 👼 💃 & Uvicorn, 🔛 ❔ **FastAPI** ⚓️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
✔️ 🏧 🛠️ 🧾 🕸 👩💻 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://flask.palletsprojects.com" class="external-link" target="_blank">🏺</a>
|
|
||||||
|
|
||||||
🏺 "🕸", ⚫️ 🚫 🔌 💽 🛠️ 🚫 📚 👜 👈 👟 🔢 ✳.
|
|
||||||
|
|
||||||
👉 🦁 & 💪 ✔ 🔨 👜 💖 ⚙️ ☁ 💽 👑 💽 💾 ⚙️.
|
|
||||||
|
|
||||||
⚫️ 📶 🙅, ⚫️ 📶 🏋️ 💡, 👐 🧾 🤚 🙁 📡 ☝.
|
|
||||||
|
|
||||||
⚫️ 🛎 ⚙️ 🎏 🈸 👈 🚫 🎯 💪 💽, 👩💻 🧾, ⚖️ 🙆 📚 ⚒ 👈 👟 🏤-🏗 ✳. 👐 📚 👫 ⚒ 💪 🚮 ⏮️ 🔌-🔌.
|
|
||||||
|
|
||||||
👉 ⚖ 🍕, & ➖ "🕸" 👈 💪 ↔ 📔 ⚫️❔ ⚫️❔ 💪 🔑 ⚒ 👈 👤 💚 🚧.
|
|
||||||
|
|
||||||
👐 🦁 🏺, ⚫️ 😑 💖 👍 🏏 🏗 🔗. ⏭ 👜 🔎 "✳ 🎂 🛠️" 🏺.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
◾-🛠️. ⚒ ⚫️ ⏩ 🌀 & 🏏 🧰 & 🍕 💪.
|
|
||||||
|
|
||||||
✔️ 🙅 & ⏩ ⚙️ 🕹 ⚙️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://requests.readthedocs.io" class="external-link" target="_blank">📨</a>
|
|
||||||
|
|
||||||
**FastAPI** 🚫 🤙 🎛 **📨**. 👫 ↔ 📶 🎏.
|
|
||||||
|
|
||||||
⚫️ 🔜 🤙 ⚠ ⚙️ 📨 *🔘* FastAPI 🈸.
|
|
||||||
|
|
||||||
✋️, FastAPI 🤚 🌈 ⚪️➡️ 📨.
|
|
||||||
|
|
||||||
**📨** 🗃 *🔗* ⏮️ 🔗 (👩💻), ⏪ **FastAPI** 🗃 *🏗* 🔗 (💽).
|
|
||||||
|
|
||||||
👫, 🌖 ⚖️ 🌘, 🔄 🔚, 🔗 🔠 🎏.
|
|
||||||
|
|
||||||
📨 ✔️ 📶 🙅 & 🏋️ 🔧, ⚫️ 📶 ⏩ ⚙️, ⏮️ 🤔 🔢. ✋️ 🎏 🕰, ⚫️ 📶 🏋️ & 🛃.
|
|
||||||
|
|
||||||
👈 ⚫️❔, 💬 🛂 🕸:
|
|
||||||
|
|
||||||
> 📨 1️⃣ 🏆 ⏬ 🐍 📦 🌐 🕰
|
|
||||||
|
|
||||||
🌌 👆 ⚙️ ⚫️ 📶 🙅. 🖼, `GET` 📨, 👆 🔜 ✍:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
response = requests.get("http://example.com/some/url")
|
|
||||||
```
|
|
||||||
|
|
||||||
FastAPI 😑 🛠️ *➡ 🛠️* 💪 👀 💖:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
@app.get("/some/url")
|
|
||||||
def read_url():
|
|
||||||
return {"message": "Hello World"}
|
|
||||||
```
|
|
||||||
|
|
||||||
👀 🔀 `requests.get(...)` & `@app.get(...)`.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
* ✔️ 🙅 & 🏋️ 🛠️.
|
|
||||||
* ⚙️ 🇺🇸🔍 👩🔬 📛 (🛠️) 🔗, 🎯 & 🏋️ 🌌.
|
|
||||||
* ✔️ 🤔 🔢, ✋️ 🏋️ 🛃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://swagger.io/" class="external-link" target="_blank">🦁</a> / <a href="https://github.com/OAI/OpenAPI-Specification/" class="external-link" target="_blank">🗄</a>
|
|
||||||
|
|
||||||
👑 ⚒ 👤 💚 ⚪️➡️ ✳ 🎂 🛠️ 🏧 🛠️ 🧾.
|
|
||||||
|
|
||||||
⤴️ 👤 🔎 👈 📤 🐩 📄 🔗, ⚙️ 🎻 (⚖️ 📁, ↔ 🎻) 🤙 🦁.
|
|
||||||
|
|
||||||
& 📤 🕸 👩💻 🔢 🦁 🛠️ ⏪ ✍. , 💆♂ 💪 🏗 🦁 🧾 🛠️ 🔜 ✔ ⚙️ 👉 🕸 👩💻 🔢 🔁.
|
|
||||||
|
|
||||||
☝, 🦁 👐 💾 🏛, 📁 🗄.
|
|
||||||
|
|
||||||
👈 ⚫️❔ 🕐❔ 💬 🔃 ⏬ 2️⃣.0️⃣ ⚫️ ⚠ 💬 "🦁", & ⏬ 3️⃣ ➕ "🗄".
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🛠️ & ⚙️ 📂 🐩 🛠️ 🔧, ↩️ 🛃 🔗.
|
|
||||||
|
|
||||||
& 🛠️ 🐩-⚓️ 👩💻 🔢 🧰:
|
|
||||||
|
|
||||||
* <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">🦁 🎚</a>
|
|
||||||
* <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">📄</a>
|
|
||||||
|
|
||||||
👫 2️⃣ 👐 ➖ 📶 🌟 & ⚖, ✋️ 🔨 ⏩ 🔎, 👆 💪 🔎 💯 🌖 🎛 👩💻 🔢 🗄 (👈 👆 💪 ⚙️ ⏮️ **FastAPI**).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🏺 🎂 🛠️
|
|
||||||
|
|
||||||
📤 📚 🏺 🎂 🛠️, ✋️ ⏮️ 💰 🕰 & 👷 🔘 🔬 👫, 👤 🔎 👈 📚 😞 ⚖️ 🚫, ⏮️ 📚 🧍 ❔ 👈 ⚒ 👫 🙃.
|
|
||||||
|
|
||||||
### <a href="https://marshmallow.readthedocs.io/en/stable/" class="external-link" target="_blank">🍭</a>
|
|
||||||
|
|
||||||
1️⃣ 👑 ⚒ 💪 🛠️ ⚙️ 📊 "<abbr title="also called marshalling, conversion">🛠️</abbr>" ❔ ✊ 📊 ⚪️➡️ 📟 (🐍) & 🏭 ⚫️ 🔘 🕳 👈 💪 📨 🔘 🕸. 🖼, 🏭 🎚 ⚗ 📊 ⚪️➡️ 💽 🔘 🎻 🎚. 🏭 `datetime` 🎚 🔘 🎻, ♒️.
|
|
||||||
|
|
||||||
➕1️⃣ 🦏 ⚒ 💚 🔗 💽 🔬, ⚒ 💭 👈 💽 ☑, 🤝 🎯 🔢. 🖼, 👈 🏑 `int`, & 🚫 🎲 🎻. 👉 ✴️ ⚠ 📨 💽.
|
|
||||||
|
|
||||||
🍵 💽 🔬 ⚙️, 👆 🔜 ✔️ 🌐 ✅ ✋, 📟.
|
|
||||||
|
|
||||||
👫 ⚒ ⚫️❔ 🍭 🏗 🚚. ⚫️ 👑 🗃, & 👤 ✔️ ⚙️ ⚫️ 📚 ⏭.
|
|
||||||
|
|
||||||
✋️ ⚫️ ✍ ⏭ 📤 🔀 🐍 🆎 🔑. , 🔬 🔠 <abbr title="the definition of how data should be formed">🔗</abbr> 👆 💪 ⚙️ 🎯 🇨🇻 & 🎓 🚚 🍭.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
⚙️ 📟 🔬 "🔗" 👈 🚚 💽 🆎 & 🔬, 🔁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://webargs.readthedocs.io/en/latest/" class="external-link" target="_blank">Webarg</a>
|
|
||||||
|
|
||||||
➕1️⃣ 🦏 ⚒ ✔ 🔗 <abbr title="reading and converting to Python data">✍</abbr> 📊 ⚪️➡️ 📨 📨.
|
|
||||||
|
|
||||||
Webarg 🧰 👈 ⚒ 🚚 👈 🔛 🔝 📚 🛠️, 🔌 🏺.
|
|
||||||
|
|
||||||
⚫️ ⚙️ 🍭 🔘 💽 🔬. & ⚫️ ✍ 🎏 👩💻.
|
|
||||||
|
|
||||||
⚫️ 👑 🧰 & 👤 ✔️ ⚙️ ⚫️ 📚 💁♂️, ⏭ ✔️ **FastAPI**.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
Webarg ✍ 🎏 🍭 👩💻.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
✔️ 🏧 🔬 📨 📨 💽.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://apispec.readthedocs.io/en/stable/" class="external-link" target="_blank">APISpec</a>
|
|
||||||
|
|
||||||
🍭 & Webarg 🚚 🔬, ✍ & 🛠️ 🔌-🔌.
|
|
||||||
|
|
||||||
✋️ 🧾 ❌. ⤴️ APISpec ✍.
|
|
||||||
|
|
||||||
⚫️ 🔌-📚 🛠️ (& 📤 🔌-💃 💁♂️).
|
|
||||||
|
|
||||||
🌌 ⚫️ 👷 👈 👆 ✍ 🔑 🔗 ⚙️ 📁 📁 🔘 #️⃣ 🔠 🔢 🚚 🛣.
|
|
||||||
|
|
||||||
& ⚫️ 🏗 🗄 🔗.
|
|
||||||
|
|
||||||
👈 ❔ ⚫️ 👷 🏺, 💃, 🆘, ♒️.
|
|
||||||
|
|
||||||
✋️ ⤴️, 👥 ✔️ 🔄 ⚠ ✔️ ◾-❕, 🔘 🐍 🎻 (🦏 📁).
|
|
||||||
|
|
||||||
👨🎨 💪 🚫 ℹ 🌅 ⏮️ 👈. & 🚥 👥 🔀 🔢 ⚖️ 🍭 🔗 & 💭 🔀 👈 📁#️⃣, 🏗 🔗 🔜 ❌.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
APISpec ✍ 🎏 🍭 👩💻.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🐕🦺 📂 🐩 🛠️, 🗄.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://flask-apispec.readthedocs.io/en/latest/" class="external-link" target="_blank">🏺-Apispec</a>
|
|
||||||
|
|
||||||
⚫️ 🏺 🔌 -, 👈 👔 👯♂️ Webarg, 🍭 & APISpec.
|
|
||||||
|
|
||||||
⚫️ ⚙️ ℹ ⚪️➡️ Webarg & 🍭 🔁 🏗 🗄 🔗, ⚙️ APISpec.
|
|
||||||
|
|
||||||
⚫️ 👑 🧰, 📶 🔽-📈. ⚫️ 🔜 🌌 🌖 🌟 🌘 📚 🏺 🔌-🔌 👅 📤. ⚫️ 💪 ↩️ 🚮 🧾 ➖ 💁♂️ 🩲 & 📝.
|
|
||||||
|
|
||||||
👉 ❎ ✔️ ✍ 📁 (➕1️⃣ ❕) 🔘 🐍 ✍.
|
|
||||||
|
|
||||||
👉 🌀 🏺, 🏺-Apispec ⏮️ 🍭 & Webarg 👇 💕 👩💻 📚 ⏭ 🏗 **FastAPI**.
|
|
||||||
|
|
||||||
⚙️ ⚫️ ↘️ 🏗 📚 🏺 🌕-📚 🚂. 👫 👑 📚 👤 (& 📚 🔢 🏉) ✔️ ⚙️ 🆙 🔜:
|
|
||||||
|
|
||||||
* <a href="https://github.com/tiangolo/full-stack" class="external-link" target="_blank">https://github.com/tiangolo/full-stack</a>
|
|
||||||
* <a href="https://github.com/tiangolo/full-stack-flask-couchbase" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-flask-couchbase</a>
|
|
||||||
* <a href="https://github.com/tiangolo/full-stack-flask-couchdb" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-flask-couchdb</a>
|
|
||||||
|
|
||||||
& 👫 🎏 🌕-📚 🚂 🧢 [**FastAPI** 🏗 🚂](project-generation.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🏺-Apispec ✍ 🎏 🍭 👩💻.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🏗 🗄 🔗 🔁, ⚪️➡️ 🎏 📟 👈 🔬 🛠️ & 🔬.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://nestjs.com/" class="external-link" target="_blank">NestJS</a> (& <a href="https://angular.io/" class="external-link" target="_blank">📐</a>)
|
|
||||||
|
|
||||||
👉 ➖🚫 🚫 🐍, NestJS 🕸 (📕) ✳ 🛠️ 😮 📐.
|
|
||||||
|
|
||||||
⚫️ 🏆 🕳 🙁 🎏 ⚫️❔ 💪 🔨 ⏮️ 🏺-Apispec.
|
|
||||||
|
|
||||||
⚫️ ✔️ 🛠️ 🔗 💉 ⚙️, 😮 📐 2️⃣. ⚫️ 🚚 🏤-® "💉" (💖 🌐 🎏 🔗 💉 ⚙️ 👤 💭),, ⚫️ 🚮 🎭 & 📟 🔁.
|
|
||||||
|
|
||||||
🔢 🔬 ⏮️ 📕 🆎 (🎏 🐍 🆎 🔑), 👨🎨 🐕🦺 👍.
|
|
||||||
|
|
||||||
✋️ 📕 📊 🚫 🛡 ⏮️ 📹 🕸, ⚫️ 🚫🔜 ⚓️ 🔛 🆎 🔬 🔬, 🛠️ & 🧾 🎏 🕰. ↩️ 👉 & 🔧 🚫, 🤚 🔬, 🛠️ & 🏧 🔗 ⚡, ⚫️ 💪 🚮 👨🎨 📚 🥉. , ⚫️ ▶️️ 🔁.
|
|
||||||
|
|
||||||
⚫️ 💪 🚫 🍵 🔁 🏷 📶 👍. , 🚥 🎻 💪 📨 🎻 🎚 👈 ✔️ 🔘 🏑 👈 🔄 🐦 🎻 🎚, ⚫️ 🚫🔜 ☑ 📄 & ✔.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
⚙️ 🐍 🆎 ✔️ 👑 👨🎨 🐕🦺.
|
|
||||||
|
|
||||||
✔️ 🏋️ 🔗 💉 ⚙️. 🔎 🌌 📉 📟 🔁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://sanic.readthedocs.io/en/latest/" class="external-link" target="_blank">🤣</a>
|
|
||||||
|
|
||||||
⚫️ 🕐 🥇 📶 ⏩ 🐍 🛠️ ⚓️ 🔛 `asyncio`. ⚫️ ⚒ 📶 🎏 🏺.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
⚫️ ⚙️ <a href="https://github.com/MagicStack/uvloop" class="external-link" target="_blank">`uvloop`</a> ↩️ 🔢 🐍 `asyncio` ➰. 👈 ⚫️❔ ⚒ ⚫️ ⏩.
|
|
||||||
|
|
||||||
⚫️ 🎯 😮 Uvicorn & 💃, 👈 ⏳ ⏩ 🌘 🤣 📂 📇.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🔎 🌌 ✔️ 😜 🎭.
|
|
||||||
|
|
||||||
👈 ⚫️❔ **FastAPI** ⚓️ 🔛 💃, ⚫️ ⏩ 🛠️ 💪 (💯 🥉-🥳 📇).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://falconframework.org/" class="external-link" target="_blank">🦅</a>
|
|
||||||
|
|
||||||
🦅 ➕1️⃣ ↕ 🎭 🐍 🛠️, ⚫️ 🔧 ⭐, & 👷 🏛 🎏 🛠️ 💖 🤗.
|
|
||||||
|
|
||||||
⚫️ 🏗 ✔️ 🔢 👈 📨 2️⃣ 🔢, 1️⃣ "📨" & 1️⃣ "📨". ⤴️ 👆 "✍" 🍕 ⚪️➡️ 📨, & "✍" 🍕 📨. ↩️ 👉 🔧, ⚫️ 🚫 💪 📣 📨 🔢 & 💪 ⏮️ 🐩 🐍 🆎 🔑 🔢 🔢.
|
|
||||||
|
|
||||||
, 💽 🔬, 🛠️, & 🧾, ✔️ ⌛ 📟, 🚫 🔁. ⚖️ 👫 ✔️ 🛠️ 🛠️ 🔛 🔝 🦅, 💖 🤗. 👉 🎏 🔺 🔨 🎏 🛠️ 👈 😮 🦅 🔧, ✔️ 1️⃣ 📨 🎚 & 1️⃣ 📨 🎚 🔢.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🔎 🌌 🤚 👑 🎭.
|
|
||||||
|
|
||||||
⤴️ ⏮️ 🤗 (🤗 ⚓️ 🔛 🦅) 😮 **FastAPI** 📣 `response` 🔢 🔢.
|
|
||||||
|
|
||||||
👐 FastAPI ⚫️ 📦, & ⚙️ ✴️ ⚒ 🎚, 🍪, & 🎛 👔 📟.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://moltenframework.com/" class="external-link" target="_blank">♨</a>
|
|
||||||
|
|
||||||
👤 🔎 ♨ 🥇 ▶️ 🏗 **FastAPI**. & ⚫️ ✔️ 🎏 💭:
|
|
||||||
|
|
||||||
* ⚓️ 🔛 🐍 🆎 🔑.
|
|
||||||
* 🔬 & 🧾 ⚪️➡️ 👫 🆎.
|
|
||||||
* 🔗 💉 ⚙️.
|
|
||||||
|
|
||||||
⚫️ 🚫 ⚙️ 💽 🔬, 🛠️ & 🧾 🥉-🥳 🗃 💖 Pydantic, ⚫️ ✔️ 🚮 👍. , 👫 💽 🆎 🔑 🔜 🚫 ♻ 💪.
|
|
||||||
|
|
||||||
⚫️ 🚚 🐥 🍖 🌅 🔁 📳. & ⚫️ ⚓️ 🔛 🇨🇻 (↩️ 🔫), ⚫️ 🚫 🔧 ✊ 📈 ↕-🎭 🚚 🧰 💖 Uvicorn, 💃 & 🤣.
|
|
||||||
|
|
||||||
🔗 💉 ⚙️ 🚚 🏤-® 🔗 & 🔗 ❎ 🧢 🔛 📣 🆎. , ⚫️ 🚫 💪 📣 🌅 🌘 1️⃣ "🦲" 👈 🚚 🎯 🆎.
|
|
||||||
|
|
||||||
🛣 📣 👁 🥉, ⚙️ 🔢 📣 🎏 🥉 (↩️ ⚙️ 👨🎨 👈 💪 🥉 ▶️️ 🔛 🔝 🔢 👈 🍵 🔗). 👉 🔐 ❔ ✳ 🔨 ⚫️ 🌘 ❔ 🏺 (& 💃) 🔨 ⚫️. ⚫️ 🎏 📟 👜 👈 📶 😆 🔗.
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🔬 ➕ 🔬 💽 🆎 ⚙️ "🔢" 💲 🏷 🔢. 👉 📉 👨🎨 🐕🦺, & ⚫️ 🚫 💪 Pydantic ⏭.
|
|
||||||
|
|
||||||
👉 🤙 😮 🛠️ 🍕 Pydantic, 🐕🦺 🎏 🔬 📄 👗 (🌐 👉 🛠️ 🔜 ⏪ 💪 Pydantic).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://github.com/hugapi/hug" class="external-link" target="_blank">🤗</a>
|
|
||||||
|
|
||||||
🤗 🕐 🥇 🛠️ 🛠️ 📄 🛠️ 🔢 🆎 ⚙️ 🐍 🆎 🔑. 👉 👑 💭 👈 😮 🎏 🧰 🎏.
|
|
||||||
|
|
||||||
⚫️ ⚙️ 🛃 🆎 🚮 📄 ↩️ 🐩 🐍 🆎, ✋️ ⚫️ 🦏 🔁 ⏩.
|
|
||||||
|
|
||||||
⚫️ 🕐 🥇 🛠️ 🏗 🛃 🔗 📣 🎂 🛠️ 🎻.
|
|
||||||
|
|
||||||
⚫️ 🚫 ⚓️ 🔛 🐩 💖 🗄 & 🎻 🔗. ⚫️ 🚫🔜 🎯 🛠️ ⚫️ ⏮️ 🎏 🧰, 💖 🦁 🎚. ✋️ 🔄, ⚫️ 📶 💡 💭.
|
|
||||||
|
|
||||||
⚫️ ✔️ 😌, ⭐ ⚒: ⚙️ 🎏 🛠️, ⚫️ 💪 ✍ 🔗 & 🇳🇨.
|
|
||||||
|
|
||||||
⚫️ ⚓️ 🔛 ⏮️ 🐩 🔁 🐍 🕸 🛠️ (🇨🇻), ⚫️ 💪 🚫 🍵 *️⃣ & 🎏 👜, 👐 ⚫️ ✔️ ↕ 🎭 💁♂️.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🤗 ✍ ✡ 🗄, 🎏 👼 <a href="https://github.com/timothycrosley/isort" class="external-link" target="_blank">`isort`</a>, 👑 🧰 🔁 😇 🗄 🐍 📁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 💭 😮 **FastAPI**
|
|
||||||
|
|
||||||
🤗 😮 🍕 APIStar, & 1️⃣ 🧰 👤 🔎 🏆 👍, 🌟 APIStar.
|
|
||||||
|
|
||||||
🤗 ℹ 😍 **FastAPI** ⚙️ 🐍 🆎 🔑 📣 🔢, & 🏗 🔗 ⚖ 🛠️ 🔁.
|
|
||||||
|
|
||||||
🤗 😮 **FastAPI** 📣 `response` 🔢 🔢 ⚒ 🎚 & 🍪.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://github.com/encode/apistar" class="external-link" target="_blank">APIStar</a> (<= 0️⃣.5️⃣)
|
|
||||||
|
|
||||||
▶️️ ⏭ 🤔 🏗 **FastAPI** 👤 🔎 **APIStar** 💽. ⚫️ ✔️ 🌖 🌐 👤 👀 & ✔️ 👑 🔧.
|
|
||||||
|
|
||||||
⚫️ 🕐 🥇 🛠️ 🛠️ ⚙️ 🐍 🆎 🔑 📣 🔢 & 📨 👈 👤 ⏱ 👀 (⏭ NestJS & ♨). 👤 🔎 ⚫️ 🌅 ⚖️ 🌘 🎏 🕰 🤗. ✋️ APIStar ⚙️ 🗄 🐩.
|
|
||||||
|
|
||||||
⚫️ ✔️ 🏧 💽 🔬, 💽 🛠️ & 🗄 🔗 ⚡ ⚓️ 🔛 🎏 🆎 🔑 📚 🥉.
|
|
||||||
|
|
||||||
💪 🔗 🔑 🚫 ⚙️ 🎏 🐍 🆎 🔑 💖 Pydantic, ⚫️ 🍖 🌅 🎏 🍭,, 👨🎨 🐕🦺 🚫🔜 👍, ✋️, APIStar 🏆 💪 🎛.
|
|
||||||
|
|
||||||
⚫️ ✔️ 🏆 🎭 📇 🕰 (🕴 💥 💃).
|
|
||||||
|
|
||||||
🥇, ⚫️ 🚫 ✔️ 🏧 🛠️ 🧾 🕸 🎚, ✋️ 👤 💭 👤 💪 🚮 🦁 🎚 ⚫️.
|
|
||||||
|
|
||||||
⚫️ ✔️ 🔗 💉 ⚙️. ⚫️ ✔ 🏤-® 🦲, 🎏 🧰 🔬 🔛. ✋️, ⚫️ 👑 ⚒.
|
|
||||||
|
|
||||||
👤 🙅 💪 ⚙️ ⚫️ 🌕 🏗, ⚫️ 🚫 ✔️ 💂♂ 🛠️,, 👤 🚫 🚫 ❎ 🌐 ⚒ 👤 ✔️ ⏮️ 🌕-📚 🚂 ⚓️ 🔛 🏺-Apispec. 👤 ✔️ 👇 📈 🏗 ✍ 🚲 📨 ❎ 👈 🛠️.
|
|
||||||
|
|
||||||
✋️ ⤴️, 🏗 🎯 🔀.
|
|
||||||
|
|
||||||
⚫️ 🙅♂ 📏 🛠️ 🕸 🛠️, 👼 💪 🎯 🔛 💃.
|
|
||||||
|
|
||||||
🔜 APIStar ⚒ 🧰 ✔ 🗄 🔧, 🚫 🕸 🛠️.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
APIStar ✍ ✡ 🇺🇸🏛. 🎏 👨 👈 ✍:
|
|
||||||
|
|
||||||
* ✳ 🎂 🛠️
|
|
||||||
* 💃 (❔ **FastAPI** ⚓️)
|
|
||||||
* Uvicorn (⚙️ 💃 & **FastAPI**)
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | 😮 **FastAPI**
|
|
||||||
|
|
||||||
🔀.
|
|
||||||
|
|
||||||
💭 📣 💗 👜 (💽 🔬, 🛠️ & 🧾) ⏮️ 🎏 🐍 🆎, 👈 🎏 🕰 🚚 👑 👨🎨 🐕🦺, 🕳 👤 🤔 💎 💭.
|
|
||||||
|
|
||||||
& ⏮️ 🔎 📏 🕰 🎏 🛠️ & 🔬 📚 🎏 🎛, APIStar 🏆 🎛 💪.
|
|
||||||
|
|
||||||
⤴️ APIStar ⛔️ 🔀 💽 & 💃 ✍, & 🆕 👻 🏛 ✅ ⚙️. 👈 🏁 🌈 🏗 **FastAPI**.
|
|
||||||
|
|
||||||
👤 🤔 **FastAPI** "🛐 👨💼" APIStar, ⏪ 📉 & 📈 ⚒, ⌨ ⚙️, & 🎏 🍕, ⚓️ 🔛 🏫 ⚪️➡️ 🌐 👉 ⏮️ 🧰.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚙️ **FastAPI**
|
|
||||||
|
|
||||||
### <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a>
|
|
||||||
|
|
||||||
Pydantic 🗃 🔬 💽 🔬, 🛠️ & 🧾 (⚙️ 🎻 🔗) ⚓️ 🔛 🐍 🆎 🔑.
|
|
||||||
|
|
||||||
👈 ⚒ ⚫️ 📶 🏋️.
|
|
||||||
|
|
||||||
⚫️ ⭐ 🍭. 👐 ⚫️ ⏩ 🌘 🍭 📇. & ⚫️ ⚓️ 🔛 🎏 🐍 🆎 🔑, 👨🎨 🐕🦺 👑.
|
|
||||||
|
|
||||||
/// check | **FastAPI** ⚙️ ⚫️
|
|
||||||
|
|
||||||
🍵 🌐 💽 🔬, 💽 🛠️ & 🏧 🏷 🧾 (⚓️ 🔛 🎻 🔗).
|
|
||||||
|
|
||||||
**FastAPI** ⤴️ ✊ 👈 🎻 🔗 💽 & 🚮 ⚫️ 🗄, ↖️ ⚪️➡️ 🌐 🎏 👜 ⚫️ 🔨.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://www.starlette.dev/" class="external-link" target="_blank">💃</a>
|
|
||||||
|
|
||||||
💃 💿 <abbr title="The new standard for building asynchronous Python web">🔫</abbr> 🛠️/🧰, ❔ 💯 🏗 ↕-🎭 ✳ 🐕🦺.
|
|
||||||
|
|
||||||
⚫️ 📶 🙅 & 🏋️. ⚫️ 🔧 💪 🏧, & ✔️ 🔧 🦲.
|
|
||||||
|
|
||||||
⚫️ ✔️:
|
|
||||||
|
|
||||||
* 🤙 🎆 🎭.
|
|
||||||
* *️⃣ 🐕🦺.
|
|
||||||
* -🛠️ 🖥 📋.
|
|
||||||
* 🕴 & 🤫 🎉.
|
|
||||||
* 💯 👩💻 🏗 🔛 🇸🇲.
|
|
||||||
* ⚜, 🗜, 🎻 📁, 🎏 📨.
|
|
||||||
* 🎉 & 🍪 🐕🦺.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 💯 💰.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 🆎 ✍ ✍.
|
|
||||||
* 👩❤👨 🏋️ 🔗.
|
|
||||||
|
|
||||||
💃 ⏳ ⏩ 🐍 🛠️ 💯. 🕴 💥 Uvicorn, ❔ 🚫 🛠️, ✋️ 💽.
|
|
||||||
|
|
||||||
💃 🚚 🌐 🔰 🕸 🕸 🛠️.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🚫 🚚 🏧 💽 🔬, 🛠️ ⚖️ 🧾.
|
|
||||||
|
|
||||||
👈 1️⃣ 👑 👜 👈 **FastAPI** 🚮 🔛 🔝, 🌐 ⚓️ 🔛 🐍 🆎 🔑 (⚙️ Pydantic). 👈, ➕ 🔗 💉 ⚙️, 💂♂ 🚙, 🗄 🔗 ⚡, ♒️.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🔫 🆕 "🐩" ➖ 🛠️ ✳ 🐚 🏉 👨🎓. ⚫️ 🚫 "🐍 🐩" (🇩🇬), 👐 👫 🛠️ 🔨 👈.
|
|
||||||
|
|
||||||
👐, ⚫️ ⏪ ➖ ⚙️ "🐩" 📚 🧰. 👉 📉 📉 🛠️, 👆 💪 🎛 Uvicorn 🙆 🎏 🔫 💽 (💖 👸 ⚖️ Hypercorn), ⚖️ 👆 💪 🚮 🔫 🔗 🧰, 💖 `python-socketio`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check | **FastAPI** ⚙️ ⚫️
|
|
||||||
|
|
||||||
🍵 🌐 🐚 🕸 🍕. ❎ ⚒ 🔛 🔝.
|
|
||||||
|
|
||||||
🎓 `FastAPI` ⚫️ 😖 🔗 ⚪️➡️ 🎓 `Starlette`.
|
|
||||||
|
|
||||||
, 🕳 👈 👆 💪 ⏮️ 💃, 👆 💪 ⚫️ 🔗 ⏮️ **FastAPI**, ⚫️ 🌖 💃 🔛 💊.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### <a href="https://www.uvicorn.dev/" class="external-link" target="_blank">Uvicorn</a>
|
|
||||||
|
|
||||||
Uvicorn 🌩-⏩ 🔫 💽, 🏗 🔛 uvloop & httptool.
|
|
||||||
|
|
||||||
⚫️ 🚫 🕸 🛠️, ✋️ 💽. 🖼, ⚫️ 🚫 🚚 🧰 🕹 ➡. 👈 🕳 👈 🛠️ 💖 💃 (⚖️ **FastAPI**) 🔜 🚚 🔛 🔝.
|
|
||||||
|
|
||||||
⚫️ 👍 💽 💃 & **FastAPI**.
|
|
||||||
|
|
||||||
/// check | **FastAPI** 👍 ⚫️
|
|
||||||
|
|
||||||
👑 🕸 💽 🏃 **FastAPI** 🈸.
|
|
||||||
|
|
||||||
👆 💪 🌀 ⚫️ ⏮️ 🐁, ✔️ 🔁 👁-🛠️ 💽.
|
|
||||||
|
|
||||||
✅ 🌅 ℹ [🛠️](deployment/index.md){.internal-link target=_blank} 📄.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📇 & 🚅
|
|
||||||
|
|
||||||
🤔, 🔬, & 👀 🔺 🖖 Uvicorn, 💃 & FastAPI, ✅ 📄 🔃 [📇](benchmarks.md){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,442 +0,0 @@
|
||||||
# 🛠️ & 🔁 / ⌛
|
|
||||||
|
|
||||||
ℹ 🔃 `async def` ❕ *➡ 🛠️ 🔢* & 🖥 🔃 🔁 📟, 🛠️, & 🔁.
|
|
||||||
|
|
||||||
## 🏃 ❓
|
|
||||||
|
|
||||||
<abbr title="too long; didn't read"><strong>🆑;👩⚕️:</strong></abbr>
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🥉 🥳 🗃 👈 💬 👆 🤙 👫 ⏮️ `await`, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
results = await some_library()
|
|
||||||
```
|
|
||||||
|
|
||||||
⤴️, 📣 👆 *➡ 🛠️ 🔢* ⏮️ `async def` 💖:
|
|
||||||
|
|
||||||
```Python hl_lines="2"
|
|
||||||
@app.get('/')
|
|
||||||
async def read_results():
|
|
||||||
results = await some_library()
|
|
||||||
return results
|
|
||||||
```
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👆 💪 🕴 ⚙️ `await` 🔘 🔢 ✍ ⏮️ `async def`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🥉 🥳 🗃 👈 🔗 ⏮️ 🕳 (💽, 🛠️, 📁 ⚙️, ♒️.) & 🚫 ✔️ 🐕🦺 ⚙️ `await`, (👉 ⏳ 💼 🌅 💽 🗃), ⤴️ 📣 👆 *➡ 🛠️ 🔢* 🛎, ⏮️ `def`, 💖:
|
|
||||||
|
|
||||||
```Python hl_lines="2"
|
|
||||||
@app.get('/')
|
|
||||||
def results():
|
|
||||||
results = some_library()
|
|
||||||
return results
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🚥 👆 🈸 (😫) 🚫 ✔️ 🔗 ⏮️ 🕳 🙆 & ⌛ ⚫️ 📨, ⚙️ `async def`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🚥 👆 🚫 💭, ⚙️ 😐 `def`.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**🗒**: 👆 💪 🌀 `def` & `async def` 👆 *➡ 🛠️ 🔢* 🌅 👆 💪 & 🔬 🔠 1️⃣ ⚙️ 🏆 🎛 👆. FastAPI 🔜 ▶️️ 👜 ⏮️ 👫.
|
|
||||||
|
|
||||||
😆, 🙆 💼 🔛, FastAPI 🔜 👷 🔁 & 📶 ⏩.
|
|
||||||
|
|
||||||
✋️ 📄 📶 🔛, ⚫️ 🔜 💪 🎭 🛠️.
|
|
||||||
|
|
||||||
## 📡 ℹ
|
|
||||||
|
|
||||||
🏛 ⏬ 🐍 ✔️ 🐕🦺 **"🔁 📟"** ⚙️ 🕳 🤙 **"🔁"**, ⏮️ **`async` & `await`** ❕.
|
|
||||||
|
|
||||||
➡️ 👀 👈 🔤 🍕 📄 🔛:
|
|
||||||
|
|
||||||
* **🔁 📟**
|
|
||||||
* **`async` & `await`**
|
|
||||||
* **🔁**
|
|
||||||
|
|
||||||
## 🔁 📟
|
|
||||||
|
|
||||||
🔁 📟 ⛓ 👈 🇪🇸 👶 ✔️ 🌌 💬 💻 / 📋 👶 👈 ☝ 📟, ⚫️ 👶 🔜 ✔️ ⌛ *🕳 🙆* 🏁 👱 🙆. ➡️ 💬 👈 *🕳 🙆* 🤙 "🐌-📁" 👶.
|
|
||||||
|
|
||||||
, ⏮️ 👈 🕰, 💻 💪 🚶 & 🎏 👷, ⏪ "🐌-📁" 👶 🏁.
|
|
||||||
|
|
||||||
⤴️ 💻 / 📋 👶 🔜 👟 🔙 🔠 🕰 ⚫️ ✔️ 🤞 ↩️ ⚫️ ⌛ 🔄, ⚖️ 🕐❔ ⚫️ 👶 🏁 🌐 👷 ⚫️ ✔️ 👈 ☝. & ⚫️ 👶 🔜 👀 🚥 🙆 📋 ⚫️ ⌛ ✔️ ⏪ 🏁, 🤸 ⚫️❔ ⚫️ ✔️.
|
|
||||||
|
|
||||||
⏭, ⚫️ 👶 ✊ 🥇 📋 🏁 (➡️ 💬, 👆 "🐌-📁" 👶) & 😣 ⚫️❔ ⚫️ ✔️ ⏮️ ⚫️.
|
|
||||||
|
|
||||||
👈 "⌛ 🕳 🙆" 🛎 🔗 <abbr title="Input and Output">👤/🅾</abbr> 🛠️ 👈 📶 "🐌" (🔬 🚅 🕹 & 💾 💾), 💖 ⌛:
|
|
||||||
|
|
||||||
* 📊 ⚪️➡️ 👩💻 📨 🔘 🕸
|
|
||||||
* 📊 📨 👆 📋 📨 👩💻 🔘 🕸
|
|
||||||
* 🎚 📁 💾 ✍ ⚙️ & 🤝 👆 📋
|
|
||||||
* 🎚 👆 📋 🤝 ⚙️ ✍ 💾
|
|
||||||
* 🛰 🛠️ 🛠️
|
|
||||||
* 💽 🛠️ 🏁
|
|
||||||
* 💽 🔢 📨 🏁
|
|
||||||
* ♒️.
|
|
||||||
|
|
||||||
🛠️ 🕰 🍴 ✴️ ⌛ <abbr title="Input and Output">👤/🅾</abbr> 🛠️, 👫 🤙 👫 "👤/🅾 🔗" 🛠️.
|
|
||||||
|
|
||||||
⚫️ 🤙 "🔁" ↩️ 💻 / 📋 🚫 ✔️ "🔁" ⏮️ 🐌 📋, ⌛ ☑ 🙍 👈 📋 🏁, ⏪ 🔨 🕳, 💪 ✊ 📋 🏁 & 😣 👷.
|
|
||||||
|
|
||||||
↩️ 👈, 💆♂ "🔁" ⚙️, 🕐 🏁, 📋 💪 ⌛ ⏸ 🐥 👄 (⏲) 💻 / 📋 🏁 ⚫️❔ ⚫️ 🚶, & ⤴️ 👟 🔙 ✊ 🏁 & 😣 👷 ⏮️ 👫.
|
|
||||||
|
|
||||||
"🔁" (👽 "🔁") 👫 🛎 ⚙️ ⚖ "🔁", ↩️ 💻 / 📋 ⏩ 🌐 📶 🔁 ⏭ 🔀 🎏 📋, 🚥 👈 🔁 🔌 ⌛.
|
|
||||||
|
|
||||||
### 🛠️ & 🍔
|
|
||||||
|
|
||||||
👉 💭 **🔁** 📟 🔬 🔛 🕣 🤙 **"🛠️"**. ⚫️ 🎏 ⚪️➡️ **"🔁"**.
|
|
||||||
|
|
||||||
**🛠️** & **🔁** 👯♂️ 🔗 "🎏 👜 😥 🌅 ⚖️ 🌘 🎏 🕰".
|
|
||||||
|
|
||||||
✋️ ℹ 🖖 *🛠️* & *🔁* 🎏.
|
|
||||||
|
|
||||||
👀 🔺, 🌈 📄 📖 🔃 🍔:
|
|
||||||
|
|
||||||
### 🛠️ 🍔
|
|
||||||
|
|
||||||
👆 🚶 ⏮️ 👆 🥰 🤚 ⏩ 🥕, 👆 🧍 ⏸ ⏪ 🏧 ✊ ✔ ⚪️➡️ 👫👫 🚪 👆. 👶
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-01.png" class="illustration">
|
|
||||||
|
|
||||||
⤴️ ⚫️ 👆 🔄, 👆 🥉 👆 ✔ 2️⃣ 📶 🎀 🍔 👆 🥰 & 👆. 👶 👶
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-02.png" class="illustration">
|
|
||||||
|
|
||||||
🏧 💬 🕳 🍳 👨🍳 👫 💭 👫 ✔️ 🏗 👆 🍔 (✋️ 👫 ⏳ 🏗 🕐 ⏮️ 👩💻).
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-03.png" class="illustration">
|
|
||||||
|
|
||||||
👆 💸. 👶
|
|
||||||
|
|
||||||
🏧 🤝 👆 🔢 👆 🔄.
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-04.png" class="illustration">
|
|
||||||
|
|
||||||
⏪ 👆 ⌛, 👆 🚶 ⏮️ 👆 🥰 & ⚒ 🏓, 👆 🧎 & 💬 ⏮️ 👆 🥰 📏 🕰 (👆 🍔 📶 🎀 & ✊ 🕰 🏗).
|
|
||||||
|
|
||||||
👆 🏖 🏓 ⏮️ 👆 🥰, ⏪ 👆 ⌛ 🍔, 👆 💪 💸 👈 🕰 😮 ❔ 👌, 🐨 & 🙃 👆 🥰 👶 👶 👶.
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-05.png" class="illustration">
|
|
||||||
|
|
||||||
⏪ ⌛ & 💬 👆 🥰, ⚪️➡️ 🕰 🕰, 👆 ✅ 🔢 🖥 🔛 ⏲ 👀 🚥 ⚫️ 👆 🔄 ⏪.
|
|
||||||
|
|
||||||
⤴️ ☝, ⚫️ 😒 👆 🔄. 👆 🚶 ⏲, 🤚 👆 🍔 & 👟 🔙 🏓.
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-06.png" class="illustration">
|
|
||||||
|
|
||||||
👆 & 👆 🥰 🍴 🍔 & ✔️ 👌 🕰. 👶
|
|
||||||
|
|
||||||
<img src="/img/async/concurrent-burgers/concurrent-burgers-07.png" class="illustration">
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🌹 🖼 <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">👯 🍏</a>. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🌈 👆 💻 / 📋 👶 👈 📖.
|
|
||||||
|
|
||||||
⏪ 👆 ⏸, 👆 ⛽ 👶, ⌛ 👆 🔄, 🚫 🔨 🕳 📶 "😌". ✋️ ⏸ ⏩ ↩️ 🏧 🕴 ✊ ✔ (🚫 🏗 👫), 👈 👌.
|
|
||||||
|
|
||||||
⤴️, 🕐❔ ⚫️ 👆 🔄, 👆 ☑ "😌" 👷, 👆 🛠️ 🍣, 💭 ⚫️❔ 👆 💚, 🤚 👆 🥰 ⚒, 💸, ✅ 👈 👆 🤝 ☑ 💵 ⚖️ 💳, ✅ 👈 👆 🈚 ☑, ✅ 👈 ✔ ✔️ ☑ 🏬, ♒️.
|
|
||||||
|
|
||||||
✋️ ⤴️, ✋️ 👆 🚫 ✔️ 👆 🍔, 👆 👷 ⏮️ 🏧 "🔛 ⏸" ⏸, ↩️ 👆 ✔️ ⌛ 👶 👆 🍔 🔜.
|
|
||||||
|
|
||||||
✋️ 👆 🚶 ↖️ ⚪️➡️ ⏲ & 🧎 🏓 ⏮️ 🔢 👆 🔄, 👆 💪 🎛 👶 👆 🙋 👆 🥰, & "👷" 👶 👶 🔛 👈. ⤴️ 👆 🔄 🔨 🕳 📶 "😌" 😏 ⏮️ 👆 🥰 👶.
|
|
||||||
|
|
||||||
⤴️ 🏧 👶 💬 "👤 🏁 ⏮️ 🔨 🍔" 🚮 👆 🔢 🔛 ⏲ 🖥, ✋️ 👆 🚫 🦘 💖 😜 ⏪ 🕐❔ 🖥 🔢 🔀 👆 🔄 🔢. 👆 💭 🙅♂ 1️⃣ 🔜 📎 👆 🍔 ↩️ 👆 ✔️ 🔢 👆 🔄, & 👫 ✔️ 👫.
|
|
||||||
|
|
||||||
👆 ⌛ 👆 🥰 🏁 📖 (🏁 ⏮️ 👷 👶 / 📋 ➖ 🛠️ 👶), 😀 🖐 & 💬 👈 👆 🔜 🍔 ⏸.
|
|
||||||
|
|
||||||
⤴️ 👆 🚶 ⏲ 👶, ▶️ 📋 👈 🔜 🏁 👶, ⚒ 🍔, 💬 👏 & ✊ 👫 🏓. 👈 🏁 👈 🔁 / 📋 🔗 ⏮️ ⏲ ⏹. 👈 🔄, ✍ 🆕 📋, "🍴 🍔" 👶 👶, ✋️ ⏮️ 1️⃣ "🤚 🍔" 🏁 ⏹.
|
|
||||||
|
|
||||||
### 🔗 🍔
|
|
||||||
|
|
||||||
🔜 ➡️ 🌈 👫 ➖🚫 🚫 "🛠️ 🍔", ✋️ "🔗 🍔".
|
|
||||||
|
|
||||||
👆 🚶 ⏮️ 👆 🥰 🤚 🔗 ⏩ 🥕.
|
|
||||||
|
|
||||||
👆 🧍 ⏸ ⏪ 📚 (➡️ 💬 8️⃣) 🏧 👈 🎏 🕰 🍳 ✊ ✔ ⚪️➡️ 👫👫 🚪 👆.
|
|
||||||
|
|
||||||
👱 ⏭ 👆 ⌛ 👫 🍔 🔜 ⏭ 🍂 ⏲ ↩️ 🔠 8️⃣ 🏧 🚶 & 🏗 🍔 ▶️️ ↖️ ⏭ 💆♂ ⏭ ✔.
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-01.png" class="illustration">
|
|
||||||
|
|
||||||
⤴️ ⚫️ 😒 👆 🔄, 👆 🥉 👆 ✔ 2️⃣ 📶 🎀 🍔 👆 🥰 & 👆.
|
|
||||||
|
|
||||||
👆 💸 👶.
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-02.png" class="illustration">
|
|
||||||
|
|
||||||
🏧 🚶 👨🍳.
|
|
||||||
|
|
||||||
👆 ⌛, 🧍 🚪 ⏲ 👶, 👈 🙅♂ 1️⃣ 🙆 ✊ 👆 🍔 ⏭ 👆, 📤 🙅♂ 🔢 🔄.
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-03.png" class="illustration">
|
|
||||||
|
|
||||||
👆 & 👆 🥰 😩 🚫 ➡️ 🙆 🤚 🚪 👆 & ✊ 👆 🍔 🕐❔ 👫 🛬, 👆 🚫🔜 💸 🙋 👆 🥰. 👶
|
|
||||||
|
|
||||||
👉 "🔁" 👷, 👆 "🔁" ⏮️ 🏧/🍳 👶 👶. 👆 ✔️ ⌛ 👶 & 📤 ☑ 🙍 👈 🏧/🍳 👶 👶 🏁 🍔 & 🤝 👫 👆, ⚖️ ⏪, 👱 🙆 💪 ✊ 👫.
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-04.png" class="illustration">
|
|
||||||
|
|
||||||
⤴️ 👆 🏧/🍳 👶 👶 😒 👟 🔙 ⏮️ 👆 🍔, ⏮️ 📏 🕰 ⌛ 👶 📤 🚪 ⏲.
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-05.png" class="illustration">
|
|
||||||
|
|
||||||
👆 ✊ 👆 🍔 & 🚶 🏓 ⏮️ 👆 🥰.
|
|
||||||
|
|
||||||
👆 🍴 👫, & 👆 🔨. ⏹
|
|
||||||
|
|
||||||
<img src="/img/async/parallel-burgers/parallel-burgers-06.png" class="illustration">
|
|
||||||
|
|
||||||
📤 🚫 🌅 💬 ⚖️ 😏 🌅 🕰 💸 ⌛ 👶 🚪 ⏲. 👶
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🌹 🖼 <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">👯 🍏</a>. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👉 😐 🔗 🍔, 👆 💻 / 📋 👶 ⏮️ 2️⃣ 🕹 (👆 & 👆 🥰), 👯♂️ ⌛ 👶 & 💡 👫 🙋 👶 "⌛ 🔛 ⏲" 👶 📏 🕰.
|
|
||||||
|
|
||||||
⏩ 🥕 🏪 ✔️ 8️⃣ 🕹 (🏧/🍳). ⏪ 🛠️ 🍔 🏪 💪 ✔️ ✔️ 🕴 2️⃣ (1️⃣ 🏧 & 1️⃣ 🍳).
|
|
||||||
|
|
||||||
✋️, 🏁 💡 🚫 🏆. 👶
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👉 🔜 🔗 🌓 📖 🍔. 👶
|
|
||||||
|
|
||||||
🌅 "🎰 👨❤👨" 🖼 👉, 🌈 🏦.
|
|
||||||
|
|
||||||
🆙 ⏳, 🏆 🏦 ✔️ 💗 🏧 👶 👶 👶 👶 👶 👶 👶 👶 & 🦏 ⏸ 👶 👶 👶 👶 👶 👶 👶 👶.
|
|
||||||
|
|
||||||
🌐 🏧 🔨 🌐 👷 ⏮️ 1️⃣ 👩💻 ⏮️ 🎏 👶 👶 👶.
|
|
||||||
|
|
||||||
& 👆 ✔️ ⌛ 👶 ⏸ 📏 🕰 ⚖️ 👆 💸 👆 🔄.
|
|
||||||
|
|
||||||
👆 🎲 🚫🔜 💚 ✊ 👆 🥰 👶 ⏮️ 👆 👷 🏦 👶.
|
|
||||||
|
|
||||||
### 🍔 🏁
|
|
||||||
|
|
||||||
👉 😐 "⏩ 🥕 🍔 ⏮️ 👆 🥰", 📤 📚 ⌛ 👶, ⚫️ ⚒ 📚 🌅 🔑 ✔️ 🛠️ ⚙️ ⏸ 👶 👶.
|
|
||||||
|
|
||||||
👉 💼 🌅 🕸 🈸.
|
|
||||||
|
|
||||||
📚, 📚 👩💻, ✋️ 👆 💽 ⌛ 👶 👫 🚫--👍 🔗 📨 👫 📨.
|
|
||||||
|
|
||||||
& ⤴️ ⌛ 👶 🔄 📨 👟 🔙.
|
|
||||||
|
|
||||||
👉 "⌛" 👶 ⚖ ⏲, ✋️, ⚖ ⚫️ 🌐, ⚫️ 📚 ⌛ 🔚.
|
|
||||||
|
|
||||||
👈 ⚫️❔ ⚫️ ⚒ 📚 🔑 ⚙️ 🔁 ⏸ 👶 👶 📟 🕸 🔗.
|
|
||||||
|
|
||||||
👉 😇 🔀 ⚫️❔ ⚒ ✳ 🌟 (✋️ ✳ 🚫 🔗) & 👈 💪 🚶 🛠️ 🇪🇸.
|
|
||||||
|
|
||||||
& 👈 🎏 🎚 🎭 👆 🤚 ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
& 👆 💪 ✔️ 🔁 & 🔀 🎏 🕰, 👆 🤚 ↕ 🎭 🌘 🌅 💯 ✳ 🛠️ & 🔛 🇷🇪 ⏮️ 🚶, ❔ ✍ 🇪🇸 🔐 🅱 <a href="https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=query&l=zijmkf-1" class="external-link" target="_blank">(🌐 👏 💃)</a>.
|
|
||||||
|
|
||||||
### 🛠️ 👍 🌘 🔁 ❓
|
|
||||||
|
|
||||||
😆 ❗ 👈 🚫 🛐 📖.
|
|
||||||
|
|
||||||
🛠️ 🎏 🌘 🔁. & ⚫️ 👻 🔛 **🎯** 😐 👈 🔌 📚 ⌛. ↩️ 👈, ⚫️ 🛎 📚 👍 🌘 🔁 🕸 🈸 🛠️. ✋️ 🚫 🌐.
|
|
||||||
|
|
||||||
, ⚖ 👈 👅, 🌈 📄 📏 📖:
|
|
||||||
|
|
||||||
> 👆 ✔️ 🧹 🦏, 💩 🏠.
|
|
||||||
|
|
||||||
*😆, 👈 🎂 📖*.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
📤 🙅♂ ⌛ 👶 🙆, 📚 👷 🔨, 🔛 💗 🥉 🏠.
|
|
||||||
|
|
||||||
👆 💪 ✔️ 🔄 🍔 🖼, 🥇 🏠 🧖♂, ⤴️ 👨🍳, ✋️ 👆 🚫 ⌛ 👶 🕳, 🧹 & 🧹, 🔄 🚫🔜 📉 🕳.
|
|
||||||
|
|
||||||
⚫️ 🔜 ✊ 🎏 💸 🕰 🏁 ⏮️ ⚖️ 🍵 🔄 (🛠️) & 👆 🔜 ✔️ ⌛ 🎏 💸 👷.
|
|
||||||
|
|
||||||
✋️ 👉 💼, 🚥 👆 💪 ✊️ 8️⃣ 👰-🏧/🍳/🔜-🧹, & 🔠 1️⃣ 👫 (➕ 👆) 💪 ✊ 🏒 🏠 🧹 ⚫️, 👆 💪 🌐 👷 **🔗**, ⏮️ ➕ ℹ, & 🏁 🌅 🔜.
|
|
||||||
|
|
||||||
👉 😐, 🔠 1️⃣ 🧹 (🔌 👆) 🔜 🕹, 🤸 👫 🍕 👨🏭.
|
|
||||||
|
|
||||||
& 🏆 🛠️ 🕰 ✊ ☑ 👷 (↩️ ⌛), & 👷 💻 ⌛ <abbr title="Central Processing Unit">💽</abbr>, 👫 🤙 👫 ⚠ "💽 🎁".
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
⚠ 🖼 💽 🔗 🛠️ 👜 👈 🚚 🏗 🧪 🏭.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
* **🎧** ⚖️ **🖼 🏭**.
|
|
||||||
* **💻 👓**: 🖼 ✍ 💯 🔅, 🔠 🔅 ✔️ 3️⃣ 💲 / 🎨, 🏭 👈 🛎 🚚 💻 🕳 🔛 📚 🔅, 🌐 🎏 🕰.
|
|
||||||
* **🎰 🏫**: ⚫️ 🛎 🚚 📚 "✖" & "🖼" ✖. 💭 🦏 📋 ⏮️ 🔢 & ✖ 🌐 👫 👯♂️ 🎏 🕰.
|
|
||||||
* **⏬ 🏫**: 👉 🎧-🏑 🎰 🏫,, 🎏 ✔. ⚫️ 👈 📤 🚫 👁 📋 🔢 ✖, ✋️ 🦏 ⚒ 👫, & 📚 💼, 👆 ⚙️ 🎁 🕹 🏗 & / ⚖️ ⚙️ 👈 🏷.
|
|
||||||
|
|
||||||
### 🛠️ ➕ 🔁: 🕸 ➕ 🎰 🏫
|
|
||||||
|
|
||||||
⏮️ **FastAPI** 👆 💪 ✊ 📈 🛠️ 👈 📶 ⚠ 🕸 🛠️ (🎏 👑 🧲 ✳).
|
|
||||||
|
|
||||||
✋️ 👆 💪 🐄 💰 🔁 & 💾 (✔️ 💗 🛠️ 🏃♂ 🔗) **💽 🎁** ⚖ 💖 👈 🎰 🏫 ⚙️.
|
|
||||||
|
|
||||||
👈, ➕ 🙅 👐 👈 🐍 👑 🇪🇸 **💽 🧪**, 🎰 🏫 & ✴️ ⏬ 🏫, ⚒ FastAPI 📶 👍 🏏 💽 🧪 / 🎰 🏫 🕸 🔗 & 🈸 (👪 📚 🎏).
|
|
||||||
|
|
||||||
👀 ❔ 🏆 👉 🔁 🏭 👀 📄 🔃 [🛠️](deployment/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
## `async` & `await`
|
|
||||||
|
|
||||||
🏛 ⏬ 🐍 ✔️ 📶 🏋️ 🌌 🔬 🔁 📟. 👉 ⚒ ⚫️ 👀 💖 😐 "🔁" 📟 & "⌛" 👆 ▶️️ 🙍.
|
|
||||||
|
|
||||||
🕐❔ 📤 🛠️ 👈 🔜 🚚 ⌛ ⏭ 🤝 🏁 & ✔️ 🐕🦺 👉 🆕 🐍 ⚒, 👆 💪 📟 ⚫️ 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
burgers = await get_burgers(2)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔑 📥 `await`. ⚫️ 💬 🐍 👈 ⚫️ ✔️ ⌛ ⏸ `get_burgers(2)` 🏁 🔨 🚮 👜 👶 ⏭ ♻ 🏁 `burgers`. ⏮️ 👈, 🐍 🔜 💭 👈 ⚫️ 💪 🚶 & 🕳 🙆 👶 👶 👐 (💖 📨 ➕1️⃣ 📨).
|
|
||||||
|
|
||||||
`await` 👷, ⚫️ ✔️ 🔘 🔢 👈 🐕🦺 👉 🔀. 👈, 👆 📣 ⚫️ ⏮️ `async def`:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
async def get_burgers(number: int):
|
|
||||||
# Do some asynchronous stuff to create the burgers
|
|
||||||
return burgers
|
|
||||||
```
|
|
||||||
|
|
||||||
...↩️ `def`:
|
|
||||||
|
|
||||||
```Python hl_lines="2"
|
|
||||||
# This is not asynchronous
|
|
||||||
def get_sequential_burgers(number: int):
|
|
||||||
# Do some sequential stuff to create the burgers
|
|
||||||
return burgers
|
|
||||||
```
|
|
||||||
|
|
||||||
⏮️ `async def`, 🐍 💭 👈, 🔘 👈 🔢, ⚫️ ✔️ 🤔 `await` 🧬, & 👈 ⚫️ 💪 "⏸" ⏸ 🛠️ 👈 🔢 & 🚶 🕳 🙆 👶 ⏭ 👟 🔙.
|
|
||||||
|
|
||||||
🕐❔ 👆 💚 🤙 `async def` 🔢, 👆 ✔️ "⌛" ⚫️. , 👉 🏆 🚫 👷:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
# This won't work, because get_burgers was defined with: async def
|
|
||||||
burgers = get_burgers(2)
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
, 🚥 👆 ⚙️ 🗃 👈 💬 👆 👈 👆 💪 🤙 ⚫️ ⏮️ `await`, 👆 💪 ✍ *➡ 🛠️ 🔢* 👈 ⚙️ ⚫️ ⏮️ `async def`, 💖:
|
|
||||||
|
|
||||||
```Python hl_lines="2-3"
|
|
||||||
@app.get('/burgers')
|
|
||||||
async def read_burgers():
|
|
||||||
burgers = await get_burgers(2)
|
|
||||||
return burgers
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🌅 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ✔️ 👀 👈 `await` 💪 🕴 ⚙️ 🔘 🔢 🔬 ⏮️ `async def`.
|
|
||||||
|
|
||||||
✋️ 🎏 🕰, 🔢 🔬 ⏮️ `async def` ✔️ "⌛". , 🔢 ⏮️ `async def` 💪 🕴 🤙 🔘 🔢 🔬 ⏮️ `async def` 💁♂️.
|
|
||||||
|
|
||||||
, 🔃 🥚 & 🐔, ❔ 👆 🤙 🥇 `async` 🔢 ❓
|
|
||||||
|
|
||||||
🚥 👆 👷 ⏮️ **FastAPI** 👆 🚫 ✔️ 😟 🔃 👈, ↩️ 👈 "🥇" 🔢 🔜 👆 *➡ 🛠️ 🔢*, & FastAPI 🔜 💭 ❔ ▶️️ 👜.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 💚 ⚙️ `async` / `await` 🍵 FastAPI, 👆 💪 ⚫️ 👍.
|
|
||||||
|
|
||||||
### ✍ 👆 👍 🔁 📟
|
|
||||||
|
|
||||||
💃 (& **FastAPI**) ⚓️ 🔛 <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a>, ❔ ⚒ ⚫️ 🔗 ⏮️ 👯♂️ 🐍 🐩 🗃 <a href="https://docs.python.org/3/library/asyncio-task.html" class="external-link" target="_blank">✳</a> & <a href="https://trio.readthedocs.io/en/stable/" class="external-link" target="_blank">🎻</a>.
|
|
||||||
|
|
||||||
🎯, 👆 💪 🔗 ⚙️ <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a> 👆 🏧 🛠️ ⚙️ 💼 👈 🚚 🌅 🏧 ⚓ 👆 👍 📟.
|
|
||||||
|
|
||||||
& 🚥 👆 🚫 ⚙️ FastAPI, 👆 💪 ✍ 👆 👍 🔁 🈸 ⏮️ <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a> 🏆 🔗 & 🤚 🚮 💰 (✅ *📊 🛠️*).
|
|
||||||
|
|
||||||
### 🎏 📨 🔁 📟
|
|
||||||
|
|
||||||
👉 👗 ⚙️ `async` & `await` 📶 🆕 🇪🇸.
|
|
||||||
|
|
||||||
✋️ ⚫️ ⚒ 👷 ⏮️ 🔁 📟 📚 ⏩.
|
|
||||||
|
|
||||||
👉 🎏 ❕ (⚖️ 🌖 🌓) 🔌 ⏳ 🏛 ⏬ 🕸 (🖥 & ✳).
|
|
||||||
|
|
||||||
✋️ ⏭ 👈, 🚚 🔁 📟 🌖 🏗 & ⚠.
|
|
||||||
|
|
||||||
⏮️ ⏬ 🐍, 👆 💪 ✔️ ⚙️ 🧵 ⚖️ <a href="https://www.gevent.org/" class="external-link" target="_blank">🐁</a>. ✋️ 📟 🌌 🌖 🏗 🤔, ℹ, & 💭 🔃.
|
|
||||||
|
|
||||||
⏮️ ⏬ ✳ / 🖥 🕸, 👆 🔜 ✔️ ⚙️ "⏲". ❔ ↘️ "⏲ 🔥😈".
|
|
||||||
|
|
||||||
## 🔁
|
|
||||||
|
|
||||||
**🔁** 📶 🎀 ⚖ 👜 📨 `async def` 🔢. 🐍 💭 👈 ⚫️ 🕳 💖 🔢 👈 ⚫️ 💪 ▶️ & 👈 ⚫️ 🔜 🔚 ☝, ✋️ 👈 ⚫️ 5️⃣📆 ⏸ ⏸ 🔘 💁♂️, 🕐❔ 📤 `await` 🔘 ⚫️.
|
|
||||||
|
|
||||||
✋️ 🌐 👉 🛠️ ⚙️ 🔁 📟 ⏮️ `async` & `await` 📚 🕰 🔬 ⚙️ "🔁". ⚫️ ⭐ 👑 🔑 ⚒ 🚶, "🔁".
|
|
||||||
|
|
||||||
## 🏁
|
|
||||||
|
|
||||||
➡️ 👀 🎏 🔤 ⚪️➡️ 🔛:
|
|
||||||
|
|
||||||
> 🏛 ⏬ 🐍 ✔️ 🐕🦺 **"🔁 📟"** ⚙️ 🕳 🤙 **"🔁"**, ⏮️ **`async` & `await`** ❕.
|
|
||||||
|
|
||||||
👈 🔜 ⚒ 🌅 🔑 🔜. 👶
|
|
||||||
|
|
||||||
🌐 👈 ⚫️❔ 🏋️ FastAPI (🔘 💃) & ⚫️❔ ⚒ ⚫️ ✔️ ✅ 🎆 🎭.
|
|
||||||
|
|
||||||
## 📶 📡 ℹ
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👆 💪 🎲 🚶 👉.
|
|
||||||
|
|
||||||
👉 📶 📡 ℹ ❔ **FastAPI** 👷 🔘.
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 📡 💡 (🈶-🏋, 🧵, 🍫, ♒️.) & 😟 🔃 ❔ FastAPI 🍵 `async def` 🆚 😐 `def`, 🚶 ⤴️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ➡ 🛠️ 🔢
|
|
||||||
|
|
||||||
🕐❔ 👆 📣 *➡ 🛠️ 🔢* ⏮️ 😐 `def` ↩️ `async def`, ⚫️ 🏃 🔢 🧵 👈 ⤴️ ⌛, ↩️ ➖ 🤙 🔗 (⚫️ 🔜 🍫 💽).
|
|
||||||
|
|
||||||
🚥 👆 👟 ⚪️➡️ ➕1️⃣ 🔁 🛠️ 👈 🔨 🚫 👷 🌌 🔬 🔛 & 👆 ⚙️ ⚖ 🙃 📊-🕴 *➡ 🛠️ 🔢* ⏮️ ✅ `def` 🤪 🎭 📈 (🔃 1️⃣0️⃣0️⃣ 💓), 🙏 🗒 👈 **FastAPI** ⭐ 🔜 🔄. 👫 💼, ⚫️ 👻 ⚙️ `async def` 🚥 👆 *➡ 🛠️ 🔢* ⚙️ 📟 👈 🎭 🚧 <abbr title="Input/Output: disk reading or writing, network communications.">👤/🅾</abbr>.
|
|
||||||
|
|
||||||
, 👯♂️ ⚠, 🤞 👈 **FastAPI** 🔜 [⏩](index.md#_15){.internal-link target=_blank} 🌘 (⚖️ 🌘 ⭐) 👆 ⏮️ 🛠️.
|
|
||||||
|
|
||||||
### 🔗
|
|
||||||
|
|
||||||
🎏 ✔ [🔗](tutorial/dependencies/index.md){.internal-link target=_blank}. 🚥 🔗 🐩 `def` 🔢 ↩️ `async def`, ⚫️ 🏃 🔢 🧵.
|
|
||||||
|
|
||||||
### 🎧-🔗
|
|
||||||
|
|
||||||
👆 💪 ✔️ 💗 🔗 & [🎧-🔗](tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} 🚫 🔠 🎏 (🔢 🔢 🔑), 👫 💪 ✍ ⏮️ `async def` & ⏮️ 😐 `def`. ⚫️ 🔜 👷, & 🕐 ✍ ⏮️ 😐 `def` 🔜 🤙 🔛 🔢 🧵 (⚪️➡️ 🧵) ↩️ ➖ "⌛".
|
|
||||||
|
|
||||||
### 🎏 🚙 🔢
|
|
||||||
|
|
||||||
🙆 🎏 🚙 🔢 👈 👆 🤙 🔗 💪 ✍ ⏮️ 😐 `def` ⚖️ `async def` & FastAPI 🏆 🚫 📉 🌌 👆 🤙 ⚫️.
|
|
||||||
|
|
||||||
👉 🔅 🔢 👈 FastAPI 🤙 👆: *➡ 🛠️ 🔢* & 🔗.
|
|
||||||
|
|
||||||
🚥 👆 🚙 🔢 😐 🔢 ⏮️ `def`, ⚫️ 🔜 🤙 🔗 (👆 ✍ ⚫️ 👆 📟), 🚫 🧵, 🚥 🔢 ✍ ⏮️ `async def` ⤴️ 👆 🔜 `await` 👈 🔢 🕐❔ 👆 🤙 ⚫️ 👆 📟.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🔄, 👉 📶 📡 ℹ 👈 🔜 🎲 ⚠ 🚥 👆 👟 🔎 👫.
|
|
||||||
|
|
||||||
⏪, 👆 🔜 👍 ⏮️ 📄 ⚪️➡️ 📄 🔛: <a href="#_2">🏃 ❓</a>.
|
|
||||||
|
|
@ -1,34 +0,0 @@
|
||||||
# 📇
|
|
||||||
|
|
||||||
🔬 🇸🇲 📇 🎦 **FastAPI** 🈸 🏃♂ 🔽 Uvicorn <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">1️⃣ ⏩ 🐍 🛠️ 💪</a>, 🕴 🔛 💃 & Uvicorn 👫 (⚙️ 🔘 FastAPI). (*)
|
|
||||||
|
|
||||||
✋️ 🕐❔ ✅ 📇 & 🔺 👆 🔜 ✔️ 📄 🤯.
|
|
||||||
|
|
||||||
## 📇 & 🚅
|
|
||||||
|
|
||||||
🕐❔ 👆 ✅ 📇, ⚫️ ⚠ 👀 📚 🧰 🎏 🆎 🔬 🌓.
|
|
||||||
|
|
||||||
🎯, 👀 Uvicorn, 💃 & FastAPI 🔬 👯♂️ (👪 📚 🎏 🧰).
|
|
||||||
|
|
||||||
🙅 ⚠ ❎ 🧰, 👍 🎭 ⚫️ 🔜 🤚. & 🏆 📇 🚫 💯 🌖 ⚒ 🚚 🧰.
|
|
||||||
|
|
||||||
🔗 💖:
|
|
||||||
|
|
||||||
* **Uvicorn**: 🔫 💽
|
|
||||||
* **💃**: (⚙️ Uvicorn) 🕸 🕸
|
|
||||||
* **FastAPI**: (⚙️ 💃) 🛠️ 🕸 ⏮️ 📚 🌖 ⚒ 🏗 🔗, ⏮️ 💽 🔬, ♒️.
|
|
||||||
|
|
||||||
* **Uvicorn**:
|
|
||||||
* 🔜 ✔️ 🏆 🎭, ⚫️ 🚫 ✔️ 🌅 ➕ 📟 ↖️ ⚪️➡️ 💽 ⚫️.
|
|
||||||
* 👆 🚫🔜 ✍ 🈸 Uvicorn 🔗. 👈 🔜 ⛓ 👈 👆 📟 🔜 ✔️ 🔌 🌖 ⚖️ 🌘, 🌘, 🌐 📟 🚚 💃 (⚖️ **FastAPI**). & 🚥 👆 👈, 👆 🏁 🈸 🔜 ✔️ 🎏 🌥 ✔️ ⚙️ 🛠️ & 📉 👆 📱 📟 & 🐛.
|
|
||||||
* 🚥 👆 ⚖ Uvicorn, 🔬 ⚫️ 🛡 👸, Hypercorn, ✳, ♒️. 🈸 💽.
|
|
||||||
* **💃**:
|
|
||||||
* 🔜 ✔️ ⏭ 🏆 🎭, ⏮️ Uvicorn. 👐, 💃 ⚙️ Uvicorn 🏃. , ⚫️ 🎲 💪 🕴 🤚 "🐌" 🌘 Uvicorn ✔️ 🛠️ 🌅 📟.
|
|
||||||
* ✋️ ⚫️ 🚚 👆 🧰 🏗 🙅 🕸 🈸, ⏮️ 🕹 ⚓️ 🔛 ➡, ♒️.
|
|
||||||
* 🚥 👆 ⚖ 💃, 🔬 ⚫️ 🛡 🤣, 🏺, ✳, ♒️. 🕸 🛠️ (⚖️ 🕸).
|
|
||||||
* **FastAPI**:
|
|
||||||
* 🎏 🌌 👈 💃 ⚙️ Uvicorn & 🚫🔜 ⏩ 🌘 ⚫️, **FastAPI** ⚙️ 💃, ⚫️ 🚫🔜 ⏩ 🌘 ⚫️.
|
|
||||||
* FastAPI 🚚 🌅 ⚒ 🔛 🔝 💃. ⚒ 👈 👆 🌖 🕧 💪 🕐❔ 🏗 🔗, 💖 💽 🔬 & 🛠️. & ⚙️ ⚫️, 👆 🤚 🏧 🧾 🆓 (🏧 🧾 🚫 🚮 🌥 🏃♂ 🈸, ⚫️ 🏗 🔛 🕴).
|
|
||||||
* 🚥 👆 🚫 ⚙️ FastAPI & ⚙️ 💃 🔗 (⚖️ ➕1️⃣ 🧰, 💖 🤣, 🏺, 🆘, ♒️) 👆 🔜 ✔️ 🛠️ 🌐 💽 🔬 & 🛠️ 👆. , 👆 🏁 🈸 🔜 ✔️ 🎏 🌥 🚥 ⚫️ 🏗 ⚙️ FastAPI. & 📚 💼, 👉 💽 🔬 & 🛠️ 🦏 💸 📟 ✍ 🈸.
|
|
||||||
* , ⚙️ FastAPI 👆 ♻ 🛠️ 🕰, 🐛, ⏸ 📟, & 👆 🔜 🎲 🤚 🎏 🎭 (⚖️ 👍) 👆 🔜 🚥 👆 🚫 ⚙️ ⚫️ (👆 🔜 ✔️ 🛠️ ⚫️ 🌐 👆 📟).
|
|
||||||
* 🚥 👆 ⚖ FastAPI, 🔬 ⚫️ 🛡 🕸 🈸 🛠️ (⚖️ ⚒ 🧰) 👈 🚚 💽 🔬, 🛠️ & 🧾, 💖 🏺-apispec, NestJS, ♨, ♒️. 🛠️ ⏮️ 🛠️ 🏧 💽 🔬, 🛠️ & 🧾.
|
|
||||||
|
|
@ -1,323 +0,0 @@
|
||||||
# 🛠️ 🔧
|
|
||||||
|
|
||||||
🕐❔ 🛠️ **FastAPI** 🈸, ⚖️ 🤙, 🙆 🆎 🕸 🛠️, 📤 📚 🔧 👈 👆 🎲 💅 🔃, & ⚙️ 👫 👆 💪 🔎 **🏆 ☑** 🌌 **🛠️ 👆 🈸**.
|
|
||||||
|
|
||||||
⚠ 🔧:
|
|
||||||
|
|
||||||
* 💂♂ - 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
👥 🔜 👀 ❔ 👫 🔜 📉 **🛠️**.
|
|
||||||
|
|
||||||
🔚, 🏆 🎯 💪 **🍦 👆 🛠️ 👩💻** 🌌 👈 **🔐**, **❎ 📉**, & ⚙️ **📊 ℹ** (🖼 🛰 💽/🕹 🎰) ♻ 💪. 👶
|
|
||||||
|
|
||||||
👤 🔜 💬 👆 🍖 🌖 🔃 👫 **🔧** 📥, & 👈 🔜 🤞 🤝 👆 **🤔** 👆 🔜 💪 💭 ❔ 🛠️ 👆 🛠️ 📶 🎏 🌐, 🎲 **🔮** 🕐 👈 🚫 🔀.
|
|
||||||
|
|
||||||
🤔 👫 🔧, 👆 🔜 💪 **🔬 & 🔧** 🏆 🌌 🛠️ **👆 👍 🔗**.
|
|
||||||
|
|
||||||
⏭ 📃, 👤 🔜 🤝 👆 🌅 **🧱 🍮** 🛠️ FastAPI 🈸.
|
|
||||||
|
|
||||||
✋️ 🔜, ➡️ ✅ 👉 ⚠ **⚛ 💭**. 👫 🔧 ✔ 🙆 🎏 🆎 🕸 🛠️. 👶
|
|
||||||
|
|
||||||
## 💂♂ - 🇺🇸🔍
|
|
||||||
|
|
||||||
[⏮️ 📃 🔃 🇺🇸🔍](https.md){.internal-link target=_blank} 👥 🇭🇲 🔃 ❔ 🇺🇸🔍 🚚 🔐 👆 🛠️.
|
|
||||||
|
|
||||||
👥 👀 👈 🇺🇸🔍 🛎 🚚 🦲 **🔢** 👆 🈸 💽, **🤝 ❎ 🗳**.
|
|
||||||
|
|
||||||
& 📤 ✔️ 🕳 🈚 **♻ 🇺🇸🔍 📄**, ⚫️ 💪 🎏 🦲 ⚖️ ⚫️ 💪 🕳 🎏.
|
|
||||||
|
|
||||||
### 🖼 🧰 🇺🇸🔍
|
|
||||||
|
|
||||||
🧰 👆 💪 ⚙️ 🤝 ❎ 🗳:
|
|
||||||
|
|
||||||
* Traefik
|
|
||||||
* 🔁 🍵 📄 🔕 👶
|
|
||||||
* 📥
|
|
||||||
* 🔁 🍵 📄 🔕 👶
|
|
||||||
* 👌
|
|
||||||
* ⏮️ 🔢 🦲 💖 Certbot 📄 🔕
|
|
||||||
* ✳
|
|
||||||
* ⏮️ 🔢 🦲 💖 Certbot 📄 🔕
|
|
||||||
* Kubernetes ⏮️ 🚧 🕹 💖 👌
|
|
||||||
* ⏮️ 🔢 🦲 💖 🛂-👨💼 📄 🔕
|
|
||||||
* 🍵 🔘 ☁ 🐕🦺 🍕 👫 🐕🦺 (✍ 🔛 👶)
|
|
||||||
|
|
||||||
➕1️⃣ 🎛 👈 👆 💪 ⚙️ **☁ 🐕🦺** 👈 🔨 🌖 👷 ✅ ⚒ 🆙 🇺🇸🔍. ⚫️ 💪 ✔️ 🚫 ⚖️ 🈚 👆 🌅, ♒️. ✋️ 👈 💼, 👆 🚫🔜 ✔️ ⚒ 🆙 🤝 ❎ 🗳 👆.
|
|
||||||
|
|
||||||
👤 🔜 🎦 👆 🧱 🖼 ⏭ 📃.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
⤴️ ⏭ 🔧 🤔 🌐 🔃 📋 🏃 👆 ☑ 🛠️ (✅ Uvicorn).
|
|
||||||
|
|
||||||
## 📋 & 🛠️
|
|
||||||
|
|
||||||
👥 🔜 💬 📚 🔃 🏃 "**🛠️**", ⚫️ ⚠ ✔️ ☯ 🔃 ⚫️❔ ⚫️ ⛓, & ⚫️❔ 🔺 ⏮️ 🔤 "**📋**".
|
|
||||||
|
|
||||||
### ⚫️❔ 📋
|
|
||||||
|
|
||||||
🔤 **📋** 🛎 ⚙️ 🔬 📚 👜:
|
|
||||||
|
|
||||||
* **📟** 👈 👆 ✍, **🐍 📁**.
|
|
||||||
* **📁** 👈 💪 **🛠️** 🏃♂ ⚙️, 🖼: `python`, `python.exe` ⚖️ `uvicorn`.
|
|
||||||
* 🎯 📋 ⏪ ⚫️ **🏃♂** 🔛 🏗 ⚙️, ⚙️ 💽, & ♻ 👜 🔛 💾. 👉 🤙 **🛠️**.
|
|
||||||
|
|
||||||
### ⚫️❔ 🛠️
|
|
||||||
|
|
||||||
🔤 **🛠️** 🛎 ⚙️ 🌖 🎯 🌌, 🕴 🔗 👜 👈 🏃 🏃♂ ⚙️ (💖 🏁 ☝ 🔛):
|
|
||||||
|
|
||||||
* 🎯 📋 ⏪ ⚫️ **🏃♂** 🔛 🏃♂ ⚙️.
|
|
||||||
* 👉 🚫 🔗 📁, 🚫 📟, ⚫️ 🔗 **🎯** 👜 👈 ➖ **🛠️** & 🔄 🏃♂ ⚙️.
|
|
||||||
* 🙆 📋, 🙆 📟, **💪 🕴 👜** 🕐❔ ⚫️ ➖ **🛠️**. , 🕐❔ 📤 **🛠️ 🏃**.
|
|
||||||
* 🛠️ 💪 **❎** (⚖️ "💥") 👆, ⚖️ 🏃♂ ⚙️. 👈 ☝, ⚫️ ⛔️ 🏃/➖ 🛠️, & ⚫️ 💪 **🙅♂ 📏 👜**.
|
|
||||||
* 🔠 🈸 👈 👆 ✔️ 🏃 🔛 👆 💻 ✔️ 🛠️ ⛅ ⚫️, 🔠 🏃♂ 📋, 🔠 🚪, ♒️. & 📤 🛎 📚 🛠️ 🏃 **🎏 🕰** ⏪ 💻 🔛.
|
|
||||||
* 📤 💪 **💗 🛠️** **🎏 📋** 🏃 🎏 🕰.
|
|
||||||
|
|
||||||
🚥 👆 ✅ 👅 "📋 👨💼" ⚖️ "⚙️ 🖥" (⚖️ 🎏 🧰) 👆 🏃♂ ⚙️, 👆 🔜 💪 👀 📚 👈 🛠️ 🏃♂.
|
|
||||||
|
|
||||||
& , 🖼, 👆 🔜 🎲 👀 👈 📤 💗 🛠️ 🏃 🎏 🖥 📋 (🦎, 💄, 📐, ♒️). 👫 🛎 🏃 1️⃣ 🛠️ 📍 📑, ➕ 🎏 ➕ 🛠️.
|
|
||||||
|
|
||||||
<img class="shadow" src="/img/deployment/concepts/image01.png">
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🔜 👈 👥 💭 🔺 🖖 ⚖ **🛠️** & **📋**, ➡️ 😣 💬 🔃 🛠️.
|
|
||||||
|
|
||||||
## 🏃♂ 🔛 🕴
|
|
||||||
|
|
||||||
🌅 💼, 🕐❔ 👆 ✍ 🕸 🛠️, 👆 💚 ⚫️ **🕧 🏃♂**, ➡, 👈 👆 👩💻 💪 🕧 🔐 ⚫️. 👉 ↗️, 🚥 👆 ✔️ 🎯 🤔 ⚫️❔ 👆 💚 ⚫️ 🏃 🕴 🎯 ⚠, ✋️ 🌅 🕰 👆 💚 ⚫️ 🕧 🏃♂ & **💪**.
|
|
||||||
|
|
||||||
### 🛰 💽
|
|
||||||
|
|
||||||
🕐❔ 👆 ⚒ 🆙 🛰 💽 (☁ 💽, 🕹 🎰, ♒️.) 🙅 👜 👆 💪 🏃 Uvicorn (⚖️ 🎏) ❎, 🎏 🌌 👆 🕐❔ 🛠️ 🌐.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 👷 & 🔜 ⚠ **⏮️ 🛠️**.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🔗 💽 💸, **🏃♂ 🛠️** 🔜 🎲 ☠️.
|
|
||||||
|
|
||||||
& 🚥 💽 ⏏ (🖼 ⏮️ ℹ, ⚖️ 🛠️ ⚪️➡️ ☁ 🐕🦺) 👆 🎲 **🏆 🚫 👀 ⚫️**. & ↩️ 👈, 👆 🏆 🚫 💭 👈 👆 ✔️ ⏏ 🛠️ ❎. , 👆 🛠️ 🔜 🚧 ☠️. 👶
|
|
||||||
|
|
||||||
### 🏃 🔁 🔛 🕴
|
|
||||||
|
|
||||||
🏢, 👆 🔜 🎲 💚 💽 📋 (✅ Uvicorn) ▶️ 🔁 🔛 💽 🕴, & 🍵 💪 🙆 **🗿 🏥**, ✔️ 🛠️ 🕧 🏃 ⏮️ 👆 🛠️ (✅ Uvicorn 🏃♂ 👆 FastAPI 📱).
|
|
||||||
|
|
||||||
### 🎏 📋
|
|
||||||
|
|
||||||
🏆 👉, 👆 🔜 🛎 ✔️ **🎏 📋** 👈 🔜 ⚒ 💭 👆 🈸 🏃 🔛 🕴. & 📚 💼, ⚫️ 🔜 ⚒ 💭 🎏 🦲 ⚖️ 🈸 🏃, 🖼, 💽.
|
|
||||||
|
|
||||||
### 🖼 🧰 🏃 🕴
|
|
||||||
|
|
||||||
🖼 🧰 👈 💪 👉 👨🏭:
|
|
||||||
|
|
||||||
* ☁
|
|
||||||
* Kubernetes
|
|
||||||
* ☁ ✍
|
|
||||||
* ☁ 🐝 📳
|
|
||||||
* ✳
|
|
||||||
* 👨💻
|
|
||||||
* 🍵 🔘 ☁ 🐕🦺 🍕 👫 🐕🦺
|
|
||||||
* 🎏...
|
|
||||||
|
|
||||||
👤 🔜 🤝 👆 🌅 🧱 🖼 ⏭ 📃.
|
|
||||||
|
|
||||||
## ⏏
|
|
||||||
|
|
||||||
🎏 ⚒ 💭 👆 🈸 🏃 🔛 🕴, 👆 🎲 💚 ⚒ 💭 ⚫️ **⏏** ⏮️ ❌.
|
|
||||||
|
|
||||||
### 👥 ⚒ ❌
|
|
||||||
|
|
||||||
👥, 🗿, ⚒ **❌**, 🌐 🕰. 🖥 🌖 *🕧* ✔️ **🐛** 🕵♂ 🎏 🥉. 👶
|
|
||||||
|
|
||||||
& 👥 👩💻 🚧 📉 📟 👥 🔎 👈 🐛 & 👥 🛠️ 🆕 ⚒ (🎲 ❎ 🆕 🐛 💁♂️ 👶).
|
|
||||||
|
|
||||||
### 🤪 ❌ 🔁 🍵
|
|
||||||
|
|
||||||
🕐❔ 🏗 🕸 🔗 ⏮️ FastAPI, 🚥 📤 ❌ 👆 📟, FastAPI 🔜 🛎 🔌 ⚫️ 👁 📨 👈 ⏲ ❌. 🛡
|
|
||||||
|
|
||||||
👩💻 🔜 🤚 **5️⃣0️⃣0️⃣ 🔗 💽 ❌** 👈 📨, ✋️ 🈸 🔜 😣 👷 ⏭ 📨 ↩️ 💥 🍕.
|
|
||||||
|
|
||||||
### 🦏 ❌ - 💥
|
|
||||||
|
|
||||||
👐, 📤 5️⃣📆 💼 🌐❔ 👥 ✍ 📟 👈 **💥 🎂 🈸** ⚒ Uvicorn & 🐍 💥. 👶
|
|
||||||
|
|
||||||
& , 👆 🔜 🎲 🚫 💚 🈸 🚧 ☠️ ↩️ 📤 ❌ 1️⃣ 🥉, 👆 🎲 💚 ⚫️ **😣 🏃** 🌘 *➡ 🛠️* 👈 🚫 💔.
|
|
||||||
|
|
||||||
### ⏏ ⏮️ 💥
|
|
||||||
|
|
||||||
✋️ 👈 💼 ⏮️ 🤙 👎 ❌ 👈 💥 🏃♂ **🛠️**, 👆 🔜 💚 🔢 🦲 👈 🈚 **🔁** 🛠️, 🌘 👩❤👨 🕰...
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
...👐 🚥 🎂 🈸 **💥 ⏪** ⚫️ 🎲 🚫 ⚒ 🔑 🚧 🔁 ⚫️ ♾. ✋️ 📚 💼, 👆 🔜 🎲 👀 ⚫️ ⏮️ 🛠️, ⚖️ 🌘 ▶️️ ⏮️ 🛠️.
|
|
||||||
|
|
||||||
➡️ 🎯 🔛 👑 💼, 🌐❔ ⚫️ 💪 💥 🍕 🎯 💼 **🔮**, & ⚫️ ⚒ 🔑 ⏏ ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 🔜 🎲 💚 ✔️ 👜 🈚 🔁 👆 🈸 **🔢 🦲**, ↩️ 👈 ☝, 🎏 🈸 ⏮️ Uvicorn & 🐍 ⏪ 💥, 📤 🕳 🎏 📟 🎏 📱 👈 💪 🕳 🔃 ⚫️.
|
|
||||||
|
|
||||||
### 🖼 🧰 ⏏ 🔁
|
|
||||||
|
|
||||||
🏆 💼, 🎏 🧰 👈 ⚙️ **🏃 📋 🔛 🕴** ⚙️ 🍵 🏧 **⏏**.
|
|
||||||
|
|
||||||
🖼, 👉 💪 🍵:
|
|
||||||
|
|
||||||
* ☁
|
|
||||||
* Kubernetes
|
|
||||||
* ☁ ✍
|
|
||||||
* ☁ 🐝 📳
|
|
||||||
* ✳
|
|
||||||
* 👨💻
|
|
||||||
* 🍵 🔘 ☁ 🐕🦺 🍕 👫 🐕🦺
|
|
||||||
* 🎏...
|
|
||||||
|
|
||||||
## 🧬 - 🛠️ & 💾
|
|
||||||
|
|
||||||
⏮️ FastAPI 🈸, ⚙️ 💽 📋 💖 Uvicorn, 🏃♂ ⚫️ 🕐 **1️⃣ 🛠️** 💪 🍦 💗 👩💻 🔁.
|
|
||||||
|
|
||||||
✋️ 📚 💼, 👆 🔜 💚 🏃 📚 👨🏭 🛠️ 🎏 🕰.
|
|
||||||
|
|
||||||
### 💗 🛠️ - 👨🏭
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🌅 👩💻 🌘 ⚫️❔ 👁 🛠️ 💪 🍵 (🖼 🚥 🕹 🎰 🚫 💁♂️ 🦏) & 👆 ✔️ **💗 🐚** 💽 💽, ⤴️ 👆 💪 ✔️ **💗 🛠️** 🏃♂ ⏮️ 🎏 🈸 🎏 🕰, & 📎 🌐 📨 👪 👫.
|
|
||||||
|
|
||||||
🕐❔ 👆 🏃 **💗 🛠️** 🎏 🛠️ 📋, 👫 🛎 🤙 **👨🏭**.
|
|
||||||
|
|
||||||
### 👨🏭 🛠️ & ⛴
|
|
||||||
|
|
||||||
💭 ⚪️➡️ 🩺 [🔃 🇺🇸🔍](https.md){.internal-link target=_blank} 👈 🕴 1️⃣ 🛠️ 💪 👂 🔛 1️⃣ 🌀 ⛴ & 📢 📢 💽 ❓
|
|
||||||
|
|
||||||
👉 ☑.
|
|
||||||
|
|
||||||
, 💪 ✔️ **💗 🛠️** 🎏 🕰, 📤 ✔️ **👁 🛠️ 👂 🔛 ⛴** 👈 ⤴️ 📶 📻 🔠 👨🏭 🛠️ 🌌.
|
|
||||||
|
|
||||||
### 💾 📍 🛠️
|
|
||||||
|
|
||||||
🔜, 🕐❔ 📋 📐 👜 💾, 🖼, 🎰 🏫 🏷 🔢, ⚖️ 🎚 ⭕ 📁 🔢, 🌐 👈 **🍴 👄 💾 (💾)** 💽.
|
|
||||||
|
|
||||||
& 💗 🛠️ 🛎 **🚫 💰 🙆 💾**. 👉 ⛓ 👈 🔠 🏃 🛠️ ✔️ 🚮 👍 👜, 🔢, & 💾. & 🚥 👆 😩 ⭕ 💸 💾 👆 📟, **🔠 🛠️** 🔜 🍴 🌓 💸 💾.
|
|
||||||
|
|
||||||
### 💽 💾
|
|
||||||
|
|
||||||
🖼, 🚥 👆 📟 📐 🎰 🏫 🏷 ⏮️ **1️⃣ 💾 📐**, 🕐❔ 👆 🏃 1️⃣ 🛠️ ⏮️ 👆 🛠️, ⚫️ 🔜 🍴 🌘 1️⃣ 💾 💾. & 🚥 👆 ▶️ **4️⃣ 🛠️** (4️⃣ 👨🏭), 🔠 🔜 🍴 1️⃣ 💾 💾. 🌐, 👆 🛠️ 🔜 🍴 **4️⃣ 💾 💾**.
|
|
||||||
|
|
||||||
& 🚥 👆 🛰 💽 ⚖️ 🕹 🎰 🕴 ✔️ 3️⃣ 💾 💾, 🔄 📐 🌅 🌘 4️⃣ 💾 💾 🔜 🤕 ⚠. 👶
|
|
||||||
|
|
||||||
### 💗 🛠️ - 🖼
|
|
||||||
|
|
||||||
👉 🖼, 📤 **👨💼 🛠️** 👈 ▶️ & 🎛 2️⃣ **👨🏭 🛠️**.
|
|
||||||
|
|
||||||
👉 👨💼 🛠️ 🔜 🎲 1️⃣ 👂 🔛 **⛴** 📢. & ⚫️ 🔜 📶 🌐 📻 👨🏭 🛠️.
|
|
||||||
|
|
||||||
👈 👨🏭 🛠️ 🔜 🕐 🏃♂ 👆 🈸, 👫 🔜 🎭 👑 📊 📨 **📨** & 📨 **📨**, & 👫 🔜 📐 🕳 👆 🚮 🔢 💾.
|
|
||||||
|
|
||||||
<img src="/img/deployment/concepts/process-ram.drawio.svg">
|
|
||||||
|
|
||||||
& ↗️, 🎏 🎰 🔜 🎲 ✔️ **🎏 🛠️** 🏃 👍, ↖️ ⚪️➡️ 👆 🈸.
|
|
||||||
|
|
||||||
😌 ℹ 👈 🌐 **💽 ⚙️** 🔠 🛠️ 💪 **🪀** 📚 🤭 🕰, ✋️ **💾 (💾)** 🛎 🚧 🌖 ⚖️ 🌘 **⚖**.
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🛠️ 👈 🔨 ⭐ 💸 📊 🔠 🕰 & 👆 ✔️ 📚 👩💻, ⤴️ **💽 🛠️** 🔜 🎲 *⚖* (↩️ 🕧 🔜 🆙 & 🔽 🔜).
|
|
||||||
|
|
||||||
### 🖼 🧬 🧰 & 🎛
|
|
||||||
|
|
||||||
📤 💪 📚 🎯 🏆 👉, & 👤 🔜 💬 👆 🌅 🔃 🎯 🎛 ⏭ 📃, 🖼 🕐❔ 💬 🔃 ☁ & 📦.
|
|
||||||
|
|
||||||
👑 ⚛ 🤔 👈 📤 ✔️ **👁** 🦲 🚚 **⛴** **📢 📢**. & ⤴️ ⚫️ ✔️ ✔️ 🌌 **📶** 📻 🔁 **🛠️/👨🏭**.
|
|
||||||
|
|
||||||
📥 💪 🌀 & 🎛:
|
|
||||||
|
|
||||||
* **🐁** 🛠️ **Uvicorn 👨🏭**
|
|
||||||
* 🐁 🔜 **🛠️ 👨💼** 👂 🔛 **📢** & **⛴**, 🧬 🔜 ✔️ **💗 Uvicorn 👨🏭 🛠️**
|
|
||||||
* **Uvicorn** 🛠️ **Uvicorn 👨🏭**
|
|
||||||
* 1️⃣ Uvicorn **🛠️ 👨💼** 🔜 👂 🔛 **📢** & **⛴**, & ⚫️ 🔜 ▶️ **💗 Uvicorn 👨🏭 🛠️**
|
|
||||||
* **Kubernetes** & 🎏 📎 **📦 ⚙️**
|
|
||||||
* 🕳 **☁** 🧽 🔜 👂 🔛 **📢** & **⛴**. 🧬 🔜 ✔️ **💗 📦**, 🔠 ⏮️ **1️⃣ Uvicorn 🛠️** 🏃♂
|
|
||||||
* **☁ 🐕🦺** 👈 🍵 👉 👆
|
|
||||||
* ☁ 🐕🦺 🔜 🎲 **🍵 🧬 👆**. ⚫️ 🔜 🎲 ➡️ 👆 🔬 **🛠️ 🏃**, ⚖️ **📦 🖼** ⚙️, 🙆 💼, ⚫️ 🔜 🌅 🎲 **👁 Uvicorn 🛠️**, & ☁ 🐕🦺 🔜 🈚 🔁 ⚫️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚫 😟 🚥 👫 🏬 🔃 **📦**, ☁, ⚖️ Kubernetes 🚫 ⚒ 📚 🔑.
|
|
||||||
|
|
||||||
👤 🔜 💬 👆 🌅 🔃 📦 🖼, ☁, Kubernetes, ♒️. 🔮 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
📤 📚 💼 🌐❔ 👆 💚 🎭 📶 **⏭ ▶️** 👆 🈸.
|
|
||||||
|
|
||||||
🖼, 👆 💪 💚 🏃 **💽 🛠️**.
|
|
||||||
|
|
||||||
✋️ 🌅 💼, 👆 🔜 💚 🎭 👉 🔁 🕴 **🕐**.
|
|
||||||
|
|
||||||
, 👆 🔜 💚 ✔️ **👁 🛠️** 🎭 👈 **⏮️ 🔁**, ⏭ ▶️ 🈸.
|
|
||||||
|
|
||||||
& 👆 🔜 ✔️ ⚒ 💭 👈 ⚫️ 👁 🛠️ 🏃 👈 ⏮️ 🔁 ** 🚥 ⏮️, 👆 ▶️ **💗 🛠️** (💗 👨🏭) 🈸 ⚫️. 🚥 👈 🔁 🏃 **💗 🛠️**, 👫 🔜 **❎** 👷 🏃♂ ⚫️ 🔛 **🔗**, & 🚥 📶 🕳 💎 💖 💽 🛠️, 👫 💪 🤕 ⚔ ⏮️ 🔠 🎏.
|
|
||||||
|
|
||||||
↗️, 📤 💼 🌐❔ 📤 🙅♂ ⚠ 🏃 ⏮️ 🔁 💗 🕰, 👈 💼, ⚫️ 📚 ⏩ 🍵.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
, ✔️ 🤯 👈 ⚓️ 🔛 👆 🖥, 💼 👆 **5️⃣📆 🚫 💪 🙆 ⏮️ 🔁** ⏭ ▶️ 👆 🈸.
|
|
||||||
|
|
||||||
👈 💼, 👆 🚫🔜 ✔️ 😟 🔃 🙆 👉. 🤷
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🖼 ⏮️ 🔁 🎛
|
|
||||||
|
|
||||||
👉 🔜 **🪀 🙇** 🔛 🌌 👆 **🛠️ 👆 ⚙️**, & ⚫️ 🔜 🎲 🔗 🌌 👆 ▶️ 📋, 🚚 ⏏, ♒️.
|
|
||||||
|
|
||||||
📥 💪 💭:
|
|
||||||
|
|
||||||
* "🕑 📦" Kubernetes 👈 🏃 ⏭ 👆 📱 📦
|
|
||||||
* 🎉 ✍ 👈 🏃 ⏮️ 🔁 & ⤴️ ▶️ 👆 🈸
|
|
||||||
* 👆 🔜 💪 🌌 ▶️/⏏ *👈* 🎉 ✍, 🔍 ❌, ♒️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👤 🔜 🤝 👆 🌅 🧱 🖼 🔨 👉 ⏮️ 📦 🔮 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ℹ 🛠️
|
|
||||||
|
|
||||||
👆 💽(Ⓜ) () **ℹ**, 👆 💪 🍴 ⚖️ **⚙️**, ⏮️ 👆 📋, 📊 🕰 🔛 💽, & 💾 💾 💪.
|
|
||||||
|
|
||||||
❔ 🌅 ⚙️ ℹ 👆 💚 😩/♻ ❓ ⚫️ 💪 ⏩ 💭 "🚫 🌅", ✋️ 🌌, 👆 🔜 🎲 💚 🍴 **🌅 💪 🍵 💥**.
|
|
||||||
|
|
||||||
🚥 👆 💸 3️⃣ 💽 ✋️ 👆 ⚙️ 🕴 🐥 🍖 👫 💾 & 💽, 👆 🎲 **🗑 💸** 👶, & 🎲 **🗑 💽 🔦 🏋️** 👶, ♒️.
|
|
||||||
|
|
||||||
👈 💼, ⚫️ 💪 👻 ✔️ 🕴 2️⃣ 💽 & ⚙️ ↕ 🌐 👫 ℹ (💽, 💾, 💾, 🕸 💿, ♒️).
|
|
||||||
|
|
||||||
🔛 🎏 ✋, 🚥 👆 ✔️ 2️⃣ 💽 & 👆 ⚙️ **1️⃣0️⃣0️⃣ 💯 👫 💽 & 💾**, ☝ 1️⃣ 🛠️ 🔜 💭 🌅 💾, & 💽 🔜 ✔️ ⚙️ 💾 "💾" (❔ 💪 💯 🕰 🐌), ⚖️ **💥**. ⚖️ 1️⃣ 🛠️ 💪 💪 📊 & 🔜 ✔️ ⌛ ⏭ 💽 🆓 🔄.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🔜 👍 🤚 **1️⃣ ➕ 💽** & 🏃 🛠️ 🔛 ⚫️ 👈 👫 🌐 ✔️ **🥃 💾 & 💽 🕰**.
|
|
||||||
|
|
||||||
📤 🤞 👈 🤔 👆 ✔️ **🌵** ⚙️ 👆 🛠️. 🎲 ⚫️ 🚶 🦠, ⚖️ 🎲 🎏 🐕🦺 ⚖️ 🤖 ▶️ ⚙️ ⚫️. & 👆 💪 💚 ✔️ ➕ ℹ 🔒 👈 💼.
|
|
||||||
|
|
||||||
👆 💪 🚮 **❌ 🔢** 🎯, 🖼, 🕳 **🖖 5️⃣0️⃣ 💯 9️⃣0️⃣ 💯** ℹ 🛠️. ☝ 👈 📚 🎲 👑 👜 👆 🔜 💚 ⚖ & ⚙️ ⚒ 👆 🛠️.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🙅 🧰 💖 `htop` 👀 💽 & 💾 ⚙️ 👆 💽 ⚖️ 💸 ⚙️ 🔠 🛠️. ⚖️ 👆 💪 ⚙️ 🌖 🏗 ⚖ 🧰, ❔ 5️⃣📆 📎 🤭 💽, ♒️.
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 ✔️ 👂 📥 👑 🔧 👈 👆 🔜 🎲 💪 ✔️ 🤯 🕐❔ 🤔 ❔ 🛠️ 👆 🈸:
|
|
||||||
|
|
||||||
* 💂♂ - 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
🤔 👉 💭 & ❔ ✔ 👫 🔜 🤝 👆 🤔 💪 ✊ 🙆 🚫 🕐❔ 🛠️ & 🛠️ 👆 🛠️. 👶
|
|
||||||
|
|
||||||
⏭ 📄, 👤 🔜 🤝 👆 🌅 🧱 🖼 💪 🎛 👆 💪 ⏩. 👶
|
|
||||||
|
|
@ -1,731 +0,0 @@
|
||||||
# FastAPI 📦 - ☁
|
|
||||||
|
|
||||||
🕐❔ 🛠️ FastAPI 🈸 ⚠ 🎯 🏗 **💾 📦 🖼**. ⚫️ 🛎 🔨 ⚙️ <a href="https://www.docker.com/" class="external-link" target="_blank">**☁**</a>. 👆 💪 ⤴️ 🛠️ 👈 📦 🖼 1️⃣ 👩❤👨 💪 🌌.
|
|
||||||
|
|
||||||
⚙️ 💾 📦 ✔️ 📚 📈 ✅ **💂♂**, **🔬**, **🦁**, & 🎏.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🏃 & ⏪ 💭 👉 💩 ❓ 🦘 [`Dockerfile` 🔛 👶](#fastapi).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
<details>
|
|
||||||
<summary>📁 🎮 👶</summary>
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
FROM python:3.9
|
|
||||||
|
|
||||||
WORKDIR /code
|
|
||||||
|
|
||||||
COPY ./requirements.txt /code/requirements.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
|
|
||||||
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"]
|
|
||||||
```
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
## ⚫️❔ 📦
|
|
||||||
|
|
||||||
📦 (✴️ 💾 📦) 📶 **💿** 🌌 📦 🈸 ✅ 🌐 👫 🔗 & 💪 📁 ⏪ 🚧 👫 ❎ ⚪️➡️ 🎏 📦 (🎏 🈸 ⚖️ 🦲) 🎏 ⚙️.
|
|
||||||
|
|
||||||
💾 📦 🏃 ⚙️ 🎏 💾 💾 🦠 (🎰, 🕹 🎰, ☁ 💽, ♒️). 👉 ⛓ 👈 👫 📶 💿 (🔬 🌕 🕹 🎰 👍 🎂 🏃♂ ⚙️).
|
|
||||||
|
|
||||||
👉 🌌, 📦 🍴 **🐥 ℹ**, 💸 ⭐ 🏃♂ 🛠️ 🔗 (🕹 🎰 🔜 🍴 🌅 🌅).
|
|
||||||
|
|
||||||
📦 ✔️ 👫 👍 **❎** 🏃♂ 🛠️ (🛎 1️⃣ 🛠️), 📁 ⚙️, & 🕸, 🔬 🛠️, 💂♂, 🛠️, ♒️.
|
|
||||||
|
|
||||||
## ⚫️❔ 📦 🖼
|
|
||||||
|
|
||||||
**📦** 🏃 ⚪️➡️ **📦 🖼**.
|
|
||||||
|
|
||||||
📦 🖼 **🎻** ⏬ 🌐 📁, 🌐 🔢, & 🔢 📋/📋 👈 🔜 🎁 📦. **🎻** 📥 ⛓ 👈 📦 **🖼** 🚫 🏃, ⚫️ 🚫 ➖ 🛠️, ⚫️ 🕴 📦 📁 & 🗃.
|
|
||||||
|
|
||||||
🔅 "**📦 🖼**" 👈 🏪 🎻 🎚,"**📦**" 🛎 🔗 🏃♂ 👐, 👜 👈 ➖ **🛠️**.
|
|
||||||
|
|
||||||
🕐❔ **📦** ▶️ & 🏃♂ (▶️ ⚪️➡️ **📦 🖼**) ⚫️ 💪 ✍ ⚖️ 🔀 📁, 🌐 🔢, ♒️. 👈 🔀 🔜 🔀 🕴 👈 📦, ✋️ 🔜 🚫 😣 👽 📦 🖼 (🔜 🚫 🖊 💾).
|
|
||||||
|
|
||||||
📦 🖼 ⭐ **📋** 📁 & 🎚, ✅ `python` & 📁 `main.py`.
|
|
||||||
|
|
||||||
& **📦** ⚫️ (🔅 **📦 🖼**) ☑ 🏃 👐 🖼, ⭐ **🛠️**. 👐, 📦 🏃 🕴 🕐❔ ⚫️ ✔️ **🛠️ 🏃** (& 🛎 ⚫️ 🕴 👁 🛠️). 📦 ⛔️ 🕐❔ 📤 🙅♂ 🛠️ 🏃 ⚫️.
|
|
||||||
|
|
||||||
## 📦 🖼
|
|
||||||
|
|
||||||
☁ ✔️ 1️⃣ 👑 🧰 ✍ & 🛠️ **📦 🖼** & **📦**.
|
|
||||||
|
|
||||||
& 📤 📢 <a href="https://hub.docker.com/" class="external-link" target="_blank">☁ 🎡</a> ⏮️ 🏤-⚒ **🛂 📦 🖼** 📚 🧰, 🌐, 💽, & 🈸.
|
|
||||||
|
|
||||||
🖼, 📤 🛂 <a href="https://hub.docker.com/_/python" class="external-link" target="_blank">🐍 🖼</a>.
|
|
||||||
|
|
||||||
& 📤 📚 🎏 🖼 🎏 👜 💖 💽, 🖼:
|
|
||||||
|
|
||||||
* <a href="https://hub.docker.com/_/postgres" class="external-link" target="_blank">✳</a>
|
|
||||||
* <a href="https://hub.docker.com/_/mysql" class="external-link" target="_blank">✳</a>
|
|
||||||
* <a href="https://hub.docker.com/_/mongo" class="external-link" target="_blank">✳</a>
|
|
||||||
* <a href="https://hub.docker.com/_/redis" class="external-link" target="_blank">✳</a>, ♒️.
|
|
||||||
|
|
||||||
⚙️ 🏤-⚒ 📦 🖼 ⚫️ 📶 ⏩ **🌀** & ⚙️ 🎏 🧰. 🖼, 🔄 👅 🆕 💽. 🌅 💼, 👆 💪 ⚙️ **🛂 🖼**, & 🔗 👫 ⏮️ 🌐 🔢.
|
|
||||||
|
|
||||||
👈 🌌, 📚 💼 👆 💪 💡 🔃 📦 & ☁ & 🏤-⚙️ 👈 💡 ⏮️ 📚 🎏 🧰 & 🦲.
|
|
||||||
|
|
||||||
, 👆 🔜 🏃 **💗 📦** ⏮️ 🎏 👜, 💖 💽, 🐍 🈸, 🕸 💽 ⏮️ 😥 🕸 🈸, & 🔗 👫 👯♂️ 📨 👫 🔗 🕸.
|
|
||||||
|
|
||||||
🌐 📦 🧾 ⚙️ (💖 ☁ ⚖️ Kubernetes) ✔️ 👫 🕸 ⚒ 🛠️ 🔘 👫.
|
|
||||||
|
|
||||||
## 📦 & 🛠️
|
|
||||||
|
|
||||||
**📦 🖼** 🛎 🔌 🚮 🗃 🔢 📋 ⚖️ 📋 👈 🔜 🏃 🕐❔ **📦** ▶️ & 🔢 🚶♀️ 👈 📋. 📶 🎏 ⚫️❔ 🔜 🚥 ⚫️ 📋 ⏸.
|
|
||||||
|
|
||||||
🕐❔ **📦** ▶️, ⚫️ 🔜 🏃 👈 📋/📋 (👐 👆 💪 🔐 ⚫️ & ⚒ ⚫️ 🏃 🎏 📋/📋).
|
|
||||||
|
|
||||||
📦 🏃 📏 **👑 🛠️** (📋 ⚖️ 📋) 🏃.
|
|
||||||
|
|
||||||
📦 🛎 ✔️ **👁 🛠️**, ✋️ ⚫️ 💪 ▶️ ✳ ⚪️➡️ 👑 🛠️, & 👈 🌌 👆 🔜 ✔️ **💗 🛠️** 🎏 📦.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🚫 💪 ✔️ 🏃♂ 📦 🍵 **🌘 1️⃣ 🏃♂ 🛠️**. 🚥 👑 🛠️ ⛔️, 📦 ⛔️.
|
|
||||||
|
|
||||||
## 🏗 ☁ 🖼 FastAPI
|
|
||||||
|
|
||||||
🆗, ➡️ 🏗 🕳 🔜 ❗ 👶
|
|
||||||
|
|
||||||
👤 🔜 🎦 👆 ❔ 🏗 **☁ 🖼** FastAPI **⚪️➡️ 🖌**, ⚓️ 🔛 **🛂 🐍** 🖼.
|
|
||||||
|
|
||||||
👉 ⚫️❔ 👆 🔜 💚 **🏆 💼**, 🖼:
|
|
||||||
|
|
||||||
* ⚙️ **Kubernetes** ⚖️ 🎏 🧰
|
|
||||||
* 🕐❔ 🏃♂ 🔛 **🍓 👲**
|
|
||||||
* ⚙️ ☁ 🐕🦺 👈 🔜 🏃 📦 🖼 👆, ♒️.
|
|
||||||
|
|
||||||
### 📦 📄
|
|
||||||
|
|
||||||
👆 🔜 🛎 ✔️ **📦 📄** 👆 🈸 📁.
|
|
||||||
|
|
||||||
⚫️ 🔜 🪀 ✴️ 🔛 🧰 👆 ⚙️ **❎** 👈 📄.
|
|
||||||
|
|
||||||
🌅 ⚠ 🌌 ⚫️ ✔️ 📁 `requirements.txt` ⏮️ 📦 📛 & 👫 ⏬, 1️⃣ 📍 ⏸.
|
|
||||||
|
|
||||||
👆 🔜 ↗️ ⚙️ 🎏 💭 👆 ✍ [🔃 FastAPI ⏬](versions.md){.internal-link target=_blank} ⚒ ↔ ⏬.
|
|
||||||
|
|
||||||
🖼, 👆 `requirements.txt` 💪 👀 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
fastapi>=0.68.0,<0.69.0
|
|
||||||
pydantic>=1.8.0,<2.0.0
|
|
||||||
uvicorn>=0.15.0,<0.16.0
|
|
||||||
```
|
|
||||||
|
|
||||||
& 👆 🔜 🛎 ❎ 👈 📦 🔗 ⏮️ `pip`, 🖼:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install -r requirements.txt
|
|
||||||
---> 100%
|
|
||||||
Successfully installed fastapi pydantic uvicorn
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📤 🎏 📁 & 🧰 🔬 & ❎ 📦 🔗.
|
|
||||||
|
|
||||||
👤 🔜 🎦 👆 🖼 ⚙️ 🎶 ⏪ 📄 🔛. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ✍ **FastAPI** 📟
|
|
||||||
|
|
||||||
* ✍ `app` 📁 & ⛔ ⚫️.
|
|
||||||
* ✍ 🛁 📁 `__init__.py`.
|
|
||||||
* ✍ `main.py` 📁 ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
def read_root():
|
|
||||||
return {"Hello": "World"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}")
|
|
||||||
def read_item(item_id: int, q: Union[str, None] = None):
|
|
||||||
return {"item_id": item_id, "q": q}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 📁
|
|
||||||
|
|
||||||
🔜 🎏 🏗 📁 ✍ 📁 `Dockerfile` ⏮️:
|
|
||||||
|
|
||||||
```{ .dockerfile .annotate }
|
|
||||||
# (1)
|
|
||||||
FROM python:3.9
|
|
||||||
|
|
||||||
# (2)
|
|
||||||
WORKDIR /code
|
|
||||||
|
|
||||||
# (3)
|
|
||||||
COPY ./requirements.txt /code/requirements.txt
|
|
||||||
|
|
||||||
# (4)
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
||||||
|
|
||||||
# (5)
|
|
||||||
COPY ./app /code/app
|
|
||||||
|
|
||||||
# (6)
|
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
```
|
|
||||||
|
|
||||||
1️⃣. ▶️ ⚪️➡️ 🛂 🐍 🧢 🖼.
|
|
||||||
|
|
||||||
2️⃣. ⚒ ⏮️ 👷 📁 `/code`.
|
|
||||||
|
|
||||||
👉 🌐❔ 👥 🔜 🚮 `requirements.txt` 📁 & `app` 📁.
|
|
||||||
|
|
||||||
3️⃣. 📁 📁 ⏮️ 📄 `/code` 📁.
|
|
||||||
|
|
||||||
📁 **🕴** 📁 ⏮️ 📄 🥇, 🚫 🎂 📟.
|
|
||||||
|
|
||||||
👉 📁 **🚫 🔀 🛎**, ☁ 🔜 🔍 ⚫️ & ⚙️ **💾** 👉 🔁, 🛠️ 💾 ⏭ 🔁 💁♂️.
|
|
||||||
|
|
||||||
4️⃣. ❎ 📦 🔗 📄 📁.
|
|
||||||
|
|
||||||
`--no-cache-dir` 🎛 💬 `pip` 🚫 🖊 ⏬ 📦 🌐, 👈 🕴 🚥 `pip` 🔜 🏃 🔄 ❎ 🎏 📦, ✋️ 👈 🚫 💼 🕐❔ 👷 ⏮️ 📦.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
`--no-cache-dir` 🕴 🔗 `pip`, ⚫️ ✔️ 🕳 ⏮️ ☁ ⚖️ 📦.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
`--upgrade` 🎛 💬 `pip` ♻ 📦 🚥 👫 ⏪ ❎.
|
|
||||||
|
|
||||||
↩️ ⏮️ 🔁 🖨 📁 💪 🔍 **☁ 💾**, 👉 🔁 🔜 **⚙️ ☁ 💾** 🕐❔ 💪.
|
|
||||||
|
|
||||||
⚙️ 💾 👉 🔁 🔜 **🖊** 👆 📚 **🕰** 🕐❔ 🏗 🖼 🔄 & 🔄 ⏮️ 🛠️, ↩️ **⏬ & ❎** 🌐 🔗 **🔠 🕰**.
|
|
||||||
|
|
||||||
5️⃣. 📁 `./app` 📁 🔘 `/code` 📁.
|
|
||||||
|
|
||||||
👉 ✔️ 🌐 📟 ❔ ⚫️❔ **🔀 🌅 🛎** ☁ **💾** 🏆 🚫 ⚙️ 👉 ⚖️ 🙆 **📄 🔁** 💪.
|
|
||||||
|
|
||||||
, ⚫️ ⚠ 🚮 👉 **🏘 🔚** `Dockerfile`, 🔬 📦 🖼 🏗 🕰.
|
|
||||||
|
|
||||||
6️⃣. ⚒ **📋** 🏃 `uvicorn` 💽.
|
|
||||||
|
|
||||||
`CMD` ✊ 📇 🎻, 🔠 👫 🎻 ⚫️❔ 👆 🔜 🆎 📋 ⏸ 👽 🚀.
|
|
||||||
|
|
||||||
👉 📋 🔜 🏃 ⚪️➡️ **⏮️ 👷 📁**, 🎏 `/code` 📁 👆 ⚒ 🔛 ⏮️ `WORKDIR /code`.
|
|
||||||
|
|
||||||
↩️ 📋 🔜 ▶️ `/code` & 🔘 ⚫️ 📁 `./app` ⏮️ 👆 📟, **Uvicorn** 🔜 💪 👀 & **🗄** `app` ⚪️➡️ `app.main`.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📄 ⚫️❔ 🔠 ⏸ 🔨 🖊 🔠 🔢 💭 📟. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 🔜 🔜 ✔️ 📁 📊 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
.
|
|
||||||
├── app
|
|
||||||
│ ├── __init__.py
|
|
||||||
│ └── main.py
|
|
||||||
├── Dockerfile
|
|
||||||
└── requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ⛅ 🤝 ❎ 🗳
|
|
||||||
|
|
||||||
🚥 👆 🏃♂ 👆 📦 ⛅ 🤝 ❎ 🗳 (📐 ⚙) 💖 👌 ⚖️ Traefik, 🚮 🎛 `--proxy-headers`, 👉 🔜 💬 Uvicorn 💙 🎚 📨 👈 🗳 💬 ⚫️ 👈 🈸 🏃 ⛅ 🇺🇸🔍, ♒️.
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ☁ 💾
|
|
||||||
|
|
||||||
📤 ⚠ 🎱 👉 `Dockerfile`, 👥 🥇 📁 **📁 ⏮️ 🔗 😞**, 🚫 🎂 📟. ➡️ 👤 💬 👆 ⚫️❔ 👈.
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
COPY ./requirements.txt /code/requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
☁ & 🎏 🧰 **🏗** 👉 📦 🖼 **🔁**, 🚮 **1️⃣ 🧽 🔛 🔝 🎏**, ▶️ ⚪️➡️ 🔝 `Dockerfile` & ❎ 🙆 📁 ✍ 🔠 👩🌾 `Dockerfile`.
|
|
||||||
|
|
||||||
☁ & 🎏 🧰 ⚙️ **🔗 💾** 🕐❔ 🏗 🖼, 🚥 📁 🚫 🔀 ↩️ 🏁 🕰 🏗 📦 🖼, ⤴️ ⚫️ 🔜 **🏤-⚙️ 🎏 🧽** ✍ 🏁 🕰, ↩️ 🖨 📁 🔄 & 🏗 🆕 🧽 ⚪️➡️ 🖌.
|
|
||||||
|
|
||||||
❎ 📁 📁 🚫 🎯 📉 👜 💁♂️ 🌅, ✋️ ↩️ ⚫️ ⚙️ 💾 👈 🔁, ⚫️ 💪 **⚙️ 💾 ⏭ 🔁**. 🖼, ⚫️ 💪 ⚙️ 💾 👩🌾 👈 ❎ 🔗 ⏮️:
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
📁 ⏮️ 📦 📄 **🏆 🚫 🔀 🛎**. , 🖨 🕴 👈 📁, ☁ 🔜 💪 **⚙️ 💾** 👈 🔁.
|
|
||||||
|
|
||||||
& ⤴️, ☁ 🔜 💪 **⚙️ 💾 ⏭ 🔁** 👈 ⏬ & ❎ 👈 🔗. & 📥 🌐❔ 👥 **🖊 📚 🕰**. 👶 ...& ❎ 😩 ⌛. 👶 👶
|
|
||||||
|
|
||||||
⏬ & ❎ 📦 🔗 **💪 ✊ ⏲**, ✋️ ⚙️ **💾** 🔜 **✊ 🥈** 🌅.
|
|
||||||
|
|
||||||
& 👆 🔜 🏗 📦 🖼 🔄 & 🔄 ⏮️ 🛠️ ✅ 👈 👆 📟 🔀 👷, 📤 📚 📈 🕰 👉 🔜 🖊.
|
|
||||||
|
|
||||||
⤴️, 🏘 🔚 `Dockerfile`, 👥 📁 🌐 📟. 👉 ⚫️❔ **🔀 🏆 🛎**, 👥 🚮 ⚫️ 🏘 🔚, ↩️ 🌖 🕧, 🕳 ⏮️ 👉 🔁 🔜 🚫 💪 ⚙️ 💾.
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
COPY ./app /code/app
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🏗 ☁ 🖼
|
|
||||||
|
|
||||||
🔜 👈 🌐 📁 🥉, ➡️ 🏗 📦 🖼.
|
|
||||||
|
|
||||||
* 🚶 🏗 📁 (🌐❔ 👆 `Dockerfile` , ⚗ 👆 `app` 📁).
|
|
||||||
* 🏗 👆 FastAPI 🖼:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ docker build -t myimage .
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 `.` 🔚, ⚫️ 🌓 `./`, ⚫️ 💬 ☁ 📁 ⚙️ 🏗 📦 🖼.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🎏 ⏮️ 📁 (`.`).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ▶️ ☁ 📦
|
|
||||||
|
|
||||||
* 🏃 📦 ⚓️ 🔛 👆 🖼:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ docker run -d --name mycontainer -p 80:80 myimage
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## ✅ ⚫️
|
|
||||||
|
|
||||||
👆 🔜 💪 ✅ ⚫️ 👆 ☁ 📦 📛, 🖼: <a href="http://192.168.99.100/items/5?q=somequery" class="external-link" target="_blank">http://192.168.99.100/items/5?q=somequery</a> ⚖️ <a href="http://127.0.0.1/items/5?q=somequery" class="external-link" target="_blank">http://127.0.0.1/items/5?q=somequery</a> (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).
|
|
||||||
|
|
||||||
👆 🔜 👀 🕳 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"item_id": 5, "q": "somequery"}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🎓 🛠️ 🩺
|
|
||||||
|
|
||||||
🔜 👆 💪 🚶 <a href="http://192.168.99.100/docs" class="external-link" target="_blank">http://192.168.99.100/docs</a> ⚖️ <a href="http://127.0.0.1/docs" class="external-link" target="_blank">http://127.0.0.1/docs</a> (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🎓 🛠️ 🧾 (🚚 <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">🦁 🎚</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 🎛 🛠️ 🩺
|
|
||||||
|
|
||||||
& 👆 💪 🚶 <a href="http://192.168.99.100/redoc" class="external-link" target="_blank">http://192.168.99.100/redoc</a> ⚖️ <a href="http://127.0.0.1/redoc" class="external-link" target="_blank">http://127.0.0.1/redoc</a> (⚖️ 🌓, ⚙️ 👆 ☁ 🦠).
|
|
||||||
|
|
||||||
👆 🔜 👀 🎛 🏧 🧾 (🚚 <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">📄</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 🏗 ☁ 🖼 ⏮️ 👁-📁 FastAPI
|
|
||||||
|
|
||||||
🚥 👆 FastAPI 👁 📁, 🖼, `main.py` 🍵 `./app` 📁, 👆 📁 📊 💪 👀 💖 👉:
|
|
||||||
|
|
||||||
```
|
|
||||||
.
|
|
||||||
├── Dockerfile
|
|
||||||
├── main.py
|
|
||||||
└── requirements.txt
|
|
||||||
```
|
|
||||||
|
|
||||||
⤴️ 👆 🔜 ✔️ 🔀 🔗 ➡ 📁 📁 🔘 `Dockerfile`:
|
|
||||||
|
|
||||||
```{ .dockerfile .annotate hl_lines="10 13" }
|
|
||||||
FROM python:3.9
|
|
||||||
|
|
||||||
WORKDIR /code
|
|
||||||
|
|
||||||
COPY ./requirements.txt /code/requirements.txt
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
||||||
|
|
||||||
# (1)
|
|
||||||
COPY ./main.py /code/
|
|
||||||
|
|
||||||
# (2)
|
|
||||||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
```
|
|
||||||
|
|
||||||
1️⃣. 📁 `main.py` 📁 `/code` 📁 🔗 (🍵 🙆 `./app` 📁).
|
|
||||||
|
|
||||||
2️⃣. 🏃 Uvicorn & 💬 ⚫️ 🗄 `app` 🎚 ⚪️➡️ `main` (↩️ 🏭 ⚪️➡️ `app.main`).
|
|
||||||
|
|
||||||
⤴️ 🔆 Uvicorn 📋 ⚙️ 🆕 🕹 `main` ↩️ `app.main` 🗄 FastAPI 🎚 `app`.
|
|
||||||
|
|
||||||
## 🛠️ 🔧
|
|
||||||
|
|
||||||
➡️ 💬 🔄 🔃 🎏 [🛠️ 🔧](concepts.md){.internal-link target=_blank} ⚖ 📦.
|
|
||||||
|
|
||||||
📦 ✴️ 🧰 📉 🛠️ **🏗 & 🛠️** 🈸, ✋️ 👫 🚫 🛠️ 🎯 🎯 🍵 👉 **🛠️ 🔧**, & 📤 📚 💪 🎛.
|
|
||||||
|
|
||||||
**👍 📰** 👈 ⏮️ 🔠 🎏 🎛 📤 🌌 📔 🌐 🛠️ 🔧. 👶
|
|
||||||
|
|
||||||
➡️ 📄 👉 **🛠️ 🔧** ⚖ 📦:
|
|
||||||
|
|
||||||
* 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
## 🇺🇸🔍
|
|
||||||
|
|
||||||
🚥 👥 🎯 🔛 **📦 🖼** FastAPI 🈸 (& ⏪ 🏃♂ **📦**), 🇺🇸🔍 🛎 🔜 🍵 **🗜** ➕1️⃣ 🧰.
|
|
||||||
|
|
||||||
⚫️ 💪 ➕1️⃣ 📦, 🖼 ⏮️ <a href="https://traefik.io/" class="external-link" target="_blank">Traefik</a>, 🚚 **🇺🇸🔍** & **🏧** 🛠️ **📄**.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Traefik ✔️ 🛠️ ⏮️ ☁, Kubernetes, & 🎏, ⚫️ 📶 ⏩ ⚒ 🆙 & 🔗 🇺🇸🔍 👆 📦 ⏮️ ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👐, 🇺🇸🔍 💪 🍵 ☁ 🐕🦺 1️⃣ 👫 🐕🦺 (⏪ 🏃 🈸 📦).
|
|
||||||
|
|
||||||
## 🏃♂ 🔛 🕴 & ⏏
|
|
||||||
|
|
||||||
📤 🛎 ➕1️⃣ 🧰 🈚 **▶️ & 🏃♂** 👆 📦.
|
|
||||||
|
|
||||||
⚫️ 💪 **☁** 🔗, **☁ ✍**, **Kubernetes**, **☁ 🐕🦺**, ♒️.
|
|
||||||
|
|
||||||
🌅 (⚖️ 🌐) 💼, 📤 🙅 🎛 🛠️ 🏃 📦 🔛 🕴 & 🛠️ ⏏ 🔛 ❌. 🖼, ☁, ⚫️ 📋 ⏸ 🎛 `--restart`.
|
|
||||||
|
|
||||||
🍵 ⚙️ 📦, ⚒ 🈸 🏃 🔛 🕴 & ⏮️ ⏏ 💪 ⚠ & ⚠. ✋️ 🕐❔ **👷 ⏮️ 📦** 🌅 💼 👈 🛠️ 🔌 🔢. 👶
|
|
||||||
|
|
||||||
## 🧬 - 🔢 🛠️
|
|
||||||
|
|
||||||
🚥 👆 ✔️ <abbr title="A group of machines that are configured to be connected and work together in some way.">🌑</abbr> 🎰 ⏮️ **☁**, ☁ 🐝 📳, 🖖, ⚖️ ➕1️⃣ 🎏 🏗 ⚙️ 🛠️ 📎 📦 🔛 💗 🎰, ⤴️ 👆 🔜 🎲 💚 **🍵 🧬** **🌑 🎚** ↩️ ⚙️ **🛠️ 👨💼** (💖 🐁 ⏮️ 👨🏭) 🔠 📦.
|
|
||||||
|
|
||||||
1️⃣ 📚 📎 📦 🧾 ⚙️ 💖 Kubernetes 🛎 ✔️ 🛠️ 🌌 🚚 **🧬 📦** ⏪ 🔗 **📐 ⚖** 📨 📨. 🌐 **🌑 🎚**.
|
|
||||||
|
|
||||||
📚 💼, 👆 🔜 🎲 💚 🏗 **☁ 🖼 ⚪️➡️ 🖌** [🔬 🔛](#_6), ❎ 👆 🔗, & 🏃♂ **👁 Uvicorn 🛠️** ↩️ 🏃♂ 🕳 💖 🐁 ⏮️ Uvicorn 👨🏭.
|
|
||||||
|
|
||||||
### 📐 ⚙
|
|
||||||
|
|
||||||
🕐❔ ⚙️ 📦, 👆 🔜 🛎 ✔️ 🦲 **👂 🔛 👑 ⛴**. ⚫️ 💪 🎲 ➕1️⃣ 📦 👈 **🤝 ❎ 🗳** 🍵 **🇺🇸🔍** ⚖️ 🎏 🧰.
|
|
||||||
|
|
||||||
👉 🦲 🔜 ✊ **📐** 📨 & 📎 👈 👪 👨🏭 (🤞) **⚖** 🌌, ⚫️ 🛎 🤙 **📐 ⚙**.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🎏 **🤝 ❎ 🗳** 🦲 ⚙️ 🇺🇸🔍 🔜 🎲 **📐 ⚙**.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& 🕐❔ 👷 ⏮️ 📦, 🎏 ⚙️ 👆 ⚙️ ▶️ & 🛠️ 👫 🔜 ⏪ ✔️ 🔗 🧰 📶 **🕸 📻** (✅ 🇺🇸🔍 📨) ⚪️➡️ 👈 **📐 ⚙** (👈 💪 **🤝 ❎ 🗳**) 📦(Ⓜ) ⏮️ 👆 📱.
|
|
||||||
|
|
||||||
### 1️⃣ 📐 ⚙ - 💗 👨🏭 📦
|
|
||||||
|
|
||||||
🕐❔ 👷 ⏮️ **Kubernetes** ⚖️ 🎏 📎 📦 🧾 ⚙️, ⚙️ 👫 🔗 🕸 🛠️ 🔜 ✔ 👁 **📐 ⚙** 👈 👂 🔛 👑 **⛴** 📶 📻 (📨) 🎲 **💗 📦** 🏃 👆 📱.
|
|
||||||
|
|
||||||
🔠 👫 📦 🏃♂ 👆 📱 🔜 🛎 ✔️ **1️⃣ 🛠️** (✅ Uvicorn 🛠️ 🏃 👆 FastAPI 🈸). 👫 🔜 🌐 **🌓 📦**, 🏃♂ 🎏 👜, ✋️ 🔠 ⏮️ 🚮 👍 🛠️, 💾, ♒️. 👈 🌌 👆 🔜 ✊ 📈 **🛠️** **🎏 🐚** 💽, ⚖️ **🎏 🎰**.
|
|
||||||
|
|
||||||
& 📎 📦 ⚙️ ⏮️ **📐 ⚙** 🔜 **📎 📨** 🔠 1️⃣ 📦 ⏮️ 👆 📱 **🔄**. , 🔠 📨 💪 🍵 1️⃣ 💗 **🔁 📦** 🏃 👆 📱.
|
|
||||||
|
|
||||||
& 🛎 👉 **📐 ⚙** 🔜 💪 🍵 📨 👈 🚶 *🎏* 📱 👆 🌑 (✅ 🎏 🆔, ⚖️ 🔽 🎏 📛 ➡ 🔡), & 🔜 📶 👈 📻 ▶️️ 📦 *👈 🎏* 🈸 🏃♂ 👆 🌑.
|
|
||||||
|
|
||||||
### 1️⃣ 🛠️ 📍 📦
|
|
||||||
|
|
||||||
👉 🆎 😐, 👆 🎲 🔜 💚 ✔️ **👁 (Uvicorn) 🛠️ 📍 📦**, 👆 🔜 ⏪ 🚚 🧬 🌑 🎚.
|
|
||||||
|
|
||||||
, 👉 💼, 👆 **🔜 🚫** 💚 ✔️ 🛠️ 👨💼 💖 🐁 ⏮️ Uvicorn 👨🏭, ⚖️ Uvicorn ⚙️ 🚮 👍 Uvicorn 👨🏭. 👆 🔜 💚 ✔️ **👁 Uvicorn 🛠️** 📍 📦 (✋️ 🎲 💗 📦).
|
|
||||||
|
|
||||||
✔️ ➕1️⃣ 🛠️ 👨💼 🔘 📦 (🔜 ⏮️ 🐁 ⚖️ Uvicorn 🛠️ Uvicorn 👨🏭) 🔜 🕴 🚮 **🙃 🔀** 👈 👆 🌅 🎲 ⏪ ✊ 💅 ⏮️ 👆 🌑 ⚙️.
|
|
||||||
|
|
||||||
### 📦 ⏮️ 💗 🛠️ & 🎁 💼
|
|
||||||
|
|
||||||
↗️, 📤 **🎁 💼** 🌐❔ 👆 💪 💚 ✔️ **📦** ⏮️ **🐁 🛠️ 👨💼** ▶️ 📚 **Uvicorn 👨🏭 🛠️** 🔘.
|
|
||||||
|
|
||||||
📚 💼, 👆 💪 ⚙️ **🛂 ☁ 🖼** 👈 🔌 **🐁** 🛠️ 👨💼 🏃♂ 💗 **Uvicorn 👨🏭 🛠️**, & 🔢 ⚒ 🔆 🔢 👨🏭 ⚓️ 🔛 ⏮️ 💽 🐚 🔁. 👤 🔜 💬 👆 🌅 🔃 ⚫️ 🔛 [🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn](#-uvicorn).
|
|
||||||
|
|
||||||
📥 🖼 🕐❔ 👈 💪 ⚒ 🔑:
|
|
||||||
|
|
||||||
#### 🙅 📱
|
|
||||||
|
|
||||||
👆 💪 💚 🛠️ 👨💼 📦 🚥 👆 🈸 **🙅 🥃** 👈 👆 🚫 💪 (🐥 🚫) 👌-🎶 🔢 🛠️ 💁♂️ 🌅, & 👆 💪 ⚙️ 🏧 🔢 (⏮️ 🛂 ☁ 🖼), & 👆 🏃♂ ⚫️ 🔛 **👁 💽**, 🚫 🌑.
|
|
||||||
|
|
||||||
#### ☁ ✍
|
|
||||||
|
|
||||||
👆 💪 🛠️ **👁 💽** (🚫 🌑) ⏮️ **☁ ✍**, 👆 🚫🔜 ✔️ ⏩ 🌌 🛠️ 🧬 📦 (⏮️ ☁ ✍) ⏪ 🛡 🔗 🕸 & **📐 ⚖**.
|
|
||||||
|
|
||||||
⤴️ 👆 💪 💚 ✔️ **👁 📦** ⏮️ **🛠️ 👨💼** ▶️ **📚 👨🏭 🛠️** 🔘.
|
|
||||||
|
|
||||||
#### 🤴 & 🎏 🤔
|
|
||||||
|
|
||||||
👆 💪 ✔️ **🎏 🤔** 👈 🔜 ⚒ ⚫️ ⏩ ✔️ **👁 📦** ⏮️ **💗 🛠️** ↩️ ✔️ **💗 📦** ⏮️ **👁 🛠️** 🔠 👫.
|
|
||||||
|
|
||||||
🖼 (🪀 🔛 👆 🖥) 👆 💪 ✔️ 🧰 💖 🤴 🏭 🎏 📦 👈 🔜 ✔️ 🔐 **🔠 📨** 👈 👟.
|
|
||||||
|
|
||||||
👉 💼, 🚥 👆 ✔️ **💗 📦**, 🔢, 🕐❔ 🤴 👟 **✍ ⚖**, ⚫️ 🔜 🤚 🕐 **👁 📦 🔠 🕰** (📦 👈 🍵 👈 🎯 📨), ↩️ 🤚 **📈 ⚖** 🌐 🔁 📦.
|
|
||||||
|
|
||||||
⤴️, 👈 💼, ⚫️ 💪 🙅 ✔️ **1️⃣ 📦** ⏮️ **💗 🛠️**, & 🇧🇿 🧰 (✅ 🤴 🏭) 🔛 🎏 📦 📈 🤴 ⚖ 🌐 🔗 🛠️ & 🎦 👈 ⚖ 🔛 👈 👁 📦.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👑 ☝, **👌** 👉 **🚫 ✍ 🗿** 👈 👆 ✔️ 😄 ⏩. 👆 💪 ⚙️ 👫 💭 **🔬 👆 👍 ⚙️ 💼** & 💭 ⚫️❔ 👍 🎯 👆 ⚙️, ✅ 👅 ❔ 🛠️ 🔧:
|
|
||||||
|
|
||||||
* 💂♂ - 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
## 💾
|
|
||||||
|
|
||||||
🚥 👆 🏃 **👁 🛠️ 📍 📦** 👆 🔜 ✔️ 🌅 ⚖️ 🌘 👍-🔬, ⚖, & 📉 💸 💾 🍴 🔠 👈 📦 (🌅 🌘 1️⃣ 🚥 👫 🔁).
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 ⚒ 👈 🎏 💾 📉 & 📄 👆 📳 👆 📦 🧾 ⚙️ (🖼 **Kubernetes**). 👈 🌌 ⚫️ 🔜 💪 **🔁 📦** **💪 🎰** ✊ 🔘 🏧 💸 💾 💪 👫, & 💸 💪 🎰 🌑.
|
|
||||||
|
|
||||||
🚥 👆 🈸 **🙅**, 👉 🔜 🎲 **🚫 ⚠**, & 👆 💪 🚫 💪 ✔ 🏋️ 💾 📉. ✋️ 🚥 👆 **⚙️ 📚 💾** (🖼 ⏮️ **🎰 🏫** 🏷), 👆 🔜 ✅ ❔ 🌅 💾 👆 😩 & 🔆 **🔢 📦** 👈 🏃 **🔠 🎰** (& 🎲 🚮 🌖 🎰 👆 🌑).
|
|
||||||
|
|
||||||
🚥 👆 🏃 **💗 🛠️ 📍 📦** (🖼 ⏮️ 🛂 ☁ 🖼) 👆 🔜 ✔️ ⚒ 💭 👈 🔢 🛠️ ▶️ 🚫 **🍴 🌖 💾** 🌘 ⚫️❔ 💪.
|
|
||||||
|
|
||||||
## ⏮️ 🔁 ⏭ ▶️ & 📦
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 📦 (✅ ☁, Kubernetes), ⤴️ 📤 2️⃣ 👑 🎯 👆 💪 ⚙️.
|
|
||||||
|
|
||||||
### 💗 📦
|
|
||||||
|
|
||||||
🚥 👆 ✔️ **💗 📦**, 🎲 🔠 1️⃣ 🏃 **👁 🛠️** (🖼, **Kubernetes** 🌑), ⤴️ 👆 🔜 🎲 💚 ✔️ **🎏 📦** 🔨 👷 **⏮️ 📶** 👁 📦, 🏃 👁 🛠️, **⏭** 🏃 🔁 👨🏭 📦.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ Kubernetes, 👉 🔜 🎲 <a href="https://kubernetes.io/docs/concepts/workloads/pods/init-containers/" class="external-link" target="_blank">🕑 📦</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 💼 📤 🙅♂ ⚠ 🏃♂ 👈 ⏮️ 📶 **💗 🕰 🔗** (🖼 🚥 👆 🚫 🏃 💽 🛠️, ✋️ ✅ 🚥 💽 🔜), ⤴️ 👆 💪 🚮 👫 🔠 📦 ▶️️ ⏭ ▶️ 👑 🛠️.
|
|
||||||
|
|
||||||
### 👁 📦
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🙅 🖥, ⏮️ **👁 📦** 👈 ⤴️ ▶️ 💗 **👨🏭 🛠️** (⚖️ 1️⃣ 🛠️), ⤴️ 👆 💪 🏃 👈 ⏮️ 🔁 🎏 📦, ▶️️ ⏭ ▶️ 🛠️ ⏮️ 📱. 🛂 ☁ 🖼 🐕🦺 👉 🔘.
|
|
||||||
|
|
||||||
## 🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn
|
|
||||||
|
|
||||||
📤 🛂 ☁ 🖼 👈 🔌 🐁 🏃♂ ⏮️ Uvicorn 👨🏭, ℹ ⏮️ 📃: [💽 👨🏭 - 🐁 ⏮️ Uvicorn](server-workers.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👉 🖼 🔜 ⚠ ✴️ ⚠ 🔬 🔛: [📦 ⏮️ 💗 🛠️ & 🎁 💼](#_18).
|
|
||||||
|
|
||||||
* <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker" class="external-link" target="_blank">tiangolo/uvicorn-🐁-fastapi</a>.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
📤 ↕ 🤞 👈 👆 **🚫** 💪 👉 🧢 🖼 ⚖️ 🙆 🎏 🎏 1️⃣, & 🔜 👻 📆 🏗 🖼 ⚪️➡️ 🖌 [🔬 🔛: 🏗 ☁ 🖼 FastAPI](#fastapi).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👉 🖼 ✔️ **🚘-📳** 🛠️ 🔌 ⚒ **🔢 👨🏭 🛠️** ⚓️ 🔛 💽 🐚 💪.
|
|
||||||
|
|
||||||
⚫️ ✔️ **🤔 🔢**, ✋️ 👆 💪 🔀 & ℹ 🌐 📳 ⏮️ **🌐 🔢** ⚖️ 📳 📁.
|
|
||||||
|
|
||||||
⚫️ 🐕🦺 🏃 <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker#pre_start_path" class="external-link" target="_blank">**⏮️ 🔁 ⏭ ▶️**</a> ⏮️ ✍.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 🌐 📳 & 🎛, 🚶 ☁ 🖼 📃: <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker" class="external-link" target="_blank">Tiangolo/uvicorn-🐁-fastapi</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔢 🛠️ 🔛 🛂 ☁ 🖼
|
|
||||||
|
|
||||||
**🔢 🛠️** 🔛 👉 🖼 **📊 🔁** ⚪️➡️ 💽 **🐚** 💪.
|
|
||||||
|
|
||||||
👉 ⛓ 👈 ⚫️ 🔜 🔄 **🗜** 🌅 **🎭** ⚪️➡️ 💽 💪.
|
|
||||||
|
|
||||||
👆 💪 🔆 ⚫️ ⏮️ 📳 ⚙️ **🌐 🔢**, ♒️.
|
|
||||||
|
|
||||||
✋️ ⚫️ ⛓ 👈 🔢 🛠️ 🪀 🔛 💽 📦 🏃, **💸 💾 🍴** 🔜 🪀 🔛 👈.
|
|
||||||
|
|
||||||
, 🚥 👆 🈸 🍴 📚 💾 (🖼 ⏮️ 🎰 🏫 🏷), & 👆 💽 ✔️ 📚 💽 🐚 **✋️ 🐥 💾**, ⤴️ 👆 📦 💪 🔚 🆙 🔄 ⚙️ 🌅 💾 🌘 ⚫️❔ 💪, & 🤕 🎭 📚 (⚖️ 💥). 👶
|
|
||||||
|
|
||||||
### ✍ `Dockerfile`
|
|
||||||
|
|
||||||
📥 ❔ 👆 🔜 ✍ `Dockerfile` ⚓️ 🔛 👉 🖼:
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
|
||||||
|
|
||||||
COPY ./requirements.txt /app/requirements.txt
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
|
||||||
|
|
||||||
COPY ./app /app
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🦏 🈸
|
|
||||||
|
|
||||||
🚥 👆 ⏩ 📄 🔃 🏗 [🦏 🈸 ⏮️ 💗 📁](../tutorial/bigger-applications.md){.internal-link target=_blank}, 👆 `Dockerfile` 💪 ↩️ 👀 💖:
|
|
||||||
|
|
||||||
```Dockerfile hl_lines="7"
|
|
||||||
FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9
|
|
||||||
|
|
||||||
COPY ./requirements.txt /app/requirements.txt
|
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt
|
|
||||||
|
|
||||||
COPY ./app /app/app
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🕐❔ ⚙️
|
|
||||||
|
|
||||||
👆 🔜 🎲 **🚫** ⚙️ 👉 🛂 🧢 🖼 (⚖️ 🙆 🎏 🎏 1️⃣) 🚥 👆 ⚙️ **Kubernetes** (⚖️ 🎏) & 👆 ⏪ ⚒ **🧬** 🌑 🎚, ⏮️ 💗 **📦**. 📚 💼, 👆 👍 📆 **🏗 🖼 ⚪️➡️ 🖌** 🔬 🔛: [🏗 ☁ 🖼 FastAPI](#fastapi).
|
|
||||||
|
|
||||||
👉 🖼 🔜 ⚠ ✴️ 🎁 💼 🔬 🔛 [📦 ⏮️ 💗 🛠️ & 🎁 💼](#_18). 🖼, 🚥 👆 🈸 **🙅 🥃** 👈 ⚒ 🔢 🔢 🛠️ ⚓️ 🔛 💽 👷 👍, 👆 🚫 💚 😥 ⏮️ ❎ 🛠️ 🧬 🌑 🎚, & 👆 🚫 🏃 🌅 🌘 1️⃣ 📦 ⏮️ 👆 📱. ⚖️ 🚥 👆 🛠️ ⏮️ **☁ ✍**, 🏃 🔛 👁 💽, ♒️.
|
|
||||||
|
|
||||||
## 🛠️ 📦 🖼
|
|
||||||
|
|
||||||
⏮️ ✔️ 📦 (☁) 🖼 📤 📚 🌌 🛠️ ⚫️.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
* ⏮️ **☁ ✍** 👁 💽
|
|
||||||
* ⏮️ **Kubernetes** 🌑
|
|
||||||
* ⏮️ ☁ 🐝 📳 🌑
|
|
||||||
* ⏮️ ➕1️⃣ 🧰 💖 🖖
|
|
||||||
* ⏮️ ☁ 🐕🦺 👈 ✊ 👆 📦 🖼 & 🛠️ ⚫️
|
|
||||||
|
|
||||||
## ☁ 🖼 ⏮️ 🎶
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ <a href="https://python-poetry.org/" class="external-link" target="_blank">🎶</a> 🛠️ 👆 🏗 🔗, 👆 💪 ⚙️ ☁ 👁-▶️ 🏗:
|
|
||||||
|
|
||||||
```{ .dockerfile .annotate }
|
|
||||||
# (1)
|
|
||||||
FROM python:3.9 as requirements-stage
|
|
||||||
|
|
||||||
# (2)
|
|
||||||
WORKDIR /tmp
|
|
||||||
|
|
||||||
# (3)
|
|
||||||
RUN pip install poetry
|
|
||||||
|
|
||||||
# (4)
|
|
||||||
COPY ./pyproject.toml ./poetry.lock* /tmp/
|
|
||||||
|
|
||||||
# (5)
|
|
||||||
RUN poetry export -f requirements.txt --output requirements.txt --without-hashes
|
|
||||||
|
|
||||||
# (6)
|
|
||||||
FROM python:3.9
|
|
||||||
|
|
||||||
# (7)
|
|
||||||
WORKDIR /code
|
|
||||||
|
|
||||||
# (8)
|
|
||||||
COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt
|
|
||||||
|
|
||||||
# (9)
|
|
||||||
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
|
||||||
|
|
||||||
# (10)
|
|
||||||
COPY ./app /code/app
|
|
||||||
|
|
||||||
# (11)
|
|
||||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
```
|
|
||||||
|
|
||||||
1️⃣. 👉 🥇 ▶️, ⚫️ 🌟 `requirements-stage`.
|
|
||||||
|
|
||||||
2️⃣. ⚒ `/tmp` ⏮️ 👷 📁.
|
|
||||||
|
|
||||||
📥 🌐❔ 👥 🔜 🏗 📁 `requirements.txt`
|
|
||||||
|
|
||||||
3️⃣. ❎ 🎶 👉 ☁ ▶️.
|
|
||||||
|
|
||||||
4️⃣. 📁 `pyproject.toml` & `poetry.lock` 📁 `/tmp` 📁.
|
|
||||||
|
|
||||||
↩️ ⚫️ ⚙️ `./poetry.lock*` (▶️ ⏮️ `*`), ⚫️ 🏆 🚫 💥 🚥 👈 📁 🚫 💪.
|
|
||||||
|
|
||||||
5️⃣. 🏗 `requirements.txt` 📁.
|
|
||||||
|
|
||||||
6️⃣. 👉 🏁 ▶️, 🕳 📥 🔜 🛡 🏁 📦 🖼.
|
|
||||||
|
|
||||||
7️⃣. ⚒ ⏮️ 👷 📁 `/code`.
|
|
||||||
|
|
||||||
8️⃣. 📁 `requirements.txt` 📁 `/code` 📁.
|
|
||||||
|
|
||||||
👉 📁 🕴 🖖 ⏮️ ☁ ▶️, 👈 ⚫️❔ 👥 ⚙️ `--from-requirements-stage` 📁 ⚫️.
|
|
||||||
|
|
||||||
9️⃣. ❎ 📦 🔗 🏗 `requirements.txt` 📁.
|
|
||||||
|
|
||||||
1️⃣0️⃣. 📁 `app` 📁 `/code` 📁.
|
|
||||||
|
|
||||||
1️⃣1️⃣. 🏃 `uvicorn` 📋, 💬 ⚫️ ⚙️ `app` 🎚 🗄 ⚪️➡️ `app.main`.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🖊 💭 🔢 👀 ⚫️❔ 🔠 ⏸ 🔨.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
**☁ ▶️** 🍕 `Dockerfile` 👈 👷 **🍕 📦 🖼** 👈 🕴 ⚙️ 🏗 📁 ⚙️ ⏪.
|
|
||||||
|
|
||||||
🥇 ▶️ 🔜 🕴 ⚙️ **❎ 🎶** & **🏗 `requirements.txt`** ⏮️ 👆 🏗 🔗 ⚪️➡️ 🎶 `pyproject.toml` 📁.
|
|
||||||
|
|
||||||
👉 `requirements.txt` 📁 🔜 ⚙️ ⏮️ `pip` ⏪ **⏭ ▶️**.
|
|
||||||
|
|
||||||
🏁 📦 🖼 **🕴 🏁 ▶️** 🛡. ⏮️ ▶️(Ⓜ) 🔜 ❎.
|
|
||||||
|
|
||||||
🕐❔ ⚙️ 🎶, ⚫️ 🔜 ⚒ 🔑 ⚙️ **☁ 👁-▶️ 🏗** ↩️ 👆 🚫 🤙 💪 ✔️ 🎶 & 🚮 🔗 ❎ 🏁 📦 🖼, 👆 **🕴 💪** ✔️ 🏗 `requirements.txt` 📁 ❎ 👆 🏗 🔗.
|
|
||||||
|
|
||||||
⤴️ ⏭ (& 🏁) ▶️ 👆 🔜 🏗 🖼 🌅 ⚖️ 🌘 🎏 🌌 🔬 ⏭.
|
|
||||||
|
|
||||||
### ⛅ 🤝 ❎ 🗳 - 🎶
|
|
||||||
|
|
||||||
🔄, 🚥 👆 🏃♂ 👆 📦 ⛅ 🤝 ❎ 🗳 (📐 ⚙) 💖 👌 ⚖️ Traefik, 🚮 🎛 `--proxy-headers` 📋:
|
|
||||||
|
|
||||||
```Dockerfile
|
|
||||||
CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"]
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ 📦 ⚙️ (✅ ⏮️ **☁** & **Kubernetes**) ⚫️ ▶️️ 📶 🎯 🍵 🌐 **🛠️ 🔧**:
|
|
||||||
|
|
||||||
* 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
🌅 💼, 👆 🎲 🏆 🚫 💚 ⚙️ 🙆 🧢 🖼, & ↩️ **🏗 📦 🖼 ⚪️➡️ 🖌** 1️⃣ ⚓️ 🔛 🛂 🐍 ☁ 🖼.
|
|
||||||
|
|
||||||
✊ 💅 **✔** 👩🌾 `Dockerfile` & **☁ 💾** 👆 💪 **📉 🏗 🕰**, 📉 👆 📈 (& ❎ 😩). 👶
|
|
||||||
|
|
||||||
🎯 🎁 💼, 👆 💪 💚 ⚙️ 🛂 ☁ 🖼 FastAPI. 👶
|
|
||||||
|
|
@ -1,199 +0,0 @@
|
||||||
# 🔃 🇺🇸🔍
|
|
||||||
|
|
||||||
⚫️ ⏩ 🤔 👈 🇺🇸🔍 🕳 👈 "🛠️" ⚖️ 🚫.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🌌 🌖 🏗 🌘 👈.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 🏃 ⚖️ 🚫 💅, 😣 ⏮️ ⏭ 📄 🔁 🔁 👩🌾 ⚒ 🌐 🆙 ⏮️ 🎏 ⚒.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
**💡 🔰 🇺🇸🔍**, ⚪️➡️ 🏬 🤔, ✅ <a href="https://howhttps.works/" class="external-link" target="_blank">https://howhttps.works/</a>.
|
|
||||||
|
|
||||||
🔜, ⚪️➡️ **👩💻 🤔**, 📥 📚 👜 ✔️ 🤯 ⏪ 💭 🔃 🇺🇸🔍:
|
|
||||||
|
|
||||||
* 🇺🇸🔍, **💽** 💪 **✔️ "📄"** 🏗 **🥉 🥳**.
|
|
||||||
* 📚 📄 🤙 **🏆** ⚪️➡️ 🥉 🥳, 🚫 "🏗".
|
|
||||||
* 📄 ✔️ **1️⃣2️⃣🗓️**.
|
|
||||||
* 👫 **🕛**.
|
|
||||||
* & ⤴️ 👫 💪 **♻**, **🏆 🔄** ⚪️➡️ 🥉 🥳.
|
|
||||||
* 🔐 🔗 🔨 **🕸 🎚**.
|
|
||||||
* 👈 1️⃣ 🧽 **🔛 🇺🇸🔍**.
|
|
||||||
* , **📄 & 🔐** 🍵 🔨 **⏭ 🇺🇸🔍**.
|
|
||||||
* **🕸 🚫 💭 🔃 "🆔"**. 🕴 🔃 📢 📢.
|
|
||||||
* ℹ 🔃 **🎯 🆔** 📨 🚶 **🇺🇸🔍 💽**.
|
|
||||||
* **🇺🇸🔍 📄** "✔" **🎯 🆔**, ✋️ 🛠️ & 🔐 🔨 🕸 🎚, **⏭ 💭** ❔ 🆔 ➖ 🙅 ⏮️.
|
|
||||||
* **🔢**, 👈 🔜 ⛓ 👈 👆 💪 🕴 ✔️ **1️⃣ 🇺🇸🔍 📄 📍 📢 📢**.
|
|
||||||
* 🙅♂ 🤔 ❔ 🦏 👆 💽 ⚖️ ❔ 🤪 🔠 🈸 👆 ✔️ 🔛 ⚫️ 💪.
|
|
||||||
* 📤 **⚗** 👉, 👐.
|
|
||||||
* 📤 **↔** **🤝** 🛠️ (1️⃣ 🚚 🔐 🕸 🎚, ⏭ 🇺🇸🔍) 🤙 **<a href="https://en.wikipedia.org/wiki/Server_Name_Indication" class="external-link" target="_blank"><abbr title="Server Name Indication">👲</abbr></a>**.
|
|
||||||
* 👉 👲 ↔ ✔ 1️⃣ 👁 💽 (⏮️ **👁 📢 📢**) ✔️ **📚 🇺🇸🔍 📄** & 🍦 **💗 🇺🇸🔍 🆔/🈸**.
|
|
||||||
* 👉 👷, **👁** 🦲 (📋) 🏃 🔛 💽, 👂 🔛 **📢 📢 📢**, 🔜 ✔️ **🌐 🇺🇸🔍 📄** 💽.
|
|
||||||
* **⏮️** 🏆 🔐 🔗, 📻 🛠️ **🇺🇸🔍**.
|
|
||||||
* 🎚 **🗜**, ✋️ 👫 ➖ 📨 ⏮️ **🇺🇸🔍 🛠️**.
|
|
||||||
|
|
||||||
⚫️ ⚠ 💡 ✔️ **1️⃣ 📋/🇺🇸🔍 💽** 🏃 🔛 💽 (🎰, 🦠, ♒️.) & **🛠️ 🌐 🇺🇸🔍 🍕**: 📨 **🗜 🇺🇸🔍 📨**, 📨 **🗜 🇺🇸🔍 📨** ☑ 🇺🇸🔍 🈸 🏃 🎏 💽 ( **FastAPI** 🈸, 👉 💼), ✊ **🇺🇸🔍 📨** ⚪️➡️ 🈸, **🗜 ⚫️** ⚙️ ☑ **🇺🇸🔍 📄** & 📨 ⚫️ 🔙 👩💻 ⚙️ **🇺🇸🔍**. 👉 💽 🛎 🤙 **<a href="https://en.wikipedia.org/wiki/TLS_termination_proxy" class="external-link" target="_blank">🤝 ❎ 🗳</a>**.
|
|
||||||
|
|
||||||
🎛 👆 💪 ⚙️ 🤝 ❎ 🗳:
|
|
||||||
|
|
||||||
* Traefik (👈 💪 🍵 📄 🔕)
|
|
||||||
* 📥 (👈 💪 🍵 📄 🔕)
|
|
||||||
* 👌
|
|
||||||
* ✳
|
|
||||||
|
|
||||||
## ➡️ 🗜
|
|
||||||
|
|
||||||
⏭ ➡️ 🗜, 👫 **🇺🇸🔍 📄** 💲 💙 🥉 🥳.
|
|
||||||
|
|
||||||
🛠️ 📎 1️⃣ 👫 📄 ⚙️ ⚠, 🚚 📠 & 📄 😥.
|
|
||||||
|
|
||||||
✋️ ⤴️ **<a href="https://letsencrypt.org/" class="external-link" target="_blank">➡️ 🗜</a>** ✍.
|
|
||||||
|
|
||||||
⚫️ 🏗 ⚪️➡️ 💾 🏛. ⚫️ 🚚 **🇺🇸🔍 📄 🆓**, 🏧 🌌. 👫 📄 ⚙️ 🌐 🐩 🔐 💂♂, & 📏-🖖 (🔃 3️⃣ 🗓️), **💂♂ 🤙 👍** ↩️ 👫 📉 🔆.
|
|
||||||
|
|
||||||
🆔 🔐 ✔ & 📄 🏗 🔁. 👉 ✔ 🏧 🔕 👫 📄.
|
|
||||||
|
|
||||||
💭 🏧 🛠️ & 🔕 👫 📄 👈 👆 💪 ✔️ **🔐 🇺🇸🔍, 🆓, ♾**.
|
|
||||||
|
|
||||||
## 🇺🇸🔍 👩💻
|
|
||||||
|
|
||||||
📥 🖼 ❔ 🇺🇸🔍 🛠️ 💪 👀 💖, 🔁 🔁, 💸 🙋 ✴️ 💭 ⚠ 👩💻.
|
|
||||||
|
|
||||||
### 🆔 📛
|
|
||||||
|
|
||||||
⚫️ 🔜 🎲 🌐 ▶️ 👆 **🏗** **🆔 📛**. ⤴️, 👆 🔜 🔗 ⚫️ 🏓 💽 (🎲 👆 🎏 ☁ 🐕🦺).
|
|
||||||
|
|
||||||
👆 🔜 🎲 🤚 ☁ 💽 (🕹 🎰) ⚖️ 🕳 🎏, & ⚫️ 🔜 ✔️ <abbr title="That doesn't change">🔧</abbr> **📢 📢 📢**.
|
|
||||||
|
|
||||||
🏓 💽(Ⓜ) 👆 🔜 🔗 ⏺ ("`A record`") ☝ **👆 🆔** 📢 **📢 📢 👆 💽**.
|
|
||||||
|
|
||||||
👆 🔜 🎲 👉 🕐, 🥇 🕰, 🕐❔ ⚒ 🌐 🆙.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 🆔 📛 🍕 🌌 ⏭ 🇺🇸🔍, ✋️ 🌐 🪀 🔛 🆔 & 📢 📢, ⚫️ 💸 💬 ⚫️ 📥.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🏓
|
|
||||||
|
|
||||||
🔜 ➡️ 🎯 🔛 🌐 ☑ 🇺🇸🔍 🍕.
|
|
||||||
|
|
||||||
🥇, 🖥 🔜 ✅ ⏮️ **🏓 💽** ⚫️❔ **📢 🆔**, 👉 💼, `someapp.example.com`.
|
|
||||||
|
|
||||||
🏓 💽 🔜 💬 🖥 ⚙️ 🎯 **📢 📢**. 👈 🔜 📢 📢 📢 ⚙️ 👆 💽, 👈 👆 🔗 🏓 💽.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https01.drawio.svg">
|
|
||||||
|
|
||||||
### 🤝 🤝 ▶️
|
|
||||||
|
|
||||||
🖥 🔜 ⤴️ 🔗 ⏮️ 👈 📢 📢 🔛 **⛴ 4️⃣4️⃣3️⃣** (🇺🇸🔍 ⛴).
|
|
||||||
|
|
||||||
🥇 🍕 📻 🛠️ 🔗 🖖 👩💻 & 💽 & 💭 🔐 🔑 👫 🔜 ⚙️, ♒️.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https02.drawio.svg">
|
|
||||||
|
|
||||||
👉 🔗 🖖 👩💻 & 💽 🛠️ 🤝 🔗 🤙 **🤝 🤝**.
|
|
||||||
|
|
||||||
### 🤝 ⏮️ 👲 ↔
|
|
||||||
|
|
||||||
**🕴 1️⃣ 🛠️** 💽 💪 👂 🔛 🎯 **⛴** 🎯 **📢 📢**. 📤 💪 🎏 🛠️ 👂 🔛 🎏 ⛴ 🎏 📢 📢, ✋️ 🕴 1️⃣ 🔠 🌀 📢 📢 & ⛴.
|
|
||||||
|
|
||||||
🤝 (🇺🇸🔍) ⚙️ 🎯 ⛴ `443` 🔢. 👈 ⛴ 👥 🔜 💪.
|
|
||||||
|
|
||||||
🕴 1️⃣ 🛠️ 💪 👂 🔛 👉 ⛴, 🛠️ 👈 🔜 ⚫️ 🔜 **🤝 ❎ 🗳**.
|
|
||||||
|
|
||||||
🤝 ❎ 🗳 🔜 ✔️ 🔐 1️⃣ ⚖️ 🌅 **🤝 📄** (🇺🇸🔍 📄).
|
|
||||||
|
|
||||||
⚙️ **👲 ↔** 🔬 🔛, 🤝 ❎ 🗳 🔜 ✅ ❔ 🤝 (🇺🇸🔍) 📄 💪 ⚫️ 🔜 ⚙️ 👉 🔗, ⚙️ 1️⃣ 👈 🏏 🆔 📈 👩💻.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🔜 ⚙️ 📄 `someapp.example.com`.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https03.drawio.svg">
|
|
||||||
|
|
||||||
👩💻 ⏪ **💙** 👨💼 👈 🏗 👈 🤝 📄 (👉 💼 ➡️ 🗜, ✋️ 👥 🔜 👀 🔃 👈 ⏪), ⚫️ 💪 **✔** 👈 📄 ☑.
|
|
||||||
|
|
||||||
⤴️, ⚙️ 📄, 👩💻 & 🤝 ❎ 🗳 **💭 ❔ 🗜** 🎂 **🕸 📻**. 👉 🏁 **🤝 🤝** 🍕.
|
|
||||||
|
|
||||||
⏮️ 👉, 👩💻 & 💽 ✔️ **🗜 🕸 🔗**, 👉 ⚫️❔ 🤝 🚚. & ⤴️ 👫 💪 ⚙️ 👈 🔗 ▶️ ☑ **🇺🇸🔍 📻**.
|
|
||||||
|
|
||||||
& 👈 ⚫️❔ **🇺🇸🔍** , ⚫️ ✅ **🇺🇸🔍** 🔘 **🔐 🤝 🔗** ↩️ 😁 (💽) 🕸 🔗.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 🔐 📻 🔨 **🕸 🎚**, 🚫 🇺🇸🔍 🎚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🇺🇸🔍 📨
|
|
||||||
|
|
||||||
🔜 👈 👩💻 & 💽 (🎯 🖥 & 🤝 ❎ 🗳) ✔️ **🗜 🕸 🔗**, 👫 💪 ▶️ **🇺🇸🔍 📻**.
|
|
||||||
|
|
||||||
, 👩💻 📨 **🇺🇸🔍 📨**. 👉 🇺🇸🔍 📨 🔘 🗜 🤝 🔗.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https04.drawio.svg">
|
|
||||||
|
|
||||||
### 🗜 📨
|
|
||||||
|
|
||||||
🤝 ❎ 🗳 🔜 ⚙️ 🔐 ✔ **🗜 📨**, & 🔜 📶 **✅ (🗜) 🇺🇸🔍 📨** 🛠️ 🏃 🈸 (🖼 🛠️ ⏮️ Uvicorn 🏃♂ FastAPI 🈸).
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https05.drawio.svg">
|
|
||||||
|
|
||||||
### 🇺🇸🔍 📨
|
|
||||||
|
|
||||||
🈸 🔜 🛠️ 📨 & 📨 **✅ (💽) 🇺🇸🔍 📨** 🤝 ❎ 🗳.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https06.drawio.svg">
|
|
||||||
|
|
||||||
### 🇺🇸🔍 📨
|
|
||||||
|
|
||||||
🤝 ❎ 🗳 🔜 ⤴️ **🗜 📨** ⚙️ ⚛ ✔ ⏭ (👈 ▶️ ⏮️ 📄 `someapp.example.com`), & 📨 ⚫️ 🔙 🖥.
|
|
||||||
|
|
||||||
⏭, 🖥 🔜 ✔ 👈 📨 ☑ & 🗜 ⏮️ ▶️️ 🔐 🔑, ♒️. ⚫️ 🔜 ⤴️ **🗜 📨** & 🛠️ ⚫️.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https07.drawio.svg">
|
|
||||||
|
|
||||||
👩💻 (🖥) 🔜 💭 👈 📨 👟 ⚪️➡️ ☑ 💽 ↩️ ⚫️ ⚙️ ⚛ 👫 ✔ ⚙️ **🇺🇸🔍 📄** ⏭.
|
|
||||||
|
|
||||||
### 💗 🈸
|
|
||||||
|
|
||||||
🎏 💽 (⚖️ 💽), 📤 💪 **💗 🈸**, 🖼, 🎏 🛠️ 📋 ⚖️ 💽.
|
|
||||||
|
|
||||||
🕴 1️⃣ 🛠️ 💪 🚚 🎯 📢 & ⛴ (🤝 ❎ 🗳 👆 🖼) ✋️ 🎏 🈸/🛠️ 💪 🏃 🔛 💽(Ⓜ) 💁♂️, 📏 👫 🚫 🔄 ⚙️ 🎏 **🌀 📢 📢 & ⛴**.
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https08.drawio.svg">
|
|
||||||
|
|
||||||
👈 🌌, 🤝 ❎ 🗳 💪 🍵 🇺🇸🔍 & 📄 **💗 🆔**, 💗 🈸, & ⤴️ 📶 📨 ▶️️ 🈸 🔠 💼.
|
|
||||||
|
|
||||||
### 📄 🔕
|
|
||||||
|
|
||||||
☝ 🔮, 🔠 📄 🔜 **🕛** (🔃 3️⃣ 🗓️ ⏮️ 🏗 ⚫️).
|
|
||||||
|
|
||||||
& ⤴️, 📤 🔜 ➕1️⃣ 📋 (💼 ⚫️ ➕1️⃣ 📋, 💼 ⚫️ 💪 🎏 🤝 ❎ 🗳) 👈 🔜 💬 ➡️ 🗜, & ♻ 📄(Ⓜ).
|
|
||||||
|
|
||||||
<img src="/img/deployment/https/https.drawio.svg">
|
|
||||||
|
|
||||||
**🤝 📄** **🔗 ⏮️ 🆔 📛**, 🚫 ⏮️ 📢 📢.
|
|
||||||
|
|
||||||
, ♻ 📄, 🔕 📋 💪 **🎦** 🛃 (➡️ 🗜) 👈 ⚫️ 👐 **"👍" & 🎛 👈 🆔**.
|
|
||||||
|
|
||||||
👈, & 🏗 🎏 🈸 💪, 📤 📚 🌌 ⚫️ 💪 ⚫️. 🌟 🌌:
|
|
||||||
|
|
||||||
* **🔀 🏓 ⏺**.
|
|
||||||
* 👉, 🔕 📋 💪 🐕🦺 🔗 🏓 🐕🦺,, ⚓️ 🔛 🏓 🐕🦺 👆 ⚙️, 👉 5️⃣📆 ⚖️ 💪 🚫 🎛.
|
|
||||||
* **🏃 💽** (🌘 ⏮️ 📄 🛠️ 🛠️) 🔛 📢 📢 📢 🔗 ⏮️ 🆔.
|
|
||||||
* 👥 💬 🔛, 🕴 1️⃣ 🛠️ 💪 👂 🔛 🎯 📢 & ⛴.
|
|
||||||
* 👉 1️⃣ 🤔 ⚫️❔ ⚫️ 📶 ⚠ 🕐❔ 🎏 🤝 ❎ 🗳 ✊ 💅 📄 🔕 🛠️.
|
|
||||||
* ⏪, 👆 💪 ✔️ ⛔️ 🤝 ❎ 🗳 😖, ▶️ 🔕 📋 📎 📄, ⤴️ 🔗 👫 ⏮️ 🤝 ❎ 🗳, & ⤴️ ⏏ 🤝 ❎ 🗳. 👉 🚫 💯, 👆 📱(Ⓜ) 🔜 🚫 💪 ⏮️ 🕰 👈 🤝 ❎ 🗳 📆.
|
|
||||||
|
|
||||||
🌐 👉 🔕 🛠️, ⏪ 🍦 📱, 1️⃣ 👑 🤔 ⚫️❔ 👆 🔜 💚 ✔️ **🎏 ⚙️ 🍵 🇺🇸🔍** ⏮️ 🤝 ❎ 🗳 ↩️ ⚙️ 🤝 📄 ⏮️ 🈸 💽 🔗 (✅ Uvicorn).
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
✔️ **🇺🇸🔍** 📶 ⚠, & **🎯** 🏆 💼. 🌅 🎯 👆 👩💻 ✔️ 🚮 🤭 🇺🇸🔍 🔃 **🤔 👉 🔧** & ❔ 👫 👷.
|
|
||||||
|
|
||||||
✋️ 🕐 👆 💭 🔰 ℹ **🇺🇸🔍 👩💻** 👆 💪 💪 🌀 & 🔗 🎏 🧰 ℹ 👆 🛠️ 🌐 🙅 🌌.
|
|
||||||
|
|
||||||
⏭ 📃, 👤 🔜 🎦 👆 📚 🧱 🖼 ❔ ⚒ 🆙 **🇺🇸🔍** **FastAPI** 🈸. 👶
|
|
||||||
|
|
@ -1,21 +0,0 @@
|
||||||
# 🛠️
|
|
||||||
|
|
||||||
🛠️ **FastAPI** 🈸 📶 ⏩.
|
|
||||||
|
|
||||||
## ⚫️❔ 🔨 🛠️ ⛓
|
|
||||||
|
|
||||||
**🛠️** 🈸 ⛓ 🎭 💪 📶 ⚒ ⚫️ **💪 👩💻**.
|
|
||||||
|
|
||||||
**🕸 🛠️**, ⚫️ 🛎 🔌 🚮 ⚫️ **🛰 🎰**, ⏮️ **💽 📋** 👈 🚚 👍 🎭, ⚖, ♒️, 👈 👆 **👩💻** 💪 **🔐** 🈸 ♻ & 🍵 🔁 ⚖️ ⚠.
|
|
||||||
|
|
||||||
👉 🔅 **🛠️** ▶️, 🌐❔ 👆 🕧 🔀 📟, 💔 ⚫️ & ♻ ⚫️, ⛔️ & 🔁 🛠️ 💽, ♒️.
|
|
||||||
|
|
||||||
## 🛠️ 🎛
|
|
||||||
|
|
||||||
📤 📚 🌌 ⚫️ ⚓️ 🔛 👆 🎯 ⚙️ 💼 & 🧰 👈 👆 ⚙️.
|
|
||||||
|
|
||||||
👆 💪 **🛠️ 💽** 👆 ⚙️ 🌀 🧰, 👆 💪 ⚙️ **☁ 🐕🦺** 👈 🔨 🍕 👷 👆, ⚖️ 🎏 💪 🎛.
|
|
||||||
|
|
||||||
👤 🔜 🎦 👆 👑 🔧 👆 🔜 🎲 ✔️ 🤯 🕐❔ 🛠️ **FastAPI** 🈸 (👐 🌅 ⚫️ ✔ 🙆 🎏 🆎 🕸 🈸).
|
|
||||||
|
|
||||||
👆 🔜 👀 🌖 ℹ ✔️ 🤯 & ⚒ ⚫️ ⏭ 📄. 👶
|
|
||||||
|
|
@ -1,159 +0,0 @@
|
||||||
# 🏃 💽 ❎ - Uvicorn
|
|
||||||
|
|
||||||
👑 👜 👆 💪 🏃 **FastAPI** 🈸 🛰 💽 🎰 🔫 💽 📋 💖 **Uvicorn**.
|
|
||||||
|
|
||||||
📤 3️⃣ 👑 🎛:
|
|
||||||
|
|
||||||
* <a href="https://www.uvicorn.dev/" class="external-link" target="_blank">Uvicorn</a>: ↕ 🎭 🔫 💽.
|
|
||||||
* <a href="https://hypercorn.readthedocs.io/" class="external-link" target="_blank">Hypercorn</a>: 🔫 💽 🔗 ⏮️ 🇺🇸🔍/2️⃣ & 🎻 👪 🎏 ⚒.
|
|
||||||
* <a href="https://github.com/django/daphne" class="external-link" target="_blank">👸</a>: 🔫 💽 🏗 ✳ 📻.
|
|
||||||
|
|
||||||
## 💽 🎰 & 💽 📋
|
|
||||||
|
|
||||||
📤 🤪 ℹ 🔃 📛 ✔️ 🤯. 👶
|
|
||||||
|
|
||||||
🔤 "**💽**" 🛎 ⚙️ 🔗 👯♂️ 🛰/☁ 💻 (⚛ ⚖️ 🕹 🎰) & 📋 👈 🏃♂ 🔛 👈 🎰 (✅ Uvicorn).
|
|
||||||
|
|
||||||
✔️ 👈 🤯 🕐❔ 👆 ✍ "💽" 🏢, ⚫️ 💪 🔗 1️⃣ 📚 2️⃣ 👜.
|
|
||||||
|
|
||||||
🕐❔ 🔗 🛰 🎰, ⚫️ ⚠ 🤙 ⚫️ **💽**, ✋️ **🎰**, **💾** (🕹 🎰), **🕸**. 👈 🌐 🔗 🆎 🛰 🎰, 🛎 🏃♂ 💾, 🌐❔ 👆 🏃 📋.
|
|
||||||
|
|
||||||
## ❎ 💽 📋
|
|
||||||
|
|
||||||
👆 💪 ❎ 🔫 🔗 💽 ⏮️:
|
|
||||||
|
|
||||||
//// tab | Uvicorn
|
|
||||||
|
|
||||||
* <a href="https://www.uvicorn.dev/" class="external-link" target="_blank">Uvicorn</a>, 🌩-⏩ 🔫 💽, 🏗 🔛 uvloop & httptool.
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "uvicorn[standard]"
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
❎ `standard`, Uvicorn 🔜 ❎ & ⚙️ 👍 ➕ 🔗.
|
|
||||||
|
|
||||||
👈 ✅ `uvloop`, ↕-🎭 💧-♻ `asyncio`, 👈 🚚 🦏 🛠️ 🎭 📈.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Hypercorn
|
|
||||||
|
|
||||||
* <a href="https://github.com/pgjones/hypercorn" class="external-link" target="_blank">Hypercorn</a>, 🔫 💽 🔗 ⏮️ 🇺🇸🔍/2️⃣.
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install hypercorn
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
...⚖️ 🙆 🎏 🔫 💽.
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
## 🏃 💽 📋
|
|
||||||
|
|
||||||
👆 💪 ⤴️ 🏃 👆 🈸 🎏 🌌 👆 ✔️ ⌛ 🔰, ✋️ 🍵 `--reload` 🎛, ✅:
|
|
||||||
|
|
||||||
//// tab | Uvicorn
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --host 0.0.0.0 --port 80
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://0.0.0.0:80 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | Hypercorn
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ hypercorn main:app --bind 0.0.0.0:80
|
|
||||||
|
|
||||||
Running on 0.0.0.0:8080 over http (CTRL + C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
💭 ❎ `--reload` 🎛 🚥 👆 ⚙️ ⚫️.
|
|
||||||
|
|
||||||
`--reload` 🎛 🍴 🌅 🌅 ℹ, 🌅 ⚠, ♒️.
|
|
||||||
|
|
||||||
⚫️ ℹ 📚 ⏮️ **🛠️**, ✋️ 👆 **🚫🔜 🚫** ⚙️ ⚫️ **🏭**.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## Hypercorn ⏮️ 🎻
|
|
||||||
|
|
||||||
💃 & **FastAPI** ⚓️ 🔛 <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a>, ❔ ⚒ 👫 🔗 ⏮️ 👯♂️ 🐍 🐩 🗃 <a href="https://docs.python.org/3/library/asyncio-task.html" class="external-link" target="_blank">✳</a> & <a href="https://trio.readthedocs.io/en/stable/" class="external-link" target="_blank">🎻</a>.
|
|
||||||
|
|
||||||
👐, Uvicorn ⏳ 🕴 🔗 ⏮️ ✳, & ⚫️ 🛎 ⚙️ <a href="https://github.com/MagicStack/uvloop" class="external-link" target="_blank">`uvloop`</a>, ↕-🎭 💧-♻ `asyncio`.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 💚 🔗 ⚙️ **🎻**, ⤴️ 👆 💪 ⚙️ **Hypercorn** ⚫️ 🐕🦺 ⚫️. 👶
|
|
||||||
|
|
||||||
### ❎ Hypercorn ⏮️ 🎻
|
|
||||||
|
|
||||||
🥇 👆 💪 ❎ Hypercorn ⏮️ 🎻 🐕🦺:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "hypercorn[trio]"
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
### 🏃 ⏮️ 🎻
|
|
||||||
|
|
||||||
⤴️ 👆 💪 🚶♀️ 📋 ⏸ 🎛 `--worker-class` ⏮️ 💲 `trio`:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ hypercorn main:app --worker-class trio
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
& 👈 🔜 ▶️ Hypercorn ⏮️ 👆 📱 ⚙️ 🎻 👩💻.
|
|
||||||
|
|
||||||
🔜 👆 💪 ⚙️ 🎻 🔘 👆 📱. ⚖️ 👍, 👆 💪 ⚙️ AnyIO, 🚧 👆 📟 🔗 ⏮️ 👯♂️ 🎻 & ✳. 👶
|
|
||||||
|
|
||||||
## 🛠️ 🔧
|
|
||||||
|
|
||||||
👫 🖼 🏃 💽 📋 (📧.Ⓜ Uvicorn), ▶️ **👁 🛠️**, 👂 🔛 🌐 📢 (`0.0.0.0`) 🔛 🔁 ⛴ (✅ `80`).
|
|
||||||
|
|
||||||
👉 🔰 💭. ✋️ 👆 🔜 🎲 💚 ✊ 💅 🌖 👜, 💖:
|
|
||||||
|
|
||||||
* 💂♂ - 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
👤 🔜 💬 👆 🌅 🔃 🔠 👫 🔧, ❔ 💭 🔃 👫, & 🧱 🖼 ⏮️ 🎛 🍵 👫 ⏭ 📃. 👶
|
|
||||||
|
|
@ -1,181 +0,0 @@
|
||||||
# 💽 👨🏭 - 🐁 ⏮️ Uvicorn
|
|
||||||
|
|
||||||
➡️ ✅ 🔙 👈 🛠️ 🔧 ⚪️➡️ ⏭:
|
|
||||||
|
|
||||||
* 💂♂ - 🇺🇸🔍
|
|
||||||
* 🏃♂ 🔛 🕴
|
|
||||||
* ⏏
|
|
||||||
* **🧬 (🔢 🛠️ 🏃)**
|
|
||||||
* 💾
|
|
||||||
* ⏮️ 🔁 ⏭ ▶️
|
|
||||||
|
|
||||||
🆙 👉 ☝, ⏮️ 🌐 🔰 🩺, 👆 ✔️ 🎲 🏃♂ **💽 📋** 💖 Uvicorn, 🏃♂ **👁 🛠️**.
|
|
||||||
|
|
||||||
🕐❔ 🛠️ 🈸 👆 🔜 🎲 💚 ✔️ **🧬 🛠️** ✊ 📈 **💗 🐚** & 💪 🍵 🌅 📨.
|
|
||||||
|
|
||||||
👆 👀 ⏮️ 📃 🔃 [🛠️ 🔧](concepts.md){.internal-link target=_blank}, 📤 💗 🎛 👆 💪 ⚙️.
|
|
||||||
|
|
||||||
📥 👤 🔜 🎦 👆 ❔ ⚙️ <a href="https://gunicorn.org/" class="external-link" target="_blank">**🐁**</a> ⏮️ **Uvicorn 👨🏭 🛠️**.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 📦, 🖼 ⏮️ ☁ ⚖️ Kubernetes, 👤 🔜 💬 👆 🌅 🔃 👈 ⏭ 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
🎯, 🕐❔ 🏃 🔛 **Kubernetes** 👆 🔜 🎲 **🚫** 💚 ⚙️ 🐁 & ↩️ 🏃 **👁 Uvicorn 🛠️ 📍 📦**, ✋️ 👤 🔜 💬 👆 🔃 ⚫️ ⏪ 👈 📃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🐁 ⏮️ Uvicorn 👨🏭
|
|
||||||
|
|
||||||
**🐁** ✴️ 🈸 💽 ⚙️ **🇨🇻 🐩**. 👈 ⛓ 👈 🐁 💪 🍦 🈸 💖 🏺 & ✳. 🐁 ⚫️ 🚫 🔗 ⏮️ **FastAPI**, FastAPI ⚙️ 🆕 **<a href="https://asgi.readthedocs.io/en/latest/" class="external-link" target="_blank">🔫 🐩</a>**.
|
|
||||||
|
|
||||||
✋️ 🐁 🐕🦺 👷 **🛠️ 👨💼** & 🤝 👩💻 💬 ⚫️ ❔ 🎯 **👨🏭 🛠️ 🎓** ⚙️. ⤴️ 🐁 🔜 ▶️ 1️⃣ ⚖️ 🌖 **👨🏭 🛠️** ⚙️ 👈 🎓.
|
|
||||||
|
|
||||||
& **Uvicorn** ✔️ **🐁-🔗 👨🏭 🎓**.
|
|
||||||
|
|
||||||
⚙️ 👈 🌀, 🐁 🔜 🚫 **🛠️ 👨💼**, 👂 🔛 **⛴** & **📢**. & ⚫️ 🔜 **📶** 📻 👨🏭 🛠️ 🏃 **Uvicorn 🎓**.
|
|
||||||
|
|
||||||
& ⤴️ 🐁-🔗 **Uvicorn 👨🏭** 🎓 🔜 🈚 🏭 📊 📨 🐁 🔫 🐩 FastAPI ⚙️ ⚫️.
|
|
||||||
|
|
||||||
## ❎ 🐁 & Uvicorn
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "uvicorn[standard]" gunicorn
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
👈 🔜 ❎ 👯♂️ Uvicorn ⏮️ `standard` ➕ 📦 (🤚 ↕ 🎭) & 🐁.
|
|
||||||
|
|
||||||
## 🏃 🐁 ⏮️ Uvicorn 👨🏭
|
|
||||||
|
|
||||||
⤴️ 👆 💪 🏃 🐁 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80
|
|
||||||
|
|
||||||
[19499] [INFO] Starting gunicorn 20.1.0
|
|
||||||
[19499] [INFO] Listening at: http://0.0.0.0:80 (19499)
|
|
||||||
[19499] [INFO] Using worker: uvicorn.workers.UvicornWorker
|
|
||||||
[19511] [INFO] Booting worker with pid: 19511
|
|
||||||
[19513] [INFO] Booting worker with pid: 19513
|
|
||||||
[19514] [INFO] Booting worker with pid: 19514
|
|
||||||
[19515] [INFO] Booting worker with pid: 19515
|
|
||||||
[19511] [INFO] Started server process [19511]
|
|
||||||
[19511] [INFO] Waiting for application startup.
|
|
||||||
[19511] [INFO] Application startup complete.
|
|
||||||
[19513] [INFO] Started server process [19513]
|
|
||||||
[19513] [INFO] Waiting for application startup.
|
|
||||||
[19513] [INFO] Application startup complete.
|
|
||||||
[19514] [INFO] Started server process [19514]
|
|
||||||
[19514] [INFO] Waiting for application startup.
|
|
||||||
[19514] [INFO] Application startup complete.
|
|
||||||
[19515] [INFO] Started server process [19515]
|
|
||||||
[19515] [INFO] Waiting for application startup.
|
|
||||||
[19515] [INFO] Application startup complete.
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
➡️ 👀 ⚫️❔ 🔠 👈 🎛 ⛓:
|
|
||||||
|
|
||||||
* `main:app`: 👉 🎏 ❕ ⚙️ Uvicorn, `main` ⛓ 🐍 🕹 📛 "`main`",, 📁 `main.py`. & `app` 📛 🔢 👈 **FastAPI** 🈸.
|
|
||||||
* 👆 💪 🌈 👈 `main:app` 🌓 🐍 `import` 📄 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from main import app
|
|
||||||
```
|
|
||||||
|
|
||||||
* , ❤ `main:app` 🔜 🌓 🐍 `import` 🍕 `from main import app`.
|
|
||||||
* `--workers`: 🔢 👨🏭 🛠️ ⚙️, 🔠 🔜 🏃 Uvicorn 👨🏭, 👉 💼, 4️⃣ 👨🏭.
|
|
||||||
* `--worker-class`: 🐁-🔗 👨🏭 🎓 ⚙️ 👨🏭 🛠️.
|
|
||||||
* 📥 👥 🚶♀️ 🎓 👈 🐁 💪 🗄 & ⚙️ ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
import uvicorn.workers.UvicornWorker
|
|
||||||
```
|
|
||||||
|
|
||||||
* `--bind`: 👉 💬 🐁 📢 & ⛴ 👂, ⚙️ ❤ (`:`) 🎏 📢 & ⛴.
|
|
||||||
* 🚥 👆 🏃♂ Uvicorn 🔗, ↩️ `--bind 0.0.0.0:80` (🐁 🎛) 👆 🔜 ⚙️ `--host 0.0.0.0` & `--port 80`.
|
|
||||||
|
|
||||||
🔢, 👆 💪 👀 👈 ⚫️ 🎦 **🕹** (🛠️ 🆔) 🔠 🛠️ (⚫️ 🔢).
|
|
||||||
|
|
||||||
👆 💪 👀 👈:
|
|
||||||
|
|
||||||
* 🐁 **🛠️ 👨💼** ▶️ ⏮️ 🕹 `19499` (👆 💼 ⚫️ 🔜 🎏 🔢).
|
|
||||||
* ⤴️ ⚫️ ▶️ `Listening at: http://0.0.0.0:80`.
|
|
||||||
* ⤴️ ⚫️ 🔍 👈 ⚫️ ✔️ ⚙️ 👨🏭 🎓 `uvicorn.workers.UvicornWorker`.
|
|
||||||
* & ⤴️ ⚫️ ▶️ **4️⃣ 👨🏭**, 🔠 ⏮️ 🚮 👍 🕹: `19511`, `19513`, `19514`, & `19515`.
|
|
||||||
|
|
||||||
🐁 🔜 ✊ 💅 🛠️ **☠️ 🛠️** & **🔁** 🆕 🕐 🚥 💚 🚧 🔢 👨🏭. 👈 ℹ 🍕 ⏮️ **⏏** 🔧 ⚪️➡️ 📇 🔛.
|
|
||||||
|
|
||||||
👐, 👆 🔜 🎲 💚 ✔️ 🕳 🏞 ⚒ 💭 **⏏ 🐁** 🚥 💪, & **🏃 ⚫️ 🔛 🕴**, ♒️.
|
|
||||||
|
|
||||||
## Uvicorn ⏮️ 👨🏭
|
|
||||||
|
|
||||||
Uvicorn ✔️ 🎛 ▶️ & 🏃 📚 **👨🏭 🛠️**.
|
|
||||||
|
|
||||||
👐, 🔜, Uvicorn 🛠️ 🚚 👨🏭 🛠️ 🌅 📉 🌘 🐁. , 🚥 👆 💚 ✔️ 🛠️ 👨💼 👉 🎚 (🐍 🎚), ⤴️ ⚫️ 💪 👍 🔄 ⏮️ 🐁 🛠️ 👨💼.
|
|
||||||
|
|
||||||
🙆 💼, 👆 🔜 🏃 ⚫️ 💖 👉:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
|
|
||||||
<font color="#A6E22E">INFO</font>: Uvicorn running on <b>http://0.0.0.0:8080</b> (Press CTRL+C to quit)
|
|
||||||
<font color="#A6E22E">INFO</font>: Started parent process [<font color="#A1EFE4"><b>27365</b></font>]
|
|
||||||
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27368</font>]
|
|
||||||
<font color="#A6E22E">INFO</font>: Waiting for application startup.
|
|
||||||
<font color="#A6E22E">INFO</font>: Application startup complete.
|
|
||||||
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27369</font>]
|
|
||||||
<font color="#A6E22E">INFO</font>: Waiting for application startup.
|
|
||||||
<font color="#A6E22E">INFO</font>: Application startup complete.
|
|
||||||
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27370</font>]
|
|
||||||
<font color="#A6E22E">INFO</font>: Waiting for application startup.
|
|
||||||
<font color="#A6E22E">INFO</font>: Application startup complete.
|
|
||||||
<font color="#A6E22E">INFO</font>: Started server process [<font color="#A1EFE4">27367</font>]
|
|
||||||
<font color="#A6E22E">INFO</font>: Waiting for application startup.
|
|
||||||
<font color="#A6E22E">INFO</font>: Application startup complete.
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
🕴 🆕 🎛 📥 `--workers` 💬 Uvicorn ▶️ 4️⃣ 👨🏭 🛠️.
|
|
||||||
|
|
||||||
👆 💪 👀 👈 ⚫️ 🎦 **🕹** 🔠 🛠️, `27365` 👪 🛠️ (👉 **🛠️ 👨💼**) & 1️⃣ 🔠 👨🏭 🛠️: `27368`, `27369`, `27370`, & `27367`.
|
|
||||||
|
|
||||||
## 🛠️ 🔧
|
|
||||||
|
|
||||||
📥 👆 👀 ❔ ⚙️ **🐁** (⚖️ Uvicorn) 🛠️ **Uvicorn 👨🏭 🛠️** **🔁** 🛠️ 🈸, ✊ 📈 **💗 🐚** 💽, & 💪 🍦 **🌅 📨**.
|
|
||||||
|
|
||||||
⚪️➡️ 📇 🛠️ 🔧 ⚪️➡️ 🔛, ⚙️ 👨🏭 🔜 ✴️ ℹ ⏮️ **🧬** 🍕, & 🐥 🍖 ⏮️ **⏏**, ✋️ 👆 💪 ✊ 💅 🎏:
|
|
||||||
|
|
||||||
* **💂♂ - 🇺🇸🔍**
|
|
||||||
* **🏃♂ 🔛 🕴**
|
|
||||||
* ***⏏***
|
|
||||||
* 🧬 (🔢 🛠️ 🏃)
|
|
||||||
* **💾**
|
|
||||||
* **⏮️ 🔁 ⏭ ▶️**
|
|
||||||
|
|
||||||
## 📦 & ☁
|
|
||||||
|
|
||||||
⏭ 📃 🔃 [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank} 👤 🔜 💬 🎛 👆 💪 ⚙️ 🍵 🎏 **🛠️ 🔧**.
|
|
||||||
|
|
||||||
👤 🔜 🎦 👆 **🛂 ☁ 🖼** 👈 🔌 **🐁 ⏮️ Uvicorn 👨🏭** & 🔢 📳 👈 💪 ⚠ 🙅 💼.
|
|
||||||
|
|
||||||
📤 👤 🔜 🎦 👆 ❔ **🏗 👆 👍 🖼 ⚪️➡️ 🖌** 🏃 👁 Uvicorn 🛠️ (🍵 🐁). ⚫️ 🙅 🛠️ & 🎲 ⚫️❔ 👆 🔜 💚 🕐❔ ⚙️ 📎 📦 🧾 ⚙️ 💖 **Kubernetes**.
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 ⚙️ **🐁** (⚖️ Uvicorn) 🛠️ 👨💼 ⏮️ Uvicorn 👨🏭 ✊ 📈 **👁-🐚 💽**, 🏃 **💗 🛠️ 🔗**.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 👉 🧰 & 💭 🚥 👆 ⚒ 🆙 **👆 👍 🛠️ ⚙️** ⏪ ✊ 💅 🎏 🛠️ 🔧 👆.
|
|
||||||
|
|
||||||
✅ 👅 ⏭ 📃 💡 🔃 **FastAPI** ⏮️ 📦 (✅ ☁ & Kubernetes). 👆 🔜 👀 👈 👈 🧰 ✔️ 🙅 🌌 ❎ 🎏 **🛠️ 🔧** 👍. 👶
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
# 🔃 FastAPI ⏬
|
|
||||||
|
|
||||||
**FastAPI** ⏪ ➖ ⚙️ 🏭 📚 🈸 & ⚙️. & 💯 💰 🚧 1️⃣0️⃣0️⃣ 💯. ✋️ 🚮 🛠️ 🚚 🔜.
|
|
||||||
|
|
||||||
🆕 ⚒ 🚮 🛎, 🐛 🔧 🛎, & 📟 🔁 📉.
|
|
||||||
|
|
||||||
👈 ⚫️❔ ⏮️ ⏬ `0.x.x`, 👉 🎨 👈 🔠 ⏬ 💪 ⚠ ✔️ 💔 🔀. 👉 ⏩ <a href="https://semver.org/" class="external-link" target="_blank">⚛ 🛠️</a> 🏛.
|
|
||||||
|
|
||||||
👆 💪 ✍ 🏭 🈸 ⏮️ **FastAPI** ▶️️ 🔜 (& 👆 ✔️ 🎲 🔨 ⚫️ 🕰), 👆 ✔️ ⚒ 💭 👈 👆 ⚙️ ⏬ 👈 👷 ☑ ⏮️ 🎂 👆 📟.
|
|
||||||
|
|
||||||
## 📌 👆 `fastapi` ⏬
|
|
||||||
|
|
||||||
🥇 👜 👆 🔜 "📌" ⏬ **FastAPI** 👆 ⚙️ 🎯 📰 ⏬ 👈 👆 💭 👷 ☑ 👆 🈸.
|
|
||||||
|
|
||||||
🖼, ➡️ 💬 👆 ⚙️ ⏬ `0.45.0` 👆 📱.
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ `requirements.txt` 📁 👆 💪 ✔ ⏬ ⏮️:
|
|
||||||
|
|
||||||
```txt
|
|
||||||
fastapi==0.45.0
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 🔜 ⛓ 👈 👆 🔜 ⚙️ ⚫️❔ ⏬ `0.45.0`.
|
|
||||||
|
|
||||||
⚖️ 👆 💪 📌 ⚫️ ⏮️:
|
|
||||||
|
|
||||||
```txt
|
|
||||||
fastapi>=0.45.0,<0.46.0
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 🔜 ⛓ 👈 👆 🔜 ⚙️ ⏬ `0.45.0` ⚖️ 🔛, ✋️ 🌘 🌘 `0.46.0`, 🖼, ⏬ `0.45.2` 🔜 🚫.
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🙆 🎏 🧰 🛠️ 👆 👷♂, 💖 🎶, Pipenv, ⚖️ 🎏, 👫 🌐 ✔️ 🌌 👈 👆 💪 ⚙️ 🔬 🎯 ⏬ 👆 📦.
|
|
||||||
|
|
||||||
## 💪 ⏬
|
|
||||||
|
|
||||||
👆 💪 👀 💪 ⏬ (✅ ✅ ⚫️❔ ⏮️ 📰) [🚀 🗒](../release-notes.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
## 🔃 ⏬
|
|
||||||
|
|
||||||
📄 ⚛ 🛠️ 🏛, 🙆 ⏬ 🔛 `1.0.0` 💪 ⚠ 🚮 💔 🔀.
|
|
||||||
|
|
||||||
FastAPI ⏩ 🏛 👈 🙆 "🐛" ⏬ 🔀 🐛 🔧 & 🚫-💔 🔀.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
"🐛" 🏁 🔢, 🖼, `0.2.3`, 🐛 ⏬ `3`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
, 👆 🔜 💪 📌 ⏬ 💖:
|
|
||||||
|
|
||||||
```txt
|
|
||||||
fastapi>=0.45.0,<0.46.0
|
|
||||||
```
|
|
||||||
|
|
||||||
💔 🔀 & 🆕 ⚒ 🚮 "🇺🇲" ⏬.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
"🇺🇲" 🔢 🖕, 🖼, `0.2.3`, 🇺🇲 ⏬ `2`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ♻ FastAPI ⏬
|
|
||||||
|
|
||||||
👆 🔜 🚮 💯 👆 📱.
|
|
||||||
|
|
||||||
⏮️ **FastAPI** ⚫️ 📶 ⏩ (👏 💃), ✅ 🩺: [🔬](../tutorial/testing.md){.internal-link target=_blank}
|
|
||||||
|
|
||||||
⏮️ 👆 ✔️ 💯, ⤴️ 👆 💪 ♻ **FastAPI** ⏬ 🌖 ⏮️ 1️⃣, & ⚒ 💭 👈 🌐 👆 📟 👷 ☑ 🏃 👆 💯.
|
|
||||||
|
|
||||||
🚥 🌐 👷, ⚖️ ⏮️ 👆 ⚒ 💪 🔀, & 🌐 👆 💯 🚶♀️, ⤴️ 👆 💪 📌 👆 `fastapi` 👈 🆕 ⏮️ ⏬.
|
|
||||||
|
|
||||||
## 🔃 💃
|
|
||||||
|
|
||||||
👆 🚫🔜 🚫 📌 ⏬ `starlette`.
|
|
||||||
|
|
||||||
🎏 ⏬ **FastAPI** 🔜 ⚙️ 🎯 🆕 ⏬ 💃.
|
|
||||||
|
|
||||||
, 👆 💪 ➡️ **FastAPI** ⚙️ ☑ 💃 ⏬.
|
|
||||||
|
|
||||||
## 🔃 Pydantic
|
|
||||||
|
|
||||||
Pydantic 🔌 💯 **FastAPI** ⏮️ 🚮 👍 💯, 🆕 ⏬ Pydantic (🔛 `1.0.0`) 🕧 🔗 ⏮️ FastAPI.
|
|
||||||
|
|
||||||
👆 💪 📌 Pydantic 🙆 ⏬ 🔛 `1.0.0` 👈 👷 👆 & 🔛 `2.0.0`.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
```txt
|
|
||||||
pydantic>=1.2.0,<2.0.0
|
|
||||||
```
|
|
||||||
|
|
@ -1,201 +0,0 @@
|
||||||
# ⚒
|
|
||||||
|
|
||||||
## FastAPI ⚒
|
|
||||||
|
|
||||||
**FastAPI** 🤝 👆 📄:
|
|
||||||
|
|
||||||
### ⚓️ 🔛 📂 🐩
|
|
||||||
|
|
||||||
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>🗄</strong></a> 🛠️ 🏗, ✅ 📄 <abbr title="also known as: endpoints, routes">➡</abbr> <abbr title="also known as HTTP methods, as POST, GET, PUT, DELETE">🛠️</abbr>, 🔢, 💪 📨, 💂♂, ♒️.
|
|
||||||
* 🏧 📊 🏷 🧾 ⏮️ <a href="https://json-schema.org/" class="external-link" target="_blank"><strong>🎻 🔗</strong></a> (🗄 ⚫️ 🧢 🔛 🎻 🔗).
|
|
||||||
* 🔧 🤭 👫 🐩, ⏮️ 😔 🔬. ↩️ 👎 🧽 🔛 🔝.
|
|
||||||
* 👉 ✔ ⚙️ 🏧 **👩💻 📟 ⚡** 📚 🇪🇸.
|
|
||||||
|
|
||||||
### 🏧 🩺
|
|
||||||
|
|
||||||
🎓 🛠️ 🧾 & 🔬 🕸 👩💻 🔢. 🛠️ ⚓️ 🔛 🗄, 📤 💗 🎛, 2️⃣ 🔌 🔢.
|
|
||||||
|
|
||||||
* <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank"><strong>🦁 🎚</strong></a>, ⏮️ 🎓 🔬, 🤙 & 💯 👆 🛠️ 🔗 ⚪️➡️ 🖥.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* 🎛 🛠️ 🧾 ⏮️ <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank"><strong>📄</strong></a>.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🏛 🐍
|
|
||||||
|
|
||||||
⚫️ 🌐 ⚓️ 🔛 🐩 **🐍 3️⃣.6️⃣ 🆎** 📄 (👏 Pydantic). 🙅♂ 🆕 ❕ 💡. 🐩 🏛 🐍.
|
|
||||||
|
|
||||||
🚥 👆 💪 2️⃣ ⏲ ↗️ ❔ ⚙️ 🐍 🆎 (🚥 👆 🚫 ⚙️ FastAPI), ✅ 📏 🔰: [🐍 🆎](python-types.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👆 ✍ 🐩 🐍 ⏮️ 🆎:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
# Declare a variable as a str
|
|
||||||
# and get editor support inside the function
|
|
||||||
def main(user_id: str):
|
|
||||||
return user_id
|
|
||||||
|
|
||||||
|
|
||||||
# A Pydantic model
|
|
||||||
class User(BaseModel):
|
|
||||||
id: int
|
|
||||||
name: str
|
|
||||||
joined: date
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 💪 ⤴️ ⚙️ 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
my_user: User = User(id=3, name="John Doe", joined="2018-07-19")
|
|
||||||
|
|
||||||
second_user_data = {
|
|
||||||
"id": 4,
|
|
||||||
"name": "Mary",
|
|
||||||
"joined": "2018-11-30",
|
|
||||||
}
|
|
||||||
|
|
||||||
my_second_user: User = User(**second_user_data)
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`**second_user_data` ⛓:
|
|
||||||
|
|
||||||
🚶♀️ 🔑 & 💲 `second_user_data` #️⃣ 🔗 🔑-💲 ❌, 🌓: `User(id=4, name="Mary", joined="2018-11-30")`
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 👨🎨 🐕🦺
|
|
||||||
|
|
||||||
🌐 🛠️ 🏗 ⏩ & 🏋️ ⚙️, 🌐 🚫 💯 🔛 💗 👨🎨 ⏭ ▶️ 🛠️, 🚚 🏆 🛠️ 💡.
|
|
||||||
|
|
||||||
🏁 🐍 👩💻 🔬 ⚫️ 🆑 <a href="https://www.jetbrains.com/research/python-developers-survey-2017/#tools-and-features" class="external-link" target="_blank">👈 🌅 ⚙️ ⚒ "✍"</a>.
|
|
||||||
|
|
||||||
🎂 **FastAPI** 🛠️ ⚓️ 😌 👈. ✍ 👷 🌐.
|
|
||||||
|
|
||||||
👆 🔜 🛎 💪 👟 🔙 🩺.
|
|
||||||
|
|
||||||
📥 ❔ 👆 👨🎨 💪 ℹ 👆:
|
|
||||||
|
|
||||||
* <a href="https://code.visualstudio.com/" class="external-link" target="_blank">🎙 🎙 📟</a>:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">🗒</a>:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
👆 🔜 🤚 🛠️ 📟 👆 5️⃣📆 🤔 💪 ⏭. 🖼, `price` 🔑 🔘 🎻 💪 (👈 💪 ✔️ 🐦) 👈 👟 ⚪️➡️ 📨.
|
|
||||||
|
|
||||||
🙅♂ 🌖 ⌨ ❌ 🔑 📛, 👟 🔙 & ➡ 🖖 🩺, ⚖️ 📜 🆙 & 🔽 🔎 🚥 👆 😒 ⚙️ `username` ⚖️ `user_name`.
|
|
||||||
|
|
||||||
### 📏
|
|
||||||
|
|
||||||
⚫️ ✔️ 🤔 **🔢** 🌐, ⏮️ 📦 📳 🌐. 🌐 🔢 💪 👌-🎧 ⚫️❔ 👆 💪 & 🔬 🛠️ 👆 💪.
|
|
||||||
|
|
||||||
✋️ 🔢, ⚫️ 🌐 **"👷"**.
|
|
||||||
|
|
||||||
### 🔬
|
|
||||||
|
|
||||||
* 🔬 🌅 (⚖️ 🌐 ❓) 🐍 **💽 🆎**, 🔌:
|
|
||||||
* 🎻 🎚 (`dict`).
|
|
||||||
* 🎻 🎻 (`list`) ⚖ 🏬 🆎.
|
|
||||||
* 🎻 (`str`) 🏑, 🔬 🕙 & 👟 📐.
|
|
||||||
* 🔢 (`int`, `float`) ⏮️ 🕙 & 👟 💲, ♒️.
|
|
||||||
|
|
||||||
* 🔬 🌅 😍 🆎, 💖:
|
|
||||||
* 📛.
|
|
||||||
* 📧.
|
|
||||||
* 🆔.
|
|
||||||
* ...& 🎏.
|
|
||||||
|
|
||||||
🌐 🔬 🍵 👍-🏛 & 🏋️ **Pydantic**.
|
|
||||||
|
|
||||||
### 💂♂ & 🤝
|
|
||||||
|
|
||||||
💂♂ & 🤝 🛠️. 🍵 🙆 ⚠ ⏮️ 💽 ⚖️ 📊 🏷.
|
|
||||||
|
|
||||||
🌐 💂♂ ⚖ 🔬 🗄, 🔌:
|
|
||||||
|
|
||||||
* 🇺🇸🔍 🔰.
|
|
||||||
* **Oauth2️⃣** (⏮️ **🥙 🤝**). ✅ 🔰 🔛 [Oauth2️⃣ ⏮️ 🥙](tutorial/security/oauth2-jwt.md){.internal-link target=_blank}.
|
|
||||||
* 🛠️ 🔑:
|
|
||||||
* 🎚.
|
|
||||||
* 🔢 🔢.
|
|
||||||
* 🍪, ♒️.
|
|
||||||
|
|
||||||
➕ 🌐 💂♂ ⚒ ⚪️➡️ 💃 (🔌 **🎉 🍪**).
|
|
||||||
|
|
||||||
🌐 🏗 ♻ 🧰 & 🦲 👈 ⏩ 🛠️ ⏮️ 👆 ⚙️, 📊 🏪, 🔗 & ☁ 💽, ♒️.
|
|
||||||
|
|
||||||
### 🔗 💉
|
|
||||||
|
|
||||||
FastAPI 🔌 📶 ⏩ ⚙️, ✋️ 📶 🏋️ <abbr title='also known as "components", "resources", "services", "providers"'><strong>🔗 💉</strong></abbr> ⚙️.
|
|
||||||
|
|
||||||
* 🔗 💪 ✔️ 🔗, 🏗 🔗 ⚖️ **"📊" 🔗**.
|
|
||||||
* 🌐 **🔁 🍵** 🛠️.
|
|
||||||
* 🌐 🔗 💪 🚚 💽 ⚪️➡️ 📨 & **↔ ➡ 🛠️** ⚛ & 🏧 🧾.
|
|
||||||
* **🏧 🔬** *➡ 🛠️* 🔢 🔬 🔗.
|
|
||||||
* 🐕🦺 🏗 👩💻 🤝 ⚙️, **💽 🔗**, ♒️.
|
|
||||||
* **🙅♂ ⚠** ⏮️ 💽, 🕸, ♒️. ✋️ ⏩ 🛠️ ⏮️ 🌐 👫.
|
|
||||||
|
|
||||||
### ♾ "🔌-🔌"
|
|
||||||
|
|
||||||
⚖️ 🎏 🌌, 🙅♂ 💪 👫, 🗄 & ⚙️ 📟 👆 💪.
|
|
||||||
|
|
||||||
🙆 🛠️ 🏗 🙅 ⚙️ (⏮️ 🔗) 👈 👆 💪 ✍ "🔌-" 👆 🈸 2️⃣ ⏸ 📟 ⚙️ 🎏 📊 & ❕ ⚙️ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
### 💯
|
|
||||||
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 <abbr title="The amount of code that is automatically tested">💯 💰</abbr>.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 <abbr title="Python type annotations, with this your editor and external tools can give you better support">🆎 ✍</abbr> 📟 🧢.
|
|
||||||
* ⚙️ 🏭 🈸.
|
|
||||||
|
|
||||||
## 💃 ⚒
|
|
||||||
|
|
||||||
**FastAPI** 🍕 🔗 ⏮️ (& ⚓️ 🔛) <a href="https://www.starlette.dev/" class="external-link" target="_blank"><strong>💃</strong></a>. , 🙆 🌖 💃 📟 👆 ✔️, 🔜 👷.
|
|
||||||
|
|
||||||
`FastAPI` 🤙 🎧-🎓 `Starlette`. , 🚥 👆 ⏪ 💭 ⚖️ ⚙️ 💃, 🌅 🛠️ 🔜 👷 🎏 🌌.
|
|
||||||
|
|
||||||
⏮️ **FastAPI** 👆 🤚 🌐 **💃**'Ⓜ ⚒ (FastAPI 💃 🔛 💊):
|
|
||||||
|
|
||||||
* 🤙 🎆 🎭. ⚫️ <a href="https://github.com/encode/starlette#performance" class="external-link" target="_blank">1️⃣ ⏩ 🐍 🛠️ 💪, 🔛 🇷🇪 ⏮️ **✳** & **🚶**</a>.
|
|
||||||
* ** *️⃣ ** 🐕🦺.
|
|
||||||
* -🛠️ 🖥 📋.
|
|
||||||
* 🕴 & 🤫 🎉.
|
|
||||||
* 💯 👩💻 🏗 🔛 🇸🇲.
|
|
||||||
* **⚜**, 🗜, 🎻 📁, 🎏 📨.
|
|
||||||
* **🎉 & 🍪** 🐕🦺.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 💯 💰.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 🆎 ✍ ✍.
|
|
||||||
|
|
||||||
## Pydantic ⚒
|
|
||||||
|
|
||||||
**FastAPI** 🍕 🔗 ⏮️ (& ⚓️ 🔛) <a href="https://docs.pydantic.dev/" class="external-link" target="_blank"><strong>Pydantic</strong></a>. , 🙆 🌖 Pydantic 📟 👆 ✔️, 🔜 👷.
|
|
||||||
|
|
||||||
✅ 🔢 🗃 ⚓️ 🔛 Pydantic, <abbr title="Object-Relational Mapper">🐜</abbr>Ⓜ, <abbr title="Object-Document Mapper">🏭</abbr>Ⓜ 💽.
|
|
||||||
|
|
||||||
👉 ⛓ 👈 📚 💼 👆 💪 🚶♀️ 🎏 🎚 👆 🤚 ⚪️➡️ 📨 **🔗 💽**, 🌐 ✔ 🔁.
|
|
||||||
|
|
||||||
🎏 ✔ 🎏 🌌 🤭, 📚 💼 👆 💪 🚶♀️ 🎚 👆 🤚 ⚪️➡️ 💽 **🔗 👩💻**.
|
|
||||||
|
|
||||||
⏮️ **FastAPI** 👆 🤚 🌐 **Pydantic**'Ⓜ ⚒ (FastAPI ⚓️ 🔛 Pydantic 🌐 💽 🚚):
|
|
||||||
|
|
||||||
* **🙅♂ 🔠**:
|
|
||||||
* 🙅♂ 🆕 🔗 🔑 ◾-🇪🇸 💡.
|
|
||||||
* 🚥 👆 💭 🐍 🆎 👆 💭 ❔ ⚙️ Pydantic.
|
|
||||||
* 🤾 🎆 ⏮️ 👆 **<abbr title="Integrated Development Environment, similar to a code editor">💾</abbr>/<abbr title="A program that checks for code errors">🧶</abbr>/🧠**:
|
|
||||||
* ↩️ Pydantic 📊 📊 👐 🎓 👆 🔬; 🚘-🛠️, 🧽, ✍ & 👆 🤔 🔜 🌐 👷 ☑ ⏮️ 👆 ✔ 💽.
|
|
||||||
* ✔ **🏗 📊**:
|
|
||||||
* ⚙️ 🔗 Pydantic 🏷, 🐍 `typing`'Ⓜ `List` & `Dict`, ♒️.
|
|
||||||
* & 💳 ✔ 🏗 💽 🔗 🎯 & 💪 🔬, ✅ & 📄 🎻 🔗.
|
|
||||||
* 👆 💪 ✔️ 🙇 **🐦 🎻** 🎚 & ✔️ 👫 🌐 ✔ & ✍.
|
|
||||||
* **🏧**:
|
|
||||||
* Pydantic ✔ 🛃 📊 🆎 🔬 ⚖️ 👆 💪 ↔ 🔬 ⏮️ 👩🔬 🔛 🏷 🎀 ⏮️ 💳 👨🎨.
|
|
||||||
* 1️⃣0️⃣0️⃣ 💯 💯 💰.
|
|
||||||
|
|
@ -1,269 +0,0 @@
|
||||||
# ℹ FastAPI - 🤚 ℹ
|
|
||||||
|
|
||||||
👆 💖 **FastAPI**❓
|
|
||||||
|
|
||||||
🔜 👆 💖 ℹ FastAPI, 🎏 👩💻, & 📕 ❓
|
|
||||||
|
|
||||||
⚖️ 🔜 👆 💖 🤚 ℹ ⏮️ **FastAPI**❓
|
|
||||||
|
|
||||||
📤 📶 🙅 🌌 ℹ (📚 🔌 1️⃣ ⚖️ 2️⃣ 🖊).
|
|
||||||
|
|
||||||
& 📤 📚 🌌 🤚 ℹ 💁♂️.
|
|
||||||
|
|
||||||
## 👱📔 📰
|
|
||||||
|
|
||||||
👆 💪 👱📔 (🐌) [**FastAPI & 👨👧👦** 📰](newsletter.md){.internal-link target=_blank} 🚧 ℹ 🔃:
|
|
||||||
|
|
||||||
* 📰 🔃 FastAPI & 👨👧👦 👶
|
|
||||||
* 🦮 👶
|
|
||||||
* ⚒ 👶
|
|
||||||
* 💔 🔀 👶
|
|
||||||
* 💁♂ & 🎱 👶
|
|
||||||
|
|
||||||
## ⏩ FastAPI 🔛 👱📔
|
|
||||||
|
|
||||||
<a href="https://x.com/fastapi" class="external-link" target="_blank">⏩ 🐶 Fastapi 🔛 **👱📔**</a> 🤚 📰 📰 🔃 **FastAPI**. 👶
|
|
||||||
|
|
||||||
## ✴ **FastAPI** 📂
|
|
||||||
|
|
||||||
👆 💪 "✴" FastAPI 📂 (🖊 ✴ 🔼 🔝 ▶️️): <a href="https://github.com/fastapi/fastapi" class="external-link" target="_blank">https://github.com/fastapi/fastapi</a>. 👶 👶
|
|
||||||
|
|
||||||
❎ ✴, 🎏 👩💻 🔜 💪 🔎 ⚫️ 🌅 💪 & 👀 👈 ⚫️ ✔️ ⏪ ⚠ 🎏.
|
|
||||||
|
|
||||||
## ⌚ 📂 🗃 🚀
|
|
||||||
|
|
||||||
👆 💪 "⌚" FastAPI 📂 (🖊 "⌚" 🔼 🔝 ▶️️): <a href="https://github.com/fastapi/fastapi" class="external-link" target="_blank">https://github.com/fastapi/fastapi</a>. 👶
|
|
||||||
|
|
||||||
📤 👆 💪 🖊 "🚀 🕴".
|
|
||||||
|
|
||||||
🔨 ⚫️, 👆 🔜 📨 📨 (👆 📧) 🕐❔ 📤 🆕 🚀 (🆕 ⏬) **FastAPI** ⏮️ 🐛 🔧 & 🆕 ⚒.
|
|
||||||
|
|
||||||
## 🔗 ⏮️ 📕
|
|
||||||
|
|
||||||
👆 💪 🔗 ⏮️ <a href="https://tiangolo.com" class="external-link" target="_blank">👤 (🇹🇦 🇩🇬 / `tiangolo`)</a>, 📕.
|
|
||||||
|
|
||||||
👆 💪:
|
|
||||||
|
|
||||||
* <a href="https://github.com/tiangolo" class="external-link" target="_blank">⏩ 👤 🔛 **📂**</a>.
|
|
||||||
* 👀 🎏 📂 ℹ 🏗 👤 ✔️ ✍ 👈 💪 ℹ 👆.
|
|
||||||
* ⏩ 👤 👀 🕐❔ 👤 ✍ 🆕 📂 ℹ 🏗.
|
|
||||||
* <a href="https://x.com/tiangolo" class="external-link" target="_blank">⏩ 👤 🔛 **👱📔**</a> ⚖️ <a href="https://fosstodon.org/@tiangolo" class="external-link" target="_blank">☠</a>.
|
|
||||||
* 💬 👤 ❔ 👆 ⚙️ FastAPI (👤 💌 👂 👈).
|
|
||||||
* 👂 🕐❔ 👤 ⚒ 🎉 ⚖️ 🚀 🆕 🧰.
|
|
||||||
* 👆 💪 <a href="https://x.com/fastapi" class="external-link" target="_blank">⏩ 🐶 Fastapi 🔛 👱📔</a> (🎏 🏧).
|
|
||||||
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">🔗 ⏮️ 👤 🔛 **👱📔**</a>.
|
|
||||||
* 👂 🕐❔ 👤 ⚒ 🎉 ⚖️ 🚀 🆕 🧰 (👐 👤 ⚙️ 👱📔 🌖 🛎 🤷 ♂).
|
|
||||||
* ✍ ⚫️❔ 👤 ✍ (⚖️ ⏩ 👤) 🔛 <a href="https://dev.to/tiangolo" class="external-link" target="_blank">**🇸🇲.**</a> ⚖️ <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">**🔉**</a>.
|
|
||||||
* ✍ 🎏 💭, 📄, & ✍ 🔃 🧰 👤 ✔️ ✍.
|
|
||||||
* ⏩ 👤 ✍ 🕐❔ 👤 ✍ 🕳 🆕.
|
|
||||||
|
|
||||||
## 👱📔 🔃 **FastAPI**
|
|
||||||
|
|
||||||
<a href="https://x.com/compose/tweet?text=I'm loving @fastapi because... https://github.com/fastapi/fastapi" class="external-link" target="_blank">👱📔 🔃 **FastAPI**</a> & ➡️ 👤 & 🎏 💭 ⚫️❔ 👆 💖 ⚫️. 👶
|
|
||||||
|
|
||||||
👤 💌 👂 🔃 ❔ **FastAPI** 💆♂ ⚙️, ⚫️❔ 👆 ✔️ 💖 ⚫️, ❔ 🏗/🏢 👆 ⚙️ ⚫️, ♒️.
|
|
||||||
|
|
||||||
## 🗳 FastAPI
|
|
||||||
|
|
||||||
* <a href="https://www.slant.co/options/34241/~fastapi-review" class="external-link" target="_blank">🗳 **FastAPI** 📐</a>.
|
|
||||||
* <a href="https://alternativeto.net/software/fastapi/" class="external-link" target="_blank">🗳 **FastAPI** 📱</a>.
|
|
||||||
* <a href="https://stackshare.io/pypi-fastapi" class="external-link" target="_blank">💬 👆 ⚙️ **FastAPI** 🔛 ℹ</a>.
|
|
||||||
|
|
||||||
## ℹ 🎏 ⏮️ ❔ 📂
|
|
||||||
|
|
||||||
👆 💪 🔄 & ℹ 🎏 ⏮️ 👫 ❔:
|
|
||||||
|
|
||||||
* <a href="https://github.com/fastapi/fastapi/discussions/categories/questions?discussions_q=category%3AQuestions+is%3Aunanswered" class="external-link" target="_blank">📂 💬</a>
|
|
||||||
* <a href="https://github.com/fastapi/fastapi/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+label%3Aquestion+-label%3Aanswered+" class="external-link" target="_blank">📂 ❔</a>
|
|
||||||
|
|
||||||
📚 💼 👆 5️⃣📆 ⏪ 💭 ❔ 📚 ❔. 👶
|
|
||||||
|
|
||||||
🚥 👆 🤝 📚 👫👫 ⏮️ 👫 ❔, 👆 🔜 ▶️️ 🛂 [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}. 👶
|
|
||||||
|
|
||||||
💭, 🏆 ⚠ ☝: 🔄 😇. 👫👫 👟 ⏮️ 👫 😩 & 📚 💼 🚫 💭 🏆 🌌, ✋️ 🔄 🏆 👆 💪 😇. 👶
|
|
||||||
|
|
||||||
💭 **FastAPI** 👪 😇 & 👍. 🎏 🕰, 🚫 🚫 🎭 ⚖️ 😛 🎭 ⤵ 🎏. 👥 ✔️ ✊ 💅 🔠 🎏.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
📥 ❔ ℹ 🎏 ⏮️ ❔ (💬 ⚖️ ❔):
|
|
||||||
|
|
||||||
### 🤔 ❔
|
|
||||||
|
|
||||||
* ✅ 🚥 👆 💪 🤔 ⚫️❔ **🎯** & ⚙️ 💼 👨💼 💬.
|
|
||||||
|
|
||||||
* ⤴️ ✅ 🚥 ❔ (⭕ 👪 ❔) **🆑**.
|
|
||||||
|
|
||||||
* 📚 💼 ❔ 💭 🔃 👽 ⚗ ⚪️➡️ 👩💻, ✋️ 📤 💪 **👍** 1️⃣. 🚥 👆 💪 🤔 ⚠ & ⚙️ 💼 👍, 👆 💪 💪 🤔 👍 **🎛 ⚗**.
|
|
||||||
|
|
||||||
* 🚥 👆 💪 🚫 🤔 ❔, 💭 🌖 **ℹ**.
|
|
||||||
|
|
||||||
### 🔬 ⚠
|
|
||||||
|
|
||||||
🌅 💼 & 🏆 ❔ 📤 🕳 🔗 👨💼 **⏮️ 📟**.
|
|
||||||
|
|
||||||
📚 💼 👫 🔜 🕴 📁 🧬 📟, ✋️ 👈 🚫 🥃 **🔬 ⚠**.
|
|
||||||
|
|
||||||
* 👆 💪 💭 👫 🚚 <a href="https://stackoverflow.com/help/minimal-reproducible-example" class="external-link" target="_blank">⭐, 🔬, 🖼</a>, 👈 👆 💪 **📁-📋** & 🏃 🌐 👀 🎏 ❌ ⚖️ 🎭 👫 👀, ⚖️ 🤔 👫 ⚙️ 💼 👍.
|
|
||||||
|
|
||||||
* 🚥 👆 😟 💁♂️ 👍, 👆 💪 🔄 **✍ 🖼** 💖 👈 👆, 🧢 🔛 📛 ⚠. ✔️ 🤯 👈 👉 💪 ✊ 📚 🕰 & ⚫️ 💪 👻 💭 👫 ✍ ⚠ 🥇.
|
|
||||||
|
|
||||||
### 🤔 ⚗
|
|
||||||
|
|
||||||
* ⏮️ 💆♂ 💪 🤔 ❔, 👆 💪 🤝 👫 💪 **❔**.
|
|
||||||
|
|
||||||
* 📚 💼, ⚫️ 👍 🤔 👫 **📈 ⚠ ⚖️ ⚙️ 💼**, ↩️ 📤 5️⃣📆 👍 🌌 ❎ ⚫️ 🌘 ⚫️❔ 👫 🔄.
|
|
||||||
|
|
||||||
### 💭 🔐
|
|
||||||
|
|
||||||
🚥 👫 📨, 📤 ↕ 🤞 👆 🔜 ✔️ ❎ 👫 ⚠, ㊗, **👆 💂**❗ 🦸
|
|
||||||
|
|
||||||
* 🔜, 🚥 👈 ❎ 👫 ⚠, 👆 💪 💭 👫:
|
|
||||||
|
|
||||||
* 📂 💬: ™ 🏤 **❔**.
|
|
||||||
* 📂 ❔: **🔐** ❔**.
|
|
||||||
|
|
||||||
## ⌚ 📂 🗃
|
|
||||||
|
|
||||||
👆 💪 "⌚" FastAPI 📂 (🖊 "⌚" 🔼 🔝 ▶️️): <a href="https://github.com/fastapi/fastapi" class="external-link" target="_blank">https://github.com/fastapi/fastapi</a>. 👶
|
|
||||||
|
|
||||||
🚥 👆 🖊 "👀" ↩️ "🚀 🕴" 👆 🔜 📨 📨 🕐❔ 👱 ✍ 🆕 ❔ ⚖️ ❔. 👆 💪 ✔ 👈 👆 🕴 💚 🚨 🔃 🆕 ❔, ⚖️ 💬, ⚖️ 🎸, ♒️.
|
|
||||||
|
|
||||||
⤴️ 👆 💪 🔄 & ℹ 👫 ❎ 👈 ❔.
|
|
||||||
|
|
||||||
## 💭 ❔
|
|
||||||
|
|
||||||
👆 💪 <a href="https://github.com/fastapi/fastapi/discussions/new?category=questions" class="external-link" target="_blank">✍ 🆕 ❔</a> 📂 🗃, 🖼:
|
|
||||||
|
|
||||||
* 💭 **❔** ⚖️ 💭 🔃 **⚠**.
|
|
||||||
* 🤔 🆕 **⚒**.
|
|
||||||
|
|
||||||
**🗒**: 🚥 👆 ⚫️, ⤴️ 👤 🔜 💭 👆 ℹ 🎏. 👶
|
|
||||||
|
|
||||||
## 📄 🚲 📨
|
|
||||||
|
|
||||||
👆 💪 ℹ 👤 📄 🚲 📨 ⚪️➡️ 🎏.
|
|
||||||
|
|
||||||
🔄, 🙏 🔄 👆 🏆 😇. 👶
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
📥 ⚫️❔ ✔️ 🤯 & ❔ 📄 🚲 📨:
|
|
||||||
|
|
||||||
### 🤔 ⚠
|
|
||||||
|
|
||||||
* 🥇, ⚒ 💭 👆 **🤔 ⚠** 👈 🚲 📨 🔄 ❎. ⚫️ 💪 ✔️ 📏 💬 📂 💬 ⚖️ ❔.
|
|
||||||
|
|
||||||
* 📤 👍 🤞 👈 🚲 📨 🚫 🤙 💪 ↩️ ⚠ 💪 ❎ **🎏 🌌**. ⤴️ 👆 💪 🤔 ⚖️ 💭 🔃 👈.
|
|
||||||
|
|
||||||
### 🚫 😟 🔃 👗
|
|
||||||
|
|
||||||
* 🚫 😟 💁♂️ 🌅 🔃 👜 💖 💕 📧 👗, 👤 🔜 🥬 & 🔗 🛃 💕 ❎.
|
|
||||||
|
|
||||||
* 🚫 😟 🔃 👗 🚫, 📤 ⏪ 🏧 🧰 ✅ 👈.
|
|
||||||
|
|
||||||
& 🚥 📤 🙆 🎏 👗 ⚖️ ⚖ 💪, 👤 🔜 💭 🔗 👈, ⚖️ 👤 🔜 🚮 💕 🔛 🔝 ⏮️ 💪 🔀.
|
|
||||||
|
|
||||||
### ✅ 📟
|
|
||||||
|
|
||||||
* ✅ & ✍ 📟, 👀 🚥 ⚫️ ⚒ 🔑, **🏃 ⚫️ 🌐** & 👀 🚥 ⚫️ 🤙 ❎ ⚠.
|
|
||||||
|
|
||||||
* ⤴️ **🏤** 💬 👈 👆 👈, 👈 ❔ 👤 🔜 💭 👆 🤙 ✅ ⚫️.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👐, 👤 💪 🚫 🎯 💙 🎸 👈 ✔️ 📚 ✔.
|
|
||||||
|
|
||||||
📚 🕰 ⚫️ ✔️ 🔨 👈 📤 🎸 ⏮️ 3️⃣, 5️⃣ ⚖️ 🌅 ✔, 🎲 ↩️ 📛 😌, ✋️ 🕐❔ 👤 ✅ 🎸, 👫 🤙 💔, ✔️ 🐛, ⚖️ 🚫 ❎ ⚠ 👫 🛄 ❎. 👶
|
|
||||||
|
|
||||||
, ⚫️ 🤙 ⚠ 👈 👆 🤙 ✍ & 🏃 📟, & ➡️ 👤 💭 🏤 👈 👆. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
* 🚥 🇵🇷 💪 📉 🌌, 👆 💪 💭 👈, ✋️ 📤 🙅♂ 💪 💁♂️ 😟, 📤 5️⃣📆 📚 🤔 ☝ 🎑 (& 👤 🔜 ✔️ 👇 👍 👍 👶), ⚫️ 👻 🚥 👆 💪 🎯 🔛 ⚛ 👜.
|
|
||||||
|
|
||||||
### 💯
|
|
||||||
|
|
||||||
* ℹ 👤 ✅ 👈 🇵🇷 ✔️ **💯**.
|
|
||||||
|
|
||||||
* ✅ 👈 💯 **❌** ⏭ 🇵🇷. 👶
|
|
||||||
|
|
||||||
* ⤴️ ✅ 👈 💯 **🚶♀️** ⏮️ 🇵🇷. 👶
|
|
||||||
|
|
||||||
* 📚 🎸 🚫 ✔️ 💯, 👆 💪 **🎗** 👫 🚮 💯, ⚖️ 👆 💪 **🤔** 💯 👆. 👈 1️⃣ 👜 👈 🍴 🌅 🕰 & 👆 💪 ℹ 📚 ⏮️ 👈.
|
|
||||||
|
|
||||||
* ⤴️ 🏤 ⚫️❔ 👆 🔄, 👈 🌌 👤 🔜 💭 👈 👆 ✅ ⚫️. 👶
|
|
||||||
|
|
||||||
## ✍ 🚲 📨
|
|
||||||
|
|
||||||
👆 💪 [📉](contributing.md){.internal-link target=_blank} ℹ 📟 ⏮️ 🚲 📨, 🖼:
|
|
||||||
|
|
||||||
* 🔧 🤭 👆 🔎 🔛 🧾.
|
|
||||||
* 💰 📄, 📹, ⚖️ 📻 👆 ✍ ⚖️ 🔎 🔃 FastAPI <a href="https://github.com/fastapi/fastapi/edit/master/docs/en/data/external_links.yml" class="external-link" target="_blank">✍ 👉 📁</a>.
|
|
||||||
* ⚒ 💭 👆 🚮 👆 🔗 ▶️ 🔗 📄.
|
|
||||||
* ℹ [💬 🧾](contributing.md#_9){.internal-link target=_blank} 👆 🇪🇸.
|
|
||||||
* 👆 💪 ℹ 📄 ✍ ✍ 🎏.
|
|
||||||
* 🛠️ 🆕 🧾 📄.
|
|
||||||
* 🔧 ♻ ❔/🐛.
|
|
||||||
* ⚒ 💭 🚮 💯.
|
|
||||||
* 🚮 🆕 ⚒.
|
|
||||||
* ⚒ 💭 🚮 💯.
|
|
||||||
* ⚒ 💭 🚮 🧾 🚥 ⚫️ 🔗.
|
|
||||||
|
|
||||||
## ℹ 🚧 FastAPI
|
|
||||||
|
|
||||||
ℹ 👤 🚧 **FastAPI**❗ 👶
|
|
||||||
|
|
||||||
📤 📚 👷, & 🏆 ⚫️, **👆** 💪 ⚫️.
|
|
||||||
|
|
||||||
👑 📋 👈 👆 💪 ▶️️ 🔜:
|
|
||||||
|
|
||||||
* [ℹ 🎏 ⏮️ ❔ 📂](#i){.internal-link target=_blank} (👀 📄 🔛).
|
|
||||||
* [📄 🚲 📨](#i){.internal-link target=_blank} (👀 📄 🔛).
|
|
||||||
|
|
||||||
👈 2️⃣ 📋 ⚫️❔ **🍴 🕰 🏆**. 👈 👑 👷 🏆 FastAPI.
|
|
||||||
|
|
||||||
🚥 👆 💪 ℹ 👤 ⏮️ 👈, **👆 🤝 👤 🚧 FastAPI** & ⚒ 💭 ⚫️ 🚧 **🛠️ ⏩ & 👻**. 👶
|
|
||||||
|
|
||||||
## 🛑 💬
|
|
||||||
|
|
||||||
🛑 👶 <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">😧 💬 💽</a> 👶 & 🤙 👅 ⏮️ 🎏 FastAPI 👪.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
❔, 💭 👫 <a href="https://github.com/fastapi/fastapi/discussions/new?category=questions" class="external-link" target="_blank">📂 💬</a>, 📤 🌅 👍 🤞 👆 🔜 📨 ℹ [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
⚙️ 💬 🕴 🎏 🏢 💬.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🚫 ⚙️ 💬 ❔
|
|
||||||
|
|
||||||
✔️ 🤯 👈 💬 ✔ 🌅 "🆓 💬", ⚫️ ⏩ 💭 ❔ 👈 💁♂️ 🏢 & 🌅 ⚠ ❔,, 👆 💪 🚫 📨 ❔.
|
|
||||||
|
|
||||||
📂, 📄 🔜 🦮 👆 ✍ ▶️️ ❔ 👈 👆 💪 🌖 💪 🤚 👍 ❔, ⚖️ ❎ ⚠ 👆 ⏭ 💬. & 📂 👤 💪 ⚒ 💭 👤 🕧 ❔ 🌐, 🚥 ⚫️ ✊ 🕰. 👤 💪 🚫 🤙 👈 ⏮️ 💬 ⚙️. 👶
|
|
||||||
|
|
||||||
💬 💬 ⚙️ 🚫 💪 📇 📂, ❔ & ❔ 5️⃣📆 🤚 💸 💬. & 🕴 🕐 📂 💯 ▶️️ [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}, 👆 🔜 🌅 🎲 📨 🌅 🙋 📂.
|
|
||||||
|
|
||||||
🔛 🎏 🚄, 📤 💯 👩💻 💬 ⚙️, 📤 ↕ 🤞 👆 🔜 🔎 👱 💬 📤, 🌖 🌐 🕰. 👶
|
|
||||||
|
|
||||||
## 💰 📕
|
|
||||||
|
|
||||||
👆 💪 💰 🐕🦺 📕 (👤) 🔘 <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">📂 💰</a>.
|
|
||||||
|
|
||||||
📤 👆 💪 🛍 👤 ☕ 👶 👶 💬 👏. 👶
|
|
||||||
|
|
||||||
& 👆 💪 ▶️️ 🥇1st ⚖️ 🌟 💰 FastAPI. 👶 👶
|
|
||||||
|
|
||||||
## 💰 🧰 👈 🏋️ FastAPI
|
|
||||||
|
|
||||||
👆 ✔️ 👀 🧾, FastAPI 🧍 🔛 ⌚ 🐘, 💃 & Pydantic.
|
|
||||||
|
|
||||||
👆 💪 💰:
|
|
||||||
|
|
||||||
* <a href="https://github.com/sponsors/samuelcolvin" class="external-link" target="_blank">✡ 🍏 (Pydantic)</a>
|
|
||||||
* <a href="https://github.com/sponsors/encode" class="external-link" target="_blank">🗜 (💃, Uvicorn)</a>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👏 ❗ 👶
|
|
||||||
|
|
@ -1,79 +0,0 @@
|
||||||
# 📖, 🔧 & 🔮
|
|
||||||
|
|
||||||
🕰 🏁, <a href="https://github.com/fastapi/fastapi/issues/3#issuecomment-454956920" class="external-link" target="_blank"> **FastAPI** 👩💻 💭</a>:
|
|
||||||
|
|
||||||
> ⚫️❔ 📖 👉 🏗 ❓ ⚫️ 😑 ✔️ 👟 ⚪️➡️ 🕳 👌 👩❤👨 🗓️ [...]
|
|
||||||
|
|
||||||
📥 🐥 🍖 👈 📖.
|
|
||||||
|
|
||||||
## 🎛
|
|
||||||
|
|
||||||
👤 ✔️ 🏗 🔗 ⏮️ 🏗 📄 📚 1️⃣2️⃣🗓️ (🎰 🏫, 📎 ⚙️, 🔁 👨🏭, ☁ 💽, ♒️), ↘️ 📚 🏉 👩💻.
|
|
||||||
|
|
||||||
🍕 👈, 👤 💪 🔬, 💯 & ⚙️ 📚 🎛.
|
|
||||||
|
|
||||||
📖 **FastAPI** 👑 🍕 📖 🚮 ⏪.
|
|
||||||
|
|
||||||
🙆♀ 📄 [🎛](alternatives.md){.internal-link target=_blank}:
|
|
||||||
|
|
||||||
<blockquote markdown="1">
|
|
||||||
|
|
||||||
**FastAPI** 🚫🔜 🔀 🚥 🚫 ⏮️ 👷 🎏.
|
|
||||||
|
|
||||||
📤 ✔️ 📚 🧰 ✍ ⏭ 👈 ✔️ ℹ 😮 🚮 🏗.
|
|
||||||
|
|
||||||
👤 ✔️ ❎ 🏗 🆕 🛠️ 📚 1️⃣2️⃣🗓️. 🥇 👤 🔄 ❎ 🌐 ⚒ 📔 **FastAPI** ⚙️ 📚 🎏 🛠️, 🔌-🔌, & 🧰.
|
|
||||||
|
|
||||||
✋️ ☝, 📤 🙅♂ 🎏 🎛 🌘 🏗 🕳 👈 🚚 🌐 👫 ⚒, ✊ 🏆 💭 ⚪️➡️ ⏮️ 🧰, & 🌀 👫 🏆 🌌 💪, ⚙️ 🇪🇸 ⚒ 👈 ➖🚫 💪 ⏭ (🐍 3️⃣.6️⃣ ➕ 🆎 🔑).
|
|
||||||
|
|
||||||
</blockquote>
|
|
||||||
|
|
||||||
## 🔬
|
|
||||||
|
|
||||||
⚙️ 🌐 ⏮️ 🎛 👤 ✔️ 🤞 💡 ⚪️➡️ 🌐 👫, ✊ 💭, & 🌀 👫 🏆 🌌 👤 💪 🔎 👤 & 🏉 👩💻 👤 ✔️ 👷 ⏮️.
|
|
||||||
|
|
||||||
🖼, ⚫️ 🆑 👈 🎲 ⚫️ 🔜 ⚓️ 🔛 🐩 🐍 🆎 🔑.
|
|
||||||
|
|
||||||
, 🏆 🎯 ⚙️ ⏪ ♻ 🐩.
|
|
||||||
|
|
||||||
, ⏭ ▶️ 📟 **FastAPI**, 👤 💸 📚 🗓️ 🎓 🔌 🗄, 🎻 🔗, Oauth2️⃣, ♒️. 🎯 👫 💛, 🔀, & 🔺.
|
|
||||||
|
|
||||||
## 🔧
|
|
||||||
|
|
||||||
⤴️ 👤 💸 🕰 🔧 👩💻 "🛠️" 👤 💚 ✔️ 👩💻 (👩💻 ⚙️ FastAPI).
|
|
||||||
|
|
||||||
👤 💯 📚 💭 🏆 🌟 🐍 👨🎨: 🗒, 🆚 📟, 🎠 🧢 👨🎨.
|
|
||||||
|
|
||||||
🏁 <a href="https://www.jetbrains.com/research/python-developers-survey-2018/#development-tools" class="external-link" target="_blank">🐍 👩💻 🔬</a>, 👈 📔 🔃 8️⃣0️⃣ 💯 👩💻.
|
|
||||||
|
|
||||||
⚫️ ⛓ 👈 **FastAPI** 🎯 💯 ⏮️ 👨🎨 ⚙️ 8️⃣0️⃣ 💯 🐍 👩💻. & 🏆 🎏 👨🎨 😑 👷 ➡, 🌐 🚮 💰 🔜 👷 🌖 🌐 👨🎨.
|
|
||||||
|
|
||||||
👈 🌌 👤 💪 🔎 🏆 🌌 📉 📟 ❎ 🌅 💪, ✔️ 🛠️ 🌐, 🆎 & ❌ ✅, ♒️.
|
|
||||||
|
|
||||||
🌐 🌌 👈 🚚 🏆 🛠️ 💡 🌐 👩💻.
|
|
||||||
|
|
||||||
## 📄
|
|
||||||
|
|
||||||
⏮️ 🔬 📚 🎛, 👤 💭 👈 👤 🔜 ⚙️ <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">**Pydantic**</a> 🚮 📈.
|
|
||||||
|
|
||||||
⤴️ 👤 📉 ⚫️, ⚒ ⚫️ 🍕 🛠️ ⏮️ 🎻 🔗, 🐕🦺 🎏 🌌 🔬 ⚛ 📄, & 📉 👨🎨 🐕🦺 (🆎 ✅, ✍) ⚓️ 🔛 💯 📚 👨🎨.
|
|
||||||
|
|
||||||
⏮️ 🛠️, 👤 📉 <a href="https://www.starlette.dev/" class="external-link" target="_blank">**💃**</a>, 🎏 🔑 📄.
|
|
||||||
|
|
||||||
## 🛠️
|
|
||||||
|
|
||||||
🕰 👤 ▶️ 🏗 **FastAPI** ⚫️, 🏆 🍖 ⏪ 🥉, 🔧 🔬, 📄 & 🧰 🔜, & 💡 🔃 🐩 & 🔧 🆑 & 🍋.
|
|
||||||
|
|
||||||
## 🔮
|
|
||||||
|
|
||||||
👉 ☝, ⚫️ ⏪ 🆑 👈 **FastAPI** ⏮️ 🚮 💭 ➖ ⚠ 📚 👫👫.
|
|
||||||
|
|
||||||
⚫️ 💆♂ 👐 🤭 ⏮️ 🎛 ♣ 📚 ⚙️ 💼 👍.
|
|
||||||
|
|
||||||
📚 👩💻 & 🏉 ⏪ 🪀 🔛 **FastAPI** 👫 🏗 (🔌 👤 & 👇 🏉).
|
|
||||||
|
|
||||||
✋️, 📤 📚 📈 & ⚒ 👟.
|
|
||||||
|
|
||||||
**FastAPI** ✔️ 👑 🔮 ⤴️.
|
|
||||||
|
|
||||||
& [👆 ℹ](help-fastapi.md){.internal-link target=_blank} 📉 👍.
|
|
||||||
|
|
@ -1,56 +0,0 @@
|
||||||
# 🎲 🗄
|
|
||||||
|
|
||||||
🚥 👆 💪, 👆 💪 ⚙️ ⚒ & 🌐 🔢 🔗 🗄 ✔ ⚓️ 🔛 🌐, & ❎ ⚫️ 🍕.
|
|
||||||
|
|
||||||
## 🔃 💂♂, 🔗, & 🩺
|
|
||||||
|
|
||||||
🕵♂ 👆 🧾 👩💻 🔢 🏭 *🚫🔜 🚫* 🌌 🛡 👆 🛠️.
|
|
||||||
|
|
||||||
👈 🚫 🚮 🙆 ➕ 💂♂ 👆 🛠️, *➡ 🛠️* 🔜 💪 🌐❔ 👫.
|
|
||||||
|
|
||||||
🚥 📤 💂♂ ⚠ 👆 📟, ⚫️ 🔜 🔀.
|
|
||||||
|
|
||||||
🕵♂ 🧾 ⚒ ⚫️ 🌅 ⚠ 🤔 ❔ 🔗 ⏮️ 👆 🛠️, & 💪 ⚒ ⚫️ 🌅 ⚠ 👆 ℹ ⚫️ 🏭. ⚫️ 💪 🤔 🎯 📨 <a href="https://en.wikipedia.org/wiki/Security_through_obscurity" class="external-link" target="_blank">💂♂ 🔘 🌌</a>.
|
|
||||||
|
|
||||||
🚥 👆 💚 🔐 👆 🛠️, 📤 📚 👍 👜 👆 💪, 🖼:
|
|
||||||
|
|
||||||
* ⚒ 💭 👆 ✔️ 👍 🔬 Pydantic 🏷 👆 📨 💪 & 📨.
|
|
||||||
* 🔗 🙆 ✔ ✔ & 🔑 ⚙️ 🔗.
|
|
||||||
* 🙅 🏪 🔢 🔐, 🕴 🔐#️⃣.
|
|
||||||
* 🛠️ & ⚙️ 👍-💭 🔐 🧰, 💖 🇸🇲 & 🥙 🤝, ♒️.
|
|
||||||
* 🚮 🌅 🧽 ✔ 🎛 ⏮️ Oauth2️⃣ ↔ 🌐❔ 💪.
|
|
||||||
* ...♒️.
|
|
||||||
|
|
||||||
👐, 👆 5️⃣📆 ✔️ 📶 🎯 ⚙️ 💼 🌐❔ 👆 🤙 💪 ❎ 🛠️ 🩺 🌐 (✅ 🏭) ⚖️ ⚓️ 🔛 📳 ⚪️➡️ 🌐 🔢.
|
|
||||||
|
|
||||||
## 🎲 🗄 ⚪️➡️ ⚒ & 🇨🇻 {
|
|
||||||
|
|
||||||
👆 💪 💪 ⚙️ 🎏 Pydantic ⚒ 🔗 👆 🏗 🗄 & 🩺 ⚜.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/conditional_openapi/tutorial001.py hl[6,11] *}
|
|
||||||
|
|
||||||
📥 👥 📣 ⚒ `openapi_url` ⏮️ 🎏 🔢 `"/openapi.json"`.
|
|
||||||
|
|
||||||
& ⤴️ 👥 ⚙️ ⚫️ 🕐❔ 🏗 `FastAPI` 📱.
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ❎ 🗄 (✅ 🎚 🩺) ⚒ 🌐 🔢 `OPENAPI_URL` 🛁 🎻, 💖:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ OPENAPI_URL= uvicorn main:app
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
⤴️ 🚥 👆 🚶 📛 `/openapi.json`, `/docs`, ⚖️ `/redoc` 👆 🔜 🤚 `404 Not Found` ❌ 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"detail": "Not Found"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
@ -1,109 +0,0 @@
|
||||||
# 🛃 📨 & APIRoute 🎓
|
|
||||||
|
|
||||||
💼, 👆 5️⃣📆 💚 🔐 ⚛ ⚙️ `Request` & `APIRoute` 🎓.
|
|
||||||
|
|
||||||
🎯, 👉 5️⃣📆 👍 🎛 ⚛ 🛠️.
|
|
||||||
|
|
||||||
🖼, 🚥 👆 💚 ✍ ⚖️ 🔬 📨 💪 ⏭ ⚫️ 🛠️ 👆 🈸.
|
|
||||||
|
|
||||||
/// danger
|
|
||||||
|
|
||||||
👉 "🏧" ⚒.
|
|
||||||
|
|
||||||
🚥 👆 ▶️ ⏮️ **FastAPI** 👆 💪 💚 🚶 👉 📄.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚙️ 💼
|
|
||||||
|
|
||||||
⚙️ 💼 🔌:
|
|
||||||
|
|
||||||
* 🏭 🚫-🎻 📨 💪 🎻 (✅ <a href="https://msgpack.org/index.html" class="external-link" target="_blank">`msgpack`</a>).
|
|
||||||
* 🗜 🗜-🗜 📨 💪.
|
|
||||||
* 🔁 🚨 🌐 📨 💪.
|
|
||||||
|
|
||||||
## 🚚 🛃 📨 💪 🔢
|
|
||||||
|
|
||||||
➡️ 👀 ❔ ⚒ ⚙️ 🛃 `Request` 🏿 🗜 🗜 📨.
|
|
||||||
|
|
||||||
& `APIRoute` 🏿 ⚙️ 👈 🛃 📨 🎓.
|
|
||||||
|
|
||||||
### ✍ 🛃 `GzipRequest` 🎓
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 🧸 🖼 🎦 ❔ ⚫️ 👷, 🚥 👆 💪 🗜 🐕🦺, 👆 💪 ⚙️ 🚚 [`GzipMiddleware`](../advanced/middleware.md#gzipmiddleware){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🥇, 👥 ✍ `GzipRequest` 🎓, ❔ 🔜 📁 `Request.body()` 👩🔬 🗜 💪 🔍 ☑ 🎚.
|
|
||||||
|
|
||||||
🚥 📤 🙅♂ `gzip` 🎚, ⚫️ 🔜 🚫 🔄 🗜 💪.
|
|
||||||
|
|
||||||
👈 🌌, 🎏 🛣 🎓 💪 🍵 🗜 🗜 ⚖️ 🗜 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial001.py hl[8:15] *}
|
|
||||||
|
|
||||||
### ✍ 🛃 `GzipRoute` 🎓
|
|
||||||
|
|
||||||
⏭, 👥 ✍ 🛃 🏿 `fastapi.routing.APIRoute` 👈 🔜 ⚒ ⚙️ `GzipRequest`.
|
|
||||||
|
|
||||||
👉 🕰, ⚫️ 🔜 📁 👩🔬 `APIRoute.get_route_handler()`.
|
|
||||||
|
|
||||||
👉 👩🔬 📨 🔢. & 👈 🔢 ⚫️❔ 🔜 📨 📨 & 📨 📨.
|
|
||||||
|
|
||||||
📥 👥 ⚙️ ⚫️ ✍ `GzipRequest` ⚪️➡️ ⏮️ 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial001.py hl[18:26] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
`Request` ✔️ `request.scope` 🔢, 👈 🐍 `dict` ⚗ 🗃 🔗 📨.
|
|
||||||
|
|
||||||
`Request` ✔️ `request.receive`, 👈 🔢 "📨" 💪 📨.
|
|
||||||
|
|
||||||
`scope` `dict` & `receive` 🔢 👯♂️ 🍕 🔫 🔧.
|
|
||||||
|
|
||||||
& 👈 2️⃣ 👜, `scope` & `receive`, ⚫️❔ 💪 ✍ 🆕 `Request` 👐.
|
|
||||||
|
|
||||||
💡 🌅 🔃 `Request` ✅ <a href="https://www.starlette.dev/requests/" class="external-link" target="_blank">💃 🩺 🔃 📨</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🕴 👜 🔢 📨 `GzipRequest.get_route_handler` 🔨 🎏 🗜 `Request` `GzipRequest`.
|
|
||||||
|
|
||||||
🔨 👉, 👆 `GzipRequest` 🔜 ✊ 💅 🗜 📊 (🚥 💪) ⏭ 🚶♀️ ⚫️ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
⏮️ 👈, 🌐 🏭 ⚛ 🎏.
|
|
||||||
|
|
||||||
✋️ ↩️ 👆 🔀 `GzipRequest.body`, 📨 💪 🔜 🔁 🗜 🕐❔ ⚫️ 📐 **FastAPI** 🕐❔ 💪.
|
|
||||||
|
|
||||||
## 🔐 📨 💪 ⚠ 🐕🦺
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
❎ 👉 🎏 ⚠, ⚫️ 🎲 📚 ⏩ ⚙️ `body` 🛃 🐕🦺 `RequestValidationError` ([🚚 ❌](../tutorial/handling-errors.md#requestvalidationerror){.internal-link target=_blank}).
|
|
||||||
|
|
||||||
✋️ 👉 🖼 ☑ & ⚫️ 🎦 ❔ 🔗 ⏮️ 🔗 🦲.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👥 💪 ⚙️ 👉 🎏 🎯 🔐 📨 💪 ⚠ 🐕🦺.
|
|
||||||
|
|
||||||
🌐 👥 💪 🍵 📨 🔘 `try`/`except` 🍫:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial002.py hl[13,15] *}
|
|
||||||
|
|
||||||
🚥 ⚠ 📉, `Request` 👐 🔜 ↔, 👥 💪 ✍ & ⚒ ⚙️ 📨 💪 🕐❔ 🚚 ❌:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial002.py hl[16:18] *}
|
|
||||||
|
|
||||||
## 🛃 `APIRoute` 🎓 📻
|
|
||||||
|
|
||||||
👆 💪 ⚒ `route_class` 🔢 `APIRouter`:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial003.py hl[26] *}
|
|
||||||
|
|
||||||
👉 🖼, *➡ 🛠️* 🔽 `router` 🔜 ⚙️ 🛃 `TimedRoute` 🎓, & 🔜 ✔️ ➕ `X-Response-Time` 🎚 📨 ⏮️ 🕰 ⚫️ ✊ 🏗 📨:
|
|
||||||
|
|
||||||
{* ../../docs_src/custom_request_and_route/tutorial003.py hl[13:20] *}
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
# ↔ 🗄
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👉 👍 🏧 ⚒. 👆 🎲 💪 🚶 ⚫️.
|
|
||||||
|
|
||||||
🚥 👆 📄 🔰 - 👩💻 🦮, 👆 💪 🎲 🚶 👉 📄.
|
|
||||||
|
|
||||||
🚥 👆 ⏪ 💭 👈 👆 💪 🔀 🏗 🗄 🔗, 😣 👂.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
📤 💼 🌐❔ 👆 💪 💪 🔀 🏗 🗄 🔗.
|
|
||||||
|
|
||||||
👉 📄 👆 🔜 👀 ❔.
|
|
||||||
|
|
||||||
## 😐 🛠️
|
|
||||||
|
|
||||||
😐 (🔢) 🛠️, ⏩.
|
|
||||||
|
|
||||||
`FastAPI` 🈸 (👐) ✔️ `.openapi()` 👩🔬 👈 📈 📨 🗄 🔗.
|
|
||||||
|
|
||||||
🍕 🈸 🎚 🏗, *➡ 🛠️* `/openapi.json` (⚖️ ⚫️❔ 👆 ⚒ 👆 `openapi_url`) ®.
|
|
||||||
|
|
||||||
⚫️ 📨 🎻 📨 ⏮️ 🏁 🈸 `.openapi()` 👩🔬.
|
|
||||||
|
|
||||||
🔢, ⚫️❔ 👩🔬 `.openapi()` 🔨 ✅ 🏠 `.openapi_schema` 👀 🚥 ⚫️ ✔️ 🎚 & 📨 👫.
|
|
||||||
|
|
||||||
🚥 ⚫️ 🚫, ⚫️ 🏗 👫 ⚙️ 🚙 🔢 `fastapi.openapi.utils.get_openapi`.
|
|
||||||
|
|
||||||
& 👈 🔢 `get_openapi()` 📨 🔢:
|
|
||||||
|
|
||||||
* `title`: 🗄 📛, 🎦 🩺.
|
|
||||||
* `version`: ⏬ 👆 🛠️, ✅ `2.5.0`.
|
|
||||||
* `openapi_version`: ⏬ 🗄 🔧 ⚙️. 🔢, ⏪: `3.0.2`.
|
|
||||||
* `description`: 📛 👆 🛠️.
|
|
||||||
* `routes`: 📇 🛣, 👫 🔠 ® *➡ 🛠️*. 👫 ✊ ⚪️➡️ `app.routes`.
|
|
||||||
|
|
||||||
## 🔑 🔢
|
|
||||||
|
|
||||||
⚙️ ℹ 🔛, 👆 💪 ⚙️ 🎏 🚙 🔢 🏗 🗄 🔗 & 🔐 🔠 🍕 👈 👆 💪.
|
|
||||||
|
|
||||||
🖼, ➡️ 🚮 <a href="https://github.com/Rebilly/ReDoc/blob/master/docs/redoc-vendor-extensions.md#x-logo" class="external-link" target="_blank">📄 🗄 ↔ 🔌 🛃 🔱</a>.
|
|
||||||
|
|
||||||
### 😐 **FastAPI**
|
|
||||||
|
|
||||||
🥇, ✍ 🌐 👆 **FastAPI** 🈸 🛎:
|
|
||||||
|
|
||||||
{* ../../docs_src/extending_openapi/tutorial001.py hl[1,4,7:9] *}
|
|
||||||
|
|
||||||
### 🏗 🗄 🔗
|
|
||||||
|
|
||||||
⤴️, ⚙️ 🎏 🚙 🔢 🏗 🗄 🔗, 🔘 `custom_openapi()` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/extending_openapi/tutorial001.py hl[2,15:20] *}
|
|
||||||
|
|
||||||
### 🔀 🗄 🔗
|
|
||||||
|
|
||||||
🔜 👆 💪 🚮 📄 ↔, ❎ 🛃 `x-logo` `info` "🎚" 🗄 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/extending_openapi/tutorial001.py hl[21:23] *}
|
|
||||||
|
|
||||||
### 💾 🗄 🔗
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🏠 `.openapi_schema` "💾", 🏪 👆 🏗 🔗.
|
|
||||||
|
|
||||||
👈 🌌, 👆 🈸 🏆 🚫 ✔️ 🏗 🔗 🔠 🕰 👩💻 📂 👆 🛠️ 🩺.
|
|
||||||
|
|
||||||
⚫️ 🔜 🏗 🕴 🕐, & ⤴️ 🎏 💾 🔗 🔜 ⚙️ ⏭ 📨.
|
|
||||||
|
|
||||||
{* ../../docs_src/extending_openapi/tutorial001.py hl[13:14,24:25] *}
|
|
||||||
|
|
||||||
### 🔐 👩🔬
|
|
||||||
|
|
||||||
🔜 👆 💪 ❎ `.openapi()` 👩🔬 ⏮️ 👆 🆕 🔢.
|
|
||||||
|
|
||||||
{* ../../docs_src/extending_openapi/tutorial001.py hl[28] *}
|
|
||||||
|
|
||||||
### ✅ ⚫️
|
|
||||||
|
|
||||||
🕐 👆 🚶 <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a> 👆 🔜 👀 👈 👆 ⚙️ 👆 🛃 🔱 (👉 🖼, **FastAPI**'Ⓜ 🔱):
|
|
||||||
|
|
||||||
<img src="/img/tutorial/extending-openapi/image01.png">
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
# 🕹
|
|
||||||
|
|
||||||
**FastAPI** ⚓️ 🔛 **🔫** 🐩, ⚫️ 📶 ⏩ 🛠️ 🙆 **🕹** 🗃 🔗 ⏮️ 🔫.
|
|
||||||
|
|
||||||
👆 💪 🌀 😐 FastAPI *➡ 🛠️* ⏮️ 🕹 🔛 🎏 🈸.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
**🕹** ❎ 📶 🎯 ⚙️ 💼.
|
|
||||||
|
|
||||||
⚫️ ✔️ **📈** & **⚠** 🕐❔ 🔬 ⚠ **🕸 🔗**.
|
|
||||||
|
|
||||||
⚒ 💭 👆 🔬 🚥 **💰** 👆 ⚙️ 💼 ⚖ **👐**. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🕹 🗃
|
|
||||||
|
|
||||||
📥 **🕹** 🗃 👈 ✔️ **🔫** 🐕🦺. 👆 💪 ⚙️ 👫 ⏮️ **FastAPI**:
|
|
||||||
|
|
||||||
* <a href="https://strawberry.rocks/" class="external-link" target="_blank">🍓</a> 👶
|
|
||||||
* ⏮️ <a href="https://strawberry.rocks/docs/integrations/fastapi" class="external-link" target="_blank">🩺 FastAPI</a>
|
|
||||||
* <a href="https://ariadnegraphql.org/" class="external-link" target="_blank">👸</a>
|
|
||||||
* ⏮️ <a href="https://ariadnegraphql.org/docs/fastapi-integration" class="external-link" target="_blank">🩺 FastAPI</a>
|
|
||||||
* <a href="https://tartiflette.io/" class="external-link" target="_blank">🍟</a>
|
|
||||||
* ⏮️ <a href="https://tartiflette.github.io/tartiflette-asgi/" class="external-link" target="_blank">🍟 🔫</a> 🚚 🔫 🛠️
|
|
||||||
* <a href="https://graphene-python.org/" class="external-link" target="_blank">⚗</a>
|
|
||||||
* ⏮️ <a href="https://github.com/ciscorn/starlette-graphene3" class="external-link" target="_blank">💃-Graphene3️⃣</a>
|
|
||||||
|
|
||||||
## 🕹 ⏮️ 🍓
|
|
||||||
|
|
||||||
🚥 👆 💪 ⚖️ 💚 👷 ⏮️ **🕹**, <a href="https://strawberry.rocks/" class="external-link" target="_blank">**🍓**</a> **👍** 🗃 ⚫️ ✔️ 🔧 🔐 **FastAPI** 🔧, ⚫️ 🌐 ⚓️ 🔛 **🆎 ✍**.
|
|
||||||
|
|
||||||
⚓️ 🔛 👆 ⚙️ 💼, 👆 5️⃣📆 💖 ⚙️ 🎏 🗃, ✋️ 🚥 👆 💭 👤, 👤 🔜 🎲 🤔 👆 🔄 **🍓**.
|
|
||||||
|
|
||||||
📥 🤪 🎮 ❔ 👆 💪 🛠️ 🍓 ⏮️ FastAPI:
|
|
||||||
|
|
||||||
{* ../../docs_src/graphql/tutorial001.py hl[3,22,25:26] *}
|
|
||||||
|
|
||||||
👆 💪 💡 🌅 🔃 🍓 <a href="https://strawberry.rocks/" class="external-link" target="_blank">🍓 🧾</a>.
|
|
||||||
|
|
||||||
& 🩺 🔃 <a href="https://strawberry.rocks/docs/integrations/fastapi" class="external-link" target="_blank">🍓 ⏮️ FastAPI</a>.
|
|
||||||
|
|
||||||
## 🗝 `GraphQLApp` ⚪️➡️ 💃
|
|
||||||
|
|
||||||
⏮️ ⏬ 💃 🔌 `GraphQLApp` 🎓 🛠️ ⏮️ <a href="https://graphene-python.org/" class="external-link" target="_blank">⚗</a>.
|
|
||||||
|
|
||||||
⚫️ 😢 ⚪️➡️ 💃, ✋️ 🚥 👆 ✔️ 📟 👈 ⚙️ ⚫️, 👆 💪 💪 **↔** <a href="https://github.com/ciscorn/starlette-graphene3" class="external-link" target="_blank">💃-Graphene3️⃣</a>, 👈 📔 🎏 ⚙️ 💼 & ✔️ **🌖 🌓 🔢**.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 💪 🕹, 👤 🔜 👍 👆 ✅ 👅 <a href="https://strawberry.rocks/" class="external-link" target="_blank">🍓</a>, ⚫️ ⚓️ 🔛 🆎 ✍ ↩️ 🛃 🎓 & 🆎.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💡 🌅
|
|
||||||
|
|
||||||
👆 💪 💡 🌅 🔃 **🕹** <a href="https://graphql.org/" class="external-link" target="_blank">🛂 🕹 🧾</a>.
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌅 🔃 🔠 👈 🗃 🔬 🔛 👫 🔗.
|
|
||||||
|
|
@ -1,474 +0,0 @@
|
||||||
# FastAPI
|
|
||||||
|
|
||||||
<style>
|
|
||||||
.md-content .md-typeset h1 { display: none; }
|
|
||||||
</style>
|
|
||||||
|
|
||||||
<p align="center">
|
|
||||||
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
|
|
||||||
</p>
|
|
||||||
<p align="center">
|
|
||||||
<em>FastAPI 🛠️, ↕ 🎭, ⏩ 💡, ⏩ 📟, 🔜 🏭</em>
|
|
||||||
</p>
|
|
||||||
<p align="center">
|
|
||||||
<a href="https://github.com/fastapi/fastapi/actions?query=workflow%3ATest+event%3Apush+branch%3Amaster" target="_blank">
|
|
||||||
<img src="https://github.com/fastapi/fastapi/actions/workflows/test.yml/badge.svg?event=push&branch=master" alt="Test">
|
|
||||||
</a>
|
|
||||||
<a href="https://coverage-badge.samuelcolvin.workers.dev/redirect/fastapi/fastapi" target="_blank">
|
|
||||||
<img src="https://coverage-badge.samuelcolvin.workers.dev/fastapi/fastapi.svg" alt="Coverage">
|
|
||||||
</a>
|
|
||||||
<a href="https://pypi.org/project/fastapi" target="_blank">
|
|
||||||
<img src="https://img.shields.io/pypi/v/fastapi?color=%2334D058&label=pypi%20package" alt="Package version">
|
|
||||||
</a>
|
|
||||||
<a href="https://pypi.org/project/fastapi" target="_blank">
|
|
||||||
<img src="https://img.shields.io/pypi/pyversions/fastapi.svg?color=%2334D058" alt="Supported Python versions">
|
|
||||||
</a>
|
|
||||||
</p>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
**🧾**: <a href="https://fastapi.tiangolo.com" target="_blank">https://fastapi.tiangolo.com</a>
|
|
||||||
|
|
||||||
**ℹ 📟**: <a href="https://github.com/fastapi/fastapi" target="_blank">https://github.com/fastapi/fastapi</a>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
FastAPI 🏛, ⏩ (↕-🎭), 🕸 🛠️ 🏗 🛠️ ⏮️ 🐍 3️⃣.8️⃣ ➕ ⚓️ 🔛 🐩 🐍 🆎 🔑.
|
|
||||||
|
|
||||||
🔑 ⚒:
|
|
||||||
|
|
||||||
* **⏩**: 📶 ↕ 🎭, 🔛 🇷🇪 ⏮️ **✳** & **🚶** (👏 💃 & Pydantic). [1️⃣ ⏩ 🐍 🛠️ 💪](#_15).
|
|
||||||
* **⏩ 📟**: 📈 🚅 🛠️ ⚒ 🔃 2️⃣0️⃣0️⃣ 💯 3️⃣0️⃣0️⃣ 💯. *
|
|
||||||
* **👩❤👨 🐛**: 📉 🔃 4️⃣0️⃣ 💯 🗿 (👩💻) 📉 ❌. *
|
|
||||||
* **🏋️**: 👑 👨🎨 🐕🦺. <abbr title="also known as auto-complete, autocompletion, IntelliSense">🛠️</abbr> 🌐. 🌘 🕰 🛠️.
|
|
||||||
* **⏩**: 🔧 ⏩ ⚙️ & 💡. 🌘 🕰 👂 🩺.
|
|
||||||
* **📏**: 📉 📟 ❎. 💗 ⚒ ⚪️➡️ 🔠 🔢 📄. 👩❤👨 🐛.
|
|
||||||
* **🏋️**: 🤚 🏭-🔜 📟. ⏮️ 🏧 🎓 🧾.
|
|
||||||
* **🐩-⚓️**: ⚓️ 🔛 (& 🍕 🔗 ⏮️) 📂 🐩 🔗: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">🗄</a> (⏪ 💭 🦁) & <a href="https://json-schema.org/" class="external-link" target="_blank">🎻 🔗</a>.
|
|
||||||
|
|
||||||
<small>* ⚖ ⚓️ 🔛 💯 🔛 🔗 🛠️ 🏉, 🏗 🏭 🈸.</small>
|
|
||||||
|
|
||||||
## 💰
|
|
||||||
|
|
||||||
<!-- sponsors -->
|
|
||||||
|
|
||||||
{% if sponsors %}
|
|
||||||
{% for sponsor in sponsors.gold -%}
|
|
||||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
|
||||||
{% endfor -%}
|
|
||||||
{%- for sponsor in sponsors.silver -%}
|
|
||||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
<!-- /sponsors -->
|
|
||||||
|
|
||||||
<a href="https://fastapi.tiangolo.com/fastapi-people/#sponsors" class="external-link" target="_blank">🎏 💰</a>
|
|
||||||
|
|
||||||
## 🤔
|
|
||||||
|
|
||||||
"_[...] 👤 ⚙️ **FastAPI** 📚 👫 📆. [...] 👤 🤙 📆 ⚙️ ⚫️ 🌐 👇 🏉 **⚗ 🐕🦺 🤸♂**. 👫 💆♂ 🛠️ 🔘 🐚 **🖥** 🏬 & **📠** 🏬._"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">🧿 🇵🇰 - <strong>🤸♂</strong> <a href="https://github.com/fastapi/fastapi/pull/26" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_👥 🛠️ **FastAPI** 🗃 🤖 **🎂** 💽 👈 💪 🔢 🚚 **🔮**. [👨📛]_"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">🇮🇹 🇸🇻, 👨📛 👨📛, & 🇱🇰 🕉 🕉 - <strong>🙃</strong> <a href="https://eng.uber.com/ludwig-v0-2/" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_**📺** 🙏 📣 📂-ℹ 🚀 👆 **⚔ 🧾** 🎶 🛠️: **📨**❗ [🏗 ⏮️ **FastAPI**]_"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">✡ 🍏, 👖 🇪🇸, 🌲 🍏 - <strong>📺</strong> <a href="https://netflixtechblog.com/introducing-dispatch-da4b8a2a8072" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_👤 🤭 🌕 😄 🔃 **FastAPI**. ⚫️ 🎊 ❗_"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">✡ 🇭🇰 - <strong><a href="https://pythonbytes.fm/episodes/show/123/time-to-right-the-py-wrongs?time_in_sec=855" target="_blank">🐍 🔢</a> 📻 🦠</strong> <a href="https://x.com/brianokken/status/1112220079972728832" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_🤙, ⚫️❔ 👆 ✔️ 🏗 👀 💎 💠 & 🇵🇱. 📚 🌌, ⚫️ ⚫️❔ 👤 💚 **🤗** - ⚫️ 🤙 😍 👀 👱 🏗 👈._"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">✡ 🗄 - <strong><a href="https://github.com/hugapi/hug" target="_blank">🤗</a> 👼</strong> <a href="https://news.ycombinator.com/item?id=19455465" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_🚥 👆 👀 💡 1️⃣ **🏛 🛠️** 🏗 🎂 🔗, ✅ 👅 **FastAPI** [...] ⚫️ ⏩, ⏩ ⚙️ & ⏩ 💡 [...]_"
|
|
||||||
|
|
||||||
"_👥 ✔️ 🎛 🤭 **FastAPI** 👆 **🔗** [...] 👤 💭 👆 🔜 💖 ⚫️ [...]_"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">🇱🇨 🇸🇲 - ✡ Honnibal - <strong><a href="https://explosion.ai" target="_blank">💥 👲</a> 🕴 - <a href="https://spacy.io" target="_blank">🌈</a> 👼</strong> <a href="https://x.com/_inesmontani/status/1144173225322143744" target="_blank"><small>(🇦🇪)</small></a> - <a href="https://x.com/honnibal/status/1144031421859655680" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
"_🚥 🙆 👀 🏗 🏭 🐍 🛠️, 👤 🔜 🏆 👍 **FastAPI**. ⚫️ **💎 🏗**, **🙅 ⚙️** & **🏆 🛠️**, ⚫️ ✔️ ▶️️ **🔑 🦲** 👆 🛠️ 🥇 🛠️ 🎛 & 🚘 📚 🏧 & 🐕🦺 ✅ 👆 🕹 🔫 👨💻._"
|
|
||||||
|
|
||||||
<div style="text-align: right; margin-right: 10%;">🇹🇦 🍰 - <strong>📻</strong> <a href="https://www.linkedin.com/posts/deonpillsbury_cisco-cx-python-activity-6963242628536487936-trAp/" target="_blank"><small>(🇦🇪)</small></a></div>
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## **🏎**, FastAPI 🇳🇨
|
|
||||||
|
|
||||||
<a href="https://typer.tiangolo.com" target="_blank"><img src="https://typer.tiangolo.com/img/logo-margin/logo-margin-vector.svg" style="width: 20%;"></a>
|
|
||||||
|
|
||||||
🚥 👆 🏗 <abbr title="Command Line Interface">✳</abbr> 📱 ⚙️ 📶 ↩️ 🕸 🛠️, ✅ 👅 <a href="https://typer.tiangolo.com/" class="external-link" target="_blank">**🏎**</a>.
|
|
||||||
|
|
||||||
**🏎** FastAPI 🐥 👪. & ⚫️ 🎯 **FastAPI 🇳🇨**. 👶 👶 👶
|
|
||||||
|
|
||||||
## 📄
|
|
||||||
|
|
||||||
🐍 3️⃣.7️⃣ ➕
|
|
||||||
|
|
||||||
FastAPI 🧍 🔛 ⌚ 🐘:
|
|
||||||
|
|
||||||
* <a href="https://www.starlette.dev/" class="external-link" target="_blank">💃</a> 🕸 🍕.
|
|
||||||
* <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> 📊 🍕.
|
|
||||||
|
|
||||||
## 👷♂
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "fastapi[standard]"
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
👆 🔜 💪 🔫 💽, 🏭 ✅ <a href="https://www.uvicorn.dev" class="external-link" target="_blank">Uvicorn</a> ⚖️ <a href="https://github.com/pgjones/hypercorn" class="external-link" target="_blank">Hypercorn</a>.
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "uvicorn[standard]"
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
## 🖼
|
|
||||||
|
|
||||||
### ✍ ⚫️
|
|
||||||
|
|
||||||
* ✍ 📁 `main.py` ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
def read_root():
|
|
||||||
return {"Hello": "World"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}")
|
|
||||||
def read_item(item_id: int, q: Union[str, None] = None):
|
|
||||||
return {"item_id": item_id, "q": q}
|
|
||||||
```
|
|
||||||
|
|
||||||
<details markdown="1">
|
|
||||||
<summary>⚖️ ⚙️ <code>async def</code>...</summary>
|
|
||||||
|
|
||||||
🚥 👆 📟 ⚙️ `async` / `await`, ⚙️ `async def`:
|
|
||||||
|
|
||||||
```Python hl_lines="9 14"
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
async def read_root():
|
|
||||||
return {"Hello": "World"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}")
|
|
||||||
async def read_item(item_id: int, q: Union[str, None] = None):
|
|
||||||
return {"item_id": item_id, "q": q}
|
|
||||||
```
|
|
||||||
|
|
||||||
**🗒**:
|
|
||||||
|
|
||||||
🚥 👆 🚫 💭, ✅ _"🏃 ❓" _ 📄 🔃 <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank">`async` & `await` 🩺</a>.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### 🏃 ⚫️
|
|
||||||
|
|
||||||
🏃 💽 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
INFO: Started reloader process [28720]
|
|
||||||
INFO: Started server process [28722]
|
|
||||||
INFO: Waiting for application startup.
|
|
||||||
INFO: Application startup complete.
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<details markdown="1">
|
|
||||||
<summary>🔃 📋 <code>uvicorn main:app --reload</code>...</summary>
|
|
||||||
|
|
||||||
📋 `uvicorn main:app` 🔗:
|
|
||||||
|
|
||||||
* `main`: 📁 `main.py` (🐍 "🕹").
|
|
||||||
* `app`: 🎚 ✍ 🔘 `main.py` ⏮️ ⏸ `app = FastAPI()`.
|
|
||||||
* `--reload`: ⚒ 💽 ⏏ ⏮️ 📟 🔀. 🕴 👉 🛠️.
|
|
||||||
|
|
||||||
</details>
|
|
||||||
|
|
||||||
### ✅ ⚫️
|
|
||||||
|
|
||||||
📂 👆 🖥 <a href="http://127.0.0.1:8000/items/5?q=somequery" class="external-link" target="_blank">http://127.0.0.1:8000/items/5?q=somequery</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🎻 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"item_id": 5, "q": "somequery"}
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 ⏪ ✍ 🛠️ 👈:
|
|
||||||
|
|
||||||
* 📨 🇺🇸🔍 📨 _➡_ `/` & `/items/{item_id}`.
|
|
||||||
* 👯♂️ _➡_ ✊ `GET` <em>🛠️</em> (💭 🇺🇸🔍 _👩🔬_).
|
|
||||||
* _➡_ `/items/{item_id}` ✔️ _➡ 🔢_ `item_id` 👈 🔜 `int`.
|
|
||||||
* _➡_ `/items/{item_id}` ✔️ 📦 `str` _🔢 = `q`.
|
|
||||||
|
|
||||||
### 🎓 🛠️ 🩺
|
|
||||||
|
|
||||||
🔜 🚶 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🎓 🛠️ 🧾 (🚚 <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">🦁 🎚</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🎛 🛠️ 🩺
|
|
||||||
|
|
||||||
& 🔜, 🚶 <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🎛 🏧 🧾 (🚚 <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">📄</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
## 🖼 ♻
|
|
||||||
|
|
||||||
🔜 🔀 📁 `main.py` 📨 💪 ⚪️➡️ `PUT` 📨.
|
|
||||||
|
|
||||||
📣 💪 ⚙️ 🐩 🐍 🆎, 👏 Pydantic.
|
|
||||||
|
|
||||||
```Python hl_lines="4 9-12 25-27"
|
|
||||||
from typing import Union
|
|
||||||
|
|
||||||
from fastapi import FastAPI
|
|
||||||
from pydantic import BaseModel
|
|
||||||
|
|
||||||
app = FastAPI()
|
|
||||||
|
|
||||||
|
|
||||||
class Item(BaseModel):
|
|
||||||
name: str
|
|
||||||
price: float
|
|
||||||
is_offer: Union[bool, None] = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/")
|
|
||||||
def read_root():
|
|
||||||
return {"Hello": "World"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.get("/items/{item_id}")
|
|
||||||
def read_item(item_id: int, q: Union[str, None] = None):
|
|
||||||
return {"item_id": item_id, "q": q}
|
|
||||||
|
|
||||||
|
|
||||||
@app.put("/items/{item_id}")
|
|
||||||
def update_item(item_id: int, item: Item):
|
|
||||||
return {"item_name": item.name, "item_id": item_id}
|
|
||||||
```
|
|
||||||
|
|
||||||
💽 🔜 🔃 🔁 (↩️ 👆 🚮 `--reload` `uvicorn` 📋 🔛).
|
|
||||||
|
|
||||||
### 🎓 🛠️ 🩺 ♻
|
|
||||||
|
|
||||||
🔜 🚶 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
* 🎓 🛠️ 🧾 🔜 🔁 ℹ, 🔌 🆕 💪:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* 🖊 🔛 🔼 "🔄 ⚫️ 👅", ⚫️ ✔ 👆 🥧 🔢 & 🔗 🔗 ⏮️ 🛠️:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
* ⤴️ 🖊 🔛 "🛠️" 🔼, 👩💻 🔢 🔜 🔗 ⏮️ 👆 🛠️, 📨 🔢, 🤚 🏁 & 🎦 👫 🔛 🖥:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🎛 🛠️ 🩺 ♻
|
|
||||||
|
|
||||||
& 🔜, 🚶 <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
|
|
||||||
|
|
||||||
* 🎛 🧾 🔜 🎨 🆕 🔢 🔢 & 💪:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🌃
|
|
||||||
|
|
||||||
📄, 👆 📣 **🕐** 🆎 🔢, 💪, ♒️. 🔢 🔢.
|
|
||||||
|
|
||||||
👆 👈 ⏮️ 🐩 🏛 🐍 🆎.
|
|
||||||
|
|
||||||
👆 🚫 ✔️ 💡 🆕 ❕, 👩🔬 ⚖️ 🎓 🎯 🗃, ♒️.
|
|
||||||
|
|
||||||
🐩 **🐍 3️⃣.7️⃣ ➕**.
|
|
||||||
|
|
||||||
🖼, `int`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
item_id: int
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️ 🌖 🏗 `Item` 🏷:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
item: Item
|
|
||||||
```
|
|
||||||
|
|
||||||
...& ⏮️ 👈 👁 📄 👆 🤚:
|
|
||||||
|
|
||||||
* 👨🎨 🐕🦺, 🔌:
|
|
||||||
* 🛠️.
|
|
||||||
* 🆎 ✅.
|
|
||||||
* 🔬 💽:
|
|
||||||
* 🏧 & 🆑 ❌ 🕐❔ 📊 ❌.
|
|
||||||
* 🔬 🙇 🐦 🎻 🎚.
|
|
||||||
* <abbr title="also known as: serialization, parsing, marshalling">🛠️</abbr> 🔢 💽: 👟 ⚪️➡️ 🕸 🐍 💽 & 🆎. 👂 ⚪️➡️:
|
|
||||||
* 🎻.
|
|
||||||
* ➡ 🔢.
|
|
||||||
* 🔢 🔢.
|
|
||||||
* 🍪.
|
|
||||||
* 🎚.
|
|
||||||
* 📨.
|
|
||||||
* 📁.
|
|
||||||
* <abbr title="also known as: serialization, parsing, marshalling">🛠️</abbr> 🔢 📊: 🗜 ⚪️➡️ 🐍 💽 & 🆎 🕸 💽 (🎻):
|
|
||||||
* 🗜 🐍 🆎 (`str`, `int`, `float`, `bool`, `list`, ♒️).
|
|
||||||
* `datetime` 🎚.
|
|
||||||
* `UUID` 🎚.
|
|
||||||
* 💽 🏷.
|
|
||||||
* ...& 📚 🌖.
|
|
||||||
* 🏧 🎓 🛠️ 🧾, 🔌 2️⃣ 🎛 👩💻 🔢:
|
|
||||||
* 🦁 🎚.
|
|
||||||
* 📄.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👟 🔙 ⏮️ 📟 🖼, **FastAPI** 🔜:
|
|
||||||
|
|
||||||
* ✔ 👈 📤 `item_id` ➡ `GET` & `PUT` 📨.
|
|
||||||
* ✔ 👈 `item_id` 🆎 `int` `GET` & `PUT` 📨.
|
|
||||||
* 🚥 ⚫️ 🚫, 👩💻 🔜 👀 ⚠, 🆑 ❌.
|
|
||||||
* ✅ 🚥 📤 📦 🔢 🔢 📛 `q` ( `http://127.0.0.1:8000/items/foo?q=somequery`) `GET` 📨.
|
|
||||||
* `q` 🔢 📣 ⏮️ `= None`, ⚫️ 📦.
|
|
||||||
* 🍵 `None` ⚫️ 🔜 🚚 (💪 💼 ⏮️ `PUT`).
|
|
||||||
* `PUT` 📨 `/items/{item_id}`, ✍ 💪 🎻:
|
|
||||||
* ✅ 👈 ⚫️ ✔️ ✔ 🔢 `name` 👈 🔜 `str`.
|
|
||||||
* ✅ 👈 ⚫️ ✔️ ✔ 🔢 `price` 👈 ✔️ `float`.
|
|
||||||
* ✅ 👈 ⚫️ ✔️ 📦 🔢 `is_offer`, 👈 🔜 `bool`, 🚥 🎁.
|
|
||||||
* 🌐 👉 🔜 👷 🙇 🐦 🎻 🎚.
|
|
||||||
* 🗜 ⚪️➡️ & 🎻 🔁.
|
|
||||||
* 📄 🌐 ⏮️ 🗄, 👈 💪 ⚙️:
|
|
||||||
* 🎓 🧾 ⚙️.
|
|
||||||
* 🏧 👩💻 📟 ⚡ ⚙️, 📚 🇪🇸.
|
|
||||||
* 🚚 2️⃣ 🎓 🧾 🕸 🔢 🔗.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👥 🖌 🧽, ✋️ 👆 ⏪ 🤚 💭 ❔ ⚫️ 🌐 👷.
|
|
||||||
|
|
||||||
🔄 🔀 ⏸ ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
return {"item_name": item.name, "item_id": item_id}
|
|
||||||
```
|
|
||||||
|
|
||||||
...⚪️➡️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
... "item_name": item.name ...
|
|
||||||
```
|
|
||||||
|
|
||||||
...:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
... "item_price": item.price ...
|
|
||||||
```
|
|
||||||
|
|
||||||
...& 👀 ❔ 👆 👨🎨 🔜 🚘-🏁 🔢 & 💭 👫 🆎:
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
🌅 🏁 🖼 🔌 🌅 ⚒, 👀 <a href="https://fastapi.tiangolo.com/tutorial/">🔰 - 👩💻 🦮</a>.
|
|
||||||
|
|
||||||
**🚘 🚨**: 🔰 - 👩💻 🦮 🔌:
|
|
||||||
|
|
||||||
* 📄 **🔢** ⚪️➡️ 🎏 🎏 🥉: **🎚**, **🍪**, **📨 🏑** & **📁**.
|
|
||||||
* ❔ ⚒ **🔬 ⚛** `maximum_length` ⚖️ `regex`.
|
|
||||||
* 📶 🏋️ & ⏩ ⚙️ **<abbr title="also known as components, resources, providers, services, injectables">🔗 💉</abbr>** ⚙️.
|
|
||||||
* 💂♂ & 🤝, ✅ 🐕🦺 **Oauth2️⃣** ⏮️ **🥙 🤝** & **🇺🇸🔍 🔰** 🔐.
|
|
||||||
* 🌅 🏧 (✋️ 😨 ⏩) ⚒ 📣 **🙇 🐦 🎻 🏷** (👏 Pydantic).
|
|
||||||
* **🕹** 🛠️ ⏮️ <a href="https://strawberry.rocks" class="external-link" target="_blank">🍓</a> & 🎏 🗃.
|
|
||||||
* 📚 ➕ ⚒ (👏 💃):
|
|
||||||
* ** *️⃣ **
|
|
||||||
* 📶 ⏩ 💯 ⚓️ 🔛 🇸🇲 & `pytest`
|
|
||||||
* **⚜**
|
|
||||||
* **🍪 🎉**
|
|
||||||
* ...& 🌖.
|
|
||||||
|
|
||||||
## 🎭
|
|
||||||
|
|
||||||
🔬 🇸🇲 📇 🎦 **FastAPI** 🈸 🏃♂ 🔽 Uvicorn <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">1️⃣ ⏩ 🐍 🛠️ 💪</a>, 🕴 🔛 💃 & Uvicorn 👫 (⚙️ 🔘 FastAPI). (*)
|
|
||||||
|
|
||||||
🤔 🌖 🔃 ⚫️, 👀 📄 <a href="https://fastapi.tiangolo.com/benchmarks/" class="internal-link" target="_blank">📇</a>.
|
|
||||||
|
|
||||||
## 📦 🔗
|
|
||||||
|
|
||||||
⚙️ Pydantic:
|
|
||||||
|
|
||||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - 📧 🔬.
|
|
||||||
|
|
||||||
⚙️ 💃:
|
|
||||||
|
|
||||||
* <a href="https://www.python-httpx.org" target="_blank"><code>httpx</code></a> - ✔ 🚥 👆 💚 ⚙️ `TestClient`.
|
|
||||||
* <a href="https://jinja.palletsprojects.com" target="_blank"><code>jinja2</code></a> - ✔ 🚥 👆 💚 ⚙️ 🔢 📄 📳.
|
|
||||||
* <a href="https://github.com/Kludex/python-multipart" target="_blank"><code>python-multipart</code></a> - ✔ 🚥 👆 💚 🐕🦺 📨 <abbr title="converting the string that comes from an HTTP request into Python data">"✍"</abbr>, ⏮️ `request.form()`.
|
|
||||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - ✔ `SessionMiddleware` 🐕🦺.
|
|
||||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - ✔ 💃 `SchemaGenerator` 🐕🦺 (👆 🎲 🚫 💪 ⚫️ ⏮️ FastAPI).
|
|
||||||
|
|
||||||
⚙️ FastAPI / 💃:
|
|
||||||
|
|
||||||
* <a href="https://www.uvicorn.dev" target="_blank"><code>uvicorn</code></a> - 💽 👈 📐 & 🍦 👆 🈸.
|
|
||||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - ✔ 🚥 👆 💚 ⚙️ `ORJSONResponse`.
|
|
||||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - ✔ 🚥 👆 💚 ⚙️ `UJSONResponse`.
|
|
||||||
|
|
||||||
👆 💪 ❎ 🌐 👫 ⏮️ `pip install "fastapi[all]"`.
|
|
||||||
|
|
||||||
## 🛂
|
|
||||||
|
|
||||||
👉 🏗 ® 🔽 ⚖ 🇩🇪 🛂.
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
# 🏗 ⚡ - 📄
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🏗 🚂 🤚 ▶️, ⚫️ 🔌 📚 ▶️ ⚒ 🆙, 💂♂, 💽 & 🛠️ 🔗 ⏪ ⌛ 👆.
|
|
||||||
|
|
||||||
🏗 🚂 🔜 🕧 ✔️ 📶 🙃 🖥 👈 👆 🔜 ℹ & 🛠️ 👆 👍 💪, ✋️ ⚫️ 💪 👍 ▶️ ☝ 👆 🏗.
|
|
||||||
|
|
||||||
## 🌕 📚 FastAPI ✳
|
|
||||||
|
|
||||||
📂: <a href="https://github.com/tiangolo/full-stack-fastapi-postgresql" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-postgresql</a>
|
|
||||||
|
|
||||||
### 🌕 📚 FastAPI ✳ - ⚒
|
|
||||||
|
|
||||||
* 🌕 **☁** 🛠️ (☁ 🧢).
|
|
||||||
* ☁ 🐝 📳 🛠️.
|
|
||||||
* **☁ ✍** 🛠️ & 🛠️ 🇧🇿 🛠️.
|
|
||||||
* **🏭 🔜** 🐍 🕸 💽 ⚙️ Uvicorn & 🐁.
|
|
||||||
* 🐍 <a href="https://github.com/fastapi/fastapi" class="external-link" target="_blank">**FastAPI**</a> 👩💻:
|
|
||||||
* **⏩**: 📶 ↕ 🎭, 🔛 🇷🇪 ⏮️ **✳** & **🚶** (👏 💃 & Pydantic).
|
|
||||||
* **🏋️**: 👑 👨🎨 🐕🦺. <abbr title="also known as auto-complete, autocompletion, IntelliSense">🛠️</abbr> 🌐. 🌘 🕰 🛠️.
|
|
||||||
* **⏩**: 🔧 ⏩ ⚙️ & 💡. 🌘 🕰 👂 🩺.
|
|
||||||
* **📏**: 📉 📟 ❎. 💗 ⚒ ⚪️➡️ 🔠 🔢 📄.
|
|
||||||
* **🏋️**: 🤚 🏭-🔜 📟. ⏮️ 🏧 🎓 🧾.
|
|
||||||
* **🐩-⚓️**: ⚓️ 🔛 (& 🍕 🔗 ⏮️) 📂 🐩 🔗: <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">🗄</a> & <a href="https://json-schema.org/" class="external-link" target="_blank">🎻 🔗</a>.
|
|
||||||
* <a href="https://fastapi.tiangolo.com/features/" class="external-link" target="_blank">**📚 🎏 ⚒**</a> 🔌 🏧 🔬, 🛠️, 🎓 🧾, 🤝 ⏮️ Oauth2️⃣ 🥙 🤝, ♒️.
|
|
||||||
* **🔐 🔐** 🔁 🔢.
|
|
||||||
* **🥙 🤝** 🤝.
|
|
||||||
* **🇸🇲** 🏷 (🔬 🏺 ↔, 👫 💪 ⚙️ ⏮️ 🥒 👨🏭 🔗).
|
|
||||||
* 🔰 ▶️ 🏷 👩💻 (🔀 & ❎ 👆 💪).
|
|
||||||
* **⚗** 🛠️.
|
|
||||||
* **⚜** (✖️ 🇨🇳 ℹ 🤝).
|
|
||||||
* **🥒** 👨🏭 👈 💪 🗄 & ⚙️ 🏷 & 📟 ⚪️➡️ 🎂 👩💻 🍕.
|
|
||||||
* 🎂 👩💻 💯 ⚓️ 🔛 **✳**, 🛠️ ⏮️ ☁, 👆 💪 💯 🌕 🛠️ 🔗, 🔬 🔛 💽. ⚫️ 🏃 ☁, ⚫️ 💪 🏗 🆕 💽 🏪 ⚪️➡️ 🖌 🔠 🕰 (👆 💪 ⚙️ ✳, ✳, ✳, ⚖️ ⚫️❔ 👆 💚, & 💯 👈 🛠️ 👷).
|
|
||||||
* ⏩ 🐍 🛠️ ⏮️ **📂 💾** 🛰 ⚖️-☁ 🛠️ ⏮️ ↔ 💖 ⚛ ⚗ ⚖️ 🎙 🎙 📟 📂.
|
|
||||||
* **🎦** 🕸:
|
|
||||||
* 🏗 ⏮️ 🎦 ✳.
|
|
||||||
* **🥙 🤝** 🚚.
|
|
||||||
* 💳 🎑.
|
|
||||||
* ⏮️ 💳, 👑 🕹 🎑.
|
|
||||||
* 👑 🕹 ⏮️ 👩💻 🏗 & 📕.
|
|
||||||
* 👤 👩💻 📕.
|
|
||||||
* **🇷🇪**.
|
|
||||||
* **🎦-📻**.
|
|
||||||
* **Vuetify** 🌹 🧽 🔧 🦲.
|
|
||||||
* **📕**.
|
|
||||||
* ☁ 💽 ⚓️ 🔛 **👌** (📶 🤾 🎆 ⏮️ 🎦-📻).
|
|
||||||
* ☁ 👁-▶️ 🏗, 👆 🚫 💪 🖊 ⚖️ 💕 ✍ 📟.
|
|
||||||
* 🕸 💯 🏃 🏗 🕰 (💪 🔕 💁♂️).
|
|
||||||
* ⚒ 🔧 💪, ⚫️ 👷 👅 📦, ✋️ 👆 💪 🏤-🏗 ⏮️ 🎦 ✳ ⚖️ ✍ ⚫️ 👆 💪, & 🏤-⚙️ ⚫️❔ 👆 💚.
|
|
||||||
* ** *️⃣ ** ✳ 💽, 👆 💪 🔀 ⚫️ ⚙️ 📁 & ✳ 💪.
|
|
||||||
* **🥀** 🥒 👨🏭 ⚖.
|
|
||||||
* 📐 ⚖ 🖖 🕸 & 👩💻 ⏮️ **Traefik**, 👆 💪 ✔️ 👯♂️ 🔽 🎏 🆔, 👽 ➡, ✋️ 🍦 🎏 📦.
|
|
||||||
* Traefik 🛠️, ✅ ➡️ 🗜 **🇺🇸🔍** 📄 🏧 ⚡.
|
|
||||||
* ✳ **🆑** (🔁 🛠️), 🔌 🕸 & 👩💻 🔬.
|
|
||||||
|
|
||||||
## 🌕 📚 FastAPI 🗄
|
|
||||||
|
|
||||||
📂: <a href="https://github.com/tiangolo/full-stack-fastapi-couchbase" class="external-link" target="_blank">https://github.com/tiangolo/full-stack-fastapi-couchbase</a>
|
|
||||||
|
|
||||||
👶 👶 **⚠** 👶 👶
|
|
||||||
|
|
||||||
🚥 👆 ▶️ 🆕 🏗 ⚪️➡️ 🖌, ✅ 🎛 📥.
|
|
||||||
|
|
||||||
🖼, 🏗 🚂 <a href="https://github.com/tiangolo/full-stack-fastapi-postgresql" class="external-link" target="_blank">🌕 📚 FastAPI ✳</a> 💪 👍 🎛, ⚫️ 🎯 🚧 & ⚙️. & ⚫️ 🔌 🌐 🆕 ⚒ & 📈.
|
|
||||||
|
|
||||||
👆 🆓 ⚙️ 🗄-⚓️ 🚂 🚥 👆 💚, ⚫️ 🔜 🎲 👷 👌, & 🚥 👆 ⏪ ✔️ 🏗 🏗 ⏮️ ⚫️ 👈 👌 👍 (& 👆 🎲 ⏪ ℹ ⚫️ ♣ 👆 💪).
|
|
||||||
|
|
||||||
👆 💪 ✍ 🌅 🔃 ⚫️ 🩺 🏦.
|
|
||||||
|
|
||||||
## 🌕 📚 FastAPI ✳
|
|
||||||
|
|
||||||
...💪 👟 ⏪, ⚓️ 🔛 👇 🕰 🚚 & 🎏 ⚖. 👶 👶
|
|
||||||
|
|
||||||
## 🎰 🏫 🏷 ⏮️ 🌈 & FastAPI
|
|
||||||
|
|
||||||
📂: <a href="https://github.com/microsoft/cookiecutter-spacy-fastapi" class="external-link" target="_blank">https://github.com/microsoft/cookiecutter-spacy-fastapi</a>
|
|
||||||
|
|
||||||
### 🎰 🏫 🏷 ⏮️ 🌈 & FastAPI - ⚒
|
|
||||||
|
|
||||||
* **🌈** 🕜 🏷 🛠️.
|
|
||||||
* **☁ 🧠 🔎** 📨 📁 🏗.
|
|
||||||
* **🏭 🔜** 🐍 🕸 💽 ⚙️ Uvicorn & 🐁.
|
|
||||||
* **☁ 👩💻** Kubernetes (🦲) 🆑/💿 🛠️ 🏗.
|
|
||||||
* **🤸♂** 💪 ⚒ 1️⃣ 🌈 🏗 🇪🇸 ⏮️ 🏗 🖥.
|
|
||||||
* **💪 🏧** 🎏 🏷 🛠️ (Pytorch, 🇸🇲), 🚫 🌈.
|
|
||||||
|
|
@ -1,542 +0,0 @@
|
||||||
# 🐍 🆎 🎶
|
|
||||||
|
|
||||||
🐍 ✔️ 🐕🦺 📦 "🆎 🔑".
|
|
||||||
|
|
||||||
👫 **"🆎 🔑"** 🎁 ❕ 👈 ✔ 📣 <abbr title="for example: str, int, float, bool">🆎</abbr> 🔢.
|
|
||||||
|
|
||||||
📣 🆎 👆 🔢, 👨🎨 & 🧰 💪 🤝 👆 👍 🐕🦺.
|
|
||||||
|
|
||||||
👉 **⏩ 🔰 / ↗️** 🔃 🐍 🆎 🔑. ⚫️ 📔 🕴 💯 💪 ⚙️ 👫 ⏮️ **FastAPI**... ❔ 🤙 📶 🐥.
|
|
||||||
|
|
||||||
**FastAPI** 🌐 ⚓️ 🔛 👫 🆎 🔑, 👫 🤝 ⚫️ 📚 📈 & 💰.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🙅 ⚙️ **FastAPI**, 👆 🔜 💰 ⚪️➡️ 🏫 🍖 🔃 👫.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🚥 👆 🐍 🕴, & 👆 ⏪ 💭 🌐 🔃 🆎 🔑, 🚶 ⏭ 📃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🎯
|
|
||||||
|
|
||||||
➡️ ▶️ ⏮️ 🙅 🖼:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!../../docs_src/python_types/tutorial001.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
🤙 👉 📋 🔢:
|
|
||||||
|
|
||||||
```
|
|
||||||
John Doe
|
|
||||||
```
|
|
||||||
|
|
||||||
🔢 🔨 📄:
|
|
||||||
|
|
||||||
* ✊ `first_name` & `last_name`.
|
|
||||||
* 🗜 🥇 🔤 🔠 1️⃣ ↖ 💼 ⏮️ `title()`.
|
|
||||||
* <abbr title="Puts them together, as one. With the contents of one after the other.">🔢</abbr> 👫 ⏮️ 🚀 🖕.
|
|
||||||
|
|
||||||
```Python hl_lines="2"
|
|
||||||
{!../../docs_src/python_types/tutorial001.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### ✍ ⚫️
|
|
||||||
|
|
||||||
⚫️ 📶 🙅 📋.
|
|
||||||
|
|
||||||
✋️ 🔜 🌈 👈 👆 ✍ ⚫️ ⚪️➡️ 🖌.
|
|
||||||
|
|
||||||
☝ 👆 🔜 ✔️ ▶️ 🔑 🔢, 👆 ✔️ 🔢 🔜...
|
|
||||||
|
|
||||||
✋️ ⤴️ 👆 ✔️ 🤙 "👈 👩🔬 👈 🗜 🥇 🔤 ↖ 💼".
|
|
||||||
|
|
||||||
⚫️ `upper`❓ ⚫️ `uppercase`❓ `first_uppercase`❓ `capitalize`❓
|
|
||||||
|
|
||||||
⤴️, 👆 🔄 ⏮️ 🗝 👩💻 👨👧👦, 👨🎨 ✍.
|
|
||||||
|
|
||||||
👆 🆎 🥇 🔢 🔢, `first_name`, ⤴️ ❣ (`.`) & ⤴️ 🎯 `Ctrl+Space` ⏲ 🛠️.
|
|
||||||
|
|
||||||
✋️, 😞, 👆 🤚 🕳 ⚠:
|
|
||||||
|
|
||||||
<img src="/img/python-types/image01.png">
|
|
||||||
|
|
||||||
### 🚮 🆎
|
|
||||||
|
|
||||||
➡️ 🔀 👁 ⏸ ⚪️➡️ ⏮️ ⏬.
|
|
||||||
|
|
||||||
👥 🔜 🔀 ⚫️❔ 👉 🧬, 🔢 🔢, ⚪️➡️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
first_name, last_name
|
|
||||||
```
|
|
||||||
|
|
||||||
:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
first_name: str, last_name: str
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 ⚫️.
|
|
||||||
|
|
||||||
👈 "🆎 🔑":
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!../../docs_src/python_types/tutorial002.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 🚫 🎏 📣 🔢 💲 💖 🔜 ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
first_name="john", last_name="doe"
|
|
||||||
```
|
|
||||||
|
|
||||||
⚫️ 🎏 👜.
|
|
||||||
|
|
||||||
👥 ⚙️ ❤ (`:`), 🚫 🌓 (`=`).
|
|
||||||
|
|
||||||
& ❎ 🆎 🔑 🛎 🚫 🔀 ⚫️❔ 🔨 ⚪️➡️ ⚫️❔ 🔜 🔨 🍵 👫.
|
|
||||||
|
|
||||||
✋️ 🔜, 🌈 👆 🔄 🖕 🏗 👈 🔢, ✋️ ⏮️ 🆎 🔑.
|
|
||||||
|
|
||||||
🎏 ☝, 👆 🔄 ⏲ 📋 ⏮️ `Ctrl+Space` & 👆 👀:
|
|
||||||
|
|
||||||
<img src="/img/python-types/image02.png">
|
|
||||||
|
|
||||||
⏮️ 👈, 👆 💪 📜, 👀 🎛, ⏭ 👆 🔎 1️⃣ 👈 "💍 🔔":
|
|
||||||
|
|
||||||
<img src="/img/python-types/image03.png">
|
|
||||||
|
|
||||||
## 🌅 🎯
|
|
||||||
|
|
||||||
✅ 👉 🔢, ⚫️ ⏪ ✔️ 🆎 🔑:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!../../docs_src/python_types/tutorial003.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
↩️ 👨🎨 💭 🆎 🔢, 👆 🚫 🕴 🤚 🛠️, 👆 🤚 ❌ ✅:
|
|
||||||
|
|
||||||
<img src="/img/python-types/image04.png">
|
|
||||||
|
|
||||||
🔜 👆 💭 👈 👆 ✔️ 🔧 ⚫️, 🗜 `age` 🎻 ⏮️ `str(age)`:
|
|
||||||
|
|
||||||
```Python hl_lines="2"
|
|
||||||
{!../../docs_src/python_types/tutorial004.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📣 🆎
|
|
||||||
|
|
||||||
👆 👀 👑 🥉 📣 🆎 🔑. 🔢 🔢.
|
|
||||||
|
|
||||||
👉 👑 🥉 👆 🔜 ⚙️ 👫 ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
### 🙅 🆎
|
|
||||||
|
|
||||||
👆 💪 📣 🌐 🐩 🐍 🆎, 🚫 🕴 `str`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️, 🖼:
|
|
||||||
|
|
||||||
* `int`
|
|
||||||
* `float`
|
|
||||||
* `bool`
|
|
||||||
* `bytes`
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!../../docs_src/python_types/tutorial005.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 💊 🆎 ⏮️ 🆎 🔢
|
|
||||||
|
|
||||||
📤 📊 📊 👈 💪 🔌 🎏 💲, 💖 `dict`, `list`, `set` & `tuple`. & 🔗 💲 💪 ✔️ 👫 👍 🆎 💁♂️.
|
|
||||||
|
|
||||||
👉 🆎 👈 ✔️ 🔗 🆎 🤙 "**💊**" 🆎. & ⚫️ 💪 📣 👫, ⏮️ 👫 🔗 🆎.
|
|
||||||
|
|
||||||
📣 👈 🆎 & 🔗 🆎, 👆 💪 ⚙️ 🐩 🐍 🕹 `typing`. ⚫️ 🔀 🎯 🐕🦺 👫 🆎 🔑.
|
|
||||||
|
|
||||||
#### 🆕 ⏬ 🐍
|
|
||||||
|
|
||||||
❕ ⚙️ `typing` **🔗** ⏮️ 🌐 ⏬, ⚪️➡️ 🐍 3️⃣.6️⃣ ⏪ 🕐, ✅ 🐍 3️⃣.9️⃣, 🐍 3️⃣.1️⃣0️⃣, ♒️.
|
|
||||||
|
|
||||||
🐍 🏧, **🆕 ⏬** 👟 ⏮️ 📉 🐕🦺 👉 🆎 ✍ & 📚 💼 👆 🏆 🚫 💪 🗄 & ⚙️ `typing` 🕹 📣 🆎 ✍.
|
|
||||||
|
|
||||||
🚥 👆 💪 ⚒ 🌖 ⏮️ ⏬ 🐍 👆 🏗, 👆 🔜 💪 ✊ 📈 👈 ➕ 🦁. 👀 🖼 🔛.
|
|
||||||
|
|
||||||
#### 📇
|
|
||||||
|
|
||||||
🖼, ➡️ 🔬 🔢 `list` `str`.
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
⚪️➡️ `typing`, 🗄 `List` (⏮️ 🔠 `L`):
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial006.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
📣 🔢, ⏮️ 🎏 ❤ (`:`) ❕.
|
|
||||||
|
|
||||||
🆎, 🚮 `List` 👈 👆 🗄 ⚪️➡️ `typing`.
|
|
||||||
|
|
||||||
📇 🆎 👈 🔌 🔗 🆎, 👆 🚮 👫 ⬜ 🗜:
|
|
||||||
|
|
||||||
```Python hl_lines="4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial006.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.9️⃣ & 🔛
|
|
||||||
|
|
||||||
📣 🔢, ⏮️ 🎏 ❤ (`:`) ❕.
|
|
||||||
|
|
||||||
🆎, 🚮 `list`.
|
|
||||||
|
|
||||||
📇 🆎 👈 🔌 🔗 🆎, 👆 🚮 👫 ⬜ 🗜:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial006_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👈 🔗 🆎 ⬜ 🗜 🤙 "🆎 🔢".
|
|
||||||
|
|
||||||
👉 💼, `str` 🆎 🔢 🚶♀️ `List` (⚖️ `list` 🐍 3️⃣.9️⃣ & 🔛).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👈 ⛓: "🔢 `items` `list`, & 🔠 🏬 👉 📇 `str`".
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🐍 3️⃣.9️⃣ ⚖️ 🔛, 👆 🚫 ✔️ 🗄 `List` ⚪️➡️ `typing`, 👆 💪 ⚙️ 🎏 🥔 `list` 🆎 ↩️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔨 👈, 👆 👨🎨 💪 🚚 🐕🦺 ⏪ 🏭 🏬 ⚪️➡️ 📇:
|
|
||||||
|
|
||||||
<img src="/img/python-types/image05.png">
|
|
||||||
|
|
||||||
🍵 🆎, 👈 🌖 💪 🏆.
|
|
||||||
|
|
||||||
👀 👈 🔢 `item` 1️⃣ 🔣 📇 `items`.
|
|
||||||
|
|
||||||
& , 👨🎨 💭 ⚫️ `str`, & 🚚 🐕🦺 👈.
|
|
||||||
|
|
||||||
#### 🔢 & ⚒
|
|
||||||
|
|
||||||
👆 🔜 🎏 📣 `tuple`Ⓜ & `set`Ⓜ:
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial007.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.9️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial007_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
👉 ⛓:
|
|
||||||
|
|
||||||
* 🔢 `items_t` `tuple` ⏮️ 3️⃣ 🏬, `int`, ➕1️⃣ `int`, & `str`.
|
|
||||||
* 🔢 `items_s` `set`, & 🔠 🚮 🏬 🆎 `bytes`.
|
|
||||||
|
|
||||||
#### #️⃣
|
|
||||||
|
|
||||||
🔬 `dict`, 👆 🚶♀️ 2️⃣ 🆎 🔢, 🎏 ❕.
|
|
||||||
|
|
||||||
🥇 🆎 🔢 🔑 `dict`.
|
|
||||||
|
|
||||||
🥈 🆎 🔢 💲 `dict`:
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial008.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.9️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial008_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
👉 ⛓:
|
|
||||||
|
|
||||||
* 🔢 `prices` `dict`:
|
|
||||||
* 🔑 👉 `dict` 🆎 `str` (➡️ 💬, 📛 🔠 🏬).
|
|
||||||
* 💲 👉 `dict` 🆎 `float` (➡️ 💬, 🔖 🔠 🏬).
|
|
||||||
|
|
||||||
#### 🇪🇺
|
|
||||||
|
|
||||||
👆 💪 📣 👈 🔢 💪 🙆 **📚 🆎**, 🖼, `int` ⚖️ `str`.
|
|
||||||
|
|
||||||
🐍 3️⃣.6️⃣ & 🔛 (✅ 🐍 3️⃣.1️⃣0️⃣) 👆 💪 ⚙️ `Union` 🆎 ⚪️➡️ `typing` & 🚮 🔘 ⬜ 🗜 💪 🆎 🚫.
|
|
||||||
|
|
||||||
🐍 3️⃣.1️⃣0️⃣ 📤 **🎛 ❕** 🌐❔ 👆 💪 🚮 💪 🆎 👽 <abbr title='also called "bitwise or operator", but that meaning is not relevant here'>⏸ ⏸ (`|`)</abbr>.
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial008b.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.1️⃣0️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial008b_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
👯♂️ 💼 👉 ⛓ 👈 `item` 💪 `int` ⚖️ `str`.
|
|
||||||
|
|
||||||
#### 🎲 `None`
|
|
||||||
|
|
||||||
👆 💪 📣 👈 💲 💪 ✔️ 🆎, 💖 `str`, ✋️ 👈 ⚫️ 💪 `None`.
|
|
||||||
|
|
||||||
🐍 3️⃣.6️⃣ & 🔛 (✅ 🐍 3️⃣.1️⃣0️⃣) 👆 💪 📣 ⚫️ 🏭 & ⚙️ `Optional` ⚪️➡️ `typing` 🕹.
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!../../docs_src/python_types/tutorial009.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
⚙️ `Optional[str]` ↩️ `str` 🔜 ➡️ 👨🎨 ℹ 👆 🔍 ❌ 🌐❔ 👆 💪 🤔 👈 💲 🕧 `str`, 🕐❔ ⚫️ 💪 🤙 `None` 💁♂️.
|
|
||||||
|
|
||||||
`Optional[Something]` 🤙 ⌨ `Union[Something, None]`, 👫 🌓.
|
|
||||||
|
|
||||||
👉 ⛓ 👈 🐍 3️⃣.1️⃣0️⃣, 👆 💪 ⚙️ `Something | None`:
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial009.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛 - 🎛
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!> ../../docs_src/python_types/tutorial009b.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.1️⃣0️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
{!> ../../docs_src/python_types/tutorial009_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
#### ⚙️ `Union` ⚖️ `Optional`
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🐍 ⏬ 🔛 3️⃣.1️⃣0️⃣, 📥 💁♂ ⚪️➡️ 👇 📶 **🤔** ☝ 🎑:
|
|
||||||
|
|
||||||
* 👶 ❎ ⚙️ `Optional[SomeType]`
|
|
||||||
* ↩️ 👶 **⚙️ `Union[SomeType, None]`** 👶.
|
|
||||||
|
|
||||||
👯♂️ 🌓 & 🔘 👫 🎏, ✋️ 👤 🔜 👍 `Union` ↩️ `Optional` ↩️ 🔤 "**📦**" 🔜 😑 🔑 👈 💲 📦, & ⚫️ 🤙 ⛓ "⚫️ 💪 `None`", 🚥 ⚫️ 🚫 📦 & ✔.
|
|
||||||
|
|
||||||
👤 💭 `Union[SomeType, None]` 🌖 🔑 🔃 ⚫️❔ ⚫️ ⛓.
|
|
||||||
|
|
||||||
⚫️ 🔃 🔤 & 📛. ✋️ 👈 🔤 💪 📉 ❔ 👆 & 👆 🤽♂ 💭 🔃 📟.
|
|
||||||
|
|
||||||
🖼, ➡️ ✊ 👉 🔢:
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!../../docs_src/python_types/tutorial009c.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
🔢 `name` 🔬 `Optional[str]`, ✋️ ⚫️ **🚫 📦**, 👆 🚫🔜 🤙 🔢 🍵 🔢:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
say_hi() # Oh, no, this throws an error! 😱
|
|
||||||
```
|
|
||||||
|
|
||||||
`name` 🔢 **✔** (🚫 *📦*) ↩️ ⚫️ 🚫 ✔️ 🔢 💲. , `name` 🚫 `None` 💲:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
say_hi(name=None) # This works, None is valid 🎉
|
|
||||||
```
|
|
||||||
|
|
||||||
👍 📰, 🕐 👆 🔛 🐍 3️⃣.1️⃣0️⃣ 👆 🏆 🚫 ✔️ 😟 🔃 👈, 👆 🔜 💪 🎯 ⚙️ `|` 🔬 🇪🇺 🆎:
|
|
||||||
|
|
||||||
```Python hl_lines="1 4"
|
|
||||||
{!../../docs_src/python_types/tutorial009c_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ⤴️ 👆 🏆 🚫 ✔️ 😟 🔃 📛 💖 `Optional` & `Union`. 👶
|
|
||||||
|
|
||||||
#### 💊 🆎
|
|
||||||
|
|
||||||
👉 🆎 👈 ✊ 🆎 🔢 ⬜ 🗜 🤙 **💊 🆎** ⚖️ **💊**, 🖼:
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
* `List`
|
|
||||||
* `Tuple`
|
|
||||||
* `Set`
|
|
||||||
* `Dict`
|
|
||||||
* `Union`
|
|
||||||
* `Optional`
|
|
||||||
* ...& 🎏.
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.9️⃣ & 🔛
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 💽 🆎 💊 (⏮️ ⬜ 🗜 & 🆎 🔘):
|
|
||||||
|
|
||||||
* `list`
|
|
||||||
* `tuple`
|
|
||||||
* `set`
|
|
||||||
* `dict`
|
|
||||||
|
|
||||||
& 🎏 ⏮️ 🐍 3️⃣.6️⃣, ⚪️➡️ `typing` 🕹:
|
|
||||||
|
|
||||||
* `Union`
|
|
||||||
* `Optional`
|
|
||||||
* ...& 🎏.
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.1️⃣0️⃣ & 🔛
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 💽 🆎 💊 (⏮️ ⬜ 🗜 & 🆎 🔘):
|
|
||||||
|
|
||||||
* `list`
|
|
||||||
* `tuple`
|
|
||||||
* `set`
|
|
||||||
* `dict`
|
|
||||||
|
|
||||||
& 🎏 ⏮️ 🐍 3️⃣.6️⃣, ⚪️➡️ `typing` 🕹:
|
|
||||||
|
|
||||||
* `Union`
|
|
||||||
* `Optional` (🎏 ⏮️ 🐍 3️⃣.6️⃣)
|
|
||||||
* ...& 🎏.
|
|
||||||
|
|
||||||
🐍 3️⃣.1️⃣0️⃣, 🎛 ⚙️ 💊 `Union` & `Optional`, 👆 💪 ⚙️ <abbr title='also called "bitwise or operator", but that meaning is not relevant here'>⏸ ⏸ (`|`)</abbr> 📣 🇪🇺 🆎.
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
### 🎓 🆎
|
|
||||||
|
|
||||||
👆 💪 📣 🎓 🆎 🔢.
|
|
||||||
|
|
||||||
➡️ 💬 👆 ✔️ 🎓 `Person`, ⏮️ 📛:
|
|
||||||
|
|
||||||
```Python hl_lines="1-3"
|
|
||||||
{!../../docs_src/python_types/tutorial010.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
⤴️ 👆 💪 📣 🔢 🆎 `Person`:
|
|
||||||
|
|
||||||
```Python hl_lines="6"
|
|
||||||
{!../../docs_src/python_types/tutorial010.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ⤴️, 🔄, 👆 🤚 🌐 👨🎨 🐕🦺:
|
|
||||||
|
|
||||||
<img src="/img/python-types/image06.png">
|
|
||||||
|
|
||||||
## Pydantic 🏷
|
|
||||||
|
|
||||||
<a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> 🐍 🗃 🎭 📊 🔬.
|
|
||||||
|
|
||||||
👆 📣 "💠" 💽 🎓 ⏮️ 🔢.
|
|
||||||
|
|
||||||
& 🔠 🔢 ✔️ 🆎.
|
|
||||||
|
|
||||||
⤴️ 👆 ✍ 👐 👈 🎓 ⏮️ 💲 & ⚫️ 🔜 ✔ 💲, 🗜 👫 ☑ 🆎 (🚥 👈 💼) & 🤝 👆 🎚 ⏮️ 🌐 💽.
|
|
||||||
|
|
||||||
& 👆 🤚 🌐 👨🎨 🐕🦺 ⏮️ 👈 📉 🎚.
|
|
||||||
|
|
||||||
🖼 ⚪️➡️ 🛂 Pydantic 🩺:
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.6️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/python_types/tutorial011.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.9️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/python_types/tutorial011_py39.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
//// tab | 🐍 3️⃣.1️⃣0️⃣ & 🔛
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{!> ../../docs_src/python_types/tutorial011_py310.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
////
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
💡 🌖 🔃 <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic, ✅ 🚮 🩺</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
**FastAPI** 🌐 ⚓️ 🔛 Pydantic.
|
|
||||||
|
|
||||||
👆 🔜 👀 📚 🌅 🌐 👉 💡 [🔰 - 👩💻 🦮](tutorial/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Pydantic ✔️ 🎁 🎭 🕐❔ 👆 ⚙️ `Optional` ⚖️ `Union[Something, None]` 🍵 🔢 💲, 👆 💪 ✍ 🌅 🔃 ⚫️ Pydantic 🩺 🔃 <a href="https://docs.pydantic.dev/latest/concepts/models/#required-optional-fields" class="external-link" target="_blank">✔ 📦 🏑</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🆎 🔑 **FastAPI**
|
|
||||||
|
|
||||||
**FastAPI** ✊ 📈 👫 🆎 🔑 📚 👜.
|
|
||||||
|
|
||||||
⏮️ **FastAPI** 👆 📣 🔢 ⏮️ 🆎 🔑 & 👆 🤚:
|
|
||||||
|
|
||||||
* **👨🎨 🐕🦺**.
|
|
||||||
* **🆎 ✅**.
|
|
||||||
|
|
||||||
...and **FastAPI** uses the same declarations :
|
|
||||||
|
|
||||||
* **🔬 📄**: ⚪️➡️ 📨 ➡ 🔢, 🔢 🔢, 🎚, 💪, 🔗, ♒️.
|
|
||||||
* **🗜 💽**: ⚪️➡️ 📨 🚚 🆎.
|
|
||||||
* **✔ 💽**: 👟 ⚪️➡️ 🔠 📨:
|
|
||||||
* 🏭 **🏧 ❌** 📨 👩💻 🕐❔ 📊 ❌.
|
|
||||||
* **📄** 🛠️ ⚙️ 🗄:
|
|
||||||
* ❔ ⤴️ ⚙️ 🏧 🎓 🧾 👩💻 🔢.
|
|
||||||
|
|
||||||
👉 5️⃣📆 🌐 🔊 📝. 🚫 😟. 👆 🔜 👀 🌐 👉 🎯 [🔰 - 👩💻 🦮](tutorial/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
⚠ 👜 👈 ⚙️ 🐩 🐍 🆎, 👁 🥉 (↩️ ❎ 🌖 🎓, 👨🎨, ♒️), **FastAPI** 🔜 📚 👷 👆.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🚥 👆 ⏪ 🚶 🔘 🌐 🔰 & 👟 🔙 👀 🌅 🔃 🆎, 👍 ℹ <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank"> "🎮 🎼" ⚪️➡️ `mypy`</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
# 🖥 📋
|
|
||||||
|
|
||||||
👆 💪 🔬 🖥 📋 🏃 *⏮️* 🛬 📨.
|
|
||||||
|
|
||||||
👉 ⚠ 🛠️ 👈 💪 🔨 ⏮️ 📨, ✋️ 👈 👩💻 🚫 🤙 ✔️ ⌛ 🛠️ 🏁 ⏭ 📨 📨.
|
|
||||||
|
|
||||||
👉 🔌, 🖼:
|
|
||||||
|
|
||||||
* 📧 📨 📨 ⏮️ 🎭 🎯:
|
|
||||||
* 🔗 📧 💽 & 📨 📧 😑 "🐌" (📚 🥈), 👆 💪 📨 📨 ▶️️ ↖️ & 📨 📧 📨 🖥.
|
|
||||||
* 🏭 💽:
|
|
||||||
* 🖼, ➡️ 💬 👆 📨 📁 👈 🔜 🚶 🔘 🐌 🛠️, 👆 💪 📨 📨 "🚫" (🇺🇸🔍 2️⃣0️⃣2️⃣) & 🛠️ ⚫️ 🖥.
|
|
||||||
|
|
||||||
## ⚙️ `BackgroundTasks`
|
|
||||||
|
|
||||||
🥇, 🗄 `BackgroundTasks` & 🔬 🔢 👆 *➡ 🛠️ 🔢* ⏮️ 🆎 📄 `BackgroundTasks`:
|
|
||||||
|
|
||||||
{* ../../docs_src/background_tasks/tutorial001.py hl[1,13] *}
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ✍ 🎚 🆎 `BackgroundTasks` 👆 & 🚶♀️ ⚫️ 👈 🔢.
|
|
||||||
|
|
||||||
## ✍ 📋 🔢
|
|
||||||
|
|
||||||
✍ 🔢 🏃 🖥 📋.
|
|
||||||
|
|
||||||
⚫️ 🐩 🔢 👈 💪 📨 🔢.
|
|
||||||
|
|
||||||
⚫️ 💪 `async def` ⚖️ 😐 `def` 🔢, **FastAPI** 🔜 💭 ❔ 🍵 ⚫️ ☑.
|
|
||||||
|
|
||||||
👉 💼, 📋 🔢 🔜 ✍ 📁 (⚖ 📨 📧).
|
|
||||||
|
|
||||||
& ✍ 🛠️ 🚫 ⚙️ `async` & `await`, 👥 🔬 🔢 ⏮️ 😐 `def`:
|
|
||||||
|
|
||||||
{* ../../docs_src/background_tasks/tutorial001.py hl[6:9] *}
|
|
||||||
|
|
||||||
## 🚮 🖥 📋
|
|
||||||
|
|
||||||
🔘 👆 *➡ 🛠️ 🔢*, 🚶♀️ 👆 📋 🔢 *🖥 📋* 🎚 ⏮️ 👩🔬 `.add_task()`:
|
|
||||||
|
|
||||||
{* ../../docs_src/background_tasks/tutorial001.py hl[14] *}
|
|
||||||
|
|
||||||
`.add_task()` 📨 ❌:
|
|
||||||
|
|
||||||
* 📋 🔢 🏃 🖥 (`write_notification`).
|
|
||||||
* 🙆 🔁 ❌ 👈 🔜 🚶♀️ 📋 🔢 ✔ (`email`).
|
|
||||||
* 🙆 🇨🇻 ❌ 👈 🔜 🚶♀️ 📋 🔢 (`message="some notification"`).
|
|
||||||
|
|
||||||
## 🔗 💉
|
|
||||||
|
|
||||||
⚙️ `BackgroundTasks` 👷 ⏮️ 🔗 💉 ⚙️, 👆 💪 📣 🔢 🆎 `BackgroundTasks` 💗 🎚: *➡ 🛠️ 🔢*, 🔗 (☑), 🎧-🔗, ♒️.
|
|
||||||
|
|
||||||
**FastAPI** 💭 ⚫️❔ 🔠 💼 & ❔ 🏤-⚙️ 🎏 🎚, 👈 🌐 🖥 📋 🔗 👯♂️ & 🏃 🖥 ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/background_tasks/tutorial002.py hl[13,15,22,25] *}
|
|
||||||
|
|
||||||
👉 🖼, 📧 🔜 ✍ `log.txt` 📁 *⏮️* 📨 📨.
|
|
||||||
|
|
||||||
🚥 📤 🔢 📨, ⚫️ 🔜 ✍ 🕹 🖥 📋.
|
|
||||||
|
|
||||||
& ⤴️ ➕1️⃣ 🖥 📋 🏗 *➡ 🛠️ 🔢* 🔜 ✍ 📧 ⚙️ `email` ➡ 🔢.
|
|
||||||
|
|
||||||
## 📡 ℹ
|
|
||||||
|
|
||||||
🎓 `BackgroundTasks` 👟 🔗 ⚪️➡️ <a href="https://www.starlette.dev/background/" class="external-link" target="_blank">`starlette.background`</a>.
|
|
||||||
|
|
||||||
⚫️ 🗄/🔌 🔗 🔘 FastAPI 👈 👆 💪 🗄 ⚫️ ⚪️➡️ `fastapi` & ❎ 😫 🗄 🎛 `BackgroundTask` (🍵 `s` 🔚) ⚪️➡️ `starlette.background`.
|
|
||||||
|
|
||||||
🕴 ⚙️ `BackgroundTasks` (& 🚫 `BackgroundTask`), ⚫️ ⤴️ 💪 ⚙️ ⚫️ *➡ 🛠️ 🔢* 🔢 & ✔️ **FastAPI** 🍵 🎂 👆, 💖 🕐❔ ⚙️ `Request` 🎚 🔗.
|
|
||||||
|
|
||||||
⚫️ 💪 ⚙️ `BackgroundTask` 😞 FastAPI, ✋️ 👆 ✔️ ✍ 🎚 👆 📟 & 📨 💃 `Response` 🔌 ⚫️.
|
|
||||||
|
|
||||||
👆 💪 👀 🌖 ℹ <a href="https://www.starlette.dev/background/" class="external-link" target="_blank">💃 🛂 🩺 🖥 📋</a>.
|
|
||||||
|
|
||||||
## ⚠
|
|
||||||
|
|
||||||
🚥 👆 💪 🎭 🏋️ 🖥 📊 & 👆 🚫 🎯 💪 ⚫️ 🏃 🎏 🛠️ (🖼, 👆 🚫 💪 💰 💾, 🔢, ♒️), 👆 💪 💰 ⚪️➡️ ⚙️ 🎏 🦏 🧰 💖 <a href="https://docs.celeryq.dev" class="external-link" target="_blank">🥒</a>.
|
|
||||||
|
|
||||||
👫 😑 🚚 🌖 🏗 📳, 📧/👨🏭 📤 👨💼, 💖 ✳ ⚖️ ✳, ✋️ 👫 ✔ 👆 🏃 🖥 📋 💗 🛠️, & ✴️, 💗 💽.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 💪 🔐 🔢 & 🎚 ⚪️➡️ 🎏 **FastAPI** 📱, ⚖️ 👆 💪 🎭 🤪 🖥 📋 (💖 📨 📧 📨), 👆 💪 🎯 ⚙️ `BackgroundTasks`.
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
🗄 & ⚙️ `BackgroundTasks` ⏮️ 🔢 *➡ 🛠️ 🔢* & 🔗 🚮 🖥 📋.
|
|
||||||
|
|
@ -1,530 +0,0 @@
|
||||||
# 🦏 🈸 - 💗 📁
|
|
||||||
|
|
||||||
🚥 👆 🏗 🈸 ⚖️ 🕸 🛠️, ⚫️ 🛎 💼 👈 👆 💪 🚮 🌐 🔛 👁 📁.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🏪 🧰 📊 👆 🈸 ⏪ 🚧 🌐 💪.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🚥 👆 👟 ⚪️➡️ 🏺, 👉 🔜 🌓 🏺 📗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🖼 📁 📊
|
|
||||||
|
|
||||||
➡️ 💬 👆 ✔️ 📁 📊 💖 👉:
|
|
||||||
|
|
||||||
```
|
|
||||||
.
|
|
||||||
├── app
|
|
||||||
│ ├── __init__.py
|
|
||||||
│ ├── main.py
|
|
||||||
│ ├── dependencies.py
|
|
||||||
│ └── routers
|
|
||||||
│ │ ├── __init__.py
|
|
||||||
│ │ ├── items.py
|
|
||||||
│ │ └── users.py
|
|
||||||
│ └── internal
|
|
||||||
│ ├── __init__.py
|
|
||||||
│ └── admin.py
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📤 📚 `__init__.py` 📁: 1️⃣ 🔠 📁 ⚖️ 📁.
|
|
||||||
|
|
||||||
👉 ⚫️❔ ✔ 🏭 📟 ⚪️➡️ 1️⃣ 📁 🔘 ➕1️⃣.
|
|
||||||
|
|
||||||
🖼, `app/main.py` 👆 💪 ✔️ ⏸ 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
from app.routers import items
|
|
||||||
```
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
* `app` 📁 🔌 🌐. & ⚫️ ✔️ 🛁 📁 `app/__init__.py`, ⚫️ "🐍 📦" (🗃 "🐍 🕹"): `app`.
|
|
||||||
* ⚫️ 🔌 `app/main.py` 📁. ⚫️ 🔘 🐍 📦 (📁 ⏮️ 📁 `__init__.py`), ⚫️ "🕹" 👈 📦: `app.main`.
|
|
||||||
* 📤 `app/dependencies.py` 📁, 💖 `app/main.py`, ⚫️ "🕹": `app.dependencies`.
|
|
||||||
* 📤 📁 `app/routers/` ⏮️ ➕1️⃣ 📁 `__init__.py`, ⚫️ "🐍 📦": `app.routers`.
|
|
||||||
* 📁 `app/routers/items.py` 🔘 📦, `app/routers/`,, ⚫️ 🔁: `app.routers.items`.
|
|
||||||
* 🎏 ⏮️ `app/routers/users.py`, ⚫️ ➕1️⃣ 🔁: `app.routers.users`.
|
|
||||||
* 📤 📁 `app/internal/` ⏮️ ➕1️⃣ 📁 `__init__.py`, ⚫️ ➕1️⃣ "🐍 📦": `app.internal`.
|
|
||||||
* & 📁 `app/internal/admin.py` ➕1️⃣ 🔁: `app.internal.admin`.
|
|
||||||
|
|
||||||
<img src="/img/tutorial/bigger-applications/package.drawio.svg">
|
|
||||||
|
|
||||||
🎏 📁 📊 ⏮️ 🏤:
|
|
||||||
|
|
||||||
```
|
|
||||||
.
|
|
||||||
├── app # "app" is a Python package
|
|
||||||
│ ├── __init__.py # this file makes "app" a "Python package"
|
|
||||||
│ ├── main.py # "main" module, e.g. import app.main
|
|
||||||
│ ├── dependencies.py # "dependencies" module, e.g. import app.dependencies
|
|
||||||
│ └── routers # "routers" is a "Python subpackage"
|
|
||||||
│ │ ├── __init__.py # makes "routers" a "Python subpackage"
|
|
||||||
│ │ ├── items.py # "items" submodule, e.g. import app.routers.items
|
|
||||||
│ │ └── users.py # "users" submodule, e.g. import app.routers.users
|
|
||||||
│ └── internal # "internal" is a "Python subpackage"
|
|
||||||
│ ├── __init__.py # makes "internal" a "Python subpackage"
|
|
||||||
│ └── admin.py # "admin" submodule, e.g. import app.internal.admin
|
|
||||||
```
|
|
||||||
|
|
||||||
## `APIRouter`
|
|
||||||
|
|
||||||
➡️ 💬 📁 💡 🚚 👩💻 🔁 `/app/routers/users.py`.
|
|
||||||
|
|
||||||
👆 💚 ✔️ *➡ 🛠️* 🔗 👆 👩💻 👽 ⚪️➡️ 🎂 📟, 🚧 ⚫️ 🏗.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🍕 🎏 **FastAPI** 🈸/🕸 🛠️ (⚫️ 🍕 🎏 "🐍 📦").
|
|
||||||
|
|
||||||
👆 💪 ✍ *➡ 🛠️* 👈 🕹 ⚙️ `APIRouter`.
|
|
||||||
|
|
||||||
### 🗄 `APIRouter`
|
|
||||||
|
|
||||||
👆 🗄 ⚫️ & ✍ "👐" 🎏 🌌 👆 🔜 ⏮️ 🎓 `FastAPI`:
|
|
||||||
|
|
||||||
```Python hl_lines="1 3" title="app/routers/users.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/routers/users.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### *➡ 🛠️* ⏮️ `APIRouter`
|
|
||||||
|
|
||||||
& ⤴️ 👆 ⚙️ ⚫️ 📣 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
⚙️ ⚫️ 🎏 🌌 👆 🔜 ⚙️ `FastAPI` 🎓:
|
|
||||||
|
|
||||||
```Python hl_lines="6 11 16" title="app/routers/users.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/routers/users.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 💪 💭 `APIRouter` "🐩 `FastAPI`" 🎓.
|
|
||||||
|
|
||||||
🌐 🎏 🎛 🐕🦺.
|
|
||||||
|
|
||||||
🌐 🎏 `parameters`, `responses`, `dependencies`, `tags`, ♒️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 🖼, 🔢 🤙 `router`, ✋️ 👆 💪 📛 ⚫️ 👐 👆 💚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👥 🔜 🔌 👉 `APIRouter` 👑 `FastAPI` 📱, ✋️ 🥇, ➡️ ✅ 🔗 & ➕1️⃣ `APIRouter`.
|
|
||||||
|
|
||||||
## 🔗
|
|
||||||
|
|
||||||
👥 👀 👈 👥 🔜 💪 🔗 ⚙️ 📚 🥉 🈸.
|
|
||||||
|
|
||||||
👥 🚮 👫 👫 👍 `dependencies` 🕹 (`app/dependencies.py`).
|
|
||||||
|
|
||||||
👥 🔜 🔜 ⚙️ 🙅 🔗 ✍ 🛃 `X-Token` 🎚:
|
|
||||||
|
|
||||||
```Python hl_lines="1 4-6" title="app/dependencies.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/dependencies.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👥 ⚙️ 💭 🎚 📉 👉 🖼.
|
|
||||||
|
|
||||||
✋️ 🎰 💼 👆 🔜 🤚 👍 🏁 ⚙️ 🛠️ [💂♂ 🚙](security/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ➕1️⃣ 🕹 ⏮️ `APIRouter`
|
|
||||||
|
|
||||||
➡️ 💬 👆 ✔️ 🔗 💡 🚚 "🏬" ⚪️➡️ 👆 🈸 🕹 `app/routers/items.py`.
|
|
||||||
|
|
||||||
👆 ✔️ *➡ 🛠️* :
|
|
||||||
|
|
||||||
* `/items/`
|
|
||||||
* `/items/{item_id}`
|
|
||||||
|
|
||||||
⚫️ 🌐 🎏 📊 ⏮️ `app/routers/users.py`.
|
|
||||||
|
|
||||||
✋️ 👥 💚 🙃 & 📉 📟 🍖.
|
|
||||||
|
|
||||||
👥 💭 🌐 *➡ 🛠️* 👉 🕹 ✔️ 🎏:
|
|
||||||
|
|
||||||
* ➡ `prefix`: `/items`.
|
|
||||||
* `tags`: (1️⃣ 🔖: `items`).
|
|
||||||
* ➕ `responses`.
|
|
||||||
* `dependencies`: 👫 🌐 💪 👈 `X-Token` 🔗 👥 ✍.
|
|
||||||
|
|
||||||
, ↩️ ❎ 🌐 👈 🔠 *➡ 🛠️*, 👥 💪 🚮 ⚫️ `APIRouter`.
|
|
||||||
|
|
||||||
```Python hl_lines="5-10 16 21" title="app/routers/items.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
➡ 🔠 *➡ 🛠️* ✔️ ▶️ ⏮️ `/`, 💖:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
@router.get("/{item_id}")
|
|
||||||
async def read_item(item_id: str):
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
...🔡 🔜 🚫 🔌 🏁 `/`.
|
|
||||||
|
|
||||||
, 🔡 👉 💼 `/items`.
|
|
||||||
|
|
||||||
👥 💪 🚮 📇 `tags` & ➕ `responses` 👈 🔜 ✔ 🌐 *➡ 🛠️* 🔌 👉 📻.
|
|
||||||
|
|
||||||
& 👥 💪 🚮 📇 `dependencies` 👈 🔜 🚮 🌐 *➡ 🛠️* 📻 & 🔜 🛠️/❎ 🔠 📨 ⚒ 👫.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🗒 👈, 🌅 💖 [🔗 *➡ 🛠️ 👨🎨*](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, 🙅♂ 💲 🔜 🚶♀️ 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔚 🏁 👈 🏬 ➡ 🔜:
|
|
||||||
|
|
||||||
* `/items/`
|
|
||||||
* `/items/{item_id}`
|
|
||||||
|
|
||||||
...👥 🎯.
|
|
||||||
|
|
||||||
* 👫 🔜 ™ ⏮️ 📇 🔖 👈 🔌 👁 🎻 `"items"`.
|
|
||||||
* 👫 "🔖" ✴️ ⚠ 🏧 🎓 🧾 ⚙️ (⚙️ 🗄).
|
|
||||||
* 🌐 👫 🔜 🔌 🔁 `responses`.
|
|
||||||
* 🌐 👫 *➡ 🛠️* 🔜 ✔️ 📇 `dependencies` 🔬/🛠️ ⏭ 👫.
|
|
||||||
* 🚥 👆 📣 🔗 🎯 *➡ 🛠️*, **👫 🔜 🛠️ 💁♂️**.
|
|
||||||
* 📻 🔗 🛠️ 🥇, ⤴️ [`dependencies` 👨🎨](dependencies/dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, & ⤴️ 😐 🔢 🔗.
|
|
||||||
* 👆 💪 🚮 [`Security` 🔗 ⏮️ `scopes`](../advanced/security/oauth2-scopes.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
✔️ `dependencies` `APIRouter` 💪 ⚙️, 🖼, 🚚 🤝 🎂 👪 *➡ 🛠️*. 🚥 🔗 🚫 🚮 📦 🔠 1️⃣ 👫.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
`prefix`, `tags`, `responses`, & `dependencies` 🔢 (📚 🎏 💼) ⚒ ⚪️➡️ **FastAPI** ℹ 👆 ❎ 📟 ❎.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🗄 🔗
|
|
||||||
|
|
||||||
👉 📟 👨❤👨 🕹 `app.routers.items`, 📁 `app/routers/items.py`.
|
|
||||||
|
|
||||||
& 👥 💪 🤚 🔗 🔢 ⚪️➡️ 🕹 `app.dependencies`, 📁 `app/dependencies.py`.
|
|
||||||
|
|
||||||
👥 ⚙️ ⚖ 🗄 ⏮️ `..` 🔗:
|
|
||||||
|
|
||||||
```Python hl_lines="3" title="app/routers/items.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ❔ ⚖ 🗄 👷
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 💭 👌 ❔ 🗄 👷, 😣 ⏭ 📄 🔛.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👁 ❣ `.`, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from .dependencies import get_token_header
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 ⛓:
|
|
||||||
|
|
||||||
* ▶️ 🎏 📦 👈 👉 🕹 (📁 `app/routers/items.py`) 🖖 (📁 `app/routers/`)...
|
|
||||||
* 🔎 🕹 `dependencies` (👽 📁 `app/routers/dependencies.py`)...
|
|
||||||
* & ⚪️➡️ ⚫️, 🗄 🔢 `get_token_header`.
|
|
||||||
|
|
||||||
✋️ 👈 📁 🚫 🔀, 👆 🔗 📁 `app/dependencies.py`.
|
|
||||||
|
|
||||||
💭 ❔ 👆 📱/📁 📊 👀 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/bigger-applications/package.drawio.svg">
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
2️⃣ ❣ `..`, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from ..dependencies import get_token_header
|
|
||||||
```
|
|
||||||
|
|
||||||
⛓:
|
|
||||||
|
|
||||||
* ▶️ 🎏 📦 👈 👉 🕹 (📁 `app/routers/items.py`) 🖖 (📁 `app/routers/`)...
|
|
||||||
* 🚶 👪 📦 (📁 `app/`)...
|
|
||||||
* & 📤, 🔎 🕹 `dependencies` (📁 `app/dependencies.py`)...
|
|
||||||
* & ⚪️➡️ ⚫️, 🗄 🔢 `get_token_header`.
|
|
||||||
|
|
||||||
👈 👷 ☑ ❗ 👶
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🎏 🌌, 🚥 👥 ✔️ ⚙️ 3️⃣ ❣ `...`, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from ...dependencies import get_token_header
|
|
||||||
```
|
|
||||||
|
|
||||||
that 🔜 ⛓:
|
|
||||||
|
|
||||||
* ▶️ 🎏 📦 👈 👉 🕹 (📁 `app/routers/items.py`) 🖖 (📁 `app/routers/`)...
|
|
||||||
* 🚶 👪 📦 (📁 `app/`)...
|
|
||||||
* ⤴️ 🚶 👪 👈 📦 (📤 🙅♂ 👪 📦, `app` 🔝 🎚 👶)...
|
|
||||||
* & 📤, 🔎 🕹 `dependencies` (📁 `app/dependencies.py`)...
|
|
||||||
* & ⚪️➡️ ⚫️, 🗄 🔢 `get_token_header`.
|
|
||||||
|
|
||||||
👈 🔜 🔗 📦 🔛 `app/`, ⏮️ 🚮 👍 📁 `__init__.py`, ♒️. ✋️ 👥 🚫 ✔️ 👈. , 👈 🔜 🚮 ❌ 👆 🖼. 👶
|
|
||||||
|
|
||||||
✋️ 🔜 👆 💭 ❔ ⚫️ 👷, 👆 💪 ⚙️ ⚖ 🗄 👆 👍 📱 🙅♂ 🤔 ❔ 🏗 👫. 👶
|
|
||||||
|
|
||||||
### 🚮 🛃 `tags`, `responses`, & `dependencies`
|
|
||||||
|
|
||||||
👥 🚫 ❎ 🔡 `/items` 🚫 `tags=["items"]` 🔠 *➡ 🛠️* ↩️ 👥 🚮 👫 `APIRouter`.
|
|
||||||
|
|
||||||
✋️ 👥 💪 🚮 _🌅_ `tags` 👈 🔜 ✔ 🎯 *➡ 🛠️*, & ➕ `responses` 🎯 👈 *➡ 🛠️*:
|
|
||||||
|
|
||||||
```Python hl_lines="30-31" title="app/routers/items.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/routers/items.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 🏁 ➡ 🛠️ 🔜 ✔️ 🌀 🔖: `["items", "custom"]`.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 ✔️ 👯♂️ 📨 🧾, 1️⃣ `404` & 1️⃣ `403`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 👑 `FastAPI`
|
|
||||||
|
|
||||||
🔜, ➡️ 👀 🕹 `app/main.py`.
|
|
||||||
|
|
||||||
📥 🌐❔ 👆 🗄 & ⚙️ 🎓 `FastAPI`.
|
|
||||||
|
|
||||||
👉 🔜 👑 📁 👆 🈸 👈 👔 🌐 👯♂️.
|
|
||||||
|
|
||||||
& 🏆 👆 ⚛ 🔜 🔜 🖖 🚮 👍 🎯 🕹, 👑 📁 🔜 🙅.
|
|
||||||
|
|
||||||
### 🗄 `FastAPI`
|
|
||||||
|
|
||||||
👆 🗄 & ✍ `FastAPI` 🎓 🛎.
|
|
||||||
|
|
||||||
& 👥 💪 📣 [🌐 🔗](dependencies/global-dependencies.md){.internal-link target=_blank} 👈 🔜 🌀 ⏮️ 🔗 🔠 `APIRouter`:
|
|
||||||
|
|
||||||
```Python hl_lines="1 3 7" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🗄 `APIRouter`
|
|
||||||
|
|
||||||
🔜 👥 🗄 🎏 🔁 👈 ✔️ `APIRouter`Ⓜ:
|
|
||||||
|
|
||||||
```Python hl_lines="5" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
📁 `app/routers/users.py` & `app/routers/items.py` 🔁 👈 🍕 🎏 🐍 📦 `app`, 👥 💪 ⚙️ 👁 ❣ `.` 🗄 👫 ⚙️ "⚖ 🗄".
|
|
||||||
|
|
||||||
### ❔ 🏭 👷
|
|
||||||
|
|
||||||
📄:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from .routers import items, users
|
|
||||||
```
|
|
||||||
|
|
||||||
⛓:
|
|
||||||
|
|
||||||
* ▶️ 🎏 📦 👈 👉 🕹 (📁 `app/main.py`) 🖖 (📁 `app/`)...
|
|
||||||
* 👀 📦 `routers` (📁 `app/routers/`)...
|
|
||||||
* & ⚪️➡️ ⚫️, 🗄 🔁 `items` (📁 `app/routers/items.py`) & `users` (📁 `app/routers/users.py`)...
|
|
||||||
|
|
||||||
🕹 `items` 🔜 ✔️ 🔢 `router` (`items.router`). 👉 🎏 1️⃣ 👥 ✍ 📁 `app/routers/items.py`, ⚫️ `APIRouter` 🎚.
|
|
||||||
|
|
||||||
& ⤴️ 👥 🎏 🕹 `users`.
|
|
||||||
|
|
||||||
👥 💪 🗄 👫 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from app.routers import items, users
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🥇 ⏬ "⚖ 🗄":
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from .routers import items, users
|
|
||||||
```
|
|
||||||
|
|
||||||
🥈 ⏬ "🎆 🗄":
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from app.routers import items, users
|
|
||||||
```
|
|
||||||
|
|
||||||
💡 🌅 🔃 🐍 📦 & 🕹, ✍ <a href="https://docs.python.org/3/tutorial/modules.html" class="external-link" target="_blank">🛂 🐍 🧾 🔃 🕹</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ❎ 📛 💥
|
|
||||||
|
|
||||||
👥 🏭 🔁 `items` 🔗, ↩️ 🏭 🚮 🔢 `router`.
|
|
||||||
|
|
||||||
👉 ↩️ 👥 ✔️ ➕1️⃣ 🔢 📛 `router` 🔁 `users`.
|
|
||||||
|
|
||||||
🚥 👥 ✔️ 🗄 1️⃣ ⏮️ 🎏, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from .routers.items import router
|
|
||||||
from .routers.users import router
|
|
||||||
```
|
|
||||||
|
|
||||||
`router` ⚪️➡️ `users` 🔜 📁 1️⃣ ⚪️➡️ `items` & 👥 🚫🔜 💪 ⚙️ 👫 🎏 🕰.
|
|
||||||
|
|
||||||
, 💪 ⚙️ 👯♂️ 👫 🎏 📁, 👥 🗄 🔁 🔗:
|
|
||||||
|
|
||||||
```Python hl_lines="5" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🔌 `APIRouter`Ⓜ `users` & `items`
|
|
||||||
|
|
||||||
🔜, ➡️ 🔌 `router`Ⓜ ⚪️➡️ 🔁 `users` & `items`:
|
|
||||||
|
|
||||||
```Python hl_lines="10-11" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`users.router` 🔌 `APIRouter` 🔘 📁 `app/routers/users.py`.
|
|
||||||
|
|
||||||
& `items.router` 🔌 `APIRouter` 🔘 📁 `app/routers/items.py`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⏮️ `app.include_router()` 👥 💪 🚮 🔠 `APIRouter` 👑 `FastAPI` 🈸.
|
|
||||||
|
|
||||||
⚫️ 🔜 🔌 🌐 🛣 ⚪️➡️ 👈 📻 🍕 ⚫️.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
⚫️ 🔜 🤙 🔘 ✍ *➡ 🛠️* 🔠 *➡ 🛠️* 👈 📣 `APIRouter`.
|
|
||||||
|
|
||||||
, ⛅ 🎑, ⚫️ 🔜 🤙 👷 🚥 🌐 🎏 👁 📱.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
👆 🚫 ✔️ 😟 🔃 🎭 🕐❔ ✅ 📻.
|
|
||||||
|
|
||||||
👉 🔜 ✊ ⏲ & 🔜 🕴 🔨 🕴.
|
|
||||||
|
|
||||||
⚫️ 🏆 🚫 📉 🎭. 👶
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔌 `APIRouter` ⏮️ 🛃 `prefix`, `tags`, `responses`, & `dependencies`
|
|
||||||
|
|
||||||
🔜, ➡️ 🌈 👆 🏢 🤝 👆 `app/internal/admin.py` 📁.
|
|
||||||
|
|
||||||
⚫️ 🔌 `APIRouter` ⏮️ 📡 *➡ 🛠️* 👈 👆 🏢 💰 🖖 📚 🏗.
|
|
||||||
|
|
||||||
👉 🖼 ⚫️ 🔜 💎 🙅. ✋️ ➡️ 💬 👈 ↩️ ⚫️ 💰 ⏮️ 🎏 🏗 🏢, 👥 🚫🔜 🔀 ⚫️ & 🚮 `prefix`, `dependencies`, `tags`, ♒️. 🔗 `APIRouter`:
|
|
||||||
|
|
||||||
```Python hl_lines="3" title="app/internal/admin.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/internal/admin.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 👥 💚 ⚒ 🛃 `prefix` 🕐❔ ✅ `APIRouter` 👈 🌐 🚮 *➡ 🛠️* ▶️ ⏮️ `/admin`, 👥 💚 🔐 ⚫️ ⏮️ `dependencies` 👥 ⏪ ✔️ 👉 🏗, & 👥 💚 🔌 `tags` & `responses`.
|
|
||||||
|
|
||||||
👥 💪 📣 🌐 👈 🍵 ✔️ 🔀 ⏮️ `APIRouter` 🚶♀️ 👈 🔢 `app.include_router()`:
|
|
||||||
|
|
||||||
```Python hl_lines="14-17" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 🌌, ⏮️ `APIRouter` 🔜 🚧 ⚗, 👥 💪 💰 👈 🎏 `app/internal/admin.py` 📁 ⏮️ 🎏 🏗 🏢.
|
|
||||||
|
|
||||||
🏁 👈 👆 📱, 🔠 *➡ 🛠️* ⚪️➡️ `admin` 🕹 🔜 ✔️:
|
|
||||||
|
|
||||||
* 🔡 `/admin`.
|
|
||||||
* 🔖 `admin`.
|
|
||||||
* 🔗 `get_token_header`.
|
|
||||||
* 📨 `418`. 👶
|
|
||||||
|
|
||||||
✋️ 👈 🔜 🕴 📉 👈 `APIRouter` 👆 📱, 🚫 🙆 🎏 📟 👈 ⚙️ ⚫️.
|
|
||||||
|
|
||||||
, 🖼, 🎏 🏗 💪 ⚙️ 🎏 `APIRouter` ⏮️ 🎏 🤝 👩🔬.
|
|
||||||
|
|
||||||
### 🔌 *➡ 🛠️*
|
|
||||||
|
|
||||||
👥 💪 🚮 *➡ 🛠️* 🔗 `FastAPI` 📱.
|
|
||||||
|
|
||||||
📥 👥 ⚫️... 🎦 👈 👥 💪 🤷:
|
|
||||||
|
|
||||||
```Python hl_lines="21-23" title="app/main.py"
|
|
||||||
{!../../docs_src/bigger_applications/app/main.py!}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ⚫️ 🔜 👷 ☑, 👯♂️ ⏮️ 🌐 🎏 *➡ 🛠️* 🚮 ⏮️ `app.include_router()`.
|
|
||||||
|
|
||||||
/// info | 📶 📡 ℹ
|
|
||||||
|
|
||||||
**🗒**: 👉 📶 📡 ℹ 👈 👆 🎲 💪 **🚶**.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
`APIRouter`Ⓜ 🚫 "🗻", 👫 🚫 👽 ⚪️➡️ 🎂 🈸.
|
|
||||||
|
|
||||||
👉 ↩️ 👥 💚 🔌 👫 *➡ 🛠️* 🗄 🔗 & 👩💻 🔢.
|
|
||||||
|
|
||||||
👥 🚫🔜 ❎ 👫 & "🗻" 👫 ➡ 🎂, *➡ 🛠️* "🖖" (🏤-✍), 🚫 🔌 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✅ 🏧 🛠️ 🩺
|
|
||||||
|
|
||||||
🔜, 🏃 `uvicorn`, ⚙️ 🕹 `app.main` & 🔢 `app`:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn app.main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
& 📂 🩺 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🛠️ 🩺, ✅ ➡ ⚪️➡️ 🌐 🔁, ⚙️ ☑ ➡ (& 🔡) & ☑ 🔖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/bigger-applications/image01.png">
|
|
||||||
|
|
||||||
## 🔌 🎏 📻 💗 🕰 ⏮️ 🎏 `prefix`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `.include_router()` 💗 🕰 ⏮️ *🎏* 📻 ⚙️ 🎏 🔡.
|
|
||||||
|
|
||||||
👉 💪 ⚠, 🖼, 🎦 🎏 🛠️ 🔽 🎏 🔡, ✅ `/api/v1` & `/api/latest`.
|
|
||||||
|
|
||||||
👉 🏧 ⚙️ 👈 👆 5️⃣📆 🚫 🤙 💪, ✋️ ⚫️ 📤 💼 👆.
|
|
||||||
|
|
||||||
## 🔌 `APIRouter` ➕1️⃣
|
|
||||||
|
|
||||||
🎏 🌌 👆 💪 🔌 `APIRouter` `FastAPI` 🈸, 👆 💪 🔌 `APIRouter` ➕1️⃣ `APIRouter` ⚙️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
router.include_router(other_router)
|
|
||||||
```
|
|
||||||
|
|
||||||
⚒ 💭 👆 ⚫️ ⏭ 🔌 `router` `FastAPI` 📱, 👈 *➡ 🛠️* ⚪️➡️ `other_router` 🔌.
|
|
||||||
|
|
@ -1,60 +0,0 @@
|
||||||
# 💪 - 🏑
|
|
||||||
|
|
||||||
🎏 🌌 👆 💪 📣 🌖 🔬 & 🗃 *➡ 🛠️ 🔢* 🔢 ⏮️ `Query`, `Path` & `Body`, 👆 💪 📣 🔬 & 🗃 🔘 Pydantic 🏷 ⚙️ Pydantic `Field`.
|
|
||||||
|
|
||||||
## 🗄 `Field`
|
|
||||||
|
|
||||||
🥇, 👆 ✔️ 🗄 ⚫️:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_fields/tutorial001.py hl[4] *}
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👀 👈 `Field` 🗄 🔗 ⚪️➡️ `pydantic`, 🚫 ⚪️➡️ `fastapi` 🌐 🎂 (`Query`, `Path`, `Body`, ♒️).
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📣 🏷 🔢
|
|
||||||
|
|
||||||
👆 💪 ⤴️ ⚙️ `Field` ⏮️ 🏷 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_fields/tutorial001.py hl[11:14] *}
|
|
||||||
|
|
||||||
`Field` 👷 🎏 🌌 `Query`, `Path` & `Body`, ⚫️ ✔️ 🌐 🎏 🔢, ♒️.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🤙, `Query`, `Path` & 🎏 👆 🔜 👀 ⏭ ✍ 🎚 🏿 ⚠ `Param` 🎓, ❔ ⚫️ 🏿 Pydantic `FieldInfo` 🎓.
|
|
||||||
|
|
||||||
& Pydantic `Field` 📨 👐 `FieldInfo` 👍.
|
|
||||||
|
|
||||||
`Body` 📨 🎚 🏿 `FieldInfo` 🔗. & 📤 🎏 👆 🔜 👀 ⏪ 👈 🏿 `Body` 🎓.
|
|
||||||
|
|
||||||
💭 👈 🕐❔ 👆 🗄 `Query`, `Path`, & 🎏 ⚪️➡️ `fastapi`, 👈 🤙 🔢 👈 📨 🎁 🎓.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 ❔ 🔠 🏷 🔢 ⏮️ 🆎, 🔢 💲 & `Field` ✔️ 🎏 📊 *➡ 🛠️ 🔢* 🔢, ⏮️ `Field` ↩️ `Path`, `Query` & `Body`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🚮 ➕ ℹ
|
|
||||||
|
|
||||||
👆 💪 📣 ➕ ℹ `Field`, `Query`, `Body`, ♒️. & ⚫️ 🔜 🔌 🏗 🎻 🔗.
|
|
||||||
|
|
||||||
👆 🔜 💡 🌅 🔃 ❎ ➕ ℹ ⏪ 🩺, 🕐❔ 🏫 📣 🖼.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
➕ 🔑 🚶♀️ `Field` 🔜 🎁 📉 🗄 🔗 👆 🈸.
|
|
||||||
👫 🔑 5️⃣📆 🚫 🎯 🍕 🗄 🔧, 🗄 🧰, 🖼 [🗄 💳](https://validator.swagger.io/), 5️⃣📆 🚫 👷 ⏮️ 👆 🏗 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 ⚙️ Pydantic `Field` 📣 ➕ 🔬 & 🗃 🏷 🔢.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ ➕ 🇨🇻 ❌ 🚶♀️ 🌖 🎻 🔗 🗃.
|
|
||||||
|
|
@ -1,171 +0,0 @@
|
||||||
# 💪 - 💗 🔢
|
|
||||||
|
|
||||||
🔜 👈 👥 ✔️ 👀 ❔ ⚙️ `Path` & `Query`, ➡️ 👀 🌅 🏧 ⚙️ 📨 💪 📄.
|
|
||||||
|
|
||||||
## 🌀 `Path`, `Query` & 💪 🔢
|
|
||||||
|
|
||||||
🥇, ↗️, 👆 💪 🌀 `Path`, `Query` & 📨 💪 🔢 📄 ➡ & **FastAPI** 🔜 💭 ⚫️❔.
|
|
||||||
|
|
||||||
& 👆 💪 📣 💪 🔢 📦, ⚒ 🔢 `None`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_multiple_params/tutorial001.py hl[19:21] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈, 👉 💼, `item` 👈 🔜 ✊ ⚪️➡️ 💪 📦. ⚫️ ✔️ `None` 🔢 💲.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💗 💪 🔢
|
|
||||||
|
|
||||||
⏮️ 🖼, *➡ 🛠️* 🔜 ⌛ 🎻 💪 ⏮️ 🔢 `Item`, 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 👆 💪 📣 💗 💪 🔢, ✅ `item` & `user`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_multiple_params/tutorial002.py hl[22] *}
|
|
||||||
|
|
||||||
👉 💼, **FastAPI** 🔜 👀 👈 📤 🌅 🌘 1️⃣ 💪 🔢 🔢 (2️⃣ 🔢 👈 Pydantic 🏷).
|
|
||||||
|
|
||||||
, ⚫️ 🔜 ⤴️ ⚙️ 🔢 📛 🔑 (🏑 📛) 💪, & ⌛ 💪 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"item": {
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2
|
|
||||||
},
|
|
||||||
"user": {
|
|
||||||
"username": "dave",
|
|
||||||
"full_name": "Dave Grohl"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈 ✋️ `item` 📣 🎏 🌌 ⏭, ⚫️ 🔜 ⌛ 🔘 💪 ⏮️ 🔑 `item`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
**FastAPI** 🔜 🏧 🛠️ ⚪️➡️ 📨, 👈 🔢 `item` 📨 ⚫️ 🎯 🎚 & 🎏 `user`.
|
|
||||||
|
|
||||||
⚫️ 🔜 🎭 🔬 ⚗ 💽, & 🔜 📄 ⚫️ 💖 👈 🗄 🔗 & 🏧 🩺.
|
|
||||||
|
|
||||||
## ⭐ 💲 💪
|
|
||||||
|
|
||||||
🎏 🌌 📤 `Query` & `Path` 🔬 ➕ 💽 🔢 & ➡ 🔢, **FastAPI** 🚚 🌓 `Body`.
|
|
||||||
|
|
||||||
🖼, ↔ ⏮️ 🏷, 👆 💪 💭 👈 👆 💚 ✔️ ➕1️⃣ 🔑 `importance` 🎏 💪, 🥈 `item` & `user`.
|
|
||||||
|
|
||||||
🚥 👆 📣 ⚫️, ↩️ ⚫️ ⭐ 💲, **FastAPI** 🔜 🤔 👈 ⚫️ 🔢 🔢.
|
|
||||||
|
|
||||||
✋️ 👆 💪 💡 **FastAPI** 😥 ⚫️ ➕1️⃣ 💪 🔑 ⚙️ `Body`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_multiple_params/tutorial003.py hl[22] *}
|
|
||||||
|
|
||||||
👉 💼, **FastAPI** 🔜 ⌛ 💪 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"item": {
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2
|
|
||||||
},
|
|
||||||
"user": {
|
|
||||||
"username": "dave",
|
|
||||||
"full_name": "Dave Grohl"
|
|
||||||
},
|
|
||||||
"importance": 5
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
🔄, ⚫️ 🔜 🗜 📊 🆎, ✔, 📄, ♒️.
|
|
||||||
|
|
||||||
## 💗 💪 = & 🔢
|
|
||||||
|
|
||||||
↗️, 👆 💪 📣 🌖 🔢 🔢 🕐❔ 👆 💪, 🌖 🙆 💪 🔢.
|
|
||||||
|
|
||||||
, 🔢, ⭐ 💲 🔬 🔢 🔢, 👆 🚫 ✔️ 🎯 🚮 `Query`, 👆 💪:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = None
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️ 🐍 3️⃣.1️⃣0️⃣ & 🔛:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: str | None = None
|
|
||||||
```
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_multiple_params/tutorial004.py hl[27] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`Body` ✔️ 🌐 🎏 ➕ 🔬 & 🗃 🔢 `Query`,`Path` & 🎏 👆 🔜 👀 ⏪.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⏯ 👁 💪 🔢
|
|
||||||
|
|
||||||
➡️ 💬 👆 🕴 ✔️ 👁 `item` 💪 🔢 ⚪️➡️ Pydantic 🏷 `Item`.
|
|
||||||
|
|
||||||
🔢, **FastAPI** 🔜 ⤴️ ⌛ 🚮 💪 🔗.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 💚 ⚫️ ⌛ 🎻 ⏮️ 🔑 `item` & 🔘 ⚫️ 🏷 🎚, ⚫️ 🔨 🕐❔ 👆 📣 ➕ 💪 🔢, 👆 💪 ⚙️ 🎁 `Body` 🔢 `embed`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
item: Item = Body(embed=True)
|
|
||||||
```
|
|
||||||
|
|
||||||
:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_multiple_params/tutorial005.py hl[17] *}
|
|
||||||
|
|
||||||
👉 💼 **FastAPI** 🔜 ⌛ 💪 💖:
|
|
||||||
|
|
||||||
```JSON hl_lines="2"
|
|
||||||
{
|
|
||||||
"item": {
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
↩️:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 🚮 💗 💪 🔢 👆 *➡ 🛠️ 🔢*, ✋️ 📨 💪 🕴 ✔️ 👁 💪.
|
|
||||||
|
|
||||||
✋️ **FastAPI** 🔜 🍵 ⚫️, 🤝 👆 ☑ 📊 👆 🔢, & ✔ & 📄 ☑ 🔗 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👆 💪 📣 ⭐ 💲 📨 🍕 💪.
|
|
||||||
|
|
||||||
& 👆 💪 💡 **FastAPI** ⏯ 💪 🔑 🕐❔ 📤 🕴 👁 🔢 📣.
|
|
||||||
|
|
@ -1,247 +0,0 @@
|
||||||
# 💪 - 🔁 🏷
|
|
||||||
|
|
||||||
⏮️ **FastAPI**, 👆 💪 🔬, ✔, 📄, & ⚙️ 🎲 🙇 🐦 🏷 (👏 Pydantic).
|
|
||||||
|
|
||||||
## 📇 🏑
|
|
||||||
|
|
||||||
👆 💪 🔬 🔢 🏾. 🖼, 🐍 `list`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial001.py hl[14] *}
|
|
||||||
|
|
||||||
👉 🔜 ⚒ `tags` 📇, 👐 ⚫️ 🚫 📣 🆎 🔣 📇.
|
|
||||||
|
|
||||||
## 📇 🏑 ⏮️ 🆎 🔢
|
|
||||||
|
|
||||||
✋️ 🐍 ✔️ 🎯 🌌 📣 📇 ⏮️ 🔗 🆎, ⚖️ "🆎 🔢":
|
|
||||||
|
|
||||||
### 🗄 ⌨ `List`
|
|
||||||
|
|
||||||
🐍 3️⃣.9️⃣ & 🔛 👆 💪 ⚙️ 🐩 `list` 📣 👫 🆎 ✍ 👥 🔜 👀 🔛. 👶
|
|
||||||
|
|
||||||
✋️ 🐍 ⏬ ⏭ 3️⃣.9️⃣ (3️⃣.6️⃣ & 🔛), 👆 🥇 💪 🗄 `List` ⚪️➡️ 🐩 🐍 `typing` 🕹:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial002.py hl[1] *}
|
|
||||||
|
|
||||||
### 📣 `list` ⏮️ 🆎 🔢
|
|
||||||
|
|
||||||
📣 🆎 👈 ✔️ 🆎 🔢 (🔗 🆎), 💖 `list`, `dict`, `tuple`:
|
|
||||||
|
|
||||||
* 🚥 👆 🐍 ⏬ 🔅 🌘 3️⃣.9️⃣, 🗄 👫 🌓 ⏬ ⚪️➡️ `typing` 🕹
|
|
||||||
* 🚶♀️ 🔗 🆎(Ⓜ) "🆎 🔢" ⚙️ ⬜ 🗜: `[` & `]`
|
|
||||||
|
|
||||||
🐍 3️⃣.9️⃣ ⚫️ 🔜:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
my_list: list[str]
|
|
||||||
```
|
|
||||||
|
|
||||||
⏬ 🐍 ⏭ 3️⃣.9️⃣, ⚫️ 🔜:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from typing import List
|
|
||||||
|
|
||||||
my_list: List[str]
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 🌐 🐩 🐍 ❕ 🆎 📄.
|
|
||||||
|
|
||||||
⚙️ 👈 🎏 🐩 ❕ 🏷 🔢 ⏮️ 🔗 🆎.
|
|
||||||
|
|
||||||
, 👆 🖼, 👥 💪 ⚒ `tags` 🎯 "📇 🎻":
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial002.py hl[14] *}
|
|
||||||
|
|
||||||
## ⚒ 🆎
|
|
||||||
|
|
||||||
✋️ ⤴️ 👥 💭 🔃 ⚫️, & 🤔 👈 🔖 🚫🔜 🚫 🔁, 👫 🔜 🎲 😍 🎻.
|
|
||||||
|
|
||||||
& 🐍 ✔️ 🎁 💽 🆎 ⚒ 😍 🏬, `set`.
|
|
||||||
|
|
||||||
⤴️ 👥 💪 📣 `tags` ⚒ 🎻:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial003.py hl[1,14] *}
|
|
||||||
|
|
||||||
⏮️ 👉, 🚥 👆 📨 📨 ⏮️ ❎ 📊, ⚫️ 🔜 🗜 ⚒ 😍 🏬.
|
|
||||||
|
|
||||||
& 🕐❔ 👆 🔢 👈 📊, 🚥 ℹ ✔️ ❎, ⚫️ 🔜 🔢 ⚒ 😍 🏬.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 ✍ / 📄 ➡️ 💁♂️.
|
|
||||||
|
|
||||||
## 🐦 🏷
|
|
||||||
|
|
||||||
🔠 🔢 Pydantic 🏷 ✔️ 🆎.
|
|
||||||
|
|
||||||
✋️ 👈 🆎 💪 ⚫️ ➕1️⃣ Pydantic 🏷.
|
|
||||||
|
|
||||||
, 👆 💪 📣 🙇 🐦 🎻 "🎚" ⏮️ 🎯 🔢 📛, 🆎 & 🔬.
|
|
||||||
|
|
||||||
🌐 👈, 🎲 🐦.
|
|
||||||
|
|
||||||
### 🔬 📊
|
|
||||||
|
|
||||||
🖼, 👥 💪 🔬 `Image` 🏷:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial004.py hl[9:11] *}
|
|
||||||
|
|
||||||
### ⚙️ 📊 🆎
|
|
||||||
|
|
||||||
& ⤴️ 👥 💪 ⚙️ ⚫️ 🆎 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial004.py hl[20] *}
|
|
||||||
|
|
||||||
👉 🔜 ⛓ 👈 **FastAPI** 🔜 ⌛ 💪 🎏:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2,
|
|
||||||
"tags": ["rock", "metal", "bar"],
|
|
||||||
"image": {
|
|
||||||
"url": "http://example.com/baz.jpg",
|
|
||||||
"name": "The Foo live"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
🔄, 🤸 👈 📄, ⏮️ **FastAPI** 👆 🤚:
|
|
||||||
|
|
||||||
* 👨🎨 🐕🦺 (🛠️, ♒️), 🐦 🏷
|
|
||||||
* 💽 🛠️
|
|
||||||
* 💽 🔬
|
|
||||||
* 🏧 🧾
|
|
||||||
|
|
||||||
## 🎁 🆎 & 🔬
|
|
||||||
|
|
||||||
↖️ ⚪️➡️ 😐 ⭐ 🆎 💖 `str`, `int`, `float`, ♒️. 👆 💪 ⚙️ 🌅 🏗 ⭐ 🆎 👈 😖 ⚪️➡️ `str`.
|
|
||||||
|
|
||||||
👀 🌐 🎛 👆 ✔️, 🛒 🩺 <a href="https://docs.pydantic.dev/latest/concepts/types/" class="external-link" target="_blank">Pydantic 😍 🆎</a>. 👆 🔜 👀 🖼 ⏭ 📃.
|
|
||||||
|
|
||||||
🖼, `Image` 🏷 👥 ✔️ `url` 🏑, 👥 💪 📣 ⚫️ ↩️ `str`, Pydantic `HttpUrl`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial005.py hl[4,10] *}
|
|
||||||
|
|
||||||
🎻 🔜 ✅ ☑ 📛, & 📄 🎻 🔗 / 🗄 ✅.
|
|
||||||
|
|
||||||
## 🔢 ⏮️ 📇 📊
|
|
||||||
|
|
||||||
👆 💪 ⚙️ Pydantic 🏷 🏾 `list`, `set`, ♒️:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial006.py hl[20] *}
|
|
||||||
|
|
||||||
👉 🔜 ⌛ (🗜, ✔, 📄, ♒️) 🎻 💪 💖:
|
|
||||||
|
|
||||||
```JSON hl_lines="11"
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "The pretender",
|
|
||||||
"price": 42.0,
|
|
||||||
"tax": 3.2,
|
|
||||||
"tags": [
|
|
||||||
"rock",
|
|
||||||
"metal",
|
|
||||||
"bar"
|
|
||||||
],
|
|
||||||
"images": [
|
|
||||||
{
|
|
||||||
"url": "http://example.com/baz.jpg",
|
|
||||||
"name": "The Foo live"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "http://example.com/dave.jpg",
|
|
||||||
"name": "The Baz"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👀 ❔ `images` 🔑 🔜 ✔️ 📇 🖼 🎚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🙇 🐦 🏷
|
|
||||||
|
|
||||||
👆 💪 🔬 🎲 🙇 🐦 🏷:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial007.py hl[9,14,20,23,27] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👀 ❔ `Offer` ✔️ 📇 `Item`Ⓜ, ❔ 🔄 ✔️ 📦 📇 `Image`Ⓜ
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💪 😁 📇
|
|
||||||
|
|
||||||
🚥 🔝 🎚 💲 🎻 💪 👆 ⌛ 🎻 `array` (🐍 `list`), 👆 💪 📣 🆎 🔢 🔢, 🎏 Pydantic 🏷:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
images: List[Image]
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️ 🐍 3️⃣.9️⃣ & 🔛:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
images: list[Image]
|
|
||||||
```
|
|
||||||
|
|
||||||
:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial008.py hl[15] *}
|
|
||||||
|
|
||||||
## 👨🎨 🐕🦺 🌐
|
|
||||||
|
|
||||||
& 👆 🤚 👨🎨 🐕🦺 🌐.
|
|
||||||
|
|
||||||
🏬 🔘 📇:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body-nested-models/image01.png">
|
|
||||||
|
|
||||||
👆 🚫 🚫 🤚 👉 😇 👨🎨 🐕🦺 🚥 👆 👷 🔗 ⏮️ `dict` ↩️ Pydantic 🏷.
|
|
||||||
|
|
||||||
✋️ 👆 🚫 ✔️ 😟 🔃 👫 👯♂️, 📨 #️⃣ 🗜 🔁 & 👆 🔢 🗜 🔁 🎻 💁♂️.
|
|
||||||
|
|
||||||
## 💪 ❌ `dict`Ⓜ
|
|
||||||
|
|
||||||
👆 💪 📣 💪 `dict` ⏮️ 🔑 🆎 & 💲 🎏 🆎.
|
|
||||||
|
|
||||||
🍵 ✔️ 💭 ⏪ ⚫️❔ ☑ 🏑/🔢 📛 (🔜 💼 ⏮️ Pydantic 🏷).
|
|
||||||
|
|
||||||
👉 🔜 ⚠ 🚥 👆 💚 📨 🔑 👈 👆 🚫 ⏪ 💭.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🎏 ⚠ 💼 🕐❔ 👆 💚 ✔️ 🔑 🎏 🆎, ✅ `int`.
|
|
||||||
|
|
||||||
👈 ⚫️❔ 👥 🔜 👀 📥.
|
|
||||||
|
|
||||||
👉 💼, 👆 🔜 🚫 🙆 `dict` 📏 ⚫️ ✔️ `int` 🔑 ⏮️ `float` 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_nested_models/tutorial009.py hl[9] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🎻 🕴 🐕🦺 `str` 🔑.
|
|
||||||
|
|
||||||
✋️ Pydantic ✔️ 🏧 💽 🛠️.
|
|
||||||
|
|
||||||
👉 ⛓ 👈, ✋️ 👆 🛠️ 👩💻 💪 🕴 📨 🎻 🔑, 📏 👈 🎻 🔌 😁 🔢, Pydantic 🔜 🗜 👫 & ✔ 👫.
|
|
||||||
|
|
||||||
& `dict` 👆 📨 `weights` 🔜 🤙 ✔️ `int` 🔑 & `float` 💲.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⏮️ **FastAPI** 👆 ✔️ 🔆 💪 🚚 Pydantic 🏷, ⏪ 🚧 👆 📟 🙅, 📏 & 😍.
|
|
||||||
|
|
||||||
✋️ ⏮️ 🌐 💰:
|
|
||||||
|
|
||||||
* 👨🎨 🐕🦺 (🛠️ 🌐 ❗)
|
|
||||||
* 💽 🛠️ (.Ⓜ.. ✍ / 🛠️)
|
|
||||||
* 💽 🔬
|
|
||||||
* 🔗 🧾
|
|
||||||
* 🏧 🩺
|
|
||||||
|
|
@ -1,100 +0,0 @@
|
||||||
# 💪 - ℹ
|
|
||||||
|
|
||||||
## ℹ ❎ ⏮️ `PUT`
|
|
||||||
|
|
||||||
ℹ 🏬 👆 💪 ⚙️ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PUT" class="external-link" target="_blank">🇺🇸🔍 `PUT`</a> 🛠️.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `jsonable_encoder` 🗜 🔢 💽 📊 👈 💪 🏪 🎻 (✅ ⏮️ ☁ 💽). 🖼, 🏭 `datetime` `str`.
|
|
||||||
|
|
||||||
{* ../../docs_src/body_updates/tutorial001.py hl[30:35] *}
|
|
||||||
|
|
||||||
`PUT` ⚙️ 📨 💽 👈 🔜 ❎ ♻ 💽.
|
|
||||||
|
|
||||||
### ⚠ 🔃 ❎
|
|
||||||
|
|
||||||
👈 ⛓ 👈 🚥 👆 💚 ℹ 🏬 `bar` ⚙️ `PUT` ⏮️ 💪 ⚗:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{
|
|
||||||
"name": "Barz",
|
|
||||||
"price": 3,
|
|
||||||
"description": None,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
↩️ ⚫️ 🚫 🔌 ⏪ 🏪 🔢 `"tax": 20.2`, 🔢 🏷 🔜 ✊ 🔢 💲 `"tax": 10.5`.
|
|
||||||
|
|
||||||
& 📊 🔜 🖊 ⏮️ 👈 "🆕" `tax` `10.5`.
|
|
||||||
|
|
||||||
## 🍕 ℹ ⏮️ `PATCH`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/PATCH" class="external-link" target="_blank">🇺🇸🔍 `PATCH`</a> 🛠️ *🍕* ℹ 💽.
|
|
||||||
|
|
||||||
👉 ⛓ 👈 👆 💪 📨 🕴 💽 👈 👆 💚 ℹ, 🍂 🎂 🐣.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
`PATCH` 🌘 🛎 ⚙️ & 💭 🌘 `PUT`.
|
|
||||||
|
|
||||||
& 📚 🏉 ⚙️ 🕴 `PUT`, 🍕 ℹ.
|
|
||||||
|
|
||||||
👆 **🆓** ⚙️ 👫 👐 👆 💚, **FastAPI** 🚫 🚫 🙆 🚫.
|
|
||||||
|
|
||||||
✋️ 👉 🦮 🎦 👆, 🌖 ⚖️ 🌘, ❔ 👫 🎯 ⚙️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ⚙️ Pydantic `exclude_unset` 🔢
|
|
||||||
|
|
||||||
🚥 👆 💚 📨 🍕 ℹ, ⚫️ 📶 ⚠ ⚙️ 🔢 `exclude_unset` Pydantic 🏷 `.dict()`.
|
|
||||||
|
|
||||||
💖 `item.dict(exclude_unset=True)`.
|
|
||||||
|
|
||||||
👈 🔜 🏗 `dict` ⏮️ 🕴 💽 👈 ⚒ 🕐❔ 🏗 `item` 🏷, 🚫 🔢 💲.
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ⚙️ 👉 🏗 `dict` ⏮️ 🕴 💽 👈 ⚒ (📨 📨), 🚫 🔢 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_updates/tutorial002.py hl[34] *}
|
|
||||||
|
|
||||||
### ⚙️ Pydantic `update` 🔢
|
|
||||||
|
|
||||||
🔜, 👆 💪 ✍ 📁 ♻ 🏷 ⚙️ `.copy()`, & 🚶♀️ `update` 🔢 ⏮️ `dict` ⚗ 💽 ℹ.
|
|
||||||
|
|
||||||
💖 `stored_item_model.copy(update=update_data)`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body_updates/tutorial002.py hl[35] *}
|
|
||||||
|
|
||||||
### 🍕 ℹ 🌃
|
|
||||||
|
|
||||||
📄, ✔ 🍕 ℹ 👆 🔜:
|
|
||||||
|
|
||||||
* (⚗) ⚙️ `PATCH` ↩️ `PUT`.
|
|
||||||
* 🗃 🏪 💽.
|
|
||||||
* 🚮 👈 💽 Pydantic 🏷.
|
|
||||||
* 🏗 `dict` 🍵 🔢 💲 ⚪️➡️ 🔢 🏷 (⚙️ `exclude_unset`).
|
|
||||||
* 👉 🌌 👆 💪 ℹ 🕴 💲 🤙 ⚒ 👩💻, ↩️ 🔐 💲 ⏪ 🏪 ⏮️ 🔢 💲 👆 🏷.
|
|
||||||
* ✍ 📁 🏪 🏷, 🛠️ ⚫️ 🔢 ⏮️ 📨 🍕 ℹ (⚙️ `update` 🔢).
|
|
||||||
* 🗜 📁 🏷 🕳 👈 💪 🏪 👆 💽 (🖼, ⚙️ `jsonable_encoder`).
|
|
||||||
* 👉 ⭐ ⚙️ 🏷 `.dict()` 👩🔬 🔄, ✋️ ⚫️ ⚒ 💭 (& 🗜) 💲 💽 🆎 👈 💪 🗜 🎻, 🖼, `datetime` `str`.
|
|
||||||
* 🖊 💽 👆 💽.
|
|
||||||
* 📨 ℹ 🏷.
|
|
||||||
|
|
||||||
{* ../../docs_src/body_updates/tutorial002.py hl[30:37] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 🤙 ⚙️ 👉 🎏 ⚒ ⏮️ 🇺🇸🔍 `PUT` 🛠️.
|
|
||||||
|
|
||||||
✋️ 🖼 📥 ⚙️ `PATCH` ↩️ ⚫️ ✍ 👫 ⚙️ 💼.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈 🔢 🏷 ✔.
|
|
||||||
|
|
||||||
, 🚥 👆 💚 📨 🍕 ℹ 👈 💪 🚫 🌐 🔢, 👆 💪 ✔️ 🏷 ⏮️ 🌐 🔢 ™ 📦 (⏮️ 🔢 💲 ⚖️ `None`).
|
|
||||||
|
|
||||||
🔬 ⚪️➡️ 🏷 ⏮️ 🌐 📦 💲 **ℹ** & 🏷 ⏮️ ✔ 💲 **🏗**, 👆 💪 ⚙️ 💭 🔬 [➕ 🏷](extra-models.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,162 +0,0 @@
|
||||||
# 📨 💪
|
|
||||||
|
|
||||||
🕐❔ 👆 💪 📨 📊 ⚪️➡️ 👩💻 (➡️ 💬, 🖥) 👆 🛠️, 👆 📨 ⚫️ **📨 💪**.
|
|
||||||
|
|
||||||
**📨** 💪 📊 📨 👩💻 👆 🛠️. **📨** 💪 💽 👆 🛠️ 📨 👩💻.
|
|
||||||
|
|
||||||
👆 🛠️ 🌖 🕧 ✔️ 📨 **📨** 💪. ✋️ 👩💻 🚫 🎯 💪 📨 **📨** 💪 🌐 🕰.
|
|
||||||
|
|
||||||
📣 **📨** 💪, 👆 ⚙️ <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> 🏷 ⏮️ 🌐 👫 🏋️ & 💰.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📨 💽, 👆 🔜 ⚙️ 1️⃣: `POST` (🌅 ⚠), `PUT`, `DELETE` ⚖️ `PATCH`.
|
|
||||||
|
|
||||||
📨 💪 ⏮️ `GET` 📨 ✔️ ⚠ 🎭 🔧, 👐, ⚫️ 🐕🦺 FastAPI, 🕴 📶 🏗/😕 ⚙️ 💼.
|
|
||||||
|
|
||||||
⚫️ 🚫, 🎓 🩺 ⏮️ 🦁 🎚 🏆 🚫 🎦 🧾 💪 🕐❔ ⚙️ `GET`, & 🗳 🖕 💪 🚫 🐕🦺 ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🗄 Pydantic `BaseModel`
|
|
||||||
|
|
||||||
🥇, 👆 💪 🗄 `BaseModel` ⚪️➡️ `pydantic`:
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial001.py hl[4] *}
|
|
||||||
|
|
||||||
## ✍ 👆 💽 🏷
|
|
||||||
|
|
||||||
⤴️ 👆 📣 👆 💽 🏷 🎓 👈 😖 ⚪️➡️ `BaseModel`.
|
|
||||||
|
|
||||||
⚙️ 🐩 🐍 🆎 🌐 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial001.py hl[7:11] *}
|
|
||||||
|
|
||||||
🎏 🕐❔ 📣 🔢 🔢, 🕐❔ 🏷 🔢 ✔️ 🔢 💲, ⚫️ 🚫 ✔. ⏪, ⚫️ ✔. ⚙️ `None` ⚒ ⚫️ 📦.
|
|
||||||
|
|
||||||
🖼, 👉 🏷 🔛 📣 🎻 "`object`" (⚖️ 🐍 `dict`) 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"description": "An optional description",
|
|
||||||
"price": 45.2,
|
|
||||||
"tax": 3.5
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
... `description` & `tax` 📦 (⏮️ 🔢 💲 `None`), 👉 🎻 "`object`" 🔜 ☑:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"price": 45.2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 📣 ⚫️ 🔢
|
|
||||||
|
|
||||||
🚮 ⚫️ 👆 *➡ 🛠️*, 📣 ⚫️ 🎏 🌌 👆 📣 ➡ & 🔢 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial001.py hl[18] *}
|
|
||||||
|
|
||||||
...& 📣 🚮 🆎 🏷 👆 ✍, `Item`.
|
|
||||||
|
|
||||||
## 🏁
|
|
||||||
|
|
||||||
⏮️ 👈 🐍 🆎 📄, **FastAPI** 🔜:
|
|
||||||
|
|
||||||
* ✍ 💪 📨 🎻.
|
|
||||||
* 🗜 🔗 🆎 (🚥 💪).
|
|
||||||
* ✔ 💽.
|
|
||||||
* 🚥 💽 ❌, ⚫️ 🔜 📨 👌 & 🆑 ❌, ☠️ ⚫️❔ 🌐❔ & ⚫️❔ ❌ 📊.
|
|
||||||
* 🤝 👆 📨 📊 🔢 `item`.
|
|
||||||
* 👆 📣 ⚫️ 🔢 🆎 `Item`, 👆 🔜 ✔️ 🌐 👨🎨 🐕🦺 (🛠️, ♒️) 🌐 🔢 & 👫 🆎.
|
|
||||||
* 🏗 <a href="https://json-schema.org" class="external-link" target="_blank">🎻 🔗</a> 🔑 👆 🏷, 👆 💪 ⚙️ 👫 🙆 🙆 👆 💖 🚥 ⚫️ ⚒ 🔑 👆 🏗.
|
|
||||||
* 👈 🔗 🔜 🍕 🏗 🗄 🔗, & ⚙️ 🏧 🧾 <abbr title="User Interfaces">⚜</abbr>.
|
|
||||||
|
|
||||||
## 🏧 🩺
|
|
||||||
|
|
||||||
🎻 🔗 👆 🏷 🔜 🍕 👆 🗄 🏗 🔗, & 🔜 🎦 🎓 🛠️ 🩺:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body/image01.png">
|
|
||||||
|
|
||||||
& 🔜 ⚙️ 🛠️ 🩺 🔘 🔠 *➡ 🛠️* 👈 💪 👫:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body/image02.png">
|
|
||||||
|
|
||||||
## 👨🎨 🐕🦺
|
|
||||||
|
|
||||||
👆 👨🎨, 🔘 👆 🔢 👆 🔜 🤚 🆎 🔑 & 🛠️ 🌐 (👉 🚫🔜 🔨 🚥 👆 📨 `dict` ↩️ Pydantic 🏷):
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body/image03.png">
|
|
||||||
|
|
||||||
👆 🤚 ❌ ✅ ❌ 🆎 🛠️:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body/image04.png">
|
|
||||||
|
|
||||||
👉 🚫 🤞, 🎂 🛠️ 🏗 🤭 👈 🔧.
|
|
||||||
|
|
||||||
& ⚫️ 🙇 💯 🔧 🌓, ⏭ 🙆 🛠️, 🚚 ⚫️ 🔜 👷 ⏮️ 🌐 👨🎨.
|
|
||||||
|
|
||||||
📤 🔀 Pydantic ⚫️ 🐕🦺 👉.
|
|
||||||
|
|
||||||
⏮️ 🖼 ✊ ⏮️ <a href="https://code.visualstudio.com" class="external-link" target="_blank">🎙 🎙 📟</a>.
|
|
||||||
|
|
||||||
✋️ 👆 🔜 🤚 🎏 👨🎨 🐕🦺 ⏮️ <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">🗒</a> & 🌅 🎏 🐍 👨🎨:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/body/image05.png">
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ <a href="https://www.jetbrains.com/pycharm/" class="external-link" target="_blank">🗒</a> 👆 👨🎨, 👆 💪 ⚙️ <a href="https://github.com/koxudaxi/pydantic-pycharm-plugin/" class="external-link" target="_blank">Pydantic 🗒 📁</a>.
|
|
||||||
|
|
||||||
⚫️ 📉 👨🎨 🐕🦺 Pydantic 🏷, ⏮️:
|
|
||||||
|
|
||||||
* 🚘-🛠️
|
|
||||||
* 🆎 ✅
|
|
||||||
* 🛠️
|
|
||||||
* 🔎
|
|
||||||
* 🔬
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚙️ 🏷
|
|
||||||
|
|
||||||
🔘 🔢, 👆 💪 🔐 🌐 🔢 🏷 🎚 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial002.py hl[21] *}
|
|
||||||
|
|
||||||
## 📨 💪 ➕ ➡ 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 ➡ 🔢 & 📨 💪 🎏 🕰.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 🤔 👈 🔢 🔢 👈 🏏 ➡ 🔢 🔜 **✊ ⚪️➡️ ➡**, & 👈 🔢 🔢 👈 📣 Pydantic 🏷 🔜 **✊ ⚪️➡️ 📨 💪**.
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial003.py hl[17:18] *}
|
|
||||||
|
|
||||||
## 📨 💪 ➕ ➡ ➕ 🔢 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 **💪**, **➡** & **🔢** 🔢, 🌐 🎏 🕰.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 🤔 🔠 👫 & ✊ 📊 ⚪️➡️ ☑ 🥉.
|
|
||||||
|
|
||||||
{* ../../docs_src/body/tutorial004.py hl[18] *}
|
|
||||||
|
|
||||||
🔢 🔢 🔜 🤔 ⏩:
|
|
||||||
|
|
||||||
* 🚥 🔢 📣 **➡**, ⚫️ 🔜 ⚙️ ➡ 🔢.
|
|
||||||
* 🚥 🔢 **⭐ 🆎** (💖 `int`, `float`, `str`, `bool`, ♒️) ⚫️ 🔜 🔬 **🔢** 🔢.
|
|
||||||
* 🚥 🔢 📣 🆎 **Pydantic 🏷**, ⚫️ 🔜 🔬 📨 **💪**.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
FastAPI 🔜 💭 👈 💲 `q` 🚫 ✔ ↩️ 🔢 💲 `= None`.
|
|
||||||
|
|
||||||
`Union` `Union[str, None]` 🚫 ⚙️ FastAPI, ✋️ 🔜 ✔ 👆 👨🎨 🤝 👆 👍 🐕🦺 & 🔍 ❌.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🍵 Pydantic
|
|
||||||
|
|
||||||
🚥 👆 🚫 💚 ⚙️ Pydantic 🏷, 👆 💪 ⚙️ **💪** 🔢. 👀 🩺 [💪 - 💗 🔢: ⭐ 💲 💪](body-multiple-params.md#_2){.internal-link target=_blank}.
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# 🍪 🔢
|
|
||||||
|
|
||||||
👆 💪 🔬 🍪 🔢 🎏 🌌 👆 🔬 `Query` & `Path` 🔢.
|
|
||||||
|
|
||||||
## 🗄 `Cookie`
|
|
||||||
|
|
||||||
🥇 🗄 `Cookie`:
|
|
||||||
|
|
||||||
{* ../../docs_src/cookie_params/tutorial001.py hl[3] *}
|
|
||||||
|
|
||||||
## 📣 `Cookie` 🔢
|
|
||||||
|
|
||||||
⤴️ 📣 🍪 🔢 ⚙️ 🎏 📊 ⏮️ `Path` & `Query`.
|
|
||||||
|
|
||||||
🥇 💲 🔢 💲, 👆 💪 🚶♀️ 🌐 ➕ 🔬 ⚖️ ✍ 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/cookie_params/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
`Cookie` "👭" 🎓 `Path` & `Query`. ⚫️ 😖 ⚪️➡️ 🎏 ⚠ `Param` 🎓.
|
|
||||||
|
|
||||||
✋️ 💭 👈 🕐❔ 👆 🗄 `Query`, `Path`, `Cookie` & 🎏 ⚪️➡️ `fastapi`, 👈 🤙 🔢 👈 📨 🎁 🎓.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📣 🍪, 👆 💪 ⚙️ `Cookie`, ↩️ ⏪ 🔢 🔜 🔬 🔢 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
📣 🍪 ⏮️ `Cookie`, ⚙️ 🎏 ⚠ ⚓ `Query` & `Path`.
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
# ⚜ (✖️-🇨🇳 ℹ 🤝)
|
|
||||||
|
|
||||||
<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" class="external-link" target="_blank">⚜ ⚖️ "✖️-🇨🇳 ℹ 🤝"</a> 🔗 ⚠ 🕐❔ 🕸 🏃♂ 🖥 ✔️ 🕸 📟 👈 🔗 ⏮️ 👩💻, & 👩💻 🎏 "🇨🇳" 🌘 🕸.
|
|
||||||
|
|
||||||
## 🇨🇳
|
|
||||||
|
|
||||||
🇨🇳 🌀 🛠️ (`http`, `https`), 🆔 (`myapp.com`, `localhost`, `localhost.tiangolo.com`), & ⛴ (`80`, `443`, `8080`).
|
|
||||||
|
|
||||||
, 🌐 👫 🎏 🇨🇳:
|
|
||||||
|
|
||||||
* `http://localhost`
|
|
||||||
* `https://localhost`
|
|
||||||
* `http://localhost:8080`
|
|
||||||
|
|
||||||
🚥 👫 🌐 `localhost`, 👫 ⚙️ 🎏 🛠️ ⚖️ ⛴,, 👫 🎏 "🇨🇳".
|
|
||||||
|
|
||||||
## 🔁
|
|
||||||
|
|
||||||
, ➡️ 💬 👆 ✔️ 🕸 🏃 👆 🖥 `http://localhost:8080`, & 🚮 🕸 🔄 🔗 ⏮️ 👩💻 🏃 `http://localhost` (↩️ 👥 🚫 ✔ ⛴, 🖥 🔜 🤔 🔢 ⛴ `80`).
|
|
||||||
|
|
||||||
⤴️, 🖥 🔜 📨 🇺🇸🔍 `OPTIONS` 📨 👩💻, & 🚥 👩💻 📨 ☑ 🎚 ✔ 📻 ⚪️➡️ 👉 🎏 🇨🇳 (`http://localhost:8080`) ⤴️ 🖥 🔜 ➡️ 🕸 🕸 📨 🚮 📨 👩💻.
|
|
||||||
|
|
||||||
🏆 👉, 👩💻 🔜 ✔️ 📇 "✔ 🇨🇳".
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 🔜 ✔️ 🔌 `http://localhost:8080` 🕸 👷 ☑.
|
|
||||||
|
|
||||||
## 🃏
|
|
||||||
|
|
||||||
⚫️ 💪 📣 📇 `"*"` ("🃏") 💬 👈 🌐 ✔.
|
|
||||||
|
|
||||||
✋️ 👈 🔜 🕴 ✔ 🎯 🆎 📻, 🚫 🌐 👈 🔌 🎓: 🍪, ✔ 🎚 💖 📚 ⚙️ ⏮️ 📨 🤝, ♒️.
|
|
||||||
|
|
||||||
, 🌐 👷 ☑, ⚫️ 👻 ✔ 🎯 ✔ 🇨🇳.
|
|
||||||
|
|
||||||
## ⚙️ `CORSMiddleware`
|
|
||||||
|
|
||||||
👆 💪 🔗 ⚫️ 👆 **FastAPI** 🈸 ⚙️ `CORSMiddleware`.
|
|
||||||
|
|
||||||
* 🗄 `CORSMiddleware`.
|
|
||||||
* ✍ 📇 ✔ 🇨🇳 (🎻).
|
|
||||||
* 🚮 ⚫️ "🛠️" 👆 **FastAPI** 🈸.
|
|
||||||
|
|
||||||
👆 💪 ✔ 🚥 👆 👩💻 ✔:
|
|
||||||
|
|
||||||
* 🎓 (✔ 🎚, 🍪, ♒️).
|
|
||||||
* 🎯 🇺🇸🔍 👩🔬 (`POST`, `PUT`) ⚖️ 🌐 👫 ⏮️ 🃏 `"*"`.
|
|
||||||
* 🎯 🇺🇸🔍 🎚 ⚖️ 🌐 👫 ⏮️ 🃏 `"*"`.
|
|
||||||
|
|
||||||
{* ../../docs_src/cors/tutorial001.py hl[2,6:11,13:19] *}
|
|
||||||
|
|
||||||
🔢 🔢 ⚙️ `CORSMiddleware` 🛠️ 🚫 🔢, 👆 🔜 💪 🎯 🛠️ 🎯 🇨🇳, 👩🔬, ⚖️ 🎚, ✔ 🖥 ✔ ⚙️ 👫 ✖️-🆔 🔑.
|
|
||||||
|
|
||||||
📄 ❌ 🐕🦺:
|
|
||||||
|
|
||||||
* `allow_origins` - 📇 🇨🇳 👈 🔜 ✔ ⚒ ✖️-🇨🇳 📨. 🤶 Ⓜ. `['https://example.org', 'https://www.example.org']`. 👆 💪 ⚙️ `['*']` ✔ 🙆 🇨🇳.
|
|
||||||
* `allow_origin_regex` - 🎻 🎻 🏏 🛡 🇨🇳 👈 🔜 ✔ ⚒ ✖️-🇨🇳 📨. ✅ `'https://.*\.example\.org'`.
|
|
||||||
* `allow_methods` - 📇 🇺🇸🔍 👩🔬 👈 🔜 ✔ ✖️-🇨🇳 📨. 🔢 `['GET']`. 👆 💪 ⚙️ `['*']` ✔ 🌐 🐩 👩🔬.
|
|
||||||
* `allow_headers` - 📇 🇺🇸🔍 📨 🎚 👈 🔜 🐕🦺 ✖️-🇨🇳 📨. 🔢 `[]`. 👆 💪 ⚙️ `['*']` ✔ 🌐 🎚. `Accept`, `Accept-Language`, `Content-Language` & `Content-Type` 🎚 🕧 ✔ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests" class="external-link" rel="noopener" target="_blank">🙅 ⚜ 📨</a>.
|
|
||||||
* `allow_credentials` - 🎦 👈 🍪 🔜 🐕🦺 ✖️-🇨🇳 📨. 🔢 `False`. , `allow_origins` 🚫🔜 ⚒ `['*']` 🎓 ✔, 🇨🇳 🔜 ✔.
|
|
||||||
* `expose_headers` - 🎦 🙆 📨 🎚 👈 🔜 ⚒ ♿ 🖥. 🔢 `[]`.
|
|
||||||
* `max_age` - ⚒ 🔆 🕰 🥈 🖥 💾 ⚜ 📨. 🔢 `600`.
|
|
||||||
|
|
||||||
🛠️ 📨 2️⃣ 🎯 🆎 🇺🇸🔍 📨...
|
|
||||||
|
|
||||||
### ⚜ 🛫 📨
|
|
||||||
|
|
||||||
👉 🙆 `OPTIONS` 📨 ⏮️ `Origin` & `Access-Control-Request-Method` 🎚.
|
|
||||||
|
|
||||||
👉 💼 🛠️ 🔜 🆘 📨 📨 & 📨 ⏮️ ☑ ⚜ 🎚, & 👯♂️ `200` ⚖️ `400` 📨 🎓 🎯.
|
|
||||||
|
|
||||||
### 🙅 📨
|
|
||||||
|
|
||||||
🙆 📨 ⏮️ `Origin` 🎚. 👉 💼 🛠️ 🔜 🚶♀️ 📨 🔘 😐, ✋️ 🔜 🔌 ☑ ⚜ 🎚 🔛 📨.
|
|
||||||
|
|
||||||
## 🌅 ℹ
|
|
||||||
|
|
||||||
🌖 ℹ 🔃 <abbr title="Cross-Origin Resource Sharing">⚜</abbr>, ✅ <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS" class="external-link" target="_blank">🦎 ⚜ 🧾</a>.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.middleware.cors import CORSMiddleware`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 📚 🛠️ `fastapi.middleware` 🏪 👆, 👩💻. ✋️ 🌅 💪 🛠️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,113 +0,0 @@
|
||||||
# 🛠️
|
|
||||||
|
|
||||||
👆 💪 🔗 🕹 👆 👨🎨, 🖼 ⏮️ 🎙 🎙 📟 ⚖️ 🗒.
|
|
||||||
|
|
||||||
## 🤙 `uvicorn`
|
|
||||||
|
|
||||||
👆 FastAPI 🈸, 🗄 & 🏃 `uvicorn` 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/debugging/tutorial001.py hl[1,15] *}
|
|
||||||
|
|
||||||
### 🔃 `__name__ == "__main__"`
|
|
||||||
|
|
||||||
👑 🎯 `__name__ == "__main__"` ✔️ 📟 👈 🛠️ 🕐❔ 👆 📁 🤙 ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ python myapp.py
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
✋️ 🚫 🤙 🕐❔ ➕1️⃣ 📁 🗄 ⚫️, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from myapp import app
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 🌅 ℹ
|
|
||||||
|
|
||||||
➡️ 💬 👆 📁 🌟 `myapp.py`.
|
|
||||||
|
|
||||||
🚥 👆 🏃 ⚫️ ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ python myapp.py
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
⤴️ 🔗 🔢 `__name__` 👆 📁, ✍ 🔁 🐍, 🔜 ✔️ 💲 🎻 `"__main__"`.
|
|
||||||
|
|
||||||
, 📄:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 🏃.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👉 🏆 🚫 🔨 🚥 👆 🗄 👈 🕹 (📁).
|
|
||||||
|
|
||||||
, 🚥 👆 ✔️ ➕1️⃣ 📁 `importer.py` ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from myapp import app
|
|
||||||
|
|
||||||
# Some more code
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 💼, 🏧 🔢 🔘 `myapp.py` 🔜 🚫 ✔️ 🔢 `__name__` ⏮️ 💲 `"__main__"`.
|
|
||||||
|
|
||||||
, ⏸:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 🚫 🛠️.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🌅 ℹ, ✅ <a href="https://docs.python.org/3/library/__main__.html" class="external-link" target="_blank">🛂 🐍 🩺</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🏃 👆 📟 ⏮️ 👆 🕹
|
|
||||||
|
|
||||||
↩️ 👆 🏃 Uvicorn 💽 🔗 ⚪️➡️ 👆 📟, 👆 💪 🤙 👆 🐍 📋 (👆 FastAPI 🈸) 🔗 ⚪️➡️ 🕹.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🖼, 🎙 🎙 📟, 👆 💪:
|
|
||||||
|
|
||||||
* 🚶 "ℹ" 🎛.
|
|
||||||
* "🚮 📳...".
|
|
||||||
* 🖊 "🐍"
|
|
||||||
* 🏃 🕹 ⏮️ 🎛 "`Python: Current File (Integrated Terminal)`".
|
|
||||||
|
|
||||||
⚫️ 🔜 ⤴️ ▶️ 💽 ⏮️ 👆 **FastAPI** 📟, ⛔️ 👆 0️⃣, ♒️.
|
|
||||||
|
|
||||||
📥 ❔ ⚫️ 💪 👀:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/debugging/image01.png">
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ 🗒, 👆 💪:
|
|
||||||
|
|
||||||
* 📂 "🏃" 🍣.
|
|
||||||
* 🖊 🎛 "ℹ...".
|
|
||||||
* ⤴️ 🔑 🍣 🎦 🆙.
|
|
||||||
* 🖊 📁 ℹ (👉 💼, `main.py`).
|
|
||||||
|
|
||||||
⚫️ 🔜 ⤴️ ▶️ 💽 ⏮️ 👆 **FastAPI** 📟, ⛔️ 👆 0️⃣, ♒️.
|
|
||||||
|
|
||||||
📥 ❔ ⚫️ 💪 👀:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/debugging/image02.png">
|
|
||||||
|
|
@ -1,180 +0,0 @@
|
||||||
# 🎓 🔗
|
|
||||||
|
|
||||||
⏭ 🤿 ⏬ 🔘 **🔗 💉** ⚙️, ➡️ ♻ ⏮️ 🖼.
|
|
||||||
|
|
||||||
## `dict` ⚪️➡️ ⏮️ 🖼
|
|
||||||
|
|
||||||
⏮️ 🖼, 👥 🛬 `dict` ⚪️➡️ 👆 🔗 ("☑"):
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
✋️ ⤴️ 👥 🤚 `dict` 🔢 `commons` *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
& 👥 💭 👈 👨🎨 💪 🚫 🚚 📚 🐕🦺 (💖 🛠️) `dict`Ⓜ, ↩️ 👫 💪 🚫 💭 👫 🔑 & 💲 🆎.
|
|
||||||
|
|
||||||
👥 💪 👍...
|
|
||||||
|
|
||||||
## ⚫️❔ ⚒ 🔗
|
|
||||||
|
|
||||||
🆙 🔜 👆 ✔️ 👀 🔗 📣 🔢.
|
|
||||||
|
|
||||||
✋️ 👈 🚫 🕴 🌌 📣 🔗 (👐 ⚫️ 🔜 🎲 🌖 ⚠).
|
|
||||||
|
|
||||||
🔑 ⚖ 👈 🔗 🔜 "🇧🇲".
|
|
||||||
|
|
||||||
"**🇧🇲**" 🐍 🕳 👈 🐍 💪 "🤙" 💖 🔢.
|
|
||||||
|
|
||||||
, 🚥 👆 ✔️ 🎚 `something` (👈 💪 _🚫_ 🔢) & 👆 💪 "🤙" ⚫️ (🛠️ ⚫️) 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
something()
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️
|
|
||||||
|
|
||||||
```Python
|
|
||||||
something(some_argument, some_keyword_argument="foo")
|
|
||||||
```
|
|
||||||
|
|
||||||
⤴️ ⚫️ "🇧🇲".
|
|
||||||
|
|
||||||
## 🎓 🔗
|
|
||||||
|
|
||||||
👆 5️⃣📆 👀 👈 ✍ 👐 🐍 🎓, 👆 ⚙️ 👈 🎏 ❕.
|
|
||||||
|
|
||||||
🖼:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
class Cat:
|
|
||||||
def __init__(self, name: str):
|
|
||||||
self.name = name
|
|
||||||
|
|
||||||
|
|
||||||
fluffy = Cat(name="Mr Fluffy")
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 💼, `fluffy` 👐 🎓 `Cat`.
|
|
||||||
|
|
||||||
& ✍ `fluffy`, 👆 "🤙" `Cat`.
|
|
||||||
|
|
||||||
, 🐍 🎓 **🇧🇲**.
|
|
||||||
|
|
||||||
⤴️, **FastAPI**, 👆 💪 ⚙️ 🐍 🎓 🔗.
|
|
||||||
|
|
||||||
⚫️❔ FastAPI 🤙 ✅ 👈 ⚫️ "🇧🇲" (🔢, 🎓 ⚖️ 🕳 🙆) & 🔢 🔬.
|
|
||||||
|
|
||||||
🚥 👆 🚶♀️ "🇧🇲" 🔗 **FastAPI**, ⚫️ 🔜 🔬 🔢 👈 "🇧🇲", & 🛠️ 👫 🎏 🌌 🔢 *➡ 🛠️ 🔢*. ✅ 🎧-🔗.
|
|
||||||
|
|
||||||
👈 ✔ 🇧🇲 ⏮️ 🙅♂ 🔢 🌐. 🎏 ⚫️ 🔜 *➡ 🛠️ 🔢* ⏮️ 🙅♂ 🔢.
|
|
||||||
|
|
||||||
⤴️, 👥 💪 🔀 🔗 "☑" `common_parameters` ⚪️➡️ 🔛 🎓 `CommonQueryParams`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial002.py hl[11:15] *}
|
|
||||||
|
|
||||||
💸 🙋 `__init__` 👩🔬 ⚙️ ✍ 👐 🎓:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial002.py hl[12] *}
|
|
||||||
|
|
||||||
...⚫️ ✔️ 🎏 🔢 👆 ⏮️ `common_parameters`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
📚 🔢 ⚫️❔ **FastAPI** 🔜 ⚙️ "❎" 🔗.
|
|
||||||
|
|
||||||
👯♂️ 💼, ⚫️ 🔜 ✔️:
|
|
||||||
|
|
||||||
* 📦 `q` 🔢 🔢 👈 `str`.
|
|
||||||
* `skip` 🔢 🔢 👈 `int`, ⏮️ 🔢 `0`.
|
|
||||||
* `limit` 🔢 🔢 👈 `int`, ⏮️ 🔢 `100`.
|
|
||||||
|
|
||||||
👯♂️ 💼 💽 🔜 🗜, ✔, 📄 🔛 🗄 🔗, ♒️.
|
|
||||||
|
|
||||||
## ⚙️ ⚫️
|
|
||||||
|
|
||||||
🔜 👆 💪 📣 👆 🔗 ⚙️ 👉 🎓.
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial002.py hl[19] *}
|
|
||||||
|
|
||||||
**FastAPI** 🤙 `CommonQueryParams` 🎓. 👉 ✍ "👐" 👈 🎓 & 👐 🔜 🚶♀️ 🔢 `commons` 👆 🔢.
|
|
||||||
|
|
||||||
## 🆎 ✍ 🆚 `Depends`
|
|
||||||
|
|
||||||
👀 ❔ 👥 ✍ `CommonQueryParams` 🕐 🔛 📟:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
|
||||||
```
|
|
||||||
|
|
||||||
🏁 `CommonQueryParams`,:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
... = Depends(CommonQueryParams)
|
|
||||||
```
|
|
||||||
|
|
||||||
...⚫️❔ **FastAPI** 🔜 🤙 ⚙️ 💭 ⚫️❔ 🔗.
|
|
||||||
|
|
||||||
⚪️➡️ ⚫️ 👈 FastAPI 🔜 ⚗ 📣 🔢 & 👈 ⚫️❔ FastAPI 🔜 🤙 🤙.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👉 💼, 🥇 `CommonQueryParams`,:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons: CommonQueryParams ...
|
|
||||||
```
|
|
||||||
|
|
||||||
...🚫 ✔️ 🙆 🎁 🔑 **FastAPI**. FastAPI 🏆 🚫 ⚙️ ⚫️ 💽 🛠️, 🔬, ♒️. (⚫️ ⚙️ `= Depends(CommonQueryParams)` 👈).
|
|
||||||
|
|
||||||
👆 💪 🤙 ✍:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons = Depends(CommonQueryParams)
|
|
||||||
```
|
|
||||||
|
|
||||||
...:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial003.py hl[19] *}
|
|
||||||
|
|
||||||
✋️ 📣 🆎 💡 👈 🌌 👆 👨🎨 🔜 💭 ⚫️❔ 🔜 🚶♀️ 🔢 `commons`, & ⤴️ ⚫️ 💪 ℹ 👆 ⏮️ 📟 🛠️, 🆎 ✅, ♒️:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/dependencies/image02.png">
|
|
||||||
|
|
||||||
## ⌨
|
|
||||||
|
|
||||||
✋️ 👆 👀 👈 👥 ✔️ 📟 🔁 📥, ✍ `CommonQueryParams` 🕐:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
|
||||||
```
|
|
||||||
|
|
||||||
**FastAPI** 🚚 ⌨ 👫 💼, 🌐❔ 🔗 *🎯* 🎓 👈 **FastAPI** 🔜 "🤙" ✍ 👐 🎓 ⚫️.
|
|
||||||
|
|
||||||
📚 🎯 💼, 👆 💪 📄:
|
|
||||||
|
|
||||||
↩️ ✍:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
|
||||||
```
|
|
||||||
|
|
||||||
...👆 ✍:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
commons: CommonQueryParams = Depends()
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 📣 🔗 🆎 🔢, & 👆 ⚙️ `Depends()` 🚮 "🔢" 💲 (👈 ⏮️ `=`) 👈 🔢 🔢, 🍵 🙆 🔢 `Depends()`, ↩️ ✔️ ✍ 🌕 🎓 *🔄* 🔘 `Depends(CommonQueryParams)`.
|
|
||||||
|
|
||||||
🎏 🖼 🔜 ⤴️ 👀 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial004.py hl[19] *}
|
|
||||||
|
|
||||||
...& **FastAPI** 🔜 💭 ⚫️❔.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👈 😑 🌅 😨 🌘 👍, 🤷♂ ⚫️, 👆 🚫 *💪* ⚫️.
|
|
||||||
|
|
||||||
⚫️ ⌨. ↩️ **FastAPI** 💅 🔃 🤝 👆 📉 📟 🔁.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
# 🔗 ➡ 🛠️ 👨🎨
|
|
||||||
|
|
||||||
💼 👆 🚫 🤙 💪 📨 💲 🔗 🔘 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
⚖️ 🔗 🚫 📨 💲.
|
|
||||||
|
|
||||||
✋️ 👆 💪 ⚫️ 🛠️/❎.
|
|
||||||
|
|
||||||
📚 💼, ↩️ 📣 *➡ 🛠️ 🔢* 🔢 ⏮️ `Depends`, 👆 💪 🚮 `list` `dependencies` *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
||||||
## 🚮 `dependencies` *➡ 🛠️ 👨🎨*
|
|
||||||
|
|
||||||
*➡ 🛠️ 👨🎨* 📨 📦 ❌ `dependencies`.
|
|
||||||
|
|
||||||
⚫️ 🔜 `list` `Depends()`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial006.py hl[17] *}
|
|
||||||
|
|
||||||
👉 🔗 🔜 🛠️/❎ 🎏 🌌 😐 🔗. ✋️ 👫 💲 (🚥 👫 📨 🙆) 🏆 🚫 🚶♀️ 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👨🎨 ✅ ♻ 🔢 🔢, & 🎦 👫 ❌.
|
|
||||||
|
|
||||||
⚙️ 👉 `dependencies` *➡ 🛠️ 👨🎨* 👆 💪 ⚒ 💭 👫 🛠️ ⏪ ❎ 👨🎨/🏭 ❌.
|
|
||||||
|
|
||||||
⚫️ 💪 ℹ ❎ 😨 🆕 👩💻 👈 👀 ♻ 🔢 👆 📟 & 💪 💭 ⚫️ 🙃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👉 🖼 👥 ⚙️ 💭 🛃 🎚 `X-Key` & `X-Token`.
|
|
||||||
|
|
||||||
✋️ 🎰 💼, 🕐❔ 🛠️ 💂♂, 👆 🔜 🤚 🌖 💰 ⚪️➡️ ⚙️ 🛠️ [💂♂ 🚙 (⏭ 📃)](../security/index.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔗 ❌ & 📨 💲
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 🔗 *🔢* 👆 ⚙️ 🛎.
|
|
||||||
|
|
||||||
### 🔗 📄
|
|
||||||
|
|
||||||
👫 💪 📣 📨 📄 (💖 🎚) ⚖️ 🎏 🎧-🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial006.py hl[6,11] *}
|
|
||||||
|
|
||||||
### 🤚 ⚠
|
|
||||||
|
|
||||||
👫 🔗 💪 `raise` ⚠, 🎏 😐 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial006.py hl[8,13] *}
|
|
||||||
|
|
||||||
### 📨 💲
|
|
||||||
|
|
||||||
& 👫 💪 📨 💲 ⚖️ 🚫, 💲 🏆 🚫 ⚙️.
|
|
||||||
|
|
||||||
, 👆 💪 🏤-⚙️ 😐 🔗 (👈 📨 💲) 👆 ⏪ ⚙️ 👱 🙆, & ✋️ 💲 🏆 🚫 ⚙️, 🔗 🔜 🛠️:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial006.py hl[9,14] *}
|
|
||||||
|
|
||||||
## 🔗 👪 *➡ 🛠️*
|
|
||||||
|
|
||||||
⏪, 🕐❔ 👂 🔃 ❔ 📊 🦏 🈸 ([🦏 🈸 - 💗 📁](../../tutorial/bigger-applications.md){.internal-link target=_blank}), 🎲 ⏮️ 💗 📁, 👆 🔜 💡 ❔ 📣 👁 `dependencies` 🔢 👪 *➡ 🛠️*.
|
|
||||||
|
|
||||||
## 🌐 🔗
|
|
||||||
|
|
||||||
⏭ 👥 🔜 👀 ❔ 🚮 🔗 🎂 `FastAPI` 🈸, 👈 👫 ✔ 🔠 *➡ 🛠️*.
|
|
||||||
|
|
@ -1,232 +0,0 @@
|
||||||
# 🔗 ⏮️ 🌾
|
|
||||||
|
|
||||||
FastAPI 🐕🦺 🔗 👈 <abbr title='sometimes also called "exit", "cleanup", "teardown", "close", "context managers", ...'>➕ 🔁 ⏮️ 🏁</abbr>.
|
|
||||||
|
|
||||||
👉, ⚙️ `yield` ↩️ `return`, & ✍ ➕ 🔁 ⏮️.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
⚒ 💭 ⚙️ `yield` 1️⃣ 👁 🕰.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🙆 🔢 👈 ☑ ⚙️ ⏮️:
|
|
||||||
|
|
||||||
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager" class="external-link" target="_blank">`@contextlib.contextmanager`</a> ⚖️
|
|
||||||
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
|
|
||||||
|
|
||||||
🔜 ☑ ⚙️ **FastAPI** 🔗.
|
|
||||||
|
|
||||||
👐, FastAPI ⚙️ 📚 2️⃣ 👨🎨 🔘.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💽 🔗 ⏮️ `yield`
|
|
||||||
|
|
||||||
🖼, 👆 💪 ⚙️ 👉 ✍ 💽 🎉 & 🔐 ⚫️ ⏮️ 🏁.
|
|
||||||
|
|
||||||
🕴 📟 ⏭ & 🔌 `yield` 📄 🛠️ ⏭ 📨 📨:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial007.py hl[2:4] *}
|
|
||||||
|
|
||||||
🌾 💲 ⚫️❔ 💉 🔘 *➡ 🛠️* & 🎏 🔗:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial007.py hl[4] *}
|
|
||||||
|
|
||||||
📟 📄 `yield` 📄 🛠️ ⏮️ 📨 ✔️ 🚚:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial007.py hl[5:6] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `async` ⚖️ 😐 🔢.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ▶️️ 👜 ⏮️ 🔠, 🎏 ⏮️ 😐 🔗.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔗 ⏮️ `yield` & `try`
|
|
||||||
|
|
||||||
🚥 👆 ⚙️ `try` 🍫 🔗 ⏮️ `yield`, 👆 🔜 📨 🙆 ⚠ 👈 🚮 🕐❔ ⚙️ 🔗.
|
|
||||||
|
|
||||||
🖼, 🚥 📟 ☝ 🖕, ➕1️⃣ 🔗 ⚖️ *➡ 🛠️*, ⚒ 💽 💵 "💾" ⚖️ ✍ 🙆 🎏 ❌, 👆 🔜 📨 ⚠ 👆 🔗.
|
|
||||||
|
|
||||||
, 👆 💪 👀 👈 🎯 ⚠ 🔘 🔗 ⏮️ `except SomeException`.
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 ⚙️ `finally` ⚒ 💭 🚪 📶 🛠️, 🙅♂ 🤔 🚥 📤 ⚠ ⚖️ 🚫.
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial007.py hl[3,5] *}
|
|
||||||
|
|
||||||
## 🎧-🔗 ⏮️ `yield`
|
|
||||||
|
|
||||||
👆 💪 ✔️ 🎧-🔗 & "🌲" 🎧-🔗 🙆 📐 & 💠, & 🙆 ⚖️ 🌐 👫 💪 ⚙️ `yield`.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚒ 💭 👈 "🚪 📟" 🔠 🔗 ⏮️ `yield` 🏃 ☑ ✔.
|
|
||||||
|
|
||||||
🖼, `dependency_c` 💪 ✔️ 🔗 🔛 `dependency_b`, & `dependency_b` 🔛 `dependency_a`:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial008.py hl[4,12,20] *}
|
|
||||||
|
|
||||||
& 🌐 👫 💪 ⚙️ `yield`.
|
|
||||||
|
|
||||||
👉 💼 `dependency_c`, 🛠️ 🚮 🚪 📟, 💪 💲 ⚪️➡️ `dependency_b` (📥 📛 `dep_b`) 💪.
|
|
||||||
|
|
||||||
& , 🔄, `dependency_b` 💪 💲 ⚪️➡️ `dependency_a` (📥 📛 `dep_a`) 💪 🚮 🚪 📟.
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial008.py hl[16:17,24:25] *}
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 ✔️ 🔗 ⏮️ `yield` & `return` 🌀.
|
|
||||||
|
|
||||||
& 👆 💪 ✔️ 👁 🔗 👈 🚚 📚 🎏 🔗 ⏮️ `yield`, ♒️.
|
|
||||||
|
|
||||||
👆 💪 ✔️ 🙆 🌀 🔗 👈 👆 💚.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚒ 💭 🌐 🏃 ☑ ✔.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👉 👷 👏 🐍 <a href="https://docs.python.org/3/library/contextlib.html" class="external-link" target="_blank">🔑 👨💼</a>.
|
|
||||||
|
|
||||||
**FastAPI** ⚙️ 👫 🔘 🏆 👉.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔗 ⏮️ `yield` & `HTTPException`
|
|
||||||
|
|
||||||
👆 👀 👈 👆 💪 ⚙️ 🔗 ⏮️ `yield` & ✔️ `try` 🍫 👈 ✊ ⚠.
|
|
||||||
|
|
||||||
⚫️ 5️⃣📆 😋 🤚 `HTTPException` ⚖️ 🎏 🚪 📟, ⏮️ `yield`. ✋️ **⚫️ 🏆 🚫 👷**.
|
|
||||||
|
|
||||||
🚪 📟 🔗 ⏮️ `yield` 🛠️ *⏮️* 📨 📨, [⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank} 🔜 ✔️ ⏪ 🏃. 📤 🕳 😽 ⚠ 🚮 👆 🔗 🚪 📟 (⏮️ `yield`).
|
|
||||||
|
|
||||||
, 🚥 👆 🤚 `HTTPException` ⏮️ `yield`, 🔢 (⚖️ 🙆 🛃) ⚠ 🐕🦺 👈 ✊ `HTTPException`Ⓜ & 📨 🇺🇸🔍 4️⃣0️⃣0️⃣ 📨 🏆 🚫 📤 ✊ 👈 ⚠ 🚫🔜.
|
|
||||||
|
|
||||||
👉 ⚫️❔ ✔ 🕳 ⚒ 🔗 (✅ 💽 🎉), 🖼, ⚙️ 🖥 📋.
|
|
||||||
|
|
||||||
🖥 📋 🏃 *⏮️* 📨 ✔️ 📨. 📤 🙅♂ 🌌 🤚 `HTTPException` ↩️ 📤 🚫 🌌 🔀 📨 👈 *⏪ 📨*.
|
|
||||||
|
|
||||||
✋️ 🚥 🖥 📋 ✍ 💽 ❌, 🌘 👆 💪 💾 ⚖️ 😬 🔐 🎉 🔗 ⏮️ `yield`, & 🎲 🕹 ❌ ⚖️ 📄 ⚫️ 🛰 🕵 ⚙️.
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 📟 👈 👆 💭 💪 🤚 ⚠, 🏆 😐/"🙃" 👜 & 🚮 `try` 🍫 👈 📄 📟.
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🛃 ⚠ 👈 👆 🔜 💖 🍵 *⏭* 🛬 📨 & 🎲 ❎ 📨, 🎲 🙋♀ `HTTPException`, ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 🤚 ⚠ 🔌 `HTTPException` *⏭* `yield`. ✋️ 🚫 ⏮️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔁 🛠️ 🌅 ⚖️ 🌘 💖 👉 📊. 🕰 💧 ⚪️➡️ 🔝 🔝. & 🔠 🏓 1️⃣ 🍕 🔗 ⚖️ 🛠️ 📟.
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
sequenceDiagram
|
|
||||||
|
|
||||||
participant client as Client
|
|
||||||
participant handler as Exception handler
|
|
||||||
participant dep as Dep with yield
|
|
||||||
participant operation as Path Operation
|
|
||||||
participant tasks as Background tasks
|
|
||||||
|
|
||||||
Note over client,tasks: Can raise exception for dependency, handled after response is sent
|
|
||||||
Note over client,operation: Can raise HTTPException and can change the response
|
|
||||||
client ->> dep: Start request
|
|
||||||
Note over dep: Run code up to yield
|
|
||||||
opt raise
|
|
||||||
dep -->> handler: Raise HTTPException
|
|
||||||
handler -->> client: HTTP error response
|
|
||||||
dep -->> dep: Raise other exception
|
|
||||||
end
|
|
||||||
dep ->> operation: Run dependency, e.g. DB session
|
|
||||||
opt raise
|
|
||||||
operation -->> dep: Raise HTTPException
|
|
||||||
dep -->> handler: Auto forward exception
|
|
||||||
handler -->> client: HTTP error response
|
|
||||||
operation -->> dep: Raise other exception
|
|
||||||
dep -->> handler: Auto forward exception
|
|
||||||
end
|
|
||||||
operation ->> client: Return response to client
|
|
||||||
Note over client,operation: Response is already sent, can't change it anymore
|
|
||||||
opt Tasks
|
|
||||||
operation -->> tasks: Send background tasks
|
|
||||||
end
|
|
||||||
opt Raise other exception
|
|
||||||
tasks -->> dep: Raise other exception
|
|
||||||
end
|
|
||||||
Note over dep: After yield
|
|
||||||
opt Handle other exception
|
|
||||||
dep -->> dep: Handle exception, can't change response. E.g. close DB session.
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
🕴 **1️⃣ 📨** 🔜 📨 👩💻. ⚫️ 💪 1️⃣ ❌ 📨 ⚖️ ⚫️ 🔜 📨 ⚪️➡️ *➡ 🛠️*.
|
|
||||||
|
|
||||||
⏮️ 1️⃣ 📚 📨 📨, 🙅♂ 🎏 📨 💪 📨.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👉 📊 🎦 `HTTPException`, ✋️ 👆 💪 🤚 🙆 🎏 ⚠ ❔ 👆 ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
🚥 👆 🤚 🙆 ⚠, ⚫️ 🔜 🚶♀️ 🔗 ⏮️ 🌾, 🔌 `HTTPException`, & ⤴️ **🔄** ⚠ 🐕🦺. 🚥 📤 🙅♂ ⚠ 🐕🦺 👈 ⚠, ⚫️ 🔜 ⤴️ 🍵 🔢 🔗 `ServerErrorMiddleware`, 🛬 5️⃣0️⃣0️⃣ 🇺🇸🔍 👔 📟, ➡️ 👩💻 💭 👈 📤 ❌ 💽.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔑 👨💼
|
|
||||||
|
|
||||||
### ⚫️❔ "🔑 👨💼"
|
|
||||||
|
|
||||||
"🔑 👨💼" 🙆 👈 🐍 🎚 👈 👆 💪 ⚙️ `with` 📄.
|
|
||||||
|
|
||||||
🖼, <a href="https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files" class="external-link" target="_blank">👆 💪 ⚙️ `with` ✍ 📁</a>:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
with open("./somefile.txt") as f:
|
|
||||||
contents = f.read()
|
|
||||||
print(contents)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔘, `open("./somefile.txt")` ✍ 🎚 👈 🤙 "🔑 👨💼".
|
|
||||||
|
|
||||||
🕐❔ `with` 🍫 🏁, ⚫️ ⚒ 💭 🔐 📁, 🚥 📤 ⚠.
|
|
||||||
|
|
||||||
🕐❔ 👆 ✍ 🔗 ⏮️ `yield`, **FastAPI** 🔜 🔘 🗜 ⚫️ 🔑 👨💼, & 🌀 ⚫️ ⏮️ 🎏 🔗 🧰.
|
|
||||||
|
|
||||||
### ⚙️ 🔑 👨💼 🔗 ⏮️ `yield`
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👉, 🌅 ⚖️ 🌘, "🏧" 💭.
|
|
||||||
|
|
||||||
🚥 👆 ▶️ ⏮️ **FastAPI** 👆 💪 💚 🚶 ⚫️ 🔜.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🐍, 👆 💪 ✍ 🔑 👨💼 <a href="https://docs.python.org/3/reference/datamodel.html#context-managers" class="external-link" target="_blank">🏗 🎓 ⏮️ 2️⃣ 👩🔬: `__enter__()` & `__exit__()`</a>.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 👫 🔘 **FastAPI** 🔗 ⏮️ `yield` ⚙️
|
|
||||||
`with` ⚖️ `async with` 📄 🔘 🔗 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial010.py hl[1:9,13] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
➕1️⃣ 🌌 ✍ 🔑 👨💼 ⏮️:
|
|
||||||
|
|
||||||
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.contextmanager" class="external-link" target="_blank">`@contextlib.contextmanager`</a> ⚖️
|
|
||||||
* <a href="https://docs.python.org/3/library/contextlib.html#contextlib.asynccontextmanager" class="external-link" target="_blank">`@contextlib.asynccontextmanager`</a>
|
|
||||||
|
|
||||||
⚙️ 👫 🎀 🔢 ⏮️ 👁 `yield`.
|
|
||||||
|
|
||||||
👈 ⚫️❔ **FastAPI** ⚙️ 🔘 🔗 ⏮️ `yield`.
|
|
||||||
|
|
||||||
✋️ 👆 🚫 ✔️ ⚙️ 👨🎨 FastAPI 🔗 (& 👆 🚫🔜 🚫).
|
|
||||||
|
|
||||||
FastAPI 🔜 ⚫️ 👆 🔘.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,15 +0,0 @@
|
||||||
# 🌐 🔗
|
|
||||||
|
|
||||||
🆎 🈸 👆 💪 💚 🚮 🔗 🎂 🈸.
|
|
||||||
|
|
||||||
🎏 🌌 👆 💪 [🚮 `dependencies` *➡ 🛠️ 👨🎨*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank}, 👆 💪 🚮 👫 `FastAPI` 🈸.
|
|
||||||
|
|
||||||
👈 💼, 👫 🔜 ✔ 🌐 *➡ 🛠️* 🈸:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial012.py hl[15] *}
|
|
||||||
|
|
||||||
& 🌐 💭 📄 🔃 [❎ `dependencies` *➡ 🛠️ 👨🎨*](dependencies-in-path-operation-decorators.md){.internal-link target=_blank} ✔, ✋️ 👉 💼, 🌐 *➡ 🛠️* 📱.
|
|
||||||
|
|
||||||
## 🔗 👪 *➡ 🛠️*
|
|
||||||
|
|
||||||
⏪, 🕐❔ 👂 🔃 ❔ 📊 🦏 🈸 ([🦏 🈸 - 💗 📁](../../tutorial/bigger-applications.md){.internal-link target=_blank}), 🎲 ⏮️ 💗 📁, 👆 🔜 💡 ❔ 📣 👁 `dependencies` 🔢 👪 *➡ 🛠️*.
|
|
||||||
|
|
@ -1,212 +0,0 @@
|
||||||
# 🔗
|
|
||||||
|
|
||||||
**FastAPI** ✔️ 📶 🏋️ ✋️ 🏋️ **<abbr title="also known as components, resources, providers, services, injectables">🔗 💉</abbr>** ⚙️.
|
|
||||||
|
|
||||||
⚫️ 🏗 📶 🙅 ⚙️, & ⚒ ⚫️ 📶 ⏩ 🙆 👩💻 🛠️ 🎏 🦲 ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
## ⚫️❔ "🔗 💉"
|
|
||||||
|
|
||||||
**"🔗 💉"** ⛓, 📋, 👈 📤 🌌 👆 📟 (👉 💼, 👆 *➡ 🛠️ 🔢*) 📣 👜 👈 ⚫️ 🚚 👷 & ⚙️: "🔗".
|
|
||||||
|
|
||||||
& ⤴️, 👈 ⚙️ (👉 💼 **FastAPI**) 🔜 ✊ 💅 🔨 ⚫️❔ 💪 🚚 👆 📟 ⏮️ 📚 💪 🔗 ("💉" 🔗).
|
|
||||||
|
|
||||||
👉 📶 ⚠ 🕐❔ 👆 💪:
|
|
||||||
|
|
||||||
* ✔️ 💰 ⚛ (🎏 📟 ⚛ 🔄 & 🔄).
|
|
||||||
* 💰 💽 🔗.
|
|
||||||
* 🛠️ 💂♂, 🤝, 🔑 📄, ♒️.
|
|
||||||
* & 📚 🎏 👜...
|
|
||||||
|
|
||||||
🌐 👫, ⏪ 📉 📟 🔁.
|
|
||||||
|
|
||||||
## 🥇 🔁
|
|
||||||
|
|
||||||
➡️ 👀 📶 🙅 🖼. ⚫️ 🔜 🙅 👈 ⚫️ 🚫 📶 ⚠, 🔜.
|
|
||||||
|
|
||||||
✋️ 👉 🌌 👥 💪 🎯 🔛 ❔ **🔗 💉** ⚙️ 👷.
|
|
||||||
|
|
||||||
### ✍ 🔗, ⚖️ "☑"
|
|
||||||
|
|
||||||
➡️ 🥇 🎯 🔛 🔗.
|
|
||||||
|
|
||||||
⚫️ 🔢 👈 💪 ✊ 🌐 🎏 🔢 👈 *➡ 🛠️ 🔢* 💪 ✊:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial001.py hl[8:11] *}
|
|
||||||
|
|
||||||
👈 ⚫️.
|
|
||||||
|
|
||||||
**2️⃣ ⏸**.
|
|
||||||
|
|
||||||
& ⚫️ ✔️ 🎏 💠 & 📊 👈 🌐 👆 *➡ 🛠️ 🔢* ✔️.
|
|
||||||
|
|
||||||
👆 💪 💭 ⚫️ *➡ 🛠️ 🔢* 🍵 "👨🎨" (🍵 `@app.get("/some-path")`).
|
|
||||||
|
|
||||||
& ⚫️ 💪 📨 🕳 👆 💚.
|
|
||||||
|
|
||||||
👉 💼, 👉 🔗 ⌛:
|
|
||||||
|
|
||||||
* 📦 🔢 🔢 `q` 👈 `str`.
|
|
||||||
* 📦 🔢 🔢 `skip` 👈 `int`, & 🔢 `0`.
|
|
||||||
* 📦 🔢 🔢 `limit` 👈 `int`, & 🔢 `100`.
|
|
||||||
|
|
||||||
& ⤴️ ⚫️ 📨 `dict` ⚗ 📚 💲.
|
|
||||||
|
|
||||||
### 🗄 `Depends`
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial001.py hl[3] *}
|
|
||||||
|
|
||||||
### 📣 🔗, "⚓️"
|
|
||||||
|
|
||||||
🎏 🌌 👆 ⚙️ `Body`, `Query`, ♒️. ⏮️ 👆 *➡ 🛠️ 🔢* 🔢, ⚙️ `Depends` ⏮️ 🆕 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial001.py hl[15,20] *}
|
|
||||||
|
|
||||||
👐 👆 ⚙️ `Depends` 🔢 👆 🔢 🎏 🌌 👆 ⚙️ `Body`, `Query`, ♒️, `Depends` 👷 👄 🎏.
|
|
||||||
|
|
||||||
👆 🕴 🤝 `Depends` 👁 🔢.
|
|
||||||
|
|
||||||
👉 🔢 🔜 🕳 💖 🔢.
|
|
||||||
|
|
||||||
& 👈 🔢 ✊ 🔢 🎏 🌌 👈 *➡ 🛠️ 🔢* .
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 🔜 👀 ⚫️❔ 🎏 "👜", ↖️ ⚪️➡️ 🔢, 💪 ⚙️ 🔗 ⏭ 📃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🕐❔ 🆕 📨 🛬, **FastAPI** 🔜 ✊ 💅:
|
|
||||||
|
|
||||||
* 🤙 👆 🔗 ("☑") 🔢 ⏮️ ☑ 🔢.
|
|
||||||
* 🤚 🏁 ⚪️➡️ 👆 🔢.
|
|
||||||
* 🛠️ 👈 🏁 🔢 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
|
|
||||||
common_parameters(["common_parameters"])
|
|
||||||
read_items["/items/"]
|
|
||||||
read_users["/users/"]
|
|
||||||
|
|
||||||
common_parameters --> read_items
|
|
||||||
common_parameters --> read_users
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 🌌 👆 ✍ 🔗 📟 🕐 & **FastAPI** ✊ 💅 🤙 ⚫️ 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
👀 👈 👆 🚫 ✔️ ✍ 🎁 🎓 & 🚶♀️ ⚫️ 👱 **FastAPI** "®" ⚫️ ⚖️ 🕳 🎏.
|
|
||||||
|
|
||||||
👆 🚶♀️ ⚫️ `Depends` & **FastAPI** 💭 ❔ 🎂.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## `async` ⚖️ 🚫 `async`
|
|
||||||
|
|
||||||
🔗 🔜 🤙 **FastAPI** (🎏 👆 *➡ 🛠️ 🔢*), 🎏 🚫 ✔ ⏪ 🔬 👆 🔢.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `async def` ⚖️ 😐 `def`.
|
|
||||||
|
|
||||||
& 👆 💪 📣 🔗 ⏮️ `async def` 🔘 😐 `def` *➡ 🛠️ 🔢*, ⚖️ `def` 🔗 🔘 `async def` *➡ 🛠️ 🔢*, ♒️.
|
|
||||||
|
|
||||||
⚫️ 🚫 🤔. **FastAPI** 🔜 💭 ⚫️❔.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🚥 👆 🚫 💭, ✅ [🔁: *"🏃 ❓" *](../../async.md){.internal-link target=_blank} 📄 🔃 `async` & `await` 🩺.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🛠️ ⏮️ 🗄
|
|
||||||
|
|
||||||
🌐 📨 📄, 🔬 & 📄 👆 🔗 (& 🎧-🔗) 🔜 🛠️ 🎏 🗄 🔗.
|
|
||||||
|
|
||||||
, 🎓 🩺 🔜 ✔️ 🌐 ℹ ⚪️➡️ 👫 🔗 💁♂️:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/dependencies/image01.png">
|
|
||||||
|
|
||||||
## 🙅 ⚙️
|
|
||||||
|
|
||||||
🚥 👆 👀 ⚫️, *➡ 🛠️ 🔢* 📣 ⚙️ 🕐❔ *➡* & *🛠️* 🏏, & ⤴️ **FastAPI** ✊ 💅 🤙 🔢 ⏮️ ☑ 🔢, ❎ 📊 ⚪️➡️ 📨.
|
|
||||||
|
|
||||||
🤙, 🌐 (⚖️ 🏆) 🕸 🛠️ 👷 👉 🎏 🌌.
|
|
||||||
|
|
||||||
👆 🙅 🤙 👈 🔢 🔗. 👫 🤙 👆 🛠️ (👉 💼, **FastAPI**).
|
|
||||||
|
|
||||||
⏮️ 🔗 💉 ⚙️, 👆 💪 💬 **FastAPI** 👈 👆 *➡ 🛠️ 🔢* "🪀" 🔛 🕳 🙆 👈 🔜 🛠️ ⏭ 👆 *➡ 🛠️ 🔢*, & **FastAPI** 🔜 ✊ 💅 🛠️ ⚫️ & "💉" 🏁.
|
|
||||||
|
|
||||||
🎏 ⚠ ⚖ 👉 🎏 💭 "🔗 💉":
|
|
||||||
|
|
||||||
* ℹ
|
|
||||||
* 🐕🦺
|
|
||||||
* 🐕🦺
|
|
||||||
* 💉
|
|
||||||
* 🦲
|
|
||||||
|
|
||||||
## **FastAPI** 🔌-🔌
|
|
||||||
|
|
||||||
🛠️ & "🔌-"Ⓜ 💪 🏗 ⚙️ **🔗 💉** ⚙️. ✋️ 👐, 📤 🤙 **🙅♂ 💪 ✍ "🔌-🔌"**, ⚙️ 🔗 ⚫️ 💪 📣 ♾ 🔢 🛠️ & 🔗 👈 ▶️️ 💪 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
& 🔗 💪 ✍ 📶 🙅 & 🏋️ 🌌 👈 ✔ 👆 🗄 🐍 📦 👆 💪, & 🛠️ 👫 ⏮️ 👆 🛠️ 🔢 👩❤👨 ⏸ 📟, *🌖*.
|
|
||||||
|
|
||||||
👆 🔜 👀 🖼 👉 ⏭ 📃, 🔃 🔗 & ☁ 💽, 💂♂, ♒️.
|
|
||||||
|
|
||||||
## **FastAPI** 🔗
|
|
||||||
|
|
||||||
🦁 🔗 💉 ⚙️ ⚒ **FastAPI** 🔗 ⏮️:
|
|
||||||
|
|
||||||
* 🌐 🔗 💽
|
|
||||||
* ☁ 💽
|
|
||||||
* 🔢 📦
|
|
||||||
* 🔢 🔗
|
|
||||||
* 🤝 & ✔ ⚙️
|
|
||||||
* 🛠️ ⚙️ ⚖ ⚙️
|
|
||||||
* 📨 💽 💉 ⚙️
|
|
||||||
* ♒️.
|
|
||||||
|
|
||||||
## 🙅 & 🏋️
|
|
||||||
|
|
||||||
👐 🔗 🔗 💉 ⚙️ 📶 🙅 🔬 & ⚙️, ⚫️ 📶 🏋️.
|
|
||||||
|
|
||||||
👆 💪 🔬 🔗 👈 🔄 💪 🔬 🔗 👫.
|
|
||||||
|
|
||||||
🔚, 🔗 🌲 🔗 🏗, & **🔗 💉** ⚙️ ✊ 💅 🔬 🌐 👉 🔗 👆 (& 👫 🎧-🔗) & 🚚 (💉) 🏁 🔠 🔁.
|
|
||||||
|
|
||||||
🖼, ➡️ 💬 👆 ✔️ 4️⃣ 🛠️ 🔗 (*➡ 🛠️*):
|
|
||||||
|
|
||||||
* `/items/public/`
|
|
||||||
* `/items/private/`
|
|
||||||
* `/users/{user_id}/activate`
|
|
||||||
* `/items/pro/`
|
|
||||||
|
|
||||||
⤴️ 👆 💪 🚮 🎏 ✔ 📄 🔠 👫 ⏮️ 🔗 & 🎧-🔗:
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
|
|
||||||
current_user(["current_user"])
|
|
||||||
active_user(["active_user"])
|
|
||||||
admin_user(["admin_user"])
|
|
||||||
paying_user(["paying_user"])
|
|
||||||
|
|
||||||
public["/items/public/"]
|
|
||||||
private["/items/private/"]
|
|
||||||
activate_user["/users/{user_id}/activate"]
|
|
||||||
pro_items["/items/pro/"]
|
|
||||||
|
|
||||||
current_user --> active_user
|
|
||||||
active_user --> admin_user
|
|
||||||
active_user --> paying_user
|
|
||||||
|
|
||||||
current_user --> public
|
|
||||||
active_user --> private
|
|
||||||
admin_user --> activate_user
|
|
||||||
paying_user --> pro_items
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🛠️ ⏮️ **🗄**
|
|
||||||
|
|
||||||
🌐 👫 🔗, ⏪ 📣 👫 📄, 🚮 🔢, 🔬, ♒️. 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ✊ 💅 🚮 ⚫️ 🌐 🗄 🔗, 👈 ⚫️ 🎦 🎓 🧾 ⚙️.
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
# 🎧-🔗
|
|
||||||
|
|
||||||
👆 💪 ✍ 🔗 👈 ✔️ **🎧-🔗**.
|
|
||||||
|
|
||||||
👫 💪 **⏬** 👆 💪 👫.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ✊ 💅 🔬 👫.
|
|
||||||
|
|
||||||
## 🥇 🔗 "☑"
|
|
||||||
|
|
||||||
👆 💪 ✍ 🥇 🔗 ("☑") 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial005.py hl[8:9] *}
|
|
||||||
|
|
||||||
⚫️ 📣 📦 🔢 🔢 `q` `str`, & ⤴️ ⚫️ 📨 ⚫️.
|
|
||||||
|
|
||||||
👉 🙅 (🚫 📶 ⚠), ✋️ 🔜 ℹ 👥 🎯 🔛 ❔ 🎧-🔗 👷.
|
|
||||||
|
|
||||||
## 🥈 🔗, "☑" & "⚓️"
|
|
||||||
|
|
||||||
⤴️ 👆 💪 ✍ ➕1️⃣ 🔗 🔢 ("☑") 👈 🎏 🕰 📣 🔗 🚮 👍 (⚫️ "⚓️" 💁♂️):
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial005.py hl[13] *}
|
|
||||||
|
|
||||||
➡️ 🎯 🔛 🔢 📣:
|
|
||||||
|
|
||||||
* ✋️ 👉 🔢 🔗 ("☑") ⚫️, ⚫️ 📣 ➕1️⃣ 🔗 (⚫️ "🪀" 🔛 🕳 🙆).
|
|
||||||
* ⚫️ 🪀 🔛 `query_extractor`, & 🛠️ 💲 📨 ⚫️ 🔢 `q`.
|
|
||||||
* ⚫️ 📣 📦 `last_query` 🍪, `str`.
|
|
||||||
* 🚥 👩💻 🚫 🚚 🙆 🔢 `q`, 👥 ⚙️ 🏁 🔢 ⚙️, ❔ 👥 🖊 🍪 ⏭.
|
|
||||||
|
|
||||||
## ⚙️ 🔗
|
|
||||||
|
|
||||||
⤴️ 👥 💪 ⚙️ 🔗 ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/dependencies/tutorial005.py hl[22] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👀 👈 👥 🕴 📣 1️⃣ 🔗 *➡ 🛠️ 🔢*, `query_or_cookie_extractor`.
|
|
||||||
|
|
||||||
✋️ **FastAPI** 🔜 💭 👈 ⚫️ ✔️ ❎ `query_extractor` 🥇, 🚶♀️ 🏁 👈 `query_or_cookie_extractor` ⏪ 🤙 ⚫️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
```mermaid
|
|
||||||
graph TB
|
|
||||||
|
|
||||||
query_extractor(["query_extractor"])
|
|
||||||
query_or_cookie_extractor(["query_or_cookie_extractor"])
|
|
||||||
|
|
||||||
read_query["/items/"]
|
|
||||||
|
|
||||||
query_extractor --> query_or_cookie_extractor --> read_query
|
|
||||||
```
|
|
||||||
|
|
||||||
## ⚙️ 🎏 🔗 💗 🕰
|
|
||||||
|
|
||||||
🚥 1️⃣ 👆 🔗 📣 💗 🕰 🎏 *➡ 🛠️*, 🖼, 💗 🔗 ✔️ ⚠ 🎧-🔗, **FastAPI** 🔜 💭 🤙 👈 🎧-🔗 🕴 🕐 📍 📨.
|
|
||||||
|
|
||||||
& ⚫️ 🔜 🖊 📨 💲 <abbr title="A utility/system to store computed/generated values, to re-use them instead of computing them again.">"💾"</abbr> & 🚶♀️ ⚫️ 🌐 "⚓️" 👈 💪 ⚫️ 👈 🎯 📨, ↩️ 🤙 🔗 💗 🕰 🎏 📨.
|
|
||||||
|
|
||||||
🏧 😐 🌐❔ 👆 💭 👆 💪 🔗 🤙 🔠 🔁 (🎲 💗 🕰) 🎏 📨 ↩️ ⚙️ "💾" 💲, 👆 💪 ⚒ 🔢 `use_cache=False` 🕐❔ ⚙️ `Depends`:
|
|
||||||
|
|
||||||
```Python hl_lines="1"
|
|
||||||
async def needy_dependency(fresh_value: str = Depends(get_value, use_cache=False)):
|
|
||||||
return {"fresh_value": fresh_value}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
↖️ ⚪️➡️ 🌐 🎀 🔤 ⚙️ 📥, **🔗 💉** ⚙️ 🙅.
|
|
||||||
|
|
||||||
🔢 👈 👀 🎏 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
✋️, ⚫️ 📶 🏋️, & ✔ 👆 📣 🎲 🙇 🐦 🔗 "📊" (🌲).
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🌐 👉 💪 🚫 😑 ⚠ ⏮️ 👫 🙅 🖼.
|
|
||||||
|
|
||||||
✋️ 👆 🔜 👀 ❔ ⚠ ⚫️ 📃 🔃 **💂♂**.
|
|
||||||
|
|
||||||
& 👆 🔜 👀 💸 📟 ⚫️ 🔜 🖊 👆.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
# 🎻 🔗 🔢
|
|
||||||
|
|
||||||
📤 💼 🌐❔ 👆 5️⃣📆 💪 🗜 💽 🆎 (💖 Pydantic 🏷) 🕳 🔗 ⏮️ 🎻 (💖 `dict`, `list`, ♒️).
|
|
||||||
|
|
||||||
🖼, 🚥 👆 💪 🏪 ⚫️ 💽.
|
|
||||||
|
|
||||||
👈, **FastAPI** 🚚 `jsonable_encoder()` 🔢.
|
|
||||||
|
|
||||||
## ⚙️ `jsonable_encoder`
|
|
||||||
|
|
||||||
➡️ 🌈 👈 👆 ✔️ 💽 `fake_db` 👈 🕴 📨 🎻 🔗 💽.
|
|
||||||
|
|
||||||
🖼, ⚫️ 🚫 📨 `datetime` 🎚, 👈 🚫 🔗 ⏮️ 🎻.
|
|
||||||
|
|
||||||
, `datetime` 🎚 🔜 ✔️ 🗜 `str` ⚗ 💽 <a href="https://en.wikipedia.org/wiki/ISO_8601" class="external-link" target="_blank">💾 📁</a>.
|
|
||||||
|
|
||||||
🎏 🌌, 👉 💽 🚫🔜 📨 Pydantic 🏷 (🎚 ⏮️ 🔢), 🕴 `dict`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `jsonable_encoder` 👈.
|
|
||||||
|
|
||||||
⚫️ 📨 🎚, 💖 Pydantic 🏷, & 📨 🎻 🔗 ⏬:
|
|
||||||
|
|
||||||
{* ../../docs_src/encoder/tutorial001.py hl[5,22] *}
|
|
||||||
|
|
||||||
👉 🖼, ⚫️ 🔜 🗜 Pydantic 🏷 `dict`, & `datetime` `str`.
|
|
||||||
|
|
||||||
🏁 🤙 ⚫️ 🕳 👈 💪 🗜 ⏮️ 🐍 🐩 <a href="https://docs.python.org/3/library/json.html#json.dumps" class="external-link" target="_blank">`json.dumps()`</a>.
|
|
||||||
|
|
||||||
⚫️ 🚫 📨 ⭕ `str` ⚗ 💽 🎻 📁 (🎻). ⚫️ 📨 🐍 🐩 💽 📊 (✅ `dict`) ⏮️ 💲 & 🎧-💲 👈 🌐 🔗 ⏮️ 🎻.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
`jsonable_encoder` 🤙 ⚙️ **FastAPI** 🔘 🗜 💽. ✋️ ⚫️ ⚠ 📚 🎏 😐.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,62 +0,0 @@
|
||||||
# ➕ 💽 🆎
|
|
||||||
|
|
||||||
🆙 🔜, 👆 ✔️ ⚙️ ⚠ 📊 🆎, 💖:
|
|
||||||
|
|
||||||
* `int`
|
|
||||||
* `float`
|
|
||||||
* `str`
|
|
||||||
* `bool`
|
|
||||||
|
|
||||||
✋️ 👆 💪 ⚙️ 🌅 🏗 📊 🆎.
|
|
||||||
|
|
||||||
& 👆 🔜 ✔️ 🎏 ⚒ 👀 🆙 🔜:
|
|
||||||
|
|
||||||
* 👑 👨🎨 🐕🦺.
|
|
||||||
* 💽 🛠️ ⚪️➡️ 📨 📨.
|
|
||||||
* 💽 🛠️ 📨 💽.
|
|
||||||
* 💽 🔬.
|
|
||||||
* 🏧 ✍ & 🧾.
|
|
||||||
|
|
||||||
## 🎏 💽 🆎
|
|
||||||
|
|
||||||
📥 🌖 📊 🆎 👆 💪 ⚙️:
|
|
||||||
|
|
||||||
* `UUID`:
|
|
||||||
* 🐩 "⭐ 😍 🆔", ⚠ 🆔 📚 💽 & ⚙️.
|
|
||||||
* 📨 & 📨 🔜 🎨 `str`.
|
|
||||||
* `datetime.datetime`:
|
|
||||||
* 🐍 `datetime.datetime`.
|
|
||||||
* 📨 & 📨 🔜 🎨 `str` 💾 8️⃣6️⃣0️⃣1️⃣ 📁, 💖: `2008-09-15T15:53:00+05:00`.
|
|
||||||
* `datetime.date`:
|
|
||||||
* 🐍 `datetime.date`.
|
|
||||||
* 📨 & 📨 🔜 🎨 `str` 💾 8️⃣6️⃣0️⃣1️⃣ 📁, 💖: `2008-09-15`.
|
|
||||||
* `datetime.time`:
|
|
||||||
* 🐍 `datetime.time`.
|
|
||||||
* 📨 & 📨 🔜 🎨 `str` 💾 8️⃣6️⃣0️⃣1️⃣ 📁, 💖: `14:23:55.003`.
|
|
||||||
* `datetime.timedelta`:
|
|
||||||
* 🐍 `datetime.timedelta`.
|
|
||||||
* 📨 & 📨 🔜 🎨 `float` 🌐 🥈.
|
|
||||||
* Pydantic ✔ 🎦 ⚫️ "💾 8️⃣6️⃣0️⃣1️⃣ 🕰 ➕ 🔢", <a href="https://docs.pydantic.dev/latest/concepts/serialization/#json_encoders" class="external-link" target="_blank">👀 🩺 🌅 ℹ</a>.
|
|
||||||
* `frozenset`:
|
|
||||||
* 📨 & 📨, 😥 🎏 `set`:
|
|
||||||
* 📨, 📇 🔜 ✍, ❎ ❎ & 🏭 ⚫️ `set`.
|
|
||||||
* 📨, `set` 🔜 🗜 `list`.
|
|
||||||
* 🏗 🔗 🔜 ✔ 👈 `set` 💲 😍 (⚙️ 🎻 🔗 `uniqueItems`).
|
|
||||||
* `bytes`:
|
|
||||||
* 🐩 🐍 `bytes`.
|
|
||||||
* 📨 & 📨 🔜 😥 `str`.
|
|
||||||
* 🏗 🔗 🔜 ✔ 👈 ⚫️ `str` ⏮️ `binary` "📁".
|
|
||||||
* `Decimal`:
|
|
||||||
* 🐩 🐍 `Decimal`.
|
|
||||||
* 📨 & 📨, 🍵 🎏 `float`.
|
|
||||||
* 👆 💪 ✅ 🌐 ☑ Pydantic 📊 🆎 📥: <a href="https://docs.pydantic.dev/latest/concepts/types/" class="external-link" target="_blank">Pydantic 📊 🆎</a>.
|
|
||||||
|
|
||||||
## 🖼
|
|
||||||
|
|
||||||
📥 🖼 *➡ 🛠️* ⏮️ 🔢 ⚙️ 🔛 🆎.
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_data_types/tutorial001.py hl[1,3,12:16] *}
|
|
||||||
|
|
||||||
🗒 👈 🔢 🔘 🔢 ✔️ 👫 🐠 💽 🆎, & 👆 💪, 🖼, 🎭 😐 📅 🎭, 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_data_types/tutorial001.py hl[18:19] *}
|
|
||||||
|
|
@ -1,211 +0,0 @@
|
||||||
# ➕ 🏷
|
|
||||||
|
|
||||||
▶️ ⏮️ ⏮️ 🖼, ⚫️ 🔜 ⚠ ✔️ 🌅 🌘 1️⃣ 🔗 🏷.
|
|
||||||
|
|
||||||
👉 ✴️ 💼 👩💻 🏷, ↩️:
|
|
||||||
|
|
||||||
* **🔢 🏷** 💪 💪 ✔️ 🔐.
|
|
||||||
* **🔢 🏷** 🔜 🚫 ✔️ 🔐.
|
|
||||||
* **💽 🏷** 🔜 🎲 💪 ✔️ #️⃣ 🔐.
|
|
||||||
|
|
||||||
/// danger
|
|
||||||
|
|
||||||
🙅 🏪 👩💻 🔢 🔐. 🕧 🏪 "🔐 #️⃣" 👈 👆 💪 ⤴️ ✔.
|
|
||||||
|
|
||||||
🚥 👆 🚫 💭, 👆 🔜 💡 ⚫️❔ "🔐#️⃣" [💂♂ 📃](security/simple-oauth2.md#_4){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💗 🏷
|
|
||||||
|
|
||||||
📥 🏢 💭 ❔ 🏷 💪 👀 💖 ⏮️ 👫 🔐 🏑 & 🥉 🌐❔ 👫 ⚙️:
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_models/tutorial001.py hl[9,11,16,22,24,29:30,33:35,40:41] *}
|
|
||||||
|
|
||||||
### 🔃 `**user_in.dict()`
|
|
||||||
|
|
||||||
#### Pydantic `.dict()`
|
|
||||||
|
|
||||||
`user_in` Pydantic 🏷 🎓 `UserIn`.
|
|
||||||
|
|
||||||
Pydantic 🏷 ✔️ `.dict()` 👩🔬 👈 📨 `dict` ⏮️ 🏷 💽.
|
|
||||||
|
|
||||||
, 🚥 👥 ✍ Pydantic 🎚 `user_in` 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
user_in = UserIn(username="john", password="secret", email="john.doe@example.com")
|
|
||||||
```
|
|
||||||
|
|
||||||
& ⤴️ 👥 🤙:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
user_dict = user_in.dict()
|
|
||||||
```
|
|
||||||
|
|
||||||
👥 🔜 ✔️ `dict` ⏮️ 💽 🔢 `user_dict` (⚫️ `dict` ↩️ Pydantic 🏷 🎚).
|
|
||||||
|
|
||||||
& 🚥 👥 🤙:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
print(user_dict)
|
|
||||||
```
|
|
||||||
|
|
||||||
👥 🔜 🤚 🐍 `dict` ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
{
|
|
||||||
'username': 'john',
|
|
||||||
'password': 'secret',
|
|
||||||
'email': 'john.doe@example.com',
|
|
||||||
'full_name': None,
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### 🎁 `dict`
|
|
||||||
|
|
||||||
🚥 👥 ✊ `dict` 💖 `user_dict` & 🚶♀️ ⚫️ 🔢 (⚖️ 🎓) ⏮️ `**user_dict`, 🐍 🔜 "🎁" ⚫️. ⚫️ 🔜 🚶♀️ 🔑 & 💲 `user_dict` 🔗 🔑-💲 ❌.
|
|
||||||
|
|
||||||
, ▶️ ⏮️ `user_dict` ⚪️➡️ 🔛, ✍:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(**user_dict)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 🏁 🕳 🌓:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(
|
|
||||||
username="john",
|
|
||||||
password="secret",
|
|
||||||
email="john.doe@example.com",
|
|
||||||
full_name=None,
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️ 🌅 ⚫️❔, ⚙️ `user_dict` 🔗, ⏮️ ⚫️❔ 🎚 ⚫️ 💪 ✔️ 🔮:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(
|
|
||||||
username = user_dict["username"],
|
|
||||||
password = user_dict["password"],
|
|
||||||
email = user_dict["email"],
|
|
||||||
full_name = user_dict["full_name"],
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Pydantic 🏷 ⚪️➡️ 🎚 ➕1️⃣
|
|
||||||
|
|
||||||
🖼 🔛 👥 🤚 `user_dict` ⚪️➡️ `user_in.dict()`, 👉 📟:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
user_dict = user_in.dict()
|
|
||||||
UserInDB(**user_dict)
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 🌓:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(**user_in.dict())
|
|
||||||
```
|
|
||||||
|
|
||||||
...↩️ `user_in.dict()` `dict`, & ⤴️ 👥 ⚒ 🐍 "🎁" ⚫️ 🚶♀️ ⚫️ `UserInDB` 🔠 ⏮️ `**`.
|
|
||||||
|
|
||||||
, 👥 🤚 Pydantic 🏷 ⚪️➡️ 💽 ➕1️⃣ Pydantic 🏷.
|
|
||||||
|
|
||||||
#### 🎁 `dict` & ➕ 🇨🇻
|
|
||||||
|
|
||||||
& ⤴️ ❎ ➕ 🇨🇻 ❌ `hashed_password=hashed_password`, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(**user_in.dict(), hashed_password=hashed_password)
|
|
||||||
```
|
|
||||||
|
|
||||||
...🔚 🆙 💆♂ 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
UserInDB(
|
|
||||||
username = user_dict["username"],
|
|
||||||
password = user_dict["password"],
|
|
||||||
email = user_dict["email"],
|
|
||||||
full_name = user_dict["full_name"],
|
|
||||||
hashed_password = hashed_password,
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
🔗 🌖 🔢 🤖 💪 💧 💽, ✋️ 👫 ↗️ 🚫 🚚 🙆 🎰 💂♂.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📉 ❎
|
|
||||||
|
|
||||||
📉 📟 ❎ 1️⃣ 🐚 💭 **FastAPI**.
|
|
||||||
|
|
||||||
📟 ❎ 📈 🤞 🐛, 💂♂ ❔, 📟 🔁 ❔ (🕐❔ 👆 ℹ 1️⃣ 🥉 ✋️ 🚫 🎏), ♒️.
|
|
||||||
|
|
||||||
& 👉 🏷 🌐 🤝 📚 💽 & ❎ 🔢 📛 & 🆎.
|
|
||||||
|
|
||||||
👥 💪 👻.
|
|
||||||
|
|
||||||
👥 💪 📣 `UserBase` 🏷 👈 🍦 🧢 👆 🎏 🏷. & ⤴️ 👥 💪 ⚒ 🏿 👈 🏷 👈 😖 🚮 🔢 (🆎 📄, 🔬, ♒️).
|
|
||||||
|
|
||||||
🌐 💽 🛠️, 🔬, 🧾, ♒️. 🔜 👷 🛎.
|
|
||||||
|
|
||||||
👈 🌌, 👥 💪 📣 🔺 🖖 🏷 (⏮️ 🔢 `password`, ⏮️ `hashed_password` & 🍵 🔐):
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_models/tutorial002.py hl[9,15:16,19:20,23:24] *}
|
|
||||||
|
|
||||||
## `Union` ⚖️ `anyOf`
|
|
||||||
|
|
||||||
👆 💪 📣 📨 `Union` 2️⃣ 🆎, 👈 ⛓, 👈 📨 🔜 🙆 2️⃣.
|
|
||||||
|
|
||||||
⚫️ 🔜 🔬 🗄 ⏮️ `anyOf`.
|
|
||||||
|
|
||||||
👈, ⚙️ 🐩 🐍 🆎 🔑 <a href="https://docs.python.org/3/library/typing.html#typing.Union" class="external-link" target="_blank">`typing.Union`</a>:
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🕐❔ ⚖ <a href="https://docs.pydantic.dev/latest/concepts/types/#unions" class="external-link" target="_blank">`Union`</a>, 🔌 🏆 🎯 🆎 🥇, ⏩ 🌘 🎯 🆎. 🖼 🔛, 🌖 🎯 `PlaneItem` 👟 ⏭ `CarItem` `Union[PlaneItem, CarItem]`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_models/tutorial003.py hl[1,14:15,18:20,33] *}
|
|
||||||
|
|
||||||
### `Union` 🐍 3️⃣.1️⃣0️⃣
|
|
||||||
|
|
||||||
👉 🖼 👥 🚶♀️ `Union[PlaneItem, CarItem]` 💲 ❌ `response_model`.
|
|
||||||
|
|
||||||
↩️ 👥 🚶♀️ ⚫️ **💲 ❌** ↩️ 🚮 ⚫️ **🆎 ✍**, 👥 ✔️ ⚙️ `Union` 🐍 3️⃣.1️⃣0️⃣.
|
|
||||||
|
|
||||||
🚥 ⚫️ 🆎 ✍ 👥 💪 ✔️ ⚙️ ⏸ ⏸,:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
some_variable: PlaneItem | CarItem
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 🚥 👥 🚮 👈 `response_model=PlaneItem | CarItem` 👥 🔜 🤚 ❌, ↩️ 🐍 🔜 🔄 🎭 **❌ 🛠️** 🖖 `PlaneItem` & `CarItem` ↩️ 🔬 👈 🆎 ✍.
|
|
||||||
|
|
||||||
## 📇 🏷
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 📣 📨 📇 🎚.
|
|
||||||
|
|
||||||
👈, ⚙️ 🐩 🐍 `typing.List` (⚖️ `list` 🐍 3️⃣.9️⃣ & 🔛):
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_models/tutorial004.py hl[1,20] *}
|
|
||||||
|
|
||||||
## 📨 ⏮️ ❌ `dict`
|
|
||||||
|
|
||||||
👆 💪 📣 📨 ⚙️ ✅ ❌ `dict`, 📣 🆎 🔑 & 💲, 🍵 ⚙️ Pydantic 🏷.
|
|
||||||
|
|
||||||
👉 ⚠ 🚥 👆 🚫 💭 ☑ 🏑/🔢 📛 (👈 🔜 💪 Pydantic 🏷) ⏪.
|
|
||||||
|
|
||||||
👉 💼, 👆 💪 ⚙️ `typing.Dict` (⚖️ `dict` 🐍 3️⃣.9️⃣ & 🔛):
|
|
||||||
|
|
||||||
{* ../../docs_src/extra_models/tutorial005.py hl[1,8] *}
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ 💗 Pydantic 🏷 & 😖 ➡ 🔠 💼.
|
|
||||||
|
|
||||||
👆 🚫 💪 ✔️ 👁 💽 🏷 📍 👨💼 🚥 👈 👨💼 🔜 💪 ✔️ 🎏 "🇵🇸". 💼 ⏮️ 👩💻 "👨💼" ⏮️ 🇵🇸 ✅ `password`, `password_hash` & 🙅♂ 🔐.
|
|
||||||
|
|
@ -1,335 +0,0 @@
|
||||||
# 🥇 🔁
|
|
||||||
|
|
||||||
🙅 FastAPI 📁 💪 👀 💖 👉:
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py *}
|
|
||||||
|
|
||||||
📁 👈 📁 `main.py`.
|
|
||||||
|
|
||||||
🏃 🖖 💽:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
<span style="color: green;">INFO</span>: Started reloader process [28720]
|
|
||||||
<span style="color: green;">INFO</span>: Started server process [28722]
|
|
||||||
<span style="color: green;">INFO</span>: Waiting for application startup.
|
|
||||||
<span style="color: green;">INFO</span>: Application startup complete.
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
📋 `uvicorn main:app` 🔗:
|
|
||||||
|
|
||||||
* `main`: 📁 `main.py` (🐍 "🕹").
|
|
||||||
* `app`: 🎚 ✍ 🔘 `main.py` ⏮️ ⏸ `app = FastAPI()`.
|
|
||||||
* `--reload`: ⚒ 💽 ⏏ ⏮️ 📟 🔀. 🕴 ⚙️ 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🔢, 📤 ⏸ ⏮️ 🕳 💖:
|
|
||||||
|
|
||||||
```hl_lines="4"
|
|
||||||
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
👈 ⏸ 🎦 📛 🌐❔ 👆 📱 ➖ 🍦, 👆 🇧🇿 🎰.
|
|
||||||
|
|
||||||
### ✅ ⚫️
|
|
||||||
|
|
||||||
📂 👆 🖥 <a href="http://127.0.0.1:8000" class="external-link" target="_blank">http://127.0.0.1:8000</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🎻 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"message": "Hello World"}
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🎓 🛠️ 🩺
|
|
||||||
|
|
||||||
🔜 🚶 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🏧 🎓 🛠️ 🧾 (🚚 <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">🦁 🎚</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🎛 🛠️ 🩺
|
|
||||||
|
|
||||||
& 🔜, 🚶 <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>.
|
|
||||||
|
|
||||||
👆 🔜 👀 🎛 🏧 🧾 (🚚 <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">📄</a>):
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
### 🗄
|
|
||||||
|
|
||||||
**FastAPI** 🏗 "🔗" ⏮️ 🌐 👆 🛠️ ⚙️ **🗄** 🐩 ⚖ 🔗.
|
|
||||||
|
|
||||||
#### "🔗"
|
|
||||||
|
|
||||||
"🔗" 🔑 ⚖️ 📛 🕳. 🚫 📟 👈 🛠️ ⚫️, ✋️ 📝 📛.
|
|
||||||
|
|
||||||
#### 🛠️ "🔗"
|
|
||||||
|
|
||||||
👉 💼, <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank">🗄</a> 🔧 👈 🤔 ❔ 🔬 🔗 👆 🛠️.
|
|
||||||
|
|
||||||
👉 🔗 🔑 🔌 👆 🛠️ ➡, 💪 🔢 👫 ✊, ♒️.
|
|
||||||
|
|
||||||
#### 💽 "🔗"
|
|
||||||
|
|
||||||
⚖ "🔗" 💪 🔗 💠 💽, 💖 🎻 🎚.
|
|
||||||
|
|
||||||
👈 💼, ⚫️ 🔜 ⛓ 🎻 🔢, & 📊 🆎 👫 ✔️, ♒️.
|
|
||||||
|
|
||||||
#### 🗄 & 🎻 🔗
|
|
||||||
|
|
||||||
🗄 🔬 🛠️ 🔗 👆 🛠️. & 👈 🔗 🔌 🔑 (⚖️ "🔗") 📊 📨 & 📨 👆 🛠️ ⚙️ **🎻 🔗**, 🐩 🎻 📊 🔗.
|
|
||||||
|
|
||||||
#### ✅ `openapi.json`
|
|
||||||
|
|
||||||
🚥 👆 😟 🔃 ❔ 🍣 🗄 🔗 👀 💖, FastAPI 🔁 🏗 🎻 (🔗) ⏮️ 📛 🌐 👆 🛠️.
|
|
||||||
|
|
||||||
👆 💪 👀 ⚫️ 🔗: <a href="http://127.0.0.1:8000/openapi.json" class="external-link" target="_blank">http://127.0.0.1:8000/openapi.json</a>.
|
|
||||||
|
|
||||||
⚫️ 🔜 🎦 🎻 ▶️ ⏮️ 🕳 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"openapi": "3.0.2",
|
|
||||||
"info": {
|
|
||||||
"title": "FastAPI",
|
|
||||||
"version": "0.1.0"
|
|
||||||
},
|
|
||||||
"paths": {
|
|
||||||
"/items/": {
|
|
||||||
"get": {
|
|
||||||
"responses": {
|
|
||||||
"200": {
|
|
||||||
"description": "Successful Response",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
...
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ⚫️❔ 🗄
|
|
||||||
|
|
||||||
🗄 🔗 ⚫️❔ 🏋️ 2️⃣ 🎓 🧾 ⚙️ 🔌.
|
|
||||||
|
|
||||||
& 📤 💯 🎛, 🌐 ⚓️ 🔛 🗄. 👆 💪 💪 🚮 🙆 📚 🎛 👆 🈸 🏗 ⏮️ **FastAPI**.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ ⚫️ 🏗 📟 🔁, 👩💻 👈 🔗 ⏮️ 👆 🛠️. 🖼, 🕸, 📱 ⚖️ ☁ 🈸.
|
|
||||||
|
|
||||||
## 🌃, 🔁 🔁
|
|
||||||
|
|
||||||
### 🔁 1️⃣: 🗄 `FastAPI`
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py hl[1] *}
|
|
||||||
|
|
||||||
`FastAPI` 🐍 🎓 👈 🚚 🌐 🛠️ 👆 🛠️.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
`FastAPI` 🎓 👈 😖 🔗 ⚪️➡️ `Starlette`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🌐 <a href="https://www.starlette.dev/" class="external-link" target="_blank">💃</a> 🛠️ ⏮️ `FastAPI` 💁♂️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔁 2️⃣: ✍ `FastAPI` "👐"
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py hl[3] *}
|
|
||||||
|
|
||||||
📥 `app` 🔢 🔜 "👐" 🎓 `FastAPI`.
|
|
||||||
|
|
||||||
👉 🔜 👑 ☝ 🔗 ✍ 🌐 👆 🛠️.
|
|
||||||
|
|
||||||
👉 `app` 🎏 1️⃣ 🔗 `uvicorn` 📋:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
🚥 👆 ✍ 👆 📱 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial002.py hl[3] *}
|
|
||||||
|
|
||||||
& 🚮 ⚫️ 📁 `main.py`, ⤴️ 👆 🔜 🤙 `uvicorn` 💖:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:my_awesome_api --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
### 🔁 3️⃣: ✍ *➡ 🛠️*
|
|
||||||
|
|
||||||
#### ➡
|
|
||||||
|
|
||||||
"➡" 📥 🔗 🏁 🍕 📛 ▶️ ⚪️➡️ 🥇 `/`.
|
|
||||||
|
|
||||||
, 📛 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
https://example.com/items/foo
|
|
||||||
```
|
|
||||||
|
|
||||||
...➡ 🔜:
|
|
||||||
|
|
||||||
```
|
|
||||||
/items/foo
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
"➡" 🛎 🤙 "🔗" ⚖️ "🛣".
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⏪ 🏗 🛠️, "➡" 👑 🌌 🎏 "⚠" & "ℹ".
|
|
||||||
|
|
||||||
#### 🛠️
|
|
||||||
|
|
||||||
"🛠️" 📥 🔗 1️⃣ 🇺🇸🔍 "👩🔬".
|
|
||||||
|
|
||||||
1️⃣:
|
|
||||||
|
|
||||||
* `POST`
|
|
||||||
* `GET`
|
|
||||||
* `PUT`
|
|
||||||
* `DELETE`
|
|
||||||
|
|
||||||
...& 🌅 😍 🕐:
|
|
||||||
|
|
||||||
* `OPTIONS`
|
|
||||||
* `HEAD`
|
|
||||||
* `PATCH`
|
|
||||||
* `TRACE`
|
|
||||||
|
|
||||||
🇺🇸🔍 🛠️, 👆 💪 🔗 🔠 ➡ ⚙️ 1️⃣ (⚖️ 🌅) 👫 "👩🔬".
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
🕐❔ 🏗 🔗, 👆 🛎 ⚙️ 👫 🎯 🇺🇸🔍 👩🔬 🎭 🎯 🎯.
|
|
||||||
|
|
||||||
🛎 👆 ⚙️:
|
|
||||||
|
|
||||||
* `POST`: ✍ 💽.
|
|
||||||
* `GET`: ✍ 💽.
|
|
||||||
* `PUT`: ℹ 💽.
|
|
||||||
* `DELETE`: ❎ 💽.
|
|
||||||
|
|
||||||
, 🗄, 🔠 🇺🇸🔍 👩🔬 🤙 "🛠️".
|
|
||||||
|
|
||||||
👥 🔜 🤙 👫 "**🛠️**" 💁♂️.
|
|
||||||
|
|
||||||
#### 🔬 *➡ 🛠️ 👨🎨*
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py hl[6] *}
|
|
||||||
|
|
||||||
`@app.get("/")` 💬 **FastAPI** 👈 🔢 ▶️️ 🔛 🈚 🚚 📨 👈 🚶:
|
|
||||||
|
|
||||||
* ➡ `/`
|
|
||||||
* ⚙️ <abbr title="an HTTP GET method"><code>get</code> 🛠️</abbr>
|
|
||||||
|
|
||||||
/// info | `@decorator` ℹ
|
|
||||||
|
|
||||||
👈 `@something` ❕ 🐍 🤙 "👨🎨".
|
|
||||||
|
|
||||||
👆 🚮 ⚫️ 🔛 🔝 🔢. 💖 📶 📔 👒 (👤 💭 👈 🌐❔ ⚖ 👟 ⚪️➡️).
|
|
||||||
|
|
||||||
"👨🎨" ✊ 🔢 🔛 & 🔨 🕳 ⏮️ ⚫️.
|
|
||||||
|
|
||||||
👆 💼, 👉 👨🎨 💬 **FastAPI** 👈 🔢 🔛 🔗 **➡** `/` ⏮️ **🛠️** `get`.
|
|
||||||
|
|
||||||
⚫️ "**➡ 🛠️ 👨🎨**".
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 🛠️:
|
|
||||||
|
|
||||||
* `@app.post()`
|
|
||||||
* `@app.put()`
|
|
||||||
* `@app.delete()`
|
|
||||||
|
|
||||||
& 🌅 😍 🕐:
|
|
||||||
|
|
||||||
* `@app.options()`
|
|
||||||
* `@app.head()`
|
|
||||||
* `@app.patch()`
|
|
||||||
* `@app.trace()`
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 🆓 ⚙️ 🔠 🛠️ (🇺🇸🔍 👩🔬) 👆 🎋.
|
|
||||||
|
|
||||||
**FastAPI** 🚫 🛠️ 🙆 🎯 🔑.
|
|
||||||
|
|
||||||
ℹ 📥 🎁 📄, 🚫 📄.
|
|
||||||
|
|
||||||
🖼, 🕐❔ ⚙️ 🕹 👆 🛎 🎭 🌐 🎯 ⚙️ 🕴 `POST` 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔁 4️⃣: 🔬 **➡ 🛠️ 🔢**
|
|
||||||
|
|
||||||
👉 👆 "**➡ 🛠️ 🔢**":
|
|
||||||
|
|
||||||
* **➡**: `/`.
|
|
||||||
* **🛠️**: `get`.
|
|
||||||
* **🔢**: 🔢 🔛 "👨🎨" (🔛 `@app.get("/")`).
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py hl[7] *}
|
|
||||||
|
|
||||||
👉 🐍 🔢.
|
|
||||||
|
|
||||||
⚫️ 🔜 🤙 **FastAPI** 🕐❔ ⚫️ 📨 📨 📛 "`/`" ⚙️ `GET` 🛠️.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ `async` 🔢.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
👆 💪 🔬 ⚫️ 😐 🔢 ↩️ `async def`:
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial003.py hl[7] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
🚥 👆 🚫 💭 🔺, ✅ [🔁: *"🏃 ❓"*](../async.md#_2){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 🔁 5️⃣: 📨 🎚
|
|
||||||
|
|
||||||
{* ../../docs_src/first_steps/tutorial001.py hl[8] *}
|
|
||||||
|
|
||||||
👆 💪 📨 `dict`, `list`, ⭐ 💲 `str`, `int`, ♒️.
|
|
||||||
|
|
||||||
👆 💪 📨 Pydantic 🏷 (👆 🔜 👀 🌅 🔃 👈 ⏪).
|
|
||||||
|
|
||||||
📤 📚 🎏 🎚 & 🏷 👈 🔜 🔁 🗜 🎻 (🔌 🐜, ♒️). 🔄 ⚙️ 👆 💕 🕐, ⚫️ 🏆 🎲 👈 👫 ⏪ 🐕🦺.
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
* 🗄 `FastAPI`.
|
|
||||||
* ✍ `app` 👐.
|
|
||||||
* ✍ **➡ 🛠️ 👨🎨** (💖 `@app.get("/")`).
|
|
||||||
* ✍ **➡ 🛠️ 🔢** (💖 `def root(): ...` 🔛).
|
|
||||||
* 🏃 🛠️ 💽 (💖 `uvicorn main:app --reload`).
|
|
||||||
|
|
@ -1,257 +0,0 @@
|
||||||
# 🚚 ❌
|
|
||||||
|
|
||||||
📤 📚 ⚠ 🌐❔ 👆 💪 🚨 ❌ 👩💻 👈 ⚙️ 👆 🛠️.
|
|
||||||
|
|
||||||
👉 👩💻 💪 🖥 ⏮️ 🕸, 📟 ⚪️➡️ 👱 🙆, ☁ 📳, ♒️.
|
|
||||||
|
|
||||||
👆 💪 💪 💬 👩💻 👈:
|
|
||||||
|
|
||||||
* 👩💻 🚫 ✔️ 🥃 😌 👈 🛠️.
|
|
||||||
* 👩💻 🚫 ✔️ 🔐 👈 ℹ.
|
|
||||||
* 🏬 👩💻 🔄 🔐 🚫 🔀.
|
|
||||||
* ♒️.
|
|
||||||
|
|
||||||
👫 💼, 👆 🔜 🛎 📨 **🇺🇸🔍 👔 📟** ↔ **4️⃣0️⃣0️⃣** (⚪️➡️ 4️⃣0️⃣0️⃣ 4️⃣9️⃣9️⃣).
|
|
||||||
|
|
||||||
👉 🎏 2️⃣0️⃣0️⃣ 🇺🇸🔍 👔 📟 (⚪️➡️ 2️⃣0️⃣0️⃣ 2️⃣9️⃣9️⃣). 👈 "2️⃣0️⃣0️⃣" 👔 📟 ⛓ 👈 😫 📤 "🏆" 📨.
|
|
||||||
|
|
||||||
👔 📟 4️⃣0️⃣0️⃣ ↔ ⛓ 👈 📤 ❌ ⚪️➡️ 👩💻.
|
|
||||||
|
|
||||||
💭 🌐 👈 **"4️⃣0️⃣4️⃣ 🚫 🔎"** ❌ (& 🤣) ❓
|
|
||||||
|
|
||||||
## ⚙️ `HTTPException`
|
|
||||||
|
|
||||||
📨 🇺🇸🔍 📨 ⏮️ ❌ 👩💻 👆 ⚙️ `HTTPException`.
|
|
||||||
|
|
||||||
### 🗄 `HTTPException`
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial001.py hl[1] *}
|
|
||||||
|
|
||||||
### 🤚 `HTTPException` 👆 📟
|
|
||||||
|
|
||||||
`HTTPException` 😐 🐍 ⚠ ⏮️ 🌖 📊 🔗 🔗.
|
|
||||||
|
|
||||||
↩️ ⚫️ 🐍 ⚠, 👆 🚫 `return` ⚫️, 👆 `raise` ⚫️.
|
|
||||||
|
|
||||||
👉 ⛓ 👈 🚥 👆 🔘 🚙 🔢 👈 👆 🤙 🔘 👆 *➡ 🛠️ 🔢*, & 👆 🤚 `HTTPException` ⚪️➡️ 🔘 👈 🚙 🔢, ⚫️ 🏆 🚫 🏃 🎂 📟 *➡ 🛠️ 🔢*, ⚫️ 🔜 ❎ 👈 📨 ▶️️ ↖️ & 📨 🇺🇸🔍 ❌ ⚪️➡️ `HTTPException` 👩💻.
|
|
||||||
|
|
||||||
💰 🙋♀ ⚠ 🤭 `return`😅 💲 🔜 🌖 ⭐ 📄 🔃 🔗 & 💂♂.
|
|
||||||
|
|
||||||
👉 🖼, 🕐❔ 👩💻 📨 🏬 🆔 👈 🚫 🔀, 🤚 ⚠ ⏮️ 👔 📟 `404`:
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial001.py hl[11] *}
|
|
||||||
|
|
||||||
### 📉 📨
|
|
||||||
|
|
||||||
🚥 👩💻 📨 `http://example.com/items/foo` ( `item_id` `"foo"`), 👈 👩💻 🔜 📨 🇺🇸🔍 👔 📟 2️⃣0️⃣0️⃣, & 🎻 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"item": "The Foo Wrestlers"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 🚥 👩💻 📨 `http://example.com/items/bar` (🚫-🚫 `item_id` `"bar"`), 👈 👩💻 🔜 📨 🇺🇸🔍 👔 📟 4️⃣0️⃣4️⃣ ("🚫 🔎" ❌), & 🎻 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"detail": "Item not found"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🕐❔ 🙋♀ `HTTPException`, 👆 💪 🚶♀️ 🙆 💲 👈 💪 🗜 🎻 🔢 `detail`, 🚫 🕴 `str`.
|
|
||||||
|
|
||||||
👆 💪 🚶♀️ `dict`, `list`, ♒️.
|
|
||||||
|
|
||||||
👫 🍵 🔁 **FastAPI** & 🗜 🎻.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🚮 🛃 🎚
|
|
||||||
|
|
||||||
📤 ⚠ 🌐❔ ⚫️ ⚠ 💪 🚮 🛃 🎚 🇺🇸🔍 ❌. 🖼, 🆎 💂♂.
|
|
||||||
|
|
||||||
👆 🎲 🏆 🚫 💪 ⚙️ ⚫️ 🔗 👆 📟.
|
|
||||||
|
|
||||||
✋️ 💼 👆 💪 ⚫️ 🏧 😐, 👆 💪 🚮 🛃 🎚:
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial002.py hl[14] *}
|
|
||||||
|
|
||||||
## ❎ 🛃 ⚠ 🐕🦺
|
|
||||||
|
|
||||||
👆 💪 🚮 🛃 ⚠ 🐕🦺 ⏮️ <a href="https://www.starlette.dev/exceptions/" class="external-link" target="_blank">🎏 ⚠ 🚙 ⚪️➡️ 💃</a>.
|
|
||||||
|
|
||||||
➡️ 💬 👆 ✔️ 🛃 ⚠ `UnicornException` 👈 👆 (⚖️ 🗃 👆 ⚙️) 💪 `raise`.
|
|
||||||
|
|
||||||
& 👆 💚 🍵 👉 ⚠ 🌐 ⏮️ FastAPI.
|
|
||||||
|
|
||||||
👆 💪 🚮 🛃 ⚠ 🐕🦺 ⏮️ `@app.exception_handler()`:
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial003.py hl[5:7,13:18,24] *}
|
|
||||||
|
|
||||||
📥, 🚥 👆 📨 `/unicorns/yolo`, *➡ 🛠️* 🔜 `raise` `UnicornException`.
|
|
||||||
|
|
||||||
✋️ ⚫️ 🔜 🍵 `unicorn_exception_handler`.
|
|
||||||
|
|
||||||
, 👆 🔜 📨 🧹 ❌, ⏮️ 🇺🇸🔍 👔 📟 `418` & 🎻 🎚:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"message": "Oops! yolo did something. There goes a rainbow..."}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.requests import Request` & `from starlette.responses import JSONResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃. 🎏 ⏮️ `Request`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔐 🔢 ⚠ 🐕🦺
|
|
||||||
|
|
||||||
**FastAPI** ✔️ 🔢 ⚠ 🐕🦺.
|
|
||||||
|
|
||||||
👫 🐕🦺 🈚 🛬 🔢 🎻 📨 🕐❔ 👆 `raise` `HTTPException` & 🕐❔ 📨 ✔️ ❌ 💽.
|
|
||||||
|
|
||||||
👆 💪 🔐 👫 ⚠ 🐕🦺 ⏮️ 👆 👍.
|
|
||||||
|
|
||||||
### 🔐 📨 🔬 ⚠
|
|
||||||
|
|
||||||
🕐❔ 📨 🔌 ❌ 📊, **FastAPI** 🔘 🤚 `RequestValidationError`.
|
|
||||||
|
|
||||||
& ⚫️ 🔌 🔢 ⚠ 🐕🦺 ⚫️.
|
|
||||||
|
|
||||||
🔐 ⚫️, 🗄 `RequestValidationError` & ⚙️ ⚫️ ⏮️ `@app.exception_handler(RequestValidationError)` 🎀 ⚠ 🐕🦺.
|
|
||||||
|
|
||||||
⚠ 🐕🦺 🔜 📨 `Request` & ⚠.
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial004.py hl[2,14:16] *}
|
|
||||||
|
|
||||||
🔜, 🚥 👆 🚶 `/items/foo`, ↩️ 💆♂ 🔢 🎻 ❌ ⏮️:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": [
|
|
||||||
"path",
|
|
||||||
"item_id"
|
|
||||||
],
|
|
||||||
"msg": "value is not a valid integer",
|
|
||||||
"type": "type_error.integer"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 🔜 🤚 ✍ ⏬, ⏮️:
|
|
||||||
|
|
||||||
```
|
|
||||||
1 validation error
|
|
||||||
path -> item_id
|
|
||||||
value is not a valid integer (type=type_error.integer)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `RequestValidationError` 🆚 `ValidationError`
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👫 📡 ℹ 👈 👆 💪 🚶 🚥 ⚫️ 🚫 ⚠ 👆 🔜.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
`RequestValidationError` 🎧-🎓 Pydantic <a href="https://docs.pydantic.dev/latest/concepts/models/#error-handling" class="external-link" target="_blank">`ValidationError`</a>.
|
|
||||||
|
|
||||||
**FastAPI** ⚙️ ⚫️ 👈, 🚥 👆 ⚙️ Pydantic 🏷 `response_model`, & 👆 💽 ✔️ ❌, 👆 🔜 👀 ❌ 👆 🕹.
|
|
||||||
|
|
||||||
✋️ 👩💻/👩💻 🔜 🚫 👀 ⚫️. ↩️, 👩💻 🔜 📨 "🔗 💽 ❌" ⏮️ 🇺🇸🔍 👔 📟 `500`.
|
|
||||||
|
|
||||||
⚫️ 🔜 👉 🌌 ↩️ 🚥 👆 ✔️ Pydantic `ValidationError` 👆 *📨* ⚖️ 🙆 👆 📟 (🚫 👩💻 *📨*), ⚫️ 🤙 🐛 👆 📟.
|
|
||||||
|
|
||||||
& ⏪ 👆 🔧 ⚫️, 👆 👩💻/👩💻 🚫🔜 🚫 ✔️ 🔐 🔗 ℹ 🔃 ❌, 👈 💪 🎦 💂♂ ⚠.
|
|
||||||
|
|
||||||
### 🔐 `HTTPException` ❌ 🐕🦺
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 🔐 `HTTPException` 🐕🦺.
|
|
||||||
|
|
||||||
🖼, 👆 💪 💚 📨 ✅ ✍ 📨 ↩️ 🎻 👫 ❌:
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial004.py hl[3:4,9:11,22] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import PlainTextResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ⚙️ `RequestValidationError` 💪
|
|
||||||
|
|
||||||
`RequestValidationError` 🔌 `body` ⚫️ 📨 ⏮️ ❌ 💽.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ ⚫️ ⏪ 🛠️ 👆 📱 🕹 💪 & ℹ ⚫️, 📨 ⚫️ 👩💻, ♒️.
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial005.py hl[14] *}
|
|
||||||
|
|
||||||
🔜 🔄 📨 ❌ 🏬 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"title": "towel",
|
|
||||||
"size": "XL"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 🔜 📨 📨 💬 👆 👈 💽 ❌ ⚗ 📨 💪:
|
|
||||||
|
|
||||||
```JSON hl_lines="12-15"
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": [
|
|
||||||
"body",
|
|
||||||
"size"
|
|
||||||
],
|
|
||||||
"msg": "value is not a valid integer",
|
|
||||||
"type": "type_error.integer"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"body": {
|
|
||||||
"title": "towel",
|
|
||||||
"size": "XL"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### FastAPI `HTTPException` 🆚 💃 `HTTPException`
|
|
||||||
|
|
||||||
**FastAPI** ✔️ 🚮 👍 `HTTPException`.
|
|
||||||
|
|
||||||
& **FastAPI**'Ⓜ `HTTPException` ❌ 🎓 😖 ⚪️➡️ 💃 `HTTPException` ❌ 🎓.
|
|
||||||
|
|
||||||
🕴 🔺, 👈 **FastAPI**'Ⓜ `HTTPException` ✔ 👆 🚮 🎚 🔌 📨.
|
|
||||||
|
|
||||||
👉 💪/⚙️ 🔘 ✳ 2️⃣.0️⃣ & 💂♂ 🚙.
|
|
||||||
|
|
||||||
, 👆 💪 🚧 🙋♀ **FastAPI**'Ⓜ `HTTPException` 🛎 👆 📟.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 ® ⚠ 🐕🦺, 👆 🔜 ® ⚫️ 💃 `HTTPException`.
|
|
||||||
|
|
||||||
👉 🌌, 🚥 🙆 🍕 💃 🔗 📟, ⚖️ 💃 ↔ ⚖️ 🔌 -, 🤚 💃 `HTTPException`, 👆 🐕🦺 🔜 💪 ✊ & 🍵 ⚫️.
|
|
||||||
|
|
||||||
👉 🖼, 💪 ✔️ 👯♂️ `HTTPException`Ⓜ 🎏 📟, 💃 ⚠ 📁 `StarletteHTTPException`:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
||||||
```
|
|
||||||
|
|
||||||
### 🏤-⚙️ **FastAPI**'Ⓜ ⚠ 🐕🦺
|
|
||||||
|
|
||||||
🚥 👆 💚 ⚙️ ⚠ ⤴️ ⏮️ 🎏 🔢 ⚠ 🐕🦺 ⚪️➡️ **FastAPI**, 👆 💪 🗄 & 🏤-⚙️ 🔢 ⚠ 🐕🦺 ⚪️➡️ `fastapi.exception_handlers`:
|
|
||||||
|
|
||||||
{* ../../docs_src/handling_errors/tutorial006.py hl[2:5,15,21] *}
|
|
||||||
|
|
||||||
👉 🖼 👆 `print`😅 ❌ ⏮️ 📶 🎨 📧, ✋️ 👆 🤚 💭. 👆 💪 ⚙️ ⚠ & ⤴️ 🏤-⚙️ 🔢 ⚠ 🐕🦺.
|
|
||||||
|
|
@ -1,91 +0,0 @@
|
||||||
# 🎚 🔢
|
|
||||||
|
|
||||||
👆 💪 🔬 🎚 🔢 🎏 🌌 👆 🔬 `Query`, `Path` & `Cookie` 🔢.
|
|
||||||
|
|
||||||
## 🗄 `Header`
|
|
||||||
|
|
||||||
🥇 🗄 `Header`:
|
|
||||||
|
|
||||||
{* ../../docs_src/header_params/tutorial001.py hl[3] *}
|
|
||||||
|
|
||||||
## 📣 `Header` 🔢
|
|
||||||
|
|
||||||
⤴️ 📣 🎚 🔢 ⚙️ 🎏 📊 ⏮️ `Path`, `Query` & `Cookie`.
|
|
||||||
|
|
||||||
🥇 💲 🔢 💲, 👆 💪 🚶♀️ 🌐 ➕ 🔬 ⚖️ ✍ 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/header_params/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
`Header` "👭" 🎓 `Path`, `Query` & `Cookie`. ⚫️ 😖 ⚪️➡️ 🎏 ⚠ `Param` 🎓.
|
|
||||||
|
|
||||||
✋️ 💭 👈 🕐❔ 👆 🗄 `Query`, `Path`, `Header`, & 🎏 ⚪️➡️ `fastapi`, 👈 🤙 🔢 👈 📨 🎁 🎓.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📣 🎚, 👆 💪 ⚙️ `Header`, ↩️ ⏪ 🔢 🔜 🔬 🔢 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🏧 🛠️
|
|
||||||
|
|
||||||
`Header` ✔️ 🐥 ➕ 🛠️ 🔛 🔝 ⚫️❔ `Path`, `Query` & `Cookie` 🚚.
|
|
||||||
|
|
||||||
🌅 🐩 🎚 🎏 "🔠" 🦹, 💭 "➖ 🔣" (`-`).
|
|
||||||
|
|
||||||
✋️ 🔢 💖 `user-agent` ❌ 🐍.
|
|
||||||
|
|
||||||
, 🔢, `Header` 🔜 🗜 🔢 📛 🦹 ⚪️➡️ 🎦 (`_`) 🔠 (`-`) ⚗ & 📄 🎚.
|
|
||||||
|
|
||||||
, 🇺🇸🔍 🎚 💼-😛,, 👆 💪 📣 👫 ⏮️ 🐩 🐍 👗 (💭 "🔡").
|
|
||||||
|
|
||||||
, 👆 💪 ⚙️ `user_agent` 👆 🛎 🔜 🐍 📟, ↩️ 💆♂ 🎯 🥇 🔤 `User_Agent` ⚖️ 🕳 🎏.
|
|
||||||
|
|
||||||
🚥 🤔 👆 💪 ❎ 🏧 🛠️ 🎦 🔠, ⚒ 🔢 `convert_underscores` `Header` `False`:
|
|
||||||
|
|
||||||
{* ../../docs_src/header_params/tutorial002.py hl[10] *}
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
⏭ ⚒ `convert_underscores` `False`, 🐻 🤯 👈 🇺🇸🔍 🗳 & 💽 / ⚙️ 🎚 ⏮️ 🎦.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ❎ 🎚
|
|
||||||
|
|
||||||
⚫️ 💪 📨 ❎ 🎚. 👈 ⛓, 🎏 🎚 ⏮️ 💗 💲.
|
|
||||||
|
|
||||||
👆 💪 🔬 👈 💼 ⚙️ 📇 🆎 📄.
|
|
||||||
|
|
||||||
👆 🔜 📨 🌐 💲 ⚪️➡️ ❎ 🎚 🐍 `list`.
|
|
||||||
|
|
||||||
🖼, 📣 🎚 `X-Token` 👈 💪 😑 🌅 🌘 🕐, 👆 💪 ✍:
|
|
||||||
|
|
||||||
{* ../../docs_src/header_params/tutorial003.py hl[9] *}
|
|
||||||
|
|
||||||
🚥 👆 🔗 ⏮️ 👈 *➡ 🛠️* 📨 2️⃣ 🇺🇸🔍 🎚 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
X-Token: foo
|
|
||||||
X-Token: bar
|
|
||||||
```
|
|
||||||
|
|
||||||
📨 🔜 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"X-Token values": [
|
|
||||||
"bar",
|
|
||||||
"foo"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
📣 🎚 ⏮️ `Header`, ⚙️ 🎏 ⚠ ⚓ `Query`, `Path` & `Cookie`.
|
|
||||||
|
|
||||||
& 🚫 😟 🔃 🎦 👆 🔢, **FastAPI** 🔜 ✊ 💅 🏭 👫.
|
|
||||||
|
|
@ -1,83 +0,0 @@
|
||||||
# 🔰 - 👩💻 🦮
|
|
||||||
|
|
||||||
👉 🔰 🎦 👆 ❔ ⚙️ **FastAPI** ⏮️ 🌅 🚮 ⚒, 🔁 🔁.
|
|
||||||
|
|
||||||
🔠 📄 📉 🏗 🔛 ⏮️ 🕐, ✋️ ⚫️ 🏗 🎏 ❔, 👈 👆 💪 🚶 🔗 🙆 🎯 1️⃣ ❎ 👆 🎯 🛠️ 💪.
|
|
||||||
|
|
||||||
⚫️ 🏗 👷 🔮 🔗.
|
|
||||||
|
|
||||||
👆 💪 👟 🔙 & 👀 ⚫️❔ ⚫️❔ 👆 💪.
|
|
||||||
|
|
||||||
## 🏃 📟
|
|
||||||
|
|
||||||
🌐 📟 🍫 💪 📁 & ⚙️ 🔗 (👫 🤙 💯 🐍 📁).
|
|
||||||
|
|
||||||
🏃 🙆 🖼, 📁 📟 📁 `main.py`, & ▶️ `uvicorn` ⏮️:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ uvicorn main:app --reload
|
|
||||||
|
|
||||||
<span style="color: green;">INFO</span>: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
|
|
||||||
<span style="color: green;">INFO</span>: Started reloader process [28720]
|
|
||||||
<span style="color: green;">INFO</span>: Started server process [28722]
|
|
||||||
<span style="color: green;">INFO</span>: Waiting for application startup.
|
|
||||||
<span style="color: green;">INFO</span>: Application startup complete.
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
⚫️ **🏆 💡** 👈 👆 ✍ ⚖️ 📁 📟, ✍ ⚫️ & 🏃 ⚫️ 🌐.
|
|
||||||
|
|
||||||
⚙️ ⚫️ 👆 👨🎨 ⚫️❔ 🤙 🎦 👆 💰 FastAPI, 👀 ❔ 🐥 📟 👆 ✔️ ✍, 🌐 🆎 ✅, ✍, ♒️.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## ❎ FastAPI
|
|
||||||
|
|
||||||
🥇 🔁 ❎ FastAPI.
|
|
||||||
|
|
||||||
🔰, 👆 💪 💚 ❎ ⚫️ ⏮️ 🌐 📦 🔗 & ⚒:
|
|
||||||
|
|
||||||
<div class="termy">
|
|
||||||
|
|
||||||
```console
|
|
||||||
$ pip install "fastapi[all]"
|
|
||||||
|
|
||||||
---> 100%
|
|
||||||
```
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
...👈 🔌 `uvicorn`, 👈 👆 💪 ⚙️ 💽 👈 🏃 👆 📟.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👆 💪 ❎ ⚫️ 🍕 🍕.
|
|
||||||
|
|
||||||
👉 ⚫️❔ 👆 🔜 🎲 🕐 👆 💚 🛠️ 👆 🈸 🏭:
|
|
||||||
|
|
||||||
```
|
|
||||||
pip install "fastapi[standard]"
|
|
||||||
```
|
|
||||||
|
|
||||||
❎ `uvicorn` 👷 💽:
|
|
||||||
|
|
||||||
```
|
|
||||||
pip install "uvicorn[standard]"
|
|
||||||
```
|
|
||||||
|
|
||||||
& 🎏 🔠 📦 🔗 👈 👆 💚 ⚙️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🏧 👩💻 🦮
|
|
||||||
|
|
||||||
📤 **🏧 👩💻 🦮** 👈 👆 💪 ✍ ⏪ ⏮️ 👉 **🔰 - 👩💻 🦮**.
|
|
||||||
|
|
||||||
**🏧 👩💻 🦮**, 🏗 🔛 👉, ⚙️ 🎏 🔧, & 💡 👆 ➕ ⚒.
|
|
||||||
|
|
||||||
✋️ 👆 🔜 🥇 ✍ **🔰 - 👩💻 🦮** (⚫️❔ 👆 👂 ▶️️ 🔜).
|
|
||||||
|
|
||||||
⚫️ 🔧 👈 👆 💪 🏗 🏁 🈸 ⏮️ **🔰 - 👩💻 🦮**, & ⤴️ ↔ ⚫️ 🎏 🌌, ⚓️ 🔛 👆 💪, ⚙️ 🌖 💭 ⚪️➡️ **🏧 👩💻 🦮**.
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
# 🗃 & 🩺 📛
|
|
||||||
|
|
||||||
👆 💪 🛃 📚 🗃 📳 👆 **FastAPI** 🈸.
|
|
||||||
|
|
||||||
## 🗃 🛠️
|
|
||||||
|
|
||||||
👆 💪 ⚒ 📄 🏑 👈 ⚙️ 🗄 🔧 & 🏧 🛠️ 🩺 ⚜:
|
|
||||||
|
|
||||||
| 🔢 | 🆎 | 📛 |
|
|
||||||
|------------|------|-------------|
|
|
||||||
| `title` | `str` | 📛 🛠️. |
|
|
||||||
| `description` | `str` | 📏 📛 🛠️. ⚫️ 💪 ⚙️ ✍. |
|
|
||||||
| `version` | `string` | ⏬ 🛠️. 👉 ⏬ 👆 👍 🈸, 🚫 🗄. 🖼 `2.5.0`. |
|
|
||||||
| `terms_of_service` | `str` | 📛 ⚖ 🐕🦺 🛠️. 🚥 🚚, 👉 ✔️ 📛. |
|
|
||||||
| `contact` | `dict` | 📧 ℹ 🎦 🛠️. ⚫️ 💪 🔌 📚 🏑. <details><summary><code>contact</code> 🏑</summary><table><thead><tr><th>🔢</th><th>🆎</th><th>📛</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>str</code></td><td>⚖ 📛 📧 👨💼/🏢.</td></tr><tr><td><code>url</code></td><td><code>str</code></td><td>📛 ☝ 📧 ℹ. 🔜 📁 📛.</td></tr><tr><td><code>email</code></td><td><code>str</code></td><td>📧 📢 📧 👨💼/🏢. 🔜 📁 📧 📢. </td></tr></tbody></table></details> |
|
|
||||||
| `license_info` | `dict` | 🛂 ℹ 🎦 🛠️. ⚫️ 💪 🔌 📚 🏑. <details><summary><code>license_info</code> 🏑</summary><table><thead><tr><th>🔢</th><th>🆎</th><th>📛</th></tr></thead><tbody><tr><td><code>name</code></td><td><code>str</code></td><td><strong>🚚</strong> (🚥 <code>license_info</code> ⚒). 🛂 📛 ⚙️ 🛠️.</td></tr><tr><td><code>url</code></td><td><code>str</code></td><td>📛 🛂 ⚙️ 🛠️. 🔜 📁 📛. </td></tr></tbody></table></details> |
|
|
||||||
|
|
||||||
👆 💪 ⚒ 👫 ⏩:
|
|
||||||
|
|
||||||
{* ../../docs_src/metadata/tutorial001.py hl[3:16,19:31] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 ✍ ✍ `description` 🏑 & ⚫️ 🔜 ✍ 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⏮️ 👉 📳, 🏧 🛠️ 🩺 🔜 👀 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/metadata/image01.png">
|
|
||||||
|
|
||||||
## 🗃 🔖
|
|
||||||
|
|
||||||
👆 💪 🚮 🌖 🗃 🎏 🔖 ⚙️ 👪 👆 ➡ 🛠️ ⏮️ 🔢 `openapi_tags`.
|
|
||||||
|
|
||||||
⚫️ ✊ 📇 ⚗ 1️⃣ 📖 🔠 🔖.
|
|
||||||
|
|
||||||
🔠 📖 💪 🔌:
|
|
||||||
|
|
||||||
* `name` (**✔**): `str` ⏮️ 🎏 📛 👆 ⚙️ `tags` 🔢 👆 *➡ 🛠️* & `APIRouter`Ⓜ.
|
|
||||||
* `description`: `str` ⏮️ 📏 📛 🔖. ⚫️ 💪 ✔️ ✍ & 🔜 🎦 🩺 🎚.
|
|
||||||
* `externalDocs`: `dict` 🔬 🔢 🧾 ⏮️:
|
|
||||||
* `description`: `str` ⏮️ 📏 📛 🔢 🩺.
|
|
||||||
* `url` (**✔**): `str` ⏮️ 📛 🔢 🧾.
|
|
||||||
|
|
||||||
### ✍ 🗃 🔖
|
|
||||||
|
|
||||||
➡️ 🔄 👈 🖼 ⏮️ 🔖 `users` & `items`.
|
|
||||||
|
|
||||||
✍ 🗃 👆 🔖 & 🚶♀️ ⚫️ `openapi_tags` 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/metadata/tutorial004.py hl[3:16,18] *}
|
|
||||||
|
|
||||||
👀 👈 👆 💪 ⚙️ ✍ 🔘 📛, 🖼 "💳" 🔜 🎦 🦁 (**💳**) & "🎀" 🔜 🎦 ❕ (_🎀_).
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 🚫 ✔️ 🚮 🗃 🌐 🔖 👈 👆 ⚙️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ⚙️ 👆 🔖
|
|
||||||
|
|
||||||
⚙️ `tags` 🔢 ⏮️ 👆 *➡ 🛠️* (& `APIRouter`Ⓜ) 🛠️ 👫 🎏 🔖:
|
|
||||||
|
|
||||||
{* ../../docs_src/metadata/tutorial004.py hl[21,26] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
✍ 🌅 🔃 🔖 [➡ 🛠️ 📳](path-operation-configuration.md#_3){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ✅ 🩺
|
|
||||||
|
|
||||||
🔜, 🚥 👆 ✅ 🩺, 👫 🔜 🎦 🌐 🌖 🗃:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/metadata/image02.png">
|
|
||||||
|
|
||||||
### ✔ 🔖
|
|
||||||
|
|
||||||
✔ 🔠 🔖 🗃 📖 🔬 ✔ 🎦 🩺 🎚.
|
|
||||||
|
|
||||||
🖼, ✋️ `users` 🔜 🚶 ⏮️ `items` 🔤 ✔, ⚫️ 🎦 ⏭ 👫, ↩️ 👥 🚮 👫 🗃 🥇 📖 📇.
|
|
||||||
|
|
||||||
## 🗄 📛
|
|
||||||
|
|
||||||
🔢, 🗄 🔗 🍦 `/openapi.json`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 🔗 ⚫️ ⏮️ 🔢 `openapi_url`.
|
|
||||||
|
|
||||||
🖼, ⚒ ⚫️ 🍦 `/api/v1/openapi.json`:
|
|
||||||
|
|
||||||
{* ../../docs_src/metadata/tutorial002.py hl[3] *}
|
|
||||||
|
|
||||||
🚥 👆 💚 ❎ 🗄 🔗 🍕 👆 💪 ⚒ `openapi_url=None`, 👈 🔜 ❎ 🧾 👩💻 🔢 👈 ⚙️ ⚫️.
|
|
||||||
|
|
||||||
## 🩺 📛
|
|
||||||
|
|
||||||
👆 💪 🔗 2️⃣ 🧾 👩💻 🔢 🔌:
|
|
||||||
|
|
||||||
* **🦁 🎚**: 🍦 `/docs`.
|
|
||||||
* 👆 💪 ⚒ 🚮 📛 ⏮️ 🔢 `docs_url`.
|
|
||||||
* 👆 💪 ❎ ⚫️ ⚒ `docs_url=None`.
|
|
||||||
* **📄**: 🍦 `/redoc`.
|
|
||||||
* 👆 💪 ⚒ 🚮 📛 ⏮️ 🔢 `redoc_url`.
|
|
||||||
* 👆 💪 ❎ ⚫️ ⚒ `redoc_url=None`.
|
|
||||||
|
|
||||||
🖼, ⚒ 🦁 🎚 🍦 `/documentation` & ❎ 📄:
|
|
||||||
|
|
||||||
{* ../../docs_src/metadata/tutorial003.py hl[3] *}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
# 🛠️
|
|
||||||
|
|
||||||
👆 💪 🚮 🛠️ **FastAPI** 🈸.
|
|
||||||
|
|
||||||
"🛠️" 🔢 👈 👷 ⏮️ 🔠 **📨** ⏭ ⚫️ 🛠️ 🙆 🎯 *➡ 🛠️*. & ⏮️ 🔠 **📨** ⏭ 🛬 ⚫️.
|
|
||||||
|
|
||||||
* ⚫️ ✊ 🔠 **📨** 👈 👟 👆 🈸.
|
|
||||||
* ⚫️ 💪 ⤴️ 🕳 👈 **📨** ⚖️ 🏃 🙆 💪 📟.
|
|
||||||
* ⤴️ ⚫️ 🚶♀️ **📨** 🛠️ 🎂 🈸 ( *➡ 🛠️*).
|
|
||||||
* ⚫️ ⤴️ ✊ **📨** 🏗 🈸 ( *➡ 🛠️*).
|
|
||||||
* ⚫️ 💪 🕳 👈 **📨** ⚖️ 🏃 🙆 💪 📟.
|
|
||||||
* ⤴️ ⚫️ 📨 **📨**.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🔗 ⏮️ `yield`, 🚪 📟 🔜 🏃 *⏮️* 🛠️.
|
|
||||||
|
|
||||||
🚥 📤 🙆 🖥 📋 (📄 ⏪), 👫 🔜 🏃 *⏮️* 🌐 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✍ 🛠️
|
|
||||||
|
|
||||||
✍ 🛠️ 👆 ⚙️ 👨🎨 `@app.middleware("http")` 🔛 🔝 🔢.
|
|
||||||
|
|
||||||
🛠️ 🔢 📨:
|
|
||||||
|
|
||||||
* `request`.
|
|
||||||
* 🔢 `call_next` 👈 🔜 📨 `request` 🔢.
|
|
||||||
* 👉 🔢 🔜 🚶♀️ `request` 🔗 *➡ 🛠️*.
|
|
||||||
* ⤴️ ⚫️ 📨 `response` 🏗 🔗 *➡ 🛠️*.
|
|
||||||
* 👆 💪 ⤴️ 🔀 🌅 `response` ⏭ 🛬 ⚫️.
|
|
||||||
|
|
||||||
{* ../../docs_src/middleware/tutorial001.py hl[8:9,11,14] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🛃 © 🎚 💪 🚮 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers" class="external-link" target="_blank">⚙️ '✖-' 🔡</a>.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 ✔️ 🛃 🎚 👈 👆 💚 👩💻 🖥 💪 👀, 👆 💪 🚮 👫 👆 ⚜ 📳 ([⚜ (✖️-🇨🇳 ℹ 🤝)](cors.md){.internal-link target=_blank}) ⚙️ 🔢 `expose_headers` 📄 <a href="https://www.starlette.dev/middleware/#corsmiddleware" class="external-link" target="_blank">💃 ⚜ 🩺</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.requests import Request`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 ⚫️ 🏪 👆, 👩💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### ⏭ & ⏮️ `response`
|
|
||||||
|
|
||||||
👆 💪 🚮 📟 🏃 ⏮️ `request`, ⏭ 🙆 *➡ 🛠️* 📨 ⚫️.
|
|
||||||
|
|
||||||
& ⏮️ `response` 🏗, ⏭ 🛬 ⚫️.
|
|
||||||
|
|
||||||
🖼, 👆 💪 🚮 🛃 🎚 `X-Process-Time` ⚗ 🕰 🥈 👈 ⚫️ ✊ 🛠️ 📨 & 🏗 📨:
|
|
||||||
|
|
||||||
{* ../../docs_src/middleware/tutorial001.py hl[10,12:13] *}
|
|
||||||
|
|
||||||
## 🎏 🛠️
|
|
||||||
|
|
||||||
👆 💪 ⏪ ✍ 🌖 🔃 🎏 🛠️ [🏧 👩💻 🦮: 🏧 🛠️](../advanced/middleware.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
👆 🔜 ✍ 🔃 ❔ 🍵 <abbr title="Cross-Origin Resource Sharing">⚜</abbr> ⏮️ 🛠️ ⏭ 📄.
|
|
||||||
|
|
@ -1,107 +0,0 @@
|
||||||
# ➡ 🛠️ 📳
|
|
||||||
|
|
||||||
📤 📚 🔢 👈 👆 💪 🚶♀️ 👆 *➡ 🛠️ 👨🎨* 🔗 ⚫️.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👀 👈 👫 🔢 🚶♀️ 🔗 *➡ 🛠️ 👨🎨*, 🚫 👆 *➡ 🛠️ 🔢*.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📨 👔 📟
|
|
||||||
|
|
||||||
👆 💪 🔬 (🇺🇸🔍) `status_code` ⚙️ 📨 👆 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👆 💪 🚶♀️ 🔗 `int` 📟, 💖 `404`.
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🚫 💭 ⚫️❔ 🔠 🔢 📟, 👆 💪 ⚙️ ⌨ 📉 `status`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial001.py hl[3,17] *}
|
|
||||||
|
|
||||||
👈 👔 📟 🔜 ⚙️ 📨 & 🔜 🚮 🗄 🔗.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette import status`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.status` `fastapi.status` 🏪 👆, 👩💻. ✋️ ⚫️ 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔖
|
|
||||||
|
|
||||||
👆 💪 🚮 🔖 👆 *➡ 🛠️*, 🚶♀️ 🔢 `tags` ⏮️ `list` `str` (🛎 1️⃣ `str`):
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial002.py hl[17,22,27] *}
|
|
||||||
|
|
||||||
👫 🔜 🚮 🗄 🔗 & ⚙️ 🏧 🧾 🔢:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-configuration/image01.png">
|
|
||||||
|
|
||||||
### 🔖 ⏮️ 🔢
|
|
||||||
|
|
||||||
🚥 👆 ✔️ 🦏 🈸, 👆 5️⃣📆 🔚 🆙 📈 **📚 🔖**, & 👆 🔜 💚 ⚒ 💭 👆 🕧 ⚙️ **🎏 🔖** 🔗 *➡ 🛠️*.
|
|
||||||
|
|
||||||
👫 💼, ⚫️ 💪 ⚒ 🔑 🏪 🔖 `Enum`.
|
|
||||||
|
|
||||||
**FastAPI** 🐕🦺 👈 🎏 🌌 ⏮️ ✅ 🎻:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial002b.py hl[1,8:10,13,18] *}
|
|
||||||
|
|
||||||
## 📄 & 📛
|
|
||||||
|
|
||||||
👆 💪 🚮 `summary` & `description`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial003.py hl[20:21] *}
|
|
||||||
|
|
||||||
## 📛 ⚪️➡️ #️⃣
|
|
||||||
|
|
||||||
📛 😑 📏 & 📔 💗 ⏸, 👆 💪 📣 *➡ 🛠️* 📛 🔢 <abbr title="a multi-line string as the first expression inside a function (not assigned to any variable) used for documentation"> #️⃣ </abbr> & **FastAPI** 🔜 ✍ ⚫️ ⚪️➡️ 📤.
|
|
||||||
|
|
||||||
👆 💪 ✍ <a href="https://en.wikipedia.org/wiki/Markdown" class="external-link" target="_blank">✍</a> #️⃣ , ⚫️ 🔜 🔬 & 🖥 ☑ (✊ 🔘 🏧 #️⃣ 📐).
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial004.py hl[19:27] *}
|
|
||||||
|
|
||||||
⚫️ 🔜 ⚙️ 🎓 🩺:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-configuration/image02.png">
|
|
||||||
|
|
||||||
## 📨 📛
|
|
||||||
|
|
||||||
👆 💪 ✔ 📨 📛 ⏮️ 🔢 `response_description`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial005.py hl[21] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👀 👈 `response_description` 🔗 🎯 📨, `description` 🔗 *➡ 🛠️* 🏢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
🗄 ✔ 👈 🔠 *➡ 🛠️* 🚚 📨 📛.
|
|
||||||
|
|
||||||
, 🚥 👆 🚫 🚚 1️⃣, **FastAPI** 🔜 🔁 🏗 1️⃣ "🏆 📨".
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-configuration/image03.png">
|
|
||||||
|
|
||||||
## 😢 *➡ 🛠️*
|
|
||||||
|
|
||||||
🚥 👆 💪 ™ *➡ 🛠️* <abbr title="obsolete, recommended not to use it">😢</abbr>, ✋️ 🍵 ❎ ⚫️, 🚶♀️ 🔢 `deprecated`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_operation_configuration/tutorial006.py hl[16] *}
|
|
||||||
|
|
||||||
⚫️ 🔜 🎯 ™ 😢 🎓 🩺:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-configuration/image04.png">
|
|
||||||
|
|
||||||
✅ ❔ 😢 & 🚫-😢 *➡ 🛠️* 👀 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-operation-configuration/image05.png">
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 🔗 & 🚮 🗃 👆 *➡ 🛠️* 💪 🚶♀️ 🔢 *➡ 🛠️ 👨🎨*.
|
|
||||||
|
|
@ -1,117 +0,0 @@
|
||||||
# ➡ 🔢 & 🔢 🔬
|
|
||||||
|
|
||||||
🎏 🌌 👈 👆 💪 📣 🌅 🔬 & 🗃 🔢 🔢 ⏮️ `Query`, 👆 💪 📣 🎏 🆎 🔬 & 🗃 ➡ 🔢 ⏮️ `Path`.
|
|
||||||
|
|
||||||
## 🗄 ➡
|
|
||||||
|
|
||||||
🥇, 🗄 `Path` ⚪️➡️ `fastapi`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial001.py hl[3] *}
|
|
||||||
|
|
||||||
## 📣 🗃
|
|
||||||
|
|
||||||
👆 💪 📣 🌐 🎏 🔢 `Query`.
|
|
||||||
|
|
||||||
🖼, 📣 `title` 🗃 💲 ➡ 🔢 `item_id` 👆 💪 🆎:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial001.py hl[10] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
➡ 🔢 🕧 ✔ ⚫️ ✔️ 🍕 ➡.
|
|
||||||
|
|
||||||
, 👆 🔜 📣 ⚫️ ⏮️ `...` ™ ⚫️ ✔.
|
|
||||||
|
|
||||||
👐, 🚥 👆 📣 ⚫️ ⏮️ `None` ⚖️ ⚒ 🔢 💲, ⚫️ 🔜 🚫 📉 🕳, ⚫️ 🔜 🕧 🚚.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ✔ 🔢 👆 💪
|
|
||||||
|
|
||||||
➡️ 💬 👈 👆 💚 📣 🔢 🔢 `q` ✔ `str`.
|
|
||||||
|
|
||||||
& 👆 🚫 💪 📣 🕳 🙆 👈 🔢, 👆 🚫 🤙 💪 ⚙️ `Query`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 ⚙️ `Path` `item_id` ➡ 🔢.
|
|
||||||
|
|
||||||
🐍 🔜 😭 🚥 👆 🚮 💲 ⏮️ "🔢" ⏭ 💲 👈 🚫 ✔️ "🔢".
|
|
||||||
|
|
||||||
✋️ 👆 💪 🏤-✔ 👫, & ✔️ 💲 🍵 🔢 (🔢 🔢 `q`) 🥇.
|
|
||||||
|
|
||||||
⚫️ 🚫 🤔 **FastAPI**. ⚫️ 🔜 🔍 🔢 👫 📛, 🆎 & 🔢 📄 (`Query`, `Path`, ♒️), ⚫️ 🚫 💅 🔃 ✔.
|
|
||||||
|
|
||||||
, 👆 💪 📣 👆 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial002.py hl[7] *}
|
|
||||||
|
|
||||||
## ✔ 🔢 👆 💪, 🎱
|
|
||||||
|
|
||||||
🚥 👆 💚 📣 `q` 🔢 🔢 🍵 `Query` 🚫 🙆 🔢 💲, & ➡ 🔢 `item_id` ⚙️ `Path`, & ✔️ 👫 🎏 ✔, 🐍 ✔️ 🐥 🎁 ❕ 👈.
|
|
||||||
|
|
||||||
🚶♀️ `*`, 🥇 🔢 🔢.
|
|
||||||
|
|
||||||
🐍 🏆 🚫 🕳 ⏮️ 👈 `*`, ✋️ ⚫️ 🔜 💭 👈 🌐 📄 🔢 🔜 🤙 🇨🇻 ❌ (🔑-💲 👫), 💭 <abbr title="From: K-ey W-ord Arg-uments"><code>kwargs</code></abbr>. 🚥 👫 🚫 ✔️ 🔢 💲.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial003.py hl[7] *}
|
|
||||||
|
|
||||||
## 🔢 🔬: 👑 🌘 ⚖️ 🌓
|
|
||||||
|
|
||||||
⏮️ `Query` & `Path` (& 🎏 👆 🔜 👀 ⏪) 👆 💪 📣 🔢 ⚛.
|
|
||||||
|
|
||||||
📥, ⏮️ `ge=1`, `item_id` 🔜 💪 🔢 🔢 "`g`🅾 🌘 ⚖️ `e`🅾" `1`.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial004.py hl[8] *}
|
|
||||||
|
|
||||||
## 🔢 🔬: 🌘 🌘 & 🌘 🌘 ⚖️ 🌓
|
|
||||||
|
|
||||||
🎏 ✔:
|
|
||||||
|
|
||||||
* `gt`: `g`🅾 `t`👲
|
|
||||||
* `le`: `l`👭 🌘 ⚖️ `e`🅾
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial005.py hl[9] *}
|
|
||||||
|
|
||||||
## 🔢 🔬: 🎈, 🌘 🌘 & 🌘 🌘
|
|
||||||
|
|
||||||
🔢 🔬 👷 `float` 💲.
|
|
||||||
|
|
||||||
📥 🌐❔ ⚫️ ▶️️ ⚠ 💪 📣 <abbr title="greater than"><code>gt</code></abbr> & 🚫 <abbr title="greater than or equal"><code>ge</code></abbr>. ⏮️ ⚫️ 👆 💪 🚚, 🖼, 👈 💲 🔜 👑 🌘 `0`, 🚥 ⚫️ 🌘 🌘 `1`.
|
|
||||||
|
|
||||||
, `0.5` 🔜 ☑ 💲. ✋️ `0.0` ⚖️ `0` 🔜 🚫.
|
|
||||||
|
|
||||||
& 🎏 <abbr title="less than"><code>lt</code></abbr>.
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params_numeric_validations/tutorial006.py hl[11] *}
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⏮️ `Query`, `Path` (& 🎏 👆 🚫 👀) 👆 💪 📣 🗃 & 🎻 🔬 🎏 🌌 ⏮️ [🔢 🔢 & 🎻 🔬](query-params-str-validations.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
& 👆 💪 📣 🔢 🔬:
|
|
||||||
|
|
||||||
* `gt`: `g`🅾 `t`👲
|
|
||||||
* `ge`: `g`🅾 🌘 ⚖️ `e`🅾
|
|
||||||
* `lt`: `l`👭 `t`👲
|
|
||||||
* `le`: `l`👭 🌘 ⚖️ `e`🅾
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`Query`, `Path`, & 🎏 🎓 👆 🔜 👀 ⏪ 🏿 ⚠ `Param` 🎓.
|
|
||||||
|
|
||||||
🌐 👫 💰 🎏 🔢 🌖 🔬 & 🗃 👆 ✔️ 👀.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
🕐❔ 👆 🗄 `Query`, `Path` & 🎏 ⚪️➡️ `fastapi`, 👫 🤙 🔢.
|
|
||||||
|
|
||||||
👈 🕐❔ 🤙, 📨 👐 🎓 🎏 📛.
|
|
||||||
|
|
||||||
, 👆 🗄 `Query`, ❔ 🔢. & 🕐❔ 👆 🤙 ⚫️, ⚫️ 📨 👐 🎓 🌟 `Query`.
|
|
||||||
|
|
||||||
👫 🔢 📤 (↩️ ⚙️ 🎓 🔗) 👈 👆 👨🎨 🚫 ™ ❌ 🔃 👫 🆎.
|
|
||||||
|
|
||||||
👈 🌌 👆 💪 ⚙️ 👆 😐 👨🎨 & 🛠️ 🧰 🍵 ✔️ 🚮 🛃 📳 🤷♂ 📚 ❌.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,256 +0,0 @@
|
||||||
# ➡ 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 ➡ "🔢" ⚖️ "🔢" ⏮️ 🎏 ❕ ⚙️ 🐍 📁 🎻:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial001.py hl[6:7] *}
|
|
||||||
|
|
||||||
💲 ➡ 🔢 `item_id` 🔜 🚶♀️ 👆 🔢 ❌ `item_id`.
|
|
||||||
|
|
||||||
, 🚥 👆 🏃 👉 🖼 & 🚶 <a href="http://127.0.0.1:8000/items/foo" class="external-link" target="_blank">http://127.0.0.1:8000/items/foo</a>, 👆 🔜 👀 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"item_id":"foo"}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ➡ 🔢 ⏮️ 🆎
|
|
||||||
|
|
||||||
👆 💪 📣 🆎 ➡ 🔢 🔢, ⚙️ 🐩 🐍 🆎 ✍:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial002.py hl[7] *}
|
|
||||||
|
|
||||||
👉 💼, `item_id` 📣 `int`.
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
👉 🔜 🤝 👆 👨🎨 🐕🦺 🔘 👆 🔢, ⏮️ ❌ ✅, 🛠️, ♒️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💽 <abbr title="also known as: serialization, parsing, marshalling">🛠️</abbr>
|
|
||||||
|
|
||||||
🚥 👆 🏃 👉 🖼 & 📂 👆 🖥 <a href="http://127.0.0.1:8000/items/3" class="external-link" target="_blank">http://127.0.0.1:8000/items/3</a>, 👆 🔜 👀 📨:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{"item_id":3}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
👀 👈 💲 👆 🔢 📨 (& 📨) `3`, 🐍 `int`, 🚫 🎻 `"3"`.
|
|
||||||
|
|
||||||
, ⏮️ 👈 🆎 📄, **FastAPI** 🤝 👆 🏧 📨 <abbr title="converting the string that comes from an HTTP request into Python data">"✍"</abbr>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 💽 🔬
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🚶 🖥 <a href="http://127.0.0.1:8000/items/foo" class="external-link" target="_blank">http://127.0.0.1:8000/items/foo</a>, 👆 🔜 👀 👌 🇺🇸🔍 ❌:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": [
|
|
||||||
"path",
|
|
||||||
"item_id"
|
|
||||||
],
|
|
||||||
"msg": "value is not a valid integer",
|
|
||||||
"type": "type_error.integer"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
↩️ ➡ 🔢 `item_id` ✔️ 💲 `"foo"`, ❔ 🚫 `int`.
|
|
||||||
|
|
||||||
🎏 ❌ 🔜 😑 🚥 👆 🚚 `float` ↩️ `int`,: <a href="http://127.0.0.1:8000/items/4.2" class="external-link" target="_blank">http://127.0.0.1:8000/items/4.2</a>
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
, ⏮️ 🎏 🐍 🆎 📄, **FastAPI** 🤝 👆 💽 🔬.
|
|
||||||
|
|
||||||
👀 👈 ❌ 🎯 🇵🇸 ⚫️❔ ☝ 🌐❔ 🔬 🚫 🚶♀️.
|
|
||||||
|
|
||||||
👉 🙃 👍 ⏪ 🛠️ & 🛠️ 📟 👈 🔗 ⏮️ 👆 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🧾
|
|
||||||
|
|
||||||
& 🕐❔ 👆 📂 👆 🖥 <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>, 👆 🔜 👀 🏧, 🎓, 🛠️ 🧾 💖:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-params/image01.png">
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
🔄, ⏮️ 👈 🎏 🐍 🆎 📄, **FastAPI** 🤝 👆 🏧, 🎓 🧾 (🛠️ 🦁 🎚).
|
|
||||||
|
|
||||||
👀 👈 ➡ 🔢 📣 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🐩-⚓️ 💰, 🎛 🧾
|
|
||||||
|
|
||||||
& ↩️ 🏗 🔗 ⚪️➡️ <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md" class="external-link" target="_blank">🗄</a> 🐩, 📤 📚 🔗 🧰.
|
|
||||||
|
|
||||||
↩️ 👉, **FastAPI** ⚫️ 🚚 🎛 🛠️ 🧾 (⚙️ 📄), ❔ 👆 💪 🔐 <a href="http://127.0.0.1:8000/redoc" class="external-link" target="_blank">http://127.0.0.1:8000/redoc</a>:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-params/image02.png">
|
|
||||||
|
|
||||||
🎏 🌌, 📤 📚 🔗 🧰. ✅ 📟 ⚡ 🧰 📚 🇪🇸.
|
|
||||||
|
|
||||||
## Pydantic
|
|
||||||
|
|
||||||
🌐 💽 🔬 🎭 🔽 🚘 <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a>, 👆 🤚 🌐 💰 ⚪️➡️ ⚫️. & 👆 💭 👆 👍 ✋.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🎏 🆎 📄 ⏮️ `str`, `float`, `bool` & 📚 🎏 🏗 📊 🆎.
|
|
||||||
|
|
||||||
📚 👫 🔬 ⏭ 📃 🔰.
|
|
||||||
|
|
||||||
## ✔ 🤔
|
|
||||||
|
|
||||||
🕐❔ 🏗 *➡ 🛠️*, 👆 💪 🔎 ⚠ 🌐❔ 👆 ✔️ 🔧 ➡.
|
|
||||||
|
|
||||||
💖 `/users/me`, ➡️ 💬 👈 ⚫️ 🤚 📊 🔃 ⏮️ 👩💻.
|
|
||||||
|
|
||||||
& ⤴️ 👆 💪 ✔️ ➡ `/users/{user_id}` 🤚 💽 🔃 🎯 👩💻 👩💻 🆔.
|
|
||||||
|
|
||||||
↩️ *➡ 🛠️* 🔬 ✔, 👆 💪 ⚒ 💭 👈 ➡ `/users/me` 📣 ⏭ 1️⃣ `/users/{user_id}`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial003.py hl[6,11] *}
|
|
||||||
|
|
||||||
⏪, ➡ `/users/{user_id}` 🔜 🏏 `/users/me`, "💭" 👈 ⚫️ 📨 🔢 `user_id` ⏮️ 💲 `"me"`.
|
|
||||||
|
|
||||||
➡, 👆 🚫🔜 ↔ ➡ 🛠️:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial003b.py hl[6,11] *}
|
|
||||||
|
|
||||||
🥇 🕐 🔜 🕧 ⚙️ ↩️ ➡ 🏏 🥇.
|
|
||||||
|
|
||||||
## 🔁 💲
|
|
||||||
|
|
||||||
🚥 👆 ✔️ *➡ 🛠️* 👈 📨 *➡ 🔢*, ✋️ 👆 💚 💪 ☑ *➡ 🔢* 💲 🔁, 👆 💪 ⚙️ 🐩 🐍 <abbr title="Enumeration">`Enum`</abbr>.
|
|
||||||
|
|
||||||
### ✍ `Enum` 🎓
|
|
||||||
|
|
||||||
🗄 `Enum` & ✍ 🎧-🎓 👈 😖 ⚪️➡️ `str` & ⚪️➡️ `Enum`.
|
|
||||||
|
|
||||||
😖 ⚪️➡️ `str` 🛠️ 🩺 🔜 💪 💭 👈 💲 🔜 🆎 `string` & 🔜 💪 ✍ ☑.
|
|
||||||
|
|
||||||
⤴️ ✍ 🎓 🔢 ⏮️ 🔧 💲, ❔ 🔜 💪 ☑ 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial005.py hl[1,6:9] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
<a href="https://docs.python.org/3/library/enum.html" class="external-link" target="_blank">🔢 (⚖️ 🔢) 💪 🐍</a> ↩️ ⏬ 3️⃣.4️⃣.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 💭, "📊", "🎓", & "🍏" 📛 🎰 🏫 <abbr title="Technically, Deep Learning model architectures">🏷</abbr>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 📣 *➡ 🔢*
|
|
||||||
|
|
||||||
⤴️ ✍ *➡ 🔢* ⏮️ 🆎 ✍ ⚙️ 🔢 🎓 👆 ✍ (`ModelName`):
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial005.py hl[16] *}
|
|
||||||
|
|
||||||
### ✅ 🩺
|
|
||||||
|
|
||||||
↩️ 💪 💲 *➡ 🔢* 🔢, 🎓 🩺 💪 🎦 👫 🎆:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/path-params/image03.png">
|
|
||||||
|
|
||||||
### 👷 ⏮️ 🐍 *🔢*
|
|
||||||
|
|
||||||
💲 *➡ 🔢* 🔜 *🔢 👨🎓*.
|
|
||||||
|
|
||||||
#### 🔬 *🔢 👨🎓*
|
|
||||||
|
|
||||||
👆 💪 🔬 ⚫️ ⏮️ *🔢 👨🎓* 👆 ✍ 🔢 `ModelName`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial005.py hl[17] *}
|
|
||||||
|
|
||||||
#### 🤚 *🔢 💲*
|
|
||||||
|
|
||||||
👆 💪 🤚 ☑ 💲 ( `str` 👉 💼) ⚙️ `model_name.value`, ⚖️ 🏢, `your_enum_member.value`:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial005.py hl[20] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 🔐 💲 `"lenet"` ⏮️ `ModelName.lenet.value`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
#### 📨 *🔢 👨🎓*
|
|
||||||
|
|
||||||
👆 💪 📨 *🔢 👨🎓* ⚪️➡️ 👆 *➡ 🛠️*, 🐦 🎻 💪 (✅ `dict`).
|
|
||||||
|
|
||||||
👫 🔜 🗜 👫 🔗 💲 (🎻 👉 💼) ⏭ 🛬 👫 👩💻:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial005.py hl[18,21,23] *}
|
|
||||||
|
|
||||||
👆 👩💻 👆 🔜 🤚 🎻 📨 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"model_name": "alexnet",
|
|
||||||
"message": "Deep Learning FTW!"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## ➡ 🔢 ⚗ ➡
|
|
||||||
|
|
||||||
➡️ 💬 👆 ✔️ *➡ 🛠️* ⏮️ ➡ `/files/{file_path}`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 `file_path` ⚫️ 🔌 *➡*, 💖 `home/johndoe/myfile.txt`.
|
|
||||||
|
|
||||||
, 📛 👈 📁 🔜 🕳 💖: `/files/home/johndoe/myfile.txt`.
|
|
||||||
|
|
||||||
### 🗄 🐕🦺
|
|
||||||
|
|
||||||
🗄 🚫 🐕🦺 🌌 📣 *➡ 🔢* 🔌 *➡* 🔘, 👈 💪 ↘️ 😐 👈 ⚠ 💯 & 🔬.
|
|
||||||
|
|
||||||
👐, 👆 💪 ⚫️ **FastAPI**, ⚙️ 1️⃣ 🔗 🧰 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
& 🩺 🔜 👷, 👐 🚫 ❎ 🙆 🧾 💬 👈 🔢 🔜 🔌 ➡.
|
|
||||||
|
|
||||||
### ➡ 🔌
|
|
||||||
|
|
||||||
⚙️ 🎛 🔗 ⚪️➡️ 💃 👆 💪 📣 *➡ 🔢* ⚗ *➡* ⚙️ 📛 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
/files/{file_path:path}
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 💼, 📛 🔢 `file_path`, & 🏁 🍕, `:path`, 💬 ⚫️ 👈 🔢 🔜 🏏 🙆 *➡*.
|
|
||||||
|
|
||||||
, 👆 💪 ⚙️ ⚫️ ⏮️:
|
|
||||||
|
|
||||||
{* ../../docs_src/path_params/tutorial004.py hl[6] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 💪 🔢 🔌 `/home/johndoe/myfile.txt`, ⏮️ 🏁 🔪 (`/`).
|
|
||||||
|
|
||||||
👈 💼, 📛 🔜: `/files//home/johndoe/myfile.txt`, ⏮️ 2️⃣✖️ 🔪 (`//`) 🖖 `files` & `home`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⏮️ **FastAPI**, ⚙️ 📏, 🏋️ & 🐩 🐍 🆎 📄, 👆 🤚:
|
|
||||||
|
|
||||||
* 👨🎨 🐕🦺: ❌ ✅, ✍, ♒️.
|
|
||||||
* 💽 "<abbr title="converting the string that comes from an HTTP request into Python data">✍</abbr>"
|
|
||||||
* 💽 🔬
|
|
||||||
* 🛠️ ✍ & 🏧 🧾
|
|
||||||
|
|
||||||
& 👆 🕴 ✔️ 📣 👫 🕐.
|
|
||||||
|
|
||||||
👈 🎲 👑 ⭐ 📈 **FastAPI** 🔬 🎛 🛠️ (↖️ ⚪️➡️ 🍣 🎭).
|
|
||||||
|
|
@ -1,320 +0,0 @@
|
||||||
# 🔢 🔢 & 🎻 🔬
|
|
||||||
|
|
||||||
**FastAPI** ✔ 👆 📣 🌖 ℹ & 🔬 👆 🔢.
|
|
||||||
|
|
||||||
➡️ ✊ 👉 🈸 🖼:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
🔢 🔢 `q` 🆎 `Union[str, None]` (⚖️ `str | None` 🐍 3️⃣.1️⃣0️⃣), 👈 ⛓ 👈 ⚫️ 🆎 `str` ✋️ 💪 `None`, & 👐, 🔢 💲 `None`, FastAPI 🔜 💭 ⚫️ 🚫 ✔.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
FastAPI 🔜 💭 👈 💲 `q` 🚫 ✔ ↩️ 🔢 💲 `= None`.
|
|
||||||
|
|
||||||
`Union` `Union[str, None]` 🔜 ✔ 👆 👨🎨 🤝 👆 👍 🐕🦺 & 🔍 ❌.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌖 🔬
|
|
||||||
|
|
||||||
👥 🔜 🛠️ 👈 ✋️ `q` 📦, 🕐❔ ⚫️ 🚚, **🚮 📐 🚫 📉 5️⃣0️⃣ 🦹**.
|
|
||||||
|
|
||||||
### 🗄 `Query`
|
|
||||||
|
|
||||||
🏆 👈, 🥇 🗄 `Query` ⚪️➡️ `fastapi`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial002.py hl[3] *}
|
|
||||||
|
|
||||||
## ⚙️ `Query` 🔢 💲
|
|
||||||
|
|
||||||
& 🔜 ⚙️ ⚫️ 🔢 💲 👆 🔢, ⚒ 🔢 `max_length` 5️⃣0️⃣:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial002.py hl[9] *}
|
|
||||||
|
|
||||||
👥 ✔️ ❎ 🔢 💲 `None` 🔢 ⏮️ `Query()`, 👥 💪 🔜 ⚒ 🔢 💲 ⏮️ 🔢 `Query(default=None)`, ⚫️ 🍦 🎏 🎯 ⚖ 👈 🔢 💲.
|
|
||||||
|
|
||||||
:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = Query(default=None)
|
|
||||||
```
|
|
||||||
|
|
||||||
...⚒ 🔢 📦, 🎏:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = None
|
|
||||||
```
|
|
||||||
|
|
||||||
& 🐍 3️⃣.1️⃣0️⃣ & 🔛:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: str | None = Query(default=None)
|
|
||||||
```
|
|
||||||
|
|
||||||
...⚒ 🔢 📦, 🎏:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: str | None = None
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ ⚫️ 📣 ⚫️ 🎯 💆♂ 🔢 🔢.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🌅 ⚠ 🍕 ⚒ 🔢 📦 🍕:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
= None
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
= Query(default=None)
|
|
||||||
```
|
|
||||||
|
|
||||||
⚫️ 🔜 ⚙️ 👈 `None` 🔢 💲, & 👈 🌌 ⚒ 🔢 **🚫 ✔**.
|
|
||||||
|
|
||||||
`Union[str, None]` 🍕 ✔ 👆 👨🎨 🚚 👻 🐕🦺, ✋️ ⚫️ 🚫 ⚫️❔ 💬 FastAPI 👈 👉 🔢 🚫 ✔.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
⤴️, 👥 💪 🚶♀️ 🌅 🔢 `Query`. 👉 💼, `max_length` 🔢 👈 ✔ 🎻:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = Query(default=None, max_length=50)
|
|
||||||
```
|
|
||||||
|
|
||||||
👉 🔜 ✔ 📊, 🎦 🆑 ❌ 🕐❔ 📊 🚫 ☑, & 📄 🔢 🗄 🔗 *➡ 🛠️*.
|
|
||||||
|
|
||||||
## 🚮 🌅 🔬
|
|
||||||
|
|
||||||
👆 💪 🚮 🔢 `min_length`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial003.py hl[10] *}
|
|
||||||
|
|
||||||
## 🚮 🥔 🧬
|
|
||||||
|
|
||||||
👆 💪 🔬 <abbr title="A regular expression, regex or regexp is a sequence of characters that define a search pattern for strings.">🥔 🧬</abbr> 👈 🔢 🔜 🏏:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial004.py hl[11] *}
|
|
||||||
|
|
||||||
👉 🎯 🥔 🧬 ✅ 👈 📨 🔢 💲:
|
|
||||||
|
|
||||||
* `^`: ▶️ ⏮️ 📄 🦹, 🚫 ✔️ 🦹 ⏭.
|
|
||||||
* `fixedquery`: ✔️ ☑ 💲 `fixedquery`.
|
|
||||||
* `$`: 🔚 📤, 🚫 ✔️ 🙆 🌖 🦹 ⏮️ `fixedquery`.
|
|
||||||
|
|
||||||
🚥 👆 💭 💸 ⏮️ 🌐 👉 **"🥔 🧬"** 💭, 🚫 😟. 👫 🏋️ ❔ 📚 👫👫. 👆 💪 📚 💩 🍵 💆♂ 🥔 🧬.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 💪 👫 & 🚶 & 💡 👫, 💭 👈 👆 💪 ⏪ ⚙️ 👫 🔗 **FastAPI**.
|
|
||||||
|
|
||||||
## 🔢 💲
|
|
||||||
|
|
||||||
🎏 🌌 👈 👆 💪 🚶♀️ `None` 💲 `default` 🔢, 👆 💪 🚶♀️ 🎏 💲.
|
|
||||||
|
|
||||||
➡️ 💬 👈 👆 💚 📣 `q` 🔢 🔢 ✔️ `min_length` `3`, & ✔️ 🔢 💲 `"fixedquery"`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial005.py hl[7] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
✔️ 🔢 💲 ⚒ 🔢 📦.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚒ ⚫️ ✔
|
|
||||||
|
|
||||||
🕐❔ 👥 🚫 💪 📣 🌅 🔬 ⚖️ 🗃, 👥 💪 ⚒ `q` 🔢 🔢 ✔ 🚫 📣 🔢 💲, 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: str
|
|
||||||
```
|
|
||||||
|
|
||||||
↩️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = None
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 👥 🔜 📣 ⚫️ ⏮️ `Query`, 🖼 💖:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
q: Union[str, None] = Query(default=None, min_length=3)
|
|
||||||
```
|
|
||||||
|
|
||||||
, 🕐❔ 👆 💪 📣 💲 ✔ ⏪ ⚙️ `Query`, 👆 💪 🎯 🚫 📣 🔢 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial006.py hl[7] *}
|
|
||||||
|
|
||||||
### ✔ ⏮️ `None`
|
|
||||||
|
|
||||||
👆 💪 📣 👈 🔢 💪 🚫 `None`, ✋️ 👈 ⚫️ ✔. 👉 🔜 ⚡ 👩💻 📨 💲, 🚥 💲 `None`.
|
|
||||||
|
|
||||||
👈, 👆 💪 📣 👈 `None` ☑ 🆎 ✋️ ⚙️ `default=...`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial006c.py hl[9] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
Pydantic, ❔ ⚫️❔ 🏋️ 🌐 💽 🔬 & 🛠️ FastAPI, ✔️ 🎁 🎭 🕐❔ 👆 ⚙️ `Optional` ⚖️ `Union[Something, None]` 🍵 🔢 💲, 👆 💪 ✍ 🌅 🔃 ⚫️ Pydantic 🩺 🔃 <a href="https://docs.pydantic.dev/latest/concepts/models/#required-optional-fields" class="external-link" target="_blank">✔ 📦 🏑</a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔢 🔢 📇 / 💗 💲
|
|
||||||
|
|
||||||
🕐❔ 👆 🔬 🔢 🔢 🎯 ⏮️ `Query` 👆 💪 📣 ⚫️ 📨 📇 💲, ⚖️ 🙆♀ 🎏 🌌, 📨 💗 💲.
|
|
||||||
|
|
||||||
🖼, 📣 🔢 🔢 `q` 👈 💪 😑 💗 🕰 📛, 👆 💪 ✍:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial011.py hl[9] *}
|
|
||||||
|
|
||||||
⤴️, ⏮️ 📛 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://localhost:8000/items/?q=foo&q=bar
|
|
||||||
```
|
|
||||||
|
|
||||||
👆 🔜 📨 💗 `q` *🔢 🔢'* 💲 (`foo` & `bar`) 🐍 `list` 🔘 👆 *➡ 🛠️ 🔢*, *🔢 🔢* `q`.
|
|
||||||
|
|
||||||
, 📨 👈 📛 🔜:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"q": [
|
|
||||||
"foo",
|
|
||||||
"bar"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📣 🔢 🔢 ⏮️ 🆎 `list`, 💖 🖼 🔛, 👆 💪 🎯 ⚙️ `Query`, ⏪ ⚫️ 🔜 🔬 📨 💪.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
🎓 🛠️ 🩺 🔜 ℹ ➡️, ✔ 💗 💲:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/query-params-str-validations/image02.png">
|
|
||||||
|
|
||||||
### 🔢 🔢 📇 / 💗 💲 ⏮️ 🔢
|
|
||||||
|
|
||||||
& 👆 💪 🔬 🔢 `list` 💲 🚥 👌 🚚:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial012.py hl[9] *}
|
|
||||||
|
|
||||||
🚥 👆 🚶:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://localhost:8000/items/
|
|
||||||
```
|
|
||||||
|
|
||||||
🔢 `q` 🔜: `["foo", "bar"]` & 👆 📨 🔜:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"q": [
|
|
||||||
"foo",
|
|
||||||
"bar"
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
#### ⚙️ `list`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `list` 🔗 ↩️ `List[str]` (⚖️ `list[str]` 🐍 3️⃣.9️⃣ ➕):
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial013.py hl[7] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
✔️ 🤯 👈 👉 💼, FastAPI 🏆 🚫 ✅ 🎚 📇.
|
|
||||||
|
|
||||||
🖼, `List[int]` 🔜 ✅ (& 📄) 👈 🎚 📇 🔢. ✋️ `list` 😞 🚫🔜.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📣 🌅 🗃
|
|
||||||
|
|
||||||
👆 💪 🚮 🌅 ℹ 🔃 🔢.
|
|
||||||
|
|
||||||
👈 ℹ 🔜 🔌 🏗 🗄 & ⚙️ 🧾 👩💻 🔢 & 🔢 🧰.
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
✔️ 🤯 👈 🎏 🧰 5️⃣📆 ✔️ 🎏 🎚 🗄 🐕🦺.
|
|
||||||
|
|
||||||
👫 💪 🚫 🎦 🌐 ➕ ℹ 📣, 👐 🌅 💼, ❌ ⚒ ⏪ 📄 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
👆 💪 🚮 `title`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial007.py hl[10] *}
|
|
||||||
|
|
||||||
& `description`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial008.py hl[13] *}
|
|
||||||
|
|
||||||
## 📛 🔢
|
|
||||||
|
|
||||||
🌈 👈 👆 💚 🔢 `item-query`.
|
|
||||||
|
|
||||||
💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/?item-query=foobaritems
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ `item-query` 🚫 ☑ 🐍 🔢 📛.
|
|
||||||
|
|
||||||
🔐 🔜 `item_query`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 ⚫️ ⚫️❔ `item-query`...
|
|
||||||
|
|
||||||
⤴️ 👆 💪 📣 `alias`, & 👈 📛 ⚫️❔ 🔜 ⚙️ 🔎 🔢 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial009.py hl[9] *}
|
|
||||||
|
|
||||||
## 😛 🔢
|
|
||||||
|
|
||||||
🔜 ➡️ 💬 👆 🚫 💖 👉 🔢 🚫🔜.
|
|
||||||
|
|
||||||
👆 ✔️ 👈 ⚫️ 📤 ⏪ ↩️ 📤 👩💻 ⚙️ ⚫️, ✋️ 👆 💚 🩺 🎯 🎦 ⚫️ <abbr title="obsolete, recommended not to use it">😢</abbr>.
|
|
||||||
|
|
||||||
⤴️ 🚶♀️ 🔢 `deprecated=True` `Query`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial010.py hl[18] *}
|
|
||||||
|
|
||||||
🩺 🔜 🎦 ⚫️ 💖 👉:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/query-params-str-validations/image01.png">
|
|
||||||
|
|
||||||
## 🚫 ⚪️➡️ 🗄
|
|
||||||
|
|
||||||
🚫 🔢 🔢 ⚪️➡️ 🏗 🗄 🔗 (& ➡️, ⚪️➡️ 🏧 🧾 ⚙️), ⚒ 🔢 `include_in_schema` `Query` `False`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params_str_validations/tutorial014.py hl[10] *}
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
👆 💪 📣 🌖 🔬 & 🗃 👆 🔢.
|
|
||||||
|
|
||||||
💊 🔬 & 🗃:
|
|
||||||
|
|
||||||
* `alias`
|
|
||||||
* `title`
|
|
||||||
* `description`
|
|
||||||
* `deprecated`
|
|
||||||
|
|
||||||
🔬 🎯 🎻:
|
|
||||||
|
|
||||||
* `min_length`
|
|
||||||
* `max_length`
|
|
||||||
* `regex`
|
|
||||||
|
|
||||||
👫 🖼 👆 👀 ❔ 📣 🔬 `str` 💲.
|
|
||||||
|
|
||||||
👀 ⏭ 📃 👀 ❔ 📣 🔬 🎏 🆎, 💖 🔢.
|
|
||||||
|
|
@ -1,187 +0,0 @@
|
||||||
# 🔢 🔢
|
|
||||||
|
|
||||||
🕐❔ 👆 📣 🎏 🔢 🔢 👈 🚫 🍕 ➡ 🔢, 👫 🔁 🔬 "🔢" 🔢.
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial001.py hl[9] *}
|
|
||||||
|
|
||||||
🔢 ⚒ 🔑-💲 👫 👈 🚶 ⏮️ `?` 📛, 🎏 `&` 🦹.
|
|
||||||
|
|
||||||
🖼, 📛:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/?skip=0&limit=10
|
|
||||||
```
|
|
||||||
|
|
||||||
...🔢 🔢:
|
|
||||||
|
|
||||||
* `skip`: ⏮️ 💲 `0`
|
|
||||||
* `limit`: ⏮️ 💲 `10`
|
|
||||||
|
|
||||||
👫 🍕 📛, 👫 "🛎" 🎻.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 📣 👫 ⏮️ 🐍 🆎 (🖼 🔛, `int`), 👫 🗜 👈 🆎 & ✔ 🛡 ⚫️.
|
|
||||||
|
|
||||||
🌐 🎏 🛠️ 👈 ⚖ ➡ 🔢 ✔ 🔢 🔢:
|
|
||||||
|
|
||||||
* 👨🎨 🐕🦺 (🎲)
|
|
||||||
* 💽 <abbr title="converting the string that comes from an HTTP request into Python data">"✍"</abbr>
|
|
||||||
* 💽 🔬
|
|
||||||
* 🏧 🧾
|
|
||||||
|
|
||||||
## 🔢
|
|
||||||
|
|
||||||
🔢 🔢 🚫 🔧 🍕 ➡, 👫 💪 📦 & 💪 ✔️ 🔢 💲.
|
|
||||||
|
|
||||||
🖼 🔛 👫 ✔️ 🔢 💲 `skip=0` & `limit=10`.
|
|
||||||
|
|
||||||
, 🔜 📛:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/
|
|
||||||
```
|
|
||||||
|
|
||||||
🔜 🎏 🔜:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/?skip=0&limit=10
|
|
||||||
```
|
|
||||||
|
|
||||||
✋️ 🚥 👆 🚶, 🖼:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/?skip=20
|
|
||||||
```
|
|
||||||
|
|
||||||
🔢 💲 👆 🔢 🔜:
|
|
||||||
|
|
||||||
* `skip=20`: ↩️ 👆 ⚒ ⚫️ 📛
|
|
||||||
* `limit=10`: ↩️ 👈 🔢 💲
|
|
||||||
|
|
||||||
## 📦 🔢
|
|
||||||
|
|
||||||
🎏 🌌, 👆 💪 📣 📦 🔢 🔢, ⚒ 👫 🔢 `None`:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial002.py hl[9] *}
|
|
||||||
|
|
||||||
👉 💼, 🔢 🔢 `q` 🔜 📦, & 🔜 `None` 🔢.
|
|
||||||
|
|
||||||
/// check
|
|
||||||
|
|
||||||
👀 👈 **FastAPI** 🙃 🥃 👀 👈 ➡ 🔢 `item_id` ➡ 🔢 & `q` 🚫,, ⚫️ 🔢 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔢 🔢 🆎 🛠️
|
|
||||||
|
|
||||||
👆 💪 📣 `bool` 🆎, & 👫 🔜 🗜:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial003.py hl[9] *}
|
|
||||||
|
|
||||||
👉 💼, 🚥 👆 🚶:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo?short=1
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo?short=True
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo?short=true
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo?short=on
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo?short=yes
|
|
||||||
```
|
|
||||||
|
|
||||||
⚖️ 🙆 🎏 💼 📈 (🔠, 🥇 🔤 🔠, ♒️), 👆 🔢 🔜 👀 🔢 `short` ⏮️ `bool` 💲 `True`. ⏪ `False`.
|
|
||||||
|
|
||||||
|
|
||||||
## 💗 ➡ & 🔢 🔢
|
|
||||||
|
|
||||||
👆 💪 📣 💗 ➡ 🔢 & 🔢 🔢 🎏 🕰, **FastAPI** 💭 ❔ ❔.
|
|
||||||
|
|
||||||
& 👆 🚫 ✔️ 📣 👫 🙆 🎯 ✔.
|
|
||||||
|
|
||||||
👫 🔜 🔬 📛:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial004.py hl[8,10] *}
|
|
||||||
|
|
||||||
## ✔ 🔢 🔢
|
|
||||||
|
|
||||||
🕐❔ 👆 📣 🔢 💲 🚫-➡ 🔢 (🔜, 👥 ✔️ 🕴 👀 🔢 🔢), ⤴️ ⚫️ 🚫 ✔.
|
|
||||||
|
|
||||||
🚥 👆 🚫 💚 🚮 🎯 💲 ✋️ ⚒ ⚫️ 📦, ⚒ 🔢 `None`.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 💚 ⚒ 🔢 🔢 ✔, 👆 💪 🚫 📣 🙆 🔢 💲:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial005.py hl[6:7] *}
|
|
||||||
|
|
||||||
📥 🔢 🔢 `needy` ✔ 🔢 🔢 🆎 `str`.
|
|
||||||
|
|
||||||
🚥 👆 📂 👆 🖥 📛 💖:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo-item
|
|
||||||
```
|
|
||||||
|
|
||||||
...🍵 ❎ ✔ 🔢 `needy`, 👆 🔜 👀 ❌ 💖:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"detail": [
|
|
||||||
{
|
|
||||||
"loc": [
|
|
||||||
"query",
|
|
||||||
"needy"
|
|
||||||
],
|
|
||||||
"msg": "field required",
|
|
||||||
"type": "value_error.missing"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
`needy` 🚚 🔢, 👆 🔜 💪 ⚒ ⚫️ 📛:
|
|
||||||
|
|
||||||
```
|
|
||||||
http://127.0.0.1:8000/items/foo-item?needy=sooooneedy
|
|
||||||
```
|
|
||||||
|
|
||||||
...👉 🔜 👷:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"item_id": "foo-item",
|
|
||||||
"needy": "sooooneedy"
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
& ↗️, 👆 💪 🔬 🔢 ✔, ✔️ 🔢 💲, & 🍕 📦:
|
|
||||||
|
|
||||||
{* ../../docs_src/query_params/tutorial006.py hl[10] *}
|
|
||||||
|
|
||||||
👉 💼, 📤 3️⃣ 🔢 🔢:
|
|
||||||
|
|
||||||
* `needy`, ✔ `str`.
|
|
||||||
* `skip`, `int` ⏮️ 🔢 💲 `0`.
|
|
||||||
* `limit`, 📦 `int`.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `Enum`Ⓜ 🎏 🌌 ⏮️ [➡ 🔢](path-params.md#_7){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
@ -1,172 +0,0 @@
|
||||||
# 📨 📁
|
|
||||||
|
|
||||||
👆 💪 🔬 📁 📂 👩💻 ⚙️ `File`.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📨 📂 📁, 🥇 ❎ <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
|
||||||
|
|
||||||
🤶 Ⓜ. `pip install python-multipart`.
|
|
||||||
|
|
||||||
👉 ↩️ 📂 📁 📨 "📨 💽".
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🗄 `File`
|
|
||||||
|
|
||||||
🗄 `File` & `UploadFile` ⚪️➡️ `fastapi`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial001.py hl[1] *}
|
|
||||||
|
|
||||||
## 🔬 `File` 🔢
|
|
||||||
|
|
||||||
✍ 📁 🔢 🎏 🌌 👆 🔜 `Body` ⚖️ `Form`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial001.py hl[7] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`File` 🎓 👈 😖 🔗 ⚪️➡️ `Form`.
|
|
||||||
|
|
||||||
✋️ 💭 👈 🕐❔ 👆 🗄 `Query`, `Path`, `File` & 🎏 ⚪️➡️ `fastapi`, 👈 🤙 🔢 👈 📨 🎁 🎓.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📣 📁 💪, 👆 💪 ⚙️ `File`, ↩️ ⏪ 🔢 🔜 🔬 🔢 🔢 ⚖️ 💪 (🎻) 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
📁 🔜 📂 "📨 💽".
|
|
||||||
|
|
||||||
🚥 👆 📣 🆎 👆 *➡ 🛠️ 🔢* 🔢 `bytes`, **FastAPI** 🔜 ✍ 📁 👆 & 👆 🔜 📨 🎚 `bytes`.
|
|
||||||
|
|
||||||
✔️ 🤯 👈 👉 ⛓ 👈 🎂 🎚 🔜 🏪 💾. 👉 🔜 👷 👍 🤪 📁.
|
|
||||||
|
|
||||||
✋️ 📤 📚 💼 ❔ 👆 💪 💰 ⚪️➡️ ⚙️ `UploadFile`.
|
|
||||||
|
|
||||||
## 📁 🔢 ⏮️ `UploadFile`
|
|
||||||
|
|
||||||
🔬 📁 🔢 ⏮️ 🆎 `UploadFile`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial001.py hl[12] *}
|
|
||||||
|
|
||||||
⚙️ `UploadFile` ✔️ 📚 📈 🤭 `bytes`:
|
|
||||||
|
|
||||||
* 👆 🚫 ✔️ ⚙️ `File()` 🔢 💲 🔢.
|
|
||||||
* ⚫️ ⚙️ "🧵" 📁:
|
|
||||||
* 📁 🏪 💾 🆙 🔆 📐 📉, & ⏮️ 🚶♀️ 👉 📉 ⚫️ 🔜 🏪 💾.
|
|
||||||
* 👉 ⛓ 👈 ⚫️ 🔜 👷 👍 ⭕ 📁 💖 🖼, 📹, ⭕ 💱, ♒️. 🍵 😩 🌐 💾.
|
|
||||||
* 👆 💪 🤚 🗃 ⚪️➡️ 📂 📁.
|
|
||||||
* ⚫️ ✔️ <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">📁-💖</a> `async` 🔢.
|
|
||||||
* ⚫️ 🎦 ☑ 🐍 <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> 🎚 👈 👆 💪 🚶♀️ 🔗 🎏 🗃 👈 ⌛ 📁-💖 🎚.
|
|
||||||
|
|
||||||
### `UploadFile`
|
|
||||||
|
|
||||||
`UploadFile` ✔️ 📄 🔢:
|
|
||||||
|
|
||||||
* `filename`: `str` ⏮️ ⏮️ 📁 📛 👈 📂 (✅ `myimage.jpg`).
|
|
||||||
* `content_type`: `str` ⏮️ 🎚 🆎 (📁 🆎 / 📻 🆎) (✅ `image/jpeg`).
|
|
||||||
* `file`: <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> ( <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">📁-💖</a> 🎚). 👉 ☑ 🐍 📁 👈 👆 💪 🚶♀️ 🔗 🎏 🔢 ⚖️ 🗃 👈 ⌛ "📁-💖" 🎚.
|
|
||||||
|
|
||||||
`UploadFile` ✔️ 📄 `async` 👩🔬. 👫 🌐 🤙 🔗 📁 👩🔬 🔘 (⚙️ 🔗 `SpooledTemporaryFile`).
|
|
||||||
|
|
||||||
* `write(data)`: ✍ `data` (`str` ⚖️ `bytes`) 📁.
|
|
||||||
* `read(size)`: ✍ `size` (`int`) 🔢/🦹 📁.
|
|
||||||
* `seek(offset)`: 🚶 🔢 🧘 `offset` (`int`) 📁.
|
|
||||||
* 🤶 Ⓜ., `await myfile.seek(0)` 🔜 🚶 ▶️ 📁.
|
|
||||||
* 👉 ✴️ ⚠ 🚥 👆 🏃 `await myfile.read()` 🕐 & ⤴️ 💪 ✍ 🎚 🔄.
|
|
||||||
* `close()`: 🔐 📁.
|
|
||||||
|
|
||||||
🌐 👫 👩🔬 `async` 👩🔬, 👆 💪 "⌛" 👫.
|
|
||||||
|
|
||||||
🖼, 🔘 `async` *➡ 🛠️ 🔢* 👆 💪 🤚 🎚 ⏮️:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
contents = await myfile.read()
|
|
||||||
```
|
|
||||||
|
|
||||||
🚥 👆 🔘 😐 `def` *➡ 🛠️ 🔢*, 👆 💪 🔐 `UploadFile.file` 🔗, 🖼:
|
|
||||||
|
|
||||||
```Python
|
|
||||||
contents = myfile.file.read()
|
|
||||||
```
|
|
||||||
|
|
||||||
/// note | `async` 📡 ℹ
|
|
||||||
|
|
||||||
🕐❔ 👆 ⚙️ `async` 👩🔬, **FastAPI** 🏃 📁 👩🔬 🧵 & ⌛ 👫.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// note | 💃 📡 ℹ
|
|
||||||
|
|
||||||
**FastAPI**'Ⓜ `UploadFile` 😖 🔗 ⚪️➡️ **💃**'Ⓜ `UploadFile`, ✋️ 🚮 💪 🍕 ⚒ ⚫️ 🔗 ⏮️ **Pydantic** & 🎏 🍕 FastAPI.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## ⚫️❔ "📨 💽"
|
|
||||||
|
|
||||||
🌌 🕸 📨 (`<form></form>`) 📨 💽 💽 🛎 ⚙️ "🎁" 🔢 👈 📊, ⚫️ 🎏 ⚪️➡️ 🎻.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚒ 💭 ✍ 👈 📊 ⚪️➡️ ▶️️ 🥉 ↩️ 🎻.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
📊 ⚪️➡️ 📨 🛎 🗜 ⚙️ "📻 🆎" `application/x-www-form-urlencoded` 🕐❔ ⚫️ 🚫 🔌 📁.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 📨 🔌 📁, ⚫️ 🗜 `multipart/form-data`. 🚥 👆 ⚙️ `File`, **FastAPI** 🔜 💭 ⚫️ ✔️ 🤚 📁 ⚪️➡️ ☑ 🍕 💪.
|
|
||||||
|
|
||||||
🚥 👆 💚 ✍ 🌖 🔃 👉 🔢 & 📨 🏑, 👳 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">🏇</abbr> 🕸 🩺 <code>POST</code></a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👆 💪 📣 💗 `File` & `Form` 🔢 *➡ 🛠️*, ✋️ 👆 💪 🚫 📣 `Body` 🏑 👈 👆 ⌛ 📨 🎻, 📨 🔜 ✔️ 💪 🗜 ⚙️ `multipart/form-data` ↩️ `application/json`.
|
|
||||||
|
|
||||||
👉 🚫 🚫 **FastAPI**, ⚫️ 🍕 🇺🇸🔍 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 📦 📁 📂
|
|
||||||
|
|
||||||
👆 💪 ⚒ 📁 📦 ⚙️ 🐩 🆎 ✍ & ⚒ 🔢 💲 `None`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial001_02.py hl[9,17] *}
|
|
||||||
|
|
||||||
## `UploadFile` ⏮️ 🌖 🗃
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `File()` ⏮️ `UploadFile`, 🖼, ⚒ 🌖 🗃:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial001_03.py hl[13] *}
|
|
||||||
|
|
||||||
## 💗 📁 📂
|
|
||||||
|
|
||||||
⚫️ 💪 📂 📚 📁 🎏 🕰.
|
|
||||||
|
|
||||||
👫 🔜 👨💼 🎏 "📨 🏑" 📨 ⚙️ "📨 💽".
|
|
||||||
|
|
||||||
⚙️ 👈, 📣 📇 `bytes` ⚖️ `UploadFile`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial002.py hl[10,15] *}
|
|
||||||
|
|
||||||
👆 🔜 📨, 📣, `list` `bytes` ⚖️ `UploadFile`Ⓜ.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `from starlette.responses import HTMLResponse`.
|
|
||||||
|
|
||||||
**FastAPI** 🚚 🎏 `starlette.responses` `fastapi.responses` 🏪 👆, 👩💻. ✋️ 🌅 💪 📨 👟 🔗 ⚪️➡️ 💃.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### 💗 📁 📂 ⏮️ 🌖 🗃
|
|
||||||
|
|
||||||
& 🎏 🌌 ⏭, 👆 💪 ⚙️ `File()` ⚒ 🌖 🔢, `UploadFile`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_files/tutorial003.py hl[18] *}
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ `File`, `bytes`, & `UploadFile` 📣 📁 📂 📨, 📨 📨 💽.
|
|
||||||
|
|
@ -1,37 +0,0 @@
|
||||||
# 📨 📨 & 📁
|
|
||||||
|
|
||||||
👆 💪 🔬 📁 & 📨 🏑 🎏 🕰 ⚙️ `File` & `Form`.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
📨 📂 📁 & /⚖️ 📨 📊, 🥇 ❎ <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
|
||||||
|
|
||||||
🤶 Ⓜ. `pip install python-multipart`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🗄 `File` & `Form`
|
|
||||||
|
|
||||||
{* ../../docs_src/request_forms_and_files/tutorial001.py hl[1] *}
|
|
||||||
|
|
||||||
## 🔬 `File` & `Form` 🔢
|
|
||||||
|
|
||||||
✍ 📁 & 📨 🔢 🎏 🌌 👆 🔜 `Body` ⚖️ `Query`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_forms_and_files/tutorial001.py hl[8] *}
|
|
||||||
|
|
||||||
📁 & 📨 🏑 🔜 📂 📨 📊 & 👆 🔜 📨 📁 & 📨 🏑.
|
|
||||||
|
|
||||||
& 👆 💪 📣 📁 `bytes` & `UploadFile`.
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👆 💪 📣 💗 `File` & `Form` 🔢 *➡ 🛠️*, ✋️ 👆 💪 🚫 📣 `Body` 🏑 👈 👆 ⌛ 📨 🎻, 📨 🔜 ✔️ 💪 🗜 ⚙️ `multipart/form-data` ↩️ `application/json`.
|
|
||||||
|
|
||||||
👉 🚫 🚫 **FastAPI**, ⚫️ 🍕 🇺🇸🔍 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ `File` & `Form` 👯♂️ 🕐❔ 👆 💪 📨 💽 & 📁 🎏 📨.
|
|
||||||
|
|
@ -1,69 +0,0 @@
|
||||||
# 📨 💽
|
|
||||||
|
|
||||||
🕐❔ 👆 💪 📨 📨 🏑 ↩️ 🎻, 👆 💪 ⚙️ `Form`.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
⚙️ 📨, 🥇 ❎ <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
|
||||||
|
|
||||||
🤶 Ⓜ. `pip install python-multipart`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🗄 `Form`
|
|
||||||
|
|
||||||
🗄 `Form` ⚪️➡️ `fastapi`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_forms/tutorial001.py hl[1] *}
|
|
||||||
|
|
||||||
## 🔬 `Form` 🔢
|
|
||||||
|
|
||||||
✍ 📨 🔢 🎏 🌌 👆 🔜 `Body` ⚖️ `Query`:
|
|
||||||
|
|
||||||
{* ../../docs_src/request_forms/tutorial001.py hl[7] *}
|
|
||||||
|
|
||||||
🖼, 1️⃣ 🌌 Oauth2️⃣ 🔧 💪 ⚙️ (🤙 "🔐 💧") ⚫️ ✔ 📨 `username` & `password` 📨 🏑.
|
|
||||||
|
|
||||||
<abbr title="specification">🔌</abbr> 🚚 🏑 ⚫️❔ 📛 `username` & `password`, & 📨 📨 🏑, 🚫 🎻.
|
|
||||||
|
|
||||||
⏮️ `Form` 👆 💪 📣 🎏 📳 ⏮️ `Body` (& `Query`, `Path`, `Cookie`), 🔌 🔬, 🖼, 📛 (✅ `user-name` ↩️ `username`), ♒️.
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
`Form` 🎓 👈 😖 🔗 ⚪️➡️ `Body`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
📣 📨 💪, 👆 💪 ⚙️ `Form` 🎯, ↩️ 🍵 ⚫️ 🔢 🔜 🔬 🔢 🔢 ⚖️ 💪 (🎻) 🔢.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🔃 "📨 🏑"
|
|
||||||
|
|
||||||
🌌 🕸 📨 (`<form></form>`) 📨 💽 💽 🛎 ⚙️ "🎁" 🔢 👈 📊, ⚫️ 🎏 ⚪️➡️ 🎻.
|
|
||||||
|
|
||||||
**FastAPI** 🔜 ⚒ 💭 ✍ 👈 📊 ⚪️➡️ ▶️️ 🥉 ↩️ 🎻.
|
|
||||||
|
|
||||||
/// note | 📡 ℹ
|
|
||||||
|
|
||||||
📊 ⚪️➡️ 📨 🛎 🗜 ⚙️ "📻 🆎" `application/x-www-form-urlencoded`.
|
|
||||||
|
|
||||||
✋️ 🕐❔ 📨 🔌 📁, ⚫️ 🗜 `multipart/form-data`. 👆 🔜 ✍ 🔃 🚚 📁 ⏭ 📃.
|
|
||||||
|
|
||||||
🚥 👆 💚 ✍ 🌖 🔃 👉 🔢 & 📨 🏑, 👳 <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">🏇</abbr> 🕸 🩺 <code>POST</code></a>.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// warning
|
|
||||||
|
|
||||||
👆 💪 📣 💗 `Form` 🔢 *➡ 🛠️*, ✋️ 👆 💪 🚫 📣 `Body` 🏑 👈 👆 ⌛ 📨 🎻, 📨 🔜 ✔️ 💪 🗜 ⚙️ `application/x-www-form-urlencoded` ↩️ `application/json`.
|
|
||||||
|
|
||||||
👉 🚫 🚫 **FastAPI**, ⚫️ 🍕 🇺🇸🔍 🛠️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ `Form` 📣 📨 💽 🔢 🔢.
|
|
||||||
|
|
@ -1,340 +0,0 @@
|
||||||
# 📨 🏷 - 📨 🆎
|
|
||||||
|
|
||||||
👆 💪 📣 🆎 ⚙️ 📨 ✍ *➡ 🛠️ 🔢* **📨 🆎**.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ **🆎 ✍** 🎏 🌌 👆 🔜 🔢 💽 🔢 **🔢**, 👆 💪 ⚙️ Pydantic 🏷, 📇, 📖, 📊 💲 💖 🔢, 🎻, ♒️.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial001_01.py hl[18,23] *}
|
|
||||||
|
|
||||||
FastAPI 🔜 ⚙️ 👉 📨 🆎:
|
|
||||||
|
|
||||||
* **✔** 📨 💽.
|
|
||||||
* 🚥 💽 ❌ (✅ 👆 ❌ 🏑), ⚫️ ⛓ 👈 *👆* 📱 📟 💔, 🚫 🛬 ⚫️❔ ⚫️ 🔜, & ⚫️ 🔜 📨 💽 ❌ ↩️ 🛬 ❌ 💽. 👉 🌌 👆 & 👆 👩💻 💪 🎯 👈 👫 🔜 📨 💽 & 💽 💠 📈.
|
|
||||||
* 🚮 **🎻 🔗** 📨, 🗄 *➡ 🛠️*.
|
|
||||||
* 👉 🔜 ⚙️ **🏧 🩺**.
|
|
||||||
* ⚫️ 🔜 ⚙️ 🏧 👩💻 📟 ⚡ 🧰.
|
|
||||||
|
|
||||||
✋️ 🏆 🥈:
|
|
||||||
|
|
||||||
* ⚫️ 🔜 **📉 & ⛽** 🔢 📊 ⚫️❔ 🔬 📨 🆎.
|
|
||||||
* 👉 ✴️ ⚠ **💂♂**, 👥 🔜 👀 🌅 👈 🔛.
|
|
||||||
|
|
||||||
## `response_model` 🔢
|
|
||||||
|
|
||||||
📤 💼 🌐❔ 👆 💪 ⚖️ 💚 📨 💽 👈 🚫 ⚫️❔ ⚫️❔ 🆎 📣.
|
|
||||||
|
|
||||||
🖼, 👆 💪 💚 **📨 📖** ⚖️ 💽 🎚, ✋️ **📣 ⚫️ Pydantic 🏷**. 👉 🌌 Pydantic 🏷 🔜 🌐 💽 🧾, 🔬, ♒️. 🎚 👈 👆 📨 (✅ 📖 ⚖️ 💽 🎚).
|
|
||||||
|
|
||||||
🚥 👆 🚮 📨 🆎 ✍, 🧰 & 👨🎨 🔜 😭 ⏮️ (☑) ❌ 💬 👆 👈 👆 🔢 🛬 🆎 (✅#️⃣) 👈 🎏 ⚪️➡️ ⚫️❔ 👆 📣 (✅ Pydantic 🏷).
|
|
||||||
|
|
||||||
📚 💼, 👆 💪 ⚙️ *➡ 🛠️ 👨🎨* 🔢 `response_model` ↩️ 📨 🆎.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `response_model` 🔢 🙆 *➡ 🛠️*:
|
|
||||||
|
|
||||||
* `@app.get()`
|
|
||||||
* `@app.post()`
|
|
||||||
* `@app.put()`
|
|
||||||
* `@app.delete()`
|
|
||||||
* ♒️.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial001.py hl[17,22,24:27] *}
|
|
||||||
|
|
||||||
/// note
|
|
||||||
|
|
||||||
👀 👈 `response_model` 🔢 "👨🎨" 👩🔬 (`get`, `post`, ♒️). 🚫 👆 *➡ 🛠️ 🔢*, 💖 🌐 🔢 & 💪.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
`response_model` 📨 🎏 🆎 👆 🔜 📣 Pydantic 🏷 🏑,, ⚫️ 💪 Pydantic 🏷, ✋️ ⚫️ 💪, ✅ `list` Pydantic 🏷, 💖 `List[Item]`.
|
|
||||||
|
|
||||||
FastAPI 🔜 ⚙️ 👉 `response_model` 🌐 💽 🧾, 🔬, ♒️. & **🗜 & ⛽ 🔢 📊** 🚮 🆎 📄.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
🚥 👆 ✔️ ⚠ 🆎 ✅ 👆 👨🎨, ✍, ♒️, 👆 💪 📣 🔢 📨 🆎 `Any`.
|
|
||||||
|
|
||||||
👈 🌌 👆 💬 👨🎨 👈 👆 😫 🛬 🕳. ✋️ FastAPI 🔜 💽 🧾, 🔬, 🖥, ♒️. ⏮️ `response_model`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `response_model` 📫
|
|
||||||
|
|
||||||
🚥 👆 📣 👯♂️ 📨 🆎 & `response_model`, `response_model` 🔜 ✊ 📫 & ⚙️ FastAPI.
|
|
||||||
|
|
||||||
👉 🌌 👆 💪 🚮 ☑ 🆎 ✍ 👆 🔢 🕐❔ 👆 🛬 🆎 🎏 🌘 📨 🏷, ⚙️ 👨🎨 & 🧰 💖 ✍. & 👆 💪 ✔️ FastAPI 💽 🔬, 🧾, ♒️. ⚙️ `response_model`.
|
|
||||||
|
|
||||||
👆 💪 ⚙️ `response_model=None` ❎ 🏗 📨 🏷 👈 *➡ 🛠️*, 👆 5️⃣📆 💪 ⚫️ 🚥 👆 ❎ 🆎 ✍ 👜 👈 🚫 ☑ Pydantic 🏑, 👆 🔜 👀 🖼 👈 1️⃣ 📄 🔛.
|
|
||||||
|
|
||||||
## 📨 🎏 🔢 💽
|
|
||||||
|
|
||||||
📥 👥 📣 `UserIn` 🏷, ⚫️ 🔜 🔌 🔢 🔐:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial002.py hl[9,11] *}
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
⚙️ `EmailStr`, 🥇 ❎ <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email-validator`</a>.
|
|
||||||
|
|
||||||
🤶 Ⓜ. `pip install email-validator`
|
|
||||||
⚖️ `pip install pydantic[email]`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
& 👥 ⚙️ 👉 🏷 📣 👆 🔢 & 🎏 🏷 📣 👆 🔢:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial002.py hl[18] *}
|
|
||||||
|
|
||||||
🔜, 🕐❔ 🖥 🏗 👩💻 ⏮️ 🔐, 🛠️ 🔜 📨 🎏 🔐 📨.
|
|
||||||
|
|
||||||
👉 💼, ⚫️ 💪 🚫 ⚠, ↩️ ⚫️ 🎏 👩💻 📨 🔐.
|
|
||||||
|
|
||||||
✋️ 🚥 👥 ⚙️ 🎏 🏷 ➕1️⃣ *➡ 🛠️*, 👥 💪 📨 👆 👩💻 🔐 🔠 👩💻.
|
|
||||||
|
|
||||||
/// danger
|
|
||||||
|
|
||||||
🙅 🏪 ✅ 🔐 👩💻 ⚖️ 📨 ⚫️ 📨 💖 👉, 🚥 👆 💭 🌐 ⚠ & 👆 💭 ⚫️❔ 👆 🔨.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
## 🚮 🔢 🏷
|
|
||||||
|
|
||||||
👥 💪 ↩️ ✍ 🔢 🏷 ⏮️ 🔢 🔐 & 🔢 🏷 🍵 ⚫️:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003.py hl[9,11,16] *}
|
|
||||||
|
|
||||||
📥, ✋️ 👆 *➡ 🛠️ 🔢* 🛬 🎏 🔢 👩💻 👈 🔌 🔐:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003.py hl[24] *}
|
|
||||||
|
|
||||||
...👥 📣 `response_model` 👆 🏷 `UserOut`, 👈 🚫 🔌 🔐:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003.py hl[22] *}
|
|
||||||
|
|
||||||
, **FastAPI** 🔜 ✊ 💅 🖥 👅 🌐 💽 👈 🚫 📣 🔢 🏷 (⚙️ Pydantic).
|
|
||||||
|
|
||||||
### `response_model` ⚖️ 📨 🆎
|
|
||||||
|
|
||||||
👉 💼, ↩️ 2️⃣ 🏷 🎏, 🚥 👥 ✍ 🔢 📨 🆎 `UserOut`, 👨🎨 & 🧰 🔜 😭 👈 👥 🛬 ❌ 🆎, 📚 🎏 🎓.
|
|
||||||
|
|
||||||
👈 ⚫️❔ 👉 🖼 👥 ✔️ 📣 ⚫️ `response_model` 🔢.
|
|
||||||
|
|
||||||
...✋️ 😣 👂 🔛 👀 ❔ ❎ 👈.
|
|
||||||
|
|
||||||
## 📨 🆎 & 💽 🖥
|
|
||||||
|
|
||||||
➡️ 😣 ⚪️➡️ ⏮️ 🖼. 👥 💚 **✍ 🔢 ⏮️ 1️⃣ 🆎** ✋️ 📨 🕳 👈 🔌 **🌅 💽**.
|
|
||||||
|
|
||||||
👥 💚 FastAPI 🚧 **🖥** 📊 ⚙️ 📨 🏷.
|
|
||||||
|
|
||||||
⏮️ 🖼, ↩️ 🎓 🎏, 👥 ✔️ ⚙️ `response_model` 🔢. ✋️ 👈 ⛓ 👈 👥 🚫 🤚 🐕🦺 ⚪️➡️ 👨🎨 & 🧰 ✅ 🔢 📨 🆎.
|
|
||||||
|
|
||||||
✋️ 🌅 💼 🌐❔ 👥 💪 🕳 💖 👉, 👥 💚 🏷 **⛽/❎** 📊 👉 🖼.
|
|
||||||
|
|
||||||
& 👈 💼, 👥 💪 ⚙️ 🎓 & 🧬 ✊ 📈 🔢 **🆎 ✍** 🤚 👍 🐕🦺 👨🎨 & 🧰, & 🤚 FastAPI **💽 🖥**.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003_01.py hl[9:13,15:16,20] *}
|
|
||||||
|
|
||||||
⏮️ 👉, 👥 🤚 🏭 🐕🦺, ⚪️➡️ 👨🎨 & ✍ 👉 📟 ☑ ⚖ 🆎, ✋️ 👥 🤚 💽 🖥 ⚪️➡️ FastAPI.
|
|
||||||
|
|
||||||
❔ 🔨 👉 👷 ❓ ➡️ ✅ 👈 👅. 👶
|
|
||||||
|
|
||||||
### 🆎 ✍ & 🏭
|
|
||||||
|
|
||||||
🥇 ➡️ 👀 ❔ 👨🎨, ✍ & 🎏 🧰 🔜 👀 👉.
|
|
||||||
|
|
||||||
`BaseUser` ✔️ 🧢 🏑. ⤴️ `UserIn` 😖 ⚪️➡️ `BaseUser` & 🚮 `password` 🏑,, ⚫️ 🔜 🔌 🌐 🏑 ⚪️➡️ 👯♂️ 🏷.
|
|
||||||
|
|
||||||
👥 ✍ 🔢 📨 🆎 `BaseUser`, ✋️ 👥 🤙 🛬 `UserIn` 👐.
|
|
||||||
|
|
||||||
👨🎨, ✍, & 🎏 🧰 🏆 🚫 😭 🔃 👉 ↩️, ⌨ ⚖, `UserIn` 🏿 `BaseUser`, ❔ ⛓ ⚫️ *☑* 🆎 🕐❔ ⚫️❔ ⌛ 🕳 👈 `BaseUser`.
|
|
||||||
|
|
||||||
### FastAPI 💽 🖥
|
|
||||||
|
|
||||||
🔜, FastAPI, ⚫️ 🔜 👀 📨 🆎 & ⚒ 💭 👈 ⚫️❔ 👆 📨 🔌 **🕴** 🏑 👈 📣 🆎.
|
|
||||||
|
|
||||||
FastAPI 🔨 📚 👜 🔘 ⏮️ Pydantic ⚒ 💭 👈 📚 🎏 🚫 🎓 🧬 🚫 ⚙️ 📨 💽 🖥, ⏪ 👆 💪 🔚 🆙 🛬 🌅 🌅 💽 🌘 ⚫️❔ 👆 📈.
|
|
||||||
|
|
||||||
👉 🌌, 👆 💪 🤚 🏆 👯♂️ 🌏: 🆎 ✍ ⏮️ **🏭 🐕🦺** & **💽 🖥**.
|
|
||||||
|
|
||||||
## 👀 ⚫️ 🩺
|
|
||||||
|
|
||||||
🕐❔ 👆 👀 🏧 🩺, 👆 💪 ✅ 👈 🔢 🏷 & 🔢 🏷 🔜 👯♂️ ✔️ 👫 👍 🎻 🔗:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/response-model/image01.png">
|
|
||||||
|
|
||||||
& 👯♂️ 🏷 🔜 ⚙️ 🎓 🛠️ 🧾:
|
|
||||||
|
|
||||||
<img src="/img/tutorial/response-model/image02.png">
|
|
||||||
|
|
||||||
## 🎏 📨 🆎 ✍
|
|
||||||
|
|
||||||
📤 5️⃣📆 💼 🌐❔ 👆 📨 🕳 👈 🚫 ☑ Pydantic 🏑 & 👆 ✍ ⚫️ 🔢, 🕴 🤚 🐕🦺 🚚 🏭 (👨🎨, ✍, ♒️).
|
|
||||||
|
|
||||||
### 📨 📨 🔗
|
|
||||||
|
|
||||||
🏆 ⚠ 💼 🔜 [🛬 📨 🔗 🔬 ⏪ 🏧 🩺](../advanced/response-directly.md){.internal-link target=_blank}.
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003_02.py hl[8,10:11] *}
|
|
||||||
|
|
||||||
👉 🙅 💼 🍵 🔁 FastAPI ↩️ 📨 🆎 ✍ 🎓 (⚖️ 🏿) `Response`.
|
|
||||||
|
|
||||||
& 🧰 🔜 😄 ↩️ 👯♂️ `RedirectResponse` & `JSONResponse` 🏿 `Response`, 🆎 ✍ ☑.
|
|
||||||
|
|
||||||
### ✍ 📨 🏿
|
|
||||||
|
|
||||||
👆 💪 ⚙️ 🏿 `Response` 🆎 ✍:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003_03.py hl[8:9] *}
|
|
||||||
|
|
||||||
👉 🔜 👷 ↩️ `RedirectResponse` 🏿 `Response`, & FastAPI 🔜 🔁 🍵 👉 🙅 💼.
|
|
||||||
|
|
||||||
### ❌ 📨 🆎 ✍
|
|
||||||
|
|
||||||
✋️ 🕐❔ 👆 📨 🎏 ❌ 🎚 👈 🚫 ☑ Pydantic 🆎 (✅ 💽 🎚) & 👆 ✍ ⚫️ 💖 👈 🔢, FastAPI 🔜 🔄 ✍ Pydantic 📨 🏷 ⚪️➡️ 👈 🆎 ✍, & 🔜 ❌.
|
|
||||||
|
|
||||||
🎏 🔜 🔨 🚥 👆 ✔️ 🕳 💖 <abbr title='A union between multiple types means "any of these types".'>🇪🇺</abbr> 🖖 🎏 🆎 🌐❔ 1️⃣ ⚖️ 🌅 👫 🚫 ☑ Pydantic 🆎, 🖼 👉 🔜 ❌ 👶:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003_04.py hl[10] *}
|
|
||||||
|
|
||||||
...👉 ❌ ↩️ 🆎 ✍ 🚫 Pydantic 🆎 & 🚫 👁 `Response` 🎓 ⚖️ 🏿, ⚫️ 🇪🇺 (🙆 2️⃣) 🖖 `Response` & `dict`.
|
|
||||||
|
|
||||||
### ❎ 📨 🏷
|
|
||||||
|
|
||||||
▶️ ⚪️➡️ 🖼 🔛, 👆 5️⃣📆 🚫 💚 ✔️ 🔢 💽 🔬, 🧾, 🖥, ♒️. 👈 🎭 FastAPI.
|
|
||||||
|
|
||||||
✋️ 👆 💪 💚 🚧 📨 🆎 ✍ 🔢 🤚 🐕🦺 ⚪️➡️ 🧰 💖 👨🎨 & 🆎 ☑ (✅ ✍).
|
|
||||||
|
|
||||||
👉 💼, 👆 💪 ❎ 📨 🏷 ⚡ ⚒ `response_model=None`:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial003_05.py hl[9] *}
|
|
||||||
|
|
||||||
👉 🔜 ⚒ FastAPI 🚶 📨 🏷 ⚡ & 👈 🌌 👆 💪 ✔️ 🙆 📨 🆎 ✍ 👆 💪 🍵 ⚫️ 🤕 👆 FastAPI 🈸. 👶
|
|
||||||
|
|
||||||
## 📨 🏷 🔢 🔢
|
|
||||||
|
|
||||||
👆 📨 🏷 💪 ✔️ 🔢 💲, 💖:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial004.py hl[11,13:14] *}
|
|
||||||
|
|
||||||
* `description: Union[str, None] = None` (⚖️ `str | None = None` 🐍 3️⃣.1️⃣0️⃣) ✔️ 🔢 `None`.
|
|
||||||
* `tax: float = 10.5` ✔️ 🔢 `10.5`.
|
|
||||||
* `tags: List[str] = []` 🔢 🛁 📇: `[]`.
|
|
||||||
|
|
||||||
✋️ 👆 💪 💚 🚫 👫 ⚪️➡️ 🏁 🚥 👫 🚫 🤙 🏪.
|
|
||||||
|
|
||||||
🖼, 🚥 👆 ✔️ 🏷 ⏮️ 📚 📦 🔢 ☁ 💽, ✋️ 👆 🚫 💚 📨 📶 📏 🎻 📨 🌕 🔢 💲.
|
|
||||||
|
|
||||||
### ⚙️ `response_model_exclude_unset` 🔢
|
|
||||||
|
|
||||||
👆 💪 ⚒ *➡ 🛠️ 👨🎨* 🔢 `response_model_exclude_unset=True`:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial004.py hl[24] *}
|
|
||||||
|
|
||||||
& 👈 🔢 💲 🏆 🚫 🔌 📨, 🕴 💲 🤙 ⚒.
|
|
||||||
|
|
||||||
, 🚥 👆 📨 📨 👈 *➡ 🛠️* 🏬 ⏮️ 🆔 `foo`, 📨 (🚫 ✅ 🔢 💲) 🔜:
|
|
||||||
|
|
||||||
```JSON
|
|
||||||
{
|
|
||||||
"name": "Foo",
|
|
||||||
"price": 50.2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
FastAPI ⚙️ Pydantic 🏷 `.dict()` ⏮️ <a href="https://docs.pydantic.dev/latest/concepts/serialization/#modeldict" class="external-link" target="_blank">🚮 `exclude_unset` 🔢</a> 🏆 👉.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
/// info
|
|
||||||
|
|
||||||
👆 💪 ⚙️:
|
|
||||||
|
|
||||||
* `response_model_exclude_defaults=True`
|
|
||||||
* `response_model_exclude_none=True`
|
|
||||||
|
|
||||||
🔬 <a href="https://docs.pydantic.dev/latest/concepts/serialization/#modeldict" class="external-link" target="_blank">Pydantic 🩺</a> `exclude_defaults` & `exclude_none`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
#### 📊 ⏮️ 💲 🏑 ⏮️ 🔢
|
|
||||||
|
|
||||||
✋️ 🚥 👆 📊 ✔️ 💲 🏷 🏑 ⏮️ 🔢 💲, 💖 🏬 ⏮️ 🆔 `bar`:
|
|
||||||
|
|
||||||
```Python hl_lines="3 5"
|
|
||||||
{
|
|
||||||
"name": "Bar",
|
|
||||||
"description": "The bartenders",
|
|
||||||
"price": 62,
|
|
||||||
"tax": 20.2
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
👫 🔜 🔌 📨.
|
|
||||||
|
|
||||||
#### 📊 ⏮️ 🎏 💲 🔢
|
|
||||||
|
|
||||||
🚥 📊 ✔️ 🎏 💲 🔢 🕐, 💖 🏬 ⏮️ 🆔 `baz`:
|
|
||||||
|
|
||||||
```Python hl_lines="3 5-6"
|
|
||||||
{
|
|
||||||
"name": "Baz",
|
|
||||||
"description": None,
|
|
||||||
"price": 50.2,
|
|
||||||
"tax": 10.5,
|
|
||||||
"tags": []
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
FastAPI 🙃 🥃 (🤙, Pydantic 🙃 🥃) 🤔 👈, ✋️ `description`, `tax`, & `tags` ✔️ 🎏 💲 🔢, 👫 ⚒ 🎯 (↩️ ✊ ⚪️➡️ 🔢).
|
|
||||||
|
|
||||||
, 👫 🔜 🔌 🎻 📨.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
👀 👈 🔢 💲 💪 🕳, 🚫 🕴 `None`.
|
|
||||||
|
|
||||||
👫 💪 📇 (`[]`), `float` `10.5`, ♒️.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
### `response_model_include` & `response_model_exclude`
|
|
||||||
|
|
||||||
👆 💪 ⚙️ *➡ 🛠️ 👨🎨* 🔢 `response_model_include` & `response_model_exclude`.
|
|
||||||
|
|
||||||
👫 ✊ `set` `str` ⏮️ 📛 🔢 🔌 (❎ 🎂) ⚖️ 🚫 (✅ 🎂).
|
|
||||||
|
|
||||||
👉 💪 ⚙️ ⏩ ⌨ 🚥 👆 ✔️ 🕴 1️⃣ Pydantic 🏷 & 💚 ❎ 💽 ⚪️➡️ 🔢.
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
✋️ ⚫️ 👍 ⚙️ 💭 🔛, ⚙️ 💗 🎓, ↩️ 👫 🔢.
|
|
||||||
|
|
||||||
👉 ↩️ 🎻 🔗 🏗 👆 📱 🗄 (& 🩺) 🔜 1️⃣ 🏁 🏷, 🚥 👆 ⚙️ `response_model_include` ⚖️ `response_model_exclude` 🚫 🔢.
|
|
||||||
|
|
||||||
👉 ✔ `response_model_by_alias` 👈 👷 ➡.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial005.py hl[31,37] *}
|
|
||||||
|
|
||||||
/// tip
|
|
||||||
|
|
||||||
❕ `{"name", "description"}` ✍ `set` ⏮️ 📚 2️⃣ 💲.
|
|
||||||
|
|
||||||
⚫️ 🌓 `set(["name", "description"])`.
|
|
||||||
|
|
||||||
///
|
|
||||||
|
|
||||||
#### ⚙️ `list`Ⓜ ↩️ `set`Ⓜ
|
|
||||||
|
|
||||||
🚥 👆 💭 ⚙️ `set` & ⚙️ `list` ⚖️ `tuple` ↩️, FastAPI 🔜 🗜 ⚫️ `set` & ⚫️ 🔜 👷 ☑:
|
|
||||||
|
|
||||||
{* ../../docs_src/response_model/tutorial006.py hl[31,37] *}
|
|
||||||
|
|
||||||
## 🌃
|
|
||||||
|
|
||||||
⚙️ *➡ 🛠️ 👨🎨* 🔢 `response_model` 🔬 📨 🏷 & ✴️ 🚚 📢 💽 ⛽ 👅.
|
|
||||||
|
|
||||||
⚙️ `response_model_exclude_unset` 📨 🕴 💲 🎯 ⚒.
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue