This example shows you how to use Mesop and FastAPI together.
The example has an HTTP endpoint /hello
with FastAPI and a Mesop web component which fetches from the endpoint and displays the results in the UI.
This project uses uv
so you will need to install it.
You can run it like this:
DEBUG_MODE=true uv run main.py
But if you're developing locally, you will most likely want to enable auto-reloading with uvicorn
.
You can run it in production mode using the standard fastapi run
CLI command:
uv run fastapi run
Note:
uv run
is just a wrapper to use the fastapi command with the uv virtual environment.
Right now Mesop hot reload doesn't work when running with the commands above. You can use the regular Mesop CLI command mesop main.py
which supports hot reloading, but then the fastapi server isn't running. If you'd like this supported, please upvote: mesop-dev/mesop#894.