You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5.2 KiB

📨 💪

🕐 👆 💪 📨 📊 ➡️ 👩‍💻 (➡️ 💬, 🖥) 👆 🛠️, 👆 📨 📨 💪.

📨 💪 📊 📨 👩‍💻 👆 🛠️. 📨 💪 💽 👆 🛠️ 📨 👩‍💻.

👆 🛠️ 🌖 🕧 ✔️ 📨 📨 💪. 👩‍💻 🚫 🎯 💪 📨 📨 💪 🌐 🕰.

📣 📨 💪, 👆 ⚙️ Pydantic 🏷 ⏮️ 🌐 👫 🏋️ & 💰.

/// info

📨 💽, 👆 🔜 ⚙️ 1️⃣: POST (🌅 ⚠), PUT, DELETE ⚖️ PATCH.

📨 💪 ⏮️ GET 📨 ✔️🎭 🔧, 👐, 🐕‍🦺 FastAPI, 🕴 📶 🏗/😕 ⚙️ 💼.

🚫, 🎓 🩺 ⏮️ 🦁 🎚 🏆 🚫 🎦 🧾 💪 🕐 ⚙️ GET, & 🗳 🖕 💪 🚫 🐕‍🦺 ️.

///

🗄 Pydantic BaseModel

🥇, 👆 💪 🗄 BaseModel ➡️ pydantic:

{* ../../docs_src/body/tutorial001.py hl[4] *}

👆 💽 🏷

⤴️ 👆 📣 👆 💽 🏷 🎓 👈 😖 ➡️ BaseModel.

⚙️ 🐩 🐍 🆎 🌐 🔢:

{* ../../docs_src/body/tutorial001.py hl[7:11] *}

🎏 🕐 📣 🔢 🔢, 🕐 🏷 🔢 ✔️ 🔢 💲, 🚫 ✔. , ️ ✔. ⚙️ None📦.

🖼, 👉 🏷 🔛 📣 🎻 "object" (⚖️ 🐍 dict) 💖:

{
    "name": "Foo",
    "description": "An optional description",
    "price": 45.2,
    "tax": 3.5
}

... description & tax 📦 (⏮️ 🔢 💲 None), 👉 🎻 "object" 🔜 ☑:

{
    "name": "Foo",
    "price": 45.2
}

📣 🔢

🚮 👆 🛠️, 📣 🎏 🌌 👆 📣 ➡ & 🔢 🔢:

{* ../../docs_src/body/tutorial001.py hl[18] *}

...& 📣 🚮 🆎 🏷 👆 ✍, Item.

🏁

⏮️ 👈 🐍 🆎 📄, FastAPI 🔜:

  • 💪 📨 🎻.
  • 🗜 🔗 🆎 (🚥 💪).
  • 💽.
    • 🚥 💽 , 🔜 📨 👌 & 🆑 , ☠️ 🌐 & 📊.
  • 🤝 👆 📨 📊 🔢 item.
    • 👆 📣 🔢 🆎 Item, 👆 🔜 ✔️ 🌐 👨‍🎨 🐕‍🦺 (🛠️, ️) 🌐 🔢 & 👫 🆎.
  • 🏗 🎻 🔗 🔑 👆 🏷, 👆 💪 ⚙️ 👫 🙆 🙆 👆 💖 🚥 ️ ⚒ 🔑 👆 🏗.
  • 👈 🔗 🔜 🍕 🏗 🗄 🔗, & ⚙️ 🏧 🧾 .

🏧 🩺

🎻 🔗 👆 🏷 🔜 🍕 👆 🗄 🏗 🔗, & 🔜 🎦 🎓 🛠️ 🩺:

& 🔜 ⚙️ 🛠️ 🩺 🔘 🔠 🛠️ 👈 💪 👫:

👨‍🎨 🐕‍🦺

👆 👨‍🎨, 🔘 👆 🔢 👆 🔜 🤚 🆎 🔑 & 🛠️ 🌐 (👉 🚫🔜 🔨 🚥 👆 📨 dict ↩️ Pydantic 🏷):

👆 🤚 🆎 🛠️:

👉 🚫 🤞, 🎂 🛠️ 🏗 🤭 👈 🔧.

& 🙇 💯 🔧 🌓, ⏭ 🙆 🛠️, 🚚 🔜 👷 ⏮️ 🌐 👨‍🎨.

📤 🔀 Pydantic 🐕‍🦺 👉.

⏮️ 🖼 ⏮️ 🎙 🎙 📟.

👆 🔜 🤚 🎏 👨‍🎨 🐕‍🦺 ⏮️ 🗒 & 🌅 🎏 🐍 👨‍🎨:

/// tip

🚥 👆 ⚙️ 🗒 👆 👨‍🎨, 👆 💪 ⚙️ Pydantic 🗒 📁.

📉 👨‍🎨 🐕‍🦺 Pydantic 🏷, ⏮️:

  • 🚘-🛠️
  • 🆎
  • 🛠️
  • 🔎
  • 🔬

///

⚙️ 🏷

🔘 🔢, 👆 💪 🔐 🌐 🔢 🏷 🎚 🔗:

{* ../../docs_src/body/tutorial002.py hl[21] *}

📨 💪 🔢

👆 💪 📣🔢 & 📨 💪 🎏 🕰.

FastAPI 🔜 🤔 👈 🔢 🔢 👈 🏏🔢 🔜 ➡️, & 👈 🔢 🔢 👈 📣 Pydantic 🏷 🔜 ➡️ 📨 💪.

{* ../../docs_src/body/tutorial003.py hl[17:18] *}

📨 💪 🔢 🔢

👆 💪 📣 💪, & 🔢 🔢, 🌐 🎏 🕰.

FastAPI 🔜 🤔 🔠 👫 & 📊 ➡️🥉.

{* ../../docs_src/body/tutorial004.py hl[18] *}

🔢 🔢 🔜 🤔 :

  • 🚥 🔢 📣 , 🔜 ⚙️🔢.
  • 🚥 🔢 🆎 (💖 int, float, str, bool, ️) 🔜 🔬 🔢 🔢.
  • 🚥 🔢 📣 🆎 Pydantic 🏷, 🔜 🔬 📨 💪.

/// note

FastAPI 🔜 💭 👈 💲 q 🚫↩️ 🔢 💲 = None.

Union Union[str, None] 🚫 ⚙️ FastAPI, 🔜👆 👨‍🎨 🤝 👆 👍 🐕‍🦺 & 🔍 .

///

🍵 Pydantic

🚥 👆 🚫 💚 ⚙️ Pydantic 🏷, 👆 💪 ⚙️ 💪 🔢. 👀 🩺 💪 - 💗 🔢: ⭐ 💲 💪{.internal-link target=_blank}.