Hello World, in FastAPI

Python
FastAPI
Author

Galen Seilis

Published

August 21, 2024

This is a quick post showing how to create a “Hello, World” example in FastAPI.

Similar to the example Hello World, In Flask, with FastAPI we instantiate an app which contains methods that decorate other functions which will be used to returns responses. Finally, I used uvicorn to actually run the application at a given host and port.

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello, World!"}

if __name__ == '__main__':
    import uvcorn
    uvicorn.run(app, host="127.0.0.1", port=8000)

That’s all there is for this minimum working example.