Web Application Modes
Server-Side Web Apps
Server-side apps run Python on a web server, with real-time communication to the browser via WebSockets. This mode supports:- Full Python standard library
- Database connections and server-side processing
- Multiple concurrent users
- Real-time updates
- File uploads and downloads
WebAssembly (Static) Web Apps
WebAssembly apps run Python entirely in the browser using Pyodide. This mode supports:- Static hosting (CDN, GitHub Pages, etc.)
- Offline functionality
- No server costs
- Direct file system access (in browser)
WebAssembly apps have limitations: slower startup, limited package support (pure Python only), and no server-side capabilities.
Building WebAssembly Apps
Theflet build web command creates a static web application that can be hosted on any web server or CDN.
Basic Build
build/web/ directory containing static files
Configuration
Configure your web app inpyproject.toml:
pyproject.toml
Build Options
Base URL
When hosting in a subdirectory:https://example.com/my-app/
Web Renderer
Choose the Flutter web renderer:auto(default) - Automatically selects best renderercanvaskit- Better quality, larger bundleskwasm- Experimental WebAssembly renderer
Route URL Strategy
Controls how routes appear in the browser URL:path(default) - Clean URLs:example.com/page1hash- Hash-based URLs:example.com/#/page1
hash strategy for hosting on servers that don’t support URL rewriting.
CDN Mode
By default, Flet loads CanvasKit, Pyodide, and fonts from CDN for faster loading:--no-cdn for:
- Offline applications
- Air-gapped environments
- Complete control over resources
WASM Build
Disable WebAssembly to build server-side web app template only:Progressive Web App (PWA) Configuration
Make your web app installable:pyproject.toml:
pyproject.toml
Custom App Metadata
Publishing Static Web Apps
Theflet publish command creates a static web app optimized for distribution:
dist/ directory with deployable static files
Publish Options
Including Dependencies
Flet automatically detects dependencies from:- pyproject.toml (recommended):
pyproject.toml
- requirements.txt:
requirements.txt
Only pure Python packages are supported in WebAssembly apps. Packages with C extensions won’t work unless they’re compiled for Pyodide.
Pre-release Packages
To install pre-release packages:Serving Web Apps Locally
After building, test your web app locally:build/web/ on http://localhost:8000
Serve Options
- First argument: directory to serve (default:
./build/web) --port,-p: Port number (default:8000)
flet serve includes the necessary CORS headers for WebAssembly to work properly.Running Server-Side Web Apps
For development with hot reload:Server-Side Options
--port,-p: TCP port (default: random)--host: Host interface (*for all IPs)--name: App path for multi-app hosting--assets,-a: Assets directory
Multi-User Server-Side Apps
Flet automatically handles multiple concurrent users:main.py
page instance.
Deployment Examples
GitHub Pages
Netlify / Vercel
- Build your app:
- Create
netlify.tomlorvercel.json:
netlify.toml
vercel.json
- Deploy:
Docker (Server-Side)
Create aDockerfile for server-side apps:
Dockerfile
main.py
Environment Variables
Control web app behavior with environment variables:FLET_WEB_RENDERER- Web renderer (auto,canvaskit,skwasm)FLET_WEB_ROUTE_URL_STRATEGY- Routing strategy (path,hash)FLET_WEB_NO_CDN- Disable CDN (true/false)
WebAssembly Limitations
- Packages: Only pure Python packages work. No C extensions (unless compiled for Pyodide)
- Startup Time: Initial load is slower (~5-10 seconds) due to Pyodide initialization
- Memory: Limited by browser memory
- File System: Virtual file system in browser, not persistent
- Networking: CORS restrictions apply
Choosing the Right Mode
| Feature | Server-Side | WebAssembly |
|---|---|---|
| Hosting | Requires Python server | Static hosting |
| Cost | Server costs | Free (CDN/static) |
| Offline | No | Yes |
| Startup | Fast | Slow (initial) |
| Packages | All Python packages | Pure Python only |
| Database | Yes | No (browser only) |
| File System | Real file system | Virtual (browser) |
| Multi-User | Built-in | Single user |
| Best For | Enterprise apps, dashboards | Calculators, tools, demos |
Next Steps
- Learn about Deployment strategies
- Explore Desktop Apps for offline-first applications
- Read about Mobile Apps for native mobile experiences