Publish Flet App as Static Website
Flet apps can be published as standalone static websites (SPAs) running in the browser via Pyodide. This requires no server-side code.
Pyodide and Package Support
Async and Threading
time.sleep) can freeze the UI.asyncio.sleep in async methods is acceptable.Publishing Methods
1. flet build web
flet build web./build/webflet serve (opens http://localhost:8000).--web-renderer {canvaskit,html}: Sets the web renderer. Default is canvaskit.
* --use-color-emoji: Enables color emojis (increases app size).
* --base-url : Publishes the app to a sub-directory (e.g., myapp for https://domain.com/myapp).
* --route-url-strategy {path,hash}: Sets URL routing strategy. path (default) for SPA-friendly hosting, hash for providers like GitHub Pages.
assets directory are copied to the website root, allowing overrides (e.g., favicon.png, manifest.json).2. flet publish
flet publish ./distflet serve dist (opens http://localhost:8000).flet build web as dependencies are pulled at runtime via micropip.requirements.txt in the same directory as the app script.
* micropip is used in the browser to install packages.
* Direct micropip installation is possible within the app: await micropip.install("package_name") (only if sys.platform == "emscripten").
--pre: Allows installation of pre-release Python packages.
* -a ASSETS_DIR, --assets ASSETS_DIR: Path to an assets directory to be copied to the output.
* --app-name APP_NAME: Sets the application name.
* --app-description APP_DESCRIPTION: Sets the application description.
* --base-url BASE_URL: Same as in flet build web.
* --web-renderer {canvaskit,html}: Same as in flet build web.
* --route-url-strategy {path,hash}: Same as in flet build web.
--assets to copy assets. If assets directory exists and --assets is not specified, its contents are packaged with the Python app, not copied to dist.General Options and Configurations
canvaskit. Can be switched to html using --web-renderer html.canvaskit renderer omits color emojis to save size. Enable with --use-color-emoji. html renderer uses browser fonts and supports color emojis.path (default): Suitable for SPA-rendering hosts (e.g., Cloudflare Pages).
* hash: Use for hosts that don't support SPA rendering (e.g., GitHub Pages).
--base-url for apps hosted at https://domain.com/.pyproject.toml: Set [tool.flet.splash] android = false (Note: This specific example is for Android, but indicates configuration method).Assets
assets directory are copied to the website root.favicon.png or manifest.json.--assets with flet publish to specify an assets directory.assets directory exists and --assets is not used with flet publish, its contents are packaged internally, not copied to dist.
Previous
arrow_back
Self hosting