mirror of
https://github.com/fastapi/fastapi.git
synced 2025-12-27 16:21:06 -05:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32be95dd86 | ||
|
|
92b67b1b29 | ||
|
|
e0a9692261 | ||
|
|
62f82296f3 | ||
|
|
f49da74200 | ||
|
|
13ce009e9a | ||
|
|
41fcbc7d00 | ||
|
|
bec2ec7e4c | ||
|
|
7b55bf37b5 | ||
|
|
285ac017a9 | ||
|
|
d1293b8786 | ||
|
|
1d41a7d2df | ||
|
|
8045f34c52 | ||
|
|
b254688f37 | ||
|
|
026af6e248 | ||
|
|
38929aae1b | ||
|
|
550092a3bd | ||
|
|
5c054fdd65 | ||
|
|
943159afb0 | ||
|
|
91dad1cb3a | ||
|
|
1551913223 | ||
|
|
e00d29e784 | ||
|
|
ce1fb1a23b | ||
|
|
25c692d77d | ||
|
|
2f686ce1e5 | ||
|
|
14442d356f | ||
|
|
11f95ddef6 | ||
|
|
fb165a55f0 | ||
|
|
1aedc6e29d | ||
|
|
be1e3faa63 | ||
|
|
4ae63ae495 | ||
|
|
6d523d62d0 | ||
|
|
d84d6e03f4 | ||
|
|
a901e2f449 | ||
|
|
8a45645177 | ||
|
|
74cc33d16b | ||
|
|
5815fa58fb | ||
|
|
09e4859cab | ||
|
|
071b8f27f9 | ||
|
|
f08234f35a | ||
|
|
610534b703 | ||
|
|
ebc8ac7295 | ||
|
|
3cc5efc5de | ||
|
|
27da0d02a7 | ||
|
|
3425c834cc | ||
|
|
91606c3c38 | ||
|
|
7e161b3f9e | ||
|
|
9e074c2ed2 | ||
|
|
886dc33f85 | ||
|
|
f810c65e7c | ||
|
|
8dfdf69d6b | ||
|
|
7ae1f9003f | ||
|
|
247b58e0f5 | ||
|
|
2e55203879 | ||
|
|
9490491595 | ||
|
|
71321f0129 | ||
|
|
a09c1a034d | ||
|
|
ebcbe3c325 | ||
|
|
d6997ab2a0 | ||
|
|
5a297971a1 | ||
|
|
a85c02b85c | ||
|
|
c964d04004 | ||
|
|
62705820d6 | ||
|
|
31dabcb99c | ||
|
|
e68b638f6e | ||
|
|
6dc9e4a7e4 | ||
|
|
01c3556e79 | ||
|
|
a9b0911470 | ||
|
|
c07fd2d499 | ||
|
|
bfd6060996 | ||
|
|
e98eb07944 | ||
|
|
1a24c1ef05 |
4
.github/dependabot.yml
vendored
4
.github/dependabot.yml
vendored
@@ -12,9 +12,5 @@ updates:
|
||||
directory: "/"
|
||||
schedule:
|
||||
interval: "monthly"
|
||||
groups:
|
||||
python-packages:
|
||||
patterns:
|
||||
- "*"
|
||||
commit-message:
|
||||
prefix: ⬆
|
||||
|
||||
15
.github/workflows/publish.yml
vendored
15
.github/workflows/publish.yml
vendored
@@ -8,6 +8,12 @@ on:
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
package:
|
||||
- fastapi
|
||||
permissions:
|
||||
id-token: write
|
||||
steps:
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
@@ -21,19 +27,14 @@ jobs:
|
||||
# Issue ref: https://github.com/actions/setup-python/issues/436
|
||||
# cache: "pip"
|
||||
# cache-dependency-path: pyproject.toml
|
||||
- uses: actions/cache@v4
|
||||
id: cache
|
||||
with:
|
||||
path: ${{ env.pythonLocation }}
|
||||
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml') }}-publish
|
||||
- name: Install build dependencies
|
||||
run: pip install build
|
||||
- name: Build distribution
|
||||
env:
|
||||
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
|
||||
run: python -m build
|
||||
- name: Publish
|
||||
uses: pypa/gh-action-pypi-publish@v1.8.14
|
||||
with:
|
||||
password: ${{ secrets.PYPI_API_TOKEN }}
|
||||
- name: Dump GitHub context
|
||||
env:
|
||||
GITHUB_CONTEXT: ${{ toJson(github) }}
|
||||
|
||||
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@@ -32,7 +32,7 @@ jobs:
|
||||
id: cache
|
||||
with:
|
||||
path: ${{ env.pythonLocation }}
|
||||
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v07
|
||||
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-pydantic-v2-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v08
|
||||
- name: Install Dependencies
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: pip install -r requirements-tests.txt
|
||||
@@ -70,7 +70,7 @@ jobs:
|
||||
id: cache
|
||||
with:
|
||||
path: ${{ env.pythonLocation }}
|
||||
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v07
|
||||
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ matrix.pydantic-version }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt', 'requirements-docs-tests.txt') }}-test-v08
|
||||
- name: Install Dependencies
|
||||
if: steps.cache.outputs.cache-hit != 'true'
|
||||
run: pip install -r requirements-tests.txt
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
---
|
||||
|
||||
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints.
|
||||
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
|
||||
|
||||
The key features are:
|
||||
|
||||
@@ -122,8 +122,6 @@ If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be
|
||||
|
||||
## Requirements
|
||||
|
||||
Python 3.8+
|
||||
|
||||
FastAPI stands on the shoulders of giants:
|
||||
|
||||
* <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a> for the web parts.
|
||||
@@ -338,7 +336,7 @@ You do that with standard modern Python types.
|
||||
|
||||
You don't have to learn a new syntax, the methods or classes of a specific library, etc.
|
||||
|
||||
Just standard **Python 3.8+**.
|
||||
Just standard **Python**.
|
||||
|
||||
For example, for an `int`:
|
||||
|
||||
@@ -463,12 +461,12 @@ Used by Starlette:
|
||||
* <a href="https://github.com/Kludex/python-multipart" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
|
||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
|
||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - Required for Starlette's `SchemaGenerator` support (you probably don't need it with FastAPI).
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
|
||||
|
||||
Used by FastAPI / Starlette:
|
||||
|
||||
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application.
|
||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - Required if you want to use `ORJSONResponse`.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
|
||||
|
||||
You can install all of these with `pip install "fastapi[all]"`.
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ Başqalarının Pull Request-lərinə **Ən çox rəy verənlər** 🕵️ kodun
|
||||
|
||||
Bunlar **Sponsorlar**dır. 😎
|
||||
|
||||
Onlar mənim **FastAPI** (və digər) işlərimi əsasən <a href="hhttps://github.com/sponsors/tiangolo" class="external-link" target="_blank">GitHub Sponsorlar</a> vasitəsilə dəstəkləyirlə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 %}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
---
|
||||
|
||||
FastAPI Python 3.8+ ilə API yaratmaq üçün standart Python <abbr title="Tip Məsləhətləri: Type Hints">tip məsləhətlərinə</abbr> əsaslanan, müasir, sürətli (yüksək performanslı) framework-dür.
|
||||
FastAPI Python ilə API yaratmaq üçün standart Python <abbr title="Tip Məsləhətləri: Type Hints">tip məsləhətlərinə</abbr> əsaslanan, müasir, sürətli (yüksək performanslı) framework-dür.
|
||||
|
||||
Əsas xüsusiyyətləri bunlardır:
|
||||
|
||||
@@ -115,8 +115,6 @@ FastAPI Python 3.8+ ilə API yaratmaq üçün standart Python <abbr title="Tip M
|
||||
|
||||
## Tələblər
|
||||
|
||||
Python 3.8+
|
||||
|
||||
FastAPI nəhənglərin çiyinlərində dayanır:
|
||||
|
||||
* Web tərəfi üçün <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a>.
|
||||
@@ -330,7 +328,7 @@ Bunu standart müasir Python tipləri ilə edirsiniz.
|
||||
|
||||
Yeni sintaksis, müəyyən bir kitabxananın metodlarını və ya siniflərini və s. öyrənmək məcburiyyətində deyilsiniz.
|
||||
|
||||
Sadəcə standart **Python 3.8+**.
|
||||
Sadəcə standart **Python**.
|
||||
|
||||
Məsələn, `int` üçün:
|
||||
|
||||
|
||||
@@ -439,7 +439,6 @@ item: Item
|
||||
|
||||
Pydantic দ্বারা ব্যবহৃত:
|
||||
|
||||
- <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - দ্রুত JSON এর জন্য <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>.
|
||||
- <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - ইমেল যাচাইকরণের জন্য।
|
||||
|
||||
স্টারলেট দ্বারা ব্যবহৃত:
|
||||
@@ -450,12 +449,12 @@ Pydantic দ্বারা ব্যবহৃত:
|
||||
- <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - `SessionMiddleware` সহায়তার জন্য প্রয়োজন।
|
||||
- <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - স্টারলেটের SchemaGenerator সাপোর্ট এর জন্য প্রয়োজন (আপনার সম্ভাবত FastAPI প্রয়োজন নেই)।
|
||||
- <a href="https://graphene-python.org/" target="_blank"><code>graphene</code></a> - `GraphQLApp` সহায়তার জন্য প্রয়োজন।
|
||||
- <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - আপনি `UJSONResponse` ব্যবহার করতে চাইলে প্রয়োজন।
|
||||
|
||||
FastAPI / Starlette দ্বারা ব্যবহৃত:
|
||||
|
||||
- <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - সার্ভারের জন্য যা আপনার অ্যাপ্লিকেশন লোড করে এবং পরিবেশন করে।
|
||||
- <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - আপনি `ORJSONResponse` ব্যবহার করতে চাইলে প্রয়োজন।
|
||||
- <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - আপনি `UJSONResponse` ব্যবহার করতে চাইলে প্রয়োজন।
|
||||
|
||||
আপনি এই সব ইনস্টল করতে পারেন `pip install fastapi[all]` দিয়ে.
|
||||
|
||||
|
||||
537
docs/bn/docs/python-types.md
Normal file
537
docs/bn/docs/python-types.md
Normal file
@@ -0,0 +1,537 @@
|
||||
# পাইথন এর <abbr title="একটি ভেরিয়েবল কি ধরনের ডেটা ধারণ করতে পারে।">টাইপ্স</abbr> পরিচিতি
|
||||
|
||||
Python-এ ঐচ্ছিক "টাইপ হিন্ট" (যা "টাইপ অ্যানোটেশন" নামেও পরিচিত) এর জন্য সাপোর্ট রয়েছে।
|
||||
|
||||
এই **"টাইপ হিন্ট"** বা অ্যানোটেশনগুলি এক ধরণের বিশেষ <abbr title="সিনট্যাক্স হল প্রোগ্রামিং ভাষায় কোড লেখার নিয়ম ও গঠন।">সিনট্যাক্স</abbr> যা একটি ভেরিয়েবলের <abbr title="যেমন: str, int, float, bool">টাইপ</abbr> ঘোষণা করতে দেয়।
|
||||
|
||||
ভেরিয়েবলগুলির জন্য টাইপ ঘোষণা করলে, এডিটর এবং টুলগুলি আপনাকে আরও ভালো সাপোর্ট দিতে পারে।
|
||||
|
||||
এটি পাইথন টাইপ হিন্ট সম্পর্কে একটি দ্রুত **টিউটোরিয়াল / রিফ্রেশার** মাত্র। এটি **FastAPI** এর সাথে ব্যবহার করার জন্য শুধুমাত্র ন্যূনতম প্রয়োজনীয়তা কভার করে... যা আসলে খুব একটা বেশি না।
|
||||
|
||||
**FastAPI** এই টাইপ হিন্টগুলির উপর ভিত্তি করে নির্মিত, যা এটিকে অনেক সুবিধা এবং লাভ প্রদান করে।
|
||||
|
||||
তবে, আপনি যদি কখনো **FastAPI** ব্যবহার নাও করেন, তবুও এগুলি সম্পর্কে একটু শেখা আপনার উপকারে আসবে।
|
||||
|
||||
!!! Note
|
||||
যদি আপনি একজন Python বিশেষজ্ঞ হন, এবং টাইপ হিন্ট সম্পর্কে সবকিছু জানেন, তাহলে পরবর্তী অধ্যায়ে চলে যান।
|
||||
|
||||
## প্রেরণা
|
||||
|
||||
চলুন একটি সাধারণ উদাহরণ দিয়ে শুরু করি:
|
||||
|
||||
```Python
|
||||
{!../../../docs_src/python_types/tutorial001.py!}
|
||||
```
|
||||
|
||||
এই প্রোগ্রামটি কল করলে আউটপুট হয়:
|
||||
|
||||
```
|
||||
John Doe
|
||||
```
|
||||
|
||||
ফাংশনটি নিম্নলিখিত কাজ করে:
|
||||
|
||||
* `first_name` এবং `last_name` নেয়।
|
||||
* প্রতিটির প্রথম অক্ষরকে `title()` ব্যবহার করে বড় হাতের অক্ষরে রূপান্তর করে।
|
||||
* তাদেরকে মাঝখানে একটি স্পেস দিয়ে <abbr title="একটার পরে একটা একত্রিত করা">concatenate</abbr> করে।
|
||||
|
||||
```Python hl_lines="2"
|
||||
{!../../../docs_src/python_types/tutorial001.py!}
|
||||
```
|
||||
|
||||
### এটি সম্পাদনা করুন
|
||||
|
||||
এটি একটি খুব সাধারণ প্রোগ্রাম।
|
||||
|
||||
কিন্তু এখন কল্পনা করুন যে আপনি এটি শুরু থেকে লিখছিলেন।
|
||||
|
||||
এক পর্যায়ে আপনি ফাংশনের সংজ্ঞা শুরু করেছিলেন, আপনার প্যারামিটারগুলি প্রস্তুত ছিল...
|
||||
|
||||
কিন্তু তারপর আপনাকে "সেই method কল করতে হবে যা প্রথম অক্ষরকে বড় হাতের অক্ষরে রূপান্তর করে"।
|
||||
|
||||
এটা কি `upper` ছিল? নাকি `uppercase`? `first_uppercase`? `capitalize`?
|
||||
|
||||
তারপর, আপনি পুরোনো প্রোগ্রামারের বন্ধু, এডিটর অটোকমপ্লিশনের সাহায্যে নেওয়ার চেষ্টা করেন।
|
||||
|
||||
আপনি ফাংশনের প্রথম প্যারামিটার `first_name` টাইপ করেন, তারপর একটি ডট (`.`) টাইপ করেন এবং `Ctrl+Space` চাপেন অটোকমপ্লিশন ট্রিগার করার জন্য।
|
||||
|
||||
কিন্তু, দুর্ভাগ্যবশত, আপনি কিছুই উপযোগী পান না:
|
||||
|
||||
<img src="/img/python-types/image01.png">
|
||||
|
||||
### টাইপ যোগ করুন
|
||||
|
||||
আসুন আগের সংস্করণ থেকে একটি লাইন পরিবর্তন করি।
|
||||
|
||||
আমরা ঠিক এই অংশটি পরিবর্তন করব অর্থাৎ ফাংশনের প্যারামিটারগুলি, এইগুলি:
|
||||
|
||||
```Python
|
||||
first_name, last_name
|
||||
```
|
||||
|
||||
থেকে এইগুলি:
|
||||
|
||||
```Python
|
||||
first_name: str, last_name: str
|
||||
```
|
||||
|
||||
ব্যাস।
|
||||
|
||||
এগুলিই "টাইপ হিন্ট":
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!../../../docs_src/python_types/tutorial002.py!}
|
||||
```
|
||||
|
||||
এটি ডিফল্ট ভ্যালু ঘোষণা করার মত নয় যেমন:
|
||||
|
||||
```Python
|
||||
first_name="john", last_name="doe"
|
||||
```
|
||||
|
||||
এটি একটি ভিন্ন জিনিস।
|
||||
|
||||
আমরা সমান (`=`) নয়, কোলন (`:`) ব্যবহার করছি।
|
||||
|
||||
এবং টাইপ হিন্ট যোগ করা সাধারণত তেমন কিছু পরিবর্তন করে না যা টাইপ হিন্ট ছাড়াই ঘটত।
|
||||
|
||||
কিন্তু এখন, কল্পনা করুন আপনি আবার সেই ফাংশন তৈরির মাঝখানে আছেন, কিন্তু টাইপ হিন্ট সহ।
|
||||
|
||||
একই পর্যায়ে, আপনি অটোকমপ্লিট ট্রিগার করতে `Ctrl+Space` চাপেন এবং আপনি দেখতে পান:
|
||||
|
||||
<img src="/img/python-types/image02.png">
|
||||
|
||||
এর সাথে, আপনি অপশনগুলি দেখে, স্ক্রল করতে পারেন, যতক্ষণ না আপনি এমন একটি অপশন খুঁজে পান যা কিছু মনে পরিয়ে দেয়:
|
||||
|
||||
<img src="/img/python-types/image03.png">
|
||||
|
||||
## আরও প্রেরণা
|
||||
|
||||
এই ফাংশনটি দেখুন, এটিতে ইতিমধ্যে টাইপ হিন্ট রয়েছে:
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!../../../docs_src/python_types/tutorial003.py!}
|
||||
```
|
||||
|
||||
এডিটর ভেরিয়েবলগুলির টাইপ জানার কারণে, আপনি শুধুমাত্র অটোকমপ্লিশনই পান না, আপনি এরর চেকও পান:
|
||||
|
||||
<img src="/img/python-types/image04.png">
|
||||
|
||||
এখন আপনি জানেন যে আপনাকে এটি ঠিক করতে হবে, `age`-কে একটি স্ট্রিং হিসেবে রূপান্তর করতে `str(age)` ব্যবহার করতে হবে:
|
||||
|
||||
```Python hl_lines="2"
|
||||
{!../../../docs_src/python_types/tutorial004.py!}
|
||||
```
|
||||
|
||||
## টাইপ ঘোষণা
|
||||
|
||||
আপনি এতক্ষন টাইপ হিন্ট ঘোষণা করার মূল স্থানটি দেখে ফেলেছেন-- ফাংশন প্যারামিটার হিসেবে।
|
||||
|
||||
সাধারণত এটি **FastAPI** এর ক্ষেত্রেও একই।
|
||||
|
||||
### সিম্পল টাইপ
|
||||
|
||||
আপনি `str` ছাড়াও সমস্ত স্ট্যান্ডার্ড পাইথন টাইপ ঘোষণা করতে পারেন।
|
||||
|
||||
উদাহরণস্বরূপ, আপনি এগুলো ব্যবহার করতে পারেন:
|
||||
|
||||
* `int`
|
||||
* `float`
|
||||
* `bool`
|
||||
* `bytes`
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!../../../docs_src/python_types/tutorial005.py!}
|
||||
```
|
||||
|
||||
### টাইপ প্যারামিটার সহ জেনেরিক টাইপ
|
||||
|
||||
কিছু ডাটা স্ট্রাকচার অন্যান্য মান ধারণ করতে পারে, যেমন `dict`, `list`, `set` এবং `tuple`। এবং অভ্যন্তরীণ মানগুলোরও নিজেদের টাইপ থাকতে পারে।
|
||||
|
||||
এই ধরনের টাইপগুলিকে বলা হয় "**জেনেরিক**" টাইপ এবং এগুলিকে তাদের অভ্যন্তরীণ টাইপগুলি সহ ঘোষণা করা সম্ভব।
|
||||
|
||||
এই টাইপগুলি এবং অভ্যন্তরীণ টাইপগুলি ঘোষণা করতে, আপনি Python মডিউল `typing` ব্যবহার করতে পারেন। এটি বিশেষভাবে এই টাইপ হিন্টগুলি সমর্থন করার জন্য রয়েছে।
|
||||
|
||||
#### Python এর নতুন সংস্করণ
|
||||
|
||||
`typing` ব্যবহার করা সিনট্যাক্সটি Python 3.6 থেকে সর্বশেষ সংস্করণগুলি পর্যন্ত, অর্থাৎ Python 3.9, Python 3.10 ইত্যাদি সহ সকল সংস্করণের সাথে **সামঞ্জস্যপূর্ণ**।
|
||||
|
||||
Python যত এগিয়ে যাচ্ছে, **নতুন সংস্করণগুলি** এই টাইপ অ্যানোটেশনগুলির জন্য তত উন্নত সাপোর্ট নিয়ে আসছে এবং অনেক ক্ষেত্রে আপনাকে টাইপ অ্যানোটেশন ঘোষণা করতে `typing` মডিউল ইম্পোর্ট এবং ব্যবহার করার প্রয়োজন হবে না।
|
||||
|
||||
যদি আপনি আপনার প্রজেক্টের জন্য Python-এর আরও সাম্প্রতিক সংস্করণ নির্বাচন করতে পারেন, তাহলে আপনি সেই অতিরিক্ত সরলতা থেকে সুবিধা নিতে পারবেন।
|
||||
|
||||
ডক্সে রয়েছে Python-এর প্রতিটি সংস্করণের সাথে সামঞ্জস্যপূর্ণ উদাহরণগুলি (যখন পার্থক্য আছে)।
|
||||
|
||||
উদাহরণস্বরূপ, "**Python 3.6+**" মানে এটি Python 3.6 বা তার উপরে সামঞ্জস্যপূর্ণ (যার মধ্যে 3.7, 3.8, 3.9, 3.10, ইত্যাদি অন্তর্ভুক্ত)। এবং "**Python 3.9+**" মানে এটি Python 3.9 বা তার উপরে সামঞ্জস্যপূর্ণ (যার মধ্যে 3.10, ইত্যাদি অন্তর্ভুক্ত)।
|
||||
|
||||
যদি আপনি Python-এর **সর্বশেষ সংস্করণগুলি ব্যবহার করতে পারেন**, তাহলে সর্বশেষ সংস্করণের জন্য উদাহরণগুলি ব্যবহার করুন, সেগুলি আপনাকে **সর্বোত্তম এবং সহজতম সিনট্যাক্স** প্রদান করবে, যেমন, "**Python 3.10+**"।
|
||||
|
||||
#### লিস্ট
|
||||
|
||||
উদাহরণস্বরূপ, একটি ভেরিয়েবলকে `str`-এর একটি `list` হিসেবে সংজ্ঞায়িত করা যাক।
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
ভেরিয়েবলটি ঘোষণা করুন, একই কোলন (`:`) সিনট্যাক্স ব্যবহার করে।
|
||||
|
||||
টাইপ হিসেবে, `list` ব্যবহার করুন।
|
||||
|
||||
যেহেতু লিস্ট এমন একটি টাইপ যা অভ্যন্তরীণ টাইপগুলি ধারণ করে, আপনি তাদের স্কোয়ার ব্রাকেটের ভিতরে ব্যবহার করুন:
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial006_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
`typing` থেকে `List` (বড় হাতের `L` দিয়ে) ইমপোর্ট করুন:
|
||||
|
||||
``` Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial006.py!}
|
||||
```
|
||||
|
||||
ভেরিয়েবলটি ঘোষণা করুন, একই কোলন (`:`) সিনট্যাক্স ব্যবহার করে।
|
||||
|
||||
টাইপ হিসেবে, `typing` থেকে আপনার ইম্পোর্ট করা `List` ব্যবহার করুন।
|
||||
|
||||
যেহেতু লিস্ট এমন একটি টাইপ যা অভ্যন্তরীণ টাইপগুলি ধারণ করে, আপনি তাদের স্কোয়ার ব্রাকেটের ভিতরে করুন:
|
||||
|
||||
```Python hl_lines="4"
|
||||
{!> ../../../docs_src/python_types/tutorial006.py!}
|
||||
```
|
||||
|
||||
!!! Info
|
||||
স্কোয়ার ব্রাকেট এর ভিতরে ব্যবহৃত এইসব অভন্তরীন টাইপগুলোকে "ইন্টারনাল টাইপ" বলে।
|
||||
|
||||
এই উদাহরণে, এটি হচ্ছে `List`(অথবা পাইথন ৩.৯ বা তার উপরের সংস্করণের ক্ষেত্রে `list`) এ পাস করা টাইপ প্যারামিটার।
|
||||
|
||||
এর অর্থ হচ্ছে: "ভেরিয়েবল `items` একটি `list`, এবং এই লিস্টের প্রতিটি আইটেম একটি `str`।"
|
||||
|
||||
!!! Tip
|
||||
যদি আপনি Python 3.9 বা তার উপরে ব্যবহার করেন, আপনার `typing` থেকে `List` আমদানি করতে হবে না, আপনি সাধারণ `list` ওই টাইপের পরিবর্তে ব্যবহার করতে পারেন।
|
||||
|
||||
এর মাধ্যমে, আপনার এডিটর লিস্ট থেকে আইটেম প্রসেস করার সময় সাপোর্ট প্রদান করতে পারবে:
|
||||
|
||||
<img src="/img/python-types/image05.png">
|
||||
|
||||
টাইপগুলি ছাড়া, এটি করা প্রায় অসম্ভব।
|
||||
|
||||
লক্ষ্য করুন যে ভেরিয়েবল `item` হল `items` লিস্টের একটি এলিমেন্ট।
|
||||
|
||||
তবুও, এডিটর জানে যে এটি একটি `str`, এবং তার জন্য সাপোর্ট প্রদান করে।
|
||||
|
||||
#### টাপল এবং সেট
|
||||
|
||||
আপনি `tuple` এবং `set` ঘোষণা করার জন্য একই প্রক্রিয়া অনুসরণ করবেন:
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial007_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial007.py!}
|
||||
```
|
||||
|
||||
এর মানে হল:
|
||||
|
||||
* ভেরিয়েবল `items_t` হল একটি `tuple` যা ৩টি আইটেম ধারণ করে, একটি `int`, অন্য একটি `int`, এবং একটি `str`।
|
||||
* ভেরিয়েবল `items_s` হল একটি `set`, এবং এর প্রতিটি আইটেম হল `bytes` টাইপের।
|
||||
|
||||
#### ডিক্ট
|
||||
|
||||
একটি `dict` সংজ্ঞায়িত করতে, আপনি ২টি টাইপ প্যারামিটার কমা দ্বারা পৃথক করে দেবেন।
|
||||
|
||||
প্রথম টাইপ প্যারামিটারটি হল `dict`-এর কীগুলির জন্য।
|
||||
|
||||
দ্বিতীয় টাইপ প্যারামিটারটি হল `dict`-এর মানগুলির জন্য:
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial008_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial008.py!}
|
||||
```
|
||||
|
||||
|
||||
এর মানে হল:
|
||||
|
||||
* ভেরিয়েবল `prices` হল একটি `dict`:
|
||||
* এই `dict`-এর কীগুলি হল `str` টাইপের (ধরা যাক, প্রতিটি আইটেমের নাম)।
|
||||
* এই `dict`-এর মানগুলি হল `float` টাইপের (ধরা যাক, প্রতিটি আইটেমের দাম)।
|
||||
|
||||
#### ইউনিয়ন
|
||||
|
||||
আপনি একটি ভেরিয়েবলকে এমনভাবে ঘোষণা করতে পারেন যেন তা **একাধিক টাইপের** হয়, উদাহরণস্বরূপ, একটি `int` অথবা `str`।
|
||||
|
||||
Python 3.6 এবং তার উপরের সংস্করণগুলিতে (Python 3.10 অন্তর্ভুক্ত) আপনি `typing` থেকে `Union` টাইপ ব্যবহার করতে পারেন এবং স্কোয়ার ব্র্যাকেটের মধ্যে গ্রহণযোগ্য টাইপগুলি রাখতে পারেন।
|
||||
|
||||
Python 3.10-এ একটি **নতুন সিনট্যাক্স** আছে যেখানে আপনি সম্ভাব্য টাইপগুলিকে একটি <abbr title="উল্লম্ব বারালকে 'বিটওয়াইজ বা অপারেটর' বলা হয়, কিন্তু সেই অর্থ এখানে প্রাসঙ্গিক নয়">ভার্টিকাল বার (`|`)</abbr> দ্বারা পৃথক করতে পারেন।
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial008b_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial008b.py!}
|
||||
```
|
||||
|
||||
উভয় ক্ষেত্রেই এর মানে হল যে `item` হতে পারে একটি `int` অথবা `str`।
|
||||
|
||||
#### সম্ভবত `None`
|
||||
|
||||
আপনি এমনভাবে ঘোষণা করতে পারেন যে একটি মান হতে পারে এক টাইপের, যেমন `str`, আবার এটি `None`-ও হতে পারে।
|
||||
|
||||
Python 3.6 এবং তার উপরের সংস্করণগুলিতে (Python 3.10 অনতর্ভুক্ত) আপনি `typing` মডিউল থেকে `Optional` ইমপোর্ট করে এটি ঘোষণা এবং ব্যবহার করতে পারেন।
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!../../../docs_src/python_types/tutorial009.py!}
|
||||
```
|
||||
|
||||
`Optional[str]` ব্যবহার করা মানে হল শুধু `str` নয়, এটি হতে পারে `None`-ও, যা আপনার এডিটরকে সেই ত্রুটিগুলি শনাক্ত করতে সাহায্য করবে যেখানে আপনি ধরে নিচ্ছেন যে একটি মান সবসময় `str` হবে, অথচ এটি `None`-ও হতে পারেও।
|
||||
|
||||
`Optional[Something]` মূলত `Union[Something, None]`-এর একটি শর্টকাট, এবং তারা সমতুল্য।
|
||||
|
||||
এর মানে হল, Python 3.10-এ, আপনি টাইপগুলির ইউনিয়ন ঘোষণা করতে `Something | None` ব্যবহার করতে পারেন:
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial009_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial009.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+ বিকল্প"
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial009b.py!}
|
||||
```
|
||||
|
||||
#### `Union` বা `Optional` ব্যবহার
|
||||
|
||||
যদি আপনি Python 3.10-এর নীচের সংস্করণ ব্যবহার করেন, তবে এখানে আমার খুবই **ব্যক্তিগত** দৃষ্টিভঙ্গি থেকে একটি টিপস:
|
||||
|
||||
* 🚨 `Optional[SomeType]` ব্যবহার এড়িয়ে চলুন।
|
||||
* এর পরিবর্তে ✨ **`Union[SomeType, None]` ব্যবহার করুন** ✨।
|
||||
|
||||
উভয়ই সমতুল্য এবং মূলে একই, কিন্তু আমি `Union`-এর পক্ষে সুপারিশ করব কারণ "**অপশনাল**" শব্দটি মনে হতে পারে যে মানটি ঐচ্ছিক,অথচ এটি আসলে মানে "এটি হতে পারে `None`", এমনকি যদি এটি ঐচ্ছিক না হয়েও আবশ্যিক হয়।
|
||||
|
||||
আমি মনে করি `Union[SomeType, None]` এর অর্থ আরও স্পষ্টভাবে প্রকাশ করে।
|
||||
|
||||
এটি কেবল শব্দ এবং নামের ব্যাপার। কিন্তু সেই শব্দগুলি আপনি এবং আপনার সহকর্মীরা কোড সম্পর্কে কীভাবে চিন্তা করেন তা প্রভাবিত করতে পারে।
|
||||
|
||||
একটি উদাহরণ হিসেবে, এই ফাংশনটি নিন:
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!../../../docs_src/python_types/tutorial009c.py!}
|
||||
```
|
||||
|
||||
`name` প্যারামিটারটি `Optional[str]` হিসেবে সংজ্ঞায়িত হয়েছে, কিন্তু এটি **অপশনাল নয়**, আপনি প্যারামিটার ছাড়া ফাংশনটি কল করতে পারবেন না:
|
||||
|
||||
```Python
|
||||
say_hi() # ওহ না, এটি একটি ত্রুটি নিক্ষেপ করবে! 😱
|
||||
```
|
||||
|
||||
`name` প্যারামিটারটি **এখনও আবশ্যিক** (নন-অপশনাল) কারণ এটির কোনো ডিফল্ট মান নেই। তবুও, `name` এর মান হিসেবে `None` গ্রহণযোগ্য:
|
||||
|
||||
```Python
|
||||
say_hi(name=None) # এটি কাজ করে, None বৈধ 🎉
|
||||
```
|
||||
|
||||
সুখবর হল, একবার আপনি Python 3.10 ব্যবহার করা শুরু করলে, আপনাকে এগুলোর ব্যাপারে আর চিন্তা করতে হবে না, যেহুতু আপনি | ব্যবহার করেই ইউনিয়ন ঘোষণা করতে পারবেন:
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!../../../docs_src/python_types/tutorial009c_py310.py!}
|
||||
```
|
||||
|
||||
এবং তারপর আপনাকে নামগুলি যেমন `Optional` এবং `Union` নিয়ে আর চিন্তা করতে হবে না। 😎
|
||||
|
||||
#### জেনেরিক টাইপস
|
||||
|
||||
স্কোয়ার ব্র্যাকেটে টাইপ প্যারামিটার নেওয়া এই টাইপগুলিকে **জেনেরিক টাইপ** বা **জেনেরিকস** বলা হয়, যেমন:
|
||||
|
||||
=== "Python 3.10+"
|
||||
আপনি সেই একই বিল্টইন টাইপ জেনেরিক্স হিসেবে ব্যবহার করতে পারবেন(ভিতরে টাইপ সহ স্কয়ারে ব্রাকেট দিয়ে):
|
||||
|
||||
* `list`
|
||||
* `tuple`
|
||||
* `set`
|
||||
* `dict`
|
||||
|
||||
এবং Python 3.8 এর মতোই, `typing` মডিউল থেকে:
|
||||
|
||||
* `Union`
|
||||
* `Optional` (Python 3.8 এর মতোই)
|
||||
* ...এবং অন্যান্য।
|
||||
|
||||
Python 3.10-এ, `Union` এবং `Optional` জেনেরিকস ব্যবহার করার বিকল্প হিসেবে, আপনি টাইপগুলির ইউনিয়ন ঘোষণা করতে <abbr title="উল্লম্ব বারালকে 'বিটওয়াইজ বা অপারেটর' বলা হয়, কিন্তু সেই অর্থ এখানে প্রাসঙ্গিক নয়">ভার্টিকাল বার (`|`)</abbr> ব্যবহার করতে পারেন, যা ওদের থেকে অনেক ভালো এবং সহজ।
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
আপনি সেই একই বিল্টইন টাইপ জেনেরিক্স হিসেবে ব্যবহার করতে পারবেন(ভিতরে টাইপ সহ স্কয়ারে ব্রাকেট দিয়ে):
|
||||
|
||||
* `list`
|
||||
* `tuple`
|
||||
* `set`
|
||||
* `dict`
|
||||
|
||||
এবং Python 3.8 এর মতোই, `typing` মডিউল থেকে:
|
||||
|
||||
* `Union`
|
||||
* `Optional`
|
||||
* ...এবং অন্যান্য।
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
* `List`
|
||||
* `Tuple`
|
||||
* `Set`
|
||||
* `Dict`
|
||||
* `Union`
|
||||
* `Optional`
|
||||
* ...এবং অন্যান্য।
|
||||
|
||||
### ক্লাস হিসেবে টাইপস
|
||||
|
||||
আপনি একটি ভেরিয়েবলের টাইপ হিসেবে একটি ক্লাস ঘোষণা করতে পারেন।
|
||||
|
||||
ধরুন আপনার কাছে `Person` নামে একটি ক্লাস আছে, যার একটি নাম আছে:
|
||||
|
||||
```Python hl_lines="1-3"
|
||||
{!../../../docs_src/python_types/tutorial010.py!}
|
||||
```
|
||||
|
||||
তারপর আপনি একটি ভেরিয়েবলকে `Person` টাইপের হিসেবে ঘোষণা করতে পারেন:
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!../../../docs_src/python_types/tutorial010.py!}
|
||||
```
|
||||
|
||||
এবং তারপর, আবার, আপনি এডিটর সাপোর্ট পেয়ে যাবেন:
|
||||
|
||||
<img src="/img/python-types/image06.png">
|
||||
|
||||
লক্ষ্য করুন যে এর মানে হল "`one_person` হল ক্লাস `Person`-এর একটি **ইন্সট্যান্স**।"
|
||||
|
||||
এর মানে এটি নয় যে "`one_person` হল **ক্লাস** যাকে বলা হয় `Person`।"
|
||||
|
||||
## Pydantic মডেল
|
||||
|
||||
[Pydantic](https://docs.pydantic.dev/) হল একটি Python লাইব্রেরি যা ডাটা ভ্যালিডেশন সম্পাদন করে।
|
||||
|
||||
আপনি ডাটার "আকার" এট্রিবিউট সহ ক্লাস হিসেবে ঘোষণা করেন।
|
||||
|
||||
এবং প্রতিটি এট্রিবিউট এর একটি টাইপ থাকে।
|
||||
|
||||
তারপর আপনি যদি কিছু মান দিয়ে সেই ক্লাসের একটি ইন্সট্যান্স তৈরি করেন-- এটি মানগুলিকে ভ্যালিডেট করবে, প্রয়োজন অনুযায়ী তাদেরকে উপযুক্ত টাইপে রূপান্তর করবে এবং আপনাকে সমস্ত ডাটা সহ একটি অবজেক্ট প্রদান করবে।
|
||||
|
||||
এবং আপনি সেই ফলাফল অবজেক্টের সাথে এডিটর সাপোর্ট পাবেন।
|
||||
|
||||
অফিসিয়াল Pydantic ডক্স থেকে একটি উদাহরণ:
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/python_types/tutorial011_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/python_types/tutorial011_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python
|
||||
{!> ../../../docs_src/python_types/tutorial011.py!}
|
||||
```
|
||||
|
||||
!!! Info
|
||||
[Pydantic সম্পর্কে আরও জানতে, এর ডকুমেন্টেশন দেখুন](https://docs.pydantic.dev/)।
|
||||
|
||||
**FastAPI** মূলত Pydantic-এর উপর নির্মিত।
|
||||
|
||||
আপনি এই সমস্ত কিছুর অনেক বাস্তবসম্মত উদাহরণ পাবেন [টিউটোরিয়াল - ইউজার গাইডে](https://fastapi.tiangolo.com/tutorial/)।
|
||||
|
||||
!!! Tip
|
||||
যখন আপনি `Optional` বা `Union[Something, None]` ব্যবহার করেন এবং কোনো ডিফল্ট মান না থাকে, Pydantic-এর একটি বিশেষ আচরণ রয়েছে, আপনি Pydantic ডকুমেন্টেশনে [Required Optional fields](https://docs.pydantic.dev/latest/concepts/models/#required-optional-fields) সম্পর্কে আরও পড়তে পারেন।
|
||||
|
||||
## মেটাডাটা অ্যানোটেশন সহ টাইপ হিন্টস
|
||||
|
||||
Python-এ এমন একটি ফিচার আছে যা `Annotated` ব্যবহার করে এই টাইপ হিন্টগুলিতে **অতিরিক্ত মেটাডাটা** রাখতে দেয়।
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
Python 3.9-এ, `Annotated` স্ট্যান্ডার্ড লাইব্রেরিতে অন্তর্ভুক্ত, তাই আপনি এটি `typing` থেকে ইমপোর্ট করতে পারেন।
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial013_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
Python 3.9-এর নীচের সংস্করণগুলিতে, আপনি `Annotated`-কে `typing_extensions` থেকে ইমপোর্ট করেন।
|
||||
|
||||
এটি **FastAPI** এর সাথে ইতিমদ্ধে ইনস্টল হয়ে থাকবে।
|
||||
|
||||
```Python hl_lines="1 4"
|
||||
{!> ../../../docs_src/python_types/tutorial013.py!}
|
||||
```
|
||||
|
||||
Python নিজে এই `Annotated` দিয়ে কিছুই করে না। এবং এডিটর এবং অন্যান্য টুলগুলির জন্য, টাইপটি এখনও `str`।
|
||||
|
||||
কিন্তু আপনি এই `Annotated` এর মধ্যকার জায়গাটির মধ্যে **FastAPI**-এ কীভাবে আপনার অ্যাপ্লিকেশন আচরণ করুক তা সম্পর্কে অতিরিক্ত মেটাডাটা প্রদান করার জন্য ব্যবহার করতে পারেন।
|
||||
|
||||
মনে রাখার গুরুত্বপূর্ণ বিষয় হল যে **প্রথম *টাইপ প্যারামিটার*** আপনি `Annotated`-এ পাস করেন সেটি হল **আসল টাইপ**। বাকি শুধুমাত্র অন্যান্য টুলগুলির জন্য মেটাডাটা।
|
||||
|
||||
এখন আপনার কেবল জানা প্রয়োজন যে `Annotated` বিদ্যমান, এবং এটি স্ট্যান্ডার্ড Python। 😎
|
||||
|
||||
পরবর্তীতে আপনি দেখবেন এটি কতটা **শক্তিশালী** হতে পারে।
|
||||
|
||||
!!! Tip
|
||||
এটি **স্ট্যান্ডার্ড Python** হওয়ার মানে হল আপনি আপনার এডিটরে, আপনি যে টুলগুলি কোড বিশ্লেষণ এবং রিফ্যাক্টর করার জন্য ব্যবহার করেন তাতে **সেরা সম্ভাব্য ডেভেলপার এক্সপেরিয়েন্স** পাবেন। ✨
|
||||
|
||||
এবং এছাড়াও আপনার কোড অন্যান্য অনেক Python টুল এবং লাইব্রেরিগুলির সাথে খুব সামঞ্জস্যপূর্ণ হবে। 🚀
|
||||
|
||||
## **FastAPI**-এ টাইপ হিন্টস
|
||||
|
||||
**FastAPI** এই টাইপ হিন্টগুলি ব্যবহার করে বেশ কিছু জিনিস করে।
|
||||
|
||||
**FastAPI**-এ আপনি টাইপ হিন্টগুলি সহ প্যারামিটার ঘোষণা করেন এবং আপনি পান:
|
||||
|
||||
* **এডিটর সাপোর্ট**।
|
||||
* **টাইপচেক**।
|
||||
|
||||
...এবং **FastAPI** একই ঘোষণাগুলি ব্যবহার করে:
|
||||
|
||||
* **রিকুইরেমেন্টস সংজ্ঞায়িত করে**: রিকোয়েস্ট পাথ প্যারামিটার, কুয়েরি প্যারামিটার, হেডার, বডি, ডিপেন্ডেন্সিস, ইত্যাদি থেকে।
|
||||
* **ডেটা রূপান্তর করে**: রিকোয়েস্ট থেকে প্রয়োজনীয় টাইপে ডেটা।
|
||||
* **ডেটা যাচাই করে**: প্রতিটি রিকোয়েস্ট থেকে আসা ডেটা:
|
||||
* যখন ডেটা অবৈধ হয় তখন **স্বয়ংক্রিয় ত্রুটি** গ্রাহকের কাছে ফেরত পাঠানো।
|
||||
* **API ডকুমেন্টেশন তৈরি করে**: OpenAPI ব্যবহার করে:
|
||||
* যা স্বয়ংক্রিয় ইন্টার্যাক্টিভ ডকুমেন্টেশন ইউজার ইন্টারফেস দ্বারা ব্যবহৃত হয়।
|
||||
|
||||
এই সব কিছু আপনার কাছে অস্পষ্ট মনে হতে পারে। চিন্তা করবেন না। আপনি [টিউটোরিয়াল - ইউজার গাইড](https://fastapi.tiangolo.com/tutorial/) এ এই সব কিছু প্র্যাকটিসে দেখতে পাবেন।
|
||||
|
||||
গুরুত্বপূর্ণ বিষয় হল, আপনি যদি স্ট্যান্ডার্ড Python টাইপগুলি ব্যবহার করেন, তবে আরও বেশি ক্লাস, ডেকোরেটর ইত্যাদি যোগ না করেই একই স্থানে **FastAPI** আপনার অনেক কাজ করে দিবে।
|
||||
|
||||
!!! Info
|
||||
যদি আপনি টিউটোরিয়ালের সমস্ত বিষয় পড়ে ফেলে থাকেন এবং টাইপ সম্পর্কে আরও জানতে চান, তবে একটি ভালো রিসোর্স হল [mypy এর "cheat sheet"](https://mypy.readthedocs.io/en/latest/cheat_sheet_py3.html)। এই "cheat sheet" এ আপনি Python টাইপ হিন্ট সম্পর্কে বেসিক থেকে উন্নত লেভেলের ধারণা পেতে পারেন, যা আপনার কোডে টাইপ সেফটি এবং স্পষ্টতা বাড়াতে সাহায্য করবে।
|
||||
@@ -10,7 +10,7 @@ Es gibt viele Tools zum Generieren von Clients aus **OpenAPI**.
|
||||
|
||||
Ein gängiges Tool ist <a href="https://openapi-generator.tech/" class="external-link" target="_blank">OpenAPI Generator</a>.
|
||||
|
||||
Wenn Sie ein **Frontend** erstellen, ist <a href="https://github.com/ferdikoomen/openapi-typescript-codegen" class="external-link" target="_blank">openapi-typescript-codegen</a> eine sehr interessante Alternative.
|
||||
Wenn Sie ein **Frontend** erstellen, ist <a href="https://github.com/hey-api/openapi-ts" class="external-link" target="_blank">openapi-ts</a> eine sehr interessante Alternative.
|
||||
|
||||
## Client- und SDK-Generatoren – Sponsor
|
||||
|
||||
@@ -58,14 +58,14 @@ Und dieselben Informationen aus den Modellen, die in OpenAPI enthalten sind, kö
|
||||
|
||||
Nachdem wir nun die Anwendung mit den Modellen haben, können wir den Client-Code für das Frontend generieren.
|
||||
|
||||
#### `openapi-typescript-codegen` installieren
|
||||
#### `openapi-ts` installieren
|
||||
|
||||
Sie können `openapi-typescript-codegen` in Ihrem Frontend-Code installieren mit:
|
||||
Sie können `openapi-ts` in Ihrem Frontend-Code installieren mit:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ npm install openapi-typescript-codegen --save-dev
|
||||
$ npm install @hey-api/openapi-ts --save-dev
|
||||
|
||||
---> 100%
|
||||
```
|
||||
@@ -74,7 +74,7 @@ $ npm install openapi-typescript-codegen --save-dev
|
||||
|
||||
#### Client-Code generieren
|
||||
|
||||
Um den Client-Code zu generieren, können Sie das Kommandozeilentool `openapi` verwenden, das soeben installiert wurde.
|
||||
Um den Client-Code zu generieren, können Sie das Kommandozeilentool `openapi-ts` verwenden, das soeben installiert wurde.
|
||||
|
||||
Da es im lokalen Projekt installiert ist, könnten Sie diesen Befehl wahrscheinlich nicht direkt aufrufen, sondern würden ihn in Ihre Datei `package.json` einfügen.
|
||||
|
||||
@@ -87,12 +87,12 @@ Diese könnte so aussehen:
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes"
|
||||
"generate-client": "openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ Nachdem Sie das NPM-Skript `generate-client` dort stehen haben, können Sie es a
|
||||
$ npm run generate-client
|
||||
|
||||
frontend-app@1.0.0 generate-client /home/user/code/frontend-app
|
||||
> openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes
|
||||
> openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -254,12 +254,12 @@ Da das Endergebnis nun in einer Datei `openapi.json` vorliegt, würden Sie die `
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input ./openapi.json --output ./src/client --client axios --useOptions --useUnionTypes"
|
||||
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ hide:
|
||||
|
||||
---
|
||||
|
||||
FastAPI ist ein modernes, schnelles (hoch performantes) Webframework zur Erstellung von APIs mit Python 3.8+ auf Basis von Standard-Python-Typhinweisen.
|
||||
FastAPI ist ein modernes, schnelles (hoch performantes) Webframework zur Erstellung von APIs mit Python auf Basis von Standard-Python-Typhinweisen.
|
||||
|
||||
Seine Schlüssel-Merkmale sind:
|
||||
|
||||
@@ -125,8 +125,6 @@ Wenn Sie eine <abbr title="Command Line Interface – Kommandozeilen-Schnittstel
|
||||
|
||||
## Anforderungen
|
||||
|
||||
Python 3.8+
|
||||
|
||||
FastAPI steht auf den Schultern von Giganten:
|
||||
|
||||
* <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a> für die Webanteile.
|
||||
@@ -340,7 +338,7 @@ Das machen Sie mit modernen Standard-Python-Typen.
|
||||
|
||||
Sie müssen keine neue Syntax, Methoden oder Klassen einer bestimmten Bibliothek usw. lernen.
|
||||
|
||||
Nur Standard-**Python 3.8+**.
|
||||
Nur Standard-**Python+**.
|
||||
|
||||
Zum Beispiel für ein `int`:
|
||||
|
||||
|
||||
@@ -341,6 +341,6 @@ $ uvicorn main:app --root-path /api/v1
|
||||
|
||||
## 🗜 🎧-🈸
|
||||
|
||||
🚥 👆 💪 🗻 🎧-🈸 (🔬 [🎧 🈸 - 🗻](./sub-applications.md){.internal-link target=_blank}) ⏪ ⚙️ 🗳 ⏮️ `root_path`, 👆 💪 ⚫️ 🛎, 👆 🔜 ⌛.
|
||||
🚥 👆 💪 🗻 🎧-🈸 (🔬 [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}) ⏪ ⚙️ 🗳 ⏮️ `root_path`, 👆 💪 ⚫️ 🛎, 👆 🔜 ⌛.
|
||||
|
||||
FastAPI 🔜 🔘 ⚙️ `root_path` 🎆, ⚫️ 🔜 👷. 👶
|
||||
|
||||
@@ -157,4 +157,4 @@ async with lifespan(app):
|
||||
|
||||
## 🎧 🈸
|
||||
|
||||
👶 ✔️ 🤯 👈 👫 🔆 🎉 (🕴 & 🤫) 🔜 🕴 🛠️ 👑 🈸, 🚫 [🎧 🈸 - 🗻](./sub-applications.md){.internal-link target=_blank}.
|
||||
👶 ✔️ 🤯 👈 👫 🔆 🎉 (🕴 & 🤫) 🔜 🕴 🛠️ 👑 🈸, 🚫 [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}.
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
⚠ 🧰 <a href="https://openapi-generator.tech/" class="external-link" target="_blank">🗄 🚂</a>.
|
||||
|
||||
🚥 👆 🏗 **🕸**, 📶 😌 🎛 <a href="https://github.com/ferdikoomen/openapi-typescript-codegen" class="external-link" target="_blank">🗄-📕-🇦🇪</a>.
|
||||
🚥 👆 🏗 **🕸**, 📶 😌 🎛 <a href="https://github.com/hey-api/openapi-ts" class="external-link" target="_blank">🗄-📕-🇦🇪</a>.
|
||||
|
||||
## 🏗 📕 🕸 👩💻
|
||||
|
||||
@@ -46,14 +46,14 @@
|
||||
|
||||
🔜 👈 👥 ✔️ 📱 ⏮️ 🏷, 👥 💪 🏗 👩💻 📟 🕸.
|
||||
|
||||
#### ❎ `openapi-typescript-codegen`
|
||||
#### ❎ `openapi-ts`
|
||||
|
||||
👆 💪 ❎ `openapi-typescript-codegen` 👆 🕸 📟 ⏮️:
|
||||
👆 💪 ❎ `openapi-ts` 👆 🕸 📟 ⏮️:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ npm install openapi-typescript-codegen --save-dev
|
||||
$ npm install @hey-api/openapi-ts --save-dev
|
||||
|
||||
---> 100%
|
||||
```
|
||||
@@ -62,7 +62,7 @@ $ npm install openapi-typescript-codegen --save-dev
|
||||
|
||||
#### 🏗 👩💻 📟
|
||||
|
||||
🏗 👩💻 📟 👆 💪 ⚙️ 📋 ⏸ 🈸 `openapi` 👈 🔜 🔜 ❎.
|
||||
🏗 👩💻 📟 👆 💪 ⚙️ 📋 ⏸ 🈸 `openapi-ts` 👈 🔜 🔜 ❎.
|
||||
|
||||
↩️ ⚫️ ❎ 🇧🇿 🏗, 👆 🎲 🚫🔜 💪 🤙 👈 📋 🔗, ✋️ 👆 🔜 🚮 ⚫️ 🔛 👆 `package.json` 📁.
|
||||
|
||||
@@ -75,12 +75,12 @@ $ npm install openapi-typescript-codegen --save-dev
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios"
|
||||
"generate-client": "openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ $ npm install openapi-typescript-codegen --save-dev
|
||||
$ npm run generate-client
|
||||
|
||||
frontend-app@1.0.0 generate-client /home/user/code/frontend-app
|
||||
> openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios
|
||||
> openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -235,12 +235,12 @@ FastAPI ⚙️ **😍 🆔** 🔠 *➡ 🛠️*, ⚫️ ⚙️ **🛠️ 🆔**
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input ./openapi.json --output ./src/client --client axios"
|
||||
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
|
||||
👆 💪 📣 🌖 📨 ⏮️ 👫 🏷, 👔 📟, ♒️.
|
||||
|
||||
📤 🎂 📃 📥 🧾 🔃 ⚫️, 👆 💪 ✍ ⚫️ [🌖 📨 🗄](./additional-responses.md){.internal-link target=_blank}.
|
||||
📤 🎂 📃 📥 🧾 🔃 ⚫️, 👆 💪 ✍ ⚫️ [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
||||
|
||||
## 🗄 ➕
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
!!! tip
|
||||
👉 🔅 🎚 ↔ ☝.
|
||||
|
||||
🚥 👆 🕴 💪 📣 🌖 📨, 🌅 🏪 🌌 ⚫️ ⏮️ [🌖 📨 🗄](./additional-responses.md){.internal-link target=_blank}.
|
||||
🚥 👆 🕴 💪 📣 🌖 📨, 🌅 🏪 🌌 ⚫️ ⏮️ [🌖 📨 🗄](additional-responses.md){.internal-link target=_blank}.
|
||||
|
||||
👆 💪 ↔ 🗄 🔗 *➡ 🛠️* ⚙️ 🔢 `openapi_extra`.
|
||||
|
||||
|
||||
@@ -70,4 +70,4 @@ $ uvicorn main:app --reload
|
||||
|
||||
& 🎧-🈸 💪 ✔️ 🚮 👍 📌 🎧-🈸 & 🌐 🔜 👷 ☑, ↩️ FastAPI 🍵 🌐 👉 `root_path`Ⓜ 🔁.
|
||||
|
||||
👆 🔜 💡 🌅 🔃 `root_path` & ❔ ⚙️ ⚫️ 🎯 📄 🔃 [⛅ 🗳](./behind-a-proxy.md){.internal-link target=_blank}.
|
||||
👆 🔜 💡 🌅 🔃 `root_path` & ❔ ⚙️ ⚫️ 🎯 📄 🔃 [⛅ 🗳](behind-a-proxy.md){.internal-link target=_blank}.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# ✅ 🇨🇻 - 🏺, ✳, 🎏
|
||||
|
||||
👆 💪 🗻 🇨🇻 🈸 👆 👀 ⏮️ [🎧 🈸 - 🗻](./sub-applications.md){.internal-link target=_blank}, [⛅ 🗳](./behind-a-proxy.md){.internal-link target=_blank}.
|
||||
👆 💪 🗻 🇨🇻 🈸 👆 👀 ⏮️ [🎧 🈸 - 🗻](sub-applications.md){.internal-link target=_blank}, [⛅ 🗳](behind-a-proxy.md){.internal-link target=_blank}.
|
||||
|
||||
👈, 👆 💪 ⚙️ `WSGIMiddleware` & ⚙️ ⚫️ 🎁 👆 🇨🇻 🈸, 🖼, 🏺, ✳, ♒️.
|
||||
|
||||
|
||||
@@ -405,15 +405,15 @@ async def read_burgers():
|
||||
|
||||
🚥 👆 👟 ⚪️➡️ ➕1️⃣ 🔁 🛠️ 👈 🔨 🚫 👷 🌌 🔬 🔛 & 👆 ⚙️ ⚖ 🙃 📊-🕴 *➡ 🛠️ 🔢* ⏮️ ✅ `def` 🤪 🎭 📈 (🔃 1️⃣0️⃣0️⃣ 💓), 🙏 🗒 👈 **FastAPI** ⭐ 🔜 🔄. 👫 💼, ⚫️ 👻 ⚙️ `async def` 🚥 👆 *➡ 🛠️ 🔢* ⚙️ 📟 👈 🎭 🚧 <abbr title="Input/Output: disk reading or writing, network communications.">👤/🅾</abbr>.
|
||||
|
||||
, 👯♂️ ⚠, 🤞 👈 **FastAPI** 🔜 [⏩](index.md#performance){.internal-link target=_blank} 🌘 (⚖️ 🌘 ⭐) 👆 ⏮️ 🛠️.
|
||||
, 👯♂️ ⚠, 🤞 👈 **FastAPI** 🔜 [⏩](index.md#_15){.internal-link target=_blank} 🌘 (⚖️ 🌘 ⭐) 👆 ⏮️ 🛠️.
|
||||
|
||||
### 🔗
|
||||
|
||||
🎏 ✔ [🔗](./tutorial/dependencies/index.md){.internal-link target=_blank}. 🚥 🔗 🐩 `def` 🔢 ↩️ `async def`, ⚫️ 🏃 🔢 🧵.
|
||||
🎏 ✔ [🔗](tutorial/dependencies/index.md){.internal-link target=_blank}. 🚥 🔗 🐩 `def` 🔢 ↩️ `async def`, ⚫️ 🏃 🔢 🧵.
|
||||
|
||||
### 🎧-🔗
|
||||
|
||||
👆 💪 ✔️ 💗 🔗 & [🎧-🔗](./tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} 🚫 🔠 🎏 (🔢 🔢 🔑), 👫 💪 ✍ ⏮️ `async def` & ⏮️ 😐 `def`. ⚫️ 🔜 👷, & 🕐 ✍ ⏮️ 😐 `def` 🔜 🤙 🔛 🔢 🧵 (⚪️➡️ 🧵) ↩️ ➖ "⌛".
|
||||
👆 💪 ✔️ 💗 🔗 & [🎧-🔗](tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} 🚫 🔠 🎏 (🔢 🔢 🔑), 👫 💪 ✍ ⏮️ `async def` & ⏮️ 😐 `def`. ⚫️ 🔜 👷, & 🕐 ✍ ⏮️ 😐 `def` 🔜 🤙 🔛 🔢 🧵 (⚪️➡️ 🧵) ↩️ ➖ "⌛".
|
||||
|
||||
### 🎏 🚙 🔢
|
||||
|
||||
@@ -427,4 +427,4 @@ async def read_burgers():
|
||||
|
||||
🔄, 👉 📶 📡 ℹ 👈 🔜 🎲 ⚠ 🚥 👆 👟 🔎 👫.
|
||||
|
||||
⏪, 👆 🔜 👍 ⏮️ 📄 ⚪️➡️ 📄 🔛: <a href="#in-a-hurry">🏃 ❓</a>.
|
||||
⏪, 👆 🔜 👍 ⏮️ 📄 ⚪️➡️ 📄 🔛: <a href="#_2">🏃 ❓</a>.
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
## 💂♂ - 🇺🇸🔍
|
||||
|
||||
[⏮️ 📃 🔃 🇺🇸🔍](./https.md){.internal-link target=_blank} 👥 🇭🇲 🔃 ❔ 🇺🇸🔍 🚚 🔐 👆 🛠️.
|
||||
[⏮️ 📃 🔃 🇺🇸🔍](https.md){.internal-link target=_blank} 👥 🇭🇲 🔃 ❔ 🇺🇸🔍 🚚 🔐 👆 🛠️.
|
||||
|
||||
👥 👀 👈 🇺🇸🔍 🛎 🚚 🦲 **🔢** 👆 🈸 💽, **🤝 ❎ 🗳**.
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
|
||||
### 👨🏭 🛠️ & ⛴
|
||||
|
||||
💭 ⚪️➡️ 🩺 [🔃 🇺🇸🔍](./https.md){.internal-link target=_blank} 👈 🕴 1️⃣ 🛠️ 💪 👂 🔛 1️⃣ 🌀 ⛴ & 📢 📢 💽 ❓
|
||||
💭 ⚪️➡️ 🩺 [🔃 🇺🇸🔍](https.md){.internal-link target=_blank} 👈 🕴 1️⃣ 🛠️ 💪 👂 🔛 1️⃣ 🌀 ⛴ & 📢 📢 💽 ❓
|
||||
|
||||
👉 ☑.
|
||||
|
||||
@@ -241,7 +241,7 @@
|
||||
!!! tip
|
||||
🚫 😟 🚥 👫 🏬 🔃 **📦**, ☁, ⚖️ Kubernetes 🚫 ⚒ 📚 🔑.
|
||||
|
||||
👤 🔜 💬 👆 🌅 🔃 📦 🖼, ☁, Kubernetes, ♒️. 🔮 📃: [FastAPI 📦 - ☁](./docker.md){.internal-link target=_blank}.
|
||||
👤 🔜 💬 👆 🌅 🔃 📦 🖼, ☁, Kubernetes, ♒️. 🔮 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
||||
|
||||
## ⏮️ 🔁 ⏭ ▶️
|
||||
|
||||
@@ -273,7 +273,7 @@
|
||||
* 👆 🔜 💪 🌌 ▶️/⏏ *👈* 🎉 ✍, 🔍 ❌, ♒️.
|
||||
|
||||
!!! tip
|
||||
👤 🔜 🤝 👆 🌅 🧱 🖼 🔨 👉 ⏮️ 📦 🔮 📃: [FastAPI 📦 - ☁](./docker.md){.internal-link target=_blank}.
|
||||
👤 🔜 🤝 👆 🌅 🧱 🖼 🔨 👉 ⏮️ 📦 🔮 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
||||
|
||||
## ℹ 🛠️
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
⚙️ 💾 📦 ✔️ 📚 📈 ✅ **💂♂**, **🔬**, **🦁**, & 🎏.
|
||||
|
||||
!!! tip
|
||||
🏃 & ⏪ 💭 👉 💩 ❓ 🦘 [`Dockerfile` 🔛 👶](#build-a-docker-image-for-fastapi).
|
||||
🏃 & ⏪ 💭 👉 💩 ❓ 🦘 [`Dockerfile` 🔛 👶](#fastapi).
|
||||
|
||||
<details>
|
||||
<summary>📁 🎮 👶</summary>
|
||||
@@ -108,7 +108,7 @@ CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
|
||||
🌅 ⚠ 🌌 ⚫️ ✔️ 📁 `requirements.txt` ⏮️ 📦 📛 & 👫 ⏬, 1️⃣ 📍 ⏸.
|
||||
|
||||
👆 🔜 ↗️ ⚙️ 🎏 💭 👆 ✍ [🔃 FastAPI ⏬](./versions.md){.internal-link target=_blank} ⚒ ↔ ⏬.
|
||||
👆 🔜 ↗️ ⚙️ 🎏 💭 👆 ✍ [🔃 FastAPI ⏬](versions.md){.internal-link target=_blank} ⚒ ↔ ⏬.
|
||||
|
||||
🖼, 👆 `requirements.txt` 💪 👀 💖:
|
||||
|
||||
@@ -373,7 +373,7 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
|
||||
## 🛠️ 🔧
|
||||
|
||||
➡️ 💬 🔄 🔃 🎏 [🛠️ 🔧](./concepts.md){.internal-link target=_blank} ⚖ 📦.
|
||||
➡️ 💬 🔄 🔃 🎏 [🛠️ 🔧](concepts.md){.internal-link target=_blank} ⚖ 📦.
|
||||
|
||||
📦 ✴️ 🧰 📉 🛠️ **🏗 & 🛠️** 🈸, ✋️ 👫 🚫 🛠️ 🎯 🎯 🍵 👉 **🛠️ 🔧**, & 📤 📚 💪 🎛.
|
||||
|
||||
@@ -415,7 +415,7 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
|
||||
1️⃣ 📚 📎 📦 🧾 ⚙️ 💖 Kubernetes 🛎 ✔️ 🛠️ 🌌 🚚 **🧬 📦** ⏪ 🔗 **📐 ⚖** 📨 📨. 🌐 **🌑 🎚**.
|
||||
|
||||
📚 💼, 👆 🔜 🎲 💚 🏗 **☁ 🖼 ⚪️➡️ 🖌** [🔬 🔛](#dockerfile), ❎ 👆 🔗, & 🏃♂ **👁 Uvicorn 🛠️** ↩️ 🏃♂ 🕳 💖 🐁 ⏮️ Uvicorn 👨🏭.
|
||||
📚 💼, 👆 🔜 🎲 💚 🏗 **☁ 🖼 ⚪️➡️ 🖌** [🔬 🔛](#_6), ❎ 👆 🔗, & 🏃♂ **👁 Uvicorn 🛠️** ↩️ 🏃♂ 🕳 💖 🐁 ⏮️ Uvicorn 👨🏭.
|
||||
|
||||
### 📐 ⚙
|
||||
|
||||
@@ -450,7 +450,7 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
|
||||
↗️, 📤 **🎁 💼** 🌐❔ 👆 💪 💚 ✔️ **📦** ⏮️ **🐁 🛠️ 👨💼** ▶️ 📚 **Uvicorn 👨🏭 🛠️** 🔘.
|
||||
|
||||
📚 💼, 👆 💪 ⚙️ **🛂 ☁ 🖼** 👈 🔌 **🐁** 🛠️ 👨💼 🏃♂ 💗 **Uvicorn 👨🏭 🛠️**, & 🔢 ⚒ 🔆 🔢 👨🏭 ⚓️ 🔛 ⏮️ 💽 🐚 🔁. 👤 🔜 💬 👆 🌅 🔃 ⚫️ 🔛 [🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn](#official-docker-image-with-gunicorn-uvicorn).
|
||||
📚 💼, 👆 💪 ⚙️ **🛂 ☁ 🖼** 👈 🔌 **🐁** 🛠️ 👨💼 🏃♂ 💗 **Uvicorn 👨🏭 🛠️**, & 🔢 ⚒ 🔆 🔢 👨🏭 ⚓️ 🔛 ⏮️ 💽 🐚 🔁. 👤 🔜 💬 👆 🌅 🔃 ⚫️ 🔛 [🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn](#-uvicorn).
|
||||
|
||||
📥 🖼 🕐❔ 👈 💪 ⚒ 🔑:
|
||||
|
||||
@@ -514,14 +514,14 @@ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
|
||||
|
||||
## 🛂 ☁ 🖼 ⏮️ 🐁 - Uvicorn
|
||||
|
||||
📤 🛂 ☁ 🖼 👈 🔌 🐁 🏃♂ ⏮️ Uvicorn 👨🏭, ℹ ⏮️ 📃: [💽 👨🏭 - 🐁 ⏮️ Uvicorn](./server-workers.md){.internal-link target=_blank}.
|
||||
📤 🛂 ☁ 🖼 👈 🔌 🐁 🏃♂ ⏮️ Uvicorn 👨🏭, ℹ ⏮️ 📃: [💽 👨🏭 - 🐁 ⏮️ Uvicorn](server-workers.md){.internal-link target=_blank}.
|
||||
|
||||
👉 🖼 🔜 ⚠ ✴️ ⚠ 🔬 🔛: [📦 ⏮️ 💗 🛠️ & 🎁 💼](#containers-with-multiple-processes-and-special-cases).
|
||||
👉 🖼 🔜 ⚠ ✴️ ⚠ 🔬 🔛: [📦 ⏮️ 💗 🛠️ & 🎁 💼](#_18).
|
||||
|
||||
* <a href="https://github.com/tiangolo/uvicorn-gunicorn-fastapi-docker" class="external-link" target="_blank">tiangolo/uvicorn-🐁-fastapi</a>.
|
||||
|
||||
!!! warning
|
||||
📤 ↕ 🤞 👈 👆 **🚫** 💪 👉 🧢 🖼 ⚖️ 🙆 🎏 🎏 1️⃣, & 🔜 👻 📆 🏗 🖼 ⚪️➡️ 🖌 [🔬 🔛: 🏗 ☁ 🖼 FastAPI](#build-a-docker-image-for-fastapi).
|
||||
📤 ↕ 🤞 👈 👆 **🚫** 💪 👉 🧢 🖼 ⚖️ 🙆 🎏 🎏 1️⃣, & 🔜 👻 📆 🏗 🖼 ⚪️➡️ 🖌 [🔬 🔛: 🏗 ☁ 🖼 FastAPI](#fastapi).
|
||||
|
||||
👉 🖼 ✔️ **🚘-📳** 🛠️ 🔌 ⚒ **🔢 👨🏭 🛠️** ⚓️ 🔛 💽 🐚 💪.
|
||||
|
||||
@@ -574,9 +574,9 @@ COPY ./app /app/app
|
||||
|
||||
### 🕐❔ ⚙️
|
||||
|
||||
👆 🔜 🎲 **🚫** ⚙️ 👉 🛂 🧢 🖼 (⚖️ 🙆 🎏 🎏 1️⃣) 🚥 👆 ⚙️ **Kubernetes** (⚖️ 🎏) & 👆 ⏪ ⚒ **🧬** 🌑 🎚, ⏮️ 💗 **📦**. 📚 💼, 👆 👍 📆 **🏗 🖼 ⚪️➡️ 🖌** 🔬 🔛: [🏗 ☁ 🖼 FastAPI](#build-a-docker-image-for-fastapi).
|
||||
👆 🔜 🎲 **🚫** ⚙️ 👉 🛂 🧢 🖼 (⚖️ 🙆 🎏 🎏 1️⃣) 🚥 👆 ⚙️ **Kubernetes** (⚖️ 🎏) & 👆 ⏪ ⚒ **🧬** 🌑 🎚, ⏮️ 💗 **📦**. 📚 💼, 👆 👍 📆 **🏗 🖼 ⚪️➡️ 🖌** 🔬 🔛: [🏗 ☁ 🖼 FastAPI](#fastapi).
|
||||
|
||||
👉 🖼 🔜 ⚠ ✴️ 🎁 💼 🔬 🔛 [📦 ⏮️ 💗 🛠️ & 🎁 💼](#containers-with-multiple-processes-and-special-cases). 🖼, 🚥 👆 🈸 **🙅 🥃** 👈 ⚒ 🔢 🔢 🛠️ ⚓️ 🔛 💽 👷 👍, 👆 🚫 💚 😥 ⏮️ ❎ 🛠️ 🧬 🌑 🎚, & 👆 🚫 🏃 🌅 🌘 1️⃣ 📦 ⏮️ 👆 📱. ⚖️ 🚥 👆 🛠️ ⏮️ **☁ ✍**, 🏃 🔛 👁 💽, ♒️.
|
||||
👉 🖼 🔜 ⚠ ✴️ 🎁 💼 🔬 🔛 [📦 ⏮️ 💗 🛠️ & 🎁 💼](#_18). 🖼, 🚥 👆 🈸 **🙅 🥃** 👈 ⚒ 🔢 🔢 🛠️ ⚓️ 🔛 💽 👷 👍, 👆 🚫 💚 😥 ⏮️ ❎ 🛠️ 🧬 🌑 🎚, & 👆 🚫 🏃 🌅 🌘 1️⃣ 📦 ⏮️ 👆 📱. ⚖️ 🚥 👆 🛠️ ⏮️ **☁ ✍**, 🏃 🔛 👁 💽, ♒️.
|
||||
|
||||
## 🛠️ 📦 🖼
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@
|
||||
|
||||
🕐❔ 🛠️ 🈸 👆 🔜 🎲 💚 ✔️ **🧬 🛠️** ✊ 📈 **💗 🐚** & 💪 🍵 🌅 📨.
|
||||
|
||||
👆 👀 ⏮️ 📃 🔃 [🛠️ 🔧](./concepts.md){.internal-link target=_blank}, 📤 💗 🎛 👆 💪 ⚙️.
|
||||
👆 👀 ⏮️ 📃 🔃 [🛠️ 🔧](concepts.md){.internal-link target=_blank}, 📤 💗 🎛 👆 💪 ⚙️.
|
||||
|
||||
📥 👤 🔜 🎦 👆 ❔ ⚙️ <a href="https://gunicorn.org/" class="external-link" target="_blank">**🐁**</a> ⏮️ **Uvicorn 👨🏭 🛠️**.
|
||||
|
||||
!!! info
|
||||
🚥 👆 ⚙️ 📦, 🖼 ⏮️ ☁ ⚖️ Kubernetes, 👤 🔜 💬 👆 🌅 🔃 👈 ⏭ 📃: [FastAPI 📦 - ☁](./docker.md){.internal-link target=_blank}.
|
||||
🚥 👆 ⚙️ 📦, 🖼 ⏮️ ☁ ⚖️ Kubernetes, 👤 🔜 💬 👆 🌅 🔃 👈 ⏭ 📃: [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank}.
|
||||
|
||||
🎯, 🕐❔ 🏃 🔛 **Kubernetes** 👆 🔜 🎲 **🚫** 💚 ⚙️ 🐁 & ↩️ 🏃 **👁 Uvicorn 🛠️ 📍 📦**, ✋️ 👤 🔜 💬 👆 🔃 ⚫️ ⏪ 👈 📃.
|
||||
|
||||
@@ -163,7 +163,7 @@ $ uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4
|
||||
|
||||
## 📦 & ☁
|
||||
|
||||
⏭ 📃 🔃 [FastAPI 📦 - ☁](./docker.md){.internal-link target=_blank} 👤 🔜 💬 🎛 👆 💪 ⚙️ 🍵 🎏 **🛠️ 🔧**.
|
||||
⏭ 📃 🔃 [FastAPI 📦 - ☁](docker.md){.internal-link target=_blank} 👤 🔜 💬 🎛 👆 💪 ⚙️ 🍵 🎏 **🛠️ 🔧**.
|
||||
|
||||
👤 🔜 🎦 👆 **🛂 ☁ 🖼** 👈 🔌 **🐁 ⏮️ Uvicorn 👨🏭** & 🔢 📳 👈 💪 ⚠ 🙅 💼.
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# FastAPI 👫👫
|
||||
|
||||
FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
@@ -18,7 +23,7 @@ FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
👤 👼 & 🐛 **FastAPI**. 👆 💪 ✍ 🌅 🔃 👈 [ℹ FastAPI - 🤚 ℹ - 🔗 ⏮️ 📕](help-fastapi.md#connect-with-the-author){.internal-link target=_blank}.
|
||||
👤 👼 & 🐛 **FastAPI**. 👆 💪 ✍ 🌅 🔃 👈 [ℹ FastAPI - 🤚 ℹ - 🔗 ⏮️ 📕](help-fastapi.md#_3){.internal-link target=_blank}.
|
||||
|
||||
...✋️ 📥 👤 💚 🎦 👆 👪.
|
||||
|
||||
@@ -28,15 +33,15 @@ FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
|
||||
👫 👫👫 👈:
|
||||
|
||||
* [ℹ 🎏 ⏮️ ❔ 📂](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank}.
|
||||
* [✍ 🚲 📨](help-fastapi.md#create-a-pull-request){.internal-link target=_blank}.
|
||||
* 📄 🚲 📨, [✴️ ⚠ ✍](contributing.md#translations){.internal-link target=_blank}.
|
||||
* [ℹ 🎏 ⏮️ ❔ 📂](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#help-others-with-questions-in-github){.internal-link target=_blank} ⏮️ 🏁 🗓️. 👶
|
||||
👫 👩💻 👈 ✔️ [🤝 🎏 🏆 ⏮️ ❔ 📂](help-fastapi.md#i){.internal-link target=_blank} ⏮️ 🏁 🗓️. 👶
|
||||
|
||||
{% if people %}
|
||||
<div class="user-list user-list-center">
|
||||
@@ -52,7 +57,7 @@ FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
|
||||
📥 **FastAPI 🕴**. 👶
|
||||
|
||||
👫 👩💻 👈 ✔️ [ℹ 🎏 🏆 ⏮️ ❔ 📂](help-fastapi.md#help-others-with-questions-in-github){.internal-link target=_blank} 🔘 *🌐 🕰*.
|
||||
👫 👩💻 👈 ✔️ [ℹ 🎏 🏆 ⏮️ ❔ 📂](help-fastapi.md#i){.internal-link target=_blank} 🔘 *🌐 🕰*.
|
||||
|
||||
👫 ✔️ 🎦 🕴 🤝 📚 🎏. 👶
|
||||
|
||||
@@ -70,7 +75,7 @@ FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
|
||||
📥 **🔝 👨🔬**. 👶
|
||||
|
||||
👉 👩💻 ✔️ [✍ 🏆 🚲 📨](help-fastapi.md#create-a-pull-request){.internal-link target=_blank} 👈 ✔️ *🔗*.
|
||||
👉 👩💻 ✔️ [✍ 🏆 🚲 📨](help-fastapi.md#_15){.internal-link target=_blank} 👈 ✔️ *🔗*.
|
||||
|
||||
👫 ✔️ 📉 ℹ 📟, 🧾, ✍, ♒️. 👶
|
||||
|
||||
@@ -92,7 +97,7 @@ FastAPI ✔️ 🎆 👪 👈 🙋 👫👫 ⚪️➡️ 🌐 🖥.
|
||||
|
||||
### 📄 ✍
|
||||
|
||||
👤 🕴 💬 👩❤👨 🇪🇸 (& 🚫 📶 👍 👶). , 👨🔬 🕐 👈 ✔️ [**🏋️ ✔ ✍**](contributing.md#translations){.internal-link target=_blank} 🧾. 🍵 👫, 📤 🚫🔜 🧾 📚 🎏 🇪🇸.
|
||||
👤 🕴 💬 👩❤👨 🇪🇸 (& 🚫 📶 👍 👶). , 👨🔬 🕐 👈 ✔️ [**🏋️ ✔ ✍**](contributing.md#_9){.internal-link target=_blank} 🧾. 🍵 👫, 📤 🚫🔜 🧾 📚 🎏 🇪🇸.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
# ⚒
|
||||
|
||||
## FastAPI ⚒
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
📚 💼 👆 5️⃣📆 ⏪ 💭 ❔ 📚 ❔. 👶
|
||||
|
||||
🚥 👆 🤝 📚 👫👫 ⏮️ 👫 ❔, 👆 🔜 ▶️️ 🛂 [FastAPI 🕴](fastapi-people.md#experts){.internal-link target=_blank}. 👶
|
||||
🚥 👆 🤝 📚 👫👫 ⏮️ 👫 ❔, 👆 🔜 ▶️️ 🛂 [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}. 👶
|
||||
|
||||
💭, 🏆 ⚠ ☝: 🔄 😇. 👫👫 👟 ⏮️ 👫 😩 & 📚 💼 🚫 💭 🏆 🌌, ✋️ 🔄 🏆 👆 💪 😇. 👶
|
||||
|
||||
@@ -198,7 +198,7 @@
|
||||
* 🔧 🤭 👆 🔎 🔛 🧾.
|
||||
* 💰 📄, 📹, ⚖️ 📻 👆 ✍ ⚖️ 🔎 🔃 FastAPI <a href="https://github.com/tiangolo/fastapi/edit/master/docs/en/data/external_links.yml" class="external-link" target="_blank">✍ 👉 📁</a>.
|
||||
* ⚒ 💭 👆 🚮 👆 🔗 ▶️ 🔗 📄.
|
||||
* ℹ [💬 🧾](contributing.md#translations){.internal-link target=_blank} 👆 🇪🇸.
|
||||
* ℹ [💬 🧾](contributing.md#_9){.internal-link target=_blank} 👆 🇪🇸.
|
||||
* 👆 💪 ℹ 📄 ✍ ✍ 🎏.
|
||||
* 🛠️ 🆕 🧾 📄.
|
||||
* 🔧 ♻ ❔/🐛.
|
||||
@@ -215,8 +215,8 @@
|
||||
|
||||
👑 📋 👈 👆 💪 ▶️️ 🔜:
|
||||
|
||||
* [ℹ 🎏 ⏮️ ❔ 📂](#help-others-with-questions-in-github){.internal-link target=_blank} (👀 📄 🔛).
|
||||
* [📄 🚲 📨](#review-pull-requests){.internal-link target=_blank} (👀 📄 🔛).
|
||||
* [ℹ 🎏 ⏮️ ❔ 📂](#i){.internal-link target=_blank} (👀 📄 🔛).
|
||||
* [📄 🚲 📨](#i){.internal-link target=_blank} (👀 📄 🔛).
|
||||
|
||||
👈 2️⃣ 📋 ⚫️❔ **🍴 🕰 🏆**. 👈 👑 👷 🏆 FastAPI.
|
||||
|
||||
@@ -227,7 +227,7 @@
|
||||
🛑 👶 <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">😧 💬 💽</a> 👶 & 🤙 👅 ⏮️ 🎏 FastAPI 👪.
|
||||
|
||||
!!! tip
|
||||
❔, 💭 👫 <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">📂 💬</a>, 📤 🌅 👍 🤞 👆 🔜 📨 ℹ [FastAPI 🕴](fastapi-people.md#experts){.internal-link target=_blank}.
|
||||
❔, 💭 👫 <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">📂 💬</a>, 📤 🌅 👍 🤞 👆 🔜 📨 ℹ [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}.
|
||||
|
||||
⚙️ 💬 🕴 🎏 🏢 💬.
|
||||
|
||||
@@ -237,7 +237,7 @@
|
||||
|
||||
📂, 📄 🔜 🦮 👆 ✍ ▶️️ ❔ 👈 👆 💪 🌖 💪 🤚 👍 ❔, ⚖️ ❎ ⚠ 👆 ⏭ 💬. & 📂 👤 💪 ⚒ 💭 👤 🕧 ❔ 🌐, 🚥 ⚫️ ✊ 🕰. 👤 💪 🚫 🤙 👈 ⏮️ 💬 ⚙️. 👶
|
||||
|
||||
💬 💬 ⚙️ 🚫 💪 📇 📂, ❔ & ❔ 5️⃣📆 🤚 💸 💬. & 🕴 🕐 📂 💯 ▶️️ [FastAPI 🕴](fastapi-people.md#experts){.internal-link target=_blank}, 👆 🔜 🌅 🎲 📨 🌅 🙋 📂.
|
||||
💬 💬 ⚙️ 🚫 💪 📇 📂, ❔ & ❔ 5️⃣📆 🤚 💸 💬. & 🕴 🕐 📂 💯 ▶️️ [FastAPI 🕴](fastapi-people.md#_2){.internal-link target=_blank}, 👆 🔜 🌅 🎲 📨 🌅 🙋 📂.
|
||||
|
||||
🔛 🎏 🚄, 📤 💯 👩💻 💬 ⚙️, 📤 ↕ 🤞 👆 🔜 🔎 👱 💬 📤, 🌖 🌐 🕰. 👶
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
### ✍ 🛃 `GzipRequest` 🎓
|
||||
|
||||
!!! tip
|
||||
👉 🧸 🖼 🎦 ❔ ⚫️ 👷, 🚥 👆 💪 🗜 🐕🦺, 👆 💪 ⚙️ 🚚 [`GzipMiddleware`](./middleware.md#gzipmiddleware){.internal-link target=_blank}.
|
||||
👉 🧸 🖼 🎦 ❔ ⚫️ 👷, 🚥 👆 💪 🗜 🐕🦺, 👆 💪 ⚙️ 🚚 [`GzipMiddleware`](../advanced/middleware.md#gzipmiddleware){.internal-link target=_blank}.
|
||||
|
||||
🥇, 👥 ✍ `GzipRequest` 🎓, ❔ 🔜 📁 `Request.body()` 👩🔬 🗜 💪 🔍 ☑ 🎚.
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
## 🔐 📨 💪 ⚠ 🐕🦺
|
||||
|
||||
!!! tip
|
||||
❎ 👉 🎏 ⚠, ⚫️ 🎲 📚 ⏩ ⚙️ `body` 🛃 🐕🦺 `RequestValidationError` ([🚚 ❌](../tutorial/handling-errors.md#use-the-requestvalidationerror-body){.internal-link target=_blank}).
|
||||
❎ 👉 🎏 ⚠, ⚫️ 🎲 📚 ⏩ ⚙️ `body` 🛃 🐕🦺 `RequestValidationError` ([🚚 ❌](../tutorial/handling-errors.md#requestvalidationerror){.internal-link target=_blank}).
|
||||
|
||||
✋️ 👉 🖼 ☑ & ⚫️ 🎦 ❔ 🔗 ⏮️ 🔗 🦲.
|
||||
|
||||
|
||||
@@ -86,7 +86,7 @@ connect_args={"check_same_thread": False}
|
||||
|
||||
!!! info "📡 ℹ"
|
||||
|
||||
⚫️❔ 🎏 📡 ℹ [🗄 (🔗) 💽](../tutorial/sql-databases.md#note){.internal-link target=_blank} ✔.
|
||||
⚫️❔ 🎏 📡 ℹ [🗄 (🔗) 💽](../tutorial/sql-databases.md#_7){.internal-link target=_blank} ✔.
|
||||
|
||||
### ⚒ 🏒 🔁-🔗 `PeeweeConnectionState`
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
<style>
|
||||
.md-content .md-typeset h1 { display: none; }
|
||||
</style>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
|
||||
</p>
|
||||
@@ -31,7 +40,7 @@ FastAPI 🏛, ⏩ (↕-🎭), 🕸 🛠️ 🏗 🛠️ ⏮️ 🐍 3️⃣.8️
|
||||
|
||||
🔑 ⚒:
|
||||
|
||||
* **⏩**: 📶 ↕ 🎭, 🔛 🇷🇪 ⏮️ **✳** & **🚶** (👏 💃 & Pydantic). [1️⃣ ⏩ 🐍 🛠️ 💪](#performance).
|
||||
* **⏩**: 📶 ↕ 🎭, 🔛 🇷🇪 ⏮️ **✳** & **🚶** (👏 💃 & Pydantic). [1️⃣ ⏩ 🐍 🛠️ 💪](#_15).
|
||||
* **⏩ 📟**: 📈 🚅 🛠️ ⚒ 🔃 2️⃣0️⃣0️⃣ 💯 3️⃣0️⃣0️⃣ 💯. *
|
||||
* **👩❤👨 🐛**: 📉 🔃 4️⃣0️⃣ 💯 🗿 (👩💻) 📉 ❌. *
|
||||
* **🏋️**: 👑 👨🎨 🐕🦺. <abbr title="also known as auto-complete, autocompletion, IntelliSense">🛠️</abbr> 🌐. 🌘 🕰 🛠️.
|
||||
@@ -445,7 +454,6 @@ item: Item
|
||||
|
||||
⚙️ Pydantic:
|
||||
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - ⏩ 🎻 <abbr title="converting the string that comes from an HTTP request into Python data">"🎻"</abbr>.
|
||||
* <a href="https://github.com/JoshData/python-email-validator" target="_blank"><code>email_validator</code></a> - 📧 🔬.
|
||||
|
||||
⚙️ 💃:
|
||||
@@ -455,12 +463,12 @@ item: Item
|
||||
* <a href="https://github.com/Kludex/python-multipart" target="_blank"><code>python-multipart</code></a> - ✔ 🚥 👆 💚 🐕🦺 📨 <abbr title="converting the string that comes from an HTTP request into Python data">"✍"</abbr>, ⏮️ `request.form()`.
|
||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - ✔ `SessionMiddleware` 🐕🦺.
|
||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - ✔ 💃 `SchemaGenerator` 🐕🦺 (👆 🎲 🚫 💪 ⚫️ ⏮️ FastAPI).
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - ✔ 🚥 👆 💚 ⚙️ `UJSONResponse`.
|
||||
|
||||
⚙️ FastAPI / 💃:
|
||||
|
||||
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - 💽 👈 📐 & 🍦 👆 🈸.
|
||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - ✔ 🚥 👆 💚 ⚙️ `ORJSONResponse`.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - ✔ 🚥 👆 💚 ⚙️ `UJSONResponse`.
|
||||
|
||||
👆 💪 ❎ 🌐 👫 ⏮️ `pip install "fastapi[all]"`.
|
||||
|
||||
|
||||
@@ -168,7 +168,7 @@ John Doe
|
||||
|
||||
⚪️➡️ `typing`, 🗄 `List` (⏮️ 🔠 `L`):
|
||||
|
||||
``` Python hl_lines="1"
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial006.py!}
|
||||
```
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@
|
||||
!!! tip
|
||||
👥 ⚙️ 💭 🎚 📉 👉 🖼.
|
||||
|
||||
✋️ 🎰 💼 👆 🔜 🤚 👍 🏁 ⚙️ 🛠️ [💂♂ 🚙](./security/index.md){.internal-link target=_blank}.
|
||||
✋️ 🎰 💼 👆 🔜 🤚 👍 🏁 ⚙️ 🛠️ [💂♂ 🚙](security/index.md){.internal-link target=_blank}.
|
||||
|
||||
## ➕1️⃣ 🕹 ⏮️ `APIRouter`
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
|
||||
👉 ⛓ 👈 👆 💪 📨 🕴 💽 👈 👆 💚 ℹ, 🍂 🎂 🐣.
|
||||
|
||||
!!! Note
|
||||
!!! note
|
||||
`PATCH` 🌘 🛎 ⚙️ & 💭 🌘 `PUT`.
|
||||
|
||||
& 📚 🏉 ⚙️ 🕴 `PUT`, 🍕 ℹ.
|
||||
|
||||
@@ -210,4 +210,4 @@
|
||||
|
||||
## 🍵 Pydantic
|
||||
|
||||
🚥 👆 🚫 💚 ⚙️ Pydantic 🏷, 👆 💪 ⚙️ **💪** 🔢. 👀 🩺 [💪 - 💗 🔢: ⭐ 💲 💪](body-multiple-params.md#singular-values-in-body){.internal-link target=_blank}.
|
||||
🚥 👆 🚫 💚 ⚙️ Pydantic 🏷, 👆 💪 ⚙️ **💪** 🔢. 👀 🩺 [💪 - 💗 🔢: ⭐ 💲 💪](body-multiple-params.md#_2){.internal-link target=_blank}.
|
||||
|
||||
@@ -99,7 +99,7 @@ FastAPI 🐕🦺 🔗 👈 <abbr title='sometimes also called "exit", "cleanu
|
||||
|
||||
⚫️ 5️⃣📆 😋 🤚 `HTTPException` ⚖️ 🎏 🚪 📟, ⏮️ `yield`. ✋️ **⚫️ 🏆 🚫 👷**.
|
||||
|
||||
🚪 📟 🔗 ⏮️ `yield` 🛠️ *⏮️* 📨 📨, [⚠ 🐕🦺](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank} 🔜 ✔️ ⏪ 🏃. 📤 🕳 😽 ⚠ 🚮 👆 🔗 🚪 📟 (⏮️ `yield`).
|
||||
🚪 📟 🔗 ⏮️ `yield` 🛠️ *⏮️* 📨 📨, [⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank} 🔜 ✔️ ⏪ 🏃. 📤 🕳 😽 ⚠ 🚮 👆 🔗 🚪 📟 (⏮️ `yield`).
|
||||
|
||||
, 🚥 👆 🤚 `HTTPException` ⏮️ `yield`, 🔢 (⚖️ 🙆 🛃) ⚠ 🐕🦺 👈 ✊ `HTTPException`Ⓜ & 📨 🇺🇸🔍 4️⃣0️⃣0️⃣ 📨 🏆 🚫 📤 ✊ 👈 ⚠ 🚫🔜.
|
||||
|
||||
@@ -111,7 +111,7 @@ FastAPI 🐕🦺 🔗 👈 <abbr title='sometimes also called "exit", "cleanu
|
||||
|
||||
🚥 👆 ✔️ 📟 👈 👆 💭 💪 🤚 ⚠, 🏆 😐/"🙃" 👜 & 🚮 `try` 🍫 👈 📄 📟.
|
||||
|
||||
🚥 👆 ✔️ 🛃 ⚠ 👈 👆 🔜 💖 🍵 *⏭* 🛬 📨 & 🎲 ❎ 📨, 🎲 🙋♀ `HTTPException`, ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}.
|
||||
🚥 👆 ✔️ 🛃 ⚠ 👈 👆 🔜 💖 🍵 *⏭* 🛬 📨 & 🎲 ❎ 📨, 🎲 🙋♀ `HTTPException`, ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank}.
|
||||
|
||||
!!! tip
|
||||
👆 💪 🤚 ⚠ 🔌 `HTTPException` *⏭* `yield`. ✋️ 🚫 ⏮️.
|
||||
@@ -164,7 +164,7 @@ participant tasks as Background tasks
|
||||
⏮️ 1️⃣ 📚 📨 📨, 🙅♂ 🎏 📨 💪 📨.
|
||||
|
||||
!!! tip
|
||||
👉 📊 🎦 `HTTPException`, ✋️ 👆 💪 🤚 🙆 🎏 ⚠ ❔ 👆 ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}.
|
||||
👉 📊 🎦 `HTTPException`, ✋️ 👆 💪 🤚 🙆 🎏 ⚠ ❔ 👆 ✍ [🛃 ⚠ 🐕🦺](../handling-errors.md#_4){.internal-link target=_blank}.
|
||||
|
||||
🚥 👆 🤚 🙆 ⚠, ⚫️ 🔜 🚶♀️ 🔗 ⏮️ 🌾, 🔌 `HTTPException`, & ⤴️ **🔄** ⚠ 🐕🦺. 🚥 📤 🙅♂ ⚠ 🐕🦺 👈 ⚠, ⚫️ 🔜 ⤴️ 🍵 🔢 🔗 `ServerErrorMiddleware`, 🛬 5️⃣0️⃣0️⃣ 🇺🇸🔍 👔 📟, ➡️ 👩💻 💭 👈 📤 ❌ 💽.
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
!!! danger
|
||||
🙅 🏪 👩💻 🔢 🔐. 🕧 🏪 "🔐 #️⃣" 👈 👆 💪 ⤴️ ✔.
|
||||
|
||||
🚥 👆 🚫 💭, 👆 🔜 💡 ⚫️❔ "🔐#️⃣" [💂♂ 📃](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}.
|
||||
🚥 👆 🚫 💭, 👆 🔜 💡 ⚫️❔ "🔐#️⃣" [💂♂ 📃](security/simple-oauth2.md#_4){.internal-link target=_blank}.
|
||||
|
||||
## 💗 🏷
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ https://example.com/items/foo
|
||||
```
|
||||
|
||||
!!! note
|
||||
🚥 👆 🚫 💭 🔺, ✅ [🔁: *"🏃 ❓"*](../async.md#in-a-hurry){.internal-link target=_blank}.
|
||||
🚥 👆 🚫 💭 🔺, ✅ [🔁: *"🏃 ❓"*](../async.md#_2){.internal-link target=_blank}.
|
||||
|
||||
### 🔁 5️⃣: 📨 🎚
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@
|
||||
```
|
||||
|
||||
!!! info
|
||||
✍ 🌅 🔃 🔖 [➡ 🛠️ 📳](path-operation-configuration.md#tags){.internal-link target=_blank}.
|
||||
✍ 🌅 🔃 🔖 [➡ 🛠️ 📳](path-operation-configuration.md#_3){.internal-link target=_blank}.
|
||||
|
||||
### ✅ 🩺
|
||||
|
||||
|
||||
@@ -222,4 +222,4 @@ http://127.0.0.1:8000/items/foo-item?needy=sooooneedy
|
||||
* `limit`, 📦 `int`.
|
||||
|
||||
!!! tip
|
||||
👆 💪 ⚙️ `Enum`Ⓜ 🎏 🌌 ⏮️ [➡ 🔢](path-params.md#predefined-values){.internal-link target=_blank}.
|
||||
👆 💪 ⚙️ `Enum`Ⓜ 🎏 🌌 ⏮️ [➡ 🔢](path-params.md#_7){.internal-link target=_blank}.
|
||||
|
||||
@@ -163,7 +163,7 @@ UserInDB(
|
||||
```
|
||||
|
||||
!!! info
|
||||
🌅 🏁 🔑 `**👩💻_ #️⃣ ` ✅ 🔙 [🧾 **➕ 🏷**](../extra-models.md#about-user_indict){.internal-link target=_blank}.
|
||||
🌅 🏁 🔑 `**👩💻_ #️⃣ ` ✅ 🔙 [🧾 **➕ 🏷**](../extra-models.md#user_indict){.internal-link target=_blank}.
|
||||
|
||||
## 📨 🤝
|
||||
|
||||
|
||||
@@ -534,7 +534,7 @@ current_user.items
|
||||
|
||||
👉 🌌 👥 ⚒ 💭 💽 🎉 🕧 📪 ⏮️ 📨. 🚥 📤 ⚠ ⏪ 🏭 📨.
|
||||
|
||||
✋️ 👆 💪 🚫 🤚 ➕1️⃣ ⚠ ⚪️➡️ 🚪 📟 (⏮️ `yield`). 👀 🌖 [🔗 ⏮️ `yield` & `HTTPException`](./dependencies/dependencies-with-yield.md#dependencies-with-yield-and-httpexception){.internal-link target=_blank}
|
||||
✋️ 👆 💪 🚫 🤚 ➕1️⃣ ⚠ ⚪️➡️ 🚪 📟 (⏮️ `yield`). 👀 🌖 [🔗 ⏮️ `yield` & `HTTPException`](dependencies/dependencies-with-yield.md#yield-httpexception){.internal-link target=_blank}
|
||||
|
||||
& ⤴️, 🕐❔ ⚙️ 🔗 *➡ 🛠️ 🔢*, 👥 📣 ⚫️ ⏮️ 🆎 `Session` 👥 🗄 🔗 ⚪️➡️ 🇸🇲.
|
||||
|
||||
@@ -620,7 +620,7 @@ def read_user(user_id: int, db: Session = Depends(get_db)):
|
||||
🚥 👆 💪 🔗 👆 🔗 💽 🔁, 👀 [🔁 🗄 (🔗) 💽](../advanced/async-sql-databases.md){.internal-link target=_blank}.
|
||||
|
||||
!!! note "📶 📡 ℹ"
|
||||
🚥 👆 😟 & ✔️ ⏬ 📡 💡, 👆 💪 ✅ 📶 📡 ℹ ❔ 👉 `async def` 🆚 `def` 🍵 [🔁](../async.md#very-technical-details){.internal-link target=_blank} 🩺.
|
||||
🚥 👆 😟 & ✔️ ⏬ 📡 💡, 👆 💪 ✅ 📶 📡 ℹ ❔ 👉 `async def` 🆚 `def` 🍵 [🔁](../async.md#i_2){.internal-link target=_blank} 🩺.
|
||||
|
||||
## 🛠️
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@
|
||||
|
||||
### **FastAPI** 📱 📁
|
||||
|
||||
➡️ 💬 👆 ✔️ 📁 📊 🔬 [🦏 🈸](./bigger-applications.md){.internal-link target=_blank}:
|
||||
➡️ 💬 👆 ✔️ 📁 📊 🔬 [🦏 🈸](bigger-applications.md){.internal-link target=_blank}:
|
||||
|
||||
```
|
||||
.
|
||||
|
||||
@@ -345,6 +345,6 @@ and then it won't include it in the OpenAPI schema.
|
||||
|
||||
## Mounting a sub-application
|
||||
|
||||
If you need to mount a sub-application (as described in [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}) while also using a proxy with `root_path`, you can do it normally, as you would expect.
|
||||
If you need to mount a sub-application (as described in [Sub Applications - Mounts](sub-applications.md){.internal-link target=_blank}) while also using a proxy with `root_path`, you can do it normally, as you would expect.
|
||||
|
||||
FastAPI will internally use the `root_path` smartly, so it will just work. ✨
|
||||
|
||||
@@ -23,7 +23,7 @@ Import the `Response` class (sub-class) you want to use and declare it in the *p
|
||||
|
||||
For large responses, returning a `Response` directly is much faster than returning a dictionary.
|
||||
|
||||
This is because by default, FastAPI will inspect every item inside and make sure it is serializable with JSON, using the same [JSON Compatible Encoder](../tutorial/encoder.md){.internal-link target=_blank} explained in the tutorial. This is what allows you to return **arbitrary objects**, for example database models.
|
||||
This is because by default, FastAPI will inspect every item inside and make sure it is serializable as JSON, using the same [JSON Compatible Encoder](../tutorial/encoder.md){.internal-link target=_blank} explained in the tutorial. This is what allows you to return **arbitrary objects**, for example database models.
|
||||
|
||||
But if you are certain that the content that you are returning is **serializable with JSON**, you can pass it directly to the response class and avoid the extra overhead that FastAPI would have by passing your return content through the `jsonable_encoder` before passing it to the response class.
|
||||
|
||||
@@ -73,7 +73,7 @@ The same example from above, returning an `HTMLResponse`, could look like:
|
||||
A `Response` returned directly by your *path operation function* won't be documented in OpenAPI (for example, the `Content-Type` won't be documented) and won't be visible in the automatic interactive docs.
|
||||
|
||||
!!! info
|
||||
Of course, the actual `Content-Type` header, status code, etc, will come from the `Response` object your returned.
|
||||
Of course, the actual `Content-Type` header, status code, etc, will come from the `Response` object you returned.
|
||||
|
||||
### Document in OpenAPI and override `Response`
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ In that case, you can simply swap the standard `dataclasses` with `pydantic.data
|
||||
|
||||
As always, in FastAPI you can combine `def` and `async def` as needed.
|
||||
|
||||
If you need a refresher about when to use which, check out the section _"In a hurry?"_ in the docs about <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank" class="internal-link">`async` and `await`</a>.
|
||||
If you need a refresher about when to use which, check out the section _"In a hurry?"_ in the docs about [`async` and `await`](../async.md#in-a-hurry){.internal-link target=_blank}.
|
||||
|
||||
9. This *path operation function* is not returning dataclasses (although it could), but a list of dictionaries with internal data.
|
||||
|
||||
|
||||
@@ -159,4 +159,4 @@ Underneath, in the ASGI technical specification, this is part of the <a href="ht
|
||||
|
||||
## Sub Applications
|
||||
|
||||
🚨 Keep in mind that these lifespan events (startup and shutdown) will only be executed for the main application, not for [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}.
|
||||
🚨 Keep in mind that these lifespan events (startup and shutdown) will only be executed for the main application, not for [Sub Applications - Mounts](sub-applications.md){.internal-link target=_blank}.
|
||||
|
||||
@@ -10,7 +10,7 @@ There are many tools to generate clients from **OpenAPI**.
|
||||
|
||||
A common tool is <a href="https://openapi-generator.tech/" class="external-link" target="_blank">OpenAPI Generator</a>.
|
||||
|
||||
If you are building a **frontend**, a very interesting alternative is <a href="https://github.com/ferdikoomen/openapi-typescript-codegen" class="external-link" target="_blank">openapi-typescript-codegen</a>.
|
||||
If you are building a **frontend**, a very interesting alternative is <a href="https://github.com/hey-api/openapi-ts" class="external-link" target="_blank">openapi-ts</a>.
|
||||
|
||||
## Client and SDK Generators - Sponsor
|
||||
|
||||
@@ -58,14 +58,14 @@ And that same information from the models that is included in OpenAPI is what ca
|
||||
|
||||
Now that we have the app with the models, we can generate the client code for the frontend.
|
||||
|
||||
#### Install `openapi-typescript-codegen`
|
||||
#### Install `openapi-ts`
|
||||
|
||||
You can install `openapi-typescript-codegen` in your frontend code with:
|
||||
You can install `openapi-ts` in your frontend code with:
|
||||
|
||||
<div class="termy">
|
||||
|
||||
```console
|
||||
$ npm install openapi-typescript-codegen --save-dev
|
||||
$ npm install @hey-api/openapi-ts --save-dev
|
||||
|
||||
---> 100%
|
||||
```
|
||||
@@ -74,7 +74,7 @@ $ npm install openapi-typescript-codegen --save-dev
|
||||
|
||||
#### Generate Client Code
|
||||
|
||||
To generate the client code you can use the command line application `openapi` that would now be installed.
|
||||
To generate the client code you can use the command line application `openapi-ts` that would now be installed.
|
||||
|
||||
Because it is installed in the local project, you probably wouldn't be able to call that command directly, but you would put it on your `package.json` file.
|
||||
|
||||
@@ -87,12 +87,12 @@ It could look like this:
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes"
|
||||
"generate-client": "openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ After having that NPM `generate-client` script there, you can run it with:
|
||||
$ npm run generate-client
|
||||
|
||||
frontend-app@1.0.0 generate-client /home/user/code/frontend-app
|
||||
> openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes
|
||||
> openapi-ts --input http://localhost:8000/openapi.json --output ./src/client --client axios
|
||||
```
|
||||
|
||||
</div>
|
||||
@@ -237,7 +237,7 @@ We could download the OpenAPI JSON to a file `openapi.json` and then we could **
|
||||
|
||||
=== "Node.js"
|
||||
|
||||
```Python
|
||||
```Javascript
|
||||
{!> ../../../docs_src/generate_clients/tutorial004.js!}
|
||||
```
|
||||
|
||||
@@ -254,12 +254,12 @@ Now as the end result is in a file `openapi.json`, you would modify the `package
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"generate-client": "openapi --input ./openapi.json --output ./src/client --client axios --useOptions --useUnionTypes"
|
||||
"generate-client": "openapi-ts --input ./openapi.json --output ./src/client --client axios"
|
||||
},
|
||||
"author": "",
|
||||
"license": "",
|
||||
"devDependencies": {
|
||||
"openapi-typescript-codegen": "^0.20.1",
|
||||
"@hey-api/openapi-ts": "^0.27.38",
|
||||
"typescript": "^4.6.2"
|
||||
}
|
||||
}
|
||||
@@ -271,7 +271,7 @@ After generating the new client, you would now have **clean method names**, with
|
||||
|
||||
## Benefits
|
||||
|
||||
When using the automatically generated clients you would **autocompletion** for:
|
||||
When using the automatically generated clients you would get **autocompletion** for:
|
||||
|
||||
* Methods.
|
||||
* Request payloads in the body, query parameters, etc.
|
||||
|
||||
@@ -131,7 +131,7 @@ with a JSON body of:
|
||||
}
|
||||
```
|
||||
|
||||
Then *your API* will process the invoice, and at some point later, send a callback request to the `callback_url` (the *external API*):
|
||||
then *your API* will process the invoice, and at some point later, send a callback request to the `callback_url` (the *external API*):
|
||||
|
||||
```
|
||||
https://www.external.org/events/invoices/2expen51ve
|
||||
@@ -174,6 +174,6 @@ Now use the parameter `callbacks` in *your API's path operation decorator* to pa
|
||||
|
||||
Now you can start your app with Uvicorn and go to <a href="http://127.0.0.1:8000/docs" class="external-link" target="_blank">http://127.0.0.1:8000/docs</a>.
|
||||
|
||||
You will see your docs including a "Callback" section for your *path operation* that shows how the *external API* should look like:
|
||||
You will see your docs including a "Callbacks" section for your *path operation* that shows how the *external API* should look like:
|
||||
|
||||
<img src="/img/tutorial/openapi-callbacks/image01.png">
|
||||
|
||||
@@ -59,7 +59,7 @@ That defines the metadata about the main response of a *path operation*.
|
||||
|
||||
You can also declare additional responses with their models, status codes, etc.
|
||||
|
||||
There's a whole chapter here in the documentation about it, you can read it at [Additional Responses in OpenAPI](./additional-responses.md){.internal-link target=_blank}.
|
||||
There's a whole chapter here in the documentation about it, you can read it at [Additional Responses in OpenAPI](additional-responses.md){.internal-link target=_blank}.
|
||||
|
||||
## OpenAPI Extra
|
||||
|
||||
@@ -77,7 +77,7 @@ This *path operation*-specific OpenAPI schema is normally generated automaticall
|
||||
!!! tip
|
||||
This is a low level extension point.
|
||||
|
||||
If you only need to declare additional responses, a more convenient way to do it is with [Additional Responses in OpenAPI](./additional-responses.md){.internal-link target=_blank}.
|
||||
If you only need to declare additional responses, a more convenient way to do it is with [Additional Responses in OpenAPI](additional-responses.md){.internal-link target=_blank}.
|
||||
|
||||
You can extend the OpenAPI schema for a *path operation* using the parameter `openapi_extra`.
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ And then use it in a file `main.py`:
|
||||
```
|
||||
|
||||
!!! tip
|
||||
You would also need a file `__init__.py` as you saw on [Bigger Applications - Multiple Files](../tutorial/bigger-applications.md){.internal-link target=_blank}.
|
||||
You would also need a file `__init__.py` as you saw in [Bigger Applications - Multiple Files](../tutorial/bigger-applications.md){.internal-link target=_blank}.
|
||||
|
||||
## Settings in a dependency
|
||||
|
||||
|
||||
@@ -70,4 +70,4 @@ That way, the sub-application will know to use that path prefix for the docs UI.
|
||||
|
||||
And the sub-application could also have its own mounted sub-applications and everything would work correctly, because FastAPI handles all these `root_path`s automatically.
|
||||
|
||||
You will learn more about the `root_path` and how to use it explicitly in the section about [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank}.
|
||||
You will learn more about the `root_path` and how to use it explicitly in the section about [Behind a Proxy](behind-a-proxy.md){.internal-link target=_blank}.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Including WSGI - Flask, Django, others
|
||||
|
||||
You can mount WSGI applications as you saw with [Sub Applications - Mounts](./sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](./behind-a-proxy.md){.internal-link target=_blank}.
|
||||
You can mount WSGI applications as you saw with [Sub Applications - Mounts](sub-applications.md){.internal-link target=_blank}, [Behind a Proxy](behind-a-proxy.md){.internal-link target=_blank}.
|
||||
|
||||
For that, you can use the `WSGIMiddleware` and use it to wrap your WSGI application, for example, Flask, Django, etc.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Alternatives, Inspiration and Comparisons
|
||||
|
||||
What inspired **FastAPI**, how it compares to other alternatives and what it learned from them.
|
||||
What inspired **FastAPI**, how it compares to alternatives and what it learned from them.
|
||||
|
||||
## Intro
|
||||
|
||||
@@ -117,7 +117,7 @@ That's why when talking about version 2.0 it's common to say "Swagger", and for
|
||||
* <a href="https://github.com/swagger-api/swagger-ui" class="external-link" target="_blank">Swagger UI</a>
|
||||
* <a href="https://github.com/Rebilly/ReDoc" class="external-link" target="_blank">ReDoc</a>
|
||||
|
||||
These two were chosen for being fairly popular and stable, but doing a quick search, you could find dozens of additional alternative user interfaces for OpenAPI (that you can use with **FastAPI**).
|
||||
These two were chosen for being fairly popular and stable, but doing a quick search, you could find dozens of alternative user interfaces for OpenAPI (that you can use with **FastAPI**).
|
||||
|
||||
### Flask REST frameworks
|
||||
|
||||
@@ -291,7 +291,7 @@ As it is based on the previous standard for synchronous Python web frameworks (W
|
||||
!!! info
|
||||
Hug was created by Timothy Crosley, the same creator of <a href="https://github.com/timothycrosley/isort" class="external-link" target="_blank">`isort`</a>, a great tool to automatically sort imports in Python files.
|
||||
|
||||
!!! check "Ideas inspired in **FastAPI**"
|
||||
!!! check "Ideas inspiring **FastAPI**"
|
||||
Hug inspired parts of APIStar, and was one of the tools I found most promising, alongside APIStar.
|
||||
|
||||
Hug helped inspiring **FastAPI** to use Python type hints to declare parameters, and to generate a schema defining the API automatically.
|
||||
|
||||
@@ -397,7 +397,7 @@ All that is what powers FastAPI (through Starlette) and what makes it have such
|
||||
|
||||
These are very technical details of how **FastAPI** works underneath.
|
||||
|
||||
If you have quite some technical knowledge (co-routines, threads, blocking, etc.) and are curious about how FastAPI handles `async def` vs normal `def`, go ahead.
|
||||
If you have quite some technical knowledge (coroutines, threads, blocking, etc.) and are curious about how FastAPI handles `async def` vs normal `def`, go ahead.
|
||||
|
||||
### Path operation functions
|
||||
|
||||
@@ -409,11 +409,11 @@ Still, in both situations, chances are that **FastAPI** will [still be faster](i
|
||||
|
||||
### Dependencies
|
||||
|
||||
The same applies for [dependencies](./tutorial/dependencies/index.md){.internal-link target=_blank}. If a dependency is a standard `def` function instead of `async def`, it is run in the external threadpool.
|
||||
The same applies for [dependencies](tutorial/dependencies/index.md){.internal-link target=_blank}. If a dependency is a standard `def` function instead of `async def`, it is run in the external threadpool.
|
||||
|
||||
### Sub-dependencies
|
||||
|
||||
You can have multiple dependencies and [sub-dependencies](./tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} requiring each other (as parameters of the function definitions), some of them might be created with `async def` and some with normal `def`. It would still work, and the ones created with normal `def` would be called on an external thread (from the threadpool) instead of being "awaited".
|
||||
You can have multiple dependencies and [sub-dependencies](tutorial/dependencies/sub-dependencies.md){.internal-link target=_blank} requiring each other (as parameters of the function definitions), some of them might be created with `async def` and some with normal `def`. It would still work, and the ones created with normal `def` would be called on an external thread (from the threadpool) instead of being "awaited".
|
||||
|
||||
### Other utility functions
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Benchmarks
|
||||
|
||||
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">one of the fastest Python frameworks available</a>, only below Starlette and Uvicorn themselves (used internally by FastAPI). (*)
|
||||
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as <a href="https://www.techempower.com/benchmarks/#section=test&runid=7464e520-0dc2-473d-bd34-dbdfd7e85911&hw=ph&test=query&l=zijzen-7" class="external-link" target="_blank">one of the fastest Python frameworks available</a>, only below Starlette and Uvicorn themselves (used internally by FastAPI).
|
||||
|
||||
But when checking benchmarks and comparisons you should keep the following in mind.
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ But for now, let's check these important **conceptual ideas**. These concepts al
|
||||
|
||||
## Security - HTTPS
|
||||
|
||||
In the [previous chapter about HTTPS](./https.md){.internal-link target=_blank} we learned about how HTTPS provides encryption for your API.
|
||||
In the [previous chapter about HTTPS](https.md){.internal-link target=_blank} we learned about how HTTPS provides encryption for your API.
|
||||
|
||||
We also saw that HTTPS is normally provided by a component **external** to your application server, a **TLS Termination Proxy**.
|
||||
|
||||
@@ -187,7 +187,7 @@ When you run **multiple processes** of the same API program, they are commonly c
|
||||
|
||||
### Worker Processes and Ports
|
||||
|
||||
Remember from the docs [About HTTPS](./https.md){.internal-link target=_blank} that only one process can be listening on one combination of port and IP address in a server?
|
||||
Remember from the docs [About HTTPS](https.md){.internal-link target=_blank} that only one process can be listening on one combination of port and IP address in a server?
|
||||
|
||||
This is still true.
|
||||
|
||||
@@ -230,18 +230,18 @@ The main constraint to consider is that there has to be a **single** component h
|
||||
Here are some possible combinations and strategies:
|
||||
|
||||
* **Gunicorn** managing **Uvicorn workers**
|
||||
* Gunicorn would be the **process manager** listening on the **IP** and **port**, the replication would be by having **multiple Uvicorn worker processes**
|
||||
* Gunicorn would be the **process manager** listening on the **IP** and **port**, the replication would be by having **multiple Uvicorn worker processes**.
|
||||
* **Uvicorn** managing **Uvicorn workers**
|
||||
* One Uvicorn **process manager** would listen on the **IP** and **port**, and it would start **multiple Uvicorn worker processes**
|
||||
* One Uvicorn **process manager** would listen on the **IP** and **port**, and it would start **multiple Uvicorn worker processes**.
|
||||
* **Kubernetes** and other distributed **container systems**
|
||||
* Something in the **Kubernetes** layer would listen on the **IP** and **port**. The replication would be by having **multiple containers**, each with **one Uvicorn process** running
|
||||
* Something in the **Kubernetes** layer would listen on the **IP** and **port**. The replication would be by having **multiple containers**, each with **one Uvicorn process** running.
|
||||
* **Cloud services** that handle this for you
|
||||
* The cloud service will probably **handle replication for you**. It would possibly let you define **a process to run**, or a **container image** to use, in any case, it would most probably be **a single Uvicorn process**, and the cloud service would be in charge of replicating it.
|
||||
|
||||
!!! tip
|
||||
Don't worry if some of these items about **containers**, Docker, or Kubernetes don't make a lot of sense yet.
|
||||
|
||||
I'll tell you more about container images, Docker, Kubernetes, etc. in a future chapter: [FastAPI in Containers - Docker](./docker.md){.internal-link target=_blank}.
|
||||
I'll tell you more about container images, Docker, Kubernetes, etc. in a future chapter: [FastAPI in Containers - Docker](docker.md){.internal-link target=_blank}.
|
||||
|
||||
## Previous Steps Before Starting
|
||||
|
||||
@@ -273,7 +273,7 @@ Here are some possible ideas:
|
||||
* You would still need a way to start/restart *that* bash script, detect errors, etc.
|
||||
|
||||
!!! tip
|
||||
I'll give you more concrete examples for doing this with containers in a future chapter: [FastAPI in Containers - Docker](./docker.md){.internal-link target=_blank}.
|
||||
I'll give you more concrete examples for doing this with containers in a future chapter: [FastAPI in Containers - Docker](docker.md){.internal-link target=_blank}.
|
||||
|
||||
## Resource Utilization
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ It would depend mainly on the tool you use to **install** those requirements.
|
||||
|
||||
The most common way to do it is to have a file `requirements.txt` with the package names and their versions, one per line.
|
||||
|
||||
You would of course use the same ideas you read in [About FastAPI versions](./versions.md){.internal-link target=_blank} to set the ranges of versions.
|
||||
You would of course use the same ideas you read in [About FastAPI versions](versions.md){.internal-link target=_blank} to set the ranges of versions.
|
||||
|
||||
For example, your `requirements.txt` could look like:
|
||||
|
||||
@@ -373,7 +373,7 @@ Then adjust the Uvicorn command to use the new module `main` instead of `app.mai
|
||||
|
||||
## Deployment Concepts
|
||||
|
||||
Let's talk again about some of the same [Deployment Concepts](./concepts.md){.internal-link target=_blank} in terms of containers.
|
||||
Let's talk again about some of the same [Deployment Concepts](concepts.md){.internal-link target=_blank} in terms of containers.
|
||||
|
||||
Containers are mainly a tool to simplify the process of **building and deploying** an application, but they don't enforce a particular approach to handle these **deployment concepts**, and there are several possible strategies.
|
||||
|
||||
@@ -514,7 +514,7 @@ If you have a simple setup, with a **single container** that then starts multipl
|
||||
|
||||
## Official Docker Image with Gunicorn - Uvicorn
|
||||
|
||||
There is an official Docker image that includes Gunicorn running with Uvicorn workers, as detailed in a previous chapter: [Server Workers - Gunicorn with Uvicorn](./server-workers.md){.internal-link target=_blank}.
|
||||
There is an official Docker image that includes Gunicorn running with Uvicorn workers, as detailed in a previous chapter: [Server Workers - Gunicorn with Uvicorn](server-workers.md){.internal-link target=_blank}.
|
||||
|
||||
This image would be useful mainly in the situations described above in: [Containers with Multiple Processes and Special Cases](#containers-with-multiple-processes-and-special-cases).
|
||||
|
||||
|
||||
@@ -13,12 +13,12 @@ Up to this point, with all the tutorials in the docs, you have probably been run
|
||||
|
||||
When deploying applications you will probably want to have some **replication of processes** to take advantage of **multiple cores** and to be able to handle more requests.
|
||||
|
||||
As you saw in the previous chapter about [Deployment Concepts](./concepts.md){.internal-link target=_blank}, there are multiple strategies you can use.
|
||||
As you saw in the previous chapter about [Deployment Concepts](concepts.md){.internal-link target=_blank}, there are multiple strategies you can use.
|
||||
|
||||
Here I'll show you how to use <a href="https://gunicorn.org/" class="external-link" target="_blank">**Gunicorn**</a> with **Uvicorn worker processes**.
|
||||
|
||||
!!! info
|
||||
If you are using containers, for example with Docker or Kubernetes, I'll tell you more about that in the next chapter: [FastAPI in Containers - Docker](./docker.md){.internal-link target=_blank}.
|
||||
If you are using containers, for example with Docker or Kubernetes, I'll tell you more about that in the next chapter: [FastAPI in Containers - Docker](docker.md){.internal-link target=_blank}.
|
||||
|
||||
In particular, when running on **Kubernetes** you will probably **not** want to use Gunicorn and instead run **a single Uvicorn process per container**, but I'll tell you about it later in that chapter.
|
||||
|
||||
@@ -165,7 +165,7 @@ From the list of deployment concepts from above, using workers would mainly help
|
||||
|
||||
## Containers and Docker
|
||||
|
||||
In the next chapter about [FastAPI in Containers - Docker](./docker.md){.internal-link target=_blank} I'll tell some strategies you could use to handle the other **deployment concepts**.
|
||||
In the next chapter about [FastAPI in Containers - Docker](docker.md){.internal-link target=_blank} I'll tell some strategies you could use to handle the other **deployment concepts**.
|
||||
|
||||
I'll also show you the **official Docker image** that includes **Gunicorn with Uvicorn workers** and some default configurations that can be useful for simple cases.
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ You can:
|
||||
* Tell me how you use FastAPI (I love to hear that).
|
||||
* Hear when I make announcements or release new tools.
|
||||
* You can also <a href="https://twitter.com/fastapi" class="external-link" target="_blank">follow @fastapi on Twitter</a> (a separate account).
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">Follow me on **Linkedin**</a>.
|
||||
* <a href="https://www.linkedin.com/in/tiangolo/" class="external-link" target="_blank">Follow me on **LinkedIn**</a>.
|
||||
* Hear when I make announcements or release new tools (although I use Twitter more often 🤷♂).
|
||||
* Read what I write (or follow me) on <a href="https://dev.to/tiangolo" class="external-link" target="_blank">**Dev.to**</a> or <a href="https://medium.com/@tiangolo" class="external-link" target="_blank">**Medium**</a>.
|
||||
* Read other ideas, articles, and read about tools I have created.
|
||||
@@ -78,7 +78,7 @@ You can try and help others with their questions in:
|
||||
|
||||
In many cases you might already know the answer for those questions. 🤓
|
||||
|
||||
If you are helping a lot of people with their questions, you will become an official [FastAPI Expert](fastapi-people.md#experts){.internal-link target=_blank}. 🎉
|
||||
If you are helping a lot of people with their questions, you will become an official [FastAPI Expert](fastapi-people.md#fastapi-experts){.internal-link target=_blank}. 🎉
|
||||
|
||||
Just remember, the most important point is: try to be kind. People come with their frustrations and in many cases don't ask in the best way, but try as best as you can to be kind. 🤗
|
||||
|
||||
@@ -227,7 +227,7 @@ If you can help me with that, **you are helping me maintain FastAPI** and making
|
||||
Join the 👥 <a href="https://discord.gg/VQjSZaeJmf" class="external-link" target="_blank">Discord chat server</a> 👥 and hang out with others in the FastAPI community.
|
||||
|
||||
!!! tip
|
||||
For questions, ask them in <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">GitHub Discussions</a>, there's a much better chance you will receive help by the [FastAPI Experts](fastapi-people.md#experts){.internal-link target=_blank}.
|
||||
For questions, ask them in <a href="https://github.com/tiangolo/fastapi/discussions/new?category=questions" class="external-link" target="_blank">GitHub Discussions</a>, there's a much better chance you will receive help by the [FastAPI Experts](fastapi-people.md#fastapi-experts){.internal-link target=_blank}.
|
||||
|
||||
Use the chat only for other general conversations.
|
||||
|
||||
@@ -237,7 +237,7 @@ Keep in mind that as chats allow more "free conversation", it's easy to ask ques
|
||||
|
||||
In GitHub, the template will guide you to write the right question so that you can more easily get a good answer, or even solve the problem yourself even before asking. And in GitHub I can make sure I always answer everything, even if it takes some time. I can't personally do that with the chat systems. 😅
|
||||
|
||||
Conversations in the chat systems are also not as easily searchable as in GitHub, so questions and answers might get lost in the conversation. And only the ones in GitHub count to become a [FastAPI Expert](fastapi-people.md#experts){.internal-link target=_blank}, so you will most probably receive more attention in GitHub.
|
||||
Conversations in the chat systems are also not as easily searchable as in GitHub, so questions and answers might get lost in the conversation. And only the ones in GitHub count to become a [FastAPI Expert](fastapi-people.md#fastapi-experts){.internal-link target=_blank}, so you will most probably receive more attention in GitHub.
|
||||
|
||||
On the other side, there are thousands of users in the chat systems, so there's a high chance you'll find someone to talk to there, almost all the time. 😄
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ Create the *path operation function* to read notes:
|
||||
{!../../../docs_src/async_sql_databases/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! Note
|
||||
!!! note
|
||||
Notice that as we communicate with the database using `await`, the *path operation function* is declared with `async`.
|
||||
|
||||
### Notice the `response_model=List[Note]`
|
||||
@@ -122,7 +122,7 @@ Create the *path operation function* to create notes:
|
||||
|
||||
The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
|
||||
|
||||
!!! Note
|
||||
!!! note
|
||||
Notice that as we communicate with the database using `await`, the *path operation function* is declared with `async`.
|
||||
|
||||
### About `{**note.dict(), "id": last_record_id}`
|
||||
|
||||
@@ -45,7 +45,7 @@ FastAPI includes some default configuration parameters appropriate for most of t
|
||||
It includes these default configurations:
|
||||
|
||||
```Python
|
||||
{!../../../fastapi/openapi/docs.py[ln:7-13]!}
|
||||
{!../../../fastapi/openapi/docs.py[ln:7-23]!}
|
||||
```
|
||||
|
||||
You can override any of them by setting a different value in the argument `swagger_ui_parameters`.
|
||||
|
||||
@@ -36,7 +36,7 @@ hide:
|
||||
|
||||
---
|
||||
|
||||
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints.
|
||||
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python based on standard Python type hints.
|
||||
|
||||
The key features are:
|
||||
|
||||
@@ -124,8 +124,6 @@ If you are building a <abbr title="Command Line Interface">CLI</abbr> app to be
|
||||
|
||||
## Requirements
|
||||
|
||||
Python 3.8+
|
||||
|
||||
FastAPI stands on the shoulders of giants:
|
||||
|
||||
* <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a> for the web parts.
|
||||
@@ -340,7 +338,7 @@ You do that with standard modern Python types.
|
||||
|
||||
You don't have to learn a new syntax, the methods or classes of a specific library, etc.
|
||||
|
||||
Just standard **Python 3.8+**.
|
||||
Just standard **Python**.
|
||||
|
||||
For example, for an `int`:
|
||||
|
||||
@@ -465,12 +463,12 @@ Used by Starlette:
|
||||
* <a href="https://github.com/Kludex/python-multipart" target="_blank"><code>python-multipart</code></a> - Required if you want to support form <abbr title="converting the string that comes from an HTTP request into Python data">"parsing"</abbr>, with `request.form()`.
|
||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Required for `SessionMiddleware` support.
|
||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - Required for Starlette's `SchemaGenerator` support (you probably don't need it with FastAPI).
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
|
||||
|
||||
Used by FastAPI / Starlette:
|
||||
|
||||
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application.
|
||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - Required if you want to use `ORJSONResponse`.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
|
||||
|
||||
You can install all of these with `pip install "fastapi[all]"`.
|
||||
|
||||
|
||||
@@ -186,7 +186,7 @@ For example, let's define a variable to be a `list` of `str`.
|
||||
|
||||
From `typing`, import `List` (with a capital `L`):
|
||||
|
||||
``` Python hl_lines="1"
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/python_types/tutorial006.py!}
|
||||
```
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# `APIRouter` class
|
||||
|
||||
Here's the reference information for the `APIRouter` class, with all its parameters,
|
||||
attributes and methods.
|
||||
Here's the reference information for the `APIRouter` class, with all its parameters, attributes and methods.
|
||||
|
||||
You can import the `APIRouter` class directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# Background Tasks - `BackgroundTasks`
|
||||
|
||||
You can declare a parameter in a *path operation function* or dependency function
|
||||
with the type `BackgroundTasks`, and then you can use it to schedule the execution
|
||||
of background tasks after the response is sent.
|
||||
You can declare a parameter in a *path operation function* or dependency function with the type `BackgroundTasks`, and then you can use it to schedule the execution of background tasks after the response is sent.
|
||||
|
||||
You can import it directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
## `Depends()`
|
||||
|
||||
Dependencies are handled mainly with the special function `Depends()` that takes a
|
||||
callable.
|
||||
Dependencies are handled mainly with the special function `Depends()` that takes a callable.
|
||||
|
||||
Here is the reference for it and its parameters.
|
||||
|
||||
@@ -17,11 +16,9 @@ from fastapi import Depends
|
||||
|
||||
## `Security()`
|
||||
|
||||
For many scenarios, you can handle security (authorization, authentication, etc.) with
|
||||
dependencies, using `Depends()`.
|
||||
For many scenarios, you can handle security (authorization, authentication, etc.) with dependencies, using `Depends()`.
|
||||
|
||||
But when you want to also declare OAuth2 scopes, you can use `Security()` instead of
|
||||
`Depends()`.
|
||||
But when you want to also declare OAuth2 scopes, you can use `Security()` instead of `Depends()`.
|
||||
|
||||
You can import `Security()` directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
|
||||
These are the exceptions that you can raise to show errors to the client.
|
||||
|
||||
When you raise an exception, as would happen with normal Python, the rest of the
|
||||
execution is aborted. This way you can raise these exceptions from anywhere in the
|
||||
code to abort a request and show the error to the client.
|
||||
When you raise an exception, as would happen with normal Python, the rest of the execution is aborted. This way you can raise these exceptions from anywhere in the code to abort a request and show the error to the client.
|
||||
|
||||
You can use:
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# `FastAPI` class
|
||||
|
||||
Here's the reference information for the `FastAPI` class, with all its parameters,
|
||||
attributes and methods.
|
||||
Here's the reference information for the `FastAPI` class, with all its parameters, attributes and methods.
|
||||
|
||||
You can import the `FastAPI` class directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# `HTTPConnection` class
|
||||
|
||||
When you want to define dependencies that should be compatible with both HTTP and
|
||||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a
|
||||
`Request` or a `WebSocket`.
|
||||
When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a `Request` or a `WebSocket`.
|
||||
|
||||
You can import it from `fastapi.requests`:
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
There are several middlewares available provided by Starlette directly.
|
||||
|
||||
Read more about them in the
|
||||
[FastAPI docs for Middleware](https://fastapi.tiangolo.com/advanced/middleware/).
|
||||
Read more about them in the [FastAPI docs for Middleware](https://fastapi.tiangolo.com/advanced/middleware/).
|
||||
|
||||
::: fastapi.middleware.cors.CORSMiddleware
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
Here's the reference information for the request parameters.
|
||||
|
||||
These are the special functions that you can put in *path operation function*
|
||||
parameters or dependency functions with `Annotated` to get data from the request.
|
||||
These are the special functions that you can put in *path operation function* parameters or dependency functions with `Annotated` to get data from the request.
|
||||
|
||||
It includes:
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
# `Request` class
|
||||
|
||||
You can declare a parameter in a *path operation function* or dependency to be of type
|
||||
`Request` and then you can access the raw request object directly, without any
|
||||
validation, etc.
|
||||
You can declare a parameter in a *path operation function* or dependency to be of type `Request` and then you can access the raw request object directly, without any validation, etc.
|
||||
|
||||
You can import it directly from `fastapi`:
|
||||
|
||||
@@ -11,8 +9,6 @@ from fastapi import Request
|
||||
```
|
||||
|
||||
!!! tip
|
||||
When you want to define dependencies that should be compatible with both HTTP and
|
||||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a
|
||||
`Request` or a `WebSocket`.
|
||||
When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a `Request` or a `WebSocket`.
|
||||
|
||||
::: fastapi.Request
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# `Response` class
|
||||
|
||||
You can declare a parameter in a *path operation function* or dependency to be of type
|
||||
`Response` and then you can set data for the response like headers or cookies.
|
||||
You can declare a parameter in a *path operation function* or dependency to be of type `Response` and then you can set data for the response like headers or cookies.
|
||||
|
||||
You can also use it directly to create an instance of it and return it from your *path
|
||||
operations*.
|
||||
You can also use it directly to create an instance of it and return it from your *path operations*.
|
||||
|
||||
You can import it directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
# Custom Response Classes - File, HTML, Redirect, Streaming, etc.
|
||||
|
||||
There are several custom response classes you can use to create an instance and return
|
||||
them directly from your *path operations*.
|
||||
There are several custom response classes you can use to create an instance and return them directly from your *path operations*.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
|
||||
Read more about it in the [FastAPI docs for Custom Response - HTML, Stream, File, others](https://fastapi.tiangolo.com/advanced/custom-response/).
|
||||
|
||||
You can import them directly from `fastapi.responses`:
|
||||
|
||||
|
||||
@@ -2,12 +2,9 @@
|
||||
|
||||
When you need to declare dependencies with OAuth2 scopes you use `Security()`.
|
||||
|
||||
But you still need to define what is the dependable, the callable that you pass as
|
||||
a parameter to `Depends()` or `Security()`.
|
||||
But you still need to define what is the dependable, the callable that you pass as a parameter to `Depends()` or `Security()`.
|
||||
|
||||
There are multiple tools that you can use to create those dependables, and they get
|
||||
integrated into OpenAPI so they are shown in the automatic docs UI, they can be used
|
||||
by automatically generated clients and SDKs, etc.
|
||||
There are multiple tools that you can use to create those dependables, and they get integrated into OpenAPI so they are shown in the automatic docs UI, they can be used by automatically generated clients and SDKs, etc.
|
||||
|
||||
You can import them from `fastapi.security`:
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
You can use the `StaticFiles` class to serve static files, like JavaScript, CSS, images, etc.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs for Static Files](https://fastapi.tiangolo.com/tutorial/static-files/).
|
||||
Read more about it in the [FastAPI docs for Static Files](https://fastapi.tiangolo.com/tutorial/static-files/).
|
||||
|
||||
You can import it directly from `fastapi.staticfiles`:
|
||||
|
||||
|
||||
@@ -16,12 +16,9 @@ For example:
|
||||
* 403: `status.HTTP_403_FORBIDDEN`
|
||||
* etc.
|
||||
|
||||
It can be convenient to quickly access HTTP (and WebSocket) status codes in your app,
|
||||
using autocompletion for the name without having to remember the integer status codes
|
||||
by memory.
|
||||
It can be convenient to quickly access HTTP (and WebSocket) status codes in your app, using autocompletion for the name without having to remember the integer status codes by memory.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs about Response Status Code](https://fastapi.tiangolo.com/tutorial/response-status-code/).
|
||||
Read more about it in the [FastAPI docs about Response Status Code](https://fastapi.tiangolo.com/tutorial/response-status-code/).
|
||||
|
||||
## Example
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
You can use the `Jinja2Templates` class to render Jinja templates.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs for Templates](https://fastapi.tiangolo.com/advanced/templates/).
|
||||
Read more about it in the [FastAPI docs for Templates](https://fastapi.tiangolo.com/advanced/templates/).
|
||||
|
||||
You can import it directly from `fastapi.templating`:
|
||||
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
|
||||
You can use the `TestClient` class to test FastAPI applications without creating an actual HTTP and socket connection, just communicating directly with the FastAPI code.
|
||||
|
||||
Read more about it in the
|
||||
[FastAPI docs for Testing](https://fastapi.tiangolo.com/tutorial/testing/).
|
||||
Read more about it in the [FastAPI docs for Testing](https://fastapi.tiangolo.com/tutorial/testing/).
|
||||
|
||||
You can import it directly from `fastapi.testclient`:
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# `UploadFile` class
|
||||
|
||||
You can define *path operation function* parameters to be of the type `UploadFile`
|
||||
to receive files from the request.
|
||||
You can define *path operation function* parameters to be of the type `UploadFile` to receive files from the request.
|
||||
|
||||
You can import it directly from `fastapi`:
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
# WebSockets
|
||||
|
||||
When defining WebSockets, you normally declare a parameter of type `WebSocket` and
|
||||
with it you can read data from the client and send data to it.
|
||||
When defining WebSockets, you normally declare a parameter of type `WebSocket` and with it you can read data from the client and send data to it.
|
||||
|
||||
It is provided directly by Starlette, but you can import it from `fastapi`:
|
||||
|
||||
@@ -10,9 +9,7 @@ from fastapi import WebSocket
|
||||
```
|
||||
|
||||
!!! tip
|
||||
When you want to define dependencies that should be compatible with both HTTP and
|
||||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a
|
||||
`Request` or a `WebSocket`.
|
||||
When you want to define dependencies that should be compatible with both HTTP and WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a `Request` or a `WebSocket`.
|
||||
|
||||
::: fastapi.WebSocket
|
||||
options:
|
||||
@@ -44,8 +41,7 @@ from fastapi import WebSocket
|
||||
- send_json
|
||||
- close
|
||||
|
||||
When a client disconnects, a `WebSocketDisconnect` exception is raised, you can catch
|
||||
it.
|
||||
When a client disconnects, a `WebSocketDisconnect` exception is raised, you can catch it.
|
||||
|
||||
You can import it directly form `fastapi`:
|
||||
|
||||
|
||||
@@ -5,8 +5,70 @@ hide:
|
||||
|
||||
# Release Notes
|
||||
|
||||
## 0.110.3
|
||||
|
||||
## Latest Changes
|
||||
|
||||
### Docs
|
||||
|
||||
* 📝 Update references to Python version, FastAPI supports all the current versions, no need to make the version explicit. PR [#11496](https://github.com/tiangolo/fastapi/pull/11496) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ✏️ Fix typo in `fastapi/security/api_key.py`. PR [#11481](https://github.com/tiangolo/fastapi/pull/11481) by [@ch33zer](https://github.com/ch33zer).
|
||||
* ✏️ Fix typo in `security/http.py`. PR [#11455](https://github.com/tiangolo/fastapi/pull/11455) by [@omarmoo5](https://github.com/omarmoo5).
|
||||
|
||||
### Translations
|
||||
|
||||
* 🌐 Add Traditional Chinese translation for `docs/zh-hant/benchmarks.md`. PR [#11484](https://github.com/tiangolo/fastapi/pull/11484) by [@KNChiu](https://github.com/KNChiu).
|
||||
* 🌐 Update Chinese translation for `docs/zh/docs/fastapi-people.md`. PR [#11476](https://github.com/tiangolo/fastapi/pull/11476) by [@billzhong](https://github.com/billzhong).
|
||||
* 🌐 Add Chinese translation for `docs/zh/docs/how-to/index.md` and `docs/zh/docs/how-to/general.md`. PR [#11443](https://github.com/tiangolo/fastapi/pull/11443) by [@billzhong](https://github.com/billzhong).
|
||||
* 🌐 Add Spanish translation for cookie-params `docs/es/docs/tutorial/cookie-params.md`. PR [#11410](https://github.com/tiangolo/fastapi/pull/11410) by [@fabianfalon](https://github.com/fabianfalon).
|
||||
|
||||
### Internal
|
||||
|
||||
* ⬆ Bump mkdocstrings[python] from 0.23.0 to 0.24.3. PR [#11469](https://github.com/tiangolo/fastapi/pull/11469) by [@dependabot[bot]](https://github.com/apps/dependabot).
|
||||
* 🔨 Update internal scripts and remove unused ones. PR [#11499](https://github.com/tiangolo/fastapi/pull/11499) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 🔧 Migrate from Hatch to PDM for the internal build. PR [#11498](https://github.com/tiangolo/fastapi/pull/11498) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ⬆️ Upgrade MkDocs Material and re-enable cards. PR [#11466](https://github.com/tiangolo/fastapi/pull/11466) by [@tiangolo](https://github.com/tiangolo).
|
||||
* ⬆ Bump pillow from 10.2.0 to 10.3.0. PR [#11403](https://github.com/tiangolo/fastapi/pull/11403) by [@dependabot[bot]](https://github.com/apps/dependabot).
|
||||
* 🔧 Ungroup dependabot updates. PR [#11465](https://github.com/tiangolo/fastapi/pull/11465) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
## 0.110.2
|
||||
|
||||
### Fixes
|
||||
|
||||
* 🐛 Fix support for query parameters with list types, handle JSON encoding Pydantic `UndefinedType`. PR [#9929](https://github.com/tiangolo/fastapi/pull/9929) by [@arjwilliams](https://github.com/arjwilliams).
|
||||
|
||||
### Refactors
|
||||
|
||||
* ♻️ Simplify Pydantic configs in OpenAPI models in `fastapi/openapi/models.py`. PR [#10886](https://github.com/tiangolo/fastapi/pull/10886) by [@JoeTanto2](https://github.com/JoeTanto2).
|
||||
* ✨ Add support for Pydantic's 2.7 new deprecated Field parameter, remove URL from validation errors response. PR [#11461](https://github.com/tiangolo/fastapi/pull/11461) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
### Docs
|
||||
|
||||
* 📝 Fix types in examples under `docs_src/extra_data_types`. PR [#10535](https://github.com/tiangolo/fastapi/pull/10535) by [@nilslindemann](https://github.com/nilslindemann).
|
||||
* 📝 Update references to UJSON. PR [#11464](https://github.com/tiangolo/fastapi/pull/11464) by [@tiangolo](https://github.com/tiangolo).
|
||||
* 📝 Tweak docs and translations links, typos, format. PR [#11389](https://github.com/tiangolo/fastapi/pull/11389) by [@nilslindemann](https://github.com/nilslindemann).
|
||||
* 📝 Fix typo in `docs/es/docs/async.md`. PR [#11400](https://github.com/tiangolo/fastapi/pull/11400) by [@fabianfalon](https://github.com/fabianfalon).
|
||||
* 📝 Update OpenAPI client generation docs to use `@hey-api/openapi-ts`. PR [#11339](https://github.com/tiangolo/fastapi/pull/11339) by [@jordanshatford](https://github.com/jordanshatford).
|
||||
|
||||
### Translations
|
||||
|
||||
* 🌐 Update Chinese translation for `docs/zh/docs/index.html`. PR [#11430](https://github.com/tiangolo/fastapi/pull/11430) by [@waketzheng](https://github.com/waketzheng).
|
||||
* 🌐 Add Russian translation for `docs/ru/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md`. PR [#11411](https://github.com/tiangolo/fastapi/pull/11411) by [@anton2yakovlev](https://github.com/anton2yakovlev).
|
||||
* 🌐 Add Portuguese translations for `learn/index.md` `resources/index.md` `help/index.md` `about/index.md`. PR [#10807](https://github.com/tiangolo/fastapi/pull/10807) by [@nazarepiedady](https://github.com/nazarepiedady).
|
||||
* 🌐 Update Russian translations for deployments docs. PR [#11271](https://github.com/tiangolo/fastapi/pull/11271) by [@Lufa1u](https://github.com/Lufa1u).
|
||||
* 🌐 Add Bengali translations for `docs/bn/docs/python-types.md`. PR [#11376](https://github.com/tiangolo/fastapi/pull/11376) by [@imtiaz101325](https://github.com/imtiaz101325).
|
||||
* 🌐 Add Korean translation for `docs/ko/docs/tutorial/security/simple-oauth2.md`. PR [#5744](https://github.com/tiangolo/fastapi/pull/5744) by [@KdHyeon0661](https://github.com/KdHyeon0661).
|
||||
* 🌐 Add Korean translation for `docs/ko/docs/help-fastapi.md`. PR [#4139](https://github.com/tiangolo/fastapi/pull/4139) by [@kty4119](https://github.com/kty4119).
|
||||
* 🌐 Add Korean translation for `docs/ko/docs/advanced/events.md`. PR [#5087](https://github.com/tiangolo/fastapi/pull/5087) by [@pers0n4](https://github.com/pers0n4).
|
||||
* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/path-operation-configuration.md`. PR [#1954](https://github.com/tiangolo/fastapi/pull/1954) by [@SwftAlpc](https://github.com/SwftAlpc).
|
||||
* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/request-forms-and-files.md`. PR [#1946](https://github.com/tiangolo/fastapi/pull/1946) by [@SwftAlpc](https://github.com/SwftAlpc).
|
||||
* 🌐 Add Russian translation for `docs/ru/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#10532](https://github.com/tiangolo/fastapi/pull/10532) by [@AlertRED](https://github.com/AlertRED).
|
||||
* 🌐 Add Korean translation for `docs/ko/docs/tutorial/debugging.md`. PR [#5695](https://github.com/tiangolo/fastapi/pull/5695) by [@JungWooGeon](https://github.com/JungWooGeon).
|
||||
|
||||
### Internal
|
||||
|
||||
* ⬆️ Upgrade version of typer for docs. PR [#11393](https://github.com/tiangolo/fastapi/pull/11393) by [@tiangolo](https://github.com/tiangolo).
|
||||
|
||||
## 0.110.1
|
||||
|
||||
### Fixes
|
||||
|
||||
@@ -136,7 +136,7 @@ We will now use a simple dependency to read a custom `X-Token` header:
|
||||
!!! tip
|
||||
We are using an invented header to simplify this example.
|
||||
|
||||
But in real cases you will get better results using the integrated [Security utilities](./security/index.md){.internal-link target=_blank}.
|
||||
But in real cases you will get better results using the integrated [Security utilities](security/index.md){.internal-link target=_blank}.
|
||||
|
||||
## Another module with `APIRouter`
|
||||
|
||||
@@ -329,7 +329,7 @@ The section:
|
||||
from .routers import items, users
|
||||
```
|
||||
|
||||
Means:
|
||||
means:
|
||||
|
||||
* Starting in the same package that this module (the file `app/main.py`) lives in (the directory `app/`)...
|
||||
* look for the subpackage `routers` (the directory at `app/routers/`)...
|
||||
@@ -373,7 +373,7 @@ from .routers.items import router
|
||||
from .routers.users import router
|
||||
```
|
||||
|
||||
The `router` from `users` would overwrite the one from `items` and we wouldn't be able to use them at the same time.
|
||||
the `router` from `users` would overwrite the one from `items` and we wouldn't be able to use them at the same time.
|
||||
|
||||
So, to be able to use both of them in the same file, we import the submodules directly:
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ You can also use the <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/
|
||||
|
||||
This means that you can send only the data that you want to update, leaving the rest intact.
|
||||
|
||||
!!! Note
|
||||
!!! note
|
||||
`PATCH` is less commonly used and known than `PUT`.
|
||||
|
||||
And many teams use only `PUT`, even for partial updates.
|
||||
|
||||
@@ -271,6 +271,12 @@ Now you can declare your dependency using this class.
|
||||
|
||||
Notice how we write `CommonQueryParams` twice in the above code:
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python
|
||||
commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
|
||||
```
|
||||
|
||||
=== "Python 3.8+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
@@ -280,12 +286,6 @@ Notice how we write `CommonQueryParams` twice in the above code:
|
||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python
|
||||
commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
|
||||
```
|
||||
|
||||
The last `CommonQueryParams`, in:
|
||||
|
||||
```Python
|
||||
@@ -334,7 +334,7 @@ You could actually write just:
|
||||
commons = Depends(CommonQueryParams)
|
||||
```
|
||||
|
||||
..as in:
|
||||
...as in:
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
@@ -380,6 +380,12 @@ But declaring the type is encouraged as that way your editor will know what will
|
||||
|
||||
But you see that we are having some code repetition here, writing `CommonQueryParams` twice:
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python
|
||||
commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
|
||||
```
|
||||
|
||||
=== "Python 3.8+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
@@ -389,12 +395,6 @@ But you see that we are having some code repetition here, writing `CommonQueryPa
|
||||
commons: CommonQueryParams = Depends(CommonQueryParams)
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python
|
||||
commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
|
||||
```
|
||||
|
||||
**FastAPI** provides a shortcut for these cases, in where the dependency is *specifically* a class that **FastAPI** will "call" to create an instance of the class itself.
|
||||
|
||||
For those specific cases, you can do the following:
|
||||
|
||||
@@ -257,7 +257,7 @@ And you can declare dependencies with `async def` inside of normal `def` *path o
|
||||
It doesn't matter. **FastAPI** will know what to do.
|
||||
|
||||
!!! note
|
||||
If you don't know, check the [Async: *"In a hurry?"*](../../async.md){.internal-link target=_blank} section about `async` and `await` in the docs.
|
||||
If you don't know, check the [Async: *"In a hurry?"*](../../async.md#in-a-hurry){.internal-link target=_blank} section about `async` and `await` in the docs.
|
||||
|
||||
## Integrated with OpenAPI
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ So, continuing with the `user_dict` from above, writing:
|
||||
UserInDB(**user_dict)
|
||||
```
|
||||
|
||||
Would result in something equivalent to:
|
||||
would result in something equivalent to:
|
||||
|
||||
```Python
|
||||
UserInDB(
|
||||
|
||||
@@ -338,7 +338,7 @@ Your response model could have default values, like:
|
||||
|
||||
* `description: Union[str, None] = None` (or `str | None = None` in Python 3.10) has a default of `None`.
|
||||
* `tax: float = 10.5` has a default of `10.5`.
|
||||
* `tags: List[str] = []` as a default of an empty list: `[]`.
|
||||
* `tags: List[str] = []` has a default of an empty list: `[]`.
|
||||
|
||||
but you might want to omit them from the result if they were not actually stored.
|
||||
|
||||
|
||||
@@ -305,7 +305,7 @@ This new `examples` field in JSON Schema is **just a `list`** of examples, not a
|
||||
|
||||
### Pydantic and FastAPI `examples`
|
||||
|
||||
When you add `examples` inside of a Pydantic model, using `schema_extra` or `Field(examples=["something"])` that example is added to the **JSON Schema** for that Pydantic model.
|
||||
When you add `examples` inside a Pydantic model, using `schema_extra` or `Field(examples=["something"])` that example is added to the **JSON Schema** for that Pydantic model.
|
||||
|
||||
And that **JSON Schema** of the Pydantic model is included in the **OpenAPI** of your API, and then it's used in the docs UI.
|
||||
|
||||
|
||||
@@ -260,7 +260,7 @@ If the token is invalid, return an HTTP error right away.
|
||||
|
||||
Create a `timedelta` with the expiration time of the token.
|
||||
|
||||
Create a real JWT access token and return it
|
||||
Create a real JWT access token and return it.
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ First, import `OAuth2PasswordRequestForm`, and use it as a dependency with `Depe
|
||||
|
||||
Now, get the user data from the (fake) database, using the `username` from the form field.
|
||||
|
||||
If there is no such user, we return an error saying "incorrect username or password".
|
||||
If there is no such user, we return an error saying "Incorrect username or password".
|
||||
|
||||
For the error, we use the exception `HTTPException`:
|
||||
|
||||
@@ -416,7 +416,7 @@ Password: `secret2`
|
||||
|
||||
And try to use the operation `GET` with the path `/users/me`.
|
||||
|
||||
You will get an "inactive user" error, like:
|
||||
You will get an "Inactive user" error, like:
|
||||
|
||||
```JSON
|
||||
{
|
||||
|
||||
@@ -546,7 +546,7 @@ Our dependency will create a new SQLAlchemy `SessionLocal` that will be used in
|
||||
|
||||
This way we make sure the database session is always closed after the request. Even if there was an exception while processing the request.
|
||||
|
||||
But you can't raise another exception from the exit code (after `yield`). See more in [Dependencies with `yield` and `HTTPException`](./dependencies/dependencies-with-yield.md#dependencies-with-yield-and-httpexception){.internal-link target=_blank}
|
||||
But you can't raise another exception from the exit code (after `yield`). See more in [Dependencies with `yield` and `HTTPException`](dependencies/dependencies-with-yield.md#dependencies-with-yield-and-httpexception){.internal-link target=_blank}
|
||||
|
||||
And then, when using the dependency in a *path operation function*, we declare it with the type `Session` we imported directly from SQLAlchemy.
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ And your **FastAPI** application might also be composed of several files/modules
|
||||
|
||||
### **FastAPI** app file
|
||||
|
||||
Let's say you have a file structure as described in [Bigger Applications](./bigger-applications.md){.internal-link target=_blank}:
|
||||
Let's say you have a file structure as described in [Bigger Applications](bigger-applications.md){.internal-link target=_blank}:
|
||||
|
||||
```
|
||||
.
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
plugins:
|
||||
# TODO: Re-enable once this is fixed: https://github.com/squidfunk/mkdocs-material/issues/6983
|
||||
# social:
|
||||
# cards_layout_dir: ../en/layouts
|
||||
# cards_layout: custom
|
||||
# cards_layout_options:
|
||||
# logo: ../en/docs/img/icon-white.svg
|
||||
social:
|
||||
cards_layout_dir: ../en/layouts
|
||||
cards_layout: custom
|
||||
cards_layout_options:
|
||||
logo: ../en/docs/img/icon-white.svg
|
||||
typeset:
|
||||
|
||||
@@ -190,7 +190,7 @@ Luego, el cajero / cocinero 👨🍳 finalmente regresa con tus hamburguesas
|
||||
|
||||
<img src="https://fastapi.tiangolo.com/img/async/parallel-burgers/parallel-burgers-05.png" alt="illustration">
|
||||
|
||||
Cojes tus hamburguesas 🍔 y vas a la mesa con esa persona 😍.
|
||||
Coges tus hamburguesas 🍔 y vas a la mesa con esa persona 😍.
|
||||
|
||||
Sólo las comes y listo 🍔 ⏹.
|
||||
|
||||
@@ -400,7 +400,7 @@ Cuando declaras una *path operation function* con `def` normal en lugar de `asyn
|
||||
|
||||
Si vienes de otro framework asíncrono que no funciona de la manera descrita anteriormente y estás acostumbrado a definir *path operation functions* del tipo sólo cálculo con `def` simple para una pequeña ganancia de rendimiento (aproximadamente 100 nanosegundos), ten en cuenta que en **FastAPI** el efecto sería bastante opuesto. En estos casos, es mejor usar `async def` a menos que tus *path operation functions* usen un código que realice el bloqueo <abbr title="Input/Output: disk reading or writing, network communications.">I/O</abbr>.
|
||||
|
||||
Aún así, en ambas situaciones, es probable que **FastAPI** sea [aún más rápido](index.md#performance){.Internal-link target=_blank} que (o al menos comparable) a tu framework anterior.
|
||||
Aún así, en ambas situaciones, es probable que **FastAPI** sea [aún más rápido](index.md#rendimiento){.Internal-link target=_blank} que (o al menos comparable) a tu framework anterior.
|
||||
|
||||
### Dependencias
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
<style>
|
||||
.md-content .md-typeset h1 { display: none; }
|
||||
</style>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
|
||||
</p>
|
||||
@@ -23,7 +32,7 @@
|
||||
**Código Fuente**: <a href="https://github.com/tiangolo/fastapi" target="_blank">https://github.com/tiangolo/fastapi</a>
|
||||
|
||||
---
|
||||
FastAPI es un web framework moderno y rápido (de alto rendimiento) para construir APIs con Python 3.8+ basado en las anotaciones de tipos estándar de Python.
|
||||
FastAPI es un web framework moderno y rápido (de alto rendimiento) para construir APIs con Python basado en las anotaciones de tipos estándar de Python.
|
||||
|
||||
Sus características principales son:
|
||||
|
||||
@@ -106,8 +115,6 @@ Si estás construyendo un app de <abbr title="Interfaz de línea de comandos en
|
||||
|
||||
## Requisitos
|
||||
|
||||
Python 3.8+
|
||||
|
||||
FastAPI está sobre los hombros de gigantes:
|
||||
|
||||
* <a href="https://www.starlette.io/" class="external-link" target="_blank">Starlette</a> para las partes web.
|
||||
@@ -319,7 +326,7 @@ Lo haces con tipos modernos estándar de Python.
|
||||
|
||||
No tienes que aprender una sintaxis nueva, los métodos o clases de una library específica, etc.
|
||||
|
||||
Solo **Python 3.8+** estándar.
|
||||
Solo **Python** estándar.
|
||||
|
||||
Por ejemplo, para un `int`:
|
||||
|
||||
@@ -443,12 +450,12 @@ Usados por Starlette:
|
||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - Requerido para dar soporte a `SessionMiddleware`.
|
||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - Requerido para dar soporte al `SchemaGenerator` de Starlette (probablemente no lo necesites con FastAPI).
|
||||
* <a href="https://graphene-python.org/" target="_blank"><code>graphene</code></a> - Requerido para dar soporte a `GraphQLApp`.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Requerido si quieres usar `UJSONResponse`.
|
||||
|
||||
Usado por FastAPI / Starlette:
|
||||
|
||||
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - para el servidor que carga y sirve tu aplicación.
|
||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - Requerido si quieres usar `ORJSONResponse`.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Requerido si quieres usar `UJSONResponse`.
|
||||
|
||||
Puedes instalarlos con `pip install fastapi[all]`.
|
||||
|
||||
|
||||
97
docs/es/docs/tutorial/cookie-params.md
Normal file
97
docs/es/docs/tutorial/cookie-params.md
Normal file
@@ -0,0 +1,97 @@
|
||||
# Parámetros de Cookie
|
||||
|
||||
Puedes definir parámetros de Cookie de la misma manera que defines parámetros de `Query` y `Path`.
|
||||
|
||||
## Importar `Cookie`
|
||||
|
||||
Primero importa `Cookie`:
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001.py!}
|
||||
```
|
||||
|
||||
## Declarar parámetros de `Cookie`
|
||||
|
||||
Luego declara los parámetros de cookie usando la misma estructura que con `Path` y `Query`.
|
||||
|
||||
El primer valor es el valor por defecto, puedes pasar todos los parámetros adicionales de validación o anotación:
|
||||
|
||||
=== "Python 3.10+"
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.9+"
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an_py39.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+"
|
||||
|
||||
```Python hl_lines="10"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_an.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.10+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001_py310.py!}
|
||||
```
|
||||
|
||||
=== "Python 3.8+ non-Annotated"
|
||||
|
||||
!!! tip
|
||||
Prefer to use the `Annotated` version if possible.
|
||||
|
||||
```Python hl_lines="9"
|
||||
{!> ../../../docs_src/cookie_params/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! note "Detalles Técnicos"
|
||||
`Cookie` es una clase "hermana" de `Path` y `Query`. También hereda de la misma clase común `Param`.
|
||||
|
||||
Pero recuerda que cuando importas `Query`, `Path`, `Cookie` y otros de `fastapi`, en realidad son funciones que devuelven clases especiales.
|
||||
|
||||
!!! info
|
||||
Para declarar cookies, necesitas usar `Cookie`, porque de lo contrario los parámetros serían interpretados como parámetros de query.
|
||||
|
||||
## Resumen
|
||||
|
||||
Declara cookies con `Cookie`, usando el mismo patrón común que `Query` y `Path`.
|
||||
@@ -310,7 +310,7 @@ También podrías definirla como una función estándar en lugar de `async def`:
|
||||
```
|
||||
|
||||
!!! note "Nota"
|
||||
Si no sabes la diferencia, revisa el [Async: *"¿Tienes prisa?"*](../async.md#in-a-hurry){.internal-link target=_blank}.
|
||||
Si no sabes la diferencia, revisa el [Async: *"¿Tienes prisa?"*](../async.md#tienes-prisa){.internal-link target=_blank}.
|
||||
|
||||
### Paso 5: devuelve el contenido
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ $ pip install "fastapi[all]"
|
||||
|
||||
...eso también incluye `uvicorn` que puedes usar como el servidor que ejecuta tu código.
|
||||
|
||||
!!! nota
|
||||
!!! note "Nota"
|
||||
También puedes instalarlo parte por parte.
|
||||
|
||||
Esto es lo que probablemente harías una vez que desees implementar tu aplicación en producción:
|
||||
|
||||
@@ -194,4 +194,4 @@ En este caso hay 3 parámetros de query:
|
||||
* `limit`, un `int` opcional.
|
||||
|
||||
!!! tip "Consejo"
|
||||
También podrías usar los `Enum`s de la misma manera que con los [Parámetros de path](path-params.md#predefined-values){.internal-link target=_blank}.
|
||||
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}.
|
||||
|
||||
@@ -69,4 +69,4 @@ $ uvicorn main:app --reload
|
||||
|
||||
و زیر برنامه ها نیز می تواند زیر برنامه های متصل شده خود را داشته باشد و همه چیز به درستی کار کند، زیرا FastAPI تمام این مسیرهای `root_path` را به طور خودکار مدیریت می کند.
|
||||
|
||||
در بخش [پشت پراکسی](./behind-a-proxy.md){.internal-link target=_blank}. درباره `root_path` و نحوه استفاده درست از آن بیشتر خواهید آموخت.
|
||||
در بخش [پشت پراکسی](behind-a-proxy.md){.internal-link target=_blank}. درباره `root_path` و نحوه استفاده درست از آن بیشتر خواهید آموخت.
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
---
|
||||
hide:
|
||||
- navigation
|
||||
---
|
||||
|
||||
<style>
|
||||
.md-content .md-typeset h1 { display: none; }
|
||||
</style>
|
||||
|
||||
<p align="center">
|
||||
<a href="https://fastapi.tiangolo.com"><img src="https://fastapi.tiangolo.com/img/logo-margin/logo-teal.png" alt="FastAPI"></a>
|
||||
</p>
|
||||
@@ -30,7 +39,7 @@ FastAPI یک وب فریمورک مدرن و سریع (با کارایی با
|
||||
|
||||
ویژگیهای کلیدی این فریمورک عبارتند از:
|
||||
|
||||
* **<abbr title="Fast">سرعت</abbr>**: کارایی بسیار بالا و قابل مقایسه با **NodeJS** و **Go** (با تشکر از Starlette و Pydantic). [یکی از سریعترین فریمورکهای پایتونی موجود](#performance).
|
||||
* **<abbr title="Fast">سرعت</abbr>**: کارایی بسیار بالا و قابل مقایسه با **NodeJS** و **Go** (با تشکر از Starlette و Pydantic). [یکی از سریعترین فریمورکهای پایتونی موجود](#_10).
|
||||
|
||||
* **<abbr title="Fast to code">کدنویسی سریع</abbr>**: افزایش ۲۰۰ تا ۳۰۰ درصدی سرعت توسعه قابلیتهای جدید. *
|
||||
* **<abbr title="Fewer bugs">باگ کمتر</abbr>**: کاهش ۴۰ درصدی خطاهای انسانی (برنامهنویسی). *
|
||||
@@ -447,12 +456,12 @@ item: Item
|
||||
* <a href="https://pythonhosted.org/itsdangerous/" target="_blank"><code>itsdangerous</code></a> - در صورتی که بخواید از `SessionMiddleware` پشتیبانی کنید.
|
||||
* <a href="https://pyyaml.org/wiki/PyYAMLDocumentation" target="_blank"><code>pyyaml</code></a> - برای پشتیبانی `SchemaGenerator` در Starlet (به احتمال زیاد برای کار کردن با FastAPI به آن نیازی پیدا نمیکنید).
|
||||
* <a href="https://graphene-python.org/" target="_blank"><code>graphene</code></a> - در صورتی که از `GraphQLApp` پشتیبانی میکنید.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - در صورتی که بخواهید از `UJSONResponse` استفاده کنید.
|
||||
|
||||
استفاده شده توسط FastAPI / Starlette:
|
||||
|
||||
* <a href="https://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - برای سرور اجرا کننده برنامه وب.
|
||||
* <a href="https://github.com/ijl/orjson" target="_blank"><code>orjson</code></a> - در صورتی که بخواهید از `ORJSONResponse` استفاده کنید.
|
||||
* <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - در صورتی که بخواهید از `UJSONResponse` استفاده کنید.
|
||||
|
||||
میتوان همه این موارد را با استفاده از دستور `pip install fastapi[all]`. به صورت یکجا نصب کرد.
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# Réponses supplémentaires dans OpenAPI
|
||||
|
||||
!!! Attention
|
||||
!!! warning "Attention"
|
||||
Ceci concerne un sujet plutôt avancé.
|
||||
|
||||
Si vous débutez avec **FastAPI**, vous n'en aurez peut-être pas besoin.
|
||||
@@ -27,10 +27,10 @@ Par exemple, pour déclarer une autre réponse avec un code HTTP `404` et un mod
|
||||
{!../../../docs_src/additional_responses/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! Remarque
|
||||
!!! note "Remarque"
|
||||
Gardez à l'esprit que vous devez renvoyer directement `JSONResponse`.
|
||||
|
||||
!!! Info
|
||||
!!! info
|
||||
La clé `model` ne fait pas partie d'OpenAPI.
|
||||
|
||||
**FastAPI** prendra le modèle Pydantic à partir de là, générera le `JSON Schema` et le placera au bon endroit.
|
||||
@@ -172,10 +172,10 @@ Par exemple, vous pouvez ajouter un type de média supplémentaire `image/png`,
|
||||
{!../../../docs_src/additional_responses/tutorial002.py!}
|
||||
```
|
||||
|
||||
!!! Remarque
|
||||
!!! note "Remarque"
|
||||
Notez que vous devez retourner l'image en utilisant directement un `FileResponse`.
|
||||
|
||||
!!! Info
|
||||
!!! info
|
||||
À moins que vous ne spécifiiez explicitement un type de média différent dans votre paramètre `responses`, FastAPI supposera que la réponse a le même type de média que la classe de réponse principale (par défaut `application/json`).
|
||||
|
||||
Mais si vous avez spécifié une classe de réponse personnalisée avec `None` comme type de média, FastAPI utilisera `application/json` pour toute réponse supplémentaire associée à un modèle.
|
||||
@@ -206,7 +206,7 @@ Vous voulez peut-être avoir des réponses prédéfinies qui s'appliquent à de
|
||||
|
||||
Dans ces cas, vous pouvez utiliser la technique Python "d'affection par décomposition" (appelé _unpacking_ en anglais) d'un `dict` avec `**dict_to_unpack` :
|
||||
|
||||
``` Python
|
||||
```Python
|
||||
old_dict = {
|
||||
"old key": "old value",
|
||||
"second old key": "second old value",
|
||||
@@ -216,7 +216,7 @@ new_dict = {**old_dict, "new key": "new value"}
|
||||
|
||||
Ici, `new_dict` contiendra toutes les paires clé-valeur de `old_dict` plus la nouvelle paire clé-valeur :
|
||||
|
||||
``` Python
|
||||
```Python
|
||||
{
|
||||
"old key": "old value",
|
||||
"second old key": "second old value",
|
||||
|
||||
@@ -18,7 +18,7 @@ Pour y parvenir, importez `JSONResponse` et renvoyez-y directement votre contenu
|
||||
{!../../../docs_src/additional_status_codes/tutorial001.py!}
|
||||
```
|
||||
|
||||
!!! Attention
|
||||
!!! warning "Attention"
|
||||
Lorsque vous renvoyez une `Response` directement, comme dans l'exemple ci-dessus, elle sera renvoyée directement.
|
||||
|
||||
Elle ne sera pas sérialisée avec un modèle.
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user