mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-26 07:40:57 -05:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d00af00d3f | ||
|
|
b69a9f3b6f | ||
|
|
51b625e127 | ||
|
|
48b36f26d8 | ||
|
|
3a4ac24675 | ||
|
|
22bf988dfb | ||
|
|
6935fe8d38 | ||
|
|
8f03716757 | ||
|
|
d0ce9d2bdf | ||
|
|
705659bb22 | ||
|
|
4f3381a95e | ||
|
|
38ff43b690 | ||
|
|
2fe05762b2 | ||
|
|
34e6e63fb2 | ||
|
|
2d34086b70 | ||
|
|
f4dfbae903 | ||
|
|
e8322228b4 | ||
|
|
6ba8407ff3 | ||
|
|
63ae0f1070 | ||
|
|
f0866bc205 | ||
|
|
ae97785ded | ||
|
|
bcd737de33 | ||
|
|
98712b9e09 | ||
|
|
0e77481acf | ||
|
|
6ebaf0efcb | ||
|
|
4f1eb0cd9e | ||
|
|
0da0814d8a | ||
|
|
9bfc48ad9f | ||
|
|
882f77f925 | ||
|
|
85cded53c8 | ||
|
|
066ea10ac5 | ||
|
|
ff1118d6a0 | ||
|
|
6aa0435a3e | ||
|
|
659350e9cd | ||
|
|
980c88c347 | ||
|
|
3a3ad5d66d | ||
|
|
6433c3b70e | ||
|
|
4a7f6e0ae6 | ||
|
|
263e46e540 | ||
|
|
957d747d21 | ||
|
|
8b05d4518b | ||
|
|
8a146b7a28 | ||
|
|
beedc72281 | ||
|
|
8c85b8f4aa | ||
|
|
9c9cccef0c | ||
|
|
7ed9a4971e | ||
|
|
daf4970ed7 | ||
|
|
be7e7d4433 | ||
|
|
29babdc0a1 | ||
|
|
46412ff67d | ||
|
|
2e0f74f58b | ||
|
|
ff8fcd3b44 | ||
|
|
9a939dec47 | ||
|
|
f79247b4e5 | ||
|
|
46d0ffc0d7 | ||
|
|
fd5c00ab76 | ||
|
|
9f78e08c14 | ||
|
|
c81f575d0d | ||
|
|
a3f42718de | ||
|
|
10eee5c3b3 | ||
|
|
a51a98b07e | ||
|
|
0aaaed581e | ||
|
|
e8f7bf0ad5 | ||
|
|
a0c529ef0a | ||
|
|
470f1ae57d | ||
|
|
8809b3685f | ||
|
|
3c8d0abc87 | ||
|
|
265dbeb663 | ||
|
|
4636c621a9 | ||
|
|
2cb1333b97 | ||
|
|
366bdebd9e | ||
|
|
86c8f4fc2b |
6
.github/actions/people/app/main.py
vendored
6
.github/actions/people/app/main.py
vendored
@@ -515,9 +515,9 @@ def get_individual_sponsors(settings: Settings):
|
||||
|
||||
tiers: DefaultDict[float, Dict[str, SponsorEntity]] = defaultdict(dict)
|
||||
for node in nodes:
|
||||
tiers[node.tier.monthlyPriceInDollars][
|
||||
node.sponsorEntity.login
|
||||
] = node.sponsorEntity
|
||||
tiers[node.tier.monthlyPriceInDollars][node.sponsorEntity.login] = (
|
||||
node.sponsorEntity
|
||||
)
|
||||
return tiers
|
||||
|
||||
|
||||
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -117,7 +117,7 @@ jobs:
|
||||
- run: ls -la coverage
|
||||
- run: coverage combine coverage
|
||||
- run: coverage report
|
||||
- run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}"
|
||||
- run: coverage html --title "Coverage for ${{ github.sha }}"
|
||||
- name: Store coverage HTML
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,7 +7,7 @@ __pycache__
|
||||
htmlcov
|
||||
dist
|
||||
site
|
||||
.coverage
|
||||
.coverage*
|
||||
coverage.xml
|
||||
.netlify
|
||||
test.db
|
||||
|
||||
@@ -4,7 +4,7 @@ default_language_version:
|
||||
python: python3.10
|
||||
repos:
|
||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||
rev: v4.4.0
|
||||
rev: v4.6.0
|
||||
hooks:
|
||||
- id: check-added-large-files
|
||||
- id: check-toml
|
||||
@@ -13,8 +13,8 @@ repos:
|
||||
- --unsafe
|
||||
- id: end-of-file-fixer
|
||||
- id: trailing-whitespace
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
rev: v0.2.0
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.6.1
|
||||
hooks:
|
||||
- id: ruff
|
||||
args:
|
||||
|
||||
@@ -132,6 +132,8 @@ FastAPI stands on the shoulders of giants:
|
||||
|
||||
## Installation
|
||||
|
||||
Create and activate a <a href="https://fastapi.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install FastAPI:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
@@ -462,7 +464,7 @@ When you install FastAPI with `pip install "fastapi[standard]"` it comes the `st
|
||||
|
||||
Used by Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - for email validation.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - for email validation.
|
||||
|
||||
Used by Starlette:
|
||||
|
||||
|
||||
@@ -1,185 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI İnsanlar
|
||||
|
||||
FastAPI-ın bütün mənşəli insanları qəbul edən heyrətamiz icması var.
|
||||
|
||||
|
||||
|
||||
## Yaradıcı - İcraçı
|
||||
|
||||
Salam! 👋
|
||||
|
||||
Bu mənəm:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cavablar: {{ user.answers }}</div><div class="count">Pull Request-lər: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Mən **FastAPI**-ın yaradıcısı və icraçısıyam. Əlavə məlumat almaq üçün [Yardım FastAPI - Yardım alın - Müəlliflə əlaqə qurun](help-fastapi.md#connect-with-the-author){.internal-link target=_blank} səhifəsinə baxa bilərsiniz.
|
||||
|
||||
...Burada isə sizə icmanı göstərmək istəyirəm.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** icmadan çoxlu dəstək alır və mən onların əməyini vurğulamaq istəyirəm.
|
||||
|
||||
Bu insanlar:
|
||||
|
||||
* [GitHub-da başqalarının suallarına kömək edirlər](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank}.
|
||||
* [Pull Request-lər yaradırlar](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
|
||||
* Pull Request-ləri ([xüsusilə tərcümələr üçün vacib olan](contributing.md#translations){.internal-link target=_blank}.) nəzərdən keçirirlər.
|
||||
|
||||
Bu insanlara təşəkkür edirəm. 👏 🙇
|
||||
|
||||
## Keçən ayın ən fəal istifadəçiləri
|
||||
|
||||
Bu istifadəçilər keçən ay [GitHub-da başqalarının suallarına](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} ən çox kömək edənlərdir. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cavablandırılmış suallar: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Mütəxəssislər
|
||||
|
||||
Burada **FastAPI Mütəxəssisləri** var. 🤓
|
||||
|
||||
Bu istifadəçilər indiyə qədər [GitHub-da başqalarının suallarına](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} ən çox kömək edənlərdir.
|
||||
|
||||
Onlar bir çox insanlara kömək edərək mütəxəssis olduqlarını sübut ediblər. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cavablandırılmış suallar: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Ən yaxşı əməkdaşlar
|
||||
|
||||
Burada **Ən yaxşı əməkdaşlar** var. 👷
|
||||
|
||||
Bu istifadəçilərin ən çox *birləşdirilmiş* [Pull Request-ləri var](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
|
||||
|
||||
Onlar mənbə kodu, sənədləmə, tərcümələr və s. barədə əmək göstərmişlər. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Request-lər: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Bundan başqa bir neçə (yüzdən çox) əməkdaş var ki, onları <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI GitHub Əməkdaşlar səhifəsində</a> görə bilərsiniz. 👷
|
||||
|
||||
## Ən çox rəy verənlər
|
||||
|
||||
Bu istifadəçilər **ən çox rəy verənlər**dir.
|
||||
|
||||
### Tərcümələr üçün rəylər
|
||||
|
||||
Mən yalnız bir neçə dildə danışıram (və çox da yaxşı deyil 😅). Bu səbəbdən, rəy verənlər sənədlərin [**tərcümələrini təsdiqləmək üçün gücə malik olanlar**](contributing.md#translations){.internal-link target=_blank}dır. Onlar olmadan, bir çox dilə tərcümə olunmuş sənədlər olmazdı.
|
||||
|
||||
---
|
||||
|
||||
Başqalarının Pull Request-lərinə **Ən çox rəy verənlər** 🕵️ kodun, sənədlərin və xüsusilə də **tərcümələrin** keyfiyyətini təmin edirlər.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Rəylər: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsorlar
|
||||
|
||||
Bunlar **Sponsorlar**dır. 😎
|
||||
|
||||
Onlar mənim **FastAPI** (və digər) işlərimi əsasən <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsorlar</a> vasitəsilə dəstəkləyirlər.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Qızıl Sponsorlar
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Gümüş Sponsorlar
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Bürünc Sponsorlar
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### Fərdi Sponsorlar
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## Məlumatlar haqqında - texniki detallar
|
||||
|
||||
Bu səhifənin əsas məqsədi, icmanın başqalarına kömək etmək üçün göstərdiyi əməyi vurğulamaqdır.
|
||||
|
||||
Xüsusilə də normalda daha az görünən və bir çox hallarda daha çətin olan, başqalarının suallarına kömək etmək və tərcümələrlə bağlı Pull Request-lərə rəy vermək kimi səy göstərmək.
|
||||
|
||||
Bu səhifənin məlumatları hər ay hesablanır və siz <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">buradan mənbə kodunu</a> oxuya bilərsiniz.
|
||||
|
||||
Burada sponsorların əməyini də vurğulamaq istəyirəm.
|
||||
|
||||
Mən həmçinin alqoritmi, bölmələri, eşikləri və s. yeniləmək hüququnu da qoruyuram (hər ehtimala qarşı 🤷).
|
||||
@@ -442,7 +442,7 @@ Müstəqil TechEmpower meyarları göstərir ki, Uvicorn üzərində işləyən
|
||||
|
||||
Pydantic tərəfindən istifadə olunanlar:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - e-poçtun yoxlanılması üçün.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - e-poçtun yoxlanılması üçün.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" target="_blank"><code>pydantic-settings</code></a> - parametrlərin idarə edilməsi üçün.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/" target="_blank"><code>pydantic-extra-types</code></a> - Pydantic ilə istifadə edilə bilən əlavə tiplər üçün.
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ item: Item
|
||||
|
||||
Pydantic দ্বারা ব্যবহৃত:
|
||||
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - ইমেল যাচাইকরণের জন্য।
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - ইমেল যাচাইকরণের জন্য।
|
||||
|
||||
স্টারলেট দ্বারা ব্যবহৃত:
|
||||
|
||||
|
||||
@@ -95,7 +95,6 @@ Es gibt viele andere ASGI-Middlewares.
|
||||
|
||||
Zum Beispiel:
|
||||
|
||||
* <a href="https://docs.sentry.io/platforms/python/guides/fastapi/" class="external-link" target="_blank">Sentry</a>
|
||||
* <a href="https://github.com/encode/uvicorn/blob/master/uvicorn/middleware/proxy_headers.py" class="external-link" target="_blank">Uvicorns `ProxyHeadersMiddleware`</a>
|
||||
* <a href="https://github.com/florimondmanca/msgpack-asgi" class="external-link" target="_blank">MessagePack</a>
|
||||
|
||||
|
||||
@@ -1,176 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI Leute
|
||||
|
||||
FastAPI hat eine großartige Gemeinschaft, die Menschen mit unterschiedlichstem Hintergrund willkommen heißt.
|
||||
|
||||
## Erfinder - Betreuer
|
||||
|
||||
Hey! 👋
|
||||
|
||||
Das bin ich:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Answers: {{ user.answers }}</div><div class="count">Pull Requests: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Ich bin der Erfinder und Betreuer von **FastAPI**. Sie können mehr darüber in [FastAPI helfen – Hilfe erhalten – Mit dem Autor vernetzen](help-fastapi.md#mit-dem-autor-vernetzen){.internal-link target=_blank} erfahren.
|
||||
|
||||
... Aber hier möchte ich Ihnen die Gemeinschaft vorstellen.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** erhält eine Menge Unterstützung aus der Gemeinschaft. Und ich möchte ihre Beiträge hervorheben.
|
||||
|
||||
Das sind die Menschen, die:
|
||||
|
||||
* [Anderen bei Fragen auf GitHub helfen](help-fastapi.md#anderen-bei-fragen-auf-github-helfen){.internal-link target=_blank}.
|
||||
* [<abbr title='Pull Request – „Zieh-Anfrage“: Geänderten Quellcode senden, mit dem Vorschlag, ihn mit dem aktuellen Quellcode zu verschmelzen'>Pull Requests</abbr> erstellen](help-fastapi.md#einen-pull-request-erstellen){.internal-link target=_blank}.
|
||||
* Pull Requests überprüfen (Review), [besonders wichtig für Übersetzungen](contributing.md#ubersetzungen){.internal-link target=_blank}.
|
||||
|
||||
Eine Runde Applaus für sie. 👏 🙇
|
||||
|
||||
## Aktivste Benutzer im letzten Monat
|
||||
|
||||
Hier die Benutzer, die im letzten Monat am meisten [anderen mit Fragen auf Github](help-fastapi.md#anderen-bei-fragen-auf-github-helfen){.internal-link target=_blank} geholfen haben. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_active %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Fragen beantwortet: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Experten
|
||||
|
||||
Hier die **FastAPI-Experten**. 🤓
|
||||
|
||||
Das sind die Benutzer, die *insgesamt* [anderen am meisten mit Fragen auf GitHub geholfen haben](help-fastapi.md#anderen-bei-fragen-auf-github-helfen){.internal-link target=_blank}.
|
||||
|
||||
Sie haben bewiesen, dass sie Experten sind, weil sie vielen anderen geholfen haben. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Fragen beantwortet: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Top-Mitwirkende
|
||||
|
||||
Hier sind die **Top-Mitwirkenden**. 👷
|
||||
|
||||
Diese Benutzer haben [die meisten Pull Requests erstellt](help-fastapi.md#einen-pull-request-erstellen){.internal-link target=_blank} welche *<abbr title="Mergen – Zusammenführen: Unterschiedliche Versionen eines Quellcodes zusammenführen">gemerged</abbr>* wurden.
|
||||
|
||||
Sie haben Quellcode, Dokumentation, Übersetzungen, usw. beigesteuert. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requests: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Es gibt viele andere Mitwirkende (mehr als hundert), Sie können sie alle auf der <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI GitHub Contributors-Seite</a> sehen. 👷
|
||||
|
||||
## Top-Rezensenten
|
||||
|
||||
Diese Benutzer sind die **Top-Rezensenten**. 🕵️
|
||||
|
||||
### Rezensionen für Übersetzungen
|
||||
|
||||
Ich spreche nur ein paar Sprachen (und nicht sehr gut 😅). Daher bestätigen Reviewer [**Übersetzungen der Dokumentation**](contributing.md#ubersetzungen){.internal-link target=_blank}. Ohne sie gäbe es keine Dokumentation in mehreren anderen Sprachen.
|
||||
|
||||
---
|
||||
|
||||
Die **Top-Reviewer** 🕵️ haben die meisten Pull Requests von anderen überprüft und stellen die Qualität des Codes, der Dokumentation und insbesondere der **Übersetzungen** sicher.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_reviewers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Reviews: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsoren
|
||||
|
||||
Dies sind die **Sponsoren**. 😎
|
||||
|
||||
Sie unterstützen meine Arbeit an **FastAPI** (und andere), hauptsächlich durch <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub-Sponsoren</a>.
|
||||
|
||||
### Gold Sponsoren
|
||||
|
||||
{% if sponsors %}
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
### Silber Sponsoren
|
||||
|
||||
{% if sponsors %}
|
||||
{% for sponsor in sponsors.silver -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if people %}
|
||||
{% if people.sponsors_50 %}
|
||||
|
||||
### Bronze Sponsoren
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.sponsors_50 %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
### Individuelle Sponsoren
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.sponsors %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Über diese Daten - technische Details
|
||||
|
||||
Der Hauptzweck dieser Seite ist es zu zeigen, wie die Gemeinschaft anderen hilft.
|
||||
|
||||
Das beinhaltet auch Hilfe, die normalerweise weniger sichtbar und in vielen Fällen mühsamer ist, wie, anderen bei Problemen zu helfen und Pull Requests mit Übersetzungen zu überprüfen.
|
||||
|
||||
Diese Daten werden jeden Monat berechnet, Sie können den <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">Quellcode hier lesen</a>.
|
||||
|
||||
Hier weise ich auch auf Beiträge von Sponsoren hin.
|
||||
|
||||
Ich behalte mir auch das Recht vor, den Algorithmus, die Abschnitte, die Schwellenwerte usw. zu aktualisieren (nur für den Fall 🤷).
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
### Basiert auf offenen Standards
|
||||
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>OpenAPI</strong></a> für die Erstellung von APIs, inklusive Deklarationen von <abbr title="auch genannt Endpunkte, Routen">Pfad</abbr>-<abbr title="gemeint sind HTTP-Methoden wie POST, GET, PUT, DELETE">Operationen</abbr>, Parametern, Body-Anfragen, Sicherheit, usw.
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>OpenAPI</strong></a> für die Erstellung von APIs, inklusive Deklarationen von <abbr title="auch genannt Endpunkte, Routen">Pfad</abbr>-<abbr title="gemeint sind HTTP-Methoden wie POST, GET, PUT, DELETE">Operationen</abbr>, Parametern, Requestbodys, Sicherheit, usw.
|
||||
* Automatische Dokumentation der Datenmodelle mit <a href="https://json-schema.org/" class="external-link" target="_blank"><strong>JSON Schema</strong></a> (da OpenAPI selbst auf JSON Schema basiert).
|
||||
* Um diese Standards herum entworfen, nach sorgfältigem Studium. Statt einer nachträglichen Schicht darüber.
|
||||
* Dies ermöglicht auch automatische **Client-Code-Generierung** in vielen Sprachen.
|
||||
|
||||
@@ -449,7 +449,7 @@ Um mehr darüber zu erfahren, siehe den Abschnitt <a href="https://fastapi.tiang
|
||||
|
||||
Wird von Pydantic verwendet:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - für E-Mail-Validierung.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - für E-Mail-Validierung.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" target="_blank"><code>pydantic-settings</code></a> - für die Verwaltung von Einstellungen.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/" target="_blank"><code>pydantic-extra-types</code></a> - für zusätzliche Typen, mit Pydantic zu verwenden.
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ Im Folgenden deklarieren wir ein `UserIn`-Modell; es enthält ein Klartext-Passw
|
||||
|
||||
/// info
|
||||
|
||||
Um `EmailStr` zu verwenden, installieren Sie zuerst <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email_validator`</a>.
|
||||
Um `EmailStr` zu verwenden, installieren Sie zuerst <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email-validator`</a>.
|
||||
|
||||
Z. B. `pip install email-validator`
|
||||
oder `pip install pydantic[email]`.
|
||||
|
||||
@@ -95,7 +95,6 @@ app.add_middleware(UnicornMiddleware, some_config="rainbow")
|
||||
|
||||
🖼:
|
||||
|
||||
* <a href="https://docs.sentry.io/platforms/python/asgi/" class="external-link" target="_blank">🔫</a>
|
||||
* <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>
|
||||
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI 👫👫
|
||||
|
||||
FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
|
||||
## 👼 - 🐛
|
||||
|
||||
🙋 ❗ 👶
|
||||
|
||||
👉 👤:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">❔: {{ user.answers }}</div><div class="count">🚲 📨: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
👤 👼 & 🐛 **FastAPI**. 👆 💪 ✍ 🌅 🔃 👈 [ℹ FastAPI - 🤚 ℹ - 🔗 ⏮️ 📕](help-fastapi.md#_3){.internal-link target=_blank}.
|
||||
|
||||
...✋️ 📥 👤 💚 🎦 👆 👪.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** 📨 📚 🐕🦺 ⚪️➡️ 👪. & 👤 💚 🎦 👫 💰.
|
||||
|
||||
👫 👫👫 👈:
|
||||
|
||||
* [ℹ 🎏 ⏮️ ❔ 📂](help-fastapi.md#i){.internal-link target=_blank}.
|
||||
* [✍ 🚲 📨](help-fastapi.md#_15){.internal-link target=_blank}.
|
||||
* 📄 🚲 📨, [✴️ ⚠ ✍](contributing.md#_9){.internal-link target=_blank}.
|
||||
|
||||
👏 👫. 👶 👶
|
||||
|
||||
## 🌅 🦁 👩💻 🏁 🗓️
|
||||
|
||||
👫 👩💻 👈 ✔️ [🤝 🎏 🏆 ⏮️ ❔ 📂](help-fastapi.md#i){.internal-link target=_blank} ⏮️ 🏁 🗓️. 👶
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">❔ 📨: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## 🕴
|
||||
|
||||
📥 **FastAPI 🕴**. 👶
|
||||
|
||||
👫 👩💻 👈 ✔️ [ℹ 🎏 🏆 ⏮️ ❔ 📂](help-fastapi.md#i){.internal-link target=_blank} 🔘 *🌐 🕰*.
|
||||
|
||||
👫 ✔️ 🎦 🕴 🤝 📚 🎏. 👶
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">❔ 📨: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## 🔝 👨🔬
|
||||
|
||||
📥 **🔝 👨🔬**. 👶
|
||||
|
||||
👉 👩💻 ✔️ [✍ 🏆 🚲 📨](help-fastapi.md#_15){.internal-link target=_blank} 👈 ✔️ *🔗*.
|
||||
|
||||
👫 ✔️ 📉 ℹ 📟, 🧾, ✍, ♒️. 👶
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">🚲 📨: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
📤 📚 🎏 👨🔬 (🌅 🌘 💯), 👆 💪 👀 👫 🌐 <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI 📂 👨🔬 📃</a>. 👶
|
||||
|
||||
## 🔝 👨🔬
|
||||
|
||||
👫 👩💻 **🔝 👨🔬**. 👶 👶
|
||||
|
||||
### 📄 ✍
|
||||
|
||||
👤 🕴 💬 👩❤👨 🇪🇸 (& 🚫 📶 👍 👶). , 👨🔬 🕐 👈 ✔️ [**🏋️ ✔ ✍**](contributing.md#_9){.internal-link target=_blank} 🧾. 🍵 👫, 📤 🚫🔜 🧾 📚 🎏 🇪🇸.
|
||||
|
||||
---
|
||||
|
||||
**🔝 👨🔬** 👶 👶 ✔️ 📄 🏆 🚲 📨 ⚪️➡️ 🎏, 🚚 🔆 📟, 🧾, & ✴️, **✍**.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">📄: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## 💰
|
||||
|
||||
👫 **💰**. 👶
|
||||
|
||||
👫 🔗 👇 👷 ⏮️ **FastAPI** (& 🎏), ✴️ 🔘 <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">📂 💰</a>.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### 🌟 💰
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### 🥇1st 💰
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### 🥈2nd 💰
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### 🎯 💰
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## 🔃 📊 - 📡 ℹ
|
||||
|
||||
👑 🎯 👉 📃 🎦 🎯 👪 ℹ 🎏.
|
||||
|
||||
✴️ ✅ 🎯 👈 🛎 🌘 ⭐, & 📚 💼 🌅 😩, 💖 🤝 🎏 ⏮️ ❔ & ⚖ 🚲 📨 ⏮️ ✍.
|
||||
|
||||
💽 ⚖ 🔠 🗓️, 👆 💪 ✍ <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">ℹ 📟 📥</a>.
|
||||
|
||||
📥 👤 🎦 💰 ⚪️➡️ 💰.
|
||||
|
||||
👤 🏦 ▶️️ ℹ 📊, 📄, ⚡, ♒️ (💼 🤷).
|
||||
@@ -451,7 +451,7 @@ item: Item
|
||||
|
||||
⚙️ Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - 📧 🔬.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - 📧 🔬.
|
||||
|
||||
⚙️ 💃:
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ FastAPI 🔜 ⚙️ 👉 `response_model` 🌐 💽 🧾, 🔬, ♒️. & **
|
||||
|
||||
/// info
|
||||
|
||||
⚙️ `EmailStr`, 🥇 ❎ <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email_validator`</a>.
|
||||
⚙️ `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]`.
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
members:
|
||||
- login: tiangolo
|
||||
avatar_url: https://github.com/tiangolo.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/1326112
|
||||
url: https://github.com/tiangolo
|
||||
- login: Kludex
|
||||
avatar_url: https://github.com/Kludex.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/7353520
|
||||
url: https://github.com/Kludex
|
||||
- login: alejsdev
|
||||
avatar_url: https://github.com/alejsdev.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/90076947
|
||||
url: https://github.com/alejsdev
|
||||
- login: svlandeg
|
||||
avatar_url: https://github.com/svlandeg.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/8796347
|
||||
url: https://github.com/svlandeg
|
||||
- login: estebanx64
|
||||
avatar_url: https://github.com/estebanx64.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/10840422
|
||||
url: https://github.com/estebanx64
|
||||
- login: patrick91
|
||||
avatar_url: https://github.com/patrick91.png
|
||||
avatar_url: https://avatars.githubusercontent.com/u/667029
|
||||
url: https://github.com/patrick91
|
||||
|
||||
@@ -40,7 +40,7 @@ Keep in mind that you have to return the `JSONResponse` directly.
|
||||
|
||||
The `model` key is not part of OpenAPI.
|
||||
|
||||
**FastAPI** will take the Pydantic model from there, generate the `JSON Schema`, and put it in the correct place.
|
||||
**FastAPI** will take the Pydantic model from there, generate the JSON Schema, and put it in the correct place.
|
||||
|
||||
The correct place is:
|
||||
|
||||
@@ -251,5 +251,5 @@ For example:
|
||||
|
||||
To see what exactly you can include in the responses, you can check these sections in the OpenAPI specification:
|
||||
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responsesObject" class="external-link" target="_blank">OpenAPI Responses Object</a>, it includes the `Response Object`.
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responseObject" class="external-link" target="_blank">OpenAPI Response Object</a>, you can include anything from this directly in each response inside your `responses` parameter. Including `description`, `headers`, `content` (inside of this is that you declare different media types and JSON Schemas), and `links`.
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#responses-object" class="external-link" target="_blank">OpenAPI Responses Object</a>, it includes the `Response Object`.
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.1.0.md#response-object" class="external-link" target="_blank">OpenAPI Response Object</a>, you can include anything from this directly in each response inside your `responses` parameter. Including `description`, `headers`, `content` (inside of this is that you declare different media types and JSON Schemas), and `links`.
|
||||
|
||||
@@ -211,7 +211,7 @@ Now create that other file `routes.toml`:
|
||||
|
||||
This file configures Traefik to use the path prefix `/api/v1`.
|
||||
|
||||
And then it will redirect its requests to your Uvicorn running on `http://127.0.0.1:8000`.
|
||||
And then Traefik will redirect its requests to your Uvicorn running on `http://127.0.0.1:8000`.
|
||||
|
||||
Now start Traefik:
|
||||
|
||||
|
||||
@@ -255,11 +255,11 @@ This includes many libraries to interact with cloud storage, video processing, a
|
||||
|
||||
1. This is the generator function. It's a "generator function" because it contains `yield` statements inside.
|
||||
2. By using a `with` block, we make sure that the file-like object is closed after the generator function is done. So, after it finishes sending the response.
|
||||
3. This `yield from` tells the function to iterate over that thing named `file_like`. And then, for each part iterated, yield that part as coming from this generator function.
|
||||
3. This `yield from` tells the function to iterate over that thing named `file_like`. And then, for each part iterated, yield that part as coming from this generator function (`iterfile`).
|
||||
|
||||
So, it is a generator function that transfers the "generating" work to something else internally.
|
||||
|
||||
By doing it this way, we can put it in a `with` block, and that way, ensure that it is closed after finishing.
|
||||
By doing it this way, we can put it in a `with` block, and that way, ensure that the file-like object is closed after finishing.
|
||||
|
||||
/// tip
|
||||
|
||||
|
||||
@@ -88,6 +88,7 @@ The middleware will handle both standard and streaming responses.
|
||||
The following arguments are supported:
|
||||
|
||||
* `minimum_size` - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to `500`.
|
||||
* `compresslevel` - Used during GZip compression. It is an integer ranging from 1 to 9. Defaults to `9`. Lower value results in faster compression but larger file sizes, while higher value results in slower compression but smaller file sizes.
|
||||
|
||||
## Other middlewares
|
||||
|
||||
@@ -95,7 +96,6 @@ There are many other ASGI middlewares.
|
||||
|
||||
For example:
|
||||
|
||||
* <a href="https://docs.sentry.io/platforms/python/guides/fastapi/" class="external-link" target="_blank">Sentry</a>
|
||||
* <a href="https://github.com/encode/uvicorn/blob/master/uvicorn/middleware/proxy_headers.py" class="external-link" target="_blank">Uvicorn's `ProxyHeadersMiddleware`</a>
|
||||
* <a href="https://github.com/florimondmanca/msgpack-asgi" class="external-link" target="_blank">MessagePack</a>
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ This part is pretty normal, most of the code is probably already familiar to you
|
||||
|
||||
/// tip
|
||||
|
||||
The `callback_url` query parameter uses a Pydantic <a href="https://docs.pydantic.dev/latest/concepts/types/#urls" class="external-link" target="_blank">URL</a> type.
|
||||
The `callback_url` query parameter uses a Pydantic <a href="https://docs.pydantic.dev/latest/api/networks/" class="external-link" target="_blank">Url</a> type.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ Now, let's see how you could use that to return a custom response.
|
||||
|
||||
Let's say that you want to return an <a href="https://en.wikipedia.org/wiki/XML" class="external-link" target="_blank">XML</a> response.
|
||||
|
||||
You could put your XML content in a string, put it in a `Response`, and return it:
|
||||
You could put your XML content in a string, put that in a `Response`, and return it:
|
||||
|
||||
```Python hl_lines="1 18"
|
||||
{!../../../docs_src/response_directly/tutorial002.py!}
|
||||
|
||||
@@ -398,7 +398,7 @@ Now update the dependency `get_current_user`.
|
||||
|
||||
This is the one used by the dependencies above.
|
||||
|
||||
Here's were we are using the same OAuth2 scheme we created before, declaring it as a dependency: `oauth2_scheme`.
|
||||
Here's where we are using the same OAuth2 scheme we created before, declaring it as a dependency: `oauth2_scheme`.
|
||||
|
||||
Because this dependency function doesn't have any scope requirements itself, we can use `Depends` with `oauth2_scheme`, we don't have to use `Security` when we don't need to specify security scopes.
|
||||
|
||||
@@ -725,7 +725,7 @@ Here's how the hierarchy of dependencies and scopes looks like:
|
||||
* This `security_scopes` parameter has a property `scopes` with a `list` containing all these scopes declared above, so:
|
||||
* `security_scopes.scopes` will contain `["me", "items"]` for the *path operation* `read_own_items`.
|
||||
* `security_scopes.scopes` will contain `["me"]` for the *path operation* `read_users_me`, because it is declared in the dependency `get_current_active_user`.
|
||||
* `security_scopes.scopes` will contain `[]` (nothing) for the *path operation* `read_system_status`, because it didn't declare any `Security` with `scopes`, and its dependency, `get_current_user`, doesn't declare any `scope` either.
|
||||
* `security_scopes.scopes` will contain `[]` (nothing) for the *path operation* `read_system_status`, because it didn't declare any `Security` with `scopes`, and its dependency, `get_current_user`, doesn't declare any `scopes` either.
|
||||
|
||||
/// tip
|
||||
|
||||
|
||||
@@ -6,143 +6,25 @@ Most of these settings are variable (can change), like database URLs. And many c
|
||||
|
||||
For this reason it's common to provide them in environment variables that are read by the application.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
/// tip
|
||||
|
||||
If you already know what "environment variables" are and how to use them, feel free to skip to the next section below.
|
||||
To understand environment variables you can read [Environment Variables](../environment-variables.md){.internal-link target=_blank}.
|
||||
|
||||
///
|
||||
|
||||
An <a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">environment variable</a> (also known as "env var") is a variable that lives outside of the Python code, in the operating system, and could be read by your Python code (or by other programs as well).
|
||||
|
||||
You can create and use environment variables in the shell, without needing Python:
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<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 | Windows PowerShell
|
||||
|
||||
<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>
|
||||
|
||||
////
|
||||
|
||||
### Read env vars in Python
|
||||
|
||||
You could also create environment variables outside of Python, in the terminal (or with any other method), and then read them in Python.
|
||||
|
||||
For example you could have a file `main.py` with:
|
||||
|
||||
```Python hl_lines="3"
|
||||
import os
|
||||
|
||||
name = os.getenv("MY_NAME", "World")
|
||||
print(f"Hello {name} from Python")
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
||||
The second argument to <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> is the default value to return.
|
||||
|
||||
If not provided, it's `None` by default, here we provide `"World"` as the default value to use.
|
||||
|
||||
///
|
||||
|
||||
Then you could call that Python program:
|
||||
|
||||
<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>
|
||||
|
||||
As environment variables can be set outside of the code, but can be read by the code, and don't have to be stored (committed to `git`) with the rest of the files, it's common to use them for configurations or settings.
|
||||
|
||||
You can also create an environment variable only for a specific program invocation, that is only available to that program, and only for its duration.
|
||||
|
||||
To do that, create it right before the program itself, on the same line:
|
||||
|
||||
<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
|
||||
|
||||
You can read more about it at <a href="https://12factor.net/config" class="external-link" target="_blank">The Twelve-Factor App: Config</a>.
|
||||
|
||||
///
|
||||
|
||||
### Types and validation
|
||||
## Types and validation
|
||||
|
||||
These environment variables can only handle text strings, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).
|
||||
|
||||
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or validation has to be done in code.
|
||||
That means that any value read in Python from an environment variable will be a `str`, and any conversion to a different type or any validation has to be done in code.
|
||||
|
||||
## Pydantic `Settings`
|
||||
|
||||
Fortunately, Pydantic provides a great utility to handle these settings coming from environment variables with <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" class="external-link" target="_blank">Pydantic: Settings management</a>.
|
||||
Fortunately, Pydantic provides a great utility to handle these settings coming from environment variables with <a href="https://docs.pydantic.dev/latest/concepts/pydantic_settings/" class="external-link" target="_blank">Pydantic: Settings management</a>.
|
||||
|
||||
### Install `pydantic-settings`
|
||||
|
||||
First, install the `pydantic-settings` package:
|
||||
First, make sure you create your [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install the `pydantic-settings` package:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -411,7 +293,7 @@ And then update your `config.py` with:
|
||||
|
||||
/// tip
|
||||
|
||||
The `model_config` attribute is used just for Pydantic configuration. You can read more at <a href="https://docs.pydantic.dev/latest/usage/model_config/" class="external-link" target="_blank">Pydantic Model Config</a>.
|
||||
The `model_config` attribute is used just for Pydantic configuration. You can read more at <a href="https://docs.pydantic.dev/latest/concepts/config/" class="external-link" target="_blank">Pydantic: Concepts: Configuration</a>.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ There are utilities to configure it easily that you can use directly in your **F
|
||||
|
||||
## Install dependencies
|
||||
|
||||
Install `jinja2`:
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and install `jinja2`:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ You can use <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSockets
|
||||
|
||||
## Install `WebSockets`
|
||||
|
||||
First you need to install `WebSockets`:
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and install `websockets`:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
@@ -369,6 +369,8 @@ In particular, you can directly use <a href="https://anyio.readthedocs.io/en/sta
|
||||
|
||||
And even if you were not using FastAPI, you could also write your own async applications with <a href="https://anyio.readthedocs.io/en/stable/" class="external-link" target="_blank">AnyIO</a> to be highly compatible and get its benefits (e.g. *structured concurrency*).
|
||||
|
||||
I created another library on top of AnyIO, as a thin layer on top, to improve a bit the type annotations and get better **autocompletion**, **inline errors**, etc. It also has a friendly introduction and tutorial to help you **understand** and write **your own async code**: <a href="https://asyncer.tiangolo.com/" class="external-link" target="_blank">Asyncer</a>. It would be particularly useful if you need to **combine async code with regular** (blocking/synchronous) code.
|
||||
|
||||
### Other forms of asynchronous code
|
||||
|
||||
This style of using `async` and `await` is relatively new in the language.
|
||||
|
||||
@@ -6,117 +6,13 @@ First, you might want to see the basic ways to [help FastAPI and get help](help-
|
||||
|
||||
If you already cloned the <a href="https://github.com/fastapi/fastapi" class="external-link" target="_blank">fastapi repository</a> and you want to deep dive in the code, here are some guidelines to set up your environment.
|
||||
|
||||
### Virtual environment with `venv`
|
||||
### Virtual environment
|
||||
|
||||
You can create an isolated virtual local environment in a directory using Python's `venv` module. Let's do this in the cloned repository (where the `requirements.txt` is):
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python -m venv env
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
That will create a directory `./env/` with the Python binaries, and then you will be able to install packages for that local environment.
|
||||
|
||||
### Activate the environment
|
||||
|
||||
Activate the new environment with:
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source ./env/bin/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ .\env\Scripts\Activate.ps1
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows Bash
|
||||
|
||||
Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source ./env/Scripts/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
To check it worked, use:
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ which pip
|
||||
|
||||
some/directory/fastapi/env/bin/pip
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ Get-Command pip
|
||||
|
||||
some/directory/fastapi/env/bin/pip
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
|
||||
|
||||
Make sure you have the latest pip version on your local environment to avoid errors on the next steps:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python -m pip install --upgrade pip
|
||||
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
/// tip
|
||||
|
||||
Every time you install a new package with `pip` under that environment, activate the environment again.
|
||||
|
||||
This makes sure that if you use a terminal program installed by that package, you use the one from your local environment and not any other that could be installed globally.
|
||||
|
||||
///
|
||||
Follow the instructions to create and activate a [virtual environment](virtual-environments.md){.internal-link target=_blank} for the internal code of `fastapi`.
|
||||
|
||||
### Install requirements using pip
|
||||
|
||||
After activating the environment as described above:
|
||||
After activating the environment, install the required packages:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -160,7 +56,19 @@ $ bash scripts/format.sh
|
||||
|
||||
It will also auto-sort all your imports.
|
||||
|
||||
For it to sort them correctly, you need to have FastAPI installed locally in your environment, with the command in the section above using `-e`.
|
||||
## Tests
|
||||
|
||||
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ bash scripts/test-cov-html.sh
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.
|
||||
|
||||
## Docs
|
||||
|
||||
@@ -482,17 +390,3 @@ Serving at: http://127.0.0.1:8008
|
||||
* Search for such links in the translated document using the regex `#[^# ]`.
|
||||
* Search in all documents already translated into your language for `your-translated-document.md`. For example VS Code has an option "Edit" -> "Find in Files".
|
||||
* When translating a document, do not "pre-translate" `#hash-parts` that link to headings in untranslated documents.
|
||||
|
||||
## Tests
|
||||
|
||||
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ bash scripts/test-cov-html.sh
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
This command generates a directory `./htmlcov/`, if you open the file `./htmlcov/index.html` in your browser, you can explore interactively the regions of code that are covered by the tests, and notice if there is any region missing.
|
||||
|
||||
@@ -82,7 +82,9 @@ When referring to the remote machine, it's common to call it **server**, but als
|
||||
|
||||
When you install FastAPI, it comes with a production server, Uvicorn, and you can start it with the `fastapi run` command.
|
||||
|
||||
But you can also install an ASGI server manually:
|
||||
But you can also install an ASGI server manually.
|
||||
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then you can install the server:
|
||||
|
||||
//// tab | Uvicorn
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ And then the Gunicorn-compatible **Uvicorn worker** class would be in charge of
|
||||
|
||||
## Install Gunicorn and Uvicorn
|
||||
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install `gunicorn`:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
|
||||
300
docs/en/docs/environment-variables.md
Normal file
300
docs/en/docs/environment-variables.md
Normal file
@@ -0,0 +1,300 @@
|
||||
# Environment Variables
|
||||
|
||||
/// tip
|
||||
|
||||
If you already know what "environment variables" are and how to use them, feel free to skip this.
|
||||
|
||||
///
|
||||
|
||||
An environment variable (also known as "**env var**") is a variable that lives **outside** of the Python code, in the **operating system**, and could be read by your Python code (or by other programs as well).
|
||||
|
||||
Environment variables could be useful for handling application **settings**, as part of the **installation** of Python, etc.
|
||||
|
||||
## Create and Use Env Vars
|
||||
|
||||
You can **create** and use environment variables in the **shell (terminal)**, without needing Python:
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<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 | Windows PowerShell
|
||||
|
||||
<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>
|
||||
|
||||
////
|
||||
|
||||
## Read env vars in Python
|
||||
|
||||
You could also create environment variables **outside** of Python, in the terminal (or with any other method), and then **read them in Python**.
|
||||
|
||||
For example you could have a file `main.py` with:
|
||||
|
||||
```Python hl_lines="3"
|
||||
import os
|
||||
|
||||
name = os.getenv("MY_NAME", "World")
|
||||
print(f"Hello {name} from Python")
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
||||
The second argument to <a href="https://docs.python.org/3.8/library/os.html#os.getenv" class="external-link" target="_blank">`os.getenv()`</a> is the default value to return.
|
||||
|
||||
If not provided, it's `None` by default, here we provide `"World"` as the default value to use.
|
||||
|
||||
///
|
||||
|
||||
Then you could call that Python program:
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<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>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<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
|
||||
$ $Env: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>
|
||||
|
||||
////
|
||||
|
||||
As environment variables can be set outside of the code, but can be read by the code, and don't have to be stored (committed to `git`) with the rest of the files, it's common to use them for configurations or **settings**.
|
||||
|
||||
You can also create an environment variable only for a **specific program invocation**, that is only available to that program, and only for its duration.
|
||||
|
||||
To do that, create it right before the program itself, on the same line:
|
||||
|
||||
<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
|
||||
|
||||
You can read more about it at <a href="https://12factor.net/config" class="external-link" target="_blank">The Twelve-Factor App: Config</a>.
|
||||
|
||||
///
|
||||
|
||||
## Types and Validation
|
||||
|
||||
These environment variables can only handle **text strings**, as they are external to Python and have to be compatible with other programs and the rest of the system (and even with different operating systems, as Linux, Windows, macOS).
|
||||
|
||||
That means that **any value** read in Python from an environment variable **will be a `str`**, and any conversion to a different type or any validation has to be done in code.
|
||||
|
||||
You will learn more about using environment variables for handling **application settings** in the [Advanced User Guide - Settings and Environment Variables](./advanced/settings.md){.internal-link target=_blank}.
|
||||
|
||||
## `PATH` Environment Variable
|
||||
|
||||
There is a **special** environment variable called **`PATH`** that is used by the operating systems (Linux, macOS, Windows) to find programs to run.
|
||||
|
||||
The value of the variable `PATH` is a long string that is made of directories separated by a colon `:` on Linux and macOS, and by a semicolon `;` on Windows.
|
||||
|
||||
For example, the `PATH` environment variable could look like this:
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
```plaintext
|
||||
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
|
||||
```
|
||||
|
||||
This means that the system should look for programs in the directories:
|
||||
|
||||
* `/usr/local/bin`
|
||||
* `/usr/bin`
|
||||
* `/bin`
|
||||
* `/usr/sbin`
|
||||
* `/sbin`
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows
|
||||
|
||||
```plaintext
|
||||
C:\Program Files\Python312\Scripts;C:\Program Files\Python312;C:\Windows\System32
|
||||
```
|
||||
|
||||
This means that the system should look for programs in the directories:
|
||||
|
||||
* `C:\Program Files\Python312\Scripts`
|
||||
* `C:\Program Files\Python312`
|
||||
* `C:\Windows\System32`
|
||||
|
||||
////
|
||||
|
||||
When you type a **command** in the terminal, the operating system **looks for** the program in **each of those directories** listed in the `PATH` environment variable.
|
||||
|
||||
For example, when you type `python` in the terminal, the operating system looks for a program called `python` in the **first directory** in that list.
|
||||
|
||||
If it finds it, then it will **use it**. Otherwise it keeps looking in the **other directories**.
|
||||
|
||||
### Installing Python and Updating the `PATH`
|
||||
|
||||
When you install Python, you might be asked if you want to update the `PATH` environment variable.
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
Let's say you install Python and it ends up in a directory `/opt/custompython/bin`.
|
||||
|
||||
If you say yes to update the `PATH` environment variable, then the installer will add `/opt/custompython/bin` to the `PATH` environment variable.
|
||||
|
||||
It could look like this:
|
||||
|
||||
```plaintext
|
||||
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/custompython/bin
|
||||
```
|
||||
|
||||
This way, when you type `python` in the terminal, the system will find the Python program in `/opt/custompython/bin` (the last directory) and use that one.
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows
|
||||
|
||||
Let's say you install Python and it ends up in a directory `C:\opt\custompython\bin`.
|
||||
|
||||
If you say yes to update the `PATH` environment variable, then the installer will add `C:\opt\custompython\bin` to the `PATH` environment variable.
|
||||
|
||||
```plaintext
|
||||
C:\Program Files\Python312\Scripts;C:\Program Files\Python312;C:\Windows\System32;C:\opt\custompython\bin
|
||||
```
|
||||
|
||||
This way, when you type `python` in the terminal, the system will find the Python program in `C:\opt\custompython\bin` (the last directory) and use that one.
|
||||
|
||||
////
|
||||
|
||||
This way, when you type `python` in the terminal, the system will find the Python program in `/opt/custompython/bin` (the last directory) and use that one.
|
||||
|
||||
So, if you type:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
The system will **find** the `python` program in `/opt/custompython/bin` and run it.
|
||||
|
||||
It would be roughly equivalent to typing:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ /opt/custompython/bin/python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows
|
||||
|
||||
The system will **find** the `python` program in `C:\opt\custompython\bin\python` and run it.
|
||||
|
||||
It would be roughly equivalent to typing:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ C:\opt\custompython\bin\python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
This information will be useful when learning about [Virtual Environments](virtual-environments.md){.internal-link target=_blank}.
|
||||
|
||||
## Conclusion
|
||||
|
||||
With this you should have a basic understanding of what **environment variables** are and how to use them in Python.
|
||||
|
||||
You can also read more about them in the <a href="https://en.wikipedia.org/wiki/Environment_variable" class="external-link" target="_blank">Wikipedia for Environment Variable</a>.
|
||||
|
||||
In many cases it's not very obvious how environment variables would be useful and applicable right away. But they keep showing up in many different scenarios when you are developing, so it's good to know about them.
|
||||
|
||||
For example, you will need this information in the next section, about [Virtual Environments](virtual-environments.md).
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
### Based on open standards
|
||||
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>OpenAPI</strong></a> for API creation, including declarations of <abbr title="also known as: endpoints, routes">path</abbr> <abbr title="also known as HTTP methods, as POST, GET, PUT, DELETE">operations</abbr>, parameters, body requests, security, etc.
|
||||
* <a href="https://github.com/OAI/OpenAPI-Specification" class="external-link" target="_blank"><strong>OpenAPI</strong></a> for API creation, including declarations of <abbr title="also known as: endpoints, routes">path</abbr> <abbr title="also known as HTTP methods, as POST, GET, PUT, DELETE">operations</abbr>, parameters, request bodies, security, etc.
|
||||
* Automatic data model documentation with <a href="https://json-schema.org/" class="external-link" target="_blank"><strong>JSON Schema</strong></a> (as OpenAPI itself is based on JSON Schema).
|
||||
* Designed around these standards, after a meticulous study. Instead of an afterthought layer on top.
|
||||
* This also allows using automatic **client code generation** in many languages.
|
||||
|
||||
@@ -66,7 +66,7 @@ I love to hear about how **FastAPI** is being used, what you have liked in it, i
|
||||
## Vote for FastAPI
|
||||
|
||||
* <a href="https://www.slant.co/options/34241/~fastapi-review" class="external-link" target="_blank">Vote for **FastAPI** in Slant</a>.
|
||||
* <a href="https://alternativeto.net/software/fastapi/" class="external-link" target="_blank">Vote for **FastAPI** in AlternativeTo</a>.
|
||||
* <a href="https://alternativeto.net/software/fastapi/about/" class="external-link" target="_blank">Vote for **FastAPI** in AlternativeTo</a>.
|
||||
* <a href="https://stackshare.io/pypi-fastapi" class="external-link" target="_blank">Say you use **FastAPI** on StackShare</a>.
|
||||
|
||||
## Help others with questions in GitHub
|
||||
|
||||
@@ -128,6 +128,8 @@ FastAPI stands on the shoulders of giants:
|
||||
|
||||
## Installation
|
||||
|
||||
Create and activate a <a href="https://fastapi.tiangolo.com/virtual-environments/" class="external-link" target="_blank">virtual environment</a> and then install FastAPI:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
@@ -458,7 +460,7 @@ When you install FastAPI with `pip install "fastapi[standard]"` it comes the `st
|
||||
|
||||
Used by Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - for email validation.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - for email validation.
|
||||
|
||||
Used by Starlette:
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ For the other languages, confirm that:
|
||||
* The title is correct following the instructions above.
|
||||
* It has the labels `lang-all` and `lang-{lang code}`.
|
||||
* The PR changes only one Markdown file adding a translation.
|
||||
* Or in some cases, at most two files, if they are small and people reviewed them.
|
||||
* Or in some cases, at most two files, if they are small, for the same language, and people reviewed them.
|
||||
* If it's the first translation for that language, it will have additional `mkdocs.yml` files, for those cases follow the instructions below.
|
||||
* The PR doesn't add any additional or extraneous files.
|
||||
* The translation seems to have a similar structure as the original English file.
|
||||
|
||||
@@ -16,6 +16,7 @@ GitHub Repository: <a href="https://github.com/tiangolo/full-stack-fastapi-templ
|
||||
- 💃 Using TypeScript, hooks, Vite, and other parts of a modern frontend stack.
|
||||
- 🎨 [Chakra UI](https://chakra-ui.com) for the frontend components.
|
||||
- 🤖 An automatically generated frontend client.
|
||||
- 🧪 Playwright for End-to-End testing.
|
||||
- 🦇 Dark mode support.
|
||||
- 🐋 [Docker Compose](https://www.docker.com) for development and production.
|
||||
- 🔒 Secure password hashing by default.
|
||||
|
||||
@@ -519,7 +519,7 @@ You will see a lot more of all this in practice in the [Tutorial - User Guide](t
|
||||
|
||||
/// tip
|
||||
|
||||
Pydantic has a special behavior when you use `Optional` or `Union[Something, None]` without a default value, you can read more about it in the Pydantic docs about <a href="https://docs.pydantic.dev/latest/concepts/models/#required-optional-fields" class="external-link" target="_blank">Required Optional fields</a>.
|
||||
Pydantic has a special behavior when you use `Optional` or `Union[Something, None]` without a default value, you can read more about it in the Pydantic docs about <a href="https://docs.pydantic.dev/2.3/usage/models/#required-fields" class="external-link" target="_blank">Required Optional fields</a>.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -7,6 +7,57 @@ hide:
|
||||
|
||||
## Latest Changes
|
||||
|
||||
## 0.112.2
|
||||
|
||||
### Fixes
|
||||
|
||||
* 🐛 Fix `allow_inf_nan` option for Param and Body classes. PR [#11867](https://github.com/fastapi/fastapi/pull/11867) by [@giunio-prc](https://github.com/giunio-prc).
|
||||
* 🐛 Ensure that `app.include_router` merges nested lifespans. PR [#9630](https://github.com/fastapi/fastapi/pull/9630) by [@Lancetnik](https://github.com/Lancetnik).
|
||||
|
||||
### Refactors
|
||||
|
||||
* 🎨 Fix typing annotation for semi-internal `FastAPI.add_api_route()`. PR [#10240](https://github.com/fastapi/fastapi/pull/10240) by [@ordinary-jamie](https://github.com/ordinary-jamie).
|
||||
* ⬆️ Upgrade version of Ruff and reformat. PR [#12032](https://github.com/fastapi/fastapi/pull/12032) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
### Docs
|
||||
|
||||
* 📝 Fix a typo in `docs/en/docs/virtual-environments.md`. PR [#12064](https://github.com/fastapi/fastapi/pull/12064) by [@aymenkrifa](https://github.com/aymenkrifa).
|
||||
* 📝 Add docs about Environment Variables and Virtual Environments. PR [#12054](https://github.com/fastapi/fastapi/pull/12054) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 📝 Add Asyncer mention in async docs. PR [#12037](https://github.com/fastapi/fastapi/pull/12037) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 📝 Move the Features docs to the top level to improve the main page menu. PR [#12036](https://github.com/fastapi/fastapi/pull/12036) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ✏️ Fix import typo in reference example for `Security`. PR [#11168](https://github.com/fastapi/fastapi/pull/11168) by [@0shah0](https://github.com/0shah0).
|
||||
* 📝 Highlight correct line in tutorial `docs/en/docs/tutorial/body-multiple-params.md`. PR [#11978](https://github.com/fastapi/fastapi/pull/11978) by [@svlandeg](https://github.com/svlandeg).
|
||||
* 🔥 Remove Sentry link from Advanced Middleware docs. PR [#12031](https://github.com/fastapi/fastapi/pull/12031) by [@alejsdev](https://github.com/alejsdev).
|
||||
* 📝 Clarify management tasks for translations, multiples files in one PR. PR [#12030](https://github.com/fastapi/fastapi/pull/12030) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 📝 Edit the link to the OpenAPI "Responses Object" and "Response Object" sections in the "Additional Responses in OpenAPI" section. PR [#11996](https://github.com/fastapi/fastapi/pull/11996) by [@VaitoSoi](https://github.com/VaitoSoi).
|
||||
* 🔨 Specify `email-validator` dependency with dash. PR [#11515](https://github.com/fastapi/fastapi/pull/11515) by [@jirikuncar](https://github.com/jirikuncar).
|
||||
* 🌐 Add Spanish translation for `docs/es/docs/project-generation.md`. PR [#11947](https://github.com/fastapi/fastapi/pull/11947) by [@alejsdev](https://github.com/alejsdev).
|
||||
* 📝 Fix minor typo. PR [#12026](https://github.com/fastapi/fastapi/pull/12026) by [@MicaelJarniac](https://github.com/MicaelJarniac).
|
||||
* 📝 Several docs improvements, tweaks, and clarifications. PR [#11390](https://github.com/fastapi/fastapi/pull/11390) by [@nilslindemann](https://github.com/nilslindemann).
|
||||
* 📝 Add missing `compresslevel` parameter on docs for `GZipMiddleware`. PR [#11350](https://github.com/fastapi/fastapi/pull/11350) by [@junah201](https://github.com/junah201).
|
||||
* 📝 Fix inconsistent response code when item already exists in docs for testing. PR [#11818](https://github.com/fastapi/fastapi/pull/11818) by [@lokomilo](https://github.com/lokomilo).
|
||||
* 📝 Update `docs/en/docs/tutorial/body.md` with Python 3.10 union type example. PR [#11415](https://github.com/fastapi/fastapi/pull/11415) by [@rangzen](https://github.com/rangzen).
|
||||
|
||||
### Translations
|
||||
|
||||
* 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/request_file.md`. PR [#12018](https://github.com/fastapi/fastapi/pull/12018) by [@Joao-Pedro-P-Holanda](https://github.com/Joao-Pedro-P-Holanda).
|
||||
* 🌐 Add Japanese translation for `docs/ja/docs/learn/index.md`. PR [#11592](https://github.com/fastapi/fastapi/pull/11592) by [@ukwhatn](https://github.com/ukwhatn).
|
||||
* 📝 Update Spanish translation docs for consistency. PR [#12044](https://github.com/fastapi/fastapi/pull/12044) by [@alejsdev](https://github.com/alejsdev).
|
||||
* 🌐 Update Chinese translation for `docs/zh/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#12028](https://github.com/fastapi/fastapi/pull/12028) by [@xuvjso](https://github.com/xuvjso).
|
||||
* 📝 Update FastAPI People, do not translate to have the most recent info. PR [#12034](https://github.com/fastapi/fastapi/pull/12034) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 🌐 Update Urdu translation for `docs/ur/docs/benchmarks.md`. PR [#10046](https://github.com/fastapi/fastapi/pull/10046) by [@AhsanSheraz](https://github.com/AhsanSheraz).
|
||||
|
||||
### Internal
|
||||
|
||||
* ⬆ [pre-commit.ci] pre-commit autoupdate. PR [#12046](https://github.com/fastapi/fastapi/pull/12046) by [@pre-commit-ci[bot]](https://github.com/apps/pre-commit-ci).
|
||||
* 🔧 Update coverage config files. PR [#12035](https://github.com/fastapi/fastapi/pull/12035) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 🔨 Standardize shebang across shell scripts. PR [#11942](https://github.com/fastapi/fastapi/pull/11942) by [@gitworkflows](https://github.com/gitworkflows).
|
||||
* ⬆ Update sqlalchemy requirement from <1.4.43,>=1.3.18 to >=1.3.18,<2.0.33. PR [#11979](https://github.com/fastapi/fastapi/pull/11979) by [@dependabot[bot]](https://github.com/apps/dependabot).
|
||||
* 🔊 Remove old ignore warnings. PR [#11950](https://github.com/fastapi/fastapi/pull/11950) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ⬆️ Upgrade griffe-typingdoc for the docs. PR [#12029](https://github.com/fastapi/fastapi/pull/12029) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 🙈 Add .coverage* to `.gitignore`. PR [#11940](https://github.com/fastapi/fastapi/pull/11940) by [@gitworkflows](https://github.com/gitworkflows).
|
||||
* ⚙️ Record and show test coverage contexts (what test covers which line). PR [#11518](https://github.com/fastapi/fastapi/pull/11518) by [@slafs](https://github.com/slafs).
|
||||
|
||||
## 0.112.1
|
||||
|
||||
### Upgrades
|
||||
|
||||
@@ -9,7 +9,7 @@ This includes, for example:
|
||||
* Email notifications sent after performing an action:
|
||||
* As connecting to an email server and sending an email tends to be "slow" (several seconds), you can return the response right away and send the email notification in the background.
|
||||
* Processing data:
|
||||
* For example, let's say you receive a file that must go through a slow process, you can return a response of "Accepted" (HTTP 202) and process it in the background.
|
||||
* For example, let's say you receive a file that must go through a slow process, you can return a response of "Accepted" (HTTP 202) and process the file in the background.
|
||||
|
||||
## Using `BackgroundTasks`
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ For example:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="27"
|
||||
```Python hl_lines="28"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004_an_py310.py!}
|
||||
```
|
||||
|
||||
@@ -236,7 +236,7 @@ For example:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="27"
|
||||
```Python hl_lines="28"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004_an_py39.py!}
|
||||
```
|
||||
|
||||
@@ -244,7 +244,7 @@ For example:
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="28"
|
||||
```Python hl_lines="29"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004_an.py!}
|
||||
```
|
||||
|
||||
@@ -258,7 +258,7 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="25"
|
||||
```Python hl_lines="26"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004_py310.py!}
|
||||
```
|
||||
|
||||
@@ -272,7 +272,7 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="27"
|
||||
```Python hl_lines="28"
|
||||
{!> ../../../docs_src/body_multiple_params/tutorial004.py!}
|
||||
```
|
||||
|
||||
|
||||
@@ -220,7 +220,7 @@ Again, doing just that declaration, with **FastAPI** you get:
|
||||
|
||||
Apart from normal singular types like `str`, `int`, `float`, etc. you can use more complex singular types that inherit from `str`.
|
||||
|
||||
To see all the options you have, checkout the docs for <a href="https://docs.pydantic.dev/latest/concepts/types/" class="external-link" target="_blank">Pydantic's exotic types</a>. You will see some examples in the next chapter.
|
||||
To see all the options you have, checkout <a href="https://docs.pydantic.dev/latest/concepts/types/" class="external-link" target="_blank">Pydantic's Type Overview</a>. You will see some examples in the next chapter.
|
||||
|
||||
For example, as in the `Image` model we have a `url` field, we can declare it to be an instance of Pydantic's `HttpUrl` instead of a `str`:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ When you need to send data from a client (let's say, a browser) to your API, you
|
||||
|
||||
A **request** body is data sent by the client to your API. A **response** body is the data your API sends to the client.
|
||||
|
||||
Your API almost always has to send a **response** body. But clients don't necessarily need to send **request** bodies all the time.
|
||||
Your API almost always has to send a **response** body. But clients don't necessarily need to send **request bodies** all the time, sometimes they only request a path, maybe with some query parameters, but don't send a body.
|
||||
|
||||
To declare a **request** body, you use <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic</a> models with all their power and benefits.
|
||||
|
||||
@@ -237,7 +237,9 @@ The function parameters will be recognized as follows:
|
||||
|
||||
FastAPI will know that the value of `q` is not required because of the default value `= None`.
|
||||
|
||||
The `Union` in `Union[str, None]` is not used by FastAPI, but will allow your editor to give you better support and detect errors.
|
||||
The `str | None` (Python 3.10+) or `Union` in `Union[str, None]` (Python 3.8+) is not used by FastAPI to determine that the value is not required, it will know it's not required because it has a default value of `= None`.
|
||||
|
||||
But adding the type annotations will allow your editor to give you better support and detect errors.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
Then declare the cookie parameters using the same structure as with `Path` and `Query`.
|
||||
|
||||
The first value is the default value, you can pass all the extra validation or annotation parameters:
|
||||
You can define the default value as well as all the extra validation or annotation parameters:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
|
||||
@@ -18,11 +18,11 @@ Even if they are all in `localhost`, they use different protocols or ports, so,
|
||||
|
||||
So, let's say you have a frontend running in your browser at `http://localhost:8080`, and its JavaScript is trying to communicate with a backend running at `http://localhost` (because we don't specify a port, the browser will assume the default port `80`).
|
||||
|
||||
Then, the browser will send an HTTP `OPTIONS` request to the backend, and if the backend sends the appropriate headers authorizing the communication from this different origin (`http://localhost:8080`) then the browser will let the JavaScript in the frontend send its request to the backend.
|
||||
Then, the browser will send an HTTP `OPTIONS` request to the `:80`-backend, and if the backend sends the appropriate headers authorizing the communication from this different origin (`http://localhost:8080`) then the `:8080`-browser will let the JavaScript in the frontend send its request to the `:80`-backend.
|
||||
|
||||
To achieve this, the backend must have a list of "allowed origins".
|
||||
To achieve this, the `:80`-backend must have a list of "allowed origins".
|
||||
|
||||
In this case, it would have to include `http://localhost:8080` for the frontend to work correctly.
|
||||
In this case, the list would have to include `http://localhost:8080` for the `:8080`-frontend to work correctly.
|
||||
|
||||
## Wildcards
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ To do this, use `yield` instead of `return`, and write the extra steps (code) af
|
||||
|
||||
/// tip
|
||||
|
||||
Make sure to use `yield` one single time.
|
||||
Make sure to use `yield` one single time per dependency.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ Here are some of the additional data types you can use:
|
||||
* `datetime.timedelta`:
|
||||
* A Python `datetime.timedelta`.
|
||||
* In requests and responses will be represented as a `float` of total seconds.
|
||||
* Pydantic also allows representing it as a "ISO 8601 time diff encoding", <a href="https://docs.pydantic.dev/latest/concepts/serialization/#json_encoders" class="external-link" target="_blank">see the docs for more info</a>.
|
||||
* Pydantic also allows representing it as a "ISO 8601 time diff encoding", <a href="https://docs.pydantic.dev/latest/concepts/serialization/#custom-serializers" class="external-link" target="_blank">see the docs for more info</a>.
|
||||
* `frozenset`:
|
||||
* In requests and responses, treated the same as a `set`:
|
||||
* In requests, a list will be read, eliminating duplicates and converting it to a `set`.
|
||||
|
||||
@@ -156,7 +156,7 @@ UserInDB(
|
||||
|
||||
/// warning
|
||||
|
||||
The supporting additional functions are just to demo a possible flow of the data, but they of course are not providing any real security.
|
||||
The supporting additional functions `fake_password_hasher` and `fake_save_user` are just to demo a possible flow of the data, but they of course are not providing any real security.
|
||||
|
||||
///
|
||||
|
||||
@@ -194,7 +194,7 @@ That way, we can declare just the differences between the models (with plaintext
|
||||
|
||||
## `Union` or `anyOf`
|
||||
|
||||
You can declare a response to be the `Union` of two types, that means, that the response would be any of the two.
|
||||
You can declare a response to be the `Union` of two or more types, that means, that the response would be any of them.
|
||||
|
||||
It will be defined in OpenAPI with `anyOf`.
|
||||
|
||||
@@ -234,7 +234,7 @@ If it was in a type annotation we could have used the vertical bar, as:
|
||||
some_variable: PlaneItem | CarItem
|
||||
```
|
||||
|
||||
But if we put that in `response_model=PlaneItem | CarItem` we would get an error, because Python would try to perform an **invalid operation** between `PlaneItem` and `CarItem` instead of interpreting that as a type annotation.
|
||||
But if we put that in the assignment `response_model=PlaneItem | CarItem` we would get an error, because Python would try to perform an **invalid operation** between `PlaneItem` and `CarItem` instead of interpreting that as a type annotation.
|
||||
|
||||
## List of models
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
Then declare the header parameters using the same structure as with `Path`, `Query` and `Cookie`.
|
||||
|
||||
The first value is the default value, you can pass all the extra validation or annotation parameters:
|
||||
You can define the default value as well as all the extra validation or annotation parameters:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
|
||||
@@ -4,9 +4,7 @@ This tutorial shows you how to use **FastAPI** with most of its features, step b
|
||||
|
||||
Each section gradually builds on the previous ones, but it's structured to separate topics, so that you can go directly to any specific one to solve your specific API needs.
|
||||
|
||||
It is also built to work as a future reference.
|
||||
|
||||
So you can come back and see exactly what you need.
|
||||
It is also built to work as a future reference so you can come back and see exactly what you need.
|
||||
|
||||
## Run the code
|
||||
|
||||
@@ -71,7 +69,9 @@ Using it in your editor is what really shows you the benefits of FastAPI, seeing
|
||||
|
||||
## Install FastAPI
|
||||
|
||||
The first step is to install FastAPI:
|
||||
The first step is to install FastAPI.
|
||||
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then **install FastAPI**:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
@@ -155,7 +155,7 @@ FastAPI will now:
|
||||
* Show a **clear error** for the client when the data is not valid
|
||||
* **Document** the parameter in the OpenAPI schema *path operation* (so it will show up in the **automatic docs UI**)
|
||||
|
||||
## Alternative (old) `Query` as the default value
|
||||
## Alternative (old): `Query` as the default value
|
||||
|
||||
Previous versions of FastAPI (before <abbr title="before 2023-03">0.95.0</abbr>) required you to use `Query` as the default value of your parameter, instead of putting it in `Annotated`, there's a high chance that you will see code using it around, so I'll explain it to you.
|
||||
|
||||
@@ -209,7 +209,7 @@ q: str | None = Query(default=None)
|
||||
q: str | None = None
|
||||
```
|
||||
|
||||
But it declares it explicitly as being a query parameter.
|
||||
But the `Query` versions declare it explicitly as being a query parameter.
|
||||
|
||||
/// info
|
||||
|
||||
@@ -457,7 +457,7 @@ Having a default value of any type, including `None`, makes the parameter option
|
||||
|
||||
///
|
||||
|
||||
## Make it required
|
||||
## Required parameters
|
||||
|
||||
When we don't need to declare more validations or metadata, we can make the `q` query parameter required just by not declaring a default value, like:
|
||||
|
||||
@@ -573,7 +573,7 @@ It is used by Pydantic and FastAPI to explicitly declare that a value is require
|
||||
|
||||
This will let **FastAPI** know that this parameter is required.
|
||||
|
||||
### Required with `None`
|
||||
### Required, can be `None`
|
||||
|
||||
You can declare that a parameter can accept `None`, but that it's still required. This would force clients to send a value, even if the value is `None`.
|
||||
|
||||
@@ -633,7 +633,7 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
/// tip
|
||||
|
||||
Pydantic, which is what powers all the data validation and serialization in FastAPI, has a special behavior when you use `Optional` or `Union[Something, None]` without a default value, you can read more about it in the Pydantic docs about <a href="https://docs.pydantic.dev/latest/concepts/models/#required-optional-fields" class="external-link" target="_blank">Required Optional fields</a>.
|
||||
Pydantic, which is what powers all the data validation and serialization in FastAPI, has a special behavior when you use `Optional` or `Union[Something, None]` without a default value, you can read more about it in the Pydantic docs about <a href="https://docs.pydantic.dev/2.3/usage/models/#required-optional-fields" class="external-link" target="_blank">Required fields</a>.
|
||||
|
||||
///
|
||||
|
||||
@@ -809,7 +809,7 @@ the default of `q` will be: `["foo", "bar"]` and your response will be:
|
||||
}
|
||||
```
|
||||
|
||||
#### Using `list`
|
||||
#### Using just `list`
|
||||
|
||||
You can also use `list` directly instead of `List[str]` (or `list[str]` in Python 3.9+):
|
||||
|
||||
@@ -1107,7 +1107,7 @@ The docs will show it like this:
|
||||
|
||||
<img src="/img/tutorial/query-params-str-validations/image01.png">
|
||||
|
||||
## Exclude from OpenAPI
|
||||
## Exclude parameters from OpenAPI
|
||||
|
||||
To exclude a query parameter from the generated OpenAPI schema (and thus, from the automatic documentation systems), set the parameter `include_in_schema` of `Query` to `False`:
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ You can define files to be uploaded by the client using `File`.
|
||||
|
||||
To receive uploaded files, first install <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
||||
|
||||
E.g. `pip install python-multipart`.
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
```console
|
||||
$ pip install python-multipart
|
||||
```
|
||||
|
||||
This is because uploaded files are sent as "form data".
|
||||
|
||||
@@ -152,7 +156,7 @@ Using `UploadFile` has several advantages over `bytes`:
|
||||
|
||||
* `filename`: A `str` with the original file name that was uploaded (e.g. `myimage.jpg`).
|
||||
* `content_type`: A `str` with the content type (MIME type / media type) (e.g. `image/jpeg`).
|
||||
* `file`: A <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> (a <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">file-like</a> object). This is the actual Python file that you can pass directly to other functions or libraries that expect a "file-like" object.
|
||||
* `file`: A <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> (a <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">file-like</a> object). This is the actual Python file object that you can pass directly to other functions or libraries that expect a "file-like" object.
|
||||
|
||||
`UploadFile` has the following `async` methods. They all call the corresponding file methods underneath (using the internal `SpooledTemporaryFile`).
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ You can define files and form fields at the same time using `File` and `Form`.
|
||||
|
||||
To receive uploaded files and/or form data, first install <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
||||
|
||||
E.g. `pip install python-multipart`.
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
```console
|
||||
$ pip install python-multipart
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -6,7 +6,11 @@ When you need to receive form fields instead of JSON, you can use `Form`.
|
||||
|
||||
To use forms, first install <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
||||
|
||||
E.g. `pip install python-multipart`.
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
```console
|
||||
$ pip install python-multipart
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -131,10 +131,19 @@ Here we are declaring a `UserIn` model, it will contain a plaintext password:
|
||||
|
||||
/// info
|
||||
|
||||
To use `EmailStr`, first install <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email_validator`</a>.
|
||||
To use `EmailStr`, first install <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email-validator`</a>.
|
||||
|
||||
E.g. `pip install email-validator`
|
||||
or `pip install pydantic[email]`.
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
```console
|
||||
$ pip install email-validator
|
||||
```
|
||||
|
||||
or with:
|
||||
|
||||
```console
|
||||
$ pip install "pydantic[email]"
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
@@ -236,9 +245,9 @@ That's why in this example we have to declare it in the `response_model` paramet
|
||||
|
||||
## Return Type and Data Filtering
|
||||
|
||||
Let's continue from the previous example. We wanted to **annotate the function with one type** but return something that includes **more data**.
|
||||
Let's continue from the previous example. We wanted to **annotate the function with one type**, but we wanted to be able to return from the function something that actually includes **more data**.
|
||||
|
||||
We want FastAPI to keep **filtering** the data using the response model.
|
||||
We want FastAPI to keep **filtering** the data using the response model. So that even though the function returns more data, the response will only include the fields declared in the response model.
|
||||
|
||||
In the previous example, because the classes were different, we had to use the `response_model` parameter. But that also means that we don't get the support from the editor and tools checking the function return type.
|
||||
|
||||
@@ -306,7 +315,7 @@ The most common case would be [returning a Response directly as explained later
|
||||
{!> ../../../docs_src/response_model/tutorial003_02.py!}
|
||||
```
|
||||
|
||||
This simple case is handled automatically by FastAPI because the return type annotation is the class (or a subclass) of `Response`.
|
||||
This simple case is handled automatically by FastAPI because the return type annotation is the class (or a subclass of) `Response`.
|
||||
|
||||
And tools will also be happy because both `RedirectResponse` and `JSONResponse` are subclasses of `Response`, so the type annotation is correct.
|
||||
|
||||
@@ -455,7 +464,7 @@ The examples here use `.dict()` for compatibility with Pydantic v1, but you shou
|
||||
|
||||
/// info
|
||||
|
||||
FastAPI uses Pydantic model's `.dict()` with <a href="https://docs.pydantic.dev/latest/concepts/serialization/#modeldict" class="external-link" target="_blank">its `exclude_unset` parameter</a> to achieve this.
|
||||
FastAPI uses Pydantic model's `.dict()` with <a href="https://docs.pydantic.dev/1.10/usage/exporting_models/#modeldict" class="external-link" target="_blank">its `exclude_unset` parameter</a> to achieve this.
|
||||
|
||||
///
|
||||
|
||||
@@ -466,7 +475,7 @@ You can also use:
|
||||
* `response_model_exclude_defaults=True`
|
||||
* `response_model_exclude_none=True`
|
||||
|
||||
as described in <a href="https://docs.pydantic.dev/latest/concepts/serialization/#modeldict" class="external-link" target="_blank">the Pydantic docs</a> for `exclude_defaults` and `exclude_none`.
|
||||
as described in <a href="https://docs.pydantic.dev/1.10/usage/exporting_models/#modeldict" class="external-link" target="_blank">the Pydantic docs</a> for `exclude_defaults` and `exclude_none`.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ That extra info will be added as-is to the output **JSON Schema** for that model
|
||||
|
||||
//// tab | Pydantic v2
|
||||
|
||||
In Pydantic version 2, you would use the attribute `model_config`, that takes a `dict` as described in <a href="https://docs.pydantic.dev/latest/usage/model_config/" class="external-link" target="_blank">Pydantic's docs: Model Config</a>.
|
||||
In Pydantic version 2, you would use the attribute `model_config`, that takes a `dict` as described in <a href="https://docs.pydantic.dev/latest/api/config/" class="external-link" target="_blank">Pydantic's docs: Configuration</a>.
|
||||
|
||||
You can set `"json_schema_extra"` with a `dict` containing any additional data you would like to show up in the generated JSON Schema, including `examples`.
|
||||
|
||||
|
||||
@@ -56,9 +56,13 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
The <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a> package is automatically installed with **FastAPI** when you run the `pip install "fastapi[standard]"` command.
|
||||
|
||||
However, if you use the `pip install fastapi` command, the `python-multipart` package is not included by default. To install it manually, use the following command:
|
||||
However, if you use the `pip install fastapi` command, the `python-multipart` package is not included by default.
|
||||
|
||||
`pip install python-multipart`
|
||||
To install it manually, make sure you create a [virtual environment](../../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it with:
|
||||
|
||||
```console
|
||||
$ pip install python-multipart
|
||||
```
|
||||
|
||||
This is because **OAuth2** uses "form data" for sending the `username` and `password`.
|
||||
|
||||
|
||||
@@ -28,7 +28,9 @@ If you want to play with JWT tokens and see how they work, check <a href="https:
|
||||
|
||||
## Install `PyJWT`
|
||||
|
||||
We need to install `PyJWT` to generate and verify the JWT tokens in Python:
|
||||
We need to install `PyJWT` to generate and verify the JWT tokens in Python.
|
||||
|
||||
Make sure you create a [virtual environment](../../virtual-environments.md){.internal-link target=_blank}, activate it, and then install `pyjwt`:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
@@ -70,7 +72,7 @@ It supports many secure hashing algorithms and utilities to work with them.
|
||||
|
||||
The recommended algorithm is "Bcrypt".
|
||||
|
||||
So, install PassLib with Bcrypt:
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install PassLib with Bcrypt:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
@@ -101,7 +101,9 @@ Now let's see what each file/module does.
|
||||
|
||||
## Install `SQLAlchemy`
|
||||
|
||||
First you need to install `SQLAlchemy`:
|
||||
First you need to install `SQLAlchemy`.
|
||||
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
@@ -12,7 +12,11 @@ With it, you can use <a href="https://docs.pytest.org/" class="external-link" ta
|
||||
|
||||
To use `TestClient`, first install <a href="https://www.python-httpx.org" class="external-link" target="_blank">`httpx`</a>.
|
||||
|
||||
E.g. `pip install httpx`.
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
```console
|
||||
$ pip install httpx
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
@@ -206,7 +210,9 @@ If you have a Pydantic model in your test and you want to send its data to the a
|
||||
|
||||
## Run it
|
||||
|
||||
After that, you just need to install `pytest`:
|
||||
After that, you just need to install `pytest`.
|
||||
|
||||
Make sure you create a [virtual environment](../virtual-environments.md){.internal-link target=_blank}, activate it, and then install it, for example:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
|
||||
844
docs/en/docs/virtual-environments.md
Normal file
844
docs/en/docs/virtual-environments.md
Normal file
@@ -0,0 +1,844 @@
|
||||
# Virtual Environments
|
||||
|
||||
When you work in Python projects you probably should use a **virtual environment** (or a similar mechanism) to isolate the packages you install for each project.
|
||||
|
||||
/// info
|
||||
|
||||
If you already know about virtual environments, how to create them and use them, you might want to skip this section. 🤓
|
||||
|
||||
///
|
||||
|
||||
/// tip
|
||||
|
||||
A **virtual environment** is different than an **environment variable**.
|
||||
|
||||
An **environment variable** is a variable in the system that can be used by programs.
|
||||
|
||||
A **virtual environment** is a directory with some files in it.
|
||||
|
||||
///
|
||||
|
||||
/// info
|
||||
|
||||
This page will teach you how to use **virtual environments** and how they work.
|
||||
|
||||
If you are ready to adopt a **tool that manages everything** for you (including installing Python), try <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">uv</a>.
|
||||
|
||||
///
|
||||
|
||||
## Create a Project
|
||||
|
||||
First, create a directory for your project.
|
||||
|
||||
What I normally do is that I create a directory named `code` inside my home/user directory.
|
||||
|
||||
And inside of that I create one directory per project.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
// Go to the home directory
|
||||
$ cd
|
||||
// Create a directory for all your code projects
|
||||
$ mkdir code
|
||||
// Enter into that code directory
|
||||
$ cd code
|
||||
// Create a directory for this project
|
||||
$ mkdir awesome-project
|
||||
// Enter into that project directory
|
||||
$ cd awesome-project
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## Create a Virtual Environment
|
||||
|
||||
When you start working on a Python project **for the first time**, create a virtual environment **<abbr title="there are other options, this is a simple guideline">inside your project</abbr>**.
|
||||
|
||||
/// tip
|
||||
|
||||
You only need to do this **once per project**, not every time you work.
|
||||
|
||||
///
|
||||
|
||||
//// tab | `venv`
|
||||
|
||||
To create a virtual environment, you can use the `venv` module that comes with Python.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python -m venv .venv
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
/// details | What that command means
|
||||
|
||||
* `python`: use the program called `python`
|
||||
* `-m`: call a module as a script, we'll tell it which module next
|
||||
* `venv`: use the module called `venv` that normally comes installed with Python
|
||||
* `.venv`: create the virtual environment in the new directory `.venv`
|
||||
|
||||
///
|
||||
|
||||
////
|
||||
|
||||
//// tab | `uv`
|
||||
|
||||
If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> installed, you can use it to create a virtual environment.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ uv venv
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
/// tip
|
||||
|
||||
By default, `uv` will create a virtual environment in a directory called `.venv`.
|
||||
|
||||
But you could customize it passing an additional argument with the directory name.
|
||||
|
||||
///
|
||||
|
||||
////
|
||||
|
||||
That command creates a new virtual environment in a directory called `.venv`.
|
||||
|
||||
/// details | `.venv` or other name
|
||||
|
||||
You could create the virtual environment in a different directory, but there's a convention of calling it `.venv`.
|
||||
|
||||
///
|
||||
|
||||
## Activate the Virtual Environment
|
||||
|
||||
Activate the new virtual environment so that any Python command you run or package you install uses it.
|
||||
|
||||
/// tip
|
||||
|
||||
Do this **every time** you start a **new terminal session** to work on the project.
|
||||
|
||||
///
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source .venv/bin/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ .venv\Scripts\Activate.ps1
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows Bash
|
||||
|
||||
Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source .venv/Scripts/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
/// tip
|
||||
|
||||
Every time you install a **new package** in that environment, **activate** the environment again.
|
||||
|
||||
This makes sure that if you use a **terminal (<abbr title="command line interface">CLI</abbr>) program** installed by that package, you use the one from your virtual environment and not any other that could be installed globally, probably with a different version than what you need.
|
||||
|
||||
///
|
||||
|
||||
## Check the Virtual Environment is Active
|
||||
|
||||
Check that the virtual environment is active (the previous command worked).
|
||||
|
||||
/// tip
|
||||
|
||||
This is **optional**, but it's a good way to **check** that everything is working as expected and you are using the virtual environment you intended.
|
||||
|
||||
///
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ which python
|
||||
|
||||
/home/user/code/awesome-project/.venv/bin/python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
If it shows the `python` binary at `.venv/bin/python`, inside of your project (in this case `awesome-project`), then it worked. 🎉
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ Get-Command python
|
||||
|
||||
C:\Users\user\code\awesome-project\.venv\Scripts\python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
If it shows the `python` binary at `.venv\Scripts\python`, inside of your project (in this case `awesome-project`), then it worked. 🎉
|
||||
|
||||
////
|
||||
|
||||
## Upgrade `pip`
|
||||
|
||||
/// tip
|
||||
|
||||
If you use <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> you would use it to install things instead of `pip`, so you don't need to upgrade `pip`. 😎
|
||||
|
||||
///
|
||||
|
||||
If you are using `pip` to install packages (it comes by default with Python), you should **upgrade** it to the latest version.
|
||||
|
||||
Many exotic errors while installing a package are solved by just upgrading `pip` first.
|
||||
|
||||
/// tip
|
||||
|
||||
You would normally do this **once**, right after you create the virtual environment.
|
||||
|
||||
///
|
||||
|
||||
Make sure the virtual environment is active (with the command above) and then run:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python -m pip install --upgrade pip
|
||||
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## Add `.gitignore`
|
||||
|
||||
If you are using **Git** (you should), add a `.gitignore` file to exclude everything in your `.venv` from Git.
|
||||
|
||||
/// tip
|
||||
|
||||
If you used <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a> to create the virtual environment, it already did this for you, you can skip this step. 😎
|
||||
|
||||
///
|
||||
|
||||
/// tip
|
||||
|
||||
Do this **once**, right after you create the virtual environment.
|
||||
|
||||
///
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ echo "*" > .venv/.gitignore
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
/// details | What that command means
|
||||
|
||||
* `echo "*"`: will "print" the text `*` in the terminal (the next part changes that a bit)
|
||||
* `>`: anything printed to the terminal by the command to the left of `>` should not be printed but instead written to the file that goes to the right of `>`
|
||||
* `.gitignore`: the name of the file where the text should be written
|
||||
|
||||
And `*` for Git means "everything". So, it will ignore everything in the `.venv` directory.
|
||||
|
||||
That command will create a file `.gitignore` with the content:
|
||||
|
||||
```gitignore
|
||||
*
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
## Install Packages
|
||||
|
||||
After activating the environment, you can install packages in it.
|
||||
|
||||
/// tip
|
||||
|
||||
Do this **once** when installing or upgrading the packages your project needs.
|
||||
|
||||
If you need to upgrade a version or add a new package you would **do this again**.
|
||||
|
||||
///
|
||||
|
||||
### Install Packages Directly
|
||||
|
||||
If you're in a hurry and don't want to use a file to declare your project's package requirements, you can install them directly.
|
||||
|
||||
/// tip
|
||||
|
||||
It's a (very) good idea to put the packages and versions your program needs in a file (for example `requirements.txt` or `pyproject.toml`).
|
||||
|
||||
///
|
||||
|
||||
//// tab | `pip`
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ pip install "fastapi[standard]"
|
||||
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | `uv`
|
||||
|
||||
If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a>:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ uv pip install "fastapi[standard]"
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
### Install from `requirements.txt`
|
||||
|
||||
If you have a `requirements.txt`, you can now use it to install its packages.
|
||||
|
||||
//// tab | `pip`
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ pip install -r requirements.txt
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | `uv`
|
||||
|
||||
If you have <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">`uv`</a>:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ uv pip install -r requirements.txt
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
/// details | `requirements.txt`
|
||||
|
||||
A `requirements.txt` with some packages could look like:
|
||||
|
||||
```requirements.txt
|
||||
fastapi[standard]==0.113.0
|
||||
pydantic==2.8.0
|
||||
```
|
||||
|
||||
///
|
||||
|
||||
## Run Your Program
|
||||
|
||||
After you activated the virtual environment, you can run your program, and it will use the Python inside of your virtual environment with the packages you installed there.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ python main.py
|
||||
|
||||
Hello World
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## Configure Your Editor
|
||||
|
||||
You would probably use an editor, make sure you configure it to use the same virtual environment you created (it will probably autodetect it) so that you can get autocompletion and inline errors.
|
||||
|
||||
For example:
|
||||
|
||||
* <a href="https://code.visualstudio.com/docs/python/environments#_select-and-activate-an-environment" class="external-link" target="_blank">VS Code</a>
|
||||
* <a href="https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html" class="external-link" target="_blank">PyCharm</a>
|
||||
|
||||
/// tip
|
||||
|
||||
You normally have to do this only **once**, when you create the virtual environment.
|
||||
|
||||
///
|
||||
|
||||
## Deactivate the Virtual Environment
|
||||
|
||||
Once you are done working on your project you can **deactivate** the virtual environment.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ deactivate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
This way, when you run `python` it won't try to run it from that virtual environment with the packages installed there.
|
||||
|
||||
## Ready to Work
|
||||
|
||||
Now you're ready to start working on your project.
|
||||
|
||||
|
||||
|
||||
/// tip
|
||||
|
||||
Do you want to understand what's all that above?
|
||||
|
||||
Continue reading. 👇🤓
|
||||
|
||||
///
|
||||
|
||||
## Why Virtual Environments
|
||||
|
||||
To work with FastAPI you need to install <a href="https://www.python.org/" class="external-link" target="_blank">Python</a>.
|
||||
|
||||
After that, you would need to **install** FastAPI and any other **packages** you want to use.
|
||||
|
||||
To install packages you would normally use the `pip` command that comes with Python (or similar alternatives).
|
||||
|
||||
Nevertheless, if you just use `pip` directly, the packages would be installed in your **global Python environment** (the global installation of Python).
|
||||
|
||||
### The Problem
|
||||
|
||||
So, what's the problem with installing packages in the global Python environment?
|
||||
|
||||
At some point, you will probably end up writing many different programs that depend on **different packages**. And some of these projects you work on will depend on **different versions** of the same package. 😱
|
||||
|
||||
For example, you could create a project called `philosophers-stone`, this program depends on another package called **`harry`, using the version `1`**. So, you need to install `harry`.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
stone(philosophers-stone) -->|requires| harry-1[harry v1]
|
||||
```
|
||||
|
||||
Then, at some point later, you create another project called `prisoner-of-azkaban`, and this project also depends on `harry`, but this project needs **`harry` version `3`**.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
azkaban(prisoner-of-azkaban) --> |requires| harry-3[harry v3]
|
||||
```
|
||||
|
||||
But now the problem is, if you install the packages globally (in the global environment) instead of in a local **virtual environment**, you will have to choose which version of `harry` to install.
|
||||
|
||||
If you want to run `philosophers-stone` you will need to first install `harry` version `1`, for example with:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ pip install "harry==1"
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
And then you would end up with `harry` version `1` installed in your global Python environment.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph global[global env]
|
||||
harry-1[harry v1]
|
||||
end
|
||||
subgraph stone-project[philosophers-stone project]
|
||||
stone(philosophers-stone) -->|requires| harry-1
|
||||
end
|
||||
```
|
||||
|
||||
But then if you want to run `prisoner-of-azkaban`, you will need to uninstall `harry` version `1` and install `harry` version `3` (or just installing version `3` would automatically uninstall version `1`).
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ pip install "harry==3"
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
And then you would end up with `harry` version `3` installed in your global Python environment.
|
||||
|
||||
And if you try to run `philosophers-stone` again, there's a chance it would **not work** because it needs `harry` version `1`.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
subgraph global[global env]
|
||||
harry-1[<strike>harry v1</strike>]
|
||||
style harry-1 fill:#ccc,stroke-dasharray: 5 5
|
||||
harry-3[harry v3]
|
||||
end
|
||||
subgraph stone-project[philosophers-stone project]
|
||||
stone(philosophers-stone) -.-x|⛔️| harry-1
|
||||
end
|
||||
subgraph azkaban-project[prisoner-of-azkaban project]
|
||||
azkaban(prisoner-of-azkaban) --> |requires| harry-3
|
||||
end
|
||||
```
|
||||
|
||||
/// tip
|
||||
|
||||
It's very common in Python packages to try the best to **avoid breaking changes** in **new versions**, but it's better to be safe, and install newer versions intentionally and when you can run the tests to check everything is working correctly.
|
||||
|
||||
///
|
||||
|
||||
Now, imagine that with **many** other **packages** that all your **projects depend on**. That's very difficult to manage. And you would probably end up running some projects with some **incompatible versions** of the packages, and not knowing why something isn't working.
|
||||
|
||||
Also, depending on your operating system (e.g. Linux, Windows, macOS), it could have come with Python already installed. And in that case it probably had some packages pre-installed with some specific versions **needed by your system**. If you install packages in the global Python environment, you could end up **breaking** some of the programs that came with your operating system.
|
||||
|
||||
## Where are Packages Installed
|
||||
|
||||
When you install Python, it creates some directories with some files in your computer.
|
||||
|
||||
Some of these directories are the ones in charge of having all the packages you install.
|
||||
|
||||
When you run:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
// Don't run this now, it's just an example 🤓
|
||||
$ pip install "fastapi[standard]"
|
||||
---> 100%
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
That will download a compressed file with the FastAPI code, normally from <a href="https://pypi.org/project/fastapi/" class="external-link" target="_blank">PyPI</a>.
|
||||
|
||||
It will also **download** files for other packages that FastAPI depends on.
|
||||
|
||||
Then it will **extract** all those files and put them in a directory in your computer.
|
||||
|
||||
By default, it will put those files downloaded and extracted in the directory that comes with your Python installation, that's the **global environment**.
|
||||
|
||||
## What are Virtual Environments
|
||||
|
||||
The solution to the problems of having all the packages in the global environment is to use a **virtual environment for each project** you work on.
|
||||
|
||||
A virtual environment is a **directory**, very similar to the global one, where you can install the packages for a project.
|
||||
|
||||
This way, each project will have its own virtual environment (`.venv` directory) with its own packages.
|
||||
|
||||
```mermaid
|
||||
flowchart TB
|
||||
subgraph stone-project[philosophers-stone project]
|
||||
stone(philosophers-stone) --->|requires| harry-1
|
||||
subgraph venv1[.venv]
|
||||
harry-1[harry v1]
|
||||
end
|
||||
end
|
||||
subgraph azkaban-project[prisoner-of-azkaban project]
|
||||
azkaban(prisoner-of-azkaban) --->|requires| harry-3
|
||||
subgraph venv2[.venv]
|
||||
harry-3[harry v3]
|
||||
end
|
||||
end
|
||||
stone-project ~~~ azkaban-project
|
||||
```
|
||||
|
||||
## What Does Activating a Virtual Environment Mean
|
||||
|
||||
When you activate a virtual environment, for example with:
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source .venv/bin/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ .venv\Scripts\Activate.ps1
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows Bash
|
||||
|
||||
Or if you use Bash for Windows (e.g. <a href="https://gitforwindows.org/" class="external-link" target="_blank">Git Bash</a>):
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ source .venv/Scripts/activate
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
That command will create or modify some [environment variables](environment-variables.md){.internal-link target=_blank} that will be available for the next commands.
|
||||
|
||||
One of those variables is the `PATH` variable.
|
||||
|
||||
/// tip
|
||||
|
||||
You can learn more about the `PATH` environment variable in the [Environment Variables](environment-variables.md#path-environment-variable){.internal-link target=_blank} section.
|
||||
|
||||
///
|
||||
|
||||
Activating a virtual environment adds its path `.venv/bin` (on Linux and macOS) or `.venv\Scripts` (on Windows) to the `PATH` environment variable.
|
||||
|
||||
Let's say that before activating the environment, the `PATH` variable looked like this:
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
```plaintext
|
||||
/usr/bin:/bin:/usr/sbin:/sbin
|
||||
```
|
||||
|
||||
That means that the system would look for programs in:
|
||||
|
||||
* `/usr/bin`
|
||||
* `/bin`
|
||||
* `/usr/sbin`
|
||||
* `/sbin`
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows
|
||||
|
||||
```plaintext
|
||||
C:\Windows\System32
|
||||
```
|
||||
|
||||
That means that the system would look for programs in:
|
||||
|
||||
* `C:\Windows\System32`
|
||||
|
||||
////
|
||||
|
||||
After activating the virtual environment, the `PATH` variable would look something like this:
|
||||
|
||||
//// tab | Linux, macOS
|
||||
|
||||
```plaintext
|
||||
/home/user/code/awesome-project/.venv/bin:/usr/bin:/bin:/usr/sbin:/sbin
|
||||
```
|
||||
|
||||
That means that the system will now start looking first look for programs in:
|
||||
|
||||
```plaintext
|
||||
/home/user/code/awesome-project/.venv/bin
|
||||
```
|
||||
|
||||
before looking in the other directories.
|
||||
|
||||
So, when you type `python` in the terminal, the system will find the Python program in
|
||||
|
||||
```plaintext
|
||||
/home/user/code/awesome-project/.venv/bin/python
|
||||
```
|
||||
|
||||
and use that one.
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows
|
||||
|
||||
```plaintext
|
||||
C:\Users\user\code\awesome-project\.venv\Scripts;C:\Windows\System32
|
||||
```
|
||||
|
||||
That means that the system will now start looking first look for programs in:
|
||||
|
||||
```plaintext
|
||||
C:\Users\user\code\awesome-project\.venv\Scripts
|
||||
```
|
||||
|
||||
before looking in the other directories.
|
||||
|
||||
So, when you type `python` in the terminal, the system will find the Python program in
|
||||
|
||||
```plaintext
|
||||
C:\Users\user\code\awesome-project\.venv\Scripts\python
|
||||
```
|
||||
|
||||
and use that one.
|
||||
|
||||
////
|
||||
|
||||
An important detail is that it will put the virtual environment path at the **beginning** of the `PATH` variable. The system will find it **before** finding any other Python available. This way, when you run `python`, it will use the Python **from the virtual environment** instead of any other `python` (for example, a `python` from a global environment).
|
||||
|
||||
Activating a virtual environment also changes a couple of other things, but this is one of the most important things it does.
|
||||
|
||||
## Checking a Virtual Environment
|
||||
|
||||
When you check if a virtual environment is active, for example with:
|
||||
|
||||
//// tab | Linux, macOS, Windows Bash
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ which python
|
||||
|
||||
/home/user/code/awesome-project/.venv/bin/python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
//// tab | Windows PowerShell
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ Get-Command python
|
||||
|
||||
C:\Users\user\code\awesome-project\.venv\Scripts\python
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
////
|
||||
|
||||
That means that the `python` program that will be used is the one **in the virtual environment**.
|
||||
|
||||
you use `which` in Linux and macOS and `Get-Command` in Windows PowerShell.
|
||||
|
||||
The way that command works is that it will go and check in the `PATH` environment variable, going through **each path in order**, looking for the program called `python`. Once it finds it, it will **show you the path** to that program.
|
||||
|
||||
The most important part is that when you call `python`, that is the exact "`python`" that will be executed.
|
||||
|
||||
So, you can confirm if you are in the correct virtual environment.
|
||||
|
||||
/// tip
|
||||
|
||||
It's easy to activate one virtual environment, get one Python, and then **go to another project**.
|
||||
|
||||
And the second project **wouldn't work** because you are using the **incorrect Python**, from a virtual environment for another project.
|
||||
|
||||
It's useful being able to check what `python` is being used. 🤓
|
||||
|
||||
///
|
||||
|
||||
## Why Deactivate a Virtual Environment
|
||||
|
||||
For example, you could be working on a project `philosophers-stone`, **activate that virtual environment**, install packages and work with that environment.
|
||||
|
||||
And then you want to work on **another project** `prisoner-of-azkaban`.
|
||||
|
||||
You go to that project:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ cd ~/code/prisoner-of-azkaban
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
If you don't deactivate the virtual environment for `philosophers-stone`, when you run `python` in the terminal, it will try to use the Python from `philosophers-stone`.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ cd ~/code/prisoner-of-azkaban
|
||||
|
||||
$ python main.py
|
||||
|
||||
// Error importing sirius, it's not installed 😱
|
||||
Traceback (most recent call last):
|
||||
File "main.py", line 1, in <module>
|
||||
import sirius
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
But if you deactivate the virtual environment and activate the new one for `prisoner-of-askaban` then when you run `python` it will use the Python from the virtual environment in `prisoner-of-azkaban`.
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ cd ~/code/prisoner-of-azkaban
|
||||
|
||||
// You don't need to be in the old directory to deactivate, you can do it wherever you are, even after going to the other project 😎
|
||||
$ deactivate
|
||||
|
||||
// Activate the virtual environment in prisoner-of-azkaban/.venv 🚀
|
||||
$ source .venv/bin/activate
|
||||
|
||||
// Now when you run python, it will find the package sirius installed in this virtual environment ✨
|
||||
$ python main.py
|
||||
|
||||
I solemnly swear 🐺
|
||||
```
|
||||
|
||||
</div>
|
||||
|
||||
## Alternatives
|
||||
|
||||
This is a simple guide to get you started and teach you how everything works **underneath**.
|
||||
|
||||
There are many **alternatives** to managing virtual environments, package dependencies (requirements), projects.
|
||||
|
||||
Once you are ready and want to use a tool to **manage the entire project**, packages dependencies, virtual environments, etc. I would suggest you try <a href="https://github.com/astral-sh/uv" class="external-link" target="_blank">uv</a>.
|
||||
|
||||
`uv` can do a lot of things, it can:
|
||||
|
||||
* **Install Python** for you, including different versions
|
||||
* Manage the **virtual environment** for your projects
|
||||
* Install **packages**
|
||||
* Manage package **dependencies and versions** for your project
|
||||
* Make sure you have an **exact** set of packages and versions to install, including their dependencies, so that you can be sure that you can run your project in production exactly the same as in your computer while developing, this is called **locking**
|
||||
* And many other things
|
||||
|
||||
## Conclusion
|
||||
|
||||
If you read and understood all this, now **you know much more** about virtual environments than many developers out there. 🤓
|
||||
|
||||
Knowing these details will most probably be useful in a future time when you are debugging something that seems complex, but you will know **how it all works underneath**. 😎
|
||||
@@ -102,13 +102,14 @@ plugins:
|
||||
show_symbol_type_toc: true
|
||||
|
||||
nav:
|
||||
- FastAPI:
|
||||
- index.md
|
||||
- features.md
|
||||
- FastAPI: index.md
|
||||
- features.md
|
||||
- Learn:
|
||||
- learn/index.md
|
||||
- python-types.md
|
||||
- async.md
|
||||
- environment-variables.md
|
||||
- virtual-environments.md
|
||||
- Tutorial - User Guide:
|
||||
- tutorial/index.md
|
||||
- tutorial/first-steps.md
|
||||
|
||||
@@ -18,7 +18,7 @@ Para conseguir esto importa `JSONResponse` y devuelve ahí directamente tu conte
|
||||
{!../../../docs_src/additional_status_codes/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// warning | "Advertencia"
|
||||
/// warning | Advertencia
|
||||
|
||||
Cuando devuelves directamente una `Response`, como en los ejemplos anteriores, será devuelta directamente.
|
||||
|
||||
@@ -28,7 +28,7 @@ Asegúrate de que la respuesta tenga los datos que quieras, y que los valores se
|
||||
|
||||
///
|
||||
|
||||
/// note | "Detalles Técnicos"
|
||||
/// note | Detalles Técnicos
|
||||
|
||||
También podrías utilizar `from starlette.responses import JSONResponse`.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ El [Tutorial - Guía de Usuario](../tutorial/index.md){.internal-link target=_bl
|
||||
|
||||
En las secciones siguientes verás otras opciones, configuraciones, y características adicionales.
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Las próximas secciones **no son necesariamente "avanzadas"**.
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ Deberías hacerlo después de adicionar todas tus *operaciones de path*.
|
||||
{!../../../docs_src/path_operation_advanced_configuration/tutorial002.py!}
|
||||
```
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
Si llamas manualmente a `app.openapi()`, debes actualizar el `operationId`s antes de hacerlo.
|
||||
|
||||
///
|
||||
|
||||
/// warning | "Advertencia"
|
||||
/// warning | Advertencia
|
||||
|
||||
Si haces esto, debes asegurarte de que cada una de tus *funciones de las operaciones de path* tenga un nombre único.
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ Esto puede ser útil, por ejemplo, para devolver cookies o headers personalizado
|
||||
|
||||
De hecho, puedes devolver cualquier `Response` o cualquier subclase de la misma.
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
`JSONResponse` en sí misma es una subclase de `Response`.
|
||||
|
||||
@@ -38,7 +38,7 @@ Para esos casos, puedes usar el `jsonable_encoder` para convertir tus datos ante
|
||||
{!../../../docs_src/response_directly/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// note | "Detalles Técnicos"
|
||||
/// note | Detalles Técnicos
|
||||
|
||||
También puedes usar `from starlette.responses import JSONResponse`.
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ Crea un response tal como se describe en [Retornar una respuesta directamente](r
|
||||
{!../../../docs_src/response_headers/tutorial001.py!}
|
||||
```
|
||||
|
||||
/// note | "Detalles Técnicos"
|
||||
/// note | Detalles Técnicos
|
||||
|
||||
También podrías utilizar `from starlette.responses import Response` o `from starlette.responses import JSONResponse`.
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Hay algunas características adicionales para manejar la seguridad además de las que se tratan en el [Tutorial - Guía de Usuario: Seguridad](../../tutorial/security/index.md){.internal-link target=_blank}.
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Las siguientes secciones **no necesariamente son "avanzadas"**.
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ async def read_results():
|
||||
return results
|
||||
```
|
||||
|
||||
/// note | "Nota"
|
||||
/// note | Nota
|
||||
|
||||
Solo puedes usar `await` dentro de funciones creadas con `async def`.
|
||||
|
||||
@@ -138,7 +138,7 @@ Tú y esa persona 😍 se comen las hamburguesas 🍔 y la pasan genial ✨.
|
||||
|
||||
<img src="https://fastapi.tiangolo.com/img/async/concurrent-burgers/concurrent-burgers-07.png" alt="illustration">
|
||||
|
||||
/// info
|
||||
/// info | Información
|
||||
|
||||
Las ilustraciones fueron creados por <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">Ketrina Thompson</a>. 🎨
|
||||
|
||||
@@ -204,7 +204,7 @@ Sólo las comes y listo 🍔 ⏹.
|
||||
|
||||
No has hablado ni coqueteado mucho, ya que has pasado la mayor parte del tiempo esperando 🕙 frente al mostrador 😞.
|
||||
|
||||
/// info
|
||||
/// info | Información
|
||||
|
||||
Las ilustraciones fueron creados por <a href="https://www.instagram.com/ketrinadrawsalot" class="external-link" target="_blank">Ketrina Thompson</a>. 🎨
|
||||
|
||||
@@ -396,7 +396,7 @@ Todo eso es lo que impulsa FastAPI (a través de Starlette) y lo que hace que te
|
||||
|
||||
## Detalles muy técnicos
|
||||
|
||||
/// warning | "Advertencia"
|
||||
/// warning | Advertencia
|
||||
|
||||
Probablemente puedas saltarte esto.
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ Siguiendo las convenciones de *Semantic Versioning*, cualquier versión por deba
|
||||
|
||||
FastAPI también sigue la convención de que cualquier cambio hecho en una <abbr title="versiones de parche">"PATCH" version</abbr> es para solucionar errores y <abbr title="cambios que no rompan funcionalidades o compatibilidad">*non-breaking changes*</abbr>.
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
El <abbr title="parche">"PATCH"</abbr> es el último número, por ejemplo, en `0.2.3`, la <abbr title="versiones de parche">PATCH version</abbr> es `3`.
|
||||
|
||||
@@ -56,7 +56,7 @@ fastapi>=0.45.0,<0.46.0
|
||||
|
||||
En versiones <abbr title="versiones menores">"MINOR"</abbr> son añadidas nuevas características y posibles <abbr title="Cambios que rompen posibles funcionalidades o compatibilidad">breaking changes</abbr>.
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
La versión "MINOR" es el número en el medio, por ejemplo, en `0.2.3`, la <abbr title="versión menor">"MINOR" version</abbr> es `2`.
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ second_user_data = {
|
||||
my_second_user: User = User(**second_user_data)
|
||||
```
|
||||
|
||||
/// info
|
||||
/// info | Información
|
||||
|
||||
`**second_user_data` significa:
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ Como **FastAPI** está basado en el estándar **ASGI**, es muy fácil integrar c
|
||||
|
||||
Puedes combinar *operaciones de path* regulares de la library de FastAPI con GraphQL en la misma aplicación.
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
**GraphQL** resuelve algunos casos de uso específicos.
|
||||
|
||||
@@ -49,7 +49,7 @@ Versiones anteriores de Starlette incluyen la clase `GraphQLApp` para integrarlo
|
||||
|
||||
Esto fue marcado como obsoleto en Starlette, pero si aún tienes código que lo usa, puedes fácilmente **migrar** a <a href="https://github.com/ciscorn/starlette-graphene3" class="external-link" target="_blank">starlette-graphene3</a>, la cual cubre el mismo caso de uso y tiene una **interfaz casi idéntica.**
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Si necesitas GraphQL, te recomendaría revisar <a href="https://strawberry.rocks/" class="external-link" target="_blank">Strawberry</a>, que es basada en anotaciones de tipo en vez de clases y tipos personalizados.
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ Para entender más al respecto revisa la sección <a href="https://fastapi.tiang
|
||||
|
||||
Usadas por Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - para validación de emails.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - para validación de emails.
|
||||
|
||||
Usados por Starlette:
|
||||
|
||||
|
||||
28
docs/es/docs/project-generation.md
Normal file
28
docs/es/docs/project-generation.md
Normal file
@@ -0,0 +1,28 @@
|
||||
# Plantilla de FastAPI Full Stack
|
||||
|
||||
Las plantillas, aunque típicamente vienen con una configuración específica, están diseñadas para ser flexibles y personalizables. Esto te permite modificarlas y adaptarlas a los requisitos de tu proyecto, lo que las convierte en un excelente punto de partida. 🏁
|
||||
|
||||
Puedes utilizar esta plantilla para comenzar, ya que incluye gran parte de la configuración inicial, seguridad, base de datos y algunos endpoints de API ya realizados.
|
||||
|
||||
Repositorio en GitHub: [Full Stack FastAPI Template](https://github.com/tiangolo/full-stack-fastapi-template)
|
||||
|
||||
## Plantilla de FastAPI Full Stack - Tecnología y Características
|
||||
|
||||
- ⚡ [**FastAPI**](https://fastapi.tiangolo.com) para el backend API en Python.
|
||||
- 🧰 [SQLModel](https://sqlmodel.tiangolo.com) para las interacciones con la base de datos SQL en Python (ORM).
|
||||
- 🔍 [Pydantic](https://docs.pydantic.dev), utilizado por FastAPI, para la validación de datos y la gestión de configuraciones.
|
||||
- 💾 [PostgreSQL](https://www.postgresql.org) como la base de datos SQL.
|
||||
- 🚀 [React](https://react.dev) para el frontend.
|
||||
- 💃 Usando TypeScript, hooks, Vite y otras partes de un stack de frontend moderno.
|
||||
- 🎨 [Chakra UI](https://chakra-ui.com) para los componentes del frontend.
|
||||
- 🤖 Un cliente frontend generado automáticamente.
|
||||
- 🧪 Playwright para pruebas End-to-End.
|
||||
- 🦇 Soporte para modo oscuro.
|
||||
- 🐋 [Docker Compose](https://www.docker.com) para desarrollo y producción.
|
||||
- 🔒 Hashing seguro de contraseñas por defecto.
|
||||
- 🔑 Autenticación con token JWT.
|
||||
- 📫 Recuperación de contraseñas basada en email.
|
||||
- ✅ Tests con [Pytest](https://pytest.org).
|
||||
- 📞 [Traefik](https://traefik.io) como proxy inverso / balanceador de carga.
|
||||
- 🚢 Instrucciones de despliegue utilizando Docker Compose, incluyendo cómo configurar un proxy frontend Traefik para manejar certificados HTTPS automáticos.
|
||||
- 🏭 CI (integración continua) y CD (despliegue continuo) basados en GitHub Actions.
|
||||
@@ -12,7 +12,7 @@ Todo **FastAPI** está basado en estos type hints, lo que le da muchas ventajas
|
||||
|
||||
Pero, así nunca uses **FastAPI** te beneficiarás de aprender un poco sobre los type hints.
|
||||
|
||||
/// note | "Nota"
|
||||
/// note | Nota
|
||||
|
||||
Si eres un experto en Python y ya lo sabes todo sobre los type hints, salta al siguiente capítulo.
|
||||
|
||||
@@ -256,7 +256,7 @@ Tomado de la documentación oficial de Pydantic:
|
||||
{!../../../docs_src/python_types/tutorial010.py!}
|
||||
```
|
||||
|
||||
/// info | "Información"
|
||||
/// info | Información
|
||||
|
||||
Para aprender más sobre <a href="https://docs.pydantic.dev/" class="external-link" target="_blank">Pydantic mira su documentación</a>.
|
||||
|
||||
@@ -288,7 +288,7 @@ Puede que todo esto suene abstracto. Pero no te preocupes que todo lo verás en
|
||||
|
||||
Lo importante es que usando los tipos de Python estándar en un único lugar (en vez de añadir más clases, decorator, etc.) **FastAPI** hará mucho del trabajo por ti.
|
||||
|
||||
/// info | "Información"
|
||||
/// info | Información
|
||||
|
||||
Si ya pasaste por todo el tutorial y volviste a la sección de los tipos, una buena referencia es <a href="https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html" class="external-link" target="_blank">la "cheat sheet" de `mypy`</a>.
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ Primero importa `Cookie`:
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
Es preferible utilizar la versión `Annotated` si es posible.
|
||||
|
||||
///
|
||||
|
||||
@@ -46,9 +46,9 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
Es preferible utilizar la versión `Annotated` si es posible.
|
||||
|
||||
///
|
||||
|
||||
@@ -90,9 +90,9 @@ El primer valor es el valor por defecto, puedes pasar todos los parámetros adic
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
Es preferible utilizar la versión `Annotated` si es posible.
|
||||
|
||||
///
|
||||
|
||||
@@ -104,9 +104,9 @@ Prefer to use the `Annotated` version if possible.
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip
|
||||
/// tip | Consejo
|
||||
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
Es preferible utilizar la versión `Annotated` si es posible.
|
||||
|
||||
///
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ $ uvicorn main:app --reload
|
||||
|
||||
</div>
|
||||
|
||||
/// note | "Nota"
|
||||
/// note | Nota
|
||||
|
||||
El comando `uvicorn main:app` se refiere a:
|
||||
|
||||
@@ -139,7 +139,7 @@ También podrías usarlo para generar código automáticamente, para los cliente
|
||||
|
||||
`FastAPI` es una clase de Python que provee toda la funcionalidad para tu API.
|
||||
|
||||
/// note | "Detalles Técnicos"
|
||||
/// note | Detalles Técnicos
|
||||
|
||||
`FastAPI` es una clase que hereda directamente de `Starlette`.
|
||||
|
||||
@@ -205,7 +205,7 @@ https://example.com/items/foo
|
||||
/items/foo
|
||||
```
|
||||
|
||||
/// info | "Información"
|
||||
/// info | Información
|
||||
|
||||
Un "path" también se conoce habitualmente como "endpoint", "route" o "ruta".
|
||||
|
||||
@@ -259,7 +259,7 @@ El `@app.get("/")` le dice a **FastAPI** que la función que tiene justo debajo
|
||||
* el path `/`
|
||||
* usando una <abbr title="an HTTP GET method">operación <code>get</code></abbr>
|
||||
|
||||
/// info | "Información sobre `@decorator`"
|
||||
/// info | Información sobre `@decorator`
|
||||
|
||||
Esa sintaxis `@algo` se llama un "decorador" en Python.
|
||||
|
||||
@@ -286,7 +286,7 @@ y las más exóticas:
|
||||
* `@app.patch()`
|
||||
* `@app.trace()`
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
Tienes la libertad de usar cada operación (método de HTTP) como quieras.
|
||||
|
||||
@@ -324,7 +324,7 @@ También podrías definirla como una función estándar en lugar de `async def`:
|
||||
{!../../../docs_src/first_steps/tutorial003.py!}
|
||||
```
|
||||
|
||||
/// note | "Nota"
|
||||
/// note | Nota
|
||||
|
||||
Si no sabes la diferencia, revisa el [Async: *"¿Tienes prisa?"*](../async.md#tienes-prisa){.internal-link target=_blank}.
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ Puedes declarar el tipo de un parámetro de path en la función usando las anota
|
||||
|
||||
En este caso, `item_id` es declarado como un `int`.
|
||||
|
||||
/// check | "Revisa"
|
||||
/// check | Revisa
|
||||
|
||||
Esto te dará soporte en el editor dentro de tu función, con chequeo de errores, auto-completado, etc.
|
||||
|
||||
@@ -38,7 +38,7 @@ Si corres este ejemplo y abres tu navegador en <a href="http://127.0.0.1:8000/it
|
||||
{"item_id":3}
|
||||
```
|
||||
|
||||
/// check | "Revisa"
|
||||
/// check | Revisa
|
||||
|
||||
Observa que el valor que recibió (y devolvió) tu función es `3`, como un Python `int`, y no un string `"3"`.
|
||||
|
||||
@@ -69,7 +69,7 @@ debido a que el parámetro de path `item_id` tenía el valor `"foo"`, que no es
|
||||
|
||||
El mismo error aparecería si pasaras un `float` en vez de un `int` como en: <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 | "Revisa"
|
||||
/// check | Revisa
|
||||
|
||||
Así, con la misma declaración de tipo de Python, **FastAPI** te da validación de datos.
|
||||
|
||||
@@ -85,7 +85,7 @@ Cuando abras tu navegador en <a href="http://127.0.0.1:8000/docs" class="externa
|
||||
|
||||
<img src="/img/tutorial/path-params/image01.png">
|
||||
|
||||
/// check | "Revisa"
|
||||
/// check | Revisa
|
||||
|
||||
Nuevamente, con la misma declaración de tipo de Python, **FastAPI** te da documentación automática e interactiva (integrándose con Swagger UI)
|
||||
|
||||
@@ -143,13 +143,13 @@ Luego crea atributos de clase con valores fijos, que serán los valores disponib
|
||||
{!../../../docs_src/path_params/tutorial005.py!}
|
||||
```
|
||||
|
||||
/// info | "Información"
|
||||
/// info | Información
|
||||
|
||||
Las <a href="https://docs.python.org/3/library/enum.html" class="external-link" target="_blank">Enumerations (o enums) están disponibles en Python</a> desde la versión 3.4.
|
||||
|
||||
///
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
Si lo estás dudando, "AlexNet", "ResNet", y "LeNet" son solo nombres de <abbr title="Técnicamente, arquitecturas de modelos de Deep Learning">modelos</abbr> de Machine Learning.
|
||||
|
||||
@@ -189,7 +189,7 @@ Puedes obtener el valor exacto (un `str` en este caso) usando `model_name.value`
|
||||
{!../../../docs_src/path_params/tutorial005.py!}
|
||||
```
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
También podrías obtener el valor `"lenet"` con `ModelName.lenet.value`.
|
||||
|
||||
@@ -246,7 +246,7 @@ Entonces lo puedes usar con:
|
||||
{!../../../docs_src/path_params/tutorial004.py!}
|
||||
```
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
Podrías necesitar que el parámetro contenga `/home/johndoe/myfile.txt` con un slash inicial (`/`).
|
||||
|
||||
|
||||
@@ -69,13 +69,13 @@ Del mismo modo puedes declarar parámetros de query opcionales definiendo el val
|
||||
|
||||
En este caso el parámetro de la función `q` será opcional y será `None` por defecto.
|
||||
|
||||
/// check | "Revisa"
|
||||
/// check | Revisa
|
||||
|
||||
También puedes notar que **FastAPI** es lo suficientemente inteligente para darse cuenta de que el parámetro de path `item_id` es un parámetro de path y que `q` no lo es, y por lo tanto es un parámetro de query.
|
||||
|
||||
///
|
||||
|
||||
/// note | "Nota"
|
||||
/// note | Nota
|
||||
|
||||
FastAPI sabrá que `q` es opcional por el `= None`.
|
||||
|
||||
@@ -199,7 +199,7 @@ En este caso hay 3 parámetros de query:
|
||||
* `skip`, un `int` con un valor por defecto de `0`.
|
||||
* `limit`, un `int` opcional.
|
||||
|
||||
/// tip | "Consejo"
|
||||
/// tip | Consejo
|
||||
|
||||
También podrías usar los `Enum`s de la misma manera que con los [Parámetros de path](path-params.md#valores-predefinidos){.internal-link target=_blank}.
|
||||
|
||||
|
||||
@@ -442,7 +442,7 @@ item: Item
|
||||
|
||||
استفاده شده توسط Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - برای اعتبارسنجی آدرسهای ایمیل.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - برای اعتبارسنجی آدرسهای ایمیل.
|
||||
|
||||
استفاده شده توسط Starlette:
|
||||
|
||||
|
||||
@@ -1,180 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# La communauté FastAPI
|
||||
|
||||
FastAPI a une communauté extraordinaire qui accueille des personnes de tous horizons.
|
||||
|
||||
## Créateur - Mainteneur
|
||||
|
||||
Salut! 👋
|
||||
|
||||
C'est moi :
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Réponses: {{ user.answers }}</div><div class="count">Pull Requests: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Je suis le créateur et le responsable de **FastAPI**. Vous pouvez en lire plus à ce sujet dans [Aide FastAPI - Obtenir de l'aide - Se rapprocher de l'auteur](help-fastapi.md#se-rapprocher-de-lauteur){.internal-link target=_blank}.
|
||||
|
||||
...Mais ici, je veux vous montrer la communauté.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** reçoit beaucoup de soutien de la part de la communauté. Et je tiens à souligner leurs contributions.
|
||||
|
||||
Ce sont ces personnes qui :
|
||||
|
||||
* [Aident les autres à résoudre des problèmes (questions) dans GitHub](help-fastapi.md#aider-les-autres-a-resoudre-les-problemes-dans-github){.internal-link target=_blank}.
|
||||
* [Créent des Pull Requests](help-fastapi.md#creer-une-pull-request){.internal-link target=_blank}.
|
||||
* Review les Pull Requests, [particulièrement important pour les traductions](contributing.md#traductions){.internal-link target=_blank}.
|
||||
|
||||
Une salve d'applaudissements pour eux. 👏 🙇
|
||||
|
||||
## Utilisateurs les plus actifs le mois dernier
|
||||
|
||||
Ce sont les utilisateurs qui ont [aidé le plus les autres avec des problèmes (questions) dans GitHub](help-fastapi.md#aider-les-autres-a-resoudre-les-problemes-dans-github){.internal-link target=_blank} au cours du dernier mois. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Questions répondues: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Experts
|
||||
|
||||
Voici les **Experts FastAPI**. 🤓
|
||||
|
||||
Ce sont les utilisateurs qui ont [aidé le plus les autres avec des problèmes (questions) dans GitHub](help-fastapi.md#aider-les-autres-a-resoudre-les-problemes-dans-github){.internal-link target=_blank} depuis *toujours*.
|
||||
|
||||
Ils ont prouvé qu'ils étaient des experts en aidant beaucoup d'autres personnes. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Questions répondues: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Principaux contributeurs
|
||||
|
||||
Ces utilisateurs sont les **Principaux contributeurs**. 👷
|
||||
|
||||
Ces utilisateurs ont [créé le plus grand nombre de demandes Pull Request](help-fastapi.md#creer-une-pull-request){.internal-link target=_blank} qui ont été *merged*.
|
||||
|
||||
Ils ont contribué au code source, à la documentation, aux traductions, etc. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requests: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Il existe de nombreux autres contributeurs (plus d'une centaine), vous pouvez les voir tous dans la <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">Page des contributeurs de FastAPI GitHub</a>. 👷
|
||||
|
||||
## Principaux Reviewers
|
||||
|
||||
Ces utilisateurs sont les **Principaux Reviewers**. 🕵️
|
||||
|
||||
### Reviewers des traductions
|
||||
|
||||
Je ne parle que quelques langues (et pas très bien 😅). Ainsi, les reviewers sont ceux qui ont le [**pouvoir d'approuver les traductions**](contributing.md#traductions){.internal-link target=_blank} de la documentation. Sans eux, il n'y aurait pas de documentation dans plusieurs autres langues.
|
||||
|
||||
---
|
||||
|
||||
Les **Principaux Reviewers** 🕵️ ont examiné le plus grand nombre de demandes Pull Request des autres, assurant la qualité du code, de la documentation, et surtout, des **traductions**.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Reviews: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsors
|
||||
|
||||
Ce sont les **Sponsors**. 😎
|
||||
|
||||
Ils soutiennent mon travail avec **FastAPI** (et d'autres) avec <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsors</a>.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Gold 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 %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Silver Sponsors
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Bronze Sponsors
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
### Individual Sponsors
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## À propos des données - détails techniques
|
||||
|
||||
L'intention de cette page est de souligner l'effort de la communauté pour aider les autres.
|
||||
|
||||
Notamment en incluant des efforts qui sont normalement moins visibles, et, dans de nombreux cas, plus difficile, comme aider d'autres personnes à résoudre des problèmes et examiner les Pull Requests de traduction.
|
||||
|
||||
Les données sont calculées chaque mois, vous pouvez lire le <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">code source ici</a>.
|
||||
|
||||
Je me réserve également le droit de mettre à jour l'algorithme, les sections, les seuils, etc. (juste au cas où 🤷).
|
||||
@@ -449,7 +449,7 @@ Pour en savoir plus, consultez la section <a href="https://fastapi.tiangolo.com/
|
||||
|
||||
Utilisées par Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - pour la validation des adresses email.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - pour la validation des adresses email.
|
||||
|
||||
Utilisées par Starlette :
|
||||
|
||||
|
||||
@@ -446,7 +446,7 @@ item: Item
|
||||
|
||||
בשימוש Pydantic:
|
||||
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - לאימות כתובות אימייל.
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - לאימות כתובות אימייל.
|
||||
|
||||
בשימוש Starlette:
|
||||
|
||||
|
||||
@@ -443,7 +443,7 @@ Ezeknek a további megértéséhez: <a href="https://fastapi.tiangolo.com/benchm
|
||||
|
||||
Pydantic által használt:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - e-mail validációkra.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - e-mail validációkra.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" target="_blank"><code>pydantic-settings</code></a> - Beállítások követésére.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/" target="_blank"><code>pydantic-extra-types</code></a> - Extra típusok Pydantic-hoz.
|
||||
|
||||
|
||||
@@ -437,7 +437,7 @@ Per approfondire, consulta la sezione <a href="https://fastapi.tiangolo.com/benc
|
||||
|
||||
Usate da Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - per la validazione di email.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - per la validazione di email.
|
||||
|
||||
Usate da Starlette:
|
||||
|
||||
|
||||
@@ -1,184 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI People
|
||||
|
||||
FastAPIには、様々なバックグラウンドの人々を歓迎する素晴らしいコミュニティがあります。
|
||||
|
||||
## Creator - Maintainer
|
||||
|
||||
こんにちは! 👋
|
||||
|
||||
これが私です:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Answers: {{ user.answers }}</div><div class="count">Pull Requests: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endif %}
|
||||
|
||||
私は **FastAPI** の作成者および Maintainer です。詳しくは [FastAPIを応援 - ヘルプの入手 - 開発者とつながる](help-fastapi.md#_1){.internal-link target=_blank} に記載しています。
|
||||
|
||||
...ところで、ここではコミュニティを紹介したいと思います。
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** は、コミュニティから多くのサポートを受けています。そこで、彼らの貢献にスポットライトを当てたいと思います。
|
||||
|
||||
紹介するのは次のような人々です:
|
||||
|
||||
* [GitHub issuesで他の人を助ける](help-fastapi.md#github-issues){.internal-link target=_blank}。
|
||||
* [プルリクエストをする](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}。
|
||||
* プルリクエストのレビューをする ([特に翻訳に重要](contributing.md#_8){.internal-link target=_blank})。
|
||||
|
||||
彼らに大きな拍手を。👏 🙇
|
||||
|
||||
## 先月最もアクティブだったユーザー
|
||||
|
||||
彼らは、先月の[GitHub issuesで最も多くの人を助けた](help-fastapi.md#github-issues){.internal-link target=_blank}ユーザーです。☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues replied: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Experts
|
||||
|
||||
**FastAPI experts** を紹介します。🤓
|
||||
|
||||
彼らは、*これまでに* [GitHub issuesで最も多くの人を助けた](help-fastapi.md#github-issues){.internal-link target=_blank}ユーザーです。
|
||||
|
||||
多くの人を助けることでexpertsであると示されています。✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues replied: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Top Contributors
|
||||
|
||||
**Top Contributors** を紹介します。👷
|
||||
|
||||
彼らは、*マージされた* [最も多くのプルリクエストを作成した](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}ユーザーです。
|
||||
|
||||
ソースコード、ドキュメント、翻訳などに貢献してくれました。📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requests: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
他にもたくさん (100人以上) の contributors がいます。<a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI GitHub Contributors ページ</a>ですべての contributors を確認できます。👷
|
||||
|
||||
## Top Reviewers
|
||||
|
||||
以下のユーザーは **Top Reviewers** です。🕵️
|
||||
|
||||
### 翻訳のレビュー
|
||||
|
||||
私は少しの言語しか話せません (もしくはあまり上手ではありません😅)。したがって、reviewers は、ドキュメントの[**翻訳を承認する権限**](contributing.md#_8){.internal-link target=_blank}を持っています。それらがなければ、いくつかの言語のドキュメントはなかったでしょう。
|
||||
|
||||
---
|
||||
|
||||
**Top Reviewers** 🕵️は、他の人からのプルリクエストのほとんどをレビューし、コード、ドキュメント、特に**翻訳**の品質を保証しています。
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Reviews: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsors
|
||||
|
||||
**Sponsors** を紹介します。😎
|
||||
|
||||
彼らは、<a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsors</a> を介して私の **FastAPI** などに関する活動を支援してくれています。
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Gold 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 %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Silver Sponsors
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Bronze Sponsors
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### Individual Sponsors
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## データについて - 技術詳細
|
||||
|
||||
このページの目的は、他の人を助けるためのコミュニティの努力にスポットライトを当てるためです。
|
||||
|
||||
特に、他の人の issues を支援したり、翻訳のプルリクエストを確認したりするなど、通常は目立たず、多くの場合、より困難な作業を含みます。
|
||||
|
||||
データは毎月集計されます。<a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">ソースコードはこちら</a>で確認できます。
|
||||
|
||||
ここでは、スポンサーの貢献も強調しています。
|
||||
|
||||
アルゴリズム、セクション、閾値などは更新されるかもしれません (念のために 🤷)。
|
||||
@@ -435,7 +435,7 @@ item: Item
|
||||
|
||||
Pydantic によって使用されるもの:
|
||||
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - E メールの検証
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - E メールの検証
|
||||
|
||||
Starlette によって使用されるもの:
|
||||
|
||||
|
||||
5
docs/ja/docs/learn/index.md
Normal file
5
docs/ja/docs/learn/index.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# 学習
|
||||
|
||||
ここでは、**FastAPI** を学習するための入門セクションとチュートリアルを紹介します。
|
||||
|
||||
これは、FastAPIを学習するにあたっての**書籍**や**コース**であり、**公式**かつ推奨される方法とみなすことができます 😎
|
||||
@@ -441,7 +441,7 @@ item: Item
|
||||
|
||||
Pydantic이 사용하는:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - 이메일 유효성 검사.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - 이메일 유효성 검사.
|
||||
|
||||
Starlette이 사용하는:
|
||||
|
||||
|
||||
@@ -1,178 +0,0 @@
|
||||
# Ludzie FastAPI
|
||||
|
||||
FastAPI posiada wspaniałą społeczność, która jest otwarta dla ludzi z każdego środowiska.
|
||||
|
||||
## Twórca - Opienik
|
||||
|
||||
Cześć! 👋
|
||||
|
||||
To ja:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Liczba odpowiedzi: {{ user.answers }}</div><div class="count">Pull Requesty: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Jestem twórcą i opiekunem **FastAPI**. Możesz przeczytać więcej na ten temat w [Pomoc FastAPI - Uzyskaj pomoc - Skontaktuj się z autorem](help-fastapi.md#connect-with-the-author){.internal-link target=_blank}.
|
||||
|
||||
...Ale tutaj chcę pokazać Ci społeczność.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** otrzymuje wiele wsparcia od społeczności. Chciałbym podkreślić ich wkład.
|
||||
|
||||
To są ludzie, którzy:
|
||||
|
||||
* [Pomagają innym z pytaniami na GitHub](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank}.
|
||||
* [Tworzą Pull Requesty](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
|
||||
* Oceniają Pull Requesty, [to szczególnie ważne dla tłumaczeń](contributing.md#translations){.internal-link target=_blank}.
|
||||
|
||||
Proszę o brawa dla nich. 👏 🙇
|
||||
|
||||
## Najaktywniejsi użytkownicy w zeszłym miesiącu
|
||||
|
||||
Oto niektórzy użytkownicy, którzy [pomagali innym w największej liczbie pytań na GitHubie](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} podczas ostatniego miesiąca. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_active %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Udzielonych odpowiedzi: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Eksperci
|
||||
|
||||
Oto **eksperci FastAPI**. 🤓
|
||||
|
||||
To użytkownicy, którzy [pomogli innym z największa liczbą pytań na GitHubie](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} od *samego początku*.
|
||||
|
||||
Poprzez pomoc wielu innym, udowodnili, że są ekspertami. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Udzielonych odpowiedzi: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Najlepsi Kontrybutorzy
|
||||
|
||||
Oto **Najlepsi Kontrybutorzy**. 👷
|
||||
|
||||
Ci użytkownicy [stworzyli najwięcej Pull Requestów](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}, które zostały *wcalone*.
|
||||
|
||||
Współtworzyli kod źródłowy, dokumentację, tłumaczenia itp. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requesty: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Jest wielu więcej kontrybutorów (ponad setka), możesz zobaczyć ich wszystkich na stronie <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">Kontrybutorzy FastAPI na GitHub</a>. 👷
|
||||
|
||||
## Najlepsi Oceniajacy
|
||||
|
||||
Ci uzytkownicy są **Najlepszymi oceniającymi**. 🕵️
|
||||
|
||||
### Oceny Tłumaczeń
|
||||
|
||||
Ja mówię tylko kilkoma językami (i to niezbyt dobrze 😅). Zatem oceniający są tymi, którzy mają [**moc zatwierdzania tłumaczeń**](contributing.md#translations){.internal-link target=_blank} dokumentacji. Bez nich nie byłoby dokumentacji w kilku innych językach.
|
||||
|
||||
---
|
||||
|
||||
**Najlepsi Oceniający** 🕵️ przejrzeli więcej Pull Requestów, niż inni, zapewniając jakość kodu, dokumentacji, a zwłaszcza **tłumaczeń**.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_reviewers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Liczba ocen: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsorzy
|
||||
|
||||
Oto **Sponsorzy**. 😎
|
||||
|
||||
Wspierają moją pracę nad **FastAPI** (i innymi), głównie poprzez <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsors</a>.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Złoci Sponsorzy
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Srebrni Sponsorzy
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Brązowi Sponsorzy
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### Indywidualni Sponsorzy
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## Techniczne szczegóły danych
|
||||
|
||||
Głównym celem tej strony jest podkreślenie wysiłku społeczności w pomaganiu innym.
|
||||
|
||||
Szczególnie włączając wysiłki, które są zwykle mniej widoczne, a w wielu przypadkach bardziej żmudne, tak jak pomaganie innym z pytaniami i ocenianie Pull Requestów z tłumaczeniami.
|
||||
|
||||
Dane są obliczane każdego miesiąca, możesz przeczytać <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">kod źródłowy tutaj</a>.
|
||||
|
||||
Tutaj również podkreślam wkład od sponsorów.
|
||||
|
||||
Zastrzegam sobie prawo do aktualizacji algorytmu, sekcji, progów itp. (na wszelki wypadek 🤷).
|
||||
@@ -439,7 +439,7 @@ Aby dowiedzieć się o tym więcej, zobacz sekcję <a href="https://fastapi.tian
|
||||
|
||||
Używane przez Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - dla walidacji adresów email.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - dla walidacji adresów email.
|
||||
|
||||
Używane przez Starlette:
|
||||
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# Pessoas do FastAPI
|
||||
|
||||
FastAPI possue uma comunidade incrível que recebe pessoas de todos os níveis.
|
||||
|
||||
## Criador - Mantenedor
|
||||
|
||||
Ei! 👋
|
||||
|
||||
Este sou eu:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Respostas: {{ user.answers }}</div><div class="count">Pull Requests: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Eu sou o criador e mantenedor do **FastAPI**. Você pode ler mais sobre isso em [Help FastAPI - Get Help - Connect with the author](help-fastapi.md#conect-se-com-o-autor){.internal-link target=_blank}.
|
||||
|
||||
...Mas aqui eu quero mostrar a você a comunidade.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** recebe muito suporte da comunidade. E quero destacar suas contribuições.
|
||||
|
||||
Estas são as pessoas que:
|
||||
|
||||
* [Help others with issues (questions) in GitHub](help-fastapi.md#responda-perguntas-no-github){.internal-link target=_blank}.
|
||||
* [Create Pull Requests](help-fastapi.md#crie-um-pull-request){.internal-link target=_blank}.
|
||||
* Revisar Pull Requests, [especially important for translations](contributing.md#traducoes){.internal-link target=_blank}.
|
||||
|
||||
Uma salva de palmas para eles. 👏 🙇
|
||||
|
||||
## Usuários mais ativos do ultimo mês
|
||||
|
||||
Estes são os usuários que estão [helping others the most with issues (questions) in GitHub](help-fastapi.md#responda-perguntas-no-github){.internal-link target=_blank} durante o ultimo mês. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues respondidas: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Especialistas
|
||||
|
||||
Aqui está os **Especialistas do FastAPI**. 🤓
|
||||
|
||||
|
||||
Estes são os usuários que [helped others the most with issues (questions) in GitHub](help-fastapi.md#responda-perguntas-no-github){.internal-link target=_blank} em *todo o tempo*.
|
||||
|
||||
Eles provaram ser especialistas ajudando muitos outros. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues respondidas: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Top Contribuidores
|
||||
|
||||
Aqui está os **Top Contribuidores**. 👷
|
||||
|
||||
Esses usuários têm [created the most Pull Requests](help-fastapi.md#crie-um-pull-request){.internal-link target=_blank} que tem sido *mergeado*.
|
||||
|
||||
Eles contribuíram com o código-fonte, documentação, traduções, etc. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requests: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Existem muitos outros contribuidores (mais de uma centena), você pode ver todos eles em <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">Página de Contribuidores do FastAPI no GitHub</a>. 👷
|
||||
|
||||
## Top Revisores
|
||||
|
||||
Esses usuários são os **Top Revisores**. 🕵️
|
||||
|
||||
### Revisões para Traduções
|
||||
|
||||
Eu só falo algumas línguas (e não muito bem 😅). Então, os revisores são aqueles que têm o [**poder de aprovar traduções**](contributing.md#traducoes){.internal-link target=_blank} da documentação. Sem eles, não haveria documentação em vários outros idiomas.
|
||||
|
||||
---
|
||||
|
||||
Os **Top Revisores** 🕵️ revisaram a maior parte de Pull Requests de outros, garantindo a qualidade do código, documentação, e especialmente, as **traduções**.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Revisões: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Patrocinadores
|
||||
|
||||
Esses são os **Patrocinadores**. 😎
|
||||
|
||||
Eles estão apoiando meu trabalho **FastAPI** (e outros), principalmente através de <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsors</a>.
|
||||
|
||||
{% if sponsors %}
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Patrocinadores Ouro
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Patrocinadores Prata
|
||||
|
||||
{% for sponsor in sponsors.silver -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Patrocinadores Bronze
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
### Patrocinadores Individuais
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
## Sobre os dados - detalhes técnicos
|
||||
|
||||
A principal intenção desta página é destacar o esforço da comunidade para ajudar os outros.
|
||||
|
||||
Especialmente incluindo esforços que normalmente são menos visíveis, e em muitos casos mais árduo, como ajudar os outros com issues e revisando Pull Requests com traduções.
|
||||
|
||||
Os dados são calculados todo mês, você pode ler o <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">código fonte aqui</a>.
|
||||
|
||||
Aqui também estou destacando contribuições de patrocinadores.
|
||||
|
||||
Eu também me reservo o direito de atualizar o algoritmo, seções, limites, etc (só para prevenir 🤷).
|
||||
@@ -434,7 +434,7 @@ Para entender mais sobre performance, veja a seção <a href="https://fastapi.ti
|
||||
|
||||
Usados por Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - para validação de email.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - para validação de email.
|
||||
|
||||
Usados por Starlette:
|
||||
|
||||
|
||||
418
docs/pt/docs/tutorial/request_files.md
Normal file
418
docs/pt/docs/tutorial/request_files.md
Normal file
@@ -0,0 +1,418 @@
|
||||
# Arquivos de Requisição
|
||||
|
||||
Você pode definir arquivos para serem enviados para o cliente utilizando `File`.
|
||||
|
||||
/// info
|
||||
|
||||
Para receber arquivos compartilhados, primeiro instale <a href="https://github.com/Kludex/python-multipart" class="external-link" target="_blank">`python-multipart`</a>.
|
||||
|
||||
E.g. `pip install python-multipart`.
|
||||
|
||||
Isso se deve por que arquivos enviados são enviados como "dados de formulário".
|
||||
|
||||
///
|
||||
|
||||
## Importe `File`
|
||||
|
||||
Importe `File` e `UploadFile` do `fastapi`:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
## Defina os parâmetros de `File`
|
||||
|
||||
Cria os parâmetros do arquivo da mesma forma que você faria para `Body` ou `Form`:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
/// info | Informação
|
||||
|
||||
`File` é uma classe que herda diretamente de `Form`.
|
||||
|
||||
Mas lembre-se que quando você importa `Query`,`Path`, `File`, entre outros, do `fastapi`, essas são na verdade funções que retornam classes especiais.
|
||||
|
||||
///
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Para declarar o corpo de arquivos, você precisa utilizar `File`, do contrário os parâmetros seriam interpretados como parâmetros de consulta ou corpo (JSON) da requisição.
|
||||
|
||||
///
|
||||
|
||||
Os arquivos serão enviados como "form data".
|
||||
|
||||
Se você declarar o tipo do seu parâmetro na sua *função de operação de rota* como `bytes`, o **FastAPI** irá ler o arquivo para você e você receberá o conteúdo como `bytes`.
|
||||
|
||||
Lembre-se que isso significa que o conteúdo inteiro será armazenado em memória. Isso funciona bem para arquivos pequenos.
|
||||
|
||||
Mas existem vários casos em que você pode se beneficiar ao usar `UploadFile`.
|
||||
|
||||
## Parâmetros de arquivo com `UploadFile`
|
||||
|
||||
Defina um parâmetro de arquivo com o tipo `UploadFile`
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="14"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="13"
|
||||
{!> ../../../docs_src/request_files/tutorial001_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="12"
|
||||
{!> ../../../docs_src/request_files/tutorial001.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
Utilizando `UploadFile` tem várias vantagens sobre `bytes`:
|
||||
|
||||
* Você não precisa utilizar `File()` como o valor padrão do parâmetro.
|
||||
* A classe utiliza um arquivo em "spool":
|
||||
* Um arquivo guardado em memória até um tamanho máximo, depois desse limite ele é guardado em disco.
|
||||
* Isso significa que a classe funciona bem com arquivos grandes como imagens, vídeos, binários extensos, etc. Sem consumir toda a memória.
|
||||
* Você pode obter metadados do arquivo enviado.
|
||||
* Ela possui uma interface <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">semelhante a arquivos</a> `async`.
|
||||
* Ela expõe um objeto python <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> que você pode repassar para bibliotecas que esperam um objeto com comportamento de arquivo.
|
||||
|
||||
### `UploadFile`
|
||||
|
||||
`UploadFile` tem os seguintes atributos:
|
||||
|
||||
* `filename`: Uma string (`str`) com o nome original do arquivo enviado (e.g. `myimage.jpg`).
|
||||
* `content-type`: Uma `str` com o tipo do conteúdo (tipo MIME / media) (e.g. `image/jpeg`).
|
||||
* `file`: Um objeto do tipo <a href="https://docs.python.org/3/library/tempfile.html#tempfile.SpooledTemporaryFile" class="external-link" target="_blank">`SpooledTemporaryFile`</a> (um objeto <a href="https://docs.python.org/3/glossary.html#term-file-like-object" class="external-link" target="_blank">file-like</a>). O arquivo propriamente dito que você pode passar diretamente para outras funções ou bibliotecas que esperam um objeto "file-like".
|
||||
|
||||
`UploadFile` tem os seguintes métodos `async`. Todos eles chamam os métodos de arquivos por baixo dos panos (usando o objeto `SpooledTemporaryFile` interno).
|
||||
|
||||
* `write(data)`: escreve dados (`data`) em `str` ou `bytes` no arquivo.
|
||||
* `read(size)`: Lê um número de bytes/caracteres de acordo com a quantidade `size` (`int`).
|
||||
* `seek(offset)`: Navega para o byte na posição `offset` (`int`) do arquivo.
|
||||
* E.g., `await myfile.seek(0)` navegaria para o ínicio do arquivo.
|
||||
* Isso é especialmente útil se você executar `await myfile.read()` uma vez e depois precisar ler os conteúdos do arquivo de novo.
|
||||
* `close()`: Fecha o arquivo.
|
||||
|
||||
Como todos esses métodos são assíncronos (`async`) você precisa esperar ("await") por eles.
|
||||
|
||||
Por exemplo, dentro de uma *função de operação de rota* assíncrona você pode obter os conteúdos com:
|
||||
|
||||
```Python
|
||||
contents = await myfile.read()
|
||||
```
|
||||
|
||||
Se você estiver dentro de uma *função de operação de rota* definida normalmente com `def`, você pode acessar `UploadFile.file` diretamente, por exemplo:
|
||||
|
||||
```Python
|
||||
contents = myfile.file.read()
|
||||
```
|
||||
|
||||
/// note | Detalhes técnicos do `async`
|
||||
|
||||
Quando você utiliza métodos assíncronos, o **FastAPI** executa os métodos do arquivo em uma threadpool e espera por eles.
|
||||
|
||||
///
|
||||
|
||||
/// note | Detalhes técnicos do Starlette
|
||||
|
||||
O `UploadFile` do **FastAPI** herda diretamente do `UploadFile` do **Starlette**, mas adiciona algumas funcionalidades necessárias para ser compatível com o **Pydantic**
|
||||
|
||||
///
|
||||
|
||||
## O que é "Form Data"
|
||||
|
||||
A forma como formulários HTML(`<form></form>`) enviam dados para o servidor normalmente utilizam uma codificação "especial" para esses dados, que é diferente do JSON.
|
||||
|
||||
O **FastAPI** garante que os dados serão lidos da forma correta, em vez do JSON.
|
||||
|
||||
/// note | Detalhes Técnicos
|
||||
|
||||
Dados vindos de formulários geralmente tem a codificação com o "media type" `application/x-www-form-urlencoded` quando estes não incluem arquivos.
|
||||
|
||||
Mas quando os dados incluem arquivos, eles são codificados como `multipart/form-data`. Se você utilizar `File`, **FastAPI** saberá que deve receber os arquivos da parte correta do corpo da requisição.
|
||||
|
||||
Se você quer ler mais sobre essas codificações e campos de formulário, veja a documentação online da <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/POST" class="external-link" target="_blank"><abbr title="Mozilla Developer Network">MDN</abbr> sobre <code> POST</code> </a>.
|
||||
|
||||
///
|
||||
|
||||
/// warning | Aviso
|
||||
|
||||
Você pode declarar múltiplos parâmetros `File` e `Form` em uma *operação de rota*, mas você não pode declarar campos `Body`que seriam recebidos como JSON junto desses parâmetros, por que a codificação do corpo da requisição será `multipart/form-data` em vez de `application/json`.
|
||||
|
||||
Isso não é uma limitação do **FastAPI**, é uma parte do protocolo HTTP.
|
||||
|
||||
///
|
||||
|
||||
## Arquivo de upload opcional
|
||||
|
||||
Você pode definir um arquivo como opcional utilizando as anotações de tipo padrão e definindo o valor padrão como `None`:
|
||||
|
||||
//// tab | Python 3.10+
|
||||
|
||||
```Python hl_lines="9 17"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02_an_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="9 17"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="10 18"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.10+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated`, se possível
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="7 15"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02_py310.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated`, se possível
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="9 17"
|
||||
{!> ../../../docs_src/request_files/tutorial001_02.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
## `UploadFile` com Metadados Adicionais
|
||||
|
||||
Você também pode utilizar `File()` com `UploadFile`, por exemplo, para definir metadados adicionais:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="9 15"
|
||||
{!> ../../../docs_src/request_files/tutorial001_03_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="8 14"
|
||||
{!> ../../../docs_src/request_files/tutorial001_03_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="7 13"
|
||||
{!> ../../../docs_src/request_files/tutorial001_03.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
## Envio de Múltiplos Arquivos
|
||||
|
||||
É possível enviar múltiplos arquivos ao mesmo tmepo.
|
||||
|
||||
Ele ficam associados ao mesmo "campo do formulário" enviado com "form data".
|
||||
|
||||
Para usar isso, declare uma lista de `bytes` ou `UploadFile`:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="10 15"
|
||||
{!> ../../../docs_src/request_files/tutorial002_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="11 16"
|
||||
{!> ../../../docs_src/request_files/tutorial002_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="8 13"
|
||||
{!> ../../../docs_src/request_files/tutorial002_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="10 15"
|
||||
{!> ../../../docs_src/request_files/tutorial002.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
Você irá receber, como delcarado uma lista (`list`) de `bytes` ou `UploadFile`s,
|
||||
|
||||
/// note | Detalhes Técnicos
|
||||
|
||||
Você também poderia utilizar `from starlette.responses import HTMLResponse`.
|
||||
|
||||
O **FastAPI** fornece as mesmas `starlette.responses` como `fastapi.responses` apenas como um facilitador para você, desenvolvedor. Mas a maior parte das respostas vem diretamente do Starlette.
|
||||
|
||||
///
|
||||
|
||||
### Enviando Múltiplos Arquivos com Metadados Adicionais
|
||||
|
||||
E da mesma forma que antes, você pode utilizar `File()` para definir parâmetros adicionais, até mesmo para `UploadFile`:
|
||||
|
||||
//// tab | Python 3.9+
|
||||
|
||||
```Python hl_lines="11 18-20"
|
||||
{!> ../../../docs_src/request_files/tutorial003_an_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+
|
||||
|
||||
```Python hl_lines="12 19-21"
|
||||
{!> ../../../docs_src/request_files/tutorial003_an.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.9+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="9 16"
|
||||
{!> ../../../docs_src/request_files/tutorial003_py39.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
//// tab | Python 3.8+ non-Annotated
|
||||
|
||||
/// tip | Dica
|
||||
|
||||
Utilize a versão com `Annotated` se possível.
|
||||
|
||||
///
|
||||
|
||||
```Python hl_lines="11 18"
|
||||
{!> ../../../docs_src/request_files/tutorial003.py!}
|
||||
```
|
||||
|
||||
////
|
||||
|
||||
## Recapitulando
|
||||
|
||||
Use `File`, `bytes` e `UploadFile` para declarar arquivos que serão enviados na requisição, enviados como dados do formulário.
|
||||
@@ -1,184 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# Люди, поддерживающие FastAPI
|
||||
|
||||
У FastAPI замечательное сообщество, которое доброжелательно к людям с любым уровнем знаний.
|
||||
|
||||
## Создатель и хранитель
|
||||
|
||||
Хай! 👋
|
||||
|
||||
Это я:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Answers: {{ user.answers }}</div><div class="count">Pull Requests: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Я создал и продолжаю поддерживать **FastAPI**. Узнать обо мне больше можно тут [Помочь FastAPI - Получить помощь - Связаться с автором](help-fastapi.md#_2){.internal-link target=_blank}.
|
||||
|
||||
... но на этой странице я хочу показать вам наше сообщество.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI** получает огромную поддержку от своего сообщества. И я хочу отметить вклад его участников.
|
||||
|
||||
Это люди, которые:
|
||||
|
||||
* [Помогают другим с их проблемами (вопросами) на GitHub](help-fastapi.md#github_1){.internal-link target=_blank}.
|
||||
* [Создают пул-реквесты](help-fastapi.md#-_1){.internal-link target=_blank}.
|
||||
* Делают ревью пул-реквестов, [что особенно важно для переводов на другие языки](contributing.md#_8){.internal-link target=_blank}.
|
||||
|
||||
Поаплодируем им! 👏 🙇
|
||||
|
||||
## Самые активные участники за прошедший месяц
|
||||
|
||||
Эти участники [оказали наибольшую помощь другим с решением их проблем (вопросов) на GitHub](help-fastapi.md#github_1){.internal-link target=_blank} в течение последнего месяца. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues replied: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Эксперты
|
||||
|
||||
Здесь представлены **Эксперты FastAPI**. 🤓
|
||||
|
||||
Эти участники [оказали наибольшую помощь другим с решением их проблем (вопросов) на GitHub](help-fastapi.md#github_1){.internal-link target=_blank} за *всё время*.
|
||||
|
||||
Оказывая помощь многим другим, они подтвердили свой уровень знаний. ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Issues replied: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Рейтинг участников, внёсших вклад в код
|
||||
|
||||
Здесь представлен **Рейтинг участников, внёсших вклад в код**. 👷
|
||||
|
||||
Эти люди [сделали наибольшее количество пул-реквестов](help-fastapi.md#-_1){.internal-link target=_blank}, *включённых в основной код*.
|
||||
|
||||
Они сделали наибольший вклад в исходный код, документацию, переводы и т.п. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Requests: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
На самом деле таких людей довольно много (более сотни), вы можете увидеть всех на этой странице <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI GitHub Contributors page</a>. 👷
|
||||
|
||||
## Рейтинг ревьюеров
|
||||
|
||||
Здесь представлен **Рейтинг ревьюеров**. 🕵️
|
||||
|
||||
### Проверки переводов на другие языки
|
||||
|
||||
Я знаю не очень много языков (и не очень хорошо 😅).
|
||||
Итак, ревьюеры - это люди, которые могут [**подтвердить предложенный вами перевод** документации](contributing.md#_8){.internal-link target=_blank}. Без них не было бы документации на многих языках.
|
||||
|
||||
---
|
||||
|
||||
В **Рейтинге ревьюеров** 🕵️ представлены те, кто проверил наибольшее количество пул-реквестов других участников, обеспечивая качество кода, документации и, особенно, **переводов на другие языки**.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Reviews: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Спонсоры
|
||||
|
||||
Здесь представлены **Спонсоры**. 😎
|
||||
|
||||
Спонсоры поддерживают мою работу над **FastAPI** (и другими проектами) главным образом через <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsors</a>.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Золотые спонсоры
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Серебрянные спонсоры
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Бронзовые спонсоры
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### Индивидуальные спонсоры
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## О данных - технические детали
|
||||
|
||||
Основная цель этой страницы - подчеркнуть усилия сообщества по оказанию помощи другим.
|
||||
|
||||
Особенно это касается усилий, которые обычно менее заметны и во многих случаях более трудоемки, таких как помощь другим в решении проблем и проверка пул-реквестов с переводами.
|
||||
|
||||
Данные рейтинги подсчитываются каждый месяц, ознакомиться с тем, как это работает можно <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">тут</a>.
|
||||
|
||||
Кроме того, я также подчеркиваю вклад спонсоров.
|
||||
|
||||
И я оставляю за собой право обновлять алгоритмы подсчёта, виды рейтингов, пороговые значения и т.д. (так, на всякий случай 🤷).
|
||||
@@ -443,7 +443,7 @@ item: Item
|
||||
|
||||
Используется Pydantic:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - для проверки электронной почты.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - для проверки электронной почты.
|
||||
|
||||
Используется Starlette:
|
||||
|
||||
|
||||
@@ -131,7 +131,7 @@ FastAPI будет использовать значение `response_model` д
|
||||
|
||||
/// info | "Информация"
|
||||
|
||||
Чтобы использовать `EmailStr`, прежде необходимо установить <a href="https://github.com/JoshData/python-email-validator" class="external-link" target="_blank">`email_validator`</a>.
|
||||
Чтобы использовать `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]`.
|
||||
|
||||
|
||||
@@ -1,183 +0,0 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI Topluluğu
|
||||
|
||||
FastAPI, her kökenden insanı ağırlayan harika bir topluluğa sahip.
|
||||
|
||||
## Yazan - Geliştiren
|
||||
|
||||
Merhaba! 👋
|
||||
|
||||
İşte bu benim:
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.maintainers %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cevaplar: {{ user.answers }}</div><div class="count">Pull Request'ler: {{ user.prs }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Ben **FastAPI**'ın geliştiricisiyim. Bununla ilgili daha fazla bilgiyi şurada okuyabilirsiniz: [FastAPI yardım - yardım al - benimle iletişime geç](help-fastapi.md#connect-with-the-author){.internal-link target=_blank}.
|
||||
|
||||
...burada size harika FastAPI topluluğunu göstermek istiyorum.
|
||||
|
||||
---
|
||||
|
||||
**FastAPI**, topluluğundan çok destek alıyor. Ben de onların katkılarını vurgulamak istiyorum.
|
||||
|
||||
Bu insanlar:
|
||||
|
||||
* [GitHubdaki soruları cevaplayarak diğerlerine yardım ediyor](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank}.
|
||||
* [Pull Request'ler oluşturuyor](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
|
||||
* Pull Request'leri gözden geçiriyorlar, [özellikle çeviriler için bu çok önemli](contributing.md#translations){.internal-link target=_blank}.
|
||||
|
||||
Onları bir alkışlayalım. 👏 🙇
|
||||
|
||||
## Geçen Ayın En Aktif Kullanıcıları
|
||||
|
||||
Geçtiğimiz ay boyunca [GitHub'da diğerlerine en çok yardımcı olan](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} kullanıcılar. ☕
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.last_month_experts[:10] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cevaplanan soru sayısı: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Uzmanlar
|
||||
|
||||
İşte **FastAPI Uzmanları**. 🤓
|
||||
|
||||
Uzmanlarımız ise *tüm zamanlar boyunca* [GitHub'da insanların sorularına en çok yardımcı olan](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} insanlar.
|
||||
|
||||
Bir çok kullanıcıya yardım ederek uzman olduklarını kanıtladılar! ✨
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.experts[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Cevaplanan soru sayısı: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## En Fazla Katkıda Bulunanlar
|
||||
|
||||
Şimdi ise sıra **en fazla katkıda bulunanlar**da. 👷
|
||||
|
||||
Bu kullanıcılar en fazla [kaynak koduyla birleştirilen Pull Request'lere](help-fastapi.md#create-a-pull-request){.internal-link target=_blank} sahip!
|
||||
|
||||
Kaynak koduna, dökümantasyona, çevirilere ve bir sürü şeye katkıda bulundular. 📦
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_contributors[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Pull Request sayısı: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
Bunlar dışında katkıda bulunan, yüzden fazla, bir sürü insan var. Hepsini <a href="https://github.com/fastapi/fastapi/graphs/contributors" class="external-link" target="_blank">FastAPI GitHub Katkıda Bulunanlar</a> sayfasında görebilirsin. 👷
|
||||
|
||||
## En Fazla Değerlendirme Yapanlar
|
||||
|
||||
İşte **en çok değerlendirme yapanlar**. 🕵️
|
||||
|
||||
### Çeviri Değerlendirmeleri
|
||||
|
||||
Yalnızca birkaç dil konuşabiliyorum (ve çok da iyi değilim 😅). Bu yüzden değerlendirme yapanların da döküman çevirilerini [**onaylama yetkisi**](contributing.md#translations){.internal-link target=_blank} var. Onlar olmasaydı çeşitli dillerde dökümantasyon da olmazdı.
|
||||
|
||||
---
|
||||
|
||||
**En fazla değerlendirme yapanlar** 🕵️ kodun, dökümantasyonun ve özellikle **çevirilerin** Pull Request'lerini inceleyerek kalitesinden emin oldular.
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
{% for user in people.top_translations_reviewers[:50] %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a> <div class="count">Değerlendirme sayısı: {{ user.count }}</div></div>
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
## Sponsorlar
|
||||
|
||||
işte **Sponsorlarımız**. 😎
|
||||
|
||||
Çoğunlukla <a href="https://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsorları</a> aracılığıyla olmak üzere, **FastAPI** ve diğer projelerdeki çalışmalarımı destekliyorlar.
|
||||
|
||||
{% if sponsors %}
|
||||
|
||||
{% if sponsors.gold %}
|
||||
|
||||
### Altın Sponsorlar
|
||||
|
||||
{% for sponsor in sponsors.gold -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% if sponsors.silver %}
|
||||
|
||||
### Gümüş Sponsorlar
|
||||
|
||||
{% 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 %}
|
||||
|
||||
{% if sponsors.bronze %}
|
||||
|
||||
### Bronz Sponsorlar
|
||||
|
||||
{% for sponsor in sponsors.bronze -%}
|
||||
<a href="{{ sponsor.url }}" target="_blank" title="{{ sponsor.title }}"><img src="{{ sponsor.img }}" style="border-radius:15px"></a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
### Bireysel Sponsorlar
|
||||
|
||||
{% if github_sponsors %}
|
||||
{% for group in github_sponsors.sponsors %}
|
||||
|
||||
<div class="user-list user-list-center">
|
||||
|
||||
{% for user in group %}
|
||||
{% if user.login not in sponsors_badge.logins %}
|
||||
|
||||
<div class="user"><a href="{{ user.url }}" target="_blank"><div class="avatar-wrapper"><img src="{{ user.avatarUrl }}"/></div><div class="title">@{{ user.login }}</div></a></div>
|
||||
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
|
||||
</div>
|
||||
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
## Veriler - Teknik detaylar
|
||||
|
||||
Bu sayfanın temel amacı, topluluğun başkalarına yardım etme çabasını vurgulamaktır.
|
||||
|
||||
Özellikle normalde daha az görünür olan ve çoğu durumda daha zahmetli olan, diğerlerine sorularında yardımcı olmak, çevirileri ve Pull Request'leri gözden geçirmek gibi çabalar dahil.
|
||||
|
||||
Veriler ayda bir hesaplanır, <a href="https://github.com/fastapi/fastapi/blob/master/.github/actions/people/app/main.py" class="external-link" target="_blank">kaynak kodu buradan</a> okuyabilirsin.
|
||||
|
||||
Burada sponsorların katkılarını da vurguluyorum.
|
||||
|
||||
Ayrıca algoritmayı, bölümleri, eşikleri vb. güncelleme hakkımı da saklı tutuyorum (her ihtimale karşı 🤷).
|
||||
@@ -449,7 +449,7 @@ Daha fazla bilgi için, bu bölüme bir göz at <a href="https://fastapi.tiangol
|
||||
|
||||
Pydantic tarafında kullanılan:
|
||||
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - email doğrulaması için.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email-validator</code></a> - email doğrulaması için.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/pydantic_settings/" target="_blank"><code>pydantic-settings</code></a> - ayar yönetimi için.
|
||||
* <a href="https://docs.pydantic.dev/latest/usage/types/extra_types/extra_types/" target="_blank"><code>pydantic-extra-types</code></a> - Pydantic ile birlikte kullanılabilecek ek tipler için.
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user