From 84cd488df17543089e0dbb1e1ab3c7bd4e976be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Jan 2024 21:19:21 +0400 Subject: [PATCH 001/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20FastAPI=20application=20monitoring=20made=20easy=20(#10917)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Simon Gurcke --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index d53afd7f9f..d9cfe3431d 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - 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 From 7e0cdf25100207880e9519f109b9ad5377a83e01 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 17:19:42 +0000 Subject: [PATCH 002/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 8699fbddcd..6885ef68d7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From 06bf7781df11213ce4bc39370566b733de4dfd07 Mon Sep 17 00:00:00 2001 From: Fahad Md Kamal Date: Wed, 10 Jan 2024 23:43:35 +0600 Subject: [PATCH 003/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Bengali=20translat?= =?UTF-8?q?ion=20for=20`docs/bn/docs/index.md`=20(#9177)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/bn/docs/index.md | 464 ++++++++++++++++++++++++++++++++++++++++++ docs/bn/mkdocs.yml | 1 + 2 files changed, 465 insertions(+) create mode 100644 docs/bn/docs/index.md create mode 100644 docs/bn/mkdocs.yml diff --git a/docs/bn/docs/index.md b/docs/bn/docs/index.md new file mode 100644 index 0000000000..4f778e8735 --- /dev/null +++ b/docs/bn/docs/index.md @@ -0,0 +1,464 @@ +

+ FastAPI +

+

+ FastAPI āωāĻšā§āϚāĻ•ā§āώāĻŽāϤāĻž āϏāĻŽā§āĻĒāĻ¨ā§āύ, āϏāĻšāĻœā§‡ āĻļ⧇āĻ–āĻžāϰ āĻāĻŦāĻ‚ āĻĻā§āϰ⧁āϤ āϕ⧋āĻĄ āĻ•āϰ⧇ āĻĒā§āϰ⧋āĻĄāĻžāĻ•āĻļāύ⧇āϰ āϜāĻ¨ā§āϝ āĻĢā§āϰāĻžāĻŽāĻ“ā§ŸāĻžāĻ°ā§āĻ•āĨ¤ +

+

+ + Test + + + Coverage + + + Package version + +

+ +--- + +**āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋ**: 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** āĻāϰ āϏāĻžāĻĨ⧇ āϏāĻ‚āϝ⧋āϝāύ āĻšāĻšā§āϛ⧇āĨ¤_" + +
āĻ•āĻŦāĻŋāϰ āĻ–āĻžāύ - āĻŽāĻžāχāĻ•ā§āϰ⧋āϏāĻĢā§āĻŸā§‡ (ref)
+ +--- + +"_āφāĻŽāϰāĻž **FastAPI** āϞāĻžāχāĻŦā§āϰ⧇āϰāĻŋ āĻ—ā§āϰāĻšāĻŖ āĻ•āϰ⧇āĻ›āĻŋ āĻāĻ•āϟāĻŋ **REST** āϏāĻžāĻ°ā§āĻ­āĻžāϰ āϤ⧈āϰāĻŋ āĻ•āϰāϤ⧇, āϝāĻž **āĻ­āĻŦāĻŋāĻˇā§āϝāĻĻā§āĻŦāĻžāĻŖā§€** āĻĒāĻžāĻ“āϝāĻŧāĻžāϰ āϜāĻ¨ā§āϝ āĻ•ā§ā§Ÿā§‡āϰāĻŋ āĻ•āϰāĻž āϝ⧇āϤ⧇ āĻĒāĻžāϰ⧇āĨ¤ [āϞ⧁āĻĄāωāχāϗ⧇āϰ āϜāĻ¨ā§āϝ]_" + +
āĻĒāĻŋāϝāĻŧ⧇āϰ⧋ āĻŽā§‹āϞāĻŋāύ⧋, āχāϝāĻŧāĻžāϰ⧋āĻ¸ā§āϞāĻžāĻ­ āĻĻ⧁āĻĻāĻŋāύ, āĻāĻŦāĻ‚ āϏāĻžāχ āϏ⧁āĻŽāĻ¨ā§āĻĨ āĻŽāĻŋāϰāĻŋāϝāĻŧāĻžāϞāĻž - āωāĻŦāĻžāϰ (ref)
+ +--- + +"_**Netflix** āφāĻŽāĻžāĻĻ⧇āϰ **āĻ•ā§āϰāĻžāχāϏāĻŋāϏ āĻŽā§āϝāĻžāύ⧇āϜāĻŽā§‡āĻ¨ā§āϟ** āĻ…āĻ°ā§āϕ⧇āĻ¸ā§āĻŸā§āϰ⧇āĻļāύ āĻĢā§āϰ⧇āĻŽāĻ“āϝāĻŧāĻžāĻ°ā§āĻ•: **āĻĄāĻŋāϏāĻĒā§āϝāĻžāϚ** āĻāϰ āĻ“āĻĒ⧇āύ āϏ⧋āĻ°ā§āϏ āϰāĻŋāϞāĻŋāϜ āĻ˜ā§‹āώāĻŖāĻž āĻ•āϰāϤ⧇ āĻĒ⧇āϰ⧇ āφāύāĻ¨ā§āĻĻāĻŋāϤ! [āϝāĻžāĻ•āĻŋāύāĻž **FastAPI** āĻĻāĻŋāϝāĻŧ⧇ āύāĻŋāĻ°ā§āĻŽāĻŋāϤ]_" + +
āϕ⧇āĻ­āĻŋāύ āĻ—ā§āϞāĻŋāϏāύ, āĻŽāĻžāĻ°ā§āĻ• āĻ­āĻŋāϞāĻžāύ⧋āĻ­āĻž, āĻĢāϰ⧇āĻ¸ā§āϟ āĻŽāύāϏ⧇āύ - āύ⧇āϟāĻĢā§āϞāĻŋāĻ•ā§āϏ (ref)
+ +--- + +"_āφāĻŽāĻŋ **FastAPI** āύāĻŋāϝāĻŧ⧇ āϚāĻžāρāĻĻ⧇āϰ āϏāĻŽāĻžāύ āĻ‰ā§ŽāϏāĻžāĻšāĻŋāϤāĨ¤ āĻāϟāĻŋ āϖ⧁āĻŦāχ āĻŽāϜāĻžāϰ!_" + +
āĻŦā§āϰāĻžāϝāĻŧāĻžāύ āĻ“āϕ⧇āύ - āĻĒāĻžāχāĻĨāύ āĻŦāĻžāχāϟāϏ āĻĒāĻĄāĻ•āĻžāĻ¸ā§āϟ āĻšā§‹āĻ¸ā§āϟ (ref)
+ +--- + +"\_āϏāĻ¤ā§āϝāĻŋāχ, āφāĻĒāύāĻŋ āϝāĻž āϤ⧈āϰāĻŋ āĻ•āϰ⧇āϛ⧇āύ āϤāĻž āϖ⧁āĻŦ āĻŽāϜāĻŦ⧁āϤ āĻāĻŦāĻ‚ āĻĒāϰāĻŋāĻĒā§‚āĻ°ā§āύ⧎ āĻ…āύ⧇āĻ• āωāĻĒāĻžāϝāĻŧ⧇, āφāĻŽāĻŋ āϝāĻž **Hug** āĻ āĻ•āϰāϤ⧇ āĻšā§‡ā§Ÿā§‡āĻ›āĻŋāϞāĻžāĻŽ - āϤāĻž āĻ•āĻžāωāϕ⧇ āϤ⧈āϰāĻŋ āĻ•āϰāϤ⧇ āĻĻ⧇āϖ⧇ āφāĻŽāĻŋ āϏāĻ¤ā§āϝāĻŋāχ āĻ…āύ⧁āĻĒā§āϰāĻžāύāĻŋāϤ⧎\_" + +
āϟāĻŋāĻŽā§‹āĻĨāĻŋ āĻ•ā§āϰāϏāϞ⧇ - Hug āĻ¸ā§āϰāĻˇā§āϟāĻž (ref)
+ +--- + +"āφāĻĒāύāĻŋ āϝāĻĻāĻŋ REST API āϤ⧈āϰāĻŋāϰ āϜāĻ¨ā§āϝ āĻāĻ•āϟāĻŋ **āφāϧ⧁āύāĻŋāĻ• āĻĢā§āϰ⧇āĻŽāĻ“ā§ŸāĻžāĻ°ā§āĻ•** āĻļāĻŋāĻ–āϤ⧇ āϚāĻžāύ, āϤāĻžāĻšāϞ⧇ **FastAPI** āĻĻ⧇āϖ⧁āύ [...] āĻāϟāĻŋ āĻĻā§āϰ⧁āϤ, āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻ•āϰāĻž āϏāĻšāϜ āĻāĻŦāĻ‚ āĻļāĻŋāĻ–āϤ⧇āĻ“ āϏāĻšāϜ [...]\_" + +"_āφāĻŽāϰāĻž āφāĻŽāĻžāĻĻ⧇āϰ **APIs** [...] āĻāϰ āϜāĻ¨ā§āϝ **FastAPI**- āϤ⧇ āĻāϏ⧇āĻ›āĻŋ [...] āφāĻŽāĻŋ āĻŽāύ⧇ āĻ•āϰāĻŋ āφāĻĒāύāĻŋāĻ“ āĻāϟāĻŋ āĻĒāĻ›āĻ¨ā§āĻĻ āĻ•āϰāĻŦ⧇āύ [...]_" + +
āχāύ⧇āϏ āĻŽāĻ¨ā§āϟāĻžāύāĻŋ - āĻŽā§āϝāĻžāĻĨāĻŋāω āĻšā§‹āύāĻŋāĻŦāĻžāϞ - Explosion AI āĻĒā§āϰāϤāĻŋāĻˇā§āĻ āĻžāϤāĻž - spaCy āĻ¸ā§āϰāĻˇā§āϟāĻž (ref) - (ref)
+ +--- + +## **Typer**, CLI āĻāϰ āϜāĻ¨ā§āϝ FastAPI + + + +āφāĻĒāύāĻŋ āϝāĻĻāĻŋ CLI āĻ…ā§āϝāĻžāĻĒ āĻŦāĻžāύāĻžāϤ⧇ āϚāĻžāύ, āϝāĻž āĻ•āĻŋāύāĻž āĻ“ā§Ÿā§‡āĻŦ API āĻāϰ āĻĒāϰāĻŋāĻŦāĻ°ā§āϤ⧇ āϟāĻžāĻ°ā§āĻŽāĻŋāύāĻžāϞ⧇ āĻŦā§āϝāĻŦāĻšāĻžāϰ āĻšāĻŦ⧇, āϤāĻžāĻšāϞ⧇ āĻĻ⧇āϖ⧁āύ**Typer**. + +**āϟāĻžāχāĻĒāĻžāϰ** āĻšāϞ FastAPI āĻāϰ āϛ⧋āϟ āĻ­āĻžāĻ‡ā§Ÿā§‡āϰ āĻŽāϤāĨ¤ āĻāĻŦāĻ‚ āĻāϟāĻŋāϰ āωāĻĻā§āĻĻ⧇āĻļā§āϝ āĻ›āĻŋāϞ **CLIs āĻāϰ FastAPI** āĻšāĻ“ā§ŸāĻžāĨ¤ âŒ¨ī¸ 🚀 + +## āĻĒā§āϰāϝāĻŧā§‹āϜāύ⧀āϝāĻŧāϤāĻž āϗ⧁āϞ⧋ + +Python 3.7+ + +FastAPI āĻ•āĻŋāϛ⧁ āĻĻāĻžāύāĻŦ⧇āĻĻ⧇āϰ āĻ•āĻžāρāϧ⧇ āĻĻāĻžāρāĻĄāĻŧāĻŋāϝāĻŧ⧇ āφāϛ⧇: + +- Starlette āĻ“āϝāĻŧ⧇āĻŦ āĻ…āĻ‚āĻļ⧇āϰ āϜāĻ¨ā§āϝ. +- Pydantic āĻĄā§‡āϟāĻž āĻ…āĻ‚āĻļāϗ⧁āϞāĻŋāϰ āϜāĻ¨ā§āϝ. + +## āχāύāĻ¸ā§āϟāϞ⧇āĻļāύ āĻĒā§āϰāĻ•ā§āϰāĻŋ⧟āĻž + +
+ +```console +$ pip install fastapi + +---> 100% +``` + +
+ +āφāĻĒāύāĻžāϰ āĻāĻ•āϟāĻŋ ASGI āϏāĻžāĻ°ā§āĻ­āĻžāϰ⧇āϰāĻ“ āĻĒā§āϰāϝāĻŧā§‹āϜāύ āĻšāĻŦ⧇, āĻĒā§āϰ⧋āĻĄāĻžāĻ•āĻļāύ⧇āϰ āϜāĻ¨ā§āϝ Uvicorn āĻ…āĻĨāĻŦāĻž Hypercorn. + +
+ +```console +$ pip install "uvicorn[standard]" + +---> 100% +``` + +
+ +## āωāĻĻāĻžāĻšāϰāĻŖ + +### āϤ⧈āϰāĻŋ + +- `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 āĻĒā§āϰāĻĻāĻ¤ā§āϤ): + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +### āĻŦāĻŋāĻ•āĻ˛ā§āĻĒ API āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋ + +āĻāĻŦāĻ‚ āĻāĻ–āύ http://127.0.0.1:8000/redoc āĻ āϝāĻžāύ. + +āφāĻĒāύāĻŋ āĻ¸ā§āĻŦāϝāĻŧāĻ‚āĻ•ā§āϰāĻŋāϝāĻŧ āĻ­āĻžāĻŦ⧇ āĻĒā§āϰāĻ¸ā§āϤ⧁āϤ āĻŦāĻŋāĻ•āĻ˛ā§āĻĒ āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋ āĻĻ⧇āĻ–āϤ⧇ āĻĒāĻžāĻŦ⧇āύ (ReDoc āĻĒā§āϰāĻĻāĻ¤ā§āϤ): + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## āωāĻĻāĻžāĻšāϰāĻŖāĻ¸ā§āĻŦāϰ⧂āĻĒ āφāĻĒāĻ—ā§āϰ⧇āĻĄ + +āĻāĻ–āύ `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 āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋāϟāĻŋ āĻ¸ā§āĻŦāϝāĻŧāĻ‚āĻ•ā§āϰāĻŋāϝāĻŧāĻ­āĻžāĻŦ⧇ āωāĻ¨ā§āύ⧀āϤ āĻšāϝ⧇ āϝāĻžāĻŦ⧇, āύāϤ⧁āύ āĻŦāĻĄāĻŋ āϏāĻš: + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) + +- "Try it out" āĻŦāĻžāϟāύ⧇ āϚāĻžāĻĒ⧁āύ, āĻāϟāĻŋ āφāĻĒāύāĻžāϕ⧇ āĻĒ⧇āϰāĻžāĻŽāĻŋāϟāĻžāϰāϗ⧁āϞ⧋ āĻĒā§‚āϰāĻŖ āĻ•āϰāϤ⧇ āĻāĻŦāĻ‚ API āĻāϰ āϏāĻžāĻĨ⧇ āϏāϰāĻžāϏāϰāĻŋ āĻ•ā§āϰāĻŋ⧟āĻž-āĻ•āϞāĻžāĻĒ āĻ•āϰāϤ⧇ āĻĻāĻŋāĻŦ⧇: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png) + +- āϤāĻžāϰāĻĒāϰ⧇ "Execute" āĻŦāĻžāϟāύ⧇ āϚāĻžāĻĒ⧁āύ, āĻŦā§āϝāĻŦāĻšāĻžāϰāĻ•āĻžāϰ⧀āϰ āχāĻ¨ā§āϟāĻžāϰāĻĢ⧇āϏ āφāĻĒāύāĻžāϰ API āĻāϰ āϏāĻžāĻĨ⧇ āϝ⧋āĻ—āĻžāϝ⧋āĻ— āĻ•āϰāĻŦ⧇, āĻĒ⧇āϰāĻžāĻŽāĻŋāϟāĻžāϰ āĻĒāĻžāĻ āĻžāĻŦ⧇, āĻĢāϞāĻžāĻĢāϞāϗ⧁āϞāĻŋ āĻĒāĻžāĻŦ⧇ āĻāĻŦāĻ‚ āϏ⧇āϗ⧁āϞāĻŋ āĻĒāĻ°ā§āϰāĻĻāĻžā§Ÿ āĻĻ⧇āĻ–āĻžāĻŦ⧇: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png) + +### āĻŦāĻŋāĻ•āĻ˛ā§āĻĒ API āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋ āφāĻĒāĻ—ā§āϰ⧇āĻĄ + +āĻāĻŦāĻ‚ āĻāĻ–āύ http://127.0.0.1:8000/redoc āĻ āϝāĻžāύāĨ¤ + +- āĻŦāĻŋāĻ•āĻ˛ā§āĻĒ āύāĻŋāĻ°ā§āĻĻ⧇āĻļāĻŋāĻ•āĻž āύāĻĨāĻŋāϤ⧇āĻ“ āύāϤ⧁āύ āĻ•ā§ā§Ÿā§‡āϰāĻŋ āĻĒā§āϝāĻžāϰāĻžāĻŽāĻŋāϟāĻžāϰ āĻāĻŦāĻ‚ āĻŦāĻĄāĻŋ āĻĒā§āϰāϤāĻŋāĻĢāϞāĻŋāϤ āĻšāĻŦ⧇: + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) + +### āϏāĻ‚āĻ•ā§āώāĻŋāĻĒā§āϤāĻ•āϰāĻŖ + +āϏāĻ‚āĻ•ā§āώ⧇āĻĒ⧇, āφāĻĒāύāĻŋ **āĻļ⧁āϧ⧁ āĻāĻ•āĻŦāĻžāϰ** āĻĒā§āϝāĻžāϰāĻžāĻŽāĻŋāϟāĻžāϰ⧇āϰ āϧāϰāύ, āĻŦāĻĄāĻŋ āχāĻ¤ā§āϝāĻžāĻĻāĻŋ āĻĢāĻžāĻ‚āĻļāύ āĻĒā§āϝāĻžāϰāĻžāĻŽāĻŋāϟāĻžāϰ āĻšāĻŋāϏ⧇āĻŦ⧇ āĻ˜ā§‹āώāĻŖāĻž āĻ•āϰ⧇āύāĨ¤ + +āφāĻĒāύāĻŋ āϏ⧇āϟāĻŋ āφāϧ⧁āύāĻŋāĻ• āĻĒāĻžāχāĻĨāύ⧇āϰ āϏāĻžāĻĨ⧇ āĻ•āϰ⧇āύāĨ¤ + +āφāĻĒāύāĻžāϕ⧇ āύāϤ⧁āύ āĻ•āϰ⧇ āύāĻŋāĻ°ā§āĻĻāĻŋāĻˇā§āϟ āϕ⧋āύ āϞāĻžāχāĻŦā§āϰ⧇āϰāĻŋāϰ āĻŦāĻžāĻ•ā§āϝ āĻ—āĻ āύ, āĻĢāĻžāĻ‚āĻļāύ āĻŦāĻž āĻ•ā§āϞāĻžāϏ āĻ•āĻŋāϛ⧁āχ āĻļāĻŋāĻ–āϤ⧇ āĻšāĻšā§āϛ⧇ āύāĻžāĨ¤ + +āĻļ⧁āϧ⧁āχ āφāϧ⧁āύāĻŋāĻ• **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 ... +``` + +...āĻāĻŦāĻ‚ āĻĻ⧇āϖ⧁āύ āĻ•āĻŋāĻ­āĻžāĻŦ⧇ āφāĻĒāύāĻžāϰ āĻāĻĄāĻŋāϟāϰ āωāĻĒāĻžāĻĻāĻžāύāϗ⧁āϞ⧋āϕ⧇ āϏ⧟āĻ‚āĻ•ā§āϰāĻŋ⧟āĻ­āĻžāĻŦ⧇-āϏāĻŽā§āĻĒāĻ¨ā§āύ āĻ•āϰāĻŦ⧇ āĻāĻŦāĻ‚ āϤāĻžāĻĻ⧇āϰ āϧāϰāύ āϜāĻžāύāϤ⧇ āĻĒāĻžāϰāĻŦ⧇: + +![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) + +āφāϰāĻ“ āĻŦ⧈āĻļāĻŋāĻˇā§āĻŸā§āϝ āϏāĻŽā§āĻĒāĻ¨ā§āύ āωāĻĻāĻžāĻšāϰāϪ⧇āϰ āϜāĻ¨ā§āϝ, āĻĻ⧇āϖ⧁āύ āϟāĻŋāωāĻŸā§‹āϰāĻŋ⧟āĻžāϞ - āĻŦā§āϝāĻŦāĻšāĻžāϰāĻ•āĻžāϰ⧀āϰ āĻ—āĻžāχāĻĄ. + +**āĻ¸ā§āĻĒ⧟āϞāĻžāϰ āϏāϤāĻ°ā§āĻ•āϤāĻž**: āϟāĻŋāωāĻŸā§‹āϰāĻŋ⧟āĻžāϞ - āĻŦā§āϝāĻŦāĻšāĻžāϰāĻ•āĻžāϰ⧀āϰ āĻ—āĻžāχāĻĄ āύāĻŋāĻŽā§āύ⧋āĻ•ā§āϤ āĻŦāĻŋāώ⧟āϗ⧁āϞāĻŋ āĻ…āĻ¨ā§āϤāĻ°ā§āϭ⧁āĻ•ā§āϤ āĻ•āϰ⧇: + +- **āĻšā§‡āĻĄāĻžāϰ**, **āϕ⧁āĻ•āĻŋāϜ**, **āĻĢāĻ°ā§āĻŽ āĻĢāĻŋāĻ˛ā§āĻĄ** āĻāĻŦāĻ‚ **āĻĢāĻžāχāϞāϗ⧁āϞāĻŋ** āĻāĻŽāύ āĻ…āĻ¨ā§āϝāĻžāĻ¨ā§āϝ āϜāĻžā§ŸāĻ—āĻž āĻĨ⧇āϕ⧇ āĻĒā§āϝāĻžāϰāĻžāĻŽāĻŋāϟāĻžāϰ āĻ˜ā§‹āώāĻŖāĻž āĻ•āϰāĻžāĨ¤ +- `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 From 1cd23a1dbce8f2fd7f15ece57c3cd45a2cb04cac Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 17:43:56 +0000 Subject: [PATCH 004/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6885ef68d7..f3c70489b6 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -26,6 +26,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). From 843bc85155be86d7688ab126bb7ea266d410bf71 Mon Sep 17 00:00:00 2001 From: Sungyun Hur Date: Thu, 11 Jan 2024 03:15:04 +0900 Subject: [PATCH 005/305] =?UTF-8?q?=F0=9F=93=9D=20Fix=20broken=20link=20in?= =?UTF-8?q?=20`docs/en/docs/tutorial/sql-databases.md`=20(#10765)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/docs/tutorial/sql-databases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/docs/tutorial/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md index 010244bbf6..ce65079122 100644 --- a/docs/en/docs/tutorial/sql-databases.md +++ b/docs/en/docs/tutorial/sql-databases.md @@ -624,7 +624,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. From 1334485435ce0e934a965b23912654baab5d861d Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 18:15:28 +0000 Subject: [PATCH 006/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index f3c70489b6..b0a6c8dc6f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From b584faffee11bfc08bea3bd2d66c304701b921d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 10 Jan 2024 23:13:55 +0400 Subject: [PATCH 007/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20notes=20about=20Py?= =?UTF-8?q?dantic=20v2's=20new=20`.model=5Fdump()`=20(#10929)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/how-to/async-sql-encode-databases.md | 5 +++++ docs/en/docs/tutorial/body-updates.md | 20 ++++++++++++++----- docs/en/docs/tutorial/extra-models.md | 5 +++++ docs/en/docs/tutorial/response-model.md | 5 +++++ docs/en/docs/tutorial/sql-databases.md | 5 +++++ 5 files changed, 35 insertions(+), 5 deletions(-) diff --git a/docs/en/docs/how-to/async-sql-encode-databases.md b/docs/en/docs/how-to/async-sql-encode-databases.md index 697167f790..0e2ccce78d 100644 --- a/docs/en/docs/how-to/async-sql-encode-databases.md +++ b/docs/en/docs/how-to/async-sql-encode-databases.md @@ -114,6 +114,11 @@ Create the *path operation function* to create notes: {!../../../docs_src/async_sql_databases/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. + !!! Note Notice that as we communicate with the database using `await`, the *path operation function* is declared with `async`. 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/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/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md index ce65079122..1bc87a702d 100644 --- a/docs/en/docs/tutorial/sql-databases.md +++ b/docs/en/docs/tutorial/sql-databases.md @@ -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. From 91d7fb6d255156a753108b4f762a4f12b8861961 Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 19:14:15 +0000 Subject: [PATCH 008/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b0a6c8dc6f..ab64e33d0a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From 07f8d31ec9d6e2234e12515f3373f57020b1726d Mon Sep 17 00:00:00 2001 From: Aliaksei Urbanski Date: Wed, 10 Jan 2024 23:55:45 +0300 Subject: [PATCH 009/305] =?UTF-8?q?=E2=9C=A8=20Add=20support=20for=20Pytho?= =?UTF-8?q?n=203.12=20(#10666)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- .github/workflows/test.yml | 7 ++++++- docs_src/security/tutorial004.py | 6 +++--- docs_src/security/tutorial004_an.py | 6 +++--- docs_src/security/tutorial004_an_py310.py | 6 +++--- docs_src/security/tutorial004_an_py39.py | 6 +++--- docs_src/security/tutorial004_py310.py | 6 +++--- docs_src/security/tutorial005.py | 6 +++--- docs_src/security/tutorial005_an.py | 6 +++--- docs_src/security/tutorial005_an_py310.py | 6 +++--- docs_src/security/tutorial005_an_py39.py | 6 +++--- docs_src/security/tutorial005_py310.py | 6 +++--- docs_src/security/tutorial005_py39.py | 6 +++--- pyproject.toml | 10 ++++++++++ 13 files changed, 49 insertions(+), 34 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ebb80efdf..032db9c9c8 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -42,7 +42,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python-version: + - "3.12" + - "3.11" + - "3.10" + - "3.9" + - "3.8" pydantic-version: ["pydantic-v1", "pydantic-v2"] fail-fast: false steps: diff --git a/docs_src/security/tutorial004.py b/docs_src/security/tutorial004.py index 64099abe9c..134c15c5a0 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 diff --git a/docs_src/security/tutorial004_an.py b/docs_src/security/tutorial004_an.py index ca350343d2..204151a566 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 diff --git a/docs_src/security/tutorial004_an_py310.py b/docs_src/security/tutorial004_an_py310.py index 8bf5f3b718..64dfa15c62 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 diff --git a/docs_src/security/tutorial004_an_py39.py b/docs_src/security/tutorial004_an_py39.py index a634e23de9..631a8366eb 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 diff --git a/docs_src/security/tutorial004_py310.py b/docs_src/security/tutorial004_py310.py index 797d56d043..470f22e29f 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 diff --git a/docs_src/security/tutorial005.py b/docs_src/security/tutorial005.py index bd0a33581c..ece461bc8a 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 diff --git a/docs_src/security/tutorial005_an.py b/docs_src/security/tutorial005_an.py index ec4fa1a07e..c5b5609e52 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 diff --git a/docs_src/security/tutorial005_an_py310.py b/docs_src/security/tutorial005_an_py310.py index 45f3fc0bd6..5e81a50e12 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 diff --git a/docs_src/security/tutorial005_an_py39.py b/docs_src/security/tutorial005_an_py39.py index ecb5ed5160..ae9811c689 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 diff --git a/docs_src/security/tutorial005_py310.py b/docs_src/security/tutorial005_py310.py index ba756ef4f4..0fcdda4c00 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 diff --git a/docs_src/security/tutorial005_py39.py b/docs_src/security/tutorial005_py39.py index 9e4dbcffba..d756c0b6b8 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 diff --git a/pyproject.toml b/pyproject.toml index 38728d99e9..2fde7553a8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,7 @@ classifiers = [ "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Topic :: Internet :: WWW/HTTP :: HTTP Servers", "Topic :: Internet :: WWW/HTTP", ] @@ -111,6 +112,15 @@ filterwarnings = [ "ignore::trio.TrioDeprecationWarning", # TODO remove pytest-cov 'ignore::pytest.PytestDeprecationWarning:pytest_cov', + # TODO: remove after upgrading SQLAlchemy to a version that includes the following changes + # https://github.com/sqlalchemy/sqlalchemy/commit/59521abcc0676e936b31a523bd968fc157fef0c2 + 'ignore:datetime\.datetime\.utcfromtimestamp\(\) is deprecated and scheduled for removal in a future version\..*:DeprecationWarning:sqlalchemy', + # TODO: remove after upgrading python-jose to a version that explicitly supports Python 3.12 + # also, if it won't receive an update, consider replacing python-jose with some alternative + # related issues: + # - https://github.com/mpdavis/python-jose/issues/332 + # - https://github.com/mpdavis/python-jose/issues/334 + 'ignore:datetime\.datetime\.utcnow\(\) is deprecated and scheduled for removal in a future version\..*:DeprecationWarning:jose', ] [tool.coverage.run] From 21145d8e9f896502ae227678c63467fb00384cfa Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 20:56:59 +0000 Subject: [PATCH 010/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ab64e33d0a..25219b3280 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -7,6 +7,10 @@ hide: ## Latest Changes +### Features + +* ✨ Add support for Python 3.12. PR [#10666](https://github.com/tiangolo/fastapi/pull/10666) by [@Jamim](https://github.com/Jamim). + ### Docs * 📝 Add notes about Pydantic v2's new `.model_dump()`. PR [#10929](https://github.com/tiangolo/fastapi/pull/10929) by [@tiangolo](https://github.com/tiangolo). From 135dcba746cdaf2b4726f4f10fad9eb8bb91e342 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Wed, 10 Jan 2024 22:00:32 +0100 Subject: [PATCH 011/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20VS=20Code=20tutori?= =?UTF-8?q?al=20link=20(#10592)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index d9cfe3431d..f15560d1b6 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - 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 From 0da980cb0b73c8cb5713d95d44620c41c0a29b5d Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 10 Jan 2024 21:00:51 +0000 Subject: [PATCH 012/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 25219b3280..b523be75df 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -13,6 +13,7 @@ hide: ### Docs +* 📝 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). From 69cb005f61239a378a7e0715cc5e3ff4b713ab4d Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Thu, 11 Jan 2024 15:33:05 +0100 Subject: [PATCH 013/305] =?UTF-8?q?=F0=9F=93=9D=20Replace=20`email`=20with?= =?UTF-8?q?=20`username`=20in=20`docs=5Fsrc/security/tutorial007`=20code?= =?UTF-8?q?=20examples=20(#10649)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/advanced/security/http-basic-auth.md | 6 +++--- docs_src/security/tutorial007.py | 2 +- docs_src/security/tutorial007_an.py | 2 +- docs_src/security/tutorial007_an_py39.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) 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_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 From 5b1e6865c50207ad24d26b55f3577b5c3b8244b3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 14:33:27 +0000 Subject: [PATCH 014/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b523be75df..f95ccff567 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -13,6 +13,7 @@ hide: ### Docs +* 📝 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). From c46eba8004cc688ebfb4d9bf4074ccc8c6f0ca3e Mon Sep 17 00:00:00 2001 From: s111d Date: Thu, 11 Jan 2024 17:33:57 +0300 Subject: [PATCH 015/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo=20in=20?= =?UTF-8?q?`docs/en/docs/alternatives.md`=20(#10931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/docs/alternatives.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. From c3e062542375f1c8c9e645ca1889872e51e97ed4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 14:35:15 +0000 Subject: [PATCH 016/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index f95ccff567..0ec3fd4f51 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -13,6 +13,7 @@ hide: ### 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). From 5e583199b3ad252a3539f1d865e36d3c9ae61318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 11 Jan 2024 19:29:54 +0400 Subject: [PATCH 017/305] =?UTF-8?q?=E2=AC=86=EF=B8=8F=20Upgrade=20Starlett?= =?UTF-8?q?e=20to=20>=3D0.35.0,<0.36.0=20(#10938)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pyproject.toml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 2fde7553a8..8e7f8bbbe5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ classifiers = [ "Topic :: Internet :: WWW/HTTP", ] dependencies = [ - "starlette>=0.29.0,<0.33.0", + "starlette>=0.35.0,<0.36.0", "pydantic>=1.7.4,!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0", "typing-extensions>=4.8.0", ] @@ -121,6 +121,9 @@ filterwarnings = [ # - https://github.com/mpdavis/python-jose/issues/332 # - https://github.com/mpdavis/python-jose/issues/334 'ignore:datetime\.datetime\.utcnow\(\) is deprecated and scheduled for removal in a future version\..*:DeprecationWarning:jose', + # TODO: remove after upgrading Starlette to a version including https://github.com/encode/starlette/pull/2406 + # Probably Starlette 0.36.0 + "ignore: The 'method' parameter is not used, and it will be removed.:DeprecationWarning:starlette", ] [tool.coverage.run] From 7c1aeb5db21593421d96fa226461569c77f973eb Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 15:30:35 +0000 Subject: [PATCH 018/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0ec3fd4f51..3395215af3 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -11,6 +11,10 @@ hide: * ✨ 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). From cb95d1cb8927292fc096834a62c3aa46af46e4ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Thu, 11 Jan 2024 16:32:00 +0100 Subject: [PATCH 019/305] =?UTF-8?q?=F0=9F=94=96=20Release=20version=200.10?= =?UTF-8?q?9.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 2 ++ fastapi/__init__.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 3395215af3..d75d9e3bd9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -7,6 +7,8 @@ hide: ## Latest Changes +## 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). diff --git a/fastapi/__init__.py b/fastapi/__init__.py index 02ac83b5e4..f457fafd4a 100644 --- a/fastapi/__init__.py +++ b/fastapi/__init__.py @@ -1,6 +1,6 @@ """FastAPI framework, high performance, easy to learn, fast to code, ready for production""" -__version__ = "0.108.0" +__version__ = "0.109.0" from starlette import status as status From 6bda1326a47968a1e81888da39397c4460368bb8 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Thu, 11 Jan 2024 16:59:27 +0100 Subject: [PATCH 020/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20location=20info=20?= =?UTF-8?q?to=20`tutorial/bigger-applications.md`=20(#10552)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/em/docs/tutorial/bigger-applications.md | 26 ++++++++--------- docs/en/docs/tutorial/bigger-applications.md | 30 ++++++++++---------- docs/zh/docs/tutorial/bigger-applications.md | 26 ++++++++--------- 3 files changed, 41 insertions(+), 41 deletions(-) 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/en/docs/tutorial/bigger-applications.md b/docs/en/docs/tutorial/bigger-applications.md index 1cf7e50e02..9ec3720c8d 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="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/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!} ``` From fedee4d028e8c5ff634f91ca742fb404641adb40 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 15:59:47 +0000 Subject: [PATCH 021/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d75d9e3bd9..8d789b1373 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -7,6 +7,10 @@ hide: ## Latest Changes +### Docs + +* 📝 Add location info to `tutorial/bigger-applications.md`. PR [#10552](https://github.com/tiangolo/fastapi/pull/10552) by [@nilslindemann](https://github.com/nilslindemann). + ## 0.109.0 ### Features From 1369c45c2e047fe349c18fd0d4a29451de02106f Mon Sep 17 00:00:00 2001 From: Jeny Sadadia Date: Thu, 11 Jan 2024 21:37:05 +0530 Subject: [PATCH 022/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20Talk=20by=20Jeny=20Sadadia=20(#10265)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jeny Sadadia Co-authored-by: SebastiÃĄn Ramírez --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index f15560d1b6..ed512b733b 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -349,6 +349,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 From facdc9162933acec437eecb0318d8d2bfdec2d6b Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 16:07:29 +0000 Subject: [PATCH 023/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 8d789b1373..692890d73b 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). ## 0.109.0 From 838e9c964eaef85f47ec8b22b4d1feb124a3a039 Mon Sep 17 00:00:00 2001 From: malicious <38064672+malicious@users.noreply.github.com> Date: Thu, 11 Jan 2024 16:31:18 +0000 Subject: [PATCH 024/305] =?UTF-8?q?=F0=9F=93=9D=20Reword=20in=20docs,=20fr?= =?UTF-8?q?om=20"have=20in=20mind"=20to=20"keep=20in=20mind"=20(#10376)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/docs/advanced/additional-responses.md | 2 +- docs/en/docs/advanced/behind-a-proxy.md | 4 ++-- docs/en/docs/advanced/custom-response.md | 2 +- docs/en/docs/advanced/dataclasses.md | 2 +- docs/en/docs/advanced/events.md | 2 +- docs/en/docs/advanced/response-change-status-code.md | 2 +- docs/en/docs/advanced/response-cookies.md | 2 +- docs/en/docs/advanced/response-headers.md | 2 +- docs/en/docs/advanced/websockets.md | 2 +- docs/en/docs/benchmarks.md | 2 +- docs/en/docs/deployment/concepts.md | 4 ++-- docs/en/docs/deployment/https.md | 2 +- docs/en/docs/deployment/index.md | 4 ++-- docs/en/docs/deployment/manually.md | 4 ++-- docs/en/docs/help-fastapi.md | 6 +++--- docs/en/docs/how-to/sql-databases-peewee.md | 4 ++-- docs/en/docs/release-notes.md | 2 +- docs/en/docs/tutorial/body-nested-models.md | 2 +- docs/en/docs/tutorial/middleware.md | 2 +- docs/en/docs/tutorial/path-params-numeric-validations.md | 4 ++-- docs/en/docs/tutorial/query-params-str-validations.md | 8 ++++---- docs/en/docs/tutorial/request-files.md | 2 +- docs/en/docs/tutorial/security/get-current-user.md | 2 +- docs/en/docs/tutorial/security/oauth2-jwt.md | 2 +- docs/en/docs/tutorial/sql-databases.md | 2 +- 25 files changed, 36 insertions(+), 36 deletions(-) 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/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..6df1411d1f 100644 --- a/docs/en/docs/advanced/events.md +++ b/docs/en/docs/advanced/events.md @@ -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/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/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/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 692890d73b..6431ed2c3b 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -3379,7 +3379,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/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/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/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..4159b36591 100644 --- a/docs/en/docs/tutorial/security/oauth2-jwt.md +++ b/docs/en/docs/tutorial/security/oauth2-jwt.md @@ -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 1bc87a702d..161d5491d7 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 From 6761fc1fa4ffce2cc0c73117aeadce81fa3a659c Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 16:31:38 +0000 Subject: [PATCH 025/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6431ed2c3b..9cdb82e199 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From abe7db6b2489052e73b2386d6c5372922f9a7cee Mon Sep 17 00:00:00 2001 From: Mikhail Rozhkov Date: Thu, 11 Jan 2024 18:29:24 +0100 Subject: [PATCH 026/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20ML=20serving=20and=20monitoring=20with=20FastAPI=20and=20Evi?= =?UTF-8?q?dently=20(#9701)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index ed512b733b..aea400dfcd 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - 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 From 3325635eed6ab45e81de31766863e63ab3a7662a Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 17:29:48 +0000 Subject: [PATCH 027/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 9cdb82e199..ccb2d15933 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From 0380ca3e69efe642149bda481d05906f99f4da69 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Thu, 11 Jan 2024 18:42:43 +0100 Subject: [PATCH 028/305] =?UTF-8?q?=F0=9F=93=9D=20Review=20and=20rewording?= =?UTF-8?q?=20of=20`en/docs/contributing.md`=20(#10480)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/docs/contributing.md | 71 ++++++++++++++++++++---------------- 1 file changed, 40 insertions(+), 31 deletions(-) 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: From 0be64abac748116f12d68ca766915ec46ff879df Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 17:43:08 +0000 Subject: [PATCH 029/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ccb2d15933..65a81f7d31 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From e6759aa6044929d1aaaea8280dd2e576a2339dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B3=20Lino?= Date: Thu, 11 Jan 2024 20:52:15 +0100 Subject: [PATCH 030/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20Instrument=20a=20FastAPI=20service=20adding=20tracing=20with?= =?UTF-8?q?=20OpenTelemetry=20and=20send/show=20traces=20in=20Grafana=20Te?= =?UTF-8?q?mpo=20(#9440)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Carol Willing Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index aea400dfcd..4121564426 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - 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 From 4dde172a969644e4e4f88b5d6c29b1d4d2e95303 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 19:52:37 +0000 Subject: [PATCH 031/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 65a81f7d31..23dbeb5b3c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From f74aeb00674d35d10e4f9f0ecd34a8e36a0df131 Mon Sep 17 00:00:00 2001 From: Hungtsetse <33526088+hungtsetse@users.noreply.github.com> Date: Fri, 12 Jan 2024 03:56:09 +0800 Subject: [PATCH 032/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20hyperlink=20to=20`?= =?UTF-8?q?docs/en/docs/tutorial/static-files.md`=20(#10243)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/tutorial/static-files.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 99769b966975b85321a8213b48a57828fac9453c Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 19:57:48 +0000 Subject: [PATCH 033/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 23dbeb5b3c..66b7f260e6 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From b62e379a55488d523c42718616f0ad7eea526850 Mon Sep 17 00:00:00 2001 From: Ankit Anchlia Date: Thu, 11 Jan 2024 13:59:29 -0600 Subject: [PATCH 034/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20Explore=20How=20to=20Effectively=20Use=20JWT=20With=20FastAP?= =?UTF-8?q?I=20(#10212)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ankit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index 4121564426..b4b8687c4d 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ 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 From cbcd3fe863a4ee537facb65acf0e8ef9e2b6da23 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 20:01:57 +0000 Subject: [PATCH 035/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 66b7f260e6..b4b137a301 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From d192ddacec3ffc2d0ff5ec43bc7f816358ab769c Mon Sep 17 00:00:00 2001 From: Pedro Augusto de Paula Barbosa Date: Thu, 11 Jan 2024 17:18:07 -0300 Subject: [PATCH 036/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Update=20highlight?= =?UTF-8?q?ed=20line=20in=20`docs/en/docs/tutorial/bigger-applications.md`?= =?UTF-8?q?=20(#5490)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/docs/tutorial/bigger-applications.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/docs/tutorial/bigger-applications.md b/docs/en/docs/tutorial/bigger-applications.md index 9ec3720c8d..b2d9284052 100644 --- a/docs/en/docs/tutorial/bigger-applications.md +++ b/docs/en/docs/tutorial/bigger-applications.md @@ -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" title="app/main.py" +```Python hl_lines="4-5" title="app/main.py" {!../../../docs_src/bigger_applications/app/main.py!} ``` From 53a3dd740826362dd874c92d5c08fb5f607e2bc0 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 20:18:31 +0000 Subject: [PATCH 037/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b4b137a301..80a5818652 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* âœī¸ 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). From fd97e8efe43baced1c040cac3627904b37f2380b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Szaci=C5=82owski?= <44623605+piotrszacilowski@users.noreply.github.com> Date: Thu, 11 Jan 2024 22:21:35 +0100 Subject: [PATCH 038/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20usage=20of=20To?= =?UTF-8?q?ken=20model=20in=20security=20docs=20(#9313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra SÃĄnchez Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../em/docs/advanced/security/oauth2-scopes.md | 6 +++--- docs/em/docs/tutorial/security/oauth2-jwt.md | 4 ++-- .../en/docs/advanced/security/oauth2-scopes.md | 18 +++++++++--------- docs/en/docs/tutorial/security/oauth2-jwt.md | 4 ++-- docs/ja/docs/tutorial/security/oauth2-jwt.md | 2 +- docs/zh/docs/tutorial/security/oauth2-jwt.md | 2 +- docs_src/security/tutorial004.py | 8 +++++--- docs_src/security/tutorial004_an.py | 6 +++--- docs_src/security/tutorial004_an_py310.py | 6 +++--- docs_src/security/tutorial004_an_py39.py | 6 +++--- docs_src/security/tutorial004_py310.py | 8 +++++--- docs_src/security/tutorial005.py | 8 +++++--- docs_src/security/tutorial005_an.py | 6 +++--- docs_src/security/tutorial005_an_py310.py | 6 +++--- docs_src/security/tutorial005_an_py39.py | 6 +++--- docs_src/security/tutorial005_py310.py | 8 +++++--- docs_src/security/tutorial005_py39.py | 8 +++++--- 17 files changed, 61 insertions(+), 51 deletions(-) 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/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/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/tutorial/security/oauth2-jwt.md b/docs/en/docs/tutorial/security/oauth2-jwt.md index 4159b36591..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!} ``` diff --git a/docs/ja/docs/tutorial/security/oauth2-jwt.md b/docs/ja/docs/tutorial/security/oauth2-jwt.md index 348ffda016..d5b179aa05 100644 --- a/docs/ja/docs/tutorial/security/oauth2-jwt.md +++ b/docs/ja/docs/tutorial/security/oauth2-jwt.md @@ -167,7 +167,7 @@ JWTトãƒŧã‚¯ãƒŗãŽįŊ˛åãĢäŊŋį”¨ã™ã‚‹ã‚ĸãƒĢゴãƒĒã‚ēム`"HS256"`を指厚し JWTã‚ĸクã‚ģ゚トãƒŧã‚¯ãƒŗã‚’äŊœæˆã—、それをčŋ”しぞす。 -```Python hl_lines="115-128" +```Python hl_lines="115-130" {!../../../docs_src/security/tutorial004.py!} ``` 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_src/security/tutorial004.py b/docs_src/security/tutorial004.py index 134c15c5a0..044eec7003 100644 --- a/docs_src/security/tutorial004.py +++ b/docs_src/security/tutorial004.py @@ -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 204151a566..c78e8496c6 100644 --- a/docs_src/security/tutorial004_an.py +++ b/docs_src/security/tutorial004_an.py @@ -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 64dfa15c62..36dbc677e0 100644 --- a/docs_src/security/tutorial004_an_py310.py +++ b/docs_src/security/tutorial004_an_py310.py @@ -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 631a8366eb..23fc04a721 100644 --- a/docs_src/security/tutorial004_an_py39.py +++ b/docs_src/security/tutorial004_an_py39.py @@ -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 470f22e29f..8363d45ab5 100644 --- a/docs_src/security/tutorial004_py310.py +++ b/docs_src/security/tutorial004_py310.py @@ -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 ece461bc8a..b16bf440a5 100644 --- a/docs_src/security/tutorial005.py +++ b/docs_src/security/tutorial005.py @@ -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 c5b5609e52..95e406b32f 100644 --- a/docs_src/security/tutorial005_an.py +++ b/docs_src/security/tutorial005_an.py @@ -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 5e81a50e12..c6116a5ed1 100644 --- a/docs_src/security/tutorial005_an_py310.py +++ b/docs_src/security/tutorial005_an_py310.py @@ -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 ae9811c689..af51c08b50 100644 --- a/docs_src/security/tutorial005_an_py39.py +++ b/docs_src/security/tutorial005_an_py39.py @@ -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 0fcdda4c00..37a22c7090 100644 --- a/docs_src/security/tutorial005_py310.py +++ b/docs_src/security/tutorial005_py310.py @@ -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 d756c0b6b8..c275807636 100644 --- a/docs_src/security/tutorial005_py39.py +++ b/docs_src/security/tutorial005_py39.py @@ -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) From 22e68b151d92aff6d6e0cdf001b08a792e20020d Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 21:21:57 +0000 Subject: [PATCH 039/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 80a5818652..945d342d95 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From 0c796747a3d652f7d5d7fc59c5fbb68512b64ccf Mon Sep 17 00:00:00 2001 From: Ezzeddin Abdullah Date: Fri, 12 Jan 2024 00:25:37 +0200 Subject: [PATCH 040/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20template=20docs?= =?UTF-8?q?=20with=20more=20info=20about=20`url=5Ffor`=20(#5937)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/docs/advanced/templates.md | 48 +++++++++++++++++-- docs_src/templates/templates/item.html | 2 +- .../test_templates/test_tutorial001.py | 5 +- 3 files changed, 49 insertions(+), 6 deletions(-) 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_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 @@ -

Item ID: {{ id }}

+

Item ID: {{ id }}

diff --git a/tests/test_tutorial/test_templates/test_tutorial001.py b/tests/test_tutorial/test_templates/test_tutorial001.py index bfee5c0902..4d4729425e 100644 --- a/tests/test_tutorial/test_templates/test_tutorial001.py +++ b/tests/test_tutorial/test_templates/test_tutorial001.py @@ -16,7 +16,10 @@ def test_main(): client = TestClient(app) response = client.get("/items/foo") assert response.status_code == 200, response.text - assert b"

Item ID: foo

" in response.content + assert ( + b'

Item ID: foo

' + in response.content + ) response = client.get("/static/styles.css") assert response.status_code == 200, response.text assert b"color: green;" in response.content From 5f37d3870bd101bdda65e6dbda06ca969f6ef510 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 11 Jan 2024 22:25:58 +0000 Subject: [PATCH 041/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 945d342d95..af3d2e2b29 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From ea84587a2f0431a7fad42395fd1dadee3dae3fed Mon Sep 17 00:00:00 2001 From: Turabek Gaybullaev <43612265+Torabek@users.noreply.github.com> Date: Fri, 12 Jan 2024 20:10:55 +0900 Subject: [PATCH 042/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Remove=20broken=20?= =?UTF-8?q?links=20from=20`external=5Flinks.yml`=20(#10943)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/data/external_links.yml | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index b4b8687c4d..00d6f696de 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -40,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 @@ -96,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 @@ -112,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 @@ -164,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 @@ -200,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 From e0eaaee7496e3f95cd0e1c47c5473c989f390ed6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 11:11:15 +0000 Subject: [PATCH 043/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index af3d2e2b29..671e632161 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* âœī¸ 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). From 3ca38568c1a31628c3f5863fb67a99b6b44cec9d Mon Sep 17 00:00:00 2001 From: Aleksandr Andrukhov Date: Fri, 12 Jan 2024 14:12:19 +0300 Subject: [PATCH 044/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Russian=20translat?= =?UTF-8?q?ion=20for=20`docs/ru/docs/tutorial/dependencies/classes-as-depe?= =?UTF-8?q?ndencies.md`=20(#10410)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Vladislav Kramorenko <85196001+Xewus@users.noreply.github.com> --- .../dependencies/classes-as-dependencies.md | 478 ++++++++++++++++++ 1 file changed, 478 insertions(+) create mode 100644 docs/ru/docs/tutorial/dependencies/classes-as-dependencies.md diff --git a/docs/ru/docs/tutorial/dependencies/classes-as-dependencies.md b/docs/ru/docs/tutorial/dependencies/classes-as-dependencies.md new file mode 100644 index 0000000000..b6ad25dafc --- /dev/null +++ b/docs/ru/docs/tutorial/dependencies/classes-as-dependencies.md @@ -0,0 +1,478 @@ +# КĐģĐ°ŅŅŅ‹ ĐēаĐē ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚Đ¸ + +ĐŸŅ€ĐĩĐļĐ´Đĩ ҇ĐĩĐŧ ŅƒĐŗĐģŅƒĐąĐ¸Ņ‚ŅŒŅŅ в ŅĐ¸ŅŅ‚ĐĩĐŧ҃ **ВĐŊĐĩĐ´Ņ€ĐĩĐŊĐ¸Ņ Đ—Đ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚ĐĩĐš**, Đ´Đ°Đ˛Đ°ĐšŅ‚Đĩ ОйĐŊОвиĐŧ ĐŋŅ€ĐĩĐ´Ņ‹Đ´ŅƒŅ‰Đ¸Đš ĐŋŅ€Đ¸ĐŧĐĩŅ€. + +## `ĐĄĐģĐžĐ˛Đ°Ņ€ŅŒ` иС ĐŋŅ€ĐĩĐ´Ņ‹Đ´ŅƒŅ‰ĐĩĐŗĐž ĐŋŅ€Đ¸ĐŧĐĩŅ€Đ° + +В ĐŋŅ€ĐĩĐ´Ņ‹Đ´ŅƒŅ‰ĐĩĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ ĐŧŅ‹ Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°Đģи `ҁĐģĐžĐ˛Đ°Ņ€ŅŒ` иС ĐŊĐ°ŅˆĐĩĐš ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚Đ¸: + +=== "Python 3.10+" + + ```Python hl_lines="9" + {!> ../../../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** ĐˇĐ°ĐąĐžŅ‚Đ¸Ņ‚ŅŅ Đž Ņ‚ĐžĐŧ, Ņ‡Ņ‚ĐžĐąŅ‹ ĐŋĐžĐŧĐžŅ‡ŅŒ ваĐŧ ŅĐ˛ĐĩŅŅ‚Đ¸ Đē ĐŧиĐŊиĐŧ҃Đŧ҃ ĐŋĐžĐ˛Ņ‚ĐžŅ€ĐĩĐŊиĐĩ ĐēОда. From 4c231854dc2dc7336f8ad3ed399b806f6dc7d498 Mon Sep 17 00:00:00 2001 From: HiemalBeryl <63165207+HiemalBeryl@users.noreply.github.com> Date: Fri, 12 Jan 2024 19:13:04 +0800 Subject: [PATCH 045/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typos=20in?= =?UTF-8?q?=20`docs/zh/docs/tutorial/extra-data-types.md`=20(#10727)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/tutorial/extra-data-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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. ## 䞋子 From 6a4aed45f05c7e0c9db635e74b29e76ecae6ca5c Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 11:13:22 +0000 Subject: [PATCH 046/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 671e632161..457bc5e983 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,10 @@ hide: * 📝 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 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). + ## 0.109.0 ### Features From 753c8136d8b5ecffe27f7b2ac18e02687f2c269b Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 11:15:04 +0000 Subject: [PATCH 047/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 457bc5e983..628e18b108 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -24,6 +24,7 @@ hide: ### Translations +* âœī¸ 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). ## 0.109.0 From f1329abf9930165f4c53cb760fd9f809b4ed6266 Mon Sep 17 00:00:00 2001 From: theoohoho <31537466+theoohoho@users.noreply.github.com> Date: Fri, 12 Jan 2024 21:39:54 +0800 Subject: [PATCH 048/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20broken=20lin?= =?UTF-8?q?k=20in=20`docs/tutorial/sql-databases.md`=20in=20several=20lang?= =?UTF-8?q?uages=20(#10716)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/em/docs/tutorial/sql-databases.md | 2 +- docs/en/docs/tutorial/sql-databases.md | 2 +- docs/zh/docs/tutorial/sql-databases.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/docs/tutorial/sql-databases.md b/docs/en/docs/tutorial/sql-databases.md index 161d5491d7..70d9482df2 100644 --- a/docs/en/docs/tutorial/sql-databases.md +++ b/docs/en/docs/tutorial/sql-databases.md @@ -513,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 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/)。 ### 创åģē䞝čĩ–饚 From dc704036a2dd646c30fb9d58ec8a707236135f84 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 13:40:15 +0000 Subject: [PATCH 049/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 628e18b108..55b6a68948 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* âœī¸ 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). From 7e0e16fa3669d83a9992ff5aee669135ebb41fc1 Mon Sep 17 00:00:00 2001 From: Jacob McDonald <48448372+jacob-indigo@users.noreply.github.com> Date: Fri, 12 Jan 2024 09:03:25 -0500 Subject: [PATCH 050/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20warning=20about=20?= =?UTF-8?q?lifespan=20functions=20and=20backwards=20compatibility=20with?= =?UTF-8?q?=20events=20(#10734)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> --- docs/en/docs/advanced/events.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/docs/advanced/events.md b/docs/en/docs/advanced/events.md index 6df1411d1f..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. From 38915783fc355a4eb49310182f353778982c70e1 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 14:03:51 +0000 Subject: [PATCH 051/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 55b6a68948..01eefb052a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Docs +* 📝 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). From 58e2f8b1d9265a90aa0aecd7e7eb1ca8c19bf1de Mon Sep 17 00:00:00 2001 From: Delitel-WEB <57365921+Delitel-WEB@users.noreply.github.com> Date: Fri, 12 Jan 2024 17:10:31 +0300 Subject: [PATCH 052/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo=20in=20?= =?UTF-8?q?`docs/ru/docs/index.md`=20(#10672)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ru/docs/index.md b/docs/ru/docs/index.md index 97a3947bd3..6c99f623dd 100644 --- a/docs/ru/docs/index.md +++ b/docs/ru/docs/index.md @@ -321,7 +321,7 @@ def update_item(item_id: int, item: Item): ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, Đ˛Ņ‹ ĐžĐąŅŠŅĐ˛ĐģŅĐĩŅ‚Đĩ **ОдиĐŊ Ņ€Đ°Đˇ** Ņ‚Đ¸ĐŋŅ‹ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€ĐžĐ˛, Ņ‚ĐĩĐģĐž и Ņ‚. Đ´. в ĐēĐ°Ņ‡ĐĩŅŅ‚Đ˛Đĩ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€ĐžĐ˛ Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸. -Đ’Ņ‹ Đ´ĐĩĐģаĐĩŅ‚Đĩ ŅŅ‚Đž Đ¸ŅĐŋĐģŅŒĐˇŅƒŅ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊŅƒŅŽ ŅĐžĐ˛Ņ€ĐĩĐŧĐĩĐŊĐŊŅƒŅŽ Ņ‚Đ¸ĐŋĐ¸ĐˇĐ°Ņ†Đ¸ŅŽ Python. +Đ’Ņ‹ Đ´ĐĩĐģаĐĩŅ‚Đĩ ŅŅ‚Đž Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊŅƒŅŽ ŅĐžĐ˛Ņ€ĐĩĐŧĐĩĐŊĐŊŅƒŅŽ Ņ‚Đ¸ĐŋĐ¸ĐˇĐ°Ņ†Đ¸ŅŽ Python. ВаĐŧ ĐŊĐĩ ĐŊ҃ĐļĐŊĐž Đ¸ĐˇŅƒŅ‡Đ°Ņ‚ŅŒ ĐŊĐžĐ˛Ņ‹Đš ŅĐ¸ĐŊŅ‚Đ°ĐēŅĐ¸Ņ, ĐŧĐĩŅ‚ĐžĐ´Ņ‹ иĐģи ĐēĐģĐ°ŅŅŅ‹ ĐēĐžĐŊĐēŅ€ĐĩŅ‚ĐŊОК йийĐģĐ¸ĐžŅ‚ĐĩĐēи и Ņ‚. Đ´. From ca33b6edac847e27a9543c0a8dad95c1fcfc65fc Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 14:10:54 +0000 Subject: [PATCH 053/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 01eefb052a..4e795b8cc3 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -26,6 +26,7 @@ hide: ### Translations +* âœī¸ 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). From c81ab17a594e140e66424addfe8374d72550728a Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Fri, 12 Jan 2024 15:15:29 +0100 Subject: [PATCH 054/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/background-tasks.md`=20(#1056?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/background-tasks.md | 126 ++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 docs/de/docs/tutorial/background-tasks.md 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. From 4f9ad80f5d48377dae978130692dc4965fa19a2a Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 14:15:52 +0000 Subject: [PATCH 055/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 4e795b8cc3..b69ad9e784 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -26,6 +26,7 @@ hide: ### Translations +* 🌐 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). From 0aee526de9fa908027c100237a692407a5e49818 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Fri, 12 Jan 2024 15:38:17 +0100 Subject: [PATCH 056/305] =?UTF-8?q?=F0=9F=94=A7=20=20Add=20support=20for?= =?UTF-8?q?=20translations=20to=20languages=20with=20a=20longer=20code=20n?= =?UTF-8?q?ame,=20like=20`zh-hant`=20(#10950)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/language_names.yml | 1 + scripts/docs.py | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/docs/language_names.yml b/docs/language_names.yml index fbbbde303e..7c37ff2b13 100644 --- a/docs/language_names.yml +++ b/docs/language_names.yml @@ -179,4 +179,5 @@ yi: ייִדיש yo: YorÚbÃĄ za: Saɯ cueŋƅ zh: æą‰č¯­ +zh-hant: įšéĢ”ä¸­æ–‡ zu: isiZulu diff --git a/scripts/docs.py b/scripts/docs.py index a6710d7a50..37a7a34779 100644 --- a/scripts/docs.py +++ b/scripts/docs.py @@ -53,9 +53,6 @@ def get_lang_paths() -> List[Path]: def lang_callback(lang: Optional[str]) -> Union[str, None]: if lang is None: return None - if not lang.isalpha() or len(lang) != 2: - typer.echo("Use a 2 letter language code, like: es") - raise typer.Abort() lang = lang.lower() return lang @@ -289,6 +286,12 @@ def update_config() -> None: for lang_dict in languages: code = list(lang_dict.keys())[0] url = lang_dict[code] + if code not in local_language_names: + print( + f"Missing language name for: {code}, " + "update it in docs/language_names.yml" + ) + raise typer.Abort() use_name = f"{code} - {local_language_names[code]}" new_alternate.append({"link": url, "name": use_name}) new_alternate.append({"link": "/em/", "name": "😉"}) From 44f3ebce6edc3926876ac0c0370fa8b69e2dea19 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 14:38:40 +0000 Subject: [PATCH 057/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b69ad9e784..eb78fe8cf9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -31,6 +31,10 @@ hide: * âœī¸ 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 + +* 🔧 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 From be0bd344463c04ce095051a1fd6bf209165b3e94 Mon Sep 17 00:00:00 2001 From: ooknimm <68068775+ooknimm@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:52:00 +0900 Subject: [PATCH 058/305] =?UTF-8?q?=E2=9C=85=20Re-enable=20test=20in=20`te?= =?UTF-8?q?sts/test=5Ftutorial/test=5Fheader=5Fparams/test=5Ftutorial003.p?= =?UTF-8?q?y`=20after=20fix=20in=20Starlette=20(#10904)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../test_tutorial/test_header_params/test_tutorial003.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/test_tutorial/test_header_params/test_tutorial003.py b/tests/test_tutorial/test_header_params/test_tutorial003.py index 268df7a3e9..6f7de8ed41 100644 --- a/tests/test_tutorial/test_header_params/test_tutorial003.py +++ b/tests/test_tutorial/test_header_params/test_tutorial003.py @@ -12,8 +12,12 @@ client = TestClient(app) [ ("/items", None, 200, {"X-Token values": None}), ("/items", {"x-token": "foo"}, 200, {"X-Token values": ["foo"]}), - # TODO: fix this, is it a bug? - # ("/items", [("x-token", "foo"), ("x-token", "bar")], 200, {"X-Token values": ["foo", "bar"]}), + ( + "/items", + [("x-token", "foo"), ("x-token", "bar")], + 200, + {"X-Token values": ["foo", "bar"]}, + ), ], ) def test(path, headers, expected_status, expected_response): From 22e5d9e27fd3079e693cda8ae5c5a44c53b61ca2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 14:52:20 +0000 Subject: [PATCH 059/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index eb78fe8cf9..2f82b70d68 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -7,6 +7,10 @@ hide: ## Latest Changes +### Refactors + +* ✅ 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 * 📝 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). From 91666b3556aedbaae2c84112ac272d23f312e5cb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:00:18 -0500 Subject: [PATCH 060/305] =?UTF-8?q?=E2=AC=86=20Bump=20dawidd6/action-downl?= =?UTF-8?q?oad-artifact=20from=202.28.0=20to=203.0.0=20(#10777)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [dawidd6/action-download-artifact](https://github.com/dawidd6/action-download-artifact) from 2.28.0 to 3.0.0. - [Release notes](https://github.com/dawidd6/action-download-artifact/releases) - [Commits](https://github.com/dawidd6/action-download-artifact/compare/v2.28.0...v3.0.0) --- updated-dependencies: - dependency-name: dawidd6/action-download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/deploy-docs.yml | 2 +- .github/workflows/smokeshow.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-docs.yml b/.github/workflows/deploy-docs.yml index 155ebd0a8e..2bec6682c1 100644 --- a/.github/workflows/deploy-docs.yml +++ b/.github/workflows/deploy-docs.yml @@ -21,7 +21,7 @@ jobs: mkdir ./site - name: Download Artifact Docs id: download - uses: dawidd6/action-download-artifact@v2.28.0 + uses: dawidd6/action-download-artifact@v3.0.0 with: if_no_artifact_found: ignore github_token: ${{ secrets.FASTAPI_PREVIEW_DOCS_DOWNLOAD_ARTIFACTS }} diff --git a/.github/workflows/smokeshow.yml b/.github/workflows/smokeshow.yml index 38b44c4130..229f56a9fe 100644 --- a/.github/workflows/smokeshow.yml +++ b/.github/workflows/smokeshow.yml @@ -24,7 +24,7 @@ jobs: - run: pip install smokeshow - - uses: dawidd6/action-download-artifact@v2.28.0 + - uses: dawidd6/action-download-artifact@v3.0.0 with: github_token: ${{ secrets.FASTAPI_SMOKESHOW_DOWNLOAD_ARTIFACTS }} workflow: test.yml From 0ce4f80ac9aea70af3425bd337c875a85b2d4625 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 15:00:39 +0000 Subject: [PATCH 061/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2f82b70d68..156c48bbe2 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -37,6 +37,7 @@ hide: ### Internal +* âŦ† 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 From 25646a5070064053309259f1e69c98015c5ec633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jiri=20Dan=C4=9Bk?= Date: Fri, 12 Jan 2024 16:01:06 +0100 Subject: [PATCH 062/305] =?UTF-8?q?=F0=9F=94=A7=20Fix=20Ruff=20configurati?= =?UTF-8?q?on=20unintentionally=20enabling=20and=20re-disabling=20mccabe?= =?UTF-8?q?=20complexity=20check=20(#10893)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix mistake in Ruff configuration unintentionally enabling mccabe complexity check Enabling "C" turns on complexity checks (C90, mccabe), which is unintended Instead, enable "C4" to get flake8-comprehensions checks See docs at https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4 Co-authored-by: SebastiÃĄn Ramírez --- pyproject.toml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 8e7f8bbbe5..3e43f35e17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -145,15 +145,14 @@ select = [ "W", # pycodestyle warnings "F", # pyflakes "I", # isort - "C", # flake8-comprehensions "B", # flake8-bugbear + "C4", # flake8-comprehensions "UP", # pyupgrade ] ignore = [ "E501", # line too long, handled by black "B008", # do not perform function calls in argument defaults - "C901", # too complex - "W191", # indentation contains tabs + "W191", # indentation contains tabs ] [tool.ruff.per-file-ignores] From a2937099982b7da564279619f0cb257df33521f6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 10:01:52 -0500 Subject: [PATCH 063/305] =?UTF-8?q?=E2=AC=86=20Bump=20pypa/gh-action-pypi-?= =?UTF-8?q?publish=20from=201.8.10=20to=201.8.11=20(#10731)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.8.10 to 1.8.11. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](https://github.com/pypa/gh-action-pypi-publish/compare/v1.8.10...v1.8.11) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 8cbd01b92b..d053be0a06 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -32,7 +32,7 @@ jobs: - name: Build distribution run: python -m build - name: Publish - uses: pypa/gh-action-pypi-publish@v1.8.10 + uses: pypa/gh-action-pypi-publish@v1.8.11 with: password: ${{ secrets.PYPI_API_TOKEN }} - name: Dump GitHub context From c9e46ae12cfe5e32a25a78dca7499db1fae55059 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 15:02:38 +0000 Subject: [PATCH 064/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 156c48bbe2..558bd10b1f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,7 @@ hide: ### Refactors +* 🔧 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 From bc7d026b6ca487598a758b20c5935ccde1eace11 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 15:04:40 +0000 Subject: [PATCH 065/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 558bd10b1f..65128b29a9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -38,6 +38,7 @@ hide: ### Internal +* âŦ† 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). From b0cd4f915bce79575e890e4ae0cccd5b15f2e38f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 16:13:58 +0100 Subject: [PATCH 066/305] =?UTF-8?q?=E2=AC=86=20Bump=20actions/setup-python?= =?UTF-8?q?=20from=204=20to=205=20(#10764)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4 to 5. - [Release notes](https://github.com/actions/setup-python/releases) - [Commits](https://github.com/actions/setup-python/compare/v4...v5) --- updated-dependencies: - dependency-name: actions/setup-python dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/build-docs.yml | 4 ++-- .github/workflows/publish.yml | 2 +- .github/workflows/smokeshow.yml | 2 +- .github/workflows/test.yml | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index 51c069d9eb..abf2b90f68 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -39,7 +39,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" - uses: actions/cache@v3 @@ -80,7 +80,7 @@ jobs: run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" - uses: actions/cache@v3 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index d053be0a06..8ebb28a80f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,7 +15,7 @@ jobs: run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.10" # Issue ref: https://github.com/actions/setup-python/issues/436 diff --git a/.github/workflows/smokeshow.yml b/.github/workflows/smokeshow.yml index 229f56a9fe..10bff67aee 100644 --- a/.github/workflows/smokeshow.yml +++ b/.github/workflows/smokeshow.yml @@ -18,7 +18,7 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '3.9' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 032db9c9c8..b6b1736851 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: "3.11" # Issue ref: https://github.com/actions/setup-python/issues/436 @@ -57,7 +57,7 @@ jobs: run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} # Issue ref: https://github.com/actions/setup-python/issues/436 @@ -98,7 +98,7 @@ jobs: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/setup-python@v5 with: python-version: '3.8' # Issue ref: https://github.com/actions/setup-python/issues/436 From 26e57903d134742ba0ee8e65ce7985cd398afdea Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 12 Jan 2024 15:14:18 +0000 Subject: [PATCH 067/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 65128b29a9..19b4d8a35a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -38,6 +38,7 @@ hide: ### Internal +* âŦ† 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). From fad1a464e73003feb8d5ae47f5d676faf353dd3e Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Sat, 13 Jan 2024 02:00:31 +0100 Subject: [PATCH 068/305] =?UTF-8?q?=F0=9F=94=A7=20=20Group=20dependencies?= =?UTF-8?q?=20on=20dependabot=20updates=20(#10952)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/dependabot.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index cd972a0ba4..0a59adbd6b 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -11,6 +11,10 @@ updates: - package-ecosystem: "pip" directory: "/" schedule: - interval: "daily" + interval: "monthly" + groups: + python-packages: + patterns: + - "*" commit-message: prefix: âŦ† From 1ce27fd743cf95901ca44fcf24805b596615581a Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 01:00:55 +0000 Subject: [PATCH 069/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 19b4d8a35a..13efb84e96 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -38,6 +38,7 @@ hide: ### 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). From 1caee0f105d64f475e369a82f9cac90472e54d61 Mon Sep 17 00:00:00 2001 From: Ahmed Ashraf <104530599+ahmedabdou14@users.noreply.github.com> Date: Sat, 13 Jan 2024 14:49:05 +0300 Subject: [PATCH 070/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20Pydantic=20m?= =?UTF-8?q?ethod=20name=20in=20`docs/en/docs/advanced/path-operation-advan?= =?UTF-8?q?ced-configuration.md`=20(#10826)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ahmed Ashraf --- docs/en/docs/advanced/path-operation-advanced-configuration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/docs/advanced/path-operation-advanced-configuration.md b/docs/en/docs/advanced/path-operation-advanced-configuration.md index 7ca88d43ed..8b79bfe22a 100644 --- a/docs/en/docs/advanced/path-operation-advanced-configuration.md +++ b/docs/en/docs/advanced/path-operation-advanced-configuration.md @@ -163,7 +163,7 @@ For example, in this application we don't use FastAPI's integrated functionality ``` !!! info - In Pydantic version 1 the method to get the JSON Schema for a model was called `Item.schema()`, in Pydantic version 2, the method is called `Item.model_schema_json()`. + In Pydantic version 1 the method to get the JSON Schema for a model was called `Item.schema()`, in Pydantic version 2, the method is called `Item.model_json_schema()`. Nevertheless, although we are not using the default integrated functionality, we are still using a Pydantic model to manually generate the JSON Schema for the data that we want to receive in YAML. From cc5711e6f105251f8e1952c0a10c660a258a0ed3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 11:49:51 +0000 Subject: [PATCH 071/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 13efb84e96..973073205b 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -7,6 +7,8 @@ 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 * 🔧 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). From c3e2aa9dc2b1fbdb48009ed532410e1e75c2f231 Mon Sep 17 00:00:00 2001 From: fhabers21 <58401847+fhabers21@users.noreply.github.com> Date: Sat, 13 Jan 2024 12:50:36 +0100 Subject: [PATCH 072/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/index.md`=20(#9502)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/de/docs/tutorial/index.md | 80 ++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 docs/de/docs/tutorial/index.md 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: + +
+ +```console +$ pip install "fastapi[all]" + +---> 100% +``` + +
+ +...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. From 4299e712fb600b6460f85f551a2dd1d75ca7be05 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 11:51:55 +0000 Subject: [PATCH 073/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 973073205b..66f14ef1e1 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -33,6 +33,7 @@ hide: ### 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). From a37ac3819ee9b8d19d045d53d742779109d2f711 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Jos=C3=A9=20L=C3=B3pez=20Lira?= Date: Sat, 13 Jan 2024 06:57:27 -0500 Subject: [PATCH 074/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typos=20for?= =?UTF-8?q?=20Spanish=20documentation=20(#10957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/es/docs/advanced/additional-status-codes.md | 2 +- docs/es/docs/advanced/response-directly.md | 2 +- docs/es/docs/features.md | 14 +++++++------- docs/es/docs/index.md | 8 ++++---- docs/es/docs/python-types.md | 16 ++++++++-------- docs/es/docs/tutorial/first-steps.md | 2 +- docs/es/docs/tutorial/index.md | 2 +- docs/es/docs/tutorial/path-params.md | 6 +++--- 8 files changed, 26 insertions(+), 26 deletions(-) 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 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 From b24c4870d8f8f0547d956ac8c1d2c751f1f66b69 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 12:10:29 +0000 Subject: [PATCH 077/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index c632cc0b06..2234624f07 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -16,6 +16,7 @@ hide: ### Docs +* âœī¸ 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). From 83e386519d30d8c732249983ffdf7200e8af5a5d Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Sat, 13 Jan 2024 13:16:22 +0100 Subject: [PATCH 078/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20A=20few=20tweaks?= =?UTF-8?q?=20in=20`docs/de/docs/tutorial/first-steps.md`=20(#10959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/first-steps.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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`). From cca6203c18552aa95c7ad0f7fd972fd6e86d0d77 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 12:19:28 +0000 Subject: [PATCH 079/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2234624f07..510b842ba7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -16,6 +16,7 @@ hide: ### 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). From de0126d145c920c992c605538e63fe0e46b508d5 Mon Sep 17 00:00:00 2001 From: Evgenii Date: Sat, 13 Jan 2024 17:31:38 +0300 Subject: [PATCH 080/305] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Simplify=20string?= =?UTF-8?q?=20format=20with=20f-strings=20in=20`fastapi/utils.py`=20(#1057?= =?UTF-8?q?6)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- fastapi/utils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fastapi/utils.py b/fastapi/utils.py index f8463dda24..0019c21532 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -173,17 +173,17 @@ def generate_operation_id_for_path( DeprecationWarning, stacklevel=2, ) - operation_id = name + path + operation_id = f"{name}{path}" operation_id = re.sub(r"\W", "_", operation_id) - operation_id = operation_id + "_" + method.lower() + operation_id = f"{operation_id}_{method.lower()}" return operation_id def generate_unique_id(route: "APIRoute") -> str: - operation_id = route.name + route.path_format + operation_id = f"{route.name}{route.path_format}" operation_id = re.sub(r"\W", "_", operation_id) assert route.methods - operation_id = operation_id + "_" + list(route.methods)[0].lower() + operation_id = f"{operation_id}_{list(route.methods)[0].lower()}" return operation_id From 61a08d0c60cbe29784bb64cdbdea5d613a38b2e5 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 14:31:58 +0000 Subject: [PATCH 081/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 510b842ba7..1fc1a16955 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -11,6 +11,7 @@ hide: ### Refactors +* â™ģī¸ 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). From f18eadb7de142d6bf37eff900731329a541758f5 Mon Sep 17 00:00:00 2001 From: Emmett Butler <723615+emmettbutler@users.noreply.github.com> Date: Sat, 13 Jan 2024 07:10:26 -0800 Subject: [PATCH 082/305] =?UTF-8?q?=E2=9C=85=20Refactor=20tests=20for=20du?= =?UTF-8?q?plicate=20operation=20ID=20generation=20for=20compatibility=20w?= =?UTF-8?q?ith=20other=20tools=20running=20the=20FastAPI=20test=20suite=20?= =?UTF-8?q?(#10876)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- tests/test_generate_unique_id_function.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/test_generate_unique_id_function.py b/tests/test_generate_unique_id_function.py index c5ef5182b7..5aeec66367 100644 --- a/tests/test_generate_unique_id_function.py +++ b/tests/test_generate_unique_id_function.py @@ -1626,6 +1626,9 @@ def test_warn_duplicate_operation_id(): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") client.get("/openapi.json") - assert len(w) == 2 - assert issubclass(w[-1].category, UserWarning) - assert "Duplicate Operation ID" in str(w[-1].message) + assert len(w) >= 2 + duplicate_warnings = [ + warning for warning in w if issubclass(warning.category, UserWarning) + ] + assert len(duplicate_warnings) > 0 + assert "Duplicate Operation ID" in str(duplicate_warnings[0].message) From e90fc7bed4213fbf42195830a1a8f54288be4fb8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 13 Jan 2024 15:10:47 +0000 Subject: [PATCH 083/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 1fc1a16955..5e02e2352e 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -11,6 +11,7 @@ hide: ### 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). From dcc952d6990c507956669e6fc5cddba0530c79d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 15 Jan 2024 11:32:16 +0100 Subject: [PATCH 084/305] =?UTF-8?q?=E2=9C=A8=20=20Include=20HTTP=20205=20i?= =?UTF-8?q?n=20status=20codes=20with=20no=20body=20(#10969)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/utils.py b/fastapi/utils.py index 0019c21532..53b2fa0c36 100644 --- a/fastapi/utils.py +++ b/fastapi/utils.py @@ -53,7 +53,7 @@ def is_body_allowed_for_status_code(status_code: Union[int, str, None]) -> bool: }: return True current_status_code = int(status_code) - return not (current_status_code < 200 or current_status_code in {204, 304}) + return not (current_status_code < 200 or current_status_code in {204, 205, 304}) def get_path_param_names(path: str) -> Set[str]: From 69dc735fc2339f8b39a9f1b01ced7974df9c4a65 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 10:32:42 +0000 Subject: [PATCH 085/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 5e02e2352e..7b09977e70 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -9,6 +9,10 @@ hide: * âœī¸ 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). +### Features + +* ✨ Include HTTP 205 in status codes with no body. PR [#10969](https://github.com/tiangolo/fastapi/pull/10969) by [@tiangolo](https://github.com/tiangolo). + ### 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). From 63e5396a78a470c39558a37d1fefbbe1bcbf4db7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 15 Jan 2024 16:13:48 +0100 Subject: [PATCH 086/305] =?UTF-8?q?=F0=9F=91=B7=20Add=20changes-requested?= =?UTF-8?q?=20handling=20in=20GitHub=20Action=20issue=20manager=20(#10971)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issue-manager.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/issue-manager.yml b/.github/workflows/issue-manager.yml index bb967fa118..d1aad28fd3 100644 --- a/.github/workflows/issue-manager.yml +++ b/.github/workflows/issue-manager.yml @@ -31,5 +31,9 @@ jobs: "answered": { "delay": 864000, "message": "Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs." + }, + "changes-requested": { + "delay": 2628000, + "message": "As this PR had requested changes to be applied but has been inactive for a while, it's now going to be closed. But if there's anyone interested, feel free to create a new PR." } } From 2b6f12a5d00717f40b1fa0fa5e882fe021862559 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:14:34 +0000 Subject: [PATCH 087/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7b09977e70..c7ef17d65d 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -50,6 +50,7 @@ hide: ### Internal +* 👷 Add changes-requested handling in GitHub Action issue manager. PR [#10971](https://github.com/tiangolo/fastapi/pull/10971) by [@tiangolo](https://github.com/tiangolo). * 🔧 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). From cf01195555ea0111a9540bccc1444b9d802587da Mon Sep 17 00:00:00 2001 From: Pedro Augusto de Paula Barbosa Date: Mon, 15 Jan 2024 12:17:34 -0300 Subject: [PATCH 088/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20`HTTPException`?= =?UTF-8?q?=20details=20in=20`docs/en/docs/tutorial/handling-errors.md`=20?= =?UTF-8?q?(#5418)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/docs/tutorial/handling-errors.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/en/docs/tutorial/handling-errors.md b/docs/en/docs/tutorial/handling-errors.md index a03029e811..7d521696d8 100644 --- a/docs/en/docs/tutorial/handling-errors.md +++ b/docs/en/docs/tutorial/handling-errors.md @@ -234,9 +234,7 @@ You will receive a response telling you that the data is invalid containing the And **FastAPI**'s `HTTPException` error class inherits from Starlette's `HTTPException` error class. -The only difference, is that **FastAPI**'s `HTTPException` allows you to add headers to be included in the response. - -This is needed/used internally for OAuth 2.0 and some security utilities. +The only difference is that **FastAPI**'s `HTTPException` accepts any JSON-able data for the `detail` field, while Starlette's `HTTPException` only accepts strings for it. So, you can keep raising **FastAPI**'s `HTTPException` as normally in your code. From 32ae9497233a9dc859a17f642c6b9bca0260f9ca Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:17:54 +0000 Subject: [PATCH 089/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index c7ef17d65d..771d286a11 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Update `HTTPException` details in `docs/en/docs/tutorial/handling-errors.md`. PR [#5418](https://github.com/tiangolo/fastapi/pull/5418) by [@papb](https://github.com/papb). * âœī¸ 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). From 15429a9c395df0378aa58fdee00c9b63a7a40358 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:33:28 +0900 Subject: [PATCH 090/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/body-fields.md`=20(#1923)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/body-fields.md | 48 ++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 docs/ja/docs/tutorial/body-fields.md diff --git a/docs/ja/docs/tutorial/body-fields.md b/docs/ja/docs/tutorial/body-fields.md new file mode 100644 index 0000000000..8f01e82162 --- /dev/null +++ b/docs/ja/docs/tutorial/body-fields.md @@ -0,0 +1,48 @@ +# ãƒœãƒ‡ã‚Ŗ - ãƒ•ã‚ŖãƒŧãƒĢド + +`Query`や`Path`、`Body`をäŊŋãŖãĻ *path operationé–ĸ数* ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢčŋŊ加ぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚„ãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ãŽã¨åŒã˜ã‚ˆã†ãĢ、Pydanticぎ`Field`をäŊŋãŖãĻPydanticãƒĸデãƒĢぎ内部でバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚„ãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +## `Field`ãŽã‚¤ãƒŗãƒãƒŧト + +ぞず、äģĨ下ぎようãĢã‚¤ãƒŗãƒãƒŧトしぞす: + +```Python hl_lines="4" +{!../../../docs_src/body_fields/tutorial001.py!} +``` + +!!! warning "æŗ¨æ„" + `Field`はäģ–ぎ全ãĻぎもぎīŧˆ`Query`、`Path`、`Body`ãĒおīŧ‰ã¨ã¯é•い、`fastapi`からではãĒく、`pydantic`ã‹ã‚‰į›´æŽĨã‚¤ãƒŗãƒãƒŧトされãĻいることãĢæŗ¨æ„ã—ãĻください。 + +## ãƒĸデãƒĢãŽåąžæ€§ãŽåŽŖč¨€ + +äģĨ下ぎようãĢ`Field`をãƒĸデãƒĢãŽåąžæ€§ã¨ã—ãĻäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="11 12 13 14" +{!../../../docs_src/body_fields/tutorial001.py!} +``` + +`Field`は`Query`や`Path`、`Body`と同じようãĢ動äŊœã—ã€å…¨ãåŒæ§˜ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĒãŠã‚’æŒãĄãžã™ã€‚ + +!!! note "æŠ€čĄ“čŠŗį´°" + 原際ãĢはæŦĄãĢčĻ‹ã‚‹`Query`や`Path`ãĒãŠã¯ã€å…ąé€šãŽ`Param`クナ゚ぎã‚ĩブクナ゚ぎã‚ĒブジェクトをäŊœæˆã—ぞすが、それč‡ĒäŊ“はPydanticぎ`FieldInfo`クナ゚ぎã‚ĩブクナ゚です。 + + ぞた、Pydanticぎ`Field`は`FieldInfo`ãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚‚čŋ”しぞす。 + + `Body`は`FieldInfo`ぎã‚ĩブクナ゚ぎã‚Ēãƒ–ã‚¸ã‚§ã‚¯ãƒˆã‚’į›´æŽĨčŋ”すこともできぞす。そしãĻ、äģ–ãĢも`Body`クナ゚ぎã‚ĩブクナ゚であるもぎがありぞす。 + + `fastapi`から`Query`や`Path`ãĒãŠã‚’ã‚¤ãƒŗãƒãƒŧトする場合、これらは原際ãĢã¯į‰šæŽŠãĒクナ゚をčŋ”すé–ĸ数であることãĢæŗ¨æ„ã—ãĻください。 + +!!! tip "豆įŸĨ識" + 型、デフりãƒĢト値、`Field`を持つ各ãƒĸデãƒĢãŽåąžæ€§ãŒã€`Path`や`Query`、`Body`ぎäģŖã‚ã‚ŠãĢ`Field`を持つ、*path operation é–ĸ数ぎ*ãƒ‘ãƒŠãƒĄãƒŧã‚ŋと同じ構造ãĢãĒãŖãĻいることãĢæŗ¨į›Žã—ãĻください。 + +## čŋŊåŠ æƒ…å ąãŽčŋŊ加 + +čŋŊåŠ æƒ…å ąã¯`Field`や`Query`、`Body`ãĒãŠã§åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ãã—ãĻãã‚Œã¯į”Ÿæˆã•ã‚ŒãŸJSON゚キãƒŧマãĢåĢぞれぞす。 + +垌ãĢäž‹ã‚’į”¨ã„ãĻåŽŖč¨€ã‚’å­Ļãļ際ãĢ、čŋŊåŠ æƒ…å ąã‚’åĨæ‚Ēæ–šæŗ•ã‚’å­Ļずぞす。 + +## ぞとめ + +Pydanticぎ`Field`をäŊŋį”¨ã—ãĻ、ãƒĸデãƒĢãŽåąžæ€§ãĢčŋŊ加ぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚„ãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +čŋŊ加ぎキãƒŧワãƒŧドåŧ•æ•°ã‚’äŊŋį”¨ã—ãĻ、čŋŊ加ぎJSON゚キãƒŧãƒžãŽãƒĄã‚ŋデãƒŧã‚ŋã‚’æ¸Ąã™ã“ã¨ã‚‚ã§ããžã™ã€‚ From 467ab2a5756245cc53a8c0ec4fd467ffbef7d347 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:33:51 +0000 Subject: [PATCH 091/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 771d286a11..2d73401ef9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-fields.md`. PR [#1923](https://github.com/tiangolo/fastapi/pull/1923) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 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). From 88f19be7c38b1c904d453dff3f0f1f97ebdcaec7 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:34:57 +0900 Subject: [PATCH 092/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/body-nested-models.md`=20(#?= =?UTF-8?q?1930)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/body-nested-models.md | 244 ++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 docs/ja/docs/tutorial/body-nested-models.md diff --git a/docs/ja/docs/tutorial/body-nested-models.md b/docs/ja/docs/tutorial/body-nested-models.md new file mode 100644 index 0000000000..7f916c47a1 --- /dev/null +++ b/docs/ja/docs/tutorial/body-nested-models.md @@ -0,0 +1,244 @@ +# ãƒœãƒ‡ã‚Ŗ - ネ゚トされたãƒĸデãƒĢ + +**FastAPI** をäŊŋį”¨ã™ã‚‹ã¨ã€æˇąããƒã‚šãƒˆã•ã‚ŒãŸäģģæ„ãŽãƒĸデãƒĢã‚’åŽšįžŠã€æ¤œč¨ŧ、文書化、äŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™īŧˆPydanticぎおかげですīŧ‰ã€‚ + +## ãƒĒã‚šãƒˆãŽãƒ•ã‚ŖãƒŧãƒĢド + +åąžæ€§ã‚’ã‚ĩブã‚ŋイプとしãĻåŽšįžŠã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚äž‹ãˆã°ã€Pythonぎ`list`はäģĨ下ぎようãĢåŽšįžŠã§ããžã™: + +```Python hl_lines="12" +{!../../../docs_src/body_nested_models/tutorial001.py!} +``` + +これãĢã‚ˆã‚Šã€å„é …į›ŽãŽåž‹ã¯åŽŖč¨€ã•ã‚ŒãĻいぞせんが、`tags`ã¯ã‚ã‚‹é …į›ŽãŽãƒĒ゚トãĢãĒりぞす。 + +## ã‚ŋã‚¤ãƒ—ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを持つãƒĒã‚šãƒˆãŽãƒ•ã‚ŖãƒŧãƒĢド + +しかし、PythonãĢは型や「ã‚ŋã‚¤ãƒ—ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ」をäŊŋãŖãĻãƒĒã‚šãƒˆã‚’åŽŖč¨€ã™ã‚‹æ–šæŗ•ãŒã‚ã‚Šãžã™: + +### typingぎ`List`ã‚’ã‚¤ãƒŗãƒãƒŧト + +ぞず、Pythonぎ標æē–ぎ`typing`ãƒĸジãƒĨãƒŧãƒĢから`List`ã‚’ã‚¤ãƒŗãƒãƒŧトしぞす: + +```Python hl_lines="1" +{!../../../docs_src/body_nested_models/tutorial002.py!} +``` + +### ã‚ŋã‚¤ãƒ—ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを持つ`List`ãŽåŽŖč¨€ + +`list`や`dict`、`tuple`ぎようãĒã‚ŋã‚¤ãƒ—ãƒ‘ãƒŠãƒĄãƒŧã‚ŋīŧˆå†…部ぎ型īŧ‰ã‚’æŒã¤åž‹ã‚’åŽŖč¨€ã™ã‚‹ãĢは: + +* `typing`ãƒĸジãƒĨãƒŧãƒĢã‹ã‚‰ãã‚Œã‚‰ã‚’ã‚¤ãƒŗã‚šãƒˆãƒŧãƒĢしぞす。 +* 角æ‹Ŧåŧ§īŧˆ`[`と`]`īŧ‰ã‚’äŊŋãŖãĻ「ã‚ŋã‚¤ãƒ—ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ」としãĻå†…éƒ¨ãŽåž‹ã‚’æ¸Ąã—ãžã™: + +```Python +from typing import List + +my_list: List[str] +``` + +åž‹åŽŖč¨€ãŽæ¨™æē–įš„ãĒPythonぎ構文はこれだけです。 + +内部ぎ型を持つãƒĸデãƒĢãŽåąžæ€§ãĢも同じ標æē–ぎ構文をäŊŋį”¨ã—ãĻください。 + +そぎため、äģĨ下ぎ䞋では`tags`ã‚’å…ˇäŊ“įš„ãĒ「文字列ぎãƒĒ゚ト」ãĢすることができぞす: + +```Python hl_lines="14" +{!../../../docs_src/body_nested_models/tutorial002.py!} +``` + +## ã‚ģット型 + +ã—ã‹ã—ã€ã‚ˆãč€ƒãˆãĻãŋると、ã‚ŋã‚°ã¯įš°ã‚Ščŋ”すずきではãĒく、おそらくãƒĻニãƒŧクãĒ文字列ãĢãĒるぎではãĒいかと気äģ˜ã„たとしぞす。 + +そしãĻ、PythonãĢはãƒĻニãƒŧクãĒé …į›ŽãŽã‚ģãƒƒãƒˆãŽãŸã‚ãŽį‰šåˆĨãĒデãƒŧã‚ŋ型`set`がありぞす。 + +そぎため、äģĨ下ぎようãĢ、`Set`ã‚’ã‚¤ãƒŗãƒãƒŧトしãĻ`str`ぎ`set`としãĻ`tags`ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="1 14" +{!../../../docs_src/body_nested_models/tutorial003.py!} +``` + +これをäŊŋえば、デãƒŧã‚ŋãŒé‡č¤‡ã—ãĻいるãƒĒクエ゚トを受けた場合でも、ãƒĻニãƒŧクãĒé …į›ŽãŽã‚ģットãĢ変換されぞす。 + +そしãĻ、そぎデãƒŧã‚ŋをå‡ē力すると、たとえã‚Ŋãƒŧ゚ãĢé‡č¤‡ãŒã‚ãŖãŸã¨ã—ãĻも、å›ēæœ‰ãŽé …į›ŽãŽã‚ģットとしãĻå‡ē力されぞす。 + +ぞた、それãĢåŋœã˜ãĻæŗ¨é‡ˆã‚’ã¤ã‘ãŸã‚Šã€æ–‡æ›¸åŒ–ã—ãŸã‚Šã—ãžã™ã€‚ + +## ネ゚トされたãƒĸデãƒĢ + +PydanticãƒĸデãƒĢãŽå„åąžæ€§ãĢは型がありぞす。 + +しかし、そぎ型はそれč‡ĒäŊ“がåˆĨぎPydanticãƒĸデãƒĢである可čƒŊ性がありぞす。 + +ããŽãŸã‚ã€į‰šåŽšãŽåąžæ€§åã€åž‹ã€ãƒãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚’æŒ‡åŽšã—ãĻã€æˇąããƒã‚šãƒˆã—ãŸJSON`object`ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +すずãĻは、äģģæ„ãŽãƒã‚šãƒˆãĢされãĻいぞす。 + +### ã‚ĩブãƒĸデãƒĢãŽåŽšįžŠ + +䞋えば、`Image`ãƒĸデãƒĢã‚’åŽšįžŠã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="9 10 11" +{!../../../docs_src/body_nested_models/tutorial004.py!} +``` + +### ã‚ĩブãƒĸデãƒĢを型としãĻäŊŋᔍ + +そしãĻã€ãã‚Œã‚’åąžæ€§ãŽåž‹ã¨ã—ãĻäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="20" +{!../../../docs_src/body_nested_models/tutorial004.py!} +``` + +これは **FastAPI** がäģĨ下ぎようãĒãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã™ã‚‹ã“ã¨ã‚’æ„å‘ŗã—ãžã™: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": ["rock", "metal", "bar"], + "image": { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + } +} +``` + +įš°ã‚Ščŋ”しãĢãĒりぞすが、**FastAPI** をäŊŋį”¨ã—ãĻã€ããŽåŽŖč¨€ã‚’čĄŒã†ã ã‘ã§äģĨ下ぎようãĒ恊æĩを受けられぞす: + +* ネ゚トされたãƒĸデãƒĢでも寞åŋœå¯čƒŊãĒã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトīŧˆčŖœåތãĒおīŧ‰ +* デãƒŧã‚ŋ変換 +* デãƒŧã‚ŋぎ検č¨ŧ +* č‡Ē動文書化 + +## į‰šæŽŠãĒ型とバãƒĒデãƒŧã‚ˇãƒ§ãƒŗ + +`str`や`int`、`float`ぎようãĒ通常ぎ単数型ぎäģ–ãĢも、`str`をį‰ŋã—ãŸã‚ˆã‚Šč¤‡é›‘ãĒ単数型をäŊŋうこともできぞす。 + +すずãĻぎã‚Ēãƒ—ã‚ˇãƒ§ãƒŗã‚’ãŋるãĢは、Pydanticぎエキゞチック ãĒ型ぎドキãƒĨãƒĄãƒŗãƒˆã‚’įĸēčĒã—ãĻください。æŦĄãŽįĢ ã§ã„ãã¤ã‹ãŽäž‹ã‚’ãŋることができぞす。 + +䞋えば、`Image`ãƒĸデãƒĢぎようãĢ`url`ãƒ•ã‚ŖãƒŧãƒĢドがある場合、`str`ぎäģŖã‚ã‚ŠãĢPydanticぎ`HttpUrl`を指厚することができぞす: + +```Python hl_lines="4 10" +{!../../../docs_src/body_nested_models/tutorial005.py!} +``` + +文字列は有劚ãĒURLであることがįĸēčĒã•ã‚Œã€ããŽã‚ˆã†ãĢJSON゚キãƒŧマãƒģOpenAPIで文書化されぞす。 + +## ã‚ĩブãƒĸデãƒĢぎãƒĒã‚šãƒˆã‚’æŒã¤åąžæ€§ + +PydanticãƒĸデãƒĢを`list`や`set`ãĒおぎã‚ĩブã‚ŋイプとしãĻäŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™: + +```Python hl_lines="20" +{!../../../docs_src/body_nested_models/tutorial006.py!} +``` + +これは、æŦĄãŽã‚ˆã†ãĒJSONãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã—ãžã™īŧˆå¤‰æ›ã€æ¤œč¨ŧ、ドキãƒĨãƒĄãƒŗãƒˆãĒおīŧ‰: + +```JSON hl_lines="11" +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": [ + "rock", + "metal", + "bar" + ], + "images": [ + { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + }, + { + "url": "http://example.com/dave.jpg", + "name": "The Baz" + } + ] +} +``` + +!!! info "æƒ…å ą" + `images`キãƒŧがį”ģ像ã‚ĒブジェクトぎãƒĒ゚トを持つようãĢãĒãŖãŸã“ã¨ãĢæŗ¨į›Žã—ãĻください。 + +## æˇąããƒã‚šãƒˆã•ã‚ŒãŸãƒĸデãƒĢ + +æˇąããƒã‚šãƒˆã•ã‚ŒãŸäģģæ„ãŽãƒĸデãƒĢã‚’åŽšįžŠã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="9 14 20 23 27" +{!../../../docs_src/body_nested_models/tutorial007.py!} +``` + +!!! info "æƒ…å ą" + `Offer`は`Item`ぎãƒĒ゚トであり、ã‚Ēãƒ—ã‚ˇãƒ§ãƒŗãŽ`Image`ぎãƒĒã‚šãƒˆã‚’æŒãŖãĻいることãĢæŗ¨į›Žã—ãĻください。 + +## ᴔឋãĒãƒĒã‚šãƒˆãŽãƒœãƒ‡ã‚Ŗ + +期垅するJSONãƒœãƒ‡ã‚ŖãŽãƒˆãƒƒãƒ—ãƒŦベãƒĢぎ値がJSON`array`īŧˆPythonぎ`list`īŧ‰ã§ã‚れば、PydanticãƒĸデãƒĢと同じようãĢ、é–ĸæ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã§åž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python +images: List[Image] +``` + +äģĨ下ぎようãĢ: + +```Python hl_lines="15" +{!../../../docs_src/body_nested_models/tutorial008.py!} +``` + +## ã‚ã‚‰ã‚†ã‚‹å ´æ‰€ã§ãŽã‚¨ãƒ‡ã‚Ŗã‚ŋã‚ĩポãƒŧト + +ã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトもおこでも受けることができぞす。 + +äģĨ下ぎようãĢãƒĒã‚šãƒˆãŽä¸­ãŽé …į›Žã§ã‚‚: + + + +PydanticãƒĸデãƒĢではãĒく、`dict`ã‚’į›´æŽĨäŊŋį”¨ã—ãĻいる場合はこぎようãĒã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトは垗られぞせん。 + +しかし、それらãĢついãĻåŋƒé…ã™ã‚‹åŋ…čĻã¯ã‚ã‚Šãžã›ã‚“ã€‚å…ĨåŠ›ã•ã‚ŒãŸčžžæ›¸ã¯č‡Ēå‹•įš„ãĢ変換され、å‡ē力もč‡Ēå‹•įš„ãĢJSONãĢ変換されぞす。 + +## äģģæ„ãŽ`dict`ãŽãƒœãƒ‡ã‚Ŗ + +ぞた、ある型ぎキãƒŧとåˆĨぎ型ぎ値を持つ`dict`としãĻãƒœãƒ‡ã‚Ŗã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +有劚ãĒãƒ•ã‚ŖãƒŧãƒĢドãƒģåąžæ€§åã‚’äē‹å‰ãĢįŸĨるåŋ…čĻãŒã‚ã‚Šãžã›ã‚“īŧˆPydanticãƒĸデãƒĢぎ場合ぎようãĢīŧ‰ã€‚ + +これは、ぞだįŸĨらãĒいキãƒŧを受け取りたいときãĢäžŋ刊だと思いぞす。 + +--- + +äģ–ãĢも、`int`ぎようãĢäģ–ぎ型ぎキãƒŧã‚’æŒãĄãŸã„å ´åˆãĒおãĢäžŋ刊です。 + +それをここでčĻ‹ãĻいきぞしょう。 + +こぎ場合、`int`ぎキãƒŧと`float`ぎ値を持つもぎであれば、おんãĒ`dict`でも受けå…Ĩれることができぞす: + +```Python hl_lines="15" +{!../../../docs_src/body_nested_models/tutorial009.py!} +``` + +!!! tip "豆įŸĨ識" + JSONはキãƒŧとしãĻ`str`しかã‚ĩポãƒŧトしãĻいãĒいことãĢæŗ¨æ„ã—ãĻください。 + + しかしPydanticãĢはč‡Ē動デãƒŧã‚ŋ変換抟čƒŊがありぞす。 + + これは、APIクナイã‚ĸãƒŗãƒˆãŒã‚­ãƒŧとしãĻ文字列しか送äŋĄã§ããĒくãĻも、それらぎ文字列ãĢᴔឋãĒ整数がåĢぞれãĻいる限り、Pydanticが変換しãĻ検č¨ŧã™ã‚‹ã“ã¨ã‚’æ„å‘ŗã—ãžã™ã€‚ + + そしãĻ、`weights`としãĻ受け取る`dict`は、原際ãĢは`int`ぎキãƒŧと`float`ぎ値を持つことãĢãĒりぞす。 + +## ぞとめ + +**FastAPI** をäŊŋį”¨ã™ã‚‹ã¨ã€PydanticãƒĸデãƒĢが提䞛する最大限ぎ柔č쟿€§ã‚’æŒãĄãĒãŒã‚‰ã€ã‚ŗãƒŧãƒ‰ã‚’ã‚ˇãƒŗãƒ—ãƒĢãĢįŸ­ãã€ã‚¨ãƒŦã‚ŦãƒŗãƒˆãĢäŋã¤ã“とができぞす。 + +äģĨ下ぎようãĒåˆŠį‚šãŒã‚ã‚Šãžã™: + +* ã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトīŧˆãŠã“ã§ã‚‚čŖœåތīŧīŧ‰ +* デãƒŧã‚ŋ変換īŧˆåˆĨ名īŧšæ§‹æ–‡č§Ŗæžãƒģã‚ˇãƒĒã‚ĸナイã‚ēīŧ‰ +* デãƒŧã‚ŋぎ検č¨ŧ +* ゚キãƒŧマ文書 +* č‡Ē動文書化 From 2619bbd7cde8251e955512f560dc632a96f72fe8 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:35:25 +0900 Subject: [PATCH 093/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20tranlsa?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/schema-extra-example.md`=20?= =?UTF-8?q?(#1931)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/schema-extra-example.md | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 docs/ja/docs/tutorial/schema-extra-example.md diff --git a/docs/ja/docs/tutorial/schema-extra-example.md b/docs/ja/docs/tutorial/schema-extra-example.md new file mode 100644 index 0000000000..3102a49362 --- /dev/null +++ b/docs/ja/docs/tutorial/schema-extra-example.md @@ -0,0 +1,58 @@ +# ゚キãƒŧマぎčŋŊ加 - 例 + +JSON SchemaãĢčŋŊåŠ ã™ã‚‹æƒ…å ąã‚’åŽšįžŠã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +一čˆŦįš„ãĒãƒĻãƒŧã‚šã‚ąãƒŧ゚はこぎドキãƒĨãƒĄãƒŗãƒˆã§į¤ēされãĻいるようãĢ`example`をčŋŊ加することです。 + +JSON SchemaぎčŋŊåŠ æƒ…å ąã‚’åŽŖč¨€ã™ã‚‹æ–šæŗ•ã¯ã„ãã¤ã‹ã‚ã‚Šãžã™ã€‚ + +## Pydanticぎ`schema_extra` + +PydanticぎドキãƒĨãƒĄãƒŗãƒˆ: ゚キãƒŧマぎã‚Ģ゚ã‚ŋマイã‚ēでčĒŦ明されãĻいるようãĢ、`Config`と`schema_extra`をäŊŋãŖãĻPydanticãƒĸデãƒĢãŽäž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="15 16 17 18 19 20 21 22 23" +{!../../../docs_src/schema_extra_example/tutorial001.py!} +``` + +そぎčŋŊåŠ æƒ…å ąã¯ããŽãžãžå‡ē力され、JSON SchemaãĢčŋŊ加されぞす。 + +## `Field`ぎčŋŊ加åŧ•æ•° + +垌čŋ°ã™ã‚‹`Field`、`Path`、`Query`、`Body`ãĒおでは、äģģæ„ãŽåŧ•æ•°ã‚’é–ĸ数ãĢæ¸Ąã™ã“ã¨ã§JSON SchemaぎčŋŊåŠ æƒ…å ąã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™: + +```Python hl_lines="4 10 11 12 13" +{!../../../docs_src/schema_extra_example/tutorial002.py!} +``` + +!!! warning "æŗ¨æ„" + これらぎčŋŊ加åŧ•æ•°ãŒæ¸Ąã•ã‚ŒãĻも、文書化ぎためぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã¯čŋŊåŠ ã•ã‚Œãšã€æŗ¨é‡ˆã ã‘ãŒčŋŊ加されることをčĻšãˆãĻおいãĻください。 + +## `Body`ぎčŋŊ加åŧ•æ•° + +čŋŊåŠ æƒ…å ąã‚’`Field`ãĢæ¸Ąã™ãŽã¨åŒã˜ã‚ˆã†ãĢ、`Path`、`Query`、`Body`ãĒおでも同じことができぞす。 + +䞋えば、`Body`ãĢãƒœãƒ‡ã‚ŖãƒĒクエ゚トぎ`example`ã‚’æ¸Ąã™ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="21 22 23 24 25 26" +{!../../../docs_src/schema_extra_example/tutorial003.py!} +``` + +## ドキãƒĨãƒĄãƒŗãƒˆãŽUIぎ䞋 + +ä¸Šč¨˜ãŽã„ãšã‚ŒãŽæ–šæŗ•ã§ã‚‚ã€`/docs`ぎ中ではäģĨ下ぎようãĢãĒりぞす: + + + +## æŠ€čĄ“čŠŗį´° + +`example` と `examples`ãĢついãĻ... + +JSON Schemaぎ最新バãƒŧã‚¸ãƒ§ãƒŗã§ã¯`examples`ã¨ã„ã†ãƒ•ã‚ŖãƒŧãƒĢãƒ‰ã‚’åŽšįžŠã—ãĻいぞすが、OpenAPIは`examples`を持たãĒい古いバãƒŧã‚¸ãƒ§ãƒŗãŽJSON Schemaをベãƒŧ゚ãĢしãĻいぞす。 + +そぎため、OpenAPIã§ã¯åŒã˜į›Žįš„ãŽãŸã‚ãĢ`example`をį‹Ŧč‡ĒãĢåŽšįžŠã—ãĻおりīŧˆ`examples`ではãĒく`example`としãĻīŧ‰ã€ãã‚ŒãŒdocs UIīŧˆSwagger UIをäŊŋᔍīŧ‰ã§äŊŋį”¨ã•ã‚ŒãĻいぞす。 + +つぞり、`example`はJSON Schemaぎ一部ではありぞせんが、OpenAPIぎ一部であり、それがdocs UIでäŊŋį”¨ã•ã‚Œã‚‹ã“ã¨ãĢãĒりぞす。 + +## そぎäģ–ãŽæƒ…å ą + +同じようãĢã€ãƒ•ãƒ­ãƒŗãƒˆã‚¨ãƒŗãƒ‰ãŽãƒĻãƒŧã‚ļãƒŧã‚¤ãƒŗã‚ŋãƒŧフェãƒŧ゚ãĒおをã‚Ģ゚ã‚ŋマイã‚ēするためãĢ、各ãƒĸデãƒĢぎJSON SchemaãĢčŋŊ加されるį‹Ŧč‡ĒぎčŋŊåŠ æƒ…å ąã‚’čŋŊ加することができぞす。 From 79dbb11867f5217e090d3b498d91d9566be2fd95 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:35:41 +0000 Subject: [PATCH 094/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2d73401ef9..0b820dce19 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-nested-models.md`. PR [#1930](https://github.com/tiangolo/fastapi/pull/1930) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-fields.md`. PR [#1923](https://github.com/tiangolo/fastapi/pull/1923) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 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). From c238292b44340f55df15ea48eb324288b922e85a Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:36:32 +0900 Subject: [PATCH 095/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/extra-models.md`=20(#1941)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/extra-models.md | 195 ++++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 docs/ja/docs/tutorial/extra-models.md diff --git a/docs/ja/docs/tutorial/extra-models.md b/docs/ja/docs/tutorial/extra-models.md new file mode 100644 index 0000000000..aa2e5ffdcb --- /dev/null +++ b/docs/ja/docs/tutorial/extra-models.md @@ -0,0 +1,195 @@ +# ãƒĸデãƒĢ - ã‚ˆã‚ŠčŠŗã—ã + +先ãģおぎ䞋ãĢįļšãã€č¤‡æ•°ãŽé–ĸ逪ãƒĸデãƒĢを持つことが一čˆŦįš„ã§ã™ã€‚ + +これはãƒĻãƒŧã‚ļãƒŧãƒĸデãƒĢãŽå ´åˆã¯į‰šãĢそうです。ãĒぜãĒら: + +* **å…Ĩ力ãƒĸデãƒĢ** ãĢはパ゚ワãƒŧドがåŋ…čĻã§ã™ã€‚ +* **å‡ē力ãƒĸデãƒĢ**はパ゚ワãƒŧドをもつずきではありぞせん。 +* **デãƒŧã‚ŋベãƒŧ゚ãƒĸデãƒĢ**ã¯ãŠãã‚‰ããƒãƒƒã‚ˇãƒĨ化されたパ゚ワãƒŧドがåŋ…čρãĢãĒるでしょう。 + +!!! danger "åąé™ē" + ãƒĻãƒŧã‚ļãƒŧãŽåšŗæ–‡ãŽãƒ‘ã‚šãƒ¯ãƒŧドはįĩļ寞ãĢäŋå­˜ã—ãĒいでください。常ãĢčĒč¨ŧãĢåˆŠį”¨å¯čƒŊãĒ「厉全ãĒãƒãƒƒã‚ˇãƒĨ」をäŋå­˜ã—ãĻください。 + + įŸĨらãĒい斚は、[ã‚ģキãƒĨãƒĒãƒ†ã‚ŖãŽįĢ ](security/simple-oauth2.md#password-hashing){.internal-link target=_blank}で「パ゚ワãƒŧãƒ‰ãƒãƒƒã‚ˇãƒĨ」とはäŊ•かをå­Ļãļことができぞす。 + +## č¤‡æ•°ãŽãƒĸデãƒĢ + +ここでは、パ゚ワãƒŧãƒ‰ãƒ•ã‚ŖãƒŧãƒĢドをもつãƒĸデãƒĢがおぎようãĢčĻ‹ãˆã‚‹ãŽã‹ã€ãžãŸã€ãŠã“ã§äŊŋわれるぎか、大ぞかãĒã‚¤ãƒĄãƒŧã‚¸ã‚’į´šäģ‹ã—ぞす: + +```Python hl_lines="9 11 16 22 24 29-30 33-35 40-41" +{!../../../docs_src/extra_models/tutorial001.py!} +``` + +### `**user_in.dict()`ãĢついãĻ + +#### Pydanticぎ`.dict()` + +`user_in`は`UserIn`クナ゚ぎPydanticãƒĸデãƒĢです。 + +PydanticãƒĸデãƒĢãĢは、ãƒĸデãƒĢぎデãƒŧã‚ŋをåĢむ`dict`をčŋ”す`.dict()`ãƒĄã‚Ŋッドがありぞす。 + +そこで、äģĨ下ぎようãĒPydanticã‚Ēブジェクト`user_in`をäŊœæˆã™ã‚‹ã¨: + +```Python +user_in = UserIn(username="john", password="secret", email="john.doe@example.com") +``` + +そしãĻå‘ŧãŗå‡ēすと: + +```Python +user_dict = user_in.dict() +``` + +これで変数`user_dict`ぎデãƒŧã‚ŋを持つ`dict`ができぞした。īŧˆã“れはPydanticãƒĸデãƒĢぎã‚ĒブジェクトぎäģŖã‚ã‚ŠãĢ`dict`ですīŧ‰ã€‚ + +そしãĻå‘ŧãŗå‡ēすと: + +```Python +print(user_dict) +``` + +äģĨ下ぎようãĒPythonぎ`dict`を垗ることができぞす: + +```Python +{ + 'username': 'john', + 'password': 'secret', + 'email': 'john.doe@example.com', + 'full_name': None, +} +``` + +#### `dict`ãŽåą•é–‹ + +`user_dict`ぎようãĒ`dict`を受け取り、それを`**user_dict`を持つé–ĸ数īŧˆãžãŸã¯ã‚¯ãƒŠã‚šīŧ‰ãĢæ¸Ąã™ã¨ã€Pythonã¯ãã‚Œã‚’ã€Œåą•é–‹ã€ã—ãžã™ã€‚ã“ã‚Œã¯`user_dict`ぎキãƒŧã¨å€¤ã‚’į›´æŽĨキãƒŧãƒģバãƒĒãƒĨãƒŧぎåŧ•数としãĻæ¸Ąã—ãžã™ã€‚ + +そこで上čŋ°ãŽ`user_dict`ぎįļšãã‚’äģĨ下ぎようãĢ書くと: + +```Python +UserInDB(**user_dict) +``` + +äģĨä¸‹ã¨åŒį­‰ãŽįĩæžœãĢãĒりぞす: + +```Python +UserInDB( + username="john", + password="secret", + email="john.doe@example.com", + full_name=None, +) +``` + +ã‚‚ãŖã¨æ­ŖįĸēãĢč¨€ãˆã°ã€`user_dict`を将æĨįš„ãĢおんãĒå†…åŽšã§ã‚ãŖãĻã‚‚į›´æŽĨäŊŋį”¨ã™ã‚‹ã“ã¨ãĢãĒりぞす: + +```Python +UserInDB( + username = user_dict["username"], + password = user_dict["password"], + email = user_dict["email"], + full_name = user_dict["full_name"], +) +``` + +#### åˆĨぎãƒĸデãƒĢからつくるPydanticãƒĸデãƒĢ + +上čŋ°ãŽäž‹ã§ã¯`user_in.dict()`から`user_dict`ã‚’ã“ãŽã‚ŗãƒŧドぎようãĢ取垗しãĻいぞすが: + +```Python +user_dict = user_in.dict() +UserInDB(**user_dict) +``` + +これはäģĨä¸‹ã¨åŒį­‰ã§ã™: + +```Python +UserInDB(**user_in.dict()) +``` + +...ãĒぜãĒら`user_in.dict()`は`dict`であり、`**`をäģ˜ä¸Žã—ãĻ`UserInDB`ã‚’æ¸Ąã—ãĻPythonãĢã€Œåą•é–‹ã€ã•ã›ãĻいるからです。 + +そこで、åˆĨぎPydanticãƒĸデãƒĢぎデãƒŧã‚ŋからPydanticãƒĸデãƒĢを取垗しぞす。 + +#### `dict`ãŽåą•é–‹ã¨čŋŊ加åŧ•æ•° + +そしãĻ、čŋŊ加ぎキãƒŧワãƒŧドåŧ•æ•°`hashed_password=hashed_password`をäģĨ下ぎようãĢčŋŊ加すると: + +```Python +UserInDB(**user_in.dict(), hashed_password=hashed_password) +``` + +...äģĨ下ぎようãĢãĒりぞす: + +```Python +UserInDB( + username = user_dict["username"], + password = user_dict["password"], + email = user_dict["email"], + full_name = user_dict["full_name"], + hashed_password = hashed_password, +) +``` + +!!! warning "æŗ¨æ„" + ã‚ĩポãƒŧトしãĻいるčŋŊ加抟čƒŊは、デãƒŧã‚ŋぎ可čƒŊãĒæĩã‚Œã‚’デãƒĸã™ã‚‹ã ã‘ã§ã‚ã‚Šã€ã‚‚ãĄã‚ã‚“æœŦåŊ“ぎã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚’æäž›ã—ãĻいるわけではありぞせん。 + +## é‡č¤‡ãŽå‰Šæ¸› + +ã‚ŗãƒŧãƒ‰ãŽé‡č¤‡ã‚’æ¸›ã‚‰ã™ã“ã¨ã¯ã€**FastAPI**ãŽä¸­æ ¸įš„ãĒã‚ĸイデã‚ĸぎīŧ‘つです。 + +ã‚ŗãƒŧãƒ‰ãŽé‡č¤‡ãŒåĸ—えると、バグやã‚ģキãƒĨãƒĒãƒ†ã‚ŖãŽå•éĄŒã€ã‚ŗãƒŧãƒ‰ãŽéžåŒæœŸåŒ–å•éĄŒīŧˆã‚る場所では更新しãĻもäģ–ぎ場所では更新されãĒい場合īŧ‰ãĒおがį™ēį”Ÿã™ã‚‹å¯čƒŊ性がéĢ˜ããĒりぞす。 + +そしãĻ、これらぎãƒĸデãƒĢは全ãĻぎデãƒŧã‚ŋã‚’å…ąæœ‰ã—ã€åąžæ€§åã‚„åž‹ã‚’é‡č¤‡ã•ã›ãĻいぞす。 + +ã‚‚ãŖã¨č‰¯ã„æ–šæŗ•ãŒã‚ã‚Šãžã™ã€‚ + +äģ–ぎãƒĸデãƒĢぎベãƒŧ゚とãĒる`UserBase`ãƒĸデãƒĢã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ãã—ãĻ、そぎãƒĸデãƒĢãŽåąžæ€§īŧˆåž‹åŽŖč¨€ã€æ¤œč¨ŧãĒおīŧ‰ã‚’į‰ŋするã‚ĩブクナ゚をäŊœã‚‹ã“とができぞす。 + +デãƒŧã‚ŋぎ変換、検č¨ŧ、文書化ãĒおはすずãĻ通常通りãĢ動äŊœã—ぞす。 + +こぎようãĢしãĻ、ãƒĸデãƒĢé–“ãŽé•ã„ã ã‘ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="9 15 16 19 20 23 24" +{!../../../docs_src/extra_models/tutorial002.py!} +``` + +## `Union`ぞたは`anyOf` + +ãƒŦã‚šãƒãƒŗã‚šã‚’īŧ’つぎ型ぎ`Union`としãĻåŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +OpenAPIでは`anyOf`ã§åŽšįžŠã•ã‚Œãžã™ã€‚ + +そぎためãĢは、標æē–įš„ãĒPythonãŽåž‹ãƒ’ãƒŗãƒˆ`typing.Union`をäŊŋį”¨ã—ãžã™: + +```Python hl_lines="1 14 15 18 19 20 33" +{!../../../docs_src/extra_models/tutorial003.py!} +``` + +## ãƒĸデãƒĢぎãƒĒ゚ト + +同じようãĢ、ã‚ĒブジェクトぎãƒĒ゚トぎãƒŦã‚šãƒãƒŗã‚šã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +そぎためãĢは、標æē–ぎPythonぎ`typing.List`をäŊŋį”¨ã™ã‚‹: + +```Python hl_lines="1 20" +{!../../../docs_src/extra_models/tutorial004.py!} +``` + +## äģģæ„ãŽ`dict`を持つãƒŦã‚šãƒãƒŗã‚š + +ぞた、PydanticãƒĸデãƒĢをäŊŋį”¨ã›ãšãĢ、キãƒŧã¨å€¤ãŽåž‹ã ã‘ã‚’åŽšįžŠã—ãŸäģģæ„ãŽ`dict`をäŊŋãŖãĻãƒŦã‚šãƒãƒŗã‚šã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +これは、有劚ãĒãƒ•ã‚ŖãƒŧãƒĢドãƒģåąžæ€§åīŧˆPydanticãƒĸデãƒĢãĢåŋ…čρãĒもぎīŧ‰ã‚’äē‹å‰ãĢįŸĨらãĒい場合ãĢäžŋ刊です。 + +こぎ場合、`typing.Dict`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="1 8" +{!../../../docs_src/extra_models/tutorial005.py!} +``` + +## ぞとめ + +č¤‡æ•°ãŽPydanticãƒĸデãƒĢをäŊŋį”¨ã—ã€ã‚ąãƒŧ゚ごとãĢč‡Ēį”ąãĢį‰ŋしぞす。 + +ã‚¨ãƒŗãƒ†ã‚Ŗãƒ†ã‚ŖãŒį•°ãĒる「įŠļ態」を持たãĒければãĒらãĒã„å ´åˆã¯ã€ã‚¨ãƒŗãƒ†ã‚Ŗãƒ†ã‚Ŗã”ã¨ãĢ単一ぎデãƒŧã‚ŋãƒĸデãƒĢを持つåŋ…čĻã¯ã‚ã‚Šãžã›ã‚“ã€‚`password` や `password_hash` やパ゚ワãƒŧドãĒしãĒおぎいくつかぎ「įŠļ態」をもつãƒĻãƒŧã‚ļãƒŧã€Œã‚¨ãƒŗãƒ†ã‚Ŗãƒ†ã‚Ŗã€ãŽå ´åˆãŽæ§˜ãĢã™ã‚Œã°č‰¯ã„ã§ã™ã€‚ From f386011d64e68c63f397834eda1c937b660f0d75 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:38:18 +0000 Subject: [PATCH 096/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0b820dce19..bca167cd1f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese tranlsation for `docs/ja/docs/tutorial/schema-extra-example.md`. PR [#1931](https://github.com/tiangolo/fastapi/pull/1931) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-nested-models.md`. PR [#1930](https://github.com/tiangolo/fastapi/pull/1930) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-fields.md`. PR [#1923](https://github.com/tiangolo/fastapi/pull/1923) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 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). From 17511f776891d6bbdaac2a6ba7157b24259210a4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:38:58 +0000 Subject: [PATCH 097/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index bca167cd1f..33caa2ac7e 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-models.md`. PR [#1941](https://github.com/tiangolo/fastapi/pull/1941) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese tranlsation for `docs/ja/docs/tutorial/schema-extra-example.md`. PR [#1931](https://github.com/tiangolo/fastapi/pull/1931) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-nested-models.md`. PR [#1930](https://github.com/tiangolo/fastapi/pull/1930) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-fields.md`. PR [#1923](https://github.com/tiangolo/fastapi/pull/1923) by [@SwftAlpc](https://github.com/SwftAlpc). From 88225ae231731ff266f964f3bf5818a4397db223 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:42:08 +0900 Subject: [PATCH 098/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/response-status-code.md`=20?= =?UTF-8?q?(#1942)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/response-status-code.md | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 docs/ja/docs/tutorial/response-status-code.md diff --git a/docs/ja/docs/tutorial/response-status-code.md b/docs/ja/docs/tutorial/response-status-code.md new file mode 100644 index 0000000000..ead2adddaa --- /dev/null +++ b/docs/ja/docs/tutorial/response-status-code.md @@ -0,0 +1,89 @@ +# ãƒŦã‚šãƒãƒŗã‚šã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧド + +ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢã‚’æŒ‡åŽšã™ã‚‹ãŽã¨åŒã˜æ–šæŗ•ã§ã€ãƒŦã‚šãƒãƒŗã‚šãĢäŊŋį”¨ã•ã‚Œã‚‹HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドをäģĨ下ぎ*path operations*ぎいずれかぎ`status_code`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã§åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +* `@app.get()` +* `@app.post()` +* `@app.put()` +* `@app.delete()` +* ãĒお。 + +```Python hl_lines="6" +{!../../../docs_src/response_status_code/tutorial001.py!} +``` + +!!! note "å‚™č€ƒ" + `status_code`ã¯ã€Œãƒ‡ã‚ŗãƒŦãƒŧã‚ŋã€ãƒĄã‚Ŋッドīŧˆ`get`、`post`ãĒおīŧ‰ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋであることãĢæŗ¨æ„ã—ãĻください。すずãĻãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚„ãƒœãƒ‡ã‚ŖãŽã‚ˆã†ãĢ、*path operationé–ĸ数*ぎもぎではありぞせん。 + +`status_code`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋはHTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドをåĢむ数値を受け取りぞす。 + +!!! info "æƒ…å ą" + `status_code`はäģŖã‚ã‚ŠãĢ、Pythonぎ`http.HTTPStatus`ぎようãĢ、`IntEnum`を受け取ることもできぞす。 + +これは: + +* ãƒŦã‚šãƒãƒŗã‚šã§ã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧドをčŋ”しぞす。 +* OpenAPI゚キãƒŧマīŧˆãŠã‚ˆãŗãƒĻãƒŧã‚ļãƒŧã‚¤ãƒŗã‚ŋãƒŧフェãƒŧ゚īŧ‰ãĢäģĨ下ぎようãĢ文書化しぞす: + + + +!!! note "å‚™č€ƒ" + いくつかぎãƒŦã‚šãƒãƒŗã‚šã‚ŗãƒŧドīŧˆæŦĄãŽã‚ģã‚¯ã‚ˇãƒ§ãƒŗã‚’å‚į…§īŧ‰ã¯ã€ãƒŦã‚šãƒãƒŗã‚šãĢãƒœãƒ‡ã‚ŖãŒãĒいことをį¤ēしãĻいぞす。 + + FastAPIはこれをįŸĨãŖãĻいãĻ、ãƒŦã‚šãƒãƒŗã‚šãƒœãƒ‡ã‚ŖãŒãĒいというOpenAPIドキãƒĨãƒĄãƒŗãƒˆã‚’į”Ÿæˆã—ãžã™ã€‚ + +## HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドãĢついãĻ + +!!! note "å‚™č€ƒ" + すでãĢHTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドがäŊ•であるかをįŸĨãŖãĻいる場合は、æŦĄãŽã‚ģã‚¯ã‚ˇãƒ§ãƒŗãĢ゚キップしãĻください。 + +HTTPでは、ãƒŦã‚šãƒãƒŗã‚šãŽä¸€éƒ¨ã¨ã—ãĻīŧ“æĄãŽæ•°å­—ãŽã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧドを送äŋĄã—ぞす。 + +これらぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドは、それらをčĒč­˜ã™ã‚‹ãŸã‚ãĢé–ĸ逪äģ˜ã‘ã‚‰ã‚ŒãŸåå‰ã‚’æŒãŖãĻいぞすが、重čρãĒ部分はį•Ēåˇã§ã™ã€‚ + +つぞり: + +* `100`äģĨä¸Šã¯ã€Œæƒ…å ąã€ãŽãŸã‚ãŽã‚‚ãŽã§ã™ã€‚ã€‚į›´æŽĨäŊŋうことはãģとんおありぞせん。これらぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドを持つãƒŦã‚šãƒãƒŗã‚šã¯ãƒœãƒ‡ã‚Ŗã‚’æŒã¤ã“ã¨ãŒã§ããžã›ã‚“ã€‚ +* **`200`** äģĨ上は「成功」ぎãƒŦã‚šãƒãƒŗã‚šãŽãŸã‚ãŽã‚‚ãŽã§ã™ã€‚ã“ã‚Œã‚‰ã¯æœ€ã‚‚åˆŠį”¨ã™ã‚‹ã§ã‚ã‚ã†ã‚‚ãŽã§ã™ã€‚ + * `200`はデフりãƒĢトぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドで、すずãĻが「OKã€ã§ã‚ãŖãŸã“ã¨ã‚’æ„å‘ŗã—ãžã™ã€‚ + * åˆĨぎ䞋としãĻは、`201`īŧˆCreatedīŧ‰ãŒã‚りぞす。これはデãƒŧã‚ŋベãƒŧ゚ãĢ新しいãƒŦã‚ŗãƒŧドをäŊœæˆã—た垌ãĢよくäŊŋį”¨ã•ã‚Œãžã™ã€‚ + * į‰šæŽŠãĒã‚ąãƒŧ゚としãĻ、`204`īŧˆNo Contentīŧ‰ãŒã‚りぞす。こぎãƒŦã‚šãƒãƒŗã‚šã¯ã‚¯ãƒŠã‚¤ã‚ĸãƒŗãƒˆãĢčŋ”ã™ã‚ŗãƒŗãƒ†ãƒŗãƒ„ãŒãĒい場合ãĢäŊŋį”¨ã•ã‚Œãžã™ã€‚ãã—ãĻこぎãƒŦã‚šãƒãƒŗã‚šã¯ãƒœãƒ‡ã‚Ŗã‚’æŒã¤ã“ã¨ã¯ã§ããžã›ã‚“ã€‚ +* **`300`** äģĨ上は「ãƒĒダイãƒŦクト」ぎためぎもぎです。これらぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドを持つãƒŦã‚šãƒãƒŗã‚šã¯`304`īŧˆNot Modifiedīŧ‰ã‚’é™¤ãã€ãƒœãƒ‡ã‚Ŗã‚’æŒã¤ã“ã¨ã‚‚æŒãŸãĒいこともできぞす。 +* **`400`** äģĨ上は「クナイã‚ĸãƒŗãƒˆã‚¨ãƒŠãƒŧ」ぎãƒŦã‚šãƒãƒŗã‚šãŽãŸã‚ãŽã‚‚ãŽã§ã™ã€‚ã“ã‚Œã‚‰ã¯ã€ãŠãã‚‰ãæœ€ã‚‚å¤šį”¨ã™ã‚‹ã§ã‚ã‚ã†īŧ’į•Ēį›ŽãŽã‚ŋイプです。 + * 䞋えば、`404`は「Not Found」ãƒŦã‚šãƒãƒŗã‚šã§ã™ã€‚ + * クナイã‚ĸãƒŗãƒˆã‹ã‚‰ãŽä¸€čˆŦįš„ãĒエナãƒŧãĢついãĻは、`400`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ +* `500`äģĨ上はã‚ĩãƒŧバãƒŧエナãƒŧãŽãŸã‚ãŽã‚‚ãŽã§ã™ã€‚ã“ã‚Œã‚‰ã‚’į›´æŽĨäŊŋうことはãģとんおありぞせん。ã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗã‚ŗãƒŧドやã‚ĩãƒŧバãƒŧぎおこかでäŊ•ã‹å•éĄŒãŒį™ēį”Ÿã—ãŸå ´åˆã€ã“ã‚Œã‚‰ãŽã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧドぎいずれかがč‡Ēå‹•įš„ãĢčŋ”されぞす。 + +!!! tip "豆įŸĨ識" + それぞれぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧãƒ‰ã¨ãŠãŽã‚ŗãƒŧドがäŊ•ãŽãŸã‚ãŽã‚ŗãƒŧドãĒぎかãĢついãĻčŠŗį´°ã¯MDN HTTP ãƒŦã‚šãƒãƒŗã‚šã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧドãĢついãĻぎドキãƒĨãƒĄãƒŗãƒˆã‚’å‚į…§ã—ãĻください。 + +## 名前をčĻšãˆã‚‹ãŸã‚ãŽčŋ‘道 + +先ãģおぎ䞋をもう一åēĻčĻ‹ãĻãŋぞしょう: + +```Python hl_lines="6" +{!../../../docs_src/response_status_code/tutorial001.py!} +``` + +`201`は「äŊœæˆåތäē†ã€ãŽãŸã‚ãŽã‚šãƒ†ãƒŧã‚ŋã‚šã‚ŗãƒŧドです。 + +ã—ã‹ã—ã€ãã‚Œãžã‚ŒãŽã‚ŗãƒŧãƒ‰ãŽæ„å‘ŗã‚’æš—č¨˜ã™ã‚‹åŋ…čĻã¯ã‚ã‚Šãžã›ã‚“ã€‚ + +`fastapi.status`ぎäžŋ刊ãĒå¤‰æ•°ã‚’åˆŠį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +```Python hl_lines="1 6" +{!../../../docs_src/response_status_code/tutorial002.py!} +``` + +それらはäžŋ刊です。それらは同じį•Ēåˇã‚’äŋæŒã—ãĻãŠã‚Šã€ããŽæ–šæŗ•ã§ã¯ã‚¨ãƒ‡ã‚Ŗã‚ŋぎč‡Ēå‹•čŖœåŽŒã‚’äŊŋį”¨ã—ãĻそれらをčĻ‹ã¤ã‘ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + + + +!!! note "æŠ€čĄ“čŠŗį´°" + ぞた、`from starlette import status`をäŊŋうこともできぞす。 + + **FastAPI** は、`開į™ēč€…ãŽåˆŠäžŋæ€§ã‚’č€ƒæ…Žã—ãĻ、fastapi.status`と同じ`starlette.status`を提䞛しãĻいぞす。しかし、これはStarletteã‹ã‚‰į›´æŽĨ提䞛されãĻいぞす。 + +## デフりãƒĢトぎ変更 + +垌ãĢ、[é̘åēĻãĒãƒĻãƒŧã‚ļãƒŧã‚Ŧイド](../advanced/response-change-status-code.md){.internal-link target=_blank}ã§ã€ã“ã“ã§åŽŖč¨€ã—ãĻいるデフりãƒĢãƒˆã¨ã¯į•°ãĒる゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドをčŋ”ã™æ–šæŗ•ã‚’čĻ‹ãĻいきぞす。 From 217bff20cabbd47dfef43394bae72f807a44e9a7 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:43:45 +0900 Subject: [PATCH 099/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/handling-errors.md`=20(#195?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/handling-errors.md | 265 +++++++++++++++++++++++ 1 file changed, 265 insertions(+) create mode 100644 docs/ja/docs/tutorial/handling-errors.md diff --git a/docs/ja/docs/tutorial/handling-errors.md b/docs/ja/docs/tutorial/handling-errors.md new file mode 100644 index 0000000000..ec36e9880d --- /dev/null +++ b/docs/ja/docs/tutorial/handling-errors.md @@ -0,0 +1,265 @@ +# エナãƒŧãƒãƒŗãƒ‰ãƒĒãƒŗã‚° + +APIをäŊŋį”¨ã—ãĻいるクナイã‚ĸãƒŗãƒˆãĢエナãƒŧを通įŸĨするåŋ…čĻãŒã‚ã‚‹įŠļæŗã¯ãŸãã•ã‚“ã‚ã‚Šãžã™ã€‚ + +こぎクナイã‚ĸãƒŗãƒˆã¯ã€ãƒ•ãƒ­ãƒŗãƒˆã‚¨ãƒŗãƒ‰ã‚’æŒã¤ãƒ–ãƒŠã‚Ļã‚ļ、čĒ°ã‹ãŽã‚ŗãƒŧド、IoTデバイ゚ãĒãŠãŒč€ƒãˆã‚‰ã‚Œãžã™ã€‚ + +クナイã‚ĸãƒŗãƒˆãĢäģĨ下ぎようãĒことをäŧãˆã‚‹åŋ…čĻãŒã‚ã‚‹ã‹ã‚‚ã—ã‚Œãžã›ã‚“: + +* クナイã‚ĸãƒŗãƒˆãĢはそぎ操äŊœãŽãŸã‚ãŽååˆ†ãĒ樊限がありぞせん。 +* クナイã‚ĸãƒŗãƒˆã¯ããŽãƒĒã‚Ŋãƒŧ゚ãĢã‚ĸクã‚ģ゚できぞせん。 +* クナイã‚ĸãƒŗãƒˆãŒã‚ĸクã‚ģ゚しようとしãĻã„ãŸé …į›ŽãŒå­˜åœ¨ã—ãžã›ã‚“ã€‚ +* ãĒお + +これらぎ場合、通常は **400**īŧˆ400から499īŧ‰ãŽį¯„å›˛å†…ãŽ **HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧド** をčŋ”すことãĢãĒりぞす。 + +これは200ぎHTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドīŧˆ200から299īŧ‰ãĢäŧŧãĻいぞす。これらぎ「200」゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドは、äŊ•らかぎåŊĸでãƒĒã‚¯ã‚¨ã‚šãƒˆã€ŒæˆåŠŸã€ã§ã‚ãŖãŸã“ã¨ã‚’æ„å‘ŗã—ãžã™ã€‚ + +400ãŽį¯„å›˛ãĢある゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドは、クナイã‚ĸãƒŗãƒˆã‹ã‚‰ãŽã‚¨ãƒŠãƒŧãŒã‚ãŖãŸã“ã¨ã‚’æ„å‘ŗã—ãžã™ã€‚ + +**"404 Not Found"** ぎエナãƒŧīŧˆãŠã‚ˆãŗã‚¸ãƒ§ãƒŧクīŧ‰ã‚’čĻšãˆãĻいぞすかīŧŸ + +## `HTTPException`ぎäŊŋᔍ + +HTTPãƒŦã‚šãƒãƒŗã‚šã‚’ã‚¨ãƒŠãƒŧでクナイã‚ĸãƒŗãƒˆãĢčŋ”すãĢは、`HTTPException`をäŊŋį”¨ã—ãžã™ã€‚ + +### `HTTPException`ãŽã‚¤ãƒŗãƒãƒŧト + +```Python hl_lines="1" +{!../../../docs_src/handling_errors/tutorial001.py!} +``` + +### ã‚ŗãƒŧド内でぎ`HTTPException`ぎį™ēį”Ÿ + +`HTTPException`は通常ぎPythonぎ䞋外であり、APIãĢé–ĸé€Ŗã™ã‚‹ãƒ‡ãƒŧã‚ŋをčŋŊ加したもぎです。 + +Pythonぎ䞋外ãĒぎで、`return`ではãĒく、`raise`です。 + +これはぞた、*path operationé–ĸ数*ぎ内部でå‘ŧãŗå‡ēしãĻいるãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚Ŗé–ĸ数ぎ内部から`HTTPException`をį™ēį”Ÿã•ã›ãŸå ´åˆã€*path operationé–ĸ数*ãŽæŽ‹ã‚ŠãŽã‚ŗãƒŧãƒ‰ã¯åŽŸčĄŒã•ã‚Œãšã€ããŽãƒĒã‚¯ã‚¨ã‚šãƒˆã‚’į›´ãĄãĢįĩ‚äē†ã•せ、`HTTPException`からぎHTTPエナãƒŧをクナイã‚ĸãƒŗãƒˆãĢ送äŋĄã™ã‚‹ã“ã¨ã‚’æ„å‘ŗã—ãžã™ã€‚ + +値をčŋ”す`return`よりも䞋外をį™ēį”Ÿã•ã›ã‚‹ã“ã¨ãŽåˆŠį‚šã¯ã€ã€Œäžå­˜é–ĸäŋ‚とã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã€ãŽã‚ģã‚¯ã‚ˇãƒ§ãƒŗã§ã‚ˆã‚Šæ˜ŽįĸēãĢãĒりぞす。 + +こぎ䞋では、クナイã‚ĸãƒŗãƒˆãŒå­˜åœ¨ã—ãĒいIDでã‚ĸイテムをčĻæą‚ã—ãŸå ´åˆã€`404`ぎ゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドを持つ䞋外をį™ēį”Ÿã•ã›ãžã™: + +```Python hl_lines="11" +{!../../../docs_src/handling_errors/tutorial001.py!} +``` + +### ãƒŦã‚šãƒãƒŗã‚šįĩæžœ + +クナイã‚ĸãƒŗãƒˆãŒ`http://example.com/items/foo`īŧˆ`item_id` `"foo"`īŧ‰ã‚’ãƒĒクエ゚トすると、HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドが200で、äģĨ下ぎJSONãƒŦã‚šãƒãƒŗã‚šãŒčŋ”されぞす: + +```JSON +{ + "item": "The Foo Wrestlers" +} +``` + +しかし、クナイã‚ĸãƒŗãƒˆãŒ`http://example.com/items/bar`īŧˆå­˜åœ¨ã—ãĒい`item_id` `"bar"`īŧ‰ã‚’ãƒĒクエ゚トした場合、HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧド404īŧˆ"not found"エナãƒŧīŧ‰ã¨äģĨ下ぎJSONãƒŦã‚šãƒãƒŗã‚šãŒčŋ”されぞす: + +```JSON +{ + "detail": "Item not found" +} +``` + +!!! tip "豆įŸĨ識" + `HTTPException`をį™ēį”Ÿã•ã›ã‚‹éš›ãĢは、`str`だけでãĒく、JSONãĢ変換できるäģģæ„ãŽå€¤ã‚’`detail`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋとしãĻæ¸Ąã™ã“ã¨ãŒã§ããžã™ã€‚ + + `dist`や`list`ãĒãŠã‚’æ¸Ąã™ã“ã¨ãŒã§ããžã™ã€‚ + + これらは **FastAPI** ãĢã‚ˆãŖãĻč‡Ēå‹•įš„ãĢå‡Ļį†ã•ã‚Œã€JSONãĢ変換されぞす。 + +## ã‚Ģ゚ã‚ŋムヘッダãƒŧぎčŋŊ加 + +䞋えば、いくつかぎã‚ŋイプぎã‚ģキãƒĨãƒĒãƒ†ã‚ŖãŽãŸã‚ãĢ、HTTPエナãƒŧãĢã‚Ģ゚ã‚ŋムヘッダをčŋŊ加できるとäžŋ刊ãĒįŠļæŗãŒã„ãã¤ã‹ã‚ã‚Šãžã™ã€‚ + +ãŠãã‚‰ãã‚ŗãƒŧãƒ‰ãŽä¸­ã§į›´æŽĨäŊŋį”¨ã™ã‚‹åŋ…čĻã¯ãĒいでしょう。 + +しかし、é̘åēĻãĒã‚ˇãƒŠãƒĒã‚ĒぎためãĢåŋ…čρãĒ場合ãĢは、ã‚Ģ゚ã‚ŋムヘッダãƒŧをčŋŊ加することができぞす: + +```Python hl_lines="14" +{!../../../docs_src/handling_errors/tutorial002.py!} +``` + +## ã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠãŽã‚¤ãƒŗã‚šãƒˆãƒŧãƒĢ + +ã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠã¯Starletteと同じ䞋外ãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚Ŗã‚’äŊŋį”¨ã—ãĻčŋŊ加することができぞす。 + +あãĒたīŧˆãžãŸã¯äŊŋį”¨ã—ãĻいるナイブナãƒĒīŧ‰ãŒ`raise`するかもしれãĒいã‚Ģ゚ã‚ŋム䞋外`UnicornException`があるとしぞしょう。 + +そしãĻ、こぎ䞋外をFastAPIでグロãƒŧバãƒĢãĢå‡Ļį†ã—ãŸã„ã¨æ€ã„ãžã™ã€‚ + +ã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’`@app.exception_handler()`でčŋŊ加することができぞす: + +```Python hl_lines="5 6 7 13 14 15 16 17 18 24" +{!../../../docs_src/handling_errors/tutorial003.py!} +``` + +ここで、`/unicorns/yolo`をãƒĒクエ゚トすると、*path operation*は`UnicornException`を`raise`しぞす。 + +しかし、これは`unicorn_exception_handler`でå‡Ļį†ã•ã‚Œãžã™ã€‚ + +そぎため、HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧドが`418`で、JSONぎ内厚がäģĨ下ぎようãĒ明įĸēãĒエナãƒŧを受け取ることãĢãĒりぞす: + +```JSON +{"message": "Oops! yolo did something. There goes a rainbow..."} +``` + +!!! note "æŠ€čĄ“čŠŗį´°" + ぞた、`from starlette.requests import Request`と`from starlette.responses import JSONResponse`をäŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + + **FastAPI** は開į™ēč€…ãŽåˆŠäžŋæ€§ã‚’č€ƒæ…Žã—ãĻ、`fastapi.responses`と同じ`starlette.responses`を提䞛しãĻã„ãžã™ã€‚ã—ã‹ã—ã€åˆŠį”¨å¯čƒŊãĒãƒŦã‚šãƒãƒŗã‚šãŽãģとんおはStarletteã‹ã‚‰į›´æŽĨ提䞛されぞす。これは`Request`と同じです。 + +## デフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠãŽã‚Ēãƒŧバãƒŧナイド + +**FastAPI** ãĢはいくつかぎデフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠãŒã‚ã‚Šãžã™ã€‚ + +ã“ã‚Œã‚‰ãŽãƒãƒŗãƒ‰ãƒŠã¯ã€`HTTPException`を`raise`させた場合や、ãƒĒクエ゚トãĢį„ĄåŠšãĒデãƒŧã‚ŋがåĢぞれãĻいる場合ãĢデフりãƒĢトぎJSONãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”すåŊšå‰˛ã‚’æ‹…ãŖãĻいぞす。 + +ã“ã‚Œã‚‰ãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’į‹Ŧč‡Ēぎもぎでã‚Ēãƒŧバãƒŧナイドすることができぞす。 + +### ãƒĒクエ゚ト検č¨ŧぎ䞋外ぎã‚Ēãƒŧバãƒŧナイド + +ãƒĒクエ゚トãĢį„ĄåŠšãĒデãƒŧã‚ŋがåĢぞれãĻいる場合、**FastAPI** ã¯å†…éƒ¨įš„ãĢ`RequestValidationError`をį™ēį”Ÿã•ã›ãžã™ã€‚ + +ぞた、そぎためぎデフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚‚åĢぞれãĻいぞす。 + +これをã‚ĒãƒŧバãƒŧナイドするãĢは`RequestValidationError`ã‚’ã‚¤ãƒŗãƒãƒŧトしãĻ`@app.exception_handler(RequestValidationError)`ã¨ä¸€įˇ’ãĢäŊŋį”¨ã—ãĻäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’ãƒ‡ã‚ŗãƒŦãƒŧトしぞす。 + +ã“ãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã¯`Requset`と䞋外を受け取りぞす。 + +```Python hl_lines="2 14 15 16" +{!../../../docs_src/handling_errors/tutorial004.py!} +``` + +これで、`/items/foo`ãĢã‚ĸクã‚ģ゚すると、デフりãƒĢトぎJSONエナãƒŧぎäģŖã‚ã‚ŠãĢäģĨ下がčŋ”されぞす: + +```JSON +{ + "detail": [ + { + "loc": [ + "path", + "item_id" + ], + "msg": "value is not a valid integer", + "type": "type_error.integer" + } + ] +} +``` + +äģĨ下ぎようãĒãƒ†ã‚­ã‚šãƒˆį‰ˆã‚’å–åž—ã—ãžã™: + +``` +1 validation error +path -> item_id + value is not a valid integer (type=type_error.integer) +``` + +#### `RequestValidationError`と`ValidationError` + +!!! warning "æŗ¨æ„" + これらはäģŠãŽã‚ãĒたãĢã¨ãŖãĻ重čĻã§ãĒã„å ´åˆã¯įœį•ĨしãĻã‚‚č‰¯ã„æŠ€čĄ“įš„ãĒčŠŗį´°ã§ã™ã€‚ + +`RequestValidationError`はPydanticぎ`ValidationError`ぎã‚ĩブクナ゚です。 + +**FastAPI** は`response_model`でPydanticãƒĸデãƒĢをäŊŋį”¨ã—ãĻいãĻ、デãƒŧã‚ŋãĢエナãƒŧãŒã‚ãŖãŸå ´åˆã€ãƒ­ã‚°ãĢエナãƒŧãŒčĄ¨į¤ēされるようãĢこれをäŊŋį”¨ã—ãĻいぞす。 + +しかし、クナイã‚ĸãƒŗãƒˆã‚„ãƒĻãƒŧã‚ļãƒŧはそれをčĻ‹ã‚‹ã“ã¨ã¯ã‚ã‚Šãžã›ã‚“ã€‚ããŽäģŖã‚ã‚ŠãĢ、クナイã‚ĸãƒŗãƒˆã¯HTTP゚テãƒŧã‚ŋã‚šã‚ŗãƒŧド`500`ぎ「Internal Server Error」を受け取りぞす。 + +*ãƒŦã‚šãƒãƒŗã‚š*ã‚„ã‚ŗãƒŧドぎおこかīŧˆã‚¯ãƒŠã‚¤ã‚ĸãƒŗãƒˆãŽ*ãƒĒクエ゚ト*ではãĒくīŧ‰ãĢPydanticぎ`ValidationError`がある場合、それは原際ãĢã¯ã‚ŗãƒŧドぎバグãĒぎでこぎようãĢすずきです。 + +ぞた、あãĒたがそれをäŋŽæ­Ŗã—ãĻいる間は、ã‚ģキãƒĨãƒĒãƒ†ã‚ŖãŽč„†åŧ࿀§ãŒéœ˛å‘ˆã™ã‚‹å ´åˆãŒã‚るため、クナイã‚ĸãƒŗãƒˆã‚„ãƒĻãƒŧã‚ļãƒŧがエナãƒŧãĢé–ĸã™ã‚‹å†…éƒ¨æƒ…å ąãĢã‚ĸクã‚ģ゚できãĒいようãĢしãĻください。 + +### エナãƒŧãƒãƒŗãƒ‰ãƒŠ`HTTPException`ぎã‚Ēãƒŧバãƒŧナイド + +同様ãĢ、`HTTPException`ãƒãƒŗãƒ‰ãƒŠã‚’ã‚Ēãƒŧバãƒŧナイドすることもできぞす。 + +䞋えば、これらぎエナãƒŧãĢ寞しãĻは、JSONではãĒくプãƒŦãƒŧãƒŗãƒ†ã‚­ã‚šãƒˆã‚’čŋ”すようãĢすることができぞす: + +```Python hl_lines="3 4 9 10 11 22" +{!../../../docs_src/handling_errors/tutorial004.py!} +``` + +!!! note "æŠ€čĄ“čŠŗį´°" + ぞた、`from starlette.responses import PlainTextResponse`をäŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + + **FastAPI** は開į™ēč€…ãŽåˆŠäžŋæ€§ã‚’č€ƒæ…Žã—ãĻ、`fastapi.responses`と同じ`starlette.responses`を提䞛しãĻã„ãžã™ã€‚ã—ã‹ã—ã€åˆŠį”¨å¯čƒŊãĒãƒŦã‚šãƒãƒŗã‚šãŽãģとんおはStarletteã‹ã‚‰į›´æŽĨ提䞛されぞす。 + +### `RequestValidationError`ãŽãƒœãƒ‡ã‚ŖãŽäŊŋᔍ + +`RequestValidationError`ãĢã¯į„ĄåŠšãĒデãƒŧã‚ŋをåĢむ`body`がåĢぞれãĻいぞす。 + +ã‚ĸプãƒĒ開į™ē中ãĢæœŦäŊ“ãŽãƒ­ã‚°ã‚’å–ãŖãĻデバッグしたり、ãƒĻãƒŧã‚ļãƒŧãĢčŋ”したりãĒおãĢäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +```Python hl_lines="14" +{!../../../docs_src/handling_errors/tutorial005.py!} +``` + +ここで、äģĨ下ぎようãĒį„ĄåŠšãĒé …į›Žã‚’é€äŋĄã—ãĻãŋãĻください: + +```JSON +{ + "title": "towel", + "size": "XL" +} +``` + +受äŋĄã—ãŸãƒœãƒ‡ã‚Ŗã‚’åĢむデãƒŧã‚ŋãŒį„ĄåŠšã§ã‚ã‚‹ã“ã¨ã‚’į¤ēすãƒŦã‚šãƒãƒŗã‚šãŒčĄ¨į¤ēされぞす: + +```JSON hl_lines="12 13 14 15" +{ + "detail": [ + { + "loc": [ + "body", + "size" + ], + "msg": "value is not a valid integer", + "type": "type_error.integer" + } + ], + "body": { + "title": "towel", + "size": "XL" + } +} +``` + +#### FastAPIぎ`HTTPException`とStarletteぎ`HTTPException` + +**FastAPI**はį‹Ŧč‡Ēぎ`HTTPException`ã‚’æŒãŖãĻいぞす。 + +ぞた、 **FastAPI**ぎエナãƒŧクナ゚`HTTPException`はStarletteぎエナãƒŧクナ゚`HTTPException`をį‰ŋしãĻいぞす。 + +唯一ぎ違いは、**FastAPI** ぎ`HTTPException`はãƒŦã‚šãƒãƒŗã‚šãĢåĢぞれるヘッダをčŋŊ加できることです。 + +これはOAuth 2.0といくつかぎã‚ģキãƒĨãƒĒãƒ†ã‚ŖãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚ŖãŽãŸã‚ãĢå†…éƒ¨įš„ãĢåŋ…čĻã¨ã•ã‚Œã€äŊŋį”¨ã•ã‚ŒãĻいぞす。 + +ããŽãŸã‚ã€ã‚ŗãƒŧド内では通常通り **FastAPI** ぎ`HTTPException`をį™ēį”Ÿã•ã›įļšã‘ることができぞす。 + +ã—ã‹ã—ã€äž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’į™ģéŒ˛ã™ã‚‹éš›ãĢは、Starletteぎ`HTTPException`をį™ģéŒ˛ã—ãĻおくåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +これãĢより、StarletteãŽå†…éƒ¨ã‚ŗãƒŧドやStarletteãŽæ‹Ąåŧĩ抟čƒŊã‚„ãƒ—ãƒŠã‚°ã‚¤ãƒŗãŽä¸€éƒ¨ãŒ`HTTPException`をį™ēį”Ÿã•ã›ãŸå ´åˆã€ãƒãƒŗãƒ‰ãƒŠãŒãã‚Œã‚’ã‚­ãƒŖãƒƒãƒã—ãĻå‡Ļį†ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ã‚ˆã†ãĢãĒりぞす。 + +äģĨä¸‹ãŽäž‹ã§ã¯ã€åŒã˜ã‚ŗãƒŧãƒ‰å†…ã§ä¸Ąæ–šãŽ`HTTPException`をäŊŋį”¨ã§ãã‚‹ã‚ˆã†ãĢするためãĢ、Starletteぎ䞋外ぎ名前を`StarletteHTTPException`ãĢ変更しãĻいぞす: + +```Python +from starlette.exceptions import HTTPException as StarletteHTTPException +``` + +### **FastAPI** ãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠãŽå†åˆŠį”¨ + +ぞた、äŊ•ã‚‰ã‹ãŽæ–šæŗ•ã§äž‹å¤–ã‚’äŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ãŒã€**FastAPI** から同じデフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’äŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +デフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’`fastapi.exception_handlers`ã‹ã‚‰ã‚¤ãƒŗãƒãƒŧトしãĻå†åˆŠį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="2 3 4 5 15 21" +{!../../../docs_src/handling_errors/tutorial006.py!} +``` + +こぎ䞋では、非常ãĢčĄ¨įžåŠ›ãŽã‚ã‚‹ãƒĄãƒƒã‚ģãƒŧジでエナãƒŧを`print`しãĻいぞす。 + +しかし、䞋外をäŊŋį”¨ã—ãĻ、デフりãƒĢãƒˆãŽäž‹å¤–ãƒãƒŗãƒ‰ãƒŠã‚’å†åˆŠį”¨ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ã¨ã„ã†ã“ã¨ãŒį†č§Ŗã§ããžã™ã€‚ From efac3a293fecc06a4cbb933f829877cc914a95f1 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:45:27 +0900 Subject: [PATCH 100/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/python-types.md`=20(#1899)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/python-types.md | 315 +++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 docs/ja/docs/python-types.md diff --git a/docs/ja/docs/python-types.md b/docs/ja/docs/python-types.md new file mode 100644 index 0000000000..bbfef2adf1 --- /dev/null +++ b/docs/ja/docs/python-types.md @@ -0,0 +1,315 @@ +# PythonãŽåž‹ãŽį´šäģ‹ + +**Python 3.6äģĨ降** ã§ã¯ã€Œåž‹ãƒ’ãƒŗãƒˆã€ã‚Ēãƒ—ã‚ˇãƒ§ãƒŗãŒã‚ĩポãƒŧトされãĻいぞす。 + +これらぎ **"åž‹ãƒ’ãƒŗãƒˆ"** ã¯å¤‰æ•°ãŽåž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ãã‚‹æ–°ã—ã„æ§‹æ–‡ã§ã™ã€‚īŧˆPython 3.6äģĨ降īŧ‰ + +変数ãĢåž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã§ã‚¨ãƒ‡ã‚Ŗã‚ŋãƒŧやツãƒŧãƒĢãŒã‚ˆã‚Šč‰¯ã„ã‚ĩポãƒŧトを提䞛することができぞす。 + +ここではPythonãŽåž‹ãƒ’ãƒŗãƒˆãĢついãĻぎ **クイックチãƒĨãƒŧトãƒĒã‚ĸãƒĢ/ãƒĒフãƒŦãƒƒã‚ˇãƒĨ** で、**FastAPI**でそれらをäŊŋį”¨ã™ã‚‹ãŸã‚ãĢåŋ…čρãĒ最äŊŽé™ãŽã“とだけをã‚ĢバãƒŧしãĻいぞす。...原際ãĢはæœŦåŊ“ãĢ少ãĒいです。 + +**FastAPI** はすずãĻã“ã‚Œã‚‰ãŽåž‹ãƒ’ãƒŗãƒˆãĢåŸēãĨいãĻおり、多くぎåŧˇãŋã¨åˆŠį‚šã‚’ä¸ŽãˆãĻくれぞす。 + +ã—ã‹ã—ãŸã¨ãˆãžãŖãŸã **FastAPI** をäŊŋį”¨ã—ãĒい場合でも、それらãĢついãĻ少しå­Ļãļã“ã¨ã§åˆŠį‚šã‚’åž—ã‚‹ã“ã¨ãŒã§ãã‚‹ã§ã—ã‚‡ã†ã€‚ + +!!! note "å‚™č€ƒ" + もしあãĒたがPythonぎ専門åŽļで、すでãĢåž‹ãƒ’ãƒŗãƒˆãĢついãĻすずãĻįŸĨãŖãĻいるぎであれば、æŦĄãŽįĢ ãžã§čĒ­ãŋéŖ›ã°ã—ãĻください。 + +## 動抟 + +į°Ąå˜ãĒ䞋から始めãĻãŋぞしょう: + +```Python +{!../../../docs_src/python_types/tutorial001.py!} +``` + +ã“ãŽãƒ—ãƒ­ã‚°ãƒŠãƒ ã‚’åŽŸčĄŒã™ã‚‹ã¨äģĨ下がå‡ē力されぞす: + +``` +John Doe +``` + +こぎé–ĸ数はäģĨ下ぎようãĒã“ã¨ã‚’čĄŒã„ãžã™: + +* `first_name`と`last_name`を取垗しぞす。 +* `title()`ã‚’į”¨ã„ãĻ、それぞれぎ最初ぎ文字を大文字ãĢ変換しぞす。 +* įœŸã‚“ä¸­ãĢ゚ペãƒŧ゚をå…ĨれãĻ逪įĩã—ぞす。 + +```Python hl_lines="2" +{!../../../docs_src/python_types/tutorial001.py!} +``` + +### ᎍ集 + +これはとãĻã‚‚į°Ąå˜ãĒプログナムです。 + +しかし、äģŠã€ã‚ãĒたがそれを一から書いãĻã„ãŸã¨æƒŗåƒã—ãĻãŋãĻください。 + +ãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎæē–備ができãĻいたら、そぎとき、é–ĸæ•°ãŽåŽšįžŠã‚’å§‹ã‚ãĻいたことでしょう... + +しかし、そうすると「最初ぎ文字を大文字ãĢå¤‰æ›ã™ã‚‹ã‚ãŽãƒĄã‚Ŋッド」をå‘ŧãŗå‡ēすåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +それは`upper`でしたかīŧŸ`uppercase`でしたかīŧŸãã‚Œã¨ã‚‚`first_uppercase`īŧŸãžãŸã¯`capitalize`īŧŸ + +そしãĻ、古くからプログナマãƒŧぎ友äēēã§ã‚ã‚‹ã‚¨ãƒ‡ã‚Ŗã‚ŋでč‡Ēå‹•čŖœåŽŒã‚’čŠĻしãĻãŋぞす。 + +é–ĸæ•°ãŽæœ€åˆãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`first_name`をå…Ĩ力し、ドット(`.`)をå…Ĩ力しãĻから、`Ctrl+Space`をæŠŧã™ã¨čŖœåŽŒãŒåŽŸčĄŒã•ã‚Œãžã™ã€‚ + +ã—ã‹ã—ã€æ‚˛ã—ã„ã“ã¨ãĢ、これはãĒんぎåŊšãĢもįĢ‹ãĄãžã›ã‚“: + + + +### 型ぎčŋŊ加 + +先ãģãŠãŽã‚ŗãƒŧãƒ‰ã‹ã‚‰ä¸€čĄŒå¤‰æ›´ã—ãĻãŋぞしょう。 + +äģĨ下ぎé–ĸæ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋ部分を: + +```Python + first_name, last_name +``` + +äģĨ下へ変更しぞす: + +```Python + first_name: str, last_name: str +``` + +これだけです。 + +ãã‚ŒãŒã€Œåž‹ãƒ’ãƒŗãƒˆã€ã§ã™: + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial002.py!} +``` + +これは、äģĨ下ぎようãĢデフりãƒĢãƒˆå€¤ã‚’åŽŖč¨€ã™ã‚‹ãŽã¨åŒã˜ã§ã¯ã‚ã‚Šãžã›ã‚“: + +```Python + first_name="john", last_name="doe" +``` + +それとはåˆĨį‰Šã§ã™ã€‚ + +ã‚¤ã‚ŗãƒŧãƒĢīŧˆ`=`īŧ‰ã§ã¯ãĒãã€ã‚ŗãƒ­ãƒŗīŧˆ`:`īŧ‰ã‚’äŊŋį”¨ã—ãžã™ã€‚ + +そしãĻã€é€šå¸¸ã€åž‹ãƒ’ãƒŗãƒˆã‚’čŋŊ加しãĻも、それらがãĒいįŠļ態とčĩˇã“ることはäŊ•も変わりぞせん。 + +しかしäģŠã€ã‚ãĒãŸãŒå†ãŗããŽé–ĸ数をäŊœæˆã—ãĻいる最中ãĢã€åž‹ãƒ’ãƒŗãƒˆã‚’äŊŋãŖãĻã„ã‚‹ã¨æƒŗåƒã—ãĻãŋãĻ下さい。 + +同じã‚ŋã‚¤ãƒŸãƒŗã‚°ã§`Ctrl+Space`でč‡Ēå‹•čŖœåŽŒã‚’åŽŸčĄŒã™ã‚‹ã¨ã€äģĨ下ぎようãĢãĒりぞす: + + + +これであれば、あãĒたは「ベãƒĢã‚’éŗ´ã‚‰ã™ã€ä¸€ã¤ã‚’čĻ‹ã¤ã‘ã‚‹ãžã§ã€ã‚Ēãƒ—ã‚ˇãƒ§ãƒŗã‚’čĻ‹ãĻ、゚クロãƒŧãƒĢすることができぞす: + + + +## よりåŧˇã„動抟 + +こぎé–ĸ数をčĻ‹ãĻください。すでãĢåž‹ãƒ’ãƒŗãƒˆã‚’æŒãŖãĻいぞす: + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial003.py!} +``` + +ã‚¨ãƒ‡ã‚Ŗã‚ŋは変数ぎ型をįŸĨãŖãĻã„ã‚‹ãŽã§ã€čŖœåŽŒã ã‘ã§ãĒく、エナãƒŧチェックをすることもできぞす。 + + + +これで`age`を`str(age)`で文字列ãĢ変換しãĻäŋŽæ­Ŗã™ã‚‹åŋ…čĻãŒã‚ã‚‹ã“ã¨ãŒã‚ã‹ã‚Šãžã™: + +```Python hl_lines="2" +{!../../../docs_src/python_types/tutorial004.py!} +``` + +## åž‹ãŽåŽŖč¨€ + +é–ĸæ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋとしãĻã€åž‹ãƒ’ãƒŗãƒˆã‚’åŽŖč¨€ã—ãĻいるä¸ģãĒ場所をįĸēčĒã—ãžã—ãŸã€‚ + +これは **FastAPI** でäŊŋį”¨ã™ã‚‹ä¸ģãĒ場所でもありぞす。 + +### å˜į´”ãĒ型 + +`str`だけでãĒく、Pythonぎ標æē–įš„ãĒ型すずãĻã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +䞋えば、äģĨ下をäŊŋį”¨å¯čƒŊです: + +* `int` +* `float` +* `bool` +* `bytes` + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial005.py!} +``` + +### åž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを持つジェネãƒĒック型 + +デãƒŧã‚ŋ構造ぎ中ãĢは、`dict`、`list`、`set`、そしãĻ`tuple`ぎようãĢäģ–ぎ値をåĢむことができるもぎがありぞす。ぞた内部ぎ値もį‹Ŧč‡Ēぎ型を持つことができぞす。 + +ã“ã‚Œã‚‰ãŽåž‹ã‚„å†…éƒ¨ãŽåž‹ã‚’åŽŖč¨€ã™ã‚‹ãĢは、Pythonぎ標æē–ãƒĸジãƒĨãƒŧãƒĢ`typing`をäŊŋį”¨ã—ãžã™ã€‚ + +ã“ã‚Œã‚‰ãŽåž‹ãƒ’ãƒŗãƒˆã‚’ã‚ĩポãƒŧトするためãĢį‰šåˆĨãĢ存在しãĻいぞす。 + +#### `List` + +䞋えば、`str`ぎ`list`ãŽå¤‰æ•°ã‚’åŽšįžŠã—ãĻãŋぞしょう。 + +`typing`から`List`ã‚’ã‚¤ãƒŗãƒãƒŧトしぞすīŧˆå¤§æ–‡å­—ぎ`L`をåĢむīŧ‰: + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial006.py!} +``` + +同じようãĢã‚ŗãƒ­ãƒŗīŧˆ`:`īŧ‰ãŽæ§‹æ–‡ã§å¤‰æ•°ã‚’åŽŖč¨€ã—ãžã™ã€‚ + +型としãĻ、`List`をå…Ĩ力しぞす。 + +ãƒĒ゚トはいくつかぎ内部ぎ型をåĢむ型ãĒãŽã§ã€ãã‚Œã‚‰ã‚’č§’æ‹Ŧåŧ§ã§å›˛ã‚“でいぞす。 + +```Python hl_lines="4" +{!../../../docs_src/python_types/tutorial006.py!} +``` + +!!! tip "豆įŸĨ識" + 角æ‹Ŧåŧ§å†…ãŽå†…éƒ¨ãŽåž‹ã¯ã€Œåž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ」とå‘ŧばれãĻいぞす。 + + こぎ場合、`str`は`List`ãĢæ¸Ąã•ã‚Œã‚‹åž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋです。 + +つぞり: 変数`items`は`list`であり、こぎãƒĒã‚šãƒˆãŽå„é …į›Žã¯`str`です。 + +ãã†ã™ã‚‹ã“ã¨ã§ã€ã‚¨ãƒ‡ã‚Ŗã‚ŋはãƒĒã‚šãƒˆãŽé …į›Žã‚’å‡Ļį†ã—ãĻいる間ãĢもã‚ĩポãƒŧトを提䞛できぞす。 + + + +ã‚ŋイプがãĒければ、それはãģãŧ不可čƒŊです。 + +変数`item`はãƒĒ゚ト`items`ぎčĻį´ ãŽä¸€ã¤ã§ã‚ã‚‹ã“ã¨ãĢæŗ¨æ„ã—ãĻください。 + +ãã‚Œã§ã‚‚ã€ã‚¨ãƒ‡ã‚Ŗã‚ŋはそれが`str`であることをįŸĨãŖãĻいãĻ、そぎためぎã‚ĩポãƒŧトを提䞛しãĻいぞす。 + +#### `Tuple` と `Set` + +`tuple`と`set`ãŽåŽŖč¨€ã‚‚åŒæ§˜ã§ã™: + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial007.py!} +``` + +つぞり: + +* 変数`items_t`は`int`、`int`、`str`ぎ3ã¤ãŽé …į›Žã‚’æŒã¤`tuple`です + +* 変数`items_s`ã¯ãã‚Œãžã‚ŒãŽé …į›ŽãŒ`bytes`型である`set`です。 + +#### `Dict` + +`dict`ã‚’åŽŖč¨€ã™ã‚‹ãŸã‚ãĢは、ã‚ĢãƒŗãƒžåŒē切りで2ã¤ãŽåž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’æ¸Ąã—ãžã™ã€‚ + +æœ€åˆãŽåž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋは`dict`ぎキãƒŧです。 + +īŧ’į•Ēį›ŽãŽåž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋは`dict`ぎ値です。 + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial008.py!} +``` + +つぞり: + +* 変数`prices`は`dict`であり: + * こぎ`dict`ぎキãƒŧは`str`型です。īŧˆã¤ãžã‚Šã€å„é …į›ŽãŽåå‰īŧ‰ + * こぎ`dict`ぎ値は`float`型です。īŧˆã¤ãžã‚Šã€å„é …į›ŽãŽäžĄæ ŧīŧ‰ + +#### `Optional` + +ぞた、`Optional`をäŊŋį”¨ã—ãĻ、変数が`str`ぎようãĒåž‹ã‚’æŒã¤ã“ã¨ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ãŒã€ãã‚Œã¯ã€Œã‚Ēãƒ—ã‚ˇãƒ§ãƒŗã€ã§ã‚ã‚Šã€`None`ãĢすることもできぞす。 + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial009.py!} +``` + +ただぎ`str`ぎäģŖã‚ã‚ŠãĢ`Optional[str]`をäŊŋį”¨ã™ã‚‹ã“ã¨ã§ã€ã‚¨ãƒ‡ã‚Ŗã‚ŋは値が常ãĢ`str`であるとäģŽåŽšã—ãĻいる場合ãĢ原際ãĢは`None`である可čƒŊ性があるエナãƒŧを検å‡ēするぎãĢåŊšįĢ‹ãĄãžã™ã€‚ + +#### ジェネãƒĒック型 + +äģĨ下ぎようãĢ角æ‹Ŧåŧ§ã§åž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを取る型を: + +* `List` +* `Tuple` +* `Set` +* `Dict` +* `Optional` +* ...ãĒお + +**ジェネãƒĒック型** ぞたは **ジェネãƒĒク゚** とå‘ŧãŗãžã™ã€‚ + +### 型としãĻぎクナ゚ + +変数ぎ型としãĻã‚¯ãƒŠã‚šã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +䞋えば、`Person`クナ゚という名前ぎクナ゚があるとしぞしょう: + +```Python hl_lines="1 2 3" +{!../../../docs_src/python_types/tutorial010.py!} +``` + +変数ぎ型を`Person`としãĻåŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="6" +{!../../../docs_src/python_types/tutorial010.py!} +``` + +そしãĻã€å†ãŗã€ã™ãšãĻãŽã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトを垗ることができぞす: + + + +## PydanticぎãƒĸデãƒĢ + +Pydantic はデãƒŧã‚ŋ検č¨ŧã‚’čĄŒã†ãŸã‚ãŽPythonナイブナãƒĒです。 + +デãƒŧã‚ŋぎ「åŊĸã€ã‚’åąžæ€§äģ˜ããŽã‚¯ãƒŠã‚šã¨ã—ãĻåŽŖč¨€ã—ãžã™ã€‚ + +そしãĻã€ãã‚Œãžã‚ŒãŽåąžæ€§ã¯åž‹ã‚’æŒãĄãžã™ã€‚ + +さらãĢã€ã„ãã¤ã‹ãŽå€¤ã‚’æŒã¤ã‚¯ãƒŠã‚šãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚’äŊœæˆã™ã‚‹ã¨ã€ããŽå€¤ã‚’検č¨ŧし、遊切ãĒ型ãĢ変換しãĻīŧˆã‚‚しそうであればīŧ‰å…¨ãĻぎデãƒŧã‚ŋを持つã‚Ēブジェクトを提䞛しãĻくれぞす。 + +ぞた、そぎįĩæžœãŽã‚ĒブジェクトですずãĻãŽã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧトを受けることができぞす。 + +Pydanticぎå…Ŧåŧãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‹ã‚‰åŧ•ᔍ: + +```Python +{!../../../docs_src/python_types/tutorial011.py!} +``` + +!!! info "æƒ…å ą" + PydanticãĢついãĻよりå­ĻãŗãŸã„æ–šã¯ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‚’å‚į…§ã—ãĻください. + +**FastAPI** はすずãĻPydanticをベãƒŧ゚ãĢしãĻいぞす。 + +すずãĻぎことは[チãƒĨãƒŧトãƒĒã‚ĸãƒĢ - ãƒĻãƒŧã‚ļãƒŧã‚Ŧイド](tutorial/index.md){.internal-link target=_blank}で原際ãĢčĻ‹ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +## **FastAPI**ã§ãŽåž‹ãƒ’ãƒŗãƒˆ + +**FastAPI** ã¯ã“ã‚Œã‚‰ãŽåž‹ãƒ’ãƒŗãƒˆã‚’åˆŠį”¨ã—ãĻã„ãã¤ã‹ãŽã“ã¨ã‚’čĄŒã„ãžã™ã€‚ + +**FastAPI** ã§ã¯åž‹ãƒ’ãƒŗãƒˆã‚’äŊŋãŖãĻåž‹ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã¨äģĨ下ぎもぎが垗られぞす: + +* **ã‚¨ãƒ‡ã‚Ŗã‚ŋã‚ĩポãƒŧト**. +* **型チェック**. + +...そしãĻ **FastAPI** は同じようãĢåŽŖč¨€ã‚’ã™ã‚‹ã¨ã€äģĨä¸‹ãŽã“ã¨ã‚’čĄŒã„ãžã™: + +* **čρäģļãŽåŽšįžŠ**: ãƒĒã‚¯ã‚¨ã‚šãƒˆãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋ、クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ、ヘッダãƒŧã€ãƒœãƒ‡ã‚Ŗã€äžå­˜é–ĸäŋ‚ãĒおからčρäģļã‚’åŽšįžŠã—ãžã™ã€‚ +* **デãƒŧã‚ŋぎ変換**: ãƒĒクエ゚トぎデãƒŧã‚ŋをåŋ…čρãĒ型ãĢ変換しぞす。 +* **デãƒŧã‚ŋぎ検č¨ŧ**: ãƒĒクエ゚トごとãĢ: + * デãƒŧã‚ŋãŒį„ĄåŠšãĒ場合ãĢクナイã‚ĸãƒŗãƒˆãĢčŋ”される **č‡Ē動エナãƒŧ** ã‚’į”Ÿæˆã—ãžã™ã€‚ +* **ドキãƒĨãƒĄãƒŗãƒˆ** OpenAPIをäŊŋį”¨ã—ãŸAPI: + * č‡Ēå‹•įš„ãĢå¯žčŠąåž‹ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆãŽãƒĻãƒŧã‚ļãƒŧã‚¤ãƒŗã‚ŋãƒŧフェイ゚でäŊŋį”¨ã•ã‚Œãžã™ã€‚ + +すずãĻがæŠŊčąĄįš„ãĢčžã“ãˆã‚‹ã‹ã‚‚ã—ã‚Œãžã›ã‚“ã€‚åŋƒé…ã—ãĒいでください。 こぎ全ãĻぎ動äŊœã¯ [チãƒĨãƒŧトãƒĒã‚ĸãƒĢ - ãƒĻãƒŧã‚ļãƒŧã‚Ŧイド](tutorial/index.md){.internal-link target=_blank}でčĻ‹ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +重čρãĒぎは、Pythonぎ標æē–įš„ãĒ型をäŊŋうことで、īŧˆã‚¯ãƒŠã‚šã‚„ãƒ‡ã‚ŗãƒŦãƒŧã‚ŋãĒおをčŋŊ加するぎではãĒくīŧ‰īŧ‘つぎ場所で **FastAPI** が多くぎäŊœæĨ­ã‚’äģŖã‚ã‚ŠãĢã‚„ãŖãĻくれãĻいるということです。 + +!!! info "æƒ…å ą" + すでãĢすずãĻぎチãƒĨãƒŧトãƒĒã‚ĸãƒĢをįĩ‚えãĻ、型ãĢついãĻãŽčŠŗį´°ã‚’čĻ‹ã‚‹ãŸã‚ãĢこぎペãƒŧジãĢæˆģãŖãĻきた場合は、`mypy`ぎチãƒŧãƒˆã‚ˇãƒŧãƒˆã‚’å‚į…§ã—ãĻください From b21599bab0a7ab38102c9e42364d1e224ad07fe3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:46:12 +0000 Subject: [PATCH 101/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 33caa2ac7e..997d8b5aa8 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-status-code.md`. PR [#1942](https://github.com/tiangolo/fastapi/pull/1942) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-models.md`. PR [#1941](https://github.com/tiangolo/fastapi/pull/1941) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese tranlsation for `docs/ja/docs/tutorial/schema-extra-example.md`. PR [#1931](https://github.com/tiangolo/fastapi/pull/1931) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-nested-models.md`. PR [#1930](https://github.com/tiangolo/fastapi/pull/1930) by [@SwftAlpc](https://github.com/SwftAlpc). From b73de83ca2edb35122624c4ec6db4120cf5e4496 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:46:32 +0900 Subject: [PATCH 102/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/path-params-numeric-validat?= =?UTF-8?q?ions.md`=20(#1902)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .../path-params-numeric-validations.md | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 docs/ja/docs/tutorial/path-params-numeric-validations.md diff --git a/docs/ja/docs/tutorial/path-params-numeric-validations.md b/docs/ja/docs/tutorial/path-params-numeric-validations.md new file mode 100644 index 0000000000..551aeabb3a --- /dev/null +++ b/docs/ja/docs/tutorial/path-params-numeric-validations.md @@ -0,0 +1,122 @@ +# ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋと数値ぎ検č¨ŧ + +クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ寞しãĻ`Query`でより多くぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã¨ãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã§ãã‚‹ãŽã¨åŒã˜ã‚ˆã†ãĢã€ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ寞しãĻも`Path`ã§åŒã˜į¨ŽéĄžãŽãƒãƒĒデãƒŧã‚ˇãƒ§ãƒŗã¨ãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +## PathãŽã‚¤ãƒŗãƒãƒŧト + +ぞず初めãĢ、`fastapi`から`Path`ã‚’ã‚¤ãƒŗãƒãƒŧトしぞす: + +```Python hl_lines="1" +{!../../../docs_src/path_params_numeric_validations/tutorial001.py!} +``` + +## ãƒĄã‚ŋデãƒŧã‚ŋãŽåŽŖč¨€ + +ãƒ‘ãƒŠãƒĄãƒŧã‚ŋは`Query`ã¨åŒã˜ã‚‚ãŽã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +äž‹ãˆã°ã€ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`item_id`ãĢ寞しãĻ`title`ãŽãƒĄã‚ŋデãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ãĢはäģĨ下ぎようãĢしぞす: + +```Python hl_lines="8" +{!../../../docs_src/path_params_numeric_validations/tutorial001.py!} +``` + +!!! note "å‚™č€ƒ" + パ゚ぎ一部でãĒければãĒらãĒã„ãŽã§ã€ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋは常ãĢåŋ…須です。 + + そぎため、`...`をäŊŋį”¨ã—ãĻåŋ…須とį¤ēすåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + + それでも、`None`ã§åŽŖč¨€ã—ãĻも、デフりãƒĢãƒˆå€¤ã‚’č¨­åŽšã—ãĻも、äŊ•ぎåŊąéŸŋもãĒく、常ãĢåŋ…čĻã¨ã•ã‚ŒãĻいることãĢ変わりはありぞせん。 + +## åŋ…čρãĢåŋœã˜ãĻãƒ‘ãƒŠãƒĄãƒŧã‚ŋをä¸Ļãŗæ›ŋえる + +クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`をåŋ…須ぎ`str`としãĻåŽŖč¨€ã—ãŸã„ã¨ã—ãžã—ã‚‡ã†ã€‚ + +ãžãŸã€ã“ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢはäŊ•ã‚‚åŽŖč¨€ã™ã‚‹åŋ…čĻãŒãĒいぎで、`Query`をäŊŋうåŋ…čĻã¯ã‚ã‚Šãžã›ã‚“ã€‚ + +ã—ã‹ã—ã€ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`item_id`ぎためãĢ`Path`をäŊŋį”¨ã™ã‚‹åŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +Pythonは「デフりãƒĢト」を持たãĒい値ぎ前ãĢ「デフりãƒĢト」を持つ値をįŊŽãã“とができぞせん。 + +しかし、それらをä¸Ļãŗæ›ŋえることができ、デフりãƒĢト値を持たãĒい値īŧˆã‚¯ã‚¨ãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`īŧ‰ã‚’最初ãĢ持つことができぞす。 + +**FastAPI**ではé–ĸäŋ‚ã‚ã‚Šãžã›ã‚“ã€‚ãƒ‘ãƒŠãƒĄãƒŧã‚ŋは名前、型、デフりãƒĢãƒˆãŽåŽŖč¨€īŧˆ`Query`、`Path`ãĒおīŧ‰ã§æ¤œå‡ēされ、順į•Ēは気ãĢしぞせん。 + +そぎため、äģĨ下ぎようãĢé–ĸæ•°ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="8" +{!../../../docs_src/path_params_numeric_validations/tutorial002.py!} +``` + +## åŋ…čρãĢåŋœã˜ãĻãƒ‘ãƒŠãƒĄãƒŧã‚ŋをä¸Ļãŗæ›ŋえるトãƒĒック + +クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`を`Query`やデフりãƒĢト値ãĒã—ã§åŽŖč¨€ã—ã€ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`item_id`を`Path`ã‚’į”¨ã„ãĻåŽŖč¨€ã—ã€ãã‚Œã‚‰ã‚’åˆĨぎ順į•ĒãĢä¸ĻãŗãŸã„å ´åˆã€PythonãĢã¯å°‘ã—į‰šæŽŠãĒæ§‹æ–‡ãŒį”¨æ„ã•ã‚ŒãĻいぞす。 + +é–ĸæ•°ãŽæœ€åˆãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋとしãĻ`*`ã‚’æ¸Ąã—ãžã™ã€‚ + +Pythonはそぎ`*`でäŊ•かをすることはありぞせんが、それäģĨ降ぎすずãĻãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋがキãƒŧワãƒŧドåŧ•æ•°īŧˆã‚­ãƒŧと値ぎペã‚ĸīŧ‰ã¨ã—ãĻå‘ŧばれるずきもぎであるとįŸĨãŖãĻいるでしょう。それはkwargsとしãĻもįŸĨられãĻいぞす。たとえデフりãƒĢト値がãĒくãĻも。 + +```Python hl_lines="8" +{!../../../docs_src/path_params_numeric_validations/tutorial003.py!} +``` + +## 数値ぎ検č¨ŧ: äģĨ上 + +`Query`と`Path`īŧˆã€ãã—ãĻ垌čŋ°ã™ã‚‹äģ–ぎもぎīŧ‰ã‚’į”¨ã„ãĻ、文字列ぎåˆļį´„ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ãŒã€æ•°å€¤ãŽåˆļį´„ã‚‚åŒæ§˜ãĢåŽŖč¨€ã§ããžã™ã€‚ + +ここで、`ge=1`ぎ場合、`item_id`は`1`「より大きい`g`か、同じ`e`」整数でãĒれけばãĒりぞせん。 + +```Python hl_lines="8" +{!../../../docs_src/path_params_numeric_validations/tutorial004.py!} +``` + +## 数値ぎ検č¨ŧ: より大きいと小ãĒã‚Šã‚¤ã‚ŗãƒŧãƒĢ + +äģĨ下も同様です: + +* `gt`: より大きいīŧˆ`g`reater `t`hanīŧ‰ +* `le`: 小ãĒã‚Šã‚¤ã‚ŗãƒŧãƒĢīŧˆ`l`ess than or `e`qualīŧ‰ + +```Python hl_lines="9" +{!../../../docs_src/path_params_numeric_validations/tutorial005.py!} +``` + +## 数値ぎ検č¨ŧ: æĩŽå‹•å°æ•°į‚šã€ 大ãĒり小ãĒり + +数値ぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã¯`float`ぎ値ãĢ寞しãĻも有劚です。 + +ここで重čρãĢãĒãŖãĻくるぎはgtだけでãĒくgeã‚‚åŽŖč¨€ã§ãã‚‹ã“ã¨ã§ã™ã€‚ã“ã‚Œã¨åŒæ§˜ãĢ、䞋えば、値が`1`より小さくãĻも`0`より大きくãĒければãĒらãĒいことをčĻæą‚ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +ã—ãŸãŒãŖãĻ、`0.5`は有劚ãĒ値ですが、`0.0`や`0`はそうではありぞせん。 + +これはltも同じです。 + +```Python hl_lines="11" +{!../../../docs_src/path_params_numeric_validations/tutorial006.py!} +``` + +## ぞとめ + +`Query`と`Path`īŧˆãã—ãĻぞだčĻ‹ãŸã“ã¨ãĒいäģ–ぎもぎīŧ‰ã§ã¯ã€[クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋと文字列ぎ検č¨ŧ](query-params-str-validations.md){.internal-link target=_blank}と同じようãĢãƒĄã‚ŋデãƒŧã‚ŋと文字列ぎ検č¨ŧã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +ぞた、数値ぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™: + +* `gt`: より大きいīŧˆ`g`reater `t`hanīŧ‰ +* `ge`: äģĨ上īŧˆ`g`reater than or `e`qualīŧ‰ +* `lt`: より小さいīŧˆ`l`ess `t`hanīŧ‰ +* `le`: äģĨ下īŧˆ`l`ess than or `e`qualīŧ‰ + +!!! info "æƒ…å ą" + `Query`、`Path`ãĒおは垌ãĢå…ąé€šãŽ`Param`クナ゚ぎã‚ĩブクナ゚をčĻ‹ã‚‹ã“ã¨ãĢãĒりぞす。īŧˆäŊŋうåŋ…čĻã¯ã‚ã‚Šãžã›ã‚“īŧ‰ + + そしãĻ、それらすずãĻは、これぞでčĻ‹ãĻきたčŋŊ加ぎバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã¨ãƒĄã‚ŋデãƒŧã‚ŋã¨åŒã˜ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’å…ąæœ‰ã—ãĻいぞす。 + +!!! note "æŠ€čĄ“čŠŗį´°" + `fastapi`から`Query`、`Path`ãĒãŠã‚’ã‚¤ãƒŗãƒãƒŧトすると、これらは原際ãĢはé–ĸ数です。 + + å‘ŧãŗå‡ēã•ã‚Œã‚‹ã¨ã€åŒã˜åå‰ãŽã‚¯ãƒŠã‚šãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚’čŋ”しぞす。 + + そぎため、é–ĸ数である`Query`ã‚’ã‚¤ãƒŗãƒãƒŧトし、それをå‘ŧãŗå‡ēすと、`Query`ã¨ã„ã†åå‰ãŽã‚¯ãƒŠã‚šãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šãŒčŋ”されぞす。 + + これらぎé–ĸ数はīŧˆã‚¯ãƒŠã‚šã‚’į›´æŽĨäŊŋうぎではãĒくīŧ‰ã‚¨ãƒ‡ã‚Ŗã‚ŋが型ãĢついãĻエナãƒŧとしãĒいようãĢするためãĢ存在しぞす。 + + ã“ãŽæ–šæŗ•ãĢã‚ˆãŖãĻ、これらぎエナãƒŧã‚’į„ĄčĻ–ã™ã‚‹ãŸã‚ãŽč¨­åŽšã‚’čŋŊ加することãĒãã€é€šå¸¸ãŽã‚¨ãƒ‡ã‚Ŗã‚ŋã‚„ã‚ŗãƒŧãƒ‡ã‚Ŗãƒŗã‚°ãƒ„ãƒŧãƒĢをäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ From eed57df6f685b73e3ac0a01060ed2eb81d71fa92 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:46:53 +0000 Subject: [PATCH 103/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 997d8b5aa8..68b2f0a077 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/handling-errors.md`. PR [#1953](https://github.com/tiangolo/fastapi/pull/1953) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-status-code.md`. PR [#1942](https://github.com/tiangolo/fastapi/pull/1942) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-models.md`. PR [#1941](https://github.com/tiangolo/fastapi/pull/1941) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese tranlsation for `docs/ja/docs/tutorial/schema-extra-example.md`. PR [#1931](https://github.com/tiangolo/fastapi/pull/1931) by [@SwftAlpc](https://github.com/SwftAlpc). From a14907a47d723a21c46b06d73bf568a2643657e4 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 00:48:41 +0900 Subject: [PATCH 104/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/body-multiple-params.md`=20?= =?UTF-8?q?(#1903)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/body-multiple-params.md | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 docs/ja/docs/tutorial/body-multiple-params.md diff --git a/docs/ja/docs/tutorial/body-multiple-params.md b/docs/ja/docs/tutorial/body-multiple-params.md new file mode 100644 index 0000000000..2ba10c583e --- /dev/null +++ b/docs/ja/docs/tutorial/body-multiple-params.md @@ -0,0 +1,169 @@ +# ãƒœãƒ‡ã‚Ŗ - č¤‡æ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋ + +これぞで`Path`と`Query`をおうäŊŋうかをčĻ‹ãĻきぞしたが、ãƒĒã‚¯ã‚¨ã‚šãƒˆãƒœãƒ‡ã‚ŖãŽåŽŖč¨€ãŽã‚ˆã‚Šé̘åēĻãĒäŊŋい斚をčĻ‹ãĻãŋぞしょう。 + +## `Path`、`Query`ã¨ãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’æˇˇãœã‚‹ + +ãžãšã€ã‚‚ãĄã‚ã‚“ã€`Path`と`Query`とãƒĒã‚¯ã‚¨ã‚šãƒˆãƒœãƒ‡ã‚ŖãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãŽåŽŖč¨€ã¯č‡Ēį”ąãĢæˇˇãœã‚‹ã“ã¨ãŒã§ãã€ **FastAPI** はäŊ•をするずきかをįŸĨãŖãĻいぞす。 + +ぞた、デフりãƒĢトぎ`None`ã‚’č¨­åŽšã™ã‚‹ã“ã¨ã§ã€ãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋをã‚Ēãƒ—ã‚ˇãƒ§ãƒŗã¨ã—ãĻåŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™: + +```Python hl_lines="19 20 21" +{!../../../docs_src/body_multiple_params/tutorial001.py!} +``` + +!!! note "å‚™č€ƒ" + ã“ãŽå ´åˆã€ãƒœãƒ‡ã‚Ŗã‹ã‚‰å–åž—ã™ã‚‹`item`はã‚Ēãƒ—ã‚ˇãƒ§ãƒŗã§ã‚ã‚‹ã“ã¨ãĢæŗ¨æ„ã—ãĻください。デフりãƒĢト値は`None`です。 + +## č¤‡æ•°ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋ + +上čŋ°ãŽäž‹ã§ã¯ã€*path operations*は`item`ãŽåąžæ€§ã‚’æŒã¤äģĨ下ぎようãĒJSONãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã—ãĻいぞした: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +しかし、`item`と`user`ぎようãĢč¤‡æ•°ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™: + +```Python hl_lines="22" +{!../../../docs_src/body_multiple_params/tutorial002.py!} +``` + +こぎ場合、**FastAPI**はé–ĸ数内ãĢč¤‡æ•°ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋīŧˆPydanticãƒĸデãƒĢであるīŧ’ã¤ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋīŧ‰ãŒã‚ることãĢ気äģ˜ããžã™ã€‚ + +ããŽãŸã‚ã€ãƒ‘ãƒŠãƒĄãƒŧã‚ŋåã‚’ãƒœãƒ‡ã‚ŖãŽã‚­ãƒŧīŧˆãƒ•ã‚ŖãƒŧãƒĢド名īŧ‰ã¨ã—ãĻäŊŋį”¨ã—ã€äģĨ下ぎようãĒãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã—ãĻいぞす: + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + } +} +``` + +!!! note "å‚™č€ƒ" + äģĨ前と同じようãĢ`item`ãŒåŽŖč¨€ã•ã‚ŒãĻいたãĢもかかわらず、`item`はキãƒŧ`item`ã‚’æŒã¤ãƒœãƒ‡ã‚ŖãŽå†…éƒ¨ãĢあることが期垅されãĻいることãĢæŗ¨æ„ã—ãĻください。 + +**FastAPI** はãƒĒクエ゚トからč‡Ēå‹•ã§å¤‰æ›ã‚’čĄŒã„ã€ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`item`ãŒį‰šåŽšãŽå†…åŽšã‚’å—ã‘å–ã‚Šã€`user`も同じようãĢį‰šåŽšãŽå†…åŽšã‚’å—ã‘å–ã‚Šãžã™ã€‚ + +č¤‡åˆãƒ‡ãƒŧã‚ŋぎ検č¨ŧã‚’čĄŒã„ã€OpenAPI゚キãƒŧマやč‡Ē動ドキãƒĨãƒĄãƒŗãƒˆãŽã‚ˆã†ãĢ文書化しãĻくれぞす。 + +## ãƒœãƒ‡ã‚Ŗå†…ãŽå˜æ•°å€¤ + +クエãƒĒã¨ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎčŋŊ加デãƒŧã‚ŋã‚’åŽšįžŠã™ã‚‹ãŸã‚ãŽ `Query` と `Path` があるぎと同じようãĢ、 **FastAPI** ã¯åŒį­‰ãŽ `Body` を提䞛しぞす。 + +䞋えば、前ぎãƒĸデãƒĢã‚’æ‹ĄåŧĩしãĻã€åŒã˜ãƒœãƒ‡ã‚ŖãĢ `item` と `user` ぎäģ–ãĢもう一つぎキãƒŧ `importance` をå…Ĩれたいとæąēめることができぞす。 + +単数値ãĒãŽã§ããŽãžãžåŽŖč¨€ã™ã‚‹ã¨ã€**FastAPI** はそれがクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋであるとãŋãĒしぞす。 + +しかし、`Body`をäŊŋį”¨ã—ãĻ、**FastAPI** ãĢåˆĨãŽãƒœãƒ‡ã‚Ŗã‚­ãƒŧとしãĻæ‰ąã†ã‚ˆã†ãĢ指į¤ēすることができぞす: + + +```Python hl_lines="23" +{!../../../docs_src/body_multiple_params/tutorial003.py!} +``` + +こぎ場合、**FastAPI** はäģĨ下ぎようãĒãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã—ãžã™: + + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + }, + "importance": 5 +} +``` + +įš°ã‚Ščŋ”しãĢãĒりぞすが、デãƒŧã‚ŋ型ぎ変換、検č¨ŧ、文書化ãĒãŠã‚’čĄŒã„ãžã™ã€‚ + +## č¤‡æ•°ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋとクエãƒĒ + +ã‚‚ãĄã‚ã‚“ã€ãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ加えãĻ、åŋ…čρãĢåŋœã˜ãĻčŋŊ加ぎクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +デフりãƒĢトでは、単数値はクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋとしãĻč§Ŗé‡ˆã•ã‚Œã‚‹ãŽã§ã€æ˜Žį¤ēįš„ãĢ `Query` をčŋŊ加するåŋ…čĻã¯ã‚ã‚Šãžã›ã‚“ã€‚ + +```Python +q: str = None +``` + +äģĨ下ãĢおいãĻ: + +```Python hl_lines="27" +{!../../../docs_src/body_multiple_params/tutorial004.py!} +``` + +!!! info "æƒ…å ą" + `Body`もぞた、垌čŋ°ã™ã‚‹ `Query` や `Path` ãĒおと同様ãĢ、すずãĻぎ検č¨ŧãƒ‘ãƒŠãƒĄãƒŧã‚ŋã¨ãƒĄã‚ŋデãƒŧã‚ŋãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’æŒãŖãĻいぞす。 + + +## å˜ä¸€ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎ埋めčžŧãŋ + +PydanticãƒĸデãƒĢ`Item`ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`item`を1ã¤ã ã‘æŒãŖãĻいるとしぞしょう。 + +デフりãƒĢトでは、**FastAPI**ã¯ããŽãƒœãƒ‡ã‚Ŗã‚’į›´æŽĨ期垅しぞす。 + +しかし、čŋŊåŠ ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’åŽŖč¨€ã—ãŸã¨ããŽã‚ˆã†ãĢ、キãƒŧ `item` を持つ JSON とそぎ中ぎãƒĸデãƒĢãŽå†…åŽšã‚’æœŸåž…ã—ãŸã„å ´åˆã¯ã€į‰šåˆĨãĒ `Body` ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ `embed` をäŊŋうことができぞす: + +```Python +item: Item = Body(..., embed=True) +``` + +äģĨ下ãĢおいãĻ: + +```Python hl_lines="17" +{!../../../docs_src/body_multiple_params/tutorial005.py!} +``` + +こぎ場合、**FastAPI** はäģĨ下ぎようãĒãƒœãƒ‡ã‚Ŗã‚’æœŸåž…ã—ãžã™: + +```JSON hl_lines="2" +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + } +} +``` + +äģĨ下ぎäģŖã‚ã‚ŠãĢ: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +## ぞとめ + +ãƒĒã‚¯ã‚¨ã‚šãƒˆãŒå˜ä¸€ãŽãƒœãƒ‡ã‚Ŗã—ã‹æŒãĻãĒい場合でも、*path operationé–ĸ数*ãĢč¤‡æ•°ãŽãƒœãƒ‡ã‚Ŗãƒ‘ãƒŠãƒĄãƒŧã‚ŋをčŋŊ加することができぞす。 + +しかし、**FastAPI** はそれをå‡Ļį†ã—ã€é–ĸæ•°å†…ãŽæ­Ŗã—ã„ãƒ‡ãƒŧã‚ŋを与え、*path operation*å†…ãŽæ­Ŗã—ã„ã‚šã‚­ãƒŧマを検č¨ŧし、文書化しぞす。 + +ãžãŸã€ãƒœãƒ‡ã‚ŖãŽä¸€éƒ¨ã¨ã—ãĻå—ã‘å–ã‚‹å˜æ•°å€¤ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +ãžãŸã€å˜ä¸€ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã—ã‹åŽŖč¨€ã•ã‚ŒãĻいãĒã„å ´åˆã§ã‚‚ã€ãƒœãƒ‡ã‚Ŗã‚’ã‚­ãƒŧãĢ埋めčžŧむようãĢ **FastAPI** ãĢ指į¤ēすることができぞす。 From 1cf1ee42fe6469b9120257b8be4a9f7bcb117177 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:48:57 +0000 Subject: [PATCH 105/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 68b2f0a077..ebe8e1719f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/python-types.md`. PR [#1899](https://github.com/tiangolo/fastapi/pull/1899) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/handling-errors.md`. PR [#1953](https://github.com/tiangolo/fastapi/pull/1953) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-status-code.md`. PR [#1942](https://github.com/tiangolo/fastapi/pull/1942) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-models.md`. PR [#1941](https://github.com/tiangolo/fastapi/pull/1941) by [@SwftAlpc](https://github.com/SwftAlpc). From 997281bf83d3a08716c044c7cf374103bd9fc575 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:51:30 +0000 Subject: [PATCH 106/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ebe8e1719f..9ceee1fa0a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/path-params-numeric-validations.md`. PR [#1902](https://github.com/tiangolo/fastapi/pull/1902) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/python-types.md`. PR [#1899](https://github.com/tiangolo/fastapi/pull/1899) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/handling-errors.md`. PR [#1953](https://github.com/tiangolo/fastapi/pull/1953) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-status-code.md`. PR [#1942](https://github.com/tiangolo/fastapi/pull/1942) by [@SwftAlpc](https://github.com/SwftAlpc). From bf9489c0ad54634c2ea6595d0e1cfdf97b1e1a6d Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 15:53:17 +0000 Subject: [PATCH 107/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 9ceee1fa0a..33cd064e94 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-multiple-params.md`. PR [#1903](https://github.com/tiangolo/fastapi/pull/1903) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/path-params-numeric-validations.md`. PR [#1902](https://github.com/tiangolo/fastapi/pull/1902) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/python-types.md`. PR [#1899](https://github.com/tiangolo/fastapi/pull/1899) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/handling-errors.md`. PR [#1953](https://github.com/tiangolo/fastapi/pull/1953) by [@SwftAlpc](https://github.com/SwftAlpc). From 5c71522974e9dcec378165b64364b8c1deeecb16 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 01:01:54 +0900 Subject: [PATCH 108/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/response-model.md`=20(#1938?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: atsumi Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/response-model.md | 208 ++++++++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 docs/ja/docs/tutorial/response-model.md diff --git a/docs/ja/docs/tutorial/response-model.md b/docs/ja/docs/tutorial/response-model.md new file mode 100644 index 0000000000..749b330610 --- /dev/null +++ b/docs/ja/docs/tutorial/response-model.md @@ -0,0 +1,208 @@ +# ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢ + +*path operations* ぎいずれãĢおいãĻも、`response_model`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋをäŊŋį”¨ã—ãĻ、ãƒŦã‚šãƒãƒŗã‚šãŽãƒĸデãƒĢã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +* `@app.get()` +* `@app.post()` +* `@app.put()` +* `@app.delete()` +* ãĒお。 + +```Python hl_lines="17" +{!../../../docs_src/response_model/tutorial001.py!} +``` + +!!! note "å‚™č€ƒ" + `response_model`ã¯ã€Œãƒ‡ã‚ŗãƒŦãƒŧã‚ŋã€ãƒĄã‚Ŋッドīŧˆ`get`、`post`ãĒおīŧ‰ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋであることãĢæŗ¨æ„ã—ãĻください。すずãĻãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚„ãƒœãƒ‡ã‚ŖãŽã‚ˆã†ãĢ、*path operationé–ĸ数* ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋではありぞせん。 + +PydanticãƒĸデãƒĢãŽåąžæ€§ãĢ寞しãĻåŽŖč¨€ã™ã‚‹ãŽã¨åŒã˜åž‹ã‚’å—ã‘å–ã‚‹ãŽã§ã€PydanticãƒĸデãƒĢãĢãĒることもできぞすが、䞋えば、`List[Item]`ぎようãĒPydanticãƒĸデãƒĢぎ`list`ãĢãĒることもできぞす。 + +FastAPIは`response_model`をäŊŋãŖãĻäģĨ下ぎことをしぞす: + +* å‡ē力デãƒŧã‚ŋã‚’åž‹åŽŖč¨€ãĢ変換しぞす。 +* デãƒŧã‚ŋを検č¨ŧしぞす。 +* OpenAPIぎ *path operation* で、ãƒŦã‚šãƒãƒŗã‚šį”¨ãŽJSON SchemaをčŋŊ加しぞす。 +* č‡Ē動ドキãƒĨãƒĄãƒŗãƒˆã‚ˇã‚šãƒ†ãƒ ã§äŊŋį”¨ã•ã‚Œãžã™ã€‚ + +しかし、最も重čρãĒぎは: + +* å‡ē力デãƒŧã‚ŋをãƒĸデãƒĢぎデãƒŧã‚ŋãĢ限厚しぞす。これがおぎようãĢ重čρãĒぎかäģĨ下でčĻ‹ãĻいきぞしょう。 + +!!! note "æŠ€čĄ“čŠŗį´°" + ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢは、é–ĸ数ぎæˆģり値ぎã‚ĸノテãƒŧã‚ˇãƒ§ãƒŗã§ã¯ãĒãã€ã“ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã§åŽŖč¨€ã•ã‚ŒãĻいぞす。ãĒぜãĒら、パ゚é–ĸ数は原際ãĢはそぎãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢをčŋ”すぎではãĒく、`dict`やデãƒŧã‚ŋベãƒŧ゚ã‚Ēブジェクト、あるいはäģ–ぎãƒĸデãƒĢをčŋ”し、`response_model`をäŊŋį”¨ã—ãĻãƒ•ã‚ŖãƒŧãƒĢドぎåˆļé™ã‚„ã‚ˇãƒĒã‚ĸナイã‚ēã‚’čĄŒã†ã‹ã‚‰ã§ã™ã€‚ + +## 同じå…Ĩ力デãƒŧã‚ŋぎčŋ”却 + +ここでは`UserIn`ãƒĸデãƒĢã‚’åŽŖč¨€ã—ãĻいぞす。それãĢã¯åšŗæ–‡ãŽãƒ‘ã‚šãƒ¯ãƒŧドがåĢぞれãĻいぞす: + +```Python hl_lines="9 11" +{!../../../docs_src/response_model/tutorial002.py!} +``` + +そしãĻ、こぎãƒĸデãƒĢをäŊŋį”¨ã—ãĻå…ĨåŠ›ã‚’åŽŖč¨€ã—ã€åŒã˜ãƒĸデãƒĢをäŊŋãŖãĻå‡ēåŠ›ã‚’åŽŖč¨€ã—ãĻいぞす: + +```Python hl_lines="17 18" +{!../../../docs_src/response_model/tutorial002.py!} +``` + +これで、ブナã‚Ļã‚ļがパ゚ワãƒŧドをäŊŋãŖãĻãƒĻãƒŧã‚ļãƒŧをäŊœæˆã™ã‚‹éš›ãĢ、APIがãƒŦã‚šãƒãƒŗã‚šã§åŒã˜ãƒ‘ã‚šãƒ¯ãƒŧドをčŋ”すようãĢãĒりぞした。 + +こぎ場合、ãƒĻãƒŧã‚ļãƒŧč‡ĒčēĢがパ゚ワãƒŧドを送äŋĄã—ãĻã„ã‚‹ãŽã§å•éĄŒãĒいかもしれぞせん。 + +しかし、同じãƒĸデãƒĢをåˆĨぎ*path operation*ãĢäŊŋį”¨ã™ã‚‹ã¨ã€ã™ãšãĻぎクナイã‚ĸãƒŗãƒˆãĢãƒĻãƒŧã‚ļãƒŧぎパ゚ワãƒŧドを送äŋĄã—ãĻしぞうことãĢãĒりぞす。 + +!!! danger "åąé™ē" + ãƒĻãƒŧã‚ļãƒŧãŽåšŗæ–‡ãŽãƒ‘ã‚šãƒ¯ãƒŧドをäŋå­˜ã—たり、ãƒŦã‚šãƒãƒŗã‚šã§é€äŋĄã—たりすることはįĩļ寞ãĢしãĒいでください。 + +## å‡ē力ãƒĸデãƒĢぎčŋŊ加 + +äģŖã‚ã‚ŠãĢã€åšŗæ–‡ãŽãƒ‘ã‚šãƒ¯ãƒŧドを持つå…Ĩ力ãƒĸデãƒĢと、パ゚ワãƒŧドを持たãĒいå‡ē力ãƒĸデãƒĢをäŊœæˆã™ã‚‹ã“とができぞす: + +```Python hl_lines="9 11 16" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +ここでは、*path operationé–ĸ数*がパ゚ワãƒŧドをåĢむ同じå…Ĩ力ãƒĻãƒŧã‚ļãƒŧをčŋ”しãĻいるãĢもかかわらず: + +```Python hl_lines="24" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +...`response_model`を`UserOut`ã¨åŽŖč¨€ã—ãŸã“ã¨ã§ã€ãƒ‘ã‚šãƒ¯ãƒŧドがåĢぞれãĻいぞせん: + +```Python hl_lines="22" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +そぎため、**FastAPI** はå‡ē力ãƒĸデãƒĢã§åŽŖč¨€ã•ã‚ŒãĻいãĒい全ãĻぎデãƒŧã‚ŋã‚’ãƒ•ã‚ŖãƒĢã‚ŋãƒĒãƒŗã‚°ã—ãĻくれぞすīŧˆPydanticをäŊŋᔍīŧ‰ã€‚ + +## ドキãƒĨãƒĄãƒŗãƒˆã‚’čĻ‹ã‚‹ + +č‡Ē動ドキãƒĨãƒĄãƒŗãƒˆã‚’čĻ‹ã‚‹ã¨ã€å…Ĩ力ãƒĸデãƒĢとå‡ē力ãƒĸデãƒĢがそれぞれį‹Ŧč‡ĒぎJSON Schemaã‚’æŒãŖãĻいることがįĸēčĒã§ããžã™ã€‚ + + + +そしãĻã€ä¸Ąæ–šãŽãƒĸデãƒĢã¯ã€å¯žčŠąåž‹ãŽAPIドキãƒĨãƒĄãƒŗãƒˆãĢäŊŋį”¨ã•ã‚Œãžã™: + + + +## ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢãŽã‚¨ãƒŗã‚ŗãƒŧãƒ‡ã‚Ŗãƒŗã‚°ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ + +ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢãĢはデフりãƒĢãƒˆå€¤ã‚’č¨­åŽšã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="11 13 14" +{!../../../docs_src/response_model/tutorial004.py!} +``` + +* `description: str = None`は`None`がデフりãƒĢト値です。 +* `tax: float = 10.5`は`10.5`がデフりãƒĢト値です。 +* `tags: List[str] = []` はįŠēぎãƒĒ゚トīŧˆ`[]`īŧ‰ãŒãƒ‡ãƒ•りãƒĢト値です。 + +しかし、原際ãĢäŋå­˜ã•れãĻいãĒい場合ãĢはįĩæžœã‹ã‚‰ãã‚Œã‚‰ã‚’įœį•Ĩã—ãŸæ–šãŒč‰¯ã„ã‹ã‚‚ã—ã‚Œãžã›ã‚“ã€‚ + +䞋えば、NoSQLデãƒŧã‚ŋベãƒŧ゚ãĢ多くぎã‚Ēãƒ—ã‚ˇãƒ§ãƒŗåąžæ€§ã‚’æŒã¤ãƒĸデãƒĢがあるが、デフりãƒĢãƒˆå€¤ã§ã„ãŖãąã„ãŽéžå¸¸ãĢé•ˇã„JSONãƒŦã‚šãƒãƒŗã‚šã‚’é€äŋĄã—たくãĒい場合です。 + +### `response_model_exclude_unset`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎäŊŋᔍ + +*path operation ãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ*ãĢ`response_model_exclude_unset=True`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’č¨­åŽšã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="24" +{!../../../docs_src/response_model/tutorial004.py!} +``` + +そしãĻ、これらぎデフりãƒĢト値はãƒŦã‚šãƒãƒŗã‚šãĢåĢぞれず、原際ãĢč¨­åŽšã•ã‚ŒãŸå€¤ãŽãŋがåĢぞれぞす。 + +そぎため、*path operation*ãĢID`foo`ãŒč¨­åŽšã•ã‚ŒãŸitemぎãƒĒクエ゚トを送ると、ãƒŦã‚šãƒãƒŗã‚šã¯äģĨ下ぎようãĢãĒりぞすīŧˆãƒ‡ãƒ•りãƒĢト値をåĢぞãĒいīŧ‰: + +```JSON +{ + "name": "Foo", + "price": 50.2 +} +``` + +!!! info "æƒ…å ą" + FastAPIはこれをするためãĢ、PydanticãƒĸデãƒĢぎ`.dict()`をそぎ`exclude_unset`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋでäŊŋį”¨ã—ãĻいぞす。 + +!!! info "æƒ…å ą" + äģĨ下もäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + + * `response_model_exclude_defaults=True` + * `response_model_exclude_none=True` + + `exclude_defaults`と`exclude_none`ãĢついãĻは、PydanticぎドキãƒĨãƒĄãƒŗãƒˆã§čĒŦ明されãĻいる通りです。 + +#### デフりãƒĢãƒˆå€¤ã‚’æŒã¤ãƒ•ã‚ŖãƒŧãƒĢドぎ値を持つデãƒŧã‚ŋ + +しかし、ID`bar`ぎitemぎようãĢ、デフりãƒĢãƒˆå€¤ãŒč¨­åŽšã•ã‚ŒãĻいるãƒĸデãƒĢãŽãƒ•ã‚ŖãƒŧãƒĢドãĢå€¤ãŒč¨­åŽšã•ã‚ŒãĻいる場合: + +```Python hl_lines="3 5" +{ + "name": "Bar", + "description": "The bartenders", + "price": 62, + "tax": 20.2 +} +``` + +それらはãƒŦã‚šãƒãƒŗã‚šãĢåĢぞれぞす。 + +#### デフりãƒĢト値と同じ値を持つデãƒŧã‚ŋ + +ID`baz`ぎitemぎようãĢデフりãƒĢト値と同じ値を持つデãƒŧã‚ŋぎ場合: + +```Python hl_lines="3 5 6" +{ + "name": "Baz", + "description": None, + "price": 50.2, + "tax": 10.5, + "tags": [] +} +``` + +FastAPIは十分ãĢčŗĸいぎでīŧˆåŽŸéš›ãĢは、Pydanticが十分ãĢčŗĸいīŧ‰`description`や`tax`、`tags`はデフりãƒĢãƒˆå€¤ã¨åŒã˜å€¤ã‚’æŒãŖãĻいるãĢもかかわらず、明į¤ēįš„ãĢč¨­åŽšã•ã‚ŒãĻã„ã‚‹ã“ã¨ã‚’į†č§Ŗã—ãĻいぞす。īŧˆãƒ‡ãƒ•りãƒĢトから取垗するぎではãĒくīŧ‰ + +そぎため、それらはJSONãƒŦã‚šãƒãƒŗã‚šãĢåĢぞれることãĢãĒりぞす。 + +!!! tip "豆įŸĨ識" + デフりãƒĢト値は`None`だけでãĒく、ãĒã‚“ã§ã‚‚č‰¯ã„ã“ã¨ãĢæŗ¨æ„ã—ãĻください。 + 䞋えば、ãƒĒ゚トīŧˆ`[]`īŧ‰ã‚„`10.5`ぎ`float`ãĒおです。 + +### `response_model_include`と`response_model_exclude` + +*path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ*としãĻ`response_model_include`と`response_model_exclude`もäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +åąžæ€§åã‚’æŒã¤`str`ぎ`set`を受け取り、åĢめる(æŽ‹ã‚Šã‚’įœį•Ĩする)か、除外(掋りをåĢむ)しぞす。 + +これは、PydanticãƒĸデãƒĢがīŧ‘つしかãĒく、å‡ē力からいくつかぎデãƒŧã‚ŋã‚’å‰Šé™¤ã—ãŸã„å ´åˆãŽã‚¯ã‚¤ãƒƒã‚¯ã‚ˇãƒ§ãƒŧトã‚ĢットとしãĻäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +!!! tip "豆įŸĨ識" + ãã‚Œã§ã‚‚ã€ã“ã‚Œã‚‰ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋではãĒãã€č¤‡æ•°ãŽã‚¯ãƒŠã‚šã‚’äŊŋį”¨ã—ãĻã€ä¸Šč¨˜ãŽã‚ˆã†ãĒã‚ĸイデã‚ĸをäŊŋうことをおすすめしぞす。 + + これは`response_model_include`や`response_mode_exclude`をäŊŋį”¨ã—ãĻã„ãã¤ã‹ãŽåąžæ€§ã‚’įœį•ĨしãĻも、ã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗãŽOpenAPIīŧˆã¨ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆīŧ‰ã§į”Ÿæˆã•れたJSON Schemaが厌全ãĒãƒĸデãƒĢãĢãĒるからです。 + + 同様ãĢ動äŊœã™ã‚‹`response_model_by_alias`ãĢもåŊ“ãĻはぞりぞす。 + +```Python hl_lines="31 37" +{!../../../docs_src/response_model/tutorial005.py!} +``` + +!!! tip "豆įŸĨ識" + `{"name", "description"}`ぎ構文はこれらīŧ’つぎ値をもつ`set`をäŊœæˆã—ぞす。 + + これは`set(["name", "description"])`ã¨åŒį­‰ã§ã™ã€‚ + +#### `set`ぎäģŖã‚ã‚ŠãĢ`list`をäŊŋį”¨ã™ã‚‹ + +もし`set`をäŊŋį”¨ã™ã‚‹ã“ã¨ã‚’åŋ˜ã‚ŒãĻ、äģŖã‚ã‚ŠãĢ`list`や`tuple`をäŊŋį”¨ã—ãĻも、FastAPIはそれを`set`ãĢ変換しãĻæ­Ŗã—ãå‹•äŊœã—ぞす: + +```Python hl_lines="31 37" +{!../../../docs_src/response_model/tutorial006.py!} +``` + +## ぞとめ + +*path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋぎ*`response_model`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋをäŊŋį”¨ã—ãĻ、ãƒŦã‚šãƒãƒŗã‚šãƒĸデãƒĢã‚’åŽšįžŠã—ã€į‰šãĢプナイベãƒŧトデãƒŧã‚ŋãŒãƒ•ã‚ŖãƒĢã‚ŋãƒĒãƒŗã‚°ã•ã‚ŒãĻいることをäŋč¨ŧしぞす。 + +明į¤ēįš„ãĢč¨­åŽšã•ã‚ŒãŸå€¤ãŽãŋをčŋ”すãĢは、`response_model_exclude_unset`をäŊŋį”¨ã—ãžã™ã€‚ From 39bb4bbdfc654eab57ce2bc57286c3ea2ca39c7d Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 01:08:16 +0900 Subject: [PATCH 109/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/dependencies/index.md`=20an?= =?UTF-8?q?d=20`docs/ja/docs/tutorial/dependencies/classes-as-dependencies?= =?UTF-8?q?.md`=20(#1958)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- .../dependencies/classes-as-dependencies.md | 191 ++++++++++++++++ docs/ja/docs/tutorial/dependencies/index.md | 209 ++++++++++++++++++ 2 files changed, 400 insertions(+) create mode 100644 docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md create mode 100644 docs/ja/docs/tutorial/dependencies/index.md diff --git a/docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md b/docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md new file mode 100644 index 0000000000..5c150d00c5 --- /dev/null +++ b/docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md @@ -0,0 +1,191 @@ +# 䞝存é–ĸäŋ‚としãĻぎクナ゚ + +**äžå­˜æ€§æŗ¨å…Ĩ** ã‚ˇã‚šãƒ†ãƒ ã‚’æˇąãæŽ˜ã‚Šä¸‹ã’ã‚‹å‰ãĢ、先ãģおぎ䞋をã‚ĸップグãƒŦãƒŧドしãĻãŋぞしょう。 + +## 前ぎ䞋ぎ`dict` + +前ぎ䞋では、䞝存é–ĸäŋ‚īŧˆ"dependable"īŧ‰ã‹ã‚‰`dict`をčŋ”しãĻいぞした: + +```Python hl_lines="9" +{!../../../docs_src/dependencies/tutorial001.py!} +``` + +しかし、*path operationé–ĸ数*ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`commons`ãĢ`dict`がåĢぞれãĻいぞす。 + +ãžãŸã€ã‚¨ãƒ‡ã‚Ŗã‚ŋは`dict`ぎキãƒŧと値ぎ型をįŸĨることができãĒいため、多くぎã‚ĩポãƒŧトīŧˆčŖœåŽŒãŽã‚ˆã†ãĒīŧ‰ã‚’提䞛することができぞせん。 + +ã‚‚ãŖã¨ã†ãžãã‚„ã‚Œã‚‹ã¯ãšã§ã™...。 + +## 䞝存é–ĸäŋ‚ã‚’äŊœã‚‹ã‚‚ぎ + +これぞでは、䞝存é–ĸäŋ‚がé–ĸ数としãĻåŽŖč¨€ã•ã‚ŒãĻいるぎをčĻ‹ãĻきぞした。 + +しかし、䞝存é–ĸäŋ‚ã‚’åŽšįžŠã™ã‚‹æ–šæŗ•ã¯ãã‚Œã ã‘ã§ã¯ã‚ã‚Šãžã›ã‚“īŧˆããŽæ–šãŒä¸€čˆŦįš„ã‹ã‚‚ã—ã‚Œãžã›ã‚“ãŒīŧ‰ã€‚ + +重čρãĒぎは、䞝存é–ĸäŋ‚が「å‘ŧãŗå‡ēし可čƒŊ」ãĒもぎであることです。 + +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** ぎ䞝存é–ĸäŋ‚としãĻ「å‘ŧãŗå‡ēし可čƒŊãĒã‚‚ãŽã€ã‚’æ¸Ąã™ã¨ã€ããŽã€Œå‘ŧãŗå‡ēし可čƒŊãĒã‚‚ãŽã€ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’č§Ŗæžã—ã€ã‚ĩブ䞝存é–ĸäŋ‚ã‚‚åĢめãĻ、*path operationé–ĸ数*ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋと同じようãĢå‡Ļį†ã—ãžã™ã€‚ + +ãã‚Œã¯ã€ãƒ‘ãƒŠãƒĄãƒŧã‚ŋが全くãĒいå‘ŧãŗå‡ēし可čƒŊãĒもぎãĢã‚‚éŠį”¨ã•ã‚Œãžã™ã€‚ãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎãĒい*path operationé–ĸ数*と同じようãĢ。 + +ãã“ã§ã€ä¸Šã§į´šäģ‹ã—た䞝存é–ĸäŋ‚ぎ`common_parameters`を`CommonQueryParams`クナ゚ãĢ変更しぞす: + +```Python hl_lines="11 12 13 14 15" +{!../../../docs_src/dependencies/tutorial002.py!} +``` + +ã‚¯ãƒŠã‚šãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚’äŊœæˆã™ã‚‹ãŸã‚ãĢäŊŋį”¨ã•ã‚Œã‚‹`__init__`ãƒĄã‚ŊッドãĢæŗ¨į›Žã—ãĻください: + +```Python hl_lines="12" +{!../../../docs_src/dependencies/tutorial002.py!} +``` + +...äģĨ前ぎ`common_parameters`ã¨åŒã˜ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’æŒãŖãĻいぞす: + +```Python hl_lines="8" +{!../../../docs_src/dependencies/tutorial001.py!} +``` + +ã“ã‚Œã‚‰ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋは **FastAPI** が䞝存é–ĸäŋ‚ã‚’ã€Œč§Ŗæąē」するためãĢäŊŋį”¨ã™ã‚‹ã‚‚ãŽã§ã™ã€‚ + +ãŠãĄã‚‰ãŽå ´åˆã‚‚äģĨä¸‹ã‚’æŒãŖãĻいぞす: + +* ã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎ`q`クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ。 +* `skip`クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ、デフりãƒĢトは`0`。 +* `limit`クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ、デフりãƒĢトは`100`。 + +ãŠãĄã‚‰ãŽå ´åˆã‚‚ã€ãƒ‡ãƒŧã‚ŋは変換され、検č¨ŧされ、OpenAPI゚キãƒŧマãĒおで文書化されぞす。 + +## äŊŋᔍ + +これで、こぎクナ゚をäŊŋį”¨ã—ãĻ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +```Python hl_lines="19" +{!../../../docs_src/dependencies/tutorial002.py!} +``` + +**FastAPI** は`CommonQueryParams`クナ゚をå‘ŧãŗå‡ēしぞす。これãĢã‚ˆã‚Šã€ããŽã‚¯ãƒŠã‚šãŽã€Œã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã€ãŒäŊœæˆã•ã‚Œã€ã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã¯ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`commons`としãĻé–ĸ数ãĢæ¸Ąã•ã‚Œãžã™ã€‚ + +## åž‹æŗ¨é‡ˆã¨`Depends` + +ä¸ŠãŽã‚ŗãƒŧドでは`CommonQueryParams`をīŧ’回書いãĻいることãĢæŗ¨į›Žã—ãĻください: + +```Python +commons: CommonQueryParams = Depends(CommonQueryParams) +``` + +äģĨ下ãĢある最垌ぎ`CommonQueryParams`: + +```Python +... = Depends(CommonQueryParams) +``` + +...は、**FastAPI** が䞝存é–ĸäŋ‚ã‚’įŸĨるためãĢ原際ãĢäŊŋį”¨ã™ã‚‹ã‚‚ãŽã§ã™ã€‚ + +そこからFastAPIãŒåŽŖč¨€ã•ã‚ŒãŸãƒ‘ãƒŠãƒĄãƒŧã‚ŋをæŠŊå‡ēし、それが原際ãĢFastAPIがå‘ŧãŗå‡ēすもぎです。 + +--- + +こぎ場合、äģĨ下ãĢある最初ぎ`CommonQueryParams`: + +```Python +commons: CommonQueryParams ... +``` + +...は **FastAPI** ãĢ寞しãĻį‰šåˆĨãĒæ„å‘ŗã‚’ã‚‚ãĄãžã›ã‚“ã€‚FastAPIはデãƒŧã‚ŋ変換や検č¨ŧãĒおãĢはäŊŋį”¨ã—ãžã›ã‚“īŧˆãã‚Œã‚‰ãŽãŸã‚ãĢは`= Depends(CommonQueryParams)`をäŊŋį”¨ã—ãĻいぞすīŧ‰ã€‚ + +原際ãĢはäģĨ下ぎようãĢ書けばいいだけです: + +```Python +commons = Depends(CommonQueryParams) +``` + +äģĨ下ãĢあるようãĢ: + +```Python hl_lines="19" +{!../../../docs_src/dependencies/tutorial003.py!} +``` + +ã—ã‹ã—ã€åž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ã¯æŽ¨åĨ¨ã•れãĻã„ãžã™ã€‚ãã†ã™ã‚Œã°ã€ã‚¨ãƒ‡ã‚Ŗã‚ŋは`commons`ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋとしãĻäŊ•ãŒæ¸Ąã•ã‚Œã‚‹ã‹ã‚’įŸĨã‚‹ã“ã¨ãŒã§ãã€ã‚ŗãƒŧãƒ‰ãŽčŖœåŽŒã‚„åž‹ãƒã‚§ãƒƒã‚¯ãĒãŠã‚’čĄŒã†ãŽãĢåŊšįĢ‹ãĄãžã™: + + + +## ã‚ˇãƒ§ãƒŧトã‚Ģット + +しかし、ここでは`CommonQueryParams`をīŧ’å›žæ›¸ãã¨ã„ã†ã‚ŗãƒŧãƒ‰ãŽįš°ã‚Ščŋ”しがį™ēį”Ÿã—ãĻいることがわかりぞす: + +```Python +commons: CommonQueryParams = Depends(CommonQueryParams) +``` + +䞝存é–ĸäŋ‚が、クナ゚č‡ĒäŊ“ãŽã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚’äŊœæˆã™ã‚‹ãŸã‚ãĢ**FastAPI**が「å‘ŧãŗå‡ēす」*į‰šåŽšãŽ*クナ゚である場合、**FastAPI** ã¯ã“ã‚Œã‚‰ãŽã‚ąãƒŧã‚šãŽã‚ˇãƒ§ãƒŧトã‚Ģットを提䞛しãĻいぞす。 + +ãã‚Œã‚‰ãŽå…ˇäŊ“įš„ãĒã‚ąãƒŧ゚ãĢついãĻはäģĨ下ぎようãĢしぞす: + +äģĨ下ぎようãĢ書くäģŖã‚ã‚ŠãĢ: + +```Python +commons: CommonQueryParams = Depends(CommonQueryParams) +``` + +...äģĨ下ぎようãĢ書きぞす: + +```Python +commons: CommonQueryParams = Depends() +``` + +ãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎ型としãĻ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã—ã€`Depends()`ãŽä¸­ã§ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを指厚せず、`Depends()`をそぎé–ĸæ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋぎ「デフりãƒĢト」値īŧˆ`=`ぎあとぎ値īŧ‰ã¨ã—ãĻäŊŋį”¨ã™ã‚‹ã“ã¨ã§ã€`Depends(CommonQueryParams)`ぎ中でクナ゚全äŊ“ã‚’*もう一åēĻ*書かãĒくãĻもよくãĒりぞす。 + +同じ䞋ではäģĨ下ぎようãĢãĒりぞす: + +```Python hl_lines="19" +{!../../../docs_src/dependencies/tutorial004.py!} +``` + +...そしãĻ **FastAPI** はäŊ•をすずきかįŸĨãŖãĻいぞす。 + +!!! tip "豆įŸĨ識" + åŊšãĢįĢ‹ã¤ã¨ã„ã†ã‚ˆã‚Šã‚‚ã€æˇˇäšąã™ã‚‹ã‚ˆã†ã§ã‚ã‚Œã°į„ĄčĻ–ã—ãĻください。それをする*åŋ…čρ*はありぞせん。 + + それは単ãĒã‚‹ã‚ˇãƒ§ãƒŧトã‚Ģットです。ãĒぜãĒら **FastAPI** ã¯ã‚ŗãƒŧãƒ‰ãŽįš°ã‚Ščŋ”しを最小限ãĢ抑えることãĢ気をäŊŋãŖãĻいるからです。 diff --git a/docs/ja/docs/tutorial/dependencies/index.md b/docs/ja/docs/tutorial/dependencies/index.md new file mode 100644 index 0000000000..ec563a16d7 --- /dev/null +++ b/docs/ja/docs/tutorial/dependencies/index.md @@ -0,0 +1,209 @@ +# 䞝存é–ĸäŋ‚ - 最初ぎ゚テップ + +** FastAPI** は非常ãĢåŧˇåŠ›ã§ã‚ã‚ŠãĒãŒã‚‰į›´æ„Ÿįš„ãĒ **äžå­˜æ€§æŗ¨å…Ĩ** ã‚ˇã‚šãƒ†ãƒ ã‚’æŒãŖãĻいぞす。 + +それは非常ãĢã‚ˇãƒŗãƒ—ãƒĢãĢäŊŋį”¨ã§ãã‚‹ã‚ˆã†ãĢč¨­č¨ˆã•ã‚ŒãĻおり、開į™ēč€…ãŒäģ–ãŽã‚ŗãƒŗãƒãƒŧãƒãƒŗãƒˆ **FastAPI** とįĩąåˆã™ã‚‹ãŽãŒéžå¸¸ãĢį°Ąå˜ãĢãĒるようãĢč¨­č¨ˆã•ã‚ŒãĻいぞす。 + +## ã€Œäžå­˜æ€§æŗ¨å…Ĩ」とは + +**ã€Œäžå­˜æ€§æŗ¨å…Ĩ」** ã¨ã¯ã€ãƒ—ãƒ­ã‚°ãƒŠãƒŸãƒŗã‚°ãĢおいãĻã€ã‚ŗãƒŧドīŧˆã“ぎ場合は、*path operationé–ĸ数*īŧ‰ãŒå‹•äŊœã—たりäŊŋį”¨ã—ãŸã‚Šã™ã‚‹ãŸã‚ãĢåŋ…čρãĒもぎīŧˆã€Œäžå­˜é–ĸäŋ‚」īŧ‰ã‚’åŽŖč¨€ã™ã‚‹æ–šæŗ•ãŒã‚ã‚‹ã“ã¨ã‚’æ„å‘ŗã—ãžã™: + +そしãĻã€ããŽã‚ˇã‚šãƒ†ãƒ īŧˆã“ぎ場合は、**FastAPI**īŧ‰ã¯ã€åŋ…čρãĒ䞝存é–ĸäŋ‚ã‚’ã‚ŗãƒŧドãĢ提䞛するためãĢåŋ…čρãĒことはäŊ•ã§ã‚‚čĄŒã„ãžã™īŧˆäžå­˜é–ĸäŋ‚ã‚’ã€Œæŗ¨å…Ĩ」しぞすīŧ‰ã€‚ + +これはäģĨ下ぎようãĒことがåŋ…čρãĒ時ãĢとãĻもäžŋ刊です: + +* ãƒ­ã‚¸ãƒƒã‚¯ã‚’å…ąæœ‰ã—ãĻいる。īŧˆåŒã˜ã‚ŗãƒŧドロジックをäŊ•åēĻã‚‚įš°ã‚Ščŋ”しãĻいるīŧ‰ã€‚ +* デãƒŧã‚ŋベãƒŧ゚æŽĨįļšã‚’å…ąæœ‰ã™ã‚‹ã€‚ +* ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã€čĒč¨ŧ、ロãƒŧãƒĢčρäģļãĒおをåŧˇåˆļする。 +* そぎãģかãĢも多くぎこと... + +これらすずãĻã‚’ã€ã‚ŗãƒŧãƒ‰ãŽįš°ã‚Ščŋ”しを最小限ãĢ抑えãĒãŒã‚‰čĄŒã„ãžã™ã€‚ + +## 最初ぎ゚テップ + +非常ãĢã‚ˇãƒŗãƒ—ãƒĢãĒ䞋をčĻ‹ãĻãŋぞしょう。あぞりãĢã‚‚ã‚ˇãƒŗãƒ—ãƒĢãĒぎで、äģŠãŽã¨ã“ã‚ã¯ã‚ãžã‚Šå‚č€ƒãĢãĒらãĒいでしょう。 + +ã—ã‹ã—ã€ã“ãŽæ–šæŗ•ã§ã¯ **äžå­˜æ€§æŗ¨å…Ĩ** ã‚ˇã‚šãƒ†ãƒ ãŒãŠãŽã‚ˆã†ãĢ抟čƒŊするかãĢį„Ļį‚šã‚’åŊ“ãĻることができぞす。 + +### 䞝存é–ĸäŋ‚ぎäŊœæˆ + +ぞずは䞝存é–ĸäŋ‚ãĢæŗ¨į›Žã—ãĻãŋぞしょう。 + +äģĨ下ぎようãĢ、*path operationé–ĸ数*ã¨åŒã˜ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを全ãĻ取ることができるé–ĸ数ãĢすぎぞせん: + +```Python hl_lines="8 9" +{!../../../docs_src/dependencies/tutorial001.py!} +``` + +これだけです。 + +**īŧ’čĄŒ**。 + +そしãĻ、それはすずãĻぎ*path operationé–ĸ数*ãŒæŒãŖãĻいるぎと同じåŊĸã¨æ§‹é€ ã‚’æŒãŖãĻいぞす。 + +ã€Œãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ」をåĢぞãĒいīŧˆ`@app.get("/some-path")`をåĢぞãĒいīŧ‰*path operationé–ĸ数*ã¨č€ƒãˆã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +そしãĻäŊ•でもčŋ”すことができぞす。 + +こぎ場合、こぎ䞝存é–ĸäŋ‚はäģĨ下を期垅しãĻいぞす: + +* ã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`は`str`です。 +* ã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`skip`は`int`で、デフりãƒĢトは`0`です。 +* ã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`limit`は`int`で、デフりãƒĢトは`100`です。 + +そしãĻ、これらぎ値をåĢむ`dict`をčŋ”しぞす。 + +### `Depends`ãŽã‚¤ãƒŗãƒãƒŧト + +```Python hl_lines="3" +{!../../../docs_src/dependencies/tutorial001.py!} +``` + +### "dependant"でぎ䞝存é–ĸäŋ‚ぎåު荀 + +*path operationé–ĸ数*ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ`Body`や`Query`ãĒおをäŊŋį”¨ã™ã‚‹ãŽã¨åŒã˜ã‚ˆã†ãĢã€æ–°ã—ã„ãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ`Depends`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="13 18" +{!../../../docs_src/dependencies/tutorial001.py!} +``` + +é–ĸæ•°ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ`Depends`をäŊŋį”¨ã™ã‚‹ãŽã¯`Body`や`Query`ãĒおと同じですが、`Depends`ぎ動äŊœã¯å°‘ã—į•°ãĒりぞす。 + +`Depends`はīŧ‘ã¤ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋしか与えられぞせん。 + +ã“ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋはé–ĸ数ぎようãĒもぎであるåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +そしãĻ、そぎé–ĸ数は、*path operationé–ĸ数*ãŒčĄŒã†ãŽã¨åŒã˜æ–šæŗ•ã§ãƒ‘ãƒŠãƒĄãƒŧã‚ŋを取りぞす。 + +!!! tip "豆įŸĨ識" + æŦĄãŽįĢ ã§ã¯ã€é–ĸ数äģĨ外ぎ「もぎ」が䞝存é–ĸäŋ‚としãĻäŊŋį”¨ã§ãã‚‹ã‚‚ãŽã‚’čĻ‹ãĻいきぞす。 + +新しいãƒĒã‚¯ã‚¨ã‚šãƒˆãŒåˆ°į€ã™ã‚‹ãŸãŗãĢ、**FastAPI** がäģĨ下ぎようãĒå‡Ļį†ã‚’čĄŒã„ãžã™: + +* 䞝存é–ĸäŋ‚īŧˆ"dependable"īŧ‰é–ĸæ•°ã‚’æ­Ŗã—ã„ãƒ‘ãƒŠãƒĄãƒŧã‚ŋでå‘ŧãŗå‡ēしぞす。 +* é–ĸ数ぎįĩæžœã‚’取垗しぞす。 +* *path operationé–ĸ数*ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢそぎįĩæžœã‚’äģŖå…ĨしãĻください。 + +```mermaid +graph TB + +common_parameters(["common_parameters"]) +read_items["/items/"] +read_users["/users/"] + +common_parameters --> read_items +common_parameters --> read_users +``` + +ã“ãŽæ–šæŗ•ã§ã¯ã€å…ąæœ‰ã•ã‚Œã‚‹ã‚ŗãƒŧドを一åēĻæ›¸ãã€**FastAPI** が*path operations*ぎためぎå‘ŧãŗå‡ēã—ã‚’čĄŒã„ãžã™ã€‚ + +!!! check "įĸēčĒ" + į‰šåˆĨãĒクナ゚をäŊœæˆã—ãĻおこかで **FastAPI** ãĢæ¸Ąã—ãĻ「į™ģéŒ˛ã€ã™ã‚‹åŋ…čĻã¯ãĒいことãĢæŗ¨æ„ã—ãĻください。 + + `Depends`ã‚’æ¸Ąã™ã ã‘ã§ã€**FastAPI** が掋りぎå‡Ļį†ã‚’ã—ãĻくれぞす。 + +## `async`ãĢするかおうか + +䞝存é–ĸäŋ‚は **FastAPI**īŧˆ*path operationé–ĸ数*と同じīŧ‰ã‹ã‚‰ã‚‚å‘ŧãŗå‡ēされるため、é–ĸæ•°ã‚’åŽšįžŠã™ã‚‹éš›ãĢも同じãƒĢãƒŧãƒĢãŒéŠį”¨ã•ã‚Œãžã™ã€‚ + +`async def`や通常ぎ`def`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +ぞた、通常ぎ`def`*path operationé–ĸ数*ぎ中ãĢ`async def`をå…ĨれãĻ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã—ãŸã‚Šã€`async def`*path operationé–ĸ数*ぎ中ãĢ`def`をå…ĨれãĻ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã—ãŸã‚Šã™ã‚‹ã“ã¨ãĒおができぞす。 + +それは重čĻã§ã¯ã‚ã‚Šãžã›ã‚“ã€‚**FastAPI** はäŊ•をすずきかをįŸĨãŖãĻいぞす。 + +!!! note "å‚™č€ƒ" + わからãĒい場合は、ドキãƒĨãƒĄãƒŗãƒˆãŽ[Async: *"In a hurry?"*](../../async.md){.internal-link target=_blank}ぎ中ぎ`async`と`await`ãĢついãĻぎã‚ģã‚¯ã‚ˇãƒ§ãƒŗã‚’įĸēčĒã—ãĻください。 + +## OpenAPIとぎįĩąåˆ + +䞝存é–ĸäŋ‚īŧˆãŠã‚ˆãŗã‚ĩブ䞝存é–ĸäŋ‚īŧ‰ãŽã™ãšãĻぎãƒĒã‚¯ã‚¨ã‚šãƒˆåŽŖč¨€ã€æ¤œč¨ŧã€ãŠã‚ˆãŗčρäģļは、同じOpenAPI゚キãƒŧマãĢįĩąåˆã•れぞす。 + +ã¤ãžã‚Šã€å¯žčŠąåž‹ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆãĢはこれらぎ䞝存é–ĸäŋ‚から垗られる全ãĻãŽæƒ…å ąã‚‚åĢぞれãĻいるということです: + + + +## į°Ąå˜ãĒäŊŋい斚 + +čĻ‹ãĻãŋると、*path*と*operation*ãŒä¸€č‡´ã—ãŸæ™‚ãĢ*path operationé–ĸ数*ãŒåŽŖč¨€ã•ã‚ŒãĻいãĻ、**FastAPI** ãŒæ­Ŗã—ã„ãƒ‘ãƒŠãƒĄãƒŧã‚ŋでé–ĸ数をå‘ŧãŗå‡ēしãĻãƒĒクエ゚トからデãƒŧã‚ŋをæŠŊå‡ēするå‡Ļį†ã‚’ã—ãĻいぞす。 + +原は、すずãĻぎīŧˆã‚るいはãģとんおぎīŧ‰WebフãƒŦãƒŧムワãƒŧクは、こぎようãĢ動äŊœã—ぞす。 + +これらぎé–ĸæ•°ã‚’į›´æŽĨå‘ŧãŗå‡ēすことはありぞせん。これらぎé–ĸ数はフãƒŦãƒŧムワãƒŧクīŧˆã“ぎ場合は、**FastAPI**īŧ‰ãĢã‚ˆãŖãĻå‘ŧãŗå‡ēされぞす。 + +äžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ã§ã¯ã€**FastAPI** ãĢ*path operation*もぞた、*path operationé–ĸ数*ぎ前ãĢåŽŸčĄŒã•ã‚Œã‚‹ãšãäģ–ぎäŊ•かãĢ「䞝存」しãĻいることをäŧãˆã‚‹ã“とができ、**FastAPI** ãŒãã‚Œã‚’åŽŸčĄŒã—ã€įĩæžœã‚’ã€Œæŗ¨å…Ĩ」することをåŧ•き受けぞす。 + +äģ–ãĢã‚‚ã€ã€Œäžå­˜æ€§æŗ¨å…Ĩ」と同じようãĒč€ƒãˆãŽä¸€čˆŦįš„ãĒᔍčĒžãŒã‚ã‚Šãžã™: + +* ãƒĒã‚Ŋãƒŧ゚ +* プロバイダ +* ã‚ĩãƒŧビ゚ +* ã‚¤ãƒŗã‚¸ã‚§ã‚¯ã‚ŋブãƒĢ +* ã‚ŗãƒŗãƒãƒŧãƒãƒŗãƒˆ + +## **FastAPI** ãƒ—ãƒŠã‚°ã‚¤ãƒŗ + +įĩąåˆã‚„ã€Œãƒ—ãƒŠã‚°ã‚¤ãƒŗã€ã¯ **äžå­˜æ€§æŗ¨å…Ĩ** ã‚ˇã‚šãƒ†ãƒ ã‚’äŊŋãŖãĻæ§‹į¯‰ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ã—ã‹ã—ã€åŽŸéš›ãĢは、**ã€Œãƒ—ãƒŠã‚°ã‚¤ãƒŗã€ã‚’äŊœæˆã™ã‚‹åŋ…čĻã¯ã‚ã‚Šãžã›ã‚“**。䞝存é–ĸäŋ‚ã‚’äŊŋį”¨ã™ã‚‹ã“ã¨ã§ã€į„Ąé™ãŽæ•°ãŽįĩąåˆã‚„ã‚¤ãƒŗã‚ŋãƒŠã‚¯ã‚ˇãƒ§ãƒŗã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ãã€ãã‚ŒãŒ**path operationé–ĸ数*ã§åˆŠį”¨å¯čƒŊãĢãĒるからです。 + +䞝存é–ĸäŋ‚は非常ãĢã‚ˇãƒŗãƒ—ãƒĢã§į›´æ„Ÿįš„ãĒæ–šæŗ•ã§äŊœæˆã™ã‚‹ã“とができ、åŋ…čρãĒPythonãƒ‘ãƒƒã‚ąãƒŧã‚¸ã‚’ã‚¤ãƒŗãƒãƒŧトするだけで、*文字通り*æ•°čĄŒãŽã‚ŗãƒŧドでAPIé–ĸ数とįĩąåˆã™ã‚‹ã“とができぞす。 + +æŦĄãŽįĢ ã§ã¯ã€ãƒĒãƒŦãƒŧã‚ˇãƒ§ãƒŠãƒĢデãƒŧã‚ŋベãƒŧ゚やNoSQLデãƒŧã‚ŋベãƒŧ゚、ã‚ģキãƒĨãƒĒãƒ†ã‚ŖãĒおãĢついãĻ、そぎ䞋をčĻ‹ãĻいきぞす。 + +## **FastAPI** äē’æ›æ€§ + +äžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ãŒã‚ˇãƒŗãƒ—ãƒĢãĒぎで、**FastAPI** はäģĨ下ぎようãĒもぎとäē’æ›æ€§ãŒã‚りぞす: + +* すずãĻぎãƒĒãƒŦãƒŧã‚ˇãƒ§ãƒŠãƒĢデãƒŧã‚ŋベãƒŧ゚ +* NoSQLデãƒŧã‚ŋベãƒŧ゚ +* å¤–éƒ¨ãƒ‘ãƒƒã‚ąãƒŧジ +* 外部API +* čĒč¨ŧãƒģčĒå¯ã‚ˇã‚šãƒ†ãƒ  +* APIåˆŠį”¨įŠļæŗį›ŖčĻ–ã‚ˇã‚šãƒ†ãƒ  +* ãƒŦã‚šãƒãƒŗã‚šãƒ‡ãƒŧã‚ŋæŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ  +* ãĒお。 + +## ã‚ˇãƒŗãƒ—ãƒĢでパワフãƒĢ + +éšŽåą¤äžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ã¯ã€åŽšįžŠã‚„äŊŋį”¨æ–šæŗ•ãŒéžå¸¸ãĢã‚ˇãƒŗãƒ—ãƒĢであるãĢもかかわらず、非常ãĢåŧˇåŠ›ãĒもぎとãĒãŖãĻいぞす。 + +䞝存é–ĸäŋ‚ä狿…‹ã‚’åŽšįžŠã™ã‚‹äžå­˜é–ĸäŋ‚ã‚’åŽšįžŠã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +最įĩ‚įš„ãĢは、䞝存é–ĸäŋ‚ãŽéšŽåą¤ãƒ„ãƒĒãƒŧãŒæ§‹į¯‰ã•ã‚Œã€**äžå­˜æ€§æŗ¨å…Ĩ**ã‚ˇã‚šãƒ†ãƒ ãŒã€ã“ã‚Œã‚‰ãŽäžå­˜é–ĸäŋ‚īŧˆãŠã‚ˆãŗããŽã‚ĩブ䞝存é–ĸäŋ‚īŧ‰ã‚’すずãĻč§Ŗæąēし、各゚テップでįĩæžœã‚’提䞛īŧˆæŗ¨å…Ĩīŧ‰ã—ぞす。 + +䞋えば、īŧ”つぎAPIã‚¨ãƒŗãƒ‰ãƒã‚¤ãƒŗãƒˆīŧˆ*path operations*īŧ‰ãŒã‚るとしぞす: + +* `/items/public/` +* `/items/private/` +* `/users/{user_id}/activate` +* `/items/pro/` + +そしãĻ、䞝存é–ĸäŋ‚とã‚ĩブ䞝存é–ĸäŋ‚だけで、それぞれãĢį•°ãĒるパãƒŧãƒŸãƒƒã‚ˇãƒ§ãƒŗčρäģļをčŋŊ加することができぞす: + +```mermaid +graph TB + +current_user(["current_user"]) +active_user(["active_user"]) +admin_user(["admin_user"]) +paying_user(["paying_user"]) + +public["/items/public/"] +private["/items/private/"] +activate_user["/users/{user_id}/activate"] +pro_items["/items/pro/"] + +current_user --> active_user +active_user --> admin_user +active_user --> paying_user + +current_user --> public +active_user --> private +admin_user --> activate_user +paying_user --> pro_items +``` + +## **OpenAPI** とぎįĩąåˆ + +これら全ãĻぎ䞝存é–ĸäŋ‚は、čρäģļã‚’åŽŖč¨€ã™ã‚‹ã¨åŒæ™‚ãĢ、*path operations*ãĢãƒ‘ãƒŠãƒĄãƒŧã‚ŋやバãƒĒデãƒŧã‚ˇãƒ§ãƒŗã‚’čŋŊ加しぞす。 + +**FastAPI** はそれをすずãĻOpenAPI゚キãƒŧマãĢčŋŊ加しãĻã€å¯žčŠąåž‹ãŽãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‚ˇã‚šãƒ†ãƒ ãĢ襨į¤ēされるようãĢしぞす。 From 8ad62bd837c0d098c6d55c35f414710946c18628 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:10:30 +0000 Subject: [PATCH 110/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 33cd064e94..a23d367e97 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-model.md`. PR [#1938](https://github.com/tiangolo/fastapi/pull/1938) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-multiple-params.md`. PR [#1903](https://github.com/tiangolo/fastapi/pull/1903) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/path-params-numeric-validations.md`. PR [#1902](https://github.com/tiangolo/fastapi/pull/1902) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/python-types.md`. PR [#1899](https://github.com/tiangolo/fastapi/pull/1899) by [@SwftAlpc](https://github.com/SwftAlpc). From 289fbc83badcd60c9a91a2a7c1fc0e43f951d497 Mon Sep 17 00:00:00 2001 From: tokusumi <41147016+tokusumi@users.noreply.github.com> Date: Tue, 16 Jan 2024 01:12:39 +0900 Subject: [PATCH 111/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/background-tasks.md`=20(#26?= =?UTF-8?q?68)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/ja/docs/tutorial/background-tasks.md | 94 +++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 docs/ja/docs/tutorial/background-tasks.md diff --git a/docs/ja/docs/tutorial/background-tasks.md b/docs/ja/docs/tutorial/background-tasks.md new file mode 100644 index 0000000000..6094c370fd --- /dev/null +++ b/docs/ja/docs/tutorial/background-tasks.md @@ -0,0 +1,94 @@ +# バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚ク + +ãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”した *垌ãĢ* åŽŸčĄŒã•ã‚Œã‚‹ãƒãƒƒã‚¯ã‚°ãƒŠã‚Ļãƒŗãƒ‰ã‚ŋã‚šã‚¯ã‚’åŽšįžŠã§ããžã™ã€‚ + +これは、ãƒĒクエ゚ト垌ãĢå‡Ļį†ã‚’é–‹å§‹ã™ã‚‹åŋ…čĻãŒã‚ã‚‹ãŒã€ã‚¯ãƒŠã‚¤ã‚ĸãƒŗãƒˆãŒãƒŦã‚šãƒãƒŗã‚šã‚’å—ã‘å–ã‚‹å‰ãĢå‡Ļį†ã‚’įĩ‚えるåŋ…čĻãŽãĒい操äŊœãĢåŊšįĢ‹ãĄãžã™ã€‚ + +これãĢは、たとえばæŦĄãŽã‚‚ぎがåĢぞれぞす。 + +* äŊœæĨ­åŽŸčĄŒåžŒãŽãƒĄãƒŧãƒĢ通įŸĨ: + * ãƒĄãƒŧãƒĢã‚ĩãƒŧバãƒŧへぎæŽĨįļšã¨ãƒĄãƒŧãƒĢぎ送äŋĄã¯ã€Œé…い」(æ•°į§’) 傞向があるため、すぐãĢãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”し、バックグナã‚Ļãƒŗãƒ‰ã§ãƒĄãƒŧãƒĢ通įŸĨができぞす。 +* デãƒŧã‚ŋå‡Ļᐆ: + * たとえば、時間ぎかかるå‡Ļį†ã‚’åŋ…čĻã¨ã™ã‚‹ãƒ•ã‚Ąã‚¤ãƒĢ受äŋĄæ™‚ãĢは、「受äŋĄæ¸ˆãŋ」(HTTP 202) ぎãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”し、バックグナã‚Ļãƒŗãƒ‰ã§å‡Ļį†ã§ããžã™ã€‚ + +## `BackgroundTasks` ぎäŊŋᔍ + +ぞず初めãĢ、`BackgroundTasks` ã‚’ã‚¤ãƒŗãƒãƒŧトし、` BackgroundTasks` ãŽåž‹åŽŖč¨€ã¨å…ąãĢ、*path operation é–ĸ数* ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãƒŧã‚’åŽšįžŠã—ãžã™: + +```Python hl_lines="1 13" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +**FastAPI** は、`BackgroundTasks` 型ぎã‚ĒブジェクトをäŊœæˆã—ã€ããŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãƒŧãĢæ¸Ąã—ãžã™ã€‚ + +## ã‚ŋ゚クé–ĸ数ぎäŊœæˆ + +バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クとしãĻåŽŸčĄŒã•ã‚Œã‚‹é–ĸ数をäŊœæˆã—ぞす。 + +ã“ã‚Œã¯ã€ãƒ‘ãƒŠãƒĄãƒŧã‚ŋãƒŧを受け取ることができる単ãĒる標æē–įš„ãĒé–ĸ数です。 + +これは `async def` ぞたは通常ぎ `def` é–ĸ数であり、**FastAPI** ã¯ã“ã‚Œã‚’æ­Ŗã—ãå‡Ļį†ã—ãžã™ã€‚ + +ここで、ã‚ŋ゚クé–ĸæ•°ã¯ãƒ•ã‚Ąã‚¤ãƒĢ書きčžŧãŋã‚’åŽŸčĄŒã—ãžã™ (ãƒĄãƒŧãƒĢ送äŋĄãŽã‚ˇãƒŸãƒĨãƒŦãƒŧã‚ˇãƒ§ãƒŗ)。 + +ぞた、書きčžŧãŋ操äŊœã§ã¯ `async` と `await` をäŊŋį”¨ã—ãĒいため、通常ぎ `def` でé–ĸæ•°ã‚’åŽšįžŠã—ãžã™ã€‚ + +```Python hl_lines="6-9" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +## バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クぎčŋŊ加 + +*path operations é–ĸ数* 内で、`.add_task()` ãƒĄã‚ŊッドをäŊŋį”¨ã—ãĻã‚ŋ゚クé–ĸ数を *background tasks* ã‚ĒブジェクトãĢæ¸Ąã—ãžã™ã€‚ + +```Python hl_lines="14" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +`.add_task()` はäģĨ下ぎåŧ•数を受け取りぞす: + +* バックグナã‚Ļãƒŗãƒ‰ã§åŽŸčĄŒã•ã‚Œã‚‹ã‚ŋ゚クé–ĸ数 (`write_notification`)。 +* ã‚ŋ゚クé–ĸ数ãĢ順į•ĒãĢæ¸Ąã™åŋ…čĻãŽã‚ã‚‹åŧ•数ぎ列 (`email`)。 +* ã‚ŋ゚クé–ĸ数ãĢæ¸Ąã™åŋ…čĻãŽã‚ã‚‹ã‚­ãƒŧワãƒŧドåŧ•æ•° (`message="some notification"`)。 + +## äžå­˜æ€§æŗ¨å…Ĩ + +`BackgroundTasks` ぎäŊŋį”¨ã¯äžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ã§ã‚‚æŠŸčƒŊし、様々ãĒéšŽåą¤ (*path operations é–ĸ数*、䞝存性 (䞝存可čƒŊ性)、ã‚ĩブ䞝存性ãĒお) で `BackgroundTasks` åž‹ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãƒŧã‚’åŽŖč¨€ã§ããžã™ã€‚ + +**FastAPI** は、それぞれぎ場合ぎå‡Ļį†â€‹â€‹æ–šæŗ•ã¨åŒã˜ã‚Ēãƒ–ã‚¸ã‚§ã‚¯ãƒˆãŽå†åˆŠį”¨æ–šæŗ•ã‚’įŸĨãŖãĻいるため、すずãĻぎバックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クがマãƒŧジされ、バックグナã‚Ļãƒŗãƒ‰ã§åžŒã§åŽŸčĄŒã•ã‚Œãžã™ã€‚ + +```Python hl_lines="13 15 22 25" +{!../../../docs_src/background_tasks/tutorial002.py!} +``` + +こぎ䞋では、ãƒŦã‚šãƒãƒŗã‚šãŒé€äŋĄã•れた *垌* ãĢãƒĄãƒƒã‚ģãƒŧジが `log.txt` ãƒ•ã‚Ąã‚¤ãƒĢãĢ書きčžŧぞれぞす。 + +ãƒĒクエ゚トãĢクエãƒĒãŒã‚ãŖãŸå ´åˆã€ãƒãƒƒã‚¯ã‚°ãƒŠã‚Ļãƒŗãƒ‰ã‚ŋ゚クでログãĢ書きčžŧぞれぞす。 + +そしãĻ、*path operations é–ĸ数* ã§į”Ÿæˆã•ã‚ŒãŸåˆĨぎバックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クは、`email` ãƒ‘ã‚šãƒ‘ãƒŠãƒĄãƒŧã‚ŋをäŊŋį”¨ã—ãĻãƒĄãƒƒã‚ģãƒŧジを書きčžŧãŋぞす。 + +## æŠ€čĄ“įš„ãĒčŠŗį´° + +`BackgroundTasks` クナ゚は、`starlette.background`ã‹ã‚‰į›´æŽĨ取垗されぞす。 + +これは、FastAPI ãĢį›´æŽĨã‚¤ãƒŗãƒãƒŧト/ã‚¤ãƒŗã‚¯ãƒĢãƒŧドされるため、`fastapi` ã‹ã‚‰ã‚¤ãƒŗãƒãƒŧトできる上ãĢ、`starlette.background`からåˆĨぎ `BackgroundTask` (æœĢå°žãĢ `s` がãĒい) をčĒ¤ãŖãĻã‚¤ãƒŗãƒãƒŧトすることを回éŋできぞす。 + +`BackgroundTasks`ぎãŋをäŊŋį”¨ã™ã‚‹ã“ã¨ã§ (`BackgroundTask` ではãĒく)、`Request` ã‚Ēãƒ–ã‚¸ã‚§ã‚¯ãƒˆã‚’į›´æŽĨäŊŋį”¨ã™ã‚‹å ´åˆã¨åŒæ§˜ãĢ、それを *path operations é–ĸ数* ãƒ‘ãƒŠãƒĄãƒŧã‚ŋãƒŧとしãĻäŊŋį”¨ã—ã€**FastAPI** ãĢ掋りぎå‡Ļį†ã‚’äģģせることができぞす。 + +それでも、FastAPI で `BackgroundTask` を単į‹ŦでäŊŋį”¨ã™ã‚‹ã“ã¨ã¯å¯čƒŊã§ã™ãŒã€ã‚ŗãƒŧド内でã‚ĒブジェクトをäŊœæˆã—、それをåĢむStarlette `Response` をčŋ”すåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +čŠŗį´°ãĢついãĻは、バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クãĢé–ĸする Starlette ぎå…Ŧåŧãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‚’å‚į…§ã—ãĻ下さい。 + +## č­Ļ告 + +大量ぎバックグナã‚Ļãƒŗãƒ‰č¨ˆįŽ—ãŒåŋ…čĻã§ã‚ã‚Šã€åŋ…ずしも同じプロã‚ģã‚šã§åŽŸčĄŒã™ã‚‹åŋ…čĻãŒãĒい場合 (ãŸã¨ãˆã°ã€ãƒĄãƒĸãƒĒや変数ãĒãŠã‚’å…ąæœ‰ã™ã‚‹åŋ…čĻãŒãĒい場合)、Celery ぎようãĒより大きãĒäģ–ぎツãƒŧãƒĢをäŊŋį”¨ã™ã‚‹ã¨ãƒĄãƒĒットがあるかもしれぞせん。 + +ã“ã‚Œã‚‰ã¯ã€ã‚ˆã‚Šč¤‡é›‘ãĒ構成、RabbitMQ や Redis ãĒãŠãŽãƒĄãƒƒã‚ģãƒŧジ/ジョブキãƒĨãƒŧマネãƒŧã‚¸ãƒŖãƒŧをåŋ…čĻã¨ã™ã‚‹å‚žå‘ãŒã‚ã‚Šãžã™ãŒã€č¤‡æ•°ãŽãƒ—ãƒ­ã‚ģã‚šã€į‰šãĢč¤‡æ•°ãŽã‚ĩãƒŧバãƒŧでバックグナã‚Ļãƒŗãƒ‰ã‚ŋã‚šã‚¯ã‚’åŽŸčĄŒã§ããžã™ã€‚ + +䞋をįĸēčĒã™ã‚‹ãĢは、[Project Generators](../project-generation.md){.internal-link target=_blank} ã‚’å‚į…§ã—ãĻください。これらãĢはすずãĻ、Celery ãŒæ§‹į¯‰æ¸ˆãŋです。 + +ただし、同じ **FastAPI** ã‚ĸプãƒĒから変数とã‚ĒブジェクトãĢã‚ĸクã‚ģ゚するåŋ…čĻãŒã‚ã‚‹å ´åˆã€ãžãŸã¯å°ã•ãĒバックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚ク (é›ģå­ãƒĄãƒŧãƒĢ通įŸĨぎ送äŋĄãĒお) ã‚’åŽŸčĄŒã™ã‚‹åŋ…čĻãŒã‚ã‚‹å ´åˆã¯ã€å˜ãĢ `BackgroundTasks` をäŊŋį”¨ã§ããžã™ã€‚ + +## ぞとめ + +`BackgroundTasks` ã‚’ã‚¤ãƒŗãƒãƒŧトしãĻ、*path operations é–ĸ数* や䞝存é–ĸäŋ‚ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢ `BackgroundTasks`をäŊŋį”¨ã—ã€ãƒãƒƒã‚¯ã‚°ãƒŠã‚Ļãƒŗãƒ‰ã‚ŋ゚クをčŋŊ加しãĻ下さい。 From 94404fc1a087fdc6f645b56af596abbf12269bd1 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:16:10 +0000 Subject: [PATCH 112/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a23d367e97..e8fd93cac0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/index.md` and `docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md`. PR [#1958](https://github.com/tiangolo/fastapi/pull/1958) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-model.md`. PR [#1938](https://github.com/tiangolo/fastapi/pull/1938) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-multiple-params.md`. PR [#1903](https://github.com/tiangolo/fastapi/pull/1903) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/path-params-numeric-validations.md`. PR [#1902](https://github.com/tiangolo/fastapi/pull/1902) by [@SwftAlpc](https://github.com/SwftAlpc). From 6f3a134f6d5798ce9da6e74f4669056cc92f77d3 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:18:40 +0000 Subject: [PATCH 113/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index e8fd93cac0..ba357b1275 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/background-tasks.md`. PR [#2668](https://github.com/tiangolo/fastapi/pull/2668) by [@tokusumi](https://github.com/tokusumi). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/index.md` and `docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md`. PR [#1958](https://github.com/tiangolo/fastapi/pull/1958) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-model.md`. PR [#1938](https://github.com/tiangolo/fastapi/pull/1938) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/body-multiple-params.md`. PR [#1903](https://github.com/tiangolo/fastapi/pull/1903) by [@SwftAlpc](https://github.com/SwftAlpc). From c68836ae46e7d78646bb4ba26d9822d21815782b Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 01:43:41 +0900 Subject: [PATCH 114/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/dependencies/sub-dependenci?= =?UTF-8?q?es.md`=20(#1959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- .../tutorial/dependencies/sub-dependencies.md | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 docs/ja/docs/tutorial/dependencies/sub-dependencies.md diff --git a/docs/ja/docs/tutorial/dependencies/sub-dependencies.md b/docs/ja/docs/tutorial/dependencies/sub-dependencies.md new file mode 100644 index 0000000000..8848ac79ea --- /dev/null +++ b/docs/ja/docs/tutorial/dependencies/sub-dependencies.md @@ -0,0 +1,86 @@ +# ã‚ĩブ䞝存é–ĸäŋ‚ + +**ã‚ĩブ䞝存é–ĸäŋ‚** を持つ䞝存é–ĸäŋ‚ã‚’äŊœæˆã™ã‚‹ã“とができぞす。 + +それらはåŋ…čρãĒだけ **æˇąã** することができぞす。 + +**FastAPI** ã¯ãã‚Œã‚‰ã‚’č§ŖæąēしãĻくれぞす。 + +### 最初ぎ䞝存é–ĸäŋ‚「䞝存可čƒŊãĒもぎ」 + +äģĨ下ぎようãĒ最初ぎ䞝存é–ĸäŋ‚īŧˆã€Œäžå­˜å¯čƒŊãĒもぎ」īŧ‰ã‚’äŊœæˆã™ã‚‹ã“とができぞす: + +```Python hl_lines="8 9" +{!../../../docs_src/dependencies/tutorial005.py!} +``` + +これはã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎクエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`を`str`としãĻåŽŖč¨€ã—ã€ãã‚Œã‚’čŋ”すだけです。 + +これは非常ãĢã‚ˇãƒŗãƒ—ãƒĢですīŧˆã‚ぞりäžŋ刊ではありぞせんīŧ‰ãŒã€ã‚ĩブ䞝存é–ĸäŋ‚がおぎようãĢ抟čƒŊするかãĢį„Ļį‚šã‚’åŊ“ãĻるぎãĢåŊšįĢ‹ãĄãžã™ã€‚ + +### įŦŦäēŒãŽäžå­˜é–ĸäŋ‚ 「䞝存可čƒŊãĒもぎ」と「䞝存」 + +そしãĻ、åˆĨぎ䞝存é–ĸ数īŧˆã€Œäžå­˜å¯čƒŊãĒもぎ」īŧ‰ã‚’äŊœæˆã—ãĻ、同時ãĢそれč‡ĒčēĢぎ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™īŧˆã¤ãžã‚Šãã‚Œč‡ĒčēĢも「䞝存」ですīŧ‰: + +```Python hl_lines="13" +{!../../../docs_src/dependencies/tutorial005.py!} +``` + +åŽŖč¨€ã•ã‚ŒãŸãƒ‘ãƒŠãƒĄãƒŧã‚ŋãĢæŗ¨į›Žã—ãĻãŋぞしょう: + +* こぎé–ĸ数は䞝存é–ĸäŋ‚īŧˆã€Œäžå­˜å¯čƒŊãĒもぎ」īŧ‰ããŽã‚‚ぎであるãĢもかかわらず、åˆĨぎ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã—ãĻいぞすīŧˆäŊ•かäģ–ぎもぎãĢ「䞝存」しãĻいぞすīŧ‰ã€‚ + * これは`query_extractor`ãĢ䞝存しãĻおり、それがčŋ”ã™å€¤ã‚’ãƒ‘ãƒŠãƒĄãƒŧã‚ŋ`q`ãĢäģŖå…Ĩしぞす。 +* ぞた、ã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎ`last_query`クッキãƒŧを`str`としãĻåŽŖč¨€ã—ãžã™ã€‚ + * ãƒĻãƒŧã‚ļãƒŧがクエãƒĒ`q`を提䞛しãĒã‹ãŖãŸå ´åˆã€ã‚¯ãƒƒã‚­ãƒŧãĢäŋå­˜ã—ãĻいた最垌ãĢäŊŋį”¨ã—ãŸã‚¯ã‚¨ãƒĒをäŊŋį”¨ã—ãžã™ã€‚ + +### 䞝存é–ĸäŋ‚ぎäŊŋᔍ + +äģĨ下ぎようãĢ䞝存é–ĸäŋ‚ã‚’äŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="21" +{!../../../docs_src/dependencies/tutorial005.py!} +``` + +!!! info "æƒ…å ą" + *path operationé–ĸ数*ãŽä¸­ã§åŽŖč¨€ã—ãĻいる䞝存é–ĸäŋ‚は`query_or_cookie_extractor`ぎīŧ‘つだけであることãĢæŗ¨æ„ã—ãĻください。 + + しかし、**FastAPI** は`query_extractor`を最初ãĢč§Ŗæąēし、そぎįĩæžœã‚’`query_or_cookie_extractor`をå‘ŧãŗå‡ēす時ãĢæ¸Ąã™åŋ…čĻãŒã‚ã‚‹ã“ã¨ã‚’įŸĨãŖãĻいぞす。 + +```mermaid +graph TB + +query_extractor(["query_extractor"]) +query_or_cookie_extractor(["query_or_cookie_extractor"]) + +read_query["/items/"] + +query_extractor --> query_or_cookie_extractor --> read_query +``` + +## 同じ䞝存é–ĸäŋ‚ãŽč¤‡æ•°å›žãŽäŊŋᔍ + +䞝存é–ĸäŋ‚ぎīŧ‘つが同じ*path operation*ãĢ寞しãĻč¤‡æ•°å›žåŽŖč¨€ã•ã‚ŒãĻã„ã‚‹å ´åˆã€äž‹ãˆã°ã€č¤‡æ•°ãŽäžå­˜é–ĸäŋ‚ãŒå…ąé€šãŽã‚ĩブ䞝存é–ĸäŋ‚ã‚’æŒãŖãĻいる場合、**FastAPI** はãƒĒクエ゚トごとãĢīŧ‘回だけそぎã‚ĩブ䞝存é–ĸäŋ‚ã‚’å‘ŧãŗå‡ēしぞす。 + +そしãĻ、čŋ”ã•ã‚ŒãŸå€¤ã‚’ã€Œã‚­ãƒŖãƒƒã‚ˇãƒĨ」ãĢäŋå­˜ã—、同じãƒĒクエ゚トãĢ寞しãĻ䞝存é–ĸäŋ‚ã‚’äŊ•åēĻもå‘ŧãŗå‡ēすäģŖã‚ã‚ŠãĢã€į‰šåŽšãŽãƒĒクエ゚トでそれをåŋ…čĻã¨ã™ã‚‹å…¨ãĻぎ「䞝存é–ĸäŋ‚」ãĢæ¸Ąã™ã“ã¨ãĢãĒりぞす。 + +é̘åēĻãĒã‚ˇãƒŠãƒĒã‚Ēã§ã¯ã€ã€Œã‚­ãƒŖãƒƒã‚ˇãƒĨされた」値をäŊŋうぎではãĒく、同じãƒĒクエ゚トぎ各゚テップīŧˆãŠãã‚‰ãč¤‡æ•°å›žīŧ‰ã§äžå­˜é–ĸäŋ‚ã‚’å‘ŧãŗå‡ēすåŋ…čĻãŒã‚ã‚‹ã“ã¨ãŒã‚ã‹ãŖãĻいる場合、`Depens`をäŊŋį”¨ã™ã‚‹éš›ãĢ、`use_cache=False`ã¨ã„ã†ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’č¨­åŽšã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +```Python hl_lines="1" +async def needy_dependency(fresh_value: str = Depends(get_value, use_cache=False)): + return {"fresh_value": fresh_value} +``` + +## ぞとめ + +ここでäŊŋわれãĻいる洞手ãĒč¨€č‘‰ã¯åˆĨãĢしãĻ、**äžå­˜æ€§æŗ¨å…Ĩ** ã‚ˇã‚šãƒ†ãƒ ã¯éžå¸¸ãĢã‚ˇãƒŗãƒ—ãƒĢです。 + +*path operationé–ĸ数*と同じようãĢčĻ‹ãˆã‚‹ãŸã ãŽé–ĸ数です。 + +しかし、それでも非常ãĢåŧˇåŠ›ã§ã€äģģæ„ãŽæˇąããƒã‚šãƒˆã•れた䞝存é–ĸäŋ‚「グナフ」īŧˆãƒ„ãƒĒãƒŧīŧ‰ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +!!! tip "豆įŸĨ識" + ã“ã‚Œã‚‰ãŽå˜į´”ãĒ䞋では、全ãĻがåŊšãĢįĢ‹ã¤ã¨ã¯č¨€ãˆãĒいかもしれぞせん。 + + しかし、**security** ãĢついãĻぎįĢ ã§ã€ãã‚ŒãŒãŠã‚ŒãģãŠæœ‰į”¨ã§ã‚ã‚‹ã‹ãŒã‚ã‹ã‚‹ã§ã—ã‚‡ã†ã€‚ + + そしãĻ、あãĒãŸã‚’æ•‘ã†ã‚ŗãƒŧドぎ量もãŋることãĢãĒるでしょう。 From 082eb21ba031ea2d432acba34f62c2c9ebfa6026 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:44:02 +0000 Subject: [PATCH 115/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ba357b1275..19a33ab73f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/sub-dependencies.md`. PR [#1959](https://github.com/tiangolo/fastapi/pull/1959) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/background-tasks.md`. PR [#2668](https://github.com/tiangolo/fastapi/pull/2668) by [@tokusumi](https://github.com/tokusumi). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/index.md` and `docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md`. PR [#1958](https://github.com/tiangolo/fastapi/pull/1958) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/response-model.md`. PR [#1938](https://github.com/tiangolo/fastapi/pull/1938) by [@SwftAlpc](https://github.com/SwftAlpc). From b518241c590027e2367366b89cd95eaba2c05705 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 01:44:28 +0900 Subject: [PATCH 116/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/dependencies/dependencies-i?= =?UTF-8?q?n-path-operation-decorators.md`=20(#1960)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- ...pendencies-in-path-operation-decorators.md | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md diff --git a/docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md b/docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md new file mode 100644 index 0000000000..1684d9ca1e --- /dev/null +++ b/docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md @@ -0,0 +1,62 @@ +# path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋぎ䞝存é–ĸäŋ‚ + +場合ãĢã‚ˆãŖãĻは*path operationé–ĸ数*ぎ中で䞝存é–ĸäŋ‚ぎæˆģり値をæœŦåŊ“ãĢåŋ…čĻã¨ã—ãĒいこともありぞす。 + +もしくは、䞝存é–ĸäŋ‚が値をčŋ”さãĒい場合もありぞす。 + +ã—ã‹ã—ã€ãã‚Œã§ã‚‚åŽŸčĄŒãƒģč§Ŗæąēするåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +こぎようãĒ場合、*path operationé–ĸ数*ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋを`Depends`ã§åŽŖč¨€ã™ã‚‹äģŖã‚ã‚ŠãĢ、*path operation decorator*ãĢ`dependencies`ぎ`list`をčŋŊ加することができぞす。 + +## *path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ*へぎ`dependencies`ぎčŋŊ加 + +*path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ*はã‚Ēãƒ—ã‚ˇãƒ§ãƒŠãƒĢぎåŧ•æ•°`dependencies`を受け取りぞす。 + +それは`Depends()`ぎ`list`であるずきです: + +```Python hl_lines="17" +{!../../../docs_src/dependencies/tutorial006.py!} +``` + +これらぎ䞝存é–ĸäŋ‚は、通常ぎ䞝存é–ĸäŋ‚と同様ãĢåŽŸčĄŒãƒģč§Ŗæąēされぞす。しかし、それらぎ値īŧˆäŊ•かをčŋ”す場合īŧ‰ã¯*path operationé–ĸ数*ãĢã¯æ¸Ąã•ã‚Œãžã›ã‚“ã€‚ + +!!! tip "豆įŸĨ識" + ã‚¨ãƒ‡ã‚Ŗã‚ŋãĢã‚ˆãŖãĻは、æœĒäŊŋį”¨ãŽé–ĸæ•°ãƒ‘ãƒŠãƒĄãƒŧã‚ŋをチェックしãĻエナãƒŧとしãĻ襨į¤ēするもぎもありぞす。 + + `dependencies`を`path operationãƒ‡ã‚ŗãƒŦãƒŧã‚ŋ`でäŊŋį”¨ã™ã‚‹ã“ã¨ã§ã€ã‚¨ãƒ‡ã‚Ŗã‚ŋやツãƒŧãƒĢぎエナãƒŧを回éŋしãĒがらįĸē原ãĢåŽŸčĄŒã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + + ãžãŸã€ã‚ŗãƒŧドぎæœĒäŊŋį”¨ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋがあるぎをčĻ‹ãĻ、それが不čĻã ã¨æ€ãŖãĻしぞうようãĒ新しい開į™ēč€…ãŽæˇˇäšąã‚’éŋけるぎãĢもåŊšįĢ‹ã¤ã‹ã‚‚ã—ã‚Œãžã›ã‚“ã€‚ + +## 䞝存é–ĸäŋ‚ぎエナãƒŧとæˆģり値 + +通常äŊŋį”¨ã—ãĻいる䞝存é–ĸäŋ‚ぎ*é–ĸ数*と同じもぎをäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +### 䞝存é–ĸäŋ‚ぎčρäģļ + +これらはãƒĒクエ゚トぎčρäģļīŧˆãƒ˜ãƒƒãƒ€ãŽã‚ˆã†ãĒもぎīŧ‰ã‚„そぎäģ–ぎã‚ĩブ䞝存é–ĸäŋ‚ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="6 11" +{!../../../docs_src/dependencies/tutorial006.py!} +``` + +### 䞋外ぎį™ēį”Ÿ + +これらぎ䞝存é–ĸäŋ‚は通常ぎ䞝存é–ĸäŋ‚と同じようãĢ、䞋外を`raise`į™ēį”Ÿã•ã›ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="8 13" +{!../../../docs_src/dependencies/tutorial006.py!} +``` + +### æˆģり値 + +そしãĻ、値をčŋ”すこともčŋ”さãĒいこともできぞすが、値はäŊŋわれぞせん。 + +つぞり、すでãĢおこかでäŊŋãŖãĻいる通常ぎ䞝存é–ĸäŋ‚īŧˆå€¤ã‚’čŋ”すもぎīŧ‰ã‚’å†åˆŠį”¨ã™ã‚‹ã“ã¨ãŒã§ãã€å€¤ã¯äŊŋわれãĒくãĻも䞝存é–ĸäŋ‚ã¯åŽŸčĄŒã•ã‚Œãžã™: + +```Python hl_lines="9 14" +{!../../../docs_src/dependencies/tutorial006.py!} +``` + +## *path operations*ぎグãƒĢãƒŧプãĢ寞する䞝存é–ĸäŋ‚ + +垌で、より大きãĒã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗãŽæ§‹é€ ([Bigger Applications - Multiple Files](../../tutorial/bigger-applications.md){.internal-link target=_blank})ãĢついãĻčĒ­ã‚€æ™‚ãĢã€ãŠãã‚‰ãč¤‡æ•°ãŽãƒ•ã‚Ąã‚¤ãƒĢをäŊŋį”¨ã—ãĻ、*path operations*ぎグãƒĢãƒŧプãĢ寞しãĻ単一ぎ`dependencies`ãƒ‘ãƒŠãƒĄãƒŧã‚ŋã‚’åŽŖč¨€ã™ã‚‹æ–šæŗ•ã‚’å­Ļãļでしょう。 From 7b462b2e69dee36db320b9977d815cdf1f8d1d2d Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 16 Jan 2024 01:45:09 +0900 Subject: [PATCH 117/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/dependencies/dependencies-w?= =?UTF-8?q?ith-yield.md`=20(#1961)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: ryusuke.miyaji Co-authored-by: ryuckel <36391432+ryuckel@users.noreply.github.com> Co-authored-by: tokusumi Co-authored-by: T. Tokusumi <41147016+tokusumi@users.noreply.github.com> Co-authored-by: SebastiÃĄn Ramírez --- .../dependencies/dependencies-with-yield.md | 225 ++++++++++++++++++ 1 file changed, 225 insertions(+) create mode 100644 docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md diff --git a/docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md b/docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md new file mode 100644 index 0000000000..2a89e51d2b --- /dev/null +++ b/docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md @@ -0,0 +1,225 @@ +# yieldを持つ䞝存é–ĸäŋ‚ + +FastAPIは、いくつかぎįĩ‚äē†åžŒãŽčŋŊåŠ ãŽã‚šãƒ†ãƒƒãƒ—ã‚’čĄŒã†äžå­˜é–ĸäŋ‚ã‚’ã‚ĩポãƒŧトしãĻいぞす。 + +ã“ã‚Œã‚’čĄŒã†ãĢは、`return`ぎäģŖã‚ã‚ŠãĢ`yield`をäŊŋい、そぎ垌ãĢčŋŊ加ぎ゚テップを書きぞす。 + +!!! tip "豆įŸĨ識" + `yield`はåŋ…ず一åēĻだけäŊŋį”¨ã™ã‚‹ã‚ˆã†ãĢしãĻください。 + +!!! info "æƒ…å ą" + これを動äŊœã•せるãĢは、**Python 3.7** äģĨ上をäŊŋį”¨ã™ã‚‹ã‹ã€**Python 3.6** では"backports"ã‚’ã‚¤ãƒŗã‚šãƒˆãƒŧãƒĢするåŋ…čĻãŒã‚ã‚Šãžã™: + + ``` + pip install async-exit-stack async-generator + ``` + + これãĢよりasync-exit-stackとasync-generatorãŒã‚¤ãƒŗã‚šãƒˆãƒŧãƒĢされぞす。 + +!!! note "æŠ€čĄ“čŠŗį´°" + äģĨä¸‹ã¨ä¸€įˇ’ãĢäŊŋį”¨ã§ãã‚‹é–ĸ数ãĒらäŊ•でも有劚です: + + * `@contextlib.contextmanager`ぞたは + * `@contextlib.asynccontextmanager` + + これらは **FastAPI** ぎ䞝存é–ĸäŋ‚としãĻäŊŋį”¨ã™ã‚‹ãŽãĢ有劚です。 + + 原際、FastAPIã¯å†…éƒ¨įš„ãĢこれらīŧ’ã¤ãŽãƒ‡ã‚ŗãƒŦãƒŧã‚ŋをäŊŋį”¨ã—ãĻいぞす。 + +## `yield`を持つデãƒŧã‚ŋベãƒŧ゚ぎ䞝存é–ĸäŋ‚ + +䞋えば、これをäŊŋãŖãĻデãƒŧã‚ŋベãƒŧ゚ã‚ģãƒƒã‚ˇãƒ§ãƒŗã‚’äŊœæˆã—、įĩ‚äē†åžŒãĢそれを閉じることができぞす。 + +ãƒŦã‚šãƒãƒŗã‚šã‚’é€äŋĄã™ã‚‹å‰ãĢ`yield`文をåĢã‚€å‰ãŽã‚ŗãƒŧドぎãŋãŒåŽŸčĄŒã•ã‚Œãžã™ã€‚ + +```Python hl_lines="2 3 4" +{!../../../docs_src/dependencies/tutorial007.py!} +``` + +į”Ÿæˆã•ã‚ŒãŸå€¤ã¯ã€*path operations*やäģ–ぎ䞝存é–ĸäŋ‚ãĢæŗ¨å…Ĩされるもぎです: + +```Python hl_lines="4" +{!../../../docs_src/dependencies/tutorial007.py!} +``` + +`yield`文ãĢįļšãã‚ŗãƒŧドは、ãƒŦã‚šãƒãƒŗã‚šãŒé€äŋĄã•れた垌ãĢåŽŸčĄŒã•ã‚Œãžã™: + +```Python hl_lines="5 6" +{!../../../docs_src/dependencies/tutorial007.py!} +``` + +!!! tip "豆įŸĨ識" + `async`や通常ぎé–ĸ数をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + + **FastAPI** は、通常ぎ䞝存é–ĸäŋ‚と同じようãĢã€ãã‚Œãžã‚Œã§æ­Ŗã—ã„ã“ã¨ã‚’čĄŒã„ãžã™ã€‚ + +## `yield`と`try`を持つ䞝存é–ĸäŋ‚ + +`yield`を持つ䞝存é–ĸäŋ‚で`try`ブロックをäŊŋį”¨ã—ãŸå ´åˆã€ããŽäžå­˜é–ĸäŋ‚ã‚’äŊŋį”¨ã—ãŸéš›ãĢį™ēį”Ÿã—ãŸäž‹å¤–ã‚’å—ã‘å–ã‚‹ã“ã¨ãĢãĒりぞす。 + +äž‹ãˆã°ã€é€”ä¸­ãŽãŠã“ã‹ãŽæ™‚į‚šã§ã€åˆĨぎ䞝存é–ĸäŋ‚ã‚„*path operation*ぎ中で、デãƒŧã‚ŋベãƒŧã‚šãƒˆãƒŠãƒŗã‚ļã‚¯ã‚ˇãƒ§ãƒŗã‚’ã€Œãƒ­ãƒŧãƒĢバック」したり、そぎäģ–ぎエナãƒŧをäŊœæˆã—ãŸã‚Šã™ã‚‹ã‚ŗãƒŧãƒ‰ãŒã‚ãŖãŸå ´åˆã€äžå­˜é–ĸäŋ‚ぎ中で䞋外を受け取ることãĢãĒりぞす。 + +そぎため、䞝存é–ĸäŋ‚ぎ中ãĢã‚ã‚‹į‰šåŽšãŽäž‹å¤–ã‚’`except SomeException`でæŽĸすことができぞす。 + +同様ãĢ、`finally`ã‚’į”¨ã„ãĻäž‹å¤–ãŒã‚ãŖãŸã‹ãŠã†ã‹ãĢかかわらず、įĩ‚äē†ã‚šãƒ†ãƒƒãƒ—ã‚’įĸē原ãĢåŽŸčĄŒã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +```Python hl_lines="3 5" +{!../../../docs_src/dependencies/tutorial007.py!} +``` + +## `yield`を持つã‚ĩブ䞝存é–ĸäŋ‚ + +äģģæ„ãŽå¤§ãã•ã‚„åŊĸぎã‚ĩブ䞝存é–ĸäŋ‚ã‚„ã‚ĩブ䞝存é–ĸäŋ‚ぎ「ツãƒĒãƒŧ」を持つことができ、そぎ中で`yield`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +**FastAPI** は、`yield`を持つ各䞝存é–ĸäŋ‚ぎ「įĩ‚äē†ã‚ŗãƒŧãƒ‰ã€ãŒæ­Ŗã—ã„é †į•Ēã§åŽŸčĄŒã•ã‚ŒãĻいることをįĸēčĒã—ãžã™ã€‚ + +䞋えば、`dependency_c`は`dependency_b`と`dependency_b`ãĢ䞝存する`dependency_a`ãĢ、䞝存することができぞす: + +```Python hl_lines="4 12 20" +{!../../../docs_src/dependencies/tutorial008.py!} +``` + +そしãĻ、それらはすずãĻ`yield`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +こぎ場合、`dependency_c`はįĩ‚äē†ã‚ŗãƒŧãƒ‰ã‚’åŽŸčĄŒã™ã‚‹ãŸã‚ãĢ、`dependency_b`īŧˆã“こでは`dep_b`という名前īŧ‰ãŽå€¤ãŒãžã åˆŠį”¨å¯čƒŊであるåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +そしãĻ、`dependency_b`は`dependency_a`īŧˆã“こでは`dep_a`という名前īŧ‰ãŽå€¤ã‚’įĩ‚äē†ã‚ŗãƒŧãƒ‰ã§åˆŠį”¨ã§ãã‚‹ã‚ˆã†ãĢするåŋ…čĻãŒã‚ã‚Šãžã™ã€‚ + +```Python hl_lines="16 17 24 25" +{!../../../docs_src/dependencies/tutorial008.py!} +``` + +同様ãĢ、`yield`と`return`ãŒæˇˇåœ¨ã—ãŸäžå­˜é–ĸäŋ‚を持つこともできぞす。 + +ぞた、単一ぎ䞝存é–ĸäŋ‚ã‚’æŒãŖãĻいãĻ、`yield`ãĒおぎäģ–ぎ䞝存é–ĸäŋ‚をいくつかåŋ…čĻã¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +䞝存é–ĸäŋ‚ぎįĩ„ãŋ合わせはč‡Ēį”ąã§ã™ã€‚ + +**FastAPI** は、全ãĻãŒæ­Ŗã—ã„é †åēã§åŽŸčĄŒã•ã‚ŒãĻいることをįĸēčĒã—ãžã™ã€‚ + +!!! note "æŠ€čĄ“čŠŗį´°" + これはPythonぎContext Managersぎおかげで動äŊœã—ぞす。 + + **FastAPI** ã¯ã“ã‚Œã‚’åŽŸįžã™ã‚‹ãŸã‚ãĢå†…éƒ¨įš„ãĢäŊŋį”¨ã—ãĻいぞす。 + +## `yield`と`HTTPException`を持つ䞝存é–ĸäŋ‚ + +`yield`ã¨äž‹å¤–ã‚’ã‚­ãƒŖãƒƒãƒã™ã‚‹`try`ブロックを持つことができる䞝存é–ĸäŋ‚ã‚’äŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ãã‚‹ã“ã¨ãŒã‚ã‹ã‚Šãžã—ãŸã€‚ + +`yield`ぎ垌ぎįĩ‚äē†ã‚ŗãƒŧドで`HTTPException`ãĒおをį™ēį”Ÿã•ã›ãŸããĒるかもしれぞせん。しかし**それはうぞくいきぞせん** + +`yield`を持つ䞝存é–ĸäŋ‚ぎįĩ‚äē†ã‚ŗãƒŧドは[äž‹å¤–ãƒãƒŗãƒ‰ãƒŠ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}ぎ*垌ãĢ*åŽŸčĄŒã•ã‚Œãžã™ã€‚äžå­˜é–ĸäŋ‚ãĢã‚ˆãŖãĻ投げられた䞋外をįĩ‚äē†ã‚ŗãƒŧドīŧˆ`yield`ぎ垌īŧ‰ã§ã‚­ãƒŖãƒƒãƒã™ã‚‹ã‚‚ぎはãĒãĢもありぞせん。 + +つぞり、`yield`ぎ垌ãĢ`HTTPException`をį™ēį”Ÿã•ã›ãŸå ´åˆã€`HTTTPException`ã‚’ã‚­ãƒŖãƒƒãƒã—ãĻHTTP 400ぎãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”すデフりãƒĢトぎīŧˆã‚るいはäģģæ„ãŽã‚Ģ゚ã‚ŋムぎīŧ‰äž‹å¤–ãƒãƒŗãƒ‰ãƒŠã¯ã€ããŽäž‹å¤–ã‚’ã‚­ãƒŖãƒƒãƒã™ã‚‹ã“ã¨ãŒã§ããĒくãĒりぞす。 + +これは、䞝存é–ĸäŋ‚ãĢč¨­åŽšã•ã‚ŒãĻいるもぎīŧˆäž‹ãˆã°ã€DBã‚ģãƒƒã‚ˇãƒ§ãƒŗīŧ‰ã‚’、䞋えば、バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クでäŊŋį”¨ã§ãã‚‹ã‚ˆã†ãĢするもぎです。 + +バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クはãƒŦã‚šãƒãƒŗã‚šãŒé€äŋĄã•れた*垌*ãĢåŽŸčĄŒã•ã‚Œãžã™ã€‚ããŽãŸã‚ã€*すでãĢ送äŋĄã•れãĻいる*ãƒŦã‚šãƒãƒŗã‚šã‚’å¤‰æ›´ã™ã‚‹æ–šæŗ•ã™ã‚‰ãĒいぎで、`HTTPException`をį™ēį”Ÿã•ã›ã‚‹æ–šæŗ•ã¯ã‚ã‚Šãžã›ã‚“ã€‚ + +しかし、バックグナã‚Ļãƒŗãƒ‰ã‚ŋ゚クがDBエナãƒŧをį™ēį”Ÿã•ã›ãŸå ´åˆã€å°‘ãĒくとも`yield`で䞝存é–ĸäŋ‚ぎã‚ģãƒƒã‚ˇãƒ§ãƒŗã‚’ãƒ­ãƒŧãƒĢバックしたり、きれいãĢ閉じたりすることができ、エナãƒŧをログãĢč¨˜éŒ˛ã—ãŸã‚Šã€ãƒĒãƒĸãƒŧãƒˆãŽãƒˆãƒŠãƒƒã‚­ãƒŗã‚°ã‚ˇã‚šãƒ†ãƒ ãĢå ąå‘Šã—ãŸã‚Šã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +䞋外がį™ēį”Ÿã™ã‚‹å¯čƒŊæ€§ãŒã‚ã‚‹ã‚ŗãƒŧドがある場合は、最も晎通ぎ「Pythonæĩã€ãĒことをしãĻã€ã‚ŗãƒŧドぎそぎ部分ãĢ`try`ブロックをčŋŊ加しãĻください。 + +ãƒŦã‚šãƒãƒŗã‚šã‚’čŋ”したり、ãƒŦã‚šãƒãƒŗã‚šã‚’å¤‰æ›´ã—ãŸã‚Šã€`HTTPException`をį™ēį”Ÿã•ã›ãŸã‚Šã™ã‚‹*前ãĢ*å‡Ļį†ã—ãŸã„ã‚Ģ゚ã‚ŋム䞋外がある場合は、[ã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}をäŊœæˆã—ãĻください。 + +!!! tip "豆įŸĨ識" + `HTTPException`をåĢむ䞋外は、`yield`ぎ*前*でもį™ēį”Ÿã•ã›ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ãŸã ã—ã€åžŒã§ã¯ã§ããžã›ã‚“ã€‚ + +åŽŸčĄŒãŽé †åēã¯å¤šã‹ã‚Œå°‘ãĒかれäģĨä¸‹ãŽå›ŗãŽã‚ˆã†ãĢãĒりぞす。時間は上から下へとæĩã‚ŒãĻいきぞす。そしãĻã€å„åˆ—ã¯ã‚ŗãƒŧãƒ‰ã‚’į›¸äē’äŊœį”¨ã•ã›ãŸã‚Šã€åŽŸčĄŒã—ãŸã‚Šã—ãĻいる部分ぎ一つです。 + +```mermaid +sequenceDiagram + +participant client as Client +participant handler as Exception handler +participant dep as Dep with yield +participant operation as Path Operation +participant tasks as Background tasks + + Note over client,tasks: Can raise exception for dependency, handled after response is sent + Note over client,operation: Can raise HTTPException and can change the response + client ->> dep: Start request + Note over dep: Run code up to yield + opt raise + dep -->> handler: Raise HTTPException + handler -->> client: HTTP error response + dep -->> dep: Raise other exception + end + dep ->> operation: Run dependency, e.g. DB session + opt raise + operation -->> handler: Raise HTTPException + handler -->> client: HTTP error response + operation -->> dep: Raise other exception + end + operation ->> client: Return response to client + Note over client,operation: Response is already sent, can't change it anymore + opt Tasks + operation -->> tasks: Send background tasks + end + opt Raise other exception + tasks -->> dep: Raise other exception + end + Note over dep: After yield + opt Handle other exception + dep -->> dep: Handle exception, can't change response. E.g. close DB session. + end +``` + +!!! info "æƒ…å ą" + **īŧ‘つぎãƒŦã‚šãƒãƒŗã‚š** だけがクナイã‚ĸãƒŗãƒˆãĢ送äŋĄã•れぞす。それはエナãƒŧãƒŦã‚šãƒãƒŗã‚šãŽä¸€ã¤ã‹ã‚‚ã—ã‚Œãžã›ã‚“ã—ã€*path operation*からぎãƒŦã‚šãƒãƒŗã‚šã‹ã‚‚ã—ã‚Œãžã›ã‚“ã€‚ + + いずれかぎãƒŦã‚šãƒãƒŗã‚šãŒé€äŋĄã•れた垌、äģ–ぎãƒŦã‚šãƒãƒŗã‚šã‚’é€äŋĄã™ã‚‹ã“とはできぞせん。 + +!!! tip "豆įŸĨ識" + ã“ãŽå›ŗã¯`HTTPException`をį¤ēしãĻいぞすが、[ã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠ](../handling-errors.md#install-custom-exception-handlers){.internal-link target=_blank}をäŊœæˆã™ã‚‹ã“とで、äģ–ぎ䞋外をį™ēį”Ÿã•ã›ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ãã—ãĻ、そぎ䞋外は䞝存é–ĸäŋ‚ぎįĩ‚äē†ã‚ŗãƒŧドではãĒく、そぎã‚Ģ゚ã‚ŋãƒ äž‹å¤–ãƒãƒŗãƒ‰ãƒŠãĢã‚ˆãŖãĻå‡Ļį†ã•ã‚Œãžã™ã€‚ + + ã—ã‹ã—äž‹å¤–ãƒãƒŗãƒ‰ãƒŠã§å‡Ļį†ã•ã‚ŒãĒい䞋外をį™ēį”Ÿã•ã›ãŸå ´åˆã¯ã€äžå­˜é–ĸäŋ‚ぎįĩ‚äē†ã‚ŗãƒŧドでå‡Ļį†ã•ã‚Œãžã™ã€‚ + +## ã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖ + +### ã€Œã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖã€ã¨ã¯ + +ã€Œã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖã€ã¨ã¯ã€`with`文ぎ中でäŊŋį”¨ã§ãã‚‹Pythonã‚Ēブジェクトぎことです。 + +äž‹ãˆã°ã€ãƒ•ã‚Ąã‚¤ãƒĢをčĒ­ãŋčžŧむãĢは`with`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python +with open("./somefile.txt") as f: + contents = f.read() + print(contents) +``` + +そぎ垌ぎ`open("./somefile.txt")`ã¯ã€Œã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖã€ã¨å‘ŧばれるã‚ĒブジェクトをäŊœæˆã—ぞす。 + +`with`ブロックがįĩ‚äē†ã™ã‚‹ã¨ã€äž‹å¤–ãŒã‚ãŖãŸã¨ã—ãĻã‚‚ãƒ•ã‚Ąã‚¤ãƒĢをįĸēかãĢ閉じぞす。 + +`yield`を䞝存é–ĸäŋ‚ã‚’äŊœæˆã™ã‚‹ã¨ã€**FastAPI** ã¯å†…éƒ¨įš„ãĢãã‚Œã‚’ã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖãĢ変換し、äģ–ぎé–ĸé€Ŗãƒ„ãƒŧãƒĢとįĩ„ãŋ合わせぞす。 + +### `yield`を持つ䞝存é–ĸäŋ‚ã§ãŽã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖãŽäŊŋᔍ + +!!! warning "æŗ¨æ„" + これは多かれ少ãĒかれ、「é̘åēĻãĒ」į™ēæƒŗã§ã™ã€‚ + + **FastAPI** をäŊŋい始めたばかりぎ斚は、とりあえず゚キップした斚がよいかもしれぞせん。 + +Pythonでは、äģĨ下ぎīŧ’ã¤ãŽãƒĄã‚Ŋッドを持つクナ゚をäŊœæˆã™ã‚‹: `__enter__()`と`__exit__()`ã“ã¨ã§ã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖã‚’äŊœæˆã™ã‚‹ã“とができぞす。 + +ぞた、䞝存é–ĸ数ぎ中で`with`や`async with`文をäŊŋį”¨ã™ã‚‹ã“ã¨ãĢã‚ˆãŖãĻ`yield`を持つ **FastAPI** ぎ䞝存é–ĸäŋ‚ぎ中でそれらをäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="1 2 3 4 5 6 7 8 9 13" +{!../../../docs_src/dependencies/tutorial010.py!} +``` + +!!! tip "豆įŸĨ識" + ã‚ŗãƒŗãƒ†ã‚­ã‚šãƒˆãƒžãƒãƒŧã‚¸ãƒŖã‚’äŊœæˆã™ã‚‹ã‚‚ã†ä¸€ã¤ãŽæ–šæŗ•ã¯withです: + + * `@contextlib.contextmanager` ぞたは + * `@contextlib.asynccontextmanager` + + これらをäŊŋãŖãĻ、é–ĸ数を単一ぎ`yield`ã§ãƒ‡ã‚ŗãƒŦãƒŧトすることができぞす。 + + これは **FastAPI** ãŒå†…éƒ¨įš„ãĢ`yield`を持つ䞝存é–ĸäŋ‚ぎためãĢäŊŋį”¨ã—ãĻいるもぎです。 + + しかし、FastAPIぎ䞝存é–ĸäŋ‚ãĢãƒ‡ã‚ŗãƒŦãƒŧã‚ŋをäŊŋうåŋ…čĻã¯ã‚ã‚Šãžã›ã‚“īŧˆãã—ãĻäŊŋうずきではありぞせんīŧ‰ã€‚ + + FastAPIãŒå†…éƒ¨įš„ãĢã‚„ãŖãĻくれぞす。 From e500f994035b0caa675d2bd65c3ae11d9b848a95 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:45:17 +0000 Subject: [PATCH 118/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 19a33ab73f..baa10754bd 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md`. PR [#1960](https://github.com/tiangolo/fastapi/pull/1960) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/sub-dependencies.md`. PR [#1959](https://github.com/tiangolo/fastapi/pull/1959) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/background-tasks.md`. PR [#2668](https://github.com/tiangolo/fastapi/pull/2668) by [@tokusumi](https://github.com/tokusumi). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/index.md` and `docs/ja/docs/tutorial/dependencies/classes-as-dependencies.md`. PR [#1958](https://github.com/tiangolo/fastapi/pull/1958) by [@SwftAlpc](https://github.com/SwftAlpc). From 2c670325af38a738d7cd8eecd622be77f900c6d8 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 16:47:21 +0000 Subject: [PATCH 119/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index baa10754bd..5d6c557099 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -43,6 +43,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#1961](https://github.com/tiangolo/fastapi/pull/1961) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md`. PR [#1960](https://github.com/tiangolo/fastapi/pull/1960) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/sub-dependencies.md`. PR [#1959](https://github.com/tiangolo/fastapi/pull/1959) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/background-tasks.md`. PR [#2668](https://github.com/tiangolo/fastapi/pull/2668) by [@tokusumi](https://github.com/tokusumi). From 8450dc204d806bac021c6a2432d7b4a0749e77cd Mon Sep 17 00:00:00 2001 From: Rafal Skolasinski Date: Mon, 15 Jan 2024 20:41:47 +0000 Subject: [PATCH 120/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo=20in=20?= =?UTF-8?q?`fastapi/security/oauth2.py`=20(#10972)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/security/oauth2.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 9281dfb64f..be3e18cd80 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -353,7 +353,7 @@ class OAuth2(SecurityBase): bool, Doc( """ - By default, if no HTTP Auhtorization header is provided, required for + By default, if no HTTP Authorization header is provided, required for OAuth2 authentication, it will automatically cancel the request and send the client an error. From 2ce4c102fb64efd3e59b84359ddcebaaa21003ce Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 20:42:07 +0000 Subject: [PATCH 121/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 5d6c557099..ed9fdf03b7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* âœī¸ Fix typo in `fastapi/security/oauth2.py`. PR [#10972](https://github.com/tiangolo/fastapi/pull/10972) by [@RafalSkolasinski](https://github.com/RafalSkolasinski). * 📝 Update `HTTPException` details in `docs/en/docs/tutorial/handling-errors.md`. PR [#5418](https://github.com/tiangolo/fastapi/pull/5418) by [@papb](https://github.com/papb). * âœī¸ 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). From 75ea31c79e9e744832570ad0f42ff8572e9fd0dd Mon Sep 17 00:00:00 2001 From: ChanHaeng Lee <61987505+2chanhaeng@users.noreply.github.com> Date: Tue, 16 Jan 2024 06:40:57 +0900 Subject: [PATCH 122/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Fix=20typo=20error?= =?UTF-8?q?=20in=20`docs/ko/docs/tutorial/path-params.md`=20(#10758)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/path-params.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ko/docs/tutorial/path-params.md b/docs/ko/docs/tutorial/path-params.md index 5cf397e7ae..8ebd0804e5 100644 --- a/docs/ko/docs/tutorial/path-params.md +++ b/docs/ko/docs/tutorial/path-params.md @@ -101,7 +101,7 @@ ## ėˆœė„œ ëŦ¸ė œ -*ę˛Ŋ로 ë™ėž‘*ė„ 만들때 ęŗ ė • ę˛Ŋ로ëĨŧ ę°–ęŗ  ėžˆëŠ” ėƒí™Šë“¤ė„ 맞ë‹Ļ뜨ëĻ´ 눘 ėžˆėŠĩ니다. +*ę˛Ŋ로 ë™ėž‘*ė„ 만들때 ęŗ ė • ę˛Ŋ로ëĨŧ ę°–ęŗ  ėžˆëŠ” ėƒí™Šë“¤ė„ 맞ë‹Ĩ뜨ëĻ´ 눘 ėžˆėŠĩ니다. `/users/me`래ëŸŧ, 현ėžŦ ė‚ŦėšŠėžė˜ ë°ė´í„°ëĨŧ ę°€ė ¸ė˜¨ë‹¤ęŗ  í•Šė‹œë‹¤. From ae92e563b1ba0d00f1aaf2b4a472f619038bf24c Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 15 Jan 2024 21:41:21 +0000 Subject: [PATCH 123/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ed9fdf03b7..01fc71d3d0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -44,6 +44,7 @@ hide: ### Translations +* âœī¸ Fix typo error in `docs/ko/docs/tutorial/path-params.md`. PR [#10758](https://github.com/tiangolo/fastapi/pull/10758) by [@2chanhaeng](https://github.com/2chanhaeng). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#1961](https://github.com/tiangolo/fastapi/pull/1961) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md`. PR [#1960](https://github.com/tiangolo/fastapi/pull/1960) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/sub-dependencies.md`. PR [#1959](https://github.com/tiangolo/fastapi/pull/1959) by [@SwftAlpc](https://github.com/SwftAlpc). From d1e533e3705f742c7f6abaf1d68f3af75d5036e0 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 16 Jan 2024 13:11:15 +0100 Subject: [PATCH 124/305] =?UTF-8?q?=E2=9C=8F=EF=B8=8F=20Tweak=20the=20germ?= =?UTF-8?q?an=20translation=20of=20`docs/de/docs/tutorial/index.md`=20(#10?= =?UTF-8?q?962)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/index.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/de/docs/tutorial/index.md b/docs/de/docs/tutorial/index.md index dd7ed43bda..93a30d1b37 100644 --- a/docs/de/docs/tutorial/index.md +++ b/docs/de/docs/tutorial/index.md @@ -1,6 +1,6 @@ -# Tutorial - Benutzerhandbuch - Intro +# Tutorial – Benutzerhandbuch -Diese Anleitung zeigt Ihnen Schritt fÃŧr Schritt, wie Sie **FastAPI** mit den meisten Funktionen nutzen kÃļnnen. +Dieses Tutorial zeigt Ihnen Schritt fÃŧr Schritt, wie Sie **FastAPI** und die meisten seiner Funktionen verwenden 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. @@ -12,7 +12,7 @@ Dadurch kÃļnnen Sie jederzeit zurÃŧckkommen und sehen genau das, was Sie benÃļt 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: +Um eines der Beispiele auszufÃŧhren, kopieren Sie den Code in eine Datei `main.py`, und starten Sie `uvicorn` mit:
@@ -50,31 +50,31 @@ $ pip install "fastapi[all]"
-...dies beinhaltet auch `uvicorn`, das Sie als Server verwenden kÃļnnen, auf dem Ihr Code läuft. +... das beinhaltet auch `uvicorn`, welchen Sie als Server verwenden kÃļnnen, der ihren Code ausfÃŧhrt. -!!! Hinweis - Sie kÃļnnen die Installation auch in einzelnen Schritten ausfÃŧhren. +!!! note "Hinweis" + Sie kÃļnnen die einzelnen Teile auch separat installieren. - Dies werden Sie wahrscheinlich tun, wenn Sie Ihre Anwendung produktiv einsetzen mÃļchten: + Das folgende wÃŧrden Sie wahrscheinlich tun, wenn Sie Ihre Anwendung in der Produktion einsetzen: ``` pip install fastapi ``` - Installieren Sie auch `uvicorn`, dies arbeitet als Server: + Installieren Sie auch `uvicorn` als Server: ``` pip install "uvicorn[standard]" ``` - Dasselbe gilt fÃŧr jede der optionalen Abhängigkeiten, die Sie verwenden mÃļchten. + Das gleiche gilt fÃŧr jede der optionalen Abhängigkeiten, die Sie verwenden mÃļchten. -## Erweitertes Benutzerhandbuch +## Handbuch fÃŧr fortgeschrittene Benutzer -Zusätzlich gibt es ein **Erweitertes Benutzerhandbuch**, dies kÃļnnen Sie später nach diesem **Tutorial - Benutzerhandbuch** lesen. +Es gibt auch ein **Handbuch fÃŧr fortgeschrittene Benutzer**, welches Sie später nach diesem **Tutorial – Benutzerhandbuch** lesen kÃļnnen. -Das **Erweiterte Benutzerhandbuch** baut auf dieses Tutorial auf, verwendet dieselben Konzepte und bringt Ihnen zusätzliche Funktionen bei. +Das **Handbuch fÃŧr fortgeschrittene Benutzer** baut auf diesem Tutorial auf, verwendet dieselben Konzepte und bringt Ihnen einige zusätzliche Funktionen bei. -Allerdings sollten Sie zuerst das **Tutorial - Benutzerhandbuch** lesen (was Sie gerade lesen). +Allerdings sollten Sie zuerst das **Tutorial – Benutzerhandbuch** lesen (was Sie hier gerade tun). -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. +Die Dokumentation ist so konzipiert, dass Sie 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 **Handbuch fÃŧr fortgeschrittene Benutzer** vervollständigen kÃļnnen. From d761a29908aed90703d7c561f446469104903679 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 16 Jan 2024 12:11:43 +0000 Subject: [PATCH 125/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 01fc71d3d0..e42e1baf4a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -44,6 +44,7 @@ hide: ### Translations +* âœī¸ Tweak the german translation of `docs/de/docs/tutorial/index.md`. PR [#10962](https://github.com/tiangolo/fastapi/pull/10962) by [@nilslindemann](https://github.com/nilslindemann). * âœī¸ Fix typo error in `docs/ko/docs/tutorial/path-params.md`. PR [#10758](https://github.com/tiangolo/fastapi/pull/10758) by [@2chanhaeng](https://github.com/2chanhaeng). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#1961](https://github.com/tiangolo/fastapi/pull/1961) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-in-path-operation-decorators.md`. PR [#1960](https://github.com/tiangolo/fastapi/pull/1960) by [@SwftAlpc](https://github.com/SwftAlpc). From 950d9ce74dd2efd73572dfb6d0631ce9687ce14a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 16 Jan 2024 14:23:25 +0100 Subject: [PATCH 126/305] =?UTF-8?q?=F0=9F=93=9D=20Deprecate=20old=20tutori?= =?UTF-8?q?als:=20Peewee,=20Couchbase,=20encode/databases=20(#10979)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/how-to/async-sql-encode-databases.md | 5 ++++- docs/en/docs/how-to/nosql-databases-couchbase.md | 5 ++++- docs/en/docs/how-to/sql-databases-peewee.md | 5 ++++- docs/en/mkdocs.yml | 7 ++++--- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/docs/en/docs/how-to/async-sql-encode-databases.md b/docs/en/docs/how-to/async-sql-encode-databases.md index 0e2ccce78d..c7b340d679 100644 --- a/docs/en/docs/how-to/async-sql-encode-databases.md +++ b/docs/en/docs/how-to/async-sql-encode-databases.md @@ -1,4 +1,4 @@ -# Async SQL (Relational) Databases with Encode/Databases +# ~~Async SQL (Relational) Databases with Encode/Databases~~ (deprecated) !!! info These docs are about to be updated. 🎉 @@ -7,6 +7,9 @@ The new docs will include Pydantic v2 and will use SQLModel once it is updated to use Pydantic v2 as well. +!!! warning "Deprecated" + This tutorial is deprecated and will be removed in a future version. + You can also use `encode/databases` with **FastAPI** to connect to databases using `async` and `await`. It is compatible with: diff --git a/docs/en/docs/how-to/nosql-databases-couchbase.md b/docs/en/docs/how-to/nosql-databases-couchbase.md index ae6ad604ba..5633189843 100644 --- a/docs/en/docs/how-to/nosql-databases-couchbase.md +++ b/docs/en/docs/how-to/nosql-databases-couchbase.md @@ -1,4 +1,4 @@ -# NoSQL (Distributed / Big Data) Databases with Couchbase +# ~~NoSQL (Distributed / Big Data) Databases with Couchbase~~ (deprecated) !!! info These docs are about to be updated. 🎉 @@ -7,6 +7,9 @@ The new docs will hopefully use Pydantic v2 and will use ODMantic with MongoDB. +!!! warning "Deprecated" + This tutorial is deprecated and will be removed in a future version. + **FastAPI** can also be integrated with any NoSQL. Here we'll see an example using **Couchbase**, a document based NoSQL database. diff --git a/docs/en/docs/how-to/sql-databases-peewee.md b/docs/en/docs/how-to/sql-databases-peewee.md index 74a28b170f..7211f7ed3b 100644 --- a/docs/en/docs/how-to/sql-databases-peewee.md +++ b/docs/en/docs/how-to/sql-databases-peewee.md @@ -1,4 +1,7 @@ -# SQL (Relational) Databases with Peewee +# ~~SQL (Relational) Databases with Peewee~~ (deprecated) + +!!! warning "Deprecated" + This tutorial is deprecated and will be removed in a future version. !!! warning If you are just starting, the tutorial [SQL (Relational) Databases](../tutorial/sql-databases.md){.internal-link target=_blank} that uses SQLAlchemy should be enough. diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index 92d081aa12..b8d27a35b0 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -174,9 +174,6 @@ nav: - How To - Recipes: - how-to/index.md - how-to/general.md - - how-to/sql-databases-peewee.md - - how-to/async-sql-encode-databases.md - - how-to/nosql-databases-couchbase.md - how-to/graphql.md - how-to/custom-request-and-route.md - how-to/conditional-openapi.md @@ -184,6 +181,9 @@ nav: - how-to/separate-openapi-schemas.md - how-to/custom-docs-ui-assets.md - how-to/configure-swagger-ui.md + - how-to/sql-databases-peewee.md + - how-to/async-sql-encode-databases.md + - how-to/nosql-databases-couchbase.md - Reference (Code API): - reference/index.md - reference/fastapi.md @@ -242,6 +242,7 @@ markdown_extensions: format: !!python/name:pymdownx.superfences.fence_code_format '' pymdownx.tabbed: alternate_style: true + pymdownx.tilde: attr_list: null md_in_html: null extra: From fc8ea413eb8a6370c3b41de7ccad6003bf37ab13 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 16 Jan 2024 13:23:49 +0000 Subject: [PATCH 127/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index e42e1baf4a..a969545270 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Deprecate old tutorials: Peewee, Couchbase, encode/databases. PR [#10979](https://github.com/tiangolo/fastapi/pull/10979) by [@tiangolo](https://github.com/tiangolo). * âœī¸ Fix typo in `fastapi/security/oauth2.py`. PR [#10972](https://github.com/tiangolo/fastapi/pull/10972) by [@RafalSkolasinski](https://github.com/RafalSkolasinski). * 📝 Update `HTTPException` details in `docs/en/docs/tutorial/handling-errors.md`. PR [#5418](https://github.com/tiangolo/fastapi/pull/5418) by [@papb](https://github.com/papb). * âœī¸ 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). From df09e0a3f6061de4bf63b8ab7ea61b6cdd70d4fd Mon Sep 17 00:00:00 2001 From: Max Su Date: Thu, 18 Jan 2024 01:15:27 +0800 Subject: [PATCH 128/305] =?UTF-8?q?=F0=9F=8C=90=20Initialize=20translation?= =?UTF-8?q?s=20for=20Traditional=20Chinese=20(#10505)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/mkdocs.yml | 2 + docs/zh-hant/docs/index.md | 470 +++++++++++++++++++++++++++++++++++++ docs/zh-hant/mkdocs.yml | 1 + scripts/docs.py | 2 - 4 files changed, 473 insertions(+), 2 deletions(-) create mode 100644 docs/zh-hant/docs/index.md create mode 100644 docs/zh-hant/mkdocs.yml diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index b8d27a35b0..fcac555eb6 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -303,6 +303,8 @@ extra: name: yo - YorÚbÃĄ - link: /zh/ name: zh - æą‰č¯­ + - link: /zh-hant/ + name: zh - įšéĢ”ä¸­æ–‡ - link: /em/ name: 😉 extra_css: diff --git a/docs/zh-hant/docs/index.md b/docs/zh-hant/docs/index.md new file mode 100644 index 0000000000..e7a2efec95 --- /dev/null +++ b/docs/zh-hant/docs/index.md @@ -0,0 +1,470 @@ +

+ FastAPI +

+

+ FastAPI æĄ†æžļīŧŒéĢ˜æ•ˆčƒŊīŧŒæ˜“æ–ŧå­¸įŋ’īŧŒåŋĢ速開į™ŧīŧŒéŠį”¨æ–ŧį”Ÿį”ĸį’°åĸƒ +

+

+ + Test + + + Coverage + + + Package version + + + Supported Python versions + +

+ +--- + +**文äģļ**īŧš https://fastapi.tiangolo.com + +**ፋåŧįĸŧ**īŧš https://github.com/tiangolo/fastapi + +--- + +FastAPI æ˜¯ä¸€å€‹įžäģŖã€åŋĢ速īŧˆéĢ˜æ•ˆčƒŊīŧ‰įš„ web æĄ†æžļīŧŒį”¨æ–ŧ Python 3.8+ ä¸ĻæŽĄį”¨æ¨™æē– Python 型åˆĨ提į¤ē。 + +ä¸ģčĻį‰šéģžåŒ…åĢīŧš + +- **åŋĢ速**īŧš 非常éĢ˜įš„æ•ˆčƒŊīŧŒå¯čˆ‡ **NodeJS** 和 **Go** 效čƒŊᛏį•ļ (歸功æ–ŧ Starlette and Pydantic)。 [FastAPI 是最åŋĢįš„ Python web æĄ†æžļ之一](#performance)。 +- **æĨĩ速開į™ŧ**īŧš 提éĢ˜é–‹į™ŧ功čƒŊįš„é€ŸåēĻį´„ 200% 臺 300%。 \* +- **æ›´å°‘įš„ Bug**īŧ𠿏›å°‘į´„ 40% įš„äēēį‚ēīŧˆé–‹į™ŧ者īŧ‰å°Žč‡´įš„錯čĒ¤ã€‚ \* +- **į›´čĻē**īŧš å…ˇæœ‰å‡ēč‰˛įš„įˇ¨čŧ¯å™¨æ”¯æ´īŧŒč™•處éƒŊ有č‡Ēå‹•čŖœå…¨äģĨ減少åĩ錯時間。 +- **į°Ąå–Ž**īŧš č¨­č¨ˆä¸Šæ˜“æ–ŧäŊŋį”¨å’Œå­¸įŋ’īŧŒå¤§åš…æ¸›å°‘é–ąčŽ€æ–‡äģļįš„æ™‚é–“ã€‚ +- **į°ĄæŊ”**īŧš æœ€å°åŒ–ፋåŧįĸŧé‡č¤‡æ€§ã€‚å¯äģĨé€šéŽä¸åŒįš„åƒæ•¸č˛æ˜Žäž†å¯Ļįžæ›´čąå¯Œįš„åŠŸčƒŊīŧŒå’Œæ›´å°‘įš„éŒ¯čĒ¤ã€‚ +- **įŠŠåĨ**īŧš įĢ‹åŗį˛åž—į”Ÿį”ĸį´šå¯į”¨įš„į¨‹åŧįĸŧīŧŒé‚„有č‡Ēå‹•į”Ÿæˆäē’å‹•åŧæ–‡äģļ。 +- **標æē–化**īŧš åŸēæ–ŧ (ä¸”åŽŒå…¨į›¸åŽšæ–ŧ) OpenAPIs įš„į›¸é—œæ¨™æē–īŧšOpenAPIīŧˆäš‹å‰čĸĢį¨ąį‚ē Swaggerīŧ‰å’ŒJSON Schema。 + +\* åŸēæ–ŧ內部開į™ŧ團隊在åģēįĢ‹į”Ÿį”ĸæ‡‰į”¨į¨‹åŧæ™‚įš„æ¸ŦčŠĻ預äŧ°ã€‚ + +## č´ŠåŠŠ + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor -%} +{%- for sponsor in sponsors.silver -%} + +{% endfor %} +{% endif %} + + + +å…ļäģ–č´ŠåŠŠå•† + +## čŠ•åƒš + +"_[...] čŋ‘æœŸå¤§é‡įš„äŊŋᔍ **FastAPI**。 [...] į›Žå‰æ­Ŗåœ¨č¨ˆį•Ģ在**垎čģŸ**åœ˜éšŠįš„**抟器學įŋ’**服務中導å…Ĩ。å…ļ中一ä盿­Ŗåœ¨æ•´åˆåˆ°æ ¸åŋƒįš„ **Windows** į”ĸ品和一äē› **Office** į”ĸ品。_" + +
Kabir Khan - Microsoft (ref)
+ +--- + +"_我們äŊŋᔍ **FastAPI** 來åģēįĢ‹į”ĸį”Ÿ**預æ¸Ŧ**įĩæžœįš„ **REST** äŧ翜å™¨ã€‚ [for Ludwig]_" + +
Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - Uber (ref)
+ +--- + +"_**Netflix** 垈æĻŽåš¸åœ°åŽŖå¸ƒé–‹æē**åąæŠŸįŽĄį†**協čĒŋæĄ†æžļīŧš **Dispatch**! [是äŊŋᔍ **FastAPI** åģēæ§‹]_" + +
Kevin Glisson, Marc Vilanova, Forest Monsen - Netflix (ref)
+ +--- + +"_我對 **FastAPI** 興åĨŽåž—不垗äē†ã€‚åރå¤Ē有čļŖäē†īŧ_" + +
Brian Okken - Python Bytes podcast host (ref)
+ +--- + +"_老å¯ĻčĒĒīŧŒäŊ åģēé€ įš„æąčĨŋįœ‹čĩˇäž†éžå¸¸å …å›ēå’Œį˛žįˇģ。在垈多斚éĸīŧŒé€™å°ąæ˜¯æˆ‘æƒŗčĻįš„īŧŒįœ‹åˆ°æœ‰äēēåģēé€ åŽƒįœŸįš„åžˆéŧ“čˆžäēēåŋƒã€‚_" + +
Timothy Crosley - Hug creator (ref)
+ +--- + +"_åĻ‚æžœæ‚¨æƒŗå­¸įŋ’ä¸€į¨Žį”¨æ–ŧ構åģē REST API įš„**įžäģŖæĄ†æžļ**īŧŒä¸čƒŊ錯過 **FastAPI** [...] 厃非常åŋĢ速、且易æ–ŧäŊŋį”¨å’Œå­¸įŋ’ [...]_" + +"_æˆ‘å€‘įš„ **APIs** 厞į”šį”¨ **FastAPI** [...] æˆ‘æƒŗäŊ æœƒå–œæ­Ąåރ [...]_" + +
Ines Montani - Matthew Honnibal - Explosion AI å‰ĩčžĻäēē - spaCy creators (ref) - (ref)
+ +--- + +"_åĻ‚æžœæœ‰äē翃ŗčρåģēįĢ‹ä¸€å€‹į”Ÿį”ĸį’°åĸƒįš„ Python APIīŧŒæˆ‘åŧˇįƒˆæŽ¨č–Ļ **FastAPI**īŧŒåރ**č¨­č¨ˆį˛žįžŽ**īŧŒ**äŊŋį”¨į°Ąå–Ž**且**é̘åēĻ可擴充**īŧŒåŽƒåˇ˛æˆį‚ē我們 API å„Ē先開į™ŧį­–į•Ĩä¸­įš„**關éĩįĩ„äģļ**īŧŒä¸Ļ且銅動äē†č¨ąå¤šč‡Ē動化服務īŧŒäž‹åĻ‚æˆ‘å€‘įš„ Virtual TAC Engineer。_" + +
Deon Pillsbury - Cisco (ref)
+ +--- + +## **Typer**īŧŒå‘Ŋäģ¤åˆ—ä¸­įš„ FastAPI + + + +åĻ‚æžœäŊ ä¸æ˜¯åœ¨é–‹į™ŧįļ˛é  APIīŧŒč€Œæ˜¯æ­Ŗåœ¨é–‹į™ŧ一個在įĩ‚įĢ¯æŠŸä¸­é‹čĄŒįš„å‘Ŋäģ¤åˆ—æ‡‰į”¨į¨‹åŧīŧŒä¸åĻ¨å˜—čŠĻ **Typer**。 + +**Typer** 是 FastAPI įš„å°å…„åŧŸã€‚äģ–įĢ‹åŋ—成į‚ēå‘Ŋäģ¤åˆ—įš„ **FastAPI**。 âŒ¨ī¸ 🚀 + +## åŽ‰čŖéœ€æą‚ + +Python 3.8+ + +FastAPI 是įĢ™åœ¨äģĨ䏋厍äēēįš„č‚Šč†€ä¸Šīŧš + +- Starlette 負č˛Ŧįļ˛é įš„部分 +- Pydantic 負č˛Ŧčŗ‡æ–™įš„éƒ¨åˆ† + +## åŽ‰čŖ + +
+ +```console +$ pip install fastapi + +---> 100% +``` + +
+ +äŊ åŒæ™‚ä🿜ƒéœ€čρ ASGI äŧ翜å™¨į”¨æ–ŧį”Ÿį”ĸį’°åĸƒīŧŒåƒæ˜¯ Uvicorn 或 Hypercorn。 + +
+ +```console +$ pip install "uvicorn[standard]" + +---> 100% +``` + +
+ +## į¯„äž‹ + +### åģēįĢ‹ + +- åģēį̋䏀個 python æĒ”æĄˆ `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} +``` + +**æŗ¨æ„**īŧš + +åĻ‚æžœäŊ ä¸įŸĨ道是åĻæœƒį”¨åˆ°īŧŒå¯äģĨæŸĨįœ‹ _"In a hurry?"_ į̠ᝀ䏭īŧŒé—œæ–ŧ `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` æĒ”æĄˆīŧˆä¸€å€‹ python įš„ "æ¨Ąįĩ„"īŧ‰ã€‚ +- `app`īŧšåœ¨ `main.py` æĒ”æĄˆä¸­īŧŒäŊŋᔍ `app = FastAPI()` åģēįĢ‹įš„į‰Šäģļ。 +- `--reload`īŧšį¨‹åŧįĸŧ更攚垌會č‡Ē動重新啟動īŧŒčĢ‹åƒ…åœ¨é–‹į™ŧ時äŊŋį”¨æ­¤åƒæ•¸ã€‚ + +
+ +### æĒĸæŸĨ + +äŊŋį”¨į€čĻŊ器開啟 http://127.0.0.1:8000/items/5?q=somequery。 + +äŊ å°‡æœƒįœ‹åˆ°äģĨä¸‹įš„ JSON 回應īŧš + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +äŊ åˇ˛įļ“åģēįĢ‹äē†ä¸€å€‹å…ˇæœ‰äģĨ下功čƒŊįš„ APIīŧš + +- é€éŽčˇ¯åž‘ `/` 和 `/items/{item_id}` æŽĨ受 HTTP čĢ‹æą‚ã€‚ +- äģĨ䏊莝įļ“éƒŊæŽĨ受 `GET` čĢ‹æą‚īŧˆäšŸčĸĢį¨ąį‚ē HTTP _æ–šæŗ•_īŧ‰ã€‚ +- čˇ¯åž‘ `/items/{item_id}` 有一個 `int` 型åˆĨįš„ `item_id` 參數。 +- čˇ¯åž‘ `/items/{item_id}` 有一個 `str` 型åˆĨįš„æŸĨčŠĸ參數 `q`。 + +### äē’å‹•åŧ API 文äģļ + +äŊŋį”¨į€čĻŊ器開啟 http://127.0.0.1:8000/docs。 + +äŊ æœƒįœ‹åˆ°č‡Ēå‹•į”Ÿæˆįš„äē’å‹•åŧ API 文äģļīŧˆį”ą Swagger UI į”Ÿæˆīŧ‰īŧš + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +### ReDoc API 文äģļ + +äŊŋį”¨į€čĻŊ器開啟 http://127.0.0.1:8000/redoc。 + +äŊ å°‡įœ‹åˆ° ReDoc 文äģļ (į”ą ReDoc į”Ÿæˆ)īŧš + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## į¯„äž‹å‡į´š + +įžåœ¨įšŧįēŒäŋŽæ”š `main.py` æĒ”æĄˆīŧŒäž†æŽĨæ”ļ一個å¸ļ有 body įš„ `PUT` čĢ‹æą‚ã€‚ + +我們äŊŋᔍ Pydantic 來äŊŋį”¨æ¨™æē–įš„ Python 型åˆĨč˛æ˜ŽčĢ‹æą‚ã€‚ + +```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 文äģᅵƒč‡Ē動更新īŧŒä¸Ļ加å…Ĩæ–°įš„ body čĢ‹æą‚īŧš + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) + +- éģžæ“Š "Try it out" 按鈕īŧŒ äŊ å¯äģĨåĄĢå¯Ģ參數ä¸Ļį›´æŽĨ與 API äē’å‹•īŧš + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png) + +- į„ļ垌éģžæ“Š "Execute" 按鈕īŧŒäŊŋᔍ者äģ‹éĸ將會向 API į™ŧ送čĢ‹æą‚īŧŒä¸Ļ將įĩæžœéĄ¯į¤ē在čžĸ嚕上īŧš + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png) + +### ReDoc API 文äģļå‡į´š + +äŊŋį”¨į€čĻŊ器開啟 http://127.0.0.1:8000/redoc。 + +- ReDoc API 文äģᅵƒč‡Ē動更新īŧŒä¸Ļ加å…Ĩæ–°įš„åƒæ•¸å’Œ body čĢ‹æą‚īŧš + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) + +### į¸Ŋįĩ + +į¸Ŋįĩäž†čĒĒīŧŒ äŊ å°ąåƒåŽŖå‘Šå‡Ŋåŧįš„參數型åˆĨä¸€æ¨ŖīŧŒåĒåŽŖå‘Šäē†ä¸€æŦĄčĢ‹æą‚åƒæ•¸å’ŒčĢ‹æą‚ä¸ģéĢ”åƒæ•¸į­‰åž‹åˆĨ。 + +äŊ äŊŋᔍ Python 標æē–åž‹åˆĨäž†åŽŒæˆč˛æ˜Žã€‚ + +äŊ ä¸éœ€čρ孏įŋ’æ–°įš„čĒžæŗ•ã€éĄžåˆĨã€æ–šæŗ•æˆ–å‡ŊåŧåēĢį­‰į­‰ã€‚ + +åĒ需čρäŊŋᔍ **Python 3.8 äģĨä¸Šįš„į‰ˆæœŦ**。 + +čˆ‰å€‹į¯„äž‹īŧŒæ¯”åĻ‚åŽŖå‘Š int įš„åž‹åˆĨīŧš + +```Python +item_id: int +``` + +æˆ–æ˜¯ä¸€å€‹æ›´č¤‡é›œįš„ `Item` æ¨Ąåž‹īŧš + +```Python +item: Item +``` + +åœ¨é€˛čĄŒä¸€æŦĄåŽŖå‘ŠåžŒīŧŒäŊ å°‡į˛åž—īŧš + +- ᎍčŧ¯å™¨æ”¯æ´īŧš + - č‡Ēå‹•čŖœå…¨ + - 型åˆĨæĒĸæŸĨ +- čŗ‡æ–™éŠ—č­‰īŧš + - éŠ—č­‰å¤ąæ•—æ™‚č‡Ēå‹•į”Ÿæˆæ¸…æĨšįš„錯čĒ¤č¨Šæ¯ + - å¯éŠ—č­‰å¤šåą¤åˇĸį‹€įš„ JSON į‰Šäģļ +- čŊ‰æ›čŧ¸å…Ĩįš„čŗ‡æ–™īŧš čŊ‰æ›äž†č‡Ēįļ˛čˇ¯čĢ‹æą‚åˆ° Python čŗ‡æ–™åž‹åˆĨ。包åĢäģĨ下數據īŧš + - JSON + - čˇ¯åž‘åƒæ•¸ + - æŸĨčŠĸ參數 + - Cookies + - čĢ‹æą‚æ¨™é ­ + - čĄ¨å–Ž + - 文äģļ +- čŊ‰æ›čŧ¸å‡ēįš„čŗ‡æ–™īŧš čŊ‰æ› Python čŗ‡æ–™åž‹åˆĨ到įļ˛čˇ¯å‚ŗčŧ¸įš„ JSONīŧš + - čŊ‰æ› Python 型åˆĨ (`str`、 `int`、 `float`、 `bool`、 `list` į­‰) + - `datetime` į‰Šäģļ + - `UUID` į‰Šäģļ + - æ•¸æ“šæ¨Ąåž‹ + - ...還有å…ļäģ–æ›´å¤š +- č‡Ēå‹•į”Ÿæˆįš„ 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` į¯„äž‹įš„čĢ‹æą‚ body)。 +- 對æ–ŧ `PUT` įš„čĢ‹æą‚ `/items/{item_id}`īŧŒå°‡æœƒčŽ€å– body į‚ē JSONīŧš + - éŠ—č­‰æ˜¯åĻ有åŋ…åĄĢåąŦ性 `name` 且型åˆĨ是 `str`。 + - éŠ—č­‰æ˜¯åĻ有åŋ…åĄĢåąŦ性 `price` 且型åˆĨ是 `float`。 + - éŠ—č­‰æ˜¯åĻ有選åĄĢåąŦ性 `is_offer` 且型åˆĨ是 `bool`。 + - äģĨ上驗證éƒŊéŠį”¨æ–ŧå¤šåą¤æŦĄåˇĸį‹€ JSON į‰Šäģļ。 +- č‡Ē動čŊ‰æ› JSON æ ŧåŧã€‚ +- 透過 OpenAPI 文äģļäž†č¨˜éŒ„æ‰€æœ‰å…§åŽšīŧŒå¯äģĨčĸĢᔍæ–ŧīŧš + - äē’å‹•åŧæ–‡äģļįŗģįĩąã€‚ + - č‡Ē動į‚ēå¤šį¨Žį¨‹åŧčĒžč¨€į”Ÿæˆį”¨æˆļįĢ¯įš„į¨‹åŧįĸŧ。 +- æäž›å…Šį¨Žäē¤äē’åŧæ–‡äģļäģ‹éĸ。 + +--- + +雖į„ļ我們åĒ敘čŋ°äē†čĄ¨éĸįš„åŠŸčƒŊīŧŒäŊ†å…ļå¯ĻäŊ åˇ˛įļ“ᐆ觪äē†åŽƒæ˜¯åĻ‚äŊ•åŸˇčĄŒã€‚ + +čŠĻ著äŋŽæ”šäģĨ䏋ፋåŧįĸŧīŧš + +```Python + return {"item_name": item.name, "item_id": item_id} +``` + +åžžīŧš + +```Python + ... "item_name": item.name ... +``` + +äŋŽæ”šį‚ēīŧš + +```Python + ... "item_price": item.price ... +``` + +į„ļåžŒč§€å¯ŸäŊ įš„ᎍčŧ¯å™¨īŧŒæœƒč‡Ēå‹•čŖœå…¨ä¸Ļ且還įŸĨ道äģ–å€‘įš„åž‹åˆĨīŧš + +![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) + +有關更多功čƒŊįš„åŽŒæ•´į¯„äž‹īŧŒå¯äģĨåƒč€ƒ 教學 - äŊŋį”¨č€…æŒ‡å—ã€‚ + +**劇透č­Ļ告**īŧš 教學 - äŊŋį”¨č€…æŒ‡å—å…§åŽšæœ‰īŧš + +- 對䞆č‡Ēä¸åŒåœ°æ–šįš„**參數**é€˛čĄŒåŽŖå‘Šīŧšåƒæ˜¯ **headers**, **cookies**, **form čĄ¨å–Ž**äģĨ及**ä¸Šå‚ŗæĒ”æĄˆ**。 +- åĻ‚äŊ•設åޚ **驗證限åˆļ** 像是 `maximum_length` or `regex`。 +- į°Ąå–Žä¸”éžå¸¸åŽšæ˜“äŊŋį”¨įš„ **äžčŗ´æŗ¨å…Ĩ** įŗģįĩąã€‚ +- 厉全性和čēĢäģŊ驗證īŧŒåŒ…åĢ提䞛支援 **OAuth2**、**JWT tokens** 和 **HTTP Basic** éŠ—č­‰ã€‚ +- æ›´é€˛éšŽ (äŊ†åŒæ¨Ŗį°Ąå–Ž) įš„åŽŖå‘Š **å¤šåą¤æŦĄįš„åˇĸį‹€ JSON æ ŧåŧ** (感čŦ Pydantic)。 +- **GraphQL** 與 Strawberry äģĨ及å…ļäģ–įš„į›¸é—œå‡ŊåŧåēĢé€˛čĄŒæ•´åˆã€‚ +- 更多å…ļäģ–įš„åŠŸčƒŊ (感čŦ Starlette) 像是īŧš + - **WebSockets** + - æ–ŧ HTTPX 和 `pytest` įš„éžå¸¸į°Ąå–Žæ¸ŦčŠĻ + - **CORS** + - **Cookie Sessions** + - ...äģĨ及更多 + +## 效čƒŊ + +來č‡Ēį¨įĢ‹æŠŸæ§‹ TechEmpower įš„æ¸ŦčŠĻįĩæžœīŧŒéĄ¯į¤ē在 Uvicorn åŸˇčĄŒä¸‹įš„ **FastAPI** 是 最åŋĢįš„ Python æĄ†æžļ之一īŧŒ 僅æŦĄæ–ŧ Starlette 和 Uvicorn æœŦčēĢ (å…Šč€…æ˜¯ FastAPI įš„åē•åą¤)。 (\*) + +æƒŗäē†č§Ŗæ›´å¤šč¨Šæ¯īŧŒå¯äģĨåƒč€ƒ æ¸ŦčŠĻįĩæžœã€‚ + +## å¯é¸įš„äžčŗ´åĨ—äģļ + +ᔍæ–ŧ Pydanticīŧš + +- email_validator - ᔍæ–ŧé›ģ子éƒĩäģļéŠ—č­‰ã€‚ +- pydantic-settings - ᔍæ–ŧč¨­åŽšįŽĄį†ã€‚ +- pydantic-extra-types - ᔍæ–ŧ與 Pydantic 一čĩˇäŊŋį”¨įš„éĄå¤–åž‹åˆĨ。 + +ᔍæ–ŧ Starletteīŧš + +- httpx - äŊŋᔍ `TestClient`時åŋ…é ˆåŽ‰čŖã€‚ +- jinja2 - äŊŋį”¨é č¨­įš„æ¨Ąæŋ配įŊŽæ™‚åŋ…é ˆåŽ‰čŖã€‚ +- python-multipart - 需čρäŊŋᔍ `request.form()` å°čĄ¨å–Žé€˛čĄŒ "č§Ŗæž" æ™‚åŽ‰čŖã€‚ +- itsdangerous - 需čρäŊŋᔍ `SessionMiddleware` æ”¯æ´æ™‚åŽ‰čŖã€‚ +- pyyaml - ᔍæ–ŧ支援 Starlette įš„ `SchemaGenerator` (åĻ‚æžœäŊ äŊŋᔍ FastAPIīŧŒå¯čƒŊ不需čĻåŽƒ)。 +- ujson - äŊŋᔍ `UJSONResponse` 時åŋ…é ˆåŽ‰čŖã€‚ + +ᔍæ–ŧ FastAPI / Starletteīŧš + +- uvicorn - ᔍæ–ŧ加čŧ‰å’Œé‹čĄŒæ‡‰į”¨į¨‹åŧįš„æœå‹™å™¨ã€‚ +- orjson - äŊŋᔍ `ORJSONResponse`時åŋ…é ˆåŽ‰čŖã€‚ + +äŊ å¯äģĨäŊŋᔍ `pip install "fastapi[all]"` äž†åŽ‰čŖé€™ä盿‰€æœ‰äžčŗ´åĨ—äģļ。 + +## 授æŦŠ + +čŠ˛é …į›ŽéĩåžĒ MIT č¨ąå¯å”č­°ã€‚ diff --git a/docs/zh-hant/mkdocs.yml b/docs/zh-hant/mkdocs.yml new file mode 100644 index 0000000000..de18856f44 --- /dev/null +++ b/docs/zh-hant/mkdocs.yml @@ -0,0 +1 @@ +INHERIT: ../en/mkdocs.yml diff --git a/scripts/docs.py b/scripts/docs.py index 37a7a34779..0643e414f5 100644 --- a/scripts/docs.py +++ b/scripts/docs.py @@ -76,8 +76,6 @@ def callback() -> None: def new_lang(lang: str = typer.Argument(..., callback=lang_callback)): """ Generate a new docs translation directory for the language LANG. - - LANG should be a 2-letter language code, like: en, es, de, pt, etc. """ new_path: Path = Path("docs") / lang if new_path.exists(): From d74b3b25659b42233a669f032529880de8bd6c2d Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 17 Jan 2024 17:15:47 +0000 Subject: [PATCH 129/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a969545270..d5117ccd1d 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Initialize translations for Traditional Chinese. PR [#10505](https://github.com/tiangolo/fastapi/pull/10505) by [@hsuanchi](https://github.com/hsuanchi). * âœī¸ Tweak the german translation of `docs/de/docs/tutorial/index.md`. PR [#10962](https://github.com/tiangolo/fastapi/pull/10962) by [@nilslindemann](https://github.com/nilslindemann). * âœī¸ Fix typo error in `docs/ko/docs/tutorial/path-params.md`. PR [#10758](https://github.com/tiangolo/fastapi/pull/10758) by [@2chanhaeng](https://github.com/2chanhaeng). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/dependencies/dependencies-with-yield.md`. PR [#1961](https://github.com/tiangolo/fastapi/pull/1961) by [@SwftAlpc](https://github.com/SwftAlpc). From c3019096e7cc7605a192712c6f7c1bafa1b3b57f Mon Sep 17 00:00:00 2001 From: Kani Kim Date: Sat, 20 Jan 2024 08:04:42 +0900 Subject: [PATCH 130/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/learn/index.md`=20(#10977)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/learn/index.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/ko/docs/learn/index.md diff --git a/docs/ko/docs/learn/index.md b/docs/ko/docs/learn/index.md new file mode 100644 index 0000000000..7ac3a99b64 --- /dev/null +++ b/docs/ko/docs/learn/index.md @@ -0,0 +1,5 @@ +# ë°°ėš°ę¸° + +ė—Ŧ기 **FastAPI**ëĨŧ ë°°ėš°ę¸° ėœ„í•œ ėž…ëŦ¸ ėžëŖŒė™€ ėžėŠĩė„œę°€ ėžˆėŠĩ니다. + +ė—ŦëŸŦëļ„ė€ FastAPIëĨŧ ë°°ėš°ę¸° ėœ„í•´ **ėą…**, **ę°•ė˜**, **ęŗĩė‹ ėžëŖŒ** ꡸ëĻŦęŗ  ėļ”ė˛œë°›ė€ ë°Šë˛•ė„ ęŗ ë ¤í•  눘 ėžˆėŠĩ니다. 😎 From 510c7a56a412302270c34ddfbbdd345a96870d23 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 19 Jan 2024 23:05:10 +0000 Subject: [PATCH 131/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d5117ccd1d..7ca9c17a56 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/learn/index.md`. PR [#10977](https://github.com/tiangolo/fastapi/pull/10977) by [@KaniKim](https://github.com/KaniKim). * 🌐 Initialize translations for Traditional Chinese. PR [#10505](https://github.com/tiangolo/fastapi/pull/10505) by [@hsuanchi](https://github.com/hsuanchi). * âœī¸ Tweak the german translation of `docs/de/docs/tutorial/index.md`. PR [#10962](https://github.com/tiangolo/fastapi/pull/10962) by [@nilslindemann](https://github.com/nilslindemann). * âœī¸ Fix typo error in `docs/ko/docs/tutorial/path-params.md`. PR [#10758](https://github.com/tiangolo/fastapi/pull/10758) by [@2chanhaeng](https://github.com/2chanhaeng). From 62e6c888b79e0ad93656dbdfc0b8310de06ae7b5 Mon Sep 17 00:00:00 2001 From: Alejandra <90076947+alejsdev@users.noreply.github.com> Date: Mon, 22 Jan 2024 13:43:10 -0500 Subject: [PATCH 132/305] =?UTF-8?q?=F0=9F=94=A7=20Update=20config=20in=20`?= =?UTF-8?q?label-approved.yml`=20to=20accept=20translations=20with=201=20r?= =?UTF-8?q?eviewer=20(#11007)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/label-approved.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/label-approved.yml b/.github/workflows/label-approved.yml index 62daf26080..51be2413d6 100644 --- a/.github/workflows/label-approved.yml +++ b/.github/workflows/label-approved.yml @@ -17,3 +17,11 @@ jobs: - uses: docker://tiangolo/label-approved:0.0.4 with: token: ${{ secrets.FASTAPI_LABEL_APPROVED }} + config: > + { + "approved-1": + { + "number": 1, + "await_label": "awaiting-review" + } + } From 60ea8f85a1fdac21f907ba5e21a09d935829b79a Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 18:43:31 +0000 Subject: [PATCH 133/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7ca9c17a56..270d5e46a7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -72,6 +72,7 @@ hide: ### Internal +* 🔧 Update config in `label-approved.yml` to accept translations with 1 reviewer. PR [#11007](https://github.com/tiangolo/fastapi/pull/11007) by [@alejsdev](https://github.com/alejsdev). * 👷 Add changes-requested handling in GitHub Action issue manager. PR [#10971](https://github.com/tiangolo/fastapi/pull/10971) by [@tiangolo](https://github.com/tiangolo). * 🔧 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). From 2fe1a1387b1c9bbcbb7f701e15472e491295bf59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 22 Jan 2024 20:26:14 +0100 Subject: [PATCH 134/305] =?UTF-8?q?=F0=9F=94=A8=20Verify=20`mkdocs.yml`=20?= =?UTF-8?q?languages=20in=20CI,=20update=20`docs.py`=20(#11009)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-docs.yml | 4 ++-- docs/en/mkdocs.yml | 6 ++++-- scripts/build-docs.sh | 2 +- scripts/docs.py | 32 +++++++++++++++++++++++++++++++- 4 files changed, 38 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-docs.yml b/.github/workflows/build-docs.yml index abf2b90f68..7783161b9f 100644 --- a/.github/workflows/build-docs.yml +++ b/.github/workflows/build-docs.yml @@ -57,8 +57,8 @@ jobs: pip install git+https://${{ secrets.FASTAPI_MKDOCS_MATERIAL_INSIDERS }}@github.com/squidfunk/mkdocs-material-insiders.git pip install git+https://${{ secrets.FASTAPI_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/griffe-typing-deprecated.git pip install git+https://${{ secrets.FASTAPI_MKDOCS_MATERIAL_INSIDERS }}@github.com/pawamoy-insiders/mkdocstrings-python.git - - name: Verify README - run: python ./scripts/docs.py verify-readme + - name: Verify Docs + run: python ./scripts/docs.py verify-docs - name: Export Language Codes id: show-langs run: | diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index fcac555eb6..e965f4f28f 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -242,7 +242,7 @@ markdown_extensions: format: !!python/name:pymdownx.superfences.fence_code_format '' pymdownx.tabbed: alternate_style: true - pymdownx.tilde: + pymdownx.tilde: null attr_list: null md_in_html: null extra: @@ -267,6 +267,8 @@ extra: alternate: - link: / name: en - English + - link: /bn/ + name: bn - āĻŦāĻžāĻ‚āϞāĻž - link: /de/ name: de - Deutsch - link: /es/ @@ -304,7 +306,7 @@ extra: - link: /zh/ name: zh - æą‰č¯­ - link: /zh-hant/ - name: zh - įšéĢ”ä¸­æ–‡ + name: zh-hant - įšéĢ”ä¸­æ–‡ - link: /em/ name: 😉 extra_css: diff --git a/scripts/build-docs.sh b/scripts/build-docs.sh index ebf864afa3..7aa0a9a47f 100755 --- a/scripts/build-docs.sh +++ b/scripts/build-docs.sh @@ -4,5 +4,5 @@ set -e set -x # Check README.md is up to date -python ./scripts/docs.py verify-readme +python ./scripts/docs.py verify-docs python ./scripts/docs.py build-all diff --git a/scripts/docs.py b/scripts/docs.py index 0643e414f5..59578a820c 100644 --- a/scripts/docs.py +++ b/scripts/docs.py @@ -266,7 +266,7 @@ def live( mkdocs.commands.serve.serve(dev_addr="127.0.0.1:8008") -def update_config() -> None: +def get_updated_config_content() -> Dict[str, Any]: config = get_en_config() languages = [{"en": "/"}] new_alternate: List[Dict[str, str]] = [] @@ -294,12 +294,42 @@ def update_config() -> None: new_alternate.append({"link": url, "name": use_name}) new_alternate.append({"link": "/em/", "name": "😉"}) config["extra"]["alternate"] = new_alternate + return config + + +def update_config() -> None: + config = get_updated_config_content() en_config_path.write_text( yaml.dump(config, sort_keys=False, width=200, allow_unicode=True), encoding="utf-8", ) +@app.command() +def verify_config() -> None: + """ + Verify main mkdocs.yml content to make sure it uses the latest language names. + """ + typer.echo("Verifying mkdocs.yml") + config = get_en_config() + updated_config = get_updated_config_content() + if config != updated_config: + typer.secho( + "docs/en/mkdocs.yml outdated from docs/language_names.yml, " + "update language_names.yml and run " + "python ./scripts/docs.py update-languages", + color=typer.colors.RED, + ) + raise typer.Abort() + typer.echo("Valid mkdocs.yml ✅") + + +@app.command() +def verify_docs(): + verify_readme() + verify_config() + + @app.command() def langs_json(): langs = [] From 896f171aa2836765f359418742a416086021afc0 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:26:37 +0000 Subject: [PATCH 135/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 270d5e46a7..133ca03b3c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -72,6 +72,7 @@ hide: ### Internal +* 🔨 Verify `mkdocs.yml` languages in CI, update `docs.py`. PR [#11009](https://github.com/tiangolo/fastapi/pull/11009) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update config in `label-approved.yml` to accept translations with 1 reviewer. PR [#11007](https://github.com/tiangolo/fastapi/pull/11007) by [@alejsdev](https://github.com/alejsdev). * 👷 Add changes-requested handling in GitHub Action issue manager. PR [#10971](https://github.com/tiangolo/fastapi/pull/10971) by [@tiangolo](https://github.com/tiangolo). * 🔧 Group dependencies on dependabot updates. PR [#10952](https://github.com/tiangolo/fastapi/pull/10952) by [@Kludex](https://github.com/Kludex). From 01d774d38cb653504e6b1a9b942c9d2dc7238e1d Mon Sep 17 00:00:00 2001 From: Spike Ho Yeol Lee Date: Tue, 23 Jan 2024 04:31:27 +0900 Subject: [PATCH 136/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/body-nested-models.md`=20(#25?= =?UTF-8?q?06)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/body-nested-models.md | 243 ++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 docs/ko/docs/tutorial/body-nested-models.md diff --git a/docs/ko/docs/tutorial/body-nested-models.md b/docs/ko/docs/tutorial/body-nested-models.md new file mode 100644 index 0000000000..7b41aa35b9 --- /dev/null +++ b/docs/ko/docs/tutorial/body-nested-models.md @@ -0,0 +1,243 @@ +# ëŗ¸ëŦ¸ - ė¤‘ė˛Š ëĒ¨ë¸ + +**FastAPI**ëĨŧ ė´ėšŠí•˜ëŠ´ (Pydantic 덕ëļ„뗐) 단독ėœŧ로 ęšŠė´ ė¤‘ė˛Šëœ ëĒ¨ë¸ė„ ė •ė˜, 검ėĻ, ëŦ¸ė„œí™”하ëа ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. +## ëĻŦėŠ¤íŠ¸ 필드 + +ė–´íŠ¸ëĻŦ뷰트ëĨŧ ė„œë¸Œíƒ€ėž…ėœŧ로 ė •ė˜í•  눘 ėžˆėŠĩ니다. 똈ëĨŧ ë“¤ė–´ íŒŒė´ėŦ `list`는: + +```Python hl_lines="14" +{!../../../docs_src/body_nested_models/tutorial001.py!} +``` + +ė´ëŠ” `tags`ëĨŧ 항ëĒŠ ëĻŦėŠ¤íŠ¸ëĄœ 만듭니다. 각 항ëĒŠė˜ íƒ€ėž…ė„ ė„ ė–¸í•˜ė§€ ė•Šë”ëŧë„ėš”. + +## íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜ę°€ ėžˆëŠ” ëĻŦėŠ¤íŠ¸ 필드 + +í•˜ė§€ë§Œ íŒŒė´ėŦė€ 내ëļ€ė˜ íƒ€ėž…ė´ë‚˜ "íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜"ëĨŧ ė„ ė–¸í•  눘 ėžˆëŠ” íŠšė • ë°Šë˛•ė´ ėžˆėŠĩ니다: + +### typingė˜ `List` ėž„íŦ트 + +ë¨ŧė €, íŒŒė´ėŦ í‘œė¤€ `typing` ëĒ¨ë“ˆė—ė„œ `List`ëĨŧ ėž„íŦ트합니다: + +```Python hl_lines="1" +{!../../../docs_src/body_nested_models/tutorial002.py!} +``` + +### íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜ëĄœ `List` ė„ ė–¸ + +`list`, `dict`, `tuple`ęŗŧ ę°™ė€ íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜(내ëļ€ íƒ€ėž…)ëĨŧ 갖는 íƒ€ėž…ė„ ė„ ė–¸í•˜ë ¤ëŠ´: + +* `typing` ëĒ¨ë“ˆė—ė„œ ėž„íŦ트 +* 대괄호ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ "íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜"로 내ëļ€ íƒ€ėž… ė „ë‹Ŧ: `[` 및 `]` + +```Python +from typing import List + +my_list: List[str] +``` + +ė´ ëĒ¨ë“  ę˛ƒė€ íƒ€ėž… ė„ ė–¸ė„ ėœ„í•œ í‘œė¤€ íŒŒė´ėŦ ëŦ¸ë˛•ėž…ë‹ˆë‹¤. + +내ëļ€ íƒ€ėž…ė„ 갖는 ëĒ¨ë¸ ė–´íŠ¸ëĻŦëˇ°íŠ¸ė— 대해 동ėŧ한 í‘œė¤€ ëŦ¸ë˛•ė„ ė‚ŦėšŠí•˜ė„¸ėš”. + +마ė°Ŧę°€ė§€ëĄœ ė˜ˆė œė—ė„œ `tags`ëĨŧ ęĩŦ랴렁ėœŧ로 "ëŦ¸ėžė—´ė˜ ëĻŦėŠ¤íŠ¸"로 만들 눘 ėžˆėŠĩ니다: + +```Python hl_lines="14" +{!../../../docs_src/body_nested_models/tutorial002.py!} +``` + +## ė§‘í•Š íƒ€ėž… + +그런데 ėƒę°í•´ëŗ´ë‹ˆ 태그는 반ëŗĩ되늴 ė•ˆ ëŧęŗ , ęŗ ėœ í•œ(Unique) ëŦ¸ėžė—´ė´ė–´ė•ŧ 할 것 같ėŠĩ니다. + +꡸ëĻŦęŗ  íŒŒė´ėŦė€ ė§‘í•Šė„ ėœ„í•œ íŠšëŗ„í•œ ë°ė´í„° íƒ€ėž… `set`ė´ ėžˆėŠĩ니다. + +그렇다면 `Set`ė„ ėž„íŦ트 í•˜ęŗ  `tags`ëĨŧ `str`ė˜ `set`ėœŧ로 ė„ ė–¸í•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="1 14" +{!../../../docs_src/body_nested_models/tutorial003.py!} +``` + +덕ëļ„뗐 뤑ëŗĩ ë°ė´í„°ę°€ ėžˆëŠ” ėš”ė˛­ė„ ėˆ˜ė‹ í•˜ë”ëŧ도 ęŗ ėœ í•œ 항ëĒŠë“¤ė˜ ė§‘í•Šėœŧ로 ëŗ€í™˜ëŠë‹ˆë‹¤. + +꡸ëĻŦęŗ  해당 ë°ė´í„°ëĨŧ ėļœë Ĩ 할 때마다 ė†ŒėŠ¤ė— 뤑ëŗĩė´ ėžˆë”ëŧ도 ęŗ ėœ í•œ 항ëĒŠë“¤ė˜ ė§‘í•Šėœŧ로 ėļœë Ĩ됩니다. + +또한 掏뗐 따ëŧ ėŖŧė„ė´ ėƒę¸°ęŗ  ëŦ¸ė„œí™”됊니다. + +## ė¤‘ė˛Š ëĒ¨ë¸ + +Pydantic ëĒ¨ë¸ė˜ 각 ė–´íŠ¸ëĻŦ뷰트는 íƒ€ėž…ė„ 갖ėŠĩ니다. + +그런데 해당 íƒ€ėž… ėžė˛´ëĄœ 또다ëĨ¸ Pydantic ëĒ¨ë¸ė˜ íƒ€ėž…ė´ 될 눘 ėžˆėŠĩ니다. + +꡸ëŸŦë¯€ëĄœ íŠšė •í•œ ė–´íŠ¸ëĻŦëˇ°íŠ¸ė˜ ė´ëĻ„, íƒ€ėž…, 검ėĻė„ ė‚ŦėšŠí•˜ė—Ŧ 깊게 ė¤‘ė˛Šëœ JSON "ę°ė˛´"ëĨŧ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +ëĒ¨ë“  ę˛ƒė´ 단독ėœŧ로 ė¤‘ė˛ŠëŠë‹ˆë‹¤. + +### ė„œë¸ŒëĒ¨ë¸ ė •ė˜ + +똈ëĨŧ ë“¤ė–´, `Image` ëĒ¨ë¸ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="9-11" +{!../../../docs_src/body_nested_models/tutorial004.py!} +``` + +### ė„œë¸ŒëĒ¨ë“ˆė„ íƒ€ėž…ėœŧ로 ė‚ŦėšŠ + +꡸ëĻŦęŗ  ė–´íŠ¸ëĻŦëˇ°íŠ¸ė˜ íƒ€ėž…ėœŧ로 ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="20" +{!../../../docs_src/body_nested_models/tutorial004.py!} +``` + +ė´ëŠ” **FastAPI**가 ë‹¤ėŒęŗŧ 뜠ė‚Ŧ한 ëŗ¸ëŦ¸ė„ 기대한다는 ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": ["rock", "metal", "bar"], + "image": { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + } +} +``` + +ë‹¤ė‹œ 한번, **FastAPI**ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ 해당 ė„ ė–¸ė„ 함ėœŧëĄœė¨ ė–ģ는 ę˛ƒė€: + +* ė¤‘ė˛Š ëĒ¨ë¸ë„ íŽ¸ė§‘ę¸° 맀뛐(ėžë™ė™„ė„ą 등) +* ë°ė´í„° ëŗ€í™˜ +* ë°ė´í„° 검ėĻ +* ėžë™ ëŦ¸ė„œí™” + +## íŠšëŗ„í•œ íƒ€ėž…ęŗŧ 검ėĻ + +`str`, `int`, `float` 등ęŗŧ ę°™ė€ 단ėŧ íƒ€ėž…ęŗŧ는 ëŗ„ę°œëĄœ, `str`ė„ ėƒė†í•˜ëŠ” 더 ëŗĩėžĄí•œ 단ėŧ íƒ€ėž…ė„ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +ëĒ¨ë“  ė˜ĩė…˜ė„ ëŗ´ë ¤ëŠ´, Pydantic's exotic types ëŦ¸ė„œëĨŧ í™•ė¸í•˜ė„¸ėš”. ë‹¤ėŒ ėžĨė—ė„œ ëLJ氀맀 똈렜ëĨŧ ëŗŧ 눘 ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´ `Image` ëĒ¨ë¸ ė•ˆė— `url` 필드ëĨŧ `str` ëŒ€ė‹  Pydanticė˜ `HttpUrl`로 ė„ ė–¸í•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="4 10" +{!../../../docs_src/body_nested_models/tutorial005.py!} +``` + +ė´ ëŦ¸ėžė—´ė´ ėœ íš¨í•œ URLė¸ė§€ 검ė‚Ŧí•˜ęŗ  JSON ėŠ¤í‚¤ë§ˆ/OpenAPI로 ëŦ¸ė„œí™” 됩니다. + +## ė„œë¸ŒëĒ¨ë¸ ëĻŦėŠ¤íŠ¸ëĨŧ 갖는 ė–´íŠ¸ëĻŦ뷰트 + +`list`, `set` ë“ąė˜ ė„œë¸Œíƒ€ėž…ėœŧ로 Pydantic ëĒ¨ë¸ė„ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다: + +```Python hl_lines="20" +{!../../../docs_src/body_nested_models/tutorial006.py!} +``` + +ė•„ëž˜ė™€ ę°™ė€ JSON ëŗ¸ëŦ¸ėœŧ로 똈냁(ëŗ€í™˜, 검ėĻ, ëŦ¸ė„œí™” ë“ąė„)합니다: + +```JSON hl_lines="11" +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": [ + "rock", + "metal", + "bar" + ], + "images": [ + { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + }, + { + "url": "http://example.com/dave.jpg", + "name": "The Baz" + } + ] +} +``` + +!!! info "ė •ëŗ´" + `images` 키가 ė–´ë–ģ枌 ė´ë¯¸ė§€ ę°ė˛´ ëĻŦėŠ¤íŠ¸ëĨŧ ę°–ëŠ”ė§€ ėŖŧëĒŠí•˜ė„¸ėš”. + +## 깊게 ė¤‘ė˛Šëœ ëĒ¨ë¸ + +단독ėœŧ로 깊게 ė¤‘ė˛Šëœ ëĒ¨ë¸ė„ ė •ė˜í•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="9 14 20 23 27" +{!../../../docs_src/body_nested_models/tutorial007.py!} +``` + +!!! info "ė •ëŗ´" + `Offer`가 ė„ íƒė‚Ŧ항 `Image` ëĻŦėŠ¤íŠ¸ëĨŧ ė°¨ëĄ€ëĄœ 갖는 `Item` ëĻŦėŠ¤íŠ¸ëĨŧ ė–´ë–ģ枌 氀맀溠 ėžˆëŠ”ė§€ ėŖŧëĒŠí•˜ė„¸ėš” + +## 눜눘 ëĻŦėŠ¤íŠ¸ė˜ ëŗ¸ëŦ¸ + +ė˜ˆėƒë˜ëŠ” JSON ëŗ¸ëŦ¸ė˜ ėĩœėƒėœ„ ę°’ė´ JSON `array`(íŒŒė´ėŦ `list`)늴, Pydantic ëĒ¨ë¸ė—ė„œė™€ 마ė°Ŧę°€ė§€ëĄœ í•¨ėˆ˜ė˜ ë§¤ę°œëŗ€ėˆ˜ė—ė„œ íƒ€ėž…ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다: + +```Python +images: List[Image] +``` + +ė´ëĨŧ ė•„ëž˜ė˛˜ëŸŧ: + +```Python hl_lines="15" +{!../../../docs_src/body_nested_models/tutorial008.py!} +``` + +## ė–´ë””ė„œë‚˜ íŽ¸ė§‘ę¸° 맀뛐 + +꡸ëĻŦęŗ  ė–´ë””ė„œë‚˜ íŽ¸ė§‘ę¸° ė§€ė›ė„ ë°›ė„ėˆ˜ ėžˆėŠĩ니다. + +ëĻŦėŠ¤íŠ¸ 내ëļ€ í•­ëĒŠė˜ ę˛Ŋėš°ė—ë„: + + + +Pydantic ëĒ¨ë¸ ëŒ€ė‹ ė— `dict`ëĨŧ 링렑 ė‚ŦėšŠí•˜ė—Ŧ ėž‘ė—…í•  ę˛Ŋ뚰, ė´ëŸŦ한 íŽ¸ė§‘ę¸° ė§€ė›ė„ ë°›ė„ėˆ˜ ė—†ėŠĩ니다. + +í•˜ė§€ë§Œ ėˆ˜ė‹ í•œ ë”•ė…”ë„ˆëĻŦ가 ėžë™ėœŧ로 ëŗ€í™˜ë˜ęŗ  ėļœë Ĩ도 ėžë™ėœŧ로 JSONėœŧ로 ëŗ€í™˜ë˜ë¯€ëĄœ ęąąė •í•  í•„ėš”ëŠ” ė—†ėŠĩ니다. + +## 단독 `dict`ė˜ ëŗ¸ëŦ¸ + +ėŧëļ€ íƒ€ėž…ė˜ í‚¤ė™€ 다ëĨ¸ íƒ€ėž…ė˜ ę°’ė„ ė‚ŦėšŠí•˜ė—Ŧ `dict`로 ëŗ¸ëŦ¸ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +(Pydanticė„ ė‚ŦėšŠí•œ ę˛Ŋ뚰래ëŸŧ) ėœ íš¨í•œ 필드/ė–´íŠ¸ëĻŦ뷰트 ė´ëĻ„ė´ ëŦ´ė—‡ė¸ė§€ ė•Œ í•„ėš”ę°€ ė—†ėŠĩ니다. + +땄링 ëǍëĨ´ëŠ” 키ëĨŧ 받ėœŧ려는 ę˛Ŋ뚰 ėœ ėšŠí•Šë‹ˆë‹¤. + +--- + +다ëĨ¸ ėœ ėšŠí•œ ę˛Ŋėš°ëŠ” 다ëĨ¸ íƒ€ėž…ė˜ 키ëĨŧ ę°€ė§ˆ ë•Œėž…ë‹ˆë‹¤. 똈. `int`. + +ė—Ŧę¸°ė„œ ꡸ ę˛Ŋ뚰ëĨŧ ëŗŧ ę˛ƒėž…ë‹ˆë‹¤. + +ė´ ę˛Ŋ뚰, `float` ę°’ė„ 氀맄 `int` 키가 ėžˆëŠ” ëĒ¨ë“  `dict`ëĨŧ ë°›ė•„ë“¤ėž…ë‹ˆë‹¤: + +```Python hl_lines="15" +{!../../../docs_src/body_nested_models/tutorial009.py!} +``` + +!!! tip "팁" + JSONė€ 똤링 `str`형 키만 ė§€ė›í•œë‹¤ëŠ” ę˛ƒė„ ė—ŧë‘ė— ë‘ė„¸ėš”. + + í•˜ė§€ë§Œ Pydanticė€ ėžë™ ë°ė´í„° ëŗ€í™˜ė´ ėžˆėŠĩ니다. + + ėω, API 클ëŧė´ė–¸íŠ¸ę°€ ëŦ¸ėžė—´ė„ 키로 ëŗ´ë‚´ë”ëŧ도 해당 ëŦ¸ėžė—´ė´ ėˆœėˆ˜í•œ ė •ėˆ˜ëĨŧ íŦ함하는한 Pydanticė€ ė´ëĨŧ ëŗ€í™˜í•˜ęŗ  검ėĻí•Šë‹ˆë‹¤. + + ꡸ëŸŦë¯€ëĄœ `weights`로 ë°›ė€ `dict`는 ė‹¤ė œëĄœ `int` í‚¤ė™€ `float` ę°’ė„ ę°€ė§‘ë‹ˆë‹¤. + +## ėš”ė•Ŋ + +**FastAPI**ëĨŧ ė‚ŦėšŠí•˜ëŠ´ Pydantic ëĒ¨ë¸ė´ 렜ęŗĩ하는 ėĩœëŒ€ ėœ ė—°ė„ąė„ í™•ëŗ´í•˜ëŠ´ė„œ ėŊ”드ëĨŧ ę°„ë‹¨í•˜ęŗ  맧枌, ꡸ëĻŦęŗ  ėš°ė•„í•˜ę˛Œ ėœ ė§€í•  눘 ėžˆėŠĩ니다. + +ëŦŧ률 ė•„ëž˜ė˜ ė´ė ë„ ėžˆėŠĩ니다: + +* íŽ¸ė§‘ę¸° 맀뛐 (ėžë™ė™„ė„ąė´ ė–´ë””ė„œë‚˜!) +* ë°ė´í„° ëŗ€í™˜ (ėŧëĒ… íŒŒė‹ą/링ë Ŧ화) +* ë°ė´í„° 검ėĻ +* ėŠ¤í‚¤ë§ˆ ëŦ¸ė„œí™” +* ėžë™ ëŦ¸ė„œ From 5fb87313e20c68146c653cdb249e28fead4c7dd4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:31:48 +0000 Subject: [PATCH 137/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 133ca03b3c..0e4da3b9fe 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-nested-models.md`. PR [#2506](https://github.com/tiangolo/fastapi/pull/2506) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/learn/index.md`. PR [#10977](https://github.com/tiangolo/fastapi/pull/10977) by [@KaniKim](https://github.com/KaniKim). * 🌐 Initialize translations for Traditional Chinese. PR [#10505](https://github.com/tiangolo/fastapi/pull/10505) by [@hsuanchi](https://github.com/hsuanchi). * âœī¸ Tweak the german translation of `docs/de/docs/tutorial/index.md`. PR [#10962](https://github.com/tiangolo/fastapi/pull/10962) by [@nilslindemann](https://github.com/nilslindemann). From 2a8f8d1ac0edd0f021094d1afd82cbd690565d4c Mon Sep 17 00:00:00 2001 From: JRIM Date: Tue, 23 Jan 2024 04:34:47 +0900 Subject: [PATCH 138/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/python-types.md`=20(#2267)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/python-types.md | 315 +++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 docs/ko/docs/python-types.md diff --git a/docs/ko/docs/python-types.md b/docs/ko/docs/python-types.md new file mode 100644 index 0000000000..16b93a7a94 --- /dev/null +++ b/docs/ko/docs/python-types.md @@ -0,0 +1,315 @@ +# íŒŒė´ėŦ íƒ€ėž… ė†Œę°œ + +íŒŒė´ėŦė€ ė„ íƒė ėœŧ로 "íƒ€ėž… 힌트(type hints)"ëĨŧ ė§€ė›í•Šë‹ˆë‹¤. + +ė´ëŸŦ한 **íƒ€ėž… 힌트**ë“¤ė€ ëŗ€ėˆ˜ė˜ íƒ€ėž…ė„ ė„ ė–¸í•  눘 ėžˆę˛Œ 해ėŖŧ는 íŠšėˆ˜í•œ ęĩŦëŦ¸ėž…니다. + +ëŗ€ėˆ˜ė˜ íƒ€ėž…ė„ ė§€ė •í•˜ëŠ´ ė—ë””í„°ė™€ íˆ´ė´ 더 ë§Žė€ ë„ė›€ė„ 뤄 눘 ėžˆę˛Œ 됩니다. + +ė´ ëŦ¸ė„œëŠ” íŒŒė´ėŦ íƒ€ėž… ížŒíŠ¸ė— 대한 **ëš ëĨ¸ ėžėŠĩė„œ / ë‚´ėšŠí™˜ę¸°** ėˆ˜ė¤€ė˜ ëŦ¸ė„œėž…니다. ė—Ŧę¸°ė„œëŠ” **FastAPI**ëĨŧ 듰揰 ėœ„í•œ ėĩœė†Œí•œė˜ ë‚´ėšŠë§Œė„ ë‹¤ëŖšë‹ˆë‹¤. + +**FastAPI**는 íƒ€ėž… ížŒíŠ¸ė— ę¸°ë°˜ė„ ë‘ęŗ  ėžˆėœŧ늰, ė´ëŠ” ë§Žė€ ėžĨ렐ęŗŧ ė´ėĩė´ ėžˆėŠĩ니다. + +비록 **FastAPI**ëĨŧ ė“°ė§€ ė•ŠëŠ”ë‹¤ęŗ  하더ëŧ도, ėĄ°ę¸ˆė´ëŧ도 ė•Œė•„ë‘ëŠ´ ë„ė›€ė´ 될 ę˛ƒėž…ë‹ˆë‹¤. + +!!! note "및溠" + íŒŒė´ėŦ뗐 ëŠĨėˆ™í•˜ė…”ė„œ íƒ€ėž… ížŒíŠ¸ė— 대해 ëĒ¨ë‘ ė•„ė‹ ë‹¤ëŠ´, ë‹¤ėŒ ėą•í„°ëĄœ ęą´ë„ˆë›°ė„¸ėš”. + +## 동기 ëļ€ė—Ŧ + +간단한 똈렜ëļ€í„° ė‹œėž‘í•´ë´…ė‹œë‹¤: + +```Python +{!../../../docs_src/python_types/tutorial001.py!} +``` + +ė´ í”„ëĄœęˇ¸ëž¨ė„ ė‹¤í–‰í•œ 결ęŗŧ값: + +``` +John Doe +``` + +í•¨ėˆ˜ëŠ” ė•„ëž˜ė™€ ę°™ė´ ė‹¤í–‰ëŠë‹ˆë‹¤: + +* `first_name`ęŗŧ `last_name`ëĨŧ 받ėŠĩ니다. +* `title()`로 각 ė˛Ģ ëŦ¸ėžëĨŧ 대ëŦ¸ėžëĄœ ëŗ€í™˜ė‹œí‚ĩ니다. +* 두 ë‹¨ė–´ëĨŧ 뤑氄뗐 ęŗĩë°ąė„ ë‘ęŗ  ė—°ę˛°í•Šë‹ˆë‹¤. + +```Python hl_lines="2" +{!../../../docs_src/python_types/tutorial001.py!} +``` + +### ėŊ”드 ėˆ˜ė • + +ė´ęą´ ë§¤ėš° 간단한 í”„ëĄœęˇ¸ëž¨ėž…ë‹ˆë‹¤. + +그런데 ė˛˜ėŒëļ€í„° ėž‘ė„ąí•œë‹¤ęŗ  ėƒę°ė„ í•´ë´…ė‹œë‹¤. + +ė—ŦëŸŦëļ„ė€ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė¤€ëš„í–ˆęŗ , í•¨ėˆ˜ëĨŧ ė •ė˜í•˜ę¸° ė‹œėž‘í–ˆė„ 겁니다. + +ė´ë•Œ "ė˛Ģ ę¸€ėžëĨŧ 대ëŦ¸ėžëĄœ 바꾸는 í•¨ėˆ˜"ëĨŧ 호ėļœí•´ė•ŧ 합니다. + +`upper`ė˜€ë‚˜? ė•„ë‹ˆëŠ´ `uppercase`? `first_uppercase`? `capitalize`? + +그때 ę°œë°œėžë“¤ė˜ ė˜¤ëžœ ėšœęĩŦ, ė—ë””í„° ėžë™ė™„ė„ąė„ ė‹œë„í•´ë´…ë‹ˆë‹¤. + +ë‹šė‹ ė€ `first_name`ëĨŧ ėž…ë Ĩ한 뒤 렐(`.`)ė„ ėž…ë Ĩí•˜ęŗ  ėžë™ė™„ė„ąė„ ėŧœę¸° ėœ„í•´ė„œ `Ctrl+Space`ëĨŧ 눌렀ėŠĩ니다. + +í•˜ė§€ë§Œ ėŠŦ프게도 ė•„ëŦ´ëŸ° ë„ė›€ė´ ë˜ė§€ ė•ŠėŠĩ니다: + + + +### íƒ€ėž… ėļ”ę°€í•˜ę¸° + +ė´ė „ ë˛„ė „ė—ė„œ 한 ė¤„ë§Œ ėˆ˜ė •í•´ë´…ė‹œë‹¤. + +ė €íŦ는 ė´ í•¨ėˆ˜ė˜ ë§¤ę°œëŗ€ėˆ˜ ëļ€ëļ„: + +```Python + first_name, last_name +``` + +ė„ ė•„ëž˜ė™€ ę°™ė´ 바ęŋ€ 겁니다: + +```Python + first_name: str, last_name: str +``` + +ė´ę˛Œ ë‹¤ėž…ë‹ˆë‹¤. + +ė´ę˛Œ "íƒ€ėž… 힌트"ėž…ë‹ˆë‹¤: + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial002.py!} +``` + +íƒ€ėž…ížŒíŠ¸ëŠ” ë‹¤ėŒęŗŧ ę°™ė´ ę¸°ëŗ¸ ę°’ė„ ė„ ė–¸í•˜ëŠ” 것ęŗŧ는 다ëĻ…ë‹ˆë‹¤: + +```Python + first_name="john", last_name="doe" +``` + +ė´ëŠ” 다ëĨ¸ ę˛ƒėž…ë‹ˆë‹¤. + +등호(`=`) ëŒ€ė‹  ėŊœëĄ (`:`)ė„ ė“°ęŗ  ėžˆėŠĩ니다. + +ėŧë°˜ė ėœŧ로 íƒ€ėž…ížŒíŠ¸ëĨŧ ėļ”ę°€í•œë‹¤ęŗ  í•´ė„œ íŠšëŗ„í•˜ę˛Œ ė–´ë–¤ ėŧė´ ėŧė–´ë‚˜ė§€ë„ ė•ŠėŠĩ니다. + +ęˇ¸ë ‡ė§€ë§Œ ė´ė œ, ë‹¤ė‹œ í•¨ėˆ˜ëĨŧ 만드는 ë„ė¤‘ė´ëŧęŗ  ėƒę°í•´ë´…ė‹œë‹¤. 다만 ė´ë˛ˆė—” íƒ€ėž… 힌트가 ėžˆėŠĩ니다. + +ę°™ė€ ėƒí™Šė—ė„œ `Ctrl+Space`로 ėžë™ė™„ė„ąė„ ėž‘ë™ė‹œí‚¤ëŠ´, + + + +ė•„ëž˜ė™€ ę°™ė´ "ęˇ¸ë ‡ė§€!"하는 ė˜ĩė…˜ė´ 나ė˜Ŧë•ŒęšŒė§€ 늤íŦëĄ¤ė„ ë‚´ë ¤ė„œ ëŗŧ 눘 ėžˆėŠĩ니다: + + + +## 더 큰 동기ëļ€ė—Ŧ + +ė•„ëž˜ í•¨ėˆ˜ëĨŧ ëŗ´ëŠ´, ė´ë¯¸ íƒ€ėž… 힌트가 ė ėšŠë˜ė–´ ėžˆëŠ” 깸 ëŗŧ 눘 ėžˆėŠĩ니다: + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial003.py!} +``` + +íŽ¸ė§‘ę¸°ę°€ ëŗ€ėˆ˜ė˜ íƒ€ėž…ė„ ė•Œęŗ  ėžˆę¸° 때ëŦ¸ė—, ėžë™ė™„ė„ą ëŋ ė•„ë‹ˆëŧ 뗐ëŸŦ도 í™•ė¸í•  눘 ėžˆėŠĩ니다: + + + +ė´ė œ 溠뺐ė•ŧ하는 깸 ė•Œę¸° 때ëŦ¸ė—, `age`ëĨŧ `str(age)`ęŗŧ ę°™ė´ ëŦ¸ėžė—´ëĄœ 바꾸게 됩니다: + +```Python hl_lines="2" +{!../../../docs_src/python_types/tutorial004.py!} +``` + +## íƒ€ėž… ė„ ė–¸ + +밊금 í•¨ėˆ˜ė˜ ë§¤ę°œëŗ€ėˆ˜ëĄœė¨ íƒ€ėž… 힌트ëĨŧ ė„ ė–¸í•˜ëŠ” ėŖŧėš” ėžĨė†ŒëĨŧ ëŗ´ė•˜ėŠĩ니다. + +ė´ ėœ„ėš˜ëŠ” ė—ŦëŸŦëļ„ė´ **FastAPI**뙀 함ęģ˜ ė´ëĨŧ ė‚ŦėšŠí•˜ëŠ” ėŖŧėš” ėžĨė†Œėž…ë‹ˆë‹¤. + +### Simple íƒ€ėž… + +`str`ëŋ ė•„ë‹ˆëŧ ëĒ¨ë“  íŒŒė´ėŦ í‘œė¤€ íƒ€ėž…ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +똈ëĨŧ 들면: + +* `int` +* `float` +* `bool` +* `bytes` + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial005.py!} +``` + +### íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜ëĨŧ í™œėšŠí•œ Generic(ė œë„¤ëĻ­) íƒ€ėž… + +`dict`, `list`, `set`, `tuple`ęŗŧ ę°™ė€ ę°’ė„ ė €ėžĨ할 눘 ėžˆëŠ” ë°ė´í„° ęĩŦėĄ°ę°€ ėžˆęŗ , 내ëļ€ė˜ ę°’ė€ ę°ėžė˜ íƒ€ėž…ė„ ę°€ė§ˆ ėˆ˜ë„ ėžˆėŠĩ니다. + +íƒ€ėž…ęŗŧ 내ëļ€ íƒ€ėž…ė„ ė„ ė–¸í•˜ę¸° ėœ„í•´ė„œëŠ” íŒŒė´ėŦ í‘œė¤€ ëĒ¨ë“ˆė¸ `typing`ė„ ė´ėšŠí•´ė•ŧ 합니다. + +ęĩŦ랴렁ėœŧ로는 ė•„ëž˜ íƒ€ėž… 힌트ëĨŧ ė§€ė›í•Šë‹ˆë‹¤. + +#### `List` + +똈ëĨŧ 들면, `str`ė˜ `list`ė¸ ëŗ€ėˆ˜ëĨŧ ė •ė˜í•´ë´…ė‹œë‹¤. + +`typing`ė—ė„œ `List`(대ëŦ¸ėž `L`)ëĨŧ import 합니다. + +```Python hl_lines="1" +{!../../../docs_src/python_types/tutorial006.py!} +``` + +ėŊœëĄ (`:`) ëŦ¸ë˛•ė„ ė´ėšŠí•˜ė—Ŧ ëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•Šë‹ˆë‹¤. + +íƒ€ėž…ėœŧ로는 `List`ëĨŧ ë„Ŗė–´ė¤ë‹ˆë‹¤. + +ė´ë•Œ ë°°ė—´ė€ 내ëļ€ íƒ€ėž…ė„ íŦ함하는 íƒ€ėž…ė´ę¸° 때ëŦ¸ė— 대괄호 ė•ˆė— ë„Ŗė–´ė¤ë‹ˆë‹¤. + +```Python hl_lines="4" +{!../../../docs_src/python_types/tutorial006.py!} +``` + +!!! tip "팁" + 대괄호 ė•ˆė˜ 내ëļ€ íƒ€ėž…ė€ "íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜(type paramters)"ëŧęŗ  합니다. + + ė´ë˛ˆ ė˜ˆė œė—ė„œëŠ” `str`ė´ `List`뗐 ë“¤ė–´ę°„ íƒ€ėž… ë§¤ę°œëŗ€ėˆ˜ ėž…ë‹ˆë‹¤. + +ė´ëŠ” "`items`ė€ `list`ė¸ë°, ë°°ė—´ė— ë“¤ė–´ėžˆëŠ” ė•„ė´í…œ ę°ę°ė€ `str`ė´ë‹¤"ëŧ는 ëœģėž…ë‹ˆë‹¤. + +ė´ë ‡ę˛Œ 함ėœŧëĄœė¨, ė—ë””í„°ëŠ” ë°°ė—´ė— ë“¤ė–´ėžˆëŠ” ė•„ė´í…œė„ 래ëĻŦ할때도 ë„ė›€ė„ 뤄 눘 ėžˆę˛Œ 됩니다: + + + +íƒ€ėž…ė´ ė—†ėœŧ늴 ė´ęą´ ęą°ė˜ ëļˆę°€ëŠĨė´ë‚˜ 다ëĻ„ ė—†ėŠĩ니다. + +ëŗ€ėˆ˜ `item`ė€ `items`ė˜ ę°œëŗ„ ėš”ė†Œëŧ는 ė‚Ŧė‹¤ė„ ė•Œė•„ë‘ė„¸ėš”. + +꡸ëĻŦęŗ  ė—ë””í„°ëŠ” ęŗ„ė† `str`ëŧ는 ė‚Ŧė‹¤ė„ ė•Œęŗ  ë„ė™€ė¤ë‹ˆë‹¤. + +#### `Tuple`ęŗŧ `Set` + +`tuple`ęŗŧ `set`도 동ėŧ하게 ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial007.py!} +``` + +ė´ ëœģė€ ė•„ëž˜ė™€ 같ėŠĩ니다: + +* ëŗ€ėˆ˜ `items_t`는, ė°¨ëĄ€ëŒ€ëĄœ `int`, `int`, `str`ė¸ `tuple`ė´ë‹¤. +* ëŗ€ėˆ˜ `items_s`는, 각 ė•„ė´í…œė´ `bytes`ė¸ `set`ė´ë‹¤. + +#### `Dict` + +`dict`ëĨŧ ė„ ė–¸í•˜ë ¤ëŠ´ ėģ´ë§ˆëĄœ ęĩŦëļ„된 2ę°œė˜ 파ëŧë¯¸í„°ę°€ í•„ėš”í•Šë‹ˆë‹¤. + +ė˛Ģ ë˛ˆė§¸ ë§¤ę°œëŗ€ėˆ˜ëŠ” `dict`ė˜ 키(key)ė´ęŗ , + +두 ë˛ˆė§¸ ë§¤ę°œëŗ€ėˆ˜ëŠ” `dict`ė˜ 값(value)ėž…ë‹ˆë‹¤. + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial008.py!} +``` + +ė´ ëœģė€ ė•„ëž˜ė™€ 같ėŠĩ니다: + +* ëŗ€ėˆ˜ `prices`는 `dict`ė´ë‹¤: + * `dict`ė˜ 키(key)는 `str`íƒ€ėž…ė´ë‹¤. (각 ė•„ė´í…œė˜ ė´ëĻ„(name)) + * `dict`ė˜ 값(value)는 `float`íƒ€ėž…ė´ë‹¤. (각 ė•„ė´í…œė˜ 가격(price)) + +#### `Optional` + +`str`ęŗŧ ę°™ė´ íƒ€ėž…ė„ ė„ ė–¸í•  때 `Optional`ė„ 듏 ėˆ˜ë„ ėžˆëŠ”ë°, "ė„ íƒė (Optional)"ė´ę¸°ë•ŒëŦ¸ė— `None`도 될 눘 ėžˆėŠĩ니다: + +```Python hl_lines="1 4" +{!../../../docs_src/python_types/tutorial009.py!} +``` + +`Optional[str]`ė„ `str` ëŒ€ė‹  ė“°ę˛Œ 되늴, íŠšė • ę°’ė´ ė‹¤ė œëĄœëŠ” `None`ė´ 될 ėˆ˜ë„ ėžˆëŠ”ë° í•­ėƒ `str`ė´ëŧęŗ  ę°€ė •í•˜ëŠ” ėƒí™Šė—ė„œ ė—ë””í„°ę°€ 뗐ëŸŦëĨŧ ė°žę˛Œ ë„ė™€ė¤„ 눘 ėžˆėŠĩ니다. + +#### Generic(ė œë„¤ëĻ­) íƒ€ėž… + +ė´ íƒ€ėž…ė€ 대괄호 ė•ˆė— ë§¤ę°œëŗ€ėˆ˜ëĨŧ ę°€ė§€ëŠ°, ėĸ…ëĨ˜ëŠ”: + +* `List` +* `Tuple` +* `Set` +* `Dict` +* `Optional` +* ...등등 + +ėœ„ė™€ ę°™ė€ íƒ€ėž…ė€ **Generic(ė œë„¤ëĻ­) íƒ€ėž…** í˜šė€ **Generics(ė œë„¤ëϭ늤)**ëŧęŗ  ëļˆëĻŊ니다. + +### íƒ€ėž…ėœŧëĄœė„œė˜ í´ëž˜ėŠ¤ + +ëŗ€ėˆ˜ė˜ íƒ€ėž…ėœŧ로 í´ëž˜ėŠ¤ëĨŧ ė„ ė–¸í•  ėˆ˜ë„ ėžˆėŠĩ니다. + +ė´ëĻ„(name)ė„ 氀맄 `Person` í´ëž˜ėŠ¤ę°€ ėžˆë‹¤ęŗ  í•´ë´…ė‹œë‹¤. + +```Python hl_lines="1-3" +{!../../../docs_src/python_types/tutorial010.py!} +``` + +그렇게 하면 ëŗ€ėˆ˜ëĨŧ `Person`ė´ëŧęŗ  ė„ ė–¸í•  눘 ėžˆę˛Œ 됩니다. + +```Python hl_lines="6" +{!../../../docs_src/python_types/tutorial010.py!} +``` + +꡸ëĻŦęŗ  ė—­ė‹œë‚˜ ëĒ¨ë“  ė—ë””í„° ë„ė›€ė„ 받게 ë˜ę˛ ėŖ . + + + +## Pydantic ëĒ¨ë¸ + +Pydanticė€ ë°ė´í„° 검ėĻ(Validation)ė„ ėœ„í•œ íŒŒė´ėŦ ëŧė´ë¸ŒëŸŦëĻŦėž…ë‹ˆë‹¤. + +ë‹šė‹ ė€ ė†ė„ąë“¤ė„ íŦ함한 í´ëž˜ėŠ¤ 형태로 "ëǍ떑(shape)"ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  각 ė†ė„ąė€ íƒ€ėž…ė„ 氀맀溠 ėžˆėŠĩ니다. + +ė´ í´ëž˜ėŠ¤ëĨŧ í™œėšŠí•˜ė—Ŧė„œ ę°’ė„ 氀맀溠 ėžˆëŠ” ė¸ėŠ¤í„´ėŠ¤ëĨŧ 만들게 되늴, í•„ėš”í•œ ę˛Ŋėš°ė—ëŠ” ė ë‹ší•œ íƒ€ėž…ėœŧ로 ëŗ€í™˜ęšŒė§€ ė‹œí‚¤ę¸°ë„ 하ė—Ŧ ë°ė´í„°ę°€ íŦ함된 ę°ė˛´ëĨŧ 반환합니다. + +꡸ëĻŦęŗ  결ęŗŧ ę°ė˛´ė— ëŒ€í•´ė„œëŠ” ė—ë””í„°ė˜ ë„ė›€ė„ ë°›ė„ 눘 ėžˆę˛Œ 됩니다. + +Pydantic ęŗĩė‹ ëŦ¸ė„œ ė˜ˆė‹œ: + +```Python +{!../../../docs_src/python_types/tutorial011.py!} +``` + +!!! info "ė •ëŗ´" + Pydantic<뗐 대해 더 ë°°ėš°ęŗ  ė‹ļ다면 ęŗĩė‹ ëŦ¸ė„œëĨŧ ė°¸ęŗ í•˜ė„¸ėš”. + + +**FastAPI**는 ëĒ¨ë‘ Pydanticė„ 기반ėœŧ로 ë˜ė–´ ėžˆėŠĩ니다. + +ė´ ëĒ¨ë“  ę˛ƒė´ ė‹¤ė œëĄœ ė–´ë–ģ枌 ė‚ŦėšŠë˜ëŠ”ė§€ė— ëŒ€í•´ė„œëŠ” [ėžėŠĩė„œ - ė‚ŦėšŠėž ė•ˆë‚´ė„œ](tutorial/index.md){.internal-link target=_blank} ė—ė„œ 더 ë§Žė´ í™•ė¸í•˜ė‹¤ 눘 ėžˆėŠĩ니다. + +## **FastAPI**ė—ė„œė˜ íƒ€ėž… 힌트 + +**FastAPI**는 ė—ŦëŸŦ ëļ€ëļ„ė—ė„œ íƒ€ėž… ížŒíŠ¸ė˜ ėžĨė ė„ ėˇ¨í•˜ęŗ  ėžˆėŠĩ니다. + +**FastAPI**ė—ė„œ íƒ€ėž… ížŒíŠ¸ė™€ 함ęģ˜ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•˜ëŠ´ ėžĨė ė€: + +* **ė—ë””í„° ë„ė›€**. +* **íƒ€ėž… í™•ė¸**. + +...꡸ëĻŦęŗ  **FastAPI**는 ę°™ė€ ė •ė˜ëĨŧ ė•„ëž˜ė—ë„ ė ėšŠí•Šë‹ˆë‹¤: + +* **ėš”ęĩŦė‚Ŧ항 ė •ė˜**: ėš”ė˛­ ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜, ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜, 헤더, 바디, ė˜ėĄ´ė„ą 등. +* **ë°ė´í„° ëŗ€í™˜**: ėš”ė˛­ė—ė„œ ėš”ęĩŦ한 íƒ€ėž…ėœŧ로. +* **ë°ė´í„° 검ėĻ**: 각 ėš”ė˛­ë§ˆë‹¤: + * ë°ė´í„°ę°€ ėœ íš¨í•˜ė§€ ė•Šė€ ę˛Ŋėš°ė—ëŠ” **ėžë™ėœŧ로 뗐ëŸŦ**ëĨŧ ë°œėƒí•Šë‹ˆë‹¤. +* OpenAPIëĨŧ í™œėšŠí•œ **API ëŦ¸ė„œí™”**: + * ėžë™ėœŧ로 ėƒí˜¸ėž‘ėšŠí•˜ëŠ” ėœ ė € ė¸í„°íŽ˜ė´ėŠ¤ė— ė“°ė´ę˛Œ 됩니다. + +ėœ„ ë‚´ėšŠė´ ë‹¤ė†Œ ėļ”ėƒė ėŧ ėˆ˜ë„ ėžˆė§€ë§Œ, ęąąė •ë§ˆė„¸ėš”. [ėžėŠĩė„œ - ė‚ŦėšŠėž ė•ˆë‚´ė„œ](tutorial/index.md){.internal-link target=_blank}ė—ė„œ ė „ëļ€ í™•ė¸ 가ëŠĨ합니다. + +가ėžĨ ė¤‘ėš”í•œ ęą´, í‘œė¤€ íŒŒė´ėŦ íƒ€ėž…ė„ 한 ęŗŗė—ė„œ(í´ëž˜ėŠ¤ëĨŧ 더하거나, 데ėŊ”ë ˆė´í„° ė‚ŦėšŠí•˜ëŠ” ëŒ€ė‹ ) ė‚ŦėšŠí•¨ėœŧëĄœė¨ **FastAPI**가 ë‹šė‹ ė„ ėœ„í•´ ë§Žė€ ėŧė„ í•´ė¤€ë‹¤ëŠ” ė‚Ŧė‹¤ė´ėŖ . + +!!! info "ė •ëŗ´" + 만ė•Ŋ ëĒ¨ë“  ėžėŠĩė„œëĨŧ 다 ëŗ´ė•˜ėŒė—ë„ íƒ€ėž…ė— ëŒ€í•´ė„œ 더 ëŗ´ęŗ ėž ë°ŠëŦ¸í•œ ę˛Ŋėš°ė—ëŠ” `mypy`ė—ė„œ 렜ęŗĩ하는 "cheat sheet"ė´ ėĸ‹ė€ ėžëŖŒę°€ 될 겁니다. From eea7635713bdda4a2ad9393efe5a720d15a22122 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:36:25 +0000 Subject: [PATCH 139/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0e4da3b9fe..2eb764e1e7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/python-types.md`. PR [#2267](https://github.com/tiangolo/fastapi/pull/2267) by [@jrim](https://github.com/jrim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-nested-models.md`. PR [#2506](https://github.com/tiangolo/fastapi/pull/2506) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/learn/index.md`. PR [#10977](https://github.com/tiangolo/fastapi/pull/10977) by [@KaniKim](https://github.com/KaniKim). * 🌐 Initialize translations for Traditional Chinese. PR [#10505](https://github.com/tiangolo/fastapi/pull/10505) by [@hsuanchi](https://github.com/hsuanchi). From 87a4c9ef01afe9066678d655866c5f5cd8bc26c2 Mon Sep 17 00:00:00 2001 From: Spike Ho Yeol Lee Date: Tue, 23 Jan 2024 04:37:01 +0900 Subject: [PATCH 140/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/query-params-str-validations.?= =?UTF-8?q?md`=20(#2415)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tutorial/query-params-str-validations.md | 303 ++++++++++++++++++ 1 file changed, 303 insertions(+) create mode 100644 docs/ko/docs/tutorial/query-params-str-validations.md diff --git a/docs/ko/docs/tutorial/query-params-str-validations.md b/docs/ko/docs/tutorial/query-params-str-validations.md new file mode 100644 index 0000000000..7ae100dcc4 --- /dev/null +++ b/docs/ko/docs/tutorial/query-params-str-validations.md @@ -0,0 +1,303 @@ +# ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ė™€ ëŦ¸ėžė—´ 검ėĻ + +**FastAPI**ëĨŧ ė‚ŦėšŠí•˜ëŠ´ ë§¤ę°œëŗ€ėˆ˜ė— 대한 ėļ”ę°€ ė •ëŗ´ 및 검ėĻė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +ė´ ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė„ ė˜ˆëĄœ ë“¤ė–´ëŗ´ę˛ ėŠĩ니다: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial001.py!} +``` + +ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `q`는 `Optional[str]` ėžëŖŒí˜•ėž…ë‹ˆë‹¤. ėω, `str` ėžëŖŒí˜•ė´ė§€ë§Œ `None` ė—­ė‹œ 될 눘 ėžˆėŒė„ ëœģí•˜ęŗ , ė‹¤ė œëĄœ ę¸°ëŗ¸ę°’ė€ `None`ė´ę¸° 때ëŦ¸ė— FastAPI는 ė´ ë§¤ę°œëŗ€ėˆ˜ę°€ í•„ėˆ˜ę°€ ė•„ë‹ˆëŧ는 ę˛ƒė„ ė••ë‹ˆë‹¤. + +!!! note "및溠" + FastAPI는 `q`ė˜ ę¸°ëŗ¸ę°’ė´ `= None`ė´ę¸° 때ëŦ¸ė— í•„ėˆ˜ę°€ ė•„ë‹˜ė„ ė••ë‹ˆë‹¤. + + `Optional[str]`뗐 ėžˆëŠ” `Optional`ė€ FastAPI가 ė‚ŦėšŠí•˜ëŠ”ę˛Œ ė•„ë‹ˆė§€ë§Œ, íŽ¸ė§‘ę¸°ė—ę˛Œ 더 ë‚˜ė€ 맀뛐ęŗŧ 똤ëĨ˜ íƒė§€ëĨŧ 렜ęŗĩ하게 í•´ė¤ë‹ˆë‹¤. + +## ėļ”ę°€ 검ėĻ + +`q`가 ė„ íƒė ė´ė§€ë§Œ ę°’ė´ ėŖŧė–´ė§ˆ 때마다 **ę°’ė´ 50 ę¸€ėžëĨŧ 봈ęŗŧí•˜ė§€ ė•Šę˛Œ** ę°•ė œí•˜ë ¤ 합니다. + +### `Query` ėž„íŦ트 + +ė´ëĨŧ ėœ„í•´ ë¨ŧė € `fastapi`ė—ė„œ `Query`ëĨŧ ėž„íŦ트합니다: + +```Python hl_lines="3" +{!../../../docs_src/query_params_str_validations/tutorial002.py!} +``` + +## ę¸°ëŗ¸ę°’ėœŧ로 `Query` ė‚ŦėšŠ + +ė´ė œ `Query`ëĨŧ ë§¤ę°œëŗ€ėˆ˜ė˜ ę¸°ëŗ¸ę°’ėœŧ로 ė‚ŦėšŠí•˜ė—Ŧ `max_length` ë§¤ę°œëŗ€ėˆ˜ëĨŧ 50ėœŧ로 ė„¤ė •í•Šë‹ˆë‹¤: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial002.py!} +``` + +ę¸°ëŗ¸ę°’ `None`ė„ `Query(None)`ėœŧ로 바ęŋ”ė•ŧ í•˜ë¯€ëĄœ, `Query`ė˜ ė˛Ģ ë˛ˆė§¸ ë§¤ę°œëŗ€ėˆ˜ëŠ” ę¸°ëŗ¸ę°’ė„ ė •ė˜í•˜ëŠ” 것ęŗŧ ę°™ė€ ëĒŠė ėœŧ로 ė‚ŦėšŠëŠë‹ˆë‹¤. + +꡸ëŸŦë¯€ëĄœ: + +```Python +q: Optional[str] = Query(None) +``` + +...ėœ„ ėŊ”드는 ė•„ëž˜ė™€ 동ėŧ하게 ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ íƒė ėœŧ로 만듭니다: + +```Python +q: Optional[str] = None +``` + +í•˜ė§€ë§Œ ëĒ…ė‹œė ėœŧ로 ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•Šë‹ˆë‹¤. + +!!! info "ė •ëŗ´" + FastAPI는 ë‹¤ėŒ ëļ€ëļ„뗐 관ė‹Ŧė´ ėžˆėŠĩ니다: + + ```Python + = None + ``` + + 또는: + + ```Python + = Query(None) + ``` + + ꡸ëĻŦęŗ  `None`ė„ ė‚ŦėšŠí•˜ė—Ŧ ėŋŧëŧ ë§¤ę°œëŗ€ėˆ˜ę°€ í•„ėˆ˜ė ė´ė§€ ė•Šë‹¤ëŠ” ę˛ƒė„ íŒŒė•…í•Šë‹ˆë‹¤. + + `Optional` ëļ€ëļ„ė€ íŽ¸ė§‘ę¸°ė—ę˛Œ 더 ë‚˜ė€ ė§€ė›ė„ 렜ęŗĩ하기 ėœ„í•´ė„œë§Œ ė‚ŦėšŠëŠë‹ˆë‹¤. + +또한 `Query`로 더 ë§Žė€ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė „ë‹Ŧ할 눘 ėžˆėŠĩ니다. ė§€ę¸ˆė˜ ę˛Ŋ뚰 ëŦ¸ėžė—´ė— ė ėšŠë˜ëŠ” `max_length` ë§¤ę°œëŗ€ėˆ˜ėž…ë‹ˆë‹¤: + +```Python +q: str = Query(None, max_length=50) +``` + +ė´ëŠ” ë°ė´í„°ëĨŧ 검ėĻí•  ę˛ƒė´ęŗ , ë°ė´í„°ę°€ ėœ íš¨í•˜ė§€ ė•Šë‹¤ëŠ´ ëĒ…ë°ąí•œ 똤ëĨ˜ëĨŧ ëŗ´ė—ŦėŖŧ늰, OpenAPI ėŠ¤í‚¤ë§ˆ *ę˛Ŋ로 ë™ėž‘*뗐 ë§¤ę°œëŗ€ėˆ˜ëĨŧ ëŦ¸ė„œí™” 합니다. + +## 검ėĻ ėļ”ę°€ + +ë§¤ę°œëŗ€ėˆ˜ `min_length` 또한 ėļ”가할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial003.py!} +``` + +## ė •ęˇœė‹ ėļ”ę°€ + +ë§¤ę°œëŗ€ėˆ˜ė™€ ėŧėš˜í•´ė•ŧ 하는 ė •ęˇœí‘œí˜„ė‹ė„ ė •ė˜í•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="10" +{!../../../docs_src/query_params_str_validations/tutorial004.py!} +``` + +ė´ íŠšė • ė •ęˇœí‘œí˜„ė‹ė€ ė „ë‹Ŧ ë°›ė€ ë§¤ę°œëŗ€ėˆ˜ ę°’ė„ 검ė‚Ŧ합니다: + +* `^`: ė´ė „ė— ëŦ¸ėžę°€ 뗆溠 뒤따ëĨ´ëŠ” ëŦ¸ėžëĄœ ė‹œėž‘í•Šë‹ˆë‹¤. +* `fixedquery`: ė •í™•ížˆ `fixedquery` ę°’ė„ 갖ėŠĩ니다. +* `$`: ė—Ŧę¸°ė„œ ëë‚˜ęŗ  `fixedquery` ė´í›„ëĄœ ė•„ëŦ´ ëŦ¸ėžë„ ę°–ė§€ ė•ŠėŠĩ니다. + +**"ė •ęˇœí‘œí˜„ė‹"** ę°œë…ė— 대해 ėƒė‹¤ę°ė„ 느ęŧˆë‹¤ëŠ´ ęąąė •í•˜ė§€ ė•Šė•„ë„ 됩니다. ë§Žė€ ė‚ŦëžŒė—ę˛Œ ė–´ë ¤ėš´ ėŖŧė œėž…ë‹ˆë‹¤. ė•„ė§ė€ ė •ęˇœí‘œí˜„ė‹ ė—†ė´ë„ ë§Žė€ ėž‘ė—…ë“¤ė„ 할 눘 ėžˆėŠĩ니다. + +í•˜ė§€ë§Œ ė–¸ė œë“ ė§€ ę°€ė„œ ë°°ėš¸ėˆ˜ ėžˆęŗ , **FastAPI**ė—ė„œ 링렑 ė‚ŦėšŠí•  눘 ėžˆë‹¤ëŠ” ė‚Ŧė‹¤ė„ ė•Œęŗ  ėžˆė–´ė•ŧ 합니다. + +## ę¸°ëŗ¸ę°’ + +ę¸°ëŗ¸ę°’ėœŧ로 ė‚ŦėšŠí•˜ëŠ” ė˛Ģ ë˛ˆė§¸ ė¸ėžëĄœ `None`ė„ ė „ë‹Ŧí•˜ë“¯ė´, 다ëĨ¸ ę°’ė„ ė „ë‹Ŧ할 눘 ėžˆėŠĩ니다. + +`min_length`가 `3`ė´ęŗ , ę¸°ëŗ¸ę°’ė´ `"fixedquery"`ė¸ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `q`ëĨŧ ė„ ė–¸í•´ë´…ė‹œë‹¤: + +```Python hl_lines="7" +{!../../../docs_src/query_params_str_validations/tutorial005.py!} +``` + +!!! note "및溠" + ę¸°ëŗ¸ę°’ė„ 갖는 것만ėœŧ로 ë§¤ę°œëŗ€ėˆ˜ëŠ” ė„ íƒė ė´ 됩니다. + +## í•„ėˆ˜ëĄœ 만들기 + +더 ë§Žė€ 검ėĻė´ë‚˜ ëŠ”íƒ€ë°ė´í„°ëĨŧ ė„ ė–¸í•  í•„ėš”ę°€ ė—†ëŠ” ę˛Ŋ뚰, ë‹¤ėŒęŗŧ ę°™ė´ ę¸°ëŗ¸ę°’ė„ ė„ ė–¸í•˜ė§€ ė•Šęŗ  ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `q`ëĨŧ í•„ėˆ˜ëĄœ 만들 눘 ėžˆėŠĩ니다: + +```Python +q: str +``` + +ė•„ëž˜ ëŒ€ė‹ : + +```Python +q: Optional[str] = None +``` + +꡸ëŸŦ나 ė´ė œ ë‹¤ėŒęŗŧ ę°™ė´ `Query`로 ė„ ė–¸í•Šë‹ˆë‹¤: + +```Python +q: Optional[str] = Query(None, min_length=3) +``` + +ęˇ¸ëž˜ė„œ `Query`ëĨŧ í•„ėˆ˜ę°’ėœŧ로 ë§Œë“¤ė–´ė•ŧ 할 때면, ė˛Ģ ë˛ˆė§¸ ė¸ėžëĄœ `...`ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="7" +{!../../../docs_src/query_params_str_validations/tutorial006.py!} +``` + +!!! info "ė •ëŗ´" + ė´ė „ė— `...`ëĨŧ ëŗ¸ė ė´ ė—†ë‹¤ëŠ´: íŠšëŗ„í•œ 단ėŧ값ėœŧ로, íŒŒė´ėŦė˜ ėŧëļ€ė´ëа "Ellipsis"ëŧ ëļ€ëĻ…ë‹ˆë‹¤. + +ė´ë ‡ę˛Œ 하면 **FastAPI**가 ė´ ë§¤ę°œëŗ€ėˆ˜ëŠ” í•„ėˆ˜ėž„ė„ ė•Œ 눘 ėžˆėŠĩ니다. + +## ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ ëĻŦėŠ¤íŠ¸ / ë‹¤ė¤‘ę°’ + +ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ `Query`뙀 함ęģ˜ ëĒ…ė‹œė ėœŧ로 ė„ ė–¸í•  때, ę°’ë“¤ė˜ ëĻŦėŠ¤íŠ¸ë‚˜ 다ëĨ¸ 방법ėœŧ로 ė—ŦëŸŦ ę°’ė„ 받도록 ė„ ė–¸ 할 ėˆ˜ë„ ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´, URLė—ė„œ ė—ŦëŸŦ번 ë‚˜ė˜¤ëŠ” `q` ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•˜ë ¤ëŠ´ ë‹¤ėŒęŗŧ ę°™ė´ ėž‘ė„ąí•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial011.py!} +``` + +ė•„ëž˜ė™€ ę°™ė€ URLė„ ė‚ŦėšŠí•Šë‹ˆë‹¤: + +``` +http://localhost:8000/items/?q=foo&q=bar +``` + +ė—ŦëŸŦ `q` *ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜* ę°’ë“¤ė„ (`foo` 및 `bar`) íŒŒė´ėŦ `list`로 *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜* 내 *í•¨ėˆ˜ ë§¤ę°œëŗ€ėˆ˜* `q`로 ė „ë‹Ŧ 받ėŠĩ니다. + +따ëŧė„œ 해당 URL뗐 대한 ė‘ë‹ĩė€ ë‹¤ėŒęŗŧ 같ėŠĩ니다: + +```JSON +{ + "q": [ + "foo", + "bar" + ] +} +``` + +!!! tip "팁" + ėœ„ė˜ ė˜ˆė™€ ę°™ė´ `list` ėžëŖŒí˜•ėœŧ로 ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•˜ë ¤ëŠ´ `Query`ëĨŧ ëĒ…ė‹œė ėœŧ로 ė‚ŦėšŠí•´ė•ŧ 합니다. ęˇ¸ë ‡ė§€ ė•Šėœŧ늴 ėš”ė˛­ ëŗ¸ëŦ¸ėœŧ로 í•´ė„ëŠë‹ˆë‹¤. + +대화형 API ëŦ¸ė„œëŠ” ė—ŦëŸŦ ę°’ė„ í—ˆėšŠí•˜ë„ëĄ ėˆ˜ė • 됩니다: + + + +### ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ ëĻŦėŠ¤íŠ¸ / ę¸°ëŗ¸ę°’ė„ ė‚ŦėšŠí•˜ëŠ” ë‹¤ė¤‘ę°’ + +꡸ëĻŦęŗ  렜ęŗĩ된 ę°’ė´ ė—†ėœŧ늴 ę¸°ëŗ¸ `list` ę°’ė„ ė •ė˜í•  ėˆ˜ë„ ėžˆėŠĩ니다: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial012.py!} +``` + +ė•„ëž˜ëĄœ ė´ë™í•œë‹¤ëŠ´: + +``` +http://localhost:8000/items/ +``` + +`q`ė˜ ę¸°ëŗ¸ę°’ė€: `["foo", "bar"]`ė´ëŠ° ė‘ë‹ĩė€ ë‹¤ėŒė´ 됩니다: + +```JSON +{ + "q": [ + "foo", + "bar" + ] +} +``` + +#### `list` ė‚ŦėšŠí•˜ę¸° + +`List[str]` ëŒ€ė‹  `list`ëĨŧ 링렑 ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다: + +```Python hl_lines="7" +{!../../../docs_src/query_params_str_validations/tutorial013.py!} +``` + +!!! note "및溠" + ė´ ę˛Ŋ뚰 FastAPI는 ëĻŦėŠ¤íŠ¸ė˜ ë‚´ėšŠė„ 검ė‚Ŧí•˜ė§€ ė•ŠėŒė„ ëĒ…ė‹Ŧ하기 바랍니다. + + 똈ëĨŧ ë“¤ė–´, `List[int]`는 ëĻŦėŠ¤íŠ¸ ë‚´ėšŠė´ ė •ėˆ˜ė¸ė§€ 검ė‚Ŧ(및 ëŦ¸ė„œí™”)합니다. í•˜ė§€ë§Œ `list` 단독ėŧ ę˛Ŋėš°ëŠ” ė•„ë‹™ë‹ˆë‹¤. + +## 더 ë§Žė€ ëŠ”íƒ€ë°ė´í„° ė„ ė–¸ + +ë§¤ę°œëŗ€ėˆ˜ė— 대한 ė •ëŗ´ëĨŧ ėļ”가할 눘 ėžˆėŠĩ니다. + +해당 ė •ëŗ´ëŠ” ėƒė„ąëœ OpenAPI뗐 íŦí•¨ë˜ęŗ  ëŦ¸ė„œ ė‚ŦėšŠėž ė¸í„°íŽ˜ė´ėŠ¤ 및 뙏ëļ€ ë„ęĩŦė—ė„œ ė‚ŦėšŠëŠë‹ˆë‹¤. + +!!! note "및溠" + 도ęĩŦ뗐 따ëŧ OpenAPI 맀뛐 ėˆ˜ė¤€ė´ 다ëĨŧ 눘 ėžˆėŒė„ ëĒ…ė‹Ŧ하기 바랍니다. + + ėŧëļ€ëŠ” 땄링 ė„ ė–¸ëœ ėļ”ę°€ ė •ëŗ´ëĨŧ ëĒ¨ë‘ í‘œė‹œí•˜ė§€ ė•Šė„ 눘 ėžˆė§€ë§Œ, 대ëļ€ëļ„ė˜ ę˛Ŋ뚰 누ëŊ된 기ëŠĨė€ ė´ë¯¸ 개발 ęŗ„íšė´ ėžˆėŠĩ니다. + +`title`ė„ ėļ”가할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="10" +{!../../../docs_src/query_params_str_validations/tutorial007.py!} +``` + +꡸ëĻŦęŗ  `description`도 ėļ”가할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="13" +{!../../../docs_src/query_params_str_validations/tutorial008.py!} +``` + +## ëŗ„ėš­ ë§¤ę°œëŗ€ėˆ˜ + +ë§¤ę°œëŗ€ėˆ˜ę°€ `item-query`ė´ę¸¸ ė›í•œë‹¤ęŗ  ę°€ė •í•´ ë´…ė‹œë‹¤. + +ë§ˆėš˜ ë‹¤ėŒęŗŧ 같ėŠĩ니다: + +``` +http://127.0.0.1:8000/items/?item-query=foobaritems +``` + +꡸ëŸŦ나 `item-query`ė€ ėœ íš¨í•œ íŒŒė´ėŦ ëŗ€ėˆ˜ ė´ëĻ„ė´ ė•„ë‹™ë‹ˆë‹¤. + +가ėžĨ ę°€ęšŒėš´ ę˛ƒė€ `item_query`ėŧ 겁니다. + +í•˜ė§€ë§Œ ė •í™•ížˆ`item-query`ė´ę¸¸ ė›í•Šë‹ˆë‹¤... + +ė´ëŸ´ ę˛Ŋ뚰 `alias`ëĨŧ ė„ ė–¸í•  눘 ėžˆėœŧ늰, 해당 ëŗ„ėš­ė€ ë§¤ę°œëŗ€ėˆ˜ ę°’ė„ ė°žëŠ” 데 ė‚ŦėšŠëŠë‹ˆë‹¤: + +```Python hl_lines="9" +{!../../../docs_src/query_params_str_validations/tutorial009.py!} +``` + +## ë§¤ę°œëŗ€ėˆ˜ ė‚ŦėšŠí•˜ė§€ ė•Šę˛Œ 하기 + +ė´ė œëŠ” ë”ė´ėƒ ė´ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ë§ˆėŒė— ë“¤ė–´í•˜ė§€ ė•ŠëŠ”ë‹¤ęŗ  ę°€ė •í•´ ë´…ė‹œë‹¤. + +ė´ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė‚ŦėšŠí•˜ëŠ” 클ëŧė´ė–¸íŠ¸ę°€ ėžˆę¸° 때ëŦ¸ė— í•œë™ė•ˆė€ 남겨ë‘Ŧė•ŧ í•˜ė§€ë§Œ, ė‚ŦėšŠë˜ė§€ ė•ŠëŠ”ë‹¤(deprecated)ęŗ  í™•ė‹¤í•˜ę˛Œ ëŦ¸ė„œė—ė„œ ëŗ´ė—ŦėŖŧęŗ  ė‹ļėŠĩ니다. + +그렇다면 `deprecated=True` ë§¤ę°œëŗ€ėˆ˜ëĨŧ `Query`로 ė „ë‹Ŧ합니다: + +```Python hl_lines="18" +{!../../../docs_src/query_params_str_validations/tutorial010.py!} +``` + +ëŦ¸ė„œę°€ ė•„ëž˜ė™€ ę°™ė´ ëŗ´ėŧ겁니다: + + + +## ėš”ė•Ŋ + +ë§¤ę°œëŗ€ėˆ˜ė— 검ėĻęŗŧ ëŠ”íƒ€ë°ė´í„°ëĨŧ ėļ”ę°€ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +ė œë„¤ëĻ­ 검ėĻęŗŧ ëŠ”íƒ€ë°ė´í„°: + +* `alias` +* `title` +* `description` +* `deprecated` + +íŠšė • ëŦ¸ėžė—´ 검ėĻ: + +* `min_length` +* `max_length` +* `regex` + +ė˜ˆė œė—ė„œ `str` ę°’ė˜ 검ėĻė„ ė–´ë–ģ枌 ėļ”ę°€í•˜ëŠ”ė§€ ė‚´íŽ´ëŗ´ė•˜ėŠĩ니다. + +ėˆĢėžė™€ ę°™ė€ 다ëĨ¸ ėžëŖŒí˜•ė— 대한 검ėĻė„ ė–´ë–ģ枌 ė„ ė–¸í•˜ëŠ”ė§€ í™•ė¸í•˜ë ¤ëŠ´ ë‹¤ėŒ ėžĨė„ í™•ė¸í•˜ę¸° 바랍니다. From 83944b9e260b865ed587e5dbe6c5203bfb003eb2 Mon Sep 17 00:00:00 2001 From: Dahun Jeong Date: Tue, 23 Jan 2024 04:37:52 +0900 Subject: [PATCH 141/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/body-multiple-params.md`=20(#?= =?UTF-8?q?2461)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/body-multiple-params.md | 170 ++++++++++++++++++ 1 file changed, 170 insertions(+) create mode 100644 docs/ko/docs/tutorial/body-multiple-params.md diff --git a/docs/ko/docs/tutorial/body-multiple-params.md b/docs/ko/docs/tutorial/body-multiple-params.md new file mode 100644 index 0000000000..034c2e84c7 --- /dev/null +++ b/docs/ko/docs/tutorial/body-multiple-params.md @@ -0,0 +1,170 @@ +# ëŗ¸ëŦ¸ - ë‹¤ė¤‘ ë§¤ę°œëŗ€ėˆ˜ + +ė§€ę¸ˆëļ€í„° `Path`뙀 `Query`ëĨŧ ė–´ë–ģ枌 ė‚ŦėšŠí•˜ëŠ”ė§€ í™•ė¸í•˜ę˛ ėŠĩ니다. + +ėš”ė˛­ ëŗ¸ëŦ¸ 넠떏뗐 대한 ė‹Ŧ화 ė‚ŦėšŠë˛•ė„ ė•Œė•„ëŗ´ę˛ ėŠĩ니다. + +## `Path`, `Query` 및 ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ í˜ŧ합 + +ë‹šė—°í•˜ę˛Œ `Path`, `Query` 및 ėš”ė˛­ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ ė„ ė–¸ė„ ėžėœ ëĄ­ę˛Œ í˜ŧí•Ší•´ė„œ ė‚ŦėšŠí•  눘 ėžˆęŗ , **FastAPI**는 ė–´ë–¤ ë™ėž‘ė„ í• ė§€ ė••ë‹ˆë‹¤. + +또한, ę¸°ëŗ¸ ę°’ė„ `None`ėœŧ로 ė„¤ė •í•´ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ íƒė‚Ŧ항ėœŧ로 ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +```Python hl_lines="19-21" +{!../../../docs_src/body_multiple_params/tutorial001.py!} +``` + +!!! note "및溠" + ė´ ę˛Ŋėš°ė—ëŠ” ëŗ¸ëŦ¸ėœŧ로 ëļ€í„° ę°€ė ¸ė˜¨ ` item`ė€ ę¸°ëŗ¸ę°’ė´ `None`ė´ę¸° 때ëŦ¸ė—, ė„ íƒė‚Ŧí•­ė´ëŧ는 ė ė„ ėœ ė˜í•´ė•ŧ 합니다. + +## ë‹¤ė¤‘ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ + +ė´ė „ ė˜ˆė œė—ė„œ ëŗ´ë“¯ė´, *ę˛Ŋ로 ë™ėž‘*ė€ ė•„ëž˜ė™€ ę°™ė´ `Item` ė†ė„ąė„ 氀맄 JSON ëŗ¸ëŦ¸ė„ ė˜ˆėƒí•Šë‹ˆë‹¤: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +í•˜ė§€ë§Œ, ë‹¤ė¤‘ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ ė—­ė‹œ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. 똈. `item`ęŗŧ `user`: + +```Python hl_lines="22" +{!../../../docs_src/body_multiple_params/tutorial002.py!} +``` + +ė´ ę˛Ŋėš°ė—, **FastAPI**는 ė´ í•¨ėˆ˜ ė•ˆė— 한 氜 ė´ėƒė˜ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜(Pydantic ëĒ¨ë¸ė¸ 두 ë§¤ę°œëŗ€ėˆ˜)가 ėžˆë‹¤ęŗ  ė•Œ ę˛ƒėž…ë‹ˆë‹¤. + +ęˇ¸ëž˜ė„œ, ëŗ¸ëŦ¸ė˜ ë§¤ę°œëŗ€ėˆ˜ ė´ëĻ„ė„ 키(필드 ëĒ…)로 ė‚ŦėšŠí•  눘 ėžˆęŗ , ë‹¤ėŒęŗŧ ę°™ė€ ëŗ¸ëŦ¸ė„ ė˜ˆė¸Ąí•Šë‹ˆë‹¤: + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + } +} +``` + +!!! note "및溠" + ė´ė „ęŗŧ ę°™ė´ `item`ė´ ė„ ė–¸ ë˜ė—ˆë”ëŧ도, ëŗ¸ëŦ¸ ë‚´ė˜ `item` 키가 ėžˆė„ ę˛ƒė´ëŧęŗ  ė˜ˆė¸Ąí•Šë‹ˆë‹¤. + +FastAPI는 ėš”ė˛­ė„ ėžë™ėœŧ로 ëŗ€í™˜í•´, ë§¤ę°œëŗ€ėˆ˜ė˜ `item`ęŗŧ `user`ëĨŧ íŠšëŗ„í•œ ë‚´ėšŠėœŧ로 받도록 할 ę˛ƒėž…ë‹ˆë‹¤. + +ëŗĩ합 ë°ė´í„°ė˜ 검ėĻė„ ėˆ˜í–‰í•˜ęŗ  OpenAPI ėŠ¤í‚¤ë§ˆ 및 ėžë™ ëŦ¸ė„œëĨŧ ëŦ¸ė„œí™”핊니다. + +## ëŗ¸ëŦ¸ ë‚´ė˜ 단ėŧ 값 + +ėŋŧëĻŦ 및 ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ė— 대한 ėļ”ę°€ ë°ė´í„°ëĨŧ ė •ė˜í•˜ëŠ” `Query`뙀 `Path`뙀 ę°™ė´, **FastAPI**는 동등한 `Body`ëĨŧ 렜ęŗĩ합니다. + +똈ëĨŧ ë“¤ė–´ ė´ė „ė˜ ëĒ¨ë¸ė„ 확ėžĨ하면, `item`ęŗŧ `user`뙀 동ėŧ한 ëŗ¸ëŦ¸ė— 또 다ëĨ¸ `importance`ëŧ는 키ëĨŧ 갖도록 할 ėˆ˜ėžˆėŠĩ니다. + +단ėŧ ę°’ė„ 그대로 ė„ ė–¸í•œë‹¤ëŠ´, **FastAPI**는 ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĄœ ę°€ė •í•  ę˛ƒėž…ë‹ˆë‹¤. + +í•˜ė§€ë§Œ, **FastAPI**ė˜ `Body`ëĨŧ ė‚ŦėšŠí•´ 다ëĨ¸ ëŗ¸ëŦ¸ 키로 래ëĻŦ하도록 ė œė–´í•  눘 ėžˆėŠĩ니다: + + +```Python hl_lines="23" +{!../../../docs_src/body_multiple_params/tutorial003.py!} +``` + +ė´ ę˛Ŋėš°ė—ëŠ” **FastAPI**는 ëŗ¸ëŦ¸ė„ ė´ė™€ ę°™ė´ ė˜ˆė¸Ąí•  ę˛ƒėž…ë‹ˆë‹¤: + + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + }, + "importance": 5 +} +``` + +ë‹¤ė‹œ 말해, ë°ė´í„° íƒ€ėž…, 검ėĻ, ëŦ¸ė„œ ë“ąė„ ëŗ€í™˜í•Šë‹ˆë‹¤. + +## ë‹¤ė¤‘ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ė™€ ėŋŧëĻŦ + +ë‹šė—°ížˆ, í•„ėš”í•  때마다 ėļ”ę°€ė ė¸ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•  눘 ėžˆęŗ , ė´ëŠ” ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ė— ėļ”ę°€ëŠë‹ˆë‹¤. + +ę¸°ëŗ¸ė ėœŧ로 단ėŧ ę°’ė€ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĄœ í•´ė„ë˜ë¯€ëĄœ, ëĒ…ė‹œė ėœŧ로 `Query`ëĨŧ ėļ”가할 í•„ėš”ę°€ 뗆溠, ė•„ëž˜ė˛˜ëŸŧ 할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="27" +{!../../../docs_src/body_multiple_params/tutorial004.py!} +``` + +ė´ë ‡ę˛Œ: + +```Python +q: Optional[str] = None +``` + +!!! info "ė •ëŗ´" + `Body` 또한 `Query`, `Path` ꡸ëĻŦęŗ  ė´í›„ė— ëŗŧ 다ëĨ¸ ę˛ƒë“¤ė˛˜ëŸŧ 동ėŧ한 ėļ”ę°€ 검ėĻęŗŧ ëŠ”íƒ€ë°ė´í„° ë§¤ę°œëŗ€ėˆ˜ëĨŧ ę°–ęŗ  ėžˆėŠĩ니다. + +## 단ėŧ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ ė‚Ŋėž…í•˜ę¸° + +Pydantic ëĒ¨ë¸ `Item`ė˜ `item`ė„ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ëĄœ 똤링 한개만 ę°–ęŗ ėžˆë‹¤ęŗ  하겠ėŠĩ니다. + +ę¸°ëŗ¸ė ėœŧ로 **FastAPI**는 링렑 ëŗ¸ëŦ¸ėœŧ로 ė˜ˆė¸Ąí•  ę˛ƒėž…ë‹ˆë‹¤. + +í•˜ė§€ë§Œ, 만ė•Ŋ ëĒ¨ë¸ ë‚´ėšŠė— `item `키ëĨŧ 氀맄 JSONėœŧ로 ė˜ˆė¸Ąí•˜ę¸¸ ė›í•œë‹¤ëŠ´, ėļ”ę°€ė ė¸ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•œ 枃래ëŸŧ `Body`ė˜ íŠšëŗ„í•œ ë§¤ę°œëŗ€ėˆ˜ė¸ `embed`ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="17" +{!../../../docs_src/body_multiple_params/tutorial005.py!} +``` + +ė•„ëž˜ 래ëŸŧ: + +```Python +item: Item = Body(..., embed=True) +``` + +ė´ ę˛Ŋėš°ė— **FastAPI**는 ëŗ¸ëŦ¸ė„ ė•„ëž˜ ëŒ€ė‹ ė—: + +```JSON hl_lines="2" +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +ė•„ëž˜ 래ëŸŧ ė˜ˆė¸Ąí•  것 ėž…ë‹ˆë‹¤: + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + } +} +``` + +## ė •ëĻŦ + +ėš”ė˛­ė´ 단 í•œę°œė˜ ëŗ¸ëŦ¸ė„ 氀맀溠 ėžˆë”ëŧ도, *ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜*로 ë‹¤ė¤‘ ëŗ¸ëŦ¸ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ėļ”가할 눘 ėžˆėŠĩ니다. + +í•˜ė§€ë§Œ, **FastAPI**는 ė´ëĨŧ 래ëĻŦí•˜ęŗ , í•¨ėˆ˜ė— ė˜Ŧ바ëĨ¸ ë°ė´í„°ëĨŧ 렜ęŗĩ하며, *ę˛Ŋ로 ë™ėž‘*ėœŧ로 ė˜Ŧ바ëĨ¸ ėŠ¤í‚¤ë§ˆëĨŧ 검ėĻí•˜ęŗ  ëŦ¸ė„œí™” 합니다. + +또한, 단ėŧ ę°’ė„ ëŗ¸ëŦ¸ė˜ ėŧëļ€ëĄœ 받도록 ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  **FastAPI**는 단 í•œę°œė˜ ë§¤ę°œëŗ€ėˆ˜ę°€ ė„ ė–¸ 되더ëŧ도, ëŗ¸ëŦ¸ ë‚´ė˜ 키로 ė‚Ŋėž… ė‹œí‚Ŧ 눘 ėžˆėŠĩ니다. From adf61e567548183f03aecf36e42b8fca593081dc Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:39:08 +0000 Subject: [PATCH 142/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2eb764e1e7..634967faf6 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/query-params-str-validations.md`. PR [#2415](https://github.com/tiangolo/fastapi/pull/2415) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/python-types.md`. PR [#2267](https://github.com/tiangolo/fastapi/pull/2267) by [@jrim](https://github.com/jrim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-nested-models.md`. PR [#2506](https://github.com/tiangolo/fastapi/pull/2506) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/learn/index.md`. PR [#10977](https://github.com/tiangolo/fastapi/pull/10977) by [@KaniKim](https://github.com/KaniKim). From ef1ccb563d3acbdad86c00c2c89bfe356aca79b9 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:39:50 +0000 Subject: [PATCH 143/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 634967faf6..96c920d859 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-multiple-params.md`. PR [#2461](https://github.com/tiangolo/fastapi/pull/2461) by [@PandaHun](https://github.com/PandaHun). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/query-params-str-validations.md`. PR [#2415](https://github.com/tiangolo/fastapi/pull/2415) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/python-types.md`. PR [#2267](https://github.com/tiangolo/fastapi/pull/2267) by [@jrim](https://github.com/jrim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-nested-models.md`. PR [#2506](https://github.com/tiangolo/fastapi/pull/2506) by [@hard-coders](https://github.com/hard-coders). From 8ec9e30010313fd883aaa54ab8b4b14b88483907 Mon Sep 17 00:00:00 2001 From: Spike Ho Yeol Lee Date: Tue, 23 Jan 2024 04:41:09 +0900 Subject: [PATCH 144/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/response-model.md`=20(#2766)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/response-model.md | 210 ++++++++++++++++++++++++ 1 file changed, 210 insertions(+) create mode 100644 docs/ko/docs/tutorial/response-model.md diff --git a/docs/ko/docs/tutorial/response-model.md b/docs/ko/docs/tutorial/response-model.md new file mode 100644 index 0000000000..fa90c10ae1 --- /dev/null +++ b/docs/ko/docs/tutorial/response-model.md @@ -0,0 +1,210 @@ +# ė‘ë‹ĩ ëĒ¨ë¸ + +ė–´ë–¤ *ę˛Ŋ로 ë™ėž‘*ė´ë“  ë§¤ę°œëŗ€ėˆ˜ `response_model`ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ ė‘ë‹ĩė„ ėœ„í•œ ëĒ¨ë¸ė„ ė„ ė–¸í•  눘 ėžˆėŠĩ니다: + +* `@app.get()` +* `@app.post()` +* `@app.put()` +* `@app.delete()` +* 기타. + +```Python hl_lines="17" +{!../../../docs_src/response_model/tutorial001.py!} +``` + +!!! note "및溠" + `response_model`ė€ "데ėŊ”ë ˆė´í„°" ëŠ”ė†Œë“œ(`get`, `post`, 등)ė˜ ë§¤ę°œëŗ€ėˆ˜ėž…ë‹ˆë‹¤. ëĒ¨ë“  ë§¤ę°œëŗ€ėˆ˜ë“¤ęŗŧ ëŗ¸ëŦ¸(body)래ëŸŧ *ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜*가 ė•„ë‹™ë‹ˆë‹¤. + +Pydantic ëĒ¨ë¸ ė–´íŠ¸ëĻŦ뷰트ëĨŧ ė„ ė–¸í•œ 것ęŗŧ 동ėŧ한 íƒ€ėž…ė„ ėˆ˜ė‹ í•˜ë¯€ëĄœ Pydantic ëĒ¨ë¸ė´ 될 눘 ėžˆė§€ë§Œ, `List[Item]`ęŗŧ ę°™ė´ Pydantic ëĒ¨ë¸ë“¤ė˜ `list`ėŧ ėˆ˜ë„ ėžˆėŠĩ니다. + +FastAPI는 ė´ `response_model`ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ: + +* ėļœë Ĩ ë°ė´í„°ëĨŧ íƒ€ėž… ė„ ė–¸ėœŧ로 ëŗ€í™˜. +* ë°ė´í„° 검ėĻ. +* OpenAPI *ę˛Ŋ로 ë™ėž‘*ė˜ ė‘ë‹ĩ뗐 JSON ėŠ¤í‚¤ë§ˆ ėļ”ę°€. +* ėžë™ ėƒė„ą ëŦ¸ė„œ ė‹œėŠ¤í…œė— ė‚ŦėšŠ. + +í•˜ė§€ë§Œ 가ėžĨ ė¤‘ėš”í•œ ę˛ƒė€: + +* 해당 ëĒ¨ë¸ė˜ ėļœë Ĩ ë°ė´í„° ė œí•œ. ė´ę˛ƒė´ ė–ŧ마나 ė¤‘ėš”í•œė§€ ė•„ëž˜ė—ė„œ ëŗŧ ę˛ƒėž…ë‹ˆë‹¤. + +!!! note "揰눠 넏ëļ€ė‚Ŧ항" + ė‘ë‹ĩ ëĒ¨ë¸ė€ í•¨ėˆ˜ė˜ íƒ€ėž… ė–´ë…¸í…Œė´ė…˜ ëŒ€ė‹  ė´ ë§¤ę°œëŗ€ėˆ˜ëĄœ ė„ ė–¸í•˜ëŠ”ë°, ę˛Ŋ로 í•¨ėˆ˜ę°€ ė‹¤ė œ ė‘ë‹ĩ ëĒ¨ë¸ė„ ë°˜í™˜í•˜ė§€ ė•Šęŗ  `dict`, ë°ė´í„°ë˛ ė´ėŠ¤ ę°ė˛´ë‚˜ 기타 다ëĨ¸ ëĒ¨ë¸ė„ `response_model`ė„ ė‚ŦėšŠí•˜ė—Ŧ 필드 ė œí•œęŗŧ 링ë Ŧ화ëĨŧ ėˆ˜í–‰í•˜ęŗ  반환할 눘 ėžˆę¸° 때ëŦ¸ėž…니다 + +## 동ėŧ한 ėž…ë Ĩ ë°ė´í„° 반환 + +ė—Ŧę¸°ė„œ 뚰ëĻŦ는 평ëŦ¸ 비밀번호ëĨŧ íŦ함하는 `UserIn` ëĒ¨ë¸ė„ ė„ ė–¸í•Šë‹ˆë‹¤: + +```Python hl_lines="9 11" +{!../../../docs_src/response_model/tutorial002.py!} +``` + +꡸ëĻŦęŗ  ė´ ëĒ¨ë¸ė„ ė‚ŦėšŠí•˜ė—Ŧ ėž…ë Ĩė„ ė„ ė–¸í•˜ęŗ  ę°™ė€ ëĒ¨ë¸ëĄœ ėļœë Ĩė„ ė„ ė–¸í•Šë‹ˆë‹¤: + +```Python hl_lines="17-18" +{!../../../docs_src/response_model/tutorial002.py!} +``` + +ė´ė œ 브ëŧėš°ė €ę°€ 비밀번호로 ė‚ŦėšŠėžëĨŧ 만들 때마다 API는 ė‘ë‹ĩėœŧ로 동ėŧ한 비밀번호ëĨŧ 반환합니다. + +ė´ ę˛Ŋ뚰, ė‚ŦėšŠėžę°€ ėŠ¤ėŠ¤ëĄœ 비밀번호ëĨŧ ë°œė‹ í–ˆę¸° 때ëŦ¸ė— ëŦ¸ė œę°€ ë˜ė§€ ė•Šė„ 눘 ėžˆėŠĩ니다. + +꡸ëŸŦ나 동ėŧ한 ëĒ¨ë¸ė„ 다ëĨ¸ *ę˛Ŋ로 ë™ėž‘*ė—ė„œ ė‚ŦėšŠí•  ę˛Ŋ뚰, ëĒ¨ë“  클ëŧė´ė–¸íŠ¸ė—ę˛Œ ė‚ŦėšŠėžė˜ 비밀번호ëĨŧ ë°œė‹ í•  눘 ėžˆėŠĩ니다. + +!!! danger "ėœ„í—˜" + ė ˆëŒ€ëĄœ ė‚ŦėšŠėžė˜ 평ëŦ¸ 비밀번호ëĨŧ ė €ėžĨ하거나 ė‘ë‹ĩėœŧ로 ë°œė‹ í•˜ė§€ ë§ˆė‹­ė‹œė˜¤. + +## ėļœë Ĩ ëĒ¨ë¸ ėļ”ę°€ + +ëŒ€ė‹  평ëŦ¸ 비밀번호로 ėž…ë Ĩ ëĒ¨ë¸ė„ ë§Œë“¤ęŗ  해당 비밀번호 ė—†ė´ ėļœë Ĩ ëĒ¨ë¸ė„ 만들 눘 ėžˆėŠĩ니다: + +```Python hl_lines="9 11 16" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +ė—Ŧę¸°ė„œ *ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜*가 비밀번호ëĨŧ íŦ함하는 동ėŧ한 ėž…ë Ĩ ė‚ŦėšŠėžëĨŧ ë°˜í™˜í• ė§€ëŧ도: + +```Python hl_lines="24" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +...`response_model`ė„ `UserOut` ëĒ¨ë¸ëĄœ ė„ ė–¸í–ˆę¸° 때ëŦ¸ė— 비밀번호ëĨŧ íŦí•¨í•˜ė§€ ė•ŠėŠĩ니다: + +```Python hl_lines="22" +{!../../../docs_src/response_model/tutorial003.py!} +``` + +따ëŧė„œ **FastAPI**는 ėļœë Ĩ ëĒ¨ë¸ė—ė„œ ė„ ė–¸í•˜ė§€ ė•Šė€ ëĒ¨ë“  ë°ė´í„°ëĨŧ (Pydanticė„ ė‚ŦėšŠí•˜ė—Ŧ) 필터링합니다. + +## ëŦ¸ė„œė—ė„œ ëŗ´ę¸° + +ėžë™ ėƒė„ą ëŦ¸ė„œëĨŧ ëŗ´ëŠ´ ėž…ë Ĩ ëĒ¨ë¸ęŗŧ ėļœë Ĩ ëĒ¨ë¸ė´ ę°ėžė˜ JSON ėŠ¤í‚¤ë§ˆëĨŧ 氀맀溠 ėžˆėŒė„ í™•ė¸í•  눘 ėžˆėŠĩ니다: + + + +꡸ëĻŦęŗ  두 ëĒ¨ë¸ ëĒ¨ë‘ 대화형 API ëŦ¸ė„œė— ė‚ŦėšŠëŠë‹ˆë‹¤: + + + +## ė‘ë‹ĩ ëĒ¨ë¸ ė¸ėŊ”딊 ë§¤ę°œëŗ€ėˆ˜ + +ė‘ë‹ĩ ëĒ¨ë¸ė€ ė•„ëž˜ė™€ ę°™ė´ ę¸°ëŗ¸ę°’ė„ ę°€ė§ˆ 눘 ėžˆėŠĩ니다: + +```Python hl_lines="11 13-14" +{!../../../docs_src/response_model/tutorial004.py!} +``` + +* `description: Optional[str] = None`ė€ ę¸°ëŗ¸ę°’ėœŧ로 `None`ė„ 갖ėŠĩ니다. +* `tax: float = 10.5`는 ę¸°ëŗ¸ę°’ėœŧ로 `10.5`ëĨŧ 갖ėŠĩ니다. +* `tags: List[str] = []` 뚈 ëĻŦėŠ¤íŠ¸ė˜ ę¸°ëŗ¸ę°’ėœŧ로: `[]`. + +꡸ëŸŦ나 ė‹¤ė œëĄœ ė €ėžĨë˜ė§€ ė•Šė•˜ė„ ę˛Ŋ뚰 결ęŗŧė—ė„œ ę°’ė„ ėƒëžĩí•˜ęŗ  ė‹ļė„ 눘 ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´, NoSQL ë°ė´í„°ë˛ ė´ėŠ¤ė— ë§Žė€ ė„ íƒė  ė†ė„ąė´ ėžˆëŠ” ëĒ¨ë¸ė´ ėžˆė§€ë§Œ, ę¸°ëŗ¸ę°’ėœŧ로 가득 ė°Ŧ ë§¤ėš° 긴 JSON ė‘ë‹ĩė„ ëŗ´ë‚´ęŗ  ė‹ļė§€ ė•ŠėŠĩ니다. + +### `response_model_exclude_unset` ë§¤ę°œëŗ€ėˆ˜ ė‚ŦėšŠ + +*ę˛Ŋ로 ë™ėž‘ 데ėŊ”ë ˆė´í„°* ë§¤ę°œëŗ€ėˆ˜ëĨŧ `response_model_exclude_unset=True`로 네렕 할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="24" +{!../../../docs_src/response_model/tutorial004.py!} +``` + +ė´ëŸŦ한 ę¸°ëŗ¸ę°’ė€ ė‘ë‹ĩ뗐 íŦí•¨ë˜ė§€ ė•Šęŗ  ė‹¤ė œëĄœ ė„¤ė •ëœ 값만 íŦ함됩니다. + +따ëŧė„œ 해당 *ę˛Ŋ로 ë™ėž‘*뗐 ID가 `foo`ė¸ 항ëĒŠ(items)ė„ ėš”ė˛­ėœŧ로 ëŗ´ë‚´ëŠ´ (ę¸°ëŗ¸ę°’ė„ ė œė™¸í•œ) ė‘ë‹ĩė€ ë‹¤ėŒęŗŧ 같ėŠĩ니다: + +```JSON +{ + "name": "Foo", + "price": 50.2 +} +``` + +!!! info "ė •ëŗ´" + FastAPI는 ė´ëĨŧ ėœ„í•´ Pydantic ëĒ¨ë¸ė˜ `.dict()`ė˜ `exclude_unset` ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤. + +!!! info "ė •ëŗ´" + ė•„ëž˜ 또한 ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + + * `response_model_exclude_defaults=True` + * `response_model_exclude_none=True` + + Pydantic ëŦ¸ė„œė—ė„œ `exclude_defaults` 및 `exclude_none`뗐 대해 네ëĒ…í•œ 대로 ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +#### ę¸°ëŗ¸ę°’ė´ ėžˆëŠ” 필드ëĨŧ 갖는 ę°’ė˜ ë°ė´í„° + +í•˜ė§€ë§Œ ëĒ¨ë¸ė˜ 필드가 ę¸°ëŗ¸ę°’ė´ ėžˆė–´ë„ ID가 `bar`ė¸ 항ëĒŠ(items)래ëŸŧ ë°ė´í„°ę°€ ę°’ė„ 갖는다면: + +```Python hl_lines="3 5" +{ + "name": "Bar", + "description": "The bartenders", + "price": 62, + "tax": 20.2 +} +``` + +ė‘ë‹ĩ뗐 해당 ę°’ë“¤ė´ íŦ함됩니다. + +#### ę¸°ëŗ¸ę°’ęŗŧ 동ėŧ한 ę°’ė„ 갖는 ë°ė´í„° + +If the data has the same values as the default ones, like the item with ID `baz`: +ID가 `baz`ė¸ 항ëĒŠ(items)래ëŸŧ ę¸°ëŗ¸ę°’ęŗŧ 동ėŧ한 ę°’ė„ 갖는다면: + +```Python hl_lines="3 5-6" +{ + "name": "Baz", + "description": None, + "price": 50.2, + "tax": 10.5, + "tags": [] +} +``` + +`description`, `tax` ꡸ëĻŦęŗ  `tags`가 ę¸°ëŗ¸ę°’ęŗŧ 같더ëŧ도 (ę¸°ëŗ¸ę°’ė—ė„œ ę°€ė ¸ė˜¤ëŠ” ëŒ€ė‹ ) ę°’ë“¤ė´ ëĒ…ė‹œė ėœŧ로 ė„¤ė •ë˜ė—ˆë‹¤ëŠ” ę˛ƒė„ ė¸ė§€í•  ė •ë„ëĄœ FastAPI는 ėļŠëļ„히 똑똑합니다(ė‚Ŧ다, Pydanticė´ ėļŠëļ„히 똑똑합니다). + +따ëŧė„œ JSON ėŠ¤í‚¤ë§ˆė— íŦ함됩니다. + +!!! tip "팁" + `None` ëŋë§Œ ė•„ë‹ˆëŧ 다ëĨ¸ ė–´ë–¤ 것도 ę¸°ëŗ¸ę°’ė´ 될 눘 ėžˆėŠĩ니다. + + ëĻŦėŠ¤íŠ¸(`[]`), `float`ė¸ `10.5` ë“ąė´ 될 눘 ėžˆėŠĩ니다. + +### `response_model_include` 및 `response_model_exclude` + +*ę˛Ŋ로 ë™ėž‘ 데ėŊ”ë ˆė´í„°* ë§¤ę°œëŗ€ėˆ˜ `response_model_include` 및 `response_model_exclude`ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +ė´ë“¤ė€ íŦ함(ë‚˜ë¨¸ė§€ ėƒëžĩ)하거나 ė œė™¸(ë‚˜ë¨¸ė§€ íŦ함) 할 ė–´íŠ¸ëĻŦëˇ°íŠ¸ė˜ ė´ëĻ„ęŗŧ `str`ė˜ `set`ė„ 받ėŠĩ니다. + +Pydantic ëĒ¨ë¸ė´ 하나만 ėžˆęŗ  ėļœë Ĩė—ė„œ ​​ėŧëļ€ ë°ė´í„°ëĨŧ ė œęą°í•˜ë ¤ëŠ” ę˛Ŋ뚰 ëš ëĨ¸ ė§€ëĻ„ę¸¸ëĄœ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +!!! tip "팁" + í•˜ė§€ë§Œ ė´ëŸŦ한 ë§¤ę°œëŗ€ėˆ˜ ëŒ€ė‹  ė—ŦëŸŦ í´ëž˜ėŠ¤ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ ėœ„ ė•„ė´ë””ė–´ëĨŧ ė‚ŦėšŠí•˜ëŠ” ę˛ƒė„ ėļ”ė˛œí•Šë‹ˆë‹¤. + + ė´ëŠ” ėŧëļ€ ė–´íŠ¸ëĻŦ뷰트ëĨŧ ėƒëžĩ하기 ėœ„í•´ `response_model_include` 또는 `response_model_exclude`ëĨŧ ė‚ŦėšŠí•˜ë”ëŧ도 ė•ąė˜ OpenAPI(및 ëŦ¸ė„œ)가 ėƒė„ąí•œ JSON ėŠ¤í‚¤ë§ˆę°€ ė—Ŧė „ížˆ 렄랴 ëĒ¨ë¸ė— 대한 ėŠ¤í‚¤ë§ˆė´ę¸° 때ëŦ¸ėž…니다. + + ëš„ėŠˇí•˜ę˛Œ ėž‘ë™í•˜ëŠ” `response_model_by_alias` ė—­ė‹œ 마ė°Ŧę°€ė§€ëĄœ ė ėšŠëŠë‹ˆë‹¤. + +```Python hl_lines="31 37" +{!../../../docs_src/response_model/tutorial005.py!} +``` + +!!! tip "팁" + ëŦ¸ë˛• `{"name", "description"}`ė€ 두 ę°’ė„ 갖는 `set`ė„ 만듭니다. + + ė´ëŠ” `set(["name", "description"])`ęŗŧ 동ėŧ합니다. + +#### `set` ëŒ€ė‹  `list` ė‚ŦėšŠí•˜ę¸° + +`list` 또는 `tuple` ëŒ€ė‹  `set`ė„ ė‚ŦėšŠí•˜ëŠ” ë˛•ė„ ėžŠė—ˆë”ëŧ도, FastAPI는 `set`ėœŧ로 ëŗ€í™˜í•˜ęŗ  ė •ėƒė ėœŧ로 ėž‘ë™í•Šë‹ˆë‹¤: + +```Python hl_lines="31 37" +{!../../../docs_src/response_model/tutorial006.py!} +``` + +## ėš”ė•Ŋ + +ė‘ë‹ĩ ëĒ¨ë¸ė„ ė •ė˜í•˜ęŗ  ę°œė¸ė •ëŗ´ę°€ 필터되는 ę˛ƒė„ ëŗ´ėžĨ하기 ėœ„í•´ *ę˛Ŋ로 ë™ėž‘ 데ėŊ”ë ˆė´í„°*ė˜ ë§¤ę°œëŗ€ėˆ˜ `response_model`ė„ ė‚ŦėšŠí•˜ė„¸ėš”. + +ëĒ…ė‹œė ėœŧ로 ė„¤ė •ëœ 값만 반환하려면 `response_model_exclude_unset`ė„ ė‚ŦėšŠí•˜ė„¸ėš”. From ea6e0ffdc01464873452af46b36883b7a21e8fec Mon Sep 17 00:00:00 2001 From: Jeesang Kim Date: Tue, 23 Jan 2024 04:42:37 +0900 Subject: [PATCH 145/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/static-files.md`=20(#2957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/static-files.md | 40 +++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 docs/ko/docs/tutorial/static-files.md diff --git a/docs/ko/docs/tutorial/static-files.md b/docs/ko/docs/tutorial/static-files.md new file mode 100644 index 0000000000..fe1aa4e5e2 --- /dev/null +++ b/docs/ko/docs/tutorial/static-files.md @@ -0,0 +1,40 @@ +# 렕렁 파ėŧ + +'StaticFiles'ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ 디렉토ëĻŦė—ė„œ 렕렁 파ėŧė„ ėžë™ėœŧ로 렜ęŗĩ할 눘 ėžˆėŠĩ니다. + +## `StaticFiles` ė‚ŦėšŠ + +* `StaticFiles` ėž„íŦ트합니다. +* íŠšė • ę˛ŊëĄœė— `StaticFiles()` ė¸ėŠ¤í„´ėŠ¤ëĨŧ "ë§ˆėš´íŠ¸" 합니다. + +```Python hl_lines="2 6" +{!../../../docs_src/static_files/tutorial001.py!} +``` + +!!! note "揰눠렁 넏ëļ€ė‚Ŧ항" + `from starlette.staticfiles import StaticFiles` ëĨŧ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다. + + **FastAPI**는 ë‹¨ė§€ ę°œë°œėžė¸, ë‹šė‹ ė—ę˛Œ íŽ¸ė˜ëĨŧ 렜ęŗĩ하기 ėœ„í•´ `fastapi.static files` 뙀 동ėŧ한 `starlett.static files`ëĨŧ 렜ęŗĩ합니다. í•˜ė§€ë§Œ ė‚Ŧ다 ė´ę˛ƒė€ Starlettė—ė„œ 링렑 똍 ę˛ƒėž…ë‹ˆë‹¤. + +### "ë§ˆėš´íŒ…" ė´ëž€ + +"ë§ˆėš´íŒ…"ė€ íŠšė • ę˛ŊëĄœė— ė™„ė „ížˆ "독ëĻŊė ė¸" ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ ėļ”ę°€í•˜ëŠ” ę˛ƒė„ ė˜ë¯¸í•˜ëŠ”ë°, ꡸ 후 ëĒ¨ë“  í•˜ėœ„ ę˛ŊëĄœė— ëŒ€í•´ė„œë„ ė ėšŠëŠë‹ˆë‹¤. + +ë§ˆėš´íŠ¸ëœ ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė€ ė™„ė „ížˆ 독ëĻŊė ė´ę¸° 때ëŦ¸ė— `APIRouter`ëĨŧ ė‚ŦėšŠí•˜ëŠ” 것ęŗŧ는 다ëĻ…ë‹ˆë‹¤. OpenAPI 및 ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė˜ ëŦ¸ė„œëŠ” ë§ˆėš´íŠ¸ëœ ė‘ėšŠ 프로그램 ë“ąė—ė„œ ė–´ë–¤ 것도 íŦí•¨í•˜ė§€ ė•ŠėŠĩ니다. + +ėžė„¸í•œ ë‚´ėšŠė€ **ėˆ™ë ¨ëœ ė‚ŦėšŠėž ė•ˆë‚´ė„œ**ė—ė„œ í™•ė¸í•  눘 ėžˆėŠĩ니다. + +## 넏ëļ€ė‚Ŧ항 + +ė˛Ģ ë˛ˆė§¸ `"/static"`ė€ ė´ "í•˜ėœ„ ė‘ėšŠ 프로그램"ė´ "ë§ˆėš´íŠ¸"될 í•˜ėœ„ ę˛Ŋ로ëĨŧ 가ëĻŦí‚ĩ니다. 따ëŧė„œ `"/static"`ėœŧ로 ė‹œėž‘í•˜ëŠ” ëĒ¨ë“  ę˛Ŋ로는 `"/static"`ėœŧ로 래ëĻŦ됩니다. + +`'directory="static"`ė€ 렕렁 파ėŧė´ ë“¤ė–´ ėžˆëŠ” 디렉토ëĻŦė˜ ė´ëĻ„ė„ 나타냅니다. + +`name="static"`ė€ **FastAPI**ė—ė„œ 내ëļ€ė ėœŧ로 ė‚ŦėšŠí•  눘 ėžˆëŠ” ė´ëĻ„ė„ 렜ęŗĩ합니다. + +ė´ ëĒ¨ë“  ë§¤ę°œëŗ€ėˆ˜ëŠ” "`static`"ęŗŧ 다ëĨŧ 눘 ėžˆėœŧ늰, ė‚ŦėšŠėž ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė˜ ėš”ęĩŦ ė‚Ŧ항 및 ęĩŦė˛´ė ė¸ 넏ëļ€ ė •ëŗ´ė— 따ëŧ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ėĄ°ė •í•  눘 ėžˆėŠĩ니다. + + +## ėļ”ę°€ ė •ëŗ´ + +ėžė„¸í•œ ë‚´ėšŠęŗŧ ė„ íƒ ė‚Ŧí•­ė„ ëŗ´ë ¤ëŠ´ Starletteė˜ 렕렁 파ėŧ뗐 관한 ëŦ¸ė„œëĨŧ í™•ė¸í•˜ė‹­ė‹œė˜¤. From 792ba017459189ebfe99019d2b0e070b2a38a1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B8=85=E9=9D=88=E8=AA=9E?= Date: Tue, 23 Jan 2024 03:42:53 +0800 Subject: [PATCH 146/305] =?UTF-8?q?=F0=9F=8C=90=20Modify=20the=20descripti?= =?UTF-8?q?on=20of=20`zh`=20-=20Traditional=20Chinese=20(#10889)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- docs/en/mkdocs.yml | 2 +- docs/language_names.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index e965f4f28f..d34e919bde 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -304,7 +304,7 @@ extra: - link: /yo/ name: yo - YorÚbÃĄ - link: /zh/ - name: zh - æą‰č¯­ + name: zh - įŽ€äŊ“中文 - link: /zh-hant/ name: zh-hant - įšéĢ”ä¸­æ–‡ - link: /em/ diff --git a/docs/language_names.yml b/docs/language_names.yml index 7c37ff2b13..c5a15ddd97 100644 --- a/docs/language_names.yml +++ b/docs/language_names.yml @@ -178,6 +178,6 @@ xh: isiXhosa yi: ייִדיש yo: YorÚbÃĄ za: Saɯ cueŋƅ -zh: æą‰č¯­ +zh: įŽ€äŊ“中文 zh-hant: įšéĢ”ä¸­æ–‡ zu: isiZulu From 66ef70a2ba2806ad5a2dae9dcc7566609e5ed172 Mon Sep 17 00:00:00 2001 From: "jungsu.kwon" Date: Tue, 23 Jan 2024 04:43:22 +0900 Subject: [PATCH 147/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/path-operation-configuration.?= =?UTF-8?q?md`=20(#3639)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tutorial/path-operation-configuration.md | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 docs/ko/docs/tutorial/path-operation-configuration.md diff --git a/docs/ko/docs/tutorial/path-operation-configuration.md b/docs/ko/docs/tutorial/path-operation-configuration.md new file mode 100644 index 0000000000..22aad04213 --- /dev/null +++ b/docs/ko/docs/tutorial/path-operation-configuration.md @@ -0,0 +1,97 @@ +# ę˛Ŋ로 ë™ėž‘ 네렕 + +*ę˛Ŋ로 ėž‘ë™ 데ėŊ”ë ˆė´í„°*ëĨŧ ė„¤ė •í•˜ę¸° ėœ„í•´ė„œ ė „ë‹Ŧí• ėˆ˜ ėžˆëŠ” ëLJ 氀맀 ë§¤ę°œëŗ€ėˆ˜ę°€ ėžˆėŠĩ니다. + +!!! warning "ę˛Ŋęŗ " + ė•„ëž˜ ë§¤ę°œëŗ€ėˆ˜ë“¤ė€ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*가 ė•„ë‹Œ *ę˛Ŋ로 ėž‘ë™ 데ėŊ”ë ˆė´í„°*뗐 링렑 ė „ë‹Ŧ된다는 ė‚Ŧė‹¤ė„ 기ė–ĩí•˜ė‹­ė‹œė˜¤. + +## ė‘ë‹ĩ ėƒíƒœ ėŊ”드 + +*ę˛Ŋ로 ėž‘ë™*ė˜ ė‘ë‹ĩ뗐 ė‚ŦėšŠë  (HTTP) `status_code`ëĨŧ ė •ė˜í• ėˆ˜ ėžˆėŠĩ니다. + +`404`뙀 ę°™ė€ `int`형 ėŊ”드ëĨŧ 링렑 ė „ë‹Ŧí• ėˆ˜ ėžˆėŠĩ니다. + +í•˜ė§€ë§Œ 각 ėŊ”ë“œė˜ ė˜ë¯¸ëĨŧ ëǍëĨ¸ë‹¤ëŠ´, `status`뗐 ėžˆëŠ” 단ėļ• ėƒėˆ˜ë“¤ė„ ė‚ŦėšŠí• ėˆ˜ ėžˆėŠĩ니다: + +```Python hl_lines="3 17" +{!../../../docs_src/path_operation_configuration/tutorial001.py!} +``` + +각 ėƒíƒœ ėŊ”ë“œë“¤ė€ ė‘ë‹ĩ뗐 ė‚ŦėšŠë˜ëŠ°, OpenAPI ėŠ¤í‚¤ë§ˆė— ėļ”ę°€ëŠë‹ˆë‹¤. + +!!! note "揰눠렁 넏ëļ€ė‚Ŧ항" + ë‹¤ėŒęŗŧ ę°™ė´ ėž„íŦíŠ¸í•˜ė…”ë„ ėĸ‹ėŠĩ니다. `from starlette import status`. + + **FastAPI**는 ę°œë°œėž ė—ŦëŸŦëļ„ė˜ íŽ¸ė˜ëĨŧ ėœ„í•´ė„œ `starlette.status`뙀 동ėŧ한 `fastapi.status`ëĨŧ 렜ęŗĩ합니다. í•˜ė§€ë§Œ Starletteė—ė„œ 링렑 똍 ę˛ƒėž…ë‹ˆë‹¤. + +## 태그 + +(ëŗ´í†ĩ 단ėŧ `str`ė¸) `str`로 ęĩŦė„ąëœ `list`뙀 함ęģ˜ ë§¤ę°œëŗ€ėˆ˜ `tags`ëĨŧ ė „ë‹Ŧ하ė—Ŧ, `ę˛Ŋ로 ėž‘ë™`뗐 태그ëĨŧ ėļ”가할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="17 22 27" +{!../../../docs_src/path_operation_configuration/tutorial002.py!} +``` + +ė „ë‹Ŧ된 íƒœęˇ¸ë“¤ė€ OpenAPIė˜ ėŠ¤í‚¤ë§ˆė— ėļ”ę°€ë˜ëа, ėžë™ ëŦ¸ė„œ ė¸í„°íŽ˜ė´ėŠ¤ė—ė„œ ė‚ŦėšŠëŠë‹ˆë‹¤: + + + +## ėš”ė•Ŋęŗŧ 揰눠 + +`summary`뙀 `description`ė„ ėļ”가할 눘 ėžˆėŠĩ니다: + +```Python hl_lines="20-21" +{!../../../docs_src/path_operation_configuration/tutorial003.py!} +``` + +## ë…ėŠ¤íŠ¸ë§ėœŧ로 만든 揰눠 + +네ëĒ…ė€ ëŗ´í†ĩ 描떴맀溠 ė—ŦëŸŦ 뤄뗐 ęą¸ėŗėžˆę¸° 때ëŦ¸ė—, *ę˛Ŋ로 ėž‘ë™* ę¸°ėˆ ė„ í•¨ėˆ˜ ë…ėŠ¤íŠ¸ë§ 뗐 ė„ ė–¸í•  눘 ėžˆėŠĩ니다, ė´ëĨŧ **FastAPI**가 ë…ėŠ¤íŠ¸ë§ėœŧ로ëļ€í„° ėŊėŠĩ니다. + +마íŦë‹¤ėš´ ëŦ¸ë˛•ėœŧ로 ë…ėŠ¤íŠ¸ë§ė„ ėž‘ė„ąí•  눘 ėžˆėŠĩ니다, ėž‘ė„ąëœ 마íŦë‹¤ėš´ í˜•ė‹ė˜ ë…ėŠ¤íŠ¸ë§ė€ (마íŦë‹¤ėš´ė˜ 들ė—Ŧ듰揰ëĨŧ ęŗ ë ¤í•˜ė—Ŧ) ė˜Ŧ바ëĨ´ę˛Œ í™”ëŠ´ė— ėļœë Ĩ됩니다. + +```Python hl_lines="19-27" +{!../../../docs_src/path_operation_configuration/tutorial004.py!} +``` + +ė´ëŠ” 대화형 ëŦ¸ė„œė—ė„œ ė‚ŦėšŠëŠë‹ˆë‹¤: + + + +## ė‘ë‹ĩ 揰눠 + +`response_description` ë§¤ę°œëŗ€ėˆ˜ëĄœ ė‘ë‹ĩ뗐 관한 네ëĒ…ė„ ëĒ…ė‹œí•  눘 ėžˆėŠĩ니다: + +```Python hl_lines="21" +{!../../../docs_src/path_operation_configuration/tutorial005.py!} +``` + +!!! info "ė •ëŗ´" + `response_description`ė€ ęĩŦ랴렁ėœŧ로 ė‘ë‹ĩė„ ė§€ėš­í•˜ëŠ°, `description`ė€ ėŧë°˜ė ė¸ *ę˛Ŋ로 ėž‘ë™*ė„ ė§€ėš­í•Šë‹ˆë‹¤. + +!!! check "í™•ė¸" + OpenAPI는 각 *ę˛Ŋ로 ėž‘ë™*ė´ ė‘ë‹ĩ뗐 관한 네ëĒ…ė„ ėš”ęĩŦ할 ę˛ƒė„ ëĒ…ė‹œí•Šë‹ˆë‹¤. + + 따ëŧė„œ, ė‘ë‹ĩ뗐 관한 네ëĒ…ė´ ė—†ė„ę˛Ŋ뚰, **FastAPI**가 ėžë™ėœŧ로 "ė„ąęŗĩ ė‘ë‹ĩ" 뤑 하나ëĨŧ ėƒė„ąí•Šë‹ˆë‹¤. + + + +## 단ėŧ *ę˛Ŋ로 ėž‘ë™* ė§€ė›ė¤‘ë‹¨ + +단ėŧ *ę˛Ŋ로 ėž‘ë™*ė„ 뗆땠맀 ė•Šęŗ  ė§€ė›ė¤‘ë‹¨ė„ 해ė•ŧ한다면, `deprecated` ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė „ë‹Ŧ하면 됩니다. + +```Python hl_lines="16" +{!../../../docs_src/path_operation_configuration/tutorial006.py!} +``` + +대화형 ëŦ¸ė„œė— ė§€ė›ė¤‘ë‹¨ė´ëŧęŗ  í‘œė‹œëŠë‹ˆë‹¤. + + + +ė§€ė›ė¤‘ë‹¨ëœ ę˛Ŋėš°ė™€ ė§€ė›ė¤‘ë‹¨ ë˜ė§€ ė•Šė€ ę˛Ŋėš°ė— 대한 *ę˛Ŋ로 ėž‘ë™*ė´ ė–´ë–ģ枌 ëŗ´ė´ëŠ” ė§€ í™•ė¸í•˜ė‹­ė‹œė˜¤. + + + +## ė •ëĻŦ + +*ę˛Ŋ로 ėž‘ë™ 데ėŊ”ë ˆė´í„°*뗐 ë§¤ę°œëŗ€ėˆ˜(들)ëĨŧ ė „ë‹Ŧ함ėœŧ로 *ę˛Ŋ로 ėž‘ë™*ė„ ė„¤ė •í•˜ęŗ  ëŠ”íƒ€ë°ė´í„°ëĨŧ ėļ”ę°€í• ėˆ˜ ėžˆėŠĩ니다. From 77fe266a690d85aaad3da67cae4951bebcb8c0f5 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:44:45 +0000 Subject: [PATCH 148/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 96c920d859..d264b1c76c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/response-model.md`. PR [#2766](https://github.com/tiangolo/fastapi/pull/2766) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-multiple-params.md`. PR [#2461](https://github.com/tiangolo/fastapi/pull/2461) by [@PandaHun](https://github.com/PandaHun). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/query-params-str-validations.md`. PR [#2415](https://github.com/tiangolo/fastapi/pull/2415) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/python-types.md`. PR [#2267](https://github.com/tiangolo/fastapi/pull/2267) by [@jrim](https://github.com/jrim). From d532602eed903483da3ab815994cea104111ac09 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:46:50 +0000 Subject: [PATCH 149/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d264b1c76c..7895e7e857 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/static-files.md`. PR [#2957](https://github.com/tiangolo/fastapi/pull/2957) by [@jeesang7](https://github.com/jeesang7). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/response-model.md`. PR [#2766](https://github.com/tiangolo/fastapi/pull/2766) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-multiple-params.md`. PR [#2461](https://github.com/tiangolo/fastapi/pull/2461) by [@PandaHun](https://github.com/PandaHun). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/query-params-str-validations.md`. PR [#2415](https://github.com/tiangolo/fastapi/pull/2415) by [@hard-coders](https://github.com/hard-coders). From 167d2524b4dc945fe0b271a5a06de6f227b2a35c Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:47:31 +0000 Subject: [PATCH 150/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7895e7e857..d90e5966e9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Modify the description of `zh` - Traditional Chinese. PR [#10889](https://github.com/tiangolo/fastapi/pull/10889) by [@cherinyy](https://github.com/cherinyy). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/static-files.md`. PR [#2957](https://github.com/tiangolo/fastapi/pull/2957) by [@jeesang7](https://github.com/jeesang7). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/response-model.md`. PR [#2766](https://github.com/tiangolo/fastapi/pull/2766) by [@hard-coders](https://github.com/hard-coders). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/body-multiple-params.md`. PR [#2461](https://github.com/tiangolo/fastapi/pull/2461) by [@PandaHun](https://github.com/PandaHun). From 3f95f6fe4113a739cd03f46b99175793cb98e305 Mon Sep 17 00:00:00 2001 From: gyudoza Date: Tue, 23 Jan 2024 04:47:57 +0900 Subject: [PATCH 151/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/deployment/index.md`=20(#4561)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/deployment/index.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 docs/ko/docs/deployment/index.md diff --git a/docs/ko/docs/deployment/index.md b/docs/ko/docs/deployment/index.md new file mode 100644 index 0000000000..87b05b68f1 --- /dev/null +++ b/docs/ko/docs/deployment/index.md @@ -0,0 +1,21 @@ +# ë°°íŦ하기 - ë“¤ė–´ę°€ëŠ´ė„œ + +**FastAPI**ė„ ë°°íŦ하는 ę˛ƒė€ 비ęĩė  ė‰ŊėŠĩ니다. + +## ë°°íŦė˜ ė˜ë¯¸ + +**ë°°íŦ**란 ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ **ė‚ŦėšŠėžę°€ ė‚ŦėšŠ**할 눘 ėžˆë„ëĄ 하는 데 í•„ėš”í•œ ë‹¨ęŗ„ëĨŧ ėˆ˜í–‰í•˜ëŠ” ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +**ė›š API**ė˜ ę˛Ŋ뚰, ėŧë°˜ė ėœŧ로 **ė‚ŦėšŠėž**가 ė¤‘ë‹¨ė´ë‚˜ 똤ëĨ˜ ė—†ė´ ė• í”ŒëĻŦėŧ€ė´ė…˜ė— íš¨ėœ¨ė ėœŧ로 **ė ‘ęˇŧ**할 눘 ėžˆë„ëĄ ėĸ‹ė€ ė„ąëŠĨ, ė•ˆė •ė„ą ë“ąė„ 렜ęŗĩ하는 **ė„œë˛„ 프로그램ęŗŧ** 함ęģ˜ **ė›ę˛Š ė‹œėŠ¤í…œ**뗐 ė´ëĨŧ ė„¤ėš˜í•˜ëŠ” ėž‘ė—…ė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +ė´ëŠ” ė§€ė†ė ėœŧ로 ėŊ”드ëĨŧ ëŗ€ę˛Ŋí•˜ęŗ , ė§€ėš°ęŗ , ėˆ˜ė •í•˜ęŗ , 개발 ė„œë˛„ëĨŧ ė¤‘ė§€í–ˆë‹¤ę°€ ë‹¤ė‹œ ė‹œėž‘í•˜ëŠ” ë“ąė˜ **개발** ë‹¨ęŗ„ė™€ ëŒ€ėĄ°ëŠë‹ˆë‹¤. + +## ë°°íŦ ė „ëžĩ + +ė‚ŦėšŠí•˜ëŠ” 도ęĩŦ나 íŠšė • ė‚ŦëĄ€ė— 따ëŧ ė—ŦëŸŦ 氀맀 ë°Šë˛•ė´ ėžˆėŠĩ니다. + +ë°°íŦ도ęĩŦë“¤ė„ ė‚ŦėšŠí•˜ė—Ŧ 링렑 **ė„œë˛„ė— ë°°íŦ**하거나, ë°°íŦėž‘ė—…ė˜ ėŧëļ€ëĨŧ ėˆ˜í–‰í•˜ëŠ” **클ëŧėš°ë“œ ė„œëš„ėŠ¤** 또는 다ëĨ¸ ë°Šë˛•ė„ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다. + +**FastAPI** ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ ë°°íŦ할 때 ė„ íƒí•  눘 ėžˆëŠ” ëLJ 氀맀 ėŖŧėš” ë°Šë˛•ė„ ëŗ´ė—Ŧ 드ëĻŦ겠ėŠĩ니다 (대ëļ€ëļ„ ë‹¤ëĨ¸ ėœ í˜•ė˜ ė›š ė• í”ŒëĻŦėŧ€ė´ė…˜ė—ë„ ė ėšŠëŠë‹ˆë‹¤). + +ë‹¤ėŒ ė°¨ëĄ€ė— ėžė„¸í•œ ë‚´ėšŠęŗŧ ė´ëĨŧ ėœ„í•œ ëLJ 氀맀 ę¸°ėˆ ė„ ëŗŧ 눘 ėžˆėŠĩ니다. ✨ From 79ab317cbdad7a24dcf4b8f17492f54ba2f8a130 Mon Sep 17 00:00:00 2001 From: gyudoza Date: Tue, 23 Jan 2024 04:49:13 +0900 Subject: [PATCH 152/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/deployment/server-workers.md`=20(#4935?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/deployment/server-workers.md | 180 ++++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 docs/ko/docs/deployment/server-workers.md diff --git a/docs/ko/docs/deployment/server-workers.md b/docs/ko/docs/deployment/server-workers.md new file mode 100644 index 0000000000..5653c55e3b --- /dev/null +++ b/docs/ko/docs/deployment/server-workers.md @@ -0,0 +1,180 @@ +# ė„œë˛„ ė›Œėģ¤ - ęĩŦ니ėŊ˜ęŗŧ ėœ ëš„ėŊ˜ + +ė „ë‹¨ęŗ„ė—ė„œė˜ ë°°íŦ ę°œë…ë“¤ė„ ë‹¤ė‹œ í™•ė¸í•´ëŗ´ę˛ ėŠĩ니다: + +* ëŗ´ė•ˆ - HTTPS +* ė„œë˛„ ė‹œėž‘ęŗŧ ë™ė‹œė— ė‹¤í–‰í•˜ę¸° +* ėžŦė‹œėž‘ +* **ëŗĩė œëŗ¸ (ė‹¤í–‰ ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤ė˜ ėˆĢėž)** +* 메ëǍëĻŦ +* ė‹œėž‘í•˜ę¸° ė „ė˜ ė—ŦëŸŦ ë‹¨ęŗ„ë“¤ + +ė§€ę¸ˆęšŒė§€ ëŦ¸ė„œė˜ ëĒ¨ë“  튜토ëĻŦė–ŧė„ ė°¸ęŗ í•˜ė—Ŧ **단ėŧ í”„ëĄœė„¸ėŠ¤**로 Uvicornęŗŧ ę°™ė€ **ė„œë˛„ 프로그램**ė„ ė‹¤í–‰í–ˆė„ ę˛ƒėž…ë‹ˆë‹¤. + +ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ ë°°íŦ할 때 **ë‹¤ė¤‘ ėŊ”ė–´**ëĨŧ í™œėšŠí•˜ęŗ  더 ë§Žė€ ėš”ė˛­ė„ 래ëĻŦ할 눘 ėžˆë„ëĄ **í”„ëĄœė„¸ėŠ¤ ëŗĩė œëŗ¸**ė´ í•„ėš”í•Šë‹ˆë‹¤. + +ė „ ęŗŧė •ė´ė—ˆë˜ [ë°°íŦ 개념들](./concepts.md){.internal-link target=_blank}ė—ė„œ ëŗ¸ 枃래ëŸŧ ė—ŦëŸŦ氀맀 ë°Šë˛•ė´ ėĄ´ėžŦ합니다. + +ė§€ę¸ˆëļ€í„° **ęĩŦ니ėŊ˜**ė„ **ėœ ëš„ėŊ˜ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤**뙀 함ęģ˜ ė‚ŦėšŠí•˜ëŠ” ë°Šë˛•ė„ ė•Œë ¤ë“œëĻŦ겠ėŠĩ니다. + +!!! ė •ëŗ´ + 만ė•Ŋ 도ėģ¤ė™€ ėŋ ë˛„ë„¤í‹°ėŠ¤ ę°™ė€ ėģ¨í…Œė´ë„ˆëĨŧ ė‚ŦėšŠí•˜ęŗ  ėžˆë‹¤ëŠ´ ë‹¤ėŒ ėą•í„° [FastAPI뙀 ėģ¨í…Œė´ë„ˆ - 도ėģ¤](./docker.md){.internal-link target=_blank}ė—ė„œ 더 ë§Žė€ ė •ëŗ´ëĨŧ ė–ģė„ 눘 ėžˆėŠĩ니다. + + 특히, ėŋ ë˛„ë„¤í‹°ėŠ¤ė—ė„œ ė‹¤í–‰í•  때는 ęĩŦ니ėŊ˜ė„ ė‚ŦėšŠí•˜ė§€ ė•Šęŗ  ëŒ€ė‹  ėģ¨í…Œė´ë„ˆë‹š í•˜ë‚˜ė˜ ėœ ëš„ėŊ˜ í”„ëĄœė„¸ėŠ¤ëĨŧ ė‹¤í–‰í•˜ëŠ” ę˛ƒė´ ėĸ‹ėŠĩ니다. ė´ ėžĨė˜ 뒷ëļ€ëļ„ė—ė„œ 네ëĒ…í•˜ę˛ ėŠĩ니다. + +## ęĩŦ니ėŊ˜ęŗŧ ėœ ëš„ėŊ˜ ė›Œėģ¤ + +**Gunicorn**ė€ **WSGI í‘œė¤€**ė„ ėŖŧ로 ė‚ŦėšŠí•˜ëŠ” ė• í”ŒëĻŦėŧ€ė´ė…˜ ė„œë˛„ėž…ë‹ˆë‹¤. ė´ę˛ƒė€ ęĩŦ니ėŊ˜ė´ 플ëŧ늤íŦ뙀 ėŸęŗ ė™€ ę°™ė€ ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ 렜ęŗĩ할 눘 ėžˆë‹¤ëŠ” ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤. ęĩŦ니ėŊ˜ ėžė˛´ëŠ” ėĩœė‹  **ASGI í‘œė¤€**ė„ ė‚ŦėšŠí•˜ę¸° 때ëŦ¸ė— FastAPI뙀 í˜¸í™˜ë˜ė§€ ė•ŠėŠĩ니다. + +í•˜ė§€ë§Œ ęĩŦ니ėŊ˜ė€ **í”„ëĄœė„¸ėŠ¤ 관ëĻŦėž**ė—­í• ė„ í•˜ęŗ  ė‚ŦėšŠėžė—ę˛Œ íŠšė • **ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ í´ëž˜ėŠ¤**ëĨŧ ė•Œë ¤ė¤ë‹ˆë‹¤. 그런 ë‹¤ėŒ ęĩŦ니ėŊ˜ė€ 해당 í´ëž˜ėŠ¤ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ 하나 ė´ėƒė˜ **ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤**ëĨŧ ė‹œėž‘í•Šë‹ˆë‹¤. + +꡸ëĻŦęŗ  **ėœ ëš„ėŊ˜**ė€ **ęĩŦ니ėŊ˜ęŗŧ 호환되는 ė›Œėģ¤ í´ëž˜ėŠ¤**가 ėžˆėŠĩ니다. + +ė´ ėĄ°í•Šė„ ė‚ŦėšŠí•˜ė—Ŧ ęĩŦ니ėŊ˜ė€ **í”„ëĄœė„¸ėŠ¤ 관ëĻŦėž** ė—­í• ė„ 하며 **íŦ트**뙀 **IP**ëĨŧ ę´€ė°°í•˜ęŗ , **ėœ ëš„ėŊ˜ í´ëž˜ėŠ¤**ëĨŧ ė‹¤í–‰í•˜ëŠ” ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ëĄœ í†ĩė‹  ė •ëŗ´ëĨŧ **ė „ė†Ą**합니다. + +꡸ëĻŦęŗ  ë‚˜ė„œ ęĩŦ니ėŊ˜ęŗŧ 호환되는 **ėœ ëš„ėŊ˜ ė›Œėģ¤** í´ëž˜ėŠ¤ëŠ” ęĩŦ니ėŊ˜ė´ ëŗ´ë‚¸ ë°ė´í„°ëĨŧ FastAPIė—ė„œ ė‚ŦėšŠí•˜ę¸° ėœ„í•œ ASGI í‘œė¤€ėœŧ로 ëŗ€í™˜í•˜ëŠ” ėŧė„ 담당합니다. + +## ęĩŦ니ėŊ˜ęŗŧ ėœ ëš„ėŊ˜ ė„¤ėš˜í•˜ę¸° + +
+ +```console +$ pip install "uvicorn[standard]" gunicorn + +---> 100% +``` + +
+ +ė´ ëĒ…ë šė–´ëŠ” ėœ ëš„ėŊ˜ `standard` ėļ”ę°€ íŒ¨í‚¤ė§€(ėĸ‹ė€ ė„ąëŠĨė„ ėœ„í•œ)뙀 ęĩŦ니ėŊ˜ė„ ė„¤ėš˜í•  ę˛ƒėž…ë‹ˆë‹¤. + +## ęĩŦ니ėŊ˜ė„ ėœ ëš„ėŊ˜ ė›Œėģ¤ė™€ 함ęģ˜ ė‹¤í–‰í•˜ę¸° + +ė„¤ėš˜ 후 ęĩŦ니ėŊ˜ ė‹¤í–‰í•˜ę¸°: + +
+ +```console +$ gunicorn main:app --workers 4 --worker-class uvicorn.workers.UvicornWorker --bind 0.0.0.0:80 + +[19499] [INFO] Starting gunicorn 20.1.0 +[19499] [INFO] Listening at: http://0.0.0.0:80 (19499) +[19499] [INFO] Using worker: uvicorn.workers.UvicornWorker +[19511] [INFO] Booting worker with pid: 19511 +[19513] [INFO] Booting worker with pid: 19513 +[19514] [INFO] Booting worker with pid: 19514 +[19515] [INFO] Booting worker with pid: 19515 +[19511] [INFO] Started server process [19511] +[19511] [INFO] Waiting for application startup. +[19511] [INFO] Application startup complete. +[19513] [INFO] Started server process [19513] +[19513] [INFO] Waiting for application startup. +[19513] [INFO] Application startup complete. +[19514] [INFO] Started server process [19514] +[19514] [INFO] Waiting for application startup. +[19514] [INFO] Application startup complete. +[19515] [INFO] Started server process [19515] +[19515] [INFO] Waiting for application startup. +[19515] [INFO] Application startup complete. +``` + +
+ +각 ė˜ĩė…˜ė´ ëŦ´ė—‡ė„ ė˜ë¯¸í•˜ëŠ”ė§€ ė‚´íŽ´ë´…ė‹œë‹¤: + +* ė´ę˛ƒė€ ėœ ëš„ėŊ˜ęŗŧ ë˜‘ę°™ė€ ëŦ¸ë˛•ėž…ë‹ˆë‹¤. `main`ė€ íŒŒė´ėŦ ëĒ¨ë“ˆ ë„¤ėž„ "`main`"ė„ ė˜ë¯¸í•˜ë¯€ëĄœ `main.py`파ėŧė„ ëœģ합니다. ꡸ëĻŦęŗ  `app`ė€ **FastAPI** ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ ë“¤ė–´ ėžˆëŠ” ëŗ€ėˆ˜ė˜ ė´ëĻ„ėž…ë‹ˆë‹¤. + * `main:app`ė´ íŒŒė´ėŦė˜ `import` ëŦ¸ë˛•ęŗŧ 흡ė‚Ŧ한 ëŠ´ė´ ėžˆë‹¤ëŠ” 깸 ė•Œ 눘 ėžˆėŠĩ니다: + + ```Python + from main import app + ``` + + * ęŗ§, `main:app`ė•ˆė— ėžˆëŠ” ėŊœëĄ ė˜ ė˜ë¯¸ëŠ” íŒŒė´ėŦė—ė„œ `from main import app`ė—ė„œė˜ `import`뙀 같ėŠĩ니다. +* `--workers`: ė‚ŦėšŠí•  ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ė˜ ę°œėˆ˜ė´ëŠ° ėˆĢėžë§Œíŧė˜ ėœ ëš„ėŊ˜ ė›Œėģ¤ëĨŧ ė‹¤í–‰í•Šë‹ˆë‹¤. ė´ ė˜ˆė œė—ė„œëŠ” 4ę°œė˜ ė›Œėģ¤ëĨŧ ė‹¤í–‰í•Šë‹ˆë‹¤. +* `--worker-class`: ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ė—ė„œ ė‚ŦėšŠí•˜ę¸° ėœ„í•œ ęĩŦ니ėŊ˜ęŗŧ 호환되는 ė›Œėģ¤í´ëž˜ėФ. + * ė´ëŸ°ė‹ėœŧ로 ęĩŦ니ėŊ˜ė´ import하ė—Ŧ ė‚ŦėšŠí•  눘 ėžˆëŠ” í´ëž˜ėŠ¤ëĨŧ ė „ë‹Ŧí•´ė¤ë‹ˆë‹¤: + + ```Python + import uvicorn.workers.UvicornWorker + ``` + +* `--bind`: ęĩŦ니ėŊ˜ė´ ę´€ė°°í•  IP뙀 íŦ트ëĨŧ ė˜ë¯¸í•Šë‹ˆë‹¤. ėŊœëĄ  (`:`)ė„ ė‚ŦėšŠí•˜ė—Ŧ IP뙀 íŦ트ëĨŧ ęĩŦëļ„핊니다. + * 만ė•Ŋ뗐 `--bind 0.0.0.0:80` (ęĩŦ니ėŊ˜ ė˜ĩė…˜) ëŒ€ė‹  ėœ ëš„ėŊ˜ė„ 링렑 ė‹¤í–‰í•˜ęŗ  ė‹ļ다면 `--host 0.0.0.0`ęŗŧ `--port 80`ė„ ė‚ŦėšŠí•´ė•ŧ 합니다. + +ėļœë Ĩė—ė„œ 각 í”„ëĄœė„¸ėŠ¤ė— 대한 **PID** (process ID)ëĨŧ í™•ė¸í•  눘 ėžˆėŠĩ니다. (ë‹¨ėˆœí•œ ėˆĢėžėž…ë‹ˆë‹¤) + +ėļœë Ĩ ë‚´ėšŠ: + +* ęĩŦ니ėŊ˜ **í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €**는 PID `19499`로 ė‹¤í–‰ëŠë‹ˆë‹¤. (링렑 ė‹¤í–‰í•  ę˛Ŋ뚰 ėˆĢėžę°€ 다ëĨŧ 눘 ėžˆėŠĩ니다) +* ë‹¤ėŒėœŧ로 `Listening at: http://0.0.0.0:80`ė„ ė‹œėž‘í•Šë‹ˆë‹¤. +* 그런 ë‹¤ėŒ ė‚ŦėšŠí•´ė•ŧ할 `uvicorn.workers.UvicornWorker`ė˜ ė›Œėģ¤í´ëž˜ėФëĨŧ íƒė§€í•Šë‹ˆë‹¤. +* ꡸ëĻŦęŗ  PID `19511`, `19513`, `19514`, ꡸ëĻŦęŗ  `19515`ëĨŧ 氀맄 **4ę°œė˜ ė›Œėģ¤**ëĨŧ ė‹¤í–‰í•Šë‹ˆë‹¤. + + +또한 ęĩŦ니ėŊ˜ė€ ė›Œėģ¤ė˜ 눘ëĨŧ ėœ ė§€í•˜ę¸° ėœ„í•´ **ėŖŊė€ í”„ëĄœė„¸ėŠ¤**ëĨŧ 관ëĻŦí•˜ęŗ  **ėžŦė‹œėž‘**하는 ėž‘ė—…ė„ ėą…ėž„ė§‘ë‹ˆë‹¤. ė´ę˛ƒė€ ė´ë˛ˆ ėžĨ ėƒë‹¨ ëĒŠëĄė˜ **ėžŦė‹œėž‘** ę°œë…ė„ ëļ€ëļ„렁ėœŧ로 ë„ė™€ėŖŧ는 ę˛ƒėž…ë‹ˆë‹¤. + +꡸ëŸŧė—ë„ ëļˆęĩŦí•˜ęŗ  í•„ėš”í•  ę˛Ŋ뚰 뙏ëļ€ė—ė„œ **ęĩŦ니ėŊ˜ė„ ėžŦė‹œėž‘**í•˜ęŗ , í˜šė€ **ė„œë˛„ëĨŧ ė‹œėž‘í•  때 ė‹¤í–‰**할 눘 ėžˆë„ëĄ í•˜ęŗ  ė‹ļė–´í•  ę˛ƒėž…ë‹ˆë‹¤. + +## ėœ ëš„ėŊ˜ęŗŧ ė›Œėģ¤ + +ėœ ëš„ėŊ˜ė€ ëLJ ę°œė˜ **ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤**뙀 함ęģ˜ ė‹¤í–‰í•  눘 ėžˆëŠ” ė„ íƒė§€ę°€ ėžˆėŠĩ니다. + +꡸ëŸŧė—ë„ ëļˆęĩŦí•˜ęŗ , ėœ ëš„ėŊ˜ė€ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ëĨŧ ë‹¤ëŖ¨ëŠ” ë°ė— ėžˆė–´ė„œ ęĩŦ니ėŊ˜ëŗ´ë‹¤ 더 ė œí•œė ėž…ë‹ˆë‹¤. 따ëŧė„œ ė´ ėˆ˜ė¤€(íŒŒė´ėŦ ėˆ˜ė¤€)ė˜ í”„ëĄœė„¸ėŠ¤ 관ëĻŦėžëĨŧ ė‚ŦėšŠí•˜ë ¤ëŠ´ ęĩŦ니ėŊ˜ė„ í”„ëĄœė„¸ėŠ¤ 관ëĻŦėžëĄœ ė‚ŦėšŠí•˜ëŠ” ę˛ƒė´ ėĸ‹ėŠĩ니다. + +ëŗ´í†ĩ ė´ë ‡ę˛Œ ė‹¤í–‰í•  눘 ėžˆėŠĩ니다: + +
+ +```console +$ uvicorn main:app --host 0.0.0.0 --port 8080 --workers 4 +INFO: Uvicorn running on http://0.0.0.0:8080 (Press CTRL+C to quit) +INFO: Started parent process [27365] +INFO: Started server process [27368] +INFO: Waiting for application startup. +INFO: Application startup complete. +INFO: Started server process [27369] +INFO: Waiting for application startup. +INFO: Application startup complete. +INFO: Started server process [27370] +INFO: Waiting for application startup. +INFO: Application startup complete. +INFO: Started server process [27367] +INFO: Waiting for application startup. +INFO: Application startup complete. +``` + +
+ +ėƒˆëĄœėš´ ė˜ĩė…˜ė¸ `--workers`ė€ ėœ ëš„ėŊ˜ė—ę˛Œ 4ę°œė˜ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ëĨŧ ė‚ŦėšŠí•œë‹¤ęŗ  ė•Œë ¤ė¤ë‹ˆë‹¤. + +각 í”„ëĄœė„¸ėŠ¤ė˜ **PID**ëĨŧ í™•ė¸í•  눘 ėžˆėŠĩ니다. `27365`는 ėƒėœ„ í”„ëĄœė„¸ėŠ¤(**í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €**), ꡸ëĻŦęŗ  ę°ę°ė˜ ė›Œėģ¤í”„ëĄœė„¸ėŠ¤ëŠ” `27368`, `27369`, `27370`, ꡸ëĻŦęŗ  `27367`ėž…ë‹ˆë‹¤. + +## ë°°íŦ 개념들 + +ė—Ŧę¸°ė—ė„œëŠ” **ėœ ëš„ėŊ˜ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤**ëĨŧ 관ëĻŦ하는 **ęĩŦ니ėŊ˜**(또는 ėœ ëš„ėŊ˜)ė„ ė‚ŦėšŠí•˜ė—Ŧ ė• í”ŒëĻŦėŧ€ė´ė…˜ė„ **ëŗ‘ë Ŧ화**í•˜ęŗ , CPU **멀티 ėŊ”ė–´**ė˜ ėžĨė ė„ í™œėšŠí•˜ęŗ , **더 ë§Žė€ ėš”ė˛­**ė„ 래ëĻŦ할 눘 ėžˆëŠ” ë°Šë˛•ė„ ė‚´íŽ´ëŗ´ė•˜ėŠĩ니다. + +ė›Œėģ¤ëĨŧ ė‚ŦėšŠí•˜ëŠ” ę˛ƒė€ ë°°íŦ 개념 ëĒŠëĄė—ė„œ ėŖŧ로 **ëŗĩė œëŗ¸** ëļ€ëļ„ęŗŧ **ėžŦė‹œėž‘**뗐 ė•Ŋ간 ë„ė›€ė´ ë˜ė§€ë§Œ 다ëĨ¸ ë°°íŦ 개념들도 ë‹¤ëŖ¨ė–´ė•ŧ 합니다: + +* **ëŗ´ė•ˆ - HTTPS** +* **ė„œë˛„ ė‹œėž‘ęŗŧ ë™ė‹œė— ė‹¤í–‰í•˜ę¸°** +* ***ėžŦė‹œėž‘*** +* ëŗĩė œëŗ¸ (ė‹¤í–‰ ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤ė˜ ėˆĢėž) +* **메ëǍëĻŦ** +* **ė‹œėž‘í•˜ę¸° ė „ė˜ ė—ŦëŸŦ ë‹¨ęŗ„ë“¤** + + +## ėģ¨í…Œė´ë„ˆė™€ 도ėģ¤ + +ë‹¤ėŒ ėžĨė¸ [FastAPI뙀 ėģ¨í…Œė´ë„ˆ - 도ėģ¤](./docker.md){.internal-link target=_blank}ė—ė„œ 다ëĨ¸ **ë°°íŦ 개념들**ė„ ë‹¤ëŖ¨ëŠ” ė „ëžĩë“¤ė„ ė•Œë ¤ë“œëĻŦ겠ėŠĩ니다. + +또한 간단한 ėŧ€ė´ėŠ¤ė—ė„œ ė‚ŦėšŠí•  눘 ėžˆëŠ”, **ęĩŦ니ėŊ˜ęŗŧ ėœ ëš„ėŊ˜ ė›Œėģ¤**가 íŦ함ëŧ ėžˆëŠ” **ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€**뙀 함ęģ˜ ëLJ 氀맀 ę¸°ëŗ¸ ęĩŦė„ąė„ ëŗ´ė—Ŧ드ëĻŦ겠ėŠĩ니다. + +꡸ëĻŦęŗ  단ėŧ ėœ ëš„ėŊ˜ í”„ëĄœė„¸ėŠ¤(ęĩŦ니ėŊ˜ ė—†ė´)ëĨŧ ė‹¤í–‰í•  눘 ėžˆë„ëĄ **ė‚ŦėšŠėž ėžė‹ ė˜ ė´ë¯¸ė§€ëĨŧ ė˛˜ėŒëļ€í„° ęĩŦėļ•**하는 방법도 ëŗ´ė—Ŧ드ëĻŦ겠ėŠĩ니다. ė´ëŠ” 간단한 ęŗŧė •ė´ëŠ°, **ėŋ ë˛„ë„¤í‹°ėŠ¤**뙀 ę°™ė€ ëļ„ė‚° ėģ¨í…Œė´ë„ˆ 관ëĻŦ ė‹œėŠ¤í…œė„ ė‚ŦėšŠí•  때 ėˆ˜í–‰í•  ėž‘ė—…ėž…ë‹ˆë‹¤. + +## ėš”ė•Ŋ + +ë‹šė‹ ė€ **ęĩŦ니ėŊ˜**(또는 ėœ ëš„ėŊ˜)ė„ ėœ ëš„ėŊ˜ ė›Œėģ¤ė™€ 함ęģ˜ í”„ëĄœė„¸ėŠ¤ 관ëĻŦėžëĄœ ė‚ŦėšŠí•˜ė—Ŧ **멀티-ėŊ”ė–´ CPU**ëĨŧ í™œėšŠí•˜ëŠ” **멀티 í”„ëĄœė„¸ėŠ¤ëĨŧ ëŗ‘ë Ŧ로 ė‹¤í–‰**할 눘 ėžˆėŠĩ니다. + +다ëĨ¸ ë°°íŦ ę°œë…ė„ 링렑 ë‹¤ëŖ¨ëŠ´ė„œ **ėžė‹ ë§Œė˜ ë°°íŦ ė‹œėŠ¤í…œ**ė„ ęĩŦė„ąí•˜ëŠ” ę˛Ŋ뚰 ė´ëŸŦ한 도ęĩŦ뙀 ę°œë…ë“¤ė„ í™œėšŠí•  눘 ėžˆėŠĩ니다. + +ë‹¤ėŒ ėžĨė—ė„œ ėģ¨í…Œė´ë„ˆ(똈: 도ėģ¤ ë° ėŋ ë˛„ë„¤í‹°ėŠ¤)뙀 함ęģ˜í•˜ëŠ” **FastAPI**뗐 대해 ë°°ė›Œëŗ´ė„¸ėš”. ė´ëŸŦ한 íˆ´ė—ëŠ” 다ëĨ¸ **ë°°íŦ 개념**ë“¤ė„ 간단히 해결할 눘 ėžˆëŠ” ë°Šë˛•ė´ ėžˆėŠĩ니다. ✨ From 6f4223430124a30648726e02db429cd13f9e44dd Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:49:43 +0000 Subject: [PATCH 153/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d90e5966e9..7f88bc3795 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/path-operation-configuration.md`. PR [#3639](https://github.com/tiangolo/fastapi/pull/3639) by [@jungsu-kwon](https://github.com/jungsu-kwon). * 🌐 Modify the description of `zh` - Traditional Chinese. PR [#10889](https://github.com/tiangolo/fastapi/pull/10889) by [@cherinyy](https://github.com/cherinyy). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/static-files.md`. PR [#2957](https://github.com/tiangolo/fastapi/pull/2957) by [@jeesang7](https://github.com/jeesang7). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/response-model.md`. PR [#2766](https://github.com/tiangolo/fastapi/pull/2766) by [@hard-coders](https://github.com/hard-coders). From 6c3d8eb2d9318e4e2a5d3e697b18e1bcdacb290e Mon Sep 17 00:00:00 2001 From: HyeonJeong Yeo <84669195+nearnear@users.noreply.github.com> Date: Tue, 23 Jan 2024 04:50:44 +0900 Subject: [PATCH 154/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/deployment/docker.md`=20(#5657)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/deployment/docker.md | 698 ++++++++++++++++++++++++++++++ 1 file changed, 698 insertions(+) create mode 100644 docs/ko/docs/deployment/docker.md diff --git a/docs/ko/docs/deployment/docker.md b/docs/ko/docs/deployment/docker.md new file mode 100644 index 0000000000..587b445fc2 --- /dev/null +++ b/docs/ko/docs/deployment/docker.md @@ -0,0 +1,698 @@ +# ėģ¨í…Œė´ë„ˆė˜ FastAPI - 도ėģ¤ + +FastAPI ė–´í”ŒëĻŦėŧ€ė´ė…˜ė„ ë°°íŦ할 때 ėŧë°˜ė ė¸ ė ‘ęˇŧ ë°Šë˛•ė€ **ëĻŦëˆ…ėŠ¤ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**ëĨŧ ėƒė„ąí•˜ëŠ” ę˛ƒėž…ë‹ˆë‹¤. ė´ ë°Šë˛•ė€ ėŖŧ로 **도ėģ¤**ëĨŧ ė‚ŦėšŠí•´ ė´ëŖ¨ė–´ė§‘ë‹ˆë‹¤. 그런 ë‹¤ėŒ 해당 ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ ëLJ氀맀 방법ėœŧ로 ë°°íŦ할 눘 ėžˆėŠĩ니다. + +ëĻŦëˆ…ėŠ¤ ėģ¨í…Œė´ë„ˆëĨŧ ė‚ŦėšŠí•˜ëŠ” ë°ė—ëŠ” **ëŗ´ė•ˆ**, **반ëŗĩ 가ëŠĨė„ą**, **ë‹¨ėˆœí•¨** ë“ąė˜ ėžĨė ė´ ėžˆėŠĩ니다. + +!!! 팁 + ė‹œę°„ė— ė̓揰溠 ėžˆęŗ  ė´ë¯¸ ė´ëŸ°ę˛ƒë“¤ė„ ė•Œęŗ  ėžˆë‹¤ëŠ´ [`Dockerfile`👇](#build-a-docker-image-for-fastapi)로 ė í”„í•  눘 ėžˆėŠĩ니다. + +
+도ėģ¤íŒŒėŧ 미ëĻŦëŗ´ę¸° 👀 + +```Dockerfile +FROM python:3.9 + +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +COPY ./app /code/app + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] + +# If running behind a proxy like Nginx or Traefik add --proxy-headers +# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"] +``` + +
+ +## ėģ¨í…Œė´ë„ˆëž€ + +ėģ¨í…Œė´ë„ˆ(ėŖŧ로 ëĻŦëˆ…ėŠ¤ ėģ¨í…Œė´ë„ˆ)는 ė–´í”ŒëĻŦėŧ€ė´ė…˜ė˜ ė˜ėĄ´ė„ąęŗŧ í•„ėš”í•œ 파ėŧë“¤ė„ ëĒ¨ë‘ íŒ¨í‚¤ė§•í•˜ëŠ” ë§¤ėš° **가ë˛ŧ뚴** ë°Šë˛•ėž…ë‹ˆë‹¤. ėģ¨í…Œė´ë„ˆëŠ” ę°™ė€ ė‹œėŠ¤í…œė— ėžˆëŠ” 다ëĨ¸ ėģ¨í…Œė´ë„ˆ(다ëĨ¸ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ë‚˜ ėš”ė†Œë“¤)뙀 독ëĻŊ렁ėœŧ로 ėœ ė§€ëŠë‹ˆë‹¤. + +ëĻŦëˆ…ėŠ¤ ėģ¨í…Œė´ë„ˆëŠ” í˜¸ėŠ¤íŠ¸(ë¨¸ė‹ , ę°€ėƒ ë¨¸ė‹ , 클ëŧėš°ë“œ ė„œë˛„ 등)뙀 ę°™ė€ ëĻŦëˆ…ėŠ¤ ėģ¤ë„ė„ ė‚ŦėšŠí•´ ė‹¤í–‰ëŠë‹ˆë‹¤. ė´ë§ė€ ëĻŦëˆ…ėŠ¤ ėģ¨í…Œė´ë„ˆę°€ (렄랴 뚴똁랴렜ëĨŧ ëĒ¨ë°Ší•˜ëŠ” 다ëĨ¸ ę°€ėƒ ë¨¸ė‹ ęŗŧ 비ęĩí–ˆė„ 때) ë§¤ėš° ę°€ëŗë‹¤ëŠ” ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +ė´ ë°Šë˛•ė„ í†ĩ해, ėģ¨í…Œė´ë„ˆëŠ” 링렑 í”„ëĄœė„¸ėŠ¤ëĨŧ ė‹¤í–‰í•˜ëŠ” 것ęŗŧ ëš„ėŠˇí•œ ė •ë„ė˜ **ė ė€ ėžė›**ė„ ė†Œëš„í•Šë‹ˆë‹¤ (ę°€ėƒ ë¨¸ė‹ ė€ 훨ė”Ŧ ë§Žė€ ėžė›ė„ ė†Œëš„í•  ę˛ƒėž…ë‹ˆë‹¤). + +ėģ¨í…Œė´ë„ˆëŠ” 또한 ęˇ¸ë“¤ë§Œė˜ **독ëĻŊ된** ė‹¤í–‰ í”„ëĄœė„¸ėŠ¤ (ėŧë°˜ė ėœŧ로 í•˜ë‚˜ė˜ í”„ëĄœė„¸ėŠ¤ëĄœ ėļŠëļ„핊니다), 파ėŧ ė‹œėŠ¤í…œ, ꡸ëĻŦęŗ  ë„¤íŠ¸ė›ŒíŦëĨŧ ę°€ė§€ë¯€ëĄœ ë°°íŦ, ëŗ´ė•ˆ, 개발 및 기타 ęŗŧė •ė„ ë‹¨ėˆœí™” 합니다. + +## ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëž€ + +**ėģ¨í…Œė´ë„ˆ**는 **ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**ëĨŧ ė‹¤í–‰í•œ 것 ėž…ë‹ˆë‹¤. + +ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëž€ ėģ¨í…Œė´ë„ˆė— í•„ėš”í•œ ëĒ¨ë“  파ėŧ, 환ę˛Ŋ ëŗ€ėˆ˜ ꡸ëĻŦęŗ  디폴트 ëĒ…ë š/í”„ëĄœęˇ¸ëž¨ė˜ **렕렁** ë˛„ė „ėž…ë‹ˆë‹¤. ė—Ŧę¸°ė„œ **렕렁**ė´ëž€ ë§ė€ ėģ¨í…Œė´ë„ˆ **ė´ë¯¸ė§€**가 ėž‘ë™ë˜ęą°ë‚˜ ė‹¤í–‰ë˜ė§€ ė•Šėœŧ늰, ë‹¨ė§€ íŒ¨í‚¤ė§€ 파ėŧęŗŧ 메타 ë°ė´í„°ëŧ는 ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +ė €ėžĨ된 렕렁 ėģ¨í…ė¸ ė¸ **ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**뙀 ëŒ€ėĄ°ë˜ę˛Œ, **ėģ¨í…Œė´ë„ˆ**란 ëŗ´í†ĩ ė‹¤í–‰ë  눘 ėžˆëŠ” ėž‘ë™ ė¸ėŠ¤í„´ėŠ¤ëĨŧ ė˜ë¯¸í•Šë‹ˆë‹¤. + +**ėģ¨í…Œė´ë„ˆ**가 (**ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**로 ëļ€í„°) ė‹œėž‘ë˜ęŗ  ė‹¤í–‰ë˜ëŠ´, ėģ¨í…Œė´ë„ˆëŠ” 파ėŧė´ë‚˜ 환ę˛Ŋ ëŗ€ėˆ˜ëĨŧ ėƒė„ąí•˜ęą°ë‚˜ ëŗ€ę˛Ŋ할 눘 ėžˆėŠĩ니다. ė´ëŸŦ한 ëŗ€í™”ëŠ” 똤링 ėģ¨í…Œė´ë„ˆė—ė„œë§Œ ėĄ´ėžŦ하며, ꡸ ę¸°ë°˜ė´ 되는 ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ė—ëŠ” ė§€ė†ë˜ė§€ ė•ŠėŠĩ니다 (ėω ë””ėŠ¤íŦė—ëŠ” ė €ėžĨë˜ė§€ ė•ŠėŠĩ니다). + +ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëŠ” **프로그램** 파ėŧęŗŧ ėģ¨í…ė¸ , ėω `python`ęŗŧ ė–´ë–¤ 파ėŧ `main.py`뗐 비ęĩí•  눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  (**ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**뙀 ëŒ€ëš„í•´ė„œ) **ėģ¨í…Œė´ë„ˆ**는 ė´ë¯¸ė§€ė˜ ė‹¤ė œ ė‹¤í–‰ ė¸ėŠ¤í„´ėŠ¤ëĄœ **í”„ëĄœė„¸ėŠ¤**뗐 비ęĩí•  눘 ėžˆėŠĩ니다. ė‚Ŧ다, ėģ¨í…Œė´ë„ˆëŠ” **í”„ëĄœė„¸ėŠ¤ ëŸŦ닝**ė´ ėžˆė„ 때만 ė‹¤í–‰ëŠë‹ˆë‹¤ (꡸ëĻŦęŗ  ëŗ´í†ĩ í•˜ë‚˜ė˜ í”„ëĄœė„¸ėŠ¤ ėž…ë‹ˆë‹¤). ėģ¨í…Œė´ë„ˆëŠ” 내ëļ€ė—ė„œ ė‹¤í–‰ë˜ëŠ” í”„ëĄœė„¸ėŠ¤ę°€ ė—†ėœŧ늴 ėĸ…ëŖŒëŠë‹ˆë‹¤. + +## ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ + +도ėģ¤ëŠ” **ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**뙀 **ėģ¨í…Œė´ë„ˆ**ëĨŧ ėƒė„ąí•˜ęŗ  관ëĻŦ하는데 ėŖŧėš” 도ęĩŦ 뤑 하나가 ë˜ė–´ė™”ėŠĩ니다. + +꡸ëĻŦęŗ  도ėģ¤ í—ˆë¸Œė— ë‹¤ė–‘í•œ 도ęĩŦ, 환ę˛Ŋ, ë°ė´í„°ë˛ ė´ėŠ¤, ꡸ëĻŦęŗ  ė–´í”ŒëĻŦėŧ€ė´ė…˜ė— 대해 미ëĻŦ ë§Œë“¤ė–´ė§„ **ęŗĩė‹ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**가 ęŗĩę°œë˜ė–´ ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´, ęŗĩė‹ íŒŒė´ėŦ ė´ë¯¸ė§€ę°€ ėžˆėŠĩ니다. + +또한 다ëĨ¸ ëŒ€ėƒ, 똈ëĨŧ 들면 ë°ė´í„°ë˛ ė´ėŠ¤ëĨŧ ėœ„í•œ ė´ë¯¸ė§€ë“¤ë„ ėžˆėŠĩ니다: + +* PostgreSQL +* MySQL +* MongoDB +* Redis 등 + +미ëĻŦ ë§Œë“¤ė–´ė§„ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ ė‚ŦėšŠí•˜ëŠ´ ė„œëĄœ 다ëĨ¸ 도ęĩŦë“¤ė„ **결합**하기 ė‰ŊėŠĩ니다. 대ëļ€ëļ„ė˜ ę˛Ŋėš°ė—, **ęŗĩė‹ ė´ë¯¸ė§€ë“¤**ė„ ė‚ŦėšŠí•˜ęŗ  환ę˛Ŋ ëŗ€ėˆ˜ëĨŧ í†ĩ해 ė„¤ė •í•  눘 ėžˆėŠĩ니다. + +ė´ëŸ° 방법ėœŧ로 대ëļ€ëļ„ė˜ ę˛Ŋėš°ė— ėģ¨í…Œė´ë„ˆė™€ 도ėģ¤ė— 대해 ë°°ėš¸ 눘 ėžˆėœŧ늰 ë‹¤ė–‘í•œ 도ęĩŦ뙀 ėš”ė†Œë“¤ė— 대한 ė§€ė‹ė„ ėžŦė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +따ëŧė„œ, ė„œëĄœ 다ëĨ¸ **ë‹¤ė¤‘ ėģ¨í…Œė´ë„ˆ**ëĨŧ ėƒė„ąí•œ ë‹¤ėŒ ė´ë“¤ė„ ė—°ę˛°í•  눘 ėžˆėŠĩ니다. 똈ëĨŧ ë“¤ė–´ ë°ė´í„°ë˛ ė´ėŠ¤, íŒŒė´ėŦ ė–´í”ŒëĻŦėŧ€ė´ė…˜, ëĻŦė•ĄíŠ¸ í”„ëĄ íŠ¸ė—”ë“œ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė„ ė‚ŦėšŠí•˜ëŠ” ė›š ė„œë˛„ė— 대한 ėģ¨í…Œė´ë„ˆëĨŧ ë§Œë“¤ė–´ ė´ë“¤ė˜ 내ëļ€ ë„¤íŠ¸ė›ŒíŦ로 각 ėģ¨í…Œė´ë„ˆëĨŧ ė—°ę˛°í•  눘 ėžˆėŠĩ니다. + +ëĒ¨ë“  ėģ¨í…Œė´ë„ˆ 관ëĻŦ ė‹œėŠ¤í…œ(도ėģ¤ë‚˜ ėŋ ë˛„ë„¤í‹°ėŠ¤)ė€ ė´ëŸŦ한 ë„¤íŠ¸ė›Œí‚š íŠšė„ąė„ íŦí•¨í•˜ęŗ  ėžˆėŠĩ니다. + +## ėģ¨í…Œė´ë„ˆė™€ í”„ëĄœė„¸ėŠ¤ + +**ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**는 ëŗ´í†ĩ **ėģ¨í…Œė´ë„ˆ**ëĨŧ ė‹œėž‘í•˜ę¸° ėœ„í•´ í•„ėš”í•œ ëŠ”íƒ€ë°ė´í„°ė™€ 디폴트 ėģ¤ë§¨ë“œ/프로그램ęŗŧ ꡸ í”„ëĄœęˇ¸ëž¨ė— ė „ë‹Ŧ하기 ėœ„í•œ 파ëŧë¯¸í„°ë“¤ė„ íŦ함합니다. ė´ëŠ” ėģ¤ë§¨ë“œ ëŧė¸ė—ė„œ í”„ëĄœęˇ¸ëž¨ė„ ė‹¤í–‰í•  때 í•„ėš”í•œ 값들ęŗŧ 뜠ė‚Ŧ합니다. + +**ėģ¨í…Œė´ë„ˆ**가 ė‹œėž‘ë˜ëŠ´, 해당 ėģ¤ë§¨ë“œ/í”„ëĄœęˇ¸ëž¨ė´ ė‹¤í–‰ëŠë‹ˆë‹¤ (꡸ëŸŦ나 다ëĨ¸ ėģ¤ë§¨ë“œ/í”„ëĄœęˇ¸ëž¨ė„ ė‹¤í–‰í•˜ë„ëĄ ė˜¤ë˛„ëŧė´ë“œ 할 눘 ėžˆėŠĩ니다). + +ėģ¨í…Œė´ë„ˆëŠ” **ëŠ”ė¸ í”„ëĄœė„¸ėŠ¤**(ėģ¤ë§¨ë“œ 또는 프로그램)ė´ ė‹¤í–‰ë˜ëŠ” ë™ė•ˆ ė‹¤í–‰ëŠë‹ˆë‹¤. + +ėģ¨í…Œė´ë„ˆëŠ” ėŧë°˜ė ėœŧ로 **단ėŧ í”„ëĄœė„¸ėŠ¤**ëĨŧ 氀맀溠 ėžˆė§€ë§Œ, ëŠ”ė¸ í”„ëĄœė„¸ėŠ¤ė˜ ė„œë¸Œ í”„ëĄœė„¸ėŠ¤ëĨŧ ė‹œėž‘í•˜ëŠ” 것도 가ëŠĨ하며, ė´ 방법ėœŧ로 í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆė— **ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤**ëĨŧ ę°€ė§ˆ 눘 ėžˆėŠĩ니다. + +꡸ëŸŦ나 **ėĩœė†Œí•œ í•˜ë‚˜ė˜ ė‹¤í–‰ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤**ëĨŧ 氀맀맀 ė•Šęŗ ė„œëŠ” ė‹¤í–‰ė¤‘ė¸ ėģ¨í…Œė´ë„ˆëĨŧ ę°€ė§ˆ 눘 ė—†ėŠĩ니다. 만ė•Ŋ ëŠ”ė¸ í”„ëĄœė„¸ėŠ¤ę°€ ė¤‘ë‹¨ë˜ëŠ´, ėģ¨í…Œė´ë„ˆë„ ė¤‘ë‹¨ëŠë‹ˆë‹¤. + +## FastAPIëĨŧ ėœ„í•œ 도ėģ¤ ė´ë¯¸ė§€ 빌드하기 + +ė´ė œ ëŦ´ė–¸ę°€ëĨŧ ë§Œë“¤ė–´ ë´…ė‹œë‹¤! 🚀 + +**ęŗĩė‹ íŒŒė´ėŦ** ė´ë¯¸ė§€ė— 기반하ė—Ŧ, FastAPIëĨŧ ėœ„í•œ **도ėģ¤ ė´ë¯¸ė§€**ëĨŧ **맨 ė˛˜ėŒëļ€í„°** ėƒė„ąí•˜ëŠ” ë°Šë˛•ė„ ëŗ´ė´ę˛ ėŠĩ니다. + +**대ëļ€ëļ„ė˜ ę˛Ŋ뚰**뗐 ë‹¤ėŒęŗŧ ę°™ė€ ę˛ƒë“¤ė„ 하게 됩니다. 똈ëĨŧ 들면: + +* **ėŋ ë˛„ë„¤í‹°ėŠ¤** 또는 뜠ė‚Ŧ한 도ęĩŦ ė‚ŦėšŠí•˜ę¸° +* **ëŧėĻˆë˛ ëĻŦ íŒŒė´**로 ė‹¤í–‰í•˜ę¸° +* ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ ė‹¤í–‰í•  클ëŧėš°ë“œ ė„œëš„ėŠ¤ ė‚ŦėšŠí•˜ę¸° 등 + +### ėš”ęĩŦ íŒ¨í‚¤ė§€ + +ėŧë°˜ė ėœŧ로는 ė–´í”ŒëĻŦėŧ€ė´ė…˜ė˜ íŠšė • 파ėŧė„ ėœ„í•œ **íŒ¨í‚¤ė§€ ėš”ęĩŦ ėĄ°ęą´**ė´ ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤. + +꡸ ėš”ęĩŦ ėĄ°ęą´ė„ **ė„¤ėš˜**하는 ë°Šë˛•ė€ ė—ŦëŸŦëļ„ė´ ė‚ŦėšŠí•˜ëŠ” 도ęĩŦ뗐 따ëŧ 다ëĨŧ ę˛ƒėž…ë‹ˆë‹¤. + +가ėžĨ ėŧë°˜ė ė¸ ë°Šë˛•ė€ íŒ¨í‚¤ė§€ ė´ëĻ„ęŗŧ ë˛„ė „ė´ 뤄 ëŗ„ëĄœ 기록된 `requirements.txt` 파ėŧė„ 만드는 ę˛ƒėž…ë‹ˆë‹¤. + +ë˛„ė „ė˜ ë˛”ėœ„ëĨŧ ė„¤ė •í•˜ę¸° ėœ„í•´ė„œëŠ” [FastAPI ë˛„ė „ë“¤ė— 대하ė—Ŧ](./versions.md){.internal-link target=_blank}뗐 ė“°ė—Ŧė§„ 것ęŗŧ ę°™ė€ ė•„ė´ë””ė–´ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤. + +똈ëĨŧ ë“¤ė–´, `requirements.txt` 파ėŧė€ ë‹¤ėŒęŗŧ ę°™ė„ 눘 ėžˆėŠĩ니다: + +``` +fastapi>=0.68.0,<0.69.0 +pydantic>=1.8.0,<2.0.0 +uvicorn>=0.15.0,<0.16.0 +``` + +꡸ëĻŦęŗ  ėŧë°˜ė ėœŧ로 íŒ¨í‚¤ė§€ ėĸ…ė†ė„ąė€ `pip`로 ė„¤ėš˜í•Šë‹ˆë‹¤. 똈ëĨŧ ë“¤ė–´: + +
+ +```console +$ pip install -r requirements.txt +---> 100% +Successfully installed fastapi pydantic uvicorn +``` + +
+ +!!! ė •ëŗ´ + íŒ¨í‚¤ė§€ ėĸ…ė†ė„ąė„ ė •ė˜í•˜ęŗ  ė„¤ėš˜í•˜ę¸° ėœ„í•œ 방법ęŗŧ 도ęĩŦ는 ë‹¤ė–‘í•Šë‹ˆë‹¤. + + ë‚˜ė¤‘ė— ė•„ëž˜ ė„¸ė…˜ė—ė„œ PoetryëĨŧ ė‚ŦėšŠí•œ ė˜ˆė‹œëĨŧ ëŗ´ė´ę˛ ėŠĩ니다. 👇 + +### **FastAPI** ėŊ”드 ėƒė„ąí•˜ę¸° + +* `app` 디렉터ëĻŦëĨŧ ėƒė„ąí•˜ęŗ  ė´ë™í•Šë‹ˆë‹¤. +* 뚈 파ėŧ `__init__.py`ė„ ėƒė„ąí•Šë‹ˆë‹¤. +* ë‹¤ėŒęŗŧ ę°™ė€ `main.py`ė„ ėƒė„ąí•Šë‹ˆë‹¤: + +```Python +from typing import Union + +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: Union[str, None] = None): + return {"item_id": item_id, "q": q} +``` + +### 도ėģ¤íŒŒėŧ + +ė´ė œ ę°™ė€ í”„ëĄœė íŠ¸ 디렉터ëĻŦ뗐 ë‹¤ėŒęŗŧ ę°™ė€ 파ėŧ `Dockerfile`ė„ ėƒė„ąí•Šë‹ˆë‹¤: + +```{ .dockerfile .annotate } +# (1) +FROM python:3.9 + +# (2) +WORKDIR /code + +# (3) +COPY ./requirements.txt /code/requirements.txt + +# (4) +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (5) +COPY ./app /code/app + +# (6) +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. ęŗĩė‹ íŒŒė´ėŦ ë˛ ė´ėŠ¤ ė´ë¯¸ė§€ė—ė„œ ė‹œėž‘í•Šë‹ˆë‹¤. + +2. 현ėžŦ ė›Œí‚š 디렉터ëĻŦëĨŧ `/code`로 ė„¤ė •í•Šë‹ˆë‹¤. + + ė—Ŧ揰뗐 `requirements.txt` 파ėŧęŗŧ `app` 디렉터ëĻŦëĨŧ ėœ„ėš˜ė‹œí‚Ŧ ę˛ƒėž…ë‹ˆë‹¤. + +3. ėš”ęĩŦ ėĄ°ęą´ęŗŧ 파ėŧė„ `/code` 디렉터ëĻŦ로 ëŗĩė‚Ŧ합니다. + + ė˛˜ėŒė—ëŠ” **똤링** ėš”ęĩŦ ėĄ°ęą´ė´ í•„ėš”í•œ 파ėŧ만 ëŗĩė‚Ŧí•˜ęŗ , ė´ė™¸ė˜ ėŊ”드는 그대로 둡니다. + + ė´ 파ėŧė´ **ėžėŖŧ ë°”ë€Œė§€ ė•Šę¸° 때ëŦ¸ė—**, 도ėģ¤ëŠ” 파ėŧė„ íƒė§€í•˜ė—Ŧ ė´ ë‹¨ęŗ„ė˜ **ėēė‹œ**ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ ë‹¤ėŒ ë‹¨ęŗ„ė—ė„œë„ ėēė‹œëĨŧ ė‚ŦėšŠí•  눘 ėžˆë„ëĄ 합니다. + +4. ėš”ęĩŦ ėĄ°ęą´ 파ėŧ뗐 ėžˆëŠ” íŒ¨í‚¤ė§€ ėĸ…ė†ė„ąė„ ė„¤ėš˜í•Šë‹ˆë‹¤. + + `--no-cache-dir` ė˜ĩė…˜ė€ `pip`ė—ę˛Œ ë‹¤ėš´ëĄœë“œí•œ íŒ¨í‚¤ė§€ë“¤ė„ 로ėģŦ 환ę˛Ŋ뗐 ė €ėžĨí•˜ė§€ ė•Šë„ëĄ ė „ë‹Ŧ합니다. ė´ëŠ” ë§ˆėš˜ ę°™ė€ íŒ¨í‚¤ė§€ëĨŧ ė„¤ėš˜í•˜ę¸° ėœ„í•´ 똤링 `pip`만 ë‹¤ė‹œ ė‹¤í–‰í•˜ëŠ´ 될 것 ę°™ė§€ë§Œ, ėģ¨í…Œė´ë„ˆëĄœ ėž‘ė—…í•˜ëŠ” ę˛Ŋ뚰 ęˇ¸ë ‡ė§€ëŠ” ė•ŠėŠĩ니다. + + !!! 노트 + `--no-cache-dir` 는 똤링 `pip`뙀 ę´€ë ¨ë˜ė–´ ėžˆėœŧ늰, 도ėģ¤ë‚˜ ėģ¨í…Œė´ë„ˆė™€ëŠ” ëŦ´ę´€í•Šë‹ˆë‹¤. + + `--upgrade` ė˜ĩė…˜ė€ `pip`ė—ę˛Œ ė„¤ėš˜ëœ íŒ¨í‚¤ė§€ë“¤ė„ ė—…ë°ė´íŠ¸í•˜ë„ëĄ 합니다. + + ė´ė „ ë‹¨ęŗ„ė—ė„œ 파ėŧė„ ëŗĩė‚Ŧ한 ę˛ƒė´ **도ėģ¤ ėēė‹œ**뗐 ė˜í•´ íƒė§€ë˜ę¸° 때ëŦ¸ė—, ė´ ë‹¨ęŗ„ė—ė„œë„ 가ëŠĨ한 한 **도ėģ¤ ėēė‹œ**ëĨŧ ė‚ŦėšŠí•˜ę˛Œ 됩니다. + + ė´ ë‹¨ęŗ„ė—ė„œ ėēė‹œëĨŧ ė‚ŦėšŠí•˜ëŠ´ **매번** ëĒ¨ë“  ėĸ…ė†ė„ąė„ ë‹¤ėš´ëĄœë“œ ë°›ęŗ  ė„¤ėš˜í•  í•„ėš”ę°€ 뗆떴, 개발 ęŗŧė •ė—ė„œ ė´ë¯¸ė§€ëĨŧ ė§€ė†ė ėœŧ로 ėƒė„ąí•˜ëŠ” ë°ė— 드는 **ė‹œę°„**ė„ ë§Žė´ **레ė•Ŋ**할 눘 ėžˆėŠĩ니다. + +5. `/code` 디렉터ëĻŦ뗐 `./app` 디렉터ëĻŦëĨŧ ëŗĩė‚Ŧ합니다. + + **ėžėŖŧ ëŗ€ę˛Ŋ되는** ëĒ¨ë“  ėŊ”드ëĨŧ íŦí•¨í•˜ęŗ  ėžˆę¸° 때ëŦ¸ė—, 도ėģ¤ **ėēė‹œ**는 ė´ ë‹¨ęŗ„ë‚˜ **ė´í›„ė˜ ë‹¨ęŗ„ė—ė„œ** ėž˜ ė‚ŦėšŠë˜ė§€ ė•ŠėŠĩ니다. + + ꡸ëŸŦë¯€ëĄœ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ 빌드 ė‹œę°„ė„ ėĩœė í™”í•˜ę¸° ėœ„í•´ `Dockerfile`ė˜ **ęą°ė˜ 끝 ëļ€ëļ„**뗐 ėž…ë Ĩ하는 ę˛ƒė´ ė¤‘ėš”í•Šë‹ˆë‹¤. + +6. `uvicorn` ė„œë˛„ëĨŧ ė‹¤í–‰í•˜ę¸° ėœ„í•´ **ėģ¤ë§¨ë“œ**ëĨŧ ė„¤ė •í•Šë‹ˆë‹¤. + + `CMD`는 ëŦ¸ėžė—´ ëĻŦėŠ¤íŠ¸ëĨŧ ėž…ë Ĩë°›ęŗ , 각 ëŦ¸ėžė—´ė€ ėģ¤ë§¨ë“œ ëŧė¸ė˜ 각 뤄뗐 ėž…ë Ĩ할 ëŦ¸ėžė—´ėž…니다. + + ė´ ėģ¤ë§¨ë“œëŠ” **현ėžŦ ė›Œí‚š 디렉터ëĻŦ**ė—ė„œ ė‹¤í–‰ë˜ëŠ°, ė´ëŠ” ėœ„ė—ė„œ `WORKDIR /code`로 ė„¤ė •í•œ `/code` 디렉터ëĻŦ뙀 같ėŠĩ니다. + + í”„ëĄœęˇ¸ëž¨ė´ `/code`ė—ė„œ ė‹œėž‘í•˜ęŗ  ꡸ ė†ė— `./app` 디렉터ëĻŦ가 ė—ŦëŸŦëļ„ė˜ ėŊ”ë“œė™€ 함ęģ˜ ë“¤ė–´ėžˆę¸° 때ëŦ¸ė—, **Uvicorn**ė€ ė´ëĨŧ ëŗ´ęŗ  `app`ė„ `app.main`ėœŧ로ëļ€í„° **ëļˆëŸŦ ė˜Ŧ** ę˛ƒėž…ë‹ˆë‹¤. + +!!! 팁 + 각 ėŊ”드 ëŧė¸ė„ ėŊ”ë“œė˜ ėˆĢėž ë˛„ë¸”ė„ 클ëĻ­í•˜ė—Ŧ ëĻŦ뷰할 눘 ėžˆėŠĩ니다. 👆 + +ė´ė œ ė—ŦëŸŦëļ„ė€ ë‹¤ėŒęŗŧ ę°™ė€ 디렉터ëĻŦ ęĩŦėĄ°ëĨŧ 氀맀溠 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤: + +``` +. +├── app +│   ├── __init__.py +│ └── main.py +├── Dockerfile +└── requirements.txt +``` + +#### TLS ėĸ…ëŖŒ í”„ëĄė‹œė˜ 배후 + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ ėģ¨í…Œė´ë„ˆëĨŧ Nginx 또는 Traefikęŗŧ ę°™ė€ TLS ėĸ…ëŖŒ í”„ëĄė‹œ (로드 ë°¸ëŸ°ė„œ) ë’¤ė—ė„œ ė‹¤í–‰í•˜ęŗ  ėžˆë‹¤ëŠ´, `--proxy-headers` ė˜ĩė…˜ė„ 더하는 ę˛ƒė´ ėĸ‹ėŠĩ니다. ė´ ė˜ĩė…˜ė€ Uvicornė—ę˛Œ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ HTTPS ë“ąė˜ ë’¤ė—ė„œ ė‹¤í–‰ë˜ęŗ  ėžˆėœŧë¯€ëĄœ í”„ëĄė‹œė—ė„œ ė „ė†Ąëœ 헤더ëĨŧ ė‹ ëĸ°í•  눘 ėžˆë‹¤ęŗ  ė•ŒëĻŊ니다. + +```Dockerfile +CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] +``` + +#### 도ėģ¤ ėēė‹œ + +ė´ `Dockerfile`ė—ëŠ” ė¤‘ėš”í•œ 트ëĻ­ė´ ėžˆëŠ”ë°, ė˛˜ėŒė—ëŠ” **ė˜ėĄ´ė„ąė´ ėžˆëŠ” 파ėŧ만** ëŗĩė‚Ŧí•˜ęŗ , ë‚˜ë¨¸ė§€ ėŊ”드는 그대로 둡니다. ė™œ ė´ëŸ° ë°Šë˛•ė„ ė¨ė•ŧí•˜ëŠ”ė§€ 네ëĒ…í•˜ę˛ ėŠĩ니다. + +```Dockerfile +COPY ./requirements.txt /code/requirements.txt +``` + +도ėģ¤ė™€ 다ëĨ¸ 도ęĩŦë“¤ė€ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ **ėĻę°€í•˜ëŠ” ë°Šė‹ėœŧ로 빌드**합니다. `Dockerfile`ė˜ 맨 ėœ— ëļ€ëļ„ëļ€í„° ė‹œėž‘í•´, ë ˆė´ė–´ ėœ„ė— ėƒˆëĄœėš´ ë ˆė´ė–´ëĨŧ 더하는 ë°Šė‹ėœŧ로, `Dockerfile`ė˜ 각 ė§€ė‹œ ė‚Ŧ항ėœŧ로 ëļ€í„° ėƒė„ąëœ ė–´ë–¤ 파ėŧė´ë“  더해갑니다. + +도ėģ¤ ęˇ¸ëĻŦęŗ  ė´ė™€ 뜠ė‚Ŧ한 도ęĩŦë“¤ė€ ė´ë¯¸ė§€ ėƒė„ą ė‹œė— **내ëļ€ ėēė‹œ**ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤. 만ė•Ŋ ė–´ë–¤ 파ėŧė´ ë§ˆė§€ë§‰ėœŧ로 ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ 빌드한 때로ëļ€í„° ë°”ë€Œė§€ ė•Šė•˜ë‹¤ëŠ´, 파ėŧė„ ë‹¤ė‹œ ëŗĩė‚Ŧ하ė—Ŧ ėƒˆëĄœėš´ ë ˆė´ė–´ëĨŧ ė˛˜ėŒëļ€í„° ėƒė„ąí•˜ëŠ” ę˛ƒė´ ė•„ë‹ˆëŧ, ë§ˆė§€ë§‰ė— ėƒė„ąí–ˆë˜ **ę°™ė€ ë ˆė´ė–´ëĨŧ ėžŦė‚ŦėšŠ**합니다. + +ë‹¨ė§€ 파ėŧ ëŗĩė‚ŦëĨŧ ė§€ė–‘í•˜ëŠ” 것ėœŧ로 íš¨ėœ¨ė´ ë§Žė´ í–Ĩėƒë˜ëŠ” ę˛ƒė€ ė•„ë‹ˆė§€ë§Œ, ꡸ ë‹¨ęŗ„ė—ė„œ ėēė‹œëĨŧ ė‚ŦėšŠí–ˆę¸° 때ëŦ¸ė—, **ë‹¤ėŒ ë‹¨ęŗ„ė—ė„œë„ 마ė°Ŧę°€ė§€ëĄœ ėēė‹œëĨŧ ė‚ŦėšŠ**할 눘 ėžˆėŠĩ니다. 똈ëĨŧ ë“¤ė–´, ë‹¤ėŒęŗŧ ę°™ė€ ė˜ėĄ´ė„ąė„ ė„¤ėš˜í•˜ëŠ” ė§€ė‹œ ė‚Ŧí•­ė„ ėœ„í•œ ėēė‹œëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +```Dockerfile +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt +``` + +íŒ¨í‚¤ė§€ëĨŧ íŦ함하는 파ėŧė€ **ėžėŖŧ ëŗ€ę˛Ŋë˜ė§€ ė•ŠėŠĩ니다**. 따ëŧė„œ 해당 파ėŧ만 ëŗĩė‚Ŧí•˜ë¯€ëĄœė„œ, 도ėģ¤ëŠ” ꡸ ë‹¨ęŗ„ė˜ **ėēė‹œëĨŧ ė‚ŦėšŠ**할 눘 ėžˆėŠĩ니다. + +꡸ ë‹¤ėŒėœŧ로, 도ėģ¤ëŠ” **ë‹¤ėŒ ë‹¨ęŗ„ė—ė„œ** ė˜ėĄ´ė„ąė„ ë‹¤ėš´ëĄœë“œí•˜ęŗ  ė„¤ėš˜í•˜ëŠ” **ėēė‹œëĨŧ ė‚ŦėšŠ**할 눘 ėžˆę˛Œ 됩니다. 바로 ė´ ęŗŧė •ė—ė„œ 뚰ëĻŦ는 **ë§Žė€ ė‹œę°„ė„ 레ė•Ŋ**하게 됩니다. ✨ ...꡸ëĻŦęŗ  기다ëĻŦ는 ė§€ëŖ¨í•¨ë„ í”ŧ할 눘 ėžˆėŠĩ니다. đŸ˜Ē😆 + +íŒ¨í‚¤ė§€ ė˜ėĄ´ė„ąė„ ë‹¤ėš´ëĄœë“œ ë°›ęŗ  ė„¤ėš˜í•˜ëŠ” ë°ė´ëŠ” **눘 ëļ„ė´ 깸ëĻ´ 눘 ėžˆė§€ë§Œ**, **ėēė‹œ**ëĨŧ ė‚ŦėšŠí•˜ëŠ´ ėĩœëŒ€ **눘 ė´ˆë§Œė—** 끝ë‚ŧ 눘 ėžˆėŠĩ니다. + +또한 ė—ŦëŸŦëļ„ė´ 개발 ęŗŧė •ė—ė„œ ėŊ”ë“œė˜ ëŗ€ę˛Ŋ ė‚Ŧí•­ė´ ë°˜ė˜ë˜ė—ˆëŠ”ė§€ í™•ė¸í•˜ę¸° ėœ„í•´ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ ęŗ„ė†í•´ė„œ 빌드하면, 레ė•Ŋ된 ė‹œę°„ė€ ėļ•ė ë˜ė–´ ë”ėšą ėģ¤ė§ˆ ę˛ƒėž…ë‹ˆë‹¤. + +꡸ëĻŦęŗ  ë‚˜ė„œ `Dockerfile`ė˜ ęą°ė˜ 끝 ëļ€ëļ„ė—ė„œ, ëĒ¨ë“  ėŊ”드ëĨŧ ëŗĩė‚Ŧ합니다. ė´ę˛ƒė´ **가ėžĨ 빈번하게 ëŗ€ę˛Ŋ**되는 ëļ€ëļ„ė´ëа, 대ëļ€ëļ„ė˜ ę˛Ŋėš°ė— ė´ ë‹¤ėŒ ë‹¨ęŗ„ė—ė„œëŠ” ėēė‹œëĨŧ ė‚ŦėšŠí•  눘 뗆揰 때ëŦ¸ė— 가ėžĨ ë§ˆė§€ë§‰ė— 둡니다. + +```Dockerfile +COPY ./app /code/app +``` + +### 도ėģ¤ ė´ë¯¸ė§€ ėƒė„ąí•˜ę¸° + +ė´ė œ ëĒ¨ë“  파ėŧė´ ė œėžëĻŦ뗐 ėžˆėœŧ니, ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ 빌드합니다. + +* (ė—ŦëŸŦëļ„ė˜ `Dockerfile`ęŗŧ `app` 디렉터ëĻŦ가 ėœ„ėš˜í•œ) í”„ëĄœė íŠ¸ 디렉터ëĻŦ로 ė´ë™í•Šë‹ˆë‹¤. +* FastAPI ė´ë¯¸ė§€ëĨŧ 빌드합니다: + +
+ +```console +$ docker build -t myimage . + +---> 100% +``` + +
+ +!!! 팁 + 맨 ëė— ėžˆëŠ” `.` 뗐 ėŖŧëĒŠí•Šė‹œë‹¤. ė´ëŠ” `./`뙀 동등하며, 도ėģ¤ė—ę˛Œ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ 빌드하기 ėœ„í•œ 디렉터ëĻŦëĨŧ ė•Œë ¤ė¤ë‹ˆë‹¤. + + ė´ ę˛Ŋėš°ė—ëŠ” 현ėžŦ 디렉터ëĻŦ(`.`)뙀 같ėŠĩ니다. + +### 도ėģ¤ ėģ¨í…Œė´ë„ˆ ė‹œėž‘í•˜ę¸° + +* ė—ŦëŸŦëļ„ė˜ ė´ë¯¸ė§€ė— 기반하ė—Ŧ ėģ¨í…Œė´ë„ˆëĨŧ ė‹¤í–‰í•Šë‹ˆë‹¤: + +
+ +```console +$ docker run -d --name mycontainer -p 80:80 myimage +``` + +
+ +## 랴íŦ하기 + +ė—ŦëŸŦëļ„ė˜ 도ėģ¤ ėģ¨í…Œė´ë„ˆ URLė—ė„œ ė‹¤í–‰ ė‚Ŧí•­ė„ 랴íŦ할 눘 ėžˆėŠĩ니다. 똈ëĨŧ ë“¤ė–´: http://192.168.99.100/items/5?q=somequery 또는 http://127.0.0.1/items/5?q=somequery (또는 동ėŧ하게, ė—ŦëŸŦëļ„ė˜ 도ėģ¤ í˜¸ėŠ¤íŠ¸ëĨŧ ė´ėšŠí•´ė„œ 랴íŦ할 ėˆ˜ë„ ėžˆėŠĩ니다). + +ė•„ëž˜ė™€ ëš„ėŠˇí•œ ę˛ƒė„ ëŗ´ę˛Œ 될 ę˛ƒėž…ë‹ˆë‹¤: + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +## ė¸í„°ëž™í‹°ë¸Œ API ëŦ¸ė„œ + +ė´ė œ ė—ŦëŸŦëļ„ė€ http://192.168.99.100/docs 또는 http://127.0.0.1/docs로 ė´ë™í•  눘 ėžˆėŠĩ니다(또는, ė—ŦëŸŦëļ„ė˜ 도ėģ¤ í˜¸ėŠ¤íŠ¸ëĨŧ ė´ėšŠí•  눘 ėžˆėŠĩ니다). + +ė—ŦëŸŦëļ„ė€ ėžë™ėœŧ로 ėƒė„ąëœ ė¸í„°ëž™í‹°ë¸Œ API(Swagger UIė—ė„œ 렜ęŗĩ된)ëĨŧ ëŗŧ 눘 ėžˆėŠĩ니다: + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +## ëŒ€ė•ˆ API ëŦ¸ė„œ + +또한 ė—ŦëŸŦëļ„ė€ http://192.168.99.100/redoc 또는 http://127.0.0.1/redocėœŧ로 ė´ë™í•  눘 ėžˆėŠĩ니다(또는, ė—ŦëŸŦëļ„ė˜ 도ėģ¤ í˜¸ėŠ¤íŠ¸ëĨŧ ė´ėšŠí•  눘 ėžˆėŠĩ니다). + +ė—ŦëŸŦëļ„ė€ ėžë™ėœŧ로 ėƒė„ąëœ ëŒ€ė•ˆ ëŦ¸ė„œ(ReDocė—ė„œ 렜ęŗĩ된)ëĨŧ ëŗŧ 눘 ėžˆėŠĩ니다: + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## 단ėŧ 파ėŧ FastAPI로 도ėģ¤ ė´ë¯¸ė§€ ėƒė„ąí•˜ę¸° + +만ė•Ŋ ė—ŦëŸŦëļ„ė˜ FastAPI가 í•˜ë‚˜ė˜ 파ėŧė´ëŧ늴, 똈ëĨŧ ë“¤ė–´ `./app` 디렉터ëĻŦ ė—†ė´ `main.py` 파ėŧ만ėœŧ로 ė´ëŖ¨ė–´ė ¸ ėžˆë‹¤ëŠ´, 파ėŧ ęĩŦėĄ°ëŠ” ë‹¤ėŒęŗŧ 뜠ė‚Ŧ할 ę˛ƒėž…ë‹ˆë‹¤: + +``` +. +├── Dockerfile +├── main.py +└── requirements.txt +``` + +꡸ëŸŦ늴 ė—ŦëŸŦëļ„ë“¤ė€ `Dockerfile` ë‚´ė— ėžˆëŠ” 파ėŧė„ ëŗĩė‚Ŧ하기 ėœ„í•´ 掏렀 ėƒė‘í•˜ëŠ” ę˛Ŋ로ëĨŧ 바꾸기만 하면 됩니다: + +```{ .dockerfile .annotate hl_lines="10 13" } +FROM python:3.9 + +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (1) +COPY ./main.py /code/ + +# (2) +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. `main.py` 파ėŧė„ `/code` 디렉터ëĻŦ로 ęŗ§ë°”ëĄœ ëŗĩė‚Ŧ합니다(`./app` 디렉터ëĻŦ는 ęŗ ë ¤í•˜ė§€ ė•ŠėŠĩ니다). + +2. Uvicornė„ ė‹¤í–‰í•´ `app` ę°ė˛´ëĨŧ (`app.main` ëŒ€ė‹ ) `main`ėœŧ로 ëļ€í„° ëļˆëŸŦė˜¤ë„ëĄ 합니다. + +꡸ ë‹¤ėŒ Uvicorn ėģ¤ë§¨ë“œëĨŧ ėĄ°ė •í•´ė„œ FastAPI ę°ė˛´ëĨŧ ëļˆëŸŦė˜¤ëŠ”ë° `app.main` ëŒ€ė‹ ė— ėƒˆëĄœėš´ ëĒ¨ë“ˆ `main`ė„ ė‚ŦėšŠí•˜ë„ëĄ 합니다. + +## ë°°íŦ 개념 + +ė´ė œ ėģ¨í…Œė´ë„ˆė˜ ė¸ĄëŠ´ė—ė„œ [ë°°íŦ 개념](./concepts.md){.internal-link target=_blank}ė—ė„œ ë‹¤ëŖ¨ė—ˆë˜ 것ęŗŧ ę°™ė€ ë°°íŦ ę°œë…ė— 대해 ė´ė•ŧ기해 ëŗ´ę˛ ėŠĩ니다. + +ėģ¨í…Œė´ë„ˆëŠ” ėŖŧ로 ė–´í”ŒëĻŦėŧ€ė´ė…˜ė„ ëšŒë“œí•˜ęŗ  ë°°íŦ하기 ėœ„í•œ ęŗŧė •ė„ ë‹¨ėˆœí™”í•˜ëŠ” 도ęĩŦė´ė§€ë§Œ, **ë°°íŦ 개념**뗐 대한 íŠšė •í•œ ė ‘ęˇŧë˛•ė„ ę°•ėš”í•˜ė§€ ė•Šę¸° 때ëŦ¸ė— 가ëŠĨ한 ë°°íŦ ė „ëžĩė—ëŠ” ė—ŦëŸŦ氀맀氀 ėžˆėŠĩ니다. + +**ėĸ‹ė€ ė†Œė‹**ė€ ė„œëĄœ 다ëĨ¸ ė „ëžĩë“¤ė„ íŦ괄하는 ë°°íŦ ę°œë…ė´ ėžˆë‹¤ëŠ” ė ėž…ë‹ˆë‹¤. 🎉 + +ėģ¨í…Œė´ë„ˆ ė¸ĄëŠ´ė—ė„œ **ë°°íŦ 개념**ė„ ëĻŦ뷰해 ëŗ´ę˛ ėŠĩ니다: + +* HTTPS +* ęĩŦ동하기 +* ėžŦė‹œėž‘ +* ëŗĩ렜 (ė‹¤í–‰ ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤ 氜눘) +* 메ëǍëĻŦ +* ė‹œėž‘í•˜ę¸° ė „ ë‹¨ęŗ„ë“¤ + +## HTTPS + +만ė•Ŋ 뚰ëĻŦ가 FastAPI ė–´í”ŒëĻŦėŧ€ė´ė…˜ė„ ėœ„í•œ **ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**ė—ë§Œ ė§‘ė¤‘í•œë‹¤ëŠ´ (꡸ëĻŦęŗ  ë‚˜ė¤‘ė— ė‹¤í–‰ë  **ėģ¨í…Œė´ë„ˆ**뗐), HTTPS는 ėŧë°˜ė ėœŧ로 다ëĨ¸ 도ęĩŦ뗐 ė˜í•´ **뙏ëļ€ė ėœŧ로** ë‹¤ëŖ¨ė–´ė§ˆ 것 ėž…ë‹ˆë‹¤. + +**HTTPS**뙀 **ė¸ėĻė„œ**ė˜ **ėžë™** ėˇ¨ë“ė„ ë‹¤ëŖ¨ëŠ” ę˛ƒė€ 다ëĨ¸ ėģ¨í…Œė´ë„ˆę°€ 될 눘 ėžˆëŠ”ë°, 똈ëĨŧ ë“¤ė–´ Traefikė„ ė‚ŦėšŠí•˜ëŠ” ę˛ƒėž…ë‹ˆë‹¤. + +!!! 팁 + Traefikė€ 도ėģ¤, ėŋ ë˛„ë„¤í‹°ėŠ¤, ꡸ëĻŦęŗ  다ëĨ¸ 도ęĩŦ뙀 í†ĩí•Šë˜ė–´ ėžˆė–´ ė—ŦëŸŦëļ„ė˜ ėģ¨í…Œė´ë„ˆëĨŧ íŦ함하는 HTTPSëĨŧ ė…‹ė—…í•˜ęŗ  ė„¤ė •í•˜ëŠ” ę˛ƒė´ ë§¤ėš° ė‰ŊėŠĩ니다. + +ëŒ€ė•ˆė ėœŧ로, HTTPS는 클ëŧėš°ë“œ 렜ęŗĩėžė— ė˜í•´ ė„œëš„ėŠ¤ė˜ ėŧ환ėœŧ로 ë‹¤ëŖ¨ė–´ė§ˆ ėˆ˜ë„ ėžˆėŠĩ니다 (ė´ë•Œë„ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė€ ė—Ŧė „ížˆ ėģ¨í…Œė´ë„ˆė—ė„œ ė‹¤í–‰ë  ę˛ƒėž…ë‹ˆë‹¤). + +## ęĩŦ동ęŗŧ ėžŦė‹œėž‘ + +ė—ŦëŸŦëļ„ė˜ ėģ¨í…Œė´ë„ˆëĨŧ **ė‹œėž‘í•˜ęŗ  ė‹¤í–‰í•˜ëŠ”** ë°ė— ėŧë°˜ė ėœŧ로 ė‚ŦėšŠë˜ëŠ” 도ęĩŦ는 따로 ėžˆėŠĩ니다. + +ė´ëŠ” **도ėģ¤** ėžė˛´ėŧ ėˆ˜ë„ ėžˆęŗ , **도ėģ¤ ėģ´íŦėψ**, **ėŋ ë˛„ë„¤í‹°ėŠ¤**, **클ëŧėš°ë“œ ė„œëš„ėŠ¤** ë“ąė´ 될 눘 ėžˆėŠĩ니다. + +대ëļ€ëļ„ (또는 렄랴) ę˛Ŋėš°ė—, ėģ¨í…Œė´ë„ˆëĨŧ ęĩŦ동하거나 ęŗ ėžĨė‹œė— ėžŦė‹œėž‘í•˜ë„ëĄ 하는 간단한 ė˜ĩė…˜ė´ ėžˆėŠĩ니다. 똈ëĨŧ ë“¤ė–´, 도ėģ¤ė—ė„œëŠ”, ėģ¤ë§¨ë“œ ëŧė¸ ė˜ĩė…˜ `--restart` ėž…ë‹ˆë‹¤. + +ėģ¨í…Œė´ë„ˆëĨŧ ė‚ŦėšŠí•˜ė§€ ė•Šęŗ ė„œëŠ”, ė–´í”ŒëĻŦėŧ€ė´ė…˜ė„ ęĩŦë™í•˜ęŗ  ėžŦė‹œėž‘í•˜ëŠ” ę˛ƒė´ ë§¤ėš° ë˛ˆęą°ëĄ­ęŗ  ė–´ë ¤ėš¸ 눘 ėžˆėŠĩ니다. í•˜ė§€ë§Œ **ėģ¨í…Œė´ë„ˆëĨŧ ė‚ŦėšŠí•œë‹¤ëŠ´** 대ëļ€ëļ„ė˜ ę˛Ŋėš°ė— ė´ëŸ° 기ëŠĨė€ ę¸°ëŗ¸ė ėœŧ로 íŦí•¨ë˜ė–´ ėžˆėŠĩ니다. ✨ + +## ëŗĩ렜 - í”„ëĄœė„¸ėŠ¤ 氜눘 + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ **ėŋ ë˛„ë„¤í‹°ėŠ¤**뙀 ë¨¸ė‹  클ëŸŦėŠ¤í„°, 도ėģ¤ ėŠ¤ė™ ëĒ¨ë“œ, 노마드, 또는 다ëĨ¸ ė—ŦëŸŦ ë¨¸ė‹  ėœ„ė— ëļ„ė‚° ėģ¨í…Œė´ë„ˆëĨŧ 관ëĻŦ하는 ëŗĩėžĄí•œ ė‹œėŠ¤í…œė„ ë‹¤ëŖ¨ęŗ  ėžˆë‹¤ëŠ´, ė—ŦëŸŦëļ„ė€ 각 ėģ¨í…Œė´ë„ˆė—ė„œ (ė›Œėģ¤ė™€ 함ęģ˜ ė‚ŦėšŠí•˜ëŠ” Gunicorn ę°™ė€) **í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €** ëŒ€ė‹  **클ëŸŦėŠ¤í„° 레벨**ė—ė„œ **ëŗĩ렜ëĨŧ ë‹¤ëŖ¨**ęŗ  ė‹ļė„ ę˛ƒėž…ë‹ˆë‹¤. + +ėŋ ë˛„ë„¤í‹°ėŠ¤ė™€ ę°™ė€ ëļ„ė‚° ėģ¨í…Œė´ë„ˆ 관ëĻŦ ė‹œėŠ¤í…œ 뤑 ėŧëļ€ëŠ” ėŧë°˜ė ėœŧ로 ë“¤ė–´ė˜¤ëŠ” ėš”ė˛­ė— 대한 **로드 ë°¸ëŸ°ė‹ą**ė„ ė§€ė›í•˜ëŠ´ė„œ **ėģ¨í…Œė´ë„ˆ ëŗĩ렜**ëĨŧ ë‹¤ëŖ¨ëŠ” í†ĩ합된 ë°Šë˛•ė„ 氀맀溠 ėžˆėŠĩ니다. ëĒ¨ë‘ **클ëŸŦėŠ¤í„° 레벨**ė—ė„œ ë§ė´ėŖ . + +ė´ëŸ° ę˛Ŋėš°ė—, ė—ŦëŸŦëļ„ė€ [ėœ„ė—ė„œ ëŦ˜ė‚Ŧ된 것](#dockerfile)래ëŸŧ **ė˛˜ėŒëļ€í„° 도ėģ¤ ė´ë¯¸ė§€ëĨŧ** ëšŒë“œí•´ė„œ, ė˜ėĄ´ė„ąė„ ė„¤ėš˜í•˜ęŗ , Uvicorn ė›Œėģ¤ëĨŧ 관ëĻŦ하는 Gunicorn ëŒ€ė‹  **단ėŧ Uvicorn í”„ëĄœė„¸ėŠ¤**ëĨŧ ė‹¤í–‰í•˜ęŗ  ė‹ļė„ ę˛ƒėž…ë‹ˆë‹¤. + +### 로드 ë°¸ëŸ°ė„œ + +ėģ¨í…Œė´ë„ˆëĄœ ėž‘ė—…í•  때, ė—ŦëŸŦëļ„ė€ ėŧë°˜ė ėœŧ로 **ëŠ”ė¸ íŦíŠ¸ė˜ ėƒí™Šė„ ę°ė§€í•˜ëŠ”** ėš”ė†ŒëĨŧ 氀맀溠 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤. ė´ëŠ” **HTTPS**ëĨŧ ë‹¤ëŖ¨ëŠ” **TLS ėĸ…ëŖŒ í”„ëĄė‹œ**뙀 ę°™ė€ 다ëĨ¸ ėģ¨í…Œė´ë„ˆėŧ ėˆ˜ë„ ėžˆęŗ , 뜠ė‚Ŧ한 다ëĨ¸ 도ęĩŦėŧ ėˆ˜ë„ ėžˆėŠĩ니다. + +ė´ ėš”ė†Œę°€ ėš”ė˛­ë“¤ė˜ **로드**ëĨŧ ėŊė–´ë“¤ė´ęŗ  각 ė›Œėģ¤ė—ę˛Œ (바ëŧ건대) **ęˇ í˜•ė ėœŧ로** ëļ„배한다늴, ė´ ėš”ė†ŒëŠ” ėŧë°˜ė ėœŧ로 **로드 ë°¸ëŸ°ė„œ**ëŧęŗ  ëļˆëĻŊ니다. + +!!! 팁 + HTTPSëĨŧ ėœ„í•´ ė‚ŦėšŠëœ **TLS ėĸ…ëŖŒ í”„ëĄė‹œ** ėš”ė†Œ 또한 **로드 ë°¸ëŸ°ė„œ**가 될 눘 ėžˆėŠĩ니다. + +또한 ėģ¨í…Œė´ë„ˆëĄœ ėž‘ė—…í•  때, ėģ¨í…Œė´ë„ˆëĨŧ ė‹œėž‘í•˜ęŗ  관ëĻŦ하기 ėœ„í•´ ė‚ŦėšŠí•œ 것ęŗŧ 동ėŧ한 ė‹œėŠ¤í…œė€ ė´ë¯¸ 해당 **로드 ë°¸ëŸ°ė„œ**로 ëļ€í„° ė—ŦëŸŦëļ„ė˜ ė•ąė— 해당하는 ėģ¨í…Œė´ë„ˆëĄœ **ë„¤íŠ¸ė›ŒíŦ í†ĩė‹ **(똈ëĨŧ ë“¤ė–´, HTTP ėš”ė˛­)ė„ ė „ė†Ąí•˜ëŠ” 내ëļ€ė ė¸ 도ęĩŦëĨŧ 氀맀溠 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤ (ė—Ŧę¸°ė„œë„ 로드 ë°¸ëŸ°ė„œëŠ” **TLS ėĸ…ëŖŒ í”„ëĄė‹œ**ėŧ 눘 ėžˆėŠĩ니다). + +### í•˜ë‚˜ė˜ 로드 ë°¸ëŸ°ė„œ - ë‹¤ė¤‘ ė›Œėģ¤ ėģ¨í…Œė´ë„ˆ + +**ėŋ ë˛„ë„¤í‹°ėŠ¤**나 또는 다ëĨ¸ ëļ„ė‚° ėģ¨í…Œė´ë„ˆ 관ëĻŦ ė‹œėŠ¤í…œėœŧ로 ėž‘ė—…í•  때, ė‹œėŠ¤í…œ 내ëļ€ė˜ ë„¤íŠ¸ė›Œí‚š 메ėģ¤ë‹ˆėĻ˜ė„ ė´ėšŠí•¨ėœŧëĄœė¨ ëŠ”ė¸ **íŦ트**ëĨŧ ę°ė§€í•˜ęŗ  ėžˆëŠ” 단ėŧ **로드 ë°¸ëŸ°ė„œ**는 ė—ŦëŸŦëļ„ė˜ ė•ąė—ė„œ ė‹¤í–‰ë˜ęŗ  ėžˆëŠ” **ė—ŦëŸŦę°œė˜ ėģ¨í…Œė´ë„ˆ**뗐 í†ĩė‹ (ėš”ė˛­ë“¤)ė„ ė „ė†Ąí•  눘 ėžˆę˛Œ 됩니다. + +ė—ŦëŸŦëļ„ė˜ ė•ąė—ė„œ ė‹¤í–‰ë˜ęŗ  ėžˆëŠ” ę°ę°ė˜ ėģ¨í…Œė´ë„ˆëŠ” ėŧë°˜ė ėœŧ로 **í•˜ë‚˜ė˜ í”„ëĄœė„¸ėŠ¤**만 ę°€ė§ˆ ę˛ƒėž…ë‹ˆë‹¤ (똈ëĨŧ ë“¤ė–´, FastAPI ė–´í”ŒëĻŦėŧ€ė´ė…˜ė—ė„œ ė‹¤í–‰ë˜ëŠ” í•˜ë‚˜ė˜ Uvicorn í”„ëĄœė„¸ėŠ¤ė˛˜ëŸŧ). ė´ ėģ¨í…Œė´ë„ˆë“¤ė€ ëĒ¨ë‘ ę°™ė€ ę˛ƒė„ ė‹¤í–‰í•˜ëŠ” ė ė—ė„œ **동ėŧ한 ėģ¨í…Œė´ë„ˆ**ė´ė§€ë§Œ, í”„ëĄœė„¸ėŠ¤, 메ëǍëĻŦ ë“ąė€ ęŗĩėœ í•˜ė§€ ė•ŠėŠĩ니다. ė´ ë°Šė‹ėœŧ로 ė—ŦëŸŦëļ„ė€ CPUė˜ **ė„œëĄœ 다ëĨ¸ ėŊ”ė–´ë“¤** 또는 **ė„œëĄœ 다ëĨ¸ ë¨¸ė‹ ë“¤**ė„ **ëŗ‘ë Ŧ화**하는 ė´ė ė„ ė–ģė„ 눘 ėžˆėŠĩ니다. + +또한 **로드 ë°¸ëŸ°ė„œ**가 ėžˆëŠ” ëļ„ė‚° ėģ¨í…Œė´ë„ˆ ė‹œėŠ¤í…œė€ ė—ŦëŸŦëļ„ė˜ ė•ąė— ėžˆëŠ” ėģ¨í…Œė´ë„ˆ 氁氁뗐 **ė°¨ëĄ€ëŒ€ëĄœ ėš”ė˛­ė„ ëļ„ė‚°**ė‹œí‚Ŧ 것 ėž…ë‹ˆë‹¤. 따ëŧė„œ 각 ėš”ė˛­ė€ ė—ŦëŸŦëļ„ė˜ ė•ąė—ė„œ ė‹¤í–‰ë˜ëŠ” ė—ŦëŸŦę°œė˜ **ëŗĩė œëœ ėģ¨í…Œė´ë„ˆë“¤** 뤑 í•˜ë‚˜ė— ė˜í•´ ë‹¤ëŖ¨ė–´ė§ˆ 것 ėž…ë‹ˆë‹¤. + +꡸ëĻŦęŗ  ėŧë°˜ė ėœŧ로 **로드 ë°¸ëŸ°ė„œ**는 ė—ŦëŸŦëļ„ė˜ 클ëŸŦėŠ¤í„°ė— ėžˆëŠ” *다ëĨ¸* ė•ąėœŧ로 가는 ėš”ė˛­ë“¤ë„ ë‹¤ëŖ° 눘 ėžˆėœŧ늰 (똈ëĨŧ ë“¤ė–´, 다ëĨ¸ ë„ëŠ”ė¸ėœŧ로 가거나 다ëĨ¸ URL ę˛Ŋ로 ė ‘ë‘ė‚ŦëĨŧ ę°€ė§€ëŠ” ę˛Ŋ뚰), ė´ í†ĩė‹ ë“¤ė„ 클ëŸŦėŠ¤í„°ė— ėžˆëŠ” *바로 ꡸ 다ëĨ¸* ė–´í”ŒëĻŦėŧ€ė´ė…˜ėœŧ로 ė œëŒ€ëĄœ ė „ė†Ąí•  눘 ėžˆėŠĩ니다. + +### 단ėŧ í”„ëĄœė„¸ėŠ¤ëĨŧ ę°€ė§€ëŠ” ėģ¨í…Œė´ë„ˆ + +ė´ ė‹œë‚˜ëĻŦė˜¤ė˜ ę˛Ŋ뚰, ė—ŦëŸŦëļ„ė€ ė´ë¯¸ 클ëŸŦėŠ¤í„° ë ˆë˛¨ė—ė„œ ëŗĩ렜ëĨŧ ë‹¤ëŖ¨ęŗ  ėžˆė„ ę˛ƒė´ë¯€ëĄœ **ėģ¨í…Œė´ë„ˆ 당 단ėŧ (Uvicorn) í”„ëĄœė„¸ėŠ¤**ëĨŧ ę°€ė§€ęŗ ėž 할 ę˛ƒėž…ë‹ˆë‹¤. + +따ëŧė„œ, ė—ŦëŸŦëļ„ė€ Gunicorn ė´ë‚˜ Uvicorn ė›Œėģ¤, 또는 Uvicorn ė›Œėģ¤ëĨŧ ė‚ŦėšŠí•˜ëŠ” Uvicorn ë§¤ë‹ˆė €ė™€ ę°™ė€ í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €ëĨŧ 氀맀溠 ė‹ļė–´í•˜ė§€ **ė•Šė„** ę˛ƒėž…ë‹ˆë‹¤. ė—ŦëŸŦëļ„ė€ ėģ¨í…Œė´ë„ˆ 당 **단ėŧ Uvicorn í”„ëĄœė„¸ėŠ¤**ëĨŧ 氀맀溠 ė‹ļė–´í•  ę˛ƒėž…ë‹ˆë‹¤ (꡸ëŸŦ나 ė•„ë§ˆë„ ë‹¤ė¤‘ ėģ¨í…Œė´ë„ˆëĨŧ ę°€ė§ˆ ę˛ƒėž…ë‹ˆë‹¤). + +ė´ë¯¸ ė—ŦëŸŦëļ„ė´ 클ëŸŦėŠ¤í„° ė‹œėŠ¤í…œė„ 관ëĻŦí•˜ęŗ  ėžˆėœŧë¯€ëĄœ, (Uvicorn ė›Œėģ¤ëĨŧ 관ëĻŦ하는 Gunicorn ė´ë‚˜ Uvicorn 래ëŸŧ) ėģ¨í…Œė´ë„ˆ ë‚´ė— 다ëĨ¸ í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €ëĨŧ ę°€ė§€ëŠ” ę˛ƒė€ **ëļˆí•„ėš”í•œ ëŗĩėžĄė„ą**만 더하게 될 ę˛ƒėž…ë‹ˆë‹¤. + +### ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤ëĨŧ ę°€ė§€ëŠ” ėģ¨í…Œė´ë„ˆė™€ íŠšėˆ˜í•œ ę˛Ŋėš°ë“¤ + +ë‹šė—°í•œ ë§ė´ė§€ë§Œ, ė—ŦëŸŦëļ„ė´ 내ëļ€ė ėœŧ로 **Uvicorn ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ë“¤**ëĨŧ ė‹œėž‘í•˜ëŠ” **Gunicorn í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €**ëĨŧ ę°€ė§€ëŠ” 단ėŧ ėģ¨í…Œė´ë„ˆëĨŧ ė›í•˜ëŠ” **íŠšėˆ˜í•œ ę˛Ŋ뚰**도 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤. + +그런 ę˛Ŋėš°ė—, ė—ŦëŸŦëļ„ë“¤ė€ **Gunicorn**ė„ í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €ëĄœ íŦ함하는 **ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€**ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. ė´ í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €ëŠ” ë‹¤ė¤‘ **Uvicorn ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ë“¤**ė„ ė‹¤í–‰í•˜ëŠ°, 디폴트 ė„¸íŒ…ėœŧ로 현ėžŦ CPU ėŊ”떴뗐 기반하ė—Ŧ ėžë™ėœŧ로 ė›Œėģ¤ ę°œėˆ˜ëĨŧ ėĄ°ė •í•Šë‹ˆë‹¤. ė´ ė‚Ŧí•­ė— ëŒ€í•´ė„œëŠ” ė•„ëž˜ė˜ [Gunicornęŗŧ 함ęģ˜í•˜ëŠ” ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ - Uvicorn](#official-docker-image-with-gunicorn-uvicorn)ė—ė„œ 더 ë‹¤ëŖ¨ę˛ ėŠĩ니다. + +ė´ëŸ° ę˛Ŋėš°ė— 해당하는 ëLJ氀맀 ė˜ˆė‹œę°€ ėžˆėŠĩ니다: + +#### ë‹¨ėˆœí•œ ė•ą + +만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ **ėļŠëļ„히 ë‹¨ėˆœ**í•´ė„œ (ė ė–´ë„ ė•„ė§ė€) í”„ëĄœė„¸ėŠ¤ 氜눘ëĨŧ íŒŒė¸-튠 할 í•„ėš”ę°€ ė—†ęą°ë‚˜ 클ëŸŦėŠ¤í„°ę°€ ė•„ë‹Œ **단ėŧ ė„œë˛„**ė—ė„œ ė‹¤í–‰í•˜ęŗ  ėžˆë‹¤ëŠ´, ė—ŦëŸŦëļ„ė€ ėģ¨í…Œė´ë„ˆ ë‚´ė— í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €ëĨŧ ė‚ŦėšŠí•˜ęą°ë‚˜ (ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ė—ė„œ) ėžë™ėœŧ로 ė„¤ė •ë˜ëŠ” 디폴트 ę°’ė„ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +#### 도ėģ¤ ęĩŦė„ą + +ė—ŦëŸŦëļ„ė€ **도ėģ¤ ėģ´íŦėψ**로 (클ëŸŦėŠ¤í„°ę°€ ė•„ë‹Œ) **단ėŧ ė„œë˛„ëĄœ** ë°°íŦ할 눘 ėžˆėœŧ늰, ė´ ę˛Ŋėš°ė— ęŗĩėœ ëœ ë„¤íŠ¸ė›ŒíŦ뙀 **로드 ë°¸ëŸ°ė‹ą**ė„ íŦ함하는 (도ėģ¤ ėģ´íŦėĻˆëĄœ) ėģ¨í…Œė´ë„ˆė˜ ëŗĩ렜ëĨŧ 관ëĻŦ하는 ë‹¨ėˆœí•œ ë°Šë˛•ė´ ė—†ė„ ėˆ˜ë„ ėžˆėŠĩ니다. + +그렇다면 ė—ŦëŸŦëļ„ė€ **í”„ëĄœė„¸ėŠ¤ ë§¤ë‹ˆė €**뙀 함ęģ˜ ë‚´ëļ€ė— **ëĒ‡ę°œė˜ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤ë“¤**ė„ ė‹œėž‘í•˜ëŠ” **단ėŧ ėģ¨í…Œė´ë„ˆ**ëĨŧ í•„ėš”ëĄœ 할 눘 ėžˆėŠĩ니다. + +#### Prometheus뙀 다ëĨ¸ ė´ėœ ë“¤ + +ė—ŦëŸŦëļ„ė€ **단ėŧ í”„ëĄœė„¸ėŠ¤**ëĨŧ ę°€ė§€ëŠ” **ë‹¤ė¤‘ ėģ¨í…Œė´ë„ˆ** ëŒ€ė‹  **ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤**ëĨŧ ę°€ė§€ëŠ” **단ėŧ ėģ¨í…Œė´ë„ˆ**ëĨŧ ėą„íƒí•˜ëŠ” **다ëĨ¸ ė´ėœ **가 ėžˆė„ 눘 ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´ (ė—ŦëŸŦëļ„ė˜ ėžĨėš˜ 네렕뗐 따ëŧ) Prometheus ėĩ늤íŦí„°ė™€ ę°™ė´ ę°™ė€ ėģ¨í…Œė´ë„ˆė— ë“¤ė–´ė˜¤ëŠ” **각 ėš”ė˛­ė— 대해** ė ‘ęˇŧęļŒí•œė„ ę°€ė§€ëŠ” 도ęĩŦëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +ė´ ę˛Ŋėš°ė— ė—ŦëŸŦëļ„ė´ **ė—ŦëŸŦę°œė˜ ėģ¨í…Œė´ë„ˆë“¤**ė„ 氀맀溠 ėžˆë‹¤ëŠ´, Prometheus가 **메트ëĻ­ė„ ėŊė–´ 들ėŧ 때**, 디폴트로 **매번 í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆ**(íŠšė • ëĻŦí€˜ėŠ¤íŠ¸ëĨŧ 관ëĻŦ하는 바로 ꡸ ėģ¨í…Œė´ë„ˆ)로 ëļ€í„° ėŊė–´ë“¤ėŧ ę˛ƒėž…ë‹ˆë‹¤. ė´ëŠ” ëĒ¨ë“  ëŗĩė œëœ ėģ¨í…Œė´ë„ˆė— 대해 **ėļ•ė ëœ 메트ëĻ­ë“¤**ė„ ėŊė–´ë“¤ė´ëŠ” 것ęŗŧ 대비됩니다. + +그렇다면 ė´ ę˛Ŋėš°ė—ëŠ” **ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤**ëĨŧ ę°€ė§€ëŠ” **í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆ**ëĨŧ ë‘ė–´ė„œ ę°™ė€ ėģ¨í…Œė´ë„ˆė—ė„œ ëĒ¨ë“  내ëļ€ í”„ëĄœė„¸ėŠ¤ė— 대한 Prometheus 메트ëĻ­ė„ ėˆ˜ė§‘í•˜ëŠ” 로ėģŦ 도ęĩŦ(똈ëĨŧ ë“¤ė–´ Prometheus ėĩ늤íŦ터 ę°™ė€)ëĨŧ ë‘ė–´ė„œ ė´ 메그ëĻ­ë“¤ė„ í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆė— ë‚´ė—ė„œ ęŗĩėœ í•˜ëŠ” ë°Šë˛•ė´ 더 ë‹¨ėˆœí•  ę˛ƒėž…ë‹ˆë‹¤. + +--- + +ėš”ė ė€, ė´ ė¤‘ė˜ **ė–´ëŠę˛ƒë„** ė—ŦëŸŦëļ„ë“¤ė´ ë°˜ë“œė‹œ 따ëŧė•ŧ하는 **í™•ė •ëœ ė‚Ŧ다**ė´ ė•„ë‹ˆëŧ는 ę˛ƒėž…ë‹ˆë‹¤. ė—ŦëŸŦëļ„ė€ ė´ ė•„ė´ë””ė–´ë“¤ė„ **ė—ŦëŸŦëļ„ė˜ ęŗ ėœ í•œ ė´ėšŠ ė‚Ŧ례ëĨŧ 평가**하는데 ė‚ŦėšŠí•˜ęŗ , ė—ŦëŸŦëļ„ė˜ ė‹œėŠ¤í…œė— 가ėžĨ ė í•Ší•œ ė ‘ęˇŧë˛•ė´ ė–´ë–¤ ę˛ƒė¸ė§€ ę˛°ė •í•˜ëŠ°, ë‹¤ėŒė˜ ę°œë…ë“¤ė„ 관ëĻŦ하는 ë°Šë˛•ė„ í™•ė¸í•  눘 ėžˆėŠĩ니다: + +* ëŗ´ė•ˆ - HTTPS +* ęĩŦ동하기 +* ėžŦė‹œėž‘ +* ëŗĩ렜 (ė‹¤í–‰ ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤ 氜눘) +* 메ëǍëĻŦ +* ė‹œėž‘í•˜ę¸° ė „ ë‹¨ęŗ„ë“¤ + +## 메ëǍëĻŦ + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ **ėģ¨í…Œė´ë„ˆ 당 단ėŧ í”„ëĄœė„¸ėŠ¤**ëĨŧ ė‹¤í–‰í•œë‹¤ëŠ´, ė—ŦëŸŦëļ„ė€ 각 ėģ¨í…Œė´ë„ˆ(ëŗĩė œëœ ę˛Ŋėš°ė—ëŠ” ė—ŦëŸŦę°œė˜ ėģ¨í…Œė´ë„ˆë“¤)뗐 대해 ėž˜ ė •ė˜ë˜ęŗ , ė•ˆė •ė ė´ëŠ°, ė œí•œëœ ėšŠëŸ‰ė˜ 메ëǍëĻŦ ė†Œëš„ëŸ‰ė„ 氀맀溠 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤. + +꡸ëŸŦ늴 ė—ŦëŸŦëļ„ė˜ ėģ¨í…Œė´ë„ˆ 관ëĻŦ ė‹œėŠ¤í…œ(똈ëĨŧ ë“¤ė–´ **ėŋ ë˛„ë„¤í‹°ėŠ¤**) ė„¤ė •ė—ė„œ ė•žė„œ ė •ė˜ëœ 것ęŗŧ ę°™ė€ 메ëǍëĻŦ ė œí•œęŗŧ ėš”ęĩŦė‚Ŧí•­ė„ ė„¤ė •í•  눘 ėžˆėŠĩ니다. ė´ëŸ° 방법ėœŧ로 **ę°€ėšŠ ë¨¸ė‹ **ė´ í•„ėš”ëĄœí•˜ëŠ” 메ëǍëĻŦ뙀 클ëŸŦėŠ¤í„°ė— ėžˆëŠ” ę°€ėšŠ ë¨¸ė‹ ë“¤ė„ ė—ŧë‘ė— ë‘ęŗ  **ėģ¨í…Œė´ë„ˆëĨŧ ëŗĩ렜**할 눘 ėžˆėŠĩ니다. + +만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ **ë‹¨ėˆœ**하다면, ė´ę˛ƒė€ **ëŦ¸ė œę°€ ë˜ė§€ ė•Šė„** ę˛ƒė´ęŗ , ęŗ ė •ëœ 메ëǍëĻŦ ė œí•œė„ ęĩŦė˛´í™”í•  í•„ėš”ë„ ė—†ė„ ę˛ƒėž…ë‹ˆë‹¤. í•˜ė§€ë§Œ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ (똈ëĨŧ ë“¤ė–´ **ë¨¸ė‹  ëŸŦ닝** ëĒ¨ë¸ę°™ė´) **ë§Žė€ 메ëǍëĻŦëĨŧ ė†Œėš”í•œë‹¤ëŠ´**, ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ ė–ŧ마나 ë§Žė€ ė–‘ė˜ 메ëǍëĻŦëĨŧ ė‚ŦėšŠí•˜ëŠ”ė§€ í™•ė¸í•˜ęŗ  **각 ë¨¸ė‹ ė—ė„œ** ė‚ŦėšŠí•˜ëŠ” **ėģ¨í…Œė´ë„ˆė˜ 눘**ëĨŧ ėĄ°ė •í•  í•„ėš”ę°€ ėžˆėŠĩ니다 (꡸ëĻŦęŗ  í•„ėš”ė— 따ëŧ ė—ŦëŸŦëļ„ė˜ 클ëŸŦėŠ¤í„°ė— ë¨¸ė‹ ė„ ėļ”가할 눘 ėžˆėŠĩ니다). + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ **ėģ¨í…Œė´ë„ˆ 당 ė—ŦëŸŦę°œė˜ í”„ëĄœė„¸ėŠ¤**ëĨŧ ė‹¤í–‰í•œë‹¤ëŠ´ (똈ëĨŧ ë“¤ė–´ ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ 래ëŸŧ), ė—ŦëŸŦëļ„ė€ ė‹œėž‘ëœ í”„ëĄœė„¸ėŠ¤ ę°œėˆ˜ę°€ ę°€ėšŠí•œ 것 ëŗ´ë‹¤ **더 ë§Žė€ 메ëǍëĻŦëĨŧ ė†Œëš„**í•˜ė§€ ė•ŠëŠ”ė§€ í™•ė¸í•´ė•ŧ 합니다. + +## ė‹œėž‘í•˜ę¸° ė „ ë‹¨ęŗ„ë“¤ęŗŧ ėģ¨í…Œė´ë„ˆ + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ ėģ¨í…Œė´ë„ˆ(똈ëĨŧ ë“¤ė–´ 도ėģ¤, ėŋ ë˛„ë„¤í‹°ėŠ¤)ëĨŧ ė‚ŦėšŠí•œë‹¤ëŠ´, ė—ŦëŸŦëļ„ė´ ė ‘ęˇŧ할 눘 ėžˆëŠ” ėŖŧėš” ë°Šë˛•ė€ íŦ枌 ë‘ę°€ė§€ę°€ ėžˆėŠĩ니다. + +### ë‹¤ė¤‘ ėģ¨í…Œė´ë„ˆ + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ **ė—ŦëŸŦę°œė˜ ėģ¨í…Œė´ë„ˆ**ëĨŧ 氀맀溠 ėžˆë‹¤ëŠ´, ė•„ë§ˆë„ ę°ę°ė˜ ėģ¨í…Œė´ë„ˆëŠ” **í•˜ë‚˜ė˜ í”„ëĄœė„¸ėŠ¤**ëĨŧ 氀맀溠 ėžˆė„ ę˛ƒėž…ë‹ˆë‹¤(똈ëĨŧ ë“¤ė–´, **ėŋ ë˛„ë„¤í‹°ėŠ¤** 클ëŸŦėŠ¤í„°ė—ė„œ). ꡸ëŸŦ늴 ė—ŦëŸŦëļ„ė€ ëŗĩė œëœ ė›Œėģ¤ ėģ¨í…Œė´ë„ˆëĨŧ ė‹¤í–‰í•˜ę¸° **ė´ė „ė—**, í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆė— ėžˆëŠ” **ė´ė „ė˜ ë‹¨ęŗ„ë“¤ė„** ėˆ˜í–‰í•˜ëŠ” 단ėŧ í”„ëĄœė„¸ėŠ¤ëĨŧ ę°€ė§€ëŠ” **ëŗ„ë„ė˜ ėģ¨í…Œė´ë„ˆë“¤**ė„ 氀맀溠 ė‹ļė„ ę˛ƒėž…ë‹ˆë‹¤. + +!!! ė •ëŗ´ + 만ė•Ŋ ė—ŦëŸŦëļ„ė´ ėŋ ë˛„ë„¤í‹°ėŠ¤ëĨŧ ė‚ŦėšŠí•˜ęŗ  ėžˆë‹¤ëŠ´, ė•„ë§ˆë„ ė´ëŠ” Init Containerėŧ ę˛ƒėž…ë‹ˆë‹¤. + +만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė´ėšŠ ė‚ŦëĄ€ė—ė„œ ė´ė „ ë‹¨ęŗ„ë“¤ė„ **ëŗ‘ë Ŧ렁ėœŧ로 ė—ŦëŸŦ번** ėˆ˜í–‰í•˜ëŠ”ë°ė— ëŦ¸ė œę°€ ė—†ë‹¤ëŠ´ (똈ëĨŧ ë“¤ė–´ ë°ė´í„°ë˛ ė´ėŠ¤ ė´ė „ė„ ė‹¤í–‰í•˜ė§€ ė•Šęŗ  ë°ė´í„°ë˛ ė´ėŠ¤ę°€ ė¤€ëš„ë˜ė—ˆëŠ”ė§€ í™•ė¸ë§Œ 하는 ę˛Ŋ뚰), ëŠ”ė¸ í”„ëĄœė„¸ėŠ¤ëĨŧ ė‹œėž‘í•˜ę¸° 렄뗐 ė´ ë‹¨ęŗ„ë“¤ė„ 각 ėģ¨í…Œė´ë„ˆė— ë„Ŗė„ 눘 ėžˆėŠĩ니다. + +### 단ėŧ ėģ¨í…Œė´ë„ˆ + +만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė…‹ė—…ė´ **ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤**(또는 í•˜ë‚˜ė˜ í”„ëĄœė„¸ėŠ¤)ëĨŧ ė‹œėž‘í•˜ëŠ” **í•˜ë‚˜ė˜ ėģ¨í…Œė´ë„ˆ**ëĨŧ ę°€ė§€ëŠ” ë‹¨ėˆœí•œ ė…‹ė—…ė´ëŧ늴, ė‚Ŧė „ ë‹¨ęŗ„ë“¤ė„ ė•ąė„ íŦ함하는 í”„ëĄœė„¸ėŠ¤ëĨŧ ė‹œėž‘í•˜ę¸° 링렄뗐 ę°™ė€ ėģ¨í…Œė´ë„ˆė—ė„œ ė‹¤í–‰í•  눘 ėžˆėŠĩ니다. ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ëŠ” ė´ëĨŧ 내ëļ€ė ėœŧ로 ė§€ė›í•Šë‹ˆë‹¤. + +## Gunicornęŗŧ 함ęģ˜í•˜ëŠ” ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ - Uvicorn + +ė•ž ėą•í„°ė—ė„œ ėžė„¸í•˜ę˛Œ 네ëĒ…ëœ 것 래ëŸŧ, Uvicorn ė›Œėģ¤ė™€ ę°™ė´ ė‹¤í–‰ë˜ëŠ” Gunicornė„ íŦ함하는 ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ę°€ ėžˆėŠĩ니다: [ė„œë˛„ ė›Œėģ¤ - Uvicornęŗŧ 함ęģ˜í•˜ëŠ” Gunicorn](./server-workers.md){.internal-link target=_blank}. + +ė´ ė´ë¯¸ė§€ëŠ” ėŖŧ로 ėœ„ė—ė„œ 네ëĒ…ëœ ėƒí™Šė—ė„œ ėœ ėšŠí•  ę˛ƒėž…ë‹ˆë‹¤: [ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤ëĨŧ ę°€ė§€ëŠ” ėģ¨í…Œė´ë„ˆė™€ íŠšėˆ˜í•œ ę˛Ŋėš°ë“¤](#containers-with-multiple-processes-and-special-cases). + +* tiangolo/uvicorn-gunicorn-fastapi. + +!!! ę˛Ŋęŗ  + ė—ŦëŸŦëļ„ė´ ė´ ë˛ ė´ėŠ¤ ė´ë¯¸ė§€ 또는 다ëĨ¸ 뜠ė‚Ŧ한 ė´ë¯¸ė§€ëĨŧ í•„ėš”ëĄœ í•˜ė§€ **ė•Šė„** ë†’ė€ 가ëŠĨė„ąė´ ėžˆėœŧ늰, [ėœ„ė—ė„œ 네ëĒ…ëœ 枃래ëŸŧ: FastAPIëĨŧ ėœ„í•œ 도ėģ¤ ė´ë¯¸ė§€ 빌드하기](#build-a-docker-image-for-fastapi) ė˛˜ėŒëļ€í„° ė´ë¯¸ė§€ëĨŧ 빌드하는 ę˛ƒė´ 더 ë‚˜ė„ 눘 ėžˆėŠĩ니다. + +ė´ ė´ë¯¸ė§€ëŠ” 가ëŠĨ한 CPU ėŊ”떴뗐 기반한 **ëĒ‡ę°œė˜ ė›Œėģ¤ í”„ëĄœė„¸ėŠ¤**ëĨŧ ė„¤ė •í•˜ëŠ” **ėžë™-튜닝** 메ėģ¤ë‹ˆėĻ˜ė„ íŦí•¨í•˜ęŗ  ėžˆėŠĩ니다. + +ė´ ė´ë¯¸ė§€ëŠ” **ë¯ŧ감한 디폴트** ę°’ė„ 氀맀溠 ėžˆė§€ë§Œ, ė—ŦëŸŦëļ„ë“¤ė€ ė—Ŧė „ížˆ **환ę˛Ŋ ëŗ€ėˆ˜** 또는 네렕 파ėŧė„ í†ĩ해 ė„¤ė •ę°’ė„ ėˆ˜ė •í•˜ęŗ  ė—…ë°ė´íŠ¸ 할 눘 ėžˆėŠĩ니다. + +또한 늤íŦëĻŊ트ëĨŧ í†ĩ해 **ė‹œėž‘í•˜ę¸° ė „ ė‚Ŧė „ ë‹¨ęŗ„**ëĨŧ ė‹¤í–‰í•˜ëŠ” ę˛ƒė„ ė§€ė›í•Šë‹ˆë‹¤. + +!!! 팁 + ëĒ¨ë“  네렕ęŗŧ ė˜ĩė…˜ė„ ëŗ´ë ¤ëŠ´, 도ėģ¤ ė´ë¯¸ė§€ íŽ˜ė´ė§€ëĄœ ė´ë™í•Šë‹ˆë‹¤: tiangolo/uvicorn-gunicorn-fastapi. + +### ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ė— ėžˆëŠ” í”„ëĄœė„¸ėŠ¤ 氜눘 + +ė´ ė´ë¯¸ė§€ė— ėžˆëŠ” **í”„ëĄœė„¸ėŠ¤ 氜눘**는 ę°€ėšŠí•œ CPU **ėŊ”ė–´ë“¤**로 ëļ€í„° **ėžë™ėœŧ로 ęŗ„ė‚°**됩니다. + +ė´ę˛ƒė´ ė˜ë¯¸í•˜ëŠ” 바는 ė´ë¯¸ė§€ę°€ CPU로ëļ€í„° **ėĩœëŒ€í•œė˜ ė„ąëŠĨ**ė„ **ėĨė–´ė§œë‚¸ë‹¤**는 ę˛ƒėž…ë‹ˆë‹¤. + +ė—ŦëŸŦëļ„ė€ ė´ 네렕 ę°’ė„ **환ę˛Ŋ ëŗ€ėˆ˜**나 기타 방법들로 ėĄ°ė •í•  눘 ėžˆėŠĩ니다. + +꡸ëŸŦ나 í”„ëĄœė„¸ėŠ¤ė˜ ę°œėˆ˜ę°€ ėģ¨í…Œė´ë„ˆę°€ ė‹¤í–‰ë˜ęŗ  ėžˆëŠ” CPU뗐 ė˜ėĄ´í•œë‹¤ëŠ” ę˛ƒė€ 또한 **ė†Œėš”ë˜ëŠ” 메ëǍëĻŦė˜ íŦ기** 또한 ė´ė— ė˜ėĄ´í•œë‹¤ëŠ” ę˛ƒė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +그렇기 때ëŦ¸ė—, 만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ ë§Žė€ 메ëǍëĻŦëĨŧ ėš”ęĩŦí•˜ęŗ  (똈ëĨŧ ë“¤ė–´ ë¨¸ė‹ ëŸŦ닝 ëĒ¨ë¸ė˛˜ëŸŧ), ė—ŦëŸŦëļ„ė˜ ė„œë˛„ę°€ CPU ėŊ”ė–´ ėˆ˜ëŠ” ë§Žė§€ë§Œ **ė ė€ 메ëǍëĻŦ**ëĨŧ 氀맀溠 ėžˆë‹¤ëŠ´, ė—ŦëŸŦëļ„ė˜ ėģ¨í…Œė´ë„ˆëŠ” ę°€ėšŠí•œ 메ëǍëĻŦëŗ´ë‹¤ ë§Žė€ 메ëǍëĻŦëĨŧ ė‚ŦėšŠí•˜ë ¤ęŗ  ė‹œë„í•  눘 ėžˆėœŧ늰, 결ęĩ­ íŧíŦë¨ŧ늤ëĨŧ íŦ枌 ë–¨ė–´ëœ¨ëĻ´ 눘 ėžˆėŠĩ니다(ė‹Ŧ맀떴 ęŗ ėžĨė´ 날 ėˆ˜ë„ ėžˆėŠĩ니다). 🚨 + +### `Dockerfile` ėƒė„ąí•˜ę¸° + +ė´ ė´ë¯¸ė§€ė— 기반해 `Dockerfile`ė„ ėƒė„ąí•˜ëŠ” ë°Šë˛•ė€ ë‹¤ėŒęŗŧ 같ėŠĩ니다: + +```Dockerfile +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9 + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt + +COPY ./app /app +``` + +### 더 큰 ė–´í”ŒëĻŦėŧ€ė´ė…˜ + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ [ë‹¤ė¤‘ 파ėŧė„ ę°€ė§€ëŠ” 더 큰 ė–´í”ŒëĻŦėŧ€ė´ė…˜](../tutorial/bigger-applications.md){.internal-link target=_blank}ė„ ėƒė„ąí•˜ëŠ” ė„šė…˜ė„ 따랐다면, ė—ŦëŸŦëļ„ė˜ `Dockerfile`ė€ ëŒ€ė‹  ė´ë ‡ę˛Œ ėƒę˛ŧė„ ę˛ƒėž…ë‹ˆë‹¤: + +```Dockerfile hl_lines="7" +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9 + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt + +COPY ./app /app/app +``` + +### ė–¸ė œ ė‚ŦėšŠí• ęšŒ + +ė—ŦëŸŦëļ„ë“¤ė´ **ėŋ ë˛„ë„¤í‹°ėŠ¤**(또는 뜠ė‚Ŧ한 다ëĨ¸ 도ęĩŦ) ė‚ŦėšŠí•˜ęą°ë‚˜ 클ëŸŦėŠ¤í„° ë ˆë˛¨ė—ė„œ ë‹¤ė¤‘ ėģ¨í…Œė´ë„ˆëĨŧ ė´ėšŠí•´ ė´ë¯¸ **ė‚Ŧëŗ¸**ė„ ė„¤ė •í•˜ęŗ  ėžˆë‹¤ëŠ´, ęŗĩė‹ ë˛ ė´ėŠ¤ ė´ë¯¸ė§€(또는 뜠ė‚Ŧ한 다ëĨ¸ ė´ë¯¸ė§€)ëĨŧ ė‚ŦėšŠí•˜ė§€ **ė•ŠëŠ”** 것 ėĸ‹ėŠĩ니다. 그런 ę˛Ŋėš°ė— ė—ŦëŸŦëļ„ė€ ë‹¤ėŒė— 네ëĒ…ëœ 것 래ëŸŧ **ė˛˜ėŒëļ€í„° ė´ë¯¸ė§€ëĨŧ 빌드하는 것**ė´ 더 ë‚ĢėŠĩ니다: [FastAPIëĨŧ ėœ„í•œ 도ėģ¤ ė´ë¯¸ė§€ 빌드하기](#build-a-docker-image-for-fastapi). + +ė´ ė´ë¯¸ė§€ëŠ” ėœ„ė˜ [ë‹¤ė¤‘ í”„ëĄœė„¸ėŠ¤ëĨŧ ę°€ė§€ëŠ” ėģ¨í…Œė´ë„ˆė™€ íŠšėˆ˜í•œ ę˛Ŋėš°ë“¤](#containers-with-multiple-processes-and-special-cases)ė—ė„œ 네ëĒ…ëœ íŠšėˆ˜í•œ ę˛Ŋėš°ė— ëŒ€í•´ė„œë§Œ ėŖŧ로 ėœ ėšŠí•  ę˛ƒėž…ë‹ˆë‹¤. 똈ëĨŧ ë“¤ė–´, 만ė•Ŋ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė´ **ėļŠëļ„히 ë‹¨ėˆœ**í•´ė„œ CPU뗐 기반한 디폴트 í”„ëĄœė„¸ėŠ¤ 氜눘ëĨŧ ė„¤ė •í•˜ëŠ” ę˛ƒė´ ėž˜ ėž‘ë™í•œë‹¤ëŠ´, 클ëŸŦėŠ¤í„° ë ˆë˛¨ė—ė„œ ėˆ˜ë™ėœŧ로 ė‚Ŧëŗ¸ė„ ė„¤ė •í•  í•„ėš”ę°€ ė—†ė„ ę˛ƒė´ęŗ , ė—ŦëŸŦëļ„ė˜ ė•ąė—ė„œ 하나 ė´ėƒė˜ ėģ¨í…Œė´ë„ˆëĨŧ ė‹¤í–‰í•˜ė§€ë„ ė•Šė„ ę˛ƒėž…ë‹ˆë‹¤. 또는 만ė•Ŋ뗐 ė—ŦëŸŦëļ„ė´ **도ėģ¤ ėģ´íŦėψ**로 ë°°íŦ하거나, 단ėŧ ė„œë˛„ė—ė„œ ė‹¤í–‰í•˜ęą°ë‚˜ 하는 ę˛Ŋėš°ė—ë„ 마ė°Ŧę°€ė§€ėž…ë‹ˆë‹¤. + +## ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ ë°°íŦ하기 + +ėģ¨í…Œė´ë„ˆ (도ėģ¤) ė´ë¯¸ė§€ëĨŧ ė™„ė„ąí•œ ë’¤ė— ė´ëĨŧ ë°°íŦ하는 ë°Šë˛•ė—ëŠ” ė—ŦëŸŦ氀맀 ë°Šë˛•ė´ ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´: + +* 단ėŧ ė„œë˛„ė—ė„œ **도ėģ¤ ėģ´íŦėψ**로 ë°°íŦ하기 +* **ėŋ ë˛„ë„¤í‹°ėŠ¤** 클ëŸŦėŠ¤í„°ëĄœ ë°°íŦ하기 +* 도ėģ¤ ėŠ¤ė™ ëĒ¨ë“œ 클ëŸŦėŠ¤í„°ëĄœ ë°°íŦ하기 +* 노마드 ę°™ė€ 다ëĨ¸ 도ęĩŦ로 ë°°íŦ하기 +* ė—ŦëŸŦëļ„ė˜ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ ë°°íŦ해ėŖŧ는 클ëŧėš°ë“œ ė„œëš„ėŠ¤ëĄœ ë°°íŦ하기 + +## Poetryė˜ 도ėģ¤ ė´ë¯¸ė§€ + +만ė•Ŋ ė—ŦëŸŦëļ„ë“¤ė´ í”„ëĄœė íŠ¸ ė˜ėĄ´ė„ąė„ 관ëĻŦ하기 ėœ„í•´ PoetryëĨŧ ė‚ŦėšŠí•œë‹¤ëŠ´, 도ėģ¤ė˜ 멀티-ėŠ¤í…Œė´ė§€ ëšŒë”Šė„ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +```{ .dockerfile .annotate } +# (1) +FROM python:3.9 as requirements-stage + +# (2) +WORKDIR /tmp + +# (3) +RUN pip install poetry + +# (4) +COPY ./pyproject.toml ./poetry.lock* /tmp/ + +# (5) +RUN poetry export -f requirements.txt --output requirements.txt --without-hashes + +# (6) +FROM python:3.9 + +# (7) +WORKDIR /code + +# (8) +COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt + +# (9) +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (10) +COPY ./app /code/app + +# (11) +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. ė˛Ģ ėŠ¤í…Œė´ė§€ëĄœ, `requirements-stage`ëŧęŗ  ė´ëĻ„ ëļ™ė˜€ėŠĩ니다. + +2. `/tmp`ëĨŧ 현ėžŦė˜ ė›Œí‚š 디렉터ëĻŦ로 ė„¤ė •í•Šë‹ˆë‹¤. + + ė´ ėœ„ėš˜ė— 뚰ëĻŦ는 `requirements.txt` 파ėŧė„ ėƒė„ąí•  ę˛ƒėž…ë‹ˆë‹¤. + +3. ė´ 도ėģ¤ ėŠ¤í…Œė´ė§€ė—ė„œ PoetryëĨŧ ė„¤ėš˜í•Šë‹ˆë‹¤. + +4. 파ėŧ `pyproject.toml`뙀 `poetry.lock`ëĨŧ `/tmp` 디렉터ëĻŦ로 ëŗĩė‚Ŧ합니다. + + `./poetry.lock*` (`*`로 끝나는) 파ėŧė„ ė‚ŦėšŠí•˜ę¸° 때ëŦ¸ė—, 파ėŧė´ 땄링 ė‚ŦėšŠę°€ëŠĨí•˜ė§€ ė•Šë”ëŧ도 ęŗ ėžĨë‚˜ė§€ ė•Šė„ ę˛ƒėž…ë‹ˆë‹¤. + +5. `requirements.txt` 파ėŧė„ ėƒė„ąí•Šë‹ˆë‹¤. + +6. ė´ę˛ƒė´ ë§ˆė§€ë§‰ ėŠ¤í…Œė´ė§€ëĄœ, ė—Ŧ揰뗐 ėœ„ėš˜í•œ ëĒ¨ë“  ę˛ƒė´ ë§ˆė§€ë§‰ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ė— íŦ함될 ę˛ƒėž…ë‹ˆë‹¤. + +7. 현ėžŦė˜ ė›Œí‚š 디렉터ëĻŦëĨŧ `/code`로 ė„¤ė •í•Šë‹ˆë‹¤. + +8. 파ėŧ `requirements.txt`ëĨŧ `/code` 디렉터ëĻŦ로 ëŗĩė‚Ŧ합니다. + + ė´ 파ėŧė€ 똤링 ė´ė „ė˜ 도ėģ¤ ėŠ¤í…Œė´ė§€ė—ë§Œ ėĄ´ėžŦ하며, 때ëŦ¸ė— ëŗĩė‚Ŧ하기 ėœ„í•´ė„œ `--from-requirements-stage` ė˜ĩė…˜ė´ í•„ėš”í•Šë‹ˆë‹¤. + +9. ėƒė„ąëœ `requirements.txt` 파ėŧ뗐 íŒ¨í‚¤ė§€ ė˜ėĄ´ė„ąė„ ė„¤ėš˜í•Šë‹ˆë‹¤. + +10. `app` 디렉터ëĻŦëĨŧ `/code` 디렉터ëĻŦ로 ëŗĩė‚Ŧ합니다. + +11. `uvicorn` ėģ¤ë§¨ë“œëĨŧ ė‹¤í–‰í•˜ė—Ŧ, `app.main`ė—ė„œ ëļˆëŸŦ똍 `app` ę°ė˛´ëĨŧ ė‚ŦėšŠí•˜ë„ëĄ 합니다. + +!!! 팁 + 버블 ėˆĢėžëĨŧ 클ëĻ­í•´ 각 ė¤„ė´ 하는 ėŧė„ ė•Œė•„ëŗŧ 눘 ėžˆėŠĩ니다. + +**도ėģ¤ ėŠ¤í…Œė´ė§€**란 `Dockefile`ė˜ ėŧëļ€ëĄœė„œ ë‚˜ė¤‘ė— ė‚ŦėšŠí•˜ę¸° ėœ„í•œ 파ėŧë“¤ė„ ėƒė„ąí•˜ę¸° ėœ„í•œ **ėŧė‹œė ė¸ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€**로 ėž‘ë™í•Šë‹ˆë‹¤. + +ė˛Ģ ėŠ¤í…Œė´ė§€ëŠ” 똤링 **PoetryëĨŧ ė„¤ėš˜**í•˜ęŗ  Poetryė˜ `pyproject.toml` 파ėŧ로ëļ€í„° í”„ëĄœė íŠ¸ ė˜ėĄ´ė„ąė„ ėœ„í•œ **`requirements.txt`ëĨŧ ėƒė„ą**하기 ėœ„í•´ ė‚ŦėšŠëŠë‹ˆë‹¤. + +ė´ `requirements.txt` 파ėŧė€ **ë‹¤ėŒ ėŠ¤í…Œė´ė§€**ė—ė„œ `pip`로 ė‚ŦėšŠë  ę˛ƒėž…ë‹ˆë‹¤. + +ë§ˆė§€ë§‰ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ė—ëŠ” **똤링 ë§ˆė§€ë§‰ ėŠ¤í…Œė´ė§€ë§Œ** ëŗ´ėĄ´ëŠë‹ˆë‹¤. ė´ė „ ėŠ¤í…Œė´ė§€(들)ė€ ë˛„ë ¤ė§‘ë‹ˆë‹¤. + +PoetryëĨŧ ė‚ŦėšŠí•  때 **도ėģ¤ ëŠ€í‹°-ėŠ¤í…Œė´ė§€ 빌드**ëĨŧ ė‚ŦėšŠí•˜ëŠ” ę˛ƒė´ ėĸ‹ė€ë°, ė—ŦëŸŦëļ„ë“¤ė˜ í”„ëĄœė íŠ¸ ė˜ėĄ´ė„ąė„ ė„¤ėš˜í•˜ę¸° ėœ„í•´ ë§ˆė§€ë§‰ ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ė— **똤링** `requirements.txt` 파ėŧ만 í•„ėš”í•˜ė§€, Poetry뙀 ꡸ ė˜ėĄ´ė„ąė€ ėžˆė„ í•„ėš”ę°€ 뗆揰 때ëŦ¸ėž…니다. + +ė´ ë‹¤ėŒ (또한 ë§ˆė§€ë§‰) ėŠ¤í…Œė´ė§€ė—ė„œ ė—ŦëŸŦëļ„ë“¤ė€ ė´ė „ė— 네ëĒ…ëœ 것ęŗŧ ëš„ėŠˇí•œ ë°Šė‹ėœŧ로 ë°Šė‹ėœŧ로 ė´ë¯¸ė§€ëĨŧ 빌드할 눘 ėžˆėŠĩ니다. + +### TLS ėĸ…ëŖŒ í”„ëĄė‹œė˜ 배후 - Poetry + +ė´ė „ė— ė–¸ę¸‰í•œ 것ęŗŧ ę°™ė´, 만ė•Ŋ ė—ŦëŸŦëļ„ė´ ėģ¨í…Œė´ë„ˆëĨŧ Nginx 또는 Traefikęŗŧ ę°™ė€ TLS ėĸ…ëŖŒ í”„ëĄė‹œ (로드 ë°¸ëŸ°ė„œ) ë’¤ė—ė„œ ė‹¤í–‰í•˜ęŗ  ėžˆë‹¤ëŠ´, ėģ¤ë§¨ë“œė— `--proxy-headers` ė˜ĩė…˜ė„ ėļ”ę°€í•Šë‹ˆë‹¤: + +```Dockerfile +CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] +``` + +## ėš”ė•Ŋ + +ėģ¨í…Œė´ë„ˆ ė‹œėŠ¤í…œ(똈ëĨŧ ë“¤ė–´ **도ėģ¤**나 **ėŋ ë˛„ë„¤í‹°ėŠ¤**)ė„ ė‚ŦėšŠí•˜ė—Ŧ ëĒ¨ë“  **ë°°íŦ 개념**ė„ ë‹¤ëŖ¨ëŠ” ę˛ƒė€ ęŊ¤ 간단합니다: + +* HTTPS +* ęĩŦ동하기 +* ėžŦė‹œėž‘ +* ëŗĩ렜 (ė‹¤í–‰ ė¤‘ė¸ í”„ëĄœė„¸ėŠ¤ 氜눘) +* 메ëǍëĻŦ +* ė‹œėž‘í•˜ę¸° ė „ ë‹¨ęŗ„ë“¤ + +대ëļ€ëļ„ė˜ ę˛Ŋėš°ė—ė„œ ė—ŦëŸŦëļ„ė€ ė–´ë–¤ ë˛ ė´ėŠ¤ ė´ë¯¸ė§€ë„ ė‚ŦėšŠí•˜ė§€ ė•Šęŗ  ęŗĩė‹ íŒŒė´ėŦ 도ėģ¤ ė´ë¯¸ė§€ė— 기반해 **ė˛˜ėŒëļ€í„° ėģ¨í…Œė´ë„ˆ ė´ë¯¸ė§€ëĨŧ 빌드**할 ę˛ƒėž…ë‹ˆë‹¤. + +`Dockerfile`뗐 ėžˆëŠ” ė§€ė‹œ ė‚Ŧí•­ė„ **ėˆœė„œëŒ€ëĄœ** ë‹¤ëŖ¨ęŗ  **도ėģ¤ ėēė‹œ**ëĨŧ ė‚ŦėšŠí•˜ëŠ” 것ėœŧ로 ė—ŦëŸŦëļ„ė€ **빌드 ė‹œę°„ė„ ėĩœė†Œí™”**할 눘 ėžˆėœŧ늰, ė´ëĄœė¨ ėƒė‚°ė„ąė„ ėĩœëŒ€í™”í•  눘 ėžˆėŠĩ니다 (꡸ëĻŦęŗ  ė§€ëŖ¨í•¨ė„ í”ŧ할 눘 ėžˆėŖ ) 😎 + +íŠšëŗ„í•œ ę˛Ŋėš°ė—ëŠ”, FastAPIëĨŧ ėœ„í•œ ęŗĩė‹ 도ėģ¤ ė´ë¯¸ė§€ëĨŧ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다. 🤓 From 22c34a39561e3c95eac73847e7279bc0e97912c2 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:54:45 +0000 Subject: [PATCH 155/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7f88bc3795..7407d7c0b6 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/deployment/index.md`. PR [#4561](https://github.com/tiangolo/fastapi/pull/4561) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/path-operation-configuration.md`. PR [#3639](https://github.com/tiangolo/fastapi/pull/3639) by [@jungsu-kwon](https://github.com/jungsu-kwon). * 🌐 Modify the description of `zh` - Traditional Chinese. PR [#10889](https://github.com/tiangolo/fastapi/pull/10889) by [@cherinyy](https://github.com/cherinyy). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/static-files.md`. PR [#2957](https://github.com/tiangolo/fastapi/pull/2957) by [@jeesang7](https://github.com/jeesang7). From f8e77fb64c358d44b71d5a77389ffac3b7ca0509 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:55:21 +0000 Subject: [PATCH 156/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7407d7c0b6..37936f5ada 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/deployment/server-workers.md`. PR [#4935](https://github.com/tiangolo/fastapi/pull/4935) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/deployment/index.md`. PR [#4561](https://github.com/tiangolo/fastapi/pull/4561) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/path-operation-configuration.md`. PR [#3639](https://github.com/tiangolo/fastapi/pull/3639) by [@jungsu-kwon](https://github.com/jungsu-kwon). * 🌐 Modify the description of `zh` - Traditional Chinese. PR [#10889](https://github.com/tiangolo/fastapi/pull/10889) by [@cherinyy](https://github.com/cherinyy). From 0a105dc285ed5026d9fada2fe0105d005ec0db73 Mon Sep 17 00:00:00 2001 From: bilal alpaslan <47563997+BilalAlpaslan@users.noreply.github.com> Date: Mon, 22 Jan 2024 22:55:41 +0300 Subject: [PATCH 157/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/project-generation.md`=20(#5192)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/project-generation.md | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 docs/tr/docs/project-generation.md diff --git a/docs/tr/docs/project-generation.md b/docs/tr/docs/project-generation.md new file mode 100644 index 0000000000..75e3ae3397 --- /dev/null +++ b/docs/tr/docs/project-generation.md @@ -0,0 +1,84 @@ +# Proje oluşturma - Şablonlar + +Başlamak için bir proje oluşturucu kullanabilirsiniz, çÃŧnkÃŧ sizin için Ãļnceden yapÄąlmÄąÅŸ birçok başlangÄąÃ§ ​​kurulumu, gÃŧvenlik, veritabanÄą ve temel API endpoinlerini içerir. + +Bir proje oluşturucu, her zaman kendi ihtiyaçlarÄąnÄąza gÃļre gÃŧncellemeniz ve uyarlamanÄąz gereken esnek bir kuruluma sahip olacaktÄąr, ancak bu, projeniz için iyi bir başlangÄąÃ§ ​​noktasÄą olabilir. + +## Full Stack FastAPI PostgreSQL + +GitHub: https://github.com/tiangolo/full-stack-fastapi-postgresql + +### Full Stack FastAPI PostgreSQL - Özellikler + +* Full **Docker** entegrasyonu (Docker based). +* Docker Swarm Mode ile deployment. +* **Docker Compose** entegrasyonu ve lokal geliştirme için optimizasyon. +* Uvicorn ve Gunicorn ile **Production ready** Python web server'Äą. +* Python **FastAPI** backend: + * **HÄązlÄą**: **NodeJS** ve **Go** ile eşit, çok yÃŧksek performans (Starlette ve Pydantic'e teşekkÃŧrler). + * **Sezgisel**: Editor desteğı. Otomatik tamamlama. Daha az debugging. + * **Kolay**: Kolay Ãļğrenip kolay kullanmak için tasarlandÄą. Daha az dÃļkÃŧman okuma daha çok iş. + * **KÄąsa**: Minimum kod tekrarÄą. Her parametre bildiriminde birden çok Ãļzellik. + * **GÃŧçlÃŧ**: Production-ready. Otomatik interaktif dÃļkÃŧmantasyon. + * **Standartlara dayalÄą**: API'ler için aÃ§Äąk standartlara dayanÄąr (ve tamamen uyumludur): OpenAPI ve JSON ŞemasÄą. + * **Birçok diger Ãļzelliği** dahili otomatik doğrulama, serialization, interaktif dokÃŧmantasyon, OAuth2 JWT token ile authentication, vb. +* **GÃŧvenli şifreleme** . +* **JWT token** kimlik doğrulama. +* **SQLAlchemy** models (Flask dan bağımsÄązdÄąr. Celery worker'larÄą ile kullanÄąlabilir). +* KullanÄącÄąlar için temel başlangÄąÃ§ ​​modeli (gerektiği gibi değiştirin ve kaldÄąrÄąn). +* **Alembic** migration. +* **CORS** (Cross Origin Resource Sharing). +* **Celery** worker'larÄą ile backend içerisinden seçilen işleri çalÄąÅŸtÄąrabilirsiniz. +* **Pytest**'e dayalÄą, Docker ile entegre REST backend testleri ile veritabanÄąndan bağımsÄąz olarak tam API etkileşimini test edebilirsiniz. Docker'da çalÄąÅŸtığı için her seferinde sÄąfÄąrdan yeni bir veri deposu oluşturabilir (bÃļylece ElasticSearch, MongoDB, CouchDB veya ne istersen kullanabilirsin ve sadece API'nin çalÄąÅŸÄąp çalÄąÅŸmadığınÄą test edebilirsin). +* Atom Hydrogen veya Visual Studio Code Jupyter gibi uzantÄąlarla uzaktan veya Docker içi geliştirme için **Jupyter Çekirdekleri** ile kolay Python entegrasyonu. +* **Vue** ile frontend: + * Vue CLI ile oluşturulmuş. + * Dahili **JWT kimlik doğrulama**. + * Dahili Login. + * Login sonrasÄą, Kontrol paneli. + * KullanÄącÄą oluşturma ve dÃŧzenleme kontrol paneli + * Kendi kendine kullanÄącÄą sÃŧrÃŧmÃŧ. + * **Vuex**. + * **Vue-router**. + * **Vuetify** gÃŧzel material design kompanentleri için. + * **TypeScript**. + * **Nginx** tabanlÄą Docker sunucusu (Vue-router için yapÄąlandÄąrÄąlmÄąÅŸ). + * Docker ile multi-stage yapÄą, bÃļylece kodu derlemeniz, kaydetmeniz veya işlemeniz gerekmez. + * Derleme zamanÄąnda Frontend testi (devre dÄąÅŸÄą bÄąrakÄąlabilir). + * MÃŧmkÃŧn olduğu kadar modÃŧler yapÄąlmÄąÅŸtÄąr, bu nedenle kutudan Ã§Äąktığı gibi çalÄąÅŸÄąr, ancak Vue CLI ile yeniden oluşturabilir veya ihtiyaç duyduğunuz şekilde oluşturabilir ve istediğinizi yeniden kullanabilirsiniz. +* **PGAdmin** PostgreSQL database admin tool'u, PHPMyAdmin ve MySQL ile kolayca değiştirilebilir. +* **Flower** ile Celery job'larÄąnÄą monitÃļrleme. +* **Traefik** ile backend ve frontend arasÄąnda yÃŧk dengeleme, bÃļylece her ikisini de aynÄą domain altÄąnda, path ile ayrÄąlmÄąÅŸ, ancak farklÄą kapsayÄącÄąlar tarafÄąndan sunulabilirsiniz. +* Let's Encrypt **HTTPS** sertifikalarÄąnÄąn otomatik oluşturulmasÄą dahil olmak Ãŧzere Traefik entegrasyonu. +* GitLab **CI** (sÃŧrekli entegrasyon), backend ve frontend testi dahil. + +## Full Stack FastAPI Couchbase + +GitHub: https://github.com/tiangolo/full-stack-fastapi-couchbase + +âš ī¸ **UYARI** âš ī¸ + +SÄąfÄąrdan bir projeye başlÄąyorsanÄąz alternatiflerine bakÄąn. + +Örneğin, Full Stack FastAPI PostgreSQL daha iyi bir alternatif olabilir, aktif olarak geliştiriliyor ve kullanÄąlÄąyor. Ve yeni Ãļzellik ve ilerlemelere sahip. + +İsterseniz Couchbase tabanlÄą generator'Äą kullanmakta ÃļzgÃŧrsÃŧnÃŧz, hala iyi çalÄąÅŸÄąyor olmalÄą ve onunla oluşturulmuş bir projeniz varsa bu da sorun değil (ve muhtemelen zaten ihtiyaçlarÄąnÄąza gÃļre gÃŧncellediniz). + +Bununla ilgili daha fazla bilgiyi repo belgelerinde okuyabilirsiniz. + +## Full Stack FastAPI MongoDB + +... mÃŧsaitliğime ve diğer faktÃļrlere bağlÄą olarak daha sonra gelebilir. 😅 🎉 + +## Machine Learning modelleri, spaCy ve FastAPI + +GitHub: https://github.com/microsoft/cookiecutter-spacy-fastapi + +### Machine Learning modelleri, spaCy ve FastAPI - Features + +* **spaCy** NER model entegrasyonu. +* **Azure Cognitive Search** yerleşik istek biçimi. +* Uvicorn ve Gunicorn ile **Production ready** Python web server'Äą. +* Dahili **Azure DevOps** Kubernetes (AKS) CI/CD deployment. +* **Multilingual**, Proje kurulumu sÄąrasÄąnda spaCy'nin yerleşik dillerinden birini kolayca seçin. +* **Esnetilebilir** diğer frameworkler (Pytorch, Tensorflow) ile de çalÄąÅŸÄąr sadece spaCy değil. From 63ffd735d1c88820807b585eacb05de04f142429 Mon Sep 17 00:00:00 2001 From: bilal alpaslan <47563997+BilalAlpaslan@users.noreply.github.com> Date: Mon, 22 Jan 2024 22:57:04 +0300 Subject: [PATCH 158/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20`docs/tr/docs/async.md`=20(#5191)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/async.md | 401 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 401 insertions(+) create mode 100644 docs/tr/docs/async.md diff --git a/docs/tr/docs/async.md b/docs/tr/docs/async.md new file mode 100644 index 0000000000..2be5943435 --- /dev/null +++ b/docs/tr/docs/async.md @@ -0,0 +1,401 @@ +# Concurrency ve async / await + +*path operasyon fonksiyonu* için `async def `sÃļzdizimi, asenkron kod, eşzamanlÄąlÄąk ve paralellik hakkÄąnda bazÄą ayrÄąntÄąlar. + +## Aceleniz mi var? + +TL;DR: + +Eğer `await` ile çağrÄąlmasÄą gerektiğini belirten ÃŧçÃŧncÃŧ taraf kÃŧtÃŧphaneleri kullanÄąyorsanÄąz, Ãļrneğin: + +```Python +results = await some_library() +``` + +O zaman *path operasyon fonksiyonunu* `async def` ile tanÄąmlayÄąn Ãļrneğin: + +```Python hl_lines="2" +@app.get('/') +async def read_results(): + results = await some_library() + return results +``` + +!!! not + Sadece `async def` ile tanÄąmlanan fonksiyonlar içinde `await` kullanabilirsiniz. + +--- + +Eğer bir veritabanÄą, bir API, dosya sistemi vb. ile iletişim kuran bir ÃŧçÃŧncÃŧ taraf bir kÃŧtÃŧphane kullanÄąyorsanÄąz ve `await` kullanÄąmÄąnÄą desteklemiyorsa, (bu şu anda çoğu veritabanÄą kÃŧtÃŧphanesi için geçerli bir durumdur), o zaman *path operasyon fonksiyonunuzu* `def` kullanarak normal bir şekilde tanÄąmlayÄąn, Ãļrneğin: + +```Python hl_lines="2" +@app.get('/') +def results(): + results = some_library() + return results +``` + +--- + +Eğer uygulamanÄąz (bir şekilde) başka bir şeyle iletişim kurmak ve onun cevap vermesini beklemek zorunda değilse, `async def` kullanÄąn. + +--- + +Sadece bilmiyorsanÄąz, normal `def` kullanÄąn. + +--- + +**Not**: *path operasyon fonksiyonlarÄąnÄązda* `def` ve `async def`'i ihtiyaç duyduğunuz gibi karÄąÅŸtÄąrabilir ve her birini sizin için en iyi seçeneği kullanarak tanÄąmlayabilirsiniz. FastAPI onlarla doğru olanÄą yapacaktÄąr. + +Her neyse, yukarÄądaki durumlardan herhangi birinde, FastAPI yine de asenkron olarak çalÄąÅŸacak ve son derece hÄązlÄą olacaktÄąr. + +Ancak yukarÄądaki adÄąmlarÄą takip ederek, bazÄą performans optimizasyonlarÄą yapÄąlabilecektir. + +## Teknik Detaylar + +Python'un modern versiyonlarÄąnda **`async` ve `await`** sÃļzdizimi ile **"coroutines"** kullanan **"asenkron kod"** desteğine sahiptir. + +Bu ifadeyi aşağıdaki bÃļlÃŧmlerde daha da ayrÄąntÄąlÄą aÃ§ÄąklayalÄąm: + +* **Asenkron kod** +* **`async` ve `await`** +* **Coroutines** + +## Asenkron kod + +Asenkron kod programlama dilinin đŸ’Ŧ bilgisayara / programa 🤖 kodun bir noktasÄąnda, *başka bir kodun* bir yerde bitmesini 🤖 beklemesi gerektiğini sÃļylemenin bir yoludur. Bu *başka koda* "slow-file" denir 📝. + +BÃļylece, bu sÃŧreçte bilgisayar "slow-file" 📝 tamamlanÄąrken gidip başka işler yapabilir. + +Sonra bilgisayar / program 🤖 her fÄąrsatÄą olduğunda o noktada yaptığı tÃŧm işleri 🤖 bitirene kadar geri dÃļnÃŧcek. Ve 🤖 yapmasÄą gerekeni yaparak, beklediği gÃļrevlerden herhangi birinin bitip bitmediğini gÃļrecek. + +ArdÄąndan, 🤖 bitirmek için ilk gÃļrevi alÄąr ("slow-file" 📝) ve onunla ne yapmasÄą gerekiyorsa onu devam ettirir. + +Bu "başka bir şey için bekle" normalde, aşağıdakileri beklemek gibi (işlemcinin ve RAM belleğinin hÄązÄąna kÄąyasla) nispeten "yavaş" olan I/O işlemlerine atÄąfta bulunur: + +* istemci tarafÄąndan ağ Ãŧzerinden veri gÃļndermek +* ağ Ãŧzerinden istemciye gÃļnderilen veriler +* sistem tarafÄąndan okunacak ve programÄąnÄąza verilecek bir dosya içeriği +* programÄąnÄązÄąn diske yazÄąlmak Ãŧzere sisteme verdiği dosya içerikleri +* uzak bir API işlemi +* bir veritabanÄą bitirme işlemi +* sonuçlarÄą dÃļndÃŧrmek için bir veritabanÄą sorgusu +* vb. + +YÃŧrÃŧtme sÃŧresi çoğunlukla I/O işlemleri beklenerek tÃŧketildiğinden bunlara "I/O bağlantÄąlÄą" işlemler denir. + +Buna "asenkron" denir, çÃŧnkÃŧ bilgisayar/program yavaş gÃļrevle "senkronize" olmak zorunda değildir, gÃļrevin tam olarak biteceği anÄą bekler, hiçbir şey yapmadan, gÃļrev sonucunu alabilmek ve çalÄąÅŸmaya devam edebilmek için . + +Bunun yerine, "asenkron" bir sistem olarak, bir kez bittiğinde, bilgisayarÄąn / programÄąn yapmasÄą gerekeni bitirmesi için biraz (birkaç mikrosaniye) sÄąrada bekleyebilir ve ardÄąndan sonuçlarÄą almak için geri gelebilir ve onlarla çalÄąÅŸmaya devam edebilir. + +"Senkron" ("asenkron"un aksine) için genellikle "sÄąralÄą" terimini de kullanÄąrlar, çÃŧnkÃŧ bilgisayar/program, bu adÄąmlar beklemeyi içerse bile, farklÄą bir gÃļreve geçmeden Ãļnce tÃŧm adÄąmlarÄą sÄąrayla izler. + + +### EşzamanlÄąlÄąk (Concurrency) ve Burgerler + + +YukarÄąda aÃ§Äąklanan bu **asenkron** kod fikrine bazen **"eşzamanlÄąlÄąk"** da denir. **"Paralellikten"** farklÄądÄąr. + +**EşzamanlÄąlÄąk** ve **paralellik**, "aynÄą anda az ya da çok olan farklÄą işler" ile ilgilidir. + +Ancak *eşzamanlÄąlÄąk* ve *paralellik* arasÄąndaki ayrÄąntÄąlar oldukça farklÄądÄąr. + + +FarkÄą gÃļrmek için burgerlerle ilgili aşağıdaki hikayeyi hayal edin: + +### EşzamanlÄą Burgerler + + + +AşkÄąnla beraber 😍 dÄąÅŸarÄą hamburger yemeye Ã§ÄąktÄąnÄąz 🍔, kasiyer 💁 Ãļndeki insanlardan sipariş alÄąrken siz sÄąraya girdiniz. + +SÄąra sizde ve sen aşkÄąn 😍 ve kendin için 2 Ã§ÄąlgÄąn hamburger 🍔 sÃļylÃŧyorsun. + +Ödemeyi yaptÄąn 💸. + +Kasiyer 💁 mutfakdaki aÅŸÃ§Äąya đŸ‘¨â€đŸŗ hamburgerleri 🍔 hazÄąrlamasÄą gerektiğini sÃļyler ve aÅŸÃ§Äą bunu bilir (o an Ãļnceki mÃŧşterilerin siparişlerini hazÄąrlÄąyor olsa bile). + +Kasiyer 💁 size bir sÄąra numarasÄą verir. + +Beklerken askÄąnla 😍 bir masaya oturur ve uzun bir sÃŧre konuşursunuz(Burgerleriniz çok Ã§ÄąlgÄąn olduğundan ve hazÄąrlanmasÄą biraz zaman alÄąyor ✨🍔✨). + +Hamburgeri beklerkenki zamanÄą 🍔, aşkÄąnÄąn ne kadar zeki ve tatlÄą olduğuna hayran kalarak harcayabilirsin ✨😍✨. + +AşkÄąnla 😍 konuşurken arada sÄąranÄąn size gelip gelmediğini kontrol ediyorsun. + +Nihayet sÄąra size geldi. Tezgaha gidip hamburgerleri 🍔kapÄąp masaya geri dÃļnÃŧyorsun. + +AşkÄąnla hamburgerlerinizi yiyor 🍔 ve iyi vakit geçiriyorsunuz ✨. + +--- + +Bu hikayedeki bilgisayar / program 🤖 olduğunuzu hayal edin. + +SÄąrada beklerken boştasÄąn 😴, sÄąranÄą beklerken herhangi bir "Ãŧretim" yapmÄąyorsun. Ama bu sÄąra hÄązlÄą çÃŧnkÃŧ kasiyer sadece siparişleri alÄąyor (onlarÄą hazÄąrlamÄąyor), burada bir sÄąknÄątÄą yok. + +Sonra sÄąra size geldiğinde gerçekten "Ãŧretken" işler yapabilirsiniz 🤓, menÃŧyÃŧ oku, ne istediğine larar ver, aşkÄąnÄąn seçimini al 😍, Ãļde 💸, doğru kartÄą Ã§Äąkart, Ãļdemeyi kontrol et, faturayÄą kontrol et, siparişin doğru olup olmadığınÄą kontrol et, vb. + +Ama hamburgerler 🍔 hazÄąr olmamasÄąna rağmen Kasiyer 💁 ile işiniz "duraklÄąyor" ⏸, çÃŧnkÃŧ hamburgerlerin hazÄąr olmasÄąnÄą bekliyoruz 🕙. + +Ama tezgahtan uzaklaÅŸÄąp sÄąranÄąz gelene kadarmasanÄąza dÃļnebilir 🔀 ve dikkatinizi aşkÄąnÄąza 😍 verebilirsiniz vr bunun Ãŧzerine "çalÄąÅŸabilirsiniz" ⏯ 🤓. ArtÄąk "Ãŧretken" birşey yapÄąyorsunuz 🤓, sevgilinle 😍 flÃļrt eder gibi. + +Kasiyer 💁 "Hamburgerler hazÄąr !" 🍔 dediğinde ve gÃļrÃŧntÃŧlenen numara sizin numaranÄąz olduğunda hemen koşup hamburgerlerinizi almaya çalÄąÅŸmÄąyorsunuz. Biliyorsunuzki kimse sizin hamburgerlerinizi 🍔 çalmayacak çÃŧnkÃŧ sÄąra sizin. + +Yani AşkÄąnÄązÄąn😍 hikayeyi bitirmesini bekliyorsunuz (çalÄąÅŸmayÄą bitir ⏯ / gÃļrev işleniyor.. 🤓), nazikçe gÃŧlÃŧmseyin ve hamburger yemeye gittiğinizi sÃļyleyin ⏸. + +ArdÄąndan tezgaha 🔀, şimdi biten ilk gÃļreve ⏯ gidin, Hamburgerleri 🍔 alÄąn, teşekkÃŧr edin ve masaya gÃļtÃŧrÃŧn. sayacÄąn bu adÄąmÄą tamamlanÄąr ⏚. Bu da yeni bir gÃļrev olan "hamburgerleri ye" 🔀 ⏯ gÃļrevini başlatÄąrken "hamburgerleri al" ⏚ gÃļrevini bitirir. + +### Parallel Hamburgerler + +Şimdi bunlarÄąn "EşzamanlÄą Hamburger" değil, "Paralel Hamburger" olduğunu dÃŧşÃŧnelim. + +Hamburger 🍔 almak için 😍 aşkÄąnla Paralel fast food'a gidiyorsun. + +Birden fazla kasiyer varken (varsayalÄąm 8) sÄąraya girdinizđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗ ve sÄąranÄąz gelene kadar bekliyorsunuz. + +Sizden Ãļnceki herkez ayrÄąlmadan Ãļnce hamburgerlerinin 🍔 hazÄąr olmasÄąnÄą bekliyor 🕙. ÇÃŧnkÃŧ kasiyerlerin her biri bir hamburger hazÄąrlanmadan Ãļnce bir sonraki siparişe geçmiiyor. + +Sonunda senin sÄąran, aşkÄąn 😍 ve kendin için 2 hamburger 🍔 siparişi verdiniz. + +Ödemeyi yaptÄąnÄąz 💸. + +Kasiyer mutfağa gider đŸ‘¨â€đŸŗ. + +SÄąrada bekliyorsunuz 🕙, kimse sizin burgerinizi 🍔 almaya çalÄąÅŸmÄąyor çÃŧnkÃŧ sÄąra sizin. + +Sen ve aşkÄąn 😍 sÄąranÄązÄą korumak ve hamburgerleri almakla o kadar meşgulsÃŧnÃŧz ki birbirinize vakit 🕙 ayÄąramÄąyorsunuz 😞. + +İşte bu "senkron" çalÄąÅŸmadÄąr. Kasiyer/aÅŸÃ§Äą đŸ‘¨â€đŸŗile senkron hareket ediyorsunuz. Bu yÃŧzden beklemek 🕙 ve kasiyer/aÅŸÃ§Äą burgeri 🍔bitirip size getirdiğinde orda olmak zorundasÄąnÄąz yoksa başka biri alabilir. + +Sonra kasiyeri/aÅŸÃ§Äą đŸ‘¨â€đŸŗ nihayet hamburgerlerinizle 🍔, uzun bir sÃŧre sonra 🕙 tezgaha geri geliyor. + +Burgerlerinizi 🍔 al ve aşkÄąnla masanÄąza doğru ilerle 😍. + +Sadece burgerini yiyorsun 🍔 ve bitti ⏚. + +Bekleyerek çok fazla zaman geçtiğinden 🕙 konuşmaya çok fazla vakit kalmadÄą 😞. + +--- + +Paralel burger senaryosunda ise, siz iki işlemcili birer robotsunuz 🤖 (sen ve sevgilin 😍), BeklÄąyorsunuz 🕙 hem konuşarak gÃŧzel vakit geçirirken ⏯ hem de sÄąranÄązÄą bekliyorsunuz 🕙. + +Mağazada ise 8 işlemci bulunuyor (Kasiyer/aÅŸÃ§Äą) đŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗ. EşzamanlÄą burgerde yalnÄązca 2 kişi olabiliyordu (bir kasiyer ve bir aÅŸÃ§Äą) 💁 đŸ‘¨â€đŸŗ. + +Ama yine de bu en iyisi değil 😞. + +--- + +Bu hikaye burgerler 🍔 için paralel. + +Bir gerçek hayat Ãļrneği verelim. Bir banka hayal edin. + +BankalarÄąn çoğunda birkaç kasiyer 👨‍đŸ’ŧ👨‍đŸ’ŧ👨‍đŸ’ŧ👨‍đŸ’ŧ ve uzun bir sÄąra var 🕙🕙🕙🕙🕙🕙🕙🕙. + +TÃŧm işi sÄąrayla bir mÃŧşteri ile yapan tÃŧm kasiyerler 👨‍đŸ’ŧ⏯. + +Ve uzun sÃŧre kuyrukta beklemek 🕙 zorundasÄąn yoksa sÄąranÄą kaybedersin. + +Muhtemelen ayak işlerÄą yaparken sevgilini 😍 bankaya đŸĻ getirmezsin. + +### Burger Sonucu + +Bu "aşkÄąnla fast food burgerleri" senaryosunda, çok fazla bekleme olduğu için 🕙, eşzamanlÄą bir sisteme sahip olmak çok daha mantÄąklÄą â¸đŸ”€â¯. + +Web uygulamalarÄąnÄąn çoğu için durum bÃļyledir. + +Pek çok kullanÄącÄą var, ama sunucunuz pek de iyi olmayan bir bağlantÄą ile istek atmalarÄąnÄą bekliyor. + +Ve sonra yanÄątlarÄąn geri gelmesi için tekrar 🕙 bekliyor + +Bu "bekleme" 🕙 mikrosaniye cinsinden ÃļlçÃŧlÃŧr, yine de, hepsini toplarsak çok fazla bekleme var. + +Bu nedenle, web API'leri için asenkron â¸đŸ”€â¯ kod kullanmak çok daha mantÄąklÄą. + +Mevcut popÃŧler Python frameworklerinin çoğu (Flask ve Django gibi), Python'daki yeni asenkron Ãļzellikler mevcut olmadan Ãļnce yazÄąldÄą. Bu nedenle, dağıtÄąlma biçimleri paralel yÃŧrÃŧtmeyi ve yenisi kadar gÃŧçlÃŧ olmayan eski bir eşzamansÄąz yÃŧrÃŧtme biçimini destekler. + +Asenkron web (ASGI) Ãļzelliği, WebSockets için destek eklemek için Django'ya eklenmiş olsa da. + +Asenkron çalÄąÅŸabilme NodeJS in popÃŧler olmasÄąnÄąn sebebi (paralel olamasa bile) ve Go dilini gÃŧçlÃŧ yapan Ãļzelliktir. + +Ve bu **FastAPI** ile elde ettiğiniz performans dÃŧzeyiyle aynÄądÄąr. + +AynÄą anda paralellik ve asenkronluğa sahip olabildiğiniz için, test edilen NodeJS çerçevelerinin çoğundan daha yÃŧksek performans elde edersiniz ve C'ye daha yakÄąn derlenmiş bir dil olan Go ile eşit bir performans elde edersiniz (bÃŧtÃŧn teşekkÃŧrler Starlette'e ). + +### EşzamanlÄąlÄąk paralellikten daha mÄą iyi? + +HayÄąr! Hikayenin ahlakÄą bu değil. + +EşzamanlÄąlÄąk paralellikten farklÄądÄąr. Ve çok fazla bekleme içeren **belirli** senaryolarda daha iyidir. Bu nedenle, genellikle web uygulamalarÄą için paralellikten çok daha iyidir. Ama her şey için değil. + +YanÄą, bunu aklÄąnÄązda oturtmak için aşağıdaki kÄąsa hikayeyi hayal edin: + +> BÃŧyÃŧk, kirli bir evi temizlemelisin. + +*Evet, tÃŧm hikaye bu*. + +--- + +Beklemek yok 🕙. Hiçbir yerde. Sadece evin birden fazla yerinde yapÄąlacak fazlasÄąyla iş var. + +You could have turns as in the burgers example, first the living room, then the kitchen, but as you are not waiting 🕙 for anything, just cleaning and cleaning, the turns wouldn't affect anything. +Hamburger Ãļrneğindeki gibi dÃļnÃŧşleriniz olabilir, Ãļnce oturma odasÄą, sonra mutfak, ama hiçbir şey için 🕙 beklemediğinizden, sadece temizlik, temizlik ve temizlik, dÃļnÃŧşler hiçbir şeyi etkilemez. + +SÄąralÄą veya sÄąrasÄąz (eşzamanlÄąlÄąk) bitirmek aynÄą zaman alÄąr ve aynÄą miktarda işi yaparsÄąnÄąz. + +Ama bu durumda, 8 eski kasiyer/aÅŸÃ§Äą - yeni temizlikçiyi getirebilseydiniz đŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗđŸ‘Šâ€đŸŗđŸ‘¨â€đŸŗ ve her birini (artÄą siz) evin bir bÃļlgesini temizlemek için gÃļrevlendirseydiniz, ekstra yardÄąmla tÃŧm işleri **paralel** olarak yapabilir ve çok daha erken bitirebilirdiniz. + +Bu senaryoda, temizlikçilerin her biri (siz dahil) birer işlemci olacak ve Ãŧzerine dÃŧşeni yapacaktÄąr. + +YÃŧrÃŧtme sÃŧresinin çoğu (beklemek yerine) iş yapÄąldığından ve bilgisayardaki iş bir CPU tarafÄąndan yapÄąldığından, bu sorunlara "CPU bound" diyorlar". + +--- + +CPU'ya bağlÄą işlemlerin yaygÄąn Ãļrnekleri, karmaÅŸÄąk matematik işlemleri gerektiren işlerdir. + +Örneğin: + +* **Ses** veya **gÃļrÃŧntÃŧ işleme**. +* **Bilgisayar gÃļrÃŧsÃŧ**: bir gÃļrÃŧntÃŧ milyonlarca pikselden oluşur, her pikselin 3 değeri / rengi vardÄąr, bu pikseller Ãŧzerinde aynÄą anda bir şeyler hesaplamayÄą gerektiren işleme. +* **Makine Öğrenimi**: Çok sayÄąda "matris" ve "vektÃļr" çarpÄąmÄą gerektirir. SayÄąlarÄą olan ve hepsini aynÄą anda çarpan bÃŧyÃŧk bir elektronik tablo dÃŧşÃŧnÃŧn. +* **Derin Öğrenme**: Bu, Makine Öğreniminin bir alt alanÄądÄąr, dolayÄąsÄąyla aynÄąsÄą geçerlidir. Sadece çarpÄąlacak tek bir sayÄą tablosu değil, bÃŧyÃŧk bir sayÄą kÃŧmesi vardÄąr ve çoğu durumda bu modelleri oluşturmak ve/veya kullanmak için Ãļzel işlemciler kullanÄąrsÄąnÄąz. + +### EşzamanlÄąlÄąk + Paralellik: Web + Makine Öğrenimi + +**FastAPI** ile web geliştirme için çok yaygÄąn olan eşzamanlÄąlÄąktan yararlanabilirsiniz (NodeJS'in aynÄą çekiciliği). + +Ancak, Makine Öğrenimi sistemlerindekile gibi **CPU'ya bağlÄą** iş yÃŧkleri için paralellik ve çoklu işlemenin (birden çok işlemin paralel olarak çalÄąÅŸmasÄą) avantajlarÄąndan da yararlanabilirsiniz. + +Buna ek olarak Python'un **Veri Bilimi**, Makine Öğrenimi ve Ãļzellikle Derin Öğrenme için ana dil olduğu gerçeği, FastAPI'yi Veri Bilimi / Makine Öğrenimi web API'leri ve uygulamalarÄą için çok iyi bir seçenek haline getirir. + +Production'da nasÄąl oldugunu gÃļrmek için şu bÃļlÃŧme bakÄąn [Deployment](deployment/index.md){.internal-link target=_blank}. + +## `async` ve `await` + +Python'un modern sÃŧrÃŧmleri, asenkron kodu tanÄąmlamanÄąn çok sezgisel bir yoluna sahiptir. Bu, normal "sequentÄąal" (sÄąralÄą) kod gibi gÃļrÃŧnmesini ve doğru anlarda sizin için "awaÄąt" ile bekleme yapmasÄąnÄą sağlar. + +SonuçlarÄą vermeden Ãļnce beklemeyi gerektirecek ve yeni Python Ãļzelliklerini destekleyen bir işlem olduğunda aşağıdaki gibi kodlayabilirsiniz: + +```Python +burgers = await get_burgers(2) +``` + +Buradaki `await` anahtari Python'a, sonuçlarÄą `burgers` degiskenine atamadan Ãļnce `get_burgers(2)` kodunun işini bitirmesini 🕙 beklemesi gerektiğini sÃļyler. Bununla Python, bu ara zamanda başka bir şey 🔀 ⏯ yapabileceğini bilecektir (başka bir istek almak gibi). + + `await`kodunun çalÄąÅŸmasÄą için, eşzamansÄązlığı destekleyen bir fonksiyonun içinde olmasÄą gerekir. Bunu da yapmak için fonksiyonu `async def` ile tanÄąmlamamÄąz yeterlidir: + +```Python hl_lines="1" +async def get_burgers(number: int): + # burgerleri oluşturmak için asenkron birkaç iş + return burgers +``` + +...`def` yerine: + +```Python hl_lines="2" +# bu kod asenkron değil +def get_sequential_burgers(number: int): + # burgerleri oluşturmak için senkron bÄąrkaç iş + return burgers +``` + +`async def` ile Python, bu fonksÄąyonun içinde, `await` ifadelerinin farkÄąnda olmasÄą gerektiğini ve çalÄąÅŸma zamanÄą gelmeden Ãļnce bu işlevin yÃŧrÃŧtÃŧlmesini "duraklatabileceğini" ve başka bir şey yapabileceğini 🔀 bilir. + +`async def` fonksiyonunu çağırmak istediğinizde, onu "awaÄąt" Äąle kullanmanÄąz gerekir. Yani, bu işe yaramaz: + +```Python +# Bu işe yaramaz, çÃŧnkÃŧ get_burgers, şu şekilde tanÄąmlandÄą: async def +burgers = get_burgers(2) +``` + +--- + +Bu nedenle, size onu `await` ile çağırabileceğinizi sÃļyleyen bir kitaplÄąk kullanÄąyorsanÄąz, onu `async def` ile tanÄąmlanan *path fonksiyonu* içerisinde kullanmanÄąz gerekir, Ãļrneğin: + +```Python hl_lines="2-3" +@app.get('/burgers') +async def read_burgers(): + burgers = await get_burgers(2) + return burgers +``` + +### Daha fazla teknik detay + +`await` in yalnÄązca `async def` ile tanÄąmlanan fonksÄąyonlarÄąn içinde kullanÄąlabileceğini fark etmişsinizdir. + +Ama aynÄą zamanda, `async def` ile tanÄąmlanan fonksiyonlarÄąn "await" ile beklenmesi gerekir. Bu nedenle, "`async def` içeren fonksiyonlar yalnÄązca "`async def` ile tanÄąmlanan fonksiyonlarÄąn içinde çağrÄąlabilir. + + +Yani yumurta mÄą tavukdan, tavuk mu yumurtadan gibi ilk `async` fonksiyonu nasÄąl çağırÄąlÄąr? + +**FastAPI** ile çalÄąÅŸÄąyorsanÄąz bunun için endişelenmenize gerek yok, çÃŧnkÃŧ bu "ilk" fonksiyon sizin *path fonksiyonunuz* olacak ve FastAPI doğru olanÄą nasÄąl yapacağınÄą bilecek. + +Ancak FastAPI olmadan `async` / `await` kullanmak istiyorsanÄąz, resmi Python belgelerini kontrol edin. + +### Asenkron kodun diğer biçimleri + +Bu `async` ve `await` kullanimi oldukça yenidir. + +Ancak asenkron kodla çalÄąÅŸmayÄą çok daha kolay hale getirir. + +AynÄą sÃļzdizimi (hemen hemen aynÄą) son zamanlarda JavaScript'in modern sÃŧrÃŧmlerine de dahil edildi (TarayÄącÄą ve NodeJS'de). + +Ancak bundan Ãļnce, asenkron kodu işlemek oldukça karmaÅŸÄąk ve zordu. + +Python'un Ãļnceki sÃŧrÃŧmlerinde, threadlerÄą veya Gevent kullanÄąyor olabilirdin. Ancak kodu anlamak, hata ayÄąklamak ve dÃŧşÃŧnmek çok daha karmaÅŸÄąk olurdu. + +NodeJS / Browser JavaScript'in Ãļnceki sÃŧrÃŧmlerinde, "callback" kullanÄąrdÄąnÄąz. Bu da callbacks cehennemine yol açar. + +## Coroutine'ler + +**Coroutine**, bir `async def` fonksiyonu tarafÄąndan dÃļndÃŧrÃŧlen değer için çok sÃŧslÃŧ bir terimdir. Python bunun bir fonksiyon gibi bir noktada başlayÄąp biteceğini bilir, ancak içinde bir `await` olduğunda dahili olarak da duraklatÄąlabilir ⏸. + +Ancak, `async` ve `await` ile asenkron kod kullanmanÄąn tÃŧm bu işlevselliği, çoğu zaman "Coroutine" kullanmak olarak adlandÄąrÄąlÄąr. Go'nun ana Ãļzelliği olan "Goroutines" ile karÅŸÄąlaştÄąrÄąlabilir. + +## Sonuç + +AynÄą ifadeyi yukarÄądan gÃļrelim: + +> Python'Äąn modern sÃŧrÃŧmleri, **"async" ve "await"** sÃļzdizimi ile birlikte **"coroutines"** adlÄą bir Ãļzelliği kullanan **"asenkron kod"** desteğine sahiptir. + +Şimdi daha mantÄąklÄą gelmeli. ✨ + +FastAPI'ye (Starlette aracÄąlığıyla) gÃŧç veren ve bu kadar etkileyici bir performansa sahip olmasÄąnÄą sağlayan şey budur. + +## Çok Teknik Detaylar + +!!! warning + Muhtemelen burayÄą atlayabilirsiniz. + + Bunlar, **FastAPI**'nin altta nasÄąl çalÄąÅŸtığına dair çok teknik ayrÄąntÄąlardÄąr. + + Biraz teknik bilginiz varsa (co-routines, threads, blocking, vb)ve FastAPI'nin "async def" ile normal "def" arasÄąndaki farkÄą nasÄąl işlediğini merak ediyorsanÄąz, devam edin. + +### Path fonksiyonu + +"async def" yerine normal "def" ile bir *yol işlem işlevi* bildirdiğinizde, doğrudan çağrÄąlmak yerine (sunucuyu bloke edeceğinden) daha sonra beklenen harici bir iş parçacığı havuzunda çalÄąÅŸtÄąrÄąlÄąr. + +YukarÄąda aÃ§Äąklanan şekilde çalÄąÅŸmayan başka bir asenkron framework'den geliyorsanÄąz ve kÃŧçÃŧk bir performans kazancÄą (yaklaÅŸÄąk 100 nanosaniye) için "def" ile *path fonksiyonu* tanÄąmlamaya alÄąÅŸkÄąnsanÄąz, **FastAPI**'de tam tersi olacağınÄą unutmayÄąn. Bu durumlarda, *path fonksiyonu* G/Ç engelleyen durum oluşturmadÄąkça "async def" kullanmak daha iyidir. + +Yine de, her iki durumda da, **FastAPI**'nin Ãļnceki frameworkden [hala daha hÄązlÄą](/#performance){.internal-link target=_blank} (veya en azÄąndan karÅŸÄąlaştÄąrÄąlabilir) olma olasÄąlığı vardÄąr. + +### BagÄąmlÄąlÄąklar + +AynÄąsÄą bağımlÄąlÄąklar için de geçerlidir. Bir bağımlÄąlÄąk, "async def" yerine standart bir "def" işleviyse, harici iş parçacığı havuzunda çalÄąÅŸtÄąrÄąlÄąr. + +### Alt-bağımlÄąklar + +Birbirini gerektiren (fonksiyonlarin parametreleri olarak) birden fazla bağımlÄąlÄąk ve alt bağımlÄąlÄąklarÄąnÄąz olabilir, bazÄąlarÄą 'async def' ve bazÄąlarÄą normal 'def' ile oluşturulabilir. Yine de normal 'def' ile oluşturulanlar, "await" kulanilmadan harici bir iş parçacığında (iş parçacığı havuzundan) çağrÄąlÄąr. + +### Diğer yardÄąmcÄą fonksiyonlar + +Doğrudan çağırdığınÄąz diğer herhangi bir yardÄąmcÄą fonksiyonu, normal "def" veya "async def" ile tanimlayabilirsiniz. FastAPI onu çağırma şeklinizi etkilemez. + +Bu, FastAPI'nin sizin için çağırdığı fonksiyonlarin tam tersidir: *path fonksiyonu* ve bağımlÄąlÄąklar. + +YardÄąmcÄą program fonksiyonunuz 'def' ile normal bir işlevse, bir iş parçacığı havuzunda değil doğrudan (kodunuzda yazdığınÄąz gibi) çağrÄąlÄąr, işlev 'async def' ile oluşturulmuşsa çağırÄąldığı yerde 'await' ile beklemelisiniz. + +--- + +Yeniden, bunlar, onlarÄą aramaya geldiğinizde muhtemelen işinize yarayacak çok teknik ayrÄąntÄąlardÄąr. + +Aksi takdirde, yukarÄądaki bÃļlÃŧmdeki yÃļnergeleri iyi bilmelisiniz: Aceleniz mi var?. From 29c8b19af878c0f4b215da4a719969040fe7b5bc Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 19:58:14 +0000 Subject: [PATCH 159/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 37936f5ada..10e0c24b15 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/deployment/docker.md`. PR [#5657](https://github.com/tiangolo/fastapi/pull/5657) by [@nearnear](https://github.com/nearnear). * 🌐 Add Korean translation for `docs/ko/docs/deployment/server-workers.md`. PR [#4935](https://github.com/tiangolo/fastapi/pull/4935) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/deployment/index.md`. PR [#4561](https://github.com/tiangolo/fastapi/pull/4561) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/path-operation-configuration.md`. PR [#3639](https://github.com/tiangolo/fastapi/pull/3639) by [@jungsu-kwon](https://github.com/jungsu-kwon). From 1ac6b761e12c0cf40dc012396be5bbe12f47b8e3 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 23 Jan 2024 05:01:49 +0900 Subject: [PATCH 160/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/extra-data-types.md`=20(#19?= =?UTF-8?q?32)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ja/docs/tutorial/extra-data-types.md | 66 +++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 docs/ja/docs/tutorial/extra-data-types.md diff --git a/docs/ja/docs/tutorial/extra-data-types.md b/docs/ja/docs/tutorial/extra-data-types.md new file mode 100644 index 0000000000..a152e03226 --- /dev/null +++ b/docs/ja/docs/tutorial/extra-data-types.md @@ -0,0 +1,66 @@ +# čŋŊ加デãƒŧã‚ŋ型 + +äģŠãžã§ã¯ã€äģĨ下ぎようãĒ一čˆŦįš„ãĒデãƒŧã‚ŋ型をäŊŋį”¨ã—ãĻきぞした: + +* `int` +* `float` +* `str` +* `bool` + +ã—ã‹ã—ã€ã‚ˆã‚Šč¤‡é›‘ãĒデãƒŧã‚ŋ型をäŊŋį”¨ã™ã‚‹ã“ã¨ã‚‚ã§ããžã™ã€‚ + +そしãĻ、äģŠãžã§čĻ‹ãĻきたぎと同じ抟čƒŊを持つことãĢãĒりぞす: + +* į´ æ™´ã‚‰ã—ã„ã‚¨ãƒ‡ã‚Ŗã‚ŋぎã‚ĩポãƒŧト +* 受äŋĄã—たãƒĒクエ゚トからぎデãƒŧã‚ŋ変換 +* ãƒŦã‚šãƒãƒŗã‚šãƒ‡ãƒŧã‚ŋぎデãƒŧã‚ŋ変換 +* デãƒŧã‚ŋぎ検č¨ŧ +* č‡Ēå‹•æŗ¨é‡ˆã¨æ–‡æ›¸åŒ– + +## äģ–ぎデãƒŧã‚ŋ型 + +ここでは、äŊŋį”¨ã§ãã‚‹čŋŊ加ぎデãƒŧã‚ŋåž‹ãŽã„ãã¤ã‹ã‚’į´šäģ‹ã—ぞす: + +* `UUID`: + * 多くぎデãƒŧã‚ŋベãƒŧã‚šã‚„ã‚ˇã‚šãƒ†ãƒ ã§å…ąé€šãŽIDとしãĻäŊŋį”¨ã•ã‚Œã‚‹ã€æ¨™æē–įš„ãĒ「ãƒĻニバãƒŧã‚ĩãƒĢãĢãƒĻニãƒŧクãĒ識åˆĨ子」です。 + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã§ã¯`str`としãĻčĄ¨įžã•ã‚Œãžã™ã€‚ +* `datetime.datetime`: + * Pythonぎ`datetime.datetime`です。 + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã¯ISO 8601åŊĸåŧãŽ`str`ã§čĄ¨įžã•ã‚Œãžã™: `2008-09-15T15:53:00+05:00` +* `datetime.date`: + * Pythonぎ`datetime.date`です。 + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã¯ISO 8601åŊĸåŧãŽ`str`ã§čĄ¨įžã•ã‚Œãžã™: `2008-09-15` +* `datetime.time`: + * Pythonぎ`datetime.time`. + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã¯ISO 8601åŊĸåŧãŽ`str`ã§čĄ¨įžã•ã‚Œãžã™: `14:23:55.003` +* `datetime.timedelta`: + * Pythonぎ`datetime.timedelta`です。 + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã§ã¯åˆč¨ˆį§’æ•°ãŽ`float`ã§čĄ¨įžã•ã‚Œãžã™ã€‚ + * Pydanticでは「ISO 8601 time diff encoding」としãĻčĄ¨įžã™ã‚‹ã“ã¨ã‚‚å¯čƒŊã§ã™ã€‚čŠŗį´°ã¯ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‚’å‚į…§ã—ãĻください。 +* `frozenset`: + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã§ã¯`set`と同じようãĢæ‰ąã‚ã‚Œãžã™: + * ãƒĒクエ゚トでは、ãƒĒ゚トがčĒ­ãŋčžŧãžã‚Œã€é‡č¤‡ã‚’æŽ’é™¤ã—ãĻ`set`ãĢ変換されぞす。 + * ãƒŦã‚šãƒãƒŗã‚šã§ã¯`set`が`list`ãĢ変換されぞす。 + * į”Ÿæˆã•ã‚ŒãŸã‚šã‚­ãƒŧマは`set`ぎ値が一意であることを指厚しぞすīŧˆJSON Schemaぎ`uniqueItems`をäŊŋį”¨ã—ãžã™īŧ‰ã€‚ +* `bytes`: + * Pythonぎ標æē–įš„ãĒ`bytes`です。 + * ãƒĒクエ゚トとãƒŦã‚šãƒãƒŗã‚šã§ã¯`str`としãĻæ‰ąã‚ã‚Œãžã™ã€‚ + * į”Ÿæˆã•ã‚ŒãŸã‚šã‚­ãƒŧマは`str`で`binary`ぎ「フりãƒŧマット」持つことを指厚しぞす。 +* `Decimal`: + * Pythonぎ標æē–įš„ãĒ`Decimal`です。 + * ãƒĒクエ゚トやãƒŦã‚šãƒãƒŗã‚šã§ã¯`float`と同じようãĢæ‰ąã„ãžã™ã€‚ + +* Pydanticぎ全ãĻぎ有劚ãĒåž‹ã¯ã“ãĄã‚‰ã§įĸēčĒã§ããžã™: Pydantic data types。 +## 例 + +ã“ã“ã§ã¯ã€ä¸Šč¨˜ãŽåž‹ãŽã„ãã¤ã‹ã‚’äŊŋį”¨ã—ãŸãƒ‘ãƒŠãƒĄãƒŧã‚ŋを持つ*path operation*ぎ䞋をį¤ēしぞす。 + +```Python hl_lines="1 2 12-16" +{!../../../docs_src/extra_data_types/tutorial001.py!} +``` + +é–ĸæ•°å†…ãŽãƒ‘ãƒŠãƒĄãƒŧã‚ŋはč‡Ēį„ļãĒデãƒŧã‚ŋåž‹ã‚’æŒãŖãĻいることãĢæŗ¨æ„ã—ãĻください。そしãĻ、äģĨ下ぎようãĢ通常ぎæ—Ĩä옿“äŊœã‚’čĄŒã†ã“ã¨ãŒã§ããžã™: + +```Python hl_lines="18 19" +{!../../../docs_src/extra_data_types/tutorial001.py!} +``` From 7514aab30bd8355aec58a77ab18c6b22a26a00ec Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 20:02:56 +0000 Subject: [PATCH 161/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 10e0c24b15..17202d8bff 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/project-generation.md`. PR [#5192](https://github.com/tiangolo/fastapi/pull/5192) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Korean translation for `docs/ko/docs/deployment/docker.md`. PR [#5657](https://github.com/tiangolo/fastapi/pull/5657) by [@nearnear](https://github.com/nearnear). * 🌐 Add Korean translation for `docs/ko/docs/deployment/server-workers.md`. PR [#4935](https://github.com/tiangolo/fastapi/pull/4935) by [@jujumilk3](https://github.com/jujumilk3). * 🌐 Add Korean translation for `docs/ko/docs/deployment/index.md`. PR [#4561](https://github.com/tiangolo/fastapi/pull/4561) by [@jujumilk3](https://github.com/jujumilk3). From f772868a569651020d72f64fa2e66c3f4b3535f7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 20:06:11 +0000 Subject: [PATCH 162/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 17202d8bff..f915e3d26e 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/async.md`. PR [#5191](https://github.com/tiangolo/fastapi/pull/5191) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Turkish translation for `docs/tr/docs/project-generation.md`. PR [#5192](https://github.com/tiangolo/fastapi/pull/5192) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Korean translation for `docs/ko/docs/deployment/docker.md`. PR [#5657](https://github.com/tiangolo/fastapi/pull/5657) by [@nearnear](https://github.com/nearnear). * 🌐 Add Korean translation for `docs/ko/docs/deployment/server-workers.md`. PR [#4935](https://github.com/tiangolo/fastapi/pull/4935) by [@jujumilk3](https://github.com/jujumilk3). From 851daec7542bc5e565579bd2d491310d2d6b7445 Mon Sep 17 00:00:00 2001 From: SwftAlpc Date: Tue, 23 Jan 2024 05:09:02 +0900 Subject: [PATCH 163/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/encoder.md`=20(#1955)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ja/docs/tutorial/encoder.md | 34 ++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/ja/docs/tutorial/encoder.md diff --git a/docs/ja/docs/tutorial/encoder.md b/docs/ja/docs/tutorial/encoder.md new file mode 100644 index 0000000000..305867ab7b --- /dev/null +++ b/docs/ja/docs/tutorial/encoder.md @@ -0,0 +1,34 @@ +# JSONäē’æ›ã‚¨ãƒŗã‚ŗãƒŧダ + +デãƒŧã‚ŋ型īŧˆPydanticãƒĸデãƒĢぎようãĒīŧ‰ã‚’JSONとäē’æ›æ€§ãŽã‚るもぎīŧˆ`dict`や`list`ãĒおīŧ‰ãĢ変更するåŋ…čĻãŒã‚ã‚‹å ´åˆãŒã‚ã‚Šãžã™ã€‚ + +䞋えば、デãƒŧã‚ŋベãƒŧ゚ãĢäŋå­˜ã™ã‚‹åŋ…čĻãŒã‚ã‚‹å ´åˆã§ã™ã€‚ + +そぎためãĢ、**FastAPI** は`jsonable_encoder()`é–ĸ数を提䞛しãĻいぞす。 + +## `jsonable_encoder`ぎäŊŋᔍ + +JSONäē’æ›ãŽãƒ‡ãƒŧã‚ŋぎãŋを受äŋĄã™ã‚‹ãƒ‡ãƒŧã‚ŋベãƒŧ゚`fase_db`があるとしぞしょう。 + +䞋えば、`datetime`ã‚ĒブジェクトはJSONとäē’æ›æ€§ãŒãĒいぎで、こぎデãƒŧã‚ŋãƒŧベãƒŧ゚ãĢは受け取られぞせん。 + +そぎため、`datetime`ã‚ĒブジェクトはISOåŊĸåŧãŽãƒ‡ãƒŧã‚ŋをåĢむ`str`ãĢ変換されãĒければãĒりぞせん。 + +同様ãĢ、こぎデãƒŧã‚ŋベãƒŧ゚はPydanticãƒĸデãƒĢīŧˆåąžæ€§ã‚’持つã‚Ēブジェクトīŧ‰ã‚’受け取らず、`dict`だけを受け取りぞす。 + +そぎためãĢ`jsonable_encoder`をäŊŋį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ + +PydanticãƒĸデãƒĢぎようãĒã‚Ēブジェクトを受け取り、JSONäē’æ›į‰ˆã‚’čŋ”しぞす: + +```Python hl_lines="5 22" +{!../../../docs_src/encoder/tutorial001.py!} +``` + +こぎ䞋では、PydanticãƒĸデãƒĢを`dict`ãĢ、`datetime`を`str`ãĢ変換しぞす。 + +å‘ŧãŗå‡ēしたįĩæžœã¯ã€Pythonぎ標æē–ぎ`json.dumps()`ã§ã‚¨ãƒŗã‚ŗãƒŧドできるもぎです。 + +これはJSONåŊĸåŧãŽãƒ‡ãƒŧã‚ŋをåĢむ大きãĒ`str`をīŧˆæ–‡å­—列としãĻīŧ‰čŋ”しぞせん。JSONとäē’æ›æ€§ãŽã‚る値とã‚ĩブぎ値を持つPython標æē–ぎデãƒŧã‚ŋ構造īŧˆäž‹īŧš`dict`īŧ‰ã‚’čŋ”しぞす。 + +!!! note "å‚™č€ƒ" + `jsonable_encoder`は原際ãĢは **FastAPI** ãŒå†…éƒ¨įš„ãĢデãƒŧã‚ŋを変換するためãĢäŊŋį”¨ã—ãžã™ã€‚ã—ã‹ã—ã“ã‚Œã¯äģ–ãŽå¤šããŽã‚ˇãƒŠãƒĒã‚Ēã§æœ‰į”¨ã§ã™ã€‚ From c945d686bbd1c56e4e5c0ef876fe3c45e8d5bb2d Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 20:12:06 +0000 Subject: [PATCH 164/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index f915e3d26e..601d83856a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-data-types.md`. PR [#1932](https://github.com/tiangolo/fastapi/pull/1932) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Turkish translation for `docs/tr/docs/async.md`. PR [#5191](https://github.com/tiangolo/fastapi/pull/5191) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Turkish translation for `docs/tr/docs/project-generation.md`. PR [#5192](https://github.com/tiangolo/fastapi/pull/5192) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Korean translation for `docs/ko/docs/deployment/docker.md`. PR [#5657](https://github.com/tiangolo/fastapi/pull/5657) by [@nearnear](https://github.com/nearnear). From d7c588d6930e0985253aafa396091beb76340fbd Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 22 Jan 2024 20:18:27 +0000 Subject: [PATCH 165/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 601d83856a..49c1cab095 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/encoder.md`. PR [#1955](https://github.com/tiangolo/fastapi/pull/1955) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-data-types.md`. PR [#1932](https://github.com/tiangolo/fastapi/pull/1932) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Turkish translation for `docs/tr/docs/async.md`. PR [#5191](https://github.com/tiangolo/fastapi/pull/5191) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). * 🌐 Add Turkish translation for `docs/tr/docs/project-generation.md`. PR [#5192](https://github.com/tiangolo/fastapi/pull/5192) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). From 9a33950344c96445063e8e2b33993cea3b0d55d8 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 12:22:17 +0100 Subject: [PATCH 166/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20introduction=20documents=20(#10497)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/about/index.md | 3 +++ docs/de/docs/help/index.md | 3 +++ docs/de/docs/learn/index.md | 5 +++++ docs/de/docs/reference/index.md | 8 ++++++++ docs/de/docs/resources/index.md | 3 +++ 5 files changed, 22 insertions(+) create mode 100644 docs/de/docs/about/index.md create mode 100644 docs/de/docs/help/index.md create mode 100644 docs/de/docs/learn/index.md create mode 100644 docs/de/docs/reference/index.md create mode 100644 docs/de/docs/resources/index.md diff --git a/docs/de/docs/about/index.md b/docs/de/docs/about/index.md new file mode 100644 index 0000000000..4c309e02a5 --- /dev/null +++ b/docs/de/docs/about/index.md @@ -0,0 +1,3 @@ +# Über + +Über FastAPI, sein Design, seine Inspiration und mehr. 🤓 diff --git a/docs/de/docs/help/index.md b/docs/de/docs/help/index.md new file mode 100644 index 0000000000..8fdc4a0497 --- /dev/null +++ b/docs/de/docs/help/index.md @@ -0,0 +1,3 @@ +# Hilfe + +Helfen und Hilfe erhalten, beitragen, mitmachen. 🤝 diff --git a/docs/de/docs/learn/index.md b/docs/de/docs/learn/index.md new file mode 100644 index 0000000000..b5582f55b6 --- /dev/null +++ b/docs/de/docs/learn/index.md @@ -0,0 +1,5 @@ +# Lernen + +Hier finden Sie die einfÃŧhrenden Kapitel und Tutorials zum Erlernen von **FastAPI**. + +Sie kÃļnnten dies als **Buch**, als **Kurs**, als **offizielle** und empfohlene Methode zum Erlernen von FastAPI betrachten. 😎 diff --git a/docs/de/docs/reference/index.md b/docs/de/docs/reference/index.md new file mode 100644 index 0000000000..e9362b962a --- /dev/null +++ b/docs/de/docs/reference/index.md @@ -0,0 +1,8 @@ +# Referenz – Code-API + +Hier ist die Referenz oder Code-API, die Klassen, Funktionen, Parameter, Attribute und alle FastAPI-Teile, die Sie in Ihren Anwendungen verwenden kÃļnnen. + +Wenn Sie **FastAPI** lernen mÃļchten, ist es viel besser, das [FastAPI-Tutorial](https://fastapi.tiangolo.com/tutorial/) zu lesen. + +!!! note "Hinweis Deutsche Übersetzung" + Die nachfolgende API wird aus der Quelltext-Dokumentation erstellt, daher sind nur die Einleitungen auf Deutsch. diff --git a/docs/de/docs/resources/index.md b/docs/de/docs/resources/index.md new file mode 100644 index 0000000000..abf270d9fd --- /dev/null +++ b/docs/de/docs/resources/index.md @@ -0,0 +1,3 @@ +# Ressourcen + +Zusätzliche Ressourcen, externe Links, Artikel und mehr. âœˆī¸ From d2d5a5290ccd0598fdefabe74c28904406d8132f Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 11:22:48 +0000 Subject: [PATCH 167/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 49c1cab095..7bbee3c446 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for introduction documents. PR [#10497](https://github.com/tiangolo/fastapi/pull/10497) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/encoder.md`. PR [#1955](https://github.com/tiangolo/fastapi/pull/1955) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-data-types.md`. PR [#1932](https://github.com/tiangolo/fastapi/pull/1932) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Turkish translation for `docs/tr/docs/async.md`. PR [#5191](https://github.com/tiangolo/fastapi/pull/5191) by [@BilalAlpaslan](https://github.com/BilalAlpaslan). From 2f6fdf62b95befaa854eb4637ed8e928514ebaa1 Mon Sep 17 00:00:00 2001 From: Johannes Jungbluth Date: Tue, 23 Jan 2024 12:26:59 +0100 Subject: [PATCH 168/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/middleware.md`=20(#10391)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/middleware.md | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/de/docs/tutorial/middleware.md diff --git a/docs/de/docs/tutorial/middleware.md b/docs/de/docs/tutorial/middleware.md new file mode 100644 index 0000000000..7d6e6b71a3 --- /dev/null +++ b/docs/de/docs/tutorial/middleware.md @@ -0,0 +1,61 @@ +# Middleware + +Sie kÃļnnen Middleware zu **FastAPI**-Anwendungen hinzufÃŧgen. + +Eine „Middleware“ ist eine Funktion, die mit jedem **Request** arbeitet, bevor er von einer bestimmten *Pfadoperation* verarbeitet wird. Und auch mit jeder **Response**, bevor sie zurÃŧckgegeben wird. + +* Sie nimmt jeden **Request** entgegen, der an Ihre Anwendung gesendet wird. +* Sie kann dann etwas mit diesem **Request** tun oder beliebigen Code ausfÃŧhren. +* Dann gibt sie den **Request** zur Verarbeitung durch den Rest der Anwendung weiter (durch eine bestimmte *Pfadoperation*). +* Sie nimmt dann die **Response** entgegen, die von der Anwendung generiert wurde (durch eine bestimmte *Pfadoperation*). +* Sie kann etwas mit dieser **Response** tun oder beliebigen Code ausfÃŧhren. +* Dann gibt sie die **Response** zurÃŧck. + +!!! note "Technische Details" + Wenn Sie Abhängigkeiten mit `yield` haben, wird der Exit-Code *nach* der Middleware ausgefÃŧhrt. + + Wenn es Hintergrundaufgaben gab (später dokumentiert), werden sie *nach* allen Middlewares ausgefÃŧhrt. + +## Erstellung einer Middleware + +Um eine Middleware zu erstellen, verwenden Sie den Dekorator `@app.middleware("http")` Ãŧber einer Funktion. + +Die Middleware-Funktion erhält: + +* Den `request`. +* Eine Funktion `call_next`, die den `request` als Parameter erhält. + * Diese Funktion gibt den `request` an die entsprechende *Pfadoperation* weiter. + * Dann gibt es die von der entsprechenden *Pfadoperation* generierte `response` zurÃŧck. +* Sie kÃļnnen die `response` dann weiter modifizieren, bevor Sie sie zurÃŧckgeben. + +```Python hl_lines="8-9 11 14" +{!../../../docs_src/middleware/tutorial001.py!} +``` + +!!! tip "Tipp" + Beachten Sie, dass benutzerdefinierte proprietäre Header hinzugefÃŧgt werden kÃļnnen. Verwenden Sie dafÃŧr das Präfix 'X-'. + + Wenn Sie jedoch benutzerdefinierte Header haben, die ein Client in einem Browser sehen soll, mÃŧssen Sie sie zu Ihrer CORS-Konfigurationen ([CORS (Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank}) hinzufÃŧgen, indem Sie den Parameter `expose_headers` verwenden, der in der Starlette-CORS-Dokumentation dokumentiert ist. + +!!! note "Technische Details" + Sie kÃļnnten auch `from starlette.requests import Request` verwenden. + + **FastAPI** bietet es als Komfort fÃŧr Sie, den Entwickler, an. Aber es stammt direkt von Starlette. + +### Vor und nach der `response` + +Sie kÃļnnen Code hinzufÃŧgen, der mit dem `request` ausgefÃŧhrt wird, bevor dieser von einer beliebigen *Pfadoperation* empfangen wird. + +Und auch nachdem die `response` generiert wurde, bevor sie zurÃŧckgegeben wird. + +Sie kÃļnnten beispielsweise einen benutzerdefinierten Header `X-Process-Time` hinzufÃŧgen, der die Zeit in Sekunden enthält, die benÃļtigt wurde, um den Request zu verarbeiten und eine Response zu generieren: + +```Python hl_lines="10 12-13" +{!../../../docs_src/middleware/tutorial001.py!} +``` + +## Andere Middlewares + +Sie kÃļnnen später mehr Ãŧber andere Middlewares in [Handbuch fÃŧr fortgeschrittene Benutzer: Fortgeschrittene Middleware](../advanced/middleware.md){.internal-link target=_blank} lesen. + +In der nächsten Sektion erfahren Sie, wie Sie CORS mit einer Middleware behandeln kÃļnnen. From cedea4d7b5b62c8985ca806816a188a9451d1225 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 11:27:20 +0000 Subject: [PATCH 169/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7bbee3c446..69954afc1f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/middleware.md`. PR [#10391](https://github.com/tiangolo/fastapi/pull/10391) by [@JohannesJungbluth](https://github.com/JohannesJungbluth). * 🌐 Add German translation for introduction documents. PR [#10497](https://github.com/tiangolo/fastapi/pull/10497) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/encoder.md`. PR [#1955](https://github.com/tiangolo/fastapi/pull/1955) by [@SwftAlpc](https://github.com/SwftAlpc). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/extra-data-types.md`. PR [#1932](https://github.com/tiangolo/fastapi/pull/1932) by [@SwftAlpc](https://github.com/SwftAlpc). From 690edc03853e1982eaa92e67976591c7625f4aa3 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 14:04:57 +0100 Subject: [PATCH 170/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/advanced/additional-status-codes.md`?= =?UTF-8?q?=20(#10617)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../docs/advanced/additional-status-codes.md | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 docs/de/docs/advanced/additional-status-codes.md diff --git a/docs/de/docs/advanced/additional-status-codes.md b/docs/de/docs/advanced/additional-status-codes.md new file mode 100644 index 0000000000..e9de267cf9 --- /dev/null +++ b/docs/de/docs/advanced/additional-status-codes.md @@ -0,0 +1,69 @@ +# Zusätzliche Statuscodes + +Standardmäßig liefert **FastAPI** die RÃŧckgabewerte (Responses) als `JSONResponse` zurÃŧck und fÃŧgt den Inhalt der jeweiligen *Pfadoperation* in das `JSONResponse` Objekt ein. + +Es wird der Default-Statuscode oder derjenige verwendet, den Sie in Ihrer *Pfadoperation* festgelegt haben. + +## Zusätzliche Statuscodes + +Wenn Sie neben dem Hauptstatuscode weitere Statuscodes zurÃŧckgeben mÃļchten, kÃļnnen Sie dies tun, indem Sie direkt eine `Response` zurÃŧckgeben, wie etwa eine `JSONResponse`, und den zusätzlichen Statuscode direkt festlegen. + +Angenommen, Sie mÃļchten eine *Pfadoperation* haben, die das Aktualisieren von Artikeln ermÃļglicht und bei Erfolg den HTTP-Statuscode 200 „OK“ zurÃŧckgibt. + +Sie mÃļchten aber auch, dass sie neue Artikel akzeptiert. Und wenn die Elemente vorher nicht vorhanden waren, werden diese Elemente erstellt und der HTTP-Statuscode 201 „Created“ zurÃŧckgegeben. + +Um dies zu erreichen, importieren Sie `JSONResponse`, und geben Sie Ihren Inhalt direkt zurÃŧck, indem Sie den gewÃŧnschten `status_code` setzen: + +=== "Python 3.10+" + + ```Python hl_lines="4 25" + {!> ../../../docs_src/additional_status_codes/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="4 25" + {!> ../../../docs_src/additional_status_codes/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="4 26" + {!> ../../../docs_src/additional_status_codes/tutorial001_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="2 23" + {!> ../../../docs_src/additional_status_codes/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="4 25" + {!> ../../../docs_src/additional_status_codes/tutorial001.py!} + ``` + +!!! warning "Achtung" + Wenn Sie eine `Response` direkt zurÃŧckgeben, wie im obigen Beispiel, wird sie direkt zurÃŧckgegeben. + + Sie wird nicht mit einem Modell usw. serialisiert. + + Stellen Sie sicher, dass sie die gewÃŧnschten Daten enthält und dass die Werte gÃŧltiges JSON sind (wenn Sie `JSONResponse` verwenden). + +!!! note "Technische Details" + Sie kÃļnnen auch `from starlette.responses import JSONResponse` verwenden. + + **FastAPI** bietet dieselben `starlette.responses` auch via `fastapi.responses` an, als Annehmlichkeit fÃŧr Sie, den Entwickler. Die meisten verfÃŧgbaren Responses kommen aber direkt von Starlette. Das Gleiche gilt fÃŧr `status`. + +## OpenAPI- und API-Dokumentation + +Wenn Sie zusätzliche Statuscodes und Responses direkt zurÃŧckgeben, werden diese nicht in das OpenAPI-Schema (die API-Dokumentation) aufgenommen, da FastAPI keine MÃļglichkeit hat, im Voraus zu wissen, was Sie zurÃŧckgeben werden. + +Sie kÃļnnen das jedoch in Ihrem Code dokumentieren, indem Sie Folgendes verwenden: [Zusätzliche Responses](additional-responses.md){.internal-link target=_blank}. From c3914a19a7375e0b52e8e7db77cc23290a90a0c8 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 14:05:12 +0100 Subject: [PATCH 171/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/advanced/custom-response.md`=20(#10624?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/advanced/custom-response.md | 300 +++++++++++++++++++++++ 1 file changed, 300 insertions(+) create mode 100644 docs/de/docs/advanced/custom-response.md diff --git a/docs/de/docs/advanced/custom-response.md b/docs/de/docs/advanced/custom-response.md new file mode 100644 index 0000000000..68c037ad7b --- /dev/null +++ b/docs/de/docs/advanced/custom-response.md @@ -0,0 +1,300 @@ +# Benutzerdefinierte Response – HTML, Stream, Datei, andere + +Standardmäßig gibt **FastAPI** die Responses mittels `JSONResponse` zurÃŧck. + +Sie kÃļnnen das Ãŧberschreiben, indem Sie direkt eine `Response` zurÃŧckgeben, wie in [Eine Response direkt zurÃŧckgeben](response-directly.md){.internal-link target=_blank} gezeigt. + +Wenn Sie jedoch direkt eine `Response` zurÃŧckgeben, werden die Daten nicht automatisch konvertiert und die Dokumentation wird nicht automatisch generiert (zum Beispiel wird der spezifische „Medientyp“, der im HTTP-Header `Content-Type` angegeben ist, nicht Teil der generierten OpenAPI). + +Sie kÃļnnen aber auch die `Response`, die Sie verwenden mÃļchten, im *Pfadoperation-Dekorator* deklarieren. + +Der Inhalt, den Sie von Ihrer *Pfadoperation-Funktion* zurÃŧckgeben, wird in diese `Response` eingefÃŧgt. + +Und wenn diese `Response` einen JSON-Medientyp (`application/json`) hat, wie es bei `JSONResponse` und `UJSONResponse` der Fall ist, werden die von Ihnen zurÃŧckgegebenen Daten automatisch mit jedem Pydantic `response_model` konvertiert (und gefiltert), das Sie im *Pfadoperation-Dekorator* deklariert haben. + +!!! note "Hinweis" + Wenn Sie eine Response-Klasse ohne Medientyp verwenden, erwartet FastAPI, dass Ihre Response keinen Inhalt hat, und dokumentiert daher das Format der Response nicht in deren generierter OpenAPI-Dokumentation. + +## `ORJSONResponse` verwenden + +Um beispielsweise noch etwas Leistung herauszuholen, kÃļnnen Sie `orjson` installieren und verwenden, und die Response als `ORJSONResponse` deklarieren. + +Importieren Sie die `Response`-Klasse (-Unterklasse), die Sie verwenden mÃļchten, und deklarieren Sie sie im *Pfadoperation-Dekorator*. + +Bei umfangreichen Responses ist die direkte RÃŧckgabe einer `Response` viel schneller als ein Dictionary zurÃŧckzugeben. + +Das liegt daran, dass FastAPI standardmäßig jedes enthaltene Element ÃŧberprÃŧft und sicherstellt, dass es als JSON serialisierbar ist, und zwar unter Verwendung desselben [JSON-kompatiblen Encoders](../tutorial/encoder.md){.internal-link target=_blank}, der im Tutorial erläutert wurde. Dadurch kÃļnnen Sie **beliebige Objekte** zurÃŧckgeben, zum Beispiel Datenbankmodelle. + +Wenn Sie jedoch sicher sind, dass der von Ihnen zurÃŧckgegebene Inhalt **mit JSON serialisierbar** ist, kÃļnnen Sie ihn direkt an die Response-Klasse Ãŧbergeben und die zusätzliche Arbeit vermeiden, die FastAPI hätte, indem es Ihren zurÃŧckgegebenen Inhalt durch den `jsonable_encoder` leitet, bevor es ihn an die Response-Klasse Ãŧbergibt. + +```Python hl_lines="2 7" +{!../../../docs_src/custom_response/tutorial001b.py!} +``` + +!!! info + Der Parameter `response_class` wird auch verwendet, um den „Medientyp“ der Response zu definieren. + + In diesem Fall wird der HTTP-Header `Content-Type` auf `application/json` gesetzt. + + Und er wird als solcher in OpenAPI dokumentiert. + +!!! tip "Tipp" + Die `ORJSONResponse` ist derzeit nur in FastAPI verfÃŧgbar, nicht in Starlette. + +## HTML-Response + +Um eine Response mit HTML direkt von **FastAPI** zurÃŧckzugeben, verwenden Sie `HTMLResponse`. + +* Importieren Sie `HTMLResponse`. +* Übergeben Sie `HTMLResponse` als den Parameter `response_class` Ihres *Pfadoperation-Dekorators*. + +```Python hl_lines="2 7" +{!../../../docs_src/custom_response/tutorial002.py!} +``` + +!!! info + Der Parameter `response_class` wird auch verwendet, um den „Medientyp“ der Response zu definieren. + + In diesem Fall wird der HTTP-Header `Content-Type` auf `text/html` gesetzt. + + Und er wird als solcher in OpenAPI dokumentiert. + +### Eine `Response` zurÃŧckgeben + +Wie in [Eine Response direkt zurÃŧckgeben](response-directly.md){.internal-link target=_blank} gezeigt, kÃļnnen Sie die Response auch direkt in Ihrer *Pfadoperation* Ãŧberschreiben, indem Sie diese zurÃŧckgeben. + +Das gleiche Beispiel von oben, das eine `HTMLResponse` zurÃŧckgibt, kÃļnnte so aussehen: + +```Python hl_lines="2 7 19" +{!../../../docs_src/custom_response/tutorial003.py!} +``` + +!!! warning "Achtung" + Eine `Response`, die direkt von Ihrer *Pfadoperation-Funktion* zurÃŧckgegeben wird, wird in OpenAPI nicht dokumentiert (zum Beispiel wird der `Content-Type` nicht dokumentiert) und ist in der automatischen interaktiven Dokumentation nicht sichtbar. + +!!! info + NatÃŧrlich stammen der eigentliche `Content-Type`-Header, der Statuscode, usw., aus dem `Response`-Objekt, das Sie zurÃŧckgegeben haben. + +### In OpenAPI dokumentieren und `Response` Ãŧberschreiben + +Wenn Sie die Response innerhalb der Funktion Ãŧberschreiben und gleichzeitig den „Medientyp“ in OpenAPI dokumentieren mÃļchten, kÃļnnen Sie den `response_class`-Parameter verwenden UND ein `Response`-Objekt zurÃŧckgeben. + +Die `response_class` wird dann nur zur Dokumentation der OpenAPI-Pfadoperation* verwendet, Ihre `Response` wird jedoch unverändert verwendet. + +#### Eine `HTMLResponse` direkt zurÃŧckgeben + +Es kÃļnnte zum Beispiel so etwas sein: + +```Python hl_lines="7 21 23" +{!../../../docs_src/custom_response/tutorial004.py!} +``` + +In diesem Beispiel generiert die Funktion `generate_html_response()` bereits eine `Response` und gibt sie zurÃŧck, anstatt das HTML in einem `str` zurÃŧckzugeben. + +Indem Sie das Ergebnis des Aufrufs von `generate_html_response()` zurÃŧckgeben, geben Sie bereits eine `Response` zurÃŧck, die das Standardverhalten von **FastAPI** Ãŧberschreibt. + +Aber da Sie die `HTMLResponse` auch in der `response_class` Ãŧbergeben haben, weiß **FastAPI**, dass sie in OpenAPI und der interaktiven Dokumentation als HTML mit `text/html` zu dokumentieren ist: + + + +## VerfÃŧgbare Responses + +Hier sind einige der verfÃŧgbaren Responses. + +Bedenken Sie, dass Sie `Response` verwenden kÃļnnen, um alles andere zurÃŧckzugeben, oder sogar eine benutzerdefinierte Unterklasse zu erstellen. + +!!! note "Technische Details" + Sie kÃļnnen auch `from starlette.responses import HTMLResponse` verwenden. + + **FastAPI** bietet dieselben `starlette.responses` auch via `fastapi.responses` an, als Annehmlichkeit fÃŧr Sie, den Entwickler. Die meisten verfÃŧgbaren Responses kommen aber direkt von Starlette. + +### `Response` + +Die Hauptklasse `Response`, alle anderen Responses erben von ihr. + +Sie kÃļnnen sie direkt zurÃŧckgeben. + +Sie akzeptiert die folgenden Parameter: + +* `content` – Ein `str` oder `bytes`. +* `status_code` – Ein `int`-HTTP-Statuscode. +* `headers` – Ein `dict` von Strings. +* `media_type` – Ein `str`, der den Medientyp angibt. Z. B. `"text/html"`. + +FastAPI (eigentlich Starlette) fÃŧgt automatisch einen Content-Length-Header ein. Außerdem wird es einen Content-Type-Header einfÃŧgen, der auf dem media_type basiert, und fÃŧr Texttypen einen Zeichensatz (charset) anfÃŧgen. + +```Python hl_lines="1 18" +{!../../../docs_src/response_directly/tutorial002.py!} +``` + +### `HTMLResponse` + +Nimmt Text oder Bytes entgegen und gibt eine HTML-Response zurÃŧck, wie Sie oben gelesen haben. + +### `PlainTextResponse` + +Nimmt Text oder Bytes entgegen und gibt eine Plain-Text-Response zurÃŧck. + +```Python hl_lines="2 7 9" +{!../../../docs_src/custom_response/tutorial005.py!} +``` + +### `JSONResponse` + +Nimmt einige Daten entgegen und gibt eine `application/json`-codierte Response zurÃŧck. + +Dies ist die Standard-Response, die in **FastAPI** verwendet wird, wie Sie oben gelesen haben. + +### `ORJSONResponse` + +Eine schnelle alternative JSON-Response mit `orjson`, wie Sie oben gelesen haben. + +### `UJSONResponse` + +Eine alternative JSON-Response mit `ujson`. + +!!! warning "Achtung" + `ujson` ist bei der Behandlung einiger Sonderfälle weniger sorgfältig als Pythons eingebaute Implementierung. + +```Python hl_lines="2 7" +{!../../../docs_src/custom_response/tutorial001.py!} +``` + +!!! tip "Tipp" + MÃļglicherweise ist `ORJSONResponse` eine schnellere Alternative. + +### `RedirectResponse` + +Gibt eine HTTP-Weiterleitung (HTTP-Redirect) zurÃŧck. Verwendet standardmäßig den Statuscode 307 – Temporäre Weiterleitung (Temporary Redirect). + +Sie kÃļnnen eine `RedirectResponse` direkt zurÃŧckgeben: + +```Python hl_lines="2 9" +{!../../../docs_src/custom_response/tutorial006.py!} +``` + +--- + +Oder Sie kÃļnnen sie im Parameter `response_class` verwenden: + + +```Python hl_lines="2 7 9" +{!../../../docs_src/custom_response/tutorial006b.py!} +``` + +Wenn Sie das tun, kÃļnnen Sie die URL direkt von Ihrer *Pfadoperation*-Funktion zurÃŧckgeben. + +In diesem Fall ist der verwendete `status_code` der Standardcode fÃŧr die `RedirectResponse`, also `307`. + +--- + +Sie kÃļnnen den Parameter `status_code` auch in Kombination mit dem Parameter `response_class` verwenden: + +```Python hl_lines="2 7 9" +{!../../../docs_src/custom_response/tutorial006c.py!} +``` + +### `StreamingResponse` + +Nimmt einen asynchronen Generator oder einen normalen Generator/Iterator und streamt den Responsebody. + +```Python hl_lines="2 14" +{!../../../docs_src/custom_response/tutorial007.py!} +``` + +#### Verwendung von `StreamingResponse` mit dateiähnlichen Objekten + +Wenn Sie ein dateiähnliches (file-like) Objekt haben (z. B. das von `open()` zurÃŧckgegebene Objekt), kÃļnnen Sie eine Generatorfunktion erstellen, um Ãŧber dieses dateiähnliche Objekt zu iterieren. + +Auf diese Weise mÃŧssen Sie nicht alles zuerst in den Arbeitsspeicher lesen und kÃļnnen diese Generatorfunktion an `StreamingResponse` Ãŧbergeben und zurÃŧckgeben. + +Das umfasst viele Bibliotheken zur Interaktion mit Cloud-Speicher, Videoverarbeitung und anderen. + +```{ .python .annotate hl_lines="2 10-12 14" } +{!../../../docs_src/custom_response/tutorial008.py!} +``` + +1. Das ist die Generatorfunktion. Es handelt sich um eine „Generatorfunktion“, da sie `yield`-Anweisungen enthält. +2. Durch die Verwendung eines `with`-Blocks stellen wir sicher, dass das dateiähnliche Objekt geschlossen wird, nachdem die Generatorfunktion fertig ist. Also, nachdem sie mit dem Senden der Response fertig ist. +3. Dieses `yield from` weist die Funktion an, Ãŧber das Ding namens `file_like` zu iterieren. Und dann fÃŧr jeden iterierten Teil, diesen Teil so zurÃŧckzugeben, als wenn er aus dieser Generatorfunktion (`iterfile`) stammen wÃŧrde. + + Es handelt sich also hier um eine Generatorfunktion, die die „generierende“ Arbeit intern auf etwas anderes Ãŧberträgt. + + Auf diese Weise kÃļnnen wir das Ganze in einen `with`-Block einfÃŧgen und so sicherstellen, dass das dateiartige Objekt nach Abschluss geschlossen wird. + +!!! tip "Tipp" + Beachten Sie, dass wir, da wir Standard-`open()` verwenden, welches `async` und `await` nicht unterstÃŧtzt, hier die Pfadoperation mit normalen `def` deklarieren. + +### `FileResponse` + +Streamt eine Datei asynchron als Response. + +Nimmt zur Instanziierung einen anderen Satz von Argumenten entgegen als die anderen Response-Typen: + +* `path` – Der Dateipfad zur Datei, die gestreamt werden soll. +* `headers` – Alle benutzerdefinierten Header, die inkludiert werden sollen, als Dictionary. +* `media_type` – Ein String, der den Medientyp angibt. Wenn nicht gesetzt, wird der Dateiname oder Pfad verwendet, um auf einen Medientyp zu schließen. +* `filename` – Wenn gesetzt, wird das in der `Content-Disposition` der Response eingefÃŧgt. + +Datei-Responses enthalten die entsprechenden `Content-Length`-, `Last-Modified`- und `ETag`-Header. + +```Python hl_lines="2 10" +{!../../../docs_src/custom_response/tutorial009.py!} +``` + +Sie kÃļnnen auch den Parameter `response_class` verwenden: + +```Python hl_lines="2 8 10" +{!../../../docs_src/custom_response/tutorial009b.py!} +``` + +In diesem Fall kÃļnnen Sie den Dateipfad direkt von Ihrer *Pfadoperation*-Funktion zurÃŧckgeben. + +## Benutzerdefinierte Response-Klasse + +Sie kÃļnnen Ihre eigene benutzerdefinierte Response-Klasse erstellen, die von `Response` erbt und diese verwendet. + +Nehmen wir zum Beispiel an, dass Sie `orjson` verwenden mÃļchten, aber mit einigen benutzerdefinierten Einstellungen, die in der enthaltenen `ORJSONResponse`-Klasse nicht verwendet werden. + +Sie mÃļchten etwa, dass Ihre Response eingerÃŧcktes und formatiertes JSON zurÃŧckgibt. DafÃŧr mÃļchten Sie die orjson-Option `orjson.OPT_INDENT_2` verwenden. + +Sie kÃļnnten eine `CustomORJSONResponse` erstellen. Das Wichtigste, was Sie tun mÃŧssen, ist, eine `Response.render(content)`-Methode zu erstellen, die den Inhalt als `bytes` zurÃŧckgibt: + +```Python hl_lines="9-14 17" +{!../../../docs_src/custom_response/tutorial009c.py!} +``` + +Statt: + +```json +{"message": "Hello World"} +``` + +... wird die Response jetzt Folgendes zurÃŧckgeben: + +```json +{ + "message": "Hello World" +} +``` + +NatÃŧrlich werden Sie wahrscheinlich viel bessere MÃļglichkeiten finden, Vorteil daraus zu ziehen, als JSON zu formatieren. 😉 + +## Standard-Response-Klasse + +Beim Erstellen einer **FastAPI**-Klasseninstanz oder eines `APIRouter`s kÃļnnen Sie angeben, welche Response-Klasse standardmäßig verwendet werden soll. + +Der Parameter, der das definiert, ist `default_response_class`. + +Im folgenden Beispiel verwendet **FastAPI** standardmäßig `ORJSONResponse` in allen *Pfadoperationen*, anstelle von `JSONResponse`. + +```Python hl_lines="2 4" +{!../../../docs_src/custom_response/tutorial010.py!} +``` + +!!! tip "Tipp" + Sie kÃļnnen dennoch weiterhin `response_class` in *Pfadoperationen* Ãŧberschreiben, wie bisher. + +## Zusätzliche Dokumentation + +Sie kÃļnnen auch den Medientyp und viele andere Details in OpenAPI mit `responses` deklarieren: [Zusätzliche Responses in OpenAPI](additional-responses.md){.internal-link target=_blank}. From 149fa96dc73225b8f6817b829eee9870cb787c60 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:05:21 +0000 Subject: [PATCH 172/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 69954afc1f..41ade632c0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/advanced/additional-status-codes.md`. PR [#10617](https://github.com/tiangolo/fastapi/pull/10617) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/middleware.md`. PR [#10391](https://github.com/tiangolo/fastapi/pull/10391) by [@JohannesJungbluth](https://github.com/JohannesJungbluth). * 🌐 Add German translation for introduction documents. PR [#10497](https://github.com/tiangolo/fastapi/pull/10497) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/encoder.md`. PR [#1955](https://github.com/tiangolo/fastapi/pull/1955) by [@SwftAlpc](https://github.com/SwftAlpc). From 2c1dd4a92be3dda8af3835783e85980958ab8228 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:05:40 +0000 Subject: [PATCH 173/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 41ade632c0..9b091c4942 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/advanced/custom-response.md`. PR [#10624](https://github.com/tiangolo/fastapi/pull/10624) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/additional-status-codes.md`. PR [#10617](https://github.com/tiangolo/fastapi/pull/10617) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/middleware.md`. PR [#10391](https://github.com/tiangolo/fastapi/pull/10391) by [@JohannesJungbluth](https://github.com/JohannesJungbluth). * 🌐 Add German translation for introduction documents. PR [#10497](https://github.com/tiangolo/fastapi/pull/10497) by [@nilslindemann](https://github.com/nilslindemann). From 43a7ff782bc7e136c579e9b704916e6e8bea8dc5 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 14:06:03 +0100 Subject: [PATCH 174/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/advanced/openapi-webhooks.md`=20(#1071?= =?UTF-8?q?2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/advanced/openapi-webhooks.md | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/de/docs/advanced/openapi-webhooks.md diff --git a/docs/de/docs/advanced/openapi-webhooks.md b/docs/de/docs/advanced/openapi-webhooks.md new file mode 100644 index 0000000000..339218080d --- /dev/null +++ b/docs/de/docs/advanced/openapi-webhooks.md @@ -0,0 +1,51 @@ +# OpenAPI-Webhooks + +Es gibt Fälle, in denen Sie Ihren API-Benutzern mitteilen mÃļchten, dass Ihre Anwendung mit einigen Daten *deren* Anwendung aufrufen (ein Request senden) kÃļnnte, normalerweise um Ãŧber ein bestimmtes **Event** zu **benachrichtigen**. + +Das bedeutet, dass anstelle des normalen Prozesses, bei dem Benutzer Requests an Ihre API senden, **Ihre API** (oder Ihre Anwendung) **Requests an deren System** (an deren API, deren Anwendung) senden kÃļnnte. + +Das wird normalerweise als **Webhook** bezeichnet. + +## Webhooks-Schritte + +Der Prozess besteht normalerweise darin, dass **Sie in Ihrem Code definieren**, welche Nachricht Sie senden mÃļchten, den **Body des Requests**. + +Sie definieren auch auf irgendeine Weise, zu welchen **Momenten** Ihre Anwendung diese Requests oder Events sendet. + +Und **Ihre Benutzer** definieren auf irgendeine Weise (zum Beispiel irgendwo in einem Web-Dashboard) die **URL**, an die Ihre Anwendung diese Requests senden soll. + +Die gesamte **Logik** zur Registrierung der URLs fÃŧr Webhooks und der Code zum tatsächlichen Senden dieser Requests liegt bei Ihnen. Sie schreiben es so, wie Sie mÃļchten, in **Ihrem eigenen Code**. + +## Webhooks mit **FastAPI** und OpenAPI dokumentieren + +Mit **FastAPI** kÃļnnen Sie mithilfe von OpenAPI die Namen dieser Webhooks, die Arten von HTTP-Operationen, die Ihre Anwendung senden kann (z. B. `POST`, `PUT`, usw.) und die Request**bodys** definieren, die Ihre Anwendung senden wÃŧrde. + +Dies kann es Ihren Benutzern viel einfacher machen, **deren APIs zu implementieren**, um Ihre **Webhook**-Requests zu empfangen. MÃļglicherweise kÃļnnen diese sogar einen Teil des eigenem API-Codes automatisch generieren. + +!!! info + Webhooks sind in OpenAPI 3.1.0 und hÃļher verfÃŧgbar und werden von FastAPI `0.99.0` und hÃļher unterstÃŧtzt. + +## Eine Anwendung mit Webhooks + +Wenn Sie eine **FastAPI**-Anwendung erstellen, gibt es ein `webhooks`-Attribut, mit dem Sie *Webhooks* definieren kÃļnnen, genauso wie Sie *Pfadoperationen* definieren wÃŧrden, zum Beispiel mit `@app.webhooks.post()`. + +```Python hl_lines="9-13 36-53" +{!../../../docs_src/openapi_webhooks/tutorial001.py!} +``` + +Die von Ihnen definierten Webhooks landen im **OpenAPI**-Schema und der automatischen **Dokumentations-Oberfläche**. + +!!! info + Das `app.webhooks`-Objekt ist eigentlich nur ein `APIRouter`, derselbe Typ, den Sie verwenden wÃŧrden, wenn Sie Ihre Anwendung mit mehreren Dateien strukturieren. + +Beachten Sie, dass Sie bei Webhooks tatsächlich keinen *Pfad* (wie `/items/`) deklarieren, sondern dass der Text, den Sie dort Ãŧbergeben, lediglich eine **Kennzeichnung** des Webhooks (der Name des Events) ist. Zum Beispiel ist in `@app.webhooks.post("new-subscription")` der Webhook-Name `new-subscription`. + +Das liegt daran, dass erwartet wird, dass **Ihre Benutzer** den tatsächlichen **URL-Pfad**, an dem diese den Webhook-Request empfangen mÃļchten, auf andere Weise definieren (z. B. Ãŧber ein Web-Dashboard). + +### Es in der Dokumentation ansehen + +Jetzt kÃļnnen Sie Ihre Anwendung mit Uvicorn starten und auf http://127.0.0.1:8000/docs gehen. + +Sie werden sehen, dass Ihre Dokumentation die normalen *Pfadoperationen* und jetzt auch einige **Webhooks** enthält: + + From 74cf1c97025b3afe2c77baeba18620ac2b496d03 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 14:07:40 +0100 Subject: [PATCH 175/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/advanced/generate-clients.md`=20(#1072?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/advanced/generate-clients.md | 286 ++++++++++++++++++++++ 1 file changed, 286 insertions(+) create mode 100644 docs/de/docs/advanced/generate-clients.md diff --git a/docs/de/docs/advanced/generate-clients.md b/docs/de/docs/advanced/generate-clients.md new file mode 100644 index 0000000000..2fcba59569 --- /dev/null +++ b/docs/de/docs/advanced/generate-clients.md @@ -0,0 +1,286 @@ +# Clients generieren + +Da **FastAPI** auf der OpenAPI-Spezifikation basiert, erhalten Sie automatische Kompatibilität mit vielen Tools, einschließlich der automatischen API-Dokumentation (bereitgestellt von Swagger UI). + +Ein besonderer Vorteil, der nicht unbedingt offensichtlich ist, besteht darin, dass Sie fÃŧr Ihre API **Clients generieren** kÃļnnen (manchmal auch **SDKs** genannt), fÃŧr viele verschiedene **Programmiersprachen**. + +## OpenAPI-Client-Generatoren + +Es gibt viele Tools zum Generieren von Clients aus **OpenAPI**. + +Ein gängiges Tool ist OpenAPI Generator. + +Wenn Sie ein **Frontend** erstellen, ist openapi-typescript-codegen eine sehr interessante Alternative. + +## Client- und SDK-Generatoren – Sponsor + +Es gibt auch einige **vom Unternehmen entwickelte** Client- und SDK-Generatoren, die auf OpenAPI (FastAPI) basieren. In einigen Fällen kÃļnnen diese Ihnen **weitere Funktionalität** zusätzlich zu qualitativ hochwertigen generierten SDKs/Clients bieten. + +Einige von diesen ✨ [**sponsern FastAPI**](../help-fastapi.md#den-autor-sponsern){.internal-link target=_blank} ✨, das gewährleistet die kontinuierliche und gesunde **Entwicklung** von FastAPI und seinem **Ökosystem**. + +Und es zeigt deren wahres Engagement fÃŧr FastAPI und seine **Community** (Sie), da diese Ihnen nicht nur einen **guten Service** bieten mÃļchten, sondern auch sicherstellen mÃļchten, dass Sie Ãŧber ein **gutes und gesundes Framework** verfÃŧgen, FastAPI. 🙇 + +Beispielsweise kÃļnnten Sie Speakeasy ausprobieren. + +Es gibt auch mehrere andere Unternehmen, welche ähnliche Dienste anbieten und die Sie online suchen und finden kÃļnnen. 🤓 + +## Einen TypeScript-Frontend-Client generieren + +Beginnen wir mit einer einfachen FastAPI-Anwendung: + +=== "Python 3.9+" + + ```Python hl_lines="7-9 12-13 16-17 21" + {!> ../../../docs_src/generate_clients/tutorial001_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9-11 14-15 18 19 23" + {!> ../../../docs_src/generate_clients/tutorial001.py!} + ``` + +Beachten Sie, dass die *Pfadoperationen* die Modelle definieren, welche diese fÃŧr die Request- und Response-Payload verwenden, indem sie die Modelle `Item` und `ResponseMessage` verwenden. + +### API-Dokumentation + +Wenn Sie zur API-Dokumentation gehen, werden Sie sehen, dass diese die **Schemas** fÃŧr die Daten enthält, welche in Requests gesendet und in Responses empfangen werden: + + + +Sie kÃļnnen diese Schemas sehen, da sie mit den Modellen in der Anwendung deklariert wurden. + +Diese Informationen sind im **OpenAPI-Schema** der Anwendung verfÃŧgbar und werden dann in der API-Dokumentation angezeigt (von Swagger UI). + +Und dieselben Informationen aus den Modellen, die in OpenAPI enthalten sind, kÃļnnen zum **Generieren des Client-Codes** verwendet werden. + +### Einen TypeScript-Client generieren + +Nachdem wir nun die Anwendung mit den Modellen haben, kÃļnnen wir den Client-Code fÃŧr das Frontend generieren. + +#### `openapi-typescript-codegen` installieren + +Sie kÃļnnen `openapi-typescript-codegen` in Ihrem Frontend-Code installieren mit: + +
+ +```console +$ npm install openapi-typescript-codegen --save-dev + +---> 100% +``` + +
+ +#### Client-Code generieren + +Um den Client-Code zu generieren, kÃļnnen Sie das Kommandozeilentool `openapi` verwenden, das soeben installiert wurde. + +Da es im lokalen Projekt installiert ist, kÃļnnten Sie diesen Befehl wahrscheinlich nicht direkt aufrufen, sondern wÃŧrden ihn in Ihre Datei `package.json` einfÃŧgen. + +Diese kÃļnnte so aussehen: + +```JSON hl_lines="7" +{ + "name": "frontend-app", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "generate-client": "openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes" + }, + "author": "", + "license": "", + "devDependencies": { + "openapi-typescript-codegen": "^0.20.1", + "typescript": "^4.6.2" + } +} +``` + +Nachdem Sie das NPM-Skript `generate-client` dort stehen haben, kÃļnnen Sie es ausfÃŧhren mit: + +
+ +```console +$ npm run generate-client + +frontend-app@1.0.0 generate-client /home/user/code/frontend-app +> openapi --input http://localhost:8000/openapi.json --output ./src/client --client axios --useOptions --useUnionTypes +``` + +
+ +Dieser Befehl generiert Code in `./src/client` und verwendet intern `axios` (die Frontend-HTTP-Bibliothek). + +### Den Client-Code ausprobieren + +Jetzt kÃļnnen Sie den Client-Code importieren und verwenden. Er kÃļnnte wie folgt aussehen, beachten Sie, dass Sie automatische Codevervollständigung fÃŧr die Methoden erhalten: + + + +Sie erhalten außerdem automatische Vervollständigung fÃŧr die zu sendende Payload: + + + +!!! tip "Tipp" + Beachten Sie die automatische Vervollständigung fÃŧr `name` und `price`, welche in der FastAPI-Anwendung im `Item`-Modell definiert wurden. + +Sie erhalten Inline-Fehlerberichte fÃŧr die von Ihnen gesendeten Daten: + + + +Das Response-Objekt hat auch automatische Vervollständigung: + + + +## FastAPI-Anwendung mit Tags + +In vielen Fällen wird Ihre FastAPI-Anwendung grÃļßer sein und Sie werden wahrscheinlich Tags verwenden, um verschiedene Gruppen von *Pfadoperationen* zu separieren. + +Beispielsweise kÃļnnten Sie einen Abschnitt fÃŧr **Items (Artikel)** und einen weiteren Abschnitt fÃŧr **Users (Benutzer)** haben, und diese kÃļnnten durch Tags getrennt sein: + +=== "Python 3.9+" + + ```Python hl_lines="21 26 34" + {!> ../../../docs_src/generate_clients/tutorial002_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="23 28 36" + {!> ../../../docs_src/generate_clients/tutorial002.py!} + ``` + +### Einen TypeScript-Client mit Tags generieren + +Wenn Sie unter Verwendung von Tags einen Client fÃŧr eine FastAPI-Anwendung generieren, wird normalerweise auch der Client-Code anhand der Tags getrennt. + +Auf diese Weise kÃļnnen Sie die Dinge fÃŧr den Client-Code richtig ordnen und gruppieren: + + + +In diesem Fall haben Sie: + +* `ItemsService` +* `UsersService` + +### Client-Methodennamen + +Im Moment sehen die generierten Methodennamen wie `createItemItemsPost` nicht sehr sauber aus: + +```TypeScript +ItemsService.createItemItemsPost({name: "Plumbus", price: 5}) +``` + +... das liegt daran, dass der Client-Generator fÃŧr jede *Pfadoperation* die OpenAPI-interne **Operation-ID** verwendet. + +OpenAPI erfordert, dass jede Operation-ID innerhalb aller *Pfadoperationen* eindeutig ist. Daher verwendet FastAPI den **Funktionsnamen**, den **Pfad** und die **HTTP-Methode/-Operation**, um diese Operation-ID zu generieren. Denn so kann sichergestellt werden, dass die Operation-IDs eindeutig sind. + +Aber ich zeige Ihnen als nächstes, wie Sie das verbessern kÃļnnen. 🤓 + +## Benutzerdefinierte Operation-IDs und bessere Methodennamen + +Sie kÃļnnen die Art und Weise, wie diese Operation-IDs **generiert** werden, **ändern**, um sie einfacher zu machen und **einfachere Methodennamen** in den Clients zu haben. + +In diesem Fall mÃŧssen Sie auf andere Weise sicherstellen, dass jede Operation-ID **eindeutig** ist. + +Sie kÃļnnten beispielsweise sicherstellen, dass jede *Pfadoperation* einen Tag hat, und dann die Operation-ID basierend auf dem **Tag** und dem **Namen** der *Pfadoperation* (dem Funktionsnamen) generieren. + +### Funktion zum Generieren einer eindeutigen ID erstellen + +FastAPI verwendet eine **eindeutige ID** fÃŧr jede *Pfadoperation*, diese wird fÃŧr die **Operation-ID** und auch fÃŧr die Namen aller benÃļtigten benutzerdefinierten Modelle fÃŧr Requests oder Responses verwendet. + +Sie kÃļnnen diese Funktion anpassen. Sie nimmt eine `APIRoute` und gibt einen String zurÃŧck. + +Hier verwendet sie beispielsweise den ersten Tag (Sie werden wahrscheinlich nur einen Tag haben) und den Namen der *Pfadoperation* (den Funktionsnamen). + +Anschließend kÃļnnen Sie diese benutzerdefinierte Funktion als Parameter `generate_unique_id_function` an **FastAPI** Ãŧbergeben: + +=== "Python 3.9+" + + ```Python hl_lines="6-7 10" + {!> ../../../docs_src/generate_clients/tutorial003_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="8-9 12" + {!> ../../../docs_src/generate_clients/tutorial003.py!} + ``` + +### Einen TypeScript-Client mit benutzerdefinierten Operation-IDs generieren + +Wenn Sie nun den Client erneut generieren, werden Sie feststellen, dass er Ãŧber die verbesserten Methodennamen verfÃŧgt: + + + +Wie Sie sehen, haben die Methodennamen jetzt den Tag und dann den Funktionsnamen, aber keine Informationen aus dem URL-Pfad und der HTTP-Operation. + +### Vorab-Modifikation der OpenAPI-Spezifikation fÃŧr den Client-Generator + +Der generierte Code enthält immer noch etwas **verdoppelte Information**. + +Wir wissen bereits, dass diese Methode mit den **Items** zusammenhängt, da sich dieses Wort in `ItemsService` befindet (vom Tag Ãŧbernommen), aber wir haben auch immer noch den Tagnamen im Methodennamen vorangestellt. 😕 + +Wir werden das wahrscheinlich weiterhin fÃŧr OpenAPI im Allgemeinen beibehalten wollen, da dadurch sichergestellt wird, dass die Operation-IDs **eindeutig** sind. + +Aber fÃŧr den generierten Client kÃļnnten wir die OpenAPI-Operation-IDs direkt vor der Generierung der Clients **modifizieren**, um diese Methodennamen schÃļner und **sauberer** zu machen. + +Wir kÃļnnten das OpenAPI-JSON in eine Datei `openapi.json` herunterladen und dann mit einem Skript wie dem folgenden **den vorangestellten Tag entfernen**: + +=== "Python" + + ```Python + {!> ../../../docs_src/generate_clients/tutorial004.py!} + ``` + +=== "Node.js" + + ```Javascript + {!> ../../../docs_src/generate_clients/tutorial004.js!} + ``` + +Damit wÃŧrden die Operation-IDs von Dingen wie `items-get_items` in `get_items` umbenannt, sodass der Client-Generator einfachere Methodennamen generieren kann. + +### Einen TypeScript-Client mit der modifizierten OpenAPI generieren + +Da das Endergebnis nun in einer Datei `openapi.json` vorliegt, wÃŧrden Sie die `package.json` ändern, um diese lokale Datei zu verwenden, zum Beispiel: + +```JSON hl_lines="7" +{ + "name": "frontend-app", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "generate-client": "openapi --input ./openapi.json --output ./src/client --client axios --useOptions --useUnionTypes" + }, + "author": "", + "license": "", + "devDependencies": { + "openapi-typescript-codegen": "^0.20.1", + "typescript": "^4.6.2" + } +} +``` + +Nach der Generierung des neuen Clients hätten Sie nun **saubere Methodennamen** mit allen **Autovervollständigungen**, **Inline-Fehlerberichten**, usw.: + + + +## Vorteile + +Wenn Sie die automatisch generierten Clients verwenden, erhalten Sie **automatische Codevervollständigung** fÃŧr: + +* Methoden. +* Request-Payloads im Body, Query-Parameter, usw. +* Response-Payloads. + +Außerdem erhalten Sie fÃŧr alles **Inline-Fehlerberichte**. + +Und wann immer Sie den Backend-Code aktualisieren und das Frontend **neu generieren**, stehen alle neuen *Pfadoperationen* als Methoden zur VerfÃŧgung, die alten werden entfernt und alle anderen Änderungen werden im generierten Code reflektiert. 🤓 + +Das bedeutet auch, dass, wenn sich etwas ändert, dies automatisch im Client-Code **reflektiert** wird. Und wenn Sie den Client **erstellen**, kommt es zu einer Fehlermeldung, wenn die verwendeten Daten **nicht Ãŧbereinstimmen**. + +Sie wÃŧrden also sehr frÃŧh im Entwicklungszyklus **viele Fehler erkennen**, anstatt darauf warten zu mÃŧssen, dass die Fehler Ihren Endbenutzern in der Produktion angezeigt werden, und dann zu versuchen, zu debuggen, wo das Problem liegt. ✨ From 5ca3d175879166c4956b92d4bb7745086fe3b21d Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:08:30 +0000 Subject: [PATCH 176/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 9b091c4942..d7a8e0c60d 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/advanced/openapi-webhooks.md`. PR [#10712](https://github.com/tiangolo/fastapi/pull/10712) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/custom-response.md`. PR [#10624](https://github.com/tiangolo/fastapi/pull/10624) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/additional-status-codes.md`. PR [#10617](https://github.com/tiangolo/fastapi/pull/10617) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/middleware.md`. PR [#10391](https://github.com/tiangolo/fastapi/pull/10391) by [@JohannesJungbluth](https://github.com/JohannesJungbluth). From 13b908df68e48416d968980d9b3f6f00f8ff54ad Mon Sep 17 00:00:00 2001 From: 3w36zj6 <52315048+3w36zj6@users.noreply.github.com> Date: Tue, 23 Jan 2024 22:10:49 +0900 Subject: [PATCH 177/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/security/index.md`=20(#5798?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ja/docs/tutorial/security/index.md | 101 ++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 docs/ja/docs/tutorial/security/index.md diff --git a/docs/ja/docs/tutorial/security/index.md b/docs/ja/docs/tutorial/security/index.md new file mode 100644 index 0000000000..390f210477 --- /dev/null +++ b/docs/ja/docs/tutorial/security/index.md @@ -0,0 +1,101 @@ +# ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗå…Ĩ門 + +ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã€čĒč¨ŧ、čĒå¯ã‚’æ‰ąã†ãĢã¯å¤šããŽæ–šæŗ•ãŒã‚ã‚Šãžã™ã€‚ + +そしãĻã€é€šå¸¸ã€ãã‚Œã¯č¤‡é›‘ã§ã€Œé›Ŗã—ã„ã€ãƒˆãƒ”ãƒƒã‚¯ã§ã™ã€‚ + +多くぎフãƒŦãƒŧムワãƒŧã‚¯ã‚„ã‚ˇã‚šãƒ†ãƒ ã§ã¯ã€ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã¨čĒč¨ŧをå‡Ļį†ã™ã‚‹ã ã‘ã§ã€č†¨å¤§ãĒåŠ´åŠ›ã¨ã‚ŗãƒŧドがåŋ…čρãĢãĒりぞすīŧˆå¤šããŽå ´åˆã€æ›¸ã‹ã‚ŒãŸå…¨ã‚ŗãƒŧドぎ50%äģĨ上を占めることがありぞすīŧ‰ã€‚ + +**FastAPI** は、ã‚ģキãƒĨãƒĒãƒ†ã‚ŖãŽä앿§˜ã‚’すずãĻ勉åŧˇã—ãĻå­ĻãļことãĒく、標æē–įš„ãĒæ–šæŗ•ã§į°Ąå˜ãĢ、čŋ…速ãĢ**ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗ**ã‚’æ‰ąã†ãŸã‚ãŽãƒ„ãƒŧãƒĢをいくつか提䞛しぞす。 + +しかし、そぎ前ãĢ、いくつかぎ小さãĒæĻ‚åŋĩをįĸēčĒã—ãžã—ã‚‡ã†ã€‚ + +## おæ€ĨぎですかīŧŸ + +ã‚‚ã—ã€ã“ã‚Œã‚‰ãŽį”¨čĒžãĢčˆˆå‘ŗãŒãĒく、ãƒĻãƒŧã‚ļãƒŧ名とパ゚ワãƒŧドãĢåŸēãĨくčĒč¨ŧでã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚’**äģŠã™ã**įĸēäŋã™ã‚‹åŋ…čĻãŒã‚ã‚‹å ´åˆã¯ã€æŦĄãŽįĢ ãĢé€˛ã‚“ã§ãã ã•ã„ã€‚ + +## OAuth2 + +OAuth2は、čĒč¨ŧとčĒå¯ã‚’å‡Ļį†ã™ã‚‹ãŸã‚ãŽã„ãã¤ã‹ãŽæ–šæŗ•ã‚’åŽšįžŠã—ãŸä앿§˜ã§ã™ã€‚ + +かãĒりåēƒį¯„回ãĒä앿§˜ã§ã€ã„ãã¤ã‹ãŽč¤‡é›‘ãĒãƒĻãƒŧã‚šã‚ąãƒŧ゚をã‚ĢバãƒŧしãĻいぞす。 + +これãĢは「ã‚ĩãƒŧドパãƒŧãƒ†ã‚Ŗã€ã‚’äŊŋį”¨ã—ãĻčĒč¨ŧã™ã‚‹æ–šæŗ•ãŒåĢぞれãĻいぞす。 + +これが、「Facebook、Google、Twitter、GitHubをäŊŋãŖãĻãƒ­ã‚°ã‚¤ãƒŗã€ã‚’äŊŋį”¨ã—ãŸã™ãšãĻãŽã‚ˇã‚šãƒ†ãƒ ãŽčƒŒåžŒã§äŊŋわれãĻいるäģ•įĩ„ãŋです。 + +### OAuth 1 + +OAuth 1というもぎもありぞしたが、これはOAuth2ã¨ã¯å…¨ãį•°ãĒり、通äŋĄã‚’おぎようãĢæš—åˇåŒ–ã™ã‚‹ã‹ã¨ã„ã†ä앿§˜ãŒį›´æŽĨįš„ãĢåĢぞれãĻãŠã‚Šã€ã‚ˆã‚Šč¤‡é›‘ãĒもぎとãĒãŖãĻいぞす。 + +įžåœ¨ã§ã¯ã‚ãžã‚Šæ™ŽåŠã—ãĻいぞせんし、äŊŋわれãĻもいぞせん。 + +OAuth2は、通äŋĄã‚’æš—åˇåŒ–ã™ã‚‹æ–šæŗ•ã‚’æŒ‡åŽšã›ãšã€ã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗãŒHTTPSã§æäž›ã•ã‚Œã‚‹ã“ã¨ã‚’æƒŗåŽšã—ãĻいぞす。 + +!!! tip "豆įŸĨ識" + **デプロイ**ぎã‚ģã‚¯ã‚ˇãƒ§ãƒŗã§ã¯ã€TraefikとLet's EncryptをäŊŋį”¨ã—ãĻã€į„Ąæ–™ã§HTTPSã‚’č¨­åŽšã™ã‚‹æ–šæŗ•ãŒį´šäģ‹ã•れãĻいぞす。 + + +## OpenID Connect + +OpenID Connectは、**OAuth2**をベãƒŧ゚ãĢしたåˆĨぎä앿§˜ã§ã™ã€‚ + +これはOAuth2ã‚’æ‹Ąåŧĩしたもぎで、OAuth2ã§ã¯ã‚„ã‚„æ›–æ˜§ã ãŖãŸéƒ¨åˆ†ã‚’æ˜ŽįĸēãĢã—ã€ã‚ˆã‚Šį›¸äē’é‹į”¨æ€§ã‚’éĢ˜ã‚ã‚ˆã†ã¨ã—ãŸã‚‚ãŽã§ã™ã€‚ + +䞋としãĻ、GoogleãŽãƒ­ã‚°ã‚¤ãƒŗã¯OpenID ConnectをäŊŋį”¨ã—ãĻいぞすīŧˆã“れはOAuth2がベãƒŧ゚ãĢãĒãŖãĻいぞすīŧ‰ã€‚ + +しかし、FacebookãŽãƒ­ã‚°ã‚¤ãƒŗã¯OpenID Connectをã‚ĩポãƒŧトしãĻいぞせん。OAuth2をį‹Ŧč‡ĒãĢã‚ĸãƒŦãƒŗã‚¸ã—ãĻいぞす。 + +### OpenID (「OpenID Connect」ではãĒい) + +ぞた、「OpenID」というä앿§˜ã‚‚ありぞした。それは、**OpenID Connect**ã¨åŒã˜ã“ã¨ã‚’č§Ŗæąēしようとしたもぎですが、OAuth2ãĢåŸēãĨいãĻいるわけではありぞせんでした。 + +つぞり、厌全ãĒčŋŊåŠ ã‚ˇã‚šãƒ†ãƒ ã ãŖãŸãŽã§ã™ã€‚ + +įžåœ¨ã§ã¯ã‚ãžã‚Šæ™ŽåŠã—ãĻいぞせんし、äŊŋわれãĻもいぞせん。 + +## OpenAPI + +OpenAPIīŧˆäģĨ前はSwaggerとしãĻįŸĨられãĻいぞしたīŧ‰ã¯ã€APIã‚’æ§‹į¯‰ã™ã‚‹ãŸã‚ãŽã‚Ēãƒŧãƒ—ãƒŗãĒä앿§˜ã§ã™īŧˆįžåœ¨ã¯Linux Foundationぎ一部ãĢãĒãŖãĻいぞすīŧ‰ã€‚ + +**FastAPI**は、**OpenAPI**をベãƒŧ゚ãĢしãĻいぞす。 + +ãã‚ŒãŒã€č¤‡æ•°ãŽč‡Ēå‹•å¯žčŠąåž‹ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆãƒģã‚¤ãƒŗã‚ŋãƒŧフェãƒŧã‚šã‚„ã‚ŗãƒŧãƒ‰į”ŸæˆãĒおを可čƒŊãĢしãĻいるぎです。 + +OpenAPIãĢã¯ã€č¤‡æ•°ãŽã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã€Œã‚šã‚­ãƒŧãƒ ã€ã‚’åŽšįžŠã™ã‚‹æ–šæŗ•ãŒã‚ã‚Šãžã™ã€‚ + +それらをäŊŋį”¨ã™ã‚‹ã“ã¨ã§ã€ã“ã‚Œã‚‰ãŽå¯žčŠąåž‹ãƒ‰ã‚­ãƒĨãƒĄãƒŗãƒˆã‚ˇã‚šãƒ†ãƒ ã‚’åĢむ、標æē–ベãƒŧ゚ぎツãƒŧãƒĢをすずãĻæ´ģį”¨ã§ããžã™ã€‚ + +OpenAPIでは、äģĨ下ぎã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚šã‚­ãƒŧãƒ ã‚’åŽšįžŠã—ãĻいぞす: + +* `apiKey`: ã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗå›ē有ぎキãƒŧで、これらぎもぎから取垗できぞす。 + * クエãƒĒãƒ‘ãƒŠãƒĄãƒŧã‚ŋ + * ヘッダãƒŧ + * クッキãƒŧ +* `http`: 標æē–įš„ãĒHTTPčĒč¨ŧã‚ˇã‚šãƒ†ãƒ ã§ã€ã“ã‚Œã‚‰ãŽã‚‚ãŽã‚’åĢãŋぞす。 + * `bearer`: ヘッダ `Authorization` ぎ値が `Bearer ` で、トãƒŧã‚¯ãƒŗãŒåĢぞれぞす。これはOAuth2からį‰ŋしãĻいぞす。 + * HTTP BasicčĒč¨ŧ + * HTTP ダイジェ゚トčĒč¨ŧãĒお +* `oauth2`: OAuth2ぎã‚ģキãƒĨãƒĒãƒ†ã‚Ŗå‡Ļį†æ–šæŗ•īŧˆã€Œãƒ•ロãƒŧ」とå‘ŧばれぞすīŧ‰ãŽã™ãšãĻ。 + * これらぎフロãƒŧぎいくつかは、OAuth 2.0čĒč¨ŧプロバイダīŧˆGoogle、Facebook、Twitter、GitHubãĒおīŧ‰ã‚’æ§‹į¯‰ã™ã‚‹ãŽãĢ遊しãĻいぞす。 + * `implicit` + * `clientCredentials` + * `authorizationCode` + * しかし、同じã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗå†…ã§čĒč¨ŧã‚’į›´æŽĨå‡Ļį†ã™ã‚‹ãŸã‚ãĢ厌全ãĢ抟čƒŊã™ã‚‹į‰šåŽšãŽã€Œãƒ•ãƒ­ãƒŧ」がありぞす。 + * `password`: æŦĄãŽã„くつかぎįĢ ã§ã¯ã€ããŽäž‹ã‚’į´šäģ‹ã—ぞす。 +* `openIdConnect`: OAuth2čĒč¨ŧデãƒŧã‚ŋをč‡Ēå‹•įš„ãĢį™ēčĻ‹ã™ã‚‹æ–šæŗ•ã‚’åŽšįžŠã§ããžã™ã€‚ + * こぎč‡Ē動検å‡ēãƒĄã‚Ģニã‚ēムは、OpenID Connectぎä앿§˜ã§åŽšįžŠã•ã‚ŒãĻいるもぎです。 + + +!!! tip "豆įŸĨ識" + Google、Facebook、Twitter、GitHubãĒお、äģ–ぎčĒč¨ŧ/čĒå¯ãƒ—ãƒ­ãƒã‚¤ãƒ€ã‚’įĩąåˆã™ã‚‹ã“とも可čƒŊで、比čŧƒįš„į°Ąå˜ã§ã™ã€‚ + + æœ€ã‚‚č¤‡é›‘ãĒå•éĄŒã¯ã€ãã‚Œã‚‰ãŽã‚ˆã†ãĒčĒč¨ŧ/čĒå¯ãƒ—ãƒ­ãƒã‚¤ãƒ€ã‚’æ§‹į¯‰ã™ã‚‹ã“ã¨ã§ã™ãŒã€**FastAPI**は、あãĒたぎためãĢ重いäģ•äē‹ã‚’こãĒしãĒãŒã‚‰ã€ãã‚Œã‚’į°Ąå˜ãĢčĄŒã†ãŸã‚ãŽãƒ„ãƒŧãƒĢを提䞛しぞす。 + +## **FastAPI** ãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚Ŗ + +FastAPIは `fastapi.security` ãƒĸジãƒĨãƒŧãƒĢぎ中で、これらぎã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚šã‚­ãƒŧムごとãĢいくつかぎツãƒŧãƒĢを提䞛し、これらぎã‚ģキãƒĨãƒĒãƒ†ã‚ŖãƒĄã‚Ģニã‚ēãƒ ã‚’į°Ąå˜ãĢäŊŋį”¨ã§ãã‚‹ã‚ˆã†ãĢしぞす。 + +æŦĄãŽįĢ ã§ã¯ã€**FastAPI** が提䞛するこれらぎツãƒŧãƒĢをäŊŋãŖãĻ、あãĒたぎAPIãĢã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚’čŋŊåŠ ã™ã‚‹æ–šæŗ•ãĢついãĻčĻ‹ãĻいきぞす。 + +ぞた、それがおぎようãĢã‚¤ãƒŗã‚ŋãƒŠã‚¯ãƒ†ã‚Ŗãƒ–ãĒドキãƒĨãƒĄãƒŗãƒˆã‚ˇã‚šãƒ†ãƒ ãĢč‡Ēå‹•įš„ãĢįĩąåˆã•れるかもčĻ‹ãĻいきぞす。 From 7c9cb476a48d1de73557bcee22c62323d7b19971 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:11:16 +0000 Subject: [PATCH 178/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d7a8e0c60d..ffbeaff15e 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/advanced/generate-clients.md`. PR [#10725](https://github.com/tiangolo/fastapi/pull/10725) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/openapi-webhooks.md`. PR [#10712](https://github.com/tiangolo/fastapi/pull/10712) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/custom-response.md`. PR [#10624](https://github.com/tiangolo/fastapi/pull/10624) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/additional-status-codes.md`. PR [#10617](https://github.com/tiangolo/fastapi/pull/10617) by [@nilslindemann](https://github.com/nilslindemann). From 280f49ea835eb6f2d900aee2d9bb2f8425ab4dde Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:15:22 +0000 Subject: [PATCH 179/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ffbeaff15e..68f6b07629 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/index.md`. PR [#5798](https://github.com/tiangolo/fastapi/pull/5798) by [@3w36zj6](https://github.com/3w36zj6). * 🌐 Add German translation for `docs/de/docs/advanced/generate-clients.md`. PR [#10725](https://github.com/tiangolo/fastapi/pull/10725) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/openapi-webhooks.md`. PR [#10712](https://github.com/tiangolo/fastapi/pull/10712) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/custom-response.md`. PR [#10624](https://github.com/tiangolo/fastapi/pull/10624) by [@nilslindemann](https://github.com/nilslindemann). From 51329762539c3ed1ed72e4a4860ccf5711aa7301 Mon Sep 17 00:00:00 2001 From: Nikita <78080842+NiKuma0@users.noreply.github.com> Date: Tue, 23 Jan 2024 16:54:17 +0300 Subject: [PATCH 180/305] =?UTF-8?q?=F0=9F=8C=90=20Russian=20translation:?= =?UTF-8?q?=20updated=20`fastapi-people.md`.=20(#10255)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/fastapi-people.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/ru/docs/fastapi-people.md b/docs/ru/docs/fastapi-people.md index 64ae66a035..6778cceab7 100644 --- a/docs/ru/docs/fastapi-people.md +++ b/docs/ru/docs/fastapi-people.md @@ -5,7 +5,7 @@ ## ĐĄĐžĐˇĐ´Đ°Ņ‚ĐĩĐģҌ и Ņ…Ņ€Đ°ĐŊĐ¸Ņ‚ĐĩĐģҌ -ĐšŅƒ! 👋 +ĐĨаК! 👋 Đ­Ņ‚Đž Ņ: From 315d8184e7e393106cb985ac3aff10d22b4d4080 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:54:45 +0000 Subject: [PATCH 181/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 68f6b07629..a1ee0f0cf0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Russian translation: updated `fastapi-people.md`.. PR [#10255](https://github.com/tiangolo/fastapi/pull/10255) by [@NiKuma0](https://github.com/NiKuma0). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/index.md`. PR [#5798](https://github.com/tiangolo/fastapi/pull/5798) by [@3w36zj6](https://github.com/3w36zj6). * 🌐 Add German translation for `docs/de/docs/advanced/generate-clients.md`. PR [#10725](https://github.com/tiangolo/fastapi/pull/10725) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/advanced/openapi-webhooks.md`. PR [#10712](https://github.com/tiangolo/fastapi/pull/10712) by [@nilslindemann](https://github.com/nilslindemann). From 95d5902af17cf1e260d2ff6e9b5afb22c5a2bb4e Mon Sep 17 00:00:00 2001 From: Aleksandr Andrukhov Date: Tue, 23 Jan 2024 16:55:32 +0300 Subject: [PATCH 182/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Russian=20translat?= =?UTF-8?q?ion=20for=20`docs/ru/docs/tutorial/body-updates.md`=20(#10373)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/tutorial/body-updates.md | 153 ++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 docs/ru/docs/tutorial/body-updates.md diff --git a/docs/ru/docs/tutorial/body-updates.md b/docs/ru/docs/tutorial/body-updates.md new file mode 100644 index 0000000000..4998ab31ac --- /dev/null +++ b/docs/ru/docs/tutorial/body-updates.md @@ -0,0 +1,153 @@ +# Body - ОбĐŊОвĐģĐĩĐŊĐ¸Ņ + +## ПоĐģĐŊĐžĐĩ ОйĐŊОвĐģĐĩĐŊиĐĩ ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ `PUT` + +ДĐģŅ ĐŋĐžĐģĐŊĐžĐŗĐž ОйĐŊОвĐģĐĩĐŊĐ¸Ņ ŅĐģĐĩĐŧĐĩĐŊŅ‚Đ° ĐŧĐžĐļĐŊĐž Đ˛ĐžŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒŅŅ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸ĐĩĐš HTTP `PUT`. + +Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Ņ„ŅƒĐŊĐēŅ†Đ¸ŅŽ `jsonable_encoder` Đ´ĐģŅ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊĐ¸Ņ Đ˛Ņ…ĐžĐ´ĐŊҋ҅ даĐŊĐŊҋ҅ в JSON, Ņ‚Đ°Đē ĐēаĐē ĐŊĐĩŅ€ĐĩĐ´Đēи ҁĐģŅƒŅ‡Đ°Đ¸, ĐēĐžĐŗĐ´Đ° Ņ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ ĐŧĐžĐļĐŊĐž Ņ‚ĐžĐģҌĐēĐž ҁ ĐŋŅ€ĐžŅŅ‚Ņ‹Đŧи Ņ‚Đ¸ĐŋаĐŧи даĐŊĐŊҋ҅ (ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, Đ´ĐģŅ Ņ…Ņ€Đ°ĐŊĐĩĐŊĐ¸Ņ в NoSQL-йаСĐĩ даĐŊĐŊҋ҅). + +=== "Python 3.10+" + + ```Python hl_lines="28-33" + {!> ../../../docs_src/body_updates/tutorial001_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="30-35" + {!> ../../../docs_src/body_updates/tutorial001_py39.py!} + ``` + +=== "Python 3.6+" + + ```Python hl_lines="30-35" + {!> ../../../docs_src/body_updates/tutorial001.py!} + ``` + +`PUT` Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ Đ´ĐģŅ ĐŋĐžĐģŅƒŅ‡ĐĩĐŊĐ¸Ņ даĐŊĐŊҋ҅, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ Đ´ĐžĐģĐļĐŊŅ‹ ĐŋĐžĐģĐŊĐžŅŅ‚ŅŒŅŽ СаĐŧĐĩĐŊĐ¸Ņ‚ŅŒ ŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒŅŽŅ‰Đ¸Đĩ даĐŊĐŊŅ‹Đĩ. + +### ĐŸŅ€ĐĩĐ´ŅƒĐŋŅ€ĐĩĐļĐ´ĐĩĐŊиĐĩ Đž СаĐŧĐĩĐŊĐĩ + +Đ­Ņ‚Đž ОСĐŊĐ°Ņ‡Đ°ĐĩŅ‚, Ņ‡Ņ‚Đž ĐĩҁĐģи Đ˛Ņ‹ Ņ…ĐžŅ‚Đ¸Ņ‚Đĩ ОйĐŊĐžĐ˛Đ¸Ņ‚ŅŒ ŅĐģĐĩĐŧĐĩĐŊŅ‚ `bar`, Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅ `PUT` ҁ Ņ‚ĐĩĐģĐžĐŧ, ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‰Đ¸Đŧ: + +```Python +{ + "name": "Barz", + "price": 3, + "description": None, +} +``` + +ĐŋĐžŅĐēĐžĐģҌĐē҃ ĐžĐŊĐž ĐŊĐĩ вĐēĐģŅŽŅ‡Đ°ĐĩŅ‚ ҃ĐļĐĩ ŅĐžŅ…Ņ€Đ°ĐŊĐĩĐŊĐŊŅ‹Đš Đ°Ņ‚Ņ€Đ¸ĐąŅƒŅ‚ `"tax": 20.2`, Đ˛Ņ…ĐžĐ´ĐŊĐ°Ņ ĐŧОдĐĩĐģҌ ĐŋŅ€Đ¸ĐŧĐĩŅ‚ СĐŊĐ°Ņ‡ĐĩĐŊиĐĩ ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ `"tax": 10.5`. + +И даĐŊĐŊŅ‹Đĩ ĐąŅƒĐ´ŅƒŅ‚ ŅĐžŅ…Ņ€Đ°ĐŊĐĩĐŊŅ‹ ҁ ŅŅ‚Đ¸Đŧ "ĐŊĐžĐ˛Ņ‹Đŧ" `tax`, Ņ€Đ°Đ˛ĐŊŅ‹Đŧ `10,5`. + +## Đ§Đ°ŅŅ‚Đ¸Ņ‡ĐŊĐžĐĩ ОйĐŊОвĐģĐĩĐŊиĐĩ ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ `PATCH` + +ĐĸаĐēĐļĐĩ ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ HTTP `PATCH` ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸ŅŽ Đ´ĐģŅ *Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊĐžĐŗĐž* ОйĐŊОвĐģĐĩĐŊĐ¸Ņ даĐŊĐŊҋ҅. + +Đ­Ņ‚Đž ОСĐŊĐ°Ņ‡Đ°ĐĩŅ‚, Ņ‡Ņ‚Đž ĐŧĐžĐļĐŊĐž ĐŋĐĩŅ€ĐĩĐ´Đ°Đ˛Đ°Ņ‚ŅŒ Ņ‚ĐžĐģҌĐēĐž Ņ‚Đĩ даĐŊĐŊŅ‹Đĩ, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž ОйĐŊĐžĐ˛Đ¸Ņ‚ŅŒ, ĐžŅŅ‚Đ°Đ˛ĐģŅŅ ĐžŅŅ‚Đ°ĐģҌĐŊŅ‹Đĩ ĐŊĐĩŅ‚Ņ€ĐžĐŊŅƒŅ‚Ņ‹Đŧи. + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + `PATCH` ĐŧĐĩĐŊĐĩĐĩ Ņ€Đ°ŅĐŋŅ€ĐžŅŅ‚Ņ€Đ°ĐŊĐĩĐŊ и иСвĐĩҁ҂ĐĩĐŊ, ҇ĐĩĐŧ `PUT`. + + А ĐŧĐŊĐžĐŗĐ¸Đĩ ĐēĐžĐŧаĐŊĐ´Ņ‹ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅŽŅ‚ Ņ‚ĐžĐģҌĐēĐž `PUT`, даĐļĐĩ Đ´ĐģŅ Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊĐžĐŗĐž ОйĐŊОвĐģĐĩĐŊĐ¸Ņ. + + Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ **ŅĐ˛ĐžĐąĐžĐ´ĐŊĐž** Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Đ¸Ņ… ĐēаĐē ŅƒĐŗĐžĐ´ĐŊĐž, **FastAPI** ĐŊĐĩ ĐŊаĐēĐģĐ°Đ´Ņ‹Đ˛Đ°ĐĩŅ‚ ĐŊиĐēаĐēĐ¸Ņ… ĐžĐŗŅ€Đ°ĐŊĐ¸Ņ‡ĐĩĐŊиК. + + Но в даĐŊĐŊĐžĐŧ Ņ€ŅƒĐēĐžĐ˛ĐžĐ´ŅŅ‚Đ˛Đĩ йОĐģĐĩĐĩ иĐģи ĐŧĐĩĐŊĐĩĐĩ ĐŋĐžĐŊŅŅ‚ĐŊĐž, ĐēаĐē ĐžĐŊи Đ´ĐžĐģĐļĐŊŅ‹ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒŅŅ. + +### Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `exclude_unset` в Pydantic + +Đ•ŅĐģи ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž Đ˛Ņ‹ĐŋĐžĐģĐŊĐ¸Ņ‚ŅŒ Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊĐžĐĩ ОйĐŊОвĐģĐĩĐŊиĐĩ, Ņ‚Đž ĐžŅ‡ĐĩĐŊҌ ĐŋĐžĐģĐĩСĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐŋĐ°Ņ€Đ°ĐŧĐĩ҂Ҁ `exclude_unset` в ĐŧĐĩŅ‚ĐžĐ´Đĩ `.dict()` ĐŧОдĐĩĐģи Pydantic. + +НаĐŋŅ€Đ¸ĐŧĐĩŅ€, `item.dict(exclude_unset=True)`. + +В Ņ€ĐĩĐˇŅƒĐģŅŒŅ‚Đ°Ņ‚Đĩ ĐąŅƒĐ´ĐĩŅ‚ ŅĐŗĐĩĐŊĐĩŅ€Đ¸Ņ€ĐžĐ˛Đ°ĐŊ ҁĐģĐžĐ˛Đ°Ņ€ŅŒ, ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‰Đ¸Đš Ņ‚ĐžĐģҌĐēĐž Ņ‚Đĩ даĐŊĐŊŅ‹Đĩ, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐąŅ‹Đģи СадаĐŊŅ‹ ĐŋŅ€Đ¸ ŅĐžĐˇĐ´Đ°ĐŊии ĐŧОдĐĩĐģи `item`, ĐąĐĩС ŅƒŅ‡ĐĩŅ‚Đ° СĐŊĐ°Ņ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ. Đ—Đ°Ņ‚ĐĩĐŧ Đ˛Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ŅŅ‚Đž Đ´ĐģŅ ŅĐžĐˇĐ´Đ°ĐŊĐ¸Ņ ҁĐģĐžĐ˛Đ°Ņ€Ņ Ņ‚ĐžĐģҌĐēĐž ҁ Ņ‚ĐĩĐŧи даĐŊĐŊŅ‹Đŧи, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐąŅ‹Đģи ŅƒŅŅ‚Đ°ĐŊОвĐģĐĩĐŊŅ‹ (ĐžŅ‚ĐŋŅ€Đ°Đ˛ĐģĐĩĐŊŅ‹ в СаĐŋŅ€ĐžŅĐĩ), ĐžĐŋ҃ҁĐēĐ°Ņ СĐŊĐ°Ņ‡ĐĩĐŊĐ¸Ņ ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ: + +=== "Python 3.10+" + + ```Python hl_lines="32" + {!> ../../../docs_src/body_updates/tutorial002_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="34" + {!> ../../../docs_src/body_updates/tutorial002_py39.py!} + ``` + +=== "Python 3.6+" + + ```Python hl_lines="34" + {!> ../../../docs_src/body_updates/tutorial002.py!} + ``` + +### Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `update` в Pydantic + +ĐĸĐĩĐŋĐĩŅ€ŅŒ ĐŧĐžĐļĐŊĐž ŅĐžĐˇĐ´Đ°Ņ‚ŅŒ ĐēĐžĐŋĐ¸ŅŽ ŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒŅŽŅ‰ĐĩĐš ĐŧОдĐĩĐģи, Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅ `.copy()`, и ĐŋĐĩŅ€ĐĩĐ´Đ°Ņ‚ŅŒ ĐŋĐ°Ņ€Đ°ĐŧĐĩ҂Ҁ `update` ҁ `dict`, ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‰Đ¸Đŧ даĐŊĐŊŅ‹Đĩ Đ´ĐģŅ ОйĐŊОвĐģĐĩĐŊĐ¸Ņ. + +НаĐŋŅ€Đ¸ĐŧĐĩŅ€, `stored_item_model.copy(update=update_data)`: + +=== "Python 3.10+" + + ```Python hl_lines="33" + {!> ../../../docs_src/body_updates/tutorial002_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="35" + {!> ../../../docs_src/body_updates/tutorial002_py39.py!} + ``` + +=== "Python 3.6+" + + ```Python hl_lines="35" + {!> ../../../docs_src/body_updates/tutorial002.py!} + ``` + +### ĐšŅ€Đ°Ņ‚ĐēĐž Đž Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊĐžĐŧ ОйĐŊОвĐģĐĩĐŊии + +В ҆ĐĩĐģĐžĐŧ, Đ´ĐģŅ ĐŋŅ€Đ¸ĐŧĐĩĐŊĐĩĐŊĐ¸Ņ Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊҋ҅ ОйĐŊОвĐģĐĩĐŊиК ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž: + +* (ОĐŋŅ†Đ¸ĐžĐŊаĐģҌĐŊĐž) Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ `PATCH` вĐŧĐĩŅŅ‚Đž `PUT`. +* ИСвĐģĐĩŅ‡ŅŒ ŅĐžŅ…Ņ€Đ°ĐŊŅ‘ĐŊĐŊŅ‹Đĩ даĐŊĐŊŅ‹Đĩ. +* ПоĐŧĐĩŅŅ‚Đ¸Ņ‚ŅŒ ŅŅ‚Đ¸ даĐŊĐŊŅ‹Đĩ в Pydantic ĐŧОдĐĩĐģҌ. +* ĐĄĐŗĐĩĐŊĐĩŅ€Đ¸Ņ€ĐžĐ˛Đ°Ņ‚ŅŒ `dict` ĐąĐĩС СĐŊĐ°Ņ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ иС Đ˛Ņ…ĐžĐ´ĐŊОК ĐŧОдĐĩĐģи (ҁ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩĐŧ `exclude_unset`). + * ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, ĐŧĐžĐļĐŊĐž ОйĐŊОвĐģŅŅ‚ŅŒ Ņ‚ĐžĐģҌĐēĐž Ņ‚Đĩ СĐŊĐ°Ņ‡ĐĩĐŊĐ¸Ņ, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ Đ´ĐĩĐšŅŅ‚Đ˛Đ¸Ņ‚ĐĩĐģҌĐŊĐž ŅƒŅŅ‚Đ°ĐŊОвĐģĐĩĐŊŅ‹ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģĐĩĐŧ, вĐŧĐĩŅŅ‚Đž Ņ‚ĐžĐŗĐž Ņ‡Ņ‚ĐžĐąŅ‹ ĐŋĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģŅŅ‚ŅŒ СĐŊĐ°Ņ‡ĐĩĐŊĐ¸Ņ, ҃ĐļĐĩ ŅĐžŅ…Ņ€Đ°ĐŊĐĩĐŊĐŊŅ‹Đĩ в ĐŧОдĐĩĐģи ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ. +* ĐĄĐžĐˇĐ´Đ°Ņ‚ŅŒ ĐēĐžĐŋĐ¸ŅŽ Ņ…Ņ€Đ°ĐŊиĐŧОК ĐŧОдĐĩĐģи, ОйĐŊОвив ĐĩĐĩ Đ°Ņ‚Ņ€Đ¸ĐąŅƒŅ‚Ņ‹ ĐŋĐžĐģŅƒŅ‡ĐĩĐŊĐŊŅ‹Đŧи Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊŅ‹Đŧи ОйĐŊОвĐģĐĩĐŊĐ¸ŅĐŧи (ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `update`). +* ĐŸŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°Ņ‚ŅŒ ҁĐēĐžĐŋĐ¸Ņ€ĐžĐ˛Đ°ĐŊĐŊŅƒŅŽ ĐŧОдĐĩĐģҌ в Ņ‚Đž, Ņ‡Ņ‚Đž ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ ŅĐžŅ…Ņ€Đ°ĐŊĐĩĐŊĐž в Đ˛Đ°ŅˆĐĩĐš БД (ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ `jsonable_encoder`). + * Đ­Ņ‚Đž ŅŅ€Đ°Đ˛ĐŊиĐŧĐž ҁ ĐŋĐžĐ˛Ņ‚ĐžŅ€ĐŊŅ‹Đŧ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩĐŧ ĐŧĐĩŅ‚ĐžĐ´Đ° ĐŧОдĐĩĐģи `.dict()`, ĐŊĐž ĐŋŅ€Đ¸ ŅŅ‚ĐžĐŧ ĐŋŅ€ĐžĐ¸ŅŅ…ĐžĐ´Đ¸Ņ‚ ĐŋŅ€ĐžĐ˛ĐĩŅ€Đēа (и ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊиĐĩ) СĐŊĐ°Ņ‡ĐĩĐŊиК в Ņ‚Đ¸ĐŋŅ‹ даĐŊĐŊҋ҅, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐŧĐžĐŗŅƒŅ‚ ĐąŅ‹Ņ‚ŅŒ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊŅ‹ в JSON, ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, `datetime` в `str`. +* ĐĄĐžŅ…Ņ€Đ°ĐŊĐ¸Ņ‚ŅŒ даĐŊĐŊŅ‹Đĩ в ŅĐ˛ĐžĐĩĐš БД. +* ВĐĩŅ€ĐŊŅƒŅ‚ŅŒ ОйĐŊОвĐģĐĩĐŊĐŊŅƒŅŽ ĐŧОдĐĩĐģҌ. + +=== "Python 3.10+" + + ```Python hl_lines="28-35" + {!> ../../../docs_src/body_updates/tutorial002_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="30-37" + {!> ../../../docs_src/body_updates/tutorial002_py39.py!} + ``` + +=== "Python 3.6+" + + ```Python hl_lines="30-37" + {!> ../../../docs_src/body_updates/tutorial002.py!} + ``` + +!!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + Đ­Ņ‚Ņƒ ĐļĐĩ Ņ‚ĐĩŅ…ĐŊиĐē҃ ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ и Đ´ĐģŅ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸ HTTP `PUT`. + + Но в ĐŋŅ€Đ¸Đ˛ĐĩĐ´ĐĩĐŊĐŊĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ `PATCH`, ĐŋĐžŅĐēĐžĐģҌĐē҃ ĐžĐŊ ĐąŅ‹Đģ ŅĐžĐˇĐ´Đ°ĐŊ иĐŧĐĩĐŊĐŊĐž Đ´ĐģŅ Ņ‚Đ°ĐēĐ¸Ņ… ҁĐģŅƒŅ‡Đ°Đĩв Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊĐ¸Ņ. + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + ĐžĐąŅ€Đ°Ņ‚Đ¸Ņ‚Đĩ вĐŊиĐŧаĐŊиĐĩ, Ņ‡Ņ‚Đž Đ˛Ņ…ĐžĐ´ĐŊĐ°Ņ ĐŧОдĐĩĐģҌ ĐŋĐž-ĐŋŅ€ĐĩĐļĐŊĐĩĐŧ҃ ваĐģĐ¸Đ´Đ¸Ņ€ŅƒĐĩŅ‚ŅŅ. + + ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, ĐĩҁĐģи Đ˛Ņ‹ Ņ…ĐžŅ‚Đ¸Ņ‚Đĩ ĐŋĐžĐģŅƒŅ‡Đ°Ņ‚ŅŒ Ņ‡Đ°ŅŅ‚Đ¸Ņ‡ĐŊŅ‹Đĩ ОйĐŊОвĐģĐĩĐŊĐ¸Ņ, в ĐēĐžŅ‚ĐžŅ€Ņ‹Ņ… ĐŧĐžĐŗŅƒŅ‚ ĐąŅ‹Ņ‚ŅŒ ĐžĐŋŅƒŅ‰ĐĩĐŊŅ‹ Đ˛ŅĐĩ Đ°Ņ‚Ņ€Đ¸ĐąŅƒŅ‚Ņ‹, ваĐŧ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž иĐŧĐĩŅ‚ŅŒ ĐŧОдĐĩĐģҌ, в ĐēĐžŅ‚ĐžŅ€ĐžĐš Đ˛ŅĐĩ Đ°Ņ‚Ņ€Đ¸ĐąŅƒŅ‚Ņ‹ ĐŋĐžĐŧĐĩ҇ĐĩĐŊŅ‹ ĐēаĐē ĐŊĐĩĐžĐąŅĐˇĐ°Ņ‚ĐĩĐģҌĐŊŅ‹Đĩ (ŅĐž СĐŊĐ°Ņ‡ĐĩĐŊĐ¸ŅĐŧи ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ иĐģи `None`). + + Đ§Ņ‚ĐžĐąŅ‹ ĐžŅ‚ĐģĐ¸Ņ‡Đ¸Ņ‚ŅŒ ĐŧОдĐĩĐģи ŅĐž Đ˛ŅĐĩĐŧи ĐŊĐĩĐžĐąŅĐˇĐ°Ņ‚ĐĩĐģҌĐŊŅ‹Đŧи СĐŊĐ°Ņ‡ĐĩĐŊĐ¸ŅĐŧи Đ´ĐģŅ **ОйĐŊОвĐģĐĩĐŊĐ¸Ņ** ĐžŅ‚ ĐŧОдĐĩĐģĐĩĐš ҁ ĐžĐąŅĐˇĐ°Ņ‚ĐĩĐģҌĐŊŅ‹Đŧи СĐŊĐ°Ņ‡ĐĩĐŊĐ¸ŅĐŧи Đ´ĐģŅ **ŅĐžĐˇĐ´Đ°ĐŊĐ¸Ņ**, ĐŧĐžĐļĐŊĐž Đ˛ĐžŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒŅŅ идĐĩŅĐŧи, ĐžĐŋĐ¸ŅĐ°ĐŊĐŊŅ‹Đŧи в [ДоĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đĩ ĐŧОдĐĩĐģи](extra-models.md){.internal-link target=_blank}. From 672b501b98c5d3b2589b6092080e4da8fc9ba835 Mon Sep 17 00:00:00 2001 From: Aleksandr Andrukhov Date: Tue, 23 Jan 2024 16:56:12 +0300 Subject: [PATCH 183/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Russian=20translat?= =?UTF-8?q?ion=20for=20`docs/ru/docs/tutorial/encoder.md`=20(#10374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/tutorial/encoder.md | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 docs/ru/docs/tutorial/encoder.md diff --git a/docs/ru/docs/tutorial/encoder.md b/docs/ru/docs/tutorial/encoder.md new file mode 100644 index 0000000000..c26b2c9411 --- /dev/null +++ b/docs/ru/docs/tutorial/encoder.md @@ -0,0 +1,42 @@ +# JSON ĐēĐžĐ´Đ¸Ņ€ĐžĐ˛Ņ‰Đ¸Đē + +В ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Ņ… ҁĐģŅƒŅ‡Đ°ŅŅ… ĐŧĐžĐļĐĩŅ‚ ĐŋĐžŅ‚Ņ€ĐĩĐąĐžĐ˛Đ°Ņ‚ŅŒŅŅ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊиĐĩ Ņ‚Đ¸Đŋа даĐŊĐŊҋ҅ (ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, Pydantic-ĐŧОдĐĩĐģи) в Ņ‚Đ¸Đŋ, ŅĐžĐ˛ĐŧĐĩŅŅ‚Đ¸ĐŧŅ‹Đš ҁ JSON (ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, `dict`, `list` и Ņ‚.Đ´.). + +НаĐŋŅ€Đ¸ĐŧĐĩŅ€, ĐĩҁĐģи ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž Ņ…Ņ€Đ°ĐŊĐ¸Ņ‚ŅŒ ĐĩĐŗĐž в йаСĐĩ даĐŊĐŊҋ҅. + +ДĐģŅ ŅŅ‚ĐžĐŗĐž **FastAPI** ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅĐĩŅ‚ Ņ„ŅƒĐŊĐēŅ†Đ¸ŅŽ `jsonable_encoder()`. + +## Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ `jsonable_encoder` + +ĐŸŅ€ĐĩĐ´ŅŅ‚Đ°Đ˛Đ¸Đŧ, Ņ‡Ņ‚Đž ҃ Đ˛Đ°Ņ ĐĩŅŅ‚ŅŒ йаСа даĐŊĐŊҋ҅ `fake_db`, ĐēĐžŅ‚ĐžŅ€Đ°Ņ ĐŋŅ€Đ¸ĐŊиĐŧаĐĩŅ‚ Ņ‚ĐžĐģҌĐēĐž JSON-ŅĐžĐ˛ĐŧĐĩŅŅ‚Đ¸ĐŧŅ‹Đĩ даĐŊĐŊŅ‹Đĩ. + +НаĐŋŅ€Đ¸ĐŧĐĩŅ€, ĐžĐŊ ĐŊĐĩ ĐŋŅ€Đ¸ĐŊиĐŧаĐĩŅ‚ ĐžĐąŅŠĐĩĐē҂ҋ `datetime`, Ņ‚Đ°Đē ĐēаĐē ĐžĐŊи ĐŊĐĩ ŅĐžĐ˛ĐŧĐĩŅŅ‚Đ¸ĐŧŅ‹ ҁ JSON. + +В Ņ‚Đ°ĐēĐžĐŧ ҁĐģŅƒŅ‡Đ°Đĩ ĐžĐąŅŠĐĩĐēŅ‚ `datetime` ҁĐģĐĩĐ´ŅƒĐĩŅ‚ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°Ņ‚ŅŒ в ŅŅ‚Ņ€ĐžĐē҃ ŅĐžĐžŅ‚Đ˛ĐĩŅ‚ŅŅ‚Đ˛ŅƒŅŽŅ‰ŅƒŅŽ Ņ„ĐžŅ€ĐŧĐ°Ņ‚Ņƒ ISO. + +ĐĸĐžŅ‡ĐŊĐž Ņ‚Đ°Đē ĐļĐĩ ŅŅ‚Đ° йаСа даĐŊĐŊҋ҅ ĐŊĐĩ ĐŧĐžĐļĐĩŅ‚ ĐŋŅ€Đ¸ĐŊŅŅ‚ŅŒ Pydantic ĐŧОдĐĩĐģҌ (ĐžĐąŅŠĐĩĐēŅ‚ ҁ Đ°Ņ‚Ņ€Đ¸ĐąŅƒŅ‚Đ°Đŧи), а Ņ‚ĐžĐģҌĐēĐž `dict`. + +ДĐģŅ ŅŅ‚ĐžĐŗĐž ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Ņ„ŅƒĐŊĐēŅ†Đ¸ŅŽ `jsonable_encoder`. + +ОĐŊа ĐŋŅ€Đ¸ĐŊиĐŧаĐĩŅ‚ ĐžĐąŅŠĐĩĐēŅ‚, ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, ĐŧОдĐĩĐģҌ Pydantic, и Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ĐĩŅ‚ ĐĩĐŗĐž вĐĩŅ€ŅĐ¸ŅŽ, ŅĐžĐ˛ĐŧĐĩŅŅ‚Đ¸ĐŧŅƒŅŽ ҁ JSON: + +=== "Python 3.10+" + + ```Python hl_lines="4 21" + {!> ../../../docs_src/encoder/tutorial001_py310.py!} + ``` + +=== "Python 3.6+" + + ```Python hl_lines="5 22" + {!> ../../../docs_src/encoder/tutorial001.py!} + ``` + +В даĐŊĐŊĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ ĐžĐŊа ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇŅƒĐĩŅ‚ Pydantic ĐŧОдĐĩĐģҌ в `dict`, а `datetime` - в `str`. + +Đ ĐĩĐˇŅƒĐģŅŒŅ‚Đ°Ņ‚ĐžĐŧ ĐĩŅ‘ Đ˛Ņ‹ĐˇĐžĐ˛Đ° ŅĐ˛ĐģŅĐĩŅ‚ŅŅ ĐžĐąŅŠĐĩĐēŅ‚, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ СаĐēĐžĐ´Đ¸Ņ€ĐžĐ˛Đ°ĐŊ ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸ иС ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊОК йийĐģĐ¸ĐžŅ‚ĐĩĐēи Python – `json.dumps()`. + +Đ¤ŅƒĐŊĐēŅ†Đ¸Ņ ĐŊĐĩ Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ĐĩŅ‚ йОĐģŅŒŅˆĐžĐš `str`, ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‰Đ¸Đš даĐŊĐŊŅ‹Đĩ в Ņ„ĐžŅ€ĐŧĐ°Ņ‚Đĩ JSON (в видĐĩ ŅŅ‚Ņ€ĐžĐēи). ОĐŊа Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ĐĩŅ‚ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊŅƒŅŽ ŅŅ‚Ņ€ŅƒĐēŅ‚ŅƒŅ€Ņƒ даĐŊĐŊҋ҅ Python (ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€, `dict`) ŅĐž СĐŊĐ°Ņ‡ĐĩĐŊĐ¸ŅĐŧи и ĐŋОдСĐŊĐ°Ņ‡ĐĩĐŊĐ¸ŅĐŧи, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ŅĐžĐ˛ĐŧĐĩŅŅ‚Đ¸ĐŧŅ‹ ҁ JSON. + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + `jsonable_encoder` Ņ„Đ°ĐēŅ‚Đ¸Ņ‡ĐĩҁĐēи Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ **FastAPI** вĐŊŅƒŅ‚Ņ€Đ¸ ŅĐ¸ŅŅ‚ĐĩĐŧŅ‹ Đ´ĐģŅ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊĐ¸Ņ даĐŊĐŊҋ҅. ОдĐŊаĐēĐž ĐžĐŊ ĐŋĐžĐģĐĩСĐĩĐŊ и вО ĐŧĐŊĐžĐŗĐ¸Ņ… Đ´Ņ€ŅƒĐŗĐ¸Ņ… ҁ҆ĐĩĐŊĐ°Ņ€Đ¸ŅŅ…. From ac5e73b19dd09a60e49097de1ce0068b4f5464e1 Mon Sep 17 00:00:00 2001 From: Aleksandr Andrukhov Date: Tue, 23 Jan 2024 16:56:29 +0300 Subject: [PATCH 184/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Russian=20translat?= =?UTF-8?q?ion=20for=20`docs/ru/docs/tutorial/handling-errors.md`=20(#1037?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/tutorial/handling-errors.md | 261 +++++++++++++++++++++++ 1 file changed, 261 insertions(+) create mode 100644 docs/ru/docs/tutorial/handling-errors.md diff --git a/docs/ru/docs/tutorial/handling-errors.md b/docs/ru/docs/tutorial/handling-errors.md new file mode 100644 index 0000000000..f578cf1983 --- /dev/null +++ b/docs/ru/docs/tutorial/handling-errors.md @@ -0,0 +1,261 @@ +# ĐžĐąŅ€Đ°ĐąĐžŅ‚Đēа ĐžŅˆĐ¸ĐąĐžĐē + +ĐĄŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒĐĩŅ‚ ĐŧĐŊĐžĐļĐĩŅŅ‚Đ˛Đž ŅĐ¸Ņ‚ŅƒĐ°Ņ†Đ¸Đš, ĐēĐžĐŗĐ´Đ° ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž ŅĐžĐžĐąŅ‰Đ¸Ņ‚ŅŒ Ой ĐžŅˆĐ¸ĐąĐēĐĩ ĐēĐģиĐĩĐŊŅ‚Ņƒ, Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅŽŅ‰ĐĩĐŧ҃ Đ˛Đ°Ņˆ API. + +ĐĸаĐēиĐŧ ĐēĐģиĐĩĐŊŅ‚ĐžĐŧ ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ ĐąŅ€Đ°ŅƒĐˇĐĩŅ€ ҁ Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´ĐžĐŧ, Ņ‡ŅƒĐļОК ĐēОд, IoT-ŅƒŅŅ‚Ņ€ĐžĐšŅŅ‚Đ˛Đž и Ņ‚.Đ´. + +ВозĐŧĐžĐļĐŊĐž, ваĐŧ ĐŋŅ€Đ¸Đ´ĐĩŅ‚ŅŅ ŅĐžĐžĐąŅ‰Đ¸Ņ‚ŅŒ ĐēĐģиĐĩĐŊŅ‚Ņƒ Đž ҁĐģĐĩĐ´ŅƒŅŽŅ‰ĐĩĐŧ: + +* КĐģиĐĩĐŊŅ‚ ĐŊĐĩ иĐŧĐĩĐĩŅ‚ Đ´ĐžŅŅ‚Đ°Ņ‚ĐžŅ‡ĐŊҋ҅ ĐŋŅ€Đ¸Đ˛Đ¸ĐģĐĩĐŗĐ¸Đš Đ´ĐģŅ Đ˛Ņ‹ĐŋĐžĐģĐŊĐĩĐŊĐ¸Ņ даĐŊĐŊОК ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸. +* КĐģиĐĩĐŊŅ‚ ĐŊĐĩ иĐŧĐĩĐĩŅ‚ Đ´ĐžŅŅ‚ŅƒĐŋа Đē даĐŊĐŊĐžĐŧ҃ Ņ€ĐĩŅŅƒŅ€ŅŅƒ. +* Đ­ĐģĐĩĐŧĐĩĐŊŅ‚, Đē ĐēĐžŅ‚ĐžŅ€ĐžĐŧ҃ ĐēĐģиĐĩĐŊŅ‚ ĐŋŅ‹Ņ‚Đ°ĐģŅŅ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ŅŒ Đ´ĐžŅŅ‚ŅƒĐŋ, ĐŊĐĩ ŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒĐĩŅ‚. +* и Ņ‚.Đ´. + +В Ņ‚Đ°ĐēĐ¸Ņ… ҁĐģŅƒŅ‡Đ°ŅŅ… ĐžĐąŅ‹Ņ‡ĐŊĐž Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ĐĩŅ‚ŅŅ **HTTP-ĐēОд ŅŅ‚Đ°Ņ‚ŅƒŅĐ° ĐžŅ‚Đ˛ĐĩŅ‚Đ°** в диаĐŋаСОĐŊĐĩ **400** (ĐžŅ‚ 400 Đ´Đž 499). + +ОĐŊи ĐŋĐžŅ…ĐžĐļи ĐŊа Đ´Đ˛ŅƒŅ…ŅĐžŅ‚Ņ‹Đĩ HTTP ŅŅ‚Đ°Ņ‚ŅƒŅ-ĐēĐžĐ´Ņ‹ (ĐžŅ‚ 200 Đ´Đž 299), ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ОСĐŊĐ°Ņ‡Đ°ŅŽŅ‚, Ņ‡Ņ‚Đž СаĐŋŅ€ĐžŅ ĐžĐąŅ€Đ°ĐąĐžŅ‚Đ°ĐŊ ҃ҁĐŋĐĩ҈ĐŊĐž. + +ЧĐĩŅ‚Ņ‹Ņ€Ņ‘Ņ…ŅĐžŅ‚Ņ‹Đĩ ŅŅ‚Đ°Ņ‚ŅƒŅ-ĐēĐžĐ´Ņ‹ ОСĐŊĐ°Ņ‡Đ°ŅŽŅ‚, Ņ‡Ņ‚Đž ĐžŅˆĐ¸ĐąĐēа ĐŋŅ€ĐžĐ¸ĐˇĐžŅˆĐģа ĐŋĐž виĐŊĐĩ ĐēĐģиĐĩĐŊŅ‚Đ°. + +ПоĐŧĐŊĐ¸Ņ‚Đĩ Đģи ĐžŅˆĐ¸ĐąĐēи **"404 Not Found "** (и ŅˆŅƒŅ‚Đēи) ? + +## Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ `HTTPException` + +ДĐģŅ Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‚Đ° ĐēĐģиĐĩĐŊŅ‚Ņƒ HTTP-ĐžŅ‚Đ˛ĐĩŅ‚ĐžĐ˛ ҁ ĐžŅˆĐ¸ĐąĐēаĐŧи Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ `HTTPException`. + +### ИĐŧĐŋĐžŅ€Ņ‚Đ¸Ņ€ŅƒĐšŅ‚Đĩ `HTTPException` + +```Python hl_lines="1" +{!../../../docs_src/handling_errors/tutorial001.py!} +``` + +### Đ’Ņ‹ĐˇĐžĐ˛Đ¸Ņ‚Đĩ `HTTPException` в ŅĐ˛ĐžĐĩĐŧ ĐēОдĐĩ + +`HTTPException` - ŅŅ‚Đž ĐžĐąŅ‹Ņ‡ĐŊĐžĐĩ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ Python ҁ Đ´ĐžĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đŧи даĐŊĐŊŅ‹Đŧи, аĐēŅ‚ŅƒĐ°ĐģҌĐŊŅ‹Đŧи Đ´ĐģŅ API. + +ĐŸĐžŅĐēĐžĐģҌĐē҃ ŅŅ‚Đž Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ Python, Ņ‚Đž ĐĩĐŗĐž ĐŊĐĩ `Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ŅŽŅ‚`, а `Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°ŅŽŅ‚`. + +Đ­Ņ‚Đž Ņ‚Đ°ĐēĐļĐĩ ОСĐŊĐ°Ņ‡Đ°ĐĩŅ‚, Ņ‡Ņ‚Đž ĐĩҁĐģи Đ˛Ņ‹ ĐŊĐ°Ņ…ĐžĐ´Đ¸Ņ‚ĐĩҁҌ вĐŊŅƒŅ‚Ņ€Đ¸ Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸, ĐēĐžŅ‚ĐžŅ€Đ°Ņ Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°ĐĩŅ‚ŅŅ вĐŊŅƒŅ‚Ņ€Đ¸ Đ˛Đ°ŅˆĐĩĐš *Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸ ĐŋŅƒŅ‚Đ¸*, и Đ˛Ņ‹ ĐŋОдĐŊиĐŧаĐĩŅ‚Đĩ `HTTPException` вĐŊŅƒŅ‚Ņ€Đ¸ ŅŅ‚ĐžĐš Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸, Ņ‚Đž ĐžĐŊа ĐŊĐĩ ĐąŅƒĐ´ĐĩŅ‚ Đ˛Ņ‹ĐŋĐžĐģĐŊŅŅ‚ŅŒ ĐžŅŅ‚Đ°ĐģҌĐŊОК ĐēОд в *Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸ ĐŋŅƒŅ‚Đ¸*, а ŅŅ€Đ°ĐˇŅƒ СавĐĩŅ€ŅˆĐ¸Ņ‚ СаĐŋŅ€ĐžŅ и ĐžŅ‚ĐŋŅ€Đ°Đ˛Đ¸Ņ‚ HTTP-ĐžŅˆĐ¸ĐąĐē҃ иС `HTTPException` ĐēĐģиĐĩĐŊŅ‚Ņƒ. + +О Ņ‚ĐžĐŧ, ĐŊĐ°ŅĐēĐžĐģҌĐēĐž Đ˛Ņ‹ĐŗĐžĐ´ĐŊĐĩĐĩ `Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°Ņ‚ŅŒ` Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ, ҇ĐĩĐŧ `Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°Ņ‚ŅŒ` СĐŊĐ°Ņ‡ĐĩĐŊиĐĩ, ĐąŅƒĐ´ĐĩŅ‚ Ņ€Đ°ŅŅĐēаСаĐŊĐž в Ņ€Đ°ĐˇĐ´ĐĩĐģĐĩ, ĐŋĐžŅĐ˛ŅŅ‰ĐĩĐŊĐŊĐžĐŧ ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚ŅĐŧ и ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸. + +В даĐŊĐŊĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ, ĐēĐžĐŗĐ´Đ° ĐēĐģиĐĩĐŊŅ‚ СаĐŋŅ€Đ°ŅˆĐ¸Đ˛Đ°ĐĩŅ‚ ŅĐģĐĩĐŧĐĩĐŊŅ‚ ĐŋĐž ĐŊĐĩŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒŅŽŅ‰ĐĩĐŧ҃ ID, вОСĐŊиĐēаĐĩŅ‚ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ ŅĐž ŅŅ‚Đ°Ņ‚ŅƒŅ-ĐēОдОĐŧ `404`: + +```Python hl_lines="11" +{!../../../docs_src/handling_errors/tutorial001.py!} +``` + +### Đ’ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°ĐĩĐŧŅ‹Đš ĐžŅ‚Đ˛ĐĩŅ‚ + +Đ•ŅĐģи ĐēĐģиĐĩĐŊŅ‚ СаĐŋŅ€ĐžŅĐ¸Ņ‚ `http://example.com/items/foo` (`item_id` `"foo"`), Ņ‚Đž ĐžĐŊ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ ŅŅ‚Đ°Ņ‚ŅƒŅ-ĐēОд 200 и ĐžŅ‚Đ˛ĐĩŅ‚ в Ņ„ĐžŅ€ĐŧĐ°Ņ‚Đĩ JSON: + +```JSON +{ + "item": "The Foo Wrestlers" +} +``` + +Но ĐĩҁĐģи ĐēĐģиĐĩĐŊŅ‚ СаĐŋŅ€ĐžŅĐ¸Ņ‚ `http://example.com/items/bar` (ĐŊĐĩŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒŅŽŅ‰Đ¸Đš `item_id` `"bar"`), Ņ‚Đž ĐžĐŊ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ ŅŅ‚Đ°Ņ‚ŅƒŅ-ĐēОд 404 (ĐžŅˆĐ¸ĐąĐēа "ĐŊĐĩ ĐŊаКдĐĩĐŊĐž") и JSON-ĐžŅ‚Đ˛ĐĩŅ‚ в видĐĩ: + +```JSON +{ + "detail": "Item not found" +} +``` + +!!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + ĐŸŅ€Đ¸ Đ˛Ņ‹ĐˇĐžĐ˛Đĩ `HTTPException` в ĐēĐ°Ņ‡ĐĩŅŅ‚Đ˛Đĩ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `detail` ĐŧĐžĐļĐŊĐž ĐŋĐĩŅ€ĐĩĐ´Đ°Đ˛Đ°Ņ‚ŅŒ ĐģŅŽĐąĐžĐĩ СĐŊĐ°Ņ‡ĐĩĐŊиĐĩ, ĐēĐžŅ‚ĐžŅ€ĐžĐĩ ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇĐžĐ˛Đ°ĐŊĐž в JSON, а ĐŊĐĩ Ņ‚ĐžĐģҌĐēĐž `str`. + + Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐŋĐĩŅ€ĐĩĐ´Đ°Ņ‚ŅŒ `dict`, `list` и Ņ‚.Đ´. + + ОĐŊи Đ°Đ˛Ņ‚ĐžĐŧĐ°Ņ‚Đ¸Ņ‡ĐĩҁĐēи ĐžĐąŅ€Đ°ĐąĐ°Ņ‚Ņ‹Đ˛Đ°ŅŽŅ‚ŅŅ **FastAPI** и ĐŋŅ€ĐĩĐžĐąŅ€Đ°ĐˇŅƒŅŽŅ‚ŅŅ в JSON. + +## ДобавĐģĐĩĐŊиĐĩ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēĐ¸Ņ… ĐˇĐ°ĐŗĐžĐģОвĐēОв + +В ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Ņ… ŅĐ¸Ņ‚ŅƒĐ°Ņ†Đ¸ŅŅ… ĐŋĐžĐģĐĩСĐŊĐž иĐŧĐĩŅ‚ŅŒ вОСĐŧĐžĐļĐŊĐžŅŅ‚ŅŒ дОйавĐģŅŅ‚ŅŒ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēиĐĩ ĐˇĐ°ĐŗĐžĐģОвĐēи Đē ĐžŅˆĐ¸ĐąĐēĐĩ HTTP. НаĐŋŅ€Đ¸ĐŧĐĩŅ€, Đ´ĐģŅ ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Ņ… Ņ‚Đ¸ĐŋОв ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸. + +ĐĄĐēĐžŅ€ĐĩĐĩ Đ˛ŅĐĩĐŗĐž, ваĐŧ ĐŊĐĩ ĐŋĐžŅ‚Ņ€ĐĩĐąŅƒĐĩŅ‚ŅŅ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐĩĐŗĐž ĐŊĐĩĐŋĐžŅŅ€ĐĩĐ´ŅŅ‚Đ˛ĐĩĐŊĐŊĐž в ĐēОдĐĩ. + +Но в ҁĐģŅƒŅ‡Đ°Đĩ, ĐĩҁĐģи ŅŅ‚Đž ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž Đ´ĐģŅ ĐŋŅ€ĐžĐ´Đ˛Đ¸ĐŊŅƒŅ‚ĐžĐŗĐž ҁ҆ĐĩĐŊĐ°Ņ€Đ¸Ņ, ĐŧĐžĐļĐŊĐž Đ´ĐžĐąĐ°Đ˛Đ¸Ņ‚ŅŒ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēиĐĩ ĐˇĐ°ĐŗĐžĐģОвĐēи: + +```Python hl_lines="14" +{!../../../docs_src/handling_errors/tutorial002.py!} +``` + +## ĐŖŅŅ‚Đ°ĐŊОвĐēа ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēĐ¸Ņ… ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸ĐēОв Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК + +Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ Đ´ĐžĐąĐ°Đ˛Đ¸Ņ‚ŅŒ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēиĐĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ Ņ‚Đž ĐļĐĩ ŅĐ°ĐŧĐžĐĩ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ - ŅƒŅ‚Đ¸ĐģĐ¸Ņ‚Ņ‹ ĐžŅ‚ Starlette. + +ДоĐŋŅƒŅŅ‚Đ¸Đŧ, ҃ Đ˛Đ°Ņ ĐĩŅŅ‚ŅŒ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌҁĐēĐžĐĩ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ `UnicornException`, ĐēĐžŅ‚ĐžŅ€ĐžĐĩ Đ˛Ņ‹ (иĐģи Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩĐŧĐ°Ņ ваĐŧи йийĐģĐ¸ĐžŅ‚ĐĩĐēа) ĐŧĐžĐļĐĩŅ‚Đĩ `Đ˛Ņ‹ĐˇĐ˛Đ°Ņ‚ŅŒ`. + +И Đ˛Ņ‹ Ņ…ĐžŅ‚Đ¸Ņ‚Đĩ ĐžĐąŅ€Đ°ĐąĐ°Ņ‚Ņ‹Đ˛Đ°Ņ‚ŅŒ ŅŅ‚Đž Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ ĐŗĐģОйаĐģҌĐŊĐž ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ FastAPI. + +МоĐļĐŊĐž Đ´ĐžĐąĐ°Đ˛Đ¸Ņ‚ŅŒ ŅĐžĐąŅŅ‚Đ˛ĐĩĐŊĐŊŅ‹Đš ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ `@app.exception_handler()`: + +```Python hl_lines="5-7 13-18 24" +{!../../../docs_src/handling_errors/tutorial003.py!} +``` + +ЗдĐĩҁҌ, ĐĩҁĐģи СаĐŋŅ€ĐžŅĐ¸Ņ‚ŅŒ `/unicorns/yolo`, Ņ‚Đž *ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Ņ ĐŋŅƒŅ‚Đ¸* Đ˛Ņ‹ĐˇĐžĐ˛ĐĩŅ‚ `UnicornException`. + +Но ĐžĐŊĐž ĐąŅƒĐ´ĐĩŅ‚ ĐžĐąŅ€Đ°ĐąĐžŅ‚Đ°ĐŊĐž `unicorn_exception_handler`. + +ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, Đ˛Ņ‹ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚Đĩ Ņ‡Đ¸ŅŅ‚ŅƒŅŽ ĐžŅˆĐ¸ĐąĐē҃ ҁ ĐēОдОĐŧ ŅĐžŅŅ‚ĐžŅĐŊĐ¸Ņ HTTP `418` и ŅĐžĐ´ĐĩŅ€ĐļиĐŧŅ‹Đŧ JSON: + +```JSON +{"message": "Oops! yolo did something. There goes a rainbow..."} +``` + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + ĐĸаĐēĐļĐĩ ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ `from starlette.requests import Request` и `from starlette.responses import JSONResponse`. + + **FastAPI** ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅĐĩŅ‚ Ņ‚ĐžŅ‚ ĐļĐĩ `starlette.responses`, Ņ‡Ņ‚Đž и `fastapi.responses`, ĐŋŅ€ĐžŅŅ‚Đž Đ´ĐģŅ ŅƒĐ´ĐžĐąŅŅ‚Đ˛Đ° Ņ€Đ°ĐˇŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēа. ОдĐŊаĐēĐž йОĐģŅŒŅˆĐ¸ĐŊŅŅ‚Đ˛Đž Đ´ĐžŅŅ‚ŅƒĐŋĐŊҋ҅ ĐžŅ‚Đ˛ĐĩŅ‚ĐžĐ˛ ĐŋĐžŅŅ‚ŅƒĐŋаĐĩŅ‚ ĐŊĐĩĐŋĐžŅŅ€ĐĩĐ´ŅŅ‚Đ˛ĐĩĐŊĐŊĐž иС Starlette. ĐĸĐž ĐļĐĩ ŅĐ°ĐŧĐžĐĩ ĐēĐ°ŅĐ°ĐĩŅ‚ŅŅ и `Request`. + +## ПĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊиĐĩ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊҋ҅ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸ĐēОв Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК + +**FastAPI** иĐŧĐĩĐĩŅ‚ ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ. + +Đ­Ņ‚Đ¸ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи ĐžŅ‚Đ˛ĐĩŅ‡Đ°ŅŽŅ‚ Са Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‚ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊҋ҅ JSON-ĐžŅ‚Đ˛ĐĩŅ‚ĐžĐ˛ ĐŋŅ€Đ¸ `Đ˛Ņ‹ĐˇĐžĐ˛Đĩ` `HTTPException` и ĐŋŅ€Đ¸ ĐŊаĐģĐ¸Ņ‡Đ¸Đ¸ в СаĐŋŅ€ĐžŅĐĩ ĐŊĐĩĐ´ĐžĐŋŅƒŅŅ‚Đ¸Đŧҋ҅ даĐŊĐŊҋ҅. + +Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐŋĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐ¸Ņ‚ŅŒ ŅŅ‚Đ¸ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŊа ŅĐ˛ĐžĐ¸ ŅĐžĐąŅŅ‚Đ˛ĐĩĐŊĐŊŅ‹Đĩ. + +### ПĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊиĐĩ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŋŅ€ĐžĐ˛ĐĩŅ€Đēи СаĐŋŅ€ĐžŅĐ° + +ĐšĐžĐŗĐ´Đ° СаĐŋŅ€ĐžŅ ŅĐžĐ´ĐĩŅ€ĐļĐ¸Ņ‚ ĐŊĐĩĐ´ĐžĐŋŅƒŅŅ‚Đ¸ĐŧŅ‹Đĩ даĐŊĐŊŅ‹Đĩ, **FastAPI** вĐŊŅƒŅ‚Ņ€ĐĩĐŊĐŊĐĩ Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°ĐĩŅ‚ ĐžŅˆĐ¸ĐąĐē҃ `RequestValidationError`. + +А Ņ‚Đ°ĐēĐļĐĩ вĐēĐģŅŽŅ‡Đ°ĐĩŅ‚ в ҁĐĩĐąŅ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ. + +Đ§Ņ‚ĐžĐąŅ‹ ĐŋĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐ¸Ņ‚ŅŒ ĐĩĐŗĐž, иĐŧĐŋĐžŅ€Ņ‚Đ¸Ņ€ŅƒĐšŅ‚Đĩ `RequestValidationError` и Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐšŅ‚Đĩ ĐĩĐŗĐž ҁ `@app.exception_handler(RequestValidationError)` Đ´ĐģŅ ŅĐžĐˇĐ´Đ°ĐŊĐ¸Ņ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēа Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК. + +ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊĐ¸Ņ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ ĐžĐąŅŠĐĩĐēŅ‚ `Request` и Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ. + +```Python hl_lines="2 14-16" +{!../../../docs_src/handling_errors/tutorial004.py!} +``` + +ĐĸĐĩĐŋĐĩŅ€ŅŒ, ĐĩҁĐģи ĐŋĐĩŅ€ĐĩĐšŅ‚Đ¸ Đē `/items/foo`, Ņ‚Đž вĐŧĐĩŅŅ‚Đž ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊОК JSON-ĐžŅˆĐ¸ĐąĐēи ҁ: + +```JSON +{ + "detail": [ + { + "loc": [ + "path", + "item_id" + ], + "msg": "value is not a valid integer", + "type": "type_error.integer" + } + ] +} +``` + +Đ˛Ņ‹ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚Đĩ Ņ‚ĐĩĐēŅŅ‚ĐžĐ˛ŅƒŅŽ вĐĩŅ€ŅĐ¸ŅŽ: + +``` +1 validation error +path -> item_id + value is not a valid integer (type=type_error.integer) +``` + +#### `RequestValidationError` иĐģи `ValidationError` + +!!! warning "ВĐŊиĐŧаĐŊиĐĩ" + Đ­Ņ‚Đž Ņ‚ĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐŧĐžĐļĐŊĐž ĐŋŅ€ĐžĐŋŅƒŅŅ‚Đ¸Ņ‚ŅŒ, ĐĩҁĐģи ĐžĐŊи ĐŊĐĩ ваĐļĐŊŅ‹ Đ´ĐģŅ Đ˛Đ°Ņ ҁĐĩĐšŅ‡Đ°Ņ. + +`RequestValidationError` ŅĐ˛ĐģŅĐĩŅ‚ŅŅ ĐŋОдĐēĐģĐ°ŅŅĐžĐŧ Pydantic `ValidationError`. + +**FastAPI** Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ ĐĩĐŗĐž Đ´ĐģŅ Ņ‚ĐžĐŗĐž, Ņ‡Ņ‚ĐžĐąŅ‹, ĐĩҁĐģи Đ˛Ņ‹ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚Đĩ Pydantic-ĐŧОдĐĩĐģҌ в `response_model`, и Đ˛Đ°ŅˆĐ¸ даĐŊĐŊŅ‹Đĩ ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‚ ĐžŅˆĐ¸ĐąĐē҃, Đ˛Ņ‹ ŅƒĐ˛Đ¸Đ´ĐĩĐģи ĐžŅˆĐ¸ĐąĐē҃ в ĐļŅƒŅ€ĐŊаĐģĐĩ. + +Но ĐēĐģиĐĩĐŊŅ‚/ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌ ŅŅ‚ĐžĐŗĐž ĐŊĐĩ ŅƒĐ˛Đ¸Đ´Đ¸Ņ‚. ВĐŧĐĩŅŅ‚Đž ŅŅ‚ĐžĐŗĐž ĐēĐģиĐĩĐŊŅ‚ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ ŅĐžĐžĐąŅ‰ĐĩĐŊиĐĩ "Internal Server Error" ҁ ĐēОдОĐŧ ŅĐžŅŅ‚ĐžŅĐŊĐ¸Ņ HTTP `500`. + +ĐĸаĐē и Đ´ĐžĐģĐļĐŊĐž ĐąŅ‹Ņ‚ŅŒ, ĐŋĐžŅ‚ĐžĐŧ҃ Ņ‡Ņ‚Đž ĐĩҁĐģи в Đ˛Đ°ŅˆĐĩĐŧ *ĐžŅ‚Đ˛ĐĩŅ‚Đĩ* иĐģи ĐŗĐ´Đĩ-ĐģийО в Đ˛Đ°ŅˆĐĩĐŧ ĐēОдĐĩ (ĐŊĐĩ в *СаĐŋŅ€ĐžŅĐĩ* ĐēĐģиĐĩĐŊŅ‚Đ°) вОСĐŊиĐēаĐĩŅ‚ Pydantic `ValidationError`, Ņ‚Đž ŅŅ‚Đž Đ´ĐĩĐšŅŅ‚Đ˛Đ¸Ņ‚ĐĩĐģҌĐŊĐž ĐžŅˆĐ¸ĐąĐēа в Đ˛Đ°ŅˆĐĩĐŧ ĐēОдĐĩ. + +И ĐŋĐžĐēа Đ˛Ņ‹ ĐŊĐĩ ŅƒŅŅ‚Ņ€Đ°ĐŊĐ¸Ņ‚Đĩ ĐžŅˆĐ¸ĐąĐē҃, Đ˛Đ°ŅˆĐ¸ ĐēĐģиĐĩĐŊ҂ҋ/ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģи ĐŊĐĩ Đ´ĐžĐģĐļĐŊŅ‹ иĐŧĐĩŅ‚ŅŒ Đ´ĐžŅŅ‚ŅƒĐŋа Đē вĐŊŅƒŅ‚Ņ€ĐĩĐŊĐŊĐĩĐš иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Đ¸ Đž ĐŊĐĩĐš, Ņ‚Đ°Đē ĐēаĐē ŅŅ‚Đž ĐŧĐžĐļĐĩŅ‚ ĐŋŅ€Đ¸Đ˛ĐĩŅŅ‚Đ¸ Đē ŅƒŅĐˇĐ˛Đ¸ĐŧĐžŅŅ‚Đ¸ в ŅĐ¸ŅŅ‚ĐĩĐŧĐĩ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸. + +### ПĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐ¸Ņ‚Đĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē ĐžŅˆĐ¸ĐąĐžĐē `HTTPException` + +АĐŊаĐģĐžĐŗĐ¸Ņ‡ĐŊŅ‹Đŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ ĐŧĐžĐļĐŊĐž ĐŋĐĩŅ€ĐĩĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐ¸Ņ‚ŅŒ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē `HTTPException`. + +НаĐŋŅ€Đ¸ĐŧĐĩŅ€, Đ´ĐģŅ ŅŅ‚Đ¸Ņ… ĐžŅˆĐ¸ĐąĐžĐē ĐŧĐžĐļĐŊĐž вĐĩŅ€ĐŊŅƒŅ‚ŅŒ ĐžĐąŅ‹Ņ‡ĐŊŅ‹Đš Ņ‚ĐĩĐēŅŅ‚ĐžĐ˛Ņ‹Đš ĐžŅ‚Đ˛ĐĩŅ‚ вĐŧĐĩŅŅ‚Đž JSON: + +```Python hl_lines="3-4 9-11 22" +{!../../../docs_src/handling_errors/tutorial004.py!} +``` + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + МоĐļĐŊĐž Ņ‚Đ°ĐēĐļĐĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ `from starlette.responses import PlainTextResponse`. + + **FastAPI** ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅĐĩŅ‚ Ņ‚ĐžŅ‚ ĐļĐĩ `starlette.responses`, Ņ‡Ņ‚Đž и `fastapi.responses`, ĐŋŅ€ĐžŅŅ‚Đž Đ´ĐģŅ ŅƒĐ´ĐžĐąŅŅ‚Đ˛Đ° Ņ€Đ°ĐˇŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēа. ОдĐŊаĐēĐž йОĐģŅŒŅˆĐ¸ĐŊŅŅ‚Đ˛Đž Đ´ĐžŅŅ‚ŅƒĐŋĐŊҋ҅ ĐžŅ‚Đ˛ĐĩŅ‚ĐžĐ˛ ĐŋĐžŅŅ‚ŅƒĐŋаĐĩŅ‚ ĐŊĐĩĐŋĐžŅŅ€ĐĩĐ´ŅŅ‚Đ˛ĐĩĐŊĐŊĐž иС Starlette. + +### Đ˜ŅĐŋĐžĐģŅŒĐˇŅƒĐšŅ‚Đĩ Ņ‚ĐĩĐģĐž `RequestValidationError` + +ĐžŅˆĐ¸ĐąĐēа `RequestValidationError` ŅĐžĐ´ĐĩŅ€ĐļĐ¸Ņ‚ ĐŋĐžĐģŅƒŅ‡ĐĩĐŊĐŊĐžĐĩ `Ņ‚ĐĩĐģĐž` ҁ ĐŊĐĩĐ´ĐžĐŋŅƒŅŅ‚Đ¸ĐŧŅ‹Đŧи даĐŊĐŊŅ‹Đŧи. + +Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐĩĐŗĐž ĐŋŅ€Đ¸ Ņ€Đ°ĐˇŅ€Đ°ĐąĐžŅ‚ĐēĐĩ ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊĐ¸Ņ Đ´ĐģŅ Ņ€ĐĩĐŗĐ¸ŅŅ‚Ņ€Đ°Ņ†Đ¸Đ¸ Ņ‚ĐĩĐģа и ĐĩĐŗĐž ĐžŅ‚ĐģадĐēи, Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‚Đ° ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅŽ и Ņ‚.Đ´. + +```Python hl_lines="14" +{!../../../docs_src/handling_errors/tutorial005.py!} +``` + +ĐĸĐĩĐŋĐĩŅ€ŅŒ ĐŋĐžĐŋŅ€ĐžĐąŅƒĐšŅ‚Đĩ ĐžŅ‚ĐŋŅ€Đ°Đ˛Đ¸Ņ‚ŅŒ ĐŊĐĩĐ´ĐĩĐšŅŅ‚Đ˛Đ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đš ŅĐģĐĩĐŧĐĩĐŊŅ‚, ĐŊаĐŋŅ€Đ¸ĐŧĐĩŅ€: + +```JSON +{ + "title": "towel", + "size": "XL" +} +``` + +Đ’Ņ‹ ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚Đĩ ĐžŅ‚Đ˛ĐĩŅ‚ Đž Ņ‚ĐžĐŧ, Ņ‡Ņ‚Đž даĐŊĐŊŅ‹Đĩ ĐŊĐĩĐ´ĐĩĐšŅŅ‚Đ˛Đ¸Ņ‚ĐĩĐģҌĐŊŅ‹, ŅĐžĐ´ĐĩŅ€ĐļĐ°Ņ‰Đ¸Đš ҁĐģĐĩĐ´ŅƒŅŽŅ‰ĐĩĐĩ Ņ‚ĐĩĐģĐž: + +```JSON hl_lines="12-15" +{ + "detail": [ + { + "loc": [ + "body", + "size" + ], + "msg": "value is not a valid integer", + "type": "type_error.integer" + } + ], + "body": { + "title": "towel", + "size": "XL" + } +} +``` + +#### `HTTPException` в FastAPI иĐģи в Starlette + +**FastAPI** иĐŧĐĩĐĩŅ‚ ŅĐžĐąŅŅ‚Đ˛ĐĩĐŊĐŊŅ‹Đš `HTTPException`. + +КĐģĐ°ŅŅ ĐžŅˆĐ¸ĐąĐžĐē **FastAPI** `HTTPException` ĐŊĐ°ŅĐģĐĩĐ´ŅƒĐĩŅ‚ ĐžŅ‚ ĐēĐģĐ°ŅŅĐ° ĐžŅˆĐ¸ĐąĐžĐē Starlette `HTTPException`. + +ЕдиĐŊŅŅ‚Đ˛ĐĩĐŊĐŊĐžĐĩ ĐžŅ‚ĐģĐ¸Ņ‡Đ¸Đĩ СаĐēĐģŅŽŅ‡Đ°ĐĩŅ‚ŅŅ в Ņ‚ĐžĐŧ, Ņ‡Ņ‚Đž `HTTPException` ĐžŅ‚ **FastAPI** ĐŋОСвОĐģŅĐĩŅ‚ дОйавĐģŅŅ‚ŅŒ ĐˇĐ°ĐŗĐžĐģОвĐēи, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ĐąŅƒĐ´ŅƒŅ‚ вĐēĐģŅŽŅ‡ĐĩĐŊŅ‹ в ĐžŅ‚Đ˛ĐĩŅ‚. + +ОĐŊ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸Đŧ/Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ вĐŊŅƒŅ‚Ņ€Đ¸ ŅĐ¸ŅŅ‚ĐĩĐŧŅ‹ Đ´ĐģŅ OAuth 2.0 и ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Ņ… ŅƒŅ‚Đ¸ĐģĐ¸Ņ‚ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸. + +ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, Đ˛Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐŋŅ€ĐžĐ´ĐžĐģĐļĐ°Ņ‚ŅŒ Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°Ņ‚ŅŒ `HTTPException` ĐžŅ‚ **FastAPI** ĐēаĐē ĐžĐąŅ‹Ņ‡ĐŊĐž в ŅĐ˛ĐžĐĩĐŧ ĐēОдĐĩ. + +Но ĐēĐžĐŗĐ´Đ° Đ˛Ņ‹ Ņ€ĐĩĐŗĐ¸ŅŅ‚Ņ€Đ¸Ņ€ŅƒĐĩŅ‚Đĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК, Đ˛Ņ‹ Đ´ĐžĐģĐļĐŊŅ‹ ĐˇĐ°Ņ€ĐĩĐŗĐ¸ŅŅ‚Ņ€Đ¸Ņ€ĐžĐ˛Đ°Ņ‚ŅŒ ĐĩĐŗĐž Đ´ĐģŅ `HTTPException` ĐžŅ‚ Starlette. + +ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, ĐĩҁĐģи ĐēаĐēĐ°Ņ-ĐģийО Ņ‡Đ°ŅŅ‚ŅŒ вĐŊŅƒŅ‚Ņ€ĐĩĐŊĐŊĐĩĐŗĐž ĐēОда Starlette, Ņ€Đ°ŅŅˆĐ¸Ņ€ĐĩĐŊиĐĩ иĐģи ĐŋĐģĐ°ĐŗĐ¸ĐŊ Starlette Đ˛Ņ‹ĐˇĐžĐ˛ĐĩŅ‚ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ Starlette `HTTPException`, Đ˛Đ°Ņˆ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đē ҁĐŧĐžĐļĐĩŅ‚ ĐŋĐĩŅ€ĐĩŅ…Đ˛Đ°Ņ‚Đ¸Ņ‚ŅŒ и ĐžĐąŅ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ ĐĩĐŗĐž. + +В даĐŊĐŊĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ, Ņ‡Ņ‚ĐžĐąŅ‹ иĐŧĐĩŅ‚ŅŒ вОСĐŧĐžĐļĐŊĐžŅŅ‚ŅŒ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Ойа `HTTPException` в ОдĐŊĐžĐŧ ĐēОдĐĩ, Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊĐ¸Ņ Starlette ĐŋĐĩŅ€ĐĩиĐŧĐĩĐŊОваĐŊŅ‹ в `StarletteHTTPException`: + +```Python +from starlette.exceptions import HTTPException as StarletteHTTPException +``` + +### ПĐĩŅ€ĐĩĐ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸ĐēОв Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК **FastAPI** + +Đ•ŅĐģи Đ˛Ņ‹ Ņ…ĐžŅ‚Đ¸Ņ‚Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ вĐŧĐĩҁ҂Đĩ ҁ Ņ‚ĐĩĐŧи ĐļĐĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸ĐēаĐŧи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ иС **FastAPI**, Đ˛Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ иĐŧĐŋĐžŅ€Ņ‚Đ¸Ņ€ĐžĐ˛Đ°Ņ‚ŅŒ и ĐŋĐžĐ˛Ņ‚ĐžŅ€ĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК ĐŋĐž ҃ĐŧĐžĐģŅ‡Đ°ĐŊĐ¸ŅŽ иС `fastapi.exception_handlers`: + +```Python hl_lines="2-5 15 21" +{!../../../docs_src/handling_errors/tutorial006.py!} +``` + +В ŅŅ‚ĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ Đ˛Ņ‹ ĐŋŅ€ĐžŅŅ‚Đž `Đ˛Ņ‹Đ˛ĐžĐ´Đ¸Ņ‚Đĩ в Ņ‚ĐĩŅ€ĐŧиĐŊаĐģ` ĐžŅˆĐ¸ĐąĐē҃ ҁ ĐžŅ‡ĐĩĐŊҌ Đ˛Ņ‹Ņ€Đ°ĐˇĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đŧ ŅĐžĐžĐąŅ‰ĐĩĐŊиĐĩĐŧ, ĐŊĐž идĐĩŅ ваĐŧ ĐŋĐžĐŊŅŅ‚ĐŊа. Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиĐĩ, а ĐˇĐ°Ņ‚ĐĩĐŧ ĐŋŅ€ĐžŅŅ‚Đž ĐŋĐžĐ˛Ņ‚ĐžŅ€ĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ŅŅ‚Đ°ĐŊĐ´Đ°Ņ€Ņ‚ĐŊŅ‹Đĩ ĐžĐąŅ€Đ°ĐąĐžŅ‚Ņ‡Đ¸Đēи Đ¸ŅĐēĐģŅŽŅ‡ĐĩĐŊиК. From ccdc96293683a2e44237a500f4cb4740784a8f17 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:56:42 +0000 Subject: [PATCH 185/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a1ee0f0cf0..6a261712f4 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Russian translation for `docs/ru/docs/tutorial/body-updates.md`. PR [#10373](https://github.com/tiangolo/fastapi/pull/10373) by [@AlertRED](https://github.com/AlertRED). * 🌐 Russian translation: updated `fastapi-people.md`.. PR [#10255](https://github.com/tiangolo/fastapi/pull/10255) by [@NiKuma0](https://github.com/NiKuma0). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/index.md`. PR [#5798](https://github.com/tiangolo/fastapi/pull/5798) by [@3w36zj6](https://github.com/3w36zj6). * 🌐 Add German translation for `docs/de/docs/advanced/generate-clients.md`. PR [#10725](https://github.com/tiangolo/fastapi/pull/10725) by [@nilslindemann](https://github.com/nilslindemann). From cc9c448ed45b544b32bb5e59efc5091f0b52db3b Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:57:19 +0000 Subject: [PATCH 186/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6a261712f4..a5f76de0b5 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Russian translation for `docs/ru/docs/tutorial/encoder.md`. PR [#10374](https://github.com/tiangolo/fastapi/pull/10374) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/body-updates.md`. PR [#10373](https://github.com/tiangolo/fastapi/pull/10373) by [@AlertRED](https://github.com/AlertRED). * 🌐 Russian translation: updated `fastapi-people.md`.. PR [#10255](https://github.com/tiangolo/fastapi/pull/10255) by [@NiKuma0](https://github.com/NiKuma0). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/index.md`. PR [#5798](https://github.com/tiangolo/fastapi/pull/5798) by [@3w36zj6](https://github.com/3w36zj6). From 0fb326fc6ed21d94647822a9dee949abcb538ec6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 13:58:04 +0000 Subject: [PATCH 187/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a5f76de0b5..4ccedda1dc 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Russian translation for `docs/ru/docs/tutorial/handling-errors.md`. PR [#10375](https://github.com/tiangolo/fastapi/pull/10375) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/encoder.md`. PR [#10374](https://github.com/tiangolo/fastapi/pull/10374) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/body-updates.md`. PR [#10373](https://github.com/tiangolo/fastapi/pull/10373) by [@AlertRED](https://github.com/AlertRED). * 🌐 Russian translation: updated `fastapi-people.md`.. PR [#10255](https://github.com/tiangolo/fastapi/pull/10255) by [@NiKuma0](https://github.com/NiKuma0). From 9060c427a6deb883bc07df16ae9b573d2e6585d3 Mon Sep 17 00:00:00 2001 From: Aleksandr Andrukhov Date: Tue, 23 Jan 2024 17:00:11 +0300 Subject: [PATCH 188/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Russian=20translat?= =?UTF-8?q?ion=20for=20`docs/ru/docs/tutorial/security/first-steps.md`=20(?= =?UTF-8?q?#10541)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ru/docs/tutorial/security/first-steps.md | 232 ++++++++++++++++++ 1 file changed, 232 insertions(+) create mode 100644 docs/ru/docs/tutorial/security/first-steps.md diff --git a/docs/ru/docs/tutorial/security/first-steps.md b/docs/ru/docs/tutorial/security/first-steps.md new file mode 100644 index 0000000000..b70a60a387 --- /dev/null +++ b/docs/ru/docs/tutorial/security/first-steps.md @@ -0,0 +1,232 @@ +# БĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚ŅŒ - ĐŋĐĩŅ€Đ˛Ņ‹Đĩ ŅˆĐ°ĐŗĐ¸ + +ĐŸŅ€ĐĩĐ´ŅŅ‚Đ°Đ˛Đ¸Đŧ, Ņ‡Ņ‚Đž ҃ Đ˛Đ°Ņ ĐĩŅŅ‚ŅŒ ŅĐ˛ĐžĐš **ĐąŅĐēĐĩĐŊĐ´** API ĐŊа ĐŊĐĩĐēĐžŅ‚ĐžŅ€ĐžĐŧ Đ´ĐžĐŧĐĩĐŊĐĩ. + +И ҃ Đ˛Đ°Ņ ĐĩŅŅ‚ŅŒ **Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´** ĐŊа Đ´Ņ€ŅƒĐŗĐžĐŧ Đ´ĐžĐŧĐĩĐŊĐĩ иĐģи ĐŊа Đ´Ņ€ŅƒĐŗĐžĐŧ ĐŋŅƒŅ‚Đ¸ Ņ‚ĐžĐŗĐž ĐļĐĩ Đ´ĐžĐŧĐĩĐŊа (иĐģи в ĐŧОйиĐģҌĐŊĐžĐŧ ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊии). + +И Đ˛Ņ‹ Ņ…ĐžŅ‚Đ¸Ņ‚Đĩ иĐŧĐĩŅ‚ŅŒ вОСĐŧĐžĐļĐŊĐžŅŅ‚ŅŒ Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Đ¸ Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊда ҁ ĐąŅĐēĐĩĐŊĐ´ĐžĐŧ, Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅ **иĐŧŅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ** и **ĐŋĐ°Ņ€ĐžĐģҌ**. + +ĐœŅ‹ ĐŧĐžĐļĐĩĐŧ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ **OAuth2** Đ´ĐģŅ ŅĐžĐˇĐ´Đ°ĐŊĐ¸Ņ Ņ‚Đ°ĐēОК ŅĐ¸ŅŅ‚ĐĩĐŧŅ‹ ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ **FastAPI**. + +Но Đ´Đ°Đ˛Đ°ĐšŅ‚Đĩ иСйавиĐŧ Đ˛Đ°Ņ ĐžŅ‚ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐžŅŅ‚Đ¸ Ņ‡Đ¸Ņ‚Đ°Ņ‚ŅŒ Đ˛ŅŅŽ Đ´ĐģиĐŊĐŊŅƒŅŽ ҁĐŋĐĩŅ†Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸ŅŽ, Ņ‡Ņ‚ĐžĐąŅ‹ ĐŊĐ°ĐšŅ‚Đ¸ Ņ‚Đĩ ĐŊĐĩйОĐģŅŒŅˆĐ¸Đĩ ĐēŅƒŅĐžŅ‡Đēи иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Đ¸, ĐēĐžŅ‚ĐžŅ€Ņ‹Đĩ ваĐŧ ĐŊ҃ĐļĐŊŅ‹. + +ДĐģŅ Ņ€Đ°ĐąĐžŅ‚Ņ‹ ҁ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚ŅŒŅŽ Đ˛ĐžŅĐŋĐžĐģŅŒĐˇŅƒĐĩĐŧŅŅ ҁҀĐĩĐ´ŅŅ‚Đ˛Đ°Đŧи, ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģĐĩĐŊĐŊŅ‹Đŧи **FastAPI**. + +## КаĐē ŅŅ‚Đž Đ˛Ņ‹ĐŗĐģŅĐ´Đ¸Ņ‚ + +Đ”Đ°Đ˛Đ°ĐšŅ‚Đĩ ҁĐŊĐ°Ņ‡Đ°Đģа ĐŋŅ€ĐžŅŅ‚Đž Đ˛ĐžŅĐŋĐžĐģŅŒĐˇŅƒĐĩĐŧŅŅ ĐēОдОĐŧ и ĐŋĐžŅĐŧĐžŅ‚Ņ€Đ¸Đŧ, ĐēаĐē ĐžĐŊ Ņ€Đ°ĐąĐžŅ‚Đ°ĐĩŅ‚, а ĐˇĐ°Ņ‚ĐĩĐŧ Đ´ĐĩŅ‚Đ°ĐģҌĐŊĐž Ņ€Đ°ĐˇĐąĐĩҀґĐŧ, Ņ‡Ņ‚Đž ĐŋŅ€ĐžĐ¸ŅŅ…ĐžĐ´Đ¸Ņ‚. + +## ХОСдаĐŊиĐĩ `main.py` + +ĐĄĐēĐžĐŋĐ¸Ņ€ŅƒĐšŅ‚Đĩ ĐŋŅ€Đ¸ĐŧĐĩŅ€ в Ņ„Đ°ĐšĐģ `main.py`: + +=== "Python 3.9+" + + ```Python + {!> ../../../docs_src/security/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python + {!> ../../../docs_src/security/tutorial001_an.py!} + ``` + +=== "Python 3.8+ ĐąĐĩС Annotated" + + !!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + ĐŸŅ€ĐĩĐ´ĐŋĐžŅ‡Ņ‚Đ¸Ņ‚ĐĩĐģҌĐŊĐĩĐĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ вĐĩŅ€ŅĐ¸ŅŽ ҁ аĐŊĐŊĐžŅ‚Đ°Ņ†Đ¸ĐĩĐš, ĐĩҁĐģи ŅŅ‚Đž вОСĐŧĐžĐļĐŊĐž. + + ```Python + {!> ../../../docs_src/security/tutorial001.py!} + ``` + + +## ЗаĐŋ҃ҁĐē + +!!! info "ДоĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊĐ°Ņ иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Ņ" + ВĐŊĐ°Ņ‡Đ°ĐģĐĩ, ŅƒŅŅ‚Đ°ĐŊĐžĐ˛Đ¸Ņ‚Đĩ йийĐģĐ¸ĐžŅ‚ĐĩĐē҃ `python-multipart`. + + А иĐŧĐĩĐŊĐŊĐž: `pip install python-multipart`. + + Đ­Ņ‚Đž ŅĐ˛ŅĐˇĐ°ĐŊĐž ҁ Ņ‚ĐĩĐŧ, Ņ‡Ņ‚Đž **OAuth2** Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ "даĐŊĐŊŅ‹Đĩ Ņ„ĐžŅ€ĐŧŅ‹" Đ´ĐģŅ ĐŋĐĩŅ€ĐĩĐ´Đ°Ņ‡Đ¸ `иĐŧĐĩĐŊи ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģŅ`. + +ЗаĐŋŅƒŅŅ‚Đ¸Ņ‚Đĩ Đ˛Đ°Ņˆ ҁĐĩŅ€Đ˛ĐĩŅ€: + +
+ +```console +$ uvicorn main:app --reload + +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +``` + +
+ +## ĐŸŅ€ĐžĐ˛ĐĩŅ€Đēа + +ПĐĩŅ€ĐĩĐšĐ´Đ¸Ņ‚Đĩ Đē иĐŊŅ‚ĐĩŅ€Đ°ĐēŅ‚Đ¸Đ˛ĐŊОК Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ°Ņ†Đ¸Đ¸ ĐŋĐž Đ°Đ´Ņ€Đĩҁ҃: http://127.0.0.1:8000/docs. + +Đ’Ņ‹ ŅƒĐ˛Đ¸Đ´Đ¸Ņ‚Đĩ ĐŋŅ€Đ¸ĐŧĐĩŅ€ĐŊĐž ҁĐģĐĩĐ´ŅƒŅŽŅ‰ĐĩĐĩ: + + + +!!! check "КĐŊĐžĐŋĐēа Đ°Đ˛Ņ‚ĐžŅ€Đ¸ĐˇĐ°Ņ†Đ¸Đ¸!" + ĐŖ Đ˛Đ°Ņ ҃ĐļĐĩ ĐŋĐžŅĐ˛Đ¸ĐģĐ°ŅŅŒ ĐŊĐžĐ˛Đ°Ņ ĐēĐŊĐžĐŋĐēа "Authorize". + + А ҃ *ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸ ĐŋŅƒŅ‚Đ¸* Ņ‚ĐĩĐŋĐĩŅ€ŅŒ ĐŋĐžŅĐ˛Đ¸ĐģŅŅ ĐŧаĐģĐĩĐŊҌĐēиК СаĐŧĐžŅ‡ĐĩĐē в ĐŋŅ€Đ°Đ˛ĐžĐŧ вĐĩҀ҅ĐŊĐĩĐŧ ŅƒĐŗĐģ҃, ĐŊа ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐŧĐžĐļĐŊĐž ĐŊаĐļĐ°Ņ‚ŅŒ. + +ĐŸŅ€Đ¸ ĐŊаĐļĐ°Ņ‚Đ¸Đ¸ ĐŊа ĐŊĐĩĐĩ ĐŋĐžŅĐ˛ĐģŅĐĩŅ‚ŅŅ ĐŊĐĩйОĐģŅŒŅˆĐ°Ņ Ņ„ĐžŅ€Đŧа Đ°Đ˛Ņ‚ĐžŅ€Đ¸ĐˇĐ°Ņ†Đ¸Đ¸, в ĐēĐžŅ‚ĐžŅ€ŅƒŅŽ ĐŊ҃ĐļĐŊĐž ввĐĩŅŅ‚Đ¸ `иĐŧŅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģҌ` (и Đ´Ņ€ŅƒĐŗĐ¸Đĩ ĐŊĐĩĐžĐąŅĐˇĐ°Ņ‚ĐĩĐģҌĐŊŅ‹Đĩ ĐŋĐžĐģŅ): + + + +!!! note "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + НĐĩваĐļĐŊĐž, Ņ‡Ņ‚Đž Đ˛Ņ‹ ввĐĩĐ´ĐĩŅ‚Đĩ в Ņ„ĐžŅ€Đŧ҃, ĐžĐŊа ĐŋĐžĐēа ĐŊĐĩ ĐąŅƒĐ´ĐĩŅ‚ Ņ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ. Но ĐŧŅ‹ Đē ŅŅ‚ĐžĐŧ҃ Đĩ҉Đĩ ĐŋŅ€Đ¸Đ´ĐĩĐŧ. + +КоĐŊĐĩ҇ĐŊĐž, ŅŅ‚Đž ĐŊĐĩ Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´ Đ´ĐģŅ ĐēĐžĐŊĐĩ҇ĐŊҋ҅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģĐĩĐš, ĐŊĐž ŅŅ‚Đž ĐžŅ‚ĐģĐ¸Ņ‡ĐŊŅ‹Đš Đ°Đ˛Ņ‚ĐžĐŧĐ°Ņ‚Đ¸Ņ‡ĐĩҁĐēиК иĐŊŅŅ‚Ņ€ŅƒĐŧĐĩĐŊŅ‚ Đ´ĐģŅ иĐŊŅ‚ĐĩŅ€Đ°ĐēŅ‚Đ¸Đ˛ĐŊĐžĐŗĐž Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ¸Ņ€ĐžĐ˛Đ°ĐŊĐ¸Ņ Đ˛ŅĐĩŅ… Đ˛Đ°ŅˆĐ¸Ņ… API. + +ОĐŊ ĐŧĐžĐļĐĩŅ‚ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒŅŅ ĐēĐžĐŧаĐŊдОК Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊда (ĐēĐžŅ‚ĐžŅ€ĐžĐš ĐŧĐžĐļĐĩŅ‚Đĩ ĐąŅ‹Ņ‚ŅŒ и Đ˛Ņ‹ ŅĐ°Đŧи). + +ОĐŊ ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊ ŅŅ‚ĐžŅ€ĐžĐŊĐŊиĐŧи ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊĐ¸ŅĐŧи и ŅĐ¸ŅŅ‚ĐĩĐŧаĐŧи. + +ĐšŅ€ĐžĐŧĐĩ Ņ‚ĐžĐŗĐž, ĐĩĐŗĐž ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ŅĐ°ĐŧĐžŅŅ‚ĐžŅŅ‚ĐĩĐģҌĐŊĐž Đ´ĐģŅ ĐžŅ‚ĐģадĐēи, ĐŋŅ€ĐžĐ˛ĐĩŅ€Đēи и Ņ‚ĐĩŅŅ‚Đ¸Ņ€ĐžĐ˛Đ°ĐŊĐ¸Ņ ОдĐŊĐžĐŗĐž и Ņ‚ĐžĐŗĐž ĐļĐĩ ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊĐ¸Ņ. + +## ĐŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Ņ ĐŋĐž ĐŋĐ°Ņ€ĐžĐģŅŽ + +ĐĸĐĩĐŋĐĩŅ€ŅŒ Đ´Đ°Đ˛Đ°ĐšŅ‚Đĩ вĐĩŅ€ĐŊĐĩĐŧŅŅ ĐŊĐĩĐŧĐŊĐžĐŗĐž ĐŊаСад и Ņ€Đ°ĐˇĐąĐĩŅ€ĐĩĐŧŅŅ, Ņ‡Ņ‚Đž ĐļĐĩ ŅŅ‚Đž Ņ‚Đ°ĐēĐžĐĩ. + +ĐŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Ņ ĐŋĐž ĐŋĐ°Ņ€ĐžĐģŅŽ ŅĐ˛ĐģŅĐĩŅ‚ŅŅ ОдĐŊиĐŧ иС ҁĐŋĐžŅĐžĐąĐžĐ˛, ĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊĐŊҋ҅ в OAuth2, Đ´ĐģŅ ОйĐĩҁĐŋĐĩ҇ĐĩĐŊĐ¸Ņ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸ и Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Đ¸. + +OAuth2 ĐąŅ‹Đģ Ņ€Đ°ĐˇŅ€Đ°ĐąĐžŅ‚Đ°ĐŊ Đ´ĐģŅ Ņ‚ĐžĐŗĐž, Ņ‡Ņ‚ĐžĐąŅ‹ ĐąŅĐēŅĐŊĐ´ иĐģи API ĐąŅ‹Đģи ĐŊĐĩĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧŅ‹ ĐžŅ‚ ҁĐĩŅ€Đ˛ĐĩŅ€Đ°, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸Ņ†Đ¸Ņ€ŅƒĐĩŅ‚ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ. + +Но в ĐŊĐ°ŅˆĐĩĐŧ ҁĐģŅƒŅ‡Đ°Đĩ ОдĐŊĐž и Ņ‚Đž ĐļĐĩ ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊиĐĩ **FastAPI** ĐąŅƒĐ´ĐĩŅ‚ Ņ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ ҁ API и Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸ĐĩĐš. + +Đ˜Ņ‚Đ°Đē, Ņ€Đ°ŅŅĐŧĐžŅ‚Ņ€Đ¸Đŧ ĐĩĐŗĐž ҁ ŅŅ‚ĐžĐš ҃ĐŋŅ€ĐžŅ‰ĐĩĐŊĐŊОК Ņ‚ĐžŅ‡Đēи ĐˇŅ€ĐĩĐŊĐ¸Ņ: + +* ПоĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌ Đ˛Đ˛ĐžĐ´Đ¸Ņ‚ ĐŊа Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´Đĩ `иĐŧŅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģҌ` и ĐŊаĐļиĐŧаĐĩŅ‚ `Enter`. +* Đ¤Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´ (Ņ€Đ°ĐąĐžŅ‚Đ°ŅŽŅ‰Đ¸Đš в ĐąŅ€Đ°ŅƒĐˇĐĩŅ€Đĩ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ) ĐžŅ‚ĐŋŅ€Đ°Đ˛ĐģŅĐĩŅ‚ ŅŅ‚Đ¸ `иĐŧŅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģҌ` ĐŊа ĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊĐŊŅ‹Đš URL в ĐŊĐ°ŅˆĐĩĐŧ API (ĐžĐąŅŠŅĐ˛ĐģĐĩĐŊĐŊŅ‹Đš ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `tokenUrl="token"`). +* API ĐŋŅ€ĐžĐ˛ĐĩŅ€ŅĐĩŅ‚ ŅŅ‚Đ¸ `иĐŧŅ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģҌ` и Đ˛Ņ‹Đ´Đ°ĐĩŅ‚ в ĐžŅ‚Đ˛ĐĩŅ‚ "Ņ‚ĐžĐēĐĩĐŊ" (ĐŧŅ‹ Đĩ҉Đĩ ĐŊĐĩ Ņ€ĐĩаĐģиСОваĐģи ĐŊĐ¸Ņ‡ĐĩĐŗĐž иС ŅŅ‚ĐžĐŗĐž). + * "ĐĸĐžĐēĐĩĐŊ" - ŅŅ‚Đž ĐŋŅ€ĐžŅŅ‚Đž ŅŅ‚Ņ€ĐžĐēа ҁ ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Đŧ ŅĐžĐ´ĐĩŅ€ĐļиĐŧŅ‹Đŧ, ĐēĐžŅ‚ĐžŅ€ĐžĐĩ ĐŧŅ‹ ĐŧĐžĐļĐĩĐŧ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐŋОСĐļĐĩ Đ´ĐģŅ вĐĩŅ€Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Đ¸ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ. + * ĐžĐąŅ‹Ņ‡ĐŊĐž ŅŅ€ĐžĐē Đ´ĐĩĐšŅŅ‚Đ˛Đ¸Ņ Ņ‚ĐžĐēĐĩĐŊа Đ¸ŅŅ‚ĐĩĐēаĐĩŅ‚ ҇ĐĩŅ€ĐĩС ĐŊĐĩĐēĐžŅ‚ĐžŅ€ĐžĐĩ Đ˛Ņ€ĐĩĐŧŅ. + * ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅŽ ĐŋŅ€Đ¸Đ´ĐĩŅ‚ŅŅ ҁĐŊОва Đ˛ĐžĐšŅ‚Đ¸ в ŅĐ¸ŅŅ‚ĐĩĐŧ҃ в ĐēаĐēОК-Ņ‚Đž ĐŧĐžĐŧĐĩĐŊŅ‚ Đ˛Ņ€ĐĩĐŧĐĩĐŊи. + * И ĐĩҁĐģи Ņ‚ĐžĐēĐĩĐŊ ĐąŅƒĐ´ĐĩŅ‚ ҃ĐēŅ€Đ°Đ´ĐĩĐŊ, Ņ‚Đž Ņ€Đ¸ŅĐē ĐąŅƒĐ´ĐĩŅ‚ ĐŧĐĩĐŊҌ҈Đĩ, Ņ‚Đ°Đē ĐēаĐē ĐžĐŊ ĐŊĐĩ ĐŋĐžŅ…ĐžĐļ ĐŊа ĐŋĐžŅŅ‚ĐžŅĐŊĐŊŅ‹Đš ĐēĐģŅŽŅ‡, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐąŅƒĐ´ĐĩŅ‚ Ņ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ вĐĩ҇ĐŊĐž (в йОĐģŅŒŅˆĐ¸ĐŊŅŅ‚Đ˛Đĩ ҁĐģŅƒŅ‡Đ°Đĩв). +* Đ¤Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´ Đ˛Ņ€ĐĩĐŧĐĩĐŊĐŊĐž Ņ…Ņ€Đ°ĐŊĐ¸Ņ‚ ŅŅ‚ĐžŅ‚ Ņ‚ĐžĐēĐĩĐŊ в ĐēаĐēĐžĐŧ-Ņ‚Đž ĐŧĐĩҁ҂Đĩ. +* ПоĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģҌ ҉ĐĩĐģĐēаĐĩŅ‚ ĐŧŅ‹ŅˆŅŒŅŽ ĐŊа Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´Đĩ, Ņ‡Ņ‚ĐžĐąŅ‹ ĐŋĐĩŅ€ĐĩĐšŅ‚Đ¸ в Đ´Ņ€ŅƒĐŗĐžĐš Ņ€Đ°ĐˇĐ´ĐĩĐģ ĐŊа Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´Đĩ. +* Đ¤Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´Ņƒ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž ĐŋĐžĐģŅƒŅ‡Đ¸Ņ‚ŅŒ Đ´ĐžĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đĩ даĐŊĐŊŅ‹Đĩ иС API. + * Но Đ´ĐģŅ ŅŅ‚ĐžĐŗĐž ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸Đŧа Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Ņ Đ´ĐģŅ ĐēĐžĐŊĐēŅ€ĐĩŅ‚ĐŊОК ĐēĐžĐŊĐĩ҇ĐŊОК Ņ‚ĐžŅ‡Đēи. + * ĐŸĐžŅŅ‚ĐžĐŧ҃ Đ´ĐģŅ Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Đ¸ в ĐŊĐ°ŅˆĐĩĐŧ API ĐžĐŊ ĐŋĐžŅŅ‹ĐģаĐĩŅ‚ ĐˇĐ°ĐŗĐžĐģОвОĐē `Authorization` ŅĐž СĐŊĐ°Ņ‡ĐĩĐŊиĐĩĐŧ `Bearer` ĐŋĐģŅŽŅ ŅĐ°Đŧ Ņ‚ĐžĐēĐĩĐŊ. + * Đ•ŅĐģи Ņ‚ĐžĐēĐĩĐŊ ŅĐžĐ´ĐĩŅ€ĐļĐ¸Ņ‚ `foobar`, Ņ‚Đž ŅĐžĐ´ĐĩŅ€ĐļаĐŊиĐĩ ĐˇĐ°ĐŗĐžĐģОвĐēа `Authorization` ĐąŅƒĐ´ĐĩŅ‚ Ņ‚Đ°ĐēиĐŧ: `Bearer foobar`. + +## КĐģĐ°ŅŅ `OAuth2PasswordBearer` в **FastAPI** + +**FastAPI** ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅĐĩŅ‚ ĐŊĐĩҁĐēĐžĐģҌĐēĐž ҁҀĐĩĐ´ŅŅ‚Đ˛ ĐŊа Ņ€Đ°ĐˇĐŊҋ҅ ŅƒŅ€ĐžĐ˛ĐŊŅŅ… Đ°ĐąŅŅ‚Ņ€Đ°ĐēŅ†Đ¸Đ¸ Đ´ĐģŅ Ņ€ĐĩаĐģĐ¸ĐˇĐ°Ņ†Đ¸Đ¸ ŅŅ‚Đ¸Ņ… Ņ„ŅƒĐŊĐēŅ†Đ¸Đš ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸. + +В даĐŊĐŊĐžĐŧ ĐŋŅ€Đ¸ĐŧĐĩŅ€Đĩ ĐŧŅ‹ ĐąŅƒĐ´ĐĩĐŧ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ **OAuth2**, ҁ Đ°ŅƒŅ‚ĐĩĐŊŅ‚Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸ĐĩĐš ĐŋĐž ĐŋĐ°Ņ€ĐžĐģŅŽ, Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒŅ Ņ‚ĐžĐēĐĩĐŊ **Bearer**. ДĐģŅ ŅŅ‚ĐžĐŗĐž ĐŧŅ‹ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩĐŧ ĐēĐģĐ°ŅŅ `OAuth2PasswordBearer`. + +!!! info "ДоĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊĐ°Ņ иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Ņ" + ĐĸĐžĐēĐĩĐŊ "bearer" - ĐŊĐĩ ĐĩдиĐŊŅŅ‚Đ˛ĐĩĐŊĐŊŅ‹Đš Đ˛Đ°Ņ€Đ¸Đ°ĐŊŅ‚, ĐŊĐž Đ´ĐģŅ ĐŊĐ°ŅˆĐĩĐŗĐž ҁĐģŅƒŅ‡Đ°Ņ ĐžĐŊ ŅĐ˛ĐģŅĐĩŅ‚ŅŅ ĐŊаиĐģŅƒŅ‡ŅˆĐ¸Đŧ. + + И ŅŅ‚Đž ĐŧĐžĐļĐĩŅ‚ ĐąŅ‹Ņ‚ŅŒ ĐģŅƒŅ‡ŅˆĐ¸Đŧ Đ˛Đ°Ņ€Đ¸Đ°ĐŊŅ‚ĐžĐŧ Đ´ĐģŅ йОĐģŅŒŅˆĐ¸ĐŊŅŅ‚Đ˛Đ° ҁĐģŅƒŅ‡Đ°Đĩв Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊĐ¸Ņ, ĐĩҁĐģи Ņ‚ĐžĐģҌĐēĐž Đ˛Ņ‹ ĐŊĐĩ ŅĐ˛ĐģŅĐĩŅ‚ĐĩҁҌ ŅĐēҁĐŋĐĩŅ€Ņ‚ĐžĐŧ в ОйĐģĐ°ŅŅ‚Đ¸ OAuth2 и Ņ‚ĐžŅ‡ĐŊĐž СĐŊаĐĩŅ‚Đĩ, ĐŋĐžŅ‡ĐĩĐŧ҃ ваĐŧ ĐģŅƒŅ‡ŅˆĐĩ ĐŋĐžĐ´Ņ…ĐžĐ´Đ¸Ņ‚ ĐēаĐēОК-Ņ‚Đž Đ´Ņ€ŅƒĐŗĐžĐš Đ˛Đ°Ņ€Đ¸Đ°ĐŊŅ‚. + + В ŅŅ‚ĐžĐŧ ҁĐģŅƒŅ‡Đ°Đĩ **FastAPI** Ņ‚Đ°ĐēĐļĐĩ ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅĐĩŅ‚ иĐŊŅŅ‚Ņ€ŅƒĐŧĐĩĐŊ҂ҋ Đ´ĐģŅ ĐĩĐŗĐž Ņ€ĐĩаĐģĐ¸ĐˇĐ°Ņ†Đ¸Đ¸. + +ĐŸŅ€Đ¸ ŅĐžĐˇĐ´Đ°ĐŊии ŅĐēСĐĩĐŧĐŋĐģŅŅ€Đ° ĐēĐģĐ°ŅŅĐ° `OAuth2PasswordBearer` ĐŧŅ‹ ĐŋĐĩŅ€ĐĩдаĐĩĐŧ в ĐŊĐĩĐŗĐž ĐŋĐ°Ņ€Đ°ĐŧĐĩ҂Ҁ `tokenUrl`. Đ­Ņ‚ĐžŅ‚ ĐŋĐ°Ņ€Đ°ĐŧĐĩ҂Ҁ ŅĐžĐ´ĐĩŅ€ĐļĐ¸Ņ‚ URL, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐēĐģиĐĩĐŊŅ‚ (Ņ„Ņ€ĐžĐŊŅ‚ĐĩĐŊĐ´, Ņ€Đ°ĐąĐžŅ‚Đ°ŅŽŅ‰Đ¸Đš в ĐąŅ€Đ°ŅƒĐˇĐĩŅ€Đĩ ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ) ĐąŅƒĐ´ĐĩŅ‚ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Đ´ĐģŅ ĐžŅ‚ĐŋŅ€Đ°Đ˛Đēи `иĐŧĐĩĐŊи ĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ĐĩĐģŅ` и `ĐŋĐ°Ņ€ĐžĐģŅ` ҁ ҆ĐĩĐģŅŒŅŽ ĐŋĐžĐģŅƒŅ‡ĐĩĐŊĐ¸Ņ Ņ‚ĐžĐēĐĩĐŊа. + +=== "Python 3.9+" + + ```Python hl_lines="8" + {!> ../../../docs_src/security/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="7" + {!> ../../../docs_src/security/tutorial001_an.py!} + ``` + +=== "Python 3.8+ ĐąĐĩС Annotated" + + !!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + ĐŸŅ€ĐĩĐ´ĐŋĐžŅ‡Ņ‚Đ¸Ņ‚ĐĩĐģҌĐŊĐĩĐĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ вĐĩŅ€ŅĐ¸ŅŽ ҁ аĐŊĐŊĐžŅ‚Đ°Ņ†Đ¸ĐĩĐš, ĐĩҁĐģи ŅŅ‚Đž вОСĐŧĐžĐļĐŊĐž. + + ```Python hl_lines="6" + {!> ../../../docs_src/security/tutorial001.py!} + ``` + +!!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + ЗдĐĩҁҌ `tokenUrl="token"` ҁҁҋĐģаĐĩŅ‚ŅŅ ĐŊа ĐžŅ‚ĐŊĐžŅĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đš URL `token`, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐŧŅ‹ Đĩ҉Đĩ ĐŊĐĩ ŅĐžĐˇĐ´Đ°Đģи. ĐŸĐžŅĐēĐžĐģҌĐē҃ ŅŅ‚Đž ĐžŅ‚ĐŊĐžŅĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đš URL, ĐžĐŊ ŅĐēвиваĐģĐĩĐŊŅ‚ĐĩĐŊ `./token`. + + ĐŸĐžŅĐēĐžĐģҌĐē҃ ĐŧŅ‹ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩĐŧ ĐžŅ‚ĐŊĐžŅĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đš URL, ĐĩҁĐģи Đ˛Đ°Ņˆ API Ņ€Đ°ŅĐŋĐžĐģĐžĐļĐĩĐŊ ĐŋĐž Đ°Đ´Ņ€Đĩҁ҃ `https://example.com/`, Ņ‚Đž ĐžĐŊ ĐąŅƒĐ´ĐĩŅ‚ ҁҁҋĐģĐ°Ņ‚ŅŒŅŅ ĐŊа `https://example.com/token`. Đ•ŅĐģи ĐļĐĩ Đ˛Đ°Ņˆ API Ņ€Đ°ŅĐŋĐžĐģĐžĐļĐĩĐŊ ĐŋĐž Đ°Đ´Ņ€Đĩҁ҃ `https://example.com/api/v1/`, Ņ‚Đž ĐžĐŊ ĐąŅƒĐ´ĐĩŅ‚ ҁҁҋĐģĐ°Ņ‚ŅŒŅŅ ĐŊа `https://example.com/api/v1/token`. + + Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ ĐžŅ‚ĐŊĐžŅĐ¸Ņ‚ĐĩĐģҌĐŊĐžĐŗĐž URL ваĐļĐŊĐž Đ´ĐģŅ Ņ‚ĐžĐŗĐž, Ņ‡Ņ‚ĐžĐąŅ‹ Đ˛Đ°ŅˆĐĩ ĐŋŅ€Đ¸ĐģĐžĐļĐĩĐŊиĐĩ ĐŋŅ€ĐžĐ´ĐžĐģĐļаĐģĐž Ņ€Đ°ĐąĐžŅ‚Đ°Ņ‚ŅŒ даĐļĐĩ в Ņ‚Đ°ĐēĐ¸Ņ… ҁĐģĐžĐļĐŊҋ҅ ҁĐģŅƒŅ‡Đ°ŅŅ…, ĐēаĐē ĐžĐŊĐž ĐŊĐ°Ņ…ĐžĐ´Đ¸Ņ‚ŅŅ [Са ĐŋŅ€ĐžĐēŅĐ¸-ҁĐĩŅ€Đ˛ĐĩŅ€ĐžĐŧ](../../advanced/behind-a-proxy.md){.internal-link target=_blank}. + +Đ­Ņ‚ĐžŅ‚ ĐŋĐ°Ņ€Đ°ĐŧĐĩ҂Ҁ ĐŊĐĩ ŅĐžĐˇĐ´Đ°ĐĩŅ‚ ĐēĐžĐŊĐĩ҇ĐŊŅƒŅŽ Ņ‚ĐžŅ‡Đē҃ / *ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸ŅŽ ĐŋŅƒŅ‚Đ¸*, а ĐžĐąŅŠŅĐ˛ĐģŅĐĩŅ‚, Ņ‡Ņ‚Đž URL `/token` ĐąŅƒĐ´ĐĩŅ‚ Ņ‚Đ°ĐēиĐŧ, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš ĐēĐģиĐĩĐŊŅ‚ Đ´ĐžĐģĐļĐĩĐŊ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ Đ´ĐģŅ ĐŋĐžĐģŅƒŅ‡ĐĩĐŊĐ¸Ņ Ņ‚ĐžĐēĐĩĐŊа. Đ­Ņ‚Đ° иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Ņ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ в OpenAPI, а ĐˇĐ°Ņ‚ĐĩĐŧ в иĐŊŅ‚ĐĩŅ€Đ°ĐēŅ‚Đ¸Đ˛ĐŊҋ҅ ŅĐ¸ŅŅ‚ĐĩĐŧĐ°Ņ… Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ°Ņ†Đ¸Đ¸ API. + +Đ’ŅĐēĐžŅ€Đĩ ĐŧŅ‹ ŅĐžĐˇĐ´Đ°Đ´Đ¸Đŧ и ŅĐ°Đŧ҃ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸ŅŽ ĐŋŅƒŅ‚Đ¸. + +!!! info "ДоĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊĐ°Ņ иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸Ņ" + Đ•ŅĐģи Đ˛Ņ‹ ĐžŅ‡ĐĩĐŊҌ ŅŅ‚Ņ€ĐžĐŗĐ¸Đš "ĐŋĐ¸Ņ‚ĐžĐŊĐ¸ŅŅ‚", Ņ‚Đž ваĐŧ ĐŧĐžĐļĐĩŅ‚ ĐŊĐĩ ĐŋĐžĐŊŅ€Đ°Đ˛Đ¸Ņ‚ŅŒŅŅ ŅŅ‚Đ¸ĐģҌ ĐŊаСваĐŊĐ¸Ņ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Đ° `tokenUrl` вĐŧĐĩŅŅ‚Đž `token_url`. + + Đ­Ņ‚Đž ŅĐ˛ŅĐˇĐ°ĐŊĐž ҁ Ņ‚ĐĩĐŧ, Ņ‡Ņ‚Đž Ņ‚ŅƒŅ‚ Đ¸ŅĐŋĐžĐģŅŒĐˇŅƒĐĩŅ‚ŅŅ Ņ‚Đž ĐļĐĩ иĐŧŅ, Ņ‡Ņ‚Đž и в ҁĐŋĐĩŅ†Đ¸Ņ„Đ¸ĐēĐ°Ņ†Đ¸Đ¸ OpenAPI. ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, ĐĩҁĐģи ваĐŧ ĐŊĐĩĐžĐąŅ…ĐžĐ´Đ¸ĐŧĐž йОĐģĐĩĐĩ ĐŋĐžĐ´Ņ€ĐžĐąĐŊĐž Đ¸ĐˇŅƒŅ‡Đ¸Ņ‚ŅŒ ĐēаĐēŅƒŅŽ-ĐģийО иС ŅŅ‚Đ¸Ņ… ҁ҅ĐĩĐŧ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸, Đ˛Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐŋŅ€ĐžŅŅ‚Đž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐēĐžĐŋĐ¸Ņ€ĐžĐ˛Đ°ĐŊиĐĩ/Đ˛ŅŅ‚Đ°Đ˛Đē҃, Ņ‡Ņ‚ĐžĐąŅ‹ ĐŊĐ°ĐšŅ‚Đ¸ Đ´ĐžĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊŅƒŅŽ иĐŊŅ„ĐžŅ€ĐŧĐ°Ņ†Đ¸ŅŽ Đž ĐŊĐĩĐš. + +ПĐĩŅ€ĐĩĐŧĐĩĐŊĐŊĐ°Ņ `oauth2_scheme` ŅĐ˛ĐģŅĐĩŅ‚ŅŅ ŅĐēСĐĩĐŧĐŋĐģŅŅ€ĐžĐŧ `OAuth2PasswordBearer`, ĐŊĐž ĐžĐŊа Ņ‚Đ°ĐēĐļĐĩ ŅĐ˛ĐģŅĐĩŅ‚ŅŅ "Đ˛Ņ‹ĐˇŅ‹Đ˛Đ°ĐĩĐŧОК". + +ЕĐĩ ĐŧĐžĐļĐŊĐž Đ˛Ņ‹ĐˇĐ˛Đ°Ņ‚ŅŒ ҁĐģĐĩĐ´ŅƒŅŽŅ‰Đ¸Đŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ: + +```Python +oauth2_scheme(some, parameters) +``` + +ĐŸĐžŅŅ‚ĐžĐŧ҃ ĐĩĐĩ ĐŧĐžĐļĐŊĐž Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ вĐŧĐĩҁ҂Đĩ ҁ `Depends`. + +### Đ˜ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°ĐŊиĐĩ + +ĐĸĐĩĐŋĐĩŅ€ŅŒ Đ˛Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐŋĐĩŅ€ĐĩĐ´Đ°Ņ‚ŅŒ Đ˛Đ°Ņˆ `oauth2_scheme` в ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚ŅŒ ҁ ĐŋĐžĐŧĐžŅ‰ŅŒŅŽ `Depends`. + +=== "Python 3.9+" + + ```Python hl_lines="12" + {!> ../../../docs_src/security/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="11" + {!> ../../../docs_src/security/tutorial001_an.py!} + ``` + +=== "Python 3.8+ ĐąĐĩС Annotated" + + !!! tip "ĐŸĐžĐ´ŅĐēаСĐēа" + ĐŸŅ€ĐĩĐ´ĐŋĐžŅ‡Ņ‚Đ¸Ņ‚ĐĩĐģҌĐŊĐĩĐĩ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ вĐĩŅ€ŅĐ¸ŅŽ ҁ аĐŊĐŊĐžŅ‚Đ°Ņ†Đ¸ĐĩĐš, ĐĩҁĐģи ŅŅ‚Đž вОСĐŧĐžĐļĐŊĐž. + + ```Python hl_lines="10" + {!> ../../../docs_src/security/tutorial001.py!} + ``` + +Đ­Ņ‚Đ° ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚ŅŒ ĐąŅƒĐ´ĐĩŅ‚ ĐŋŅ€ĐĩĐ´ĐžŅŅ‚Đ°Đ˛ĐģŅŅ‚ŅŒ `ŅŅ‚Ņ€ĐžĐē҃`, ĐēĐžŅ‚ĐžŅ€Đ°Ņ ĐŋŅ€Đ¸ŅĐ˛Đ°Đ¸Đ˛Đ°ĐĩŅ‚ŅŅ ĐŋĐ°Ņ€Đ°ĐŧĐĩŅ‚Ņ€Ņƒ `token` в *Ņ„ŅƒĐŊĐēŅ†Đ¸Đ¸ ĐžĐŋĐĩŅ€Đ°Ņ†Đ¸Đ¸ ĐŋŅƒŅ‚Đ¸*. + +**FastAPI** ĐąŅƒĐ´ĐĩŅ‚ СĐŊĐ°Ņ‚ŅŒ, Ņ‡Ņ‚Đž ĐžĐŊ ĐŧĐžĐļĐĩŅ‚ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ŅŅ‚Ņƒ ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚ŅŒ Đ´ĐģŅ ĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊĐ¸Ņ "ҁ҅ĐĩĐŧŅ‹ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸" в ҁ҅ĐĩĐŧĐĩ OpenAPI (и Đ°Đ˛Ņ‚ĐžĐŧĐ°Ņ‚Đ¸Ņ‡ĐĩҁĐēОК Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ°Ņ†Đ¸Đ¸ ĐŋĐž API). + +!!! info "ĐĸĐĩŅ…ĐŊĐ¸Ņ‡ĐĩҁĐēиĐĩ Đ´ĐĩŅ‚Đ°Đģи" + **FastAPI** ĐąŅƒĐ´ĐĩŅ‚ СĐŊĐ°Ņ‚ŅŒ, Ņ‡Ņ‚Đž ĐžĐŊ ĐŧĐžĐļĐĩŅ‚ Đ¸ŅĐŋĐžĐģŅŒĐˇĐžĐ˛Đ°Ņ‚ŅŒ ĐēĐģĐ°ŅŅ `OAuth2PasswordBearer` (ĐžĐąŅŠŅĐ˛ĐģĐĩĐŊĐŊŅ‹Đš в ĐˇĐ°Đ˛Đ¸ŅĐ¸ĐŧĐžŅŅ‚Đ¸) Đ´ĐģŅ ĐžĐŋŅ€ĐĩĐ´ĐĩĐģĐĩĐŊĐ¸Ņ ҁ҅ĐĩĐŧŅ‹ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸ в OpenAPI, ĐŋĐžŅĐēĐžĐģҌĐē҃ ĐžĐŊ ĐŊĐ°ŅĐģĐĩĐ´ŅƒĐĩŅ‚ŅŅ ĐžŅ‚ `fastapi.security.oauth2.OAuth2`, ĐēĐžŅ‚ĐžŅ€Ņ‹Đš, в ŅĐ˛ĐžŅŽ ĐžŅ‡ĐĩŅ€ĐĩĐ´ŅŒ, ĐŊĐ°ŅĐģĐĩĐ´ŅƒĐĩŅ‚ŅŅ ĐžŅ‚ `fastapi.security.base.SecurityBase`. + + Đ’ŅĐĩ ŅƒŅ‚Đ¸ĐģĐ¸Ņ‚Ņ‹ ĐąĐĩСОĐŋĐ°ŅĐŊĐžŅŅ‚Đ¸, иĐŊŅ‚ĐĩĐŗŅ€Đ¸Ņ€ŅƒĐĩĐŧŅ‹Đĩ в OpenAPI (и Đ°Đ˛Ņ‚ĐžĐŧĐ°Ņ‚Đ¸Ņ‡ĐĩҁĐēĐ°Ņ Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ°Ņ†Đ¸Ņ ĐŋĐž API), ĐŊĐ°ŅĐģĐĩĐ´ŅƒŅŽŅ‚ŅŅ ĐžŅ‚ `SecurityBase`, ĐŋĐžŅŅ‚ĐžĐŧ҃ **FastAPI** ĐŧĐžĐļĐĩŅ‚ СĐŊĐ°Ņ‚ŅŒ, ĐēаĐē иĐŊŅ‚ĐĩĐŗŅ€Đ¸Ņ€ĐžĐ˛Đ°Ņ‚ŅŒ Đ¸Ņ… в OpenAPI. + +## Đ§Ņ‚Đž ĐžĐŊ Đ´ĐĩĐģаĐĩŅ‚ + +ОĐŊ ĐąŅƒĐ´ĐĩŅ‚ Đ¸ŅĐēĐ°Ņ‚ŅŒ в СаĐŋŅ€ĐžŅĐĩ ĐˇĐ°ĐŗĐžĐģОвОĐē `Authorization` и ĐŋŅ€ĐžĐ˛ĐĩŅ€ŅŅ‚ŅŒ, ŅĐžĐ´ĐĩŅ€ĐļĐ¸Ņ‚ Đģи ĐžĐŊ СĐŊĐ°Ņ‡ĐĩĐŊиĐĩ `Bearer` ҁ ĐŊĐĩĐēĐžŅ‚ĐžŅ€Ņ‹Đŧ Ņ‚ĐžĐēĐĩĐŊĐžĐŧ, и Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‰Đ°Ņ‚ŅŒ Ņ‚ĐžĐēĐĩĐŊ в видĐĩ `ŅŅ‚Ņ€ĐžĐēи`. + +Đ•ŅĐģи ĐžĐŊ ĐŊĐĩ Đ˛Đ¸Đ´Đ¸Ņ‚ ĐˇĐ°ĐŗĐžĐģОвĐēа `Authorization` иĐģи СĐŊĐ°Ņ‡ĐĩĐŊиĐĩ ĐŊĐĩ иĐŧĐĩĐĩŅ‚ Ņ‚ĐžĐēĐĩĐŊа `Bearer`, Ņ‚Đž в ĐžŅ‚Đ˛ĐĩŅ‚ ĐąŅƒĐ´ĐĩŅ‚ Đ˛Ņ‹Đ´Đ°ĐŊа ĐžŅˆĐ¸ĐąĐēа ҁ ĐēОдОĐŧ ŅĐžŅŅ‚ĐžŅĐŊĐ¸Ņ 401 (`UNAUTHORIZED`). + +ДĐģŅ Đ˛ĐžĐˇĐ˛Ņ€Đ°Ņ‚Đ° ĐžŅˆĐ¸ĐąĐēи даĐļĐĩ ĐŊĐĩ ĐŊ҃ĐļĐŊĐž ĐŋŅ€ĐžĐ˛ĐĩŅ€ŅŅ‚ŅŒ, ŅŅƒŅ‰ĐĩŅŅ‚Đ˛ŅƒĐĩŅ‚ Đģи Ņ‚ĐžĐēĐĩĐŊ. Đ’Ņ‹ ĐŧĐžĐļĐĩŅ‚Đĩ ĐąŅ‹Ņ‚ŅŒ ŅƒĐ˛ĐĩŅ€ĐĩĐŊŅ‹, Ņ‡Ņ‚Đž ĐĩҁĐģи Đ˛Đ°ŅˆĐ° Ņ„ŅƒĐŊĐēŅ†Đ¸Ņ ĐąŅƒĐ´ĐĩŅ‚ Đ˛Ņ‹ĐŋĐžĐģĐŊиĐģĐ°ŅŅŒ, Ņ‚Đž в ŅŅ‚ĐžĐŧ Ņ‚ĐžĐēĐĩĐŊĐĩ ĐĩŅŅ‚ŅŒ `ŅŅ‚Ņ€ĐžĐēа`. + +ĐŸŅ€ĐžĐ˛ĐĩŅ€Đ¸Ņ‚ŅŒ ŅŅ‚Đž ĐŧĐžĐļĐŊĐž ҃ĐļĐĩ ҁĐĩĐšŅ‡Đ°Ņ в иĐŊŅ‚ĐĩŅ€Đ°ĐēŅ‚Đ¸Đ˛ĐŊОК Đ´ĐžĐē҃ĐŧĐĩĐŊŅ‚Đ°Ņ†Đ¸Đ¸: + + + +ĐœŅ‹ ĐŋĐžĐēа ĐŊĐĩ ĐŋŅ€ĐžĐ˛ĐĩŅ€ŅĐĩĐŧ ваĐģидĐŊĐžŅŅ‚ŅŒ Ņ‚ĐžĐēĐĩĐŊа, ĐŊĐž Đ´ĐģŅ ĐŊĐ°Ņ‡Đ°Đģа ĐŊĐĩĐŋĐģĐžŅ…Đž. + +## Đ ĐĩĐˇŅŽĐŧĐĩ + +ĐĸаĐēиĐŧ ĐžĐąŅ€Đ°ĐˇĐžĐŧ, Đ˛ŅĐĩĐŗĐž Са 3-4 Đ´ĐžĐŋĐžĐģĐŊĐ¸Ņ‚ĐĩĐģҌĐŊŅ‹Đĩ ŅŅ‚Ņ€ĐžĐēи Đ˛Ņ‹ ĐŋĐžĐģŅƒŅ‡Đ°ĐĩŅ‚Đĩ ĐŊĐĩĐēŅƒŅŽ ĐŋŅ€Đ¸ĐŧĐ¸Ņ‚Đ¸Đ˛ĐŊŅƒŅŽ Ņ„ĐžŅ€Đŧ҃ ĐˇĐ°Ņ‰Đ¸Ņ‚Ņ‹. From a56d32c3a463eb83173d01bb42eac46511e98952 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:01:38 +0000 Subject: [PATCH 189/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 4ccedda1dc..1a0f15d301 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Russian translation for `docs/ru/docs/tutorial/security/first-steps.md`. PR [#10541](https://github.com/tiangolo/fastapi/pull/10541) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/handling-errors.md`. PR [#10375](https://github.com/tiangolo/fastapi/pull/10375) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/encoder.md`. PR [#10374](https://github.com/tiangolo/fastapi/pull/10374) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/body-updates.md`. PR [#10373](https://github.com/tiangolo/fastapi/pull/10373) by [@AlertRED](https://github.com/AlertRED). From 0ec0df50906a2fcb30e6c96c7206b185e61a3de4 Mon Sep 17 00:00:00 2001 From: DoHyun Kim Date: Tue, 23 Jan 2024 23:02:49 +0900 Subject: [PATCH 190/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/security/get-current-user.md`?= =?UTF-8?q?=20(#5737)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tutorial/security/get-current-user.md | 151 ++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 docs/ko/docs/tutorial/security/get-current-user.md diff --git a/docs/ko/docs/tutorial/security/get-current-user.md b/docs/ko/docs/tutorial/security/get-current-user.md new file mode 100644 index 0000000000..ce944b16d4 --- /dev/null +++ b/docs/ko/docs/tutorial/security/get-current-user.md @@ -0,0 +1,151 @@ +# 현ėžŦ ė‚ŦėšŠėž ę°€ė ¸ė˜¤ę¸° + +ė´ė „ ėžĨė—ė„œ (ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œė„ 기반ėœŧ로 한)ëŗ´ė•ˆ ė‹œėŠ¤í…œė€ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ė—ė„œ `str`로 `token`ė„ 렜ęŗĩ했ėŠĩ니다: + +```Python hl_lines="10" +{!../../../docs_src/security/tutorial001.py!} +``` + +꡸ëŸŦ나 ė•„ė§ë„ ėœ ėšŠí•˜ė§€ ė•ŠėŠĩ니다. + +현ėžŦ ė‚ŦėšŠėžëĨŧ 렜ęŗĩ하도록 í•Šė‹œë‹¤. + +## ėœ ė € ëĒ¨ë¸ ėƒė„ąí•˜ę¸° + +ë¨ŧė € Pydantic ėœ ė € ëĒ¨ë¸ė„ ë§Œë“¤ė–´ ëŗ´ę˛ ėŠĩ니다. + +Pydanticė„ ė‚ŦėšŠí•˜ė—Ŧ ëŗ¸ëŦ¸ė„ ė„ ė–¸í•˜ëŠ” 것ęŗŧ ę°™ė€ ë°Šė‹ėœŧ로 다ëĨ¸ ęŗŗė—ė„œ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +=== "íŒŒė´ėŦ 3.7 ė´ėƒ" + + ```Python hl_lines="5 12-16" + {!> ../../../docs_src/security/tutorial002.py!} + ``` + +=== "íŒŒė´ėŦ 3.10 ė´ėƒ" + + ```Python hl_lines="3 10-14" + {!> ../../../docs_src/security/tutorial002_py310.py!} + ``` + +## `get_current_user` ė˜ėĄ´ė„ą ėƒė„ąí•˜ę¸° + +ė˜ėĄ´ė„ą `get_current_user`ëĨŧ ë§Œë“¤ė–´ ë´…ė‹œë‹¤. + +ė˜ėĄ´ė„ąė´ í•˜ėœ„ ė˜ėĄ´ė„ąė„ ę°€ė§ˆ 눘 ėžˆë‹¤ëŠ” ę˛ƒė„ 기ė–ĩí•˜ė‹­ë‹ˆęšŒ? + +`get_current_user`는 ė´ė „ė— ėƒė„ąí•œ 것ęŗŧ 동ėŧ한 `oauth2_scheme`ęŗŧ ėĸ…ė†ė„ąė„ 갖게 됩니다. + +ė´ė „ė— *ę˛Ŋ로 ë™ėž‘*ė—ė„œ 링렑 ėˆ˜í–‰í–ˆë˜ 것ęŗŧ 동ėŧ하게 냈 ėĸ…ė†ė„ą `get_current_user`는 í•˜ėœ„ ėĸ…ė†ė„ą `oauth2_scheme`ė—ė„œ `str`로 `token`ė„ ėˆ˜ė‹ í•Šë‹ˆë‹¤. + +=== "íŒŒė´ėŦ 3.7 ė´ėƒ" + + ```Python hl_lines="25" + {!> ../../../docs_src/security/tutorial002.py!} + ``` + +=== "íŒŒė´ėŦ 3.10 ė´ėƒ" + + ```Python hl_lines="23" + {!> ../../../docs_src/security/tutorial002_py310.py!} + ``` + +## ėœ ė € ę°€ė ¸ė˜¤ę¸° + +`get_current_user`는 í† í°ė„ `str`로 ėˇ¨í•˜ęŗ  Pydantic `User` ëĒ¨ë¸ė„ 반환하는 뚰ëĻŦ가 만든 (ę°€ė§œ) ėœ í‹¸ëĻŦ티 í•¨ėˆ˜ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤. + +=== "íŒŒė´ėŦ 3.7 ė´ėƒ" + + ```Python hl_lines="19-22 26-27" + {!> ../../../docs_src/security/tutorial002.py!} + ``` + +=== "íŒŒė´ėŦ 3.10 ė´ėƒ" + + ```Python hl_lines="17-20 24-25" + {!> ../../../docs_src/security/tutorial002_py310.py!} + ``` + +## 현ėžŦ ėœ ė € ėŖŧėž…í•˜ę¸° + +ė´ė œ *ę˛Ŋ로 ėž‘ë™*ė—ė„œ `get_current_user`뙀 동ėŧ한 `Depends`ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +=== "íŒŒė´ėŦ 3.7 ė´ėƒ" + + ```Python hl_lines="31" + {!> ../../../docs_src/security/tutorial002.py!} + ``` + +=== "íŒŒė´ėŦ 3.10 ė´ėƒ" + + ```Python hl_lines="29" + {!> ../../../docs_src/security/tutorial002_py310.py!} + ``` + +Pydantic ëĒ¨ë¸ė¸ `User`로 `current_user`ė˜ íƒ€ėž…ė„ ė„ ė–¸í•˜ëŠ” ę˛ƒė„ ė•Œė•„ė•ŧ 합니다. + +ė´ę˛ƒė€ ëĒ¨ë“  ė™„ëŖŒ 및 íƒ€ėž… 검ė‚ŦëĨŧ í†ĩ해 í•¨ėˆ˜ 내ëļ€ė—ė„œ 뚰ëĻŦëĨŧ ë„ėš¸ ę˛ƒėž…ë‹ˆë‹¤. + +!!! 팁 + ėš”ė˛­ ëŗ¸ëŦ¸ë„ Pydantic ëĒ¨ë¸ëĄœ ė„ ė–¸ëœë‹¤ëŠ” ę˛ƒė„ 기ė–ĩ할 ę˛ƒėž…ë‹ˆë‹¤. + + ė—Ŧę¸°ė„œ **FastAPI**는 `Depends`ëĨŧ ė‚ŦėšŠí•˜ęŗ  ėžˆę¸° 때ëŦ¸ė— í˜ŧë™ë˜ė§€ ė•ŠėŠĩ니다. + +!!! í™•ė¸ + ė´ ė˜ėĄ´ė„ą ė‹œėŠ¤í…œė´ ė„¤ęŗ„ëœ ë°Šė‹ė€ ëĒ¨ë‘ `User` ëĒ¨ë¸ė„ 반환하는 ë‹¤ė–‘í•œ ė˜ėĄ´ė„ą(다ëĨ¸ "ė˜ėĄ´ė ė¸")ė„ ę°€ė§ˆ 눘 ėžˆë„ëĄ 합니다. + + 해당 íƒ€ėž…ė˜ ë°ė´í„°ëĨŧ 반환할 눘 ėžˆëŠ” ė˜ėĄ´ė„ąė´ 하나만 ėžˆëŠ” 것ėœŧ로 ė œí•œë˜ė§€ ė•ŠėŠĩ니다. + +## 다ëĨ¸ ëĒ¨ë¸ + +ė´ė œ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ė—ė„œ 현ėžŦ ė‚ŦėšŠėžëĨŧ 링렑 氀렏ė˜Ŧ 눘 ėžˆėœŧ늰 `Depends`ëĨŧ ė‚ŦėšŠí•˜ė—Ŧ **ė˜ėĄ´ė„ą ėŖŧėž…** ėˆ˜ė¤€ė—ė„œ ëŗ´ė•ˆ 메ėģ¤ë‹ˆėĻ˜ė„ 래ëĻŦ할 눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  ëŗ´ė•ˆ ėš”ęĩŦ ė‚Ŧí•­ė— 대한 ëĒ¨ë“  ëĒ¨ë¸ 또는 ë°ė´í„°ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다(ė´ ę˛Ŋ뚰 Pydantic ëĒ¨ë¸ `User`). + +꡸ëŸŦ나 ėŧëļ€ íŠšė • ë°ė´í„° ëĒ¨ë¸, í´ëž˜ėŠ¤ 또는 íƒ€ėž…ė„ ė‚ŦėšŠí•˜ë„ëĄ ė œí•œë˜ė§€ ė•ŠėŠĩ니다. + +ëĒ¨ë¸ė— `id`뙀 `email`ė´ ėžˆęŗ  `username`ė´ 뗆描 ė›í•˜ė‹­ë‹ˆęšŒ? 맞ėŠĩ니다. ė´ë“¤ė€ 동ėŧ한 도ęĩŦëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +`str`만 ę°–ęŗ  ė‹ļėŠĩ니까? ė•„ë‹ˆëŠ´ ꡸ëƒĨ `dict`ëĨŧ ę°–ęŗ  ė‹ļėŠĩ니까? ė•„ë‹ˆëŠ´ ë°ė´í„°ë˛ ė´ėŠ¤ í´ëž˜ėŠ¤ ëĒ¨ë¸ ė¸ėŠ¤í„´ėŠ¤ëĨŧ 링렑 ę°–ęŗ  ė‹ļėŠĩ니까? ęˇ¸ë“¤ė€ ëĒ¨ë‘ ę°™ė€ ë°Šė‹ėœŧ로 ėž‘ë™í•Šë‹ˆë‹¤. + +ė‹¤ė œëĄœ ė• í”ŒëĻŦėŧ€ė´ė…˜ė— ëĄœęˇ¸ė¸í•˜ëŠ” ė‚ŦėšŠėžę°€ ė—†ė§€ë§Œ ė•Ąė„¸ėŠ¤ 토큰만 ėžˆëŠ” 로봇, 봇 또는 기타 ė‹œėŠ¤í…œė´ ėžˆėŠĩ니까? ë‹¤ė‹œ ë§í•˜ė§€ë§Œ ëĒ¨ë‘ 동ėŧ하게 ėž‘ë™í•Šë‹ˆë‹¤. + +ė• í”ŒëĻŦėŧ€ė´ė…˜ė— í•„ėš”í•œ ëĒ¨ë“  ėĸ…ëĨ˜ė˜ ëĒ¨ë¸, ëĒ¨ë“  ėĸ…ëĨ˜ė˜ í´ëž˜ėŠ¤, ëĒ¨ë“  ėĸ…ëĨ˜ė˜ ë°ė´í„°ë˛ ė´ėŠ¤ëĨŧ ė‚ŦėšŠí•˜ė‹­ė‹œė˜¤. **FastAPI**는 ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œė„ ë‹¤ëŖ¨ė—ˆėŠĩ니다. + +## ėŊ”드 ė‚Ŧė´ėψ + +ė´ ė˜ˆëŠ” ėžĨ황해 ëŗ´ėŧ 눘 ėžˆėŠĩ니다. 동ėŧ한 파ėŧė—ė„œ ëŗ´ė•ˆ, ë°ė´í„° ëĒ¨ë¸, ėœ í‹¸ëĻŦ티 기ëŠĨ 및 *ę˛Ŋ로 ėž‘ë™*ė„ í˜ŧí•Ší•˜ęŗ  ėžˆėŒė„ ė—ŧë‘ė— ë‘ė‹­ė‹œė˜¤. + +꡸ëŸŦ나 ė´ę˛Œ 키íŦė¸íŠ¸ėž…ë‹ˆë‹¤. + +ëŗ´ė•ˆęŗŧ ėĸ…ė†ė„ą ėŖŧėž… 항ëĒŠė„ 한 번만 ėž‘ė„ąí•˜ëŠ´ 됩니다. + +꡸ëĻŦęŗ  ė›í•˜ëŠ” 만íŧ ëŗĩėžĄí•˜ę˛Œ 만들 눘 ėžˆėŠĩ니다. 그래도 ėœ ė—°ė„ąęŗŧ 함ęģ˜ í•œ 溺뗐 한 ë˛ˆė— ėž‘ė„ąí•  눘 ėžˆėŠĩ니다. + +꡸ëŸŦ나 동ėŧ한 ëŗ´ė•ˆ ė‹œėŠ¤í…œė„ ė‚ŦėšŠí•˜ė—Ŧ 눘랜 ę°œė˜ ė—”ë“œíŦė¸íŠ¸(*ę˛Ŋ로 ėž‘ë™*)ëĨŧ ę°€ė§ˆ 눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  그들 ëĒ¨ë‘(또는 ė›í•˜ëŠ” ëļ€ëļ„)는 ė´ëŸŦ한 ė˜ėĄ´ė„ą 또는 ėƒė„ąí•œ 다ëĨ¸ ė˜ėĄ´ė„ąė„ ėžŦė‚ŦėšŠí•˜ëŠ” ė´ė ė„ ė–ģė„ 눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  ė´ 눘랜 ę°œė˜ *ę˛Ŋ로 ėž‘ë™*ė€ ëĒ¨ë‘ 3뤄 ė •ë„ëĄœ 뤄ėŧ 눘 ėžˆėŠĩ니다. + +=== "íŒŒė´ėŦ 3.7 ė´ėƒ" + + ```Python hl_lines="30-32" + {!> ../../../docs_src/security/tutorial002.py!} + ``` + +=== "íŒŒė´ėŦ 3.10 ė´ėƒ" + + ```Python hl_lines="28-30" + {!> ../../../docs_src/security/tutorial002_py310.py!} + ``` + +## ėš”ė•Ŋ + +ė´ė œ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ė—ė„œ 현ėžŦ ė‚ŦėšŠėžëĨŧ 링렑 氀렏ė˜Ŧ 눘 ėžˆėŠĩ니다. + +뚰ëĻŦ는 ė´ë¯¸ ė´ë“¤ ė‚Ŧė´ė— ėžˆėŠĩ니다. + +ė‚ŦėšŠėž/클ëŧė´ė–¸íŠ¸ę°€ ė‹¤ė œëĄœ `username`ęŗŧ `password`ëĨŧ ëŗ´ë‚´ë ¤ëŠ´ *ę˛Ŋ로 ėž‘ë™*ė„ ėļ”ę°€í•˜ę¸°ë§Œ 하면 됩니다. + +ë‹¤ėŒ ėžĨė„ í™•ė¸í•´ ë´…ė‹œë‹¤. From 058044fdb148d6af6a90fbd13001c6423209569e Mon Sep 17 00:00:00 2001 From: Kani Kim Date: Tue, 23 Jan 2024 23:04:27 +0900 Subject: [PATCH 191/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/features.md`=20(#10976)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/features.md | 203 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 docs/ko/docs/features.md diff --git a/docs/ko/docs/features.md b/docs/ko/docs/features.md new file mode 100644 index 0000000000..42a3ff172c --- /dev/null +++ b/docs/ko/docs/features.md @@ -0,0 +1,203 @@ +--- +hide: + - navigation +--- + +# 기ëŠĨ + +## FastAPIė˜ 기ëŠĨ + +**FastAPI**는 ë‹¤ėŒęŗŧ ę°™ė€ 기ëŠĨė„ 렜ęŗĩ합니다: + +### 개방형 í‘œė¤€ė„ 기반ėœŧ로 + +* ę˛ŊëĄœėž‘ë™, ë§¤ę°œëŗ€ėˆ˜, ëŗ¸ëŦ¸ ėš”ė˛­, ëŗ´ė•ˆ ꡸ ė™¸ė˜ ė„ ė–¸ė„ íŦ함한 API ėƒė„ąė„ ėœ„í•œ OpenAPI +* JSON Schema (OpenAPI ėžė˛´ę°€ JSON SchemaëĨŧ 기반ėœŧ로 í•˜ęŗ  ėžˆėŠĩ니다)ëĨŧ ė‚ŦėšŠí•œ ėžë™ ë°ė´í„° ëĒ¨ë¸ ëŦ¸ė„œí™”. +* ë‹¨ėˆœížˆ 떠ė˜Ŧë ¤ė„œ 덧ëļ™ė¸ 기ëŠĨė´ ė•„ë‹™ë‹ˆë‹¤. 넏ė‹Ŧ한 검토ëĨŧ ęą°ėšœ 후, ė´ëŸŦ한 í‘œė¤€ė„ 기반ėœŧ로 ė„¤ęŗ„ë˜ė—ˆėŠĩ니다. +* ė´ëŠ” 또한 ë‹¤ė–‘í•œ ė–¸ė–´ëĄœ ėžë™ė ė¸ **클ëŧė´ė–¸íŠ¸ ėŊ”드 ėƒė„ą**ė„ ė‚ŦėšŠí•  눘 ėžˆę˛Œ ė§€ė›í•Šë‹ˆë‹¤. + +### ëŦ¸ė„œ ėžë™í™” + +대화형 API ëŦ¸ė„œė™€ ė›š íƒėƒ‰ ėœ ė € ė¸í„°íŽ˜ė´ėŠ¤ëĨŧ 렜ęŗĩ합니다. í”„ë ˆėž„ė›ŒíŦ가 OpenAPIëĨŧ 기반ėœŧ로 í•˜ę¸°ė—, 2氀맀 ė˜ĩė…˜ė´ ę¸°ëŗ¸ė ėœŧ로 ë“¤ė–´ę°„ ė—ŦëŸŦ ė˜ĩė…˜ė´ ėĄ´ėžŦ합니다. + +* 대화형 íƒėƒ‰ Swagger UIëĨŧ ė´ėšŠí•´, 브ëŧėš°ė €ė—ė„œ 바로 ė—ŦëŸŦëļ„ė˜ APIëĨŧ 호ėļœí•˜ęą°ë‚˜ í…ŒėŠ¤íŠ¸í•  눘 ėžˆėŠĩ니다. + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) + +* ReDocė„ ė´ėšŠí•´ API ëŦ¸ė„œí™”ëĨŧ ëŒ€ė˛´í•  눘 ėžˆėŠĩ니다. + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) + +### 掏렀 현대 íŒŒė´ėŦ + +(Pydantic 덕ëļ„뗐) FastAPI는 í‘œė¤€ **íŒŒė´ėŦ 3.6 íƒ€ėž…** 넠떏뗐 ę¸°ë°˜í•˜ęŗ  ėžˆėŠĩ니다. ėƒˆëĄœ ë°°ėš¸ ëŦ¸ë˛•ė´ ė—†ėŠĩ니다. 掏렀 í‘œė¤€ė ė¸ 현대 íŒŒė´ėŦėž…ë‹ˆë‹¤. + +만ė•Ŋ ė—ŦëŸŦëļ„ė´ íŒŒė´ėŦ íƒ€ėž…ė„ ė–´ë–ģ枌 ė‚ŦėšŠí•˜ëŠ”ė§€ė— 대한 2ëļ„ ė •ë„ė˜ ëŗĩėŠĩė´ í•„ėš”í•˜ë‹¤ëŠ´ (비록 ė—ŦëŸŦëļ„ė´ FastAPIëĨŧ ė‚ŦėšŠí•˜ė§€ ė•ŠëŠ”ë‹¤ 하더ëŧ도), ë‹¤ėŒė˜ ė§§ė€ ėžėŠĩė„œëĨŧ í™•ė¸í•˜ė„¸ėš”: [íŒŒė´ėŦ íƒ€ėž…](python-types.md){.internal-link target=\_blank}. + +ė—ŦëŸŦëļ„ė€ íƒ€ėž…ė„ ė´ėšŠí•œ í‘œė¤€ íŒŒė´ėŦė„ ë‹¤ėŒęŗŧ ę°™ė´ ė ė„ 눘 ėžˆėŠĩ니다: + +```Python +from datetime import date + +from pydantic import BaseModel + +# ëŗ€ėˆ˜ëĨŧ str로 ė„ ė–¸ +# ꡸ 후 í•¨ėˆ˜ ė•ˆė—ė„œ íŽ¸ė§‘ę¸° ė§€ė›ė„ 받ėœŧė„¸ėš” +def main(user_id: str): + return user_id + + +# Pydantic ëĒ¨ë¸ +class User(BaseModel): + id: int + name: str + joined: date +``` + +ėœ„ė˜ ėŊ”드는 ë‹¤ėŒęŗŧ ę°™ė´ ė‚ŦėšŠë  눘 ėžˆėŠĩ니다: + +```Python +my_user: User = User(id=3, name="John Doe", joined="2018-07-19") + +second_user_data = { + "id": 4, + "name": "Mary", + "joined": "2018-11-30", +} + +my_second_user: User = User(**second_user_data) +``` + +!!! ė •ëŗ´ + `**second_user_data`가 ëœģ하는 것: + + `second_user_data` ë”•ė…”ë„ˆëĻŦė˜ í‚¤ė™€ ę°’ė„ 키-값 ė¸ėžëĄœė„œ 바로 ë„˜ę˛¨ė¤ë‹ˆë‹¤. ë‹¤ėŒęŗŧ 동ėŧ합니다: `User(id=4, name="Mary", joined="2018-11-30")` + +### íŽ¸ė§‘ę¸° 맀뛐 + +ëĒ¨ë“  í”„ë ˆėž„ė›ŒíŦ는 ė‚ŦėšŠí•˜ę¸° ė‰Ŋęŗ  링洀렁ėœŧ로 ė„¤ęŗ„ë˜ė—ˆėœŧ늰, ėĸ‹ė€ 개발 ę˛Ŋí—˜ė„ ëŗ´ėžĨ하기 ėœ„í•´ ę°œë°œė„ ė‹œėž‘í•˜ę¸°ë„ 렄뗐 ëĒ¨ë“  ę˛°ė •ë“¤ė€ ė—ŦëŸŦ íŽ¸ė§‘ę¸°ė—ė„œ í…ŒėŠ¤íŠ¸ëŠë‹ˆë‹¤. + +ėĩœęˇŧ íŒŒė´ėŦ ę°œë°œėž 네ëŦ¸ėĄ°ė‚Ŧė—ė„œ "ėžë™ ė™„ė„ą"ė´ 가ėžĨ ë§Žė´ ė‚ŦėšŠë˜ëŠ” 기ëŠĨė´ëŧ는 ę˛ƒė´ ë°í˜€ėĄŒėŠĩ니다. + +**FastAPI** í”„ë ˆėž„ė›ŒíŦė˜ ëĒ¨ë“  ëļ€ëļ„ė€ ė´ëĨŧ ėļŠėĄąí•˜ę¸° ėœ„í•´ ė„¤ęŗ„ë˜ė—ˆėŠĩ니다. ėžë™ė™„ė„ąė€ ė–´ëŠ ęŗŗė—ė„œë‚˜ ėž‘ë™í•Šë‹ˆë‹¤. + +ė—ŦëŸŦëļ„ė€ ëŦ¸ė„œëĄœ ë‹¤ė‹œ ëŒė•„ė˜Ŧ ėŧė´ ęą°ė˜ ė—†ė„ 겁니다. + +ë‹¤ėŒė€ íŽ¸ė§‘ę¸°ę°€ ė–´ë–ģ枌 ė—ŦëŸŦëļ„ė„ ë„ė™€ėŖŧëŠ”ė§€ ëŗ´ė—Ŧė¤ë‹ˆë‹¤: + +* Visual Studio Codeė—ė„œ: + +![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) + +* PyCharmė—ė„œ: + +![editor support](https://fastapi.tiangolo.com/img/pycharm-completion.png) + +ė—ŦëŸŦëļ„ė´ ė´ė „ė— ëļˆę°€ëŠĨí•˜ë‹¤ęŗ  ęŗ ë ¤í–ˆë˜ ėŊ”드도 ė™„ė„ąí•  눘 ėžˆė„ 겁니다. 똈ëĨŧ ë“¤ė–´, ėš”ė˛­ė—ė„œ ė „ë‹Ŧ되는 (ė¤‘ė˛Šë  ėˆ˜ë„ ėžˆëŠ”)JSON ëŗ¸ëŦ¸ 내ëļ€ė— ėžˆëŠ” `price` í‚¤ėž…ë‹ˆë‹¤. + +ėž˜ëĒģ된 키 ė´ëĻ„ė„ ė ė„ ėŧ도, ëŦ¸ė„œëĨŧ ė™”ë‹¤ 갔다할 ėŧ도 ė—†ėœŧ늰, í˜šė€ ë§ˆė§€ë§‰ėœŧ로 `username` 또는 `user_name`ė„ ė‚ŦėšŠí–ˆëŠ”ė§€ ė°žę¸° ėœ„í•´ ėœ„ ė•„ëž˜ëĄœ 늤íŦ롤할 ėŧ도 ė—†ėŠĩ니다. + +### 토막 ė •ëŗ´ + +ė–´ëŠ ęŗŗė—ė„œë‚˜ ė„ íƒė  ęĩŦė„ąė´ 가ëŠĨ한 ëĒ¨ë“  ę˛ƒė— 합ëĻŦė ė¸ ę¸°ëŗ¸ę°’ė´ ė„¤ė •ë˜ė–´ ėžˆėŠĩ니다. ëĒ¨ë“  ë§¤ę°œëŗ€ėˆ˜ëŠ” ė—ŦëŸŦëļ„ė´ í•„ėš”í•˜ęą°ë‚˜, ė›í•˜ëŠ” APIëĨŧ ė •ė˜í•˜ę¸° ėœ„í•´ ë¯¸ė„¸í•˜ę˛Œ ėĄ°ė •í•  눘 ėžˆėŠĩ니다. + +í•˜ė§€ë§Œ ę¸°ëŗ¸ė ėœŧ로 ëĒ¨ë“  ę˛ƒė´ "꡸ëƒĨ ėž‘ë™í•Šë‹ˆë‹¤". + +### 검ėĻ + +* ë‹¤ėŒė„ íŦ함한, 대ëļ€ëļ„ė˜ (í˜šė€ ëĒ¨ë“ ?) íŒŒė´ėŦ **ë°ė´í„° íƒ€ėž…** 검ėĻí•  눘 ėžˆėŠĩ니다: + * JSON ę°ė˛´ (`dict`). + * ė•„ė´í…œ íƒ€ėž…ė„ ė •ė˜í•˜ëŠ” JSON ë°°ė—´ (`list`). + * ėĩœė†Œ ę¸¸ė´ė™€ ėĩœëŒ€ ę¸¸ė´ëĨŧ ė •ė˜í•˜ëŠ” ëŦ¸ėžė—´ (`str`) 필드. + * ėĩœė†Ÿę°’ęŗŧ ėĩœëŒ“ę°’ė„ ę°€ė§€ëŠ” ėˆĢėž (`int`, `float`), ꡸ 뙏. + +* ë‹¤ėŒęŗŧ ę°™ė´ ë”ėšą ė´ėƒ‰ė ė¸ íƒ€ėž…ė— 대해 검ėĻí•  눘 ėžˆėŠĩ니다: + * URL. + * ė´ëŠ”ėŧ. + * UUID. + * ...다ëĨ¸ 것들. + +ëĒ¨ë“  검ėĻė€ ę˛Ŧęŗ í•˜ëŠ´ė„œ ėž˜ 확ëĻŊ된 **Pydantic**뗐 ė˜í•´ 래ëĻŦ됩니다. + +### ëŗ´ė•ˆęŗŧ ė¸ėĻ + +ëŗ´ė•ˆęŗŧ ė¸ėĻė´ í†ĩí•Šë˜ė–´ ėžˆėŠĩ니다. ë°ė´í„°ë˛ ė´ėŠ¤ë‚˜ ë°ė´í„° ëĒ¨ë¸ęŗŧė˜ íƒ€í˜‘ė—†ė´ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +ë‹¤ėŒė„ íŦ함하는, ëĒ¨ë“  ëŗ´ė•ˆ ėŠ¤í‚¤ë§ˆę°€ OpenAPI뗐 ė •ė˜ë˜ė–´ ėžˆėŠĩ니다. + +* HTTP Basic. +* **OAuth2** (**JWT tokens** 또한 íŦ함). [OAuth2 with JWT](tutorial/security/oauth2-jwt.md){.internal-link target=\_blank}뗐 ėžˆëŠ” ėžėŠĩė„œëĨŧ í™•ė¸í•´ ëŗ´ė„¸ėš”. +* ë‹¤ėŒė— ë“¤ė–´ ėžˆëŠ” API 키: + * 헤더. + * ë§¤ę°œëŗ€ėˆ˜. + * ėŋ í‚¤ 및 ꡸ 뙏. + +ėļ”氀렁ėœŧ로 (**ė„¸ė…˜ ėŋ í‚¤**ëĨŧ íŦ함한) ëĒ¨ë“  ëŗ´ė•ˆ 기ëŠĨė€ Starlette뗐 ėžˆėŠĩ니다. + +ëĒ¨ë‘ ėžŦė‚ŦėšŠí•  눘 ėžˆëŠ” 도ęĩŦ뙀 ėģ´íŦ넌트로 ë§Œë“¤ė–´ė ¸ ėžˆė–´ ė—ŦëŸŦëļ„ė˜ ė‹œėŠ¤í…œ, ë°ė´í„° ė €ėžĨė†Œ, ę´€ęŗ„í˜• 및 NoSQL ë°ė´í„°ë˛ ė´ėŠ¤ 등ęŗŧ ė‰Ŋ枌 í†ĩ합할 눘 ėžˆėŠĩ니다. + +### ė˜ėĄ´ė„ą ėŖŧėž… + +FastAPI는 ė‚ŦėšŠí•˜ę¸° ë§¤ėš° ę°„íŽ¸í•˜ė§€ë§Œ, ė—„ė˛­ë‚œ ė˜ėĄ´ė„ą ėŖŧėž…ė‹œėŠ¤í…œė„ íŦí•¨í•˜ęŗ  ėžˆėŠĩ니다. + +* ė˜ėĄ´ė„ąė€ ė˜ėĄ´ė„ąė„ ę°€ė§ˆėˆ˜ë„ ėžˆė–´, ė´ëĨŧ í†ĩ해 ė˜ėĄ´ė„ąė˜ ęŗ„ė¸ĩė´ë‚˜ **ė˜ėĄ´ė„ąė˜ "그래프"**ëĨŧ í˜•ė„ąí•Šë‹ˆë‹¤. +* ëĒ¨ë“  ę˛ƒė´ í”„ë ˆėž„ė›ŒíŦ뗐 ė˜í•´ **ėžë™ė ėœŧ로 래ëĻŦ됩니다**. +* ëĒ¨ë“  ė˜ėĄ´ė„ąė€ ėš”ė˛­ė—ė„œ ë°ė´í„°ëĨŧ ėš”ęĩŦ하ė—Ŧ ėžë™ ëŦ¸ė„œí™”뙀 **ę˛Ŋ로 ėž‘ë™ 렜ė•Ŋė„ 강화할 눘 ėžˆėŠĩ니다**. +* ė˜ėĄ´ė„ąė—ė„œ ė •ė˜ëœ _ę˛Ŋ로 ėž‘ë™_ ë§¤ę°œëŗ€ėˆ˜ė— ëŒ€í•´ė„œë„ **ėžë™ 검ėĻ**ė´ ė´ëŖ¨ė–´ ė§‘ë‹ˆë‹¤. +* ëŗĩėžĄí•œ ė‚ŦėšŠėžė˜ ė¸ėĻ ė‹œėŠ¤í…œ, **ë°ė´í„°ë˛ ė´ėŠ¤ 뗰枰**, ë“ąë“ąė„ ė§€ė›í•Šë‹ˆë‹¤. +* ë°ė´í„°ë˛ ė´ėŠ¤, í”„ëĄ íŠ¸ė—”ë“œ 등ęŗŧ ę´€ë ¨ë˜ė–´ **íƒ€í˜‘í•˜ė§€ ė•Šė•„ë„ 됩니다**. í•˜ė§€ë§Œ ꡸ ëĒ¨ë“  것ęŗŧ ė‰Ŋ枌 í†ĩí•Šė´ 가ëŠĨ합니다. + +### ė œí•œ ė—†ëŠ” "플ëŸŦęˇ¸ė¸" + +또는 다ëĨ¸ 방법ėœŧ로, ęˇ¸ę˛ƒë“¤ė„ ė‚ŦėšŠí•  í•„ėš” ė—†ė´ í•„ėš”í•œ ėŊ”드만 ėž„íŦ트할 눘 ėžˆėŠĩ니다. + +ė–´ëŠ í†ĩ합도 (ė˜ėĄ´ė„ąęŗŧ 함ęģ˜) ė‚ŦėšŠí•˜ę¸° ė‰Ŋ枌 ė„¤ęŗ„ë˜ė–´ ėžˆė–´, *ę˛Ŋ로 ėž‘ë™*뗐 ė‚ŦėšŠëœ 것ęŗŧ 동ėŧ한 ęĩŦėĄ°ė™€ ëŦ¸ë˛•ė„ ė‚ŦėšŠí•˜ė—Ŧ 2ė¤„ė˜ ėŊ”ë“œëĄœ ė—ŦëŸŦëļ„ė˜ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė— ė‚ŦėšŠí•  "플ëŸŦęˇ¸ė¸"ė„ 만들 눘 ėžˆėŠĩ니다. + +### í…ŒėŠ¤íŠ¸ 결ęŗŧ + +* 100% í…ŒėŠ¤íŠ¸ ë˛”ėœ„. +* 100% íƒ€ėž…ė´ ëĒ…ė‹œëœ ėŊ”드 ë˛ ė´ėŠ¤. +* ėƒėšŠ ė–´í”ŒëĻŦėŧ€ė´ė…˜ė—ė„œė˜ ė‚ŦėšŠ. + +## Starlette 기ëŠĨ + +**FastAPI**는 StarletteëĨŧ 기반ėœŧ로 ęĩŦėļ•ë˜ė—ˆėœŧ늰, ė´ė™€ ė™„ė „ížˆ 호환됩니다. 따ëŧė„œ, ė—ŦëŸŦëļ„ė´ ëŗ´ėœ í•˜ęŗ  ėžˆëŠ” ė–´ë–¤ ėļ”ę°€ė ė¸ Starlette ėŊ”드도 ėž‘ë™í•  ę˛ƒėž…ë‹ˆë‹¤. + +`FastAPI`는 ė‹¤ė œëĄœ `Starlette`ė˜ í•˜ėœ„ í´ëž˜ėŠ¤ėž…ë‹ˆë‹¤. ęˇ¸ëž˜ė„œ, ė—ŦëŸŦëļ„ė´ ė´ë¯¸ Starletteė„ ė•Œęŗ  ėžˆęą°ë‚˜ ė‚ŦėšŠí•˜ęŗ  ėžˆėœŧ늴, 대ëļ€ëļ„ė˜ 기ëŠĨė´ ę°™ė€ ë°Šė‹ėœŧ로 ėž‘ë™í•  ę˛ƒėž…ë‹ˆë‹¤. + +**FastAPI**ëĨŧ ė‚ŦėšŠí•˜ëŠ´ ė—ŦëŸŦëļ„ė€ **Starlette**ė˜ 기ëŠĨ 대ëļ€ëļ„ė„ ė–ģ枌 될 ę˛ƒėž…ë‹ˆë‹¤(FastAPI가 ë‹¨ėˆœížˆ StarletteëĨŧ 강화했기 때ëŦ¸ėž…니다): + +* ė•„ėŖŧ ė¸ėƒė ė¸ ė„ąëŠĨ. ė´ëŠ” **NodeJS**뙀 **Go**뙀 동등하게 ė‚ŦėšŠ 가ëŠĨ한 가ėžĨ ëš ëĨ¸ íŒŒė´ėŦ í”„ë ˆėž„ė›ŒíŦ 뤑 í•˜ë‚˜ėž…ë‹ˆë‹¤. +* **WebSocket** 맀뛐. +* í”„ëĄœė„¸ėŠ¤ ë‚´ė˜ 밹꡸ëŧėš´ë“œ ėž‘ė—…. +* ė‹œėž‘ęŗŧ ėĸ…ëŖŒ ė´ë˛¤íŠ¸. +* HTTPX 기반 í…ŒėŠ¤íŠ¸ 클ëŧė´ė–¸íŠ¸. +* **CORS**, GZip, 렕렁 파ėŧ, ėŠ¤íŠ¸ëĻŦ밍 ė‘ë‹ĩ. +* **ė„¸ė…˜ęŗŧ ėŋ í‚¤** 맀뛐. +* 100% í…ŒėŠ¤íŠ¸ ë˛”ėœ„. +* 100% íƒ€ėž…ė´ ëĒ…ė‹œëœ ėŊ”드 ë˛ ė´ėŠ¤. + +## Pydantic 기ëŠĨ + +**FastAPI**는 Pydanticė„ 기반ėœŧ로 하며 Pydanticęŗŧ 뙄ë˛Ŋ하게 호환됩니다. ęˇ¸ëž˜ė„œ ė–´ëŠ ėļ”ę°€ė ė¸ Pydantic ėŊ”드ëĨŧ ė—ŦëŸŦëļ„ė´ 氀맀溠 ėžˆë“  ėž‘ë™í•  ę˛ƒėž…ë‹ˆë‹¤. + +Pydanticė„ 기반ėœŧ로 하는, ë°ė´í„°ë˛ ė´ėŠ¤ëĨŧ ėœ„í•œ ORM, ODMė„ íŦ함한 뙏ëļ€ ëŧė´ë¸ŒëŸŦëĻŦëĨŧ íŦ함합니다. + +ė´ëŠ” ëĒ¨ë“  ę˛ƒė´ ėžë™ėœŧ로 검ėĻë˜ę¸° 때ëŦ¸ė—, ë§Žė€ ę˛Ŋėš°ė—ė„œ ėš”ė˛­ė„ í†ĩ해 ė–ģė€ 동ėŧ한 ę°ė˛´ëĨŧ, **링렑 ë°ė´í„°ë˛ ė´ėŠ¤ëĄœ** ë„˜ę˛¨ė¤„ 눘 ėžˆėŠĩ니다. + +반대로도 마ė°Ŧę°€ė§€ė´ëŠ°, ë§Žė€ ę˛Ŋėš°ė—ė„œ ė—ŦëŸŦëļ„ė€ **링렑 클ëŧė´ė–¸íŠ¸ëĄœ** 掏렀 ę°ė˛´ëĨŧ ë„˜ę˛¨ė¤„ 눘 ėžˆėŠĩ니다. + +**FastAPI**ëĨŧ ė‚ŦėšŠí•˜ëŠ´ (ëĒ¨ë“  ë°ė´í„° 래ëĻŦëĨŧ ėœ„í•´ FastAPI가 Pydanticė„ 기반ėœŧ로 하기 ėžˆę¸°ė—) **Pydantic**ė˜ ëĒ¨ë“  기ëŠĨė„ ė–ģ枌 됩니다: + +* **ė–´ë ĩė§€ ė•Šė€ 떏떴**: + * ėƒˆëĄœėš´ ėŠ¤í‚¤ë§ˆ ė •ė˜ ë§ˆė´íŦ로 떏떴ëĨŧ ë°°ėš°ė§€ ė•Šė•„ë„ 됩니다. + * ė—ŦëŸŦëļ„ė´ íŒŒė´ėŦ íƒ€ėž…ė„ ė•ˆë‹¤ëŠ´, ė—ŦëŸŦëļ„ė€ Pydanticė„ ė–´ë–ģ枌 ė‚ŦėšŠí•˜ëŠ”ė§€ ė•„ëŠ” 겁니다. +* ė—ŦëŸŦëļ„ė˜ **IDE/ëĻ°í„°/뇌**뙀 ėž˜ ė–´ėš¸ëĻŊ니다: + * Pydantic ë°ė´í„° ęĩŦėĄ°ëŠ” ë‹¨ėˆœ ė—ŦëŸŦëļ„ė´ ė •ė˜í•œ í´ëž˜ėŠ¤ė˜ ė¸ėŠ¤í„´ėŠ¤ė´ę¸° 때ëŦ¸ė—, ėžë™ ė™„ė„ą, ëĻ°íŒ…, mypy ꡸ëĻŦęŗ  ė—ŦëŸŦëļ„ė˜ ė§ę´€ęšŒė§€ ė—ŦëŸŦëļ„ė˜ 검ėĻëœ ë°ė´í„°ė™€ ė˜Ŧ바ëĨ´ę˛Œ ėž‘ë™í•Šë‹ˆë‹¤. +* **ëŗĩėžĄí•œ ęĩŦėĄ°**ëĨŧ 검ėĻí•Šë‹ˆë‹¤: + * ęŗ„ė¸ĩė ė¸ Pydantic ëĒ¨ë¸, íŒŒė´ėŦ `typing`ė˜ `List`뙀 `Dict`, ꡸ 뙏ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤. + * ꡸ëĻŦęŗ  검ėĻėžëŠ” ëŗĩėžĄí•œ ë°ė´í„° ėŠ¤í‚¤ë§ˆëĨŧ ëĒ…í™•í•˜ęŗ  ė‰Ŋ枌 ė •ė˜ 및 í™•ė¸í•˜ëŠ° JSON ėŠ¤í‚¤ë§ˆëĄœ ëŦ¸ė„œí™”핊니다. + * ė—ŦëŸŦëļ„ė€ 깊게 **ė¤‘ė˛Šëœ JSON** ę°ė˛´ëĨŧ ę°€ė§ˆ 눘 ėžˆėœŧ늰, ė´ ę°ė˛´ ëĒ¨ë‘ 검ėĻí•˜ęŗ  네ëĒ…ė„ ëļ™ėŧ 눘 ėžˆėŠĩ니다. +* **확ėžĨ 가ëŠĨė„ą**: + * Pydanticė€ ė‚ŦėšŠėž ė •ė˜ ë°ė´í„° íƒ€ėž…ė„ ė •ė˜í•  눘 ėžˆę˛Œ 하거나, 검ėĻėž 데ėŊ”ë ˆė´í„°ę°€ ëļ™ė€ ëĒ¨ë¸ė˜ ëŠ”ė†Œë“œëĨŧ ė‚ŦėšŠí•˜ė—Ŧ 검ėĻė„ 확ėžĨ할 눘 ėžˆėŠĩ니다. +* 100% í…ŒėŠ¤íŠ¸ ë˛”ėœ„. From 3351674918894ac32cf041972b76e841c77efb1a Mon Sep 17 00:00:00 2001 From: Kani Kim Date: Tue, 23 Jan 2024 23:05:09 +0900 Subject: [PATCH 192/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/help/index.md`=20(#10983)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/help/index.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/ko/docs/help/index.md diff --git a/docs/ko/docs/help/index.md b/docs/ko/docs/help/index.md new file mode 100644 index 0000000000..fc023071ac --- /dev/null +++ b/docs/ko/docs/help/index.md @@ -0,0 +1,3 @@ +# ë„ė›€ + +ë„ė›€ė„ ėŖŧęŗ  ë°›ęŗ , 기ė—Ŧí•˜ęŗ , ė°¸ė—Ŧ합니다. 🤝 From aa3ed353b3219b32095eeeceb77dfc5d4fd7c582 Mon Sep 17 00:00:00 2001 From: Matteo Date: Tue, 23 Jan 2024 15:06:33 +0100 Subject: [PATCH 193/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Italian=20translat?= =?UTF-8?q?ion=20for=20`docs/it/docs/index.md`=20(#5233)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/it/docs/index.md | 464 ++++++++++++++++++++++++++++++++++++++++++ docs/it/mkdocs.yml | 1 + 2 files changed, 465 insertions(+) create mode 100644 docs/it/docs/index.md create mode 100644 docs/it/mkdocs.yml diff --git a/docs/it/docs/index.md b/docs/it/docs/index.md new file mode 100644 index 0000000000..6190eb6aa0 --- /dev/null +++ b/docs/it/docs/index.md @@ -0,0 +1,464 @@ + +{!../../../docs/missing-translation.md!} + + +

+ FastAPI +

+

+ FastAPI framework, alte prestazioni, facile da imparare, rapido da implementare, pronto per il rilascio in produzione +

+

+ + Build Status + + + Coverage + + + Package version + +

+ +--- + +**Documentazione**: https://fastapi.tiangolo.com + +**Codice Sorgente**: https://github.com/tiangolo/fastapi + +--- + +FastAPI è un web framework moderno e veloce (a prestazioni elevate) che serve a creare API con Python 3.6+ basato sulle annotazioni di tipo di Python. + +Le sue caratteristiche principali sono: + +* **Velocità**: Prestazioni molto elevate, alla pari di **NodeJS** e **Go** (grazie a Starlette e Pydantic). [Uno dei framework Python piÚ veloci in circolazione](#performance). +* **Veloce da programmare**: Velocizza il lavoro consentendo il rilascio di nuove funzionalità tra il 200% e il 300% piÚ rapidamente. * +* **Meno bug**: Riduce di circa il 40% gli errori che commettono gli sviluppatori durante la scrittura del codice. * +* **Intuitivo**: Grande supporto per gli editor di testo con autocompletamento in ogni dove. In questo modo si puÃ˛ dedicare meno tempo al debugging. +* **Facile**: Progettato per essere facile da usare e imparare. Si riduce il tempo da dedicare alla lettura della documentazione. +* **Sintentico**: Minimizza la duplicazione di codice. Molteplici funzionalità, ognuna con la propria dichiarazione dei parametri. Meno errori. +* **Robusto**: Crea codice pronto per la produzione con documentazione automatica interattiva. +* **Basato sugli standard**: Basato su (e completamente compatibile con) gli open standard per le API: OpenAPI (precedentemente Swagger) e JSON Schema. + +* Stima basata sull'esito di test eseguiti su codice sorgente di applicazioni rilasciate in produzione da un team interno di sviluppatori. + +## Sponsor + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor -%} +{%- for sponsor in sponsors.silver -%} + +{% endfor %} +{% endif %} + + + +Altri sponsor + +## Recensioni + +"_[...] I'm using **FastAPI** a ton these days. [...] I'm actually planning to use it for all of my team's **ML services at Microsoft**. Some of them are getting integrated into the core **Windows** product and some **Office** products._" + +
Kabir Khan - Microsoft (ref)
+ +--- + +"_We adopted the **FastAPI** library to spawn a **REST** server that can be queried to obtain **predictions**. [for Ludwig]_" + +
Piero Molino, Yaroslav Dudin, e Sai Sumanth Miryala - Uber (ref)
+ +--- + +"_**Netflix** is pleased to announce the open-source release of our **crisis management** orchestration framework: **Dispatch**! [built with **FastAPI**]_" + +
Kevin Glisson, Marc Vilanova, Forest Monsen - Netflix (ref)
+ +--- + +"_I’m over the moon excited about **FastAPI**. It’s so fun!_" + +
Brian Okken - Python Bytes podcast host (ref)
+ +--- + +"_Honestly, what you've built looks super solid and polished. In many ways, it's what I wanted **Hug** to be - it's really inspiring to see someone build that._" + +
Timothy Crosley - Hug creator (ref)
+ +--- + +"_If you're looking to learn one **modern framework** for building REST APIs, check out **FastAPI** [...] It's fast, easy to use and easy to learn [...]_" + +"_We've switched over to **FastAPI** for our **APIs** [...] I think you'll like it [...]_" + +
Ines Montani - Matthew Honnibal - Explosion AI founders - spaCy creators (ref) - (ref)
+ +--- + +## **Typer**, la FastAPI delle CLI + + + +Se stai sviluppando un'app CLI da usare nel terminale invece che una web API, ti consigliamo **Typer**. + +**Typer** è il fratello minore di FastAPI. Ed è stato ideato per essere la **FastAPI delle CLI**. âŒ¨ī¸ 🚀 + +## Requisiti + +Python 3.6+ + +FastAPI è basata su importanti librerie: + +* Starlette per le parti web. +* Pydantic per le parti dei dati. + +## Installazione + +
+ +```console +$ pip install fastapi + +---> 100% +``` + +
+ +Per il rilascio in produzione, sarà necessario un server ASGI come Uvicorn oppure Hypercorn. + +
+ +```console +$ pip install uvicorn[standard] + +---> 100% +``` + +
+ +## Esempio + +### Crea un file + +* Crea un file `main.py` con: + +```Python +from fastapi import FastAPI +from typing import Optional + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: str = Optional[None]): + return {"item_id": item_id, "q": q} +``` + +
+Oppure usa async def... + +Se il tuo codice usa `async` / `await`, allora usa `async def`: + +```Python hl_lines="7 12" +from fastapi import FastAPI +from typing import Optional + +app = FastAPI() + + +@app.get("/") +async def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +async def read_item(item_id: int, q: Optional[str] = None): + return {"item_id": item_id, "q": q} +``` + +**Nota**: + +e vuoi approfondire, consulta la sezione _"In a hurry?"_ su `async` e `await` nella documentazione. + +
+ +### Esegui il server + +Puoi far partire il server cosÃŦ: + +
+ +```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. +``` + +
+ +
+Informazioni sul comando uvicorn main:app --reload... + +Vediamo il comando `uvicorn main:app` in dettaglio: + +* `main`: il file `main.py` (il "modulo" Python). +* `app`: l'oggetto creato dentro `main.py` con la riga di codice `app = FastAPI()`. +* `--reload`: ricarica il server se vengono rilevati cambiamenti del codice. Usalo solo durante la fase di sviluppo. + +
+ +### Testa l'API + +Apri il browser all'indirizzo http://127.0.0.1:8000/items/5?q=somequery. + +Vedrai la seguente risposta JSON: + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +Hai appena creato un'API che: + +* Riceve richieste HTTP sui _paths_ `/` and `/items/{item_id}`. +* Entrambi i _paths_ accettano`GET` operations (conosciuti anche come HTTP _methods_). +* Il _path_ `/items/{item_id}` ha un _path parameter_ `item_id` che deve essere un `int`. +* Il _path_ `/items/{item_id}` ha una `str` _query parameter_ `q`. + +### Documentazione interattiva dell'API + +Adesso vai all'indirizzo http://127.0.0.1:8000/docs. + +Vedrai la documentazione interattiva dell'API (offerta da Swagger UI): + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +### Documentazione interattiva alternativa + +Adesso accedi all'url http://127.0.0.1:8000/redoc. + +Vedrai la documentazione interattiva dell'API (offerta da ReDoc): + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## Esempio piÚ avanzato + +Adesso modifica il file `main.py` per ricevere un _body_ da una richiesta `PUT`. + +Dichiara il _body_ usando le annotazioni di tipo standard di Python, grazie a Pydantic. + +```Python hl_lines="2 7-10 23-25" +from fastapi import FastAPI +from pydantic import BaseModel +from typing import Optional + +app = FastAPI() + + +class Item(BaseModel): + name: str + price: float + is_offer: bool = Optional[None] + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: Optional[str] = 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} +``` + +Il server dovrebbe ricaricarsi in automatico (perchÊ hai specificato `--reload` al comando `uvicorn` lanciato precedentemente). + +### Aggiornamento della documentazione interattiva + +Adesso vai su http://127.0.0.1:8000/docs. + +* La documentazione interattiva dell'API verrà automaticamente aggiornata, includendo il nuovo _body_: + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) + +* Fai click sul pulsante "Try it out", che ti permette di inserire i parametri per interagire direttamente con l'API: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png) + +* Successivamente, premi sul pulsante "Execute". L'interfaccia utente comunicherà con la tua API, invierà i parametri, riceverà i risultati della richiesta, e li mostrerà sullo schermo: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png) + +### Aggiornamento della documentazione alternativa + +Ora vai su http://127.0.0.1:8000/redoc. + +* Anche la documentazione alternativa dell'API mostrerà il nuovo parametro della query e il _body_: + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) + +### Riepilogo + +Ricapitolando, è sufficiente dichiarare **una sola volta** i tipi dei parametri, del body, ecc. come parametri di funzioni. + +Questo con le annotazioni per i tipi standard di Python. + +Non c'è bisogno di imparare una nuova sintassi, metodi o classi specifici a una libreria, ecc. + +È normalissimo **Python 3.6+**. + +Per esempio, per un `int`: + +```Python +item_id: int +``` + +o per un modello `Item` piÚ complesso: + +```Python +item: Item +``` + +...e con quella singola dichiarazione hai in cambio: + +* Supporto per gli editor di testo, incluso: + * Autocompletamento. + * Controllo sulle annotazioni di tipo. +* Validazione dei dati: + * Errori chiari e automatici quando i dati sono invalidi. + * Validazione anche per gli oggetti JSON piÚ complessi. +* Conversione dei dati di input: da risorse esterne a dati e tipi di Python. È possibile leggere da: + * JSON. + * Path parameters. + * Query parameters. + * Cookies. + * Headers. + * Form. + * File. +* Conversione dei dati di output: converte dati e tipi di Python a dati per la rete (come JSON): + * Converte i tipi di Python (`str`, `int`, `float`, `bool`, `list`, ecc). + * Oggetti `datetime`. + * Oggetti `UUID`. + * Modelli del database. + * ...e molto di piÚ. +* Generazione di una documentazione dell'API interattiva, con scelta dell'interfaccia grafica: + * Swagger UI. + * ReDoc. + +--- + +Tornando al precedente esempio, **FastAPI**: + +* Validerà che esiste un `item_id` nel percorso delle richieste `GET` e `PUT`. +* Validerà che `item_id` sia di tipo `int` per le richieste `GET` e `PUT`. + * Se non lo è, il client vedrà un errore chiaro e utile. +* Controllerà se ci sia un parametro opzionale chiamato `q` (per esempio `http://127.0.0.1:8000/items/foo?q=somequery`) per le richieste `GET`. + * Siccome il parametro `q` è dichiarato con `= None`, è opzionale. + * Senza il `None` sarebbe stato obbligatorio (come per il body della richiesta `PUT`). +* Per le richieste `PUT` su `/items/{item_id}`, leggerà il body come JSON, questo comprende: + * verifica che la richiesta abbia un attributo obbligatorio `name` e che sia di tipo `str`. + * verifica che la richiesta abbia un attributo obbligatorio `price` e che sia di tipo `float`. + * verifica che la richiesta abbia un attributo opzionale `is_offer` e che sia di tipo `bool`, se presente. + * Tutto questo funzionerebbe anche con oggetti JSON piÚ complessi. +* Convertirà *da* e *a* JSON automaticamente. +* Documenterà tutto con OpenAPI, che puÃ˛ essere usato per: + * Sistemi di documentazione interattivi. + * Sistemi di generazione di codice dal lato client, per molti linguaggi. +* Fornirà 2 interfacce di documentazione dell'API interattive. + +--- + +Questa è solo la punta dell'iceberg, ma dovresti avere già un'idea di come il tutto funzioni. + +Prova a cambiare questa riga di codice: + +```Python + return {"item_name": item.name, "item_id": item_id} +``` + +...da: + +```Python + ... "item_name": item.name ... +``` + +...a: + +```Python + ... "item_price": item.price ... +``` + +...e osserva come il tuo editor di testo autocompleterà gli attributi e sarà in grado di riconoscere i loro tipi: + +![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) + +Per un esempio piÚ completo che mostra piÚ funzionalità del framework, consulta Tutorial - Guida Utente. + +**Spoiler alert**: il tutorial - Guida Utente include: + +* Dichiarazione di **parameters** da altri posti diversi come: **headers**, **cookies**, **form fields** e **files**. +* Come stabilire **vincoli di validazione** come `maximum_length` o `regex`. +* Un sistema di **Dependency Injection** facile da usare e molto potente. +e potente. +* Sicurezza e autenticazione, incluso il supporto per **OAuth2** con **token JWT** e autenticazione **HTTP Basic**. +* Tecniche piÚ avanzate (ma ugualmente semplici) per dichiarare **modelli JSON altamente nidificati** (grazie a Pydantic). +* E altre funzionalità (grazie a Starlette) come: + * **WebSockets** + * **GraphQL** + * test molto facili basati su `requests` e `pytest` + * **CORS** + * **Cookie Sessions** + * ...e altro ancora. + +## Prestazioni + +Benchmark indipendenti di TechEmpower mostrano che **FastAPI** basato su Uvicorn è uno dei framework Python piÚ veloci in circolazione, solamente dietro a Starlette e Uvicorn (usate internamente da FastAPI). (*) + +Per approfondire, consulta la sezione Benchmarks. + +## Dipendenze opzionali + +Usate da Pydantic: + +* ujson - per un "parsing" di JSON piÚ veloce. +* email_validator - per la validazione di email. + +Usate da Starlette: + +* requests - Richiesto se vuoi usare il `TestClient`. +* aiofiles - Richiesto se vuoi usare `FileResponse` o `StaticFiles`. +* jinja2 - Richiesto se vuoi usare la configurazione template di default. +* python-multipart - Richiesto se vuoi supportare il "parsing" con `request.form()`. +* itsdangerous - Richiesto per usare `SessionMiddleware`. +* pyyaml - Richiesto per il supporto dello `SchemaGenerator` di Starlette (probabilmente non ti serve con FastAPI). +* graphene - Richiesto per il supporto di `GraphQLApp`. +* ujson - Richiesto se vuoi usare `UJSONResponse`. + +Usate da FastAPI / Starlette: + +* uvicorn - per il server che carica e serve la tua applicazione. +* orjson - ichiesto se vuoi usare `ORJSONResponse`. + +Puoi installarle tutte con `pip install fastapi[all]`. + +## Licenza + +Questo progetto è concesso in licenza in base ai termini della licenza MIT. diff --git a/docs/it/mkdocs.yml b/docs/it/mkdocs.yml new file mode 100644 index 0000000000..de18856f44 --- /dev/null +++ b/docs/it/mkdocs.yml @@ -0,0 +1 @@ +INHERIT: ../en/mkdocs.yml From f021ccb9058429641aa6400db83eb37717d5827f Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:09:28 +0000 Subject: [PATCH 194/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 1a0f15d301..66faea43b0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/security/get-current-user.md`. PR [#5737](https://github.com/tiangolo/fastapi/pull/5737) by [@KdHyeon0661](https://github.com/KdHyeon0661). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/security/first-steps.md`. PR [#10541](https://github.com/tiangolo/fastapi/pull/10541) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/handling-errors.md`. PR [#10375](https://github.com/tiangolo/fastapi/pull/10375) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/encoder.md`. PR [#10374](https://github.com/tiangolo/fastapi/pull/10374) by [@AlertRED](https://github.com/AlertRED). From 6d46b60cb3a84a1746e7aec36cf22bec5f495860 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:09:56 +0000 Subject: [PATCH 195/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 66faea43b0..94e1b062e0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/features.md`. PR [#10976](https://github.com/tiangolo/fastapi/pull/10976) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/security/get-current-user.md`. PR [#5737](https://github.com/tiangolo/fastapi/pull/5737) by [@KdHyeon0661](https://github.com/KdHyeon0661). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/security/first-steps.md`. PR [#10541](https://github.com/tiangolo/fastapi/pull/10541) by [@AlertRED](https://github.com/AlertRED). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/handling-errors.md`. PR [#10375](https://github.com/tiangolo/fastapi/pull/10375) by [@AlertRED](https://github.com/AlertRED). From 189f679f9babaa1c31e6661d861f82601fc98173 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:10:30 +0300 Subject: [PATCH 196/305] =?UTF-8?q?=F0=9F=8C=90=20Update=20Turkish=20trans?= =?UTF-8?q?lation=20for=20`docs/tr/docs/benchmarks.md`=20(#11005)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/benchmarks.md | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/docs/tr/docs/benchmarks.md b/docs/tr/docs/benchmarks.md index 1ce3c758f1..eb5472869a 100644 --- a/docs/tr/docs/benchmarks.md +++ b/docs/tr/docs/benchmarks.md @@ -1,34 +1,34 @@ # KÄąyaslamalar -BağımsÄąz TechEmpower kÄąyaslamalarÄą gÃļsteriyor ki Uvicorn'la beraber çalÄąÅŸan **FastAPI** uygulamalarÄą Python'un en hÄązlÄą frameworklerinden birisi , sadece Starlette ve Uvicorn'dan daha dÃŧşÃŧk sÄąralamada (FastAPI bu frameworklerin Ãŧzerine kurulu). (*) +BağımsÄąz TechEmpower kÄąyaslamalarÄą gÃļsteriyor ki en hÄązlÄą Python frameworklerinden birisi olan Uvicorn ile çalÄąÅŸtÄąrÄąlan **FastAPI** uygulamalarÄą, sadece Starlette ve Uvicorn'dan daha dÃŧşÃŧk sÄąralamada (FastAPI bu frameworklerin Ãŧzerine kurulu) yer alÄąyor. (*) Fakat kÄąyaslamalarÄą ve karÅŸÄąlaştÄąrmalarÄą incelerken şunlarÄą aklÄąnÄązda bulundurmalÄąsÄąnÄąz. -## KÄąyaslamalar ve hÄąz +## KÄąyaslamalar ve HÄąz -KÄąyaslamalarÄą incelediğinizde, farklÄą Ãļzelliklere sahip birçok araçlarÄąn eşdeğer olarak karÅŸÄąlaştÄąrÄąldığınÄą gÃļrmek yaygÄąndÄąr. +KÄąyaslamalarÄą incelediğinizde, farklÄą Ãļzelliklere sahip araçlarÄąn eşdeğer olarak karÅŸÄąlaştÄąrÄąldığınÄą yaygÄąn bir şekilde gÃļrebilirsiniz. -Özellikle, Uvicorn, Starlette ve FastAPI'Äąn birlikte karÅŸÄąlaştÄąrÄąldığınÄą gÃļrmek için (diğer birçok araç arasÄąnda). +Özellikle, (diğer birçok araç arasÄąnda) Uvicorn, Starlette ve FastAPI'Äąn birlikte karÅŸÄąlaştÄąrÄąldığınÄą gÃļrebilirsiniz. -Araç tarafÄąndan çÃļzÃŧlen sorun ne kadar basitse, o kadar iyi performans alacaktÄąr. Ve kÄąyaslamalarÄąn çoğu, araç tarafÄąndan sağlanan ek Ãļzellikleri test etmez. +AracÄąn çÃļzdÃŧğÃŧ problem ne kadar basitse, performansÄą o kadar iyi olacaktÄąr. Ancak kÄąyaslamalarÄąn çoğu, aracÄąn sağladığı ek Ãļzellikleri test etmez. Hiyerarşi şÃļyledir: * **Uvicorn**: bir ASGI sunucusu - * **Starlette**: (Uvicorn'u kullanÄąr) bir web microframeworkÃŧ - * **FastAPI**: (Starlette'i kullanÄąr) data validation vb. ile API'lar oluşturmak için çeşitli ek Ãļzelliklere sahip bir API frameworkÃŧ + * **Starlette**: (Uvicorn'u kullanÄąr) bir web mikroframeworkÃŧ + * **FastAPI**: (Starlette'i kullanÄąr) veri doğrulama vb. çeşitli ek Ãļzelliklere sahip, API oluşturmak için kullanÄąlan bir API mikroframeworkÃŧ * **Uvicorn**: - * Sunucunun kendisi dÄąÅŸÄąnda ekstra bir kod içermediği için en iyi performansa sahip olacaktÄąr - * Direkt olarak Uvicorn'da bir uygulama yazmazsÄąnÄąz. Bu, en azÄąndan Starlette tarafÄąndan sağlanan tÃŧm kodu (veya **FastAPI**) az çok içermesi gerektiği anlamÄąna gelir. Ve eğer bunu yaptÄąysanÄąz, son uygulamanÄąz bir framework kullanmak ve uygulama kodlarÄąnÄą ve buglarÄą en aza indirmekle aynÄą ek yÃŧke sahip olacaktÄąr. + * Sunucunun kendisi dÄąÅŸÄąnda ekstra bir kod içermediği için en iyi performansa sahip olacaktÄąr. + * Doğrudan Uvicorn ile bir uygulama yazmazsÄąnÄąz. Bu, yazdığınÄąz kodun en azÄąndan Starlette tarafÄąndan sağlanan tÃŧm kodu (veya **FastAPI**) az çok içermesi gerektiği anlamÄąna gelir. Eğer bunu yaptÄąysanÄąz, son uygulamanÄąz bir framework kullanmak ve uygulama kodlarÄąnÄą ve hatalarÄą en aza indirmekle aynÄą ek yÃŧke sahip olacaktÄąr. * Eğer Uvicorn'u karÅŸÄąlaştÄąrÄąyorsanÄąz, Daphne, Hypercorn, uWSGI, vb. uygulama sunucularÄą ile karÅŸÄąlaştÄąrÄąn. * **Starlette**: - * Uvicorn'dan sonraki en iyi performansa sahip olacak. AslÄąnda, Starlette çalÄąÅŸmak için Uvicorn'u kullanÄąyor. DolayÄąsÄąyla, muhtemelen daha fazla kod çalÄąÅŸtÄąrmak zorunda kaldığında Uvicorn'dan sadece "daha yavaş" olabilir. - * Ancak routing based on paths ile vb. basit web uygulamalarÄą oluşturmak için araçlar sağlar. - * Eğer Starlette'i karÅŸÄąlaştÄąrÄąyorsanÄąz, Sanic, Flask, Django, vb. frameworkler (veya microframeworkler) ile karÅŸÄąlaştÄąrÄąn. + * Uvicorn'dan sonraki en iyi performansa sahip olacaktÄąr. İşin aslÄą, Starlette çalÄąÅŸmak için Uvicorn'u kullanÄąyor. DolayÄąsÄąyla, daha fazla kod çalÄąÅŸtÄąrmaasÄą gerektiğinden muhtemelen Uvicorn'dan sadece "daha yavaş" olabilir. + * Ancak yol bazlÄą yÃļnlendirme vb. basit web uygulamalarÄą oluşturmak için araçlar sağlar. + * Eğer Starlette'i karÅŸÄąlaştÄąrÄąyorsanÄąz, Sanic, Flask, Django, vb. frameworkler (veya mikroframeworkler) ile karÅŸÄąlaştÄąrÄąn. * **FastAPI**: - * Starlette'in Uvicorn'u kullandığı ve ondan daha hÄązlÄą olamayacağı gibi, **FastAPI** da Starlette'i kullanÄąr, bu yÃŧzden ondan daha hÄązlÄą olamaz. - * FastAPI, Starlette'e ek olarak daha fazla Ãļzellik sunar. Data validation ve serialization gibi API'lar oluştururken neredeyse ve her zaman ihtiyaç duyduğunuz Ãļzellikler. Ve bunu kullanarak, Ãŧcretsiz olarak otomatik dokÃŧmantasyon elde edersiniz (otomatik dokÃŧmantasyon çalÄąÅŸan uygulamalara ek yÃŧk getirmez, başlangÄąÃ§ta oluşturulur). - * FastAPI'Äą kullanmadÄąysanÄąz ve Starlette'i doğrudan kullandÄąysanÄąz (veya başka bir araç, Sanic, Flask, Responder, vb.) tÃŧm data validation'Äą ve serialization'Äą kendiniz sağlamanÄąz gerekir. DolayÄąsÄąyla, son uygulamanÄąz FastAPI kullanÄąlarak oluşturulmuş gibi hÃĸlÃĸ aynÄą ek yÃŧke sahip olacaktÄąr. Çoğu durumda, uygulamalarda yazÄąlan kodun bÃŧyÃŧk çoğunluğunu data validation ve serialization oluşturur. - * DolayÄąsÄąyla, FastAPI'Äą kullanarak geliştirme sÃŧresinden, buglardan, kod satÄąrlarÄąndan tasarruf edersiniz ve muhtemelen kullanmasaydÄąnÄąz aynÄą performansÄą (veya daha iyisini) elde edersiniz. (hepsini kodunuza uygulamak zorunda kalacağınÄąz gibi) - * Eğer FastAPI'Äą karÅŸÄąlaştÄąrÄąyorsanÄąz, Flask-apispec, NestJS, Molten, vb. gibi data validation, serialization ve dokÃŧmantasyon sağlayan bir web uygulamasÄą frameworkÃŧ ile (veya araç setiyle) karÅŸÄąlaştÄąrÄąn. Entegre otomatik data validation, serialization ve dokÃŧmantasyon içeren frameworkler. + * Starlette'in Uvicorn'u kullandığı ve ondan daha hÄązlÄą olamayacağı gibi, **FastAPI**'da Starlette'i kullanÄąr, dolayÄąsÄąyla ondan daha hÄązlÄą olamaz. + * FastAPI, Starlette'e ek olarak daha fazla Ãļzellik sunar. Bunlar veri doğrulama ve dÃļnÃŧşÃŧmÃŧ gibi API'lar oluştururken neredeyse ve her zaman ihtiyaç duyduğunuz Ãļzelliklerdir. Ve bunu kullanarak, Ãŧcretsiz olarak otomatik dokÃŧmantasyon elde edersiniz (otomatik dokÃŧmantasyon çalÄąÅŸan uygulamalara ek yÃŧk getirmez, başlangÄąÃ§ta oluşturulur). + * FastAPI'Äą kullanmadÄąysanÄąz ve Starlette'i doğrudan kullandÄąysanÄąz (veya başka bir araç, Sanic, Flask, Responder, vb.) tÃŧm veri doğrulama ve dÃļnÃŧştÃŧrme araçlarÄąnÄą kendiniz geliştirmeniz gerekir. DolayÄąsÄąyla, son uygulamanÄąz FastAPI kullanÄąlarak oluşturulmuş gibi hÃĸlÃĸ aynÄą ek yÃŧke sahip olacaktÄąr. Çoğu durumda, uygulamalarda yazÄąlan kodun bÃŧyÃŧk bir kÄąsmÄąnÄą veri doğrulama ve dÃļnÃŧştÃŧrme kodlarÄą oluşturur. + * DolayÄąsÄąyla, FastAPI'Äą kullanarak geliştirme sÃŧresinden, hatalardan, kod satÄąrlarÄąndan tasarruf edersiniz ve kullanmadığınÄąz durumda (birçok Ãļzelliği geliştirmek zorunda kalmakla birlikte) muhtemelen aynÄą performansÄą (veya daha iyisini) elde ederdiniz. + * Eğer FastAPI'Äą karÅŸÄąlaştÄąrÄąyorsanÄąz, Flask-apispec, NestJS, Molten, vb. gibi veri doğrulama, dÃļnÃŧştÃŧrme ve dokÃŧmantasyon sağlayan bir web uygulamasÄą frameworkÃŧ ile (veya araç setiyle) karÅŸÄąlaştÄąrÄąn. From 9e06513033d881001b04616084348ee6300e98e6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:10:41 +0000 Subject: [PATCH 197/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 94e1b062e0..f8c4589c69 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/help/index.md`. PR [#10983](https://github.com/tiangolo/fastapi/pull/10983) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/features.md`. PR [#10976](https://github.com/tiangolo/fastapi/pull/10976) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/security/get-current-user.md`. PR [#5737](https://github.com/tiangolo/fastapi/pull/5737) by [@KdHyeon0661](https://github.com/KdHyeon0661). * 🌐 Add Russian translation for `docs/ru/docs/tutorial/security/first-steps.md`. PR [#10541](https://github.com/tiangolo/fastapi/pull/10541) by [@AlertRED](https://github.com/AlertRED). From 7586688cc961791afbfc3c568aba2b3fecea27c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:11:15 +0300 Subject: [PATCH 198/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/about/index.md`=20(#11006)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/about/index.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/tr/docs/about/index.md diff --git a/docs/tr/docs/about/index.md b/docs/tr/docs/about/index.md new file mode 100644 index 0000000000..e9dee5217c --- /dev/null +++ b/docs/tr/docs/about/index.md @@ -0,0 +1,3 @@ +# HakkÄąnda + +FastAPI, tasarÄąmÄą, ilham kaynağı ve daha fazlasÄą hakkÄąnda. 🤓 From 39cff8d7d6dea15c4b6e767dec5317b949f4e645 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:12:29 +0000 Subject: [PATCH 199/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index f8c4589c69..baae05a03b 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Italian translation for `docs/it/docs/index.md`. PR [#5233](https://github.com/tiangolo/fastapi/pull/5233) by [@matteospanio](https://github.com/matteospanio). * 🌐 Add Korean translation for `docs/ko/docs/help/index.md`. PR [#10983](https://github.com/tiangolo/fastapi/pull/10983) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/features.md`. PR [#10976](https://github.com/tiangolo/fastapi/pull/10976) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/security/get-current-user.md`. PR [#5737](https://github.com/tiangolo/fastapi/pull/5737) by [@KdHyeon0661](https://github.com/KdHyeon0661). From 754ea10fcc745975473c10745e543b162a015961 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Tue, 23 Jan 2024 17:13:01 +0300 Subject: [PATCH 200/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/help/index.md`=20(#11013)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/help/index.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/tr/docs/help/index.md diff --git a/docs/tr/docs/help/index.md b/docs/tr/docs/help/index.md new file mode 100644 index 0000000000..cef0914ce7 --- /dev/null +++ b/docs/tr/docs/help/index.md @@ -0,0 +1,3 @@ +# YardÄąm + +YardÄąm alÄąn, yardÄąm edin, katkÄąda bulunun, dahil olun. 🤝 From 2341f7210137f4b85b361fd2dfd21a6261d62208 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:15:50 +0000 Subject: [PATCH 201/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index baae05a03b..bff875447a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Update Turkish translation for `docs/tr/docs/benchmarks.md`. PR [#11005](https://github.com/tiangolo/fastapi/pull/11005) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Italian translation for `docs/it/docs/index.md`. PR [#5233](https://github.com/tiangolo/fastapi/pull/5233) by [@matteospanio](https://github.com/matteospanio). * 🌐 Add Korean translation for `docs/ko/docs/help/index.md`. PR [#10983](https://github.com/tiangolo/fastapi/pull/10983) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `docs/ko/docs/features.md`. PR [#10976](https://github.com/tiangolo/fastapi/pull/10976) by [@KaniKim](https://github.com/KaniKim). From a12c5db74c6f12d90761356250ff3e2d72d678d4 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:16:59 +0000 Subject: [PATCH 202/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index bff875447a..09f599436a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/about/index.md`. PR [#11006](https://github.com/tiangolo/fastapi/pull/11006) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Update Turkish translation for `docs/tr/docs/benchmarks.md`. PR [#11005](https://github.com/tiangolo/fastapi/pull/11005) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Italian translation for `docs/it/docs/index.md`. PR [#5233](https://github.com/tiangolo/fastapi/pull/5233) by [@matteospanio](https://github.com/matteospanio). * 🌐 Add Korean translation for `docs/ko/docs/help/index.md`. PR [#10983](https://github.com/tiangolo/fastapi/pull/10983) by [@KaniKim](https://github.com/KaniKim). From 30f1a1c4efbcfb4025090a06b4ac94d29fc0b9b7 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 14:19:05 +0000 Subject: [PATCH 203/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 09f599436a..0379bd921e 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/help/index.md`. PR [#11013](https://github.com/tiangolo/fastapi/pull/11013) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/about/index.md`. PR [#11006](https://github.com/tiangolo/fastapi/pull/11006) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Update Turkish translation for `docs/tr/docs/benchmarks.md`. PR [#11005](https://github.com/tiangolo/fastapi/pull/11005) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Italian translation for `docs/it/docs/index.md`. PR [#5233](https://github.com/tiangolo/fastapi/pull/5233) by [@matteospanio](https://github.com/matteospanio). From 30f31540fc3bfe8725cc1ebee0a440c4812539c9 Mon Sep 17 00:00:00 2001 From: mojtaba <121169359+mojtabapaso@users.noreply.github.com> Date: Tue, 23 Jan 2024 18:36:11 +0330 Subject: [PATCH 204/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Persian=20translat?= =?UTF-8?q?ion=20for=20`docs/fa/docs/tutorial/security/index.md`=20(#9945)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/fa/docs/tutorial/security/index.md | 100 ++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 docs/fa/docs/tutorial/security/index.md diff --git a/docs/fa/docs/tutorial/security/index.md b/docs/fa/docs/tutorial/security/index.md new file mode 100644 index 0000000000..4e68ba9619 --- /dev/null +++ b/docs/fa/docs/tutorial/security/index.md @@ -0,0 +1,100 @@ +# Ø§Ų…Ų†ÛŒØĒ + +ØąŲˆØ´â€ŒŲ‡Ø§ÛŒ Ų…ØŽØĒŲ„ŲÛŒ Ø¨ØąØ§ÛŒ Ų…Ø¯ÛŒØąÛŒØĒ Ø§Ų…Ų†ÛŒØĒ، ØĒØŖÛŒÛŒØ¯ Ų‡ŲˆÛŒØĒ ؈ اؚØĒØ¨Ø§ØąØŗŲ†ØŦی ؈ØŦŲˆØ¯ Ø¯Ø§ØąØ¯. + +ØšŲ…ŲˆŲ…Ø§Ų‹ Ø§ÛŒŲ† یڊ Ų…ŲˆØļŲˆØš ŲžÛŒÚ†ÛŒØ¯Ų‡ ؈ "ØŗØŽØĒ" Ø§ØŗØĒ. + +Ø¯Øą Ø¨ØŗÛŒØ§ØąÛŒ Ø§Ø˛ ŲØąÛŒŲ… ŲˆØąÚŠ Ų‡Ø§ ؈ ØŗÛŒØŗØĒŲ…â€ŒŲ‡Ø§ØŒ ŲŲ‚Øˇ Ų…Ø¯ÛŒØąÛŒØĒ Ø§Ų…Ų†ÛŒØĒ ؈ ØĒØŖÛŒÛŒØ¯ Ų‡ŲˆÛŒØĒ Ų†ÛŒØ§Ø˛ Ø¨Ų‡ ØĒŲ„Ø§Ø´ ؈ ڊد Ų†ŲˆÛŒØŗÛŒ Ø˛ÛŒØ§Ø¯ÛŒ Ø¯Ø§ØąØ¯ (Ø¯Øą Ø¨ØŗÛŒØ§ØąÛŒ Ø§Ø˛ Ų…ŲˆØ§ØąØ¯ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†Ø¯ 50% یا بیشØĒØą ÚŠŲ„ ڊد Ų†ŲˆØ´ØĒŲ‡ Ø´Ø¯Ų‡ باشد). + + +ŲØąÛŒŲ… ŲˆØąÚŠ **FastAPI** Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒ Ų…ØĒؚددی ØąØ§ Ø¯Øą ا؎ØĒÛŒØ§Øą Ø´Ų…Ø§ Ų‚ØąØ§Øą Ų…ÛŒ Ø¯Ų‡Ø¯ ØĒا Ø¨Ų‡ ØąØ§Ø­ØĒی، با ØŗØąØšØĒ، Ø¨Ų‡ ØĩŲˆØąØĒ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ ؈ Ø¨Ø¯ŲˆŲ† Ų†ÛŒØ§Ø˛ Ø¨Ų‡ Ų…ØˇØ§Ų„ØšŲ‡ ؈ ÛŒØ§Ø¯Ú¯ÛŒØąÛŒ Ų‡Ų…Ų‡ ØŦØ˛ØĻیاØĒ Ø§Ų…Ų†ÛŒØĒ، Ø¯Øą Ų…Ø¯ÛŒØąÛŒØĒ **Ø§Ų…Ų†ÛŒØĒ** Ø¨Ų‡ Ø´Ų…Ø§ ÚŠŲ…ÚŠ ÚŠŲ†Ø¯. + +Ø§Ų…Ø§ Ų‚Ø¨Ų„ Ø§Ø˛ ØĸŲ†ØŒ بیایید Ø¨ØąØŽÛŒ Ø§Ø˛ Ų…ŲØ§Ų‡ÛŒŲ… ÚŠŲˆÚ†ÚŠ ØąØ§ Ø¨ØąØąØŗÛŒ ÚŠŲ†ÛŒŲ…. + +## ØšØŦŲ„Ų‡ Ø¯Ø§ØąÛŒØ¯ØŸ + +Ø§Ú¯Øą Ø¨Ų‡ Ų‡ÛŒÚ† یڊ Ø§Ø˛ Ø§ÛŒŲ† اØĩØˇŲ„Ø§Ø­Ø§ØĒ Ø§Ų‡Ų…ÛŒØĒ Ų†Ų…ÛŒ Ø¯Ų‡ÛŒØ¯ ؈ ŲŲ‚Øˇ Ų†ÛŒØ§Ø˛ Ø¨Ų‡ Ø§ŲØ˛ŲˆØ¯Ų† Ø§Ų…Ų†ÛŒØĒ با ØĒØŖÛŒÛŒØ¯ Ų‡ŲˆÛŒØĒ Ø¨Øą Ø§ØŗØ§Øŗ Ų†Ø§Ų… ÚŠØ§ØąØ¨ØąÛŒ ؈ ØąŲ…Ø˛ ØšØ¨ŲˆØą Ø¯Ø§ØąÛŒØ¯ØŒ *Ų‡Ų…ÛŒŲ† Ø§Ų„Ø§Ų†* Ø¨Ų‡ ؁ØĩŲ„ Ų‡Ø§ÛŒ بؚدی Ø¨ØąŲˆÛŒØ¯. + +## ŲžØąŲˆØĒÚŠŲ„ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OAuth2 + +ŲžØąŲˆØĒÚŠŲ„ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OAuth2 یڊ Ų…Ø´ØŽØĩŲ‡ Ø§ØŗØĒ ÚŠŲ‡ Ú†Ų†Ø¯ÛŒŲ† ØąŲˆØ´ Ø¨ØąØ§ÛŒ Ų…Ø¯ÛŒØąÛŒØĒ ØĒØŖÛŒÛŒØ¯ Ų‡ŲˆÛŒØĒ ؈ اؚØĒØ¨Ø§Øą ØŗŲ†ØŦی ØĒØšØąÛŒŲ Ų…ÛŒ ÚŠŲ†Ø¯. + +Ø§ÛŒŲ† Ų…Ø´ØŽØĩŲ‡ Ø¨ØŗÛŒØ§Øą Ú¯ØŗØĒØąØ¯Ų‡ Ø§ØŗØĒ ؈ Ú†Ų†Ø¯ÛŒŲ† Ø­Ø§Ų„ØĒ Ø§ØŗØĒŲØ§Ø¯Ų‡ ŲžÛŒÚ†ÛŒØ¯Ų‡ ØąØ§ ŲžŲˆØ´Ø´ Ų…ÛŒ Ø¯Ų‡Ø¯. + +Ø¯Øą ØĸŲ† ØąŲˆØ´ Ų‡Ø§ÛŒÛŒ Ø¨ØąØ§ÛŒ ØĒØŖÛŒÛŒØ¯ Ų‡ŲˆÛŒØĒ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ "Ø¨ØąŲ†Ø§Ų…Ų‡ Ų‡Ø§ÛŒ Ø´ØŽØĩ ØĢØ§Ų„ØĢ" ؈ØŦŲˆØ¯ Ø¯Ø§ØąØ¯. + +Ø§ÛŒŲ† Ų‡Ų…Ø§Ų† Ú†ÛŒØ˛ÛŒ Ø§ØŗØĒ ÚŠŲ‡ ØĒŲ…Ø§Ų…ÛŒ ØŗÛŒØŗØĒŲ… Ų‡Ø§ÛŒ با "ŲˆØąŲˆØ¯ با ŲÛŒØŗØ¨ŲˆÚŠØŒ Ú¯ŲˆÚ¯Ų„ØŒ ØĒŲˆÛŒÛŒØĒØąØŒ گیØĒ Ų‡Ø§Ø¨" Ø¯Øą ŲžØ§ÛŒÛŒŲ† ØĸŲ† ØąØ§ Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒ ÚŠŲ†Ų†Ø¯. + +### ŲžØąŲˆØĒÚŠŲ„ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OAuth 1 + +ŲžØąŲˆØĒÚŠŲ„ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OAuth1 Ų†ÛŒØ˛ ؈ØŦŲˆØ¯ داشØĒ ÚŠŲ‡ با OAuth2 ØŽÛŒŲ„ÛŒ Ų…ØĒŲØ§ŲˆØĒ Ø§ØŗØĒ ؈ ŲžÛŒÚ†ÛŒØ¯Ú¯ÛŒ بیشØĒØąÛŒ داشØĒ، Ø˛ÛŒØąØ§ Ø´Ø§Ų…Ų„ Ų…Ø´ØŽØĩاØĒ Ų…ØŗØĒŲ‚ÛŒŲ… Ø¯Øą Ų…ŲˆØąØ¯ ØąŲ…Ø˛Ú¯Ø°Ø§ØąÛŒ Ø§ØąØĒØ¨Ø§Øˇ Ø¨ŲˆØ¯. + +Ø¯Øą Ø­Ø§Ų„ حاØļØą OAuth1 Ø¨ØŗÛŒØ§Øą Ų…Ø­Ø¨ŲˆØ¨ یا Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø´Ø¯Ų‡ Ų†ÛŒØŗØĒ. + +ŲžØąŲˆØĒÚŠŲ„ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OAuth2 ØąŲˆØ´ ØąŲ…Ø˛Ú¯Ø°Ø§ØąÛŒ Ø§ØąØĒØ¨Ø§Øˇ ØąØ§ Ų…Ø´ØŽØĩ Ų†Ų…ÛŒ ÚŠŲ†Ø¯ØŒ Ø¨Ų„ÚŠŲ‡ Ø§Ų†ØĒØ¸Ø§Øą Ø¯Ø§ØąØ¯ ÚŠŲ‡ Ø¨ØąŲ†Ø§Ų…Ų‡ Ø´Ų…Ø§ با HTTPS ØŗØąŲˆÛŒØŗ Ø¯Ų‡ÛŒ Ø´ŲˆØ¯. + +!!! Ų†ÚŠØĒŲ‡ + Ø¯Øą ب؎ش Ø¯Øą Ų…ŲˆØąØ¯ **Ø§ØŗØĒŲ‚ØąØ§Øą** ، Ø´Ų…Ø§ یاد ØŽŲˆØ§Ų‡ÛŒØ¯ Ú¯ØąŲØĒ ÚŠŲ‡ Ú†Ú¯ŲˆŲ†Ų‡ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ Traefik ؈ Let's Encrypt ØąØ§ÛŒÚ¯Ø§Ų† HTTPS ØąØ§ ØąØ§Ų‡ Ø§Ų†Ø¯Ø§Ø˛ÛŒ ÚŠŲ†ÛŒØ¯. + +## Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenID Connect + +Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenID Connect، Ų…Ø´ØŽØĩŲ‡â€ŒØ§ÛŒ Ø¯ÛŒÚ¯Øą Ø§ØŗØĒ ÚŠŲ‡ Ø¨Øą ŲžØ§ÛŒŲ‡ **OAuth2** ØŗØ§ØŽØĒŲ‡ Ø´Ø¯Ų‡ Ø§ØŗØĒ. + +Ø§ÛŒŲ† Ų…Ø´ØŽØĩŲ‡ØŒ Ø¨Ų‡ Ú¯ØŗØĒØąØ´ OAuth2 Ų…ÛŒâ€ŒŲžØąØ¯Ø§Ø˛Ø¯ ؈ Ø¨ØąØŽÛŒ Ų…ŲˆØ§ØąØ¯ÛŒ ÚŠŲ‡ Ø¯Øą OAuth2 Ų†ØŗØ¨ØĒØ§Ų‹ ØĒØąØ¯ÛŒØ¯ Ø¨ØąØ§Ų†Ú¯ÛŒØ˛ Ų‡ØŗØĒŲ†Ø¯ ØąØ§ Ų…Ø´ØŽØĩ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ ØĒا ØŗØšÛŒ Ø´ŲˆØ¯ ØĸŲ† ØąØ§ با ØŗØ§ÛŒØą ØŗÛŒØŗØĒŲ…â€ŒŲ‡Ø§ Ų‚Ø§Ø¨Ų„ Ø§ØąØĒØ¨Ø§Øˇ ÚŠŲ†Ø¯. + +Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† Ų…ØĢØ§Ų„ØŒ ŲˆØąŲˆØ¯ Ø¨Ų‡ ØŗÛŒØŗØĒŲ… Ú¯ŲˆÚ¯Ų„ Ø§Ø˛ OpenID Connect Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ (ÚŠŲ‡ Ø¯Øą Ø˛ÛŒØą Ø§Ø˛ OAuth2 Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒÚŠŲ†Ø¯). + +Ø§Ų…Ø§ ŲˆØąŲˆØ¯ Ø¨Ų‡ ØŗÛŒØŗØĒŲ… ŲÛŒØŗØ¨ŲˆÚŠØŒ Ø§Ø˛ OpenID Connect ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ Ų†Ų…ÛŒâ€ŒÚŠŲ†Ø¯. Ø¨Ų‡ ØŦای ØĸŲ†ØŒ Ų†ØŗØŽŲ‡ ØŽŲˆØ¯Ø´ Ø§Ø˛ OAuth2 ØąØ§ Ø¯Ø§ØąØ¯. + +### Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenID (Ų†Ų‡ "OpenID Connect" ) + +Ų‡Ų…Ú†Ų†ÛŒŲ† Ų…Ø´ØŽØĩŲ‡ "OpenID" Ų†ÛŒØ˛ ؈ØŦŲˆØ¯ داشØĒ ÚŠŲ‡ ØŗØšÛŒ Ø¯Øą Ø­Ų„ Ų…ØŗØ§ØĻŲ„ Ų…Ø´Ø§Ø¨Ų‡ OpenID Connect داشØĒ، Ø§Ų…Ø§ Ø¨Øą ŲžØ§ÛŒŲ‡ OAuth2 ØŗØ§ØŽØĒŲ‡ Ų†Ø´Ø¯Ų‡ Ø¨ŲˆØ¯. + +Ø¨Ų†Ø§Ø¨ØąØ§ÛŒŲ†ØŒ یڊ ØŗÛŒØŗØĒŲ… ØŦØ¯Ø§Ú¯Ø§Ų†Ų‡ Ø¨ŲˆØ¯. + +Ø§ÚŠŲ†ŲˆŲ† Ø§ÛŒŲ† Ų…Ø´ØŽØĩŲ‡ ÚŠŲ…ØĒØą Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒØ´ŲˆØ¯ ؈ Ų…Ø­Ø¨ŲˆØ¨ÛŒØĒ Ø˛ÛŒØ§Ø¯ÛŒ Ų†Ø¯Ø§ØąØ¯. + +## Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenAPI + +Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenAPI (Ų‚Ø¨Ų„Ø§Ų‹ با Ų†Ø§Ų… Swagger Ø´Ų†Ø§ØŽØĒŲ‡ Ų…ÛŒâ€ŒØ´Ø¯) یڊ open specification Ø¨ØąØ§ÛŒ ØŗØ§ØŽØĒ APIs (ÚŠŲ‡ Ø¯Øą Ø­Ø§Ų„ حاØļØą ØŦØ˛ØĻی Ø§Ø˛ Ø¨Ų†ÛŒØ§Ø¯ Ų„ÛŒŲ†ŲˆÚŠØŗ Ų…ÛŒØ¨Ø§Ø´Ø¯) Ø§ØŗØĒ. + +ŲØąÛŒŲ… ŲˆØąÚŠ **FastAPI** Ø¨Øą Ø§ØŗØ§Øŗ **OpenAPI** Ø§ØŗØĒ. + +Ø§ÛŒŲ† ؎اØĩیØĒ، Ø§Ų…ÚŠØ§Ų† Ø¯Ø§ØąØ¯ ØĒا Ú†Ų†Ø¯ÛŒŲ† ØąØ§Ø¨Øˇ Ų…ØŗØĒŲ†Ø¯Ø§ØĒ ØĒØšØ§Ų…Ų„ÛŒ ØŽŲˆØ¯ÚŠØ§Øą(automatic interactive documentation interfaces)، ØĒŲˆŲ„ÛŒØ¯ ڊد ؈ ØēÛŒØąŲ‡ ؈ØŦŲˆØ¯ داشØĒŲ‡ باشد. + +Ų…Ø´ØŽØĩŲ‡ OpenAPI ØąŲˆØ´ÛŒ Ø¨ØąØ§ÛŒ ØĒØšØąÛŒŲ Ú†Ų†Ø¯ÛŒŲ† "schemes" Ø¯Ø§ØąØ¯. + +با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ ØĸŲ†â€ŒŲ‡Ø§ØŒ Ø´Ų…Ø§ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ Ø§Ø˛ Ų‡Ų…Ų‡ Ø§ÛŒŲ† Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒ Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯ØŒ Ø§Ø˛ ØŦŲ…Ų„Ų‡ Ø§ÛŒŲ† ØŗÛŒØŗØĒŲ…â€ŒŲ‡Ø§ÛŒ Ų…ØŗØĒŲ†Ø¯Ø§ØĒ ØĒØšØ§Ų…Ų„ÛŒ(interactive documentation systems). + +Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ OpenAPI Ø´ÛŒŲˆŲ‡â€ŒŲ‡Ø§ÛŒ Ø§Ų…Ų†ÛŒØĒی Ø˛ÛŒØą ØąØ§ ØĒØšØąÛŒŲ Ų…ÛŒâ€ŒÚŠŲ†Ø¯: + +* Ø´ÛŒŲˆŲ‡ `apiKey`: یڊ ÚŠŲ„ÛŒØ¯ ا؎ØĒØĩاØĩی Ø¨ØąØ§ÛŒ Ø¨ØąŲ†Ø§Ų…Ų‡ ÚŠŲ‡ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†Ø¯ Ø§Ø˛ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø´ŲˆØ¯: + * ŲžØ§ØąØ§Ų…ØĒØą ØŦØŗØĒØŦ؈. + * Ų‡Ø¯Øą. + * ÚŠŲˆÚŠÛŒ. +* Ø´ÛŒŲˆŲ‡ `http`: ØŗÛŒØŗØĒŲ…â€ŒŲ‡Ø§ÛŒ Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ HTTP، Ø§Ø˛ ØŦŲ…Ų„Ų‡: + * Ų…Ų‚Ø¯Ø§Øą `bearer`: یڊ Ų‡Ø¯Øą `Authorization` با Ų…Ų‚Ø¯Ø§Øą `Bearer` Ø¨Ų‡ Ų‡Ų…ØąØ§Ų‡ یڊ ØĒŲˆÚŠŲ†. Ø§ÛŒŲ† Ø§Ø˛ OAuth2 Ø¨Ų‡ Ø§ØąØĢ Ø¨ØąØ¯Ų‡ Ø´Ø¯Ų‡ Ø§ØŗØĒ. + * Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ ŲžØ§ÛŒŲ‡ HTTP. + * ŲˆÛŒÚ˜Ú¯ÛŒ HTTP Digest ؈ ØēÛŒØąŲ‡. +* Ø´ÛŒŲˆŲ‡ `oauth2`: ØĒŲ…Ø§Ų… ØąŲˆØ´â€ŒŲ‡Ø§ÛŒ OAuth2 Ø¨ØąØ§ÛŒ Ų…Ø¯ÛŒØąÛŒØĒ Ø§Ų…Ų†ÛŒØĒ (Ø¨Ų‡ Ų†Ø§Ų… "flows"). + * Ú†Ų†Ø¯ÛŒŲ† Ø§Ø˛ Ø§ÛŒŲ† flows Ø¨ØąØ§ÛŒ ØŗØ§ØŽØĒ یڊ Ø§ØąØ§ØĻŲ‡â€ŒØ¯Ų‡Ų†Ø¯Ų‡ Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ OAuth 2.0 Ų…Ų†Ø§ØŗØ¨ Ų‡ØŗØĒŲ†Ø¯ (Ų…Ø§Ų†Ų†Ø¯ Ú¯ŲˆÚ¯Ų„ØŒ ŲÛŒØŗØ¨ŲˆÚŠØŒ ØĒŲˆÛŒÛŒØĒØąØŒ گیØĒâ€ŒŲ‡Ø§Ø¨ ؈ ØēÛŒØąŲ‡): + * ŲˆÛŒÚ˜Ú¯ÛŒ `implicit` + * ŲˆÛŒÚ˜Ú¯ÛŒ `clientCredentials` + * ŲˆÛŒÚ˜Ú¯ÛŒ `authorizationCode` + * Ø§Ų…Ø§ یڊ "flow" ؎اØĩ ؈ØŦŲˆØ¯ Ø¯Ø§ØąØ¯ ÚŠŲ‡ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†Ø¯ Ø¨Ų‡ ØˇŲˆØą ÚŠØ§Ų…Ų„ Ø¨ØąØ§ÛŒ Ų…Ø¯ÛŒØąÛŒØĒ Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ Ø¯Øą Ų‡Ų…Ø§Ų† Ø¨ØąŲ†Ø§Ų…Ų‡ Ø¨Ų‡ ÚŠØ§Øą ØąŲˆØ¯: + * Ø¨ØąØąØŗÛŒ `password`: Ú†Ų†Ø¯ ؁ØĩŲ„ بؚدی Ø¨Ų‡ Ų…ØĢØ§Ų„â€ŒŲ‡Ø§ÛŒ Ø§ÛŒŲ† Ų…ŲˆØąØ¯ ØŽŲˆØ§Ų‡ÛŒŲ… ŲžØąØ¯Ø§ØŽØĒ. +* Ø´ÛŒŲˆŲ‡ `openIdConnect`: یڊ ØąŲˆØ´ Ø¨ØąØ§ÛŒ ØĒØšØąÛŒŲ Ų†Ø­ŲˆŲ‡ ÚŠØ´Ų Ø¯Ø§Ø¯Ų‡â€ŒŲ‡Ø§ÛŒ Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ OAuth2 Ø¨Ų‡ ØĩŲˆØąØĒ ØŽŲˆØ¯ÚŠØ§Øą. + * ÚŠØ´Ų ØŽŲˆØ¯ÚŠØ§Øą Ø§ÛŒŲ† Ų…ŲˆØļŲˆØš ØąØ§ ÚŠŲ‡ Ø¯Øą Ų…Ø´ØŽØĩŲ‡ OpenID Connect ØĒØšØąÛŒŲ Ø´Ø¯Ų‡ Ø§ØŗØĒ، Ų…Ø´ØŽØĩ Ų…ÛŒâ€ŒÚŠŲ†Ø¯. + +!!! Ų†ÚŠØĒŲ‡ + ادØēØ§Ų… ØŗØ§ÛŒØą Ø§ØąØ§ØĻŲ‡â€ŒØ¯Ų‡Ų†Ø¯Ú¯Ø§Ų† Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ/اØŦØ§Ø˛Ų‡â€ŒØ¯Ų‡ÛŒ Ų…Ø§Ų†Ų†Ø¯ Ú¯ŲˆÚ¯Ų„ØŒ ŲÛŒØŗØ¨ŲˆÚŠØŒ ØĒŲˆÛŒÛŒØĒØąØŒ گیØĒâ€ŒŲ‡Ø§Ø¨ ؈ ØēÛŒØąŲ‡ Ų†ÛŒØ˛ Ø§Ų…ÚŠØ§Ų†â€ŒŲžØ°ÛŒØą ؈ Ų†ØŗØ¨ØĒØ§Ų‹ ØĸØŗØ§Ų† Ø§ØŗØĒ. + + Ų…Ø´ÚŠŲ„ ŲžÛŒÚ†ÛŒØ¯Ų‡â€ŒØĒØąÛŒŲ† Ų…ØŗØĻŲ„Ų‡ØŒ ØŗØ§ØŽØĒ یڊ Ø§ØąØ§ØĻŲ‡â€ŒØ¯Ų‡Ų†Ø¯Ų‡ Ø§Ø­ØąØ§Ø˛ Ų‡ŲˆÛŒØĒ/اØŦØ§Ø˛Ų‡â€ŒØ¯Ų‡ÛŒ Ų…Ø§Ų†Ų†Ø¯ ØĸŲ†â€ŒŲ‡Ø§ Ø§ØŗØĒ، Ø§Ų…Ø§ **FastAPI** Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒ Ų„Ø§Ø˛Ų… Ø¨ØąØ§ÛŒ Ø§Ų†ØŦØ§Ų… Ø§ÛŒŲ† ÚŠØ§Øą ØąØ§ با ØŗŲ‡ŲˆŲ„ØĒ Ø¨Ų‡ Ø´Ų…Ø§ Ų…ÛŒâ€ŒØ¯Ų‡Ø¯ ؈ Ų‡Ų…Ų‡ ÚŠØ§ØąŲ‡Ø§ÛŒ ØŗŲ†Ú¯ÛŒŲ† ØąØ§ Ø¨ØąØ§ÛŒ Ø´Ų…Ø§ Ø§Ų†ØŦØ§Ų… Ų…ÛŒâ€ŒØ¯Ų‡Ø¯. + +## Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒ **FastAPI** + +ŲØąÛŒŲ… ŲˆØąÚŠ FastAPI Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒÛŒ Ø¨ØąØ§ÛŒ Ų‡Øą یڊ Ø§Ø˛ Ø§ÛŒŲ† Ø´ÛŒŲˆŲ‡â€ŒŲ‡Ø§ÛŒ Ø§Ų…Ų†ÛŒØĒی Ø¯Øą Ų…Ø§Ú˜ŲˆŲ„`fastapi.security` ŲØąØ§Ų‡Ų… Ų…ÛŒâ€ŒÚŠŲ†Ø¯ ÚŠŲ‡ Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ Ø§ÛŒŲ† Ų…ÚŠØ§Ų†ÛŒØ˛Ų…â€ŒŲ‡Ø§ÛŒ Ø§Ų…Ų†ÛŒØĒی ØąØ§ ØŗØ§Ø¯Ų‡â€ŒØĒØą Ų…ÛŒâ€ŒÚŠŲ†Ø¯. + +Ø¯Øą ؁ØĩŲ„â€ŒŲ‡Ø§ÛŒ بؚدی، Ø´Ų…Ø§ یاد ØŽŲˆØ§Ų‡ÛŒØ¯ Ú¯ØąŲØĒ ÚŠŲ‡ Ú†Ú¯ŲˆŲ†Ų‡ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ Ø§ÛŒŲ† Ø§Ø¨Ø˛Ø§ØąŲ‡Ø§ÛŒ Ø§ØąØ§ØĻŲ‡ Ø´Ø¯Ų‡ ØĒŲˆØŗØˇ **FastAPI**، Ø§Ų…Ų†ÛŒØĒ ØąØ§ Ø¨Ų‡ API ØŽŲˆØ¯ اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +Ų‡Ų…Ú†Ų†ÛŒŲ†ØŒ ØŽŲˆØ§Ų‡ÛŒØ¯ دید ÚŠŲ‡ Ú†Ú¯ŲˆŲ†Ų‡ Ø¨Ų‡ ØĩŲˆØąØĒ ØŽŲˆØ¯ÚŠØ§Øą Ø¯Øą ØŗÛŒØŗØĒŲ… Ų…ØŗØĒŲ†Ø¯Ø§ØĒ ØĒØšØ§Ų…Ų„ÛŒ ادØēØ§Ų… Ų…ÛŒâ€ŒØ´ŲˆØ¯. From 9a5181abfcea5cfa6cbaf3439304ec676272ed95 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 15:06:34 +0000 Subject: [PATCH 205/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0379bd921e..0755b68262 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Persian translation for `docs/fa/docs/tutorial/security/index.md`. PR [#9945](https://github.com/tiangolo/fastapi/pull/9945) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Add Turkish translation for `docs/tr/docs/help/index.md`. PR [#11013](https://github.com/tiangolo/fastapi/pull/11013) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/about/index.md`. PR [#11006](https://github.com/tiangolo/fastapi/pull/11006) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Update Turkish translation for `docs/tr/docs/benchmarks.md`. PR [#11005](https://github.com/tiangolo/fastapi/pull/11005) by [@hasansezertasan](https://github.com/hasansezertasan). From aae29cac5c1b25722bd5d7ce1796d4930998ca85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Tue, 23 Jan 2024 19:02:27 +0300 Subject: [PATCH 206/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/learn/index.md`=20(#11014)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/learn/index.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/tr/docs/learn/index.md diff --git a/docs/tr/docs/learn/index.md b/docs/tr/docs/learn/index.md new file mode 100644 index 0000000000..52e3aa54df --- /dev/null +++ b/docs/tr/docs/learn/index.md @@ -0,0 +1,5 @@ +# Öğren + +**FastAPI** Ãļğrenmek için giriş bÃļlÃŧmleri ve Ãļğreticiler burada yer alÄąyor. + +BurayÄą, bir **kitap**, bir **kurs**, ve FastAPI Ãļğrenmenin **resmi** ve Ãļnerilen yolu olarak dÃŧşÃŧnÃŧlebilirsiniz. 😎 From 6aa521aa03772cea0e9eb0b31f36fb41f8f15991 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 16:02:56 +0000 Subject: [PATCH 207/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0755b68262..7d2dc438ff 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/learn/index.md`. PR [#11014](https://github.com/tiangolo/fastapi/pull/11014) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/security/index.md`. PR [#9945](https://github.com/tiangolo/fastapi/pull/9945) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Add Turkish translation for `docs/tr/docs/help/index.md`. PR [#11013](https://github.com/tiangolo/fastapi/pull/11013) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/about/index.md`. PR [#11006](https://github.com/tiangolo/fastapi/pull/11006) by [@hasansezertasan](https://github.com/hasansezertasan). From dcf8b24ece34a7aa8f3c28d1e962733aebe97a05 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Tue, 23 Jan 2024 17:04:13 +0100 Subject: [PATCH 208/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/benchmarks.md`=20(#10866)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/benchmarks.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 docs/de/docs/benchmarks.md diff --git a/docs/de/docs/benchmarks.md b/docs/de/docs/benchmarks.md new file mode 100644 index 0000000000..6efd56e830 --- /dev/null +++ b/docs/de/docs/benchmarks.md @@ -0,0 +1,34 @@ +# Benchmarks + +Unabhängige TechEmpower-Benchmarks zeigen, **FastAPI**-Anwendungen, die unter Uvicorn ausgefÃŧhrt werden, gehÃļren zu den schnellsten existierenden Python-Frameworks, nur Starlette und Uvicorn selbst (intern von FastAPI verwendet) sind schneller. + +Beim Ansehen von Benchmarks und Vergleichen sollten Sie jedoch Folgende Punkte beachten. + +## Benchmarks und Geschwindigkeit + +Wenn Sie sich die Benchmarks ansehen, werden häufig mehrere Tools mit unterschiedlichen Eigenschaften als gleichwertig verglichen. + +Konkret geht es darum, Uvicorn, Starlette und FastAPI miteinander zu vergleichen (neben vielen anderen Tools). + +Je einfacher das Problem, welches durch das Tool gelÃļst wird, desto besser ist die Performanz. Und die meisten Benchmarks testen nicht die zusätzlichen Funktionen, welche das Tool bietet. + +Die Hierarchie ist wie folgt: + +* **Uvicorn**: ein ASGI-Server + * **Starlette**: (verwendet Uvicorn) ein Web-Mikroframework + * **FastAPI**: (verwendet Starlette) ein API-Mikroframework mit mehreren zusätzlichen Funktionen zum Erstellen von APIs, mit Datenvalidierung, usw. + +* **Uvicorn**: + * Bietet die beste Leistung, da außer dem Server selbst nicht viel zusätzlicher Code vorhanden ist. + * Sie wÃŧrden eine Anwendung nicht direkt in Uvicorn schreiben. Das wÃŧrde bedeuten, dass Ihr Code zumindest mehr oder weniger den gesamten von Starlette (oder **FastAPI**) bereitgestellten Code enthalten mÃŧsste. Und wenn Sie das täten, hätte Ihre endgÃŧltige Anwendung den gleichen Overhead wie die Verwendung eines Frameworks nebst Minimierung Ihres Anwendungscodes und der Fehler. + * Wenn Sie Uvicorn vergleichen, vergleichen Sie es mit Anwendungsservern wie Daphne, Hypercorn, uWSGI, usw. +* **Starlette**: + * Wird nach Uvicorn die nächstbeste Performanz erbringen. Tatsächlich nutzt Starlette intern Uvicorn. Daher kann es wahrscheinlich nur „langsamer“ als Uvicorn sein, weil mehr Code ausgefÃŧhrt wird. + * Aber es bietet Ihnen die Tools zum Erstellen einfacher Webanwendungen, mit Routing basierend auf Pfaden, usw. + * Wenn Sie Starlette vergleichen, vergleichen Sie es mit Webframeworks (oder Mikroframeworks) wie Sanic, Flask, Django, usw. +* **FastAPI**: + * So wie Starlette Uvicorn verwendet und nicht schneller als dieses sein kann, verwendet **FastAPI** Starlette, sodass es nicht schneller als dieses sein kann. + * FastAPI bietet zusätzlich zu Starlette weitere Funktionen. Funktionen, die Sie beim Erstellen von APIs fast immer benÃļtigen, wie Datenvalidierung und Serialisierung. Und wenn Sie es verwenden, erhalten Sie kostenlos automatische Dokumentation (die automatische Dokumentation verursacht nicht einmal zusätzlichen Aufwand fÃŧr laufende Anwendungen, sie wird beim Start generiert). + * Wenn Sie FastAPI nicht, und direkt Starlette (oder ein anderes Tool wie Sanic, Flask, Responder, usw.) verwenden wÃŧrden, mÃŧssten Sie die gesamte Datenvalidierung und Serialisierung selbst implementieren. Ihre finale Anwendung hätte also immer noch den gleichen Overhead, als ob sie mit FastAPI erstellt worden wäre. Und in vielen Fällen ist diese Datenvalidierung und Serialisierung der grÃļßte Teil des in Anwendungen geschriebenen Codes. + * Durch die Verwendung von FastAPI sparen Sie also Entwicklungszeit, Fehler und Codezeilen und wÃŧrden wahrscheinlich die gleiche Leistung (oder eine bessere) erzielen, die Sie hätten, wenn Sie es nicht verwenden wÃŧrden (da Sie alles in Ihrem Code implementieren mÃŧssten). + * Wenn Sie FastAPI vergleichen, vergleichen Sie es mit einem Webanwendung-Framework (oder einer Reihe von Tools), welche Datenvalidierung, Serialisierung und Dokumentation bereitstellen, wie Flask-apispec, NestJS, Molten, usw. – Frameworks mit integrierter automatischer Datenvalidierung, Serialisierung und Dokumentation. From 4c077492aec56aba2f0bf6a8b16c7f7212a0382f Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 16:04:37 +0000 Subject: [PATCH 209/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7d2dc438ff..0a9b353626 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -45,6 +45,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/benchmarks.md`. PR [#10866](https://github.com/tiangolo/fastapi/pull/10866) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Turkish translation for `docs/tr/docs/learn/index.md`. PR [#11014](https://github.com/tiangolo/fastapi/pull/11014) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/security/index.md`. PR [#9945](https://github.com/tiangolo/fastapi/pull/9945) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Add Turkish translation for `docs/tr/docs/help/index.md`. PR [#11013](https://github.com/tiangolo/fastapi/pull/11013) by [@hasansezertasan](https://github.com/hasansezertasan). From 8e9af7932c3ee53a7263044c53b88341f0b87745 Mon Sep 17 00:00:00 2001 From: Alejandra <90076947+alejsdev@users.noreply.github.com> Date: Tue, 23 Jan 2024 12:31:56 -0500 Subject: [PATCH 210/305] =?UTF-8?q?=F0=9F=94=A7=20Add=20Italian=20to=20`mk?= =?UTF-8?q?docs.yml`=20(#11016)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/mkdocs.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index d34e919bde..2b843e026d 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -283,6 +283,8 @@ extra: name: hu - magyar - link: /id/ name: id - Bahasa Indonesia + - link: /it/ + name: it - italiano - link: /ja/ name: ja - æ—ĨæœŦčĒž - link: /ko/ From e96e74ad36c77273018e87932ad1de7a19aeb67b Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 23 Jan 2024 17:32:19 +0000 Subject: [PATCH 211/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0a9b353626..9e28af40b1 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -109,6 +109,7 @@ hide: ### Internal +* 🔧 Add Italian to `mkdocs.yml`. PR [#11016](https://github.com/tiangolo/fastapi/pull/11016) by [@alejsdev](https://github.com/alejsdev). * 🔨 Verify `mkdocs.yml` languages in CI, update `docs.py`. PR [#11009](https://github.com/tiangolo/fastapi/pull/11009) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update config in `label-approved.yml` to accept translations with 1 reviewer. PR [#11007](https://github.com/tiangolo/fastapi/pull/11007) by [@alejsdev](https://github.com/alejsdev). * 👷 Add changes-requested handling in GitHub Action issue manager. PR [#10971](https://github.com/tiangolo/fastapi/pull/10971) by [@tiangolo](https://github.com/tiangolo). From 9ee70f82e7691246d78446c0ff04c1e4496bf383 Mon Sep 17 00:00:00 2001 From: Jessica Temporal Date: Thu, 25 Jan 2024 23:53:05 +0900 Subject: [PATCH 212/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=20Tips=20on=20migrating=20from=20Flask=20to=20FastAPI=20and=20?= =?UTF-8?q?vice-versa=20(#11029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/data/external_links.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index 00d6f696de..44b064fe9b 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - author: Jessica Temporal + author_link: https://jtemporal.com/socials + link: https://jtemporal.com/tips-on-migrating-from-flask-to-fastapi-and-vice-versa/ + title: Tips on migrating from Flask to FastAPI and vice-versa - author: Ankit Anchlia author_link: https://linkedin.com/in/aanchlia21 link: https://hackernoon.com/explore-how-to-effectively-use-jwt-with-fastapi @@ -302,6 +306,11 @@ Articles: author_link: https://qiita.com/mtitg link: https://qiita.com/mtitg/items/47770e9a562dd150631d title: FastAPIīŊœDBæŽĨįļšã—ãĻCRUDするPythončŖŊAPIã‚ĩãƒŧバãƒŧã‚’æ§‹į¯‰ + Portuguese: + - author: Jessica Temporal + author_link: https://jtemporal.com/socials + link: https://jtemporal.com/dicas-para-migrar-de-flask-para-fastapi-e-vice-versa/ + title: Dicas para migrar uma aplicaÃ§ÃŖo de Flask para FastAPI e vice-versa Russian: - author: Troy KÃļhler author_link: https://www.linkedin.com/in/trkohler/ From 9af7f2a5d5e6ce37ecfe2449f645f69881abc953 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 14:53:25 +0000 Subject: [PATCH 213/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 9e28af40b1..5d31e52615 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Add External Link: Tips on migrating from Flask to FastAPI and vice-versa. PR [#11029](https://github.com/tiangolo/fastapi/pull/11029) by [@jtemporal](https://github.com/jtemporal). * 📝 Deprecate old tutorials: Peewee, Couchbase, encode/databases. PR [#10979](https://github.com/tiangolo/fastapi/pull/10979) by [@tiangolo](https://github.com/tiangolo). * âœī¸ Fix typo in `fastapi/security/oauth2.py`. PR [#10972](https://github.com/tiangolo/fastapi/pull/10972) by [@RafalSkolasinski](https://github.com/RafalSkolasinski). * 📝 Update `HTTPException` details in `docs/en/docs/tutorial/handling-errors.md`. PR [#5418](https://github.com/tiangolo/fastapi/pull/5418) by [@papb](https://github.com/papb). From e55c7ccbcb723b5d290d29c20df530cfc7df4d72 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Thu, 25 Jan 2024 15:53:41 +0100 Subject: [PATCH 214/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/query-params.md`=20(#10293)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/query-params.md | 226 ++++++++++++++++++++++++++ 1 file changed, 226 insertions(+) create mode 100644 docs/de/docs/tutorial/query-params.md diff --git a/docs/de/docs/tutorial/query-params.md b/docs/de/docs/tutorial/query-params.md new file mode 100644 index 0000000000..1b9b56bea8 --- /dev/null +++ b/docs/de/docs/tutorial/query-params.md @@ -0,0 +1,226 @@ +# Query-Parameter + +Wenn Sie in ihrer Funktion Parameter deklarieren, die nicht Teil der Pfad-Parameter sind, dann werden diese automatisch als „Query“-Parameter interpretiert. + +```Python hl_lines="9" +{!../../../docs_src/query_params/tutorial001.py!} +``` + +Query-Parameter (Deutsch: Abfrage-Parameter) sind die SchlÃŧssel-Wert-Paare, die nach dem `?` in einer URL aufgelistet sind, getrennt durch `&`-Zeichen. + +Zum Beispiel sind in der URL: + +``` +http://127.0.0.1:8000/items/?skip=0&limit=10 +``` + +... die Query-Parameter: + +* `skip`: mit dem Wert `0` +* `limit`: mit dem Wert `10` + +Da sie Teil der URL sind, sind sie „naturgemäß“ Strings. + +Aber wenn Sie sie mit Python-Typen deklarieren (im obigen Beispiel als `int`), werden sie zu diesem Typ konvertiert, und gegen diesen validiert. + +Die gleichen Prozesse, die fÃŧr Pfad-Parameter stattfinden, werden auch auf Query-Parameter angewendet: + +* Editor UnterstÃŧtzung (natÃŧrlich) +* „Parsen“ der Daten +* Datenvalidierung +* Automatische Dokumentation + +## Defaultwerte + +Da Query-Parameter nicht ein festgelegter Teil des Pfades sind, kÃļnnen sie optional sein und Defaultwerte haben. + +Im obigen Beispiel haben sie die Defaultwerte `skip=0` und `limit=10`. + +Wenn Sie also zur URL: + +``` +http://127.0.0.1:8000/items/ +``` + +gehen, so ist das das gleiche wie die URL: + +``` +http://127.0.0.1:8000/items/?skip=0&limit=10 +``` + +Aber wenn Sie zum Beispiel zu: + +``` +http://127.0.0.1:8000/items/?skip=20 +``` + +gehen, werden die Parameter-Werte Ihrer Funktion sein: + +* `skip=20`: da Sie das in der URL gesetzt haben +* `limit=10`: weil das der Defaultwert ist + +## Optionale Parameter + +Auf die gleiche Weise kÃļnnen Sie optionale Query-Parameter deklarieren, indem Sie deren Defaultwert auf `None` setzen: + +=== "Python 3.10+" + + ```Python hl_lines="7" + {!> ../../../docs_src/query_params/tutorial002_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9" + {!> ../../../docs_src/query_params/tutorial002.py!} + ``` + +In diesem Fall wird der Funktionsparameter `q` optional, und standardmäßig `None` sein. + +!!! check + Beachten Sie auch, dass **FastAPI** intelligent genug ist, um zu erkennen, dass `item_id` ein Pfad-Parameter ist und `q` keiner, daher muss letzteres ein Query-Parameter sein. + +## Query-Parameter Typkonvertierung + +Sie kÃļnnen auch `bool`-Typen deklarieren und sie werden konvertiert: + +=== "Python 3.10+" + + ```Python hl_lines="7" + {!> ../../../docs_src/query_params/tutorial003_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9" + {!> ../../../docs_src/query_params/tutorial003.py!} + ``` + +Wenn Sie nun zu: + +``` +http://127.0.0.1:8000/items/foo?short=1 +``` + +oder + +``` +http://127.0.0.1:8000/items/foo?short=True +``` + +oder + +``` +http://127.0.0.1:8000/items/foo?short=true +``` + +oder + +``` +http://127.0.0.1:8000/items/foo?short=on +``` + +oder + +``` +http://127.0.0.1:8000/items/foo?short=yes +``` + +gehen, oder zu irgendeiner anderen Variante der Groß-/Kleinschreibung (Alles groß, Anfangsbuchstabe groß, usw.), dann wird Ihre Funktion den Parameter `short` mit dem `bool`-Wert `True` sehen, ansonsten mit dem Wert `False`. + +## Mehrere Pfad- und Query-Parameter + +Sie kÃļnnen mehrere Pfad-Parameter und Query-Parameter gleichzeitig deklarieren, **FastAPI** weiß, was welches ist. + +Und Sie mÃŧssen sie auch nicht in einer spezifischen Reihenfolge deklarieren. + +Parameter werden anhand ihres Namens erkannt: + +=== "Python 3.10+" + + ```Python hl_lines="6 8" + {!> ../../../docs_src/query_params/tutorial004_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="8 10" + {!> ../../../docs_src/query_params/tutorial004.py!} + ``` + +## Erforderliche Query-Parameter + +Wenn Sie einen Defaultwert fÃŧr Nicht-Pfad-Parameter deklarieren (Bis jetzt haben wir nur Query-Parameter gesehen), dann ist der Parameter nicht erforderlich. + +Wenn Sie keinen spezifischen Wert haben wollen, sondern der Parameter einfach optional sein soll, dann setzen Sie den Defaultwert auf `None`. + +Aber wenn Sie wollen, dass ein Query-Parameter erforderlich ist, vergeben Sie einfach keinen Defaultwert: + +```Python hl_lines="6-7" +{!../../../docs_src/query_params/tutorial005.py!} +``` + +Hier ist `needy` ein erforderlicher Query-Parameter vom Typ `str`. + +Wenn Sie in Ihrem Browser eine URL wie: + +``` +http://127.0.0.1:8000/items/foo-item +``` + +... Ãļffnen, ohne den benÃļtigten Parameter `needy`, dann erhalten Sie einen Fehler wie den folgenden: + +```JSON +{ + "detail": [ + { + "type": "missing", + "loc": [ + "query", + "needy" + ], + "msg": "Field required", + "input": null, + "url": "https://errors.pydantic.dev/2.1/v/missing" + } + ] +} +``` + +Da `needy` ein erforderlicher Parameter ist, mÃŧssen Sie ihn in der URL setzen: + +``` +http://127.0.0.1:8000/items/foo-item?needy=sooooneedy +``` + +... Das funktioniert: + +```JSON +{ + "item_id": "foo-item", + "needy": "sooooneedy" +} +``` + +Und natÃŧrlich kÃļnnen Sie einige Parameter als erforderlich, einige mit Defaultwert, und einige als vollständig optional definieren: + +=== "Python 3.10+" + + ```Python hl_lines="8" + {!> ../../../docs_src/query_params/tutorial006_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="10" + {!> ../../../docs_src/query_params/tutorial006.py!} + ``` + +In diesem Fall gibt es drei Query-Parameter: + +* `needy`, ein erforderlicher `str`. +* `skip`, ein `int` mit einem Defaultwert `0`. +* `limit`, ein optionales `int`. + +!!! tip "Tipp" + Sie kÃļnnen auch `Enum`s verwenden, auf die gleiche Weise wie mit [Pfad-Parametern](path-params.md#vordefinierte-parameterwerte){.internal-link target=_blank}. From 28e679d6dccabce4336901f840f125237f6bed12 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 14:55:49 +0000 Subject: [PATCH 215/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 5d31e52615..6434871d86 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -46,6 +46,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/query-params.md`. PR [#10293](https://github.com/tiangolo/fastapi/pull/10293) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/benchmarks.md`. PR [#10866](https://github.com/tiangolo/fastapi/pull/10866) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Turkish translation for `docs/tr/docs/learn/index.md`. PR [#11014](https://github.com/tiangolo/fastapi/pull/11014) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/security/index.md`. PR [#9945](https://github.com/tiangolo/fastapi/pull/9945) by [@mojtabapaso](https://github.com/mojtabapaso). From ecee093e340de9221558e06fe34c9d80f2609819 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:56:05 +0300 Subject: [PATCH 216/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/how-to/index.md`=20(#11021)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/how-to/index.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 docs/tr/docs/how-to/index.md diff --git a/docs/tr/docs/how-to/index.md b/docs/tr/docs/how-to/index.md new file mode 100644 index 0000000000..8ece295158 --- /dev/null +++ b/docs/tr/docs/how-to/index.md @@ -0,0 +1,11 @@ +# NasÄąl YapÄąlÄąr - Tarifler + +Burada çeşitli konular hakkÄąnda farklÄą tarifler veya "nasÄąl yapÄąlÄąr" kÄąlavuzlarÄą yer alÄąyor. + +Bu fikirlerin bÃŧyÃŧk bir kÄąsmÄą aşağı yukarÄą **bağımsÄąz** olacaktÄąr, çoğu durumda bunlarÄą sadece **projenize** hitap ediyorsa incelemelisiniz. + +Projeniz için ilginç ve yararlÄą gÃļrÃŧnen bir şey varsa devam edin ve inceleyin, aksi halde bunlarÄą atlayabilirsiniz. + +!!! tip "İpucu" + + **FastAPI**'Äą dÃŧzgÃŧn (ve Ãļnerilen) şekilde Ãļğrenmek istiyorsanÄąz [Öğretici - KullanÄącÄą Rehberi](../tutorial/index.md){.internal-link target=_blank}'ni bÃļlÃŧm bÃļlÃŧm okuyun. From 3e98fb9c8390f068bb6b40bbe12c6abbddaadaed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:57:16 +0300 Subject: [PATCH 217/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/resources/index.md`=20(#11020)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/resources/index.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 docs/tr/docs/resources/index.md diff --git a/docs/tr/docs/resources/index.md b/docs/tr/docs/resources/index.md new file mode 100644 index 0000000000..fc71a9ca1b --- /dev/null +++ b/docs/tr/docs/resources/index.md @@ -0,0 +1,3 @@ +# Kaynaklar + +Ek kaynaklar, dÄąÅŸ bağlantÄąlar, makaleler ve daha fazlasÄą. âœˆī¸ From 01c56c059e71ff1c902bc1b4dcf672a0f6ca7e58 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 14:58:23 +0000 Subject: [PATCH 218/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6434871d86..7e8e8487d9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -46,6 +46,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/how-to/index.md`. PR [#11021](https://github.com/tiangolo/fastapi/pull/11021) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add German translation for `docs/de/docs/tutorial/query-params.md`. PR [#10293](https://github.com/tiangolo/fastapi/pull/10293) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/benchmarks.md`. PR [#10866](https://github.com/tiangolo/fastapi/pull/10866) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Turkish translation for `docs/tr/docs/learn/index.md`. PR [#11014](https://github.com/tiangolo/fastapi/pull/11014) by [@hasansezertasan](https://github.com/hasansezertasan). From 06bdf03bcee34761ca94b97c2aa93b4dd01f667c Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 14:59:03 +0000 Subject: [PATCH 219/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7e8e8487d9..cf9a031ace 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -46,6 +46,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/resources/index.md`. PR [#11020](https://github.com/tiangolo/fastapi/pull/11020) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/how-to/index.md`. PR [#11021](https://github.com/tiangolo/fastapi/pull/11021) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add German translation for `docs/de/docs/tutorial/query-params.md`. PR [#10293](https://github.com/tiangolo/fastapi/pull/10293) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/benchmarks.md`. PR [#10866](https://github.com/tiangolo/fastapi/pull/10866) by [@nilslindemann](https://github.com/nilslindemann). From 5d74e58e952e9286d8352fb9f2e904fad8746f07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Sezer=20Ta=C5=9Fan?= <13135006+hasansezertasan@users.noreply.github.com> Date: Thu, 25 Jan 2024 17:59:43 +0300 Subject: [PATCH 220/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Turkish=20translat?= =?UTF-8?q?ion=20for=20`docs/tr/docs/history-design-future.md`=20(#11012)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/tr/docs/history-design-future.md | 79 +++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 docs/tr/docs/history-design-future.md diff --git a/docs/tr/docs/history-design-future.md b/docs/tr/docs/history-design-future.md new file mode 100644 index 0000000000..950fcf37d7 --- /dev/null +++ b/docs/tr/docs/history-design-future.md @@ -0,0 +1,79 @@ +# Geçmişi, TasarÄąmÄą ve Geleceği + +Bir sÃŧre Ãļnce, bir **FastAPI** kullanÄącÄąsÄą sordu: + +> Bu projenin geçmişi nedir? Birkaç hafta içinde hiçbir yerden harika bir şeye dÃļnÃŧşmÃŧş gibi gÃļrÃŧnÃŧyor [...] + +İşte o geçmişin bir kÄąsmÄą. + +## Alternatifler + +Bir sÃŧredir karmaÅŸÄąk gereksinimlere sahip API'lar oluşturuyor (Makine Öğrenimi, dağıtÄąk sistemler, asenkron işler, NoSQL veritabanlarÄą vb.) ve farklÄą geliştirici ekiplerini yÃļnetiyorum. + +Bu sÃŧreçte birçok alternatifi araştÄąrmak, test etmek ve kullanmak zorunda kaldÄąm. + +**FastAPI**'Äąn geçmişi, bÃŧyÃŧk ÃļlçÃŧde Ãļnceden geliştirilen araçlarÄąn geçmişini kapsÄąyor. + +[Alternatifler](alternatives.md){.internal-link target=_blank} bÃļlÃŧmÃŧnde belirtildiği gibi: + +
+ +BaşkalarÄąnÄąn daha Ãļnceki çalÄąÅŸmalarÄą olmasaydÄą, **FastAPI** var olmazdÄą. + +Geçmişte oluşturulan pek çok araç **FastAPI**'a ilham kaynağı olmuştur. + +YÄąllardÄąr yeni bir framework oluşturmaktan kaÃ§ÄąnÄąyordum. BaşlangÄąÃ§ta **FastAPI**'Äąn çÃļzdÃŧğÃŧ sorunlarÄą çÃļzebilmek için pek çok farklÄą framework, eklenti ve araç kullanmayÄą denedim. + +Ancak bir noktada, geçmişteki diğer araçlardan en iyi fikirleri alarak bÃŧtÃŧn bu çÃļzÃŧmleri kapsayan, ayrÄąca bÃŧtÃŧn bunlarÄą Python'Äąn daha Ãļnce mevcut olmayan Ãļzelliklerini (Python 3.6+ ile gelen tip belirteçleri) kullanarak yapan bir şey Ãŧretmekten başka bir seçenek kalmamÄąÅŸtÄą. + +
+ +## AraştÄąrma + +Önceki alternatifleri kullanarak hepsinden bir şeyler Ãļğrenip, fikirler alÄąp, bunlarÄą kendim ve çalÄąÅŸtığım geliştirici ekipler için en iyi şekilde birleştirebilme şansÄąm oldu. + +Mesela, ideal olarak standart Python tip belirteçlerine dayanmasÄą gerektiği aÃ§ÄąktÄą. + +AyrÄąca, en iyi yaklaÅŸÄąm zaten mevcut olan standartlarÄą kullanmaktÄą. + +Sonuç olarak, **FastAPI**'Äą kodlamaya başlamadan Ãļnce, birkaç ay boyunca OpenAPI, JSON Schema, OAuth2 ve benzerlerinin tanÄąmlamalarÄąnÄą inceledim. İlişkilerini, ÃļrtÃŧştÃŧkleri noktalarÄą ve farklÄąlÄąklarÄąnÄą anlamaya çalÄąÅŸtÄąm. + +## TasarÄąm + +SonrasÄąnda, (**FastAPI** kullanan bir geliştirici olarak) sahip olmak istediğim "API"Äą tasarlamak için biraz zaman harcadÄąm. + +Çeşitli fikirleri en popÃŧler Python editÃļrlerinde test ettim: PyCharm, VS Code, Jedi tabanlÄą editÃļrler. + +Bu test, en son Python Developer Survey'ine gÃļre, kullanÄącÄąlarÄąn yaklaÅŸÄąk %80'inin kullandığı editÃļrleri kapsÄąyor. + +Bu da demek oluyor ki **FastAPI**, Python geliştiricilerinin %80'inin kullandığı editÃļrlerle test edildi. Ve diğer editÃļrlerin çoğu benzer şekilde çalÄąÅŸtığından, avantajlarÄą neredeyse tÃŧm editÃļrlerde çalÄąÅŸacaktÄąr. + +Bu şekilde, kod tekrarÄąnÄą mÃŧmkÃŧn olduğunca azaltmak, her yerde otomatik tamamlama, tip ve hata kontrollerine sahip olmak için en iyi yollarÄą bulabildim. + +Hepsi, tÃŧm geliştiriciler için en iyi geliştirme deneyimini sağlayacak şekilde. + +## Gereksinimler + +Çeşitli alternatifleri test ettikten sonra, avantajlarÄąndan dolayÄą **Pydantic**'i kullanmaya karar verdim. + +Sonra, JSON Schema ile tamamen uyumlu olmasÄąnÄą sağlamak, kÄąsÄątlama bildirimlerini tanÄąmlamanÄąn farklÄą yollarÄąnÄą desteklemek ve birkaç editÃļrdeki testlere dayanarak editÃļr desteğini (tip kontrolleri, otomatik tamamlama) geliştirmek için katkÄąda bulundum. + +Geliştirme sÄąrasÄąnda, diğer ana gereksinim olan **Starlette**'e de katkÄąda bulundum. + +## Geliştirme + +**FastAPI**'Äą oluşturmaya başladığımda, parçalarÄąn çoğu zaten yerindeydi, tasarÄąm tanÄąmlanmÄąÅŸtÄą, gereksinimler ve araçlar hazÄąrdÄą, standartlar ve tanÄąmlamalar hakkÄąndaki bilgi net ve tazeydi. + +## Gelecek + +Şimdiye kadar, **FastAPI**'Äąn fikirleriyle birçok kişiye faydalÄą olduğu apaÃ§Äąk ortada. + +Birçok kullanÄąm durumuna daha iyi uyduğu için, Ãļnceki alternatiflerin yerine seçiliyor. + +Ben ve ekibim dahil, birçok geliştirici ve ekip projelerinde **FastAPI**'ya bağlÄą. + +Tabi, geliştirilecek birçok Ãļzellik ve iyileştirme mevcut. + +**FastAPI**'Äąn ÃļnÃŧnde harika bir gelecek var. + +[YardÄąmlarÄąnÄąz](help-fastapi.md){.internal-link target=_blank} çok değerlidir. From 1b01cbe0927d3dc7ababf4d5dd52cc0c4874e296 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 15:03:50 +0000 Subject: [PATCH 221/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index cf9a031ace..b6ac779a88 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -46,6 +46,7 @@ hide: ### Translations +* 🌐 Add Turkish translation for `docs/tr/docs/history-design-future.md`. PR [#11012](https://github.com/tiangolo/fastapi/pull/11012) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/resources/index.md`. PR [#11020](https://github.com/tiangolo/fastapi/pull/11020) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/how-to/index.md`. PR [#11021](https://github.com/tiangolo/fastapi/pull/11021) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add German translation for `docs/de/docs/tutorial/query-params.md`. PR [#10293](https://github.com/tiangolo/fastapi/pull/10293) by [@nilslindemann](https://github.com/nilslindemann). From d693d0a980eb7aaa3b98ed7731057543493c014c Mon Sep 17 00:00:00 2001 From: Luccas Mateus Date: Thu, 25 Jan 2024 12:05:24 -0300 Subject: [PATCH 222/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Portuguese=20trans?= =?UTF-8?q?lation=20for=20`docs/pt/docs/tutorial/schema-extra-example.md`?= =?UTF-8?q?=20(#4065)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/pt/docs/tutorial/schema-extra-example.md | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 docs/pt/docs/tutorial/schema-extra-example.md diff --git a/docs/pt/docs/tutorial/schema-extra-example.md b/docs/pt/docs/tutorial/schema-extra-example.md new file mode 100644 index 0000000000..0355450fa8 --- /dev/null +++ b/docs/pt/docs/tutorial/schema-extra-example.md @@ -0,0 +1,109 @@ +# Declare um exemplo dos dados da requisiÃ§ÃŖo + +VocÃĒ pode declarar exemplos dos dados que a sua aplicaÃ§ÃŖo pode receber. + +Aqui estÃŖo vÃĄrias formas de se fazer isso. + +## `schema_extra` do Pydantic + +VocÃĒ pode declarar um `example` para um modelo Pydantic usando `Config` e `schema_extra`, conforme descrito em DocumentaÃ§ÃŖo do Pydantic: Schema customization: + +```Python hl_lines="15-23" +{!../../../docs_src/schema_extra_example/tutorial001.py!} +``` + +Essas informaçÃĩes extras serÃŖo adicionadas como se encontram no **JSON Schema** de resposta desse modelo e serÃŖo usadas na documentaÃ§ÃŖo da API. + +!!! tip "Dica" + VocÃĒ pode usar a mesma tÊcnica para estender o JSON Schema e adicionar suas prÃŗprias informaçÃĩes extras de forma personalizada. + + Por exemplo, vocÃĒ pode usar isso para adicionar metadados para uma interface de usuÃĄrio de front-end, etc. + +## `Field` de argumentos adicionais + +Ao usar `Field ()` com modelos Pydantic, vocÃĒ tambÊm pode declarar informaçÃĩes extras para o **JSON Schema** passando quaisquer outros argumentos arbitrÃĄrios para a funÃ§ÃŖo. + +VocÃĒ pode usar isso para adicionar um `example` para cada campo: + +```Python hl_lines="4 10-13" +{!../../../docs_src/schema_extra_example/tutorial002.py!} +``` + +!!! warning "AtenÃ§ÃŖo" + Lembre-se de que esses argumentos extras passados ​​nÃŖo adicionarÃŖo nenhuma validaÃ§ÃŖo, apenas informaçÃĩes extras, para fins de documentaÃ§ÃŖo. + +## `example` e `examples` no OpenAPI + +Ao usar quaisquer dos: + +* `Path()` +* `Query()` +* `Header()` +* `Cookie()` +* `Body()` +* `Form()` +* `File()` + +vocÃĒ tambÊm pode declarar um dado `example` ou um grupo de `examples` com informaçÃĩes adicionais que serÃŖo adicionadas ao **OpenAPI**. + +### `Body` com `example` + +Aqui nÃŗs passamos um `example` dos dados esperados por `Body()`: + +```Python hl_lines="21-26" +{!../../../docs_src/schema_extra_example/tutorial003.py!} +``` + +### Exemplo na UI da documentaÃ§ÃŖo + +Com qualquer um dos mÊtodos acima, os `/docs` vÃŖo ficar assim: + + + +### `Body` com vÃĄrios `examples` + +Alternativamente ao Ãēnico `example`, vocÃĒ pode passar `examples` usando um `dict` com **vÃĄrios examples**, cada um com informaçÃĩes extras que serÃŖo adicionadas no **OpenAPI** tambÊm. + +As chaves do `dict` identificam cada exemplo, e cada valor Ê outro `dict`. + +Cada `dict` de exemplo específico em `examples` pode conter: + +* `summary`: Pequena descriÃ§ÃŖo do exemplo. +* `description`: Uma descriÃ§ÃŖo longa que pode conter texto em Markdown. +* `value`: O prÃŗprio exemplo mostrado, ex: um `dict`. +* `externalValue`: alternativa ao `value`, uma URL apontando para o exemplo. Embora isso possa nÃŖo ser suportado por tantas ferramentas quanto `value`. + +```Python hl_lines="22-48" +{!../../../docs_src/schema_extra_example/tutorial004.py!} +``` + +### Exemplos na UI da documentaÃ§ÃŖo + +Com `examples` adicionado a `Body()`, os `/docs` vÃŖo ficar assim: + + + +## Detalhes tÊcnicos + +!!! warning "AtenÃ§ÃŖo" + Esses sÃŖo detalhes muito tÊcnicos sobre os padrÃĩes **JSON Schema** e **OpenAPI**. + + Se as ideias explicadas acima jÃĄ funcionam para vocÃĒ, isso pode ser o suficiente, e vocÃĒ provavelmente nÃŖo precisa desses detalhes, fique à vontade para pular. + +Quando vocÃĒ adiciona um exemplo dentro de um modelo Pydantic, usando `schema_extra` ou` Field(example="something") `esse exemplo Ê adicionado ao **JSON Schema** para esse modelo Pydantic. + +E esse **JSON Schema** do modelo Pydantic estÃĄ incluído no **OpenAPI** da sua API e, em seguida, Ê usado na UI da documentaÃ§ÃŖo. + +O **JSON Schema** na verdade nÃŖo tem um campo `example` nos padrÃĩes. VersÃĩes recentes do JSON Schema definem um campo `examples`, mas o OpenAPI 3.0.3 Ê baseado numa versÃŖo mais antiga do JSON Schema que nÃŖo tinha `examples`. + +Por isso, o OpenAPI 3.0.3 definiu o seu prÃŗprio `example` para a versÃŖo modificada do **JSON Schema** que Ê usada, para o mesmo prÃŗposito (mas Ê apenas `example` no singular, nÃŖo `examples`), e Ê isso que Ê usado pela UI da documentaÃ§ÃŖo da API(usando o Swagger UI). + +Portanto, embora `example` nÃŖo seja parte do JSON Schema, Ê parte da versÃŖo customizada do JSON Schema usada pelo OpenAPI, e Ê isso que vai ser usado dentro da UI de documentaÃ§ÃŖo. + +Mas quando vocÃĒ usa `example` ou `examples` com qualquer um dos outros utilitÃĄrios (`Query()`, `Body()`, etc.) esses exemplos nÃŖo sÃŖo adicionados ao JSON Schema que descreve esses dados (nem mesmo para versÃŖo prÃŗpria do OpenAPI do JSON Schema), eles sÃŖo adicionados diretamente à declaraÃ§ÃŖo da *operaÃ§ÃŖo de rota* no OpenAPI (fora das partes do OpenAPI que usam o JSON Schema). + +Para `Path()`, `Query()`, `Header()`, e `Cookie()`, o `example` e `examples` sÃŖo adicionados a definiÃ§ÃŖo do OpenAPI, dentro do `Parameter Object` (na especificaÃ§ÃŖo). + +E para `Body()`, `File()`, e `Form()`, o `example` e `examples` sÃŖo de maneira equivalente adicionados para a definiÃ§ÃŖo do OpenAPI, dentro do `Request Body Object`, no campo `content`, no `Media Type Object` (na especificaÃ§ÃŖo). + +Por outro lado, hÃĄ uma versÃŖo mais recente do OpenAPI: **3.1.0**, lançada recentemente. Baseado no JSON Schema mais recente e a maioria das modificaçÃĩes da versÃŖo customizada do OpenAPI do JSON Schema sÃŖo removidas, em troca dos recursos das versÃĩes recentes do JSON Schema, portanto, todas essas pequenas diferenças sÃŖo reduzidas. No entanto, a UI do Swagger atualmente nÃŖo oferece suporte a OpenAPI 3.1.0, entÃŖo, por enquanto, Ê melhor continuar usando as opçÃĩes acima. From 92feb735317996ef81763da370efa92c61a6d925 Mon Sep 17 00:00:00 2001 From: github-actions Date: Thu, 25 Jan 2024 15:09:59 +0000 Subject: [PATCH 223/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b6ac779a88..a2b2199a8a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -46,6 +46,7 @@ hide: ### Translations +* 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/schema-extra-example.md`. PR [#4065](https://github.com/tiangolo/fastapi/pull/4065) by [@luccasmmg](https://github.com/luccasmmg). * 🌐 Add Turkish translation for `docs/tr/docs/history-design-future.md`. PR [#11012](https://github.com/tiangolo/fastapi/pull/11012) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/resources/index.md`. PR [#11020](https://github.com/tiangolo/fastapi/pull/11020) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/how-to/index.md`. PR [#11021](https://github.com/tiangolo/fastapi/pull/11021) by [@hasansezertasan](https://github.com/hasansezertasan). From 7ee93035515abbbb32c0dd14e6b9e9464a8fe50b Mon Sep 17 00:00:00 2001 From: Donny Peeters <46660228+Donnype@users.noreply.github.com> Date: Sat, 27 Jan 2024 10:08:54 +0100 Subject: [PATCH 224/305] =?UTF-8?q?=F0=9F=93=9D=20Add=20External=20Link:?= =?UTF-8?q?=2010=20Tips=20for=20adding=20SQLAlchemy=20to=20FastAPI=20(#110?= =?UTF-8?q?36)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/data/external_links.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/en/data/external_links.yml b/docs/en/data/external_links.yml index 44b064fe9b..58e7acefee 100644 --- a/docs/en/data/external_links.yml +++ b/docs/en/data/external_links.yml @@ -1,5 +1,9 @@ Articles: English: + - author: Donny Peeters + author_link: https://github.com/Donnype + link: https://bitestreams.com/blog/fastapi-sqlalchemy/ + title: 10 Tips for adding SQLAlchemy to FastAPI - author: Jessica Temporal author_link: https://jtemporal.com/socials link: https://jtemporal.com/tips-on-migrating-from-flask-to-fastapi-and-vice-versa/ From e196abad3ed64d0b25054e1d7a9ed558cb9b3294 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:09:13 +0000 Subject: [PATCH 225/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a2b2199a8a..a778d7fbf1 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Add External Link: 10 Tips for adding SQLAlchemy to FastAPI. PR [#11036](https://github.com/tiangolo/fastapi/pull/11036) by [@Donnype](https://github.com/Donnype). * 📝 Add External Link: Tips on migrating from Flask to FastAPI and vice-versa. PR [#11029](https://github.com/tiangolo/fastapi/pull/11029) by [@jtemporal](https://github.com/jtemporal). * 📝 Deprecate old tutorials: Peewee, Couchbase, encode/databases. PR [#10979](https://github.com/tiangolo/fastapi/pull/10979) by [@tiangolo](https://github.com/tiangolo). * âœī¸ Fix typo in `fastapi/security/oauth2.py`. PR [#10972](https://github.com/tiangolo/fastapi/pull/10972) by [@RafalSkolasinski](https://github.com/RafalSkolasinski). From 2378cfd56ab87738edd16e97e11716c8d9a80b9b Mon Sep 17 00:00:00 2001 From: Kani Kim Date: Sat, 27 Jan 2024 18:11:46 +0900 Subject: [PATCH 226/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`/docs/ko/docs/tutorial/body.md`=20(#11000)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/body.md | 213 ++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 docs/ko/docs/tutorial/body.md diff --git a/docs/ko/docs/tutorial/body.md b/docs/ko/docs/tutorial/body.md new file mode 100644 index 0000000000..9317285728 --- /dev/null +++ b/docs/ko/docs/tutorial/body.md @@ -0,0 +1,213 @@ +# ėš”ė˛­ ëŗ¸ëŦ¸ + +클ëŧė´ė–¸íŠ¸(브ëŧėš°ė €ëŧęŗ  í•´ë´…ė‹œë‹¤)로ëļ€í„° ė—ŦëŸŦëļ„ė˜ API로 ë°ė´í„°ëĨŧ ëŗ´ë‚´ė•ŧ 할 때, **ėš”ė˛­ ëŗ¸ëŦ¸**ėœŧ로 ëŗ´ëƒ…ë‹ˆë‹¤. + +**ėš”ė˛­** ëŗ¸ëŦ¸ė€ 클ëŧė´ė–¸íŠ¸ė—ė„œ API로 ëŗ´ë‚´ė§€ëŠ” ë°ė´í„°ėž…ë‹ˆë‹¤. **ė‘ë‹ĩ** ëŗ¸ëŦ¸ė€ API가 클ëŧė´ė–¸íŠ¸ëĄœ ëŗ´ë‚´ëŠ” ë°ė´í„°ėž…ë‹ˆë‹¤. + +ė—ŦëŸŦëļ„ė˜ API는 대ëļ€ëļ„ė˜ ę˛Ŋ뚰 **ė‘ë‹ĩ** ëŗ¸ëŦ¸ė„ ëŗ´ë‚´ė•ŧ 합니다. í•˜ė§€ë§Œ 클ëŧė´ė–¸íŠ¸ëŠ” **ėš”ė˛­** ëŗ¸ëŦ¸ė„ 매 번 ëŗ´ë‚ŧ í•„ėš”ę°€ ė—†ėŠĩ니다. + +**ėš”ė˛­** ëŗ¸ëŦ¸ė„ ė„ ė–¸í•˜ę¸° ėœ„í•´ė„œ ëĒ¨ë“  강ë Ĩ함ęŗŧ ė´ė ė„ 갖ėļ˜ Pydantic ëĒ¨ë¸ė„ ė‚ŦėšŠí•Šë‹ˆë‹¤. + +!!! ė •ëŗ´ + ë°ė´í„°ëĨŧ ëŗ´ë‚´ę¸° ėœ„í•´, (ėĸ€ 더 ëŗ´íŽ¸ė ė¸) `POST`, `PUT`, `DELETE` í˜šė€ `PATCH` 뤑뗐 하나ëĨŧ ė‚ŦėšŠí•˜ëŠ” ę˛ƒė´ ėĸ‹ėŠĩ니다. + + `GET` ėš”ė˛­ė— ëŗ¸ëŦ¸ė„ ë‹´ė•„ ëŗ´ë‚´ëŠ” ę˛ƒė€ ëĒ…ė„¸ė„œė— ė •ė˜ë˜ė§€ ė•Šė€ í–‰ë™ėž…ë‹ˆë‹¤. ꡸ëŸŧė—ë„ ëļˆęĩŦí•˜ęŗ , ė´ ë°Šė‹ė€ ė•„ėŖŧ ëŗĩėžĄí•œ/ęˇší•œė˜ ė‚ŦėšŠ ėƒí™Šė—ė„œë§Œ FastAPI뗐 ė˜í•´ ė§€ė›ëŠë‹ˆë‹¤. + + `GET` ėš”ė˛­ė— ëŗ¸ëŦ¸ė„ 담는 ę˛ƒė€ ęļŒėžĨë˜ė§€ ė•Šę¸°ė—, Swagger UIę°™ė€ 대화형 ëŦ¸ė„œė—ė„œëŠ” `GET` ė‚ŦėšŠė‹œ 담기는 ëŗ¸ëŦ¸ė— 대한 ëŦ¸ė„œëĨŧ í‘œė‹œí•˜ė§€ ė•Šėœŧ늰, 뤑氄뗐 ėžˆëŠ” í”„ëĄė‹œëŠ” ė´ëĨŧ ė§€ė›í•˜ė§€ ė•Šė„ ėˆ˜ë„ ėžˆėŠĩ니다. + +## Pydanticė˜ `BaseModel` ėž„íŦ트 + +ë¨ŧė € `pydantic`ė—ė„œ `BaseModel`ëĨŧ ėž„íŦ트해ė•ŧ 합니다: + +=== "Python 3.10+" + + ```Python hl_lines="2" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="4" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +## ė—ŦëŸŦëļ„ė˜ ë°ė´í„° ëĒ¨ë¸ 만들기 + +`BaseModel`ëĨŧ ėƒė†ë°›ė€ í´ëž˜ėŠ¤ëĄœ ė—ŦëŸŦëļ„ė˜ ë°ė´í„° ëĒ¨ë¸ė„ ė„ ė–¸í•Šë‹ˆë‹¤. + +ëĒ¨ë“  ė–´íŠ¸ëĻŦëˇ°íŠ¸ė— 대해 í‘œė¤€ íŒŒė´ėŦ íƒ€ėž…ė„ ė‚ŦėšŠí•Šë‹ˆë‹¤: + +=== "Python 3.10+" + + ```Python hl_lines="5-9" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="7-11" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•  ë•Œė™€ ę°™ė´, ëĒ¨ë¸ ė–´íŠ¸ëĻŦ뷰트가 ę¸°ëŗ¸ ę°’ė„ 氀맀溠 ėžˆė–´ë„ ė´ëŠ” í•„ėˆ˜ę°€ ė•„ë‹™ë‹ˆë‹¤. ęˇ¸ė™¸ė—ëŠ” í•„ėˆ˜ėž…ë‹ˆë‹¤. 掏렀 `None`ė„ ė‚ŦėšŠí•˜ė—Ŧ ė„ íƒė ėœŧ로 만들 눘 ėžˆėŠĩ니다. + +똈ëĨŧ 들면, ėœ„ė˜ ė´ ëĒ¨ë¸ė€ JSON "`object`" (í˜šė€ íŒŒė´ėŦ `dict`)ė„ ë‹¤ėŒęŗŧ ę°™ė´ ė„ ė–¸í•Šë‹ˆë‹¤: + +```JSON +{ + "name": "Foo", + "description": "ė„ íƒė ė¸ 네ëĒ…ëž€", + "price": 45.2, + "tax": 3.5 +} +``` + +...`description`ęŗŧ `tax`는 (ę¸°ëŗ¸ ę°’ė´ `None`ėœŧ로 ë˜ė–´ ėžˆė–´) ė„ íƒė ė´ę¸° 때ëŦ¸ė—, ė´ JSON "`object`"는 ë‹¤ėŒęŗŧ ę°™ė€ ėƒí™Šė—ė„œë„ ėœ íš¨í•Šë‹ˆë‹¤: + +```JSON +{ + "name": "Foo", + "price": 45.2 +} +``` + +## ë§¤ę°œëŗ€ėˆ˜ëĄœė„œ ė„ ė–¸í•˜ę¸° + +ė—ŦëŸŦëļ„ė˜ *ę˛Ŋ로 ėž‘ë™*뗐 ėļ”ę°€í•˜ę¸° ėœ„í•´, ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ ꡸ëĻŦęŗ  ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ė—ė„œ ė„ ė–¸í–ˆë˜ 것ęŗŧ ę°™ė€ ë°Šė‹ėœŧ로 ė„ ė–¸í•˜ëŠ´ 됩니다. + +=== "Python 3.10+" + + ```Python hl_lines="16" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +...꡸ëĻŦęŗ  ë§Œë“¤ė–´ë‚¸ ëĒ¨ë¸ė¸ `Item`ėœŧ로 íƒ€ėž…ė„ ė„ ė–¸í•Šë‹ˆë‹¤. + +## 결ęŗŧ + +ėœ„ė—ė„œė˜ ë‹¨ėˆœí•œ íŒŒė´ėŦ íƒ€ėž… ė„ ė–¸ėœŧ로, **FastAPI**는 ë‹¤ėŒęŗŧ ę°™ė´ ë™ėž‘í•Šë‹ˆë‹¤: + +* ėš”ė˛­ė˜ ëŗ¸ëŦ¸ė„ JSONėœŧ로 ėŊė–´ ë“¤ėž…ë‹ˆë‹¤. +* (í•„ėš”í•˜ë‹¤ëŠ´) ëŒ€ė‘ë˜ëŠ” íƒ€ėž…ėœŧ로 ëŗ€í™˜í•Šë‹ˆë‹¤. +* ë°ė´í„°ëĨŧ 검ėĻí•Šë‹ˆë‹¤. + * 만ė•Ŋ ë°ė´í„°ę°€ ėœ íš¨í•˜ė§€ ė•Šë‹¤ëŠ´, ė •í™•ížˆ ė–´ë–¤ ę˛ƒė´ ꡸ëĻŦęŗ  ė–´ë””ė—ė„œ ë°ė´í„°ę°€ ėž˜ ëĒģ ë˜ė—ˆëŠ”ė§€ ė§€ė‹œí•˜ëŠ” ėšœė ˆí•˜ęŗ  ëĒ…ëŖŒí•œ 뗐ëŸŦëĨŧ 반환할 ę˛ƒėž…ë‹ˆë‹¤. +* ë§¤ę°œëŗ€ėˆ˜ `item`뗐 íŦ함된 ėˆ˜ė‹  ë°ė´í„°ëĨŧ 렜ęŗĩ합니다. + * í•¨ėˆ˜ ë‚´ė—ė„œ ë§¤ę°œëŗ€ėˆ˜ëĨŧ `Item` íƒ€ėž…ėœŧ로 ė„ ė–¸í–ˆę¸° 때ëŦ¸ė—, ëĒ¨ë“  ė–´íŠ¸ëĻŦëˇ°íŠ¸ė™€ 掏뗐 대한 íƒ€ėž…ė— 대한 íŽ¸ė§‘ę¸° 맀뛐(ė™„ė„ą 등)ė„ 또한 ë°›ė„ 눘 ėžˆėŠĩ니다. +* ė—ŦëŸŦëļ„ė˜ ëĒ¨ë¸ė„ ėœ„í•œ JSON ėŠ¤í‚¤ë§ˆ ė •ė˜ëĨŧ ėƒė„ąí•Šë‹ˆë‹¤. ė—ŦëŸŦëļ„ė˜ í”„ëĄœė íŠ¸ė— ė í•Ší•˜ë‹¤ëŠ´ ė—ŦëŸŦëļ„ė´ ė‚ŦėšŠí•˜ęŗ  ė‹ļė€ ęŗŗ ė–´ë””ė—ė„œë‚˜ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. +* ė´ëŸŦ한 ėŠ¤í‚¤ë§ˆëŠ”, ėƒė„ąëœ OpenAPI ėŠ¤í‚¤ë§ˆ ėŧëļ€ę°€ 될 ę˛ƒė´ëŠ°, ėžë™ ëŦ¸ė„œí™” UI뗐 ė‚ŦėšŠëŠë‹ˆë‹¤. + +## ėžë™ ëŦ¸ė„œí™” + +ëĒ¨ë¸ė˜ JSON ėŠ¤í‚¤ë§ˆëŠ” ėƒė„ąëœ OpenAPI ėŠ¤í‚¤ë§ˆė— íŦ함되며 대화형 API ëŦ¸ė„œė— í‘œė‹œëŠë‹ˆë‹¤: + + + +ė´ëĨŧ í•„ėš”ëĄœ 하는 ę°ę°ė˜ *ę˛Ŋ로 ėž‘ë™*내ëļ€ė˜ API ëŦ¸ė„œė—ë„ ė‚ŦėšŠëŠë‹ˆë‹¤: + + + +## íŽ¸ė§‘ę¸° 맀뛐 + +íŽ¸ė§‘ę¸°ė—ė„œ, í•¨ėˆ˜ ë‚´ė—ė„œ íƒ€ėž… ížŒíŠ¸ė™€ ė™„ė„ąė„ ė–´ë””ė„œë‚˜ (만ė•Ŋ Pydantic model ëŒ€ė‹ ė— `dict`ė„ ë°›ė„ ę˛Ŋ뚰 ë‚˜íƒ€ë‚˜ė§€ ė•Šė„ 눘 ėžˆėŠĩ니다) ë°›ė„ 눘 ėžˆėŠĩ니다: + + + +ėž˜ëĒģ된 íƒ€ėž… 뗰낰뗐 대한 뗐ëŸŦ í™•ė¸ë„ ë°›ė„ 눘 ėžˆėŠĩ니다: + + + +ë‹¨ėˆœí•œ ėš°ė—°ė´ ė•„ë‹™ë‹ˆë‹¤. í”„ë ˆėž„ė›ŒíŦ 렄랴氀 ė´ëŸŦ한 ë””ėžė¸ė„ 뤑ė‹Ŧėœŧ로 ė„¤ęŗ„ë˜ė—ˆėŠĩ니다. + +꡸ ė–´ë–¤ ė‹¤í–‰ 렄뗐, ëĒ¨ë“  íŽ¸ė§‘ę¸°ė—ė„œ ėž‘ë™í•  눘 ėžˆë„ëĄ ëŗ´ėžĨ하기 ėœ„í•´ 네溄 ë‹¨ęŗ„ė—ė„œ 혹독하게 í…ŒėŠ¤íŠ¸ë˜ė—ˆėŠĩ니다. + +ė´ëĨŧ ė§€ė›í•˜ę¸° ėœ„í•´ Pydantic ėžė˛´ė—ė„œ ëLJëLJ ëŗ€ę˛Ŋė ė´ ėžˆė—ˆėŠĩ니다. + +ė´ė „ 늤íŦëĻ°ėƒˇė€ Visual Studio CodeëĨŧ ė°ė€ ę˛ƒėž…ë‹ˆë‹¤. + +í•˜ė§€ë§Œ ë˜‘ę°™ė€ íŽ¸ė§‘ę¸° ė§€ė›ė„ PyCharmė—ė„œ ë°›ė„ 눘 ėžˆęą°ë‚˜, 대ëļ€ëļ„ė˜ 다ëĨ¸ íŽ¸ė§‘ę¸°ė—ė„œë„ ë°›ė„ 눘 ėžˆėŠĩ니다: + + + +!!! 팁 + 만ė•Ŋ PyCharmëĨŧ íŽ¸ė§‘ę¸°ëĄœ ė‚ŦėšŠí•œë‹¤ëŠ´, Pydantic PyCharm Pluginė„ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + + ë‹¤ėŒ ė‚Ŧí•­ė„ íŦ함해 Pydantic ëĒ¨ë¸ė— 대한 íŽ¸ė§‘ę¸° ė§€ė›ė„ í–Ĩėƒė‹œí‚ĩ니다: + + * ėžë™ ė™„ė„ą + * íƒ€ėž… í™•ė¸ + * ëĻŦ팩토링 + * ę˛€ėƒ‰ + * 렐枀 + +## ëĒ¨ë¸ ė‚ŦėšŠí•˜ę¸° + +í•¨ėˆ˜ ė•ˆė—ė„œ ëĒ¨ë¸ ę°ė˛´ė˜ ëĒ¨ë“  ė–´íŠ¸ëĻŦëˇ°íŠ¸ė— 링렑 ė ‘ęˇŧ 가ëŠĨ합니다: + +=== "Python 3.10+" + + ```Python hl_lines="19" + {!> ../../../docs_src/body/tutorial002_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="21" + {!> ../../../docs_src/body/tutorial002.py!} + ``` + +## ėš”ė˛­ ëŗ¸ëŦ¸ + ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ + +ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ė™€ ėš”ė˛­ ëŗ¸ëŦ¸ė„ ë™ė‹œė— ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +**FastAPI**는 ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ė™€ ėŧėš˜í•˜ëŠ” í•¨ėˆ˜ ë§¤ę°œëŗ€ėˆ˜ę°€ **ę˛ŊëĄœė—ė„œ 氀렏뙀ė•ŧ 한다**는 ę˛ƒė„ ė¸ė§€í•˜ëŠ°, Pydantic ëĒ¨ë¸ëĄœ ė„ ė–¸ëœ ꡸ í•¨ėˆ˜ ë§¤ę°œëŗ€ėˆ˜ëŠ” **ėš”ė˛­ ëŗ¸ëŦ¸ė—ė„œ 氀렏뙀ė•ŧ 한다**는 ę˛ƒė„ ė¸ė§€í•  ę˛ƒėž…ë‹ˆë‹¤. + +=== "Python 3.10+" + + ```Python hl_lines="15-16" + {!> ../../../docs_src/body/tutorial003_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="17-18" + {!> ../../../docs_src/body/tutorial003.py!} + ``` + +## ėš”ė˛­ ëŗ¸ëŦ¸ + ę˛Ŋ로 + ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ + +**ëŗ¸ëŦ¸**, **ę˛Ŋ로** ꡸ëĻŦęŗ  **ėŋŧëĻŦ** ë§¤ę°œëŗ€ėˆ˜ ëĒ¨ë‘ ë™ė‹œė— ė„ ė–¸í•  ėˆ˜ë„ ėžˆėŠĩ니다. + +**FastAPI**는 ę°ę°ė„ ė¸ė§€í•˜ęŗ  ë°ė´í„°ëĨŧ ė˜ŗë°”ëĨ¸ ėœ„ėš˜ė— 氀렏ė˜Ŧ ę˛ƒėž…ë‹ˆë‹¤. + +=== "Python 3.10+" + + ```Python hl_lines="16" + {!> ../../../docs_src/body/tutorial004_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body/tutorial004.py!} + ``` + +í•¨ėˆ˜ ë§¤ę°œëŗ€ėˆ˜ëŠ” ë‹¤ėŒė„ 따ëŧė„œ ė¸ė§€í•˜ę˛Œ 됩니다: + +* 만ė•Ŋ ë§¤ę°œëŗ€ėˆ˜ę°€ **ę˛Ŋ로**ė—ë„ ė„ ė–¸ë˜ė–´ ėžˆë‹¤ëŠ´, ė´ëŠ” ę˛Ŋ로 ë§¤ę°œëŗ€ėˆ˜ëĄœ ė‚ŦėšŠë  ę˛ƒėž…ë‹ˆë‹¤. +* 만ė•Ŋ ë§¤ę°œëŗ€ėˆ˜ę°€ (`int`, `float`, `str`, `bool` 등ęŗŧ ę°™ė€) **뜠ėŧ한 íƒ€ėž…**ėœŧ로 ë˜ė–´ėžˆėœŧ늴, **ėŋŧëĻŦ** ë§¤ę°œëŗ€ėˆ˜ëĄœ í•´ė„ë  ę˛ƒėž…ë‹ˆë‹¤. +* 만ė•Ŋ ë§¤ę°œëŗ€ėˆ˜ę°€ **Pydantic ëĒ¨ë¸** íƒ€ėž…ėœŧ로 ė„ ė–¸ë˜ė–´ ėžˆėœŧ늴, ėš”ė˛­ **ëŗ¸ëŦ¸**ėœŧ로 í•´ė„ë  ę˛ƒėž…ë‹ˆë‹¤. + +!!! 및溠 + FastAPI는 `q`ė˜ ę°’ė´ í•„ėš”ė—†ėŒė„ ė•Œę˛Œ 될 ę˛ƒėž…ë‹ˆë‹¤. ę¸°ëŗ¸ ę°’ė´ `= None`ė´ę¸° 때ëŦ¸ėž…니다. + + `Union[str, None]`뗐 ėžˆëŠ” `Union`ė€ FastAPI뗐 ė˜í•´ ė‚ŦėšŠëœ ę˛ƒė´ ė•„ë‹ˆė§€ë§Œ, íŽ¸ė§‘ę¸°ëĄœ 하ė—Ŧ금 더 ë‚˜ė€ 맀뛐ęŗŧ 뗐ëŸŦ íƒė§€ëĨŧ ė§€ė›í•  ę˛ƒėž…ë‹ˆë‹¤. + +## Pydanticė—†ė´ + +만ė•Ŋ Pydantic ëĒ¨ë¸ė„ ė‚ŦėšŠí•˜ęŗ  ė‹ļė§€ ė•Šë‹¤ëŠ´, **Body** ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다. [Body - ë‹¤ė¤‘ ë§¤ę°œëŗ€ėˆ˜: ëŗ¸ëŦ¸ė— ėžˆëŠ” 뜠ėŧ한 값](body-multiple-params.md#singular-values-in-body){.internal-link target=_blank} ëŦ¸ė„œëĨŧ í™•ė¸í•˜ė„¸ėš”. From 00395f3eeb0bc2627e9829ff0d62e70548c19a7f Mon Sep 17 00:00:00 2001 From: Kani Kim Date: Sat, 27 Jan 2024 18:12:44 +0900 Subject: [PATCH 227/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/dependencies/index.md`=20(#10?= =?UTF-8?q?989)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/dependencies/index.md | 353 ++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100644 docs/ko/docs/tutorial/dependencies/index.md diff --git a/docs/ko/docs/tutorial/dependencies/index.md b/docs/ko/docs/tutorial/dependencies/index.md new file mode 100644 index 0000000000..d5d113860f --- /dev/null +++ b/docs/ko/docs/tutorial/dependencies/index.md @@ -0,0 +1,353 @@ +# ė˜ėĄ´ė„ą + +**FastAPI**는 ė•„ėŖŧ 강ë Ĩí•˜ė§€ë§Œ ė§ę´€ė ė¸ **ė˜ėĄ´ė„ą ėŖŧėž…** ė‹œėŠ¤í…œė„ 氀맀溠 ėžˆėŠĩ니다. + +ė´ëŠ” ė‚ŦėšŠí•˜ę¸° ė•„ėŖŧ ė‰Ŋ枌 ė„¤ęŗ„í–ˆėœŧ늰, ė–´ëŠ ę°œë°œėžë‚˜ 다ëĨ¸ ėģ´íŦë„ŒíŠ¸ė™€ **FastAPI**ëĨŧ ė‰Ŋ枌 í†ĩ합할 눘 ėžˆë„ëĄ ë§Œë“¤ė—ˆėŠĩ니다. + +## "ė˜ėĄ´ė„ą ėŖŧėž…"ė€ ëŦ´ė—‡ėž…ë‹ˆęšŒ? + +**"ė˜ėĄ´ė„ą ėŖŧėž…"**ė€ í”„ëĄœęˇ¸ëž˜ë°ė—ė„œ ė—ŦëŸŦëļ„ė˜ ėŊ”드(ė´ ę˛Ŋ뚰, ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜)가 ėž‘ë™í•˜ęŗ  ė‚ŦėšŠí•˜ëŠ” 데 í•„ėš”ëĄœ 하는 것, ėω "ė˜ėĄ´ė„ą"ė„ ė„ ė–¸í•  눘 ėžˆëŠ” ë°Šë˛•ė„ ė˜ë¯¸í•Šë‹ˆë‹¤. + +꡸ í›„ė—, ė‹œėŠ¤í…œ(ė´ ę˛Ŋ뚰 FastAPI)ė€ ė—ŦëŸŦëļ„ė˜ ėŊ”ë“œę°€ ėš”ęĩŦ하는 ė˜ėĄ´ė„ąė„ 렜ęŗĩ하기 ėœ„í•´ í•„ėš”í•œ ëĒ¨ë“  ėž‘ė—…ė„ 래ëĻŦ합니다.(ė˜ėĄ´ė„ąė„ "ėŖŧėž…"합니다) + +ė´ëŠ” ė—ŦëŸŦëļ„ė´ ë‹¤ėŒęŗŧ ę°™ė€ ė‚Ŧí•­ė„ í•„ėš”ëĄœ 할 때 ë§¤ėš° ėœ ėšŠí•Šë‹ˆë‹¤: + +* ęŗĩėšŠëœ ëĄœė§ė„ ę°€ėĄŒė„ ę˛Ŋ뚰 (ę°™ė€ ėŊ”드 ëĄœė§ė´ ęŗ„ė† 반ëŗĩ되는 ę˛Ŋ뚰). +* ë°ė´í„°ë˛ ė´ėŠ¤ ė—°ę˛°ė„ ęŗĩėœ í•˜ëŠ” ę˛Ŋ뚰. +* ëŗ´ė•ˆ, ė¸ėĻ, ė—­í•  ėš”ęĩŦ ė‚Ŧ항 ë“ąė„ ę°•ė œí•˜ëŠ” ę˛Ŋ뚰. +* ꡸ëĻŦęŗ  ë§Žė€ 다ëĨ¸ ė‚Ŧ항... + +ė´ ëĒ¨ë“  ė‚Ŧí•­ė„ 할 때 ėŊ”드 반ëŗĩė„ ėĩœė†Œí™”핊니다. + +## ė˛Ģë˛ˆė§¸ ë‹¨ęŗ„ + +ė•„ėŖŧ 간단한 똈렜ëĨŧ ë´…ė‹œë‹¤. 너ëŦ´ 간단할 ę˛ƒė´ę¸°ė— ė§€ę¸ˆ 당ėžĨė€ ėœ ėšŠí•˜ė§€ ė•Šė„ 눘 ėžˆėŠĩ니다. + +í•˜ė§€ë§Œ ė´ëĨŧ í†ĩ해 **ė˜ėĄ´ė„ą ėŖŧėž…** ė‹œėŠ¤í…œė´ ė–´ë–ģ枌 ėž‘ë™í•˜ëŠ”ė§€ė— ė¤‘ė ė„ 둘 ę˛ƒėž…ë‹ˆë‹¤. + +### ė˜ėĄ´ė„ą í˜šė€ "디펜더블" 만들기 + +ė˜ėĄ´ė„ąė— ė§‘ė¤‘í•´ ë´…ė‹œë‹¤. + +*ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*가 ę°€ė§ˆ 눘 ėžˆëŠ” ëĒ¨ë“  ë§¤ę°œëŗ€ėˆ˜ëĨŧ 갖는 ë‹¨ėˆœí•œ í•¨ėˆ˜ėž…ë‹ˆë‹¤: + +=== "Python 3.10+" + + ```Python hl_lines="8-9" + {!> ../../../docs_src/dependencies/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="8-11" + {!> ../../../docs_src/dependencies/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9-12" + {!> ../../../docs_src/dependencies/tutorial001_an.py!} + ``` + +=== "Python 3.10+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="6-7" + {!> ../../../docs_src/dependencies/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="8-11" + {!> ../../../docs_src/dependencies/tutorial001.py!} + ``` + +ė´ę˛Œ ë‹¤ėž…ë‹ˆë‹¤. + +**단 두 ė¤„ėž…ë‹ˆë‹¤**. + +꡸ëĻŦęŗ , ė´ í•¨ėˆ˜ëŠ” ė—ŦëŸŦëļ„ė˜ ëĒ¨ë“  *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*가 氀맀溠 ėžˆëŠ” 것ęŗŧ ę°™ė€ í˜•íƒœė™€ ęĩŦėĄ°ëĨŧ 氀맀溠 ėžˆėŠĩ니다. + +ė—ŦëŸŦëļ„ė€ ė´ëĨŧ "데ėŊ”ë ˆė´í„°"가 ė—†ëŠ” (`@app.get("/some-path")`가 ė—†ëŠ”) *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ëŧęŗ  ėƒę°í•  눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  ė—ŦëŸŦëļ„ė´ ė›í•˜ëŠ” ëŦ´ė—‡ė´ë“  반환할 눘 ėžˆėŠĩ니다. + +ė´ ę˛Ŋ뚰, ė´ ė˜ėĄ´ė„ąė€ ë‹¤ėŒęŗŧ ę°™ė€ ę˛Ŋ뚰ëĨŧ 기대합니다: + +* ė„ íƒė ė¸ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `q`, `str`ė„ ėžëŖŒí˜•ėœŧ로 ę°€ė§‘ë‹ˆë‹¤. +* ė„ íƒė ė¸ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `skip`, `int`ëĨŧ ėžëŖŒí˜•ėœŧ로 ę°€ė§€ëŠ° ę¸°ëŗ¸ ę°’ė€ `0`ėž…ë‹ˆë‹¤. +* ė„ íƒė ė¸ ėŋŧëĻŦ ë§¤ę°œëŗ€ėˆ˜ `limit`,`int`ëĨŧ ėžëŖŒí˜•ėœŧ로 ę°€ė§€ëŠ° ę¸°ëŗ¸ ę°’ė€ `100`ėž…ë‹ˆë‹¤. + +꡸ 후 ėœ„ė˜ ę°’ė„ íŦ함한 `dict` ėžëŖŒí˜•ėœŧ로 반환할 ëŋėž…니다. + +!!! ė •ëŗ´ + FastAPI는 0.95.0 ë˛„ė „ëļ€í„° `Annotated`뗐 대한 ė§€ė›ė„ (꡸ëĻŦęŗ  ė´ëĨŧ ė‚ŦėšŠí•˜ę¸° ęļŒėžĨ합니다) ėļ”ę°€í–ˆėŠĩ니다. + + ė˜›ë‚  ë˛„ė „ė„ 氀맀溠 ėžˆëŠ” ę˛Ŋ뚰, `Annotated`ëĨŧ ė‚ŦėšŠí•˜ë ¤ 하면 뗐ëŸŦëĨŧ ë§žė´í•˜ę˛Œ 될 ę˛ƒėž…ë‹ˆë‹¤. + + `Annotated`ëĨŧ ė‚ŦėšŠí•˜ę¸° 렄뗐 ėĩœė†Œ 0.95.1로 [FastAPI ë˛„ė „ ė—…ęˇ¸ë ˆė´ë“œ](../../deployment/versions.md#upgrading-the-fastapi-versions){.internal-link target=_blank}ëĨŧ í™•ė‹¤í•˜ę˛Œ í•˜ė„¸ėš”. + +### `Depends` ëļˆëŸŦ똤揰 + +=== "Python 3.10+" + + ```Python hl_lines="3" + {!> ../../../docs_src/dependencies/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="3" + {!> ../../../docs_src/dependencies/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="3" + {!> ../../../docs_src/dependencies/tutorial001_an.py!} + ``` + +=== "Python 3.10+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="1" + {!> ../../../docs_src/dependencies/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="3" + {!> ../../../docs_src/dependencies/tutorial001.py!} + ``` + +### "ė˜ėĄ´ėž"뗐 ė˜ėĄ´ė„ą ëĒ…ė‹œí•˜ę¸° + +*ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ė˜ ë§¤ę°œëŗ€ėˆ˜ëĄœ `Body`, `Query` ë“ąė„ ė‚ŦėšŠí•˜ëŠ” ë°Šė‹ęŗŧ ę°™ė´ ėƒˆëĄœėš´ ë§¤ę°œëŗ€ėˆ˜ëĄœ `Depends`ëĨŧ ė‚ŦėšŠí•Šë‹ˆë‹¤: + +=== "Python 3.10+" + + ```Python hl_lines="13 18" + {!> ../../../docs_src/dependencies/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="15 20" + {!> ../../../docs_src/dependencies/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="16 21" + {!> ../../../docs_src/dependencies/tutorial001_an.py!} + ``` + +=== "Python 3.10+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="11 16" + {!> ../../../docs_src/dependencies/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ Annotated가 ė—†ëŠ” ę˛Ŋ뚰" + + !!! 팁 + 가ëŠĨ하다면 `Annotated`가 ë‹Ŧëϰ ë˛„ė „ė„ ęļŒėžĨ합니다. + + ```Python hl_lines="15 20" + {!> ../../../docs_src/dependencies/tutorial001.py!} + ``` + +비록 `Body`, `Query` ë“ąė„ ė‚ŦėšŠí•˜ëŠ” 것ęŗŧ ę°™ė€ ë°Šė‹ėœŧ로 ė—ŦëŸŦëļ„ė˜ í•¨ėˆ˜ė˜ ë§¤ę°œëŗ€ėˆ˜ė— ėžˆëŠ” `Depends`ëĨŧ ė‚ŦėšŠí•˜ė§€ë§Œ, `Depends`는 ė•Ŋ간 다ëĨ´ę˛Œ ėž‘ë™í•Šë‹ˆë‹¤. + +`Depends`뗐 단ėŧ ë§¤ę°œëŗ€ėˆ˜ë§Œ ė „ë‹Ŧ했ėŠĩ니다. + +ė´ ë§¤ę°œëŗ€ėˆ˜ëŠ” í•¨ėˆ˜ę°™ė€ ę˛ƒė´ė–´ė•ŧ 합니다. + +ė—ŦëŸŦëļ„ė€ 링렑 **호ėļœí•˜ė§€ ė•Šė•˜ėŠĩ니다** (ëė— 괄호ëĨŧ ėš˜ė§€ ė•Šė•˜ėŠĩ니다), ë‹¨ė§€ `Depends()`뗐 ë§¤ę°œëŗ€ėˆ˜ëĄœ 넘겨 ė¤Ŧė„ ëŋėž…니다. + +꡸ëĻŦęŗ  ꡸ í•¨ėˆ˜ëŠ” *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*가 ėž‘ë™í•˜ëŠ” 것ęŗŧ ę°™ė€ ë°Šė‹ėœŧ로 ë§¤ę°œëŗ€ėˆ˜ëĨŧ 받ėŠĩ니다. + +!!! 팁 + ė—ŦëŸŦëļ„ė€ ë‹¤ėŒ ėžĨė—ė„œ í•¨ėˆ˜ëĨŧ ė œė™¸í•˜ęŗ ė„œ, "다ëĨ¸ 것들"ė´ ė–´ë–ģ枌 ė˜ėĄ´ė„ąėœŧ로 ė‚ŦėšŠë˜ëŠ”ė§€ ė•Œę˛Œ 될 ę˛ƒėž…ë‹ˆë‹¤. + +ėƒˆëĄœėš´ ėš”ė˛­ė´ ë„ė°Ší•  때마다, **FastAPI**는 ë‹¤ėŒė„ 래ëĻŦ합니다: + +* ė˜Ŧ바ëĨ¸ ë§¤ę°œëŗ€ėˆ˜ëĨŧ 氀맄 ė˜ėĄ´ė„ą("디펜더블") í•¨ėˆ˜ëĨŧ 호ėļœí•Šë‹ˆë‹¤. +* í•¨ėˆ˜ė—ė„œ 결ęŗŧëĨŧ ë°›ė•„ė˜ĩ니다. +* *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*뗐 ėžˆëŠ” ë§¤ę°œëŗ€ėˆ˜ė— ꡸ 결ęŗŧëĨŧ 할당합니다 + +```mermaid +graph TB + +common_parameters(["common_parameters"]) +read_items["/items/"] +read_users["/users/"] + +common_parameters --> read_items +common_parameters --> read_users +``` + +ė´ë ‡ę˛Œ 하면 ęŗĩėšŠ ėŊ”드ëĨŧ 한번만 ė ė–´ë„ 되늰, **FastAPI**는 *ę˛Ŋ로 ėž‘ë™*ė„ ėœ„í•´ ė´ė— 대한 호ėļœė„ 래ëĻŦ합니다. + +!!! í™•ė¸ + íŠšëŗ„í•œ í´ëž˜ėŠ¤ëĨŧ ë§Œë“¤ė§€ ė•Šė•„ë„ 되늰, ė´ëŸŦ한 것 í˜šė€ ëš„ėŠˇí•œ ėĸ…ëĨ˜ëĨŧ **FastAPI**뗐 "등록"하기 ėœ„í•´ ė–´ë–¤ 溺뗐 넘겨ėŖŧė§€ ė•Šė•„ë„ 됩니다. + + ë‹¨ėˆœížˆ `Depends`뗐 넘겨ėŖŧ기만 하면 되늰, **FastAPI**는 ë‚˜ë¨¸ė§€ëĨŧ ė–´ė°Œí• ė§€ ė•Œęŗ  ėžˆėŠĩ니다. + +## `Annotated`ė¸ ė˜ėĄ´ė„ą ęŗĩėœ í•˜ę¸° + +ėœ„ė˜ ė˜ˆė œė—ė„œ ëLJëLJ ėž‘ė€ **ėŊ”드 뤑ëŗĩ**ė´ ėžˆë‹¤ëŠ” ę˛ƒė„ ëŗ´ė•˜ė„ 겁니다. + +`common_parameters()`ė˜ėĄ´ė„ ė‚ŦėšŠí•´ė•ŧ 한다면, íƒ€ėž… ëĒ…ė‹œė™€ `Depends()`뙀 함ęģ˜ ė „ė˛´ ë§¤ę°œëŗ€ėˆ˜ëĨŧ 렁떴ė•ŧ 합니다: + +```Python +commons: Annotated[dict, Depends(common_parameters)] +``` + +í•˜ė§€ë§Œ `Annotated`ëĨŧ ė‚ŦėšŠí•˜ęŗ  ėžˆę¸°ė—, `Annotated` ę°’ė„ ëŗ€ėˆ˜ė— ė €ėžĨí•˜ęŗ  ė—ŦëŸŦ ėžĨė†Œė—ė„œ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다: + +=== "Python 3.10+" + + ```Python hl_lines="12 16 21" + {!> ../../../docs_src/dependencies/tutorial001_02_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="14 18 23" + {!> ../../../docs_src/dependencies/tutorial001_02_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="15 19 24" + {!> ../../../docs_src/dependencies/tutorial001_02_an.py!} + ``` + +!!! 팁 + ė´ëŠ” 掏렀 í‘œė¤€ íŒŒė´ėŦė´ęŗ  "type alias"ëŧęŗ  ëļ€ëĨ´ëа ė‚Ŧ다 **FastAPI**뗐 ęĩ­í•œë˜ëŠ” ę˛ƒė€ ė•„ë‹™ë‹ˆë‹¤. + + í•˜ė§€ë§Œ, `Annotated`ëĨŧ íŦ함하ė—Ŧ, **FastAPI**가 íŒŒė´ėŦ í‘œė¤€ė„ 기반ėœŧ로 í•˜ęŗ  ėžˆę¸°ė—, ė´ëĨŧ ė—ŦëŸŦëļ„ė˜ ėŊ”드 트ëĻ­ėœŧ로 ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. 😎 + +ė´ ė˜ėĄ´ė„ąė€ ęŗ„ė†í•´ė„œ ė˜ˆėƒí•œëŒ€ëĄœ ėž‘ë™í•  ę˛ƒė´ëŠ°, **렜ėŧ ėĸ‹ė€ ëļ€ëļ„**ė€ **íƒ€ėž… ė •ëŗ´ę°€ ëŗ´ėĄ´ëœë‹¤ëŠ” ę˛ƒėž…ë‹ˆë‹¤**. ėω ė—ŦëŸŦëļ„ė˜ íŽ¸ė§‘ę¸°ę°€ **ėžë™ ė™„ė„ą**, **ė¸ëŧė¸ 뗐ëŸŦ** ë“ąė„ ęŗ„ė†í•´ė„œ 렜ęŗĩ할 눘 ėžˆë‹¤ëŠ” ę˛ƒėž…ë‹ˆë‹¤. `mypy`ę°™ė€ 다ëĨ¸ 도ęĩŦ도 마ė°Ŧę°€ė§€ėž…ë‹ˆë‹¤. + +ė´ëŠ” 특히 **ë§Žė€ *ę˛Ŋ로 ėž‘ë™***ė—ė„œ **ę°™ė€ ė˜ėĄ´ė„ą**ė„ ęŗ„ė†í•´ė„œ ė‚ŦėšŠí•˜ëŠ” **거대 ėŊ”드 기반**ė•ˆė—ė„œ ė‚ŦėšŠí•˜ëŠ´ ėœ ėšŠí•  ę˛ƒėž…ë‹ˆë‹¤. + +## `async`하게, í˜šė€ `async`í•˜ė§€ ė•Šę˛Œ + +ė˜ėĄ´ė„ąė´ (*ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*ė—ė„œ 래ëŸŧ ë˜‘ę°™ė´) **FastAPI**뗐 ė˜í•´ 호ėļœë  눘 ėžˆėœŧ늰, í•¨ėˆ˜ëĨŧ ė •ė˜í•  때 동ėŧ한 ęˇœėš™ė´ ė ėšŠëŠë‹ˆë‹¤. + +`async def`ė„ ė‚ŦėšŠí•˜ęą°ë‚˜ í˜šė€ ėŧë°˜ė ė¸ `def`ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  ėŧë°˜ė ė¸ `def` *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜* ė•ˆė— `async def`로 ė˜ėĄ´ė„ąė„ ė„ ė–¸í•  눘 ėžˆėœŧ늰, `async def` *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜* ė•ˆė— `def`로 ė˜ėĄ´ė„ąė„ ė„ ė–¸í•˜ëŠ” ë“ąė˜ ë°Šë˛•ė´ ėžˆėŠĩ니다. + +ė•„ëŦ´ ëŦ¸ė œ ė—†ėŠĩ니다. **FastAPI**는 ëŦ´ė—‡ė„ í• ė§€ ė•Œęŗ  ėžˆėŠĩ니다. + +!!! 및溠 + ėž˜ ëǍëĨ´ė‹œę˛ ë‹¤ëŠ´, [Async: *"In a hurry?"*](../../async.md){.internal-link target=_blank} ëŦ¸ė„œė—ė„œ `async`뙀 `await`뗐 대해 í™•ė¸í•  눘 ėžˆėŠĩ니다. + +## OpenAPI뙀 í†ĩ합 + +ëĒ¨ë“  ėš”ė˛­ ė„ ė–¸, 검ėĻęŗŧ ė˜ėĄ´ė„ą(및 í•˜ėœ„ ė˜ėĄ´ė„ą)뗐 대한 ėš”ęĩŦ ė‚Ŧí•­ė€ 동ėŧ한 OpenAPI ėŠ¤í‚¤ë§ˆė— í†ĩ합됩니다. + +따ëŧė„œ 대화형 ëŦ¸ė„œė— ė´ëŸŦ한 ė˜ėĄ´ė„ąė— 대한 ëĒ¨ë“  ė •ëŗ´ ė—­ė‹œ íŦí•¨í•˜ęŗ  ėžˆėŠĩ니다: + + + +## 간단한 ė‚ŦėšŠë˛• + +ė´ëĨŧ ëŗ´ëŠ´, *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*는 *ę˛Ŋ로*뙀 *ėž‘ë™*ė´ ë§¤ėš­ë˜ëŠ´ ė–¸ė œë“ ė§€ ė‚ŦėšŠë˜ë„ëĄ ė •ė˜ë˜ė—ˆėœŧ늰, **FastAPI**는 ė˜Ŧ바ëĨ¸ ë§¤ę°œëŗ€ėˆ˜ëĨŧ 氀맄 í•¨ėˆ˜ëĨŧ 호ėļœí•˜ęŗ  해당 ėš”ė˛­ė—ė„œ ë°ė´í„°ëĨŧ ėļ”ėļœí•Šë‹ˆë‹¤. + +ė‚Ŧ다, ëĒ¨ë“  (í˜šė€ 대ëļ€ëļ„ė˜) ė›š í”„ë ˆėž„ė›ŒíŦ는 ė´ė™€ ę°™ė€ ë°Šė‹ėœŧ로 ėž‘ë™í•Šë‹ˆë‹¤. + +ė—ŦëŸŦëļ„ė€ ė´ëŸŦ한 í•¨ėˆ˜ë“¤ė„ ė ˆëŒ€ 링렑 호ėļœí•˜ė§€ ė•ŠėŠĩ니다. í”„ë ˆėž„ė›ŒíŦ(ė´ ę˛Ŋ뚰 **FastAPI**)뗐 ė˜í•´ 호ėļœëŠë‹ˆë‹¤. + +ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œęŗŧ 함ęģ˜ëŧ늴 **FastAPI**ė—ę˛Œ ė—ŦëŸŦëļ„ė˜ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*가 ė‹¤í–‰ë˜ę¸° 렄뗐 ė‹¤í–‰ë˜ė–´ė•ŧ 하는 ëŦ´ė–¸ę°€ė— ė—ŦëŸŦëļ„ė˜ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜* 또한 "ė˜ėĄ´"í•˜ęŗ  ėžˆėŒė„ ė•ŒëĻ´ 눘 ėžˆėœŧ늰, **FastAPI**는 ė´ëĨŧ ė‹¤í–‰í•˜ęŗ  결ęŗŧëĨŧ "ėŖŧėž…"할 ę˛ƒėž…ë‹ˆë‹¤. + +"ė˜ėĄ´ė„ą ėŖŧėž…"ė´ëŧ는 동ėŧ한 ė•„ė´ë””ė–´ė— 대한 다ëĨ¸ ėŧë°˜ė ė¸ ėšŠė–´ëŠ” ë‹¤ėŒęŗŧ 같ėŠĩ니다: + +* ëĻŦė†ŒėŠ¤ +* 렜ęŗĩėž +* ė„œëš„ėŠ¤ +* ė¸ė í„°ë¸” +* ėģ´íŦ넌트 + +## **FastAPI** 플ëŸŦęˇ¸ė¸ + +í†ĩ합ęŗŧ "플ëŸŦęˇ¸ė¸"ė€ **ė˜ėĄ´ė„ą ėŖŧėž…** ė‹œėŠ¤í…œė„ ė‚ŦėšŠí•˜ė—Ŧ ęĩŦėļ•í•  눘 ėžˆėŠĩ니다. í•˜ė§€ë§Œ ė‹¤ė œëĄœ **"플ëŸŦęˇ¸ė¸"ė„ 만들 í•„ėš”ëŠ” ė—†ėŠĩ니다**, ė™œëƒí•˜ëŠ´ ė˜ėĄ´ė„ąė„ ė‚ŦėšŠí•¨ėœŧëĄœė¨ ė—ŦëŸŦëļ„ė˜ *ę˛Ŋ로 ėž‘ë™ í•¨ėˆ˜*뗐 í†ĩ합ęŗŧ ėƒí˜¸ ėž‘ėšŠė„ ëŦ´í•œëŒ€ëĄœ ė„ ė–¸í•  눘 ėžˆę¸° 때ëŦ¸ėž…니다. + +꡸ëĻŦęŗ  "말 그대로", 掏렀 í•„ėš”ëĄœ 하는 íŒŒė´ėŦ íŒ¨í‚¤ė§€ëĨŧ ėž„íŦíŠ¸í•˜ęŗ  단 ëLJ ė¤„ė˜ ėŊ”ë“œëĄœ ė—ŦëŸŦëļ„ė˜ API í•¨ėˆ˜ė™€ í†ĩ합함ėœŧëĄœė¨, ė˜ėĄ´ė„ąė„ ė•„ėŖŧ ę°„ë‹¨í•˜ęŗ  ė§ę´€ė ė¸ 방법ėœŧ로 만들 눘 ėžˆėŠĩ니다. + +ę´€ęŗ„í˜• 및 NoSQL ë°ė´í„°ë˛ ė´ėŠ¤, ëŗ´ė•ˆ 등, ė´ė— 대한 ė˜ˆė‹œëĨŧ ë‹¤ėŒ ėžĨė—ė„œ ëŗŧ 눘 ėžˆėŠĩ니다. + +## **FastAPI** í˜¸í™˜ė„ą + +ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œė˜ ë‹¨ėˆœí•¨ė€ **FastAPI**ëĨŧ ë‹¤ėŒęŗŧ ę°™ė€ ėš”ė†Œë“¤ęŗŧ 호환할 눘 ėžˆę˛Œ 합니다: + +* ëĒ¨ë“  ę´€ęŗ„í˜• ë°ė´í„°ë˛ ė´ėŠ¤ +* NoSQL ë°ė´í„°ë˛ ė´ėŠ¤ +* 뙏ëļ€ íŒ¨í‚¤ė§€ +* 뙏ëļ€ API +* ė¸ėĻ 및 ęļŒí•œ ëļ€ė—Ŧ ė‹œėŠ¤í…œ +* API ė‚ŦėšŠ ëĒ¨ë‹ˆí„°ë§ ė‹œėŠ¤í…œ +* ė‘ë‹ĩ ë°ė´í„° ėŖŧėž… ė‹œėŠ¤í…œ +* 기타 등등. + +## ę°„íŽ¸í•˜ęŗ  강ë Ĩ하다 + +ęŗ„ė¸ĩė ė¸ ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œė€ ė •ė˜í•˜ęŗ  ė‚ŦėšŠí•˜ę¸° ė‰Ŋė§€ë§Œ, ė—Ŧė „ížˆ ë§¤ėš° 강ë Ĩ합니다. + +ė—ŦëŸŦëļ„ė€ ėŠ¤ėŠ¤ëĄœëĨŧ ė˜ėĄ´í•˜ëŠ” ė˜ėĄ´ė„ąė„ ė •ė˜í•  눘 ėžˆėŠĩ니다. + +ëė—ëŠ”, ęŗ„ė¸ĩė ė¸ 나ëŦ´ëĄœ 된 ė˜ėĄ´ė„ąė´ ë§Œë“¤ė–´ė§€ëŠ°, ꡸ëĻŦęŗ  **ė˜ėĄ´ė„ą ėŖŧėž…** ė‹œėŠ¤í…œė€ (í•˜ėœ„ ė˜ėĄ´ė„ąë„ 마ė°Ŧę°€ė§€ëĄœ) ė´ëŸŦ한 ė˜ėĄ´ė„ąë“¤ė„ 래ëĻŦí•˜ęŗ  각 ë‹¨ęŗ„ë§ˆë‹¤ 결ęŗŧëĨŧ 렜ęŗĩ합니다(ėŖŧėž…í•Šë‹ˆë‹¤). + +똈ëĨŧ 들면, ė—ŦëŸŦëļ„ė´ 4ę°œė˜ API ė—”ë“œíŦė¸íŠ¸(*ę˛Ŋ로 ėž‘ë™*)ëĨŧ 氀맀溠 ėžˆë‹¤ęŗ  í•´ë´…ė‹œë‹¤: + +* `/items/public/` +* `/items/private/` +* `/users/{user_id}/activate` +* `/items/pro/` + +꡸ ë‹¤ėŒ 氁氁뗐 대해 掏렀 ė˜ėĄ´ė„ąęŗŧ í•˜ėœ„ ė˜ėĄ´ė„ąė„ ė‚ŦėšŠí•˜ė—Ŧ 다ëĨ¸ ęļŒí•œ ėš”ęĩŦ ė‚Ŧí•­ė„ ėļ”가할 눘 ėžˆė„ 겁니다: + +```mermaid +graph TB + +current_user(["current_user"]) +active_user(["active_user"]) +admin_user(["admin_user"]) +paying_user(["paying_user"]) + +public["/items/public/"] +private["/items/private/"] +activate_user["/users/{user_id}/activate"] +pro_items["/items/pro/"] + +current_user --> active_user +active_user --> admin_user +active_user --> paying_user + +current_user --> public +active_user --> private +admin_user --> activate_user +paying_user --> pro_items +``` + +## **OpenAPI**ė™€ė˜ í†ĩ합 + +ė´ ëĒ¨ë“  ė˜ėĄ´ė„ąė€ ę°ę°ė˜ ėš”ęĩŦė‚Ŧí•­ė„ ė„ ė–¸í•˜ëŠ” ë™ė‹œė—, *ę˛Ŋ로 ėž‘ë™*뗐 ë§¤ę°œëŗ€ėˆ˜, 검ėĻ ë“ąė„ ėļ”ę°€í•Šë‹ˆë‹¤. + +**FastAPI**는 ė´ ëĒ¨ë“  ę˛ƒė„ OpenAPI ėŠ¤í‚¤ë§ˆė— ėļ”가할 ę˛ƒė´ëŠ°, ė´ëĨŧ í†ĩ해 대화형 ëŦ¸ė„œ ė‹œėŠ¤í…œė— 나타날 ę˛ƒėž…ë‹ˆë‹¤. From b110cd62a029d0672bd7bff12e81518da265d0dd Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:12:59 +0000 Subject: [PATCH 228/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a778d7fbf1..60a7ae3614 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -47,6 +47,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `/docs/ko/docs/tutorial/body.md`. PR [#11000](https://github.com/tiangolo/fastapi/pull/11000) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/schema-extra-example.md`. PR [#4065](https://github.com/tiangolo/fastapi/pull/4065) by [@luccasmmg](https://github.com/luccasmmg). * 🌐 Add Turkish translation for `docs/tr/docs/history-design-future.md`. PR [#11012](https://github.com/tiangolo/fastapi/pull/11012) by [@hasansezertasan](https://github.com/hasansezertasan). * 🌐 Add Turkish translation for `docs/tr/docs/resources/index.md`. PR [#11020](https://github.com/tiangolo/fastapi/pull/11020) by [@hasansezertasan](https://github.com/hasansezertasan). From 2ccc0ccf01d57c3ca5d6900ba0433cc089516466 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:13:27 +0000 Subject: [PATCH 229/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 60a7ae3614..a87e4d044a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -47,6 +47,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/dependencies/index.md`. PR [#10989](https://github.com/tiangolo/fastapi/pull/10989) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `/docs/ko/docs/tutorial/body.md`. PR [#11000](https://github.com/tiangolo/fastapi/pull/11000) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/schema-extra-example.md`. PR [#4065](https://github.com/tiangolo/fastapi/pull/4065) by [@luccasmmg](https://github.com/luccasmmg). * 🌐 Add Turkish translation for `docs/tr/docs/history-design-future.md`. PR [#11012](https://github.com/tiangolo/fastapi/pull/11012) by [@hasansezertasan](https://github.com/hasansezertasan). From 4c0d12497fe75a180792f75d3a944d6d33d8836b Mon Sep 17 00:00:00 2001 From: Alper Date: Sat, 27 Jan 2024 12:14:47 +0300 Subject: [PATCH 230/305] :globe_with_meridians: Add Turkish translation for `docs/tr/docs/alternatives.md` (#10502) --- docs/tr/docs/alternatives.md | 409 +++++++++++++++++++++++++++++++++++ 1 file changed, 409 insertions(+) create mode 100644 docs/tr/docs/alternatives.md diff --git a/docs/tr/docs/alternatives.md b/docs/tr/docs/alternatives.md new file mode 100644 index 0000000000..9c69503c98 --- /dev/null +++ b/docs/tr/docs/alternatives.md @@ -0,0 +1,409 @@ +# Alternatifler, İlham KaynaklarÄą ve KarÅŸÄąlaştÄąrmalar + +**FastAPI**'ya neler ilham verdi? Diğer alternatiflerle karÅŸÄąlaştÄąrÄąldığında farklarÄą neler? **FastAPI** diğer alternatiflerinden neler Ãļğrendi? + +## Giriş + +BaşkalarÄąnÄąn daha Ãļnceki çalÄąÅŸmalarÄą olmasaydÄą, **FastAPI** var olmazdÄą. + +Geçmişte oluşturulan pek çok araç **FastAPI**'a ilham kaynağı olmuştur. + +YÄąllardÄąr yeni bir framework oluşturmaktan kaÃ§ÄąnÄąyordum. BaşlangÄąÃ§ta **FastAPI**'Äąn çÃļzdÃŧğÃŧ sorunlarÄą çÃļzebilmek için pek çok farklÄą framework, eklenti ve araç kullanmayÄą denedim. + +Ancak bir noktada, geçmişteki diğer araçlardan en iyi fikirleri alarak bÃŧtÃŧn bu çÃļzÃŧmleri kapsayan, ayrÄąca bÃŧtÃŧn bunlarÄą Python'Äąn daha Ãļnce mevcut olmayan Ãļzelliklerini (Python 3.6+ ile gelen tip belirteçleri) kullanarak yapan bir şey Ãŧretmekten başka seçenek kalmamÄąÅŸtÄą. + +## Daha Önce Geliştirilen Araçlar + +### Django + +Django geniş çapta gÃŧvenilen, Python ekosistemindeki en popÃŧler web framework'ÃŧdÃŧr. Instagram gibi sistemleri geliştirmede kullanÄąlmÄąÅŸtÄąr. + +MySQL ve PostgreSQL gibi ilişkisel veritabanlarÄąyla nispeten sÄąkÄą bir şekilde bağlantÄąlÄądÄąr. Bu nedenle Couchbase, MongoDB ve Cassandra gibi NoSQL veritabanlarÄąnÄą ana veritabanÄą motoru olarak kullanmak pek de kolay değil. + +Modern Ãļn uçlarda (React, Vue.js ve Angular gibi) veya diğer sistemler (Ãļrneğin nesnelerin interneti cihazlarÄą) tarafÄąndan kullanÄąlan API'lar yerine arka uçta HTML Ãŧretmek için oluşturuldu. + +### Django REST Framework + +Django REST framework'Ãŧ, Django'nun API kabiliyetlerini arttÄąrmak için arka planda Django kullanan esnek bir araç grubu olarak oluşturuldu. + +Üstelik Mozilla, Red Hat ve Eventbrite gibi pek çok şirket tarafÄąndan kullanÄąlÄąyor. + +**Otomatik API dÃļkÃŧmantasyonu**nun ilk Ãļrneklerinden biri olduğu için, **FastAPI** arayÄąÅŸÄąna ilham veren ilk fikirlerden biri oldu. + +!!! note "Not" + Django REST Framework'Ãŧ, aynÄą zamanda **FastAPI**'Äąn dayandığı Starlette ve Uvicorn'un da yaratÄącÄąsÄą olan Tom Christie tarafÄąndan geliştirildi. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + KullanÄącÄąlar için otomatik API dÃļkÃŧmantasyonu sunan bir web arayÃŧzÃŧne sahip olmalÄą. + +### Flask + +Flask bir mikro framework olduğundan Django gibi framework'lerin aksine veritabanÄą entegrasyonu gibi Django ile gelen pek çok Ãļzelliği direkt barÄąndÄąrmaz. + +Sağladığı basitlik ve esneklik NoSQL veritabanlarÄąnÄą ana veritabanÄą sistemi olarak kullanmak gibi şeyler yapmaya olanak sağlar. + +YapÄąsÄą oldukça basit olduğundan Ãļğrenmesi de nispeten basittir, tabii dÃļkÃŧmantasyonu bazÄą noktalarda biraz teknik hale geliyor. + +AyrÄąca Django ile birlikte gelen veritabanÄą, kullanÄącÄą yÃļnetimi ve diğer pek çok Ãļzelliğe ihtiyaç duymayan uygulamalarda da yaygÄąn olarak kullanÄąlÄąyor. Ancak bu tÃŧr Ãļzelliklerin pek çoğu eklentiler ile eklenebiliyor. + +Uygulama parçalarÄąnÄąn bÃļyle ayrÄąlÄąyor oluşu ve istenilen Ãļzelliklerle genişletilebilecek bir mikro framework olmak tam da benim istediğim bir Ãļzellikti. + +Flask'Äąn basitliği gÃļz ÃļnÃŧnde bulundurulduğu zaman, API geliştirmek için iyi bir seçim gibi gÃļrÃŧnÃŧyordu. SÄąradaki şey ise Flask için bir "Django REST Framework"! + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + Gereken araçlarÄą ve parçalarÄą birleştirip eşleştirmeyi kolaylaştÄąracak bir mikro framework olmalÄą. + + Basit ve kullanmasÄą kolay bir yÃļnlendirme sistemine sahip olmalÄą. + +### Requests + +**FastAPI** aslÄąnda **Requests**'in bir alternatifi değil. İkisininde kapsamÄą oldukça farklÄą. + +AslÄąnda Requests'i bir FastAPI uygulamasÄąnÄąn *içinde* kullanmak daha olağan olurdu. + +Ama yine de, FastAPI, Requests'ten oldukça ilham aldÄą. + +**Requests**, API'lar ile bir istemci olarak *etkileşime geçmeyi* sağlayan bir kÃŧtÃŧphaneyken **FastAPI** bir sunucu olarak API'lar oluşturmaya yarar. + +Öyle ya da bÃļyle zÄąt uçlarda olmalarÄąna rağmen birbirlerini tamamlÄąyorlar. + +Requests oldukça basit ve sezgisel bir tasarÄąma sahip, kullanmasÄą da mantÄąklÄą varsayÄąlan değerlerle oldukça kolay. Ama aynÄą zamanda çok gÃŧçlÃŧ ve gayet Ãļzelleştirilebilir. + +Bu yÃŧzden resmi web sitede de sÃļylendiği gibi: + +> Requests, tÃŧm zamanlarÄąn en çok indirilen Python paketlerinden biridir. + +KullanÄąm şekli oldukça basit. Örneğin bir `GET` isteği yapmak için aşağıdaki yeterli: + +```Python +response = requests.get("http://example.com/some/url") +``` + +Bunun FastAPI'deki API *yol işlemi* şÃļyle gÃļrÃŧnÃŧr: + +```Python hl_lines="1" +@app.get("/some/url") +def read_url(): + return {"message": "Hello World!"} +``` + +`requests.get(...)` ile `@app.get(...)` arasÄąndaki benzerliklere bakÄąn. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + * Basit ve sezgisel bir API'ya sahip olmalÄą. + * HTTP metot isimlerini (işlemlerini) anlaÅŸÄąlÄąr olacak bir şekilde, direkt kullanmalÄą. + * MantÄąklÄą varsayÄąlan değerlere ve buna rağmen gÃŧçlÃŧ bir Ãļzelleştirme desteğine sahip olmalÄą. + +### Swagger / OpenAPI + +Benim Django REST Framework'Ãŧnden istediğim ana Ãļzellik otomatik API dÃļkÃŧmantasyonuydu. + +Daha sonra API'larÄą dÃļkÃŧmanlamak için Swagger adÄąnda JSON (veya JSON'un bir uzantÄąsÄą olan YAML'Äą) kullanan bir standart olduğunu buldum. + +Üstelik Swagger API'larÄą için zaten halihazÄąrda oluşturulmuş bir web arayÃŧzÃŧ vardÄą. Yani, bir API için Swagger dÃļkÃŧmantasyonu oluşturmak bu arayÃŧzÃŧ otomatik olarak kullanabilmek demekti. + +Swagger bir noktada Linux Foundation'a verildi ve adÄą OpenAPI olarak değiştirildi. + +İşte bu yÃŧzden versiyon 2.0 hakkÄąnda konuşurken "Swagger", versiyon 3 ve Ãŧzeri için ise "OpenAPI" adÄąnÄą kullanmak daha yaygÄąn. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + API spesifikasyonlarÄą için Ãļzel bir şema yerine bir aÃ§Äąk standart benimseyip kullanmalÄą. + + AyrÄąca standarda bağlÄą kullanÄącÄą arayÃŧzÃŧ araçlarÄąnÄą entegre etmeli: + + * Swagger UI + * ReDoc + + YukarÄądaki ikisi oldukça popÃŧler ve istikrarlÄą olduğu için seçildi, ancak hÄązlÄą bir araştÄąrma yaparak **FastAPI** ile kullanabileceğiniz pek çok OpenAPI alternatifi arayÃŧz bulabilirsiniz. + +### Flask REST framework'leri + +Pek çok Flask REST framework'Ãŧ var, fakat bunlarÄą biraz araştÄąrdÄąktan sonra pek çoğunun artÄąk geliştirilmediğini ve gÃļze batan bazÄą sorunlarÄąnÄąn olduğunu gÃļrdÃŧm. + +### Marshmallow + +API sistemlerine gereken ana Ãļzelliklerden biri de koddan veriyi alÄąp ağ Ãŧzerinde gÃļnderilebilecek bir şeye çevirmek, yani veri dÃļnÃŧşÃŧmÃŧ. Bu işleme veritabanÄąndaki veriyi içeren bir objeyi JSON objesine çevirmek, `datetime` objelerini metinlere çevirmek gibi Ãļrnekler verilebilir. + +API'lara gereken bir diğer bÃŧyÃŧk Ãļzellik ise veri doğrulamadÄąr, yani verinin çeşitli parametrelere bağlÄą olarak doğru ve tutarlÄą olduğundan emin olmaktÄąr. Örneğin bir alanÄąn `int` olmasÄąna karar verdiniz, daha sonra rastgele bir metin değeri almasÄąnÄą istemezsiniz. Bu Ãļzellikle sisteme dÄąÅŸarÄądan gelen veri için kullanÄąÅŸlÄą bir Ãļzellik oluyor. + +Bir veri doğrulama sistemi olmazsa bÃŧtÃŧn bu kontrolleri koda dÃļkerek kendiniz yapmak zorunda kalÄąrdÄąnÄąz. + +Marshmallow bu Ãļzellikleri sağlamak için geliştirilmişti. Benim de geçmişte oldukça sÄąk kullandığım harika bir kÃŧtÃŧphanedir. + +Ama... Python'un tip belirteçleri gelmeden Ãļnce oluşturulmuştu. Yani her şemayÄą tanÄąmlamak için Marshmallow'un sunduğu spesifik araçlarÄą ve sÄąnÄąflarÄą kullanmanÄąz gerekiyordu. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + Kod kullanarak otomatik olarak veri tipini ve veri doğrulamayÄą belirten "şemalar" tanÄąmlamalÄą. + +### Webargs + +API'larÄąn ihtiyacÄą olan bir diğer Ãļnemli Ãļzellik ise gelen isteklerdeki verileri Python objelerine ayrÄąÅŸtÄąrabilmektir. + +Webargs, Flask gibi bir kaç framework'Ãŧn Ãŧzerinde bunu sağlamak için geliştirilen bir araçtÄąr. + +Veri doğrulama için arka planda Marshmallow kullanÄąyor, hatta aynÄą geliştiriciler tarafÄąndan oluşturuldu. + +Webargs da harika bir araç ve onu da geçmişte henÃŧz **FastAPI** yokken çok kullandÄąm. + +!!! info "Bilgi" + Webargs aynÄą Marshmallow geliştirileri tarafÄąndan oluşturuldu. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + Gelen istek verisi için otomatik veri doğrulamaya sahip olmalÄą. + +### APISpec + +Marshmallow ve Webargs eklentiler olarak; veri doğrulama, ayrÄąÅŸtÄąrma ve dÃļnÃŧştÃŧrmeyi sağlÄąyor. + +Ancak dÃļkÃŧmantasyondan hala ses seda yok. Daha sonrasÄąnda ise APISpec geldi. + +APISpec pek çok framework için bir eklenti olarak kullanÄąlÄąyor (Starlette için de bir eklentisi var). + +ŞemanÄąn tanÄąmÄąnÄą yol'a istek geldiğinde çalÄąÅŸan her bir fonksiyonun dÃļkÃŧman dizesinin içine YAML formatÄąnda olacak şekilde yazÄąyorsunuz o da OpenAPI şemalarÄą Ãŧretiyor. + +Flask, Starlette, Responder ve benzerlerinde bu şekilde çalÄąÅŸÄąyor. + +Fakat sonrasÄąnda yine mikro sÃļzdizimi problemiyle karÅŸÄąlaÅŸÄąyoruz. Python metinlerinin içinde koskoca bir YAML oluyor. + +EditÃļr bu konuda pek yardÄąmcÄą olamaz. Üstelik eğer parametreleri ya da Marshmallow şemalarÄąnÄą değiştirip YAML kodunu gÃŧncellemeyi unutursak artÄąk dÃļkÃŧman geçerliliğini yitiriyor. + +!!! info "Bilgi" + APISpec de aynÄą Marshmallow geliştiricileri tarafÄąndan oluşturuldu. + +!!! check "**FastAPI**'a nasÄąl ilham verdi?" + API'lar için aÃ§Äąk standart desteği olmalÄą (OpenAPI gibi). + +### Flask-apispec + +Flask-apispec ise Webargs, Marshmallow ve APISpec'i birbirine bağlayan bir Flask eklentisi. + +Webargs ve Marshmallow'daki bilgiyi APISpec ile otomatik OpenAPI şemalarÄą Ãŧretmek için kullanÄąyor. + +Hak ettiği değeri gÃļrmeyen, harika bir araç. Piyasadaki çoğu Flask eklentisinden çok daha popÃŧler olmalÄą. Hak ettiği değeri gÃļrmÃŧyor oluşunun sebebi ise dÃļkÃŧmantasyonun çok kÄąsa ve soyut olmasÄą olabilir. + +BÃļylece Flask-apispec, Python dÃļkÃŧman dizilerine YAML gibi farklÄą bir syntax yazma sorununu çÃļzmÃŧş oldu. + +**FastAPI**'Äą geliştirene dek benim favori arka uç kombinasyonum Flask'in yanÄąnda Marshmallow ve Webargs ile birlikte Flask-apispec idi. + +Bunu kullanmak, bir kaç full-stack Flask projesi oluşturucusunun yaratÄąlmasÄąna yol açtÄą. Bunlar benim (ve bir kaç harici ekibin de) şimdiye kadar kullandığı asÄąl stackler: + +* https://github.com/tiangolo/full-stack +* https://github.com/tiangolo/full-stack-flask-couchbase +* https://github.com/tiangolo/full-stack-flask-couchdb + +AynÄą full-stack Ãŧreticiler [**FastAPI** Proje Üreticileri](project-generation.md){.internal-link target=_blank}'nin de temelini oluşturdu. + +!!! info "Bilgi" + Flask-apispec de aynÄą Marshmallow geliştiricileri tarafÄąndan Ãŧretildi. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Veri dÃļnÃŧşÃŧmÃŧ ve veri doğrulamayÄą tanÄąmlayan kodu kullanarak otomatik olarak OpenAPI şemasÄą oluşturmalÄą. + +### NestJS (and Angular) + +Bu Python teknolojisi bile değil. NestJS, Angulardan ilham almÄąÅŸ olan bir JavaScript (TypeScript) NodeJS framework'Ãŧ. + +Flask-apispec ile yapÄąlabileceklere nispeten benzeyen bir şey elde ediyor. + +Angular 2'den ilham alan, içine gÃļmÃŧlÃŧ bir bağımlÄąlÄąk enjeksiyonu sistemi var. Bildiğim diğer tÃŧm bağımlÄąlÄąk enjeksiyonu sistemlerinde olduğu gibi"bağımlÄąlÄąk"larÄą Ãļnceden kaydetmenizi gerektiriyor. BÃļylece projeyi daha detaylÄą hale getiriyor ve kod tekrarÄąnÄą da arttÄąrÄąyor. + +Parametreler TypeScript tipleri (Python tip belirteçlerine benzer) ile aÃ§Äąklandığından editÃļr desteği oldukça iyi. + +Ama TypeScript verileri kod JavaScript'e derlendikten sonra korunmadığından, bunlara dayanarak aynÄą anda veri doğrulamasÄą, veri dÃļnÃŧşÃŧmÃŧ ve dÃļkÃŧmantasyon tanÄąmlanamÄąyor. Bundan ve bazÄą tasarÄąm tercihlerinden dolayÄą veri doğrulamasÄą, dÃļnÃŧşÃŧmÃŧ ve otomatik şema Ãŧretimi için pek çok yere dekorator eklemek gerekiyor. Bu da projeyi oldukça detaylandÄąrÄąyor. + +İç içe geçen derin modelleri pek iyi işleyemiyor. Yani eğer istekteki JSON gÃļvdesi derin bir JSON objesiyse dÃŧzgÃŧn bir şekilde dÃļkÃŧmante edilip doğrulanamÄąyor. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + GÃŧzel bir editÃļr desteği için Python tiplerini kullanmalÄą. + + GÃŧçlÃŧ bir bağımlÄąlÄąk enjeksiyon sistemine sahip olmalÄą. Kod tekrarÄąnÄą minimuma indirecek bir yol bulmalÄą. + +### Sanic + +Sanic, `asyncio`'ya dayanan son derece hÄązlÄą Python kÃŧtÃŧphanelerinden biriydi. Flask'a epey benzeyecek şekilde geliştirilmişti. + +!!! note "Teknik detaylar" + İçerisinde standart Python `asyncio` dÃļngÃŧsÃŧ yerine `uvloop` kullanÄąldÄą. HÄązÄąnÄąn asÄąl kaynağı buydu. + + Uvicorn ve Starlette'e ilham kaynağı olduğu oldukça aÃ§Äąk, şu anda ikisi de aÃ§Äąk karÅŸÄąlaştÄąrmalarda Sanicten daha hÄązlÄą gÃļzÃŧkÃŧyor. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Uçuk performans sağlayacak bir yol bulmalÄą. + + Tam da bu yÃŧzden **FastAPI** Starlette'e dayanÄąyor, çÃŧnkÃŧ Starlette şu anda kullanÄąlabilir en hÄązlÄą framework. (ÃŧçÃŧncÃŧ parti karÅŸÄąlaştÄąrmalÄą testlerine gÃļre) + +### Falcon + +Falcon ise bir diğer yÃŧksek performanslÄą Python framework'Ãŧ. Minimal olacak şekilde Hug gibi diğer framework'lerin temeli olabilmek için tasarlandÄą. + +İki parametre kabul eden fonksiyonlar şeklinde tasarlandÄą, biri "istek" ve diğeri ise "cevap". Sonra isteğin çeşitli kÄąsÄąmlarÄąnÄą **okuyor**, cevaba ise bir şeyler **yazÄąyorsunuz**. Bu tasarÄąmdan dolayÄą istek parametrelerini ve gÃļvdelerini standart Python tip belirteçlerini kullanarak fonksiyon parametreleriyle belirtmek mÃŧmkÃŧn değil. + +Yani veri doğrulama, veri dÃļnÃŧştÃŧrme ve dÃļkÃŧmantasyonun hepsi kodda yer almalÄą, otomatik halledemiyoruz. Ya da Falcon Ãŧzerine bir framework olarak uygulanmalarÄą gerekiyor, aynÄą Hug'da olduğu gibi. Bu ayrÄąm Falcon'un tasarÄąmÄąndan esinlenen, istek ve cevap objelerini parametre olarak işleyen diğer kÃŧtÃŧphanelerde de yer alÄąyor. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Harika bir performans'a sahip olmanÄąn yollarÄąnÄą bulmalÄą. + + Hug ile birlikte (Hug zaten Falcon'a dayandığından) **FastAPI**'Äąn fonksiyonlarda `cevap` parametresi belirtmesinde ilham kaynağı oldu. + + FastAPI'da opsiyonel olmasÄąna rağmen, daha çok header'lar, çerezler ve alternatif durum kodlarÄą belirlemede kullanÄąlÄąyor. + +### Molten + +**FastAPI**'Äą geliştirmenin ilk aşamalarÄąnda Molten'Äą keşfettim. Pek çok ortak fikrimiz vardÄą: + +* Python'daki tip belirteçlerini baz alÄąyordu. +* Bunlara bağlÄą olarak veri doğrulamasÄą ve dÃļkÃŧmantasyon sağlÄąyordu. +* Bir bağımlÄąlÄąk enjeksiyonu sistemi vardÄą. + +Veri doğrulama, veri dÃļnÃŧştÃŧrme ve dÃļkÃŧmantasyon için Pydantic gibi bir ÃŧçÃŧncÃŧ parti kÃŧtÃŧphane kullanmÄąyor, kendi içerisinde bunlara sahip. Yani bu veri tipi tanÄąmlarÄąnÄą tekrar kullanmak pek de kolay değil. + +Biraz daha detaylÄą ayarlamalara gerek duyuyor. AyrÄąca ASGI yerine WSGI'a dayanÄąyor. Yani Uvicorn, Starlette ve Sanic gibi araçlarÄąn yÃŧksek performansÄąndan faydalanacak şekilde tasarlanmamÄąÅŸ. + +BağımlÄąlÄąk enjeksiyonu sistemi bağımlÄąlÄąklarÄąn Ãļnceden kaydedilmesini ve sonrasÄąnda belirlenen veri tiplerine gÃļre çÃļzÃŧlmesini gerektiriyor. Yani spesifik bir tip, birden fazla bileşen ile belirlenemiyor. + +Yol'lar fonksiyonun ÃŧstÃŧnde endpoint'i işleyen dekoratÃļrler yerine farklÄą yerlerde tanÄąmlanan fonksiyonlarla belirlenir. Bu Flask (ve Starlette) yerine daha çok Django'nun yaklaÅŸÄąmÄąna daha yakÄąn bir metot. Bu, kodda nispeten birbiriyle sÄąkÄą ilişkili olan şeyleri ayÄąrmaya sebep oluyor. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Model Ãļzelliklerinin "standart" değerlerini kullanarak veri tipleri için ekstra veri doğrulama koşullarÄą tanÄąmlamalÄą. Bu editÃļr desteğini geliştiriyor ve daha Ãļnceden Pydantic'te yoktu. + + Bu aslÄąnda Pydantic'in de aynÄą doğrulama stiline geçmesinde ilham kaynağı oldu. Şu anda bÃŧtÃŧn bu Ãļzellikler Pydantic'in yapÄąsÄąnda yer alÄąyor. + +### Hug + +Hug, Python tip belirteçlerini kullanarak API parametrelerinin tipini belirlemeyi uygulayan ilk framework'lerdendi. Bu, diğer araçlara da ilham kaynağı olan harika bir fikirdi. + +Tip belirlerken standart Python veri tipleri yerine kendi Ãļzel tiplerini kullandÄą, yine de bu ileriye dÃļnÃŧk devasa bir adÄąmdÄą. + +Hug ayrÄąca tÃŧm API'Äą JSON ile ifade eden Ãļzel bir şema oluşturan ilk framework'lerdendir. + +OpenAPI veya JSON ŞemasÄą gibi bir standarda bağlÄą değildi. Yani Swagger UI gibi diğer araçlarla entegre etmek kolay olmazdÄą. Ama yine de, bu oldukça yenilikçi bir fikirdi. + +AyrÄąca ilginç ve çok rastlanmayan bir Ãļzelliği vardÄą: aynÄą framework'Ãŧ kullanarak hem API'lar hem de CLI'lar oluşturmak mÃŧmkÃŧndÃŧ. + +Senkron çalÄąÅŸan Python web framework'lerinin standardÄąna (WSGI) dayandığından dolayÄą Websocket'leri ve diğer şeyleri işleyemiyor, ancak yine de yÃŧksek performansa sahip. + +!!! info "Bilgi" + Hug, Python dosyalarÄąnda bulunan dahil etme satÄąrlarÄąnÄą otomatik olarak sÄąralayan harika bir araç olan `isort`'un geliştiricisi Timothy Crosley tarafÄąndan geliştirildi. + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Hug, APIStar'Äąn çeşitli kÄąsÄąmlarÄąnda esin kaynağı oldu ve APIStar'la birlikte en umut verici bulduğum araçlardan biriydi. + + **FastAPI**, Python tip belirteçlerini kullanarak parametre belirlemede ve API'Äą otomatÄąk tanÄąmlayan bir şema Ãŧretmede de Hug'a esinlendi. + + **FastAPI**'Äąn header ve çerez tanÄąmlamak için fonksiyonlarda `response` parametresini belirtmesinde de Hug'dan ilham alÄąndÄą. + +### APIStar (<= 0.5) + +**FastAPI**'Äą geliştirmeye başlamadan hemen Ãļnce **APIStar** sunucusunu buldum. Benim aradığım şeylerin neredeyse hepsine sahipti ve harika bir tasarÄąmÄą vardÄą. + +Benim şimdiye kadar gÃļrdÃŧğÃŧm Python tip belirteçlerini kullanarak parametre ve istekler belirlemeyi uygulayan ilk framework'lerdendi (Molten ve NestJS'den Ãļnce). APIStar'Äą da aşağı yukarÄą Hug ile aynÄą zamanlarda buldum. Fakat APIStar OpenAPI standardÄąnÄą kullanÄąyordu. + +FarklÄą yerlerdeki tip belirteçlerine bağlÄą olarak otomatik veri doğrulama, veri dÃļnÃŧştÃŧrme ve OpenAPI şemasÄą oluşturma desteği sunuyordu. + +GÃļvde şema tanÄąmlarÄą Pydantic ile aynÄą Python tip belirteçlerini kullanmÄąyordu, biraz daha Marsmallow'a benziyordu. DolayÄąsÄąyla editÃļr desteği de o kadar iyi olmazdÄą ama APIStar eldeki en iyi seçenekti. + +O dÃļnemlerde karÅŸÄąlaştÄąrmalarda en iyi performansa sahipti (yalnÄązca Starlette'e kaybediyordu). + +BaşlangÄąÃ§ta otomatik API dÃļkÃŧmantasyonu sunan bir web arayÃŧzÃŧ yoktu, ama ben ona Swagger UI ekleyebileceğimi biliyordum. + +BağımlÄąlÄąk enjeksiyon sistemi vardÄą. YukarÄąda bahsettiğim diğer araçlar gibi bundaki sistem de bileşenlerin Ãļnceden kaydedilmesini gerektiriyordu. Yine de harika bir Ãļzellikti. + +GÃŧvenlik entegrasyonu olmadığından dolayÄą APIStar'Äą hiç bir zaman tam bir projede kullanamadÄąm. Bu yÃŧzden Flask-apispec'e bağlÄą full-stack proje Ãŧreticilerde sahip olduğum Ãļzellikleri tamamen değiştiremedim. Bu gÃŧvenlik entegrasyonunu ekleyen bir PR oluşturmak da projelerim arasÄąnda yer alÄąyordu. + +SonrasÄąnda ise projenin odağı değişti. + +Geliştiricinin Starlette'e odaklanmasÄą gerekince proje de artÄąk bir API web framework'Ãŧ olmayÄą bÄąraktÄą. + +ArtÄąk APIStar, OpenAPI Ãļzelliklerini doğrulamak için bir dizi araç sunan bir proje haline geldi. + +!!! info "Bilgi" + APIStar, aşağıdaki projeleri de Ãŧreten Tom Christie tarafÄąndan geliştirildi: + + * Django REST Framework + * **FastAPI**'Äąn da dayandığı Starlette + * Starlette ve **FastAPI** tarafÄąndan da kullanÄąlan Uvicorn + +!!! check "**FastAPI**'a nasÄąl ilham oldu?" + Var oldu. + + AynÄą Python veri tipleriyle birden fazla şeyi belirleme (veri doğrulama, veri dÃļnÃŧştÃŧrme ve dÃļkÃŧmantasyon), bir yandan da harika bir editÃļr desteği sunma, benim muhteşem bulduğum bir fikirdi. + + Uzunca bir sÃŧre boyunca benzer bir framework arayÄąp pek çok farklÄą alternatifi denedikten sonra, APIStar en iyi seçenekti. + + Sonra APIStar bir sunucu olmayÄą bÄąraktÄą ve Starlette oluşturuldu. Starlette, bÃļyle bir sunucu sistemi için daha iyi bir temel sunuyordu. Bu da **FastAPI**'Äąn son esin kaynağıydÄą. + + Ben bu Ãļnceki araçlardan Ãļğrendiklerime dayanarak **FastAPI**'Äąn Ãļzelliklerini arttÄąrÄąp geliştiriyor, tip desteği sistemi ve diğer kÄąsÄąmlarÄą iyileştiriyorum ancak yine de **FastAPI**'Äą APIStar'Äąn "ruhani varisi" olarak gÃļrÃŧyorum. + +## **FastAPI** TarafÄąndan KullanÄąlanlar + +### Pydantic + +Pydantic Python tip belirteçlerine dayanan; veri doğrulama, veri dÃļnÃŧştÃŧrme ve dÃļkÃŧmantasyon tanÄąmlamak (JSON Şema kullanarak) için bir kÃŧtÃŧphanedir. + +Tip belirteçleri kullanÄąyor olmasÄą onu aÅŸÄąrÄą sezgisel yapÄąyor. + +Marshmallow ile karÅŸÄąlaştÄąrÄąlabilir. Ancak karÅŸÄąlaştÄąrmalarda Marshmallowdan daha hÄązlÄą gÃļrÃŧnÃŧyor. AynÄą Python tip belirteçlerine dayanÄąyor ve editÃļr desteği de harika. + +!!! check "**FastAPI** nerede kullanÄąyor?" + BÃŧtÃŧn veri doğrulama, veri dÃļnÃŧştÃŧrme ve JSON ŞemasÄąna bağlÄą otomatik model dÃļkÃŧmantasyonunu halletmek için! + + **FastAPI** yaptığı her şeyin yanÄą sÄąra bu JSON Şema verisini alÄąp daha sonra OpenAPI'ya yerleştiriyor. + +### Starlette + +Starlette hafif bir ASGI framework'Ãŧ ve yÃŧksek performanslÄą asyncio servisleri oluşturmak için ideal. + +KullanÄąmÄą çok kolay ve sezgisel, kolaylÄąkla genişletilebilecek ve modÃŧler bileşenlere sahip olacak şekilde tasarlandÄą. + +Sahip olduğu bir kaç Ãļzellik: + +* Cidden etkileyici bir performans. +* WebSocket desteği. +* İşlem-içi arka plan gÃļrevleri. +* Başlatma ve kapatma olaylarÄą. +* HTTPX ile geliştirilmiş bir test istemcisi. +* CORS, GZip, Static Files ve Streaming cevaplarÄą desteği. +* Session ve çerez desteği. +* Kodun %100'Ãŧ test kapsamÄąnda. +* Kodun %100'Ãŧ tip belirteçleriyle desteklenmiştir. +* YalnÄązca bir kaç zorunlu bağımlÄąlığa sahip. + +Starlette şu anda test edilen en hÄązlÄą Python framework'Ãŧ. YalnÄązca bir sunucu olan Uvicorn'a yeniliyor, o da zaten bir framework değil. + +Starlette bÃŧtÃŧn temel web mikro framework işlevselliğini sağlÄąyor. + +Ancak otomatik veri doğrulama, veri dÃļnÃŧştÃŧrme ve dÃļkÃŧmantasyon sağlamyor. + +Bu, **FastAPI**'Äąn onun Ãŧzerine tamamen Python tip belirteçlerine bağlÄą olarak eklediği (Pydantic ile) ana şeylerden biri. **FastAPI** bunun yanÄąnda artÄą olarak bağımlÄąlÄąk enjeksiyonu sistemi, gÃŧvenlik araçlarÄą, OpenAPI şema Ãŧretimi ve benzeri Ãļzellikler de ekliyor. + +!!! note "Teknik Detaylar" + ASGI, Django'nun ana ekibi tarafÄąndan geliştirilen yeni bir "standart". Bir "Python standardÄą" (PEP) olma sÃŧrecinde fakat henÃŧz bir standart değil. + + Bununla birlikte, halihazÄąrda birçok araç tarafÄąndan bir "standart" olarak kullanÄąlmakta. Bu, Uvicorn'u farklÄą ASGI sunucularÄąyla (Daphne veya Hypercorn gibi) değiştirebileceğiniz veya `python-socketio` gibi ASGI ile uyumlu araçlarÄą ekleyebileciğiniz için birlikte çalÄąÅŸÄąlabilirliği bÃŧyÃŧk ÃļlçÃŧde arttÄąrÄąyor. + +!!! check "**FastAPI** nerede kullanÄąyor?" + + TÃŧm temel web kÄąsÄąmlarÄąnda Ãŧzerine Ãļzellikler eklenerek kullanÄąlmakta. + + `FastAPI` sÄąnÄąfÄąnÄąn kendisi direkt olarak `Starlette` sÄąnÄąfÄąnÄą miras alÄąyor! + + Yani, Starlette ile yapabileceğiniz her şeyi, Starlette'in bir nevi gÃŧçlendirilmiş hali olan **FastAPI** ile doğrudan yapabilirsiniz. + +### Uvicorn + +Uvicorn, uvlook ile httptools Ãŧzerine kurulu ÄąÅŸÄąk hzÄąnda bir ASGI sunucusudur. + +Bir web framework'Ãŧnden ziyade bir sunucudur, yani yollara bağlÄą yÃļnlendirme yapmanÄązÄą sağlayan araçlarÄą yoktur. Bu daha çok Starlette (ya da **FastAPI**) gibi bir framework'Ãŧn sunucuya ek olarak sağladığı bir şeydir. + +Starlette ve **FastAPI** için tavsiye edilen sunucu Uvicorndur. + +!!! check "**FastAPI** neden tavsiye ediyor?" + **FastAPI** uygulamalarÄąnÄą çalÄąÅŸtÄąrmak için ana web sunucusu Uvicorn! + + Gunicorn ile birleştirdiğinizde asenkron ve çoklu işlem destekleyen bir sunucu elde ediyorsunuz! + + Daha fazla detay için [Deployment](deployment/index.md){.internal-link target=_blank} bÃļlÃŧmÃŧnÃŧ inceleyebilirsiniz. + +## KarÅŸÄąlaştÄąrma ve HÄąz + +Uvicorn, Starlette ve FastAPI arasÄąndakÄą farkÄą daha iyi anlamak ve karÅŸÄąlaştÄąrma yapmak için [KÄąyaslamalar](benchmarks.md){.internal-link target=_blank} bÃļlÃŧmÃŧne bakÄąn! From 2f2a7ad361d2819671c1471fa15a9e5333651872 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:17:26 +0000 Subject: [PATCH 231/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a87e4d044a..6f44d597ce 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -47,6 +47,7 @@ hide: ### Translations +* :globe_with_meridians: Add Turkish translation for `docs/tr/docs/alternatives.md`. PR [#10502](https://github.com/tiangolo/fastapi/pull/10502) by [@alperiox](https://github.com/alperiox). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/dependencies/index.md`. PR [#10989](https://github.com/tiangolo/fastapi/pull/10989) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `/docs/ko/docs/tutorial/body.md`. PR [#11000](https://github.com/tiangolo/fastapi/pull/11000) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Portuguese translation for `docs/pt/docs/tutorial/schema-extra-example.md`. PR [#4065](https://github.com/tiangolo/fastapi/pull/4065) by [@luccasmmg](https://github.com/luccasmmg). From 381751499254f5060a69012cb4b4d0e2bb939004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jun-Ah=20=EC=A4=80=EC=95=84?= Date: Sat, 27 Jan 2024 18:28:49 +0900 Subject: [PATCH 232/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/background-tasks.md`=20(#5910?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/background-tasks.md | 102 ++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 docs/ko/docs/tutorial/background-tasks.md diff --git a/docs/ko/docs/tutorial/background-tasks.md b/docs/ko/docs/tutorial/background-tasks.md new file mode 100644 index 0000000000..a951ead16f --- /dev/null +++ b/docs/ko/docs/tutorial/background-tasks.md @@ -0,0 +1,102 @@ +# 밹꡸ëŧėš´ë“œ ėž‘ė—… + +FastAPIė—ė„œëŠ” ė‘ë‹ĩė„ 반환한 í›„ė— ė‹¤í–‰í•  밹꡸ëŧėš´ë“œ ėž‘ė—…ė„ ė •ė˜í•  눘 ėžˆėŠĩ니다. + +밹꡸ëŧėš´ë“œ ėž‘ė—…ė€ 클ëŧė´ė–¸íŠ¸ę°€ ė‘ë‹ĩė„ 받기 ėœ„í•´ ėž‘ė—…ė´ ė™„ëŖŒë  ë•ŒęšŒė§€ 기다ëĻ´ í•„ėš”ę°€ 뗆揰 때ëŦ¸ė— ėš”ė˛­ í›„ė— ë°œėƒí•´ė•ŧ하는 ėž‘ė—…ė— ë§¤ėš° ėœ ėšŠí•Šë‹ˆë‹¤. + +ė´ëŸŦ한 ėž‘ė—…ė—ëŠ” ë‹¤ėŒė´ íŦ함됩니다. + +* ėž‘ė—…ė„ ėˆ˜í–‰í•œ 후 ė „ė†Ąë˜ëŠ” ė´ëŠ”ėŧ ė•ŒëĻŧ + * ė´ëŠ”ėŧ ė„œë˛„ė— ė—°ę˛°í•˜ęŗ  ė´ëŠ”ėŧė„ ė „ė†Ąí•˜ëŠ” ę˛ƒė€ (ëLJ 봈 ė •ë„) "느ëϰ" ę˛Ŋí–Ĩė´ ėžˆėœŧë¯€ëĄœ, ė‘ë‹ĩė€ ėĻ‰ė‹œ ë°˜í™˜í•˜ęŗ  ė´ëŠ”ėŧ ė•ŒëĻŧė€ 밹꡸ëŧėš´ë“œė—ė„œ ė „ė†Ąí•˜ëŠ” 枌 가ëŠĨ합니다. +* ë°ė´í„° 래ëĻŦ: + * 똈ëĨŧ ë“¤ė–´ 래ëĻŦ뗐 ė˜¤ëžœ ė‹œę°„ė´ 깸ëĻŦ는 ë°ė´í„°ëĨŧ ë°›ė•˜ė„ 때 "Accepted" (HTTP 202)ė„ ë°˜í™˜í•˜ęŗ , 밹꡸ëŧėš´ë“œė—ė„œ ë°ė´í„°ëĨŧ 래ëĻŦ할 눘 ėžˆėŠĩ니다. + +## `밹꡸ëŧėš´ë“œ ėž‘ė—…` ė‚ŦėšŠ + +ë¨ŧė € ė•„ëž˜ė™€ ę°™ė´ `BackgroundTasks`ëĨŧ ėž„íŦíŠ¸í•˜ęŗ , `BackgroundTasks`ëĨŧ _ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_ ė—ė„œ ë§¤ę°œëŗ€ėˆ˜ëĄœ ę°€ė ¸ė˜¤ęŗ  ė •ė˜í•Šë‹ˆë‹¤. + +```Python hl_lines="1 13" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +**FastAPI** 는 `BackgroundTasks` 氜랴ëĨŧ ėƒė„ąí•˜ęŗ , 매개 ëŗ€ėˆ˜ëĄœ ė „ë‹Ŧ합니다. + +## ėž‘ė—… í•¨ėˆ˜ ėƒė„ą + +밹꡸ëŧėš´ë“œ ėž‘ė—…ėœŧ로 ė‹¤í–‰í•  í•¨ėˆ˜ëĨŧ ė •ė˜í•Šë‹ˆë‹¤. + +ė´ę˛ƒė€ ë‹¨ėˆœížˆ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ë°›ė„ 눘 ėžˆëŠ” í‘œė¤€ í•¨ėˆ˜ėŧ ëŋėž…니다. + +**FastAPI**는 ė´ę˛ƒė´ `async def` í•¨ėˆ˜ė´ë“ , ėŧ반 `def` í•¨ėˆ˜ė´ë“  내ëļ€ė ėœŧ로 ė´ëĨŧ ė˜Ŧ바ëĨ´ę˛Œ 래ëĻŦ합니다. + +ė´ ę˛Ŋ뚰, ė•„ëž˜ ėž‘ė—…ė€ 파ėŧ뗐 ė“°ëŠ” í•¨ėˆ˜ėž…ë‹ˆë‹¤. (ė´ëŠ”ėŧ ëŗ´ë‚´ę¸° ė‹œëŦŧë ˆė´ė…˜) + +꡸ëĻŦęŗ  ė´ ėž‘ė—…ė€ `async`뙀 `await`ëĨŧ ė‚ŦėšŠí•˜ė§€ ė•Šėœŧë¯€ëĄœ ėŧ반 `def` í•¨ėˆ˜ëĄœ ė„ ė–¸í•Šë‹ˆë‹¤. + +```Python hl_lines="6-9" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +## 밹꡸ëŧėš´ë“œ ėž‘ė—… ėļ”ę°€ + +_ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_ ë‚´ė—ė„œ ėž‘ė—… í•¨ėˆ˜ëĨŧ `.add_task()` í•¨ėˆ˜ í†ĩ해 _밹꡸ëŧėš´ë“œ ėž‘ė—…_ ę°œė˛´ė— ė „ë‹Ŧ합니다. + +```Python hl_lines="14" +{!../../../docs_src/background_tasks/tutorial001.py!} +``` + +`.add_task()` í•¨ėˆ˜ëŠ” ë‹¤ėŒęŗŧ ę°™ė€ ė¸ėžëĨŧ 받ėŠĩ니다 : + +- 밹꡸ëŧėš´ë“œė—ė„œ ė‹¤í–‰ë˜ëŠ” ėž‘ė—… í•¨ėˆ˜ (`write_notification`). +- ėž‘ė—… í•¨ėˆ˜ė— ėˆœė„œëŒ€ëĄœ ė „ë‹Ŧë˜ė–´ė•ŧ 하는 ėŧë ¨ė˜ ė¸ėž (`email`). +- ėž‘ė—… í•¨ėˆ˜ė— ė „ë‹Ŧë˜ė–´ė•ŧ하는 ëĒ¨ë“  í‚¤ė›Œë“œ ė¸ėž (`message="some notification"`). + +## ė˜ėĄ´ė„ą ėŖŧėž… + +`BackgroundTasks`ëĨŧ ė˜ėĄ´ė„ą ėŖŧėž… ė‹œėŠ¤í…œęŗŧ 함ęģ˜ ė‚ŦėšŠí•˜ëŠ´ _ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_, ėĸ…ė†ė„ą, í•˜ėœ„ ėĸ…ė†ė„ą 등 ė—ŦëŸŦ ėˆ˜ė¤€ė—ė„œ BackgroundTasks ėœ í˜•ė˜ ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė„ ė–¸í•  눘 ėžˆėŠĩ니다. + +**FastAPI**는 각 ę˛Ŋėš°ė— ėˆ˜í–‰í•  ėž‘ė—…ęŗŧ 동ėŧ한 氜랴ëĨŧ 내ëļ€ė ėœŧ로 ėžŦė‚ŦėšŠí•˜ę¸°ė—, ëĒ¨ë“  밹꡸ëŧėš´ë“œ ėž‘ė—…ė´ 함ęģ˜ ëŗ‘í•Šë˜ęŗ  ë‚˜ė¤‘ė— 밹꡸ëŧėš´ë“œė—ė„œ ė‹¤í–‰ëŠë‹ˆë‹¤. + +=== "Python 3.6 and above" + + ```Python hl_lines="13 15 22 25" + {!> ../../../docs_src/background_tasks/tutorial002.py!} + ``` + +=== "Python 3.10 and above" + + ```Python hl_lines="11 13 20 23" + {!> ../../../docs_src/background_tasks/tutorial002_py310.py!} + ``` + +ė´ ė˜ˆė œė—ė„œëŠ” ė‘ë‹ĩė´ 반환된 í›„ė— `log.txt` 파ėŧ뗐 ëŠ”ė‹œė§€ę°€ 기록됩니다. + +ėš”ė˛­ė— ėŋŧëĻŦ가 ėžˆëŠ” ę˛Ŋ뚰 밹꡸ëŧėš´ë“œ ėž‘ė—…ė˜ ëĄœęˇ¸ė— 기록됩니다. + +꡸ëĻŦęŗ  _ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_ ė—ė„œ ėƒė„ąëœ 또 다ëĨ¸ 밹꡸ëŧėš´ë“œ ėž‘ė—…ė€ ę˛Ŋ로 매개 ëŗ€ėˆ˜ëĨŧ í™œėšŠí•˜ė—Ŧ ė‚ŦėšŠí•˜ė—Ŧ ëŠ”ė‹œė§€ëĨŧ ėž‘ė„ąí•Šë‹ˆë‹¤. + +## 揰눠렁 넏ëļ€ė‚Ŧ항 + +`BackgroundTasks` í´ëž˜ėŠ¤ëŠ” `starlette.background`ė—ė„œ 링렑 氀렏ė˜ĩ니다. + +`BackgroundTasks` í´ëž˜ėŠ¤ëŠ” FastAPIė—ė„œ 링렑 ėž„íŦ트하거나 íŦ함하기 때ëŦ¸ė— ė‹¤ėˆ˜ëĄœ `BackgroundTask` (ëė— `s`가 ė—†ėŒ)ė„ ėž„íŦ트하더ëŧ도 starlette.backgroundė—ė„œ `BackgroundTask`ëĨŧ ę°€ė ¸ė˜¤ëŠ” ę˛ƒė„ ë°Šė§€í•  눘 ėžˆėŠĩ니다. + +(`BackgroundTask`가 ė•„ë‹Œ) `BackgroundTasks`ëĨŧ ė‚ŦėšŠí•˜ëŠ´, _ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_ ë§¤ę°œëŗ€ėˆ˜ëĄœ ė‚ŦėšŠí•  눘 ėžˆę˛Œ ë˜ęŗ  ë‚˜ë¨¸ė§€ëŠ” **FastAPI**가 ëŒ€ė‹  래ëĻŦ하도록 할 눘 ėžˆėŠĩ니다. ė´ę˛ƒė€ `Request` ę°ė˛´ëĨŧ 링렑 ė‚ŦėšŠí•˜ëŠ” 것ęŗŧ ę°™ė€ ë°Šė‹ėž…ë‹ˆë‹¤. + +FastAPIė—ė„œ `BackgroundTask`ëĨŧ 단독ėœŧ로 ė‚ŦėšŠí•˜ëŠ” ę˛ƒė€ ė—Ŧė „ížˆ 가ëŠĨ합니다. í•˜ė§€ë§Œ ę°ė˛´ëĨŧ ėŊ”ë“œė—ė„œ ėƒė„ąí•˜ęŗ , ė´ ę°ė˛´ëĨŧ íŦ함하는 Starlette `Response`ëĨŧ 반환해ė•ŧ 합니다. + +`Starletteė˜ ęŗĩė‹ ëŦ¸ė„œ`ė—ė„œ 밹꡸ëŧėš´ë“œ ėž‘ė—…ė— 대한 ėžė„¸í•œ ë‚´ėšŠė„ í™•ė¸í•  눘 ėžˆėŠĩ니다. + +## ę˛Ŋęŗ  + +만ė•Ŋ ëŦ´ęą°ėš´ 밹꡸ëŧėš´ë“œ ėž‘ė—…ė„ ėˆ˜í–‰í•´ė•ŧí•˜ęŗ  동ėŧ한 í”„ëĄœė„¸ėŠ¤ė—ė„œ ė‹¤í–‰í•  í•„ėš”ę°€ ė—†ëŠ” ę˛Ŋ뚰 (똈: 메ëǍëĻŦ, ëŗ€ėˆ˜ ë“ąė„ ęŗĩėœ í•  í•„ėš”ę°€ ė—†ėŒ) `Celery`뙀 ę°™ė€ 큰 도ęĩŦëĨŧ ė‚ŦėšŠí•˜ëŠ´ ë„ė›€ė´ 될 눘 ėžˆėŠĩ니다. + +RabbitMQ 또는 Redis뙀 ę°™ė€ ëŠ”ė‹œė§€/ėž‘ė—… 큐 ė‹œėŠ¤í…œ ëŗ´ë‹¤ ëŗĩėžĄí•œ ęĩŦė„ąė´ í•„ėš”í•œ ę˛Ŋí–Ĩė´ ėžˆė§€ë§Œ, ė—ŦëŸŦ ėž‘ė—… í”„ëĄœė„¸ėŠ¤ëĨŧ 특히 ė—ŦëŸŦ ė„œë˛„ė˜ 밹꡸ëŧėš´ë“œė—ė„œ ė‹¤í–‰í•  눘 ėžˆėŠĩ니다. + +똈렜ëĨŧ ëŗ´ė‹œë ¤ëŠ´ [í”„ëĄœė íŠ¸ ėƒė„ąę¸°](../project-generation.md){.internal-link target=\_blank} ëĨŧ ė°¸ęŗ í•˜ė„¸ėš”. 해당 ė˜ˆė œė—ëŠ” ė´ë¯¸ ęĩŦė„ąëœ `Celery`가 íŦí•¨ë˜ė–´ ėžˆėŠĩ니다. + +꡸ëŸŦ나 동ėŧ한 FastAPI ė•ąė—ė„œ ëŗ€ėˆ˜ 및 ę°œė˛´ė— ė ‘ęˇŧ해ė•ŧ햐는 ėž‘ė€ 밹꡸ëŧėš´ë“œ ėˆ˜í–‰ė´ í•„ėš”í•œ ę˛Ŋ뚰 (똈 : ė•ŒëĻŧ ė´ëŠ”ėŧ ëŗ´ë‚´ę¸°) 간단하게 `BackgroundTasks`ëĨŧ ė‚ŦėšŠí•´ëŗ´ė„¸ėš”. + +## ėš”ė•Ŋ + +밹꡸ëŧėš´ë“œ ėž‘ė—…ė„ ėļ”ę°€í•˜ę¸° ėœ„í•´ _ę˛Ŋ로 ë™ėž‘ í•¨ėˆ˜_ 뗐 ë§¤ę°œëŗ€ėˆ˜ëĄœ `BackgroundTasks`ëĨŧ ę°€ė ¸ė˜¤ęŗ  ė‚ŦėšŠí•Šë‹ˆë‹¤. From a67f9767a0d651bc296cda221c4c6685cbdeca6d Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:30:03 +0000 Subject: [PATCH 233/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6f44d597ce..88db92d51c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -47,6 +47,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/background-tasks.md`. PR [#5910](https://github.com/tiangolo/fastapi/pull/5910) by [@junah201](https://github.com/junah201). * :globe_with_meridians: Add Turkish translation for `docs/tr/docs/alternatives.md`. PR [#10502](https://github.com/tiangolo/fastapi/pull/10502) by [@alperiox](https://github.com/alperiox). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/dependencies/index.md`. PR [#10989](https://github.com/tiangolo/fastapi/pull/10989) by [@KaniKim](https://github.com/KaniKim). * 🌐 Add Korean translation for `/docs/ko/docs/tutorial/body.md`. PR [#11000](https://github.com/tiangolo/fastapi/pull/11000) by [@KaniKim](https://github.com/KaniKim). From d522cdcb7a9762acaf03b25dc1fa2e500751c228 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sat, 27 Jan 2024 10:39:50 +0100 Subject: [PATCH 234/305] =?UTF-8?q?=F0=9F=93=9D=20Tweak=20docs=20for=20Beh?= =?UTF-8?q?ind=20a=20Proxy=20(#11038)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/advanced/behind-a-proxy.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/en/docs/advanced/behind-a-proxy.md b/docs/en/docs/advanced/behind-a-proxy.md index 01998cc912..4da2ddefc4 100644 --- a/docs/en/docs/advanced/behind-a-proxy.md +++ b/docs/en/docs/advanced/behind-a-proxy.md @@ -18,7 +18,11 @@ In this case, the original path `/app` would actually be served at `/api/v1/app` Even though all your code is written assuming there's just `/app`. -And the proxy would be **"stripping"** the **path prefix** on the fly before transmitting the request to Uvicorn, keep your application convinced that it is serving at `/app`, so that you don't have to update all your code to include the prefix `/api/v1`. +```Python hl_lines="6" +{!../../../docs_src/behind_a_proxy/tutorial001.py!} +``` + +And the proxy would be **"stripping"** the **path prefix** on the fly before transmitting the request to Uvicorn, keeping your application convinced that it is being served at `/app`, so that you don't have to update all your code to include the prefix `/api/v1`. Up to here, everything would work as normally. From 44645f882f02e98c6cb4e6d88ba035ab2966125a Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 09:40:14 +0000 Subject: [PATCH 235/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 88db92d51c..ab5e6a425d 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Tweak docs for Behind a Proxy. PR [#11038](https://github.com/tiangolo/fastapi/pull/11038) by [@tiangolo](https://github.com/tiangolo). * 📝 Add External Link: 10 Tips for adding SQLAlchemy to FastAPI. PR [#11036](https://github.com/tiangolo/fastapi/pull/11036) by [@Donnype](https://github.com/Donnype). * 📝 Add External Link: Tips on migrating from Flask to FastAPI and vice-versa. PR [#11029](https://github.com/tiangolo/fastapi/pull/11029) by [@jtemporal](https://github.com/jtemporal). * 📝 Deprecate old tutorials: Peewee, Couchbase, encode/databases. PR [#10979](https://github.com/tiangolo/fastapi/pull/10979) by [@tiangolo](https://github.com/tiangolo). From 23fc06dab919c9067f0f1970f18fb25345030801 Mon Sep 17 00:00:00 2001 From: pablocm83 Date: Sat, 27 Jan 2024 05:43:44 -0500 Subject: [PATCH 236/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Spanish=20translat?= =?UTF-8?q?ion=20for=20`docs/es/docs/newsletter.md`=20(#10922)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/es/docs/newsletter.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/es/docs/newsletter.md diff --git a/docs/es/docs/newsletter.md b/docs/es/docs/newsletter.md new file mode 100644 index 0000000000..f4dcfe155c --- /dev/null +++ b/docs/es/docs/newsletter.md @@ -0,0 +1,5 @@ +# Boletín de Noticias de FastAPI y amigos + + + + From f4e2b6f451a0e7be73aa35bc95a0fae91041532e Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 10:44:06 +0000 Subject: [PATCH 237/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index ab5e6a425d..0759535bc0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -48,6 +48,7 @@ hide: ### Translations +* 🌐 Add Spanish translation for `docs/es/docs/newsletter.md`. PR [#10922](https://github.com/tiangolo/fastapi/pull/10922) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/background-tasks.md`. PR [#5910](https://github.com/tiangolo/fastapi/pull/5910) by [@junah201](https://github.com/junah201). * :globe_with_meridians: Add Turkish translation for `docs/tr/docs/alternatives.md`. PR [#10502](https://github.com/tiangolo/fastapi/pull/10502) by [@alperiox](https://github.com/alperiox). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/dependencies/index.md`. PR [#10989](https://github.com/tiangolo/fastapi/pull/10989) by [@KaniKim](https://github.com/KaniKim). From 4b8c822c922d9d353238b5210b25bebb1e9e9252 Mon Sep 17 00:00:00 2001 From: pablocm83 Date: Sat, 27 Jan 2024 05:51:32 -0500 Subject: [PATCH 238/305] =?UTF-8?q?=F0=9F=8C=90=20Update=20Spanish=20trans?= =?UTF-8?q?lation=20for=20`docs/es/docs/features.md`=20(#10884)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/es/docs/features.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/docs/es/docs/features.md b/docs/es/docs/features.md index d68791d635..1496628d1a 100644 --- a/docs/es/docs/features.md +++ b/docs/es/docs/features.md @@ -1,3 +1,8 @@ +--- +hide: + - navigation +--- + # Características ## Características de FastAPI @@ -164,7 +169,6 @@ Con **FastAPI** obtienes todas las características de **Starlette** (porque Fas * DesempeÃąo realmente impresionante. Es uno de los frameworks de Python mÃĄs rÃĄpidos, a la par con **NodeJS** y **Go**. * Soporte para **WebSocket**. -* Soporte para **GraphQL**. * Tareas en background. * Eventos de startup y shutdown. * Cliente de pruebas construido con HTTPX. @@ -190,8 +194,6 @@ Con **FastAPI** obtienes todas las características de **Pydantic** (dado que Fa * Si sabes tipos de Python, sabes cÃŗmo usar Pydantic. * InteractÃēa bien con tu **IDE/linter/cerebro**: * Porque las estructuras de datos de Pydantic son solo instances de clases que tu defines, el auto-completado, el linting, mypy y tu intuiciÃŗn deberían funcionar bien con tus datos validados. -* **RÃĄpido**: - * En benchmarks Pydantic es mÃĄs rÃĄpido que todas las otras libraries probadas. * Valida **estructuras complejas**: * Usa modelos jerÃĄrquicos de modelos de Pydantic, `typing` de Python, `List` y `Dict`, etc. * Los validadores tambiÊn permiten que se definan fÃĄcil y claramente schemas complejos de datos. Estos son chequeados y documentados como JSON Schema. From 8602873d1aefafc66ff69fb6df08d13549b7ce7f Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 27 Jan 2024 10:51:51 +0000 Subject: [PATCH 239/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0759535bc0..2277843e09 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -48,6 +48,7 @@ hide: ### Translations +* 🌐 Update Spanish translation for `docs/es/docs/features.md`. PR [#10884](https://github.com/tiangolo/fastapi/pull/10884) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Spanish translation for `docs/es/docs/newsletter.md`. PR [#10922](https://github.com/tiangolo/fastapi/pull/10922) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/background-tasks.md`. PR [#5910](https://github.com/tiangolo/fastapi/pull/5910) by [@junah201](https://github.com/junah201). * :globe_with_meridians: Add Turkish translation for `docs/tr/docs/alternatives.md`. PR [#10502](https://github.com/tiangolo/fastapi/pull/10502) by [@alperiox](https://github.com/alperiox). From 3b18f1bfc1069e5353c5dcbd6ba9c22063711fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 28 Jan 2024 10:53:45 +0100 Subject: [PATCH 240/305] =?UTF-8?q?=F0=9F=92=84=20Fix=20CSS=20breaking=20R?= =?UTF-8?q?TL=20languages=20(erroneously=20introduced=20by=20a=20previous?= =?UTF-8?q?=20RTL=20PR)=20(#11039)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/css/custom.css | 4 ---- 1 file changed, 4 deletions(-) diff --git a/docs/en/docs/css/custom.css b/docs/en/docs/css/custom.css index 187040792b..386aa9d7e7 100644 --- a/docs/en/docs/css/custom.css +++ b/docs/en/docs/css/custom.css @@ -136,10 +136,6 @@ code { display: inline-block; } -.md-content__inner h1 { - direction: ltr !important; -} - .illustration { margin-top: 2em; margin-bottom: 2em; From 04de371a3acf82a2434209c32225332bfca82978 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 09:54:03 +0000 Subject: [PATCH 241/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2277843e09..2b443bb796 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -123,6 +123,7 @@ hide: ### Internal +* 💄 Fix CSS breaking RTL languages (erroneously introduced by a previous RTL PR). PR [#11039](https://github.com/tiangolo/fastapi/pull/11039) by [@tiangolo](https://github.com/tiangolo). * 🔧 Add Italian to `mkdocs.yml`. PR [#11016](https://github.com/tiangolo/fastapi/pull/11016) by [@alejsdev](https://github.com/alejsdev). * 🔨 Verify `mkdocs.yml` languages in CI, update `docs.py`. PR [#11009](https://github.com/tiangolo/fastapi/pull/11009) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update config in `label-approved.yml` to accept translations with 1 reviewer. PR [#11007](https://github.com/tiangolo/fastapi/pull/11007) by [@alejsdev](https://github.com/alejsdev). From c7111f67ec75fc9e1b8f5bddbbb97191404a26c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 28 Jan 2024 11:33:07 +0100 Subject: [PATCH 242/305] =?UTF-8?q?=F0=9F=93=9D=20Tweak=20wording=20in=20`?= =?UTF-8?q?help-fastapi.md`=20(#11040)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/help-fastapi.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/docs/help-fastapi.md b/docs/en/docs/help-fastapi.md index 71c5804097..095fc8c586 100644 --- a/docs/en/docs/help-fastapi.md +++ b/docs/en/docs/help-fastapi.md @@ -51,7 +51,7 @@ You can: * Tell me how you use FastAPI (I love to hear that). * Hear when I make announcements or release new tools. * You can also follow @fastapi on Twitter (a separate account). -* Connect with me on **Linkedin**. +* Follow me on **Linkedin**. * Hear when I make announcements or release new tools (although I use Twitter more often 🤷‍♂). * Read what I write (or follow me) on **Dev.to** or **Medium**. * Read other ideas, articles, and read about tools I have created. From 9fd7aa8abe9d8b0deb25f4014a19e547711d4bb6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 10:33:29 +0000 Subject: [PATCH 243/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2b443bb796..251e16e4c3 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -22,6 +22,7 @@ hide: ### Docs +* 📝 Tweak wording in `help-fastapi.md`. PR [#11040](https://github.com/tiangolo/fastapi/pull/11040) by [@tiangolo](https://github.com/tiangolo). * 📝 Tweak docs for Behind a Proxy. PR [#11038](https://github.com/tiangolo/fastapi/pull/11038) by [@tiangolo](https://github.com/tiangolo). * 📝 Add External Link: 10 Tips for adding SQLAlchemy to FastAPI. PR [#11036](https://github.com/tiangolo/fastapi/pull/11036) by [@Donnype](https://github.com/Donnype). * 📝 Add External Link: Tips on migrating from Flask to FastAPI and vice-versa. PR [#11029](https://github.com/tiangolo/fastapi/pull/11029) by [@jtemporal](https://github.com/jtemporal). From 4d93299a57f3552b6c338169f3869212ed89bc9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Sun, 28 Jan 2024 11:38:34 +0100 Subject: [PATCH 244/305] =?UTF-8?q?=F0=9F=94=A7=20Update=20sponsors,=20rem?= =?UTF-8?q?ove=20Deta=20(#11041)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 - docs/en/data/sponsors.yml | 3 --- docs/en/docs/deployment/cloud.md | 1 - docs/ko/docs/deployment/cloud.md | 1 - docs/zh/docs/deployment/cloud.md | 1 - 5 files changed, 7 deletions(-) diff --git a/README.md b/README.md index 2df5cba0bd..764cd5a36f 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,6 @@ The key features are: - diff --git a/docs/en/data/sponsors.yml b/docs/en/data/sponsors.yml index 121a3b7616..bd5b86e444 100644 --- a/docs/en/data/sponsors.yml +++ b/docs/en/data/sponsors.yml @@ -21,9 +21,6 @@ gold: title: Auth, user management and more for your B2B product img: https://fastapi.tiangolo.com/img/sponsors/propelauth.png silver: - - url: https://www.deta.sh/?ref=fastapi - title: The launchpad for all your (team's) ideas - img: https://fastapi.tiangolo.com/img/sponsors/deta.svg - url: https://training.talkpython.fm/fastapi-courses title: FastAPI video courses on demand from people you trust img: https://fastapi.tiangolo.com/img/sponsors/talkpython.png diff --git a/docs/en/docs/deployment/cloud.md b/docs/en/docs/deployment/cloud.md index b2836aeb49..29f0ad1f6f 100644 --- a/docs/en/docs/deployment/cloud.md +++ b/docs/en/docs/deployment/cloud.md @@ -14,4 +14,3 @@ You might want to try their services and follow their guides: * Platform.sh * Porter -* Deta diff --git a/docs/ko/docs/deployment/cloud.md b/docs/ko/docs/deployment/cloud.md index f2b965a911..2d6938e200 100644 --- a/docs/ko/docs/deployment/cloud.md +++ b/docs/ko/docs/deployment/cloud.md @@ -14,4 +14,3 @@ * Platform.sh * Porter -* Deta diff --git a/docs/zh/docs/deployment/cloud.md b/docs/zh/docs/deployment/cloud.md index 398f613728..b086b7b6b8 100644 --- a/docs/zh/docs/deployment/cloud.md +++ b/docs/zh/docs/deployment/cloud.md @@ -14,4 +14,3 @@ * Platform.sh * Porter -* Deta From 52df4d0378859404eca24910a59b088f1a7af6ea Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 10:38:55 +0000 Subject: [PATCH 245/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 251e16e4c3..43c7ec2445 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -124,6 +124,7 @@ hide: ### Internal +* 🔧 Update sponsors, remove Deta. PR [#11041](https://github.com/tiangolo/fastapi/pull/11041) by [@tiangolo](https://github.com/tiangolo). * 💄 Fix CSS breaking RTL languages (erroneously introduced by a previous RTL PR). PR [#11039](https://github.com/tiangolo/fastapi/pull/11039) by [@tiangolo](https://github.com/tiangolo). * 🔧 Add Italian to `mkdocs.yml`. PR [#11016](https://github.com/tiangolo/fastapi/pull/11016) by [@alejsdev](https://github.com/alejsdev). * 🔨 Verify `mkdocs.yml` languages in CI, update `docs.py`. PR [#11009](https://github.com/tiangolo/fastapi/pull/11009) by [@tiangolo](https://github.com/tiangolo). From 38f8181fdc2796c7499f77da11ebf3849c1fe9d9 Mon Sep 17 00:00:00 2001 From: xzmeng Date: Mon, 29 Jan 2024 02:00:42 +0800 Subject: [PATCH 246/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/deployment/docker.md`=20(#10296)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/deployment/docker.md | 728 ++++++++++++++++++++++++++++++ 1 file changed, 728 insertions(+) create mode 100644 docs/zh/docs/deployment/docker.md diff --git a/docs/zh/docs/deployment/docker.md b/docs/zh/docs/deployment/docker.md new file mode 100644 index 0000000000..0f89067041 --- /dev/null +++ b/docs/zh/docs/deployment/docker.md @@ -0,0 +1,728 @@ +# åŽšå™¨ä¸­įš„ FastAPI - Docker + +部įŊ˛ FastAPI åē”ᔍፋåēæ—ļīŧŒå¸¸č§įš„æ–šæŗ•æ˜¯æž„åģē **Linux 厚器镜像**。 通常äŊŋᔍ **Docker** 厌成。 į„ļ后īŧŒäŊ å¯äģĨ通čŋ‡å‡ į§å¯čƒŊįš„æ–šåŧäš‹ä¸€éƒ¨įŊ˛č¯Ĩ厚器镜像。 + +äŊŋᔍ Linux 厚器有几ä¸Ēäŧ˜į‚šīŧŒåŒ…æ‹Ŧ**厉全性**、**可复åˆļ性**、**įŽ€å•æ€§**į­‰ã€‚ + +!!! tip + čĩļæ—ļ间åšļ䏔厞įģįŸĨ道čŋ™äē›ä¸œčĨŋäē†īŧŸ 莺čŊŦ到下éĸįš„ [`Dockerfile` 👇](#ä¸ē-fastapi-构åģē-docker-镜像)。 + + +
+Dockerfile Preview 👀 + +```Dockerfile +FROM python:3.9 + +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +COPY ./app /code/app + +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] + +# If running behind a proxy like Nginx or Traefik add --proxy-headers +# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80", "--proxy-headers"] +``` + +
+ +## äģ€äšˆæ˜¯åŽšå™¨ + +厚器īŧˆä¸ģčĻæ˜¯ Linux 厚器īŧ‰æ˜¯ä¸€į§éžå¸¸**čŊģ量įē§**įš„æ‰“åŒ…åē”ᔍፋåēįš„æ–šåŧīŧŒå…ļ包æ‹Ŧ所有䞝čĩ–éĄšå’Œåŋ…čĻįš„æ–‡äģļīŧŒåŒæ—ļ厃äģŦ可äģĨ和同一įŗģįģŸä¸­įš„å…ļäģ–厚器īŧˆæˆ–者å…ļäģ–åē”ᔍፋåē/įģ„äģļīŧ‰į›¸äē’éš”įĻģ。 + +Linux 厚器äŊŋᔍåŽŋä¸ģæœēīŧˆåĻ‚į‰Šį†æœåŠĄå™¨ã€č™šæ‹Ÿæœē、ä瑿œåŠĄå™¨į­‰īŧ‰įš„Linux 内核čŋčĄŒã€‚ čŋ™æ„å‘ŗį€åރäģŦ非常čŊģ量īŧˆä¸Žæ¨Ąæ‹Ÿæ•´ä¸Ē操äŊœįŗģįģŸįš„åŽŒæ•´č™šæ‹Ÿæœēį›¸æ¯”īŧ‰ã€‚ + +通čŋ‡čŋ™æ ˇįš„æ–šåŧīŧŒåŽšå™¨æļˆč€—**åžˆå°‘įš„čĩ„æē**īŧŒä¸Žį›´æŽĨčŋčĄŒčŋ›į¨‹į›¸åŊ“īŧˆč™šæ‹Ÿæœēäŧšæļˆč€—更多īŧ‰ã€‚ + +åŽšå™¨įš„čŋ›į¨‹īŧˆé€šå¸¸åĒ有一ä¸Ēīŧ‰ã€æ–‡äģļįŗģįģŸå’ŒįŊ‘įģœéƒŊčŋčĄŒåœ¨éš”įĻģįš„įŽ¯åĸƒīŧŒčŋ™įŽ€åŒ–äē†éƒ¨įŊ˛ã€åŽ‰å…¨ã€åŧ€å‘į­‰ã€‚ + +## äģ€äšˆæ˜¯åŽšå™¨é•œåƒ + +**厚器**是äģŽ**厚器镜像**čŋčĄŒįš„。 + +厚器镜像是厚器中文äģļã€įŽ¯åĸƒå˜é‡å’Œéģ˜čޤå‘Ŋäģ¤/ፋåēįš„**静态**į‰ˆæœŦ。 **静态**čŋ™é‡Œįš„æ„æ€æ˜¯åŽšå™¨**镜像**čŋ˜æ˛Ąæœ‰čŋčĄŒīŧŒåĒæ˜¯æ‰“åŒ…įš„æ–‡äģļ和元数捎。 + +ä¸Žå­˜å‚¨é™æ€å†…åŽšįš„â€œ**厚器镜像**â€į›¸åīŧŒâ€œ**厚器**â€é€šå¸¸æŒ‡æ­Ŗåœ¨čŋčĄŒįš„厞䞋īŧŒåŗæ­Ŗåœ¨**æ‰§čĄŒįš„**。 + +åŊ“**厚器**启动åšļčŋčĄŒæ—ļīŧˆäģŽ**厚器镜像**启动īŧ‰īŧŒåŽƒå¯äģĨ创åģ翈–更攚文äģļã€įŽ¯åĸƒå˜é‡į­‰ã€‚čŋ™ä盿›´æ”šå°†äģ…存在äēŽč¯Ĩ厚器中īŧŒč€Œä¸äŧšæŒäš…åŒ–åˆ°åē•åą‚įš„åŽšå™¨é•œåƒä¸­īŧˆä¸äŧšäŋå­˜åˆ°įŖį›˜īŧ‰ã€‚ + +åŽšå™¨é•œåƒį›¸åŊ“äēŽ**ፋåē**和文äģļīŧŒäž‹åĻ‚ `python`å‘Ŋäģ¤ å’ŒæŸä盿–‡äģļ åĻ‚`main.py`。 + +而**厚器**æœŦčēĢīŧˆä¸Ž**厚器镜像**į›¸åīŧ‰æ˜¯é•œåƒįš„厞际čŋčĄŒåŽžäž‹īŧŒį›¸åŊ“äēŽ**čŋ›į¨‹**。 äē‹åŽžä¸ŠīŧŒåŽšå™¨äģ…在有**čŋ›į¨‹čŋčĄŒ**æ—ļ才čŋčĄŒīŧˆé€šå¸¸åރåĒ是一ä¸Ē单į‹Ŧįš„čŋ›į¨‹īŧ‰ã€‚ åŊ“åŽšå™¨ä¸­æ˛Ąæœ‰čŋ›į¨‹čŋčĄŒæ—ļīŧŒåŽšå™¨å°ąäŧšåœæ­ĸ。 + + + +## 厚器镜像 + +Docker ä¸€į›´æ˜¯åˆ›åģēå’ŒįŽĄį†**厚器镜像**和**厚器**įš„ä¸ģčρåˇĨå…ˇäš‹ä¸€ã€‚ + +čŋ˜æœ‰ä¸€ä¸Ēå…Ŧå…ą Docker Hub īŧŒå…ļ中包åĢéĸ„åˆļįš„ **厘斚厚器镜像**, 适ᔍäēŽčޏ多åˇĨå…ˇã€įŽ¯åĸƒã€æ•°æŽåē“å’Œåē”ᔍፋåēã€‚ + +例åĻ‚īŧŒæœ‰ä¸€ä¸ĒåŽ˜æ–šįš„ Python 镜像。 + +čŋ˜æœ‰čޏ多å…ļäģ–é•œåƒį”¨äēŽä¸åŒįš„需čρīŧˆäž‹åĻ‚æ•°æŽåē“īŧ‰īŧŒäž‹åĻ‚īŧš + + +* PostgreSQL +* MySQL +* MongoDB +* Redis, etc. + + +通čŋ‡äŊŋᔍéĸ„åˆļįš„åŽšå™¨é•œåƒīŧŒå¯äģĨ非常čŊģæžåœ°**įģ„合**åšļäŊŋį”¨ä¸åŒįš„åˇĨå…ˇã€‚ 例åĻ‚īŧŒå°č¯•一ä¸Ēæ–°įš„æ•°æŽåē“。 在大多数情å†ĩ下īŧŒäŊ å¯äģĨäŊŋᔍ**厘斚镜像**īŧŒåĒ需ä¸ēå…ļ配įŊŽįޝåĸƒå˜é‡åŗå¯ã€‚ + +čŋ™æ ˇīŧŒåœ¨čŽ¸å¤šæƒ…å†ĩ下īŧŒäŊ å¯äģĨäē†č§ŖåŽšå™¨å’Œ DockerīŧŒåšļ通čŋ‡čŽ¸å¤šä¸åŒįš„åˇĨå…ˇå’Œįģ„äģļ重复äŊŋᔍčŋ™äē›įŸĨč¯†ã€‚ + +因此īŧŒäŊ å¯äģĨčŋčĄŒå¸Ļæœ‰ä¸åŒå†…åŽšįš„**多ä¸Ē厚器**īŧŒäž‹åĻ‚æ•°æŽåē“、Python åē”ᔍፋåēã€å¸Ļ有 React 前į̝åē”ᔍፋåēįš„ Web æœåŠĄå™¨īŧŒåšļ通čŋ‡å†…部įŊ‘įģœå°†åރäģŦčŋžæŽĨ在一čĩˇã€‚ + +æ‰€æœ‰åŽšå™¨įŽĄį†įŗģįģŸīŧˆåĻ‚ Docker 或 Kubernetesīŧ‰éƒŊ集成äē†čŋ™äē›įŊ‘įģœåŠŸčƒŊ。 + +## 厚器和čŋ›į¨‹ + +**厚器镜像**通常在å…ļ元数捎中包åĢ启动**厚器**æ—ļåē”čŋčĄŒįš„éģ˜čޤፋåēæˆ–å‘Ŋäģ¤äģĨ及čρäŧ é€’įģ™č¯Ĩፋåēįš„参数。 与在å‘Ŋäģ¤čĄŒä¸­įš„æƒ…å†ĩéžå¸¸į›¸äŧŧ。 + +åŊ“ **厚器** 启动æ—ļīŧŒåŽƒå°†čŋčĄŒč¯Ĩå‘Ŋäģ¤/ፋåēīŧˆå°ŊįŽĄäŊ å¯äģĨčĻ†į›–åŽƒåšļäŊŋå…ļčŋčĄŒä¸åŒįš„å‘Ŋäģ¤/ፋåēīŧ‰ã€‚ + +åĒčρ**ä¸ģčŋ›į¨‹**īŧˆå‘Ŋä줿ˆ–ፋåēīŧ‰åœ¨čŋčĄŒīŧŒåŽšå™¨å°ąåœ¨čŋčĄŒã€‚ + +厚器通常有一ä¸Ē**单ä¸Ēčŋ›į¨‹**īŧŒäŊ†äšŸå¯äģĨäģŽä¸ģčŋ›į¨‹å¯åЍ子čŋ›į¨‹īŧŒčŋ™æ ˇäŊ å°ąå¯äģĨ在同一ä¸Ē厚器中æ‹Ĩ有**多ä¸Ēčŋ›į¨‹**。 + +äŊ†æ˜¯īŧŒåĻ‚æžœæ˛Ąæœ‰**臺少䏀ä¸Ēæ­Ŗåœ¨čŋčĄŒįš„čŋ›į¨‹**īŧŒå°ąä¸å¯čƒŊ有一ä¸Ēæ­Ŗåœ¨čŋčĄŒįš„厚器。 åĻ‚æžœä¸ģčŋ›į¨‹åœæ­ĸīŧŒåŽšå™¨äšŸäŧšåœæ­ĸ。 + + +## ä¸ē FastAPI 构åģē Docker 镜像 + +åĨŊ吧īŧŒčŽŠæˆ‘äģŦįŽ°åœ¨æž„åģē一äē›ä¸œčĨŋīŧ 🚀 + +我将向äŊ åą•į¤ēåĻ‚äŊ•åŸēäēŽ **厘斚 Python** 镜像 **äģŽå¤´åŧ€å§‹** ä¸ē FastAPI 构åģē **Docker 镜像**。 + +čŋ™æ˜¯äŊ åœ¨**大多数情å†ĩ**ä¸‹æƒŗčĻåšįš„īŧŒäž‹åĻ‚īŧš + +* äŊŋᔍ **Kubernetes** 或įąģäŧŧåˇĨå…ˇ +* 在 **Raspberry Pi** 上čŋčĄŒæ—ļ +* äŊŋį”¨å¯ä¸ēäŊ čŋčĄŒåŽšå™¨é•œåƒįš„ä瑿œåŠĄį­‰ã€‚ + +### 䞝čĩ–饚 + +äŊ é€šå¸¸äŧšåœ¨æŸä¸Ē文äģļ中包åĢåē”ᔍፋåēįš„**䞝čĩ–饚**。 + +å…ˇäŊ“åšæŗ•å–å†ŗäēŽäŊ **åŽ‰čŖ…**čŋ™äē›äžčĩ–æ—ļ所äŊŋį”¨įš„åˇĨå…ˇã€‚ + +æœ€å¸¸č§įš„æ–šæŗ•æ˜¯åˆ›åģē一ä¸Ē`requirements.txt`文äģļīŧŒå…ļä¸­æ¯čĄŒåŒ…åĢ一ä¸ĒåŒ…åį§°å’ŒåŽƒįš„į‰ˆæœŦ。 + +äŊ åŊ“į„ļ䚟可äģĨäŊŋį”¨åœ¨[å…ŗäēŽ FastAPI į‰ˆæœŦ](./versions.md){.internal-link target=_blank} ä¸­čŽ˛åˆ°įš„æ–šæŗ•æĨ莞įŊŽį‰ˆæœŦčŒƒå›´ã€‚ + +例åĻ‚īŧŒäŊ įš„`requirements.txt`可čƒŊåĻ‚ä¸‹æ‰€į¤ēīŧš + + +``` +fastapi>=0.68.0,<0.69.0 +pydantic>=1.8.0,<2.0.0 +uvicorn>=0.15.0,<0.16.0 +``` + +äŊ é€šå¸¸äŧšäŊŋᔍ`pip`åŽ‰čŖ…čŋ™äē›äžčĩ–饚īŧš + +
+ +```console +$ pip install -r requirements.txt +---> 100% +Successfully installed fastapi pydantic uvicorn +``` + +
+ +!!! info + čŋ˜æœ‰å…ļäģ–æ–‡äģļæ ŧåŧå’ŒåˇĨå…ˇæĨåŽšäš‰å’ŒåŽ‰čŖ…äžčĩ–éĄšã€‚ + + 我将在下éĸįš„éƒ¨åˆ†ä¸­å‘äŊ åą•į¤ē一ä¸ĒäŊŋᔍ Poetry įš„į¤ē䞋。 👇 + +### 创åģē **FastAPI** äģŖį  + +* 创åģē`app`į›ŽåŊ•åšļčŋ›å…Ĩ。 +* 创åģē一ä¸ĒįŠē文äģļ`__init__.py`。 +* 创åģē一ä¸Ē `main.py` 文äģļīŧš + + + +```Python +from typing import Union + +from fastapi import FastAPI + +app = FastAPI() + + +@app.get("/") +def read_root(): + return {"Hello": "World"} + + +@app.get("/items/{item_id}") +def read_item(item_id: int, q: Union[str, None] = None): + return {"item_id": item_id, "q": q} +``` + +### Dockerfile + +įŽ°åœ¨åœ¨į›¸åŒįš„projectį›ŽåŊ•创åģē一ä¸Ē名ä¸ē`Dockerfile`įš„æ–‡äģļ: + +```{ .dockerfile .annotate } +# (1) +FROM python:3.9 + +# (2) +WORKDIR /code + +# (3) +COPY ./requirements.txt /code/requirements.txt + +# (4) +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (5) +COPY ./app /code/app + +# (6) +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. äģŽåŽ˜æ–šPythonåŸēįĄ€é•œåƒåŧ€å§‹ã€‚ + +2. 将åŊ“前åˇĨäŊœį›ŽåŊ•莞įŊŽä¸ē`/code`。 + + čŋ™æ˜¯æˆ‘äģŦ攞įŊŽ`requirements.txt`文äģļ和`app`į›ŽåŊ•įš„äŊįŊŽã€‚ + +3. 将įŦĻ合čĻæą‚įš„æ–‡äģļ复åˆļ到`/code`į›ŽåŊ•中。 + + éĻ–å…ˆäģ…复åˆļrequirements.txt文äģļīŧŒč€Œä¸å¤åˆļå…ļäŊ™äģŖį ã€‚ + + į”ąäēŽæ­¤æ–‡äģļ**不įģå¸¸æ›´æ”š**īŧŒDocker å°†æŖ€æĩ‹åˆ°åރåšļ在čŋ™ä¸€æ­Ĩ中äŊŋᔍ**įŧ“å­˜**īŧŒäģŽč€Œä¸ē下一æ­Ĩ吝ᔍįŧ“存。 + +4. åŽ‰čŖ…éœ€æą‚æ–‡äģļä¸­įš„åŒ…äžčĩ–éĄšã€‚ + + `--no-cache-dir` é€‰éĄšå‘Šč¯‰ `pip` 不čρ圍æœŦ地äŋå­˜ä¸‹čŊŊįš„åŒ…īŧŒå› ä¸ēåĒ有åŊ“ `pip` 再æŦĄčŋčĄŒäģĨåŽ‰čŖ…į›¸åŒįš„åŒ…æ—ļ才äŧščŋ™æ ˇīŧŒäŊ†åœ¨ä¸ŽåŽšå™¨ä¸€čĩˇåˇĨäŊœæ—ļ情å†ĩåšļ非åĻ‚æ­¤ã€‚ + + !!! įŦ”čް + `--no-cache-dir` äģ…与 `pip` ᛏ兺īŧŒä¸Ž Docker æˆ–åŽšå™¨æ— å…ŗã€‚ + + `--upgrade` é€‰éĄšå‘Šč¯‰ `pip` 升įē§čŊ¯äģļ包īŧˆåĻ‚æžœåˇ˛įģåމ誅īŧ‰ã€‚ + + 因ä¸ē上一æ­Ĩ复åˆļ文äģļ可äģĨčĸĢ **Docker įŧ“å­˜** æŖ€æĩ‹åˆ°īŧŒæ‰€äģĨæ­¤æ­ĨéĒ¤äšŸå°† **äŊŋᔍ Docker įŧ“å­˜**īŧˆåĻ‚æžœå¯į”¨īŧ‰ã€‚ + + 在åŧ€å‘čŋ‡į¨‹ä¸­ä¸€æŦĄåˆä¸€æŦĄæž„åģē镜像æ—ļīŧŒåœ¨æ­¤æ­ĨéǤ䏭äŊŋᔍįŧ“存将ä¸ēäŊ čŠ‚įœå¤§é‡**æ—ļ间**īŧŒč€Œä¸æ˜¯**每æŦĄ**éƒŊ**下čŊŊå’ŒåŽ‰čŖ…**所有䞝čĩ–éĄšã€‚ + + +5. 将“./appâ€į›ŽåŊ•复åˆļ到“/codeâ€į›ŽåŊ•中。 + + į”ąäēŽå…ļ中包åĢ**更攚最éĸ‘įš**įš„æ‰€æœ‰äģŖį īŧŒå› æ­¤ Docker **įŧ“å­˜**不äŧščŊ쿘“ᔍäēŽæ­¤æ“äŊœæˆ–äģģäŊ•**后įģ­æ­ĨéǤ**。 + + 因此īŧŒå°†å…ļ攞在`Dockerfile`**æŽĨčŋ‘最后**įš„äŊįŊŽéžå¸¸é‡čρīŧŒäģĨäŧ˜åŒ–åŽšå™¨é•œåƒįš„æž„åģēæ—ļ间。 + +6. 莞įŊŽ**å‘Ŋäģ¤**æĨčŋčĄŒ `uvicorn` æœåŠĄå™¨ã€‚ + + `CMD` æŽĨ受一ä¸Ē字įŦĻä¸˛åˆ—čĄ¨īŧŒæ¯ä¸Ē字įŦĻ串éƒŊ是äŊ åœ¨å‘Ŋäģ¤čĄŒä¸­čž“å…Ĩįš„å†…åŽšīŧŒåšļᔍįŠēæ ŧ分隔。 + + č¯Ĩå‘Ŋäģ¤å°†äģŽ **åŊ“前åˇĨäŊœį›ŽåŊ•** čŋčĄŒīŧŒåŗäŊ ä¸ŠéĸäŊŋᔍ`WORKDIR /code`莞įŊŽįš„同一`/code`į›ŽåŊ•。 + + 因ä¸ēፋåēå°†äģŽ`/code`启动īŧŒåšļ且å…ļ中包åĢäŊ įš„äģŖį įš„į›ŽåŊ•`./app`īŧŒæ‰€äģĨ**Uvicorn**将čƒŊ够äģŽ`app.main`中æŸĨįœ‹åšļ**import**`app`。 + +!!! tip + 通čŋ‡å•å‡ģäģŖį ä¸­įš„æ¯ä¸Ēæ•°å­—æ°”æŗĄæĨæŸĨįœ‹æ¯čĄŒįš„äŊœį”¨ã€‚ 👆 + +äŊ įŽ°åœ¨åē”č¯Ĩå…ˇæœ‰åĻ‚ä¸‹į›ŽåŊ•į쓿ž„īŧš +``` +. +├── app +│   ├── __init__.py +│ └── main.py +├── Dockerfile +└── requirements.txt +``` + + +#### 在 TLS į숿­ĸäģŖį†åŽéĸ + +åĻ‚æžœäŊ åœ¨ Nginx 或 Traefik į­‰ TLS į숿­ĸäģŖį†īŧˆč´ŸčŊŊå‡čĄĄå™¨īŧ‰åŽéĸčŋčĄŒåŽšå™¨īŧŒč¯ˇæˇģåŠ é€‰éĄš `--proxy-headers`īŧŒčŋ™å°†å‘Šč¯‰ Uvicorn äŋĄäģģč¯ĨäģŖį†å‘é€įš„æ ‡å¤´īŧŒå‘Šč¯‰åރåē”ᔍፋåēæ­Ŗåœ¨ HTTPS 后éĸčŋčĄŒį­‰äŋĄæ¯ + +```Dockerfile +CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] +``` + +#### Docker įŧ“å­˜ + +čŋ™ä¸Ē`Dockerfile`中有一ä¸Ē重čĻįš„æŠ€åˇ§īŧŒæˆ‘äģŦéĻ–å…ˆåĒ单į‹Ŧ复åˆļ**包åĢ䞝čĩ–éĄšįš„æ–‡äģļ**īŧŒč€Œä¸æ˜¯å…ļäŊ™äģŖį ã€‚ čŽŠæˆ‘æĨå‘Šč¯‰äŊ čŋ™æ˜¯ä¸ēäģ€äšˆã€‚ + +```Dockerfile +COPY ./requirements.txt /code/requirements.txt +``` + +Docker之įąģįš„æž„åģēåˇĨå…ˇæ˜¯é€ščŋ‡**åĸžé‡**įš„æ–šåŧæĨ构åģēčŋ™äē›åŽšå™¨é•œåƒįš„ã€‚å…ˇäŊ“åšæŗ•æ˜¯äģŽ`Dockerfile`éĄļ部åŧ€å§‹īŧŒæ¯ä¸€æĄæŒ‡äģ¤į”Ÿæˆįš„æ–‡äģļéƒŊæ˜¯é•œåƒįš„â€œä¸€åą‚â€īŧŒåŒčŋ‡æŠŠčŋ™äē›â€œåą‚â€ä¸€åą‚ä¸€åą‚åœ°å åŠ åˆ°åŸēįĄ€é•œåƒä¸ŠīŧŒæœ€åŽæˆ‘äģŦå°ąåž—åˆ°ä熿œ€įģˆįš„镜像。 + +Docker 和įąģäŧŧåˇĨå…ˇåœ¨æž„åģē镜像æ—ļ也äŧšäŊŋᔍ**内部įŧ“å­˜**īŧŒåĻ‚æžœč‡Ē上æŦĄæž„åģē厚器镜像äģĨæĨ文äģ￞Ąæœ‰æ›´æ”šīŧŒé‚ŖäšˆåŽƒå°†**重新äŊŋį”¨ä¸ŠæŦĄåˆ›åģēįš„åŒä¸€åą‚**īŧŒč€Œä¸æ˜¯å†æŦĄå¤åˆļ文äģļåšļäģŽå¤´åŧ€å§‹åˆ›åģēæ–°åą‚。 + +äģ…äģ…éŋ免文äģļįš„å¤åˆļ不一厚äŧšæœ‰å¤Ē多速åēĻæå‡īŧŒäŊ†æ˜¯åĻ‚æžœåœ¨čŋ™ä¸€æ­ĨäŊŋᔍäē†įŧ“å­˜īŧŒé‚Ŗäšˆæ‰å¯äģĨ**在下一æ­Ĩ中äŊŋᔍįŧ“å­˜**。 例åĻ‚īŧŒå¯äģĨäŊŋį”¨åŽ‰čŖ…äžčĩ–éĄšé‚ŖæĄæŒ‡äģ¤įš„įŧ“å­˜īŧš + +```Dockerfile +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt +``` + + +包åĢ包䞝čĩ–éĄšįš„æ–‡äģļ**不äŧšéĸ‘įšæ›´æ”š**。 åĒ复åˆļč¯Ĩ文äģļīŧˆä¸å¤åˆļå…ļäģ–įš„åē”ᔍäģŖį īŧ‰īŧŒDocker 才čƒŊ在čŋ™ä¸€æ­Ĩ**äŊŋᔍįŧ“å­˜**。 + +Docker čŋ›č€ŒčƒŊ**äŊŋᔍįŧ“å­˜čŋ›čĄŒä¸‹ä¸€æ­Ĩ**īŧŒåŗä¸‹čŊŊåšļåŽ‰čŖ…čŋ™äē›äžčĩ–éĄšã€‚ čŋ™æ‰æ˜¯æˆ‘äģŦ**čŠ‚įœå¤§é‡æ—ļ间**įš„åœ°æ–šã€‚ ✨ ...可äģĨéŋå…æ— čŠįš„į­‰åž…ã€‚ đŸ˜Ē😆 + +下čŊŊå’ŒåŽ‰čŖ…äžčĩ–饚**可čƒŊ需čĻå‡ åˆ†é’Ÿ**īŧŒäŊ†äŊŋᔍ**įŧ“å­˜**最多**åĒ需čĻå‡ į§’é’Ÿ**。 + +į”ąäēŽäŊ åœ¨åŧ€å‘čŋ‡į¨‹ä¸­äŧšä¸€æŦĄåˆä¸€æŦĄåœ°æž„åģē厚器镜像äģĨæŖ€æŸĨäģŖį æ›´æ”šæ˜¯åĻ有效īŧŒå› æ­¤å¯äģĨį´¯čŽĄčŠ‚įœå¤§é‡æ—ļ间。 + +在`Dockerfile`æœĢ尞附čŋ‘īŧŒæˆ‘äģŦ再æˇģ加复åˆļäģŖį įš„æŒ‡äģ¤ã€‚ į”ąäēŽäģŖį æ˜¯**更攚最éĸ‘įšįš„**īŧŒæ‰€äģĨ将å…ļ攞在最后īŧŒå› ä¸ēčŋ™ä¸€æ­Ĩäš‹åŽįš„å†…åŽšåŸēæœŦ上éƒŊæ˜¯æ— æŗ•äŊŋᔍįŧ“å­˜įš„ã€‚ + +```Dockerfile +COPY ./app /code/app +``` + +### 构åģē Docker 镜像 + +įŽ°åœ¨æ‰€æœ‰æ–‡äģļéƒŊåˇ˛å°ąäŊīŧŒčŽŠæˆ‘äģŦ构åģē厚器镜像。 + +* čŊŦåˆ°éĄšį›Žį›ŽåŊ•īŧˆåœ¨`Dockerfile`æ‰€åœ¨įš„äŊįŊŽīŧŒåŒ…åĢ`app`į›ŽåŊ•īŧ‰ã€‚ +* 构åģēäŊ įš„ FastAPI 镜像īŧš + + +
+ +```console +$ docker build -t myimage . + +---> 100% +``` + +
+ + +!!! tip + æŗ¨æ„æœ€åŽįš„ `.`īŧŒåŽƒį›¸åŊ“äēŽ`./`īŧŒåŽƒå‘Šč¯‰ Docker ᔍäēŽæž„åģēåŽšå™¨é•œåƒįš„į›ŽåŊ•。 + + 在æœŦ例中īŧŒåŽƒæ˜¯į›¸åŒįš„åŊ“å‰į›ŽåŊ•īŧˆ`.`īŧ‰ã€‚ + +### 启动 Docker 厚器 + +* 栚捎äŊ įš„镜像čŋčĄŒåŽšå™¨īŧš + +
+ +```console +$ docker run -d --name mycontainer -p 80:80 myimage +``` + +
+ +## æŖ€æŸĨ一下 + + +äŊ åē”č¯ĨčƒŊ在DockeråŽšå™¨įš„URLä¸­æŖ€æŸĨ厃īŧŒäž‹åĻ‚: http://192.168.99.100/items/5?q=somequery 或 http://127.0.0.1/items/5?q=somequery (或å…ļäģ–į­‰äģˇįš„īŧŒäŊŋᔍ Docker ä¸ģæœē). + +äŊ äŧšįœ‹åˆ°įąģäŧŧ内厚īŧš + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +## äē¤äē’åŧ API æ–‡æĄŖ + +įŽ°åœ¨äŊ å¯äģĨčŊŦ到 http://192.168.99.100/docs 或 http://127.0.0.1/docs īŧˆæˆ–å…ļäģ–į­‰äģˇįš„īŧŒäŊŋᔍ Docker ä¸ģæœēīŧ‰ã€‚ + +äŊ å°†įœ‹åˆ°č‡Ē动äē¤äē’åŧ API æ–‡æĄŖīŧˆį”ą Swagger UI): + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +## å¤‡é€‰įš„ API æ–‡æĄŖ + +äŊ čŋ˜å¯äģĨčŽŋ问 http://192.168.99.100/redoc 或 http://127.0.0.1/redoc īŧˆæˆ–å…ļäģ–į­‰äģˇįš„īŧŒäŊŋᔍ Docker ä¸ģæœēīŧ‰ã€‚ + +äŊ å°†įœ‹åˆ°å¤‡é€‰įš„č‡ĒåŠ¨æ–‡æĄŖīŧˆį”ą ReDoc 提䞛īŧ‰īŧš + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## äŊŋį”¨å•æ–‡äģļ FastAPI 构åģē Docker 镜像 + +åĻ‚æžœäŊ įš„ FastAPI 是单ä¸Ē文äģļīŧŒäž‹åĻ‚æ˛Ąæœ‰`./app`į›ŽåŊ•įš„`main.py`īŧŒåˆ™äŊ įš„æ–‡äģļį쓿ž„可čƒŊåĻ‚ä¸‹æ‰€į¤ēīŧš + +``` +. +├── Dockerfile +├── main.py +└── requirements.txt +``` + +į„ļ后äŊ åĒéœ€æ›´æ”šį›¸åē”įš„čˇ¯åž„åŗå¯å°†æ–‡äģļ复åˆļ到`Dockerfile`中īŧš + +```{ .dockerfile .annotate hl_lines="10 13" } +FROM python:3.9 + +WORKDIR /code + +COPY ./requirements.txt /code/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (1) +COPY ./main.py /code/ + +# (2) +CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. į›´æŽĨ将`main.py`文äģļ复åˆļ到`/code`į›ŽåŊ•中īŧˆä¸åŒ…åĢäģģäŊ•`./app`į›ŽåŊ•īŧ‰ã€‚ + +2. čŋčĄŒ Uvicorn åšļå‘Šč¯‰åŽƒäģŽ `main` å¯ŧå…Ĩ `app` å¯ščąĄīŧˆč€Œä¸æ˜¯äģŽ `app.main` å¯ŧå…Ĩīŧ‰ã€‚ + +į„ļåŽč°ƒæ•´Uvicornå‘Ŋäģ¤äŊŋį”¨æ–°æ¨Ąå—`main`č€Œä¸æ˜¯`app.main`æĨå¯ŧå…ĨFastAPI 厞䞋`app`。 + +## 部įŊ˛æĻ‚åŋĩ + +我äģŦå†č°ˆč°ˆåŽšå™¨æ–šéĸįš„ä¸€äē›į›¸åŒįš„[部įŊ˛æĻ‚åŋĩ](./concepts.md){.internal-link target=_blank}。 + +厚器ä¸ģčĻæ˜¯ä¸€į§įŽ€åŒ–**构åģē和部įŊ˛**åē”ᔍፋåēįš„čŋ‡į¨‹įš„åˇĨå…ˇīŧŒäŊ†åރäģŦåšļ不åŧēåˆļæ‰§čĄŒį‰šåŽšįš„æ–šæŗ•æĨ处ᐆčŋ™äē›**部įŊ˛æĻ‚åŋĩ**īŧŒåšļä¸”æœ‰å‡ į§å¯čƒŊįš„į­–į•Ĩ。 + +**åĨŊæļˆæ¯**是īŧŒå¯šäēŽæ¯į§ä¸åŒįš„į­–į•ĨīŧŒéƒŊæœ‰ä¸€į§æ–šæŗ•å¯äģĨæļĩį›–æ‰€æœ‰éƒ¨įŊ˛æĻ‚åŋĩ。 🎉 + +čŽŠæˆ‘äģŦäģŽåŽšå™¨įš„č§’åēĻå›žéĄžä¸€ä¸‹čŋ™äē›**部įŊ˛æĻ‚åŋĩ**īŧš + +* HTTPS +* 启动æ—ļčŋčĄŒ +* 重新启动 +* 复åˆļīŧˆčŋčĄŒįš„čŋ›į¨‹æ•°īŧ‰ +* 内存 +* åŧ€å§‹å‰įš„先前æ­ĨéǤ + + +## HTTPS + +åĻ‚æžœæˆ‘äģŦåĒå…ŗæŗ¨ FastAPI åē”ᔍፋåēįš„ **厚器镜像**īŧˆäģĨåŠį¨åŽčŋčĄŒįš„ **厚器**īŧ‰īŧŒHTTPS 通常äŧšį”ąåĻ一ä¸ĒåˇĨå…ˇåœ¨ **外部** å¤„į†ã€‚ + +厃可äģĨ是åĻ一ä¸Ē厚器īŧŒäž‹åĻ‚äŊŋᔍ TraefikīŧŒå¤„ᐆ **HTTPS** 和 **č‡Ē动**čŽˇå–**蝁äšĻ**。 + +!!! tip + Traefik可äģĨ与 Docker、Kubernetes į­‰é›†æˆīŧŒå› æ­¤äŊŋį”¨åŽƒä¸ēåŽšå™¨čŽžįŊŽå’Œé…įŊŽ HTTPS 非常厚易。 + +æˆ–č€…īŧŒHTTPS 可äģĨį”ąä瑿œåŠĄå•†äŊœä¸ēå…ļæœåŠĄäš‹ä¸€čŋ›čĄŒå¤„ᐆīŧˆåŒæ—ļäģåœ¨åŽšå™¨ä¸­čŋčĄŒåē”ᔍፋåēīŧ‰ã€‚ + +## 在启动和重新启动æ—ļčŋčĄŒ + +通常čŋ˜æœ‰åĻ一ä¸ĒåˇĨå…ˇč´Ÿč´Ŗ**启动和čŋčĄŒ**äŊ įš„厚器。 + +厃可äģĨį›´æŽĨ是**Docker**, æˆ–č€…**Docker Compose**、**Kubernetes**、**ä瑿œåŠĄ**į­‰ã€‚ + +在大多数īŧˆæˆ–所有īŧ‰æƒ…å†ĩ下īŧŒæœ‰ä¸€ä¸ĒįŽ€å•įš„é€‰éĄšå¯äģĨ在启动æ—ļčŋčĄŒåŽšå™¨åšļåœ¨å¤ąč´Ĩæ—ļ重新启动。 例åĻ‚īŧŒåœ¨ Docker 中īŧŒåŽƒæ˜¯å‘Ŋäģ¤čĄŒé€‰éĄš `--restart`。 + +åĻ‚æžœä¸äŊŋį”¨åŽšå™¨īŧŒčŽŠåē”ᔍፋåēåœ¨å¯åЍæ—ļčŋčĄŒåšļ重新启动可čƒŊäŧšåžˆéēģįƒĻ且困隞。 äŊ†åœ¨å¤§å¤šæ•°æƒ…å†ĩ下īŧŒåŊ“**äŊŋį”¨åŽšå™¨**æ—ļīŧŒéģ˜čŽ¤æƒ…å†ĩ下äŧšåŒ…åĢč¯Ĩ功čƒŊ。 ✨ + +## 复åˆļ - čŋ›į¨‹æ•° + +åĻ‚æžœäŊ æœ‰ä¸€ä¸Ē é›†įž¤, 比åĻ‚ **Kubernetes**、Docker Swarm、Nomad 或å…ļäģ–įąģäŧŧįš„å¤æ‚įŗģį쟿ĨįŽĄį†å¤šå°æœēå™¨ä¸Šįš„åˆ†å¸ƒåŧåŽšå™¨īŧŒé‚ŖäšˆäŊ å¯čƒŊ希望在**é›†įž¤įē§åˆĢ**å¤„į†å¤åˆļ**īŧŒč€Œä¸æ˜¯åœ¨æ¯ä¸Ē厚器中äŊŋᔍ**čŋ›į¨‹įŽĄį†å™¨**īŧˆåĻ‚å¸Ļ有Workerįš„ Gunicornīŧ‰ 。 + +像 Kubernetes čŋ™æ ˇįš„分布åŧåŽšå™¨įŽĄį†įŗģįģŸé€šå¸¸æœ‰ä¸€äē›é›†æˆįš„æ–šæŗ•æĨ处ᐆ**åŽšå™¨įš„å¤åˆļ**īŧŒåŒæ—ļäģį„ļ支持äŧ å…Ĩč¯ˇæą‚įš„**负čŊŊå‡čĄĄ**。 全部éƒŊ在**é›†įž¤įē§åˆĢ**。 + +在čŋ™ä盿ƒ…å†ĩ下īŧŒäŊ å¯čƒŊ希望äģŽå¤´åŧ€å§‹æž„åģē一ä¸Ē **Docker 镜像**īŧŒåĻ‚[上éĸæ‰€č§Ŗé‡Š](#dockerfile)įš„é‚Ŗæ ˇīŧŒåŽ‰čŖ…äžčĩ–饚åšļčŋčĄŒ **单ä¸Ē Uvicorn čŋ›į¨‹**īŧŒč€Œä¸æ˜¯čŋčĄŒ Gunicorn 和 Uvicorn workersčŋ™į§ã€‚ + + +### 负čŊŊå‡čĄĄå™¨ + +äŊŋį”¨åŽšå™¨æ—ļīŧŒé€šå¸¸äŧšæœ‰ä¸€äē›įģ„äģļ**ᛑåŦä¸ģįĢ¯åŖ**。 厃可čƒŊæ˜¯å¤„į† **HTTPS** įš„ **TLS į숿­ĸäģŖį†** 或一äē›įąģäŧŧįš„åˇĨå…ˇįš„åĻ一ä¸Ē厚器。 + +į”ąäēŽč¯Ĩįģ„äģļ将æŽĨå—č¯ˇæą‚įš„**负čŊŊ**åšļīŧˆå¸Œæœ›īŧ‰äģĨ**åšŗčĄĄ**įš„æ–šåŧåœ¨worker䚋间分配č¯Ĩč¯ˇæą‚īŧŒå› æ­¤åŽƒé€šå¸¸äšŸį§°ä¸ē**负čŊŊå‡čĄĄå™¨**。 + +!!! tip + ᔍäēŽ HTTPS **TLS į숿­ĸäģŖį†** įš„į›¸åŒįģ„äģļ䚟可čƒŊ是 **负čŊŊå‡čĄĄå™¨**。 + +åŊ“äŊŋį”¨åŽšå™¨æ—ļīŧŒäŊ į”¨æĨå¯åŠ¨å’ŒįŽĄį†åŽšå™¨įš„åŒä¸€įŗģįģŸåˇ˛įģå…ˇæœ‰å†…部åˇĨå…ˇæĨäŧ čž“æĨč‡Ēč¯Ĩ**负čŊŊå‡čĄĄå™¨**īŧˆäšŸå¯äģĨ是**TLS į숿­ĸäģŖį†**) įš„**įŊ‘įģœé€šäŋĄ**īŧˆäž‹åĻ‚HTTPč¯ˇæą‚īŧ‰åˆ°äŊ įš„åē”ᔍፋåēåŽšå™¨ã€‚ + +### 一ä¸Ē负čŊŊå‡čĄĄå™¨ - 多ä¸Ēworker厚器 + +åŊ“äŊŋᔍ **Kubernetes** 或įąģäŧŧįš„åˆ†å¸ƒåŧåŽšå™¨įŽĄį†įŗģį쟿—ļīŧŒäŊŋᔍå…ļ内部įŊ‘į윿œēåˆļå°†å…čŽ¸å•ä¸Ē在ä¸ģ **įĢ¯åŖ** 上äžĻåŦįš„ **负čŊŊå‡čĄĄå™¨** 将通äŋĄīŧˆč¯ˇæą‚īŧ‰äŧ čž“到可čƒŊįš„ **多ä¸Ē** čŋčĄŒäŊ åē”ᔍፋåēįš„厚器。 + +čŋčĄŒäŊ įš„åē”ᔍፋåēįš„æ¯ä¸Ē厚器通常**åĒ有一ä¸Ēčŋ›į¨‹**īŧˆäž‹åĻ‚īŧŒčŋčĄŒ FastAPI åē”ᔍፋåēįš„ Uvicorn čŋ›į¨‹īŧ‰ã€‚ 厃äģŦéƒŊ是**į›¸åŒįš„åŽšå™¨**īŧŒčŋčĄŒį›¸åŒįš„东čĨŋīŧŒäŊ†æ¯ä¸Ē厚器éƒŊ有č‡Ēåˇąįš„čŋ›į¨‹ã€å†…å­˜į­‰ã€‚čŋ™æ ˇäŊ å°ąå¯äģĨ在 CPU įš„**不同核åŋƒ**īŧŒ į”šč‡ŗåœ¨**ä¸åŒįš„æœē器**å……åˆ†åˆŠį”¨**åšļčĄŒåŒ–(parallelization)**。 + +å…ˇæœ‰**负čŊŊå‡čĄĄå™¨**įš„åˆ†å¸ƒåŧåŽšå™¨įŗģįģŸå°†**å°†č¯ˇæą‚čŊŽæĩåˆ†é…**įģ™äŊ įš„åē”ᔍፋåēįš„æ¯ä¸Ē厚器。 因此īŧŒæ¯ä¸Ēč¯ˇæą‚éƒŊ可äģĨį”ąčŋčĄŒäŊ įš„åē”ᔍፋåēįš„多ä¸Ē**复åˆļ厚器**之一æĨå¤„į†ã€‚ + +通常īŧŒčŋ™ä¸Ē**负čŊŊå‡čĄĄå™¨**čƒŊå¤Ÿå¤„į†å‘é€åˆ°é›†įž¤ä¸­įš„*å…ļäģ–*åē”ᔍፋåēįš„č¯ˇæą‚īŧˆäž‹åĻ‚å‘é€åˆ°ä¸åŒįš„åŸŸīŧŒæˆ–åœ¨ä¸åŒįš„ URL čˇ¯åž„å‰įŧ€ä¸‹īŧ‰īŧŒåšļæ­ŖįĄŽåœ°å°†č¯Ĩ通äŋĄäŧ čž“åˆ°åœ¨é›†įž¤ä¸­čŋčĄŒįš„*å…ļäģ–*åē”ᔍፋåēįš„寚åē”厚器。 + + + + + + +### 每ä¸Ē厚器一ä¸Ēčŋ›į¨‹ + +在čŋ™į§įąģåž‹įš„åœē景中īŧŒäŊ å¯čƒŊ希望**每ä¸Ē厚器有一ä¸ĒīŧˆUvicornīŧ‰čŋ›į¨‹**īŧŒå› ä¸ēäŊ åˇ˛įģåœ¨é›†įž¤įē§åˆĢå¤„į†å¤åˆļ。 + +因此īŧŒåœ¨čŋ™į§æƒ…å†ĩ下īŧŒäŊ **不äŧš**希望æ‹Ĩ有像 Gunicorn 和 Uvicorn workerä¸€æ ˇįš„čŋ›į¨‹įŽĄį†å™¨īŧŒæˆ–者 Uvicorn äŊŋᔍč‡Ēåˇąįš„ Uvicorn worker。 äŊ å¯čƒŊ希望每ä¸Ē厚器īŧˆäŊ†å¯čƒŊ有多ä¸Ē厚器īŧ‰åĒ有一ä¸Ē**单į‹Ŧįš„ Uvicorn čŋ›į¨‹**。 + +在厚器内æ‹Ĩ有åĻ一ä¸Ēčŋ›į¨‹įŽĄį†å™¨īŧˆå°ąåƒäŊŋᔍ Gunicorn 或 Uvicorn įŽĄį† Uvicorn åˇĨäŊœįēŋį¨‹ä¸€æ ˇīŧ‰åĒäŧšåĸžåŠ **不åŋ…čĻįš„å¤æ‚æ€§**īŧŒč€ŒäŊ åžˆå¯čƒŊ厞įģåœ¨é›†įž¤įŗģįģŸä¸­å¤„ᐆčŋ™äē›å¤æ‚性äē†ã€‚ + +### å…ˇæœ‰å¤šä¸Ēčŋ›į¨‹įš„厚器 + +åŊ“į„ļīŧŒåœ¨æŸäē›**į‰šæŽŠæƒ…å†ĩ**īŧŒäŊ å¯čƒŊ希望æ‹Ĩ有 **一ä¸Ē厚器**īŧŒå…ļ中包åĢ **Gunicorn čŋ›į¨‹įŽĄį†å™¨**īŧŒåšļ在å…ļ中启动多ä¸Ē **Uvicorn workerčŋ›į¨‹**。 + +在čŋ™ä盿ƒ…å†ĩ下īŧŒäŊ å¯äģĨäŊŋᔍ **厘斚 Docker 镜像**īŧŒå…ļ中包åĢ **Gunicorn** äŊœä¸ēčŋčĄŒå¤šä¸Ē **Uvicorn åˇĨäŊœčŋ›į¨‹** įš„čŋ›į¨‹įŽĄį†å™¨īŧŒäģĨ及一äē›éģ˜čŽ¤čŽžįŊŽæĨ栚捎åŊ“前情å†ĩč°ƒæ•´åˇĨäŊœčŋ›į¨‹æ•°é‡ č‡Ē动CPUæ ¸åŋƒã€‚ 我将在下éĸįš„ [Gunicorn - Uvicorn 厘斚 Docker 镜像](#official-docker-image-with-gunicorn-uvicorn) ä¸­å‘Šč¯‰äŊ æ›´å¤šį›¸å…ŗäŋĄæ¯ã€‚ + +下éĸ一äē›äģ€äšˆæ—ļ候čŋ™į§åšæŗ•æœ‰æ„äš‰įš„į¤ē例īŧš + + +#### 一ä¸ĒįŽ€å•įš„åē”ᔍፋåē + +åĻ‚æžœäŊ įš„åē”ᔍፋåē**čļŗå¤ŸįŽ€å•**īŧŒäŊ ä¸éœ€čρīŧˆč‡ŗå°‘įŽ°åœ¨ä¸éœ€čρīŧ‰čŋ‡å¤šåœ°åžŽč°ƒčŋ›į¨‹æ•°é‡īŧŒåšļ且äŊ å¯äģĨäŊŋᔍč‡Ē动éģ˜čޤå€ŧīŧŒé‚ŖäšˆäŊ å¯čƒŊ需čĻåŽšå™¨ä¸­įš„čŋ›į¨‹įŽĄį†å™¨ īŧˆäŊŋį”¨åŽ˜æ–š Docker 镜像īŧ‰īŧŒåšļ且äŊ åœ¨**单ä¸ĒæœåŠĄå™¨**č€Œä¸æ˜¯é›†įž¤ä¸ŠčŋčĄŒåŽƒã€‚ + +#### Docker Compose + +äŊ å¯äģĨäŊŋᔍ **Docker Compose** 部įŊ˛åˆ°**单ä¸ĒæœåŠĄå™¨**īŧˆč€Œä¸æ˜¯é›†įž¤īŧ‰īŧŒå› æ­¤äŊ æ˛Ąæœ‰ä¸€į§įŽ€å•įš„æ–šæŗ•æĨįŽĄį†åŽšå™¨įš„å¤åˆļīŧˆäŊŋᔍ Docker Composeīŧ‰īŧŒåŒæ—ļäŋį•™å…ąäēĢįŊ‘įģœå’Œ **负čŊŊå‡čĄĄ**。 + +į„ļ后īŧŒäŊ å¯čƒŊ希望æ‹Ĩ有一ä¸Ē**单ä¸Ē厚器**īŧŒå…ļ中有一ä¸Ē**čŋ›į¨‹įŽĄį†å™¨**īŧŒåœ¨å…ļ中启动**多ä¸Ēworkerčŋ›į¨‹**。 + +#### Prometheus和å…ļäģ–原因 + +äŊ čŋ˜å¯čƒŊ有**å…ļäģ–原因**īŧŒčŋ™å°†äŊŋäŊ æ›´åŽšæ˜“æ‹Ĩ有一ä¸Ēå¸Ļ有**多ä¸Ēčŋ›į¨‹**įš„**单ä¸Ē厚器**īŧŒč€Œä¸æ˜¯æ‹Ĩ有每ä¸Ē厚器中éƒŊ有**单ä¸Ēčŋ›į¨‹**įš„**多ä¸Ē厚器**。 + +例åĻ‚īŧˆå–冺äēŽäŊ įš„莞įŊŽīŧ‰äŊ å¯äģĨ在同一ä¸Ē厚器中æ‹Ĩ有一äē›åˇĨå…ˇīŧŒäž‹åĻ‚ Prometheus exporterīŧŒč¯ĨåˇĨå…ˇåē”č¯Ĩ有权čŽŋ问**每ä¸Ēč¯ˇæą‚**。 + +在čŋ™į§æƒ…å†ĩ下īŧŒåĻ‚æžœäŊ æœ‰**多ä¸Ē厚器**īŧŒéģ˜čŽ¤æƒ…å†ĩ下īŧŒåŊ“ Prometheus æĨ**č¯ģ取metrics**æ—ļīŧŒåŽƒæ¯æŦĄéƒŊäŧščŽˇå–**单ä¸Ē厚器**įš„metricsīŧˆå¯šäēŽå¤„ᐆč¯Ĩį‰šåŽšč¯ˇæą‚įš„åŽšå™¨īŧ‰īŧŒč€Œä¸æ˜¯čŽˇå–æ‰€æœ‰å¤åˆļåŽšå™¨įš„**ᴝ᧝metrics**。 + +在čŋ™į§æƒ…å†ĩīŧŒ čŋ™į§åšæŗ•äŧšæ›´åŠ įŽ€å•īŧščŽŠ**一ä¸Ē厚器**å…ˇæœ‰**多ä¸Ēčŋ›į¨‹**īŧŒåšļ在同一ä¸Ē厚器上äŊŋᔍæœŦ地åˇĨå…ˇīŧˆäž‹åĻ‚ Prometheus exporterīŧ‰æ”ļ集所有内部čŋ›į¨‹įš„ Prometheus 指标åšļå…Ŧåŧ€å•ä¸ĒåŽšå™¨ä¸Šįš„čŋ™ä盿Œ‡æ ‡ã€‚ + +--- + +čĻį‚šæ˜¯īŧŒčŋ™äē›éƒŊ**不是**äŊ åŋ…éĄģį›˛į›ŽéĩåžĒįš„**ä¸€æˆä¸å˜įš„č§„åˆ™**。 äŊ å¯äģĨ栚捎čŋ™ä盿€čˇ¯**蝄äŧ°äŊ č‡Ēåˇąįš„åœē景**åšļå†ŗåŽšäģ€äšˆæ–šæŗ•æ˜¯æœ€é€‚åˆäŊ įš„įš„įŗģįģŸīŧŒč€ƒč™‘åĻ‚äŊ•įŽĄį†äģĨ下æĻ‚åŋĩīŧš + +* 厉全性 - HTTPS +* 启动æ—ļčŋčĄŒ +* 重新启动 +* 复åˆļīŧˆčŋčĄŒįš„čŋ›į¨‹æ•°īŧ‰ +* 内存 +* åŧ€å§‹å‰įš„先前æ­ĨéǤ + +## 内存 + +åĻ‚æžœäŊ **每ä¸Ē厚器čŋčĄŒä¸€ä¸Ēčŋ›į¨‹**īŧŒé‚Ŗäšˆæ¯ä¸Ē厚器所æļˆč€—įš„å†…å­˜æˆ–å¤šæˆ–å°‘æ˜¯åŽšäš‰æ˜ŽįĄŽįš„ã€į¨ŗåŽšįš„ä¸”æœ‰é™įš„īŧˆåĻ‚æžœåŽƒäģŦ是复åˆļįš„īŧŒåˆ™ä¸æ­ĸ一ä¸Ēīŧ‰ã€‚ + +į„ļ后īŧŒäŊ å¯äģĨåœ¨åŽšå™¨įŽĄį†įŗģįģŸįš„配įŊŽä¸­čŽžįŊŽį›¸åŒįš„内存限åˆļ和čĻæą‚īŧˆäž‹åĻ‚åœ¨ **Kubernetes** 中īŧ‰ã€‚ čŋ™æ ˇīŧŒåŽƒå°†čƒŊ够在**å¯į”¨æœē器**中**复åˆļ厚器**īŧŒåŒæ—ļč€ƒč™‘åŽšå™¨æ‰€éœ€įš„å†…å­˜é‡äģĨåŠé›†įž¤ä¸­æœēå™¨ä¸­įš„å¯į”¨å†…å­˜é‡ã€‚ + +åĻ‚æžœäŊ įš„åē”ᔍፋåēåžˆ**įŽ€å•**īŧŒčŋ™å¯čƒŊ**不是闎éĸ˜**īŧŒåšļ且äŊ å¯čƒŊ不需čĻæŒ‡åŽšå†…å­˜é™åˆļ。 äŊ†æ˜¯īŧŒåĻ‚æžœäŊ **äŊŋį”¨å¤§é‡å†…å­˜**īŧˆäž‹åĻ‚äŊŋᔍ**æœē器å­Ļäš **æ¨Ąåž‹īŧ‰īŧŒåˆ™åē”č¯ĨæŖ€æŸĨäŊ æļˆč€—äē†å¤šå°‘内存åšļč°ƒæ•´**每台æœē器**中čŋčĄŒįš„**厚器数量**īŧˆäšŸčŽ¸å¯äģĨå‘é›†įž¤æˇģ加更多æœē器īŧ‰ã€‚ + +åĻ‚æžœäŊ **每ä¸Ē厚器čŋčĄŒå¤šä¸Ēčŋ›į¨‹**īŧˆäž‹åĻ‚äŊŋį”¨åŽ˜æ–š Docker 镜像īŧ‰īŧŒäŊ åŋ…éĄģįĄŽäŋå¯åŠ¨įš„čŋ›į¨‹æ•°é‡ä¸äŧšæļˆč€—æ¯”å¯į”¨å†…å­˜**æ›´å¤šįš„å†…å­˜**。 + +## å¯åŠ¨äš‹å‰įš„æ­ĨéĒ¤å’ŒåŽšå™¨ + +åĻ‚æžœäŊ äŊŋį”¨åŽšå™¨īŧˆäž‹åĻ‚ Docker、Kubernetesīŧ‰īŧŒé‚ŖäšˆäŊ å¯äģĨäŊŋį”¨ä¸¤į§ä¸ģčĻæ–šæŗ•ã€‚ + + +### 多ä¸Ē厚器 + +åĻ‚æžœäŊ æœ‰ **多ä¸Ē厚器**īŧŒå¯čƒŊ每ä¸Ē厚器éƒŊčŋčĄŒä¸€ä¸Ē **单ä¸Ēčŋ›į¨‹**īŧˆäž‹åĻ‚īŧŒåœ¨ **Kubernetes** é›†įž¤ä¸­īŧ‰īŧŒé‚ŖäšˆäŊ å¯čƒŊ希望有一ä¸Ē **单į‹Ŧįš„åŽšå™¨** æ‰§čĄŒäģĨ下操äŊœīŧš 在单ä¸Ē厚器中čŋčĄŒå•ä¸Ēčŋ›į¨‹æ‰§čĄŒ**先前æ­ĨéǤ**īŧŒåŗčŋčĄŒå¤åˆļįš„worker厚器䚋前。 + +!!! info + åĻ‚æžœäŊ äŊŋᔍ KubernetesīŧŒčŋ™å¯čƒŊ是 Init Container。 + +åĻ‚æžœåœ¨äŊ įš„į”¨äž‹ä¸­īŧŒčŋčĄŒå‰éĸįš„æ­ĨéǤ**åšļčĄŒå¤šæŦĄ**æ˛Ąæœ‰é—Žéĸ˜īŧˆäž‹åĻ‚īŧŒåĻ‚æžœäŊ æ˛Ąæœ‰čŋčĄŒæ•°æŽåē“čŋį§ģīŧŒč€ŒåĒæ˜¯æŖ€æŸĨ数捎å瓿˜¯åĻ厞准备åĨŊīŧ‰īŧŒé‚ŖäšˆäŊ äšŸå¯äģĨ将厃äģŦ攞在åŧ€å§‹ä¸ģčŋ›į¨‹äš‹å‰åœ¨æ¯ä¸Ē厚器中。 + +### 单厚器 + +åĻ‚æžœäŊ æœ‰ä¸€ä¸ĒįŽ€å•įš„čŽžįŊŽīŧŒäŊŋᔍ䏀ä¸Ē**单ä¸Ē厚器**īŧŒį„ļ后启动多ä¸Ē**åˇĨäŊœčŋ›į¨‹**īŧˆæˆ–č€…äšŸåĒ是一ä¸Ēčŋ›į¨‹īŧ‰īŧŒé‚ŖäšˆäŊ å¯äģĨ在启动čŋ›į¨‹äš‹å‰åœ¨åē”ᔍፋåēåŒä¸€ä¸Ē厚器中čŋčĄŒå…ˆå‰įš„æ­ĨéĒ¤ã€‚ 厘斚 Docker 镜像内部支持čŋ™ä¸€į‚šã€‚ + +## å¸Ļ有 Gunicorn įš„åŽ˜æ–š Docker 镜像 - Uvicorn + +有一ä¸Ē厘斚 Docker 镜像īŧŒå…ļ中包åĢ与 Uvicorn worker一čĩˇčŋčĄŒįš„ GunicornīŧŒåĻ‚ä¸Šä¸€įĢ æ‰€čŋ°īŧš[æœåŠĄå™¨åˇĨäŊœįēŋፋ - Gunicorn 与 Uvicorn](./server-workers.md){.internal-link target=_blank}。 + +č¯Ĩ镜像ä¸ģčρ圍䏊čŋ°æƒ…å†ĩä¸‹æœ‰į”¨īŧš[å…ˇæœ‰å¤šä¸Ēčŋ›į¨‹å’Œį‰šæŽŠæƒ…å†ĩįš„åŽšå™¨](#containers-with-multiple-processes-and-special-cases)。 + + + +* tiangolo/uvicorn-gunicorn-fastapi. + + +!!! warning + äŊ åžˆæœ‰å¯čƒŊ不需čĻæ­¤åŸēįĄ€é•œåƒæˆ–äģģäŊ•å…ļäģ–įąģäŧŧįš„é•œåƒīŧŒæœ€åĨŊäģŽå¤´åŧ€å§‹æž„åģē镜像īŧŒåĻ‚[上éĸ所čŋ°īŧšä¸ē FastAPI 构åģē Docker 镜像](#build-a-docker-image-for-fastapi)。 + +č¯Ĩ镜像包åĢ一ä¸Ē**č‡ĒåŠ¨č°ƒæ•´**æœēåˆļīŧŒį”¨äēŽæ šæŽå¯į”¨įš„ CPU æ ¸åŋƒčŽžįŊŽ**workerčŋ›į¨‹æ•°**。 + +åŽƒå…ˇæœ‰**åˆį†įš„éģ˜čޤå€ŧ**īŧŒäŊ†äŊ äģį„ļ可äģĨäŊŋᔍ**įŽ¯åĸƒå˜é‡**或配įŊŽæ–‡äģļæ›´æ”šå’Œæ›´æ–°æ‰€æœ‰é…įŊŽã€‚ + +厃čŋ˜æ”¯æŒé€ščŋ‡ä¸€ä¸Ē脚æœŦčŋčĄŒ**åŧ€å§‹å‰įš„先前æ­ĨéǤ** 。 + +!!! tip + čρæŸĨįœ‹æ‰€æœ‰é…įŊŽå’Œé€‰éĄšīŧŒč¯ˇčŊŦ到 Docker 镜像éĄĩéĸīŧš tiangolo/uvicorn-gunicorn-fastapi。 + +### 厘斚 Docker é•œåƒä¸Šįš„čŋ›į¨‹æ•° + +æ­¤é•œåƒä¸Šįš„**čŋ›į¨‹æ•°**æ˜¯æ šæŽå¯į”¨įš„ CPU **æ ¸åŋƒ**č‡ĒåŠ¨čŽĄįŽ—įš„ã€‚ + +čŋ™æ„å‘ŗį€åŽƒå°†å°č¯•å°Ŋ可čƒŊ多地**æĻ¨å–**CPU įš„**性čƒŊ**。 + +äŊ čŋ˜å¯äģĨäŊŋᔍ **įŽ¯åĸƒå˜é‡** į­‰é…įŊŽæĨč°ƒæ•´åŽƒã€‚ + +äŊ†čŋ™äšŸæ„å‘ŗį€īŧŒį”ąäēŽčŋ›į¨‹æ•°é‡å–冺äēŽåŽšå™¨čŋčĄŒįš„ CPUīŧŒå› æ­¤**æļˆč€—įš„å†…å­˜é‡**äšŸå°†å–å†ŗäēŽč¯Ĩ数量。 + +因此īŧŒåĻ‚æžœäŊ įš„åē”ᔍፋåēæļˆč€—大量内存īŧˆäž‹åĻ‚æœē器å­Ļäš æ¨Ąåž‹īŧ‰īŧŒåšļ且äŊ įš„æœåŠĄå™¨æœ‰åžˆå¤š CPU æ ¸åŋƒ**äŊ†å†…存垈少**īŧŒé‚ŖäšˆäŊ įš„厚器最įģˆå¯čƒŊäŧšå°č¯•äŊŋį”¨æ¯”åŽžé™…æƒ…å†ĩæ›´å¤šįš„å†…å­˜ å¯į”¨īŧŒåšļ且性čƒŊäŧšä¸‹é™åžˆå¤šīŧˆį”šč‡ŗå´Šæēƒīŧ‰ã€‚ 🚨 + +### 创åģē一ä¸Ē`Dockerfile` + +äģĨ下是åĻ‚äŊ•栚捎此镜像创åģē`Dockerfile`īŧš + + +```Dockerfile +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9 + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt + +COPY ./app /app +``` + +### æ›´å¤§įš„åē”ᔍፋåē + +åĻ‚æžœäŊ æŒ‰į…§æœ‰å…ŗåˆ›åģē[å…ˇæœ‰å¤šä¸Ē文äģļįš„æ›´å¤§åē”ᔍፋåē](../tutorial/bigger-applications.md){.internal-link target=_blank}įš„éƒ¨åˆ†čŋ›čĄŒæ“äŊœīŧŒäŊ įš„`Dockerfile`可čƒŊįœ‹čĩˇæĨčŋ™æ ˇīŧš + +```Dockerfile hl_lines="7" +FROM tiangolo/uvicorn-gunicorn-fastapi:python3.9 + +COPY ./requirements.txt /app/requirements.txt + +RUN pip install --no-cache-dir --upgrade -r /app/requirements.txt + +COPY ./app /app/app +``` + +### äŊ•æ—ļäŊŋᔍ + +åĻ‚æžœäŊ äŊŋᔍ **Kubernetes** īŧˆæˆ–å…ļäģ–īŧ‰åšļ且äŊ åˇ˛įģåœ¨é›†įž¤įē§åˆĢ莞įŊŽ **复åˆļ**īŧŒåšļä¸”å…ˇæœ‰å¤šä¸Ē **厚器**。 在čŋ™ä盿ƒ…å†ĩ下īŧŒäŊ æœ€åĨŊæŒ‰į…§ä¸Šéĸįš„æčŋ° **äģŽå¤´åŧ€å§‹æž„åģē镜像**īŧš[ä¸ē FastAPI 构åģē Docker 镜像](#build-a-docker-image-for-fastapi)。 + +č¯Ĩ镜像ä¸ģčρ圍[å…ˇæœ‰å¤šä¸Ēčŋ›į¨‹įš„åŽšå™¨å’Œį‰šæŽŠæƒ…å†ĩ](#containers-with-multiple-processes-and-special-cases)中描čŋ°įš„į‰šæŽŠæƒ…å†ĩä¸‹æœ‰į”¨ã€‚ 例åĻ‚īŧŒåĻ‚æžœäŊ įš„åē”ᔍፋåē**čļŗå¤ŸįŽ€å•**īŧŒåŸēäēŽ CPU 莞įŊŽéģ˜čޤčŋ›į¨‹æ•°æ•ˆæžœåžˆåĨŊīŧŒäŊ ä¸æƒŗåœ¨é›†įž¤įē§åˆĢ手动配įŊŽå¤åˆļīŧŒåšļ且不äŧščŋčĄŒæ›´å¤ščŋ›į¨‹, æˆ–č€…äŊ äŊŋᔍ **Docker Compose** čŋ›čĄŒéƒ¨įŊ˛īŧŒåœ¨å•ä¸ĒæœåŠĄå™¨ä¸ŠčŋčĄŒį­‰ã€‚ + +## 部įŊ˛åŽšå™¨é•œåƒ + +æ‹Ĩ有厚器īŧˆDockerīŧ‰é•œåƒåŽīŧŒæœ‰å¤šį§æ–šæŗ•å¯äģĨ部įŊ˛åŽƒã€‚ + +例åĻ‚īŧš + +* 在单ä¸ĒæœåŠĄå™¨ä¸­äŊŋᔍ **Docker Compose** +* äŊŋᔍ **Kubernetes** é›†įž¤ +* äŊŋᔍ Docker Swarm æ¨Ąåŧé›†įž¤ +* äŊŋᔍNomadį­‰å…ļäģ–åˇĨå…ˇ +* äŊŋᔍä瑿œåŠĄčŽˇå–åŽšå™¨é•œåƒåšļ部įŊ˛åރ + +## Docker 镜像与Poetry + +åĻ‚æžœäŊ äŊŋᔍ Poetry æĨįŽĄį†éĄšį›Žįš„äžčĩ–饚īŧŒäŊ å¯äģĨäŊŋᔍ Docker 多é˜ļæŽĩ构åģēīŧš + + + +```{ .dockerfile .annotate } +# (1) +FROM python:3.9 as requirements-stage + +# (2) +WORKDIR /tmp + +# (3) +RUN pip install poetry + +# (4) +COPY ./pyproject.toml ./poetry.lock* /tmp/ + +# (5) +RUN poetry export -f requirements.txt --output requirements.txt --without-hashes + +# (6) +FROM python:3.9 + +# (7) +WORKDIR /code + +# (8) +COPY --from=requirements-stage /tmp/requirements.txt /code/requirements.txt + +# (9) +RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt + +# (10) +COPY ./app /code/app + +# (11) +CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "80"] +``` + +1. čŋ™æ˜¯įŦŦ一é˜ļæŽĩīŧŒį§°ä¸ē`requirements-stage`。 + +2. 将 `/tmp` 莞įŊŽä¸ēåŊ“前åˇĨäŊœį›ŽåŊ•。 + + čŋ™æ˜¯æˆ‘äģŦį”Ÿæˆæ–‡äģļ`requirements.txt`įš„åœ°æ–š + +3. 在此é˜ļæŽĩåŽ‰čŖ…Poetry。 + +4. 将`pyproject.toml`和`poetry.lock`文äģļ复åˆļ到`/tmp`į›ŽåŊ•。 + + 因ä¸ē厃äŊŋᔍ `./poetry.lock*` īŧˆäģĨ `*` įģ“å°žīŧ‰īŧŒæ‰€äģĨåĻ‚æžœč¯Ĩ文äģļå°šä¸å¯į”¨īŧŒåŽƒä¸äŧšå´Šæēƒã€‚ + +5. į”Ÿæˆ`requirements.txt`文äģļ。 + +6. čŋ™æ˜¯æœ€åŽé˜ļæŽĩīŧŒčŋ™é‡Œįš„äģģäŊ•内厚éƒŊ将äŋį•™åœ¨æœ€įģˆįš„厚器镜像中。 + +7. 将åŊ“前åˇĨäŊœį›ŽåŊ•莞įŊŽä¸ē`/code`。 + +8. 将 `requirements.txt` 文äģļ复åˆļ到 `/code` į›ŽåŊ•。 + + č¯Ĩ文äģļäģ…存在äēŽå‰ä¸€ä¸Ēé˜ļæŽĩīŧŒčŋ™å°ąæ˜¯ä¸ēäģ€äšˆæˆ‘äģŦäŊŋᔍ `--from-requirements-stage` æĨ复åˆļ厃。 + +9. åŽ‰čŖ…į”Ÿæˆįš„`requirements.txt`文äģļä¸­įš„äžčĩ–éĄšã€‚ + +10. 将`app`į›ŽåŊ•复åˆļ到`/code`į›ŽåŊ•。 + +11. čŋčĄŒ`uvicorn`å‘Ŋäģ¤īŧŒå‘Šč¯‰åރäŊŋᔍäģŽ`app.main`å¯ŧå…Ĩįš„`app`å¯ščąĄã€‚ + +!!! tip + 单å‡ģæ°”æŗĄæ•°å­—å¯æŸĨįœ‹æ¯čĄŒįš„äŊœį”¨ã€‚ + +**Docker stage** 是 `Dockerfile` įš„ä¸€éƒ¨åˆ†īŧŒį”¨äŊœ **临æ—ļ厚器镜像**īŧŒäģ…ᔍäēŽį”Ÿæˆä¸€äē›į¨åŽäŊŋį”¨įš„æ–‡äģļ。 + +įŦŦ一é˜ļæŽĩäģ…ᔍäēŽ **åŽ‰čŖ… Poetry** åšļäŊŋᔍ Poetry įš„ `pyproject.toml` 文äģļä¸­įš„éĄšį›Žäžčĩ–饚 **į”Ÿæˆ `requirements.txt`**。 + +æ­¤`requirements.txt`文äģļ将在**下一é˜ļæŽĩ**与`pip`一čĩˇäŊŋį”¨ã€‚ + +在最įģˆįš„厚器镜像中**äģ…äŋį•™æœ€åŽé˜ļæŽĩ**。 äš‹å‰įš„é˜ļæŽĩ将čĸĢä¸ĸåŧƒã€‚ + +äŊŋᔍ Poetry æ—ļīŧŒäŊŋᔍ **Docker 多é˜ļæŽĩ构åģē** æ˜¯æœ‰æ„äš‰įš„īŧŒå› ä¸ēäŊ åŽžé™…ä¸Šåšļ不需čĻåœ¨æœ€įģˆįš„åŽšå™¨é•œåƒä¸­åŽ‰čŖ… Poetry 及å…ļ䞝čĩ–饚īŧŒäŊ  **åĒ需čρ** į”Ÿæˆį”¨äēŽåŽ‰čŖ…éĄšį›Žäžčĩ–éĄšįš„`requirements.txt`文äģļ。 + +į„ļ后īŧŒåœ¨ä¸‹ä¸€ä¸Ēīŧˆä🿘¯æœ€åŽä¸€ä¸Ēīŧ‰é˜ļæŽĩīŧŒäŊ å°†æˆ–多或少地äģĨ与前éĸ描čŋ°įš„į›¸åŒįš„æ–šåŧæž„åģē镜像。 + +### 在TLS į숿­ĸäģŖį†åŽéĸ - Poetry + +åŒæ ˇīŧŒåĻ‚æžœäŊ åœ¨ Nginx 或 Traefik į­‰ TLS į숿­ĸäģŖį†īŧˆč´ŸčŊŊå‡čĄĄå™¨īŧ‰åŽéĸčŋčĄŒåŽšå™¨īŧŒč¯ˇå°†é€‰éĄš`--proxy-headers`æˇģ加到å‘Ŋäģ¤ä¸­īŧš + + +```Dockerfile +CMD ["uvicorn", "app.main:app", "--proxy-headers", "--host", "0.0.0.0", "--port", "80"] +``` + +## å›žéĄž + +äŊŋį”¨åŽšå™¨įŗģįģŸīŧˆäž‹åĻ‚äŊŋᔍ**Docker**和**Kubernetes**īŧ‰īŧŒå¤„į†æ‰€æœ‰**部įŊ˛æĻ‚åŋĩ**å˜åž—į›¸åŊ“įŽ€å•īŧš + +* HTTPS +* 启动æ—ļčŋčĄŒ +* 重新启动 +* 复åˆļīŧˆčŋčĄŒįš„čŋ›į¨‹æ•°īŧ‰ +* 内存 +* åŧ€å§‹å‰įš„先前æ­ĨéǤ + +在大多数情å†ĩ下īŧŒäŊ å¯čƒŊä¸æƒŗäŊŋᔍäģģäŊ•åŸēįĄ€é•œåƒīŧŒč€Œæ˜¯åŸēäēŽåŽ˜æ–š Python Docker 镜像 **äģŽå¤´åŧ€å§‹æž„åģē厚器镜像** 。 + +处ᐆåĨŊ`Dockerfile`和 **Docker įŧ“å­˜**中指äģ¤įš„**éĄēåē**īŧŒäŊ å¯äģĨ**最小化构åģēæ—ļ间**īŧŒäģŽč€Œæœ€å¤§é™åēĻ地提éĢ˜į”Ÿäē§åŠ›īŧˆåšļéŋå…æ— čŠīŧ‰ã€‚ 😎 + +在某äē›į‰šæŽŠæƒ…å†ĩ下īŧŒäŊ å¯čƒŊ需čρäŊŋᔍ FastAPI įš„åŽ˜æ–š Docker 镜像。 🤓 From 008be03f31d16699c7319313df998365243b3dcd Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:01:03 +0000 Subject: [PATCH 247/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 43c7ec2445..b07c911d3c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/deployment/docker.md`. PR [#10296](https://github.com/tiangolo/fastapi/pull/10296) by [@xzmeng](https://github.com/xzmeng). * 🌐 Update Spanish translation for `docs/es/docs/features.md`. PR [#10884](https://github.com/tiangolo/fastapi/pull/10884) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Spanish translation for `docs/es/docs/newsletter.md`. PR [#10922](https://github.com/tiangolo/fastapi/pull/10922) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/background-tasks.md`. PR [#5910](https://github.com/tiangolo/fastapi/pull/5910) by [@junah201](https://github.com/junah201). From 49113c35be8c51624da0f74260bd96cb5ff29bc5 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:03:58 +0800 Subject: [PATCH 248/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/project-generation.md`=20(#3831)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/project-generation.md | 84 ++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 docs/zh/docs/project-generation.md diff --git a/docs/zh/docs/project-generation.md b/docs/zh/docs/project-generation.md new file mode 100644 index 0000000000..feafa53331 --- /dev/null +++ b/docs/zh/docs/project-generation.md @@ -0,0 +1,84 @@ +# éĄšį›Žį”Ÿæˆ - æ¨Ąæŋ + +éĄšį›Žį”Ÿæˆå™¨ä¸€čˆŦéƒŊäŧšæäž›åžˆå¤šåˆå§‹čŽžįŊŽã€åމ免æŽĒæ–Ŋ、数捎åē“īŧŒį”šč‡ŗčŋ˜å‡†å¤‡åĨŊäē†įŦŦ一ä¸Ē API įĢ¯į‚šīŧŒčƒŊ帎劊您åŋĢ速上手。 + +éĄšį›Žį”Ÿæˆå™¨įš„čŽžįŊŽé€šå¸¸éƒŊ垈ä¸ģ观īŧŒæ‚¨å¯äģĨ按需更新或äŋŽæ”šīŧŒäŊ†å¯šäēŽæ‚¨įš„éĄšį›ŽæĨ蝴īŧŒåŽƒæ˜¯éžå¸¸åĨŊįš„čĩˇį‚šã€‚ + +## 全栈 FastAPI + PostgreSQL + +GitHubīŧšhttps://github.com/tiangolo/full-stack-fastapi-postgresql + +### 全栈 FastAPI + PostgreSQL - 功čƒŊ + +* åŽŒæ•´įš„ **Docker** 集成īŧˆåŸēäēŽ Dockerīŧ‰ +* Docker Swarm åŧ€å‘æ¨Ąåŧ +* **Docker Compose** æœŦ地åŧ€å‘集成与äŧ˜åŒ– +* **į”Ÿäē§å¯į”¨**įš„ Python įŊ‘į윿œåŠĄå™¨īŧŒäŊŋᔍ Uvicorn 或 Gunicorn +* Python **FastAPI** 后į̝īŧš +* * **速åēĻåŋĢ**īŧšå¯ä¸Ž **NodeJS** 和 **Go** æ¯”č‚Šįš„æžéĢ˜æ€§čƒŊīŧˆåŊ’功äēŽ Starlette 和 Pydanticīŧ‰ + * **į›´č§‚**īŧšåŧēå¤§įš„įŧ–čž‘å™¨æ”¯æŒīŧŒå¤„å¤„įš†å¯č‡Ē动čĄĨ全īŧŒå‡å°‘č°ƒč¯•æ—ļ间 + * **įŽ€å•**īŧšæ˜“å­Ļã€æ˜“į”¨īŧŒé˜…č¯ģæ–‡æĄŖæ‰€éœ€æ—ļé—´æ›´įŸ­ + * **įŽ€įŸ­**īŧšäģŖį é‡å¤æœ€å°åŒ–īŧŒæ¯æŦĄå‚æ•°åŖ°æ˜ŽéƒŊ可äģĨåŽžįŽ°å¤šä¸Ē功čƒŊ + * **åĨåŖŽ**īŧš į”Ÿäē§įē§åˆĢįš„äģŖį īŧŒčŋ˜æœ‰č‡Ē动äē¤äē’æ–‡æĄŖ + * **åŸēäēŽæ ‡å‡†**īŧšåŽŒå…¨å…ŧ厚åšļåŸēäēŽ API åŧ€æ”žæ ‡å‡†īŧšOpenAPI 和 JSON Schema + * **更多功čƒŊ**包æ‹Ŧč‡Ē动éĒŒč¯ã€åēåˆ—化、äē¤äē’æ–‡æĄŖã€OAuth2 JWT äģ¤į‰ŒčēĢäģŊéĒŒč¯į­‰ +* **åŽ‰å…¨å¯†į **īŧŒéģ˜čޤäŊŋį”¨å¯†į å“ˆå¸Œ +* **JWT äģ¤į‰Œ**čēĢäģŊénj蝁 +* **SQLAlchemy** æ¨Ąåž‹īŧˆį‹ŦįĢ‹äēŽ Flask æ‰Šåą•īŧŒå¯į›´æŽĨᔍäēŽ Celery Workerīŧ‰ +* åŸēįĄ€įš„į”¨æˆˇæ¨Ąåž‹īŧˆå¯æŒ‰éœ€äŋŽæ”šæˆ–åˆ é™¤īŧ‰ +* **Alembic** čŋį§ģ +* **CORS**īŧˆčˇ¨åŸŸčĩ„æēå…ąäēĢīŧ‰ +* **Celery** Worker 可äģŽåŽį̝å…ļ厃部分有选拊地å¯ŧå…ĨåšļäŊŋį”¨æ¨Ąåž‹å’ŒäģŖį  +* REST 后į̝æĩ‹č¯•åŸēäēŽ PytestīŧŒåšļ与 Docker 集成īŧŒå¯į‹ŦįĢ‹äēŽæ•°æŽåē“åŽžįŽ°åŽŒæ•´įš„ API äē¤äē’æĩ‹č¯•。因ä¸ē是在 Docker 中čŋčĄŒīŧŒæ¯æŦĄéƒŊ可äģŽå¤´æž„åģēæ–°įš„æ•°æŽå­˜å‚¨īŧˆäŊŋᔍ ElasticSearch、MongoDB、CouchDB į­‰æ•°æŽåē“īŧŒäģ…æĩ‹č¯• API čŋčĄŒīŧ‰ +* Python 与 **Jupyter Kernels** 集成īŧŒį”¨äēŽčŋœį¨‹æˆ– Docker 厚器内部åŧ€å‘īŧŒäŊŋᔍ Atom Hydrogen 或 Visual Studio Code įš„ Jupyter 插äģļ +* **Vue** 前į̝īŧš + * į”ą Vue CLI į”Ÿæˆ + * **JWT čēĢäģŊénj蝁**处ᐆ + * į™ģåŊ•č§†å›ž + * į™ģåŊ•后昞į¤ēä¸ģäģĒčĄ¨į›˜č§†å›ž + * ä¸ģäģĒčĄ¨į›˜æ”¯æŒį”¨æˆˇåˆ›åģē与įŧ–čž‘ + * į”¨æˆˇäŋĄæ¯įŧ–čž‘ + * **Vuex** + * **Vue-router** + * **Vuetify** įžŽåŒ–įģ„äģļ + * **TypeScript** + * åŸēäēŽ **Nginx** įš„ Docker æœåŠĄå™¨īŧˆäŧ˜åŒ–äē† Vue-router 配įŊŽīŧ‰ + * Docker 多é˜ļæŽĩ构åģēīŧŒæ— éœ€äŋå­˜æˆ–提äē¤įŧ–č¯‘įš„äģŖį  + * 在构åģēæ—ļčŋčĄŒå‰į̝æĩ‹č¯•īŧˆå¯įρᔍīŧ‰ + * å°Ŋé‡æ¨Ąå—åŒ–īŧŒåŧ€įŽąåŗį”¨īŧŒäŊ†äģå¯äŊŋᔍ Vue CLI é‡æ–°į”Ÿæˆæˆ–åˆ›åģ翉€éœ€éĄšį›ŽīŧŒæˆ–å¤į”¨æ‰€éœ€å†…åŽš +* äŊŋᔍ **PGAdmin** įŽĄį† PostgreSQL 数捎åē“īŧŒå¯čŊģæžæ›ŋæĸä¸ē PHPMyAdmin 或 MySQL +* äŊŋᔍ **Flower** į›‘æŽ§ Celery äģģåŠĄ +* äŊŋᔍ **Traefik** å¤„į†å‰åŽį̝负čŊŊåšŗčĄĄīŧŒå¯æŠŠå‰åŽįĢ¯æ”žåœ¨åŒä¸€ä¸Ē域下īŧŒæŒ‰čˇ¯åž„分隔īŧŒäŊ†åœ¨ä¸åŒåŽšå™¨ä¸­æäž›æœåŠĄ +* Traefik 集成īŧŒåŒ…æ‹Ŧč‡ĒåŠ¨į”Ÿæˆ Let's Encrypt **HTTPS** 凭蝁 +* GitLab **CI**īŧˆæŒįģ­é›†æˆīŧ‰īŧŒåŒ…æ‹Ŧ前后į̝æĩ‹č¯• + +## 全栈 FastAPI + Couchbase + +GitHubīŧšhttps://github.com/tiangolo/full-stack-fastapi-couchbase + +âš ī¸ **č­Ļ告** âš ī¸ + +åĻ‚æžœæ‚¨æƒŗäģŽå¤´åŧ€å§‹åˆ›åģēæ–°éĄšį›ŽīŧŒåģē莎äŊŋᔍäģĨä¸‹å¤‡é€‰æ–šæĄˆã€‚ + +例åĻ‚īŧŒéĄšį›Žį”Ÿæˆå™¨å…¨æ ˆ FastAPI + PostgreSQL äŧ𿛴适ᔍīŧŒčŋ™ä¸ĒéĄšį›Žįš„įģ´æŠ¤į§¯æžīŧŒį”¨įš„äēē䚟多īŧŒčŋ˜åŒ…æ‹Ŧä熿‰€æœ‰æ–°åŠŸčƒŊ和攚čŋ›å†…厚。 + +åŊ“į„ļīŧŒæ‚¨äšŸå¯äģĨ攞åŋƒäŊŋᔍčŋ™ä¸ĒåŸēäēŽ Couchbase įš„į”Ÿæˆå™¨īŧŒåŽƒäšŸčƒŊæ­Ŗå¸¸äŊŋį”¨ã€‚å°ąįŽ—į”¨åŽƒį”ŸæˆéĄšį›ŽäšŸæ˛Ąæœ‰äģģäŊ•é—Žéĸ˜īŧˆä¸ēä熿›´åĨŊ地æģĄčļŗéœ€æą‚īŧŒæ‚¨å¯äģĨč‡ĒčĄŒæ›´æ–°čŋ™ä¸ĒéĄšį›Žīŧ‰ã€‚ + +č¯Ļ见čĩ„æēäģ“åē“ä¸­įš„æ–‡æĄŖã€‚ + +## 全栈 FastAPI + MongoDB + +â€Ļâ€Ļæ•Ŧč¯ˇæœŸåž…īŧŒåž—įœ‹æˆ‘æœ‰æ˛Ąæœ‰æ—ļ间做čŋ™ä¸ĒéĄšį›Žã€‚đŸ˜… 🎉 + +## FastAPI + spaCy æœē器å­Ļäš æ¨Ąåž‹ + +GitHubīŧšhttps://github.com/microsoft/cookiecutter-spacy-fastapi + +### FastAPI + spaCy æœē器å­Ļäš æ¨Ąåž‹ - 功čƒŊ + +* 集成 **spaCy** NER æ¨Ąåž‹ +* 内įŊŽ **Azure 莤įŸĨ搜į´ĸ**č¯ˇæą‚æ ŧåŧ +* **į”Ÿäē§å¯į”¨**įš„ Python įŊ‘į윿œåŠĄå™¨īŧŒäŊŋᔍ Uvicorn 与 Gunicorn +* 内įŊŽ **Azure DevOps** Kubernetes (AKS) CI/CD åŧ€å‘ +* **多蝭**支持īŧŒå¯åœ¨éĄšį›ŽčŽžįŊŽæ—ļ选拊 spaCy 内įŊŽįš„蝭荀 +* 不äģ…åą€é™äēŽ spaCyīŧŒå¯**čŊģæžæ‰Šåą•**臺å…ļåŽƒæ¨Ąåž‹æĄ†æžļīŧˆPytorch、TensorFlowīŧ‰ From e1119a16cb2e8ac12895945b9f1d20e8f78d3ca6 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:05:04 +0000 Subject: [PATCH 249/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b07c911d3c..2bf05c1ab8 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/project-generation.md`. PR [#3831](https://github.com/tiangolo/fastapi/pull/3831) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/docker.md`. PR [#10296](https://github.com/tiangolo/fastapi/pull/10296) by [@xzmeng](https://github.com/xzmeng). * 🌐 Update Spanish translation for `docs/es/docs/features.md`. PR [#10884](https://github.com/tiangolo/fastapi/pull/10884) by [@pablocm83](https://github.com/pablocm83). * 🌐 Add Spanish translation for `docs/es/docs/newsletter.md`. PR [#10922](https://github.com/tiangolo/fastapi/pull/10922) by [@pablocm83](https://github.com/pablocm83). From 5b0bff3e934754dcad520fdcb3d0167ee6c6b100 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:05:57 +0800 Subject: [PATCH 250/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/history-design-future.md`=20(#3832)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/history-design-future.md | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 docs/zh/docs/history-design-future.md diff --git a/docs/zh/docs/history-design-future.md b/docs/zh/docs/history-design-future.md new file mode 100644 index 0000000000..56a15d0037 --- /dev/null +++ b/docs/zh/docs/history-design-future.md @@ -0,0 +1,78 @@ +# åŽ†å˛ã€čŽžčŽĄã€æœĒæĨ + +不䚅前īŧŒæ›žæœ‰Â **FastAPI** į”¨æˆˇé—Žčŋ‡īŧš + +> čŋ™ä¸ĒéĄšį›Žæœ‰æ€Žæ ˇįš„åŽ†å˛īŧŸåĨŊ像厃åĒᔍäē†å‡ å‘¨å°ąäģŽéģ˜é옿— é—ģ变垗äŧ—所周įŸĨâ€Ļâ€Ļ + +在此īŧŒæˆ‘äģŦįŽ€å•å›žéĄžä¸€ä¸‹ **FastAPI** įš„åŽ†å˛ã€‚ + +## å¤‡é€‰æ–šæĄˆ + +æœ‰é‚Ŗäšˆå‡ åš´īŧŒæˆ‘曞éĸ†å¯ŧ数ä¸Ēåŧ€å‘å›ĸ队ä¸ēč¯¸å¤šå¤æ‚éœ€æą‚åˆ›åģēå„į§ APIīŧŒčŋ™äē›éœ€æą‚包æ‹Ŧæœē器å­Ļ䚠、分布įŗģįģŸã€åŧ‚æ­ĨäģģåŠĄã€NoSQL 数捎åē“į­‰éĸ†åŸŸã€‚ + +äŊœä¸ēåˇĨäŊœįš„一部分īŧŒæˆ‘需čĻč°ƒį ”åžˆå¤šå¤‡é€‰æ–šæĄˆã€čŋ˜čρæĩ‹č¯•åšļ且äŊŋᔍčŋ™äē›å¤‡é€‰æ–šæĄˆã€‚ + +**FastAPI** å…ļ厞åĒ是åģļįģ­äē†čŋ™äē›å‰čžˆįš„åŽ†å˛ã€‚ + +æ­ŖåĻ‚[å¤‡é€‰æ–šæĄˆ](alternatives.md){.internal-link target=_blank}一įĢ æ‰€čŋ°īŧš + +
+æ˛Ąæœ‰å¤§åŽļäš‹å‰æ‰€åšįš„åˇĨäŊœīŧŒ**FastAPI** å°ąä¸äŧšå­˜åœ¨ã€‚ + +äģĨ前创åģēįš„čŋ™äē›åˇĨå…ˇä¸ēåŽƒįš„å‡ēįŽ°æäž›äē†įĩ感。 + +åœ¨é‚Ŗå‡ åš´ä¸­īŧŒæˆ‘ä¸€į›´å›žéŋ创åģēæ–°įš„æĄ†æžļ。éĻ–å…ˆīŧŒæˆ‘å°č¯•äŊŋį”¨å„į§æĄ†æžļ、插äģļ、åˇĨ兎觪冺 **FastAPI** įŽ°åœ¨įš„åŠŸčƒŊ。 + +äŊ†åˆ°äē†ä¸€åŽšį¨‹åēĻ䚋后īŧŒæˆ‘åˆĢ无选拊īŧŒåĒčƒŊäģŽäš‹å‰įš„åˇĨå…ˇä¸­æą˛å–æœ€äŧ˜æ€čˇ¯īŧŒåšļäģĨå°Ŋ量åĨŊįš„æ–šåŧæŠŠčŋ™ä盿€čˇ¯æ•´åˆåœ¨ä¸€čĩˇīŧŒäŊŋį”¨äš‹å‰į”šč‡ŗæ˜¯ä¸æ”¯æŒįš„č¯­č¨€į‰šæ€§īŧˆPython 3.6+ įš„įąģ型提į¤ēīŧ‰īŧŒäģŽč€Œåˆ›åģē一ä¸ĒčƒŊæģĄčļŗæˆ‘æ‰€æœ‰éœ€æą‚įš„æĄ†æžļ。 + +
+ +## č°ƒį ” + +通čŋ‡äŊŋį”¨äš‹å‰æ‰€æœ‰įš„å¤‡é€‰æ–šæĄˆīŧŒæˆ‘有æœēäŧšäģŽåރäģŦ之中å­Ļ到äē†åžˆå¤šä¸œčĨŋīŧŒčŽˇå–äē†åžˆå¤šæƒŗæŗ•īŧŒåšļäģĨæˆ‘å’Œæˆ‘įš„åŧ€å‘å›ĸ队čƒŊæƒŗåˆ°įš„æœ€åĨŊæ–šåŧæŠŠčŋ™ä盿€čˇ¯æ•´åˆæˆä¸€äŊ“。 + +例åĻ‚īŧŒå¤§åŽļéƒŊ清æĨšīŧŒåœ¨į†æƒŗįŠļ态下īŧŒåރåē”č¯ĨåŸēäēŽæ ‡å‡†įš„ Python įąģ型提į¤ē。 + +而且īŧŒæœ€åĨŊįš„æ–šåŧæ˜¯äŊŋį”¨įŽ°æœ‰įš„æ ‡å‡†ã€‚ + +因此īŧŒį”šč‡ŗåœ¨åŧ€å‘ **FastAPI** 前īŧŒæˆ‘å°ąčŠąäē†å‡ ä¸Ēæœˆįš„æ—ļé—´į ”įŠļ OpenAPI、JSON Schema、OAuth2 į­‰č§„čŒƒã€‚æˇąå…Ĩį†č§ŖåŽƒäģŦäš‹é—´įš„å…ŗįŗģ、重叠及åŒēåˆĢ䚋处。 + +## 莞莥 + +į„ļ后īŧŒæˆ‘åˆčŠąäē†ä¸€ä盿—ļ间äģŽį”¨æˆˇč§’åēĻīŧˆäŊŋᔍ FastAPI įš„åŧ€å‘者īŧ‰čŽžčŽĄäē†åŧ€å‘者 **API**。 + +同æ—ļīŧŒæˆ‘čŋ˜åœ¨æœ€æĩčĄŒįš„ Python äģŖį įŧ–čž‘å™¨ä¸­æĩ‹č¯•äē†åžˆå¤šæ€čˇ¯īŧŒåŒ…æ‹Ŧ PyCharm、VS Code、åŸēäēŽ Jedi įš„įŧ–čž‘å™¨ã€‚ + +栚捎最新 Python åŧ€å‘č€…č°ƒį ”æŠĨ告昞į¤ēīŧŒčŋ™å‡ į§įŧ–čž‘å™¨čφᛖäē†įēĻ 80% įš„į”¨æˆˇã€‚ + +äšŸå°ąæ˜¯č¯´īŧŒ**FastAPI** é’ˆå¯šåˇŽä¸å¤š 80% įš„ Python åŧ€å‘者äŊŋį”¨įš„įŧ–čž‘å™¨čŋ›čĄŒä熿ĩ‹č¯•īŧŒč€Œä¸”å…ļ厃大多数įŧ–čž‘å™¨įš„åˇĨäŊœæ–šåŧäšŸä¸Žäš‹įąģäŧŧīŧŒå› æ­¤īŧŒ**FastAPI** įš„äŧ˜åŠŋ几䚎čƒŊ在所有įŧ–čž‘å™¨ä¸ŠäŊ“įŽ°ã€‚ + +通čŋ‡čŋ™į§æ–šåŧīŧŒæˆ‘å°ąčƒŊ扞到å°Ŋ可čƒŊ减少äģŖį é‡å¤įš„æœ€äŊŗæ–šåŧīŧŒčŋ›č€ŒåŽžįŽ°å¤„å¤„éƒŊ有č‡Ē动čĄĨ全、įąģ型提į¤ēä¸Žé”™č¯¯æŖ€æŸĨį­‰æ”¯æŒã€‚ + +所有čŋ™äē›éƒŊ是ä¸ēäē†įģ™åŧ€å‘č€…æäž›æœ€äŊŗįš„åŧ€å‘äŊ“éĒŒã€‚ + +## éœ€æą‚éĄš + +įģčŋ‡æĩ‹č¯•å¤šį§å¤‡é€‰æ–šæĄˆīŧŒæˆ‘最įģˆå†ŗåޚäŊŋᔍ **Pydantic**īŧŒåšļå……åˆ†åˆŠį”¨åŽƒįš„äŧ˜åŠŋ。 + +æˆ‘į”šč‡ŗä¸ē厃做äē†ä¸å°‘č´ĄįŒŽīŧŒčŽŠåŽƒåŽŒįžŽå…ŧ厚äē† JSON SchemaīŧŒæ”¯æŒå¤šį§æ–šåŧåŽšäš‰įēĻæŸåŖ°æ˜ŽīŧŒåšļåŸēäēŽå¤šä¸Ēįŧ–čž‘å™¨īŧŒæ”ščŋ›äē†åŽƒå¯šįŧ–čž‘å™¨æ”¯æŒīŧˆįąģåž‹æŖ€æŸĨ、č‡Ē动čĄĨ全īŧ‰ã€‚ + +在åŧ€å‘期间īŧŒæˆ‘čŋ˜ä¸ē **Starlette** 做äē†ä¸å°‘č´ĄįŒŽīŧŒčŋ™æ˜¯åĻ一ä¸Ēå…ŗé”Žéœ€æą‚éĄšã€‚ + +## åŧ€å‘ + +åŊ“我启动 **FastAPI** åŧ€å‘įš„æ—ļ候īŧŒįģå¤§å¤šæ•°éƒ¨äģļéƒŊ厞įģå°ąäŊīŧŒčŽžčŽĄåˇ˛įģåŽšäš‰īŧŒéœ€æą‚éĄšå’ŒåˇĨå…ˇäšŸåˇ˛įģå‡†å¤‡å°ąįģĒīŧŒį›¸å…ŗæ ‡å‡†ä¸Žč§„čŒƒįš„įŸĨč¯†å‚¨å¤‡äšŸéžå¸¸æ¸…æ™°č€Œæ–°é˛œã€‚ + +## æœĒæĨ + +č‡ŗæ­¤īŧŒ**FastAPI** 及å…ļᐆåŋĩ厞įģä¸ē垈多äē翉€į”¨ã€‚ + +寚äēŽåžˆå¤šį”¨äž‹īŧŒåŽƒæ¯”äģĨå‰åžˆå¤šå¤‡é€‰æ–šæĄˆéƒŊæ›´é€‚į”¨ã€‚ + +垈多åŧ€å‘č€…å’Œåŧ€å‘å›ĸ队厞įģäžčĩ– **FastAPI** åŧ€å‘äģ–äģŦįš„éĄšį›ŽīŧˆåŒ…æ‹Ŧæˆ‘å’Œæˆ‘įš„å›ĸ队īŧ‰ã€‚ + +äŊ†īŧŒ**FastAPI** äģæœ‰åžˆå¤šæ”ščŋ›įš„äŊ™åœ°īŧŒäšŸčŋ˜éœ€čρæˇģåŠ æ›´å¤šįš„åŠŸčƒŊ。 + +æ€ģ之īŧŒ**FastAPI** 前景光明。 + +在此īŧŒæˆ‘äģŦ襡åŋƒæ„Ÿč°ĸ[æ‚¨įš„å¸ŽåŠŠ](help-fastapi.md){.internal-link target=_blank}。 From f81bedd853b2255b0f91107180a336448c422768 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:06:55 +0800 Subject: [PATCH 251/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/deployment/deta.md`=20(#3837)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/deployment/deta.md | 244 ++++++++++++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 docs/zh/docs/deployment/deta.md diff --git a/docs/zh/docs/deployment/deta.md b/docs/zh/docs/deployment/deta.md new file mode 100644 index 0000000000..a7390f7869 --- /dev/null +++ b/docs/zh/docs/deployment/deta.md @@ -0,0 +1,244 @@ +# 在 Deta 上部įŊ˛ FastAPI + +æœŦ节äģ‹įģåĻ‚äŊ•äŊŋᔍ Deta å…č´šæ–šæĄˆéƒ¨įŊ˛ **FastAPI** åē”į”¨ã€‚đŸŽ + +部įŊ˛æ“äŊœéœ€čρ大įēĻ 10 分钟。 + +!!! info "č¯´æ˜Ž" + + Deta 是 **FastAPI** įš„čĩžåŠŠå•†ã€‚ 🎉 + +## åŸēįĄ€ **FastAPI** åē”ᔍ + +* 创åģēåē”į”¨æ–‡äģļ多īŧŒäž‹åĻ‚ `./fastapideta/`īŧŒčŋ›å…Ĩ文äģļ多 + +### FastAPI äģŖį  + +* 创åģē包åĢåς䏋äģŖį įš„ `main.py`īŧš + +```Python +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): + return {"item_id": item_id} +``` + +### éœ€æą‚éĄš + +在文äģļ多里新åģē包åĢåĻ‚ä¸‹å†…åŽšįš„ `requirements.txt` 文äģļīŧš + +```text +fastapi +``` + +!!! tip "提į¤ē" + + 在 Deta 上部įŊ˛æ—ļæ— éœ€åމ誅 UvicornīŧŒč™Ŋį„ļ在æœŦ地æĩ‹č¯•åē”ᔍæ—ļ需čĻåŽ‰čŖ…ã€‚ + +### 文äģļ多æžļ构 + +`./fastapideta/` 文äģļå¤šä¸­įŽ°åœ¨æœ‰ä¸¤ä¸Ē文äģļīŧš + +``` +. +└── main.py +└── requirements.txt +``` + +## 创åģēå…č´š Deta č´Ļåˇ + +创åģēå…č´šįš„ Deta č´ĻåˇīŧŒåĒ需čρį”ĩ子邎äģļå’Œå¯†į ã€‚ + +į”šč‡ŗä¸éœ€čρäŋĄį”¨åĄã€‚ + +## åŽ‰čŖ… CLI + +创åģēč´ĻåˇåŽīŧŒåމ誅 Deta CLIīŧš + +=== "Linux, macOS" + +
+ + ```console + $ curl -fsSL https://get.deta.dev/cli.sh | sh + ``` + +
+ +=== "Windows PowerShell" + +
+ + ```console + $ iwr https://get.deta.dev/cli.ps1 -useb | iex + ``` + +
+ +åŽ‰čŖ…åŽŒ CLI 后īŧŒæ‰“åŧ€æ–°įš„ TerminalīŧŒå°ąčƒŊæŖ€æĩ‹åˆ°åˆšåŽ‰čŖ…įš„ CLI。 + +åœ¨æ–°įš„ Terminal 里īŧŒį”¨äģĨ下å‘Ŋäģ¤įĄŽčޤ CLI 是åĻæ­ŖįĄŽåŽ‰čŖ…īŧš + +
+ +```console +$ deta --help + +Deta command line interface for managing deta micros. +Complete documentation available at https://docs.deta.sh + +Usage: + deta [flags] + deta [command] + +Available Commands: + auth Change auth settings for a deta micro + +... +``` + +
+ +!!! tip "提į¤ē" + + åŽ‰čŖ… CLI 遇到闎éĸ˜æ—ļīŧŒč¯ˇå‚阅 Deta åŽ˜æĄŖã€‚ + +## äŊŋᔍ CLI į™ģåŊ• + +įŽ°åœ¨īŧŒäŊŋᔍ CLI į™ģåŊ• Detaīŧš + +
+ +```console +$ deta login + +Please, log in from the web page. Waiting.. +Logged in successfully. +``` + +
+ +čŋ™ä¸Ēå‘Ŋäģ¤äŧ𿉓åŧ€æĩč§ˆå™¨åšļč‡Ē动énj蝁čēĢäģŊ。 + +## äŊŋᔍ Deta 部įŊ˛ + +æŽĨ下æĨīŧŒäŊŋᔍ Deta CLI 部įŊ˛åē”ᔍīŧš + +
+ +```console +$ deta new + +Successfully created a new micro + +// Notice the "endpoint" 🔍 + +{ + "name": "fastapideta", + "runtime": "python3.7", + "endpoint": "https://qltnci.deta.dev", + "visor": "enabled", + "http_auth": "enabled" +} + +Adding dependencies... + + +---> 100% + + +Successfully installed fastapi-0.61.1 pydantic-1.7.2 starlette-0.13.6 +``` + +
+ +您äŧšįœ‹åˆ°åς䏋 JSON äŋĄæ¯īŧš + +```JSON hl_lines="4" +{ + "name": "fastapideta", + "runtime": "python3.7", + "endpoint": "https://qltnci.deta.dev", + "visor": "enabled", + "http_auth": "enabled" +} +``` + +!!! tip "提į¤ē" + + 您部įŊ˛æ—ļįš„ `"endpoint"` URL 可čƒŊäŧšæœ‰æ‰€ä¸åŒã€‚ + +## æŸĨįœ‹æ•ˆæžœ + +打åŧ€æĩč§ˆå™¨īŧŒčˇŗčŊŦ到 `endpoint` URL。æœŦ䞋中是 `https://qltnci.deta.dev`īŧŒäŊ†æ‚¨įš„铞æŽĨ可čƒŊ与此不同。 + +FastAPI åē”ᔍäŧščŋ”回åς䏋 JSON 响åē”īŧš + +```JSON +{ + "Hello": "World" +} +``` + +æŽĨ下æĨīŧŒčˇŗčŊŦ到 API æ–‡æĄŖ `/docs`īŧŒæœŦ䞋中是 `https://qltnci.deta.dev/docs`。 + +æ–‡æĄŖæ˜žį¤ēåς䏋īŧš + + + +## 吝ᔍå…Ŧåŧ€čŽŋ问 + +éģ˜čŽ¤æƒ…å†ĩ下īŧŒDeta äŊŋį”¨æ‚¨įš„č´Ļåˇ Cookies 处ᐆčēĢäģŊéĒŒč¯ã€‚ + +åē”į”¨ä¸€åˆ‡å°ąįģĒ䚋后īŧŒäŊŋᔍåς䏋å‘Ŋäģ¤čŽŠå…Ŧäŧ—䚟čƒŊįœ‹åˆ°æ‚¨įš„åē”ᔍīŧš + +
+ +```console +$ deta auth disable + +Successfully disabled http auth +``` + +
+ +įŽ°åœ¨īŧŒå°ąå¯äģĨ把 URL 分äēĢįģ™å¤§åŽļīŧŒäģ–äģŦå°ąčƒŊčŽŋé—Žæ‚¨įš„ API äē†ã€‚đŸš€ + +## HTTPS + +恭喜īŧæ‚¨åˇ˛įģåœ¨ Deta 上部įŊ˛äē† FastAPI åē”ᔍīŧđŸŽ‰ 🍰 + +čŋ˜čĻæŗ¨æ„īŧŒDeta čƒŊå¤Ÿæ­ŖįĄŽå¤„į† HTTPSīŧŒå› æ­¤æ‚¨ä¸åŋ…操åŋƒ HTTPSīŧŒæ‚¨įš„åŽĸæˆˇįĢ¯č‚¯åŽščƒŊæœ‰åŽ‰å…¨åŠ å¯†įš„čŋžæŽĨ。 ✅ 🔒 + +## æŸĨįœ‹ Visor + +äģŽ API æ–‡æĄŖīŧˆURL 是 `https://gltnci.deta.dev/docs`īŧ‰å‘é€č¯ˇæą‚č‡ŗ*čˇ¯åž„æ“äŊœ* `/items/{item_id}`。 + +例åĻ‚īŧŒID `5`。 + +įŽ°åœ¨čˇŗčŊŦ臺 https://web.deta.sh。 + +åˇĻčžšæ æœ‰ä¸Ē "Micros" æ ‡į­žīŧŒé‡Œéĸæ˜¯æ‰€æœ‰įš„åē”į”¨ã€‚ + +čŋ˜æœ‰ä¸€ä¸Ē **Details** 和 **Visor** æ ‡į­žīŧŒčˇŗčŊŦ到 **Visor** æ ‡į­žã€‚ + +在čŋ™é‡ŒæŸĨįœ‹æœ€čŋ‘发送įģ™åē”į”¨įš„č¯ˇæą‚ã€‚ + +您可äģĨįŧ–čž‘æˆ–é‡æ–°äŊŋᔍčŋ™äē›č¯ˇæą‚。 + + + +## 更多内厚 + +åĻ‚æžœčĻæŒäš…åŒ–äŋå­˜åē”į”¨æ•°æŽīŧŒå¯äģĨäŊŋį”¨æäž›äē†**å…č´šæ–šæĄˆ**įš„ Deta Base。 + +č¯Ļ见 Deta åŽ˜æĄŖã€‚ From 6008c04e2e05a75accd6f61ee67ebe48e9fe0ac9 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:07:45 +0000 Subject: [PATCH 252/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 2bf05c1ab8..9edf728b7a 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/history-design-future.md`. PR [#3832](https://github.com/tiangolo/fastapi/pull/3832) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/project-generation.md`. PR [#3831](https://github.com/tiangolo/fastapi/pull/3831) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/docker.md`. PR [#10296](https://github.com/tiangolo/fastapi/pull/10296) by [@xzmeng](https://github.com/xzmeng). * 🌐 Update Spanish translation for `docs/es/docs/features.md`. PR [#10884](https://github.com/tiangolo/fastapi/pull/10884) by [@pablocm83](https://github.com/pablocm83). From a54ca1487607b71f94ab721b5117abf41460620a Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:08:47 +0000 Subject: [PATCH 253/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 9edf728b7a..189e217ea0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/deployment/deta.md`. PR [#3837](https://github.com/tiangolo/fastapi/pull/3837) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/history-design-future.md`. PR [#3832](https://github.com/tiangolo/fastapi/pull/3832) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/project-generation.md`. PR [#3831](https://github.com/tiangolo/fastapi/pull/3831) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/docker.md`. PR [#10296](https://github.com/tiangolo/fastapi/pull/10296) by [@xzmeng](https://github.com/xzmeng). From 1e8b44f3e4c48528480367b4a8f44b1d7cfb8462 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:09:26 +0800 Subject: [PATCH 254/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/testing-database.md`=20(#382?= =?UTF-8?q?1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/testing-database.md | 97 +++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 docs/zh/docs/advanced/testing-database.md diff --git a/docs/zh/docs/advanced/testing-database.md b/docs/zh/docs/advanced/testing-database.md new file mode 100644 index 0000000000..8dc95c25f4 --- /dev/null +++ b/docs/zh/docs/advanced/testing-database.md @@ -0,0 +1,97 @@ +# æĩ‹č¯•数捎åē“ + +您čŋ˜å¯äģĨäŊŋᔍ[æĩ‹č¯•䞝čĩ–饚](testing-dependencies.md){.internal-link target=_blank}ä¸­įš„čĻ†į›–äžčĩ–éĄšæ–šæŗ•å˜æ›´æĩ‹č¯•įš„æ•°æŽåē“。 + +åŽžįŽ°čŽžįŊŽå…ļ厃æĩ‹č¯•数捎åē“、在æĩ‹č¯•后回æģšæ•°æŽã€æˆ–éĸ„åĄĢæĩ‹č¯•æ•°æŽį­‰æ“äŊœã€‚ + +æœŦįĢ įš„ä¸ģčĻæ€čˇ¯ä¸Žä¸Šä¸€įĢ åŽŒå…¨į›¸åŒã€‚ + +## ä¸ē SQL åē”ᔍæˇģ加æĩ‹č¯• + +ä¸ēäē†äŊŋᔍæĩ‹č¯•数捎åē“īŧŒæˆ‘äģŦčĻå‡įē§ [SQL å…ŗįŗģ型数捎åē“](../tutorial/sql-databases.md){.internal-link target=_blank} 一įĢ ä¸­įš„į¤ē䞋。 + +åē”į”¨įš„æ‰€æœ‰äģŖį éƒŊä¸€æ ˇīŧŒį›´æŽĨæŸĨįœ‹é‚Ŗä¸€įĢ įš„į¤ē例äģŖį åŗå¯ã€‚ + +æœŦįĢ åĒ是新æˇģ加ä熿ĩ‹č¯•æ–‡äģļ。 + +æ­Ŗå¸¸įš„äžčĩ–饚 `get_db()` čŋ”回数捎åē“äŧšč¯ã€‚ + +æĩ‹č¯•æ—ļäŊŋᔍčĻ†į›–äžčĩ–饚čŋ”回č‡Ē厚䚉数捎åē“äŧšč¯äģŖæ›ŋæ­Ŗå¸¸įš„äžčĩ–éĄšã€‚ + +æœŦ例中īŧŒčĻåˆ›åģēäģ…ᔍäēŽæĩ‹č¯•įš„ä¸´æ—ļ数捎åē“。 + +## 文äģļæžļæž„ + +创åģēæ–°æ–‡äģļ `sql_app/tests/test_sql_app.py`。 + +因此īŧŒæ–°įš„æ–‡äģļæžļæž„åς䏋īŧš + +``` hl_lines="9-11" +. +└── sql_app + ├── __init__.py + ├── crud.py + ├── database.py + ├── main.py + ├── models.py + ├── schemas.py + └── tests + ├── __init__.py + └── test_sql_app.py +``` + +## 创åģēæ–°įš„æ•°æŽåē“äŧšč¯ + +éĻ–å…ˆīŧŒä¸ē新åģēæ•°æŽåē“创åģēæ–°įš„æ•°æŽåē“äŧšč¯ã€‚ + +æĩ‹č¯•æ—ļīŧŒäŊŋᔍ `test.db` æ›ŋäģŖ `sql_app.db`。 + +äŊ†å…ļäŊ™įš„äŧšč¯äģŖį åŸēæœŦ上éƒŊæ˜¯ä¸€æ ˇįš„īŧŒåĒčĻå¤åˆļå°ąå¯äģĨäē†ã€‚ + +```Python hl_lines="8-13" +{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!} +``` + +!!! tip "提į¤ē" + + ä¸ē减少äģŖį é‡å¤īŧŒæœ€åĨŊ把čŋ™æŽĩäģŖį å†™æˆå‡Ŋ数īŧŒåœ¨ `database.py` 与 `tests/test_sql_app.py`中äŊŋį”¨ã€‚ + + ä¸ēä熿ŠŠæŗ¨æ„åŠ›é›†ä¸­åœ¨æĩ‹č¯•äģŖį ä¸ŠīŧŒæœŦ例åĒ是复åˆļäē†čŋ™æŽĩäģŖį ã€‚ + +## 创åģēæ•°æŽåē“ + +因ä¸ēįŽ°åœ¨æ˜¯æƒŗåœ¨æ–°æ–‡äģļ中äŊŋį”¨æ–°æ•°æŽåē“īŧŒæ‰€äģĨčρäŊŋᔍäģĨ下äģŖį åˆ›åģēæ•°æŽåē“īŧš + +```Python +Base.metadata.create_all(bind=engine) +``` + +一čˆŦ是在 `main.py` ä¸­č°ƒį”¨čŋ™čĄŒäģŖį īŧŒäŊ†åœ¨ `main.py` 里īŧŒčŋ™čĄŒäģŖį į”¨äēŽåˆ›åģē `sql_app.db`īŧŒäŊ†æ˜¯įŽ°åœ¨čρä¸ēæĩ‹č¯•创åģē `test.db`。 + +因此īŧŒčρ圍æĩ‹č¯•äģŖį ä¸­æˇģ加čŋ™čĄŒäģŖį åˆ›åģēæ–°įš„æ•°æŽå瓿–‡äģļ。 + +```Python hl_lines="16" +{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!} +``` + +## čĻ†į›–äžčĩ–饚 + +æŽĨ下æĨīŧŒåˆ›åģēčĻ†į›–äžčĩ–饚īŧŒåšļä¸ēåē”ᔍæˇģ加čĻ†į›–å†…åŽšã€‚ + +```Python hl_lines="19-24 27" +{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!} +``` + +!!! tip "提į¤ē" + + `overrider_get_db()` 与 `get_db` įš„äģŖį å‡ äšŽåŽŒå…¨ä¸€æ ˇīŧŒåĒ是 `overrider_get_db` 中äŊŋᔍæĩ‹č¯•数捎åē“įš„ `TestingSessionLocal`。 + +## æĩ‹č¯•åē”ᔍ + +į„ļ后īŧŒå°ąå¯äģĨæ­Ŗå¸¸æĩ‹č¯•äē†ã€‚ + +```Python hl_lines="32-47" +{!../../../docs_src/sql_databases/sql_app/tests/test_sql_app.py!} +``` + +æĩ‹č¯•期间īŧŒæ‰€æœ‰åœ¨æ•°æŽåē“ä¸­æ‰€åšįš„äŋŽæ”šéƒŊ在 `test.db` 里īŧŒä¸äŧšåŊąå“ä¸ģåē”į”¨įš„ `sql_app.db`。 From 539e032b2d93150a2101a102ed6020b96bd8e325 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:11:59 +0000 Subject: [PATCH 255/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 189e217ea0..c36c220b9c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-database.md`. PR [#3821](https://github.com/tiangolo/fastapi/pull/3821) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/deta.md`. PR [#3837](https://github.com/tiangolo/fastapi/pull/3837) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/history-design-future.md`. PR [#3832](https://github.com/tiangolo/fastapi/pull/3832) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/project-generation.md`. PR [#3831](https://github.com/tiangolo/fastapi/pull/3831) by [@jaystone776](https://github.com/jaystone776). From 4b7fa89f4ed09fc447c7d82c46c0f1843393639d Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:12:29 +0800 Subject: [PATCH 256/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/testing-websockets.md`=20(#3?= =?UTF-8?q?817)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/testing-websockets.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 docs/zh/docs/advanced/testing-websockets.md diff --git a/docs/zh/docs/advanced/testing-websockets.md b/docs/zh/docs/advanced/testing-websockets.md new file mode 100644 index 0000000000..f303e1d67c --- /dev/null +++ b/docs/zh/docs/advanced/testing-websockets.md @@ -0,0 +1,13 @@ +# æĩ‹č¯• WebSockets + +æĩ‹č¯• WebSockets 也äŊŋᔍ `TestClient`。 + +ä¸ēæ­¤īŧŒčρ圍 `with` 蝭åĨ中äŊŋᔍ `TestClient` čŋžæŽĨ WebSocket。 + +```Python hl_lines="27-31" +{!../../../docs_src/app_testing/tutorial002.py!} +``` + +!!! note "įŦ”čް" + + 更多įģ†čŠ‚č¯Ļ见 Starlette åŽ˜æĄŖ - æĩ‹č¯• WebSockets。 From 92cf191f1ff0989b85126c1cd2860b511b86539a Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:17:01 +0000 Subject: [PATCH 257/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index c36c220b9c..c9a2fc3da9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-websockets.md`. PR [#3817](https://github.com/tiangolo/fastapi/pull/3817) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-database.md`. PR [#3821](https://github.com/tiangolo/fastapi/pull/3821) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/deta.md`. PR [#3837](https://github.com/tiangolo/fastapi/pull/3837) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/history-design-future.md`. PR [#3832](https://github.com/tiangolo/fastapi/pull/3832) by [@jaystone776](https://github.com/jaystone776). From eaf394d3646aef4e73eaf84168506a9dc78f76d1 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:21:02 +0800 Subject: [PATCH 258/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/testing-events.md`=20(#3818)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/testing-events.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 docs/zh/docs/advanced/testing-events.md diff --git a/docs/zh/docs/advanced/testing-events.md b/docs/zh/docs/advanced/testing-events.md new file mode 100644 index 0000000000..222a67c8cf --- /dev/null +++ b/docs/zh/docs/advanced/testing-events.md @@ -0,0 +1,7 @@ +# æĩ‹č¯•äē‹äģļīŧšå¯åЍ - å…ŗé—­ + +äŊŋᔍ `TestClient` 和 `with` 蝭åĨīŧŒåœ¨æĩ‹č¯•中čŋčĄŒäē‹äģļ处ᐆ噍īŧˆ`startup` 与 `shutdown`īŧ‰ã€‚ + +```Python hl_lines="9-12 20-24" +{!../../../docs_src/app_testing/tutorial003.py!} +``` From fc4606e1d005549c324641e882c91cce795b9687 Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:22:37 +0800 Subject: [PATCH 259/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/behind-a-proxy.md`=20(#3820)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/behind-a-proxy.md | 351 ++++++++++++++++++++++++ 1 file changed, 351 insertions(+) create mode 100644 docs/zh/docs/advanced/behind-a-proxy.md diff --git a/docs/zh/docs/advanced/behind-a-proxy.md b/docs/zh/docs/advanced/behind-a-proxy.md new file mode 100644 index 0000000000..738bd7119b --- /dev/null +++ b/docs/zh/docs/advanced/behind-a-proxy.md @@ -0,0 +1,351 @@ +# äŊŋᔍäģŖį† + +有ä盿ƒ…å†ĩ下īŧŒæ‚¨å¯čƒŊčρäŊŋᔍ Traefik 或 Nginx į­‰**äģŖį†**æœåŠĄå™¨īŧŒåšļæˇģ加åē”į”¨ä¸čƒŊ蝆åˆĢįš„é™„åŠ čˇ¯åž„å‰įŧ€é…įŊŽã€‚ + +æ­¤æ—ļīŧŒčρäŊŋᔍ `root_path` 配įŊŽåē”į”¨ã€‚ + +`root_path` 是 ASGI č§„čŒƒæäž›įš„æœēåˆļīŧŒFastAPI å°ąæ˜¯åŸēäēŽæ­¤č§„čŒƒåŧ€å‘įš„īŧˆé€ščŋ‡ Starletteīŧ‰ã€‚ + +`root_path` ᔍäēŽå¤„ᐆčŋ™äē›į‰šåŽšæƒ…å†ĩ。 + +在挂čŊŊ子åē”ᔍæ—ļīŧŒäšŸå¯äģĨ在内部äŊŋį”¨ã€‚ + +## į§ģé™¤čˇ¯åž„å‰įŧ€įš„äģŖį† + +æœŦ例中īŧŒį§ģé™¤čˇ¯åž„å‰įŧ€įš„äģŖį†æ˜¯æŒ‡åœ¨äģŖį ä¸­åŖ°æ˜Žčˇ¯åž„ `/app`īŧŒį„ļ后在åē”ᔍéĄļåą‚æˇģ加äģŖį†īŧŒæŠŠ **FastAPI** åē”į”¨æ”žåœ¨ `/api/v1` čˇ¯åž„ä¸‹ã€‚ + +æœŦäž‹įš„åŽŸå§‹čˇ¯åž„ `/app` 厞际上是在 `/api/v1/app` æäž›æœåŠĄã€‚ + +å“Ē怕所有äģŖį éƒŊå‡čŽžåĒ有 `/app`。 + +äģŖį†åĒåœ¨æŠŠč¯ˇæą‚äŧ é€įģ™ Uvicorn 䚋前才äŧš**į§ģé™¤čˇ¯åž„å‰įŧ€**īŧŒčŽŠåē”ᔍäģĨä¸ē厃是在 `/app` æäž›æœåŠĄīŧŒå› æ­¤ä¸åŋ…在äģŖį ä¸­åŠ å…Ĩ前įŧ€ `/api/v1`。 + +äŊ†äš‹åŽīŧŒåœ¨īŧˆå‰į̝īŧ‰æ‰“åŧ€ API æ–‡æĄŖæ—ļīŧŒäģŖį†äŧščĻæą‚åœ¨ `/openapi.json`īŧŒč€Œä¸æ˜¯ `/api/v1/openapi.json` 中提取 OpenAPI æĻ‚回。 + +因此īŧŒ īŧˆčŋčĄŒåœ¨æĩč§ˆå™¨ä¸­įš„īŧ‰å‰į̝äŧšå°č¯•čŽŋ问 `/openapi.json`īŧŒäŊ†æ˛Ąæœ‰åŠžæŗ•čŽˇå– OpenAPI æĻ‚回。 + +čŋ™æ˜¯å› ä¸ēåē”ᔍäŊŋᔍäē†äģĨ `/api/v1` ä¸ēčˇ¯åž„å‰įŧ€įš„äģŖį†īŧŒå‰į̝čρäģŽ `/api/v1/openapi.json` 中提取 OpenAPI æĻ‚回。 + +```mermaid +graph LR + +browser("Browser") +proxy["Proxy on http://0.0.0.0:9999/api/v1/app"] +server["Server on http://127.0.0.1:8000/app"] + +browser --> proxy +proxy --> server +``` + +!!! tip "提į¤ē" + + IP `0.0.0.0` 叏ᔍäēŽæŒ‡į¨‹åēį›‘åŦæœŦæœēæˆ–æœåŠĄå™¨ä¸Šįš„æ‰€æœ‰æœ‰æ•ˆ IP。 + +API æ–‡æĄŖčŋ˜éœ€čρ OpenAPI æĻ‚å›žåŖ°æ˜Ž API `server` äŊäēŽ `/api/v1`īŧˆäŊŋᔍäģŖį†æ—ļįš„ URLīŧ‰ã€‚äž‹åĻ‚īŧš + +```JSON hl_lines="4-8" +{ + "openapi": "3.0.2", + // More stuff here + "servers": [ + { + "url": "/api/v1" + } + ], + "paths": { + // More stuff here + } +} +``` + +æœŦäž‹ä¸­įš„ `Proxy` 是 **Traefik**īŧŒ`server` 是čŋčĄŒ FastAPI åē”į”¨įš„ **Uvicorn**。 + +### 提䞛 `root_path` + +ä¸ēæ­¤īŧŒčρäģĨåĻ‚ä¸‹æ–šåŧäŊŋᔍå‘Ŋäģ¤čĄŒé€‰éĄš `--root-path`īŧš + +
+ +```console +$ uvicorn main:app --root-path /api/v1 + +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +``` + +
+ +Hypercorn 䚟支持 `--root-path `é€‰éĄšã€‚ + +!!! note "技术įģ†čŠ‚" + + ASGI č§„čŒƒåŽšäš‰įš„ `root_path` å°ąæ˜¯ä¸ēäē†čŋ™į§į”¨äž‹ã€‚ + + åšļ且 `--root-path` å‘Ŋäģ¤čĄŒé€‰éĄšæ”¯æŒ `root_path`。 + +### æŸĨįœ‹åŊ“å‰įš„ `root_path` + +čŽˇå–åē”ᔍä¸ē每ä¸Ēč¯ˇæą‚äŊŋį”¨įš„åŊ“前 `root_path`īŧŒčŋ™æ˜¯ `scope` å­—å…¸įš„å†…åŽšīŧˆä🿘¯ ASGI č§„čŒƒįš„å†…åŽšīŧ‰ã€‚ + +我äģŦ在čŋ™é‡Œįš„äŋĄæ¯é‡ŒåŒ…åĢ `roo_path` åĒ是ä¸ēä熿ŧ”į¤ē。 + +```Python hl_lines="8" +{!../../../docs_src/behind_a_proxy/tutorial001.py!} +``` + +į„ļ后īŧŒį”¨äģĨ下å‘Ŋäģ¤å¯åЍ Uvicornīŧš + +
+ +```console +$ uvicorn main:app --root-path /api/v1 + +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +``` + +
+ +čŋ”å›žįš„å“åē”åς䏋īŧš + +```JSON +{ + "message": "Hello World", + "root_path": "/api/v1" +} +``` + +### 在 FastAPI åē”į”¨é‡ŒčŽžįŊŽ `root_path` + +čŋ˜æœ‰ä¸€į§æ–šæĄˆīŧŒåĻ‚æžœä¸čƒŊ提䞛 `--root-path` æˆ–į­‰æ•ˆįš„å‘Ŋäģ¤čĄŒé€‰éĄšīŧŒåˆ™åœ¨åˆ›åģē FastAPI åē”ᔍæ—ļčĻčŽžįŊŽ `root_path` 参数。 + +```Python hl_lines="3" +{!../../../docs_src/behind_a_proxy/tutorial002.py!} +``` + +äŧ é€’ `root_path` įģ™ `FastAPI` 与äŧ é€’ `--root-path` å‘Ŋäģ¤čĄŒé€‰éĄšįģ™ Uvicorn 或 Hypercorn ä¸€æ ˇã€‚ + +### å…ŗäēŽ `root_path` + +æŗ¨æ„īŧŒæœåŠĄå™¨īŧˆUvicornīŧ‰åĒ是把 `root_path` äŧ é€’įģ™åē”į”¨ã€‚ + +在æĩč§ˆå™¨ä¸­čž“å…Ĩ http://127.0.0.1:8000/app æ—ļčƒŊįœ‹åˆ°æ ‡å‡†å“åē”īŧš + +```JSON +{ + "message": "Hello World", + "root_path": "/api/v1" +} +``` + +厃不čĻæą‚čŽŋ问 `http://127.0.0.1:800/api/v1/app`。 + +Uvicorn éĸ„期äģŖį†åœ¨ `http://127.0.0.1:8000/app` čŽŋ问 UvicornīŧŒč€Œåœ¨éĄļ部æˇģ加 `/api/v1` 前įŧ€æ˜¯äģŖį†čĻåšįš„ä狿ƒ…。 + +## å…ŗäēŽį§ģé™¤čˇ¯åž„å‰įŧ€įš„äģŖį† + +æŗ¨æ„īŧŒį§ģé™¤čˇ¯åž„å‰įŧ€įš„äģŖį†åĒ是配įŊŽäģŖį†įš„æ–šåŧäš‹ä¸€ã€‚ + +大部分情å†ĩ下īŧŒäģŖį†éģ˜čޤéƒŊ不äŧšį§ģé™¤čˇ¯åž„å‰įŧ€ã€‚ + +īŧˆæœĒį§ģé™¤čˇ¯åž„å‰įŧ€æ—ļīŧ‰äģŖį†į›‘åŦ `https://myawesomeapp.com` į­‰å¯ščąĄīŧŒåĻ‚æžœæĩč§ˆå™¨čˇŗčŊŦ到 `https://myawesomeapp.com/api/v1/app`īŧŒä¸”æœåŠĄå™¨īŧˆäž‹åĻ‚ Uvicornīŧ‰į›‘åŦ `http://127.0.0.1:8000` äģŖį†īŧˆæœĒį§ģé™¤čˇ¯åž„å‰įŧ€īŧ‰ äŧšåœ¨åŒæ ˇįš„čˇ¯åž„īŧš`http://127.0.0.1:8000/api/v1/app` čŽŋ问 Uvicorn。 + +## æœŦ地æĩ‹č¯• Traefik + +您可äģĨčŊ쿘“地在æœŦ地äŊŋᔍ Traefik čŋčĄŒį§ģé™¤čˇ¯åž„å‰įŧ€įš„蝕éĒŒã€‚ + +下čŊŊ TraefikīŧŒčŋ™æ˜¯ä¸€ä¸ĒäēŒčŋ›åˆļ文äģļīŧŒéœ€čĻč§ŖåŽ‹æ–‡äģļīŧŒåšļ在 Terminal 䏭ᛴæŽĨčŋčĄŒã€‚ + +į„ļ后创åģē包åĢåĻ‚ä¸‹å†…åŽšįš„ `traefik.toml` 文äģļīŧš + +```TOML hl_lines="3" +[entryPoints] + [entryPoints.http] + address = ":9999" + +[providers] + [providers.file] + filename = "routes.toml" +``` + +čŋ™ä¸Ē文äģᅧŠ Traefik ᛑåŦįĢ¯åŖčŽžįŊŽä¸ē `9999`īŧŒåšļ莞įŊŽčρäŊŋᔍåĻ一ä¸Ē文äģļ `routes.toml`。 + +!!! tip "提į¤ē" + + äŊŋᔍįĢ¯åŖ 9999 äģŖæ›ŋæ ‡å‡†įš„ HTTP įĢ¯åŖ 80īŧŒčŋ™æ ˇå°ąä¸åŋ…äŊŋį”¨įŽĄį†å‘˜æƒé™čŋčĄŒīŧˆ`sudo`īŧ‰ã€‚ + +æŽĨ下æĨīŧŒåˆ›åģē `routes.toml`īŧš + +```TOML hl_lines="5 12 20" +[http] + [http.middlewares] + + [http.middlewares.api-stripprefix.stripPrefix] + prefixes = ["/api/v1"] + + [http.routers] + + [http.routers.app-http] + entryPoints = ["http"] + service = "app" + rule = "PathPrefix(`/api/v1`)" + middlewares = ["api-stripprefix"] + + [http.services] + + [http.services.app] + [http.services.app.loadBalancer] + [[http.services.app.loadBalancer.servers]] + url = "http://127.0.0.1:8000" +``` + +čŋ™ä¸Ē文äģļ配įŊŽ Traefik äŊŋį”¨čˇ¯åž„å‰įŧ€ `/api/v1`。 + +į„ļ后īŧŒåŽƒæŠŠč¯ˇæą‚é‡åŽšäŊåˆ°čŋčĄŒåœ¨ `http://127.0.0.1:8000` ä¸Šįš„ Uvicorn。 + +įŽ°åœ¨īŧŒå¯åЍ Traefikīŧš + +
+ +```console +$ ./traefik --configFile=traefik.toml + +INFO[0000] Configuration loaded from file: /home/user/awesomeapi/traefik.toml +``` + +
+ +æŽĨ下æĨīŧŒäŊŋᔍ Uvicorn 启动åē”ᔍīŧŒåšļäŊŋᔍ `--root-path` 选项īŧš + +
+ +```console +$ uvicorn main:app --root-path /api/v1 + +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +``` + +
+ +### æŸĨįœ‹å“åē” + +čŽŋ问åĢ Uvicorn įĢ¯åŖįš„ URLīŧšhttp://127.0.0.1:8000/appīŧŒå°ąčƒŊįœ‹åˆ°æ ‡å‡†å“åē”īŧš + +```JSON +{ + "message": "Hello World", + "root_path": "/api/v1" +} +``` + +!!! tip "提į¤ē" + + æŗ¨æ„īŧŒå°ąįŽ—čŽŋ问 `http://127.0.0.1:8000/app`īŧŒä🿘žį¤ēäģŽé€‰éĄš `--root-path` ä¸­æå–įš„ `/api/v1`īŧŒčŋ™æ˜¯ `root_path` įš„å€ŧ。 + +打åŧ€åĢ Traefik įĢ¯åŖįš„ URLīŧŒåŒ…åĢčˇ¯åž„å‰įŧ€īŧšhttp://127.0.0.1:9999/api/v1/app。 + +åž—åˆ°åŒæ ˇįš„å“åē”īŧš + +```JSON +{ + "message": "Hello World", + "root_path": "/api/v1" +} +``` + +äŊ†čŋ™ä¸€æŦĄ URL 包åĢäē†äģŖį†æäž›įš„čˇ¯åž„å‰įŧ€īŧš`/api/v1`。 + +åŊ“į„ļīŧŒčŋ™æ˜¯é€ščŋ‡äģŖį†čŽŋ问åē”į”¨įš„æ–šåŧīŧŒå› æ­¤īŧŒčˇ¯åž„前įŧ€ `/app/v1` į‰ˆæœŦ才是**æ­ŖįĄŽ**įš„ã€‚ + +而不å¸Ļčˇ¯åž„å‰įŧ€įš„į‰ˆæœŦīŧˆ`http://127.0.0.1:8000/app`īŧ‰īŧŒåˆ™į”ą Uvicorn į›´æŽĨ提䞛īŧŒä¸“äž›*äģŖį†*īŧˆTraefikīŧ‰čŽŋ闎。 + +čŋ™æŧ”į¤ēäē†äģŖį†īŧˆTraefikīŧ‰åĻ‚äŊ•äŊŋį”¨čˇ¯åž„å‰įŧ€īŧŒäģĨåŠæœåŠĄå™¨īŧˆUvicornīŧ‰åĻ‚äŊ•äŊŋį”¨é€‰éĄš `--root-path` ä¸­įš„ `root_path`。 + +### æŸĨįœ‹æ–‡æĄŖ + +äŊ†čŋ™æ‰æ˜¯æœ‰čļŖįš„地斚 ✨ + +čŽŋ问åē”į”¨įš„**厘斚**æ–šåŧæ˜¯é€ščŋ‡åĢčˇ¯åž„å‰įŧ€įš„äģŖį†ã€‚å› æ­¤īŧŒä¸å‡ē所料īŧŒåĻ‚æžœæ˛Ąæœ‰åœ¨ URL 中æˇģåŠ čˇ¯åž„å‰įŧ€īŧŒį›´æŽĨčŽŋ问通čŋ‡ Uvicorn čŋčĄŒįš„ API æ–‡æĄŖīŧŒä¸čƒŊæ­Ŗå¸¸čŽŋ问īŧŒå› ä¸ē需čĻé€ščŋ‡äģŖį†æ‰čƒŊčŽŋ闎。 + +输å…Ĩ http://127.0.0.1:8000/docs æŸĨįœ‹ API æ–‡æĄŖīŧš + + + +äŊ†čž“å…Ĩ**厘斚**链æŽĨ `/api/v1/docs`īŧŒåšļäŊŋᔍįĢ¯åŖ `9999` čŽŋ问 API æ–‡æĄŖīŧŒå°ąčƒŊæ­Ŗå¸¸čŋčĄŒäē†īŧđŸŽ‰ + +输å…Ĩ http://127.0.0.1:9999/api/v1/docs æŸĨįœ‹æ–‡æĄŖīŧš + + + +ä¸€åˆ‡æ­Ŗå¸¸ã€‚ âœ”ī¸ + +čŋ™æ˜¯å› ä¸ē FastAPI 在 OpenAPI 里äŊŋᔍ `root_path` æäž›įš„ URL 创åģēéģ˜čޤ `server`。 + +## é™„åŠ įš„æœåŠĄå™¨ + +!!! warning "č­Ļ告" + + æ­¤į”¨äž‹čžƒéšžīŧŒå¯äģĨ莺čŋ‡ã€‚ + +éģ˜čŽ¤æƒ…å†ĩ下īŧŒ**FastAPI** äŊŋᔍ `root_path` įš„é“žæŽĨ在 OpenAPI æĻ‚回中创åģē `server`。 + +äŊ†äšŸå¯äģĨäŊŋᔍå…ļ厃备选 `servers`īŧŒäž‹åĻ‚īŧŒéœ€čĻåŒä¸€ä¸Ē API æ–‡æĄŖä¸Ž staging å’Œį”Ÿäē§įޝåĸƒäē¤äē’。 + +åĻ‚æžœäŧ é€’č‡Ē厚䚉 `servers` åˆ—čĄ¨īŧŒåšļ有 `root_path`īŧˆ 因ä¸ē API äŊŋᔍäē†äģŖį†īŧ‰īŧŒ**FastAPI** äŧšåœ¨åˆ—襨åŧ€å¤´äŊŋᔍčŋ™ä¸Ē `root_path` 插å…Ĩ**æœåŠĄå™¨**。 + +例åĻ‚īŧš + +```Python hl_lines="4-7" +{!../../../docs_src/behind_a_proxy/tutorial003.py!} +``` + +čŋ™æŽĩäģŖį į”Ÿäē§åς䏋 OpenAPI æĻ‚回īŧš + +```JSON hl_lines="5-7" +{ + "openapi": "3.0.2", + // More stuff here + "servers": [ + { + "url": "/api/v1" + }, + { + "url": "https://stag.example.com", + "description": "Staging environment" + }, + { + "url": "https://prod.example.com", + "description": "Production environment" + } + ], + "paths": { + // More stuff here + } +} +``` + +!!! tip "提į¤ē" + + æŗ¨æ„īŧŒč‡ĒåŠ¨į”ŸæˆæœåŠĄå™¨æ—ļīŧŒ`url` įš„å€ŧ `/api/v1` 提取č‡Ē `roog_path`。 + +http://127.0.0.1:9999/api/v1/docsÂ įš„ API æ–‡æĄŖæ‰€į¤ēåς䏋īŧš + + + +!!! tip "提į¤ē" + + API æ–‡æĄŖä¸Žæ‰€é€‰įš„æœåŠĄå™¨čŋ›čĄŒäē¤äē’。 + +### äģŽ `root_path` įρᔍč‡ĒåŠ¨æœåŠĄå™¨ + +åĻ‚æžœä¸æƒŗčŽŠ **FastAPI** 包åĢäŊŋᔍ `root_path` įš„č‡ĒåŠ¨æœåŠĄå™¨īŧŒåˆ™čρäŊŋį”¨å‚æ•° `root_path_in_servers=False`īŧš + +```Python hl_lines="9" +{!../../../docs_src/behind_a_proxy/tutorial004.py!} +``` + +čŋ™æ ˇīŧŒå°ąä¸äŧšåœ¨ OpenAPI æĻ‚回中包åĢæœåŠĄå™¨äē†ã€‚ + +## 挂čŊŊ子åē”ᔍ + +åĻ‚éœ€æŒ‚čŊŊ子åē”ᔍīŧˆč¯Ļ见 [子åē”ᔍ - 挂čŊŊ](./sub-applications.md){.internal-link target=_blank}īŧ‰īŧŒäšŸčĻé€ščŋ‡ `root_path` äŊŋᔍäģŖį†īŧŒčŋ™ä¸Žæ­Ŗå¸¸åē”į”¨ä¸€æ ˇīŧŒåˆĢ无äēŒč‡´ã€‚ + +FastAPI 在内部äŊŋᔍ `root_path`īŧŒå› æ­¤å­åē”į”¨äšŸå¯äģĨæ­Ŗå¸¸čŋčĄŒã€‚✨ From 13c6eb2db00a51ef66f533eb60ff47d133c4084e Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:23:10 +0800 Subject: [PATCH 260/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/events.md`=20(#3815)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/docs/advanced/events.md | 51 +++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 docs/zh/docs/advanced/events.md diff --git a/docs/zh/docs/advanced/events.md b/docs/zh/docs/advanced/events.md new file mode 100644 index 0000000000..6017b8ef02 --- /dev/null +++ b/docs/zh/docs/advanced/events.md @@ -0,0 +1,51 @@ +# äē‹äģļīŧšå¯åЍ - å…ŗé—­ + +**FastAPI** 支持厚䚉在åē”į”¨å¯åŠ¨å‰īŧŒæˆ–åē”į”¨å…ŗé—­åŽæ‰§čĄŒįš„äē‹äģļ处ᐆ噍īŧˆå‡Ŋ数īŧ‰ã€‚ + +äē‹äģļå‡Ŋ数æ—ĸ可äģĨåŖ°æ˜Žä¸ēåŧ‚æ­Ĩå‡Ŋ数īŧˆ`async def`īŧ‰īŧŒäšŸå¯äģĨåŖ°æ˜Žä¸ē晎通å‡Ŋ数īŧˆ`def`īŧ‰ã€‚ + +!!! warning "č­Ļ告" + + **FastAPI** åĒæ‰§čĄŒä¸ģåē”į”¨ä¸­įš„äē‹äģļ处ᐆ噍īŧŒä¸æ‰§čĄŒ[子åē”ᔍ - 挂čŊŊ](./sub-applications.md){.internal-link target=_blank}ä¸­įš„äē‹äģļå¤„į†å™¨ã€‚ + +## `startup` äē‹äģļ + +äŊŋᔍ `startup` äē‹äģļåŖ°æ˜Ž `app` 启动前čŋčĄŒįš„å‡Ŋ数īŧš + +```Python hl_lines="8" +{!../../../docs_src/events/tutorial001.py!} +``` + +æœŦ例中īŧŒ`startup` äē‹äģļ处ᐆ噍å‡Ŋ数ä¸ēéĄšį›Žæ•°æŽåē“īŧˆåĒ是**字典**īŧ‰æäž›äē†ä¸€äē›åˆå§‹å€ŧ。 + +**FastAPI** 支持多ä¸Ēäē‹äģļ处ᐆ噍å‡Ŋ数。 + +åĒ有所有 `startup` äē‹äģļ处ᐆ噍čŋčĄŒåŽŒæ¯•īŧŒ**FastAPI** åē”į”¨æ‰åŧ€å§‹æŽĨæ”ļč¯ˇæą‚ã€‚ + +## `shutdown` äē‹äģļ + +äŊŋᔍ `shutdown` äē‹äģļåŖ°æ˜Ž `app` å…ŗé—­æ—ļčŋčĄŒįš„å‡Ŋ数īŧš + +```Python hl_lines="6" +{!../../../docs_src/events/tutorial002.py!} +``` + +此处īŧŒ`shutdown` äē‹äģļ处ᐆ噍å‡Ŋ数在 `log.txt` 中写å…Ĩä¸€čĄŒæ–‡æœŦ `Application shutdown`。 + +!!! info "č¯´æ˜Ž" + + `open()` å‡Ŋ数中īŧŒ`mode="a"` æŒ‡įš„æ˜¯**čŋŊ加**。因此čŋ™čĄŒæ–‡æœŦäŧšæˇģ加在文äģļåˇ˛æœ‰å†…åŽšäš‹åŽīŧŒä¸äŧščĻ†į›–äš‹å‰įš„å†…åŽšã€‚ + +!!! tip "提į¤ē" + + æŗ¨æ„īŧŒæœŦ例äŊŋᔍ Python `open()` 标准å‡Ŋ数与文äģļäē¤äē’。 + + čŋ™ä¸Ēå‡Ŋæ•°æ‰§čĄŒ I/Oīŧˆčž“å…Ĩ/输å‡ēīŧ‰æ“äŊœīŧŒéœ€čĻį­‰åž…å†…åŽšå†™čŋ›įŖį›˜ã€‚ + + äŊ† `open()` å‡Ŋ数不支持äŊŋᔍ `async` 与 `await`。 + + 因此īŧŒåŖ°æ˜Žäē‹äģļ处ᐆå‡Ŋ数čρäŊŋᔍ `def`īŧŒä¸čƒŊäŊŋᔍ `asnyc def`。 + +!!! info "č¯´æ˜Ž" + + æœ‰å…ŗäē‹äģļå¤„į†å™¨įš„č¯Ļ情īŧŒč¯ˇå‚阅 Starlette åŽ˜æĄŖ - äē‹äģļ。 From 5f194ddcc01c06a02a179d74055a95c7f79b772a Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:23:59 +0000 Subject: [PATCH 261/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index c9a2fc3da9..dc2b8ab3c8 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-events.md`. PR [#3818](https://github.com/tiangolo/fastapi/pull/3818) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-websockets.md`. PR [#3817](https://github.com/tiangolo/fastapi/pull/3817) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-database.md`. PR [#3821](https://github.com/tiangolo/fastapi/pull/3821) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/deployment/deta.md`. PR [#3837](https://github.com/tiangolo/fastapi/pull/3837) by [@jaystone776](https://github.com/jaystone776). From 39d26f3491c2e93cfada205a59d56238932ed096 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:26:17 +0000 Subject: [PATCH 262/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index dc2b8ab3c8..484b4bed43 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/behind-a-proxy.md`. PR [#3820](https://github.com/tiangolo/fastapi/pull/3820) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-events.md`. PR [#3818](https://github.com/tiangolo/fastapi/pull/3818) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-websockets.md`. PR [#3817](https://github.com/tiangolo/fastapi/pull/3817) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-database.md`. PR [#3821](https://github.com/tiangolo/fastapi/pull/3821) by [@jaystone776](https://github.com/jaystone776). From 1f9d5a1db9aa6ab0fe4f8a849fba873487ef3c8f Mon Sep 17 00:00:00 2001 From: jaystone776 Date: Mon, 29 Jan 2024 02:26:57 +0800 Subject: [PATCH 263/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Chinese=20translat?= =?UTF-8?q?ion=20for=20`docs/zh/docs/advanced/advanced-dependencies.md`=20?= =?UTF-8?q?(#3798)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zh/docs/advanced/advanced-dependencies.md | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 docs/zh/docs/advanced/advanced-dependencies.md diff --git a/docs/zh/docs/advanced/advanced-dependencies.md b/docs/zh/docs/advanced/advanced-dependencies.md new file mode 100644 index 0000000000..b2f6e3559e --- /dev/null +++ b/docs/zh/docs/advanced/advanced-dependencies.md @@ -0,0 +1,71 @@ +# é̘įē§äžčĩ–饚 + +## å‚æ•°åŒ–įš„äžčĩ–饚 + +我äģŦäš‹å‰įœ‹åˆ°įš„æ‰€æœ‰äžčĩ–饚éƒŊ是写æ­ģįš„å‡Ŋ数或įąģ。 + +äŊ†äšŸå¯äģĨä¸ē䞝čĩ–饚莞įŊŽå‚æ•°īŧŒéŋå…åŖ°æ˜Žå¤šä¸Ēä¸åŒįš„å‡Ŋ数或įąģ。 + +å‡čŽžčĻåˆ›åģēæ ĄénjæŸĨč¯ĸ参数 `q` 是åĻ包åĢå›ēåŽšå†…åŽšįš„äžčĩ–éĄšã€‚ + +äŊ†æ­¤å¤„čĻæŠŠåž…æŖ€éĒŒįš„å›ē厚内厚厚䚉ä¸ē参数。 + +## **å¯č°ƒį”¨**厞䞋 + +Python 可äģĨ把įąģ厞䞋变ä¸ē**å¯č°ƒį”¨éĄš**。 + +čŋ™é‡Œč¯´įš„不是įąģæœŦčēĢīŧˆįąģæœŦå°ąæ˜¯å¯č°ƒį”¨éĄšīŧ‰īŧŒč€Œæ˜¯įąģ厞䞋。 + +ä¸ēæ­¤īŧŒéœ€čĻåŖ°æ˜Ž `__call__` æ–šæŗ•īŧš + +```Python hl_lines="10" +{!../../../docs_src/dependencies/tutorial011.py!} +``` + +æœŦ例中īŧŒ**FastAPI** äŊŋᔍ `__call__` æŖ€æŸĨ附加参数及子䞝čĩ–饚īŧŒį¨åŽīŧŒčŋ˜čĻč°ƒį”¨åŽƒå‘*čˇ¯åž„æ“äŊœå‡Ŋ数*äŧ é€’å€ŧ。 + +## 参数化厞䞋 + +æŽĨ下æĨīŧŒäŊŋᔍ `__init__` åŖ°æ˜Žį”¨äēŽ**参数化**䞝čĩ–éĄšįš„åŽžäž‹å‚æ•°īŧš + +```Python hl_lines="7" +{!../../../docs_src/dependencies/tutorial011.py!} +``` + +æœŦ例中īŧŒ**FastAPI** 不äŊŋᔍ `__init__`īŧŒæˆ‘äģŦčρᛴæŽĨ在äģŖį ä¸­äŊŋį”¨ã€‚ + +## 创åģē厞䞋 + +äŊŋᔍäģĨ下äģŖį åˆ›åģēįąģ厞䞋īŧš + +```Python hl_lines="16" +{!../../../docs_src/dependencies/tutorial011.py!} +``` + +čŋ™æ ˇå°ąå¯äģĨ**参数化**䞝čĩ–饚īŧŒåŽƒåŒ…åĢ `checker.fixed_content` įš„åąžæ€§ - `"bar"`。 + +## 把厞䞋äŊœä¸ē䞝čĩ–饚 + +į„ļ后īŧŒä¸čĻå†åœ¨ `Depends(checker)` 中äŊŋᔍ `Depends(FixedContentQueryChecker)`īŧŒ č€Œæ˜¯čρäŊŋᔍ `checker`īŧŒå› ä¸ē䞝čĩ–éĄšæ˜¯įąģ厞䞋 - `checker`īŧŒä¸æ˜¯įąģ。 + +å¤„į†äžčĩ–饚æ—ļīŧŒ**FastAPI** äģĨåĻ‚ä¸‹æ–šåŧč°ƒį”¨ `checker`īŧš + +```Python +checker(q="somequery") +``` + +â€Ļâ€Ļåšļᔍ*čˇ¯åž„æ“äŊœå‡Ŋ数*įš„å‚æ•° `fixed_content_included` čŋ”回䞝čĩ–éĄšįš„å€ŧīŧš + +```Python hl_lines="20" +{!../../../docs_src/dependencies/tutorial011.py!} +``` + +!!! tip "提į¤ē" + + æœŦįĢ į¤ē䞋有äē›åˆģ意īŧŒäšŸįœ‹ä¸å‡ē有äģ€äšˆį”¨å¤„。 + + čŋ™ä¸ĒįŽ€äž‹åĒ是ä¸ēäē†č¯´æ˜Žé̘įē§äžčĩ–éĄšįš„čŋäŊœæœēåˆļ。 + + åœ¨æœ‰å…ŗåŽ‰å…¨įš„įĢ čŠ‚ä¸­īŧŒåˇĨå…ˇå‡Ŋ数将äģĨčŋ™į§æ–šåŧåŽžįŽ°ã€‚ + + åĒčρčƒŊᐆ觪æœŦįĢ å†…åŽšīŧŒå°ąčƒŊį†č§ŖåŽ‰å…¨åˇĨå…ˇčƒŒåŽįš„čŋčĄŒæœēåˆļ。 From 0cf8c74e464656df601cc644311bdb021d3331bb Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:27:02 +0000 Subject: [PATCH 264/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 484b4bed43..7a1b061efe 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/events.md`. PR [#3815](https://github.com/tiangolo/fastapi/pull/3815) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/behind-a-proxy.md`. PR [#3820](https://github.com/tiangolo/fastapi/pull/3820) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-events.md`. PR [#3818](https://github.com/tiangolo/fastapi/pull/3818) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-websockets.md`. PR [#3817](https://github.com/tiangolo/fastapi/pull/3817) by [@jaystone776](https://github.com/jaystone776). From b2faa22f42714ffa808f05912e4e1f35fb6d754c Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:30:52 +0000 Subject: [PATCH 265/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 7a1b061efe..853330031f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Chinese translation for `docs/zh/docs/advanced/advanced-dependencies.md`. PR [#3798](https://github.com/tiangolo/fastapi/pull/3798) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/events.md`. PR [#3815](https://github.com/tiangolo/fastapi/pull/3815) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/behind-a-proxy.md`. PR [#3820](https://github.com/tiangolo/fastapi/pull/3820) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/testing-events.md`. PR [#3818](https://github.com/tiangolo/fastapi/pull/3818) by [@jaystone776](https://github.com/jaystone776). From aae14c5379ff18f9e328bfe415f4d5275578f97b Mon Sep 17 00:00:00 2001 From: Sho Nakamura Date: Mon, 29 Jan 2024 03:36:35 +0900 Subject: [PATCH 266/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Japanese=20transla?= =?UTF-8?q?tion=20for=20`docs/ja/docs/tutorial/security/get-current-user.m?= =?UTF-8?q?d`=20(#2681)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: SebastiÃĄn Ramírez --- .../tutorial/security/get-current-user.md | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 docs/ja/docs/tutorial/security/get-current-user.md diff --git a/docs/ja/docs/tutorial/security/get-current-user.md b/docs/ja/docs/tutorial/security/get-current-user.md new file mode 100644 index 0000000000..7f8dcaad21 --- /dev/null +++ b/docs/ja/docs/tutorial/security/get-current-user.md @@ -0,0 +1,114 @@ +# įžåœ¨ãŽãƒĻãƒŧã‚ļãƒŧぎ取垗 + +一つ前ぎįĢ ã§ã¯ã€īŧˆäžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ãĢåŸēãĨいたīŧ‰ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚ˇã‚šãƒ†ãƒ ã¯ã€ *path operationé–ĸ数* ãĢ `str` としãĻ `token` を与えãĻいぞした: + +```Python hl_lines="10" +{!../../../docs_src/security/tutorial001.py!} +``` + +しかし、それはぞだそんãĒãĢæœ‰į”¨ã§ã¯ã‚ã‚Šãžã›ã‚“ã€‚ + +įžåœ¨ãŽãƒĻãƒŧã‚ļãƒŧを取垗するようãĢしãĻãŋぞしょう。 + +## ãƒĻãƒŧã‚ļãƒŧãƒĸデãƒĢぎäŊœæˆ + +ぞずは、PydanticぎãƒĻãƒŧã‚ļãƒŧãƒĸデãƒĢをäŊœæˆã—ぞしょう。 + +ãƒœãƒ‡ã‚Ŗã‚’åŽŖč¨€ã™ã‚‹ãŽãĢPydanticをäŊŋį”¨ã™ã‚‹ãŽã¨åŒã˜ã‚„ã‚Šæ–šã§ã€PydanticをåˆĨぎおんãĒところでもäŊŋうことができぞす: + +```Python hl_lines="5 12-16" +{!../../../docs_src/security/tutorial002.py!} +``` + +## 䞝存é–ĸäŋ‚ `get_current_user` をäŊœæˆ + +䞝存é–ĸäŋ‚ `get_current_user` をäŊœãŖãĻãŋぞしょう。 + +䞝存é–ĸäŋ‚はã‚ĩブ䞝存é–ĸäŋ‚を持つことができるぎをčĻšãˆãĻいぞすかīŧŸ + +`get_current_user` は前ãĢäŊœæˆã—た `oauth2_scheme` と同じ䞝存é–ĸäŋ‚ã‚’æŒãĄãžã™ã€‚ + +äģĨå‰į›´æŽĨ *path operation* ぎ中でしãĻいたぎと同じようãĢ、新しい䞝存é–ĸäŋ‚である `get_current_user` は `str` としãĻ `token` を受け取るようãĢãĒりぞす: + +```Python hl_lines="25" +{!../../../docs_src/security/tutorial002.py!} +``` + +## ãƒĻãƒŧã‚ļãƒŧぎ取垗 + +`get_current_user` はäŊœæˆã—たīŧˆåŊį‰ŠãŽīŧ‰ãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚Ŗé–ĸ数をäŊŋãŖãĻ、 `str` としãĻトãƒŧã‚¯ãƒŗã‚’å—ã‘å–ã‚Šã€å…ˆãģおぎPydanticぎ `User` ãƒĸデãƒĢをčŋ”却しぞす: + +```Python hl_lines="19-22 26-27" +{!../../../docs_src/security/tutorial002.py!} +``` + +## įžåœ¨ãŽãƒĻãƒŧã‚ļãƒŧãŽæŗ¨å…Ĩ + +ですぎで、 `get_current_user` ãĢ寞しãĻ同様ãĢ *path operation* ぎ中で `Depends` ã‚’åˆŠį”¨ã§ããžã™ã€‚ + +```Python hl_lines="31" +{!../../../docs_src/security/tutorial002.py!} +``` + +PydanticãƒĸデãƒĢぎ `User` としãĻ、 `current_user` ãŽåž‹ã‚’åŽŖč¨€ã™ã‚‹ã“ã¨ãĢæŗ¨æ„ã—ãĻください。 + +そぎé–ĸ数ぎ中ですずãĻぎå…ĨåŠ›čŖœåŽŒã‚„åž‹ãƒã‚§ãƒƒã‚¯ã‚’čĄŒã†éš›ãĢåŊšãĢįĢ‹ãĄãžã™ã€‚ + +!!! tip "豆įŸĨ識" + ãƒĒã‚¯ã‚¨ã‚šãƒˆãƒœãƒ‡ã‚Ŗã¯PydanticãƒĸデãƒĢã§ã‚‚åŽŖč¨€ã§ãã‚‹ã“ã¨ã‚’čĻšãˆãĻいるかもしれぞせん。 + + ここでは `Depends` をäŊŋãŖãĻいるおかげで、 **FastAPI** ãŒæˇˇäšąã™ã‚‹ã“ã¨ã¯ã‚ã‚Šãžã›ã‚“ã€‚ + + +!!! check "įĸēčĒ" + 䞝存é–ĸäŋ‚ã‚ˇã‚šãƒ†ãƒ ãŒã“ãŽã‚ˆã†ãĢč¨­č¨ˆã•ã‚ŒãĻいるおかげで、 `User` ãƒĸデãƒĢをčŋ”却するåˆĨぎ䞝存é–ĸäŋ‚īŧˆåˆĨぎ"dependables"īŧ‰ã‚’持つことができぞす。 + + 同じデãƒŧã‚ŋ型をčŋ”却する䞝存é–ĸäŋ‚は一つだけしか持ãĻãĒい、というåˆļį´„ãŒå…ĨることはãĒいぎです。 + + +## åˆĨぎãƒĸデãƒĢ + +これで、*path operationé–ĸ数* ãŽä¸­ã§įžåœ¨ãŽãƒĻãƒŧã‚ļãƒŧã‚’į›´æŽĨ取垗し、`Depends` をäŊŋãŖãĻ、 **äžå­˜æ€§æŗ¨å…Ĩ** ãƒŦベãƒĢでã‚ģキãƒĨãƒĒãƒ†ã‚ŖãƒĄã‚Ģニã‚ēムをå‡Ļį†ã§ãã‚‹ã‚ˆã†ãĢãĒりぞした。 + +そしãĻ、ã‚ģキãƒĨãƒĒãƒ†ã‚ŖčρäģļぎためãĢおんãĒãƒĸデãƒĢやデãƒŧã‚ŋã§ã‚‚åˆŠį”¨ã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚īŧˆã“ぎ場合は、 PydanticãƒĸデãƒĢぎ `User`īŧ‰ + +ã—ã‹ã—ã€į‰šåŽšãŽãƒ‡ãƒŧã‚ŋãƒĸデãƒĢやクナ゚、型ãĢåˆļ限されることはありぞせん。 + +ãƒĸデãƒĢを、 `id` と `email` は持つが、 `username` は全く持たãĒいようãĢしたいですかīŧŸ わかりぞした。同じ手æŽĩでこうしたこともできぞす。 + +ある `str` ã ã‘ã‚’æŒãĄãŸã„īŧŸ あるいはある `dict` だけですかīŧŸ それとも、デãƒŧã‚ŋベãƒŧ゚クナ゚ぎãƒĸデãƒĢã‚¤ãƒŗã‚šã‚ŋãƒŗã‚šã‚’į›´æŽĨæŒãĄãŸã„ã§ã™ã‹īŧŸ すずãĻ同じやり斚で抟čƒŊしぞす。 + +原際ãĢは、あãĒたぎã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗãĢã¯ãƒ­ã‚°ã‚¤ãƒŗã™ã‚‹ã‚ˆã†ãĒãƒĻãƒŧã‚ļãƒŧはおらず、単ãĢã‚ĸクã‚ģ゚トãƒŧã‚¯ãƒŗã‚’æŒã¤ãƒ­ãƒœãƒƒãƒˆã‚„ãƒœãƒƒãƒˆã€åˆĨãŽã‚ˇã‚šãƒ†ãƒ ãŒã‚ã‚Šãžã™ã‹īŧŸã“こでも、全く同じようãĢすずãĻ抟čƒŊしぞす。 + +あãĒたぎã‚ĸプãƒĒã‚ąãƒŧã‚ˇãƒ§ãƒŗãĢåŋ…čρãĒぎがおんãĒį¨ŽéĄžãŽãƒĸデãƒĢ、おんãĒį¨ŽéĄžãŽã‚¯ãƒŠã‚šã€ãŠã‚“ãĒį¨ŽéĄžãŽãƒ‡ãƒŧã‚ŋベãƒŧã‚šã§ã‚ãŖãŸã¨ã—ãĻも、 **FastAPI** ã¯äžå­˜æ€§æŗ¨å…Ĩã‚ˇã‚šãƒ†ãƒ ã§ã‚ĢバãƒŧしãĻくれぞす。 + + +## ã‚ŗãƒŧドã‚ĩイã‚ē + +ã“ãŽäž‹ã¯å†—é•ˇãĢčĻ‹ãˆã‚‹ã‹ã‚‚ã—ã‚Œãžã›ã‚“ã€‚ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã¨ãƒ‡ãƒŧã‚ŋãƒĸデãƒĢãƒĻãƒŧãƒ†ã‚ŖãƒĒãƒ†ã‚Ŗé–ĸæ•°ãŠã‚ˆãŗ *path operations* ãŒåŒã˜ãƒ•ã‚Ąã‚¤ãƒĢãĢæˇˇåœ¨ã—ãĻいるということをčĻšãˆãĻおいãĻください。 + +しかし、ここãĢ重čρãĒãƒã‚¤ãƒŗãƒˆãŒã‚ã‚Šãžã™ã€‚ + +ã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã¨äžå­˜æ€§æŗ¨å…ĨãĢé–ĸするもぎは、一åēĻだけ書きぞす。 + +そしãĻ、それはåĨŊきãĒã ã‘č¤‡é›‘ãĢã™ã‚‹ã“ã¨ãŒã§ããžã™ã€‚ãã‚Œã§ã‚‚ã€ä¸€įŽ‡æ‰€ãĢ、一åēĻだけ書くぎです。すずãĻぎ柔č쟿€§ã‚’備えぞす。 + +しかし、同じã‚ģキãƒĨãƒĒãƒ†ã‚Ŗã‚ˇã‚šãƒ†ãƒ ã‚’äŊŋãŖãĻäŊ•åƒã‚‚ãŽã‚¨ãƒŗãƒ‰ãƒã‚¤ãƒŗãƒˆīŧˆ*path operations*īŧ‰ã‚’持つことができぞす。 + +そしãĻã€ãã‚Œã‚‰ã‚¨ãƒŗãƒ‰ãƒã‚¤ãƒŗãƒˆãŽã™ãšãĻīŧˆåŋ…čρãĒ、おぎ部分でもīŧ‰ãŒã“うした䞝存é–ĸäŋ‚や、あãĒたがäŊœæˆã™ã‚‹åˆĨぎ䞝存é–ĸäŋ‚ã‚’å†åˆŠį”¨ã™ã‚‹åˆŠį‚šã‚’äēĢ受できるぎです。 + +さらãĢ、こうしたäŊ•千もぎ *path operations* ã¯ã€ãŸãŖãŸ3čĄŒã§čĄ¨įžã§ãã‚‹ãŽã§ã™: + +```Python hl_lines="30-32" +{!../../../docs_src/security/tutorial002.py!} +``` + +## ぞとめ + +これで、 *path operationé–ĸ数* ãŽä¸­ã§į›´æŽĨįžåœ¨ãŽãƒĻãƒŧã‚ļãƒŧを取垗できるようãĢãĒりぞした。 + +æ—ĸãĢ半分ぎところぞでæĨãĻいぞす。 + +あとは、 `username` と `password` を原際ãĢそぎãƒĻãƒŧã‚ļãƒŧやクナイã‚ĸãƒŗãƒˆãĢ送る、 *path operation* をčŋŊ加するåŋ…čĻãŒã‚ã‚‹ã ã‘ã§ã™ã€‚ + +æŦĄã¯ãã‚Œã‚’čĒŦ明しぞす。 From ab22b795903bb9a782ccfc3d2b4e450b565f6bfc Mon Sep 17 00:00:00 2001 From: github-actions Date: Sun, 28 Jan 2024 18:43:09 +0000 Subject: [PATCH 267/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 853330031f..b4337c742f 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/get-current-user.md`. PR [#2681](https://github.com/tiangolo/fastapi/pull/2681) by [@sh0nk](https://github.com/sh0nk). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/advanced-dependencies.md`. PR [#3798](https://github.com/tiangolo/fastapi/pull/3798) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/events.md`. PR [#3815](https://github.com/tiangolo/fastapi/pull/3815) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/behind-a-proxy.md`. PR [#3820](https://github.com/tiangolo/fastapi/pull/3820) by [@jaystone776](https://github.com/jaystone776). From 26ab83e1571af3b229dc748e68972e446edf47ca Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Mon, 29 Jan 2024 18:32:43 +0100 Subject: [PATCH 268/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/body-multiple-params.md`=20(#?= =?UTF-8?q?10308)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/body-multiple-params.md | 308 ++++++++++++++++++ 1 file changed, 308 insertions(+) create mode 100644 docs/de/docs/tutorial/body-multiple-params.md diff --git a/docs/de/docs/tutorial/body-multiple-params.md b/docs/de/docs/tutorial/body-multiple-params.md new file mode 100644 index 0000000000..6a237243e5 --- /dev/null +++ b/docs/de/docs/tutorial/body-multiple-params.md @@ -0,0 +1,308 @@ +# Body – Mehrere Parameter + +Jetzt, da wir gesehen haben, wie `Path` und `Query` verwendet werden, schauen wir uns fortgeschrittenere VerwendungsmÃļglichkeiten von Requestbody-Deklarationen an. + +## `Path`-, `Query`- und Body-Parameter vermischen + +Zuerst einmal, Sie kÃļnnen `Path`-, `Query`- und Requestbody-Parameter-Deklarationen frei mischen und **FastAPI** wird wissen, was zu tun ist. + +Und Sie kÃļnnen auch Body-Parameter als optional kennzeichnen, indem Sie den Defaultwert auf `None` setzen: + +=== "Python 3.10+" + + ```Python hl_lines="18-20" + {!> ../../../docs_src/body_multiple_params/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="18-20" + {!> ../../../docs_src/body_multiple_params/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="19-21" + {!> ../../../docs_src/body_multiple_params/tutorial001_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="17-19" + {!> ../../../docs_src/body_multiple_params/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="19-21" + {!> ../../../docs_src/body_multiple_params/tutorial001.py!} + ``` + +!!! note "Hinweis" + Beachten Sie, dass in diesem Fall das `item`, welches vom Body genommen wird, optional ist. Da es `None` als Defaultwert hat. + +## Mehrere Body-Parameter + +Im vorherigen Beispiel erwartete die *Pfadoperation* einen JSON-Body mit den Attributen eines `Item`s, etwa: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +Aber Sie kÃļnnen auch mehrere Body-Parameter deklarieren, z. B. `item` und `user`: + +=== "Python 3.10+" + + ```Python hl_lines="20" + {!> ../../../docs_src/body_multiple_params/tutorial002_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="22" + {!> ../../../docs_src/body_multiple_params/tutorial002.py!} + ``` + +In diesem Fall wird **FastAPI** bemerken, dass es mehr als einen Body-Parameter in der Funktion gibt (zwei Parameter, die Pydantic-Modelle sind). + +Es wird deshalb die Parameternamen als SchlÃŧssel (Feldnamen) im Body verwenden, und erwartet einen Body wie folgt: + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + } +} +``` + +!!! note "Hinweis" + Beachten Sie, dass, obwohl `item` wie zuvor deklariert wurde, es nun unter einem SchlÃŧssel `item` im Body erwartet wird. + +**FastAPI** wird die automatische Konvertierung des Requests Ãŧbernehmen, sodass der Parameter `item` seinen spezifischen Inhalt bekommt, genau so wie der Parameter `user`. + +Es wird die Validierung dieser zusammengesetzten Daten Ãŧbernehmen, und sie im OpenAPI-Schema und der automatischen Dokumentation dokumentieren. + +## Einzelne Werte im Body + +So wie `Query` und `Path` fÃŧr Query- und Pfad-Parameter, hat **FastAPI** auch das Äquivalent `Body`, um Extra-Daten fÃŧr Body-Parameter zu definieren. + +Zum Beispiel, das vorherige Modell erweiternd, kÃļnnten Sie entscheiden, dass Sie einen weiteren SchlÃŧssel `importance` haben mÃļchten, im selben Body, Seite an Seite mit `item` und `user`. + +Wenn Sie diesen Parameter einfach so hinzufÃŧgen, wird **FastAPI** annehmen, dass es ein Query-Parameter ist. + +Aber Sie kÃļnnen **FastAPI** instruieren, ihn als weiteren Body-SchlÃŧssel zu erkennen, indem Sie `Body` verwenden: + +=== "Python 3.10+" + + ```Python hl_lines="23" + {!> ../../../docs_src/body_multiple_params/tutorial003_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="23" + {!> ../../../docs_src/body_multiple_params/tutorial003_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="24" + {!> ../../../docs_src/body_multiple_params/tutorial003_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="20" + {!> ../../../docs_src/body_multiple_params/tutorial003_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="22" + {!> ../../../docs_src/body_multiple_params/tutorial003.py!} + ``` + +In diesem Fall erwartet **FastAPI** einen Body wie: + +```JSON +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + }, + "user": { + "username": "dave", + "full_name": "Dave Grohl" + }, + "importance": 5 +} +``` + +Wiederum wird es die Daten konvertieren, validieren, dokumentieren, usw. + +## Mehrere Body-Parameter und Query-Parameter + +NatÃŧrlich kÃļnnen Sie auch, wann immer Sie das brauchen, weitere Query-Parameter hinzufÃŧgen, zusätzlich zu den Body-Parametern. + +Da einfache Werte standardmäßig als Query-Parameter interpretiert werden, mÃŧssen Sie `Query` nicht explizit hinzufÃŧgen, Sie kÃļnnen einfach schreiben: + +```Python +q: Union[str, None] = None +``` + +Oder in Python 3.10 und darÃŧber: + +```Python +q: str | None = None +``` + +Zum Beispiel: + +=== "Python 3.10+" + + ```Python hl_lines="27" + {!> ../../../docs_src/body_multiple_params/tutorial004_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="27" + {!> ../../../docs_src/body_multiple_params/tutorial004_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="28" + {!> ../../../docs_src/body_multiple_params/tutorial004_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="25" + {!> ../../../docs_src/body_multiple_params/tutorial004_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="27" + {!> ../../../docs_src/body_multiple_params/tutorial004.py!} + ``` + +!!! info + `Body` hat die gleichen zusätzlichen Validierungs- und Metadaten-Parameter wie `Query` und `Path` und andere, die Sie später kennenlernen. + +## Einen einzelnen Body-Parameter einbetten + +Nehmen wir an, Sie haben nur einen einzelnen `item`-Body-Parameter, ein Pydantic-Modell `Item`. + +Normalerweise wird **FastAPI** dann seinen JSON-Body direkt erwarten. + +Aber wenn Sie mÃļchten, dass es einen JSON-Body erwartet, mit einem SchlÃŧssel `item` und darin den Inhalt des Modells, so wie es das tut, wenn Sie mehrere Body-Parameter deklarieren, dann kÃļnnen Sie den speziellen `Body`-Parameter `embed` setzen: + +```Python +item: Item = Body(embed=True) +``` + +so wie in: + +=== "Python 3.10+" + + ```Python hl_lines="17" + {!> ../../../docs_src/body_multiple_params/tutorial005_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="17" + {!> ../../../docs_src/body_multiple_params/tutorial005_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body_multiple_params/tutorial005_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="15" + {!> ../../../docs_src/body_multiple_params/tutorial005_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="17" + {!> ../../../docs_src/body_multiple_params/tutorial005.py!} + ``` + +In diesem Fall erwartet **FastAPI** einen Body wie: + +```JSON hl_lines="2" +{ + "item": { + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 + } +} +``` + +statt: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2 +} +``` + +## Zusammenfassung + +Sie kÃļnnen mehrere Body-Parameter zu ihrer *Pfadoperation-Funktion* hinzufÃŧgen, obwohl ein Request nur einen einzigen Body enthalten kann. + +**FastAPI** wird sich darum kÃŧmmern, Ihnen korrekte Daten in Ihrer Funktion zu Ãŧberreichen, und das korrekte Schema in der *Pfadoperation* zu validieren und zu dokumentieren. + +Sie kÃļnnen auch einzelne Werte deklarieren, die als Teil des Bodys empfangen werden. + +Und Sie kÃļnnen **FastAPI** instruieren, den Body in einem SchlÃŧssel unterzubringen, selbst wenn nur ein einzelner Body-Parameter deklariert ist. From b180d39d7e03e9ae778a1cfe42d11e909131026d Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 17:33:04 +0000 Subject: [PATCH 269/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index b4337c742f..a4f9a4593c 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/body-multiple-params.md`. PR [#10308](https://github.com/tiangolo/fastapi/pull/10308) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/get-current-user.md`. PR [#2681](https://github.com/tiangolo/fastapi/pull/2681) by [@sh0nk](https://github.com/sh0nk). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/advanced-dependencies.md`. PR [#3798](https://github.com/tiangolo/fastapi/pull/3798) by [@jaystone776](https://github.com/jaystone776). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/events.md`. PR [#3815](https://github.com/tiangolo/fastapi/pull/3815) by [@jaystone776](https://github.com/jaystone776). From 32e5a37d1d2f56f496fb4cc9f9ef0d4919953ed1 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Mon, 29 Jan 2024 18:35:23 +0100 Subject: [PATCH 270/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/body.md`=20(#10295)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/body.md | 213 ++++++++++++++++++++++++++++++++++ 1 file changed, 213 insertions(+) create mode 100644 docs/de/docs/tutorial/body.md diff --git a/docs/de/docs/tutorial/body.md b/docs/de/docs/tutorial/body.md new file mode 100644 index 0000000000..97215a780a --- /dev/null +++ b/docs/de/docs/tutorial/body.md @@ -0,0 +1,213 @@ +# Requestbody + +Wenn Sie Daten von einem Client (sagen wir, einem Browser) zu Ihrer API senden, dann senden Sie diese als einen **Requestbody** (Deutsch: AnfragekÃļrper). + +Ein **Request**body sind Daten, die vom Client zu Ihrer API gesendet werden. Ein **Response**body (Deutsch: AntwortkÃļrper) sind Daten, die Ihre API zum Client sendet. + +Ihre API sendet fast immer einen **Response**body. Aber Clients senden nicht unbedingt immer **Request**bodys (sondern nur Metadaten). + +Um einen **Request**body zu deklarieren, verwenden Sie Pydantic-Modelle mit allen deren Fähigkeiten und VorzÃŧgen. + +!!! info + Um Daten zu versenden, sollten Sie eines von: `POST` (meistverwendet), `PUT`, `DELETE` oder `PATCH` verwenden. + + Senden Sie einen Body mit einem `GET`-Request, dann fÃŧhrt das laut Spezifikation zu undefiniertem Verhalten. Trotzdem wird es von FastAPI unterstÃŧtzt, fÃŧr sehr komplexe/extreme Anwendungsfälle. + + Da aber davon abgeraten wird, zeigt die interaktive Dokumentation mit Swagger-Benutzeroberfläche die Dokumentation fÃŧr den Body auch nicht an, wenn `GET` verwendet wird. Dazwischengeschaltete Proxys unterstÃŧtzen es mÃļglicherweise auch nicht. + +## Importieren Sie Pydantics `BaseModel` + +Zuerst mÃŧssen Sie `BaseModel` von `pydantic` importieren: + +=== "Python 3.10+" + + ```Python hl_lines="2" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="4" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +## Erstellen Sie Ihr Datenmodell + +Dann deklarieren Sie Ihr Datenmodell als eine Klasse, die von `BaseModel` erbt. + +Verwenden Sie Standard-Python-Typen fÃŧr die Klassenattribute: + +=== "Python 3.10+" + + ```Python hl_lines="5-9" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="7-11" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +Wie auch bei Query-Parametern gilt, wenn ein Modellattribut einen Defaultwert hat, ist das Attribut nicht erforderlich. Ansonsten ist es erforderlich. Verwenden Sie `None`, um es als optional zu kennzeichnen. + +Zum Beispiel deklariert das obige Modell ein JSON "`object`" (oder Python-`dict`) wie dieses: + +```JSON +{ + "name": "Foo", + "description": "An optional description", + "price": 45.2, + "tax": 3.5 +} +``` + +Da `description` und `tax` optional sind (mit `None` als Defaultwert), wäre folgendes JSON "`object`" auch gÃŧltig: + +```JSON +{ + "name": "Foo", + "price": 45.2 +} +``` + +## Deklarieren Sie es als Parameter + +Um es zu Ihrer *Pfadoperation* hinzuzufÃŧgen, deklarieren Sie es auf die gleiche Weise, wie Sie Pfad- und Query-Parameter deklariert haben: + +=== "Python 3.10+" + + ```Python hl_lines="16" + {!> ../../../docs_src/body/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body/tutorial001.py!} + ``` + +... und deklarieren Sie seinen Typ als das Modell, welches Sie erstellt haben, `Item`. + +## Resultate + +Mit nur dieser Python-Typdeklaration, wird **FastAPI**: + +* Den Requestbody als JSON lesen. +* Die entsprechenden Typen konvertieren (falls nÃļtig). +* Diese Daten validieren. + * Wenn die Daten ungÃŧltig sind, einen klar lesbaren Fehler zurÃŧckgeben, der anzeigt, wo und was die inkorrekten Daten waren. +* Ihnen die erhaltenen Daten im Parameter `item` Ãŧbergeben. + * Da Sie diesen in der Funktion als vom Typ `Item` deklariert haben, erhalten Sie die ganze Editor-UnterstÃŧtzung (Autovervollständigung, usw.) fÃŧr alle Attribute und deren Typen. +* Eine JSON Schema Definition fÃŧr Ihr Modell generieren, welche Sie Ãŧberall sonst verwenden kÃļnnen, wenn es fÃŧr Ihr Projekt Sinn macht. +* Diese Schemas werden Teil des generierten OpenAPI-Schemas und werden von den UIs der automatischen Dokumentation verwendet. + +## Automatische Dokumentation + +Die JSON-Schemas Ihrer Modelle werden Teil ihrer OpenAPI-generierten Schemas und werden in der interaktiven API Dokumentation angezeigt: + + + +Und werden auch verwendet in der API-Dokumentation innerhalb jeder *Pfadoperation*, welche sie braucht: + + + +## Editor UnterstÃŧtzung + +In Ihrem Editor, innerhalb Ihrer Funktion, erhalten Sie Typhinweise und Code-Vervollständigung Ãŧberall (was nicht der Fall wäre, wenn Sie ein `dict` anstelle eines Pydantic Modells erhalten hätten): + + + +Sie bekommen auch Fehler-Meldungen fÃŧr inkorrekte Typoperationen: + + + +Das ist nicht zufällig so, das ganze Framework wurde um dieses Design herum aufgebaut. + +Und es wurde in der Designphase grÃŧndlich getestet, vor der Implementierung, um sicherzustellen, dass es mit jedem Editor funktioniert. + +Es gab sogar ein paar Änderungen an Pydantic selbst, um das zu unterstÃŧtzen. + +Die vorherigen Screenshots zeigten Visual Studio Code. + +Aber Sie bekommen die gleiche Editor-UnterstÃŧtzung in PyCharm und in den meisten anderen Python-Editoren: + + + +!!! tip "Tipp" + Wenn Sie PyCharm als Ihren Editor verwenden, probieren Sie das Pydantic PyCharm Plugin aus. + + Es verbessert die Editor-UnterstÃŧtzung fÃŧr Pydantic-Modelle, mit: + + * Code-Vervollständigung + * TypÃŧberprÃŧfungen + * Refaktorisierung + * Suchen + * Inspektionen + +## Das Modell verwenden + +Innerhalb der Funktion kÃļnnen Sie alle Attribute des Modells direkt verwenden: + +=== "Python 3.10+" + + ```Python hl_lines="19" + {!> ../../../docs_src/body/tutorial002_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="21" + {!> ../../../docs_src/body/tutorial002.py!} + ``` + +## Requestbody- + Pfad-Parameter + +Sie kÃļnnen Pfad- und Requestbody-Parameter gleichzeitig deklarieren. + +**FastAPI** erkennt, dass Funktionsparameter, die mit Pfad-Parametern Ãŧbereinstimmen, **vom Pfad genommen** werden sollen, und dass Funktionsparameter, welche Pydantic-Modelle sind, **vom Requestbody genommen** werden sollen. + +=== "Python 3.10+" + + ```Python hl_lines="15-16" + {!> ../../../docs_src/body/tutorial003_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="17-18" + {!> ../../../docs_src/body/tutorial003.py!} + ``` + +## Requestbody- + Pfad- + Query-Parameter + +Sie kÃļnnen auch zur gleichen Zeit **Body-**, **Pfad-** und **Query-Parameter** deklarieren. + +**FastAPI** wird jeden Parameter korrekt erkennen und die Daten vom richtigen Ort holen. + +=== "Python 3.10+" + + ```Python hl_lines="16" + {!> ../../../docs_src/body/tutorial004_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body/tutorial004.py!} + ``` + +Die Funktionsparameter werden wie folgt erkannt: + +* Wenn der Parameter auch im **Pfad** deklariert wurde, wird er als Pfad-Parameter interpretiert. +* Wenn der Parameter ein **einfacher Typ** ist (wie `int`, `float`, `str`, `bool`, usw.), wird er als **Query**-Parameter interpretiert. +* Wenn der Parameter vom Typ eines **Pydantic-Modells** ist, wird er als Request**body** interpretiert. + +!!! note "Hinweis" + FastAPI weiß, dass der Wert von `q` nicht erforderlich ist, wegen des definierten Defaultwertes `= None` + + Das `Union` in `Union[str, None]` wird von FastAPI nicht verwendet, aber es erlaubt Ihrem Editor, Sie besser zu unterstÃŧtzen und Fehler zu erkennen. + +## Ohne Pydantic + +Wenn Sie keine Pydantic-Modelle verwenden wollen, kÃļnnen Sie auch **Body**-Parameter nehmen. Siehe die Dokumentation unter [Body – Mehrere Parameter: Einfache Werte im Body](body-multiple-params.md#einzelne-werte-im-body){.internal-link target=\_blank}. From 4185f0bd9d9a30935de9bfb2c00b1b9702d9c2c6 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Mon, 29 Jan 2024 18:36:19 +0100 Subject: [PATCH 271/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/body-fields.md`=20(#10310)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/body-fields.md | 115 +++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 docs/de/docs/tutorial/body-fields.md diff --git a/docs/de/docs/tutorial/body-fields.md b/docs/de/docs/tutorial/body-fields.md new file mode 100644 index 0000000000..643be7489b --- /dev/null +++ b/docs/de/docs/tutorial/body-fields.md @@ -0,0 +1,115 @@ +# Body – Felder + +So wie Sie zusätzliche Validation und Metadaten in Parametern der **Pfadoperation-Funktion** mittels `Query`, `Path` und `Body` deklarieren, kÃļnnen Sie auch innerhalb von Pydantic-Modellen zusätzliche Validation und Metadaten deklarieren, mittels Pydantics `Field`. + +## `Field` importieren + +Importieren Sie es zuerst: + +=== "Python 3.10+" + + ```Python hl_lines="4" + {!> ../../../docs_src/body_fields/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="4" + {!> ../../../docs_src/body_fields/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="4" + {!> ../../../docs_src/body_fields/tutorial001_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="2" + {!> ../../../docs_src/body_fields/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="4" + {!> ../../../docs_src/body_fields/tutorial001.py!} + ``` + +!!! warning "Achtung" + Beachten Sie, dass `Field` direkt von `pydantic` importiert wird, nicht von `fastapi`, wie die anderen (`Query`, `Path`, `Body`, usw.) + +## Modellattribute deklarieren + +Dann kÃļnnen Sie `Field` mit Modellattributen deklarieren: + +=== "Python 3.10+" + + ```Python hl_lines="11-14" + {!> ../../../docs_src/body_fields/tutorial001_an_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="11-14" + {!> ../../../docs_src/body_fields/tutorial001_an_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="12-15" + {!> ../../../docs_src/body_fields/tutorial001_an.py!} + ``` + +=== "Python 3.10+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="9-12" + {!> ../../../docs_src/body_fields/tutorial001_py310.py!} + ``` + +=== "Python 3.8+ nicht annotiert" + + !!! tip "Tipp" + Bevorzugen Sie die `Annotated`-Version, falls mÃļglich. + + ```Python hl_lines="11-14" + {!> ../../../docs_src/body_fields/tutorial001.py!} + ``` + +`Field` funktioniert genauso wie `Query`, `Path` und `Body`, es hat die gleichen Parameter, usw. + +!!! note "Technische Details" + Tatsächlich erstellen `Query`, `Path` und andere, die sie kennenlernen werden, Instanzen von Unterklassen einer allgemeinen Klasse `Param`, die ihrerseits eine Unterklasse von Pydantics `FieldInfo`-Klasse ist. + + Und Pydantics `Field` gibt ebenfalls eine Instanz von `FieldInfo` zurÃŧck. + + `Body` gibt auch Instanzen einer Unterklasse von `FieldInfo` zurÃŧck. Und später werden Sie andere sehen, die Unterklassen der `Body`-Klasse sind. + + Denken Sie daran, dass `Query`, `Path` und andere von `fastapi` tatsächlich Funktionen sind, die spezielle Klassen zurÃŧckgeben. + +!!! tip "Tipp" + Beachten Sie, dass jedes Modellattribut mit einem Typ, Defaultwert und `Field` die gleiche Struktur hat wie ein Parameter einer Pfadoperation-Funktion, nur mit `Field` statt `Path`, `Query`, `Body`. + +## Zusätzliche Information hinzufÃŧgen + +Sie kÃļnnen zusätzliche Information in `Field`, `Query`, `Body`, usw. deklarieren. Und es wird im generierten JSON-Schema untergebracht. + +Sie werden später mehr darÃŧber lernen, wie man zusätzliche Information unterbringt, wenn Sie lernen, Beispiele zu deklarieren. + +!!! warning "Achtung" + Extra-SchlÃŧssel, die `Field` Ãŧberreicht werden, werden auch im resultierenden OpenAPI-Schema Ihrer Anwendung gelistet. Da diese SchlÃŧssel nicht notwendigerweise Teil der OpenAPI-Spezifikation sind, kÃļnnten einige OpenAPI-Tools, wie etwa [der OpenAPI-Validator](https://validator.swagger.io/), nicht mit Ihrem generierten Schema funktionieren. + +## Zusammenfassung + +Sie kÃļnnen Pydantics `Field` verwenden, um zusätzliche Validierungen und Metadaten fÃŧr Modellattribute zu deklarieren. + +Sie kÃļnnen auch Extra-SchlÃŧssel verwenden, um zusätzliche JSON-Schema-Metadaten zu Ãŧberreichen. From 2d886c0e7563cec5a98a823f3eb0932e3e3a394e Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 17:36:44 +0000 Subject: [PATCH 272/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index a4f9a4593c..f6685ed7a9 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/body.md`. PR [#10295](https://github.com/tiangolo/fastapi/pull/10295) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body-multiple-params.md`. PR [#10308](https://github.com/tiangolo/fastapi/pull/10308) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/get-current-user.md`. PR [#2681](https://github.com/tiangolo/fastapi/pull/2681) by [@sh0nk](https://github.com/sh0nk). * 🌐 Add Chinese translation for `docs/zh/docs/advanced/advanced-dependencies.md`. PR [#3798](https://github.com/tiangolo/fastapi/pull/3798) by [@jaystone776](https://github.com/jaystone776). From 7c5c29de9ee7362155665cacfd93e6d76a282242 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 17:37:16 +0000 Subject: [PATCH 273/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index f6685ed7a9..03319666ac 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/body-fields.md`. PR [#10310](https://github.com/tiangolo/fastapi/pull/10310) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body.md`. PR [#10295](https://github.com/tiangolo/fastapi/pull/10295) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body-multiple-params.md`. PR [#10308](https://github.com/tiangolo/fastapi/pull/10308) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Japanese translation for `docs/ja/docs/tutorial/security/get-current-user.md`. PR [#2681](https://github.com/tiangolo/fastapi/pull/2681) by [@sh0nk](https://github.com/sh0nk). From 11a1268fe29b0aeb8bcb69c2c0aa1721fa95fd65 Mon Sep 17 00:00:00 2001 From: Reza Rohani Date: Mon, 29 Jan 2024 21:18:49 +0330 Subject: [PATCH 274/305] =?UTF-8?q?=F0=9F=8C=90=20Update=20Farsi=20transla?= =?UTF-8?q?tion=20for=20`docs/fa/docs/index.md`=20(#10216)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/fa/docs/index.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/docs/fa/docs/index.md b/docs/fa/docs/index.md index 2480843891..cc211848bb 100644 --- a/docs/fa/docs/index.md +++ b/docs/fa/docs/index.md @@ -32,9 +32,9 @@ FastAPI یڊ ŲˆØ¨ ŲØąÛŒŲ…â€ŒŲˆØąÚŠ Ų…Ø¯ØąŲ† ؈ ØŗØąÛŒØš (با ÚŠØ§ØąØ§ÛŒÛŒ با * **ØŗØąØšØĒ**: ÚŠØ§ØąØ§ÛŒÛŒ Ø¨ØŗÛŒØ§Øą Ø¨Ø§Ų„Ø§ ؈ Ų‚Ø§Ø¨Ų„ Ų…Ų‚Ø§ÛŒØŗŲ‡ با **NodeJS** ؈ **Go** (با ØĒØ´ÚŠØą Ø§Ø˛ Starlette ؈ Pydantic). [یڊی Ø§Ø˛ ØŗØąÛŒØšâ€ŒØĒØąÛŒŲ† ŲØąÛŒŲ…â€ŒŲˆØąÚŠâ€ŒŲ‡Ø§ÛŒ ŲžØ§ÛŒØĒŲˆŲ†ÛŒ Ų…ŲˆØŦŲˆØ¯](#performance). -* **ÚŠØ¯Ų†ŲˆÛŒØŗÛŒ ØŗØąÛŒØš**: Ø§ŲØ˛Ø§ÛŒØ´ Û˛Û°Û° ØĒا ÛŗÛ°Û° Ø¯ØąØĩدی ØŗØąØšØĒ ØĒŲˆØŗØšŲ‡ ŲØ§Ø¨Ų„ÛŒØĒâ€ŒŲ‡Ø§ÛŒ ØŦدید. * +* **ÚŠØ¯Ų†ŲˆÛŒØŗÛŒ ØŗØąÛŒØš**: Ø§ŲØ˛Ø§ÛŒØ´ Û˛Û°Û° ØĒا ÛŗÛ°Û° Ø¯ØąØĩدی ØŗØąØšØĒ ØĒŲˆØŗØšŲ‡ Ų‚Ø§Ø¨Ų„ÛŒØĒâ€ŒŲ‡Ø§ÛŒ ØŦدید. * * **باگ ÚŠŲ…ØĒØą**: ÚŠØ§Ų‡Ø´ Û´Û° Ø¯ØąØĩدی ØŽØˇØ§Ų‡Ø§ÛŒ Ø§Ų†ØŗØ§Ų†ÛŒ (Ø¨ØąŲ†Ø§Ų…Ų‡â€ŒŲ†ŲˆÛŒØŗÛŒ). * -* **ØēØąÛŒØ˛ÛŒ**: ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ ŲŲˆŲ‚â€ŒØ§Ų„ØšØ§Ø¯Ų‡ Ø¯Øą Ų…Ø­ÛŒØˇâ€ŒŲ‡Ø§ÛŒ ØĒŲˆØŗØšŲ‡ ÛŒÚŠŲžØ§ØąÚ†Ų‡ (IDE). ØĒÚŠŲ…ÛŒŲ„ Ø¯Øą Ų‡Ų…Ų‡ Ø¨ØŽØ´â€ŒŲ‡Ø§ÛŒ ڊد. ÚŠØ§Ų‡Ø´ Ø˛Ų…Ø§Ų† ØąŲØš باگ. +* **Ų‡ŲˆØ´Ų…Ų†Ø¯Ø§Ų†Ų‡**: ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ ŲŲˆŲ‚â€ŒØ§Ų„ØšØ§Ø¯Ų‡ Ø¯Øą Ų…Ø­ÛŒØˇâ€ŒŲ‡Ø§ÛŒ ØĒŲˆØŗØšŲ‡ ÛŒÚŠŲžØ§ØąÚ†Ų‡ (IDE). ØĒÚŠŲ…ÛŒŲ„ Ø¯Øą Ų‡Ų…Ų‡ Ø¨ØŽØ´â€ŒŲ‡Ø§ÛŒ ڊد. ÚŠØ§Ų‡Ø´ Ø˛Ų…Ø§Ų† ØąŲØš باگ. * **ØĸØŗØ§Ų†**: ØˇØąØ§Ø­ÛŒ Ø´Ø¯Ų‡ Ø¨ØąØ§ÛŒ ÛŒØ§Ø¯Ú¯ÛŒØąÛŒ ؈ Ø§ØŗØĒŲØ§Ø¯Ų‡ ØĸØŗØ§Ų†. ÚŠØ§Ų‡Ø´ Ø˛Ų…Ø§Ų† Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ Ø¨ØąØ§ÛŒ Ų…ØąØ§ØŦØšŲ‡ Ø¨Ų‡ Ų…ØŗØĒŲ†Ø¯Ø§ØĒ. * **ÚŠŲˆÚ†ÚŠ**: ÚŠØ§Ų‡Ø´ ØĒÚŠØąØ§Øą Ø¯Øą ڊد. Ú†Ų†Ø¯ÛŒŲ† Ų‚Ø§Ø¨Ų„ÛŒØĒ Ø¨ØąØ§ÛŒ Ų‡Øą ŲžØ§ØąØ§Ų…ØĒØą (Ų…Ų†Ø¸ŲˆØą ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ ŲˆØąŲˆØ¯ÛŒ ØĒابؚ Ų‡Ų†Ø¯Ų„Øą Ų…ÛŒâ€ŒØ¨Ø§Ø´Ø¯ØŒ Ø¨Ų‡ ب؎ش ØŽŲ„Ø§ØĩŲ‡ Ø¯Øą Ų‡Ų…ÛŒŲ† ØĩŲØ­Ų‡ Ų…ØąØ§ØŦØšŲ‡ Ø´ŲˆØ¯). باگ ÚŠŲ…ØĒØą. * **Ø§ØŗØĒŲˆØ§Øą**: ایØŦاد ڊدی ØĸŲ…Ø§Ø¯Ų‡ Ø¨ØąØ§ÛŒ Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø¯Øą Ų…Ø­ÛŒØˇ ŲžØąŲˆØ¯Ø§ÚŠØ´Ų† ؈ ØĒŲˆŲ„ÛŒØ¯ ØŽŲˆØ¯ÚŠØ§Øą Ų…ØŗØĒŲ†Ø¯Ø§ØĒ ØĒØšØ§Ų…Ų„ÛŒ @@ -140,7 +140,7 @@ $ pip install "uvicorn[standard]" ## Ų…ØĢØ§Ų„ ### ایØŦاد ÚŠŲ†ÛŒØ¯ -* ŲØ§ÛŒŲ„ÛŒ Ø¨Ų‡ Ų†Ø§Ų… `main.py` با Ų…Ø­ØĒŲˆØ§ÛŒ Ø˛ÛŒØą ایØŦاد ÚŠŲ†ÛŒØ¯ : +* ŲØ§ÛŒŲ„ÛŒ Ø¨Ų‡ Ų†Ø§Ų… `main.py` با Ų…Ø­ØĒŲˆØ§ÛŒ Ø˛ÛŒØą ایØŦاد ÚŠŲ†ÛŒØ¯: ```Python from typing import Union @@ -163,7 +163,7 @@ def read_item(item_id: int, q: Union[str, None] = None):
Ų‡Ų…Ú†Ų†ÛŒŲ† Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ Ø§Ø˛ async def... Ų†ÛŒØ˛ Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯ -Ø§Ú¯Øą Ø¯Øą ڊدØĒØ§Ų† Ø§Ø˛ `async` / `await` Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒÚŠŲ†ÛŒØ¯, Ø§Ø˛ `async def` Ø¨ØąØ§ÛŒ ØĒØšØąÛŒŲ ØĒابؚ ØŽŲˆØ¯ Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯: +Ø§Ú¯Øą Ø¯Øą ڊدØĒØ§Ų† Ø§Ø˛ `async` / `await` Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒÚŠŲ†ÛŒØ¯ØŒ Ø§Ø˛ `async def` Ø¨ØąØ§ÛŒ ØĒØšØąÛŒŲ ØĒابؚ ØŽŲˆØ¯ Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯: ```Python hl_lines="9 14" from typing import Optional @@ -211,7 +211,7 @@ INFO: Application startup complete.
Ø¯ØąØ¨Ø§ØąŲ‡ Ø¯ØŗØĒŲˆØą uvicorn main:app --reload... -Ø¯ØŗØĒŲˆØą `uvicorn main:app` Ø´Ø§Ų…Ų„ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒ: +Ø¯ØŗØĒŲˆØą `uvicorn main:app` Ø´Ø§Ų…Ų„ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒ: * `main`: ŲØ§ÛŒŲ„ `main.py` (Ų…Ø§Ú˜ŲˆŲ„ ŲžØ§ÛŒØĒŲˆŲ† ایØŦاد Ø´Ø¯Ų‡). * `app`: Ø´ÛŒØĄ ایØŦاد Ø´Ø¯Ų‡ Ø¯Øą ŲØ§ÛŒŲ„ `main.py` Ø¯Øą ØŽØˇ `app = FastAPI()`. @@ -232,7 +232,7 @@ INFO: Application startup complete. ØĒا Ø§ÛŒŲ†ØŦا Ø´Ų…Ø§ APIای ØŗØ§ØŽØĒید ÚŠŲ‡: * Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ HTTP Ø¨Ų‡ _Ų…ØŗÛŒØąŲ‡Ø§ÛŒ_ `/` ؈ `/items/{item_id}` ØąØ§ Ø¯ØąÛŒØ§ŲØĒ Ų…ÛŒâ€ŒÚŠŲ†Ø¯. -* Ų‡ØąØ¯Ųˆ _Ų…ØŗÛŒØą_ ØšŲ…Ų„ÛŒØ§ØĒ (یا HTTP _Ų…ØĒد_) `GET` ØąØ§ ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ Ų…ÛŒâ€ŒÚŠŲ†Ų†Ø¯. +* Ų‡ØąØ¯Ųˆ _Ų…ØŗÛŒØą_ ØšŲ…Ų„ÛŒØ§ØĒ (یا HTTP _Ų…ØĒد_) `GET` ØąØ§ ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ Ų…ÛŒâ€ŒÚŠŲ†Ø¯. * _Ų…ØŗÛŒØą_ `/items/{item_id}` Ø´Ø§Ų…Ų„ _ŲžØ§ØąØ§Ų…ØĒØą Ų…ØŗÛŒØą_ `item_id` Ø§Ø˛ Ų†ŲˆØš `int` Ø§ØŗØĒ. * _Ų…ØŗÛŒØą_ `/items/{item_id}` Ø´Ø§Ų…Ų„ _ŲžØ§ØąØ§Ų…ØĒØą ŲžØąØŗŲ…Ø§Ų†_ ا؎ØĒÛŒØ§ØąÛŒ `q` Ø§Ø˛ Ų†ŲˆØš `str` Ø§ØŗØĒ. @@ -254,7 +254,7 @@ INFO: Application startup complete. ## ØĒØēÛŒÛŒØą Ų…ØĢØ§Ų„ -Ø­Ø§Ų„ ŲØ§ÛŒŲ„ `main.py` ØąØ§ Ų…ØˇØ§Ø¨Ų‚ Ø˛ÛŒØą ŲˆÛŒØąØ§ÛŒØ´ ÚŠŲ†ÛŒØ¯ ØĒا بØĒŲˆØ§Ų†ÛŒØ¯ Ø¨Ø¯Ų†Ų‡ یڊ Ø¯ØąØŽŲˆØ§ØŗØĒ `PUT` ØąØ§ Ø¯ØąÛŒØ§ŲØĒ ÚŠŲ†ÛŒØ¯. +Ø­Ø§Ų„ ŲØ§ÛŒŲ„ `main.py` ØąØ§ Ų…ØˇØ§Ø¨Ų‚ Ø˛ÛŒØą ŲˆÛŒØąØ§ÛŒØ´ ÚŠŲ†ÛŒØ¯ ØĒا بØĒŲˆØ§Ų†ÛŒØ¯ Ø¨Ø¯Ų†Ų‡ یڊ Ø¯ØąØŽŲˆØ§ØŗØĒ `PUT` ØąØ§ Ø¯ØąÛŒØ§ŲØĒ ÚŠŲ†ÛŒØ¯. Ø¨Ų‡ ÚŠŲ…ÚŠ Pydantic Ø¨Ø¯Ų†Ų‡ Ø¯ØąØŽŲˆØ§ØŗØĒ ØąØ§ با Ø§Ų†ŲˆØ§Øš Ø§ØŗØĒØ§Ų†Ø¯Ø§ØąØ¯ ŲžØ§ÛŒØĒŲˆŲ† ØĒØšØąÛŒŲ ÚŠŲ†ÛŒØ¯. @@ -298,11 +298,11 @@ def update_item(item_id: int, item: Item): ![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) -* ØąŲˆÛŒ Ø¯ÚŠŲ…Ų‡ "Try it out" ÚŠŲ„ÛŒÚŠ ÚŠŲ†ÛŒØ¯, Ø§ÚŠŲ†ŲˆŲ† Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ Ų‡Øą API ØąØ§ Ų…Ø´ØŽØĩ ÚŠØąØ¯Ų‡ ؈ Ø¨Ų‡ ØĩŲˆØąØĒ Ų…ØŗØĒŲ‚ÛŒŲ… با ØĸŲ†Ų‡Ø§ ØĒØšØ§Ų…Ų„ ÚŠŲ†ÛŒØ¯: +* ØąŲˆÛŒ Ø¯ÚŠŲ…Ų‡ "Try it out" ÚŠŲ„ÛŒÚŠ ÚŠŲ†ÛŒØ¯ØŒ Ø§ÚŠŲ†ŲˆŲ† Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ Ų‡Øą API ØąØ§ Ų…Ø´ØŽØĩ ÚŠØąØ¯Ų‡ ؈ Ø¨Ų‡ ØĩŲˆØąØĒ Ų…ØŗØĒŲ‚ÛŒŲ… با ØĸŲ†Ų‡Ø§ ØĒØšØ§Ų…Ų„ ÚŠŲ†ÛŒØ¯: ![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png) -* ØŗŲžØŗ ØąŲˆÛŒ Ø¯ÚŠŲ…Ų‡ "Execute" ÚŠŲ„ÛŒÚŠ ÚŠŲ†ÛŒØ¯, ØŽŲˆØ§Ų‡ÛŒØ¯ دید ÚŠŲ‡ ŲˆØ§ØŗØˇ ÚŠØ§ØąÛŒØąÛŒ با APIŲ‡Ø§ÛŒ ØĒØšØąÛŒŲ Ø´Ø¯Ų‡ Ø§ØąØĒØ¨Ø§Øˇ Ø¨ØąŲ‚ØąØ§Øą ÚŠØąØ¯Ų‡ØŒ ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ ØąØ§ Ø¨Ų‡ ØĸŲ†â€ŒŲ‡Ø§ Ø§ØąØŗØ§Ų„ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ØŒ ØŗŲžØŗ Ų†ØĒایØŦ ØąØ§ Ø¯ØąÛŒØ§ŲØĒ ÚŠØąØ¯Ų‡ ؈ Ø¯Øą ØĩŲØ­Ų‡ Ų†Ø´Ø§Ų† Ų…ÛŒâ€ŒØ¯Ų‡Ø¯: +* ØŗŲžØŗ ØąŲˆÛŒ Ø¯ÚŠŲ…Ų‡ "Execute" ÚŠŲ„ÛŒÚŠ ÚŠŲ†ÛŒØ¯ØŒ ØŽŲˆØ§Ų‡ÛŒØ¯ دید ÚŠŲ‡ ŲˆØ§ØŗØˇ ÚŠØ§ØąØ¨ØąÛŒ با APIŲ‡Ø§ÛŒ ØĒØšØąÛŒŲ Ø´Ø¯Ų‡ Ø§ØąØĒØ¨Ø§Øˇ Ø¨ØąŲ‚ØąØ§Øą ÚŠØąØ¯Ų‡ØŒ ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ ØąØ§ Ø¨Ų‡ ØĸŲ†â€ŒŲ‡Ø§ Ø§ØąØŗØ§Ų„ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ØŒ ØŗŲžØŗ Ų†ØĒایØŦ ØąØ§ Ø¯ØąÛŒØ§ŲØĒ ÚŠØąØ¯Ų‡ ؈ Ø¯Øą ØĩŲØ­Ų‡ Ų†Ø´Ø§Ų† Ų…ÛŒâ€ŒØ¯Ų‡Ø¯: ![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png) @@ -342,7 +342,7 @@ item: Item * ØĒÚŠŲ…ÛŒŲ„ ڊد. * Ø¨ØąØąØŗÛŒ Ø§Ų†ŲˆØ§Øš Ø¯Ø§Ø¯Ų‡. * اؚØĒØ¨Ø§ØąØŗŲ†ØŦی Ø¯Ø§Ø¯Ų‡: - * ØŽØˇØ§Ų‡Ø§ÛŒ ØŽŲˆØ¯ÚŠØ§Øą ؈ Ų…Ø´ØŽØĩ Ø¯Øą Ų‡Ų†Ú¯Ø§Ų… Ų†Ø§Ų…ØšØĒØ¨Øą Ø¨ŲˆØ¯Ų† Ø¯Ø§Ø¯Ų‡ + * ØŽØˇØ§Ų‡Ø§ÛŒ ØŽŲˆØ¯ÚŠØ§Øą ؈ Ų…Ø´ØŽØĩ Ø¯Øą Ų‡Ų†Ú¯Ø§Ų… Ų†Ø§Ų…ØšØĒØ¨Øą Ø¨ŲˆØ¯Ų† Ø¯Ø§Ø¯Ų‡. * اؚØĒØ¨Ø§ØąØŗŲ†ØŦی، Ø­ØĒی Ø¨ØąØ§ÛŒ Ø§Ø´ÛŒØ§ØĄ JSON ØĒ؈ Ø¯Øą ØĒ؈. * ØĒØ¨Ø¯ÛŒŲ„ Ø¯Ø§Ø¯Ų‡ ŲˆØąŲˆØ¯ÛŒ: ÚŠŲ‡ Ø§Ø˛ Ø´Ø¨ÚŠŲ‡ ØąØŗÛŒØ¯Ų‡ Ø¨Ų‡ Ø§Ų†ŲˆØ§Øš ؈ Ø¯Ø§Ø¯â€ŒŲ‡â€Œ ŲžØ§ÛŒØĒŲˆŲ†ÛŒ. Ø§ÛŒŲ† Ø¯Ø§Ø¯Ų‡â€Œ Ø´Ø§Ų…Ų„: * JSON. @@ -366,22 +366,22 @@ item: Item Ø¨Ų‡ Ų…ØĢØ§Ų„ Ų‚Ø¨Ų„ÛŒ Ø¨Ø§Ø˛ Ų…ÛŒâ€ŒÚ¯ØąØ¯ÛŒŲ…ØŒ Ø¯Øą Ø§ÛŒŲ† Ų…ØĢØ§Ų„ **FastAPI** Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą ØąØ§ Ø§Ų†ØŦØ§Ų… Ų…ÛŒâ€ŒØ¯Ų‡Ø¯: -* اؚØĒØ¨Ø§ØąØŗŲ†ØŦی Ø§ÛŒŲ†ÚŠŲ‡ ŲžØ§ØąØ§Ų…ØĒØą `item_id` Ø¯Øą Ų…ØŗÛŒØą Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `GET` ؈ `PUT` Ų…ŲˆØŦŲˆØ¯ Ø§ØŗØĒ . +* اؚØĒØ¨Ø§ØąØŗŲ†ØŦی Ø§ÛŒŲ†ÚŠŲ‡ ŲžØ§ØąØ§Ų…ØĒØą `item_id` Ø¯Øą Ų…ØŗÛŒØą Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `GET` ؈ `PUT` Ų…ŲˆØŦŲˆØ¯ Ø§ØŗØĒ. * اؚØĒØ¨Ø§ØąØŗŲ†ØŦی Ø§ÛŒŲ†ÚŠŲ‡ ŲžØ§ØąØ§Ų…ØĒØą `item_id` Ø¯Øą Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `GET` ؈ `PUT` Ø§Ø˛ Ų†ŲˆØš `int` Ø§ØŗØĒ. * Ø§Ú¯Øą ØēÛŒØą Ø§Ø˛ Ø§ÛŒŲ† Ų…ŲˆØ§ØąØ¯ باشد، ØŗØąŲˆÛŒØŗâ€ŒÚ¯ÛŒØąŲ†Ø¯Ų‡ ØŽØˇØ§ÛŒ Ų…ŲÛŒØ¯ ؈ Ų…Ø´ØŽØĩی Ø¯ØąÛŒØ§ŲØĒ ØŽŲˆØ§Ų‡Ø¯ ÚŠØąØ¯. * Ø¨ØąØąØŗÛŒ ؈ØŦŲˆØ¯ ŲžØ§ØąØ§Ų…ØĒØą ŲžØąØŗŲ…Ø§Ų† ا؎ØĒÛŒØ§ØąÛŒ `q` (Ų…Ø§Ų†Ų†Ø¯ `http://127.0.0.1:8000/items/foo?q=somequery`) Ø¯Øą Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `GET`. - * Ø§Ø˛ ØĸŲ†ØŦا ÚŠŲ‡ ŲžØ§ØąØ§Ų…ØĒØą `q` با `= None` Ų…Ų‚Ø¯Ø§ØąØ¯Ų‡ÛŒ Ø´Ø¯Ų‡ Ø§ØŗØĒ, Ø§ÛŒŲ† ŲžØ§ØąØ§Ų…ØĒØą ا؎ØĒÛŒØ§ØąÛŒ Ø§ØŗØĒ. + * Ø§Ø˛ ØĸŲ†ØŦا ÚŠŲ‡ ŲžØ§ØąØ§Ų…ØĒØą `q` با `= None` Ų…Ų‚Ø¯Ø§ØąØ¯Ų‡ÛŒ Ø´Ø¯Ų‡ Ø§ØŗØĒ، Ø§ÛŒŲ† ŲžØ§ØąØ§Ų…ØĒØą ا؎ØĒÛŒØ§ØąÛŒ Ø§ØŗØĒ. * Ø§Ú¯Øą Ø§Ø˛ Ų…Ų‚Ø¯Ø§Øą Ø§ŲˆŲ„ÛŒŲ‡ `None` Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų†ÚŠŲ†ÛŒŲ…ØŒ Ø§ÛŒŲ† ŲžØ§ØąØ§Ų…ØĒØą Ø§Ų„Ø˛Ø§Ų…ÛŒ ØŽŲˆØ§Ų‡Ø¯ Ø¨ŲˆØ¯ (Ų‡Ų…Ø§Ų†Ų†Ø¯ Ø¨Ø¯Ų†Ų‡ Ø¯ØąØŽŲˆØ§ØŗØĒ Ø¯Øą Ø¯ØąØŽŲˆØ§ØŗØĒ `PUT`). -* Ø¨ØąØ§ÛŒ Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `PUT` Ø¨Ų‡ ØĸØ¯ØąØŗ `/items/{item_id}`, Ø¨Ø¯Ų†Ų‡ Ø¯ØąØŽŲˆØ§ØŗØĒ باید Ø§Ø˛ Ų†ŲˆØš JSON ØĒØšØąÛŒŲ Ø´Ø¯Ų‡ باشد: +* Ø¨ØąØ§ÛŒ Ø¯ØąØŽŲˆØ§ØŗØĒâ€ŒŲ‡Ø§ÛŒ `PUT` Ø¨Ų‡ ØĸØ¯ØąØŗ `/items/{item_id}`، Ø¨Ø¯Ų†Ų‡ Ø¯ØąØŽŲˆØ§ØŗØĒ باید Ø§Ø˛ Ų†ŲˆØš JSON ØĒØšØąÛŒŲ Ø´Ø¯Ų‡ باشد: * Ø¨ØąØąØŗÛŒ Ø§ÛŒŲ†ÚŠŲ‡ Ø¨Ø¯Ų†Ų‡ Ø´Ø§Ų…Ų„ ŲÛŒŲ„Ø¯ÛŒ با Ų†Ø§Ų… `name` ؈ Ø§Ø˛ Ų†ŲˆØš `str` Ø§ØŗØĒ. * Ø¨ØąØąØŗÛŒ Ø§ÛŒŲ†ÚŠŲ‡ Ø¨Ø¯Ų†Ų‡ Ø´Ø§Ų…Ų„ ŲÛŒŲ„Ø¯ÛŒ با Ų†Ø§Ų… `price` ؈ Ø§Ø˛ Ų†ŲˆØš `float` Ø§ØŗØĒ. - * Ø¨ØąØąØŗÛŒ Ø§ÛŒŲ†ÚŠŲ‡ Ø¨Ø¯Ų†Ų‡ Ø´Ø§Ų…Ų„ ŲÛŒŲ„Ø¯ÛŒ ا؎ØĒÛŒØ§ØąÛŒ با Ų†Ø§Ų… `is_offer` Ø§ØŗØĒ, ÚŠŲ‡ Ø¯Øą ØĩŲˆØąØĒ ؈ØŦŲˆØ¯ باید Ø§Ø˛ Ų†ŲˆØš `bool` باشد. + * Ø¨ØąØąØŗÛŒ Ø§ÛŒŲ†ÚŠŲ‡ Ø¨Ø¯Ų†Ų‡ Ø´Ø§Ų…Ų„ ŲÛŒŲ„Ø¯ÛŒ ا؎ØĒÛŒØ§ØąÛŒ با Ų†Ø§Ų… `is_offer` Ø§ØŗØĒ، ÚŠŲ‡ Ø¯Øą ØĩŲˆØąØĒ ؈ØŦŲˆØ¯ باید Ø§Ø˛ Ų†ŲˆØš `bool` باشد. * ØĒŲ…Ø§Ų…ÛŒ Ø§ÛŒŲ† Ų…ŲˆØ§ØąØ¯ Ø¨ØąØ§ÛŒ Ø§Ø´ÛŒØ§ØĄ JSON Ø¯Øą Ų‡Øą ØšŲ…Ų‚ÛŒ Ų‚Ø§Ø¨Ų„ Ø¨ØąØąØŗÛŒ Ų…ÛŒâ€ŒØ¨Ø§Ø´Ø¯. * ØĒØ¨Ø¯ÛŒŲ„ Ø§Ø˛/Ø¨Ų‡ JSON Ø¨Ų‡ ØĩŲˆØąØĒ ØŽŲˆØ¯ÚŠØ§Øą. -* Ų…ØŗØĒŲ†Ø¯ØŗØ§Ø˛ÛŒ Ų‡Ų…Ų‡ Ú†ÛŒØ˛ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ OpenAPI, ÚŠŲ‡ Ų…ÛŒâ€ŒØĒŲˆØ§Ų† Ø§Ø˛ ØĸŲ† Ø¨ØąØ§ÛŒ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠØąØ¯: +* Ų…ØŗØĒŲ†Ø¯ØŗØ§Ø˛ÛŒ Ų‡Ų…Ų‡ Ú†ÛŒØ˛ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ OpenAPI، ÚŠŲ‡ Ų…ÛŒâ€ŒØĒŲˆØ§Ų† Ø§Ø˛ ØĸŲ† Ø¨ØąØ§ÛŒ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠØąØ¯: * ØŗÛŒØŗØĒŲ… Ų…ØŗØĒŲ†Ø¯Ø§ØĒ ØĒØšØ§Ų…Ų„ÛŒ. * ØĒŲˆŲ„ÛŒØ¯ ØŽŲˆØ¯ÚŠØ§Øą ڊد ØŗØąŲˆÛŒØŗâ€ŒÚ¯ÛŒØąŲ†Ø¯Ų‡â€Œ Ø¯Øą Ø˛Ø¨Ø§Ų†â€ŒŲ‡Ø§ÛŒ Ø¨ØąŲ†Ø§Ų…Ų‡â€ŒŲ†ŲˆÛŒØŗÛŒ Ø¨ÛŒØ´Ų…Ø§Øą. -* ŲØąØ§Ų‡Ų… ØŗØ§Ø˛ÛŒ Û˛ Ų…ØŗØĒŲ†Ø¯ ØĒØšØ§Ų…Ų„ÛŒ Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą ŲˆØ¨ Ø¨Ų‡ ØĩŲˆØąØĒ ŲžÛŒØ´â€ŒŲØąØļ . +* ŲØąØ§Ų‡Ų… ØŗØ§Ø˛ÛŒ Û˛ Ų…ØŗØĒŲ†Ø¯ ØĒØšØ§Ų…Ų„ÛŒ Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą ŲˆØ¨ Ø¨Ų‡ ØĩŲˆØąØĒ ŲžÛŒØ´â€ŒŲØąØļ. --- @@ -413,7 +413,7 @@ item: Item **Ų‡Ø´Ø¯Ø§Øą Ø§ØŗŲžŲˆÛŒŲ„**: ب؎ش ØĸŲ…ŲˆØ˛Ø´ - ØąØ§Ų‡Ų†Ų…Ø§ÛŒ ÚŠØ§ØąØ¨Øą Ø´Ø§Ų…Ų„ Ų…ŲˆØ§ØąØ¯ Ø˛ÛŒØą Ø§ØŗØĒ: -* Ø§ØšŲ„Ø§Ų† **ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ** Ų…ŲˆØŦŲˆØ¯ Ø¯Øą Ø¨ØŽØ´â€ŒŲ‡Ø§ÛŒ Ø¯ÛŒÚ¯Øą Ø¯ØąØŽŲˆØ§ØŗØĒ، Ø´Ø§Ų…Ų„: **ØŗØąØĸÛŒŲ†Ø¯â€Œ (Ų‡Ø¯Øą)Ų‡Ø§**, **ÚŠŲˆÚŠÛŒâ€ŒŲ‡Ø§**, **ŲÛŒŲ„Ø¯â€ŒŲ‡Ø§ÛŒ ŲØąŲ…** ؈ **ŲØ§ÛŒŲ„â€ŒŲ‡Ø§**. +* Ø§ØšŲ„Ø§Ų† **ŲžØ§ØąØ§Ų…ØĒØąŲ‡Ø§ÛŒ** Ų…ŲˆØŦŲˆØ¯ Ø¯Øą Ø¨ØŽØ´â€ŒŲ‡Ø§ÛŒ Ø¯ÛŒÚ¯Øą Ø¯ØąØŽŲˆØ§ØŗØĒ، Ø´Ø§Ų…Ų„: **ØŗØąØĸÛŒŲ†Ø¯â€Œ (Ų‡Ø¯Øą)Ų‡Ø§**، **ÚŠŲˆÚŠÛŒâ€ŒŲ‡Ø§**، **ŲÛŒŲ„Ø¯â€ŒŲ‡Ø§ÛŒ ŲØąŲ…** ؈ **ŲØ§ÛŒŲ„â€ŒŲ‡Ø§**. * Ú†Ú¯ŲˆŲ†Ú¯ÛŒ ØĒŲ†Ø¸ÛŒŲ… **Ų…Ø­Ø¯ŲˆØ¯ÛŒØĒâ€ŒŲ‡Ø§ÛŒ اؚØĒØ¨Ø§ØąØŗŲ†ØŦی** Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† Ų…ØĢØ§Ų„ `maximum_length` یا `regex`. * ØŗÛŒØŗØĒŲ… **Dependency Injection** Ų‚ŲˆÛŒ ؈ ÚŠØ§ØąØ¨ØąØ¯ÛŒ. * Ø§Ų…Ų†ÛŒØĒ ؈ ØĒایید Ų‡ŲˆÛŒØĒ, Ø´Ø§Ų…Ų„ ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ Ø§Ø˛ **OAuth2** Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą **JWT tokens** ؈ **HTTP Basic**. @@ -428,7 +428,7 @@ item: Item ## ÚŠØ§ØąØ§ÛŒÛŒ -Ų…ØšÛŒØ§Øą (Ø¨Ų†Ú†Ų…Ø§ØąÚŠâ€Œ)Ų‡Ø§ÛŒ Ų…ØŗØĒŲ‚Ų„ TechEmpower حاڊی Ø§Ø˛ ØĸŲ† Ø§ØŗØĒ ÚŠŲ‡ Ø¨ØąŲ†Ø§Ų…Ų‡â€ŒŲ‡Ø§ÛŒ **FastAPI** ÚŠŲ‡ ØĒØ­ØĒ Uvicorn اØŦØąØ§ Ų…ÛŒâ€ŒØ´ŲˆØ¯ØŒ یڊی Ø§Ø˛ ØŗØąÛŒØšâ€ŒØĒØąÛŒŲ† ŲØąÛŒŲ…â€ŒŲˆØąÚŠâ€ŒŲ‡Ø§ÛŒ Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą ŲžØ§ÛŒØĒŲˆŲ†, Ø§ØŗØĒ ÚŠŲ‡ ÚŠŲ…ÛŒ ØļØšÛŒŲâ€ŒØĒØą Ø§Ø˛ Starlette ؈ Uvicorn ØšŲ…Ų„ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ (ŲØąÛŒŲ…â€ŒŲˆØąÚŠ ؈ ØŗØąŲˆØąÛŒ ÚŠŲ‡ FastAPI Ø¨Øą Ø§ØŗØ§Øŗ ØĸŲ†Ų‡Ø§ ایØŦاد Ø´Ø¯Ų‡ Ø§ØŗØĒ) (*) +Ų…ØšÛŒØ§Øą (Ø¨Ų†Ú†Ų…Ø§ØąÚŠâ€Œ)Ų‡Ø§ÛŒ Ų…ØŗØĒŲ‚Ų„ TechEmpower حاڊی Ø§Ø˛ ØĸŲ† Ø§ØŗØĒ ÚŠŲ‡ Ø¨ØąŲ†Ø§Ų…Ų‡â€ŒŲ‡Ø§ÛŒ **FastAPI** ÚŠŲ‡ ØĒØ­ØĒ Uvicorn اØŦØąØ§ Ų…ÛŒâ€ŒØ´ŲˆØ¯ØŒ یڊی Ø§Ø˛ ØŗØąÛŒØšâ€ŒØĒØąÛŒŲ† ŲØąÛŒŲ…â€ŒŲˆØąÚŠâ€ŒŲ‡Ø§ÛŒ Ų…Ø¨ØĒŲ†ÛŒ Ø¨Øą ŲžØ§ÛŒØĒŲˆŲ†ØŒ Ø§ØŗØĒ ÚŠŲ‡ ÚŠŲ…ÛŒ ØļØšÛŒŲâ€ŒØĒØą Ø§Ø˛ Starlette ؈ Uvicorn ØšŲ…Ų„ Ų…ÛŒâ€ŒÚŠŲ†Ø¯ (ŲØąÛŒŲ…â€ŒŲˆØąÚŠ ؈ ØŗØąŲˆØąÛŒ ÚŠŲ‡ FastAPI Ø¨Øą Ø§ØŗØ§Øŗ ØĸŲ†Ų‡Ø§ ایØŦاد Ø´Ø¯Ų‡ Ø§ØŗØĒ) (*) Ø¨ØąØ§ÛŒ Ø¯ØąÚŠ Ø¨Ų‡ØĒØąÛŒ Ø§Ø˛ Ø§ÛŒŲ† Ų…ŲˆØļŲˆØš Ø¨Ų‡ ب؎ش Ø¨Ų†Ú†â€ŒŲ…Ø§ØąÚŠâ€ŒŲ‡Ø§ Ų…ØąØ§ØŦØšŲ‡ ÚŠŲ†ÛŒØ¯. @@ -445,7 +445,7 @@ item: Item * jinja2 - Ø¯Øą ØĩŲˆØąØĒی ÚŠŲ‡ Ø¨ØŽŲˆØ§Ų‡ÛŒØ¯ Ø§Ø˛ ŲžÛŒÚŠØąØ¨Ų†Ø¯ÛŒ ŲžÛŒØ´â€ŒŲØąØļ Ø¨ØąØ§ÛŒ Ų‚Ø§Ų„Ø¨â€ŒŲ‡Ø§ Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯. * python-multipart - Ø¯Øą ØĩŲˆØąØĒی ÚŠŲ‡ Ø¨ØŽŲˆØ§Ų‡ÛŒØ¯ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ `request.form()` Ø§Ø˛ Ų‚Ø§Ø¨Ų„ÛŒØĒ "ØĒØŦØ˛ÛŒŲ‡ (parse)" ŲØąŲ… Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯. * itsdangerous - Ø¯Øą ØĩŲˆØąØĒی ÚŠŲ‡ Ø¨ØŽŲˆØ§ÛŒØ¯ Ø§Ø˛ `SessionMiddleware` ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ ÚŠŲ†ÛŒØ¯. -* pyyaml - Ø¨ØąØ§ÛŒ ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ `SchemaGenerator` Ø¯Øą Starlet (Ø¨Ų‡ احØĒŲ…Ø§Ų„ Ø˛ÛŒØ§Ø¯ Ø¨ØąØ§ÛŒ ÚŠØ§Øą ÚŠØąØ¯Ų† با FastAPI Ø¨Ų‡ ØĸŲ† Ų†ÛŒØ§Ø˛ÛŒ ŲžÛŒØ¯Ø§ Ų†Ų…ÛŒâ€ŒÚŠŲ†ÛŒØ¯.). +* pyyaml - Ø¨ØąØ§ÛŒ ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ `SchemaGenerator` Ø¯Øą Starlet (Ø¨Ų‡ احØĒŲ…Ø§Ų„ Ø˛ÛŒØ§Ø¯ Ø¨ØąØ§ÛŒ ÚŠØ§Øą ÚŠØąØ¯Ų† با FastAPI Ø¨Ų‡ ØĸŲ† Ų†ÛŒØ§Ø˛ÛŒ ŲžÛŒØ¯Ø§ Ų†Ų…ÛŒâ€ŒÚŠŲ†ÛŒØ¯). * graphene - Ø¯Øą ØĩŲˆØąØĒی ÚŠŲ‡ Ø§Ø˛ `GraphQLApp` ŲžØ´ØĒÛŒØ¨Ø§Ų†ÛŒ Ų…ÛŒâ€ŒÚŠŲ†ÛŒØ¯. * ujson - Ø¯Øą ØĩŲˆØąØĒی ÚŠŲ‡ Ø¨ØŽŲˆØ§Ų‡ÛŒØ¯ Ø§Ø˛ `UJSONResponse` Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯. From 08b98adea61dd424c41e00b60fd04b1c7bf6df52 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 17:49:07 +0000 Subject: [PATCH 275/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 03319666ac..412b55fee3 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Update Farsi translation for `docs/fa/docs/index.md`. PR [#10216](https://github.com/tiangolo/fastapi/pull/10216) by [@theonlykingpin](https://github.com/theonlykingpin). * 🌐 Add German translation for `docs/de/docs/tutorial/body-fields.md`. PR [#10310](https://github.com/tiangolo/fastapi/pull/10310) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body.md`. PR [#10295](https://github.com/tiangolo/fastapi/pull/10295) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body-multiple-params.md`. PR [#10308](https://github.com/tiangolo/fastapi/pull/10308) by [@nilslindemann](https://github.com/nilslindemann). From e3728489fad1cdf871faa537472e9028b42304ff Mon Sep 17 00:00:00 2001 From: mojtaba <121169359+mojtabapaso@users.noreply.github.com> Date: Mon, 29 Jan 2024 21:23:46 +0330 Subject: [PATCH 276/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Persian=20translat?= =?UTF-8?q?ion=20for=20`docs/fa/docs/tutorial/middleware.md`=20(#9695)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/fa/docs/tutorial/middleware.md | 59 +++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 docs/fa/docs/tutorial/middleware.md diff --git a/docs/fa/docs/tutorial/middleware.md b/docs/fa/docs/tutorial/middleware.md new file mode 100644 index 0000000000..c5752a4b54 --- /dev/null +++ b/docs/fa/docs/tutorial/middleware.md @@ -0,0 +1,59 @@ +# Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§Øą - middleware + +Ø´Ų…Ø§ Ų…ÛŒØĒŲˆØ§Ų†ÛŒØ¯ Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§ØąŲ‡Ø§ ØąØ§ Ø¯Øą **FastAPI** اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +"Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§Øą" یڊ ØĒابؚ Ø§ØŗØĒ ÚŠŲ‡ با Ų‡Øą Ø¯ØąØŽŲˆØ§ØŗØĒ(request) Ų‚Ø¨Ų„ Ø§Ø˛ ŲžØąØ¯Ø§Ø˛Ø´ ØĒŲˆØŗØˇ Ų‡Øą path operation (ØšŲ…Ų„ÛŒØ§ØĒ Ų…ØŗÛŒØą) ؎اØĩ ÚŠØ§Øą Ų…ÛŒâ€ŒÚŠŲ†Ø¯. Ų‡Ų…Ú†Ų†ÛŒŲ† با Ų‡Øą ŲžØ§ØŗØŽ(response) Ų‚Ø¨Ų„ Ø§Ø˛ Ø¨Ø§Ø˛Ú¯Ø´ØĒ ØĸŲ† Ų†ÛŒØ˛ ÚŠØ§Øą Ų…ÛŒâ€ŒÚŠŲ†Ø¯. + +* Ų‡Øą **Ø¯ØąØŽŲˆØ§ØŗØĒی (request)** ÚŠŲ‡ Ø¨Ų‡ Ø¨ØąŲ†Ø§Ų…Ų‡ Ø´Ų…Ø§ Ų…ÛŒ Øĸید ØąØ§ Ų…ÛŒ Ú¯ÛŒØąØ¯. +* ØŗŲžØŗ Ų…ÛŒ ØĒŲˆØ§Ų†Ø¯ ÚŠØ§ØąÛŒ Ø¨ØąØ§ÛŒ ØĸŲ† **Ø¯ØąØŽŲˆØ§ØŗØĒ** Ø§Ų†ØŦØ§Ų… Ø¯Ų‡ÛŒØ¯ یا Ų‡Øą ڊد Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ØĒØ§Ų† ØąØ§ اØŦØąØ§ ÚŠŲ†ÛŒØ¯. +* ØŗŲžØŗ **Ø¯ØąØŽŲˆØ§ØŗØĒ** ØąØ§ Ø¨Ų‡ ب؎ش Ø¯ÛŒÚ¯ØąÛŒ Ø§Ø˛ Ø¨ØąŲ†Ø§Ų…Ų‡ (ØĒŲˆØŗØˇ یڊ path operation Ų…Ø´ØŽØĩ) Ø¨ØąØ§ÛŒ ŲžØąØ¯Ø§Ø˛Ø´ Ø§ØąØŗØ§Ų„ Ų…ÛŒ ÚŠŲ†Ø¯. +* ØŗŲžØŗ **ŲžØ§ØŗØŽ** ØĒŲˆŲ„ÛŒØ¯ Ø´Ø¯Ų‡ ØĒŲˆØŗØˇ Ø¨ØąŲ†Ø§Ų…Ų‡ ØąØ§ (ØĒŲˆØŗØˇ یڊ path operation Ų…Ø´ØŽØĩ) Ø¯ØąÛŒØ§ŲØĒ Ų…ÛŒâ€ŒÚŠŲ†Ø¯. +* Ų…ÛŒ ØĒŲˆØ§Ų†Ø¯ ÚŠØ§ØąÛŒ با **ŲžØ§ØŗØŽ** Ø§Ų†ØŦØ§Ų… Ø¯Ų‡ÛŒØ¯ یا Ų‡Øą ڊد Ų…ŲˆØąØ¯ Ų†ÛŒØ§Ø˛ØĒØ§Ų† ØąØ§ اØŦØąØ§ ÚŠŲ†Ø¯. +* ØŗŲžØŗ **ŲžØ§ØŗØŽ** ØąØ§ Ø¨ØąŲ…ÛŒ Ú¯ØąØ¯Ø§Ų†Ø¯. + +!!! ØĒ؈ØŦŲ‡ "ØŦØ˛ØĻیاØĒ ŲŲ†ÛŒ" + Ø¯Øą ØĩŲˆØąØĒ ؈ØŦŲˆØ¯ ŲˆØ§Ø¨ØŗØĒگی Ų‡Ø§ÛŒÛŒ با `yield`، ڊد ØŽØąŲˆØŦی **ŲžØŗ Ø§Ø˛** اØŦØąØ§ÛŒ Ų…ÛŒØ§Ų†â€Œâ€ŒØ§ŲØ˛Ø§Øą اØŦØąØ§ ØŽŲˆØ§Ų‡Ø¯ شد. + + Ø¯Øą ØĩŲˆØąØĒ ؈ØŦŲˆØ¯ Ų‡Øą Ú¯ŲˆŲ†Ų‡ ŲˆØ¸Ø§ÛŒŲ ŲžØŗ Ø˛Ų…ÛŒŲ†Ų‡ (ÚŠŲ‡ Ø¯Øą Ø§Ø¯Ø§Ų…Ų‡ ØĒ؈Øļیح Ø¯Ø§Ø¯Ų‡ Ų…ÛŒâ€ŒØ´ŲˆŲ†Ø¯)، ØĒŲ…Ø§Ų… Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§ØąŲ‡Ø§ *ŲžØŗ Ø§Ø˛ ØĸŲ†* اØŦØąØ§ ØŽŲˆØ§Ų‡Ų†Ø¯ شد. + +## ØŗØ§ØŽØĒ یڊ Ų…ÛŒØ§Ų† Ø§ŲØ˛Ø§Øą + +Ø¨ØąØ§ÛŒ ایØŦاد یڊ Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§ØąØŒ Ø§Ø˛ Ø¯ÚŠŲˆØąÛŒØĒŲˆØą `@app.middleware("http")` Ø¯Øą Ø¨Ø§Ų„Ø§ÛŒ یڊ ØĒابؚ Ø§ØŗØĒŲØ§Ø¯Ų‡ Ų…ÛŒâ€ŒØ´ŲˆØ¯. + +ØĒابؚ Ų…ÛŒØ§Ų† Ø§ŲØ˛Ø§Øą Ø¯ØąÛŒØ§ŲØĒ Ų…ÛŒ ÚŠŲ†Ø¯: +* `Ø¯ØąØŽŲˆØ§ØŗØĒ` +* ØĒابؚ `call_next` ÚŠŲ‡ `Ø¯ØąØŽŲˆØ§ØŗØĒ` ØąØ§ Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† ŲžØ§ØąØ§Ų…ØĒØą Ø¯ØąÛŒØ§ŲØĒ Ų…ÛŒ ÚŠŲ†Ø¯ + * Ø§ÛŒŲ† ØĒابؚ `Ø¯ØąØŽŲˆØ§ØŗØĒ` ØąØ§ Ø¨Ų‡ *path operation* Ų…ØąØ¨ŲˆØˇŲ‡ Ø§ØąØŗØ§Ų„ Ų…ÛŒ ÚŠŲ†Ø¯. + * ØŗŲžØŗ `ŲžØ§ØŗØŽ` ØĒŲˆŲ„ÛŒØ¯ Ø´Ø¯Ų‡ ØĒŲˆØŗØˇ *path operation* Ų…ØąØ¨ŲˆØˇŲ‡ ØąØ§ Ø¨ØąŲ…ÛŒâ€ŒÚ¯ØąØ¯Ø§Ų†Ø¯. +* Ø´Ų…Ø§ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ ØŗŲžØŗ `ŲžØ§ØŗØŽ` ØąØ§ ØĒØēÛŒÛŒØą Ø¯Ø§Ø¯Ų‡ ؈ ŲžØŗ Ø§Ø˛ ØĸŲ† ØąØ§ Ø¨ØąÚ¯ØąØ¯Ø§Ų†ÛŒØ¯. + +```Python hl_lines="8-9 11 14" +{!../../../docs_src/middleware/tutorial001.py!} +``` + +!!! Ų†ÚŠØĒŲ‡ Ø¨Ų‡ ØŽØ§ØˇØą داشØĒŲ‡ باشید ÚŠŲ‡ Ų‡Ø¯ØąŲ‡Ø§ÛŒ ا؎ØĒØĩاØĩی ØŗŲØ§ØąØ´ÛŒ ØąØ§ Ų…ÛŒ ØĒŲˆØ§Ų† با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ ŲžÛŒØ´ŲˆŲ†Ø¯ "X-" اØļØ§ŲŲ‡ ÚŠØąØ¯. + + Ø§Ų…Ø§ Ø§Ú¯Øą Ų‡Ø¯ØąŲ‡Ø§ÛŒ ØŗŲØ§ØąØ´ÛŒ Ø¯Ø§ØąÛŒØ¯ ÚŠŲ‡ Ų…ÛŒâ€ŒØŽŲˆØ§Ų‡ÛŒØ¯ Ų…ØąŲˆØąÚ¯Øą ÚŠØ§ØąØ¨Øą بØĒŲˆØ§Ų†Ø¯ ØĸŲ†Ų‡Ø§ ØąØ§ Ø¨Ø¨ÛŒŲ†Ø¯ØŒ باید ØĸŲ†Ų‡Ø§ ØąØ§ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ ŲžØ§ØąØ§Ų…ØĒØą `expose_headers` ÚŠŲ‡ Ø¯Øą Ų…ØŗØĒŲ†Ø¯Ø§ØĒ CORS Ø§Ø˛ Starlette ØĒ؈Øļیح Ø¯Ø§Ø¯Ų‡ Ø´Ø¯Ų‡ Ø§ØŗØĒ، Ø¨Ų‡ ŲžÛŒÚŠØąØ¨Ų†Ø¯ÛŒ CORS ØŽŲˆØ¯ اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +!!! ØĒ؈ØŦŲ‡ "ØŦØ˛ØĻیاØĒ ŲŲ†ÛŒ" + Ø´Ų…Ø§ Ų‡Ų…Ú†Ų†ÛŒŲ† Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ Ø§Ø˛ `from starlette.requests import Request` Ø§ØŗØĒŲØ§Ø¯Ų‡ ÚŠŲ†ÛŒØ¯. + + **FastAPI** Ø§ÛŒŲ† ØąØ§ Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† یڊ ØŗŲ‡ŲˆŲ„ØĒ Ø¨ØąØ§ÛŒ Ø´Ų…Ø§ Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† Ø¨ØąŲ†Ø§Ų…Ų‡â€ŒŲ†ŲˆÛŒØŗ ŲØąØ§Ų‡Ų… Ų…ÛŒâ€ŒÚŠŲ†Ø¯. Ø§Ų…Ø§ Ø§ÛŒŲ† Ų…ØŗØĒŲ‚ÛŒŲ…Ø§ Ø§Ø˛ Starlette Ø¨Ų‡ Ø¯ØŗØĒ Ų…ÛŒâ€ŒØĸید. + +### Ų‚Ø¨Ų„ ؈ بؚد Ø§Ø˛ `ŲžØ§ØŗØŽ` + +Ø´Ų…Ø§ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ ڊدی ØąØ§ Ø¨ØąØ§ÛŒ اØŦØąØ§ با `Ø¯ØąØŽŲˆØ§ØŗØĒ`، Ų‚Ø¨Ų„ Ø§Ø˛ Ø§ÛŒŲ†ÚŠŲ‡ Ų‡Øą *path operation* ØĸŲ† ØąØ§ Ø¯ØąÛŒØ§ŲØĒ ÚŠŲ†Ø¯ØŒ اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +Ų‡Ų…Ú†Ų†ÛŒŲ† ŲžØŗ Ø§Ø˛ ØĒŲˆŲ„ÛŒØ¯ `ŲžØ§ØŗØŽ`، Ų‚Ø¨Ų„ Ø§Ø˛ Ø¨Ø§Ø˛Ú¯Ø´ØĒ ØĸŲ†ØŒ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ ڊدی ØąØ§ اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +Ø¨Ų‡ ØšŲ†ŲˆØ§Ų† Ų…ØĢØ§Ų„ØŒ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ یڊ Ų‡Ø¯Øą ØŗŲØ§ØąØ´ÛŒ Ø¨Ų‡ Ų†Ø§Ų… `X-Process-Time` ÚŠŲ‡ Ø´Ø§Ų…Ų„ Ø˛Ų…Ø§Ų† ŲžØąØ¯Ø§Ø˛Ø´ Ø¯ØąØŽŲˆØ§ØŗØĒ ؈ ØĒŲˆŲ„ÛŒØ¯ ŲžØ§ØŗØŽ Ø¨Ų‡ ØĩŲˆØąØĒ ØĢØ§Ų†ÛŒŲ‡ Ø§ØŗØĒ، اØļØ§ŲŲ‡ ÚŠŲ†ÛŒØ¯. + +```Python hl_lines="10 12-13" +{!../../../docs_src/middleware/tutorial001.py!} +``` + + ## ØŗØ§ÛŒØą Ų…ÛŒØ§Ų† Ø§ŲØ˛Ø§Øą + +Ø´Ų…Ø§ Ų…ÛŒâ€ŒØĒŲˆØ§Ų†ÛŒØ¯ Ø¨ØšØ¯Ø§Ų‹ Ø¯Øą Ų…ŲˆØąØ¯ Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§ØąŲ‡Ø§ÛŒ Ø¯ÛŒÚ¯Øą Ø¯Øą [ØąØ§Ų‡Ų†Ų…Ø§ÛŒ ÚŠØ§ØąØ¨Øą ŲžÛŒØ´ØąŲØĒŲ‡: Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§Øą ŲžÛŒØ´ØąŲØĒŲ‡](../advanced/middleware.md){.internal-link target=_blank} بیشØĒØą Ø¨ØŽŲˆØ§Ų†ÛŒØ¯. + +Ø´Ų…Ø§ Ø¯Øą ب؎ش بؚدی Ø¯Øą Ų…ŲˆØąØ¯ Ø§ÛŒŲ† ÚŠŲ‡ Ú†Ú¯ŲˆŲ†Ų‡ با Ø§ØŗØĒŲØ§Ø¯Ų‡ Ø§Ø˛ یڊ Ų…ÛŒØ§Ų†â€ŒØ§ŲØ˛Ø§ØąØŒ CORS ØąØ§ Ų…Ø¯ÛŒØąÛŒØĒ ÚŠŲ†ÛŒØ¯ØŒ ØŽŲˆØ§Ų‡ÛŒØ¯ ØŽŲˆØ§Ų†Ø¯. From 4f8eec808f7edebec85cc976a42e2b7f7f70a400 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 17:55:19 +0000 Subject: [PATCH 277/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 412b55fee3..15798ec4b0 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Persian translation for `docs/fa/docs/tutorial/middleware.md`. PR [#9695](https://github.com/tiangolo/fastapi/pull/9695) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Update Farsi translation for `docs/fa/docs/index.md`. PR [#10216](https://github.com/tiangolo/fastapi/pull/10216) by [@theonlykingpin](https://github.com/theonlykingpin). * 🌐 Add German translation for `docs/de/docs/tutorial/body-fields.md`. PR [#10310](https://github.com/tiangolo/fastapi/pull/10310) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add German translation for `docs/de/docs/tutorial/body.md`. PR [#10295](https://github.com/tiangolo/fastapi/pull/10295) by [@nilslindemann](https://github.com/nilslindemann). From 653a3579ca807f55e128084e3833ed6324f902a6 Mon Sep 17 00:00:00 2001 From: Nils Lindemann Date: Mon, 29 Jan 2024 19:10:09 +0100 Subject: [PATCH 278/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20German=20translati?= =?UTF-8?q?on=20for=20`docs/de/docs/tutorial/body-nested-models.md`=20(#10?= =?UTF-8?q?313)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/de/docs/tutorial/body-nested-models.md | 382 ++++++++++++++++++++ 1 file changed, 382 insertions(+) create mode 100644 docs/de/docs/tutorial/body-nested-models.md diff --git a/docs/de/docs/tutorial/body-nested-models.md b/docs/de/docs/tutorial/body-nested-models.md new file mode 100644 index 0000000000..976f3f924e --- /dev/null +++ b/docs/de/docs/tutorial/body-nested-models.md @@ -0,0 +1,382 @@ +# Body – Verschachtelte Modelle + +Mit **FastAPI** kÃļnnen Sie (dank Pydantic) beliebig tief verschachtelte Modelle definieren, validieren und dokumentieren. + +## Listen als Felder + +Sie kÃļnnen ein Attribut als Kindtyp definieren, zum Beispiel eine Python-`list`e. + +=== "Python 3.10+" + + ```Python hl_lines="12" + {!> ../../../docs_src/body_nested_models/tutorial001_py310.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="14" + {!> ../../../docs_src/body_nested_models/tutorial001.py!} + ``` + +Das bewirkt, dass `tags` eine Liste ist, wenngleich es nichts Ãŧber den Typ der Elemente der Liste aussagt. + +## Listen mit Typ-Parametern als Felder + +Aber Python erlaubt es, Listen mit inneren Typen, auch „Typ-Parameter“ genannt, zu deklarieren. + +### `List` von `typing` importieren + +In Python 3.9 oder darÃŧber kÃļnnen Sie einfach `list` verwenden, um diese Typannotationen zu deklarieren, wie wir unten sehen werden. 💡 + +In Python-Versionen vor 3.9 (3.6 und darÃŧber), mÃŧssen Sie zuerst `List` von Pythons Standardmodul `typing` importieren. + +```Python hl_lines="1" +{!> ../../../docs_src/body_nested_models/tutorial002.py!} +``` + +### Eine `list`e mit einem Typ-Parameter deklarieren + +Um Typen wie `list`, `dict`, `tuple` mit inneren Typ-Parametern (inneren Typen) zu deklarieren: + +* Wenn Sie eine Python-Version kleiner als 3.9 verwenden, importieren Sie das Äquivalent zum entsprechenden Typ vom `typing`-Modul +* Überreichen Sie den/die inneren Typ(en) von eckigen Klammern umschlossen, `[` und `]`, als „Typ-Parameter“ + +In Python 3.9 wäre das: + +```Python +my_list: list[str] +``` + +Und in Python-Versionen vor 3.9: + +```Python +from typing import List + +my_list: List[str] +``` + +Das ist alles Standard-Python-Syntax fÃŧr Typdeklarationen. + +Verwenden Sie dieselbe Standardsyntax fÃŧr Modellattribute mit inneren Typen. + +In unserem Beispiel kÃļnnen wir also bewirken, dass `tags` spezifisch eine „Liste von Strings“ ist: + +=== "Python 3.10+" + + ```Python hl_lines="12" + {!> ../../../docs_src/body_nested_models/tutorial002_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="14" + {!> ../../../docs_src/body_nested_models/tutorial002_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="14" + {!> ../../../docs_src/body_nested_models/tutorial002.py!} + ``` + +## Set-Typen + +Aber dann denken wir darÃŧber nach und stellen fest, dass sich die Tags nicht wiederholen sollen, es sollen eindeutige Strings sein. + +Python hat einen Datentyp speziell fÃŧr Mengen eindeutiger Dinge: das `set`. + +Deklarieren wir also `tags` als Set von Strings. + +=== "Python 3.10+" + + ```Python hl_lines="12" + {!> ../../../docs_src/body_nested_models/tutorial003_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="14" + {!> ../../../docs_src/body_nested_models/tutorial003_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="1 14" + {!> ../../../docs_src/body_nested_models/tutorial003.py!} + ``` + +Jetzt, selbst wenn Sie einen Request mit duplizierten Daten erhalten, werden diese zu einem Set eindeutiger Dinge konvertiert. + +Und wann immer Sie diese Daten ausgeben, selbst wenn die Quelle Duplikate hatte, wird es als Set von eindeutigen Dingen ausgegeben. + +Und es wird entsprechend annotiert/dokumentiert. + +## Verschachtelte Modelle + +Jedes Attribut eines Pydantic-Modells hat einen Typ. + +Aber dieser Typ kann selbst ein anderes Pydantic-Modell sein. + +Sie kÃļnnen also tief verschachtelte JSON-„Objekte“ deklarieren, mit spezifischen Attributnamen, -typen, und -validierungen. + +Alles das beliebig tief verschachtelt. + +### Ein Kindmodell definieren + +Wir kÃļnnen zum Beispiel ein `Image`-Modell definieren. + +=== "Python 3.10+" + + ```Python hl_lines="7-9" + {!> ../../../docs_src/body_nested_models/tutorial004_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="9-11" + {!> ../../../docs_src/body_nested_models/tutorial004_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9-11" + {!> ../../../docs_src/body_nested_models/tutorial004.py!} + ``` + +### Das Kindmodell als Typ verwenden + +Und dann kÃļnnen wir es als Typ eines Attributes verwenden. + +=== "Python 3.10+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body_nested_models/tutorial004_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="20" + {!> ../../../docs_src/body_nested_models/tutorial004_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="20" + {!> ../../../docs_src/body_nested_models/tutorial004.py!} + ``` + +Das wÃŧrde bedeuten, dass **FastAPI** einen Body erwartet wie: + +```JSON +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": ["rock", "metal", "bar"], + "image": { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + } +} +``` + +Wiederum, nur mit dieser Deklaration erhalten Sie von **FastAPI**: + +* Editor-UnterstÃŧtzung (Codevervollständigung, usw.), selbst fÃŧr verschachtelte Modelle +* Datenkonvertierung +* Datenvalidierung +* Automatische Dokumentation + +## Spezielle Typen und Validierungen + +Abgesehen von normalen einfachen Typen, wie `str`, `int`, `float`, usw. kÃļnnen Sie komplexere einfache Typen verwenden, die von `str` erben. + +Um alle Optionen kennenzulernen, die Sie haben, schauen Sie sich Pydantics TypÃŧbersicht an. Sie werden im nächsten Kapitel ein paar Beispiele kennenlernen. + +Da wir zum Beispiel im `Image`-Modell ein Feld `url` haben, kÃļnnen wir deklarieren, dass das eine Instanz von Pydantics `HttpUrl` sein soll, anstelle eines `str`: + +=== "Python 3.10+" + + ```Python hl_lines="2 8" + {!> ../../../docs_src/body_nested_models/tutorial005_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="4 10" + {!> ../../../docs_src/body_nested_models/tutorial005_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="4 10" + {!> ../../../docs_src/body_nested_models/tutorial005.py!} + ``` + +Es wird getestet, ob der String eine gÃŧltige URL ist, und als solche wird er in JSON Schema / OpenAPI dokumentiert. + +## Attribute mit Listen von Kindmodellen + +Sie kÃļnnen Pydantic-Modelle auch als Typen innerhalb von `list`, `set`, usw. verwenden: + +=== "Python 3.10+" + + ```Python hl_lines="18" + {!> ../../../docs_src/body_nested_models/tutorial006_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="20" + {!> ../../../docs_src/body_nested_models/tutorial006_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="20" + {!> ../../../docs_src/body_nested_models/tutorial006.py!} + ``` + +Das wird einen JSON-Body erwarten (konvertieren, validieren, dokumentieren), wie: + +```JSON hl_lines="11" +{ + "name": "Foo", + "description": "The pretender", + "price": 42.0, + "tax": 3.2, + "tags": [ + "rock", + "metal", + "bar" + ], + "images": [ + { + "url": "http://example.com/baz.jpg", + "name": "The Foo live" + }, + { + "url": "http://example.com/dave.jpg", + "name": "The Baz" + } + ] +} +``` + +!!! info + Beachten Sie, dass der `images`-SchlÃŧssel jetzt eine Liste von Bild-Objekten hat. + +## Tief verschachtelte Modelle + +Sie kÃļnnen beliebig tief verschachtelte Modelle definieren: + +=== "Python 3.10+" + + ```Python hl_lines="7 12 18 21 25" + {!> ../../../docs_src/body_nested_models/tutorial007_py310.py!} + ``` + +=== "Python 3.9+" + + ```Python hl_lines="9 14 20 23 27" + {!> ../../../docs_src/body_nested_models/tutorial007_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9 14 20 23 27" + {!> ../../../docs_src/body_nested_models/tutorial007.py!} + ``` + +!!! info + Beachten Sie, wie `Offer` eine Liste von `Item`s hat, von denen jedes seinerseits eine optionale Liste von `Image`s hat. + +## Bodys aus reinen Listen + +Wenn Sie mÃļchten, dass das äußerste Element des JSON-Bodys ein JSON-`array` (eine Python-`list`e) ist, kÃļnnen Sie den Typ im Funktionsparameter deklarieren, mit der gleichen Syntax wie in Pydantic-Modellen: + +```Python +images: List[Image] +``` + +oder in Python 3.9 und darÃŧber: + +```Python +images: list[Image] +``` + +so wie in: + +=== "Python 3.9+" + + ```Python hl_lines="13" + {!> ../../../docs_src/body_nested_models/tutorial008_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="15" + {!> ../../../docs_src/body_nested_models/tutorial008.py!} + ``` + +## Editor-UnterstÃŧtzung Ãŧberall + +Und Sie erhalten Editor-UnterstÃŧtzung Ãŧberall. + +Selbst fÃŧr Dinge in Listen: + + + +Sie wÃŧrden diese Editor-UnterstÃŧtzung nicht erhalten, wenn Sie direkt mit `dict`, statt mit Pydantic-Modellen arbeiten wÃŧrden. + +Aber Sie mÃŧssen sich auch nicht weiter um die Modelle kÃŧmmern, hereinkommende Dicts werden automatisch in sie konvertiert. Und was Sie zurÃŧckgeben, wird automatisch nach JSON konvertiert. + +## Bodys mit beliebigen `dict`s + +Sie kÃļnnen einen Body auch als `dict` deklarieren, mit SchlÃŧsseln eines Typs und Werten eines anderen Typs. + +So brauchen Sie vorher nicht zu wissen, wie die Feld-/Attribut-Namen lauten (wie es bei Pydantic-Modellen der Fall wäre). + +Das ist nÃŧtzlich, wenn Sie SchlÃŧssel empfangen, deren Namen Sie nicht bereits kennen. + +--- + +Ein anderer nÃŧtzlicher Anwendungsfall ist, wenn Sie SchlÃŧssel eines anderen Typs haben wollen, z. B. `int`. + +Das schauen wir uns mal an. + +Im folgenden Beispiel akzeptieren Sie irgendein `dict`, solange es `int`-SchlÃŧssel und `float`-Werte hat. + +=== "Python 3.9+" + + ```Python hl_lines="7" + {!> ../../../docs_src/body_nested_models/tutorial009_py39.py!} + ``` + +=== "Python 3.8+" + + ```Python hl_lines="9" + {!> ../../../docs_src/body_nested_models/tutorial009.py!} + ``` + +!!! tip "Tipp" + Bedenken Sie, dass JSON nur `str` als SchlÃŧssel unterstÃŧtzt. + + Aber Pydantic hat automatische Datenkonvertierung. + + Das bedeutet, dass Ihre API-Clients nur Strings senden kÃļnnen, aber solange diese Strings nur Zahlen enthalten, wird Pydantic sie konvertieren und validieren. + + Und das `dict` welches Sie als `weights` erhalten, wird `int`-SchlÃŧssel und `float`-Werte haben. + +## Zusammenfassung + +Mit **FastAPI** haben Sie die maximale Flexibilität von Pydantic-Modellen, während Ihr Code einfach, kurz und elegant bleibt. + +Aber mit all den VorzÃŧgen: + +* Editor-UnterstÃŧtzung (Codevervollständigung Ãŧberall) +* Datenkonvertierung (auch bekannt als Parsen, Serialisierung) +* Datenvalidierung +* Schema-Dokumentation +* Automatische Dokumentation From a235d93002b925b0d2d7aa650b7ab6d7bb4b24dd Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 29 Jan 2024 18:10:30 +0000 Subject: [PATCH 279/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 15798ec4b0..1e3af47141 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add German translation for `docs/de/docs/tutorial/body-nested-models.md`. PR [#10313](https://github.com/tiangolo/fastapi/pull/10313) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/middleware.md`. PR [#9695](https://github.com/tiangolo/fastapi/pull/9695) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Update Farsi translation for `docs/fa/docs/index.md`. PR [#10216](https://github.com/tiangolo/fastapi/pull/10216) by [@theonlykingpin](https://github.com/theonlykingpin). * 🌐 Add German translation for `docs/de/docs/tutorial/body-fields.md`. PR [#10310](https://github.com/tiangolo/fastapi/pull/10310) by [@nilslindemann](https://github.com/nilslindemann). From 1b824e0c2352ec67e45a139d22aba9382c2d2622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 30 Jan 2024 10:58:10 +0100 Subject: [PATCH 280/305] =?UTF-8?q?=F0=9F=94=A7=20Update=20sponsors:=20Tal?= =?UTF-8?q?kPython=20badge=20image=20(#11048)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- docs/en/data/sponsors.yml | 2 +- docs/en/docs/img/sponsors/talkpython-v2.jpg | Bin 0 -> 18712 bytes 3 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 docs/en/docs/img/sponsors/talkpython-v2.jpg diff --git a/README.md b/README.md index 764cd5a36f..968ccf7a74 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ The key features are: - + diff --git a/docs/en/data/sponsors.yml b/docs/en/data/sponsors.yml index bd5b86e444..0ce434b5e2 100644 --- a/docs/en/data/sponsors.yml +++ b/docs/en/data/sponsors.yml @@ -23,7 +23,7 @@ gold: silver: - url: https://training.talkpython.fm/fastapi-courses title: FastAPI video courses on demand from people you trust - img: https://fastapi.tiangolo.com/img/sponsors/talkpython.png + img: https://fastapi.tiangolo.com/img/sponsors/talkpython-v2.jpg - url: https://testdriven.io/courses/tdd-fastapi/ title: Learn to build high-quality web apps with best practices img: https://fastapi.tiangolo.com/img/sponsors/testdriven.svg diff --git a/docs/en/docs/img/sponsors/talkpython-v2.jpg b/docs/en/docs/img/sponsors/talkpython-v2.jpg new file mode 100644 index 0000000000000000000000000000000000000000..4a1e492a162458847861035ce010dfde35734c97 GIT binary patch literal 18712 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 Date: Tue, 30 Jan 2024 09:58:29 +0000 Subject: [PATCH 281/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 1e3af47141..3c207f98de 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -141,6 +141,7 @@ hide: ### Internal +* 🔧 Update sponsors: TalkPython badge image. PR [#11048](https://github.com/tiangolo/fastapi/pull/11048) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update sponsors, remove Deta. PR [#11041](https://github.com/tiangolo/fastapi/pull/11041) by [@tiangolo](https://github.com/tiangolo). * 💄 Fix CSS breaking RTL languages (erroneously introduced by a previous RTL PR). PR [#11039](https://github.com/tiangolo/fastapi/pull/11039) by [@tiangolo](https://github.com/tiangolo). * 🔧 Add Italian to `mkdocs.yml`. PR [#11016](https://github.com/tiangolo/fastapi/pull/11016) by [@alejsdev](https://github.com/alejsdev). From 2a21dfba0ee0334825aecfd9ef1f85dc02b92e80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 30 Jan 2024 15:24:35 +0100 Subject: [PATCH 282/305] =?UTF-8?q?=F0=9F=8D=B1=20Update=20sponsors:=20Tal?= =?UTF-8?q?kPython=20badge=20(#11052)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/img/sponsors/talkpython-v2.jpg | Bin 18712 -> 9778 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/docs/en/docs/img/sponsors/talkpython-v2.jpg b/docs/en/docs/img/sponsors/talkpython-v2.jpg index 4a1e492a162458847861035ce010dfde35734c97..adb0152489fa8dea5594a78a835e0cbfa817e840 100644 GIT binary patch literal 9778 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 literal 18712 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 Date: Tue, 30 Jan 2024 14:24:57 +0000 Subject: [PATCH 283/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 3c207f98de..6838bfa2b1 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -141,6 +141,7 @@ hide: ### Internal +* 🍱 Update sponsors: TalkPython badge. PR [#11052](https://github.com/tiangolo/fastapi/pull/11052) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update sponsors: TalkPython badge image. PR [#11048](https://github.com/tiangolo/fastapi/pull/11048) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update sponsors, remove Deta. PR [#11041](https://github.com/tiangolo/fastapi/pull/11041) by [@tiangolo](https://github.com/tiangolo). * 💄 Fix CSS breaking RTL languages (erroneously introduced by a previous RTL PR). PR [#11039](https://github.com/tiangolo/fastapi/pull/11039) by [@tiangolo](https://github.com/tiangolo). From fb7af9ec72656048df07dd40bab8721075f967a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 30 Jan 2024 19:46:56 +0100 Subject: [PATCH 284/305] =?UTF-8?q?=F0=9F=91=B7=20Upgrade=20GitHub=20Actio?= =?UTF-8?q?n=20issue-manager=20(#11056)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/issue-manager.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/issue-manager.yml b/.github/workflows/issue-manager.yml index d1aad28fd3..0f564d7218 100644 --- a/.github/workflows/issue-manager.yml +++ b/.github/workflows/issue-manager.yml @@ -23,7 +23,7 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: tiangolo/issue-manager@0.4.0 + - uses: tiangolo/issue-manager@0.5.0 with: token: ${{ secrets.FASTAPI_ISSUE_MANAGER }} config: > From ec5e08251d77ea81f7e5d5ccebb1fa55950add7a Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 30 Jan 2024 18:47:20 +0000 Subject: [PATCH 285/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 6838bfa2b1..0f0dbb1c90 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -141,6 +141,7 @@ hide: ### Internal +* 👷 Upgrade GitHub Action issue-manager. PR [#11056](https://github.com/tiangolo/fastapi/pull/11056) by [@tiangolo](https://github.com/tiangolo). * 🍱 Update sponsors: TalkPython badge. PR [#11052](https://github.com/tiangolo/fastapi/pull/11052) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update sponsors: TalkPython badge image. PR [#11048](https://github.com/tiangolo/fastapi/pull/11048) by [@tiangolo](https://github.com/tiangolo). * 🔧 Update sponsors, remove Deta. PR [#11041](https://github.com/tiangolo/fastapi/pull/11041) by [@tiangolo](https://github.com/tiangolo). From 7178eb4fb1b88cdd69d356c8d34c03905262c745 Mon Sep 17 00:00:00 2001 From: JeongHyeongKim Date: Wed, 31 Jan 2024 23:35:27 +0900 Subject: [PATCH 286/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Korean=20translati?= =?UTF-8?q?on=20for=20`docs/ko/docs/tutorial/middleware.md`=20(#2829)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/ko/docs/tutorial/middleware.md | 61 +++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 docs/ko/docs/tutorial/middleware.md diff --git a/docs/ko/docs/tutorial/middleware.md b/docs/ko/docs/tutorial/middleware.md new file mode 100644 index 0000000000..f35b446a61 --- /dev/null +++ b/docs/ko/docs/tutorial/middleware.md @@ -0,0 +1,61 @@ +# ë¯¸ë“¤ė›¨ė–´ + +ë¯¸ë“¤ė›¨ė–´ëĨŧ **FastAPI** ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė— ėļ”가할 눘 ėžˆėŠĩ니다. + +"ë¯¸ë“¤ė›¨ė–´"는 íŠšė • *ę˛Ŋ로 ėž‘ë™*뗐 ė˜í•´ 래ëĻŦ되기 ė „, ëĒ¨ë“  **ėš”ė˛­**뗐 ëŒ€í•´ė„œ ë™ėž‘í•˜ëŠ” í•¨ėˆ˜ėž…ë‹ˆë‹¤. 또한 ëĒ¨ë“  **ė‘ë‹ĩ**ė´ 반환되기 ė „ė—ë„ 동ėŧ하게 ë™ėž‘í•Šë‹ˆë‹¤. + +* ë¯¸ë“¤ė›¨ė–´ëŠ” ė‘ėšŠ 프로그램ėœŧ로 ė˜¤ëŠ” **ėš”ė˛­**ëĨŧ 氀렏ė˜ĩ니다. +* **ėš”ė˛­** 또는 다ëĨ¸ í•„ėš”í•œ ėŊ”드ëĨŧ ė‹¤í–‰ ė‹œí‚Ŧ 눘 ėžˆėŠĩ니다. +* **ėš”ė˛­**ė„ ė‘ėšŠ í”„ëĄœęˇ¸ëž¨ė˜ *ę˛Ŋ로 ėž‘ë™*ėœŧ로 ė „ë‹Ŧ하ė—Ŧ 래ëĻŦ합니다. +* ė• í”ŒëĻŦėŧ€ė´ė…˜ė˜ *ę˛Ŋ로 ėž‘ė—…*ė—ė„œ ėƒė„ąí•œ **ė‘ë‹ĩ**ëĨŧ 받ėŠĩ니다. +* **ė‘ë‹ĩ** 또는 다ëĨ¸ í•„ėš”í•œ ėŊ”드ëĨŧ ė‹¤í–‰ė‹œí‚¤ëŠ” ë™ėž‘ė„ 할 눘 ėžˆėŠĩ니다. +* **ė‘ë‹ĩ**ëĨŧ 반환합니다. + +!!! note "揰눠 넏ëļ€ė‚Ŧ항" + 만ė•Ŋ `yield`ëĨŧ ė‚ŦėšŠí•œ ė˜ėĄ´ė„ąė„ 氀맀溠 ėžˆë‹¤ëŠ´, ë¯¸ë“¤ė›¨ė–´ę°€ ė‹¤í–‰ë˜ęŗ  난 í›„ė— exitė´ ė‹¤í–‰ëŠë‹ˆë‹¤. + + 만ė•Ŋ (ë‚˜ė¤‘ė— ëŦ¸ė„œė—ė„œ ë‹¤ëŖ°) 밹꡸ëŧėš´ë“œ ėž‘ė—…ė´ ėžˆë‹¤ëŠ´, ëĒ¨ë“  ë¯¸ë“¤ė›¨ė–´ę°€ ė‹¤í–‰ë˜ęŗ  *난 í›„ė—* ė‹¤í–‰ëŠë‹ˆë‹¤. + +## ë¯¸ë“¤ė›¨ė–´ 만들기 + +ë¯¸ë“¤ė›¨ė–´ëĨŧ ėž‘ė„ąí•˜ę¸° ėœ„í•´ė„œ í•¨ėˆ˜ ėƒë‹¨ė— `@app.middleware("http")` 데ėŊ”ë ˆė´í„°ëĨŧ ė‚ŦėšŠí•  눘 ėžˆėŠĩ니다. + +ë¯¸ë“¤ė›¨ė–´ í•¨ėˆ˜ëŠ” ë‹¤ėŒ 항ëĒŠë“¤ė„ 받ėŠĩ니다: + +* `request`. +* `request`ëĨŧ ë§¤ę°œëŗ€ėˆ˜ëĄœ 받는 `call_next` í•¨ėˆ˜. + * ė´ í•¨ėˆ˜ëŠ” `request`ëĨŧ 해당하는 *ę˛Ŋ로 ėž‘ė—…*ėœŧ로 ė „ë‹Ŧ합니다. + * 그런 ë‹¤ėŒ, *ę˛Ŋ로 ėž‘ė—…*뗐 ė˜í•´ ėƒė„ąëœ `response` ëĨŧ 반환합니다. +* `response`ëĨŧ 반환하기 렄뗐 ėļ”ę°€ëĄœ `response`ëĨŧ ėˆ˜ė •í•  눘 ėžˆėŠĩ니다. + +```Python hl_lines="8-9 11 14" +{!../../../docs_src/middleware/tutorial001.py!} +``` + +!!! tip "팁" + ė‚ŦėšŠėž ė •ė˜ 헤더는 'X-' ė ‘ë‘ė‚ŦëĨŧ ė‚ŦėšŠí•˜ė—Ŧ ėļ”가할 눘 ėžˆėŠĩ니다. + + ꡸ëŸŦ나 만ė•Ŋ 클ëŧė´ė–¸íŠ¸ė˜ 브ëŧėš°ė €ė—ė„œ ëŗŧ 눘 ėžˆëŠ” ė‚ŦėšŠėž ė •ė˜ 헤더ëĨŧ 氀맀溠 ėžˆë‹¤ëŠ´, ęˇ¸ę˛ƒë“¤ė„ CORS 네렕([CORS (Cross-Origin Resource Sharing)](cors.md){.internal-link target=_blank})뗐 Starlette CORS ëŦ¸ė„œė— ëĒ…ė‹œëœ `expose_headers` ë§¤ę°œëŗ€ėˆ˜ëĨŧ ė´ėšŠí•˜ė—Ŧ í—¤ë”ë“¤ė„ ėļ”ę°€í•˜ė—Ŧė•ŧ합니다. + +!!! note "揰눠렁 넏ëļ€ė‚Ŧ항" + `from starlette.requests import request`ëĨŧ ė‚ŦėšŠí•  ėˆ˜ë„ ėžˆėŠĩ니다. + + **FastAPI**는 ę°œë°œėžė—ę˛Œ íŽ¸ė˜ëĨŧ ėœ„í•´ ė´ëĨŧ 렜ęŗĩ합니다. ꡸ëŸŦ나 Starletteė—ė„œ 링렑 íŒŒėƒë˜ė—ˆėŠĩ니다. + +### `response`ė˜ ė „ęŗŧ 후 + +*ę˛Ŋ로 ėž‘ë™*ė„ 받기 ė „ `request`뙀 함ęģ˜ ėž‘ë™í•  눘 ėžˆëŠ” ėŊ”드ëĨŧ ėļ”가할 눘 ėžˆėŠĩ니다. + +꡸ëĻŦęŗ  `response` 또한 ėƒė„ąëœ 후 반환되기 렄뗐 ėŊ”드ëĨŧ ėļ”ę°€ 할 눘 ėžˆėŠĩ니다. + +똈ëĨŧ ë“¤ė–´, ėš”ė˛­ė„ ėˆ˜í–‰í•˜ęŗ  ė‘ë‹ĩė„ ėƒė„ąí•˜ëŠ”ë° ęšŒė§€ 깸ëϰ ė‹œę°„ ę°’ė„ 氀맀溠 ėžˆëŠ” `X-Process-Time` ę°™ė€ ė‚ŦėšŠėž ė •ė˜ 헤더ëĨŧ ėļ”가할 눘 ėžˆėŠĩ니다. + +```Python hl_lines="10 12-13" +{!../../../docs_src/middleware/tutorial001.py!} +``` + +## 다ëĨ¸ ë¯¸ë“¤ė›¨ė–´ + +ë¯¸ë“¤ė›¨ė–´ė— 대한 더 ë§Žė€ ė •ëŗ´ëŠ” [ėˆ™ë ¨ëœ ė‚ŦėšŠėž ė•ˆë‚´ė„œ: í–Ĩėƒëœ ë¯¸ë“¤ė›¨ė–´](../advanced/middleware.md){.internal-link target=\_blank}ė—ė„œ í™•ė¸í•  눘 ėžˆėŠĩ니다. + +ë‹¤ėŒ ëļ€ëļ„ė—ė„œ ë¯¸ë“¤ė›¨ė–´ė™€ 함ęģ˜ CORSëĨŧ ė–´ë–ģ枌 ë‹¤ëŖ¨ëŠ”ė§€ė— 대해 í™•ė¸í•  ę˛ƒėž…ë‹ˆë‹¤. From 531b0d5e035be7de800b541828023084a79cf4ad Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 31 Jan 2024 14:35:50 +0000 Subject: [PATCH 287/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 0f0dbb1c90..d7dba1721b 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Korean translation for `docs/ko/docs/tutorial/middleware.md`. PR [#2829](https://github.com/tiangolo/fastapi/pull/2829) by [@JeongHyeongKim](https://github.com/JeongHyeongKim). * 🌐 Add German translation for `docs/de/docs/tutorial/body-nested-models.md`. PR [#10313](https://github.com/tiangolo/fastapi/pull/10313) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/middleware.md`. PR [#9695](https://github.com/tiangolo/fastapi/pull/9695) by [@mojtabapaso](https://github.com/mojtabapaso). * 🌐 Update Farsi translation for `docs/fa/docs/index.md`. PR [#10216](https://github.com/tiangolo/fastapi/pull/10216) by [@theonlykingpin](https://github.com/theonlykingpin). From 67494c2b5eaf27f372812e21850c204e2bc79cc6 Mon Sep 17 00:00:00 2001 From: Aykhan Shahsuvarov <88669260+aykhans@users.noreply.github.com> Date: Wed, 31 Jan 2024 19:45:57 +0400 Subject: [PATCH 288/305] =?UTF-8?q?=F0=9F=8C=90=20Add=20Azerbaijani=20tran?= =?UTF-8?q?slation=20for=20`docs/az/docs/index.md`=20(#11047)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/az/docs/index.md | 469 ++++++++++++++++++++++++++++++++++++++++++ docs/az/mkdocs.yml | 1 + docs/en/mkdocs.yml | 2 + 3 files changed, 472 insertions(+) create mode 100644 docs/az/docs/index.md create mode 100644 docs/az/mkdocs.yml diff --git a/docs/az/docs/index.md b/docs/az/docs/index.md new file mode 100644 index 0000000000..a227065125 --- /dev/null +++ b/docs/az/docs/index.md @@ -0,0 +1,469 @@ +

+ FastAPI +

+

+ FastAPI framework, yÃŧksək məshuldarlÄą, Ãļyrənməsi asan, çevik kodlama, istifadəyə hazÄąrdÄąr +

+

+ + Test + + + Əhatə + + + Paket versiyasÄą + + + Dəstəklənən Python versiyalarÄą + +

+ +--- + +**Sənədlər**: https://fastapi.tiangolo.com + +**Qaynaq Kodu**: https://github.com/tiangolo/fastapi + +--- + +FastAPI Python 3.8+ ilə API yaratmaq ÃŧçÃŧn standart Python tip məsləhətlərinə əsaslanan, mÃŧasir, sÃŧrətli (yÃŧksək performanslÄą) framework-dÃŧr. + +Əsas xÃŧsusiyyətləri bunlardÄąr: + +* **SÃŧrətli**: Çox yÃŧksək performans, **NodeJS** və **Go** səviyyəsində (Starlette və Pydantic-ə təşəkkÃŧrlər). [Ən sÃŧrətli Python frameworklərindən biridir](#performans). +* **Çevik kodlama**: FunksiyanallÄąqlarÄą inkişaf etdirmək sÃŧrətini təxminən 200%-dən 300%-ə qədər artÄąrÄąn. * +* **Daha az xəta**: İnsan (developer) tərəfindən tÃļrədilən səhvlərin təxminən 40% -ni azaldÄąn. * +* **İntuitiv**: Əla redaktor dəstəyi. Hər yerdə otomatik tamamlama. XətalarÄą mÃŧəyyənləşdirməyə daha az vaxt sərf edəcəksiniz. +* **Asan**: İstifadəsi və Ãļyrənilməsi asan olmasÄą ÃŧçÃŧn nəzərdə tutulmuşdur. Sənədləri oxumaq ÃŧçÃŧn daha az vaxt ayÄąracaqsÄąnÄąz. +* **QÄąsa**: Kod təkrarlanmasÄąnÄą minimuma endirin. Hər bir parametr tərifində birdən çox xÃŧsusiyyət ilə və daha az səhvlə qarÅŸÄąlaşacaqsÄąnÄąz. +* **GÃŧclÃŧ**: Avtomatik və interaktiv sənədlərlə birlikdə istifadəyə hazÄąr kod əldə edə bilərsiniz. +* **Standartlara əsaslanan**: API-lar ÃŧçÃŧn aÃ§Äąq standartlara əsaslanÄąr (və tam uyğun gəlir): OpenAPI (əvvəlki adÄą ilə Swagger) və JSON Schema. + +* Bu fikirlər daxili development komandasÄąnÄąn hazÄąrladÄąqlarÄą məhsullarÄąn sÄąnaqlarÄąna əsaslanÄąr. + +## Sponsorlar + + + +{% if sponsors %} +{% for sponsor in sponsors.gold -%} + +{% endfor -%}` +{%- for sponsor in sponsors.silver -%} + +{% endfor %} +{% endif %} + + + +Digər sponsorlar + +## Rəylər + +"_[...] Son gÃŧnlərdə **FastAPI**-Äą çox istifadə edirəm. [...] Əslində onu komandamÄąn bÃŧtÃŧn **Microsoftda ML sevislərində** istifadə etməyi planlayÄąram. OnlarÄąn bəziləri **windows**-un əsas məhsuluna və bəzi **Office** məhsullarÄąna inteqrasiya olunurlar._" + +
Kabir Khan - Microsoft (ref)
+ +--- + +"_**FastAPI** kitabxanasÄąnÄą **Proqnozlar** əldə etmək ÃŧçÃŧn sorğulana bilən **REST** serverini yaratmaqda istifadə etdik._" + +
Piero Molino, Yaroslav Dudin, and Sai Sumanth Miryala - Uber (ref)
+ +--- + +"_**Netflix** **bÃļhran idarəçiliyi** orkestrləşmə framework-nÃŧn aÃ§Äąq qaynaqlÄą buraxÄąlÄąÅŸÄąnÄą elan etməkdən məmnundur: **Dispatch**! [**FastAPI** ilə quruldu]_" + +
Kevin Glisson, Marc Vilanova, Forest Monsen - Netflix (ref)
+ +--- + +"_**FastAPI** ÃŧçÃŧn həyəcanlÄąyam. Çox əyləncəlidir!_" + +
Brian Okken - Python Bytes podcast host (ref)
+ +--- + +"_DÃŧzÃŧnÃŧ desəm, sizin qurduğunuz şey həqiqətən mÃļhkəm və peşəkar gÃļrÃŧnÃŧr. Bir çox cəhətdən **Hug**-un olmasÄąnÄą istədiyim kimdir - kiminsə belə bir şey qurduğunu gÃļrmək həqiqətən ruhlandÄąrÄącÄądÄąr._" + +
Timothy Crosley - Hug creator (ref)
+ +--- + +"_Əgər REST API-lər yaratmaq ÃŧçÃŧn **mÃŧasir framework** Ãļyrənmək istəyirsinizsə, **FastAPI**-a baxÄąn [...] SÃŧrətli, istifadəsi və Ãļyrənməsi asandÄąr. [...]_" + +"_**API** xidmətlərimizi **FastAPI**-a kÃļçÃŧrdÃŧk [...] Sizin də bəyənəcəyinizi dÃŧşÃŧnÃŧrÃŧk._" + +
Ines Montani - Matthew Honnibal - Explosion AI founders - spaCy creators (ref) - (ref)
+ +--- + +"_Python ilə istifadəyə hazÄąr API qurmaq istəyən hər kəsə **FastAPI**-Äą tÃļvsiyə edirəm. **MÃļhtəşəm şəkildə dizayn edilmiş**, **istifadəsi asan** və **yÃŧksək dərəcədə genişlənə bilən**-dir, API əsaslÄą inkişaf strategiyamÄązÄąn **əsas komponentinə** çevrilib və Virtual TAC Engineer kimi bir çox avtomatlaşdÄąrma və servisləri idarə edir._" + +
Deon Pillsbury - Cisco (ref)
+ +--- + +## **Typer**, CLI-larÄąn FastAPI-Äą + + + +Əgər siz veb API əvəzinə terminalda istifadə ediləcək CLI proqramÄą qurursunuzsa, **Typer**-a baxa bilərsiniz. + +**Typer** FastAPI-Äąn kiçik qardaÅŸÄądÄąr. Və o, CLI-lərin **FastAPI**-Äą olmaq ÃŧçÃŧn nəzərdə tutulub. âŒ¨ī¸ 🚀 + +## Tələblər + +Python 3.8+ + +FastAPI nəhənglərin çiyinlərində dayanÄąr: + +* Web tərəfi ÃŧçÃŧn Starlette. +* Data tərəfi ÃŧçÃŧn Pydantic. + +## QuraşdÄąrma + +
+ +```console +$ pip install fastapi + +---> 100% +``` + +
+ +Tətbiqimizi əlçatan etmək ÃŧçÃŧn bizə Uvicorn və ya Hypercorn kimi ASGI server lazÄąmdÄąr. + +
+ +```console +$ pip install "uvicorn[standard]" + +---> 100% +``` + +
+ +## NÃŧmunə + +### Kodu yaradaq + +* `main.py` adlÄą fayl yaradaq və ona aşağıdakÄą kodu yerləşdirək: + +```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} +``` + +
+Və ya async def... + +Əgər kodunuzda `async` və ya `await` vardÄąrsa `async def` istifadə edə bilərik: + +```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} +``` + +**Qeyd**: + +Əgər bu mÃļvzu haqqÄąnda məlumatÄąnÄąz yoxdursa `async` və `await` sənədindəki _"Tələsirsən?"_ bÃļlməsinə baxa bilərsiniz. + +
+ +### Kodu işə salaq + +Serveri aşağıdakÄą əmr ilə işə salaq: + +
+ +```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 əmri haqqÄąnda... + +`uvicorn main:app` əmri aşağıdakÄąlara instinad edir: + +* `main`: `main.py` faylÄą (yəni Python "modulu"). +* `app`: `main.py` faylÄąnda `app = FastAPI()` sətrində yaratdığımÄąz `FastAPI` obyektidir. +* `--reload`: kod dəyişikliyindən sonra avtomatik olaraq serveri yenidən işə salÄąr. Bu parametrdən yalnÄąz development mərhələsində istifadə etməliyik. + +
+ +### İndi yoxlayaq + +Bu linki brauzerimizdə açaq http://127.0.0.1:8000/items/5?q=somequery. + +AşağıdakÄą kimi bir JSON cavabÄą gÃļrəcəksiniz: + +```JSON +{"item_id": 5, "q": "somequery"} +``` + +Siz artÄąq bir API yaratmÄąsÄąnÄąz, hansÄą ki: + +* `/` və `/items/{item_id}` _yollarÄąnda_ HTTP sorğularÄąnÄą qəbul edir. +* Hər iki _yolda_ `GET` əməliyyatlarÄąnÄą (həmçinin HTTP _metodlarÄą_ kimi bilinir) aparÄąr. +* `/items/{item_id}` _yolu_ `item_id` adlÄą `int` qiyməti almalÄą olan _yol parametrinə_ sahibdir. +* `/items/{item_id}` _yolunun_ `q` adlÄą yol parametri var və bu parametr istəyə bağlÄą olsa da, `str` qiymətini almalÄądÄąr. + +### İnteraktiv API Sənədləri + +İndi http://127.0.0.1:8000/docs ÃŧnvanÄąna daxil olun. + +Avtomatik interaktiv API sənədlərini gÃļrəcəksiniz (Swagger UI tərəfindən təmin edilir): + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-01-swagger-ui-simple.png) + +### Alternativ API sənədləri + +İndi isə http://127.0.0.1:8000/redoc ÃŧnvanÄąna daxil olun. + +ReDoc tərəfindən təqdim edilən avtomatik sənədləri gÃļrəcəksiniz: + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-02-redoc-simple.png) + +## NÃŧmunəni Yeniləyək + +İndi gəlin `main.py` faylÄąnÄą `PUT` sorğusu ilə birlikdə gÃļvdə qəbul edəcək şəkildə dəyişdirək. + +Pydantic sayəsində standart Python tiplərindən istifadə edərək gÃļvdəni mÃŧəyyən edək. + +```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} +``` +Server avtomatik olaraq yenidən işə salÄąnmalÄą idi (çÃŧnki biz yuxarÄąda `uvicorn` əmri ilə `--reload` parametrindən istifadə etmişik). + +### İnteraktiv API sənədlərindəki dəyişikliyə baxaq + +Yenidən http://127.0.0.1:8000/docs ÃŧnvanÄąna daxil olun. + +* İnteraktiv API sənədləri yeni gÃļvdə də daxil olmaq ilə avtomatik olaraq yenilənəcək: + +![Swagger UI](https://fastapi.tiangolo.com/img/index/index-03-swagger-02.png) + +* "Try it out" dÃŧyməsini klikləyin, bu, parametrləri doldurmağa və API ilə birbaşa əlaqə saxlamağa imkan verir: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-04-swagger-03.png) + +* Sonra "Execute" dÃŧyməsini klikləyin, istifadəçi interfeysi API ilə əlaqə quracaq, parametrləri gÃļndərəcək, nəticələri əldə edəcək və onlarÄą ekranda gÃļstərəcək: + +![Swagger UI interaction](https://fastapi.tiangolo.com/img/index/index-05-swagger-04.png) + +### Alternativ API Sənədlərindəki Dəyişikliyə Baxaq + +İndi isə yenidən http://127.0.0.1:8000/redoc ÃŧnvanÄąna daxil olun. + +* Alternativ sənədlər həm də yeni sorğu parametri və gÃļvdəsini əks etdirəcək: + +![ReDoc](https://fastapi.tiangolo.com/img/index/index-06-redoc-02.png) + +### XÃŧlasə + +Ümumiləşdirsək, parametrlər, gÃļvdə və s. Biz məlumat nÃļvlərini **bir dəfə** funksiya parametrləri kimi təyin edirik. + +Bunu standart mÃŧasir Python tipləri ilə edirsiniz. + +Yeni sintaksis, mÃŧəyyən bir kitabxananÄąn metodlarÄąnÄą və ya siniflərini və s. Ãļyrənmək məcburiyyətində deyilsiniz. + +Sadəcə standart **Python 3.8+**. + +Məsələn, `int` ÃŧçÃŧn: + +```Python +item_id: int +``` + +və ya daha mÃŧrəkkəb `Item` modeli ÃŧçÃŧn: + +```Python +item: Item +``` + +...və yalnÄąz parametr tipini təyin etməklə bunlarÄą əldə edirsiniz: + +* Redaktor dəstəyi ilə: + * Avtomatik tamamlama. + * Tip yoxlanmasÄą. +* MəlumatlarÄąn Təsdiqlənməsi: + * Məlumat etibarsÄąz olduqda avtomatik olaraq aydÄąn xətalar gÃļstərir. + * Hətta çox dərin JSON obyektlərində belə doğrulama aparÄąr. +* Daxil olan məlumatlarÄą çevirmək ÃŧçÃŧn aşağıdakÄą məlumat nÃļvlərindən istifadə edilir: + * JSON. + * Yol parametrləri. + * Sorğu parametrləri. + * Çərəzlər. + * BaşlÄąqlaq. + * Formalar. + * Fayllar. +* Daxil olan məlumatlarÄą çevirmək ÃŧçÃŧn aşağıdakÄą məlumat nÃļvlərindən istifadə edilir (JSON olaraq): + * Python tiplərinin (`str`, `int`, `float`, `bool`, `list`, və s) çevrilməsi. + * `datetime` obyektləri. + * `UUID` obyektləri. + * Verilənlər bazasÄą modelləri. + * və daha çoxu... +* 2 alternativ istifadəçi interfeysi daxil olmaqla avtomatik interaktiv API sənədlərini təmin edir: + * Swagger UI. + * ReDoc. + +--- + +Gəlin əvvəlki nÃŧmunəyə qayÄądaq və **FastAPI**-nin nələr edəcəyinə nəzər salaq: + +* `GET` və `PUT` sorğularÄą ÃŧçÃŧn `item_id`-nin yolda olub-olmadığınÄą yoxlayacaq. +* `item_id`-nin `GET` və `PUT` sorğularÄą ÃŧçÃŧn nÃļvÃŧnÃŧn `int` olduğunu yoxlayacaq. + * Əgər `int` deyilsə, səbəbini gÃļstərən bir xəta mesajÄą gÃļstərəcəkdir. +* məcburi olmayan `q` parametrinin `GET` (`http://127.0.0.1:8000/items/foo?q=somequery` burdakÄą kimi) sorğusu içərisində olub olmadığınÄą yoxlayacaq. + * `q` parametrini `= None` ilə yaratdığımÄąz ÃŧçÃŧn, məcburi olmayan parametr olacaq. + * Əgər `None` olmasaydÄą, bu məcburi parametr olardÄą (`PUT` metodunun gÃļvdəsində olduğu kimi). +* `PUT` sorğusu ÃŧçÃŧn, `/items/{item_id}` gÃļvdəsini JSON olaraq oxuyacaq: + * `name` adÄąnda məcburi bir parametr olub olmadığınÄą və əgər varsa, tipinin `str` olub olmadığınÄą yoxlayacaq. + * `price` adÄąnda məcburi bir parametr olub olmadığınÄą və əgər varsa, tipinin `float` olub olmadığınÄą yoxlayacaq. + * `is_offer` adÄąnda məcburi olmayan bir parametr olub olmadığınÄą və əgər varsa, tipinin `float` olub olmadığınÄą yoxlayacaq. + * BÃŧtÃŧn bunlar ən dərin JSON obyektlərində belə işləyəcək. +* MəlumatlarÄąn JSON-a və JSON-un Python obyektinə çevrilməsi avtomatik həyata keçiriləcək. +* Hər şeyi OpenAPI ilə uyğun olacaq şəkildə avtomatik olaraq sənədləşdirəcək və onlarÄą aşağıdakÄą kimi istifadə edə biləcək: + * İnteraktiv sənədləşmə sistemləri. + * Bir çox proqramlaşdÄąrma dilləri ÃŧçÃŧn avtomatlaşdÄąrÄąlmÄąÅŸ mÃŧştəri kodu yaratma sistemləri. +* 2 interaktiv sənədləşmə veb interfeysini birbaşa təmin edəcək. + +--- + +Yeni başlamÄąÅŸÄąq, amma siz artÄąq işin məntiqini başa dÃŧşmÃŧsÃŧnÃŧz. + +İndi aşağıdakÄą sətri dəyişdirməyə çalÄąÅŸÄąn: + +```Python + return {"item_name": item.name, "item_id": item_id} +``` + +...bundan: + +```Python + ... "item_name": item.name ... +``` + +...buna: + +```Python + ... "item_price": item.price ... +``` + +...və redaktorun məlumat tiplərini bildiyini və avtomatik tamaladığınÄą gÃļrəcəksiniz: + +![editor support](https://fastapi.tiangolo.com/img/vscode-completion.png) + +Daha çox funksiyaya malik daha dolğun nÃŧmunə ÃŧçÃŧn Öyrədici - İstifadəçi TəlimatÄą səhifəsinə baxa bilərsiniz. + +**Spoiler xəbərdarlığı**: Öyrədici - istifadəçi təlimatÄąna bunlar daxildir: + +* **Parametrlərin**, **başlÄąqlar**, çərəzlər, **forma sahələri** və **fayllar** olaraq mÃŧəyyən edilməsi. +* `maximum_length` və ya `regex` kimi **doğrulama məhdudiyyətlərinin** necə təyin ediləcəyi. +* Çox gÃŧclÃŧ və istifadəsi asan **Dependency Injection** sistemi. +* TəhlÃŧkəsizlik və autentifikasiya, **JWT tokenləri** ilə **OAuth2** dəstəyi və **HTTP Basic** autentifikasiyasÄą. +* **çox dərin JSON modellərini** mÃŧəyyən etmək ÃŧçÃŧn daha irəli səviyyə (lakin eyni dərəcədə asan) Ãŧsullar (Pydantic sayəsində). +* Strawberry və digər kitabxanalar ilə **GraphQL** inteqrasiyasÄą. +* Digər əlavə xÃŧsusiyyətlər (Starlette sayəsində): + * **WebSockets** + * HTTPX və `pytest` sayəsində çox asan testlər + * **CORS** + * **Cookie Sessions** + * ...və daha çoxu. + +## Performans + +MÃŧstəqil TechEmpower meyarlarÄą gÃļstərir ki, Uvicorn Ãŧzərində işləyən **FastAPI** proqramlarÄą ən sÃŧrətli Python kitabxanalarÄąndan biridir, yalnÄąz Starlette və Uvicorn-un ÃļzÃŧndən yavaşdÄąr, ki FastAPI bunlarÄąn Ãŧzərinə qurulmuş bir framework-dÃŧr. (*) + +ƏtraflÄą məlumat ÃŧçÃŧn bu bÃļlməyə nəzər salÄąn MÃŧqayisələr. + +## Məcburi Olmayan Tələblər + +Pydantic tərəfindən istifadə olunanlar: + +* email_validator - e-poçtun yoxlanÄąlmasÄą ÃŧçÃŧn. +* pydantic-settings - parametrlərin idarə edilməsi ÃŧçÃŧn. +* pydantic-extra-types - Pydantic ilə istifadə edilə bilən əlavə tiplər ÃŧçÃŧn. + +Starlette tərəfindən istifadə olunanlar: + +* httpx - Əgər `TestClient` strukturundan istifadə edəcəksinizsə, tələb olunur. +* jinja2 - Standart şablon konfiqurasiyasÄąndan istifadə etmək istəyirsinizsə, tələb olunur. +* python-multipart - `request.form()` ilə forma "çevirmə" dəstəyindən istifadə etmək istəyirsinizsə, tələb olunur. +* itsdangerous - `SessionMiddleware` dəstəyi ÃŧçÃŧn tələb olunur. +* pyyaml - `SchemaGenerator` dəstəyi ÃŧçÃŧn tələb olunur (Çox gÃŧman ki, FastAPI istifadə edərkən buna ehtiyacÄąnÄąz olmayacaq). +* ujson - `UJSONResponse` istifadə etmək istəyirsinizsə, tələb olunur. + +Həm FastAPI, həm də Starlette tərəfindən istifadə olunur: + +* uvicorn - YaratdığımÄąz proqramÄą servis edəcək veb server kimi fəaliyyət gÃļstərir. +* orjson - `ORJSONResponse` istifadə edəcəksinizsə tələb olunur. + +BÃŧtÃŧn bunlarÄą `pip install fastapi[all]` ilə quraşdÄąra bilərsiniz. + +## Lisenziya + +Bu layihə MIT lisenziyasÄąnÄąn şərtlərinə əsasən lisenziyalaşdÄąrÄąlÄąb. diff --git a/docs/az/mkdocs.yml b/docs/az/mkdocs.yml new file mode 100644 index 0000000000..de18856f44 --- /dev/null +++ b/docs/az/mkdocs.yml @@ -0,0 +1 @@ +INHERIT: ../en/mkdocs.yml diff --git a/docs/en/mkdocs.yml b/docs/en/mkdocs.yml index 2b843e026d..9e22e3a22d 100644 --- a/docs/en/mkdocs.yml +++ b/docs/en/mkdocs.yml @@ -267,6 +267,8 @@ extra: alternate: - link: / name: en - English + - link: /az/ + name: az - azərbaycan dili - link: /bn/ name: bn - āĻŦāĻžāĻ‚āϞāĻž - link: /de/ From c8c9ae475c33b6989c02ab72c20630b2fcb9b5ec Mon Sep 17 00:00:00 2001 From: github-actions Date: Wed, 31 Jan 2024 15:46:19 +0000 Subject: [PATCH 289/305] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index d7dba1721b..3a4c6f1702 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -49,6 +49,7 @@ hide: ### Translations +* 🌐 Add Azerbaijani translation for `docs/az/docs/index.md`. PR [#11047](https://github.com/tiangolo/fastapi/pull/11047) by [@aykhans](https://github.com/aykhans). * 🌐 Add Korean translation for `docs/ko/docs/tutorial/middleware.md`. PR [#2829](https://github.com/tiangolo/fastapi/pull/2829) by [@JeongHyeongKim](https://github.com/JeongHyeongKim). * 🌐 Add German translation for `docs/de/docs/tutorial/body-nested-models.md`. PR [#10313](https://github.com/tiangolo/fastapi/pull/10313) by [@nilslindemann](https://github.com/nilslindemann). * 🌐 Add Persian translation for `docs/fa/docs/tutorial/middleware.md`. PR [#9695](https://github.com/tiangolo/fastapi/pull/9695) by [@mojtabapaso](https://github.com/mojtabapaso). From f43e18562b0dfd7b29305a1ee4751e5de1a0841e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Wed, 31 Jan 2024 23:13:52 +0100 Subject: [PATCH 290/305] =?UTF-8?q?=F0=9F=94=A7=20Update=20sponsors:=20add?= =?UTF-8?q?=20Coherence=20(#11066)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + docs/en/data/sponsors.yml | 3 +++ docs/en/data/sponsors_badge.yml | 5 +++++ docs/en/docs/deployment/cloud.md | 1 + docs/en/docs/img/sponsors/coherence-banner.png | Bin 0 -> 18388 bytes docs/en/docs/img/sponsors/coherence.png | Bin 0 -> 27886 bytes docs/en/overrides/main.html | 6 ++++++ 7 files changed, 16 insertions(+) create mode 100644 docs/en/docs/img/sponsors/coherence-banner.png create mode 100644 docs/en/docs/img/sponsors/coherence.png diff --git a/README.md b/README.md index 968ccf7a74..874abf8c65 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ The key features are: + diff --git a/docs/en/data/sponsors.yml b/docs/en/data/sponsors.yml index 0ce434b5e2..fd8518ce33 100644 --- a/docs/en/data/sponsors.yml +++ b/docs/en/data/sponsors.yml @@ -20,6 +20,9 @@ gold: - url: https://www.propelauth.com/?utm_source=fastapi&utm_campaign=1223&utm_medium=mainbadge title: Auth, user management and more for your B2B product img: https://fastapi.tiangolo.com/img/sponsors/propelauth.png + - url: https://www.withcoherence.com/?utm_medium=advertising&utm_source=fastapi&utm_campaign=banner%20january%2024 + title: Coherence + img: https://fastapi.tiangolo.com/img/sponsors/coherence.png silver: - url: https://training.talkpython.fm/fastapi-courses title: FastAPI video courses on demand from people you trust diff --git a/docs/en/data/sponsors_badge.yml b/docs/en/data/sponsors_badge.yml index 4078454a8c..00cbec7d28 100644 --- a/docs/en/data/sponsors_badge.yml +++ b/docs/en/data/sponsors_badge.yml @@ -23,3 +23,8 @@ logins: - svixhq - Alek99 - codacy + - zanfaruqui + - scalar + - bump-sh + - andrew-propelauth + - svix diff --git a/docs/en/docs/deployment/cloud.md b/docs/en/docs/deployment/cloud.md index 29f0ad1f6f..d34fbe2f71 100644 --- a/docs/en/docs/deployment/cloud.md +++ b/docs/en/docs/deployment/cloud.md @@ -14,3 +14,4 @@ You might want to try their services and follow their guides: * Platform.sh * Porter +* Coherence diff --git a/docs/en/docs/img/sponsors/coherence-banner.png b/docs/en/docs/img/sponsors/coherence-banner.png new file mode 100644 index 0000000000000000000000000000000000000000..1d495965920e7fce5127637b50fd9530ce447de4 GIT binary patch literal 18388 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 literal 0 HcmV?d00001 diff --git a/docs/en/docs/img/sponsors/coherence.png b/docs/en/docs/img/sponsors/coherence.png new file mode 100644 index 0000000000000000000000000000000000000000..d48c4edc4df9693ef0d847fcd1b6c3055cb6c609 GIT binary patch literal 27886 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