Understanding Flet’s client-server architecture and technology stack
Flet is a framework that allows you to build interactive multi-platform applications in Python without frontend experience. This page explains how Flet works under the hood.
Flet maintains a synchronized control tree between Python and Flutter:
import flet as ftdef main(page: ft.Page): # Create control tree in Python page.add( ft.Column([ ft.Text("Title"), ft.Button("Click me"), ]) ) # Flet syncs this to Flutter widgets automatically
Internally, Flet:
Serializes the Python control tree to JSON
Sends updates over WebSocket to Flutter client
Flutter deserializes and builds corresponding widgets
Your app can detect if it’s running in WebAssembly mode:
import flet as ftdef main(page: ft.Page): if page.wasm: page.add(ft.Text("Running in WebAssembly mode")) else: page.add(ft.Text("Running in standard mode"))ft.run(main)
import flet as ftdef main(page: ft.Page): # Each user gets their own page instance page.add(ft.Text(f"Session ID: {page.session_id}")) # Check connection type if page.web: page.add(ft.Text(f"Client IP: {page.client_ip}")) page.add(ft.Text(f"User Agent: {page.client_user_agent}"))ft.run(main)
import flet as ftdef main(page: ft.Page): # Platform detection platform = page.platform if platform == ft.PagePlatform.IOS: page.add(ft.Text("Running on iOS")) elif platform == ft.PagePlatform.ANDROID: page.add(ft.Text("Running on Android")) elif platform == ft.PagePlatform.MACOS: page.add(ft.Text("Running on macOS")) elif platform == ft.PagePlatform.WINDOWS: page.add(ft.Text("Running on Windows")) elif platform == ft.PagePlatform.LINUX: page.add(ft.Text("Running on Linux")) # Other platform checks if page.web: page.add(ft.Text("Running in web browser")) if page.pwa: page.add(ft.Text("Running as PWA"))ft.run(main)
import flet as ftimport timedef main(page: ft.Page): progress = ft.ProgressBar() page.add(progress) def long_running_task(): for i in range(100): progress.value = i / 100 page.update() time.sleep(0.1) # Run in background thread page.run_thread(long_running_task)ft.run(main)