+
+---
+
+**নির্দেশিকা নথি**: https://fastapi.tiangolo.com
+
+**সোর্স কোড**: https://github.com/tiangolo/fastapi
+
+---
+
+FastAPI একটি আধুনিক, দ্রুত ( বেশি ক্ষমতা ) সম্পন্ন, Python 3.6+ দিয়ে API তৈরির জন্য স্ট্যান্ডার্ড পাইথন টাইপ ইঙ্গিত ভিত্তিক ওয়েব ফ্রেমওয়ার্ক।
+
+এর মূল বৈশিষ্ট্য গুলো হলঃ
+
+- **গতি**: এটি **NodeJS** এবং **Go** এর মত কার্যক্ষমতা সম্পন্ন (Starlette এবং Pydantic এর সাহায্যে)। [পাইথন এর দ্রুততম ফ্রেমওয়ার্ক গুলোর মধ্যে এটি একটি](#_11)।
+- **দ্রুত কোড করা**:বৈশিষ্ট্য তৈরির গতি ২০০% থেকে ৩০০% বৃদ্ধি করে৷ \*
+- **স্বল্প bugs**: মানুব (ডেভেলপার) সৃষ্ট ত্রুটির প্রায় ৪০% হ্রাস করে। \*
+- **স্বজ্ঞাত**: দুর্দান্ত এডিটর সাহায্য Completion নামেও পরিচিত। দ্রুত ডিবাগ করা যায়।
+
+- **সহজ**: এটি এমন ভাবে সজানো হয়েছে যেন নির্দেশিকা নথি পড়ে সহজে শেখা এবং ব্যবহার করা যায়।
+- **সংক্ষিপ্ত**: কোড পুনরাবৃত্তি কমানোর পাশাপাশি, bug কমায় এবং প্রতিটি প্যারামিটার ঘোষণা থেকে একাধিক ফিচার পাওয়া যায় ।
+- **জোরালো**: স্বয়ংক্রিয় ভাবে তৈরি ক্রিয়াশীল নির্দেশনা নথি (documentation) সহ উৎপাদন উপযোগি (Production-ready) কোড পাওয়া যায়।
+- **মান-ভিত্তিক**: এর ভিত্তি OpenAPI (যা পুর্বে Swagger নামে পরিচিত ছিল) এবং JSON Schema এর আদর্শের মানের ওপর
+
+\* উৎপাদনমুখি এপ্লিকেশন বানানোর এক দল ডেভেলপার এর মতামত ভিত্তিক ফলাফল।
+
+## স্পনসর গণ
+
+
+
+{% if sponsors %}
+{% for sponsor in sponsors.gold -%}
+
+{% endfor -%}
+{%- for sponsor in sponsors.silver -%}
+
+{% endfor %}
+{% endif %}
+
+
+
+অন্যান্য স্পনসর গণ
+
+## মতামত সমূহ
+
+"_আমি আজকাল **FastAPI** ব্যবহার করছি। [...] আমরা ভাবছি মাইক্রোসফ্টে **ML সার্ভিস** এ সকল দলের জন্য এটি ব্যবহার করব। যার মধ্যে কিছু পণ্য **Windows** এ সংযোযন হয় এবং কিছু **Office** এর সাথে সংযোযন হচ্ছে।_"
+
+
+
+---
+
+"_আমরা **FastAPI** লাইব্রেরি গ্রহণ করেছি একটি **REST** সার্ভার তৈরি করতে, যা **ভবিষ্যদ্বাণী** পাওয়ার জন্য কুয়েরি করা যেতে পারে। [লুডউইগের জন্য]_"
+
+
পিয়েরো মোলিনো, ইয়ারোস্লাভ দুদিন, এবং সাই সুমন্থ মিরিয়ালা - উবার(ref)
+
+---
+
+"_**Netflix** আমাদের **ক্রাইসিস ম্যানেজমেন্ট** অর্কেস্ট্রেশন ফ্রেমওয়ার্ক: **ডিসপ্যাচ** এর ওপেন সোর্স রিলিজ ঘোষণা করতে পেরে আনন্দিত! [যাকিনা **FastAPI** দিয়ে নির্মিত]_"
+
+
+
+---
+
+"\_সত্যিই, আপনি যা তৈরি করেছেন তা খুব মজবুত এবং পরিপূর্ন৷ অনেক উপায়ে, আমি যা **Hug** এ করতে চেয়েছিলাম - তা কাউকে তৈরি করতে দেখে আমি সত্যিই অনুপ্রানিত৷\_"
+
+
+
+---
+
+"আপনি যদি REST API তৈরির জন্য একটি **আধুনিক ফ্রেমওয়ার্ক** শিখতে চান, তাহলে **FastAPI** দেখুন [...] এটি দ্রুত, ব্যবহার করা সহজ এবং শিখতেও সহজ [...]\_"
+
+"_আমরা আমাদের **APIs** [...] এর জন্য **FastAPI**- তে এসেছি [...] আমি মনে করি আপনিও এটি পছন্দ করবেন [...]_"
+
+
+
+---
+
+## **Typer**, CLI এর জন্য FastAPI
+
+
+
+আপনি যদি CLI অ্যাপ বানাতে চান, যা কিনা ওয়েব API এর পরিবর্তে টার্মিনালে ব্যবহার হবে, তাহলে দেখুন**Typer**.
+
+**টাইপার** হল FastAPI এর ছোট ভাইয়ের মত। এবং এটির উদ্দেশ্য ছিল **CLIs এর FastAPI** হওয়া। ⌨️ 🚀
+
+## প্রয়োজনীয়তা গুলো
+
+Python 3.7+
+
+FastAPI কিছু দানবেদের কাঁধে দাঁড়িয়ে আছে:
+
+- Starlette ওয়েব অংশের জন্য.
+- Pydantic ডেটা অংশগুলির জন্য.
+
+## ইনস্টলেশন প্রক্রিয়া
+
+
+
+## উদাহরণ
+
+### তৈরি
+
+- `main.py` নামে একটি ফাইল তৈরি করুন:
+
+```Python
+from typing import Union
+
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.get("/")
+def read_root():
+ return {"Hello": "World"}
+
+
+@app.get("/items/{item_id}")
+def read_item(item_id: int, q: Union[str, None] = None):
+ return {"item_id": item_id, "q": q}
+```
+
+
+অথবা ব্যবহার করুন async def...
+
+যদি আপনার কোড `async` / `await`, ব্যবহার করে তাহলে `async def` ব্যবহার করুন:
+
+```Python hl_lines="9 14"
+from typing import Union
+
+from fastapi import FastAPI
+
+app = FastAPI()
+
+
+@app.get("/")
+async def read_root():
+ return {"Hello": "World"}
+
+
+@app.get("/items/{item_id}")
+async def read_item(item_id: int, q: Union[str, None] = None):
+ return {"item_id": item_id, "q": q}
+```
+
+**টীকা**:
+
+আপনি যদি না জানেন, _"তাড়াহুড়ো?"_ বিভাগটি দেখুন `async` এবং `await` নথির মধ্যে দেখুন .
+
+
+
+### এটি চালান
+
+সার্ভার চালু করুন:
+
+
+
+```console
+$ uvicorn main:app --reload
+
+INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
+INFO: Started reloader process [28720]
+INFO: Started server process [28722]
+INFO: Waiting for application startup.
+INFO: Application startup complete.
+```
+
+
+
+
+নির্দেশনা সম্পর্কে uvicorn main:app --reload...
+
+`uvicorn main:app` নির্দেশনাটি দ্বারা বোঝায়:
+
+- `main`: ফাইল `main.py` (পাইথন "মডিউল")।
+- `app`: `app = FastAPI()` লাইন দিয়ে `main.py` এর ভিতরে তৈরি করা অবজেক্ট।
+- `--reload`: কোড পরিবর্তনের পরে সার্ভার পুনরায় চালু করুন। এটি শুধুমাত্র ডেভেলপমেন্ট এর সময় ব্যবহার করুন।
+
+
+
+### এটা চেক করুন
+
+আপনার ব্রাউজার খুলুন http://127.0.0.1:8000/items/5?q=somequery এ।
+
+আপনি JSON রেসপন্স দেখতে পাবেন:
+
+```JSON
+{"item_id": 5, "q": "somequery"}
+```
+
+আপনি ইতিমধ্যে একটি API তৈরি করেছেন যা:
+
+- `/` এবং `/items/{item_id}` _paths_ এ HTTP অনুরোধ গ্রহণ করে।
+- উভয় *path*ই `GET` অপারেশন নেয় ( যা HTTP _methods_ নামেও পরিচিত)।
+- _path_ `/items/{item_id}`-এ একটি _path প্যারামিটার_ `item_id` আছে যা কিনা `int` হতে হবে।
+- _path_ `/items/{item_id}`-এর একটি ঐচ্ছিক `str` _query প্যারামিটার_ `q` আছে।
+
+### ক্রিয়াশীল API নির্দেশিকা নথি
+
+এখন যান http://127.0.0.1:8000/docs.
+
+আপনি স্বয়ংক্রিয় ভাবে প্রস্তুত ক্রিয়াশীল API নির্দেশিকা নথি দেখতে পাবেন (Swagger UI প্রদত্ত):
+
+
+
+### বিকল্প API নির্দেশিকা নথি
+
+এবং এখন http://127.0.0.1:8000/redoc এ যান.
+
+আপনি স্বয়ংক্রিয় ভাবে প্রস্তুত বিকল্প নির্দেশিকা নথি দেখতে পাবেন (ReDoc প্রদত্ত):
+
+
+
+## উদাহরণস্বরূপ আপগ্রেড
+
+এখন `main.py` ফাইলটি পরিবর্তন করুন যেন এটি `PUT` রিকুয়েস্ট থেকে বডি পেতে পারে।
+
+Python স্ট্যান্ডার্ড লাইব্রেরি, Pydantic এর সাহায্যে বডি ঘোষণা করুন।
+
+```Python hl_lines="4 9-12 25-27"
+from typing import Union
+
+from fastapi import FastAPI
+from pydantic import BaseModel
+
+app = FastAPI()
+
+
+class Item(BaseModel):
+ name: str
+ price: float
+ is_offer: Union[bool, None] = None
+
+
+@app.get("/")
+def read_root():
+ return {"Hello": "World"}
+
+
+@app.get("/items/{item_id}")
+def read_item(item_id: int, q: Union[str, None] = None):
+ return {"item_id": item_id, "q": q}
+
+
+@app.put("/items/{item_id}")
+def update_item(item_id: int, item: Item):
+ return {"item_name": item.name, "item_id": item_id}
+```
+
+সার্ভারটি স্বয়ংক্রিয়ভাবে পুনরায় লোড হওয়া উচিত (কারণ আপনি উপরের `uvicorn` কমান্ডে `--reload` যোগ করেছেন)।
+
+### ক্রিয়াশীল API নির্দেশিকা নথি উন্নীতকরণ
+
+এখন http://127.0.0.1:8000/docs এডড্রেসে যান.
+
+- ক্রিয়াশীল API নির্দেশিকা নথিটি স্বয়ংক্রিয়ভাবে উন্নীত হযে যাবে, নতুন বডি সহ:
+
+
+
+- "Try it out" বাটনে চাপুন, এটি আপনাকে পেরামিটারগুলো পূরণ করতে এবং API এর সাথে সরাসরি ক্রিয়া-কলাপ করতে দিবে:
+
+
+
+- তারপরে "Execute" বাটনে চাপুন, ব্যবহারকারীর ইন্টারফেস আপনার API এর সাথে যোগাযোগ করবে, পেরামিটার পাঠাবে, ফলাফলগুলি পাবে এবং সেগুলি পর্রদায় দেখাবে:
+
+
+
+### বিকল্প API নির্দেশিকা নথি আপগ্রেড
+
+এবং এখন http://127.0.0.1:8000/redoc এ যান।
+
+- বিকল্প নির্দেশিকা নথিতেও নতুন কুয়েরি প্যারামিটার এবং বডি প্রতিফলিত হবে:
+
+
+
+### সংক্ষিপ্তকরণ
+
+সংক্ষেপে, আপনি **শুধু একবার** প্যারামিটারের ধরন, বডি ইত্যাদি ফাংশন প্যারামিটার হিসেবে ঘোষণা করেন।
+
+আপনি সেটি আধুনিক পাইথনের সাথে করেন।
+
+আপনাকে নতুন করে নির্দিষ্ট কোন লাইব্রেরির বাক্য গঠন, ফাংশন বা ক্লাস কিছুই শিখতে হচ্ছে না।
+
+শুধুই আধুনিক **Python 3.6+**
+
+উদাহরণস্বরূপ, `int` এর জন্য:
+
+```Python
+item_id: int
+```
+
+অথবা আরও জটিল `Item` মডেলের জন্য:
+
+```Python
+item: Item
+```
+
+...এবং সেই একই ঘোষণার সাথে আপনি পাবেন:
+
+- এডিটর সাহায্য, যেমন
+ - সমাপ্তি।
+ - ধরণ যাচাই
+- তথ্য যাচাইকরণ:
+ - ডেটা অবৈধ হলে স্বয়ংক্রিয় এবং পরিষ্কার ত্রুটির নির্দেশনা।
+ - এমনকি গভীরভাবে নেস্ট করা JSON অবজেক্টের জন্য বৈধতা।
+- প্রেরিত তথ্য রূপান্তর: যা নেটওয়ার্ক থেকে পাইথনের তথ্য এবং ধরনে আসে, এবং সেখান থেকে পড়া:
+
+ - JSON।
+ - পাথ প্যারামিটার।
+ - কুয়েরি প্যারামিটার।
+ - কুকিজ
+ - হেডার
+ - ফর্ম
+ - ফাইল
+
+- আউটপুট ডেটার রূপান্তর: পাইথন ডেটা এবং টাইপ থেকে নেটওয়ার্ক ডেটাতে রূপান্তর করা (JSON হিসাবে):
+ -পাইথন টাইপে রূপান্তর করুন (`str`, `int`, `float`, `bool`, `list`, ইত্যাদি)।
+ - `datetime` অবজেক্ট।
+ - `UUID` objeঅবজেক্টcts।
+ - ডাটাবেস মডেল।
+ - ...এবং আরো অনেক।
+- স্বয়ংক্রিয় ক্রিয়াশীল API নির্দেশিকা নথি, 2টি বিকল্প ব্যবহারকারীর ইন্টারফেস সহ:
+ - সোয়াগার ইউ আই (Swagger UI)।
+ - রিডক (ReDoc)।
+
+---
+
+পূর্ববর্তী কোড উদাহরণে ফিরে আসা যাক, **FastAPI** যা করবে:
+
+- `GET` এবং `PUT` অনুরোধের জন্য পথে `item_id` আছে কিনা তা যাচাই করবে।
+- `GET` এবং `PUT` অনুরোধের জন্য `item_id` টাইপ `int` এর হতে হবে তা যাচাই করবে।
+ - যদি না হয় তবে ক্লায়েন্ট একটি উপযুক্ত, পরিষ্কার ত্রুটি দেখতে পাবেন।
+- `GET` অনুরোধের জন্য একটি ঐচ্ছিক ক্যুয়েরি প্যারামিটার নামক `q` (যেমন `http://127.0.0.1:8000/items/foo?q=somequery`) আছে কি তা চেক করবে।
+ - যেহেতু `q` প্যারামিটারটি `= None` দিয়ে ঘোষণা করা হয়েছে, তাই এটি ঐচ্ছিক।
+ - `None` ছাড়া এটি প্রয়োজনীয় হতো (যেমন `PUT` এর ক্ষেত্রে হয়েছে)।
+- `/items/{item_id}` এর জন্য `PUT` অনুরোধের বডি JSON হিসাবে পড়ুন:
+ - লক্ষ করুন, `name` একটি প্রয়োজনীয় অ্যাট্রিবিউট হিসাবে বিবেচনা করেছে এবং এটি `str` হতে হবে।
+ - লক্ষ করুন এখানে, `price` অ্যাট্রিবিউটটি আবশ্যক এবং এটি `float` হতে হবে।
+ - লক্ষ করুন `is_offer` একটি ঐচ্ছিক অ্যাট্রিবিউট এবং এটি `bool` হতে হবে যদি উপস্থিত থাকে।
+ - এই সবটি গভীরভাবে অবস্থানরত JSON অবজেক্টগুলিতেও কাজ করবে।
+- স্বয়ংক্রিয়ভাবে JSON হতে এবং JSON থেকে কনভার্ট করুন।
+- OpenAPI দিয়ে সবকিছু ডকুমেন্ট করুন, যা ব্যবহার করা যেতে পারে:
+ - ক্রিয়াশীল নির্দেশিকা নথি।
+ - অনেক ভাষার জন্য স্বয়ংক্রিয় ক্লায়েন্ট কোড তৈরির ব্যবস্থা।
+- সরাসরি 2টি ক্রিয়াশীল নির্দেশিকা নথি ওয়েব পৃষ্ঠ প্রদান করা হয়েছে।
+
+---
+
+আমরা এতক্ষন শুধু এর পৃষ্ঠ তৈরি করেছি, কিন্তু আপনি ইতমধ্যেই এটি কিভাবে কাজ করে তার ধারণাও পেয়ে গিয়েছেন।
+
+নিম্নোক্ত লাইন গুলো পরিবর্তন করার চেষ্টা করুন:
+
+```Python
+ return {"item_name": item.name, "item_id": item_id}
+```
+
+...পুর্বে:
+
+```Python
+ ... "item_name": item.name ...
+```
+
+...পরবর্তীতে:
+
+```Python
+ ... "item_price": item.price ...
+```
+
+...এবং দেখুন কিভাবে আপনার এডিটর উপাদানগুলোকে সয়ংক্রিয়ভাবে-সম্পন্ন করবে এবং তাদের ধরন জানতে পারবে:
+
+
+
+আরও বৈশিষ্ট্য সম্পন্ন উদাহরণের জন্য, দেখুন টিউটোরিয়াল - ব্যবহারকারীর গাইড.
+
+**স্পয়লার সতর্কতা**: টিউটোরিয়াল - ব্যবহারকারীর গাইড নিম্নোক্ত বিষয়গুলি অন্তর্ভুক্ত করে:
+
+- **হেডার**, **কুকিজ**, **ফর্ম ফিল্ড** এবং **ফাইলগুলি** এমন অন্যান্য জায়গা থেকে প্যারামিটার ঘোষণা করা।
+- `maximum_length` বা `regex` এর মতো **যাচাইকরণ বাধামুক্তি** সেট করা হয় কিভাবে, তা নিয়ে আলোচনা করা হবে।
+- একটি খুব শক্তিশালী এবং ব্যবহার করা সহজ ডিপেন্ডেন্সি ইনজেকশন পদ্ধতি
+- **OAuth2** এবং **JWT টোকেন** এবং **HTTP Basic** auth সহ নিরাপত্তা এবং অনুমোদনপ্রাপ্তি সম্পর্কিত বিষয়সমূহের উপর।
+- **গভীরভাবে অবস্থানরত JSON মডেল** ঘোষণা করার জন্য আরও উন্নত (কিন্তু সমান সহজ) কৌশল (Pydantic কে ধন্যবাদ)।
+- আরো অতিরিক্ত বৈশিষ্ট্য (স্টারলেটকে ধন্যবাদ) হিসাবে:
+ - **WebSockets**
+ - **GraphQL**
+ - HTTPX এবং `pytest` ভিত্তিক অত্যন্ত সহজ পরীক্ষা
+ - **CORS**
+ - **Cookie Sessions**
+ - ...এবং আরো।
+
+## কর্মক্ষমতা
+
+স্বাধীন TechEmpower Benchmarks দেখায় যে **FastAPI** অ্যাপ্লিকেশনগুলি Uvicorn-এর অধীনে চলমান দ্রুততমপাইথন ফ্রেমওয়ার্কগুলির মধ্যে একটি, শুধুমাত্র Starlette এবং Uvicorn-এর পর (FastAPI দ্বারা অভ্যন্তরীণভাবে ব্যবহৃত)। (\*)
+
+এটি সম্পর্কে আরও বুঝতে, দেখুন Benchmarks.
+
+## ঐচ্ছিক নির্ভরশীলতা
+
+Pydantic দ্বারা ব্যবহৃত:
+
+- ujson - দ্রুত JSON এর জন্য "parsing".
+- email_validator - ইমেল যাচাইকরণের জন্য।
+
+স্টারলেট দ্বারা ব্যবহৃত:
+
+- httpx - আপনি যদি `TestClient` ব্যবহার করতে চান তাহলে আবশ্যক।
+- jinja2 - আপনি যদি প্রদত্ত টেমপ্লেট রূপরেখা ব্যবহার করতে চান তাহলে প্রয়োজন।
+- python-multipart - আপনি যদি ফর্ম সহায়তা করতে চান তাহলে প্রয়োজন "parsing", `request.form()` সহ।
+- itsdangerous - `SessionMiddleware` সহায়তার জন্য প্রয়োজন।
+- pyyaml - স্টারলেটের SchemaGenerator সাপোর্ট এর জন্য প্রয়োজন (আপনার সম্ভাবত FastAPI প্রয়োজন নেই)।
+- graphene - `GraphQLApp` সহায়তার জন্য প্রয়োজন।
+- ujson - আপনি `UJSONResponse` ব্যবহার করতে চাইলে প্রয়োজন।
+
+FastAPI / Starlette দ্বারা ব্যবহৃত:
+
+- uvicorn - সার্ভারের জন্য যা আপনার অ্যাপ্লিকেশন লোড করে এবং পরিবেশন করে।
+- orjson - আপনি `ORJSONResponse` ব্যবহার করতে চাইলে প্রয়োজন।
+
+আপনি এই সব ইনস্টল করতে পারেন `pip install fastapi[all]` দিয়ে.
+
+## লাইসেন্স
+
+এই প্রজেক্ট MIT লাইসেন্স নীতিমালার অধীনে শর্তায়িত।
diff --git a/docs/bn/mkdocs.yml b/docs/bn/mkdocs.yml
new file mode 100644
index 0000000000..de18856f44
--- /dev/null
+++ b/docs/bn/mkdocs.yml
@@ -0,0 +1 @@
+INHERIT: ../en/mkdocs.yml
diff --git a/docs/de/docs/tutorial/background-tasks.md b/docs/de/docs/tutorial/background-tasks.md
new file mode 100644
index 0000000000..a7bfd55a7d
--- /dev/null
+++ b/docs/de/docs/tutorial/background-tasks.md
@@ -0,0 +1,126 @@
+# Hintergrundtasks
+
+Sie können Hintergrundtasks (Hintergrund-Aufgaben) definieren, die *nach* der Rückgabe einer Response ausgeführt werden sollen.
+
+Das ist nützlich für Vorgänge, die nach einem Request ausgeführt werden müssen, bei denen der Client jedoch nicht unbedingt auf den Abschluss des Vorgangs warten muss, bevor er die Response erhält.
+
+Hierzu zählen beispielsweise:
+
+* E-Mail-Benachrichtigungen, die nach dem Ausführen einer Aktion gesendet werden:
+ * Da die Verbindung zu einem E-Mail-Server und das Senden einer E-Mail in der Regel „langsam“ ist (einige Sekunden), können Sie die Response sofort zurücksenden und die E-Mail-Benachrichtigung im Hintergrund senden.
+* Daten verarbeiten:
+ * Angenommen, Sie erhalten eine Datei, die einen langsamen Prozess durchlaufen muss. Sie können als Response „Accepted“ (HTTP 202) zurückgeben und die Datei im Hintergrund verarbeiten.
+
+## `BackgroundTasks` verwenden
+
+Importieren Sie zunächst `BackgroundTasks` und definieren Sie einen Parameter in Ihrer *Pfadoperation-Funktion* mit der Typdeklaration `BackgroundTasks`:
+
+```Python hl_lines="1 13"
+{!../../../docs_src/background_tasks/tutorial001.py!}
+```
+
+**FastAPI** erstellt für Sie das Objekt vom Typ `BackgroundTasks` und übergibt es als diesen Parameter.
+
+## Eine Taskfunktion erstellen
+
+Erstellen Sie eine Funktion, die als Hintergrundtask ausgeführt werden soll.
+
+Es handelt sich schlicht um eine Standard-Funktion, die Parameter empfangen kann.
+
+Es kann sich um eine `async def`- oder normale `def`-Funktion handeln. **FastAPI** weiß, wie damit zu verfahren ist.
+
+In diesem Fall schreibt die Taskfunktion in eine Datei (den Versand einer E-Mail simulierend).
+
+Und da der Schreibvorgang nicht `async` und `await` verwendet, definieren wir die Funktion mit normalem `def`:
+
+```Python hl_lines="6-9"
+{!../../../docs_src/background_tasks/tutorial001.py!}
+```
+
+## Den Hintergrundtask hinzufügen
+
+Übergeben Sie innerhalb Ihrer *Pfadoperation-Funktion* Ihre Taskfunktion mit der Methode `.add_task()` an das *Hintergrundtasks*-Objekt:
+
+```Python hl_lines="14"
+{!../../../docs_src/background_tasks/tutorial001.py!}
+```
+
+`.add_task()` erhält als Argumente:
+
+* Eine Taskfunktion, die im Hintergrund ausgeführt wird (`write_notification`).
+* Eine beliebige Folge von Argumenten, die der Reihe nach an die Taskfunktion übergeben werden sollen (`email`).
+* Alle Schlüsselwort-Argumente, die an die Taskfunktion übergeben werden sollen (`message="some notification"`).
+
+## Dependency Injection
+
+Die Verwendung von `BackgroundTasks` funktioniert auch mit dem Dependency Injection System. Sie können einen Parameter vom Typ `BackgroundTasks` auf mehreren Ebenen deklarieren: in einer *Pfadoperation-Funktion*, in einer Abhängigkeit (Dependable), in einer Unterabhängigkeit usw.
+
+**FastAPI** weiß, was jeweils zu tun ist und wie dasselbe Objekt wiederverwendet werden kann, sodass alle Hintergrundtasks zusammengeführt und anschließend im Hintergrund ausgeführt werden:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="13 15 22 25"
+ {!> ../../../docs_src/background_tasks/tutorial002_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="13 15 22 25"
+ {!> ../../../docs_src/background_tasks/tutorial002_an_py39.py!}
+ ```
+
+=== "Python 3.8+"
+
+ ```Python hl_lines="14 16 23 26"
+ {!> ../../../docs_src/background_tasks/tutorial002_an.py!}
+ ```
+
+=== "Python 3.10+ nicht annotiert"
+
+ !!! tip "Tipp"
+ Bevorzugen Sie die `Annotated`-Version, falls möglich.
+
+ ```Python hl_lines="11 13 20 23"
+ {!> ../../../docs_src/background_tasks/tutorial002_py310.py!}
+ ```
+
+=== "Python 3.8+ nicht annotiert"
+
+ !!! tip "Tipp"
+ Bevorzugen Sie die `Annotated`-Version, falls möglich.
+
+ ```Python hl_lines="13 15 22 25"
+ {!> ../../../docs_src/background_tasks/tutorial002.py!}
+ ```
+
+In obigem Beispiel werden die Nachrichten, *nachdem* die Response gesendet wurde, in die Datei `log.txt` geschrieben.
+
+Wenn im Request ein Query-Parameter enthalten war, wird dieser in einem Hintergrundtask in das Log geschrieben.
+
+Und dann schreibt ein weiterer Hintergrundtask, der in der *Pfadoperation-Funktion* erstellt wird, eine Nachricht unter Verwendung des Pfad-Parameters `email`.
+
+## Technische Details
+
+Die Klasse `BackgroundTasks` stammt direkt von `starlette.background`.
+
+Sie wird direkt in FastAPI importiert/inkludiert, sodass Sie sie von `fastapi` importieren können und vermeiden, versehentlich das alternative `BackgroundTask` (ohne das `s` am Ende) von `starlette.background` zu importieren.
+
+Indem Sie nur `BackgroundTasks` (und nicht `BackgroundTask`) verwenden, ist es dann möglich, es als *Pfadoperation-Funktion*-Parameter zu verwenden und **FastAPI** den Rest für Sie erledigen zu lassen, genau wie bei der direkten Verwendung des `Request`-Objekts.
+
+Es ist immer noch möglich, `BackgroundTask` allein in FastAPI zu verwenden, aber Sie müssen das Objekt in Ihrem Code erstellen und eine Starlette-`Response` zurückgeben, die es enthält.
+
+Weitere Details finden Sie in der offiziellen Starlette-Dokumentation für Hintergrundtasks.
+
+## Vorbehalt
+
+Wenn Sie umfangreiche Hintergrundberechnungen durchführen müssen und diese nicht unbedingt vom selben Prozess ausgeführt werden müssen (z. B. müssen Sie Speicher, Variablen, usw. nicht gemeinsam nutzen), könnte die Verwendung anderer größerer Tools wie z. B. Celery von Vorteil sein.
+
+Sie erfordern in der Regel komplexere Konfigurationen und einen Nachrichten-/Job-Queue-Manager wie RabbitMQ oder Redis, ermöglichen Ihnen jedoch die Ausführung von Hintergrundtasks in mehreren Prozessen und insbesondere auf mehreren Servern.
+
+Um ein Beispiel zu sehen, sehen Sie sich die [Projektgeneratoren](../project-generation.md){.internal-link target=_blank} an. Sie alle enthalten Celery, bereits konfiguriert.
+
+Wenn Sie jedoch über dieselbe **FastAPI**-Anwendung auf Variablen und Objekte zugreifen oder kleine Hintergrundtasks ausführen müssen (z. B. das Senden einer E-Mail-Benachrichtigung), können Sie einfach `BackgroundTasks` verwenden.
+
+## Zusammenfassung
+
+Importieren und verwenden Sie `BackgroundTasks` mit Parametern in *Pfadoperation-Funktionen* und Abhängigkeiten, um Hintergrundtasks hinzuzufügen.
diff --git a/docs/de/docs/tutorial/first-steps.md b/docs/de/docs/tutorial/first-steps.md
index 5997f138f0..27ba3ec167 100644
--- a/docs/de/docs/tutorial/first-steps.md
+++ b/docs/de/docs/tutorial/first-steps.md
@@ -43,7 +43,7 @@ Diese Zeile zeigt die URL, unter der Ihre Anwendung auf Ihrem lokalen Computer b
Öffnen Sie Ihren Browser unter http://127.0.0.1:8000.
-Sie werden folgende JSON-Antwort sehen:
+Sie werden folgende JSON-Response sehen:
```JSON
{"message": "Hello World"}
@@ -81,7 +81,7 @@ Diese Schemadefinition enthält Ihre API-Pfade, die möglichen Parameter, welche
#### Daten-„Schema“
-Der Begriff „Schema“ kann sich auch auf die Form von Daten beziehen, wie z.B. einen JSON-Inhalt.
+Der Begriff „Schema“ kann sich auch auf die Form von Daten beziehen, wie z. B. einen JSON-Inhalt.
In diesem Fall sind die JSON-Attribute und deren Datentypen, usw. gemeint.
@@ -328,6 +328,6 @@ Es gibt viele andere Objekte und Modelle, die automatisch zu JSON konvertiert we
* Importieren Sie `FastAPI`.
* Erstellen Sie eine `app` Instanz.
-* Schreiben Sie einen **Pfadoperation-Dekorator** (wie z.B. `@app.get("/")`).
-* Schreiben Sie eine **Pfadoperation-Funktion** (wie z.B. oben `def root(): ...`).
-* Starten Sie den Entwicklungsserver (z.B. `uvicorn main:app --reload`).
+* Schreiben Sie einen **Pfadoperation-Dekorator** (wie z. B. `@app.get("/")`).
+* Schreiben Sie eine **Pfadoperation-Funktion** (wie z. B. oben `def root(): ...`).
+* Starten Sie den Entwicklungsserver (z. B. `uvicorn main:app --reload`).
diff --git a/docs/de/docs/tutorial/index.md b/docs/de/docs/tutorial/index.md
new file mode 100644
index 0000000000..dd7ed43bda
--- /dev/null
+++ b/docs/de/docs/tutorial/index.md
@@ -0,0 +1,80 @@
+# Tutorial - Benutzerhandbuch - Intro
+
+Diese Anleitung zeigt Ihnen Schritt für Schritt, wie Sie **FastAPI** mit den meisten Funktionen nutzen können.
+
+Jeder Abschnitt baut schrittweise auf den vorhergehenden auf. Diese Abschnitte sind aber nach einzelnen Themen gegliedert, sodass Sie direkt zu einem bestimmten Thema übergehen können, um Ihre speziellen API-Anforderungen zu lösen.
+
+Außerdem dienen diese als zukünftige Referenz.
+
+Dadurch können Sie jederzeit zurückkommen und sehen genau das, was Sie benötigen.
+
+## Den Code ausführen
+
+Alle Codeblöcke können kopiert und direkt verwendet werden (da es sich um getestete Python-Dateien handelt).
+
+Um eines der Beispiele auszuführen, kopieren Sie den Code in die Datei `main.py`, und starten Sie `uvicorn` mit:
+
+
+
+```console
+$ uvicorn main:app --reload
+
+INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
+INFO: Started reloader process [28720]
+INFO: Started server process [28722]
+INFO: Waiting for application startup.
+INFO: Application startup complete.
+```
+
+
+
+Es wird **ausdrücklich empfohlen**, dass Sie den Code schreiben oder kopieren, ihn bearbeiten und lokal ausführen.
+
+Die Verwendung in Ihrem eigenen Editor zeigt Ihnen die Vorteile von FastAPI am besten, wenn Sie sehen, wie wenig Code Sie schreiben müssen, all die Typprüfungen, die automatische Vervollständigung usw.
+
+---
+
+## FastAPI installieren
+
+Der erste Schritt besteht aus der Installation von FastAPI.
+
+Für dieses Tutorial empfiehlt es sich, FastAPI mit allen optionalen Abhängigkeiten und Funktionen zu installieren:
+
+
+
+...dies beinhaltet auch `uvicorn`, das Sie als Server verwenden können, auf dem Ihr Code läuft.
+
+!!! Hinweis
+ Sie können die Installation auch in einzelnen Schritten ausführen.
+
+ Dies werden Sie wahrscheinlich tun, wenn Sie Ihre Anwendung produktiv einsetzen möchten:
+
+ ```
+ pip install fastapi
+ ```
+
+ Installieren Sie auch `uvicorn`, dies arbeitet als Server:
+
+ ```
+ pip install "uvicorn[standard]"
+ ```
+
+ Dasselbe gilt für jede der optionalen Abhängigkeiten, die Sie verwenden möchten.
+
+## Erweitertes Benutzerhandbuch
+
+Zusätzlich gibt es ein **Erweitertes Benutzerhandbuch**, dies können Sie später nach diesem **Tutorial - Benutzerhandbuch** lesen.
+
+Das **Erweiterte Benutzerhandbuch** baut auf dieses Tutorial auf, verwendet dieselben Konzepte und bringt Ihnen zusätzliche Funktionen bei.
+
+Allerdings sollten Sie zuerst das **Tutorial - Benutzerhandbuch** lesen (was Sie gerade lesen).
+
+Es ist so konzipiert, dass Sie nur mit dem **Tutorial - Benutzerhandbuch** eine vollständige Anwendung erstellen können und diese dann je nach Bedarf mit einigen der zusätzlichen Ideen aus dem **Erweiterten Benutzerhandbuch** erweitern können.
diff --git a/docs/em/docs/advanced/security/oauth2-scopes.md b/docs/em/docs/advanced/security/oauth2-scopes.md
index a4684352cc..d82fe152be 100644
--- a/docs/em/docs/advanced/security/oauth2-scopes.md
+++ b/docs/em/docs/advanced/security/oauth2-scopes.md
@@ -56,7 +56,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.
🥇, ➡️ 🔜 👀 🍕 👈 🔀 ⚪️➡️ 🖼 👑 **🔰 - 👩💻 🦮** [Oauth2️⃣ ⏮️ 🔐 (& 🔁), 📨 ⏮️ 🥙 🤝](../../tutorial/security/oauth2-jwt.md){.internal-link target=_blank}. 🔜 ⚙️ Oauth2️⃣ ↔:
-```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
+```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!../../../docs_src/security/tutorial005.py!}
```
@@ -93,7 +93,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.
✋️ 👆 🈸, 💂♂, 👆 🔜 ⚒ 💭 👆 🕴 🚮 ↔ 👈 👩💻 🤙 💪 ✔️, ⚖️ 🕐 👆 ✔️ 🔁.
-```Python hl_lines="153"
+```Python hl_lines="155"
{!../../../docs_src/security/tutorial005.py!}
```
@@ -118,7 +118,7 @@ Oauth2️⃣ 🔧 🔬 "↔" 📇 🎻 🎏 🚀.
👥 🔨 ⚫️ 📥 🎦 ❔ **FastAPI** 🍵 ↔ 📣 🎏 🎚.
-```Python hl_lines="4 139 166"
+```Python hl_lines="4 139 168"
{!../../../docs_src/security/tutorial005.py!}
```
diff --git a/docs/em/docs/tutorial/bigger-applications.md b/docs/em/docs/tutorial/bigger-applications.md
index 7b4694387d..c30bba106a 100644
--- a/docs/em/docs/tutorial/bigger-applications.md
+++ b/docs/em/docs/tutorial/bigger-applications.md
@@ -79,7 +79,7 @@
👆 🗄 ⚫️ & ✍ "👐" 🎏 🌌 👆 🔜 ⏮️ 🎓 `FastAPI`:
-```Python hl_lines="1 3"
+```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -89,7 +89,7 @@
⚙️ ⚫️ 🎏 🌌 👆 🔜 ⚙️ `FastAPI` 🎓:
-```Python hl_lines="6 11 16"
+```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -112,7 +112,7 @@
👥 🔜 🔜 ⚙️ 🙅 🔗 ✍ 🛃 `X-Token` 🎚:
-```Python hl_lines="1 4-6"
+```Python hl_lines="1 4-6" title="app/dependencies.py"
{!../../../docs_src/bigger_applications/app/dependencies.py!}
```
@@ -143,7 +143,7 @@
, ↩️ ❎ 🌐 👈 🔠 *➡ 🛠️*, 👥 💪 🚮 ⚫️ `APIRouter`.
-```Python hl_lines="5-10 16 21"
+```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -195,7 +195,7 @@ async def read_item(item_id: str):
👥 ⚙️ ⚖ 🗄 ⏮️ `..` 🔗:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -265,7 +265,7 @@ that 🔜 ⛓:
✋️ 👥 💪 🚮 _🌅_ `tags` 👈 🔜 ✔ 🎯 *➡ 🛠️*, & ➕ `responses` 🎯 👈 *➡ 🛠️*:
-```Python hl_lines="30-31"
+```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -290,7 +290,7 @@ that 🔜 ⛓:
& 👥 💪 📣 [🌐 🔗](dependencies/global-dependencies.md){.internal-link target=_blank} 👈 🔜 🌀 ⏮️ 🔗 🔠 `APIRouter`:
-```Python hl_lines="1 3 7"
+```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -298,7 +298,7 @@ that 🔜 ⛓:
🔜 👥 🗄 🎏 🔁 👈 ✔️ `APIRouter`Ⓜ:
-```Python hl_lines="5"
+```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -360,7 +360,7 @@ from .routers.users import router
, 💪 ⚙️ 👯♂️ 👫 🎏 📁, 👥 🗄 🔁 🔗:
-```Python hl_lines="4"
+```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -368,7 +368,7 @@ from .routers.users import router
🔜, ➡️ 🔌 `router`Ⓜ ⚪️➡️ 🔁 `users` & `items`:
-```Python hl_lines="10-11"
+```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -401,7 +401,7 @@ from .routers.users import router
👉 🖼 ⚫️ 🔜 💎 🙅. ✋️ ➡️ 💬 👈 ↩️ ⚫️ 💰 ⏮️ 🎏 🏗 🏢, 👥 🚫🔜 🔀 ⚫️ & 🚮 `prefix`, `dependencies`, `tags`, ♒️. 🔗 `APIRouter`:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```
@@ -409,7 +409,7 @@ from .routers.users import router
👥 💪 📣 🌐 👈 🍵 ✔️ 🔀 ⏮️ `APIRouter` 🚶♀️ 👈 🔢 `app.include_router()`:
-```Python hl_lines="14-17"
+```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -432,7 +432,7 @@ from .routers.users import router
📥 👥 ⚫️... 🎦 👈 👥 💪 🤷:
-```Python hl_lines="21-23"
+```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
diff --git a/docs/em/docs/tutorial/security/oauth2-jwt.md b/docs/em/docs/tutorial/security/oauth2-jwt.md
index bc207c5666..bc3c943f86 100644
--- a/docs/em/docs/tutorial/security/oauth2-jwt.md
+++ b/docs/em/docs/tutorial/security/oauth2-jwt.md
@@ -192,13 +192,13 @@ $ openssl rand -hex 32
=== "🐍 3️⃣.6️⃣ & 🔛"
- ```Python hl_lines="115-128"
+ ```Python hl_lines="115-130"
{!> ../../../docs_src/security/tutorial004.py!}
```
=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"
- ```Python hl_lines="114-127"
+ ```Python hl_lines="114-129"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
diff --git a/docs/em/docs/tutorial/sql-databases.md b/docs/em/docs/tutorial/sql-databases.md
index 9d46c24608..e3ced7ef4c 100644
--- a/docs/em/docs/tutorial/sql-databases.md
+++ b/docs/em/docs/tutorial/sql-databases.md
@@ -501,7 +501,7 @@ current_user.items
"🛠️" ⚒ 🔁 💪 🕐❔ 👆 🔀 📊 👆 🇸🇲 🏷, 🚮 🆕 🔢, ♒️. 🔁 👈 🔀 💽, 🚮 🆕 🏓, 🆕 🏓, ♒️.
-👆 💪 🔎 🖼 ⚗ FastAPI 🏗 📄 ⚪️➡️ [🏗 ⚡ - 📄](../project-generation.md){.internal-link target=_blank}. 🎯 `alembic` 📁 ℹ 📟.
+👆 💪 🔎 🖼 ⚗ FastAPI 🏗 📄 ⚪️➡️ [🏗 ⚡ - 📄](../project-generation.md){.internal-link target=_blank}. 🎯 `alembic` 📁 ℹ 📟.
### ✍ 🔗
diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml
index d53afd7f9f..00d6f696de 100644
--- a/docs/en/data/external_links.yml
+++ b/docs/en/data/external_links.yml
@@ -1,5 +1,25 @@
Articles:
English:
+ - author: Ankit Anchlia
+ author_link: https://linkedin.com/in/aanchlia21
+ link: https://hackernoon.com/explore-how-to-effectively-use-jwt-with-fastapi
+ title: Explore How to Effectively Use JWT With FastAPI
+ - author: Nicoló Lino
+ author_link: https://www.nlino.com
+ link: https://github.com/softwarebloat/python-tracing-demo
+ title: Instrument a FastAPI service adding tracing with OpenTelemetry and send/show traces in Grafana Tempo
+ - author: Mikhail Rozhkov, Elena Samuylova
+ author_link: https://www.linkedin.com/in/mnrozhkov/
+ link: https://www.evidentlyai.com/blog/fastapi-tutorial
+ title: ML serving and monitoring with FastAPI and Evidently
+ - author: Visual Studio Code Team
+ author_link: https://code.visualstudio.com/
+ link: https://code.visualstudio.com/docs/python/tutorial-fastapi
+ title: FastAPI Tutorial in Visual Studio Code
+ - author: Apitally
+ author_link: https://apitally.io
+ link: https://blog.apitally.io/fastapi-application-monitoring-made-easy
+ title: FastAPI application monitoring made easy
- author: John Philip
author_link: https://medium.com/@amjohnphilip
link: https://python.plainenglish.io/building-a-restful-api-with-fastapi-secure-signup-and-login-functionality-included-45cdbcb36106
@@ -20,10 +40,6 @@ Articles:
author_link: https://dev.to/
link: https://dev.to/teresafds/authorization-on-fastapi-with-casbin-41og
title: Authorization on FastAPI with Casbin
- - author: WayScript
- author_link: https://www.wayscript.com
- link: https://blog.wayscript.com/fast-api-quickstart/
- title: Quickstart Guide to Build and Host Responsive APIs with Fast API and WayScript
- author: New Relic
author_link: https://newrelic.com
link: https://newrelic.com/instant-observability/fastapi/e559ec64-f765-4470-a15f-1901fcebb468
@@ -76,10 +92,6 @@ Articles:
author_link: https://dev.to/factorlive
link: https://dev.to/factorlive/python-facebook-messenger-webhook-with-fastapi-on-glitch-4n90
title: Python Facebook messenger webhook with FastAPI on Glitch
- - author: Dom Patmore
- author_link: https://twitter.com/dompatmore
- link: https://dompatmore.com/blog/authenticate-your-fastapi-app-with-auth0
- title: Authenticate Your FastAPI App with auth0
- author: Valon Januzaj
author_link: https://www.linkedin.com/in/valon-januzaj-b02692187/
link: https://valonjanuzaj.medium.com/deploy-a-dockerized-fastapi-application-to-aws-cc757830ba1b
@@ -92,10 +104,6 @@ Articles:
author_link: https://twitter.com/louis_guitton
link: https://guitton.co/posts/fastapi-monitoring/
title: How to monitor your FastAPI service
- - author: Julien Harbulot
- author_link: https://julienharbulot.com/
- link: https://julienharbulot.com/notification-server.html
- title: HTTP server to display desktop notifications
- author: Precious Ndubueze
author_link: https://medium.com/@gabbyprecious2000
link: https://medium.com/@gabbyprecious2000/creating-a-crud-app-with-fastapi-part-one-7c049292ad37
@@ -144,18 +152,10 @@ Articles:
author_link: https://wuilly.com/
link: https://wuilly.com/2019/10/real-time-notifications-with-python-and-postgres/
title: Real-time Notifications with Python and Postgres
- - author: Benjamin Ramser
- author_link: https://iwpnd.pw
- link: https://iwpnd.pw/articles/2020-03/apache-kafka-fastapi-geostream
- title: Apache Kafka producer and consumer with FastAPI and aiokafka
- author: Navule Pavan Kumar Rao
author_link: https://www.linkedin.com/in/navule/
link: https://www.tutlinks.com/create-and-deploy-fastapi-app-to-heroku/
title: Create and Deploy FastAPI app to Heroku without using Docker
- - author: Benjamin Ramser
- author_link: https://iwpnd.pw
- link: https://iwpnd.pw/articles/2020-01/deploy-fastapi-to-aws-lambda
- title: How to continuously deploy a FastAPI to AWS Lambda with AWS SAM
- author: Arthur Henrique
author_link: https://twitter.com/arthurheinrique
link: https://medium.com/@arthur393/another-boilerplate-to-fastapi-azure-pipeline-ci-pytest-3c8d9a4be0bb
@@ -180,10 +180,6 @@ Articles:
author_link: https://dev.to/dbanty
link: https://dev.to/dbanty/why-i-m-leaving-flask-3ki6
title: Why I'm Leaving Flask
- - author: Rob Wagner
- author_link: https://robwagner.dev/
- link: https://robwagner.dev/tortoise-fastapi-setup/
- title: Setting up Tortoise ORM with FastAPI
- author: Mike Moritz
author_link: https://medium.com/@mike.p.moritz
link: https://medium.com/@mike.p.moritz/using-docker-compose-to-deploy-a-lightweight-python-rest-api-with-a-job-queue-37e6072a209b
@@ -341,6 +337,10 @@ Podcasts:
title: FastAPI on PythonBytes
Talks:
English:
+ - author: Jeny Sadadia
+ author_link: https://github.com/JenySadadia
+ link: https://www.youtube.com/watch?v=uZdTe8_Z6BQ
+ title: 'PyCon AU 2023: Testing asynchronous applications with FastAPI and pytest'
- author: Sebastián Ramírez (tiangolo)
author_link: https://twitter.com/tiangolo
link: https://www.youtube.com/watch?v=PnpTY1f4k2U
diff --git a/docs/en/docs/advanced/additional-responses.md b/docs/en/docs/advanced/additional-responses.md
index 624036ce97..41b39c18e6 100644
--- a/docs/en/docs/advanced/additional-responses.md
+++ b/docs/en/docs/advanced/additional-responses.md
@@ -28,7 +28,7 @@ For example, to declare another response with a status code `404` and a Pydantic
```
!!! note
- Have in mind that you have to return the `JSONResponse` directly.
+ Keep in mind that you have to return the `JSONResponse` directly.
!!! info
The `model` key is not part of OpenAPI.
diff --git a/docs/en/docs/advanced/async-tests.md b/docs/en/docs/advanced/async-tests.md
index c79822d63e..f9c82e6ab4 100644
--- a/docs/en/docs/advanced/async-tests.md
+++ b/docs/en/docs/advanced/async-tests.md
@@ -85,7 +85,7 @@ response = client.get('/')
Note that we're using async/await with the new `AsyncClient` - the request is asynchronous.
!!! warning
- If your application relies on lifespan events, the `AsyncClient` won't trigger these events. To ensure they are triggered, use `LifespanManager` from https://github.com/florimondmanca/asgi-lifespan#usage.
+ If your application relies on lifespan events, the `AsyncClient` won't trigger these events. To ensure they are triggered, use `LifespanManager` from florimondmanca/asgi-lifespan.
## Other Asynchronous Function Calls
diff --git a/docs/en/docs/advanced/behind-a-proxy.md b/docs/en/docs/advanced/behind-a-proxy.md
index e7af77f3da..01998cc912 100644
--- a/docs/en/docs/advanced/behind-a-proxy.md
+++ b/docs/en/docs/advanced/behind-a-proxy.md
@@ -125,7 +125,7 @@ Passing the `root_path` to `FastAPI` would be the equivalent of passing the `--r
### About `root_path`
-Have in mind that the server (Uvicorn) won't use that `root_path` for anything else than passing it to the app.
+Keep in mind that the server (Uvicorn) won't use that `root_path` for anything else than passing it to the app.
But if you go with your browser to http://127.0.0.1:8000/app you will see the normal response:
@@ -142,7 +142,7 @@ Uvicorn will expect the proxy to access Uvicorn at `http://127.0.0.1:8000/app`,
## About proxies with a stripped path prefix
-Have in mind that a proxy with stripped path prefix is only one of the ways to configure it.
+Keep in mind that a proxy with stripped path prefix is only one of the ways to configure it.
Probably in many cases the default will be that the proxy doesn't have a stripped path prefix.
diff --git a/docs/en/docs/advanced/custom-response.md b/docs/en/docs/advanced/custom-response.md
index ce2619e8de..827776f5e5 100644
--- a/docs/en/docs/advanced/custom-response.md
+++ b/docs/en/docs/advanced/custom-response.md
@@ -101,7 +101,7 @@ But as you passed the `HTMLResponse` in the `response_class` too, **FastAPI** wi
Here are some of the available responses.
-Have in mind that you can use `Response` to return anything else, or even create a custom sub-class.
+Keep in mind that you can use `Response` to return anything else, or even create a custom sub-class.
!!! note "Technical Details"
You could also use `from starlette.responses import HTMLResponse`.
diff --git a/docs/en/docs/advanced/dataclasses.md b/docs/en/docs/advanced/dataclasses.md
index 72daca06ad..ed1d5610fc 100644
--- a/docs/en/docs/advanced/dataclasses.md
+++ b/docs/en/docs/advanced/dataclasses.md
@@ -21,7 +21,7 @@ And of course, it supports the same:
This works the same way as with Pydantic models. And it is actually achieved in the same way underneath, using Pydantic.
!!! info
- Have in mind that dataclasses can't do everything Pydantic models can do.
+ Keep in mind that dataclasses can't do everything Pydantic models can do.
So, you might still need to use Pydantic models.
diff --git a/docs/en/docs/advanced/events.md b/docs/en/docs/advanced/events.md
index 6b7de41309..ca9d86ae41 100644
--- a/docs/en/docs/advanced/events.md
+++ b/docs/en/docs/advanced/events.md
@@ -92,7 +92,7 @@ The `lifespan` parameter of the `FastAPI` app takes an **async context manager**
## Alternative Events (deprecated)
!!! warning
- The recommended way to handle the *startup* and *shutdown* is using the `lifespan` parameter of the `FastAPI` app as described above.
+ The recommended way to handle the *startup* and *shutdown* is using the `lifespan` parameter of the `FastAPI` app as described above. If you provide a `lifespan` parameter, `startup` and `shutdown` event handlers will no longer be called. It's all `lifespan` or all events, not both.
You can probably skip this part.
@@ -159,4 +159,4 @@ Underneath, in the ASGI technical specification, this is part of the using the 'X-' prefix.
+Keep in mind that custom proprietary headers can be added using the 'X-' prefix.
But if you have custom headers that you want a client in a browser to be able to see, you need to add them to your CORS configurations (read more in [CORS (Cross-Origin Resource Sharing)](../tutorial/cors.md){.internal-link target=_blank}), using the parameter `expose_headers` documented in Starlette's CORS docs.
diff --git a/docs/en/docs/advanced/security/http-basic-auth.md b/docs/en/docs/advanced/security/http-basic-auth.md
index 6f9002f608..680f4dff53 100644
--- a/docs/en/docs/advanced/security/http-basic-auth.md
+++ b/docs/en/docs/advanced/security/http-basic-auth.md
@@ -105,7 +105,7 @@ if "johndoe" == "stanleyjobson" and "love123" == "swordfish":
...
```
-But right at the moment Python compares the first `j` in `johndoe` to the first `s` in `stanleyjobson`, it will return `False`, because it already knows that those two strings are not the same, thinking that "there's no need to waste more computation comparing the rest of the letters". And your application will say "incorrect user or password".
+But right at the moment Python compares the first `j` in `johndoe` to the first `s` in `stanleyjobson`, it will return `False`, because it already knows that those two strings are not the same, thinking that "there's no need to waste more computation comparing the rest of the letters". And your application will say "Incorrect username or password".
But then the attackers try with username `stanleyjobsox` and password `love123`.
@@ -116,11 +116,11 @@ if "stanleyjobsox" == "stanleyjobson" and "love123" == "swordfish":
...
```
-Python will have to compare the whole `stanleyjobso` in both `stanleyjobsox` and `stanleyjobson` before realizing that both strings are not the same. So it will take some extra microseconds to reply back "incorrect user or password".
+Python will have to compare the whole `stanleyjobso` in both `stanleyjobsox` and `stanleyjobson` before realizing that both strings are not the same. So it will take some extra microseconds to reply back "Incorrect username or password".
#### The time to answer helps the attackers
-At that point, by noticing that the server took some microseconds longer to send the "incorrect user or password" response, the attackers will know that they got _something_ right, some of the initial letters were right.
+At that point, by noticing that the server took some microseconds longer to send the "Incorrect username or password" response, the attackers will know that they got _something_ right, some of the initial letters were right.
And then they can try again knowing that it's probably something more similar to `stanleyjobsox` than to `johndoe`.
diff --git a/docs/en/docs/advanced/security/oauth2-scopes.md b/docs/en/docs/advanced/security/oauth2-scopes.md
index 304a46090e..b93d2991c4 100644
--- a/docs/en/docs/advanced/security/oauth2-scopes.md
+++ b/docs/en/docs/advanced/security/oauth2-scopes.md
@@ -79,7 +79,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 152"
+ ```Python hl_lines="3 7 11 45 63 104 106-114 120-123 127-133 138 154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```
@@ -88,7 +88,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
+ ```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```
@@ -97,7 +97,7 @@ First, let's quickly see the parts that change from the examples in the main **T
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 153"
+ ```Python hl_lines="2 4 8 12 46 64 105 107-115 121-124 128-134 139 155"
{!> ../../../docs_src/security/tutorial005.py!}
```
@@ -199,7 +199,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="152"
+ ```Python hl_lines="154"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```
@@ -208,7 +208,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="153"
+ ```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```
@@ -217,7 +217,7 @@ And we return the scopes as part of the JWT token.
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="153"
+ ```Python hl_lines="155"
{!> ../../../docs_src/security/tutorial005.py!}
```
@@ -265,7 +265,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="3 138 165"
+ ```Python hl_lines="3 138 167"
{!> ../../../docs_src/security/tutorial005_py310.py!}
```
@@ -274,7 +274,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="4 139 166"
+ ```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005_py39.py!}
```
@@ -283,7 +283,7 @@ In this case, it requires the scope `me` (it could require more than one scope).
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="4 139 166"
+ ```Python hl_lines="4 139 168"
{!> ../../../docs_src/security/tutorial005.py!}
```
diff --git a/docs/en/docs/advanced/templates.md b/docs/en/docs/advanced/templates.md
index 583abda7fb..6055b30170 100644
--- a/docs/en/docs/advanced/templates.md
+++ b/docs/en/docs/advanced/templates.md
@@ -46,21 +46,61 @@ $ pip install jinja2
## Writing templates
-Then you can write a template at `templates/item.html` with:
+Then you can write a template at `templates/item.html` with, for example:
```jinja hl_lines="7"
{!../../../docs_src/templates/templates/item.html!}
```
-It will show the `id` taken from the "context" `dict` you passed:
+### Template Context Values
+
+In the HTML that contains:
+
+{% raw %}
+
+```jinja
+Item ID: {{ id }}
+```
+
+{% endraw %}
+
+...it will show the `id` taken from the "context" `dict` you passed:
```Python
-{"request": request, "id": id}
+{"id": id}
+```
+
+For example, with an ID of `42`, this would render:
+
+```html
+Item ID: 42
+```
+
+### Template `url_for` Arguments
+
+You can also use `url_for()` inside of the template, it takes as arguments the same arguments that would be used by your *path operation function*.
+
+So, the section with:
+
+{% raw %}
+
+```jinja
+
+```
+
+{% endraw %}
+
+...will generate a link to the same URL that would be handled by the *path operation function* `read_item(id=id)`.
+
+For example, with an ID of `42`, this would render:
+
+```html
+
```
## Templates and static files
-You can also use `url_for()` inside of the template, and use it, for example, with the `StaticFiles` you mounted.
+You can also use `url_for()` inside of the template, and use it, for example, with the `StaticFiles` you mounted with the `name="static"`.
```jinja hl_lines="4"
{!../../../docs_src/templates/templates/item.html!}
diff --git a/docs/en/docs/advanced/websockets.md b/docs/en/docs/advanced/websockets.md
index 49b8fba899..b8dfab1d1f 100644
--- a/docs/en/docs/advanced/websockets.md
+++ b/docs/en/docs/advanced/websockets.md
@@ -212,7 +212,7 @@ Client #1596980209979 left the chat
!!! tip
The app above is a minimal and simple example to demonstrate how to handle and broadcast messages to several WebSocket connections.
- But have in mind that, as everything is handled in memory, in a single list, it will only work while the process is running, and will only work with a single process.
+ But keep in mind that, as everything is handled in memory, in a single list, it will only work while the process is running, and will only work with a single process.
If you need something easy to integrate with FastAPI but that is more robust, supported by Redis, PostgreSQL or others, check encode/broadcaster.
diff --git a/docs/en/docs/alternatives.md b/docs/en/docs/alternatives.md
index e02b3b55a1..70bbcac91c 100644
--- a/docs/en/docs/alternatives.md
+++ b/docs/en/docs/alternatives.md
@@ -191,7 +191,7 @@ This solved having to write YAML (another syntax) inside of Python docstrings.
This combination of Flask, Flask-apispec with Marshmallow and Webargs was my favorite backend stack until building **FastAPI**.
-Using it led to the creation of several Flask full-stack generators. These are the main stack I (and several external teams) have been using up to now:
+Using it led to the creation of several Flask full-stack generators. These are the main stacks I (and several external teams) have been using up to now:
* https://github.com/tiangolo/full-stack
* https://github.com/tiangolo/full-stack-flask-couchbase
@@ -211,7 +211,7 @@ This isn't even Python, NestJS is a JavaScript (TypeScript) NodeJS framework ins
It achieves something somewhat similar to what can be done with Flask-apispec.
-It has an integrated dependency injection system, inspired by Angular two. It requires pre-registering the "injectables" (like all the other dependency injection systems I know), so, it adds to the verbosity and code repetition.
+It has an integrated dependency injection system, inspired by Angular 2. It requires pre-registering the "injectables" (like all the other dependency injection systems I know), so, it adds to the verbosity and code repetition.
As the parameters are described with TypeScript types (similar to Python type hints), editor support is quite good.
diff --git a/docs/en/docs/benchmarks.md b/docs/en/docs/benchmarks.md
index e05fec8406..d746b6d7c4 100644
--- a/docs/en/docs/benchmarks.md
+++ b/docs/en/docs/benchmarks.md
@@ -2,7 +2,7 @@
Independent TechEmpower benchmarks show **FastAPI** applications running under Uvicorn as one of the fastest Python frameworks available, only below Starlette and Uvicorn themselves (used internally by FastAPI). (*)
-But when checking benchmarks and comparisons you should have the following in mind.
+But when checking benchmarks and comparisons you should keep the following in mind.
## Benchmarks and speed
diff --git a/docs/en/docs/contributing.md b/docs/en/docs/contributing.md
index 35bc1c5019..2d308a9dbd 100644
--- a/docs/en/docs/contributing.md
+++ b/docs/en/docs/contributing.md
@@ -4,11 +4,11 @@ First, you might want to see the basic ways to [help FastAPI and get help](help-
## Developing
-If you already cloned the repository and you know that you need to deep dive in the code, here are some guidelines to set up your environment.
+If you already cloned the fastapi repository and you want to deep dive in the code, here are some guidelines to set up your environment.
### Virtual environment with `venv`
-You can create a virtual environment in a directory using Python's `venv` module:
+You can create an isolated virtual local environment in a directory using Python's `venv` module. Let's do this in the cloned repository (where the `requirements.txt` is):
@@ -18,7 +18,7 @@ $ python -m venv env
-That will create a directory `./env/` with the Python binaries and then you will be able to install packages for that isolated environment.
+That will create a directory `./env/` with the Python binaries, and then you will be able to install packages for that local environment.
### Activate the environment
@@ -84,7 +84,7 @@ To check it worked, use:
If it shows the `pip` binary at `env/bin/pip` then it worked. 🎉
-Make sure you have the latest pip version on your virtual environment to avoid errors on the next steps:
+Make sure you have the latest pip version on your local environment to avoid errors on the next steps:
@@ -101,7 +101,7 @@ $ python -m pip install --upgrade pip
This makes sure that if you use a terminal program installed by that package, you use the one from your local environment and not any other that could be installed globally.
-### pip
+### Install requirements using pip
After activating the environment as described above:
@@ -117,20 +117,20 @@ $ pip install -r requirements.txt
It will install all the dependencies and your local FastAPI in your local environment.
-#### Using your local FastAPI
+### Using your local FastAPI
-If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your local FastAPI source code.
+If you create a Python file that imports and uses FastAPI, and run it with the Python from your local environment, it will use your cloned local FastAPI source code.
And if you update that local FastAPI source code when you run that Python file again, it will use the fresh version of FastAPI you just edited.
That way, you don't have to "install" your local version to be able to test every change.
!!! note "Technical Details"
- This only happens when you install using this included `requirements.txt` instead of installing `pip install fastapi` directly.
+ This only happens when you install using this included `requirements.txt` instead of running `pip install fastapi` directly.
- That is because inside of the `requirements.txt` file, the local version of FastAPI is marked to be installed in "editable" mode, with the `-e` option.
+ That is because inside the `requirements.txt` file, the local version of FastAPI is marked to be installed in "editable" mode, with the `-e` option.
-### Format
+### Format the code
There is a script that you can run that will format and clean all your code:
@@ -227,15 +227,13 @@ And those Python files are included/injected in the documentation when generatin
Most of the tests actually run against the example source files in the documentation.
-This helps making sure that:
+This helps to make sure that:
-* The documentation is up to date.
+* The documentation is up-to-date.
* The documentation examples can be run as is.
* Most of the features are covered by the documentation, ensured by test coverage.
-
-
-### Apps and docs at the same time
+#### Apps and docs at the same time
If you run the examples with, e.g.:
@@ -259,7 +257,9 @@ Here are the steps to help with translations.
#### Tips and guidelines
-* Check the currently existing pull requests for your language and add reviews requesting changes or approving them.
+* Check the currently existing pull requests for your language. You can filter the pull requests by the ones with the label for your language. For example, for Spanish, the label is `lang-es`.
+
+* Review those pull requests, requesting changes or approving them. For the languages I don't speak, I'll wait for several others to review the translation before merging.
!!! tip
You can add comments with change suggestions to existing pull requests.
@@ -268,19 +268,9 @@ Here are the steps to help with translations.
* Check if there's a GitHub Discussion to coordinate translations for your language. You can subscribe to it, and when there's a new pull request to review, an automatic comment will be added to the discussion.
-* Add a single pull request per page translated. That will make it much easier for others to review it.
+* If you translate pages, add a single pull request per page translated. That will make it much easier for others to review it.
-For the languages I don't speak, I'll wait for several others to review the translation before merging.
-
-* You can also check if there are translations for your language and add a review to them, that will help me know that the translation is correct and I can merge it.
- * You could check in the GitHub Discussions for your language.
- * Or you can filter the existing PRs by the ones with the label for your language, for example, for Spanish, the label is `lang-es`.
-
-* Use the same Python examples and only translate the text in the docs. You don't have to change anything for this to work.
-
-* Use the same images, file names, and links. You don't have to change anything for it to work.
-
-* To check the 2-letter code for the language you want to translate you can use the table List of ISO 639-1 codes.
+* To check the 2-letter code for the language you want to translate, you can use the table List of ISO 639-1 codes.
#### Existing language
@@ -323,7 +313,7 @@ $ python ./scripts/docs.py live es
Now you can go to http://127.0.0.1:8008 and see your changes live.
-You will see that every language has all the pages. But some pages are not translated and have a notification about the missing translation.
+You will see that every language has all the pages. But some pages are not translated and have an info box at the top, about the missing translation.
Now let's say that you want to add a translation for the section [Features](features.md){.internal-link target=_blank}.
@@ -342,7 +332,7 @@ docs/es/docs/features.md
!!! tip
Notice that the only change in the path and file name is the language code, from `en` to `es`.
-If you go to your browser you will see that now the docs show your new section. 🎉
+If you go to your browser you will see that now the docs show your new section (the info box at the top is gone). 🎉
Now you can translate it all and see how it looks as you save the file.
@@ -386,7 +376,7 @@ You can make the first pull request with those two files, `docs/ht/mkdocs.yml` a
#### Preview the result
-You can use the `./scripts/docs.py` with the `live` command to preview the results (or `mkdocs serve`).
+As already mentioned above, you can use the `./scripts/docs.py` with the `live` command to preview the results (or `mkdocs serve`).
Once you are done, you can also test it all as it would look online, including all the other languages.
@@ -423,6 +413,25 @@ Serving at: http://127.0.0.1:8008
+#### Translation specific tips and guidelines
+
+* Translate only the Markdown documents (`.md`). Do not translate the code examples at `./docs_src`.
+
+* In code blocks within the Markdown document, translate comments (`# a comment`), but leave the rest unchanged.
+
+* Do not change anything enclosed in "``" (inline code).
+
+* In lines starting with `===` or `!!!`, translate only the ` "... Text ..."` part. Leave the rest unchanged.
+
+* You can translate info boxes like `!!! warning` with for example `!!! warning "Achtung"`. But do not change the word immediately after the `!!!`, it determines the color of the info box.
+
+* Do not change the paths in links to images, code files, Markdown documents.
+
+* However, when a Markdown document is translated, the `#hash-parts` in links to its headings may change. Update these links if possible.
+ * Search for such links in the translated document using the regex `#[^# ]`.
+ * Search in all documents already translated into your language for `your-translated-document.md`. For example VS Code has an option "Edit" -> "Find in Files".
+ * When translating a document, do not "pre-translate" `#hash-parts` that link to headings in untranslated documents.
+
## Tests
There is a script that you can run locally to test all the code and generate coverage reports in HTML:
diff --git a/docs/en/docs/deployment/concepts.md b/docs/en/docs/deployment/concepts.md
index 77419f8b0d..cc01fb24e1 100644
--- a/docs/en/docs/deployment/concepts.md
+++ b/docs/en/docs/deployment/concepts.md
@@ -258,7 +258,7 @@ And you will have to make sure that it's a single process running those previous
Of course, there are some cases where there's no problem in running the previous steps multiple times, in that case, it's a lot easier to handle.
!!! tip
- Also, have in mind that depending on your setup, in some cases you **might not even need any previous steps** before starting your application.
+ Also, keep in mind that depending on your setup, in some cases you **might not even need any previous steps** before starting your application.
In that case, you wouldn't have to worry about any of this. 🤷
@@ -297,7 +297,7 @@ You can use simple tools like `htop` to see the CPU and RAM used in your server
## Recap
-You have been reading here some of the main concepts that you would probably need to have in mind when deciding how to deploy your application:
+You have been reading here some of the main concepts that you would probably need to keep in mind when deciding how to deploy your application:
* Security - HTTPS
* Running on startup
diff --git a/docs/en/docs/deployment/https.md b/docs/en/docs/deployment/https.md
index 790976a718..5cf76c1111 100644
--- a/docs/en/docs/deployment/https.md
+++ b/docs/en/docs/deployment/https.md
@@ -9,7 +9,7 @@ But it is way more complex than that.
To **learn the basics of HTTPS**, from a consumer perspective, check https://howhttps.works/.
-Now, from a **developer's perspective**, here are several things to have in mind while thinking about HTTPS:
+Now, from a **developer's perspective**, here are several things to keep in mind while thinking about HTTPS:
* For HTTPS, **the server** needs to **have "certificates"** generated by a **third party**.
* Those certificates are actually **acquired** from the third party, not "generated".
diff --git a/docs/en/docs/deployment/index.md b/docs/en/docs/deployment/index.md
index 6c43d8abbe..b43bd050a3 100644
--- a/docs/en/docs/deployment/index.md
+++ b/docs/en/docs/deployment/index.md
@@ -16,6 +16,6 @@ There are several ways to do it depending on your specific use case and the tool
You could **deploy a server** yourself using a combination of tools, you could use a **cloud service** that does part of the work for you, or other possible options.
-I will show you some of the main concepts you should probably have in mind when deploying a **FastAPI** application (although most of it applies to any other type of web application).
+I will show you some of the main concepts you should probably keep in mind when deploying a **FastAPI** application (although most of it applies to any other type of web application).
-You will see more details to have in mind and some of the techniques to do it in the next sections. ✨
+You will see more details to keep in mind and some of the techniques to do it in the next sections. ✨
diff --git a/docs/en/docs/deployment/manually.md b/docs/en/docs/deployment/manually.md
index d6892b2c14..b10a3686d7 100644
--- a/docs/en/docs/deployment/manually.md
+++ b/docs/en/docs/deployment/manually.md
@@ -10,11 +10,11 @@ There are 3 main alternatives:
## Server Machine and Server Program
-There's a small detail about names to have in mind. 💡
+There's a small detail about names to keep in mind. 💡
The word "**server**" is commonly used to refer to both the remote/cloud computer (the physical or virtual machine) and also the program that is running on that machine (e.g. Uvicorn).
-Just have that in mind when you read "server" in general, it could refer to one of those two things.
+Just keep in mind that when you read "server" in general, it could refer to one of those two things.
When referring to the remote machine, it's common to call it **server**, but also **machine**, **VM** (virtual machine), **node**. Those all refer to some type of remote machine, normally running Linux, where you run programs.
diff --git a/docs/en/docs/help-fastapi.md b/docs/en/docs/help-fastapi.md
index 8199c9b9a9..71c5804097 100644
--- a/docs/en/docs/help-fastapi.md
+++ b/docs/en/docs/help-fastapi.md
@@ -106,7 +106,7 @@ In many cases they will only copy a fragment of the code, but that's not enough
* You can ask them to provide a minimal, reproducible, example, that you can **copy-paste** and run locally to see the same error or behavior they are seeing, or to understand their use case better.
-* If you are feeling too generous, you can try to **create an example** like that yourself, just based on the description of the problem. Just have in mind that this might take a lot of time and it might be better to ask them to clarify the problem first.
+* If you are feeling too generous, you can try to **create an example** like that yourself, just based on the description of the problem. Just keep in mind that this might take a lot of time and it might be better to ask them to clarify the problem first.
### Suggest solutions
@@ -148,7 +148,7 @@ Again, please try your best to be kind. 🤗
---
-Here's what to have in mind and how to review a pull request:
+Here's what to keep in mind and how to review a pull request:
### Understand the problem
@@ -233,7 +233,7 @@ Join the 👥 `contextvars` that can create a local variable very similar to `threading.local`, but also supporting these async features.
-There are several things to have in mind.
+There are several things to keep in mind.
The `ContextVar` has to be created at the top of the module, like:
diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md
index c7787053e9..5e02e2352e 100644
--- a/docs/en/docs/release-notes.md
+++ b/docs/en/docs/release-notes.md
@@ -7,8 +7,70 @@ hide:
## Latest Changes
+* ✏️ Fix Pydantic method name in `docs/en/docs/advanced/path-operation-advanced-configuration.md`. PR [#10826](https://github.com/tiangolo/fastapi/pull/10826) by [@ahmedabdou14](https://github.com/ahmedabdou14).
+
+### Refactors
+
+* ✅ Refactor tests for duplicate operation ID generation for compatibility with other tools running the FastAPI test suite. PR [#10876](https://github.com/tiangolo/fastapi/pull/10876) by [@emmettbutler](https://github.com/emmettbutler).
+* ♻️ Simplify string format with f-strings in `fastapi/utils.py`. PR [#10576](https://github.com/tiangolo/fastapi/pull/10576) by [@eukub](https://github.com/eukub).
+* 🔧 Fix Ruff configuration unintentionally enabling and re-disabling mccabe complexity check. PR [#10893](https://github.com/tiangolo/fastapi/pull/10893) by [@jiridanek](https://github.com/jiridanek).
+* ✅ Re-enable test in `tests/test_tutorial/test_header_params/test_tutorial003.py` after fix in Starlette. PR [#10904](https://github.com/tiangolo/fastapi/pull/10904) by [@ooknimm](https://github.com/ooknimm).
+
### Docs
+* ✏️ A few tweaks in `docs/de/docs/tutorial/first-steps.md`. PR [#10959](https://github.com/tiangolo/fastapi/pull/10959) by [@nilslindemann](https://github.com/nilslindemann).
+* ✏️ Fix link in `docs/en/docs/advanced/async-tests.md`. PR [#10960](https://github.com/tiangolo/fastapi/pull/10960) by [@nilslindemann](https://github.com/nilslindemann).
+* ✏️ Fix typos for Spanish documentation. PR [#10957](https://github.com/tiangolo/fastapi/pull/10957) by [@jlopezlira](https://github.com/jlopezlira).
+* 📝 Add warning about lifespan functions and backwards compatibility with events. PR [#10734](https://github.com/tiangolo/fastapi/pull/10734) by [@jacob-indigo](https://github.com/jacob-indigo).
+* ✏️ Fix broken link in `docs/tutorial/sql-databases.md` in several languages. PR [#10716](https://github.com/tiangolo/fastapi/pull/10716) by [@theoohoho](https://github.com/theoohoho).
+* ✏️ Remove broken links from `external_links.yml`. PR [#10943](https://github.com/tiangolo/fastapi/pull/10943) by [@Torabek](https://github.com/Torabek).
+* 📝 Update template docs with more info about `url_for`. PR [#5937](https://github.com/tiangolo/fastapi/pull/5937) by [@EzzEddin](https://github.com/EzzEddin).
+* 📝 Update usage of Token model in security docs. PR [#9313](https://github.com/tiangolo/fastapi/pull/9313) by [@piotrszacilowski](https://github.com/piotrszacilowski).
+* ✏️ Update highlighted line in `docs/en/docs/tutorial/bigger-applications.md`. PR [#5490](https://github.com/tiangolo/fastapi/pull/5490) by [@papb](https://github.com/papb).
+* 📝 Add External Link: Explore How to Effectively Use JWT With FastAPI. PR [#10212](https://github.com/tiangolo/fastapi/pull/10212) by [@aanchlia](https://github.com/aanchlia).
+* 📝 Add hyperlink to `docs/en/docs/tutorial/static-files.md`. PR [#10243](https://github.com/tiangolo/fastapi/pull/10243) by [@hungtsetse](https://github.com/hungtsetse).
+* 📝 Add External Link: Instrument a FastAPI service adding tracing with OpenTelemetry and send/show traces in Grafana Tempo. PR [#9440](https://github.com/tiangolo/fastapi/pull/9440) by [@softwarebloat](https://github.com/softwarebloat).
+* 📝 Review and rewording of `en/docs/contributing.md`. PR [#10480](https://github.com/tiangolo/fastapi/pull/10480) by [@nilslindemann](https://github.com/nilslindemann).
+* 📝 Add External Link: ML serving and monitoring with FastAPI and Evidently. PR [#9701](https://github.com/tiangolo/fastapi/pull/9701) by [@mnrozhkov](https://github.com/mnrozhkov).
+* 📝 Reword in docs, from "have in mind" to "keep in mind". PR [#10376](https://github.com/tiangolo/fastapi/pull/10376) by [@malicious](https://github.com/malicious).
+* 📝 Add External Link: Talk by Jeny Sadadia. PR [#10265](https://github.com/tiangolo/fastapi/pull/10265) by [@JenySadadia](https://github.com/JenySadadia).
+* 📝 Add location info to `tutorial/bigger-applications.md`. PR [#10552](https://github.com/tiangolo/fastapi/pull/10552) by [@nilslindemann](https://github.com/nilslindemann).
+
+### Translations
+
+* 🌐 Add German translation for `docs/de/docs/tutorial/index.md`. PR [#9502](https://github.com/tiangolo/fastapi/pull/9502) by [@fhabers21](https://github.com/fhabers21).
+* 🌐 Add German translation for `docs/de/docs/tutorial/background-tasks.md`. PR [#10566](https://github.com/tiangolo/fastapi/pull/10566) by [@nilslindemann](https://github.com/nilslindemann).
+* ✏️ Fix typo in `docs/ru/docs/index.md`. PR [#10672](https://github.com/tiangolo/fastapi/pull/10672) by [@Delitel-WEB](https://github.com/Delitel-WEB).
+* ✏️ Fix typos in `docs/zh/docs/tutorial/extra-data-types.md`. PR [#10727](https://github.com/tiangolo/fastapi/pull/10727) by [@HiemalBeryl](https://github.com/HiemalBeryl).
+* 🌐 Add Russian translation for `docs/ru/docs/tutorial/dependencies/classes-as-dependencies.md`. PR [#10410](https://github.com/tiangolo/fastapi/pull/10410) by [@AlertRED](https://github.com/AlertRED).
+
+### Internal
+
+* 🔧 Group dependencies on dependabot updates. PR [#10952](https://github.com/tiangolo/fastapi/pull/10952) by [@Kludex](https://github.com/Kludex).
+* ⬆ Bump actions/setup-python from 4 to 5. PR [#10764](https://github.com/tiangolo/fastapi/pull/10764) by [@dependabot[bot]](https://github.com/apps/dependabot).
+* ⬆ Bump pypa/gh-action-pypi-publish from 1.8.10 to 1.8.11. PR [#10731](https://github.com/tiangolo/fastapi/pull/10731) by [@dependabot[bot]](https://github.com/apps/dependabot).
+* ⬆ Bump dawidd6/action-download-artifact from 2.28.0 to 3.0.0. PR [#10777](https://github.com/tiangolo/fastapi/pull/10777) by [@dependabot[bot]](https://github.com/apps/dependabot).
+* 🔧 Add support for translations to languages with a longer code name, like `zh-hant`. PR [#10950](https://github.com/tiangolo/fastapi/pull/10950) by [@tiangolo](https://github.com/tiangolo).
+
+## 0.109.0
+
+### Features
+
+* ✨ Add support for Python 3.12. PR [#10666](https://github.com/tiangolo/fastapi/pull/10666) by [@Jamim](https://github.com/Jamim).
+
+### Upgrades
+
+* ⬆️ Upgrade Starlette to >=0.35.0,<0.36.0. PR [#10938](https://github.com/tiangolo/fastapi/pull/10938) by [@tiangolo](https://github.com/tiangolo).
+
+### Docs
+
+* ✏️ Fix typo in `docs/en/docs/alternatives.md`. PR [#10931](https://github.com/tiangolo/fastapi/pull/10931) by [@s111d](https://github.com/s111d).
+* 📝 Replace `email` with `username` in `docs_src/security/tutorial007` code examples. PR [#10649](https://github.com/tiangolo/fastapi/pull/10649) by [@nilslindemann](https://github.com/nilslindemann).
+* 📝 Add VS Code tutorial link. PR [#10592](https://github.com/tiangolo/fastapi/pull/10592) by [@nilslindemann](https://github.com/nilslindemann).
+* 📝 Add notes about Pydantic v2's new `.model_dump()`. PR [#10929](https://github.com/tiangolo/fastapi/pull/10929) by [@tiangolo](https://github.com/tiangolo).
+* 📝 Fix broken link in `docs/en/docs/tutorial/sql-databases.md`. PR [#10765](https://github.com/tiangolo/fastapi/pull/10765) by [@HurSungYun](https://github.com/HurSungYun).
+* 📝 Add External Link: FastAPI application monitoring made easy. PR [#10917](https://github.com/tiangolo/fastapi/pull/10917) by [@tiangolo](https://github.com/tiangolo).
+* ✨ Generate automatic language names for docs translations. PR [#5354](https://github.com/tiangolo/fastapi/pull/5354) by [@jakul](https://github.com/jakul).
* ✏️ Fix typos in `docs/en/docs/alternatives.md` and `docs/en/docs/tutorial/dependencies/index.md`. PR [#10906](https://github.com/tiangolo/fastapi/pull/10906) by [@s111d](https://github.com/s111d).
* ✏️ Fix typos in `docs/en/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#10834](https://github.com/tiangolo/fastapi/pull/10834) by [@Molkree](https://github.com/Molkree).
* 📝 Add article: "Building a RESTful API with FastAPI: Secure Signup and Login Functionality Included". PR [#9733](https://github.com/tiangolo/fastapi/pull/9733) by [@dxphilo](https://github.com/dxphilo).
@@ -24,6 +86,7 @@ hide:
### Translations
+* 🌐 Add Bengali translation for `docs/bn/docs/index.md`. PR [#9177](https://github.com/tiangolo/fastapi/pull/9177) by [@Fahad-Md-Kamal](https://github.com/Fahad-Md-Kamal).
* ✏️ Update Python version in `index.md` in several languages. PR [#10711](https://github.com/tiangolo/fastapi/pull/10711) by [@tamago3keran](https://github.com/tamago3keran).
* 🌐 Add Russian translation for `docs/ru/docs/tutorial/request-forms-and-files.md`. PR [#10347](https://github.com/tiangolo/fastapi/pull/10347) by [@AlertRED](https://github.com/AlertRED).
* 🌐 Add Ukrainian translation for `docs/uk/docs/index.md`. PR [#10362](https://github.com/tiangolo/fastapi/pull/10362) by [@rostik1410](https://github.com/rostik1410).
@@ -3356,7 +3419,7 @@ Note: all the previous parameters are still there, so it's still possible to dec
* Add OAuth2 redirect page for Swagger UI. This allows having delegated authentication in the Swagger UI docs. For this to work, you need to add `{your_origin}/docs/oauth2-redirect` to the allowed callbacks in your OAuth2 provider (in Auth0, Facebook, Google, etc).
* For example, during development, it could be `http://localhost:8000/docs/oauth2-redirect`.
- * Have in mind that this callback URL is independent of whichever one is used by your frontend. You might also have another callback at `https://yourdomain.com/login/callback`.
+ * Keep in mind that this callback URL is independent of whichever one is used by your frontend. You might also have another callback at `https://yourdomain.com/login/callback`.
* This is only to allow delegated authentication in the API docs with Swagger UI.
* PR [#198](https://github.com/tiangolo/fastapi/pull/198) by [@steinitzu](https://github.com/steinitzu).
diff --git a/docs/en/docs/tutorial/bigger-applications.md b/docs/en/docs/tutorial/bigger-applications.md
index 1cf7e50e02..b2d9284052 100644
--- a/docs/en/docs/tutorial/bigger-applications.md
+++ b/docs/en/docs/tutorial/bigger-applications.md
@@ -79,7 +79,7 @@ You can create the *path operations* for that module using `APIRouter`.
You import it and create an "instance" the same way you would with the class `FastAPI`:
-```Python hl_lines="1 3"
+```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -89,7 +89,7 @@ And then you use it to declare your *path operations*.
Use it the same way you would use the `FastAPI` class:
-```Python hl_lines="6 11 16"
+```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -114,13 +114,13 @@ We will now use a simple dependency to read a custom `X-Token` header:
=== "Python 3.9+"
- ```Python hl_lines="3 6-8"
+ ```Python hl_lines="3 6-8" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an_py39/dependencies.py!}
```
=== "Python 3.8+"
- ```Python hl_lines="1 5-7"
+ ```Python hl_lines="1 5-7" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app_an/dependencies.py!}
```
@@ -129,7 +129,7 @@ We will now use a simple dependency to read a custom `X-Token` header:
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="1 4-6"
+ ```Python hl_lines="1 4-6" title="app/dependencies.py"
{!> ../../../docs_src/bigger_applications/app/dependencies.py!}
```
@@ -160,7 +160,7 @@ We know all the *path operations* in this module have the same:
So, instead of adding all that to each *path operation*, we can add it to the `APIRouter`.
-```Python hl_lines="5-10 16 21"
+```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -212,7 +212,7 @@ And we need to get the dependency function from the module `app.dependencies`, t
So we use a relative import with `..` for the dependencies:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -282,7 +282,7 @@ We are not adding the prefix `/items` nor the `tags=["items"]` to each *path ope
But we can still add _more_ `tags` that will be applied to a specific *path operation*, and also some extra `responses` specific to that *path operation*:
-```Python hl_lines="30-31"
+```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -307,7 +307,7 @@ You import and create a `FastAPI` class as normally.
And we can even declare [global dependencies](dependencies/global-dependencies.md){.internal-link target=_blank} that will be combined with the dependencies for each `APIRouter`:
-```Python hl_lines="1 3 7"
+```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -315,7 +315,7 @@ And we can even declare [global dependencies](dependencies/global-dependencies.m
Now we import the other submodules that have `APIRouter`s:
-```Python hl_lines="5"
+```Python hl_lines="4-5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -377,7 +377,7 @@ The `router` from `users` would overwrite the one from `items` and we wouldn't b
So, to be able to use both of them in the same file, we import the submodules directly:
-```Python hl_lines="5"
+```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -385,7 +385,7 @@ So, to be able to use both of them in the same file, we import the submodules di
Now, let's include the `router`s from the submodules `users` and `items`:
-```Python hl_lines="10-11"
+```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -418,7 +418,7 @@ It contains an `APIRouter` with some admin *path operations* that your organizat
For this example it will be super simple. But let's say that because it is shared with other projects in the organization, we cannot modify it and add a `prefix`, `dependencies`, `tags`, etc. directly to the `APIRouter`:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```
@@ -426,7 +426,7 @@ But we still want to set a custom `prefix` when including the `APIRouter` so tha
We can declare all that without having to modify the original `APIRouter` by passing those parameters to `app.include_router()`:
-```Python hl_lines="14-17"
+```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -449,7 +449,7 @@ We can also add *path operations* directly to the `FastAPI` app.
Here we do it... just to show that we can 🤷:
-```Python hl_lines="21-23"
+```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
diff --git a/docs/en/docs/tutorial/body-nested-models.md b/docs/en/docs/tutorial/body-nested-models.md
index 387f0de9aa..7058d4ad04 100644
--- a/docs/en/docs/tutorial/body-nested-models.md
+++ b/docs/en/docs/tutorial/body-nested-models.md
@@ -361,7 +361,7 @@ In this case, you would accept any `dict` as long as it has `int` keys with `flo
```
!!! tip
- Have in mind that JSON only supports `str` as keys.
+ Keep in mind that JSON only supports `str` as keys.
But Pydantic has automatic data conversion.
diff --git a/docs/en/docs/tutorial/body-updates.md b/docs/en/docs/tutorial/body-updates.md
index 3341f2d5d8..39d133c55f 100644
--- a/docs/en/docs/tutorial/body-updates.md
+++ b/docs/en/docs/tutorial/body-updates.md
@@ -59,9 +59,14 @@ This means that you can send only the data that you want to update, leaving the
### Using Pydantic's `exclude_unset` parameter
-If you want to receive partial updates, it's very useful to use the parameter `exclude_unset` in Pydantic's model's `.dict()`.
+If you want to receive partial updates, it's very useful to use the parameter `exclude_unset` in Pydantic's model's `.model_dump()`.
-Like `item.dict(exclude_unset=True)`.
+Like `item.model_dump(exclude_unset=True)`.
+
+!!! info
+ In Pydantic v1 the method was called `.dict()`, it was deprecated (but still supported) in Pydantic v2, and renamed to `.model_dump()`.
+
+ The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
That would generate a `dict` with only the data that was set when creating the `item` model, excluding default values.
@@ -87,9 +92,14 @@ Then you can use this to generate a `dict` with only the data that was set (sent
### Using Pydantic's `update` parameter
-Now, you can create a copy of the existing model using `.copy()`, and pass the `update` parameter with a `dict` containing the data to update.
+Now, you can create a copy of the existing model using `.model_copy()`, and pass the `update` parameter with a `dict` containing the data to update.
-Like `stored_item_model.copy(update=update_data)`:
+!!! info
+ In Pydantic v1 the method was called `.copy()`, it was deprecated (but still supported) in Pydantic v2, and renamed to `.model_copy()`.
+
+ The examples here use `.copy()` for compatibility with Pydantic v1, but you should use `.model_copy()` instead if you can use Pydantic v2.
+
+Like `stored_item_model.model_copy(update=update_data)`:
=== "Python 3.10+"
@@ -120,7 +130,7 @@ In summary, to apply partial updates you would:
* This way you can update only the values actually set by the user, instead of overriding values already stored with default values in your model.
* Create a copy of the stored model, updating it's attributes with the received partial updates (using the `update` parameter).
* Convert the copied model to something that can be stored in your DB (for example, using the `jsonable_encoder`).
- * This is comparable to using the model's `.dict()` method again, but it makes sure (and converts) the values to data types that can be converted to JSON, for example, `datetime` to `str`.
+ * This is comparable to using the model's `.model_dump()` method again, but it makes sure (and converts) the values to data types that can be converted to JSON, for example, `datetime` to `str`.
* Save the data to your DB.
* Return the updated model.
diff --git a/docs/en/docs/tutorial/extra-models.md b/docs/en/docs/tutorial/extra-models.md
index 590d095bd2..d83b6bc859 100644
--- a/docs/en/docs/tutorial/extra-models.md
+++ b/docs/en/docs/tutorial/extra-models.md
@@ -29,6 +29,11 @@ Here's a general idea of how the models could look like with their password fiel
{!> ../../../docs_src/extra_models/tutorial001.py!}
```
+!!! info
+ In Pydantic v1 the method was called `.dict()`, it was deprecated (but still supported) in Pydantic v2, and renamed to `.model_dump()`.
+
+ The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
+
### About `**user_in.dict()`
#### Pydantic's `.dict()`
diff --git a/docs/en/docs/tutorial/middleware.md b/docs/en/docs/tutorial/middleware.md
index 3c6868fe4d..492a1b065e 100644
--- a/docs/en/docs/tutorial/middleware.md
+++ b/docs/en/docs/tutorial/middleware.md
@@ -33,7 +33,7 @@ The middleware function receives:
```
!!! tip
- Have in mind that custom proprietary headers can be added using the 'X-' prefix.
+ Keep in mind that custom proprietary headers can be added using the 'X-' prefix.
But if you have custom headers that you want a client in a browser to be able to see, you need to add them to your CORS configurations ([CORS (Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank}) using the parameter `expose_headers` documented in Starlette's CORS docs.
diff --git a/docs/en/docs/tutorial/path-params-numeric-validations.md b/docs/en/docs/tutorial/path-params-numeric-validations.md
index 57ad20b137..b5b13cfbe6 100644
--- a/docs/en/docs/tutorial/path-params-numeric-validations.md
+++ b/docs/en/docs/tutorial/path-params-numeric-validations.md
@@ -126,7 +126,7 @@ So, you can declare your function as:
{!> ../../../docs_src/path_params_numeric_validations/tutorial002.py!}
```
-But have in mind that if you use `Annotated`, you won't have this problem, it won't matter as you're not using the function parameter default values for `Query()` or `Path()`.
+But keep in mind that if you use `Annotated`, you won't have this problem, it won't matter as you're not using the function parameter default values for `Query()` or `Path()`.
=== "Python 3.9+"
@@ -166,7 +166,7 @@ Python won't do anything with that `*`, but it will know that all the following
### Better with `Annotated`
-Have in mind that if you use `Annotated`, as you are not using function parameter default values, you won't have this problem, and you probably won't need to use `*`.
+Keep in mind that if you use `Annotated`, as you are not using function parameter default values, you won't have this problem, and you probably won't need to use `*`.
=== "Python 3.9+"
diff --git a/docs/en/docs/tutorial/query-params-str-validations.md b/docs/en/docs/tutorial/query-params-str-validations.md
index 91ae615fff..7a9bc48754 100644
--- a/docs/en/docs/tutorial/query-params-str-validations.md
+++ b/docs/en/docs/tutorial/query-params-str-validations.md
@@ -173,7 +173,7 @@ q: str | None = None
But it declares it explicitly as being a query parameter.
!!! info
- Have in mind that the most important part to make a parameter optional is the part:
+ Keep in mind that the most important part to make a parameter optional is the part:
```Python
= None
@@ -199,7 +199,7 @@ This will validate the data, show a clear error when the data is not valid, and
### `Query` as the default value or in `Annotated`
-Have in mind that when using `Query` inside of `Annotated` you cannot use the `default` parameter for `Query`.
+Keep in mind that when using `Query` inside of `Annotated` you cannot use the `default` parameter for `Query`.
Instead use the actual default value of the function parameter. Otherwise, it would be inconsistent.
@@ -659,7 +659,7 @@ You can also use `list` directly instead of `List[str]` (or `list[str]` in Pytho
```
!!! note
- Have in mind that in this case, FastAPI won't check the contents of the list.
+ Keep in mind that in this case, FastAPI won't check the contents of the list.
For example, `List[int]` would check (and document) that the contents of the list are integers. But `list` alone wouldn't.
@@ -670,7 +670,7 @@ You can add more information about the parameter.
That information will be included in the generated OpenAPI and used by the documentation user interfaces and external tools.
!!! note
- Have in mind that different tools might have different levels of OpenAPI support.
+ Keep in mind that different tools might have different levels of OpenAPI support.
Some of them might not show all the extra information declared yet, although in most of the cases, the missing feature is already planned for development.
diff --git a/docs/en/docs/tutorial/request-files.md b/docs/en/docs/tutorial/request-files.md
index c85a68ed60..8eb8ace648 100644
--- a/docs/en/docs/tutorial/request-files.md
+++ b/docs/en/docs/tutorial/request-files.md
@@ -71,7 +71,7 @@ The files will be uploaded as "form data".
If you declare the type of your *path operation function* parameter as `bytes`, **FastAPI** will read the file for you and you will receive the contents as `bytes`.
-Have in mind that this means that the whole contents will be stored in memory. This will work well for small files.
+Keep in mind that this means that the whole contents will be stored in memory. This will work well for small files.
But there are several cases in which you might benefit from using `UploadFile`.
diff --git a/docs/en/docs/tutorial/response-model.md b/docs/en/docs/tutorial/response-model.md
index d6d3d61cb4..d5683ac7f2 100644
--- a/docs/en/docs/tutorial/response-model.md
+++ b/docs/en/docs/tutorial/response-model.md
@@ -377,6 +377,11 @@ So, if you send a request to that *path operation* for the item with ID `foo`, t
}
```
+!!! info
+ In Pydantic v1 the method was called `.dict()`, it was deprecated (but still supported) in Pydantic v2, and renamed to `.model_dump()`.
+
+ The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
+
!!! info
FastAPI uses Pydantic model's `.dict()` with its `exclude_unset` parameter to achieve this.
diff --git a/docs/en/docs/tutorial/security/get-current-user.md b/docs/en/docs/tutorial/security/get-current-user.md
index e99a800c6d..dc6d87c9ca 100644
--- a/docs/en/docs/tutorial/security/get-current-user.md
+++ b/docs/en/docs/tutorial/security/get-current-user.md
@@ -227,7 +227,7 @@ Just use any kind of model, any kind of class, any kind of database that you nee
## Code size
-This example might seem verbose. Have in mind that we are mixing security, data models, utility functions and *path operations* in the same file.
+This example might seem verbose. Keep in mind that we are mixing security, data models, utility functions and *path operations* in the same file.
But here's the key point.
diff --git a/docs/en/docs/tutorial/security/oauth2-jwt.md b/docs/en/docs/tutorial/security/oauth2-jwt.md
index 0a347fed3e..1c792e3d9e 100644
--- a/docs/en/docs/tutorial/security/oauth2-jwt.md
+++ b/docs/en/docs/tutorial/security/oauth2-jwt.md
@@ -285,7 +285,7 @@ Create a real JWT access token and return it
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="114-127"
+ ```Python hl_lines="114-129"
{!> ../../../docs_src/security/tutorial004_py310.py!}
```
@@ -294,7 +294,7 @@ Create a real JWT access token and return it
!!! tip
Prefer to use the `Annotated` version if possible.
- ```Python hl_lines="115-128"
+ ```Python hl_lines="115-130"
{!> ../../../docs_src/security/tutorial004.py!}
```
@@ -318,7 +318,7 @@ In those cases, several of those entities could have the same ID, let's say `foo
So, to avoid ID collisions, when creating the JWT token for the user, you could prefix the value of the `sub` key, e.g. with `username:`. So, in this example, the value of `sub` could have been: `username:johndoe`.
-The important thing to have in mind is that the `sub` key should have a unique identifier across the entire application, and it should be a string.
+The important thing to keep in mind is that the `sub` key should have a unique identifier across the entire application, and it should be a string.
## Check it
diff --git a/docs/en/docs/tutorial/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md
index 010244bbf6..70d9482df2 100644
--- a/docs/en/docs/tutorial/sql-databases.md
+++ b/docs/en/docs/tutorial/sql-databases.md
@@ -301,7 +301,7 @@ while Pydantic *models* declare the types using `:`, the new type annotation syn
name: str
```
-Have it in mind, so you don't get confused when using `=` and `:` with them.
+Keep these in mind, so you don't get confused when using `=` and `:` with them.
### Create Pydantic *models* / schemas for reading / returning
@@ -451,6 +451,11 @@ The steps are:
{!../../../docs_src/sql_databases/sql_app/crud.py!}
```
+!!! info
+ In Pydantic v1 the method was called `.dict()`, it was deprecated (but still supported) in Pydantic v2, and renamed to `.model_dump()`.
+
+ The examples here use `.dict()` for compatibility with Pydantic v1, but you should use `.model_dump()` instead if you can use Pydantic v2.
+
!!! tip
The SQLAlchemy model for `User` contains a `hashed_password` that should contain a secure hashed version of the password.
@@ -508,7 +513,7 @@ And you would also use Alembic for "migrations" (that's its main job).
A "migration" is the set of steps needed whenever you change the structure of your SQLAlchemy models, add a new attribute, etc. to replicate those changes in the database, add a new column, a new table, etc.
-You can find an example of Alembic in a FastAPI project in the templates from [Project Generation - Template](../project-generation.md){.internal-link target=_blank}. Specifically in the `alembic` directory in the source code.
+You can find an example of Alembic in a FastAPI project in the templates from [Project Generation - Template](../project-generation.md){.internal-link target=_blank}. Specifically in the `alembic` directory in the source code.
### Create a dependency
@@ -624,7 +629,7 @@ def read_user(user_id: int, db: Session = Depends(get_db)):
```
!!! info
- If you need to connect to your relational database asynchronously, see [Async SQL (Relational) Databases](../advanced/async-sql-databases.md){.internal-link target=_blank}.
+ If you need to connect to your relational database asynchronously, see [Async SQL (Relational) Databases](../how-to/async-sql-encode-databases.md){.internal-link target=_blank}.
!!! note "Very Technical Details"
If you are curious and have a deep technical knowledge, you can check the very technical details of how this `async def` vs `def` is handled in the [Async](../async.md#very-technical-details){.internal-link target=_blank} docs.
diff --git a/docs/en/docs/tutorial/static-files.md b/docs/en/docs/tutorial/static-files.md
index 7a0c36af3f..311d2b1c8d 100644
--- a/docs/en/docs/tutorial/static-files.md
+++ b/docs/en/docs/tutorial/static-files.md
@@ -22,7 +22,7 @@ You can serve static files automatically from a directory using `StaticFiles`.
This is different from using an `APIRouter` as a mounted application is completely independent. The OpenAPI and docs from your main application won't include anything from the mounted application, etc.
-You can read more about this in the **Advanced User Guide**.
+You can read more about this in the [Advanced User Guide](../advanced/index.md){.internal-link target=_blank}.
## Details
diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml
index a64eff2696..92d081aa12 100644
--- a/docs/en/mkdocs.yml
+++ b/docs/en/mkdocs.yml
@@ -58,15 +58,18 @@ plugins:
python:
options:
extensions:
- - griffe_typingdoc
+ - griffe_typingdoc
show_root_heading: true
show_if_no_docstring: true
- preload_modules: [httpx, starlette]
+ preload_modules:
+ - httpx
+ - starlette
inherited_members: true
members_order: source
separate_signature: true
unwrap_annotated: true
- filters: ["!^_"]
+ filters:
+ - '!^_'
merge_init_into_class: true
docstring_section_style: spacy
signature_crossrefs: true
@@ -264,25 +267,25 @@ extra:
- link: /
name: en - English
- link: /de/
- name: de
- - link: /em/
- name: 😉
+ name: de - Deutsch
- link: /es/
name: es - español
- link: /fa/
- name: fa
+ name: fa - فارسی
- link: /fr/
name: fr - français
- link: /he/
- name: he
+ name: he - עברית
+ - link: /hu/
+ name: hu - magyar
- link: /id/
- name: id
+ name: id - Bahasa Indonesia
- link: /ja/
name: ja - 日本語
- link: /ko/
name: ko - 한국어
- link: /pl/
- name: pl
+ name: pl - Polski
- link: /pt/
name: pt - português
- link: /ru/
@@ -290,15 +293,17 @@ extra:
- link: /tr/
name: tr - Türkçe
- link: /uk/
- name: uk
+ name: uk - українська мова
- link: /ur/
- name: ur
+ name: ur - اردو
- link: /vi/
name: vi - Tiếng Việt
- link: /yo/
name: yo - Yorùbá
- link: /zh/
name: zh - 汉语
+ - link: /em/
+ name: 😉
extra_css:
- css/termynal.css
- css/custom.css
diff --git a/docs/es/docs/advanced/additional-status-codes.md b/docs/es/docs/advanced/additional-status-codes.md
index 1f28ea85b7..eaa3369ebe 100644
--- a/docs/es/docs/advanced/additional-status-codes.md
+++ b/docs/es/docs/advanced/additional-status-codes.md
@@ -23,7 +23,7 @@ Para conseguir esto importa `JSONResponse` y devuelve ahí directamente tu conte
No será serializado con el modelo, etc.
- Asegurate de que la respuesta tenga los datos que quieras, y que los valores sean JSON válidos (si estás usando `JSONResponse`).
+ Asegúrate de que la respuesta tenga los datos que quieras, y que los valores sean JSON válidos (si estás usando `JSONResponse`).
!!! note "Detalles Técnicos"
También podrías utilizar `from starlette.responses import JSONResponse`.
diff --git a/docs/es/docs/advanced/response-directly.md b/docs/es/docs/advanced/response-directly.md
index 54dadf5763..dee44ac08a 100644
--- a/docs/es/docs/advanced/response-directly.md
+++ b/docs/es/docs/advanced/response-directly.md
@@ -21,7 +21,7 @@ Y cuando devuelves una `Response`, **FastAPI** la pasará directamente.
No hará ninguna conversión de datos con modelos Pydantic, no convertirá el contenido a ningún tipo, etc.
-Esto te da mucha flexibilidad. Puedes devolver cualquier tipo de dato, sobrescribir cualquer declaración de datos o validación, etc.
+Esto te da mucha flexibilidad. Puedes devolver cualquier tipo de dato, sobrescribir cualquier declaración de datos o validación, etc.
## Usando el `jsonable_encoder` en una `Response`
diff --git a/docs/es/docs/features.md b/docs/es/docs/features.md
index d05c4f73e4..d68791d635 100644
--- a/docs/es/docs/features.md
+++ b/docs/es/docs/features.md
@@ -13,7 +13,7 @@
### Documentación automática
-Documentación interactiva de la API e interfaces web de exploración. Hay múltiples opciones, dos incluídas por defecto, porque el framework está basado en OpenAPI.
+Documentación interactiva de la API e interfaces web de exploración. Hay múltiples opciones, dos incluidas por defecto, porque el framework está basado en OpenAPI.
* Swagger UI, con exploración interactiva, llama y prueba tu API directamente desde tu navegador.
@@ -25,7 +25,7 @@ Documentación interactiva de la API e interfaces web de exploración. Hay múlt
### Simplemente Python moderno
-Todo está basado en las declaraciones de tipo de **Python 3.8** estándar (gracias a Pydantic). No necesitas aprender una sintáxis nueva, solo Python moderno.
+Todo está basado en las declaraciones de tipo de **Python 3.8** estándar (gracias a Pydantic). No necesitas aprender una sintaxis nueva, solo Python moderno.
Si necesitas un repaso de 2 minutos de cómo usar los tipos de Python (así no uses FastAPI) prueba el tutorial corto: [Python Types](python-types.md){.internal-link target=_blank}.
@@ -72,9 +72,9 @@ my_second_user: User = User(**second_user_data)
El framework fue diseñado en su totalidad para ser fácil e intuitivo de usar. Todas las decisiones fueron probadas en múltiples editores antes de comenzar el desarrollo para asegurar la mejor experiencia de desarrollo.
-En la última encuesta a desarrolladores de Python fue claro que la característica más usada es el "autocompletado".
+En la última encuesta a desarrolladores de Python fue claro que la característica más usada es el "auto-completado".
-El framework **FastAPI** está creado para satisfacer eso. El autocompletado funciona en todas partes.
+El framework **FastAPI** está creado para satisfacer eso. El auto-completado funciona en todas partes.
No vas a tener que volver a la documentación seguido.
@@ -140,13 +140,13 @@ FastAPI incluye un sistema de ../../../docs_src/dependencies/tutorial001_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="11"
+ {!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="12"
+ {!> ../../../docs_src/dependencies/tutorial001_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="7"
+ {!> ../../../docs_src/dependencies/tutorial001_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="11"
+ {!> ../../../docs_src/dependencies/tutorial001.py!}
+ ```
+
+Но затем мы получаем `словарь` в параметре `commons` *функции операции пути*. И мы знаем, что редакторы не могут обеспечить достаточную поддержку для `словаря`, поскольку они не могут знать их ключи и типы значений.
+
+Мы можем сделать лучше...
+
+## Что делает зависимость
+
+До сих пор вы видели зависимости, объявленные как функции.
+
+Но это не единственный способ объявления зависимостей (хотя, вероятно, более распространенный).
+
+Ключевым фактором является то, что зависимость должна быть "вызываемой".
+
+В Python "**вызываемый**" - это все, что Python может "вызвать", как функцию.
+
+Так, если у вас есть объект `something` (который может _не_ быть функцией) и вы можете "вызвать" его (выполнить) как:
+
+```Python
+something()
+```
+
+или
+
+```Python
+something(some_argument, some_keyword_argument="foo")
+```
+
+в таком случае он является "вызываемым".
+
+## Классы как зависимости
+
+Вы можете заметить, что для создания экземпляра класса в Python используется тот же синтаксис.
+
+Например:
+
+```Python
+class Cat:
+ def __init__(self, name: str):
+ self.name = name
+
+
+fluffy = Cat(name="Mr Fluffy")
+```
+
+В данном случае `fluffy` является экземпляром класса `Cat`.
+
+А чтобы создать `fluffy`, вы "вызываете" `Cat`.
+
+Таким образом, класс в Python также является **вызываемым**.
+
+Тогда в **FastAPI** в качестве зависимости можно использовать класс Python.
+
+На самом деле FastAPI проверяет, что переданный объект является "вызываемым" (функция, класс или что-либо еще) и указаны необходимые для его вызова параметры.
+
+Если вы передаёте что-то, что можно "вызывать" в качестве зависимости в **FastAPI**, то он будет анализировать параметры, необходимые для "вызова" этого объекта и обрабатывать их так же, как параметры *функции операции пути*. Включая подзависимости.
+
+Это относится и к вызываемым объектам без параметров. Работа с ними происходит точно так же, как и для *функций операции пути* без параметров.
+
+Теперь мы можем изменить зависимость `common_parameters`, указанную выше, на класс `CommonQueryParams`:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="11-15"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="11-15"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="12-16"
+ {!> ../../../docs_src/dependencies/tutorial002_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="9-13"
+ {!> ../../../docs_src/dependencies/tutorial002_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="11-15"
+ {!> ../../../docs_src/dependencies/tutorial002.py!}
+ ```
+
+Обратите внимание на метод `__init__`, используемый для создания экземпляра класса:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="12"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="12"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="13"
+ {!> ../../../docs_src/dependencies/tutorial002_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="10"
+ {!> ../../../docs_src/dependencies/tutorial002_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="12"
+ {!> ../../../docs_src/dependencies/tutorial002.py!}
+ ```
+
+...имеет те же параметры, что и ранее используемая функция `common_parameters`:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="8"
+ {!> ../../../docs_src/dependencies/tutorial001_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="9"
+ {!> ../../../docs_src/dependencies/tutorial001_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="10"
+ {!> ../../../docs_src/dependencies/tutorial001_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="6"
+ {!> ../../../docs_src/dependencies/tutorial001_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="9"
+ {!> ../../../docs_src/dependencies/tutorial001.py!}
+ ```
+
+Эти параметры и будут использоваться **FastAPI** для "решения" зависимости.
+
+В обоих случаях она будет иметь:
+
+* Необязательный параметр запроса `q`, представляющий собой `str`.
+* Параметр запроса `skip`, представляющий собой `int`, по умолчанию `0`.
+* Параметр запроса `limit`, представляющий собой `int`, по умолчанию равный `100`.
+
+В обоих случаях данные будут конвертированы, валидированы, документированы по схеме OpenAPI и т.д.
+
+## Как это использовать
+
+Теперь вы можете объявить свою зависимость, используя этот класс.
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial002_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="20"
+ {!> ../../../docs_src/dependencies/tutorial002_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="17"
+ {!> ../../../docs_src/dependencies/tutorial002_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial002.py!}
+ ```
+
+**FastAPI** вызывает класс `CommonQueryParams`. При этом создается "экземпляр" этого класса, который будет передан в качестве параметра `commons` в вашу функцию.
+
+## Аннотация типа или `Depends`
+
+Обратите внимание, что в приведенном выше коде мы два раза пишем `CommonQueryParams`:
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons: CommonQueryParams = Depends(CommonQueryParams)
+ ```
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
+ ```
+
+Последний параметр `CommonQueryParams`, в:
+
+```Python
+... Depends(CommonQueryParams)
+```
+
+...это то, что **FastAPI** будет использовать, чтобы узнать, что является зависимостью.
+
+Из него FastAPI извлечёт объявленные параметры и именно их будет вызывать.
+
+---
+
+В этом случае первый `CommonQueryParams`, в:
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[CommonQueryParams, ...
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons: CommonQueryParams ...
+ ```
+
+...не имеет никакого специального значения для **FastAPI**. FastAPI не будет использовать его для преобразования данных, валидации и т.д. (поскольку для этого используется `Depends(CommonQueryParams)`).
+
+На самом деле можно написать просто:
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[Any, Depends(CommonQueryParams)]
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons = Depends(CommonQueryParams)
+ ```
+
+...как тут:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial003_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial003_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="20"
+ {!> ../../../docs_src/dependencies/tutorial003_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="17"
+ {!> ../../../docs_src/dependencies/tutorial003_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial003.py!}
+ ```
+
+Но объявление типа приветствуется, так как в этом случае ваш редактор будет знать, что будет передано в качестве параметра `commons`, и тогда он сможет помочь вам с автодополнением, проверкой типов и т.д:
+
+
+
+## Сокращение
+
+Но вы видите, что здесь мы имеем некоторое повторение кода, дважды написав `CommonQueryParams`:
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons: CommonQueryParams = Depends(CommonQueryParams)
+ ```
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
+ ```
+
+Для случаев, когда зависимостью является *конкретный* класс, который **FastAPI** "вызовет" для создания экземпляра этого класса, можно использовать укороченную запись.
+
+
+Вместо того чтобы писать:
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[CommonQueryParams, Depends(CommonQueryParams)]
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons: CommonQueryParams = Depends(CommonQueryParams)
+ ```
+
+...следует написать:
+
+=== "Python 3.6+"
+
+ ```Python
+ commons: Annotated[CommonQueryParams, Depends()]
+ ```
+
+=== "Python 3.6 без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python
+ commons: CommonQueryParams = Depends()
+ ```
+
+Вы объявляете зависимость как тип параметра и используете `Depends()` без какого-либо параметра, вместо того чтобы *снова* писать полный класс внутри `Depends(CommonQueryParams)`.
+
+Аналогичный пример будет выглядеть следующим образом:
+
+=== "Python 3.10+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial004_an_py310.py!}
+ ```
+
+=== "Python 3.9+"
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial004_an_py39.py!}
+ ```
+
+=== "Python 3.6+"
+
+ ```Python hl_lines="20"
+ {!> ../../../docs_src/dependencies/tutorial004_an.py!}
+ ```
+
+=== "Python 3.10+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="17"
+ {!> ../../../docs_src/dependencies/tutorial004_py310.py!}
+ ```
+
+=== "Python 3.6+ без Annotated"
+
+ !!! tip "Подсказка"
+ Рекомендуется использовать версию с `Annotated` если возможно.
+
+ ```Python hl_lines="19"
+ {!> ../../../docs_src/dependencies/tutorial004.py!}
+ ```
+
+...и **FastAPI** будет знать, что делать.
+
+!!! tip "Подсказка"
+ Если это покажется вам более запутанным, чем полезным, не обращайте внимания, это вам не *нужно*.
+
+ Это просто сокращение. Потому что **FastAPI** заботится о том, чтобы помочь вам свести к минимуму повторение кода.
diff --git a/docs/zh/docs/tutorial/bigger-applications.md b/docs/zh/docs/tutorial/bigger-applications.md
index 9f0134f683..1389595669 100644
--- a/docs/zh/docs/tutorial/bigger-applications.md
+++ b/docs/zh/docs/tutorial/bigger-applications.md
@@ -79,7 +79,7 @@
你可以导入它并通过与 `FastAPI` 类相同的方式创建一个「实例」:
-```Python hl_lines="1 3"
+```Python hl_lines="1 3" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -89,7 +89,7 @@
使用方式与 `FastAPI` 类相同:
-```Python hl_lines="6 11 16"
+```Python hl_lines="6 11 16" title="app/routers/users.py"
{!../../../docs_src/bigger_applications/app/routers/users.py!}
```
@@ -112,7 +112,7 @@
现在我们将使用一个简单的依赖项来读取一个自定义的 `X-Token` 请求首部:
-```Python hl_lines="1 4-6"
+```Python hl_lines="1 4-6" title="app/dependencies.py"
{!../../../docs_src/bigger_applications/app/dependencies.py!}
```
@@ -143,7 +143,7 @@
因此,我们可以将其添加到 `APIRouter` 中,而不是将其添加到每个路径操作中。
-```Python hl_lines="5-10 16 21"
+```Python hl_lines="5-10 16 21" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -195,7 +195,7 @@ async def read_item(item_id: str):
因此,我们通过 `..` 对依赖项使用了相对导入:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -265,7 +265,7 @@ from ...dependencies import get_token_header
但是我们仍然可以添加*更多*将会应用于特定的*路径操作*的 `tags`,以及一些特定于该*路径操作*的额外 `responses`:
-```Python hl_lines="30-31"
+```Python hl_lines="30-31" title="app/routers/items.py"
{!../../../docs_src/bigger_applications/app/routers/items.py!}
```
@@ -290,7 +290,7 @@ from ...dependencies import get_token_header
我们甚至可以声明[全局依赖项](dependencies/global-dependencies.md){.internal-link target=_blank},它会和每个 `APIRouter` 的依赖项组合在一起:
-```Python hl_lines="1 3 7"
+```Python hl_lines="1 3 7" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -298,7 +298,7 @@ from ...dependencies import get_token_header
现在,我们导入具有 `APIRouter` 的其他子模块:
-```Python hl_lines="5"
+```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -360,7 +360,7 @@ from .routers.users import router
因此,为了能够在同一个文件中使用它们,我们直接导入子模块:
-```Python hl_lines="4"
+```Python hl_lines="5" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -368,7 +368,7 @@ from .routers.users import router
现在,让我们来包含来自 `users` 和 `items` 子模块的 `router`。
-```Python hl_lines="10-11"
+```Python hl_lines="10-11" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -401,7 +401,7 @@ from .routers.users import router
对于此示例,它将非常简单。但是假设由于它是与组织中的其他项目所共享的,因此我们无法对其进行修改,以及直接在 `APIRouter` 中添加 `prefix`、`dependencies`、`tags` 等:
-```Python hl_lines="3"
+```Python hl_lines="3" title="app/internal/admin.py"
{!../../../docs_src/bigger_applications/app/internal/admin.py!}
```
@@ -409,7 +409,7 @@ from .routers.users import router
我们可以通过将这些参数传递给 `app.include_router()` 来完成所有的声明,而不必修改原始的 `APIRouter`:
-```Python hl_lines="14-17"
+```Python hl_lines="14-17" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
@@ -432,7 +432,7 @@ from .routers.users import router
这里我们这样做了...只是为了表明我们可以做到🤷:
-```Python hl_lines="21-23"
+```Python hl_lines="21-23" title="app/main.py"
{!../../../docs_src/bigger_applications/app/main.py!}
```
diff --git a/docs/zh/docs/tutorial/extra-data-types.md b/docs/zh/docs/tutorial/extra-data-types.md
index a74efa61be..f4a77050ca 100644
--- a/docs/zh/docs/tutorial/extra-data-types.md
+++ b/docs/zh/docs/tutorial/extra-data-types.md
@@ -44,11 +44,11 @@
* 产生的模式将指定那些 `set` 的值是唯一的 (使用 JSON 模式的 `uniqueItems`)。
* `bytes`:
* 标准的 Python `bytes`。
- * 在请求和相应中被当作 `str` 处理。
+ * 在请求和响应中被当作 `str` 处理。
* 生成的模式将指定这个 `str` 是 `binary` "格式"。
* `Decimal`:
* 标准的 Python `Decimal`。
- * 在请求和相应中被当做 `float` 一样处理。
+ * 在请求和响应中被当做 `float` 一样处理。
* 您可以在这里检查所有有效的pydantic数据类型: Pydantic data types.
## 例子
diff --git a/docs/zh/docs/tutorial/security/oauth2-jwt.md b/docs/zh/docs/tutorial/security/oauth2-jwt.md
index 054198545e..33a4d7fc76 100644
--- a/docs/zh/docs/tutorial/security/oauth2-jwt.md
+++ b/docs/zh/docs/tutorial/security/oauth2-jwt.md
@@ -170,7 +170,7 @@ $ openssl rand -hex 32
创建并返回真正的 JWT 访问令牌。
-```Python hl_lines="115-128"
+```Python hl_lines="115-130"
{!../../../docs_src/security/tutorial004.py!}
```
diff --git a/docs/zh/docs/tutorial/sql-databases.md b/docs/zh/docs/tutorial/sql-databases.md
index a936eb27b4..c49374971e 100644
--- a/docs/zh/docs/tutorial/sql-databases.md
+++ b/docs/zh/docs/tutorial/sql-databases.md
@@ -499,7 +499,7 @@ current_user.items
“迁移”是每当您更改 SQLAlchemy 模型的结构、添加新属性等以在数据库中复制这些更改、添加新列、新表等时所需的一组步骤。
-您可以在[Project Generation - Template](https://fastapi.tiangolo.com/zh/project-generation/)的模板中找到一个 FastAPI 项目中的 Alembic 示例。具体在[`alembic`代码目录中](https://github.com/tiangolo/full-stack-fastapi-postgresql/tree/master/%7B%7Bcookiecutter.project_slug%7D%7D/backend/app/alembic/)。
+您可以在[Project Generation - Template](https://fastapi.tiangolo.com/zh/project-generation/)的模板中找到一个 FastAPI 项目中的 Alembic 示例。具体在[`alembic`代码目录中](https://github.com/tiangolo/full-stack-fastapi-postgresql/tree/master/src/backend/app/alembic/)。
### 创建依赖项
diff --git a/docs_src/security/tutorial004.py b/docs_src/security/tutorial004.py
index 64099abe9c..044eec7003 100644
--- a/docs_src/security/tutorial004.py
+++ b/docs_src/security/tutorial004.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Union
from fastapi import Depends, FastAPI, HTTPException, status
@@ -78,9 +78,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -112,8 +112,10 @@ async def get_current_active_user(current_user: User = Depends(get_current_user)
return current_user
-@app.post("/token", response_model=Token)
-async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
+@app.post("/token")
+async def login_for_access_token(
+ form_data: OAuth2PasswordRequestForm = Depends()
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
@@ -125,7 +127,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial004_an.py b/docs_src/security/tutorial004_an.py
index ca350343d2..c78e8496c6 100644
--- a/docs_src/security/tutorial004_an.py
+++ b/docs_src/security/tutorial004_an.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Union
from fastapi import Depends, FastAPI, HTTPException, status
@@ -79,9 +79,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -115,10 +115,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
@@ -130,7 +130,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial004_an_py310.py b/docs_src/security/tutorial004_an_py310.py
index 8bf5f3b718..36dbc677e0 100644
--- a/docs_src/security/tutorial004_an_py310.py
+++ b/docs_src/security/tutorial004_an_py310.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, status
@@ -78,9 +78,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -114,10 +114,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
@@ -129,7 +129,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial004_an_py39.py b/docs_src/security/tutorial004_an_py39.py
index a634e23de9..23fc04a721 100644
--- a/docs_src/security/tutorial004_an_py39.py
+++ b/docs_src/security/tutorial004_an_py39.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Annotated, Union
from fastapi import Depends, FastAPI, HTTPException, status
@@ -78,9 +78,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -114,10 +114,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
@@ -129,7 +129,7 @@ async def login_for_access_token(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial004_py310.py b/docs_src/security/tutorial004_py310.py
index 797d56d043..8363d45ab5 100644
--- a/docs_src/security/tutorial004_py310.py
+++ b/docs_src/security/tutorial004_py310.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from fastapi import Depends, FastAPI, HTTPException, status
from fastapi.security import OAuth2PasswordBearer, OAuth2PasswordRequestForm
@@ -77,9 +77,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -111,8 +111,10 @@ async def get_current_active_user(current_user: User = Depends(get_current_user)
return current_user
-@app.post("/token", response_model=Token)
-async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
+@app.post("/token")
+async def login_for_access_token(
+ form_data: OAuth2PasswordRequestForm = Depends()
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(
@@ -124,7 +126,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
access_token = create_access_token(
data={"sub": user.username}, expires_delta=access_token_expires
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005.py b/docs_src/security/tutorial005.py
index bd0a33581c..b16bf440a5 100644
--- a/docs_src/security/tutorial005.py
+++ b/docs_src/security/tutorial005.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Security, status
@@ -93,9 +93,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -143,8 +143,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
-async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
+@app.post("/token")
+async def login_for_access_token(
+ form_data: OAuth2PasswordRequestForm = Depends()
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -153,7 +155,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005_an.py b/docs_src/security/tutorial005_an.py
index ec4fa1a07e..95e406b32f 100644
--- a/docs_src/security/tutorial005_an.py
+++ b/docs_src/security/tutorial005_an.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import List, Union
from fastapi import Depends, FastAPI, HTTPException, Security, status
@@ -94,9 +94,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -144,10 +144,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -156,7 +156,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005_an_py310.py b/docs_src/security/tutorial005_an_py310.py
index 45f3fc0bd6..c6116a5ed1 100644
--- a/docs_src/security/tutorial005_an_py310.py
+++ b/docs_src/security/tutorial005_an_py310.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Annotated
from fastapi import Depends, FastAPI, HTTPException, Security, status
@@ -93,9 +93,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -143,10 +143,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -155,7 +155,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005_an_py39.py b/docs_src/security/tutorial005_an_py39.py
index ecb5ed5160..af51c08b50 100644
--- a/docs_src/security/tutorial005_an_py39.py
+++ b/docs_src/security/tutorial005_an_py39.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Annotated, List, Union
from fastapi import Depends, FastAPI, HTTPException, Security, status
@@ -93,9 +93,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -143,10 +143,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
+@app.post("/token")
async def login_for_access_token(
form_data: Annotated[OAuth2PasswordRequestForm, Depends()]
-):
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -155,7 +155,7 @@ async def login_for_access_token(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005_py310.py b/docs_src/security/tutorial005_py310.py
index ba756ef4f4..37a22c7090 100644
--- a/docs_src/security/tutorial005_py310.py
+++ b/docs_src/security/tutorial005_py310.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from fastapi import Depends, FastAPI, HTTPException, Security, status
from fastapi.security import (
@@ -92,9 +92,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: timedelta | None = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -142,8 +142,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
-async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
+@app.post("/token")
+async def login_for_access_token(
+ form_data: OAuth2PasswordRequestForm = Depends()
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -152,7 +154,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial005_py39.py b/docs_src/security/tutorial005_py39.py
index 9e4dbcffba..c275807636 100644
--- a/docs_src/security/tutorial005_py39.py
+++ b/docs_src/security/tutorial005_py39.py
@@ -1,4 +1,4 @@
-from datetime import datetime, timedelta
+from datetime import datetime, timedelta, timezone
from typing import Union
from fastapi import Depends, FastAPI, HTTPException, Security, status
@@ -93,9 +93,9 @@ def authenticate_user(fake_db, username: str, password: str):
def create_access_token(data: dict, expires_delta: Union[timedelta, None] = None):
to_encode = data.copy()
if expires_delta:
- expire = datetime.utcnow() + expires_delta
+ expire = datetime.now(timezone.utc) + expires_delta
else:
- expire = datetime.utcnow() + timedelta(minutes=15)
+ expire = datetime.now(timezone.utc) + timedelta(minutes=15)
to_encode.update({"exp": expire})
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -143,8 +143,10 @@ async def get_current_active_user(
return current_user
-@app.post("/token", response_model=Token)
-async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends()):
+@app.post("/token")
+async def login_for_access_token(
+ form_data: OAuth2PasswordRequestForm = Depends()
+) -> Token:
user = authenticate_user(fake_users_db, form_data.username, form_data.password)
if not user:
raise HTTPException(status_code=400, detail="Incorrect username or password")
@@ -153,7 +155,7 @@ async def login_for_access_token(form_data: OAuth2PasswordRequestForm = Depends(
data={"sub": user.username, "scopes": form_data.scopes},
expires_delta=access_token_expires,
)
- return {"access_token": access_token, "token_type": "bearer"}
+ return Token(access_token=access_token, token_type="bearer")
@app.get("/users/me/", response_model=User)
diff --git a/docs_src/security/tutorial007.py b/docs_src/security/tutorial007.py
index 790ee10bc6..ac816eb0c1 100644
--- a/docs_src/security/tutorial007.py
+++ b/docs_src/security/tutorial007.py
@@ -22,7 +22,7 @@ def get_current_username(credentials: HTTPBasicCredentials = Depends(security)):
if not (is_correct_username and is_correct_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
- detail="Incorrect email or password",
+ detail="Incorrect username or password",
headers={"WWW-Authenticate": "Basic"},
)
return credentials.username
diff --git a/docs_src/security/tutorial007_an.py b/docs_src/security/tutorial007_an.py
index 5fb7c8e575..9e9c3cd702 100644
--- a/docs_src/security/tutorial007_an.py
+++ b/docs_src/security/tutorial007_an.py
@@ -25,7 +25,7 @@ def get_current_username(
if not (is_correct_username and is_correct_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
- detail="Incorrect email or password",
+ detail="Incorrect username or password",
headers={"WWW-Authenticate": "Basic"},
)
return credentials.username
diff --git a/docs_src/security/tutorial007_an_py39.py b/docs_src/security/tutorial007_an_py39.py
index 17177dabf9..3d9ea27269 100644
--- a/docs_src/security/tutorial007_an_py39.py
+++ b/docs_src/security/tutorial007_an_py39.py
@@ -25,7 +25,7 @@ def get_current_username(
if not (is_correct_username and is_correct_password):
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
- detail="Incorrect email or password",
+ detail="Incorrect username or password",
headers={"WWW-Authenticate": "Basic"},
)
return credentials.username
diff --git a/docs_src/templates/templates/item.html b/docs_src/templates/templates/item.html
index a70287e77d..27994ca994 100644
--- a/docs_src/templates/templates/item.html
+++ b/docs_src/templates/templates/item.html
@@ -4,6 +4,6 @@
-