Create a FastAPI Project in 45 seconds: 6-Line Tutorial
If you want to quickly create a FastAPI project, follow these six simple steps:
- Create a new directory for your project:
- Change into the new directory:
- Create a new Python file for your FastAPI app:
- Open the main.py file in your favorite text editor and add the following code:
- Install FastAPI and uvicorn (a lightweight ASGI server) using pip:
- Run the FastAPI app using uvicorn:
mkdir my_fastapi_project
cd my_fastapi_project
touch main.py
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
def read_root():
return {"Hello": "World"}
pip install fastapi uvicorn
uvicorn main:app --reload
Congratulations! You have successfully created a FastAPI project in just 45 seconds. You can now access your FastAPI app at http://127.0.0.1:8000/
.
100% informative