Skip to content

🛠️

👆 💪 🔗 🕹 👆 👨‍🎨, 🖼 ⏮️ 🎙 🎙 📟 ⚖️ 🗒.

🤙 uvicorn

👆 FastAPI 🈸, 🗄 & 🏃 uvicorn 🔗:

import uvicorn
from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def root():
    a = "a"
    b = "b" + a
    return {"hello world": b}


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)

🔃 __name__ == "__main__"

👑 🎯 __name__ == "__main__" ✔️ 📟 👈 🛠️ 🕐❔ 👆 📁 🤙 ⏮️:

$ python myapp.py

✋️ 🚫 🤙 🕐❔ ➕1️⃣ 📁 🗄 ⚫️, 💖:

from myapp import app

🌅 ℹ

➡️ 💬 👆 📁 🌟 myapp.py.

🚥 👆 🏃 ⚫️ ⏮️:

$ python myapp.py

⤴️ 🔗 🔢 __name__ 👆 📁, ✍ 🔁 🐍, 🔜 ✔️ 💲 🎻 "__main__".

, 📄:

    uvicorn.run(app, host="0.0.0.0", port=8000)

🔜 🏃.


👉 🏆 🚫 🔨 🚥 👆 🗄 👈 🕹 (📁).

, 🚥 👆 ✔️ ➕1️⃣ 📁 importer.py ⏮️:

from myapp import app

# Some more code

👈 💼, 🏧 🔢 🔘 myapp.py 🔜 🚫 ✔️ 🔢 __name__ ⏮️ 💲 "__main__".

, ⏸:

    uvicorn.run(app, host="0.0.0.0", port=8000)

🔜 🚫 🛠️.

Info

🌅 ℹ, ✅ 🛂 🐍 🩺.

🏃 👆 📟 ⏮️ 👆 🕹

↩️ 👆 🏃 Uvicorn 💽 🔗 ⚪️➡️ 👆 📟, 👆 💪 🤙 👆 🐍 📋 (👆 FastAPI 🈸) 🔗 ⚪️➡️ 🕹.


🖼, 🎙 🎙 📟, 👆 💪:

  • 🚶 "ℹ" 🎛.
  • "🚮 📳...".
  • 🖊 "🐍"
  • 🏃 🕹 ⏮️ 🎛 "Python: Current File (Integrated Terminal)".

⚫️ 🔜 ⤴️ ▶️ 💽 ⏮️ 👆 FastAPI 📟, ⛔️ 👆 0️⃣, ♒️.

📥 ❔ ⚫️ 💪 👀:


🚥 👆 ⚙️ 🗒, 👆 💪:

  • 📂 "🏃" 🍣.
  • 🖊 🎛 "ℹ...".
  • ⤴️ 🔑 🍣 🎦 🆙.
  • 🖊 📁 ℹ (👉 💼, main.py).

⚫️ 🔜 ⤴️ ▶️ 💽 ⏮️ 👆 FastAPI 📟, ⛔️ 👆 0️⃣, ♒️.

📥 ❔ ⚫️ 💪 👀: