Skip to main content

Flet for FastAPI

· 2 min read
Feodor Fitsner
Flet founder and developer

We've just released Flet 0.10.0 with FastAPI support!

FastAPI coupled with Uvicorn, Hypercorn, Gunicorn or other web server replaces built-in Flet web server (Fletd) to reliably run production Flet workloads.

On the other hand, seasoned FastAPI developers can use Flet to easily add interactive, real-time dashboards and admin UI to their existing or new FastAPI services.

A minimal app example​

import flet as ft
import flet_fastapi

async def main(page: ft.Page):
await page.add_async(
ft.Text("Hello, Flet!")
)

app = flet_fastapi.app(main)

It's a simple app that just outputs "Hello, Flet!" on a web page.

To run the app install Flet for FastAPI and Uvicorn:

pip install flet-fastapi
pip install uvicorn

Save the code above to hello.py and then start uvicorn as:

uvicorn hello:app

Open the browser and navigate to http://127.0.0.1:8000 to see the app running.

note

Flet app must be async in order to work with FastAPI WebSocket handler.

Features and benefits​

Check the guide for complete information about Flet with FastAPI.

Let us know what you think by joining Flet Discord server or creating a new thread on Flet GitHub discussions.