HomeAbout

FastAPI

Initialize Project

pip install "fastapi[standard]"

No initialization needed when starting FastAPI server.

Create a main.py python script with basic route like below:

# main.py from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"message": "Hello World"} # @app.get("/items/{item_id}") # def read_item(item_id: int, query_param: str = None): # return {"item_id": item_id, "query_param": query_param}

Run Server

uvicorn

uvicorn is a ASGI server (Asynchronous Server Gateway Interface).

  • ASGI is a specification for asynchronous web servers and applications in Python

Used to run asynchronous web applications.

pip install uvicorn uvicorn main:app --reload # run dev server fastapi dev main.py

Swagger Doc

FastAPI comes with Swagger UI for documentation

http://localhost:8000/docs
AboutContact