docs/en/docs/reference/status.md
You can import the status module from fastapi:
from fastapi import status
status is provided directly by Starlette.
It contains a group of named constants (variables) with integer status codes.
For example:
status.HTTP_200_OKstatus.HTTP_403_FORBIDDENIt can be convenient to quickly access HTTP (and WebSocket) status codes in your app, using autocompletion for the name without having to memorize the integer status codes.
Read more about it in the FastAPI docs about Response Status Code.
from fastapi import FastAPI, status
app = FastAPI()
@app.get("/items/", status_code=status.HTTP_418_IM_A_TEAPOT)
def read_items():
return [{"name": "Plumbus"}, {"name": "Portal Gun"}]
::: fastapi.status