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.

19 KiB

🛠️ & 🔁 /

🔃 async def 🛠️ 🔢 & 🖥 🔃 🔁 📟, 🛠️, & 🔁.

🏃

🆑;👩‍⚕️:

🚥 👆 ⚙️ 🥉 🥳 🗃 👈 💬 👆 🤙 👫 ⏮️ await, 💖:

results = await some_library()

⤴️, 📣 👆 🛠️ 🔢 ⏮️ async def 💖:

@app.get('/')
async def read_results():
    results = await some_library()
    return results

!!! note 👆 💪 🕴 ⚙️ await 🔘 🔢⏮️ async def.


🚥 👆 ⚙️ 🥉 🥳 🗃 👈 🔗 ⏮️ 🕳 (💽, 🛠️, 📁 ⚙️, ️.) & 🚫 ✔️ 🐕‍🦺 ⚙️ await, (👉 💼 🌅 💽 🗃), ⤴️ 📣 👆 🛠️ 🔢 🛎, ⏮️ def, 💖:

@app.get('/')
def results():
    results = some_library()
    return results

🚥 👆 🈸 (😫) 🚫 ✔️ 🔗 ⏮️ 🕳 🙆 & 📨, ⚙️ async def.


🚥 👆 🚫 💭, ⚙️ 😐 def.


🗒: 👆 💪 🌀 def & async def 👆 🛠️ 🔢 🌅 👆 💪 & 🔬 🔠 1️⃣ ⚙️ 🏆 🎛 👆. FastAPI 🔜 ▶️👜 ⏮️ 👫.

😆, 🙆 💼 🔛, FastAPI 🔜 👷 🔁 & 📶 .

📄 📶 🔛, 🔜 💪 🎭 🛠️.

📡

🏛 🐍 ✔️ 🐕‍🦺 "🔁 📟" ⚙️ 🕳 🤙 "🔁", ⏮️ async & await .

➡️ 👀 👈 🔤 🍕 📄 🔛:

  • 🔁 📟
  • async & await
  • 🔁

🔁 📟

🔁 📟👈 🇪🇸 👶 ✔️ 🌌 💬 💻 / 📋 👶 👈📟, 👶 🔜 ✔️ 🕳 🙆 🏁 👱 🙆. ➡️ 💬 👈 🕳 🙆 🤙 "🐌-📁" 👶.

, ⏮️ 👈 🕰, 💻 💪 🚶 & 🎏 👷, "🐌-📁" 👶 🏁.

⤴️ 💻 / 📋 👶 🔜 👟 🔙 🔠 🕰 ✔️ 🤞 ↩️ 🔄, ⚖️ 🕐 👶 🏁 🌐 👷 ✔️ 👈 ☝. & 👶 🔜 👀 🚥 🙆 📋 ✔️ 🏁, 🤸 ✔️.

⏭, 👶 🥇 📋 🏁 (➡️ 💬, 👆 "🐌-📁" 👶) & 😣 ✔️ ⏮️ ️.

👈 " 🕳 🙆" 🛎 🔗 👤/🅾 🛠️ 👈 📶 "🐌" (🔬 🚅 🕹 & 💾 💾), 💖 :

  • 📊 ➡️ 👩‍💻 📨 🔘 🕸
  • 📊 📨 👆 📋 📨 👩‍💻 🔘 🕸
  • 🎚 📁 💾⚙️ & 🤝 👆 📋
  • 🎚 👆 📋 🤝 ⚙️💾
  • 🛰 🛠️ 🛠️
  • 💽 🛠️ 🏁
  • 💽 🔢 📨 🏁
  • ️.

🛠️ 🕰 🍴 ✴️ 👤/🅾 🛠️, 👫 🤙 👫 "👤/🅾 🔗" 🛠️.

🤙 "🔁" ↩️ 💻 / 📋 🚫 ✔️ "🔁" ⏮️ 🐌 📋, 🙍 👈 📋 🏁, 🔨 🕳, 💪 📋 🏁 & 😣 👷.

