Running the server with the FastAPI CLI
The FastAPI command-line interface (CLI) is a program that runs in the command line. You can use the $ fastapi
command to run a FastAPI application, manage a FastAPI project, and do other things. This feature was added in version 0.111.0 recently.
In this recipe, we’ll explore how to run a FastAPI application using the FastAPI CLI. This approach can streamline your development workflow and provide a more intuitive way to manage your server.
Getting ready
To run the recipe, ensure you have a minimum FastAPI module with the application with at least one endpoint. We will work on a new application called Live Application
, so create a new project folder called live_application
with an app
subfolder containing a main.py
module as follows:
from fastapi import FastAPI app = FastAPI(title="FastAPI Live Application") @app.get("/") def read_root(): return {"Hello": "World"...