Created
September 10, 2024 12:34
-
-
Save timvw/27b1abb740fbf6ff2878e42bd74eaab9 to your computer and use it in GitHub Desktop.
Entrypoint for FastAPI/uvicorn application executed as python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import uvicorn | |
if __name__ == "__main__": | |
''' | |
Entrypoint to run the FastAPI application (without using the FastAPI/Uvicorn CLI). | |
Because a python script can't import relatively, we apply a sys.path hack to import the application. | |
Typically you do not need this and simply invoke one of the following: | |
* rye run fastapi dev ./src/backend/app.py | |
* fastapi run dev ./src/backend/app.py | |
''' | |
import os | |
import sys | |
sys.path.append(os.path.abspath('../')) | |
from backend.app import app | |
uvicorn.run(app, host="0.0.0.0", port=8000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VsCode also has a FastAPI debug configuration