↩️ 👈, 💆‍♂ "🔁" ⚙️, 🕐 🏁, 📋 💪 🐥 👄 (⏲) 💻 / 📋 🏁 🚶, & ⤴️ 👟 🔙 🏁 & 😣 👷 ⏮️ 👫.

"🔁" (👽 "🔁") 👫 🛎 ⚙️ ⚖ "🔁", ↩️ 💻 / 📋 🌐 📶 🔁🔀 🎏 📋, 🚥 👈 🔁 🔌 .

🛠️ & 🍔

👉 💭 🔁 📟 🔬 🔛 🕣 🤙 "🛠️". 🎏 ➡️ "🔁".

🛠️ & 🔁 👯‍♂️ 🔗 "🎏 👜 😥 🌅 ⚖️ 🌘 🎏 🕰".

️ ℹ 🖖 🛠️ & 🔁 🎏.

👀 🔺, 🌈 📄 📖 🔃 🍔:

🛠️ 🍔

👆 🚶 ⏮️ 👆 🥰 🤚 🥕, 👆 🧍 🏧 ➡️ 👫👫 🚪 👆. 👶

⤴️ 👆 🔄, 👆 🥉 👆2️⃣ 📶 🎀 🍔 👆 🥰 & 👆. 👶 👶

🏧 💬 🕳 🍳 👨‍🍳 👫 💭 👫 ✔️ 🏗 👆 🍔 (👫 🏗 🕐 ⏮️ 👩‍💻).

👆 💸. 👶

🏧 🤝 👆 🔢 👆 🔄.

👆 , 👆 🚶 ⏮️ 👆 🥰 & ⚒ 🏓, 👆 🧎 & 💬 ⏮️ 👆 🥰 📏 🕰 (👆 🍔 📶 🎀 & 🕰 🏗).

👆 🏖 🏓 ⏮️ 👆 🥰, 👆 🍔, 👆 💪 💸 👈 🕰 😮 👌, 🐨 & 🙃 👆 🥰 👶 👶 👶.

& 💬 👆 🥰, ➡️ 🕰 🕰, 👆 🔢 🖥 🔛👀 🚥 👆 🔄 .

⤴️ ☝, 😒 👆 🔄. 👆 🚶 ⏲, 🤚 👆 🍔 & 👟 🔙 🏓.

👆 & 👆 🥰 🍴 🍔 & ✔️ 👌 🕰. 👶

!!! info 🌹 🖼 👯 🍏. 👶


🌈 👆 💻 / 📋 👶 👈 📖.

👆 ⏸, 👆 👶, 👆 🔄, 🚫 🔨 🕳 📶 "😌". ️ ⏸ ↩️ 🏧 🕴 ✔ (🚫 🏗 👫), 👈 👌.

⤴️, 🕐 👆 🔄, 👆 ☑ "😌" 👷, 👆 🛠️ 🍣, 💭 👆 💚, 🤚 👆 🥰 ⚒, 💸, 👈 👆 🤝💵 ⚖️ 💳, 👈 👆 🈚 ☑, 👈✔️🏬, ️.

⤴️, 👆 🚫 ✔️ 👆 🍔, 👆 👷 ⏮️ 🏧 "🔛 ⏸" ⏸, ↩️ 👆 ✔️ 👶 👆 🍔 🔜.

👆 🚶 ↖️ ➡️ ⏲ & 🧎 🏓 ⏮️ 🔢 👆 🔄, 👆 💪 🎛 👶 👆 🙋 👆 🥰, & "👷" 👶 👶 🔛 👈. ⤴️ 👆 🔄 🔨 🕳 📶 "😌" 😏 ⏮️ 👆 🥰 👶.

⤴️ 🏧 👶 💬 "👤 🏁 ⏮️ 🔨 🍔" 🚮 👆 🔢 🔛 ⏲ 🖥, 👆 🚫 🦘 💖 😜 🕐 🖥 🔢 🔀 👆 🔄 🔢. 👆 💭 🙅‍♂ 1️⃣ 🔜 📎 👆 🍔 ↩️ 👆 ✔️ 🔢 👆 🔄, & 👫 ✔️ 👫.

👆 👆 🥰 🏁 📖 (🏁 ⏮️ 👷 👶 / 📋 🛠️ 👶), 😀 🖐 & 💬 👈 👆 🔜 🍔 ⏸.

⤴️ 👆 🚶👶, ▶️ 📋 👈 🔜 🏁 👶, ⚒ 🍔, 💬 👏 & 👫 🏓. 👈 🏁 👈 🔁 / 📋 🔗 ⏮️ ⏲ ⏹. 👈 🔄, ✍ 🆕 📋, "🍴 🍔" 👶 👶, ⏮️ 1️⃣ "🤚 🍔" 🏁 ⏹.

🔗 🍔

🔜 ➡️ 🌈 👫 🚫 🚫 "🛠️ 🍔", ️ "🔗 🍔".

👆 🚶 ⏮️ 👆 🥰 🤚 🔗 🥕.

👆 🧍 📚 (➡️ 💬 8️⃣) 🏧 👈 🎏 🕰 🍳 ➡️ 👫👫 🚪 👆.

👱👆 👫 🍔 🔜🍂↩️ 🔠 8️⃣ 🏧 🚶 & 🏗 🍔 ▶️↖️💆‍♂ ⏭ ✔.

⤴️ 😒 👆 🔄, 👆 🥉 👆2️⃣ 📶 🎀 🍔 👆 🥰 & 👆.

👆 💸 👶.

🏧 🚶 👨‍🍳.

👆 , 🧍 🚪👶, 👈 🙅‍♂ 1️⃣ 🙆 👆 🍔👆, 📤 🙅‍♂ 🔢 🔄.

👆 & 👆 🥰 😩 🚫 ➡️ 🙆 🤚 🚪 👆 & 👆 🍔 🕐 👫 🛬, 👆 🚫🔜 💸 🙋 👆 🥰. 👶

👉 "🔁" 👷, 👆 "🔁" ⏮️ 🏧/🍳 👶 👶. 👆 ✔️ 👶 & 📤🙍 👈 🏧/🍳 👶 👶 🏁 🍔 & 🤝 👫 👆, ⚖️ , 👱 🙆 💪 👫.

⤴️ 👆 🏧/🍳 👶 👶 😒 👟 🔙 ⏮️ 👆 🍔, ⏮️ 📏 🕰 👶 📤 🚪 ⏲.

👆 👆 🍔 & 🚶 🏓 ⏮️ 👆 🥰.

👆 🍴 👫, & 👆 🔨. ⏹

📤 🚫 🌅 💬 ⚖️ 😏 🌅 🕰 💸 👶 🚪 ⏲. 👶

!!! info 🌹 🖼 👯 🍏. 👶


👉 😐 🔗 🍔, 👆 💻 / 📋 👶 ⏮️ 2️⃣ 🕹 (👆 & 👆 🥰), 👯‍♂️ 👶 & 💡 👫 🙋 👶 " 🔛 ⏲" 👶 📏 🕰.

🥕 🏪 ✔️ 8️⃣ 🕹 (🏧/🍳). 🛠️ 🍔 🏪 💪 ✔️ ✔️ 🕴 2️⃣ (1️⃣ 🏧 & 1️⃣ 🍳).

️, 🏁 💡 🚫 🏆. 👶


👉 🔜 🔗 🌓 📖 🍔. 👶

🌅 "🎰 👨‍❤‍👨" 🖼 👉, 🌈 🏦.

🆙 , 🏆 🏦 ✔️ 💗 🏧 👶 👶 👶 👶 👶 👶 👶 👶 & 🦏👶 👶 👶 👶 👶 👶 👶 👶.

🌐 🏧 🔨 🌐 👷 ⏮️ 1️⃣ 👩‍💻 ⏮️ 🎏 👶 👶 👶.

& 👆 ✔️ 👶📏 🕰 ⚖️ 👆 💸 👆 🔄.

👆 🎲 🚫🔜 💚 👆 🥰 👶 ⏮️ 👆 👷 🏦 👶.

🍔 🏁

👉 😐 " 🥕 🍔 ⏮️ 👆 🥰", 📤 📚 👶, ️ ⚒ 📚 🌅 🔑 ✔️ 🛠️ ⚙️👶 👶.

👉 💼 🌅 🕸 🈸.

📚, 📚 👩‍💻, 👆 💽 👶 👫 🚫--👍 🔗 📨 👫 📨.

& ⤴️ 👶 🔄 📨 👟 🔙.

👉 "" 👶 ⚖ ⏲, ️, ⚖ 🌐, 📚 🔚.

👈 ️ ⚒ 📚 🔑 ⚙️ 🔁👶 👶 📟 🕸 🔗.

👉 😇 🔀 ⚒ ✳ 🌟 (️ ✳ 🚫 🔗) & 👈 💪 🚶 🛠️ 🇪🇸.

& 👈 🎏 🎚 🎭 👆 🤚 ⏮️ FastAPI.

& 👆 💪 ✔️ 🔁 & 🔀 🎏 🕰, 👆 🤚🎭 🌘 🌅 💯🛠️ & 🔛 🇷🇪 ⏮️ 🚶, 🇪🇸 🔐 🅱 (🌐 👏 💃).

🛠️ 👍 🌘 🔁

😆 👈 🚫 🛐 📖.

🛠️ 🎏 🌘 🔁. & 👻 🔛 🎯 😐 👈 🔌 📚 . ↩️ 👈, ️ 🛎 📚 👍 🌘 🔁 🕸 🈸 🛠️. 🚫 🌐.

, ⚖ 👈 👅, 🌈 📄 📏 📖:

> 👆 ✔️ 🧹 🦏, 💩 🏠.

😆, 👈 🎂 📖.


📤 🙅‍♂ 👶 🙆, 📚 👷 🔨, 🔛 💗 🥉 🏠.

👆 💪 ✔️ 🔄 🍔 🖼, 🥇 🏠 🧖‍♂, ⤴️ 👨‍🍳, 👆 🚫 👶 🕳, 🧹 & 🧹, 🔄 🚫🔜 📉 🕳.

🔜 🎏 💸 🕰 🏁 ⏮️ ⚖️ 🍵 🔄 (🛠️) & 👆 🔜 ✔️ 🎏 💸 👷.

👉 💼, 🚥 👆 💪 8️⃣ 👰-🏧/🍳/🔜-🧹, & 🔠 1️⃣ 👫 ( 👆) 💪 🏒 🏠 🧹 ️, 👆 💪 🌐 👷 🔗, ⏮️ ℹ, & 🏁 🌅 🔜.

👉 😐, 🔠 1️⃣ 🧹 (🔌 👆) 🔜 🕹, 🤸 👫 🍕 👨‍🏭.

& 🏆 🛠️ 🕰 👷 (↩️ ), & 👷 💻 💽, 👫 🤙 👫 ⚠ "💽 🎁".


⚠ 🖼 💽 🔗 🛠️ 👜 👈 🚚 🏗 🧪 🏭.

🖼:

  • 🎧 ⚖️ 🖼 🏭.
  • 💻 👓: 🖼 ✍ 💯 🔅, 🔠 🔅 ✔️ 3️⃣ 💲 / 🎨, 🏭 👈 🛎 🚚 💻 🕳 🔛 📚 🔅, 🌐 🎏 🕰.
  • 🎰 🏫: ️ 🛎 🚚 📚 "✖" & "🖼" ✖. 💭 🦏 📋 ⏮️ 🔢 & ✖ 🌐 👫 👯‍♂️ 🎏 🕰.
  • 🏫: 👉 🎧-🏑 🎰 🏫,, 🎏 ✔. 👈 📤 🚫 👁 📋 🔢 ✖, 🦏👫, & 📚 💼, 👆 ⚙️ 🎁 🕹 🏗 & / ⚖️ ⚙️ 👈 🏷.

🛠️ 🔁: 🕸 🎰 🏫

⏮️ FastAPI 👆 💪 📈 🛠️ 👈 📶 ⚠ 🕸 🛠️ (🎏 👑 🧲 ✳).

👆 💪 🐄 💰 🔁 & 💾 (✔️ 💗 🛠️ 🏃‍♂ 🔗) 💽 🎁💖 👈 🎰 🏫 ⚙️.

👈, 🙅 👐 👈 🐍 👑 🇪🇸 💽 🧪, 🎰 🏫 & ✴️ 🏫, ⚒ FastAPI 📶 👍 🏏 💽 🧪 / 🎰 🏫 🕸 🔗 & 🈸 (👪 📚 🎏).

👀 🏆 👉 🔁 🏭 👀 📄 🔃 🛠️{.internal-link target=_blank}.

async & await

🏛 🐍 ✔️ 📶 🏋️ 🌌 🔬 🔁 📟. 👉👀 💖 😐 "🔁" 📟 & "" 👆 ▶️🙍.

🕐 📤 🛠️ 👈 🔜 🚚 🤝 🏁 & ✔️ 🐕‍🦺 👉 🆕 🐍 ⚒, 👆 💪 📟 💖:

burgers = await get_burgers(2)

🔑 📥 await. 💬 🐍 👈 ✔️ get_burgers(2) 🏁 🔨 🚮 👜 👶 ⏭ ♻ 🏁 burgers. ⏮️ 👈, 🐍 🔜 💭 👈 💪 🚶 & 🕳 🙆 👶 👶 👐 (💖 📨 1️⃣ 📨).

await 👷, ✔️ 🔘 🔢 👈 🐕‍🦺 👉 🔀. 👈, 👆 📣 ⏮️ async def:

async def get_burgers(number: int):
    # Do some asynchronous stuff to create the burgers
    return burgers

...↩️ def:

# This is not asynchronous
def get_sequential_burgers(number: int):
    # Do some sequential stuff to create the burgers
    return burgers

⏮️ async def, 🐍 💭 👈, 🔘 👈 🔢, ✔️ 🤔 await 🧬, & 👈 💪 "⏸" ⏸ 🛠️ 👈 🔢 & 🚶 🕳 🙆 👶👟 🔙.

🕐 👆 💚 🤙 async def 🔢, 👆 ✔️ "" ️. , 👉 🏆 🚫 👷:

# This won't work, because get_burgers was defined with: async def
burgers = get_burgers(2)

, 🚥 👆 ⚙️ 🗃 👈 💬 👆 👈 👆 💪 🤙 ⏮️ await, 👆 💪🛠️ 🔢 👈 ⚙️ ⏮️ async def, 💖:

@app.get('/burgers')
async def read_burgers():
    burgers = await get_burgers(2)
    return burgers

🌅 📡

👆 💪 ✔️ 👀 👈 await 💪 🕴 ⚙️ 🔘 🔢 🔬 ⏮️ async def.

🎏 🕰, 🔢 🔬 ⏮️ async def ✔️ "". , 🔢 ⏮️ async def 💪 🕴 🤙 🔘 🔢 🔬 ⏮️ async def 💁‍♂️.

, 🔃 🥚 & 🐔, 👆 🤙 🥇 async 🔢

🚥 👆 👷 ⏮️ FastAPI 👆 🚫 ✔️ 😟 🔃 👈, ↩️ 👈 "🥇" 🔢 🔜 👆 🛠️ 🔢, & FastAPI 🔜 💭 ▶️👜.

🚥 👆 💚 ⚙️ async / await 🍵 FastAPI, 👆 💪 👍.

👆 👍 🔁 📟

💃 (& FastAPI) 🔛 AnyIO, 🔗 ⏮️ 👯‍♂️ 🐍 🐩 🗃 & 🎻.

🎯, 👆 💪 🔗 ⚙️ AnyIO 👆 🏧 🛠️ ⚙️ 💼 👈 🚚 🌅 🏧 👆 👍 📟.

& 🚥 👆 🚫 ⚙️ FastAPI, 👆 💪👆 👍 🔁 🈸 ⏮️ AnyIO 🏆 🔗 & 🤚 🚮 💰 ( 📊 🛠️).

🎏 📨 🔁 📟

👉 👗 ⚙️ async & await 📶 🆕 🇪🇸.

️ ⚒ 👷 ⏮️ 🔁 📟 📚 .

👉 🎏 (⚖️ 🌖 🌓) 🔌 🏛 🕸 (🖥 & ✳).

️ ⏭ 👈, 🚚 🔁 📟 🌖 🏗 & ⚠.

⏮️ 🐍, 👆 💪 ✔️ ⚙️ 🧵 ⚖️ 🐁. 📟 🌌 🌖 🏗 🤔, ℹ, & 💭 🔃.

⏮️ ✳ / 🖥 🕸, 👆 🔜 ✔️ ⚙️ "⏲". ↘️ ⏲ 🔥😈.

🔁

🔁 📶 🎀👜 📨 async def 🔢. 🐍 💭 👈 ️ 🕳 💖 🔢 👈 💪 ▶️ & 👈 🔜 🔚 ☝, 👈 5️⃣📆 ⏸ ⏸ 🔘 💁‍♂️, 🕐 📤 await 🔘 ️.

🌐 👉 🛠️ ⚙️ 🔁 📟 ⏮️ async & await 📚 🕰 🔬 ⚙️ "🔁". 👑 🔑🚶, "🔁".

🏁

➡️ 👀 🎏 🔤 ➡️ 🔛:

🏛 🐍 ✔️ 🐕‍🦺 "🔁 📟" ⚙️ 🕳 🤙 "🔁", ⏮️ async & await .

👈 🔜🌅 🔑 🔜. 👶

🌐 👈 🏋️ FastAPI (🔘 💃) & ✔️ 🎆 🎭.

📶 📡

!!! warning 👆 💪 🎲 🚶 👉.

👉 📶 📡 ℹ ❔ **FastAPI** 👷 🔘.

🚥 👆 ✔️ 📡 💡 (🈶-🏋, 🧵, 🍫, ♒️.) & 😟 🔃 ❔ FastAPI 🍵 `async def` 🆚 😐 `def`, 🚶 ⤴️.

🛠️ 🔢

🕐 👆 📣 🛠️ 🔢 ⏮️ 😐 def ↩️ async def, 🏃 🔢 🧵 👈 ⤴️ , ↩️ 🤙 🔗 (🔜 🍫 💽).

🚥 👆 👟 ➡️ 1️⃣ 🔁 🛠️ 👈 🔨 🚫 👷 🌌 🔬 🔛 & 👆 ⚙️🙃 📊-🕴 🛠️ 🔢 ⏮️ def 🤪 🎭 📈 (🔃 1️⃣0️⃣0️⃣ 💓), 🙏 🗒 👈 FastAPI 🔜 🔄. 👫 💼, 👻 ⚙️ async def 🚥 👆 🛠️ 🔢 ⚙️ 📟 👈 🎭 🚧 👤/🅾.

, 👯‍♂️ ⚠, 🤞 👈 FastAPI 🔜 {.internal-link target=_blank} 🌘 (⚖️ 🌘 ) 👆 ⏮️ 🛠️.

🔗

🎏🔗{.internal-link target=_blank}. 🚥 🔗 🐩 def 🔢 ↩️ async def, 🏃 🔢 🧵.

🎧-🔗

👆 💪 ✔️ 💗 🔗 & 🎧-🔗{.internal-link target=_blank} 🚫 🔠 🎏 (🔢 🔢 🔑), 👫 💪⏮️ async def & ⏮️ 😐 def. 🔜 👷, & 🕐⏮️ 😐 def 🔜 🤙 🔛 🔢 🧵 (➡️ 🧵) ↩️ "".

🎏 🚙 🔢

🙆 🎏 🚙 🔢 👈 👆 🤙 🔗 💪⏮️ 😐 def ⚖️ async def & FastAPI 🏆 🚫 📉 🌌 👆 🤙 ️.

👉 🔅 🔢 👈 FastAPI 🤙 👆: 🛠️ 🔢 & 🔗.

🚥 👆 🚙 🔢 😐 🔢 ⏮️ def, 🔜 🤙 🔗 (👆👆 📟), 🚫 🧵, 🚥 🔢⏮️ async def ⤴️ 👆 🔜 await 👈 🔢 🕐 👆 🤙 👆 📟.


🔄, 👉 📶 📡👈 🔜 🎲🚥 👆 👟 🔎 👫.

, 👆 🔜 👍 ⏮️ 📄 ➡️ 📄 🔛: 🏃 ❓.