@jasen
To run a FastAPI application from the terminal, you can follow these steps:
1
|
pip install fastapi |
1 2 3 4 5 6 7 |
from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} |
1
|
uvicorn app:app --reload |
This command starts the Uvicorn server and loads your FastAPI application located in the app.py
file. The --reload
flag will automatically restart the server whenever you make changes to your code.
1
|
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) |
That's it! You have successfully run a FastAPI application from the terminal.