flet publish command compiles and packages your Flet app as a standalone static web application that can be deployed to any static hosting service (GitHub Pages, Netlify, Vercel, etc.).
Basic Usage
How It Works
flet publish creates a static web application by:
- Packaging your Python app and dependencies into a
.tar.gzarchive - Copying the Flet web runtime (Flutter web + Pyodide)
- Configuring the app to run entirely in the browser using WebAssembly
- Generating PWA (Progressive Web App) manifests
- Outputting everything to the
dist/directory
Examples
Publish Current Directory
main.py from the current directory to dist/.
Publish Specific Script
Publish with Custom Output
Publish for GitHub Pages
Publish with Custom PWA Metadata
Publish for Offline Use
Arguments
Path to the Python script that starts your Flet app.If a directory is provided, looks for
main.py inside it.Options
Output
Directory where the published web app should be placed.The directory is cleaned before publishing.
App Metadata
Full name of the application. Used in PWA metadata and may appear in the install prompt.Falls back to
tool.flet.product or project.name in pyproject.toml.A shorter version of the application name, often used in homescreen icons or install prompts.Falls back to
project.name in pyproject.toml.Short description of the application. Used in PWA manifests and metadata.Falls back to
project.description in pyproject.toml.PWA Configuration
Initial background color of your web app during the loading phase (used in splash screens).Falls back to
tool.flet.web.pwa_background_color in pyproject.toml.Default color of the browser UI (e.g., address bar) when your app is installed as a PWA.Falls back to
tool.flet.web.pwa_theme_color in pyproject.toml.Web Renderer
Flutter web renderer to use.Options:Can also be set via
auto- Automatically choose based on devicecanvaskit- WebAssembly-based renderer (best compatibility)skwasm- Experimental WASM renderer (better performance)
FLET_WEB_RENDERER environment variable or tool.flet.web.renderer in pyproject.toml.URL Configuration
Base URL path to serve the app from. Useful if the app is hosted in a subdirectory.Important: Must start and end with
/.Falls back to tool.flet.web.base_url in pyproject.toml.Examples:- Root:
/(default) - Subdirectory:
/my-app/ - GitHub Pages:
/repository-name/
Controls how routes are handled in the browser.Options:Use
path- Uses HTML5 history API (/about)hash- Uses URL fragments (/#/about)
hash when:- Deploying to static hosts without server-side routing
- GitHub Pages, Netlify, etc. (unless configured for SPA)
path when:- Server can handle SPA routing (returns
index.htmlfor all routes) - Cleaner URLs are preferred
FLET_WEB_ROUTE_URL_STRATEGY environment variable or tool.flet.web.route_url_strategy in pyproject.toml.Assets
Path to a directory containing static assets used by the app (e.g., images, fonts, icons).Can also be set via
FLET_ASSETS_DIR environment variable.Assets are copied to the dist directory and available at runtime.Dependencies
Allow micropip to install pre-release Python packages.Use this if your app depends on a prerelease version of a package.
CDN Options
Disable loading of CanvasKit, Pyodide, and fonts from CDNs.Use this for:
- Full offline deployments
- Air-gapped environments
- Corporate intranets
- Avoiding external dependencies
tool.flet.web.cdn = false in pyproject.toml.Published Output
Thedist/ directory contains:
Dependency Resolution
The publish command determines Python dependencies from:-
pyproject.toml (preferred):
Or Poetry format:
-
requirements.txt:
-
Default: If neither exists, only
fletis included.
Deployment Examples
Deploy to GitHub Pages
Deploy to Netlify
- Run
flet publish - Go to Netlify Drop
- Drag the
distfolder
Deploy to Vercel
Deploy to Firebase Hosting
Deploy to AWS S3
Self-Hosted Server
dist/ to your web server:
Configuration File
Configure publish settings inpyproject.toml:
pyproject.toml settings.
Testing Published App
After publishing, test locally:flet serve for proper testing.
PWA Features
Published apps are Progressive Web Apps (PWA) and can be:- Installed on desktop and mobile devices
- Run offline (after initial load)
- Added to home screen on mobile
- Run in standalone mode (without browser UI)
Install Prompt
Users can install your app:- Visit the published URL
- Browser shows “Install” or “Add to Home Screen” prompt
- App runs as standalone application
Offline Support
Service worker enables offline functionality:- App shell cached on first visit
- Works without internet after initial load
- Python code runs entirely in browser
Package Exclusions
These files/directories are automatically excluded fromapp.tar.gz:
- Hidden files/directories (
.git,.env, etc.) __pycache__requirements.txt(replaced with generated one)- Assets directory (copied separately)
- Dist directory (to avoid recursion)
Performance Optimization
Reduce Bundle Size
-
Use CDN (default):
-
Minimize dependencies:
Only include required packages in
pyproject.toml. -
Optimize assets:
- Compress images
- Use web-friendly formats (WebP, AVIF)
- Remove unused fonts
Improve Load Time
-
Use
canvaskitrenderer: - Enable CDN: Faster than bundling dependencies.
- Compress assets: Configure server gzip/brotli compression.
Troubleshooting
App Doesn’t Load
Check browser console for errors. Common issues:- Incorrect
--base-url - CORS headers missing (use
flet servefor testing) - Missing dependencies
Dependencies Not Installing
Ensure packages are Pyodide-compatible: Not all Python packages work in browser. Check Pyodide package list.Routing Not Working
Use hash strategy for static hosts:Large Bundle Size
Avoid--no-cdn unless necessary:
Assets Not Loading
Verify assets path:Comparison with flet build web
Both commands create web apps, but with different approaches:| Feature | flet publish | flet build web |
|---|---|---|
| Runtime | Python in browser (Pyodide) | Compiled Dart |
| Bundle size | Larger (~50 MB with CDN) | Smaller (~5-10 MB) |
| Deployment | Static hosting | Static hosting |
| Load time | Slower (loads Python) | Faster |
| Python features | Full Python support | Limited |
| Offline | After first load | After first load |
| Best for | Full Python apps, rapid development | Production, performance-critical |
flet build web for production deployments when possible. Use flet publish for rapid prototyping or when full Python compatibility is required.
Next Steps
Serve Command
Test published apps locally
Build Web
Build optimized web apps
Deployment Guide
Deploy to various platforms
PWA Guide
Progressive Web App features