3.4 KiB
⚙️ 🎻
FastAPI 🏗 🔛 🔝 Pydantic, & 👤 ✔️ 🌏 👆 ❔ ⚙️ Pydantic 🏷 📣 📨 & 📨.
✋️ FastAPI 🐕🦺 ⚙️ dataclasses
🎏 🌌:
{* ../../docs_src/dataclasses/tutorial001.py hl[1,7:12,19:20] *}
👉 🐕🦺 👏 Pydantic, ⚫️ ✔️ 🔗 🐕🦺 dataclasses
.
, ⏮️ 📟 🔛 👈 🚫 ⚙️ Pydantic 🎯, FastAPI ⚙️ Pydantic 🗜 📚 🐩 🎻 Pydantic 👍 🍛 🎻.
& ↗️, ⚫️ 🐕🦺 🎏:
- 💽 🔬
- 💽 🛠️
- 💽 🧾, ♒️.
👉 👷 🎏 🌌 ⏮️ Pydantic 🏷. & ⚫️ 🤙 🏆 🎏 🌌 🔘, ⚙️ Pydantic.
/// info
✔️ 🤯 👈 🎻 💪 🚫 🌐 Pydantic 🏷 💪.
, 👆 5️⃣📆 💪 ⚙️ Pydantic 🏷.
✋️ 🚥 👆 ✔️ 📚 🎻 🤥 🤭, 👉 👌 🎱 ⚙️ 👫 🏋️ 🕸 🛠️ ⚙️ FastAPI. 👶
///
🎻 response_model
👆 💪 ⚙️ dataclasses
response_model
🔢:
{* ../../docs_src/dataclasses/tutorial002.py hl[1,7:13,19] *}
🎻 🔜 🔁 🗜 Pydantic 🎻.
👉 🌌, 🚮 🔗 🔜 🎦 🆙 🛠️ 🩺 👩💻 🔢:

🎻 🔁 📊 📊
👆 💪 🌀 dataclasses
⏮️ 🎏 🆎 ✍ ⚒ 🐦 📊 📊.
💼, 👆 💪 ✔️ ⚙️ Pydantic ⏬ dataclasses
. 🖼, 🚥 👆 ✔️ ❌ ⏮️ 🔁 🏗 🛠️ 🧾.
👈 💼, 👆 💪 🎯 💱 🐩 dataclasses
⏮️ pydantic.dataclasses
, ❔ 💧-♻:
{!../../docs_src/dataclasses/tutorial003.py!}
1️⃣. 👥 🗄 field
⚪️➡️ 🐩 dataclasses
.
2️⃣. pydantic.dataclasses
💧-♻ dataclasses
.
3️⃣. Author
🎻 🔌 📇 Item
🎻.
4️⃣. Author
🎻 ⚙️ response_model
🔢.
5️⃣. 👆 💪 ⚙️ 🎏 🐩 🆎 ✍ ⏮️ 🎻 📨 💪.
👉 💼, ⚫️ 📇 `Item` 🎻.
6️⃣. 📥 👥 🛬 📖 👈 🔌 items
❔ 📇 🎻.
FastAPI 🎯 <abbr title="converting the data to a format that can be transmitted">✍</abbr> 💽 🎻.
7️⃣. 📥 response_model
⚙️ 🆎 ✍ 📇 Author
🎻.
🔄, 👆 💪 🌀 `dataclasses` ⏮️ 🐩 🆎 ✍.
8️⃣. 👀 👈 👉 ➡ 🛠️ 🔢 ⚙️ 🥔 def
↩️ async def
.
🕧, FastAPI 👆 💪 🌀 `def` & `async def` 💪.
🚥 👆 💪 ↗️ 🔃 🕐❔ ⚙️ ❔, ✅ 👅 📄 _"🏃 ❓" _ 🩺 🔃 <a href="https://fastapi.tiangolo.com/async/#in-a-hurry" target="_blank" class="internal-link">`async` & `await`</a>.
9️⃣. 👉 ➡ 🛠️ 🔢 🚫 🛬 🎻 (👐 ⚫️ 💪), ✋️ 📇 📖 ⏮️ 🔗 💽.
FastAPI 🔜 ⚙️ `response_model` 🔢 (👈 🔌 🎻) 🗜 📨.
👆 💪 🌀 dataclasses
⏮️ 🎏 🆎 ✍ 📚 🎏 🌀 📨 🏗 📊 📊.
✅-📟 ✍ 💁♂ 🔛 👀 🌅 🎯 ℹ.
💡 🌅
👆 💪 🌀 dataclasses
⏮️ 🎏 Pydantic 🏷, 😖 ⚪️➡️ 👫, 🔌 👫 👆 👍 🏷, ♒️.
💡 🌅, ✅ Pydantic 🩺 🔃 🎻.
⏬
👉 💪 ↩️ FastAPI ⏬ 0.67.0
. 👶