Welcome to FastAPI
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
To create your first “Hello World” application with FastAPI, you can follow these simple steps:
- Install FastAPI using pip:
- Install uvicorn, a lightweight ASGI server implementation, to run the FastAPI application:
- Create a new Python file, for example,
app.py
, and add the following code: - Run the FastAPI application using uvicorn:
- Open your web browser and navigate to
http://localhost:8000/
to see the “Hello, World!” message.
pip install fastapi
pip install uvicorn
from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
return {"message": "Hello, World!"}
uvicorn app:app --reload
Congratulations! You have successfully created your first “Hello World” API with FastAPI.
FastAPI’s simplicity, speed, and type checking features make it a powerful framework for building web APIs. You can explore more features and functionalities of FastAPI by referring to its official documentation.