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.

6.7 KiB

🔗

FastAPI ✔️ 📶 🏋️ 🏋️ 🔗 💉 ⚙️.

️ 🏗 📶 🙅 ⚙️, & ⚒ 📶 🙆 👩‍💻 🛠️ 🎏 🦲 ⏮️ FastAPI.

"🔗 💉"

"🔗 💉" ⛓, 📋, 👈 📤 🌌 👆 📟 (👉 💼, 👆 🛠️ 🔢) 📣 👜 👈 🚚 👷 & ⚙️: "🔗".

& ⤴️, 👈 ⚙️ (👉 💼 FastAPI) 🔜 💅 🔨 💪 🚚 👆 📟 ⏮️ 📚 💪 🔗 ("💉" 🔗).

👉 📶🕐 👆 💪:

  • ✔️ 💰 ⚛ (🎏 📟🔄 & 🔄).
  • 💰 💽 🔗.
  • 🛠️ 💂‍♂, 🤝, 🔑 📄, ️.
  • & 📚 🎏 👜...

🌐 👫, 📉 📟 🔁.

🥇 🔁

➡️ 👀 📶 🙅 🖼. 🔜 🙅 👈 🚫 📶 ⚠, 🔜.

👉 🌌 👥 💪 🎯 🔛 🔗 💉 ⚙️ 👷.

🔗, ⚖️ "☑"

➡️ 🥇 🎯 🔛 🔗.

🔢 👈 💪 🌐 🎏 🔢 👈 🛠️ 🔢 💪 :

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="8-11"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="6-7"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```

👈 ️.

2️⃣.

& ✔️ 🎏 💠 & 📊 👈 🌐 👆 🛠️ 🔢 ✔️.

👆 💪 💭 🛠️ 🔢 🍵 "👨‍🎨" (🍵 @app.get("/some-path")).

& 💪 📨 🕳 👆 💚.

👉 💼, 👉 🔗 :

  • 📦 🔢 🔢 q 👈 str.
  • 📦 🔢 🔢 skip 👈 int, & 🔢 0.
  • 📦 🔢 🔢 limit 👈 int, & 🔢 100.

& ⤴️ 📨 dict📚 💲.

🗄 Depends

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="3"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="1"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```

📣 🔗, "️"

🎏 🌌 👆 ⚙️ Body, Query, ️. ⏮️ 👆 🛠️ 🔢 🔢, ⚙️ Depends ⏮️ 🆕 🔢:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="15  20"
{!> ../../../docs_src/dependencies/tutorial001.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="11  16"
{!> ../../../docs_src/dependencies/tutorial001_py310.py!}
```

👐 👆 ⚙️ Depends 🔢 👆 🔢 🎏 🌌 👆 ⚙️ Body, Query, ️, Depends 👷 👄 🎏.

👆 🕴 🤝 Depends 👁 🔢.

👉 🔢 🔜 🕳 💖 🔢.

& 👈 🔢 🔢 🎏 🌌 👈 🛠️ 🔢 .

!!! tip 👆 🔜 👀 🎏 "👜", ↖️ ➡️ 🔢, 💪 ⚙️ 🔗📃.

🕐 🆕 📨 🛬, FastAPI 🔜 💅:

  • 🤙 👆 🔗 ("☑") 🔢 ⏮️🔢.
  • 🤚 🏁 ➡️ 👆 🔢.
  • 🛠️ 👈 🏁 🔢 👆 🛠️ 🔢.
graph TB

common_parameters(["common_parameters"])
read_items["/items/"]
read_users["/users/"]

common_parameters --> read_items
common_parameters --> read_users

👉 🌌 👆🔗 📟 🕐 & FastAPI 💅 🤙 👆 🛠️.

!!! check 👀 👈 👆 🚫 ✔️🎁 🎓 & 🚶‍♀️ 👱 FastAPI "®" ⚖️ 🕳 🎏.

👆 🚶‍♀️ ⚫️ `Depends` & **FastAPI** 💭 ❔ 🎂.

async ⚖️ 🚫 async

🔗 🔜 🤙 FastAPI (🎏 👆 🛠️ 🔢), 🎏 🚫 🔬 👆 🔢.

👆 💪 ⚙️ async def ⚖️ 😐 def.

& 👆 💪 📣 🔗 ⏮️ async def 🔘 😐 def 🛠️ 🔢, ⚖️ def 🔗 🔘 async def 🛠️ 🔢, ️.

🚫 🤔. FastAPI 🔜 💭 .

!!! note 🚥 👆 🚫 💭, 🔁: *"🏃 ❓" *{.internal-link target=_blank} 📄 🔃 async & await 🩺.

🛠️ ⏮️ 🗄

🌐 📨 📄, 🔬 & 📄 👆 🔗 (& 🎧-🔗) 🔜 🛠️ 🎏 🗄 🔗.

, 🎓 🩺 🔜 ✔️ 🌐➡️ 👫 🔗 💁‍♂️:

🙅 ⚙️

🚥 👆 👀 ️, 🛠️ 🔢 📣 ⚙️ 🕐 & 🛠️ 🏏, & ⤴️ FastAPI 💅 🤙 🔢 ⏮️🔢, 📊 ➡️ 📨.

🤙, 🌐 (⚖️ 🏆) 🕸 🛠️ 👷 👉 🎏 🌌.

👆 🙅 🤙 👈 🔢 🔗. 👫 🤙 👆 🛠️ (👉 💼, FastAPI).

⏮️ 🔗 💉 ⚙️, 👆 💪 💬 FastAPI 👈 👆 🛠️ 🔢 "🪀" 🔛 🕳 🙆 👈 🔜 🛠️👆 🛠️ 🔢, & FastAPI 🔜 💅 🛠️ ️ & "💉" 🏁.

🎏 ⚠ ⚖ 👉 🎏 💭 "🔗 💉":

  • 🐕‍🦺
  • 🐕‍🦺
  • 💉
  • 🦲

FastAPI 🔌-🔌

🛠️ & "🔌-"Ⓜ 💪 🏗 ⚙️ 🔗 💉 ⚙️. 👐, 📤 🤙 🙅‍♂ 💪 ✍ "🔌-🔌", ⚙️ 🔗 💪 📣🔢 🛠️ & 🔗 👈 ▶️💪 👆 🛠️ 🔢.

& 🔗 💪📶 🙅 & 🏋️ 🌌 👈👆 🗄 🐍 📦 👆 💪, & 🛠️ 👫 ⏮️ 👆 🛠️ 🔢 👩‍❤‍👨📟, 🌖.

👆 🔜 👀 🖼 👉📃, 🔃 🔗 & ☁ 💽, 💂‍♂, ️.

FastAPI 🔗

🦁 🔗 💉 ⚙️FastAPI 🔗 ⏮️:

  • 🌐 🔗 💽
  • 💽
  • 🔢 📦
  • 🔢 🔗
  • 🤝 & ✔ ⚙️
  • 🛠️ ⚙️⚙️
  • 📨 💽 💉 ⚙️
  • ️.

🙅 & 🏋️

👐 🔗 🔗 💉 ⚙️ 📶 🙅 🔬 & ⚙️, 📶 🏋️.

👆 💪 🔬 🔗 👈 🔄 💪 🔬 🔗 👫.

🔚, 🔗 🌲 🔗 🏗, & 🔗 💉 ⚙️ 💅 🔬 🌐 👉 🔗 👆 (& 👫 🎧-🔗) & 🚚 (💉) 🏁 🔠 🔁.

🖼, ➡️ 💬 👆 ✔️ 4️⃣ 🛠️ 🔗 (🛠️):

  • /items/public/
  • /items/private/
  • /users/{user_id}/activate
  • /items/pro/

⤴️ 👆 💪 🚮 🎏📄 🔠 👫 ⏮️ 🔗 & 🎧-🔗:

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

🛠️ ⏮️ 🗄

🌐 👫 🔗, 📣 👫 📄, 🚮 🔢, 🔬, ️. 👆 🛠️.

FastAPI 🔜 💅 🚮 🌐 🗄 🔗, 👈 🎦 🎓 🧾 ⚙️.