Publish web app as static website
Instructions for publishing a Flet app as a standalone static website (SPA) that runs entirely in the browser with Pyodide. No Python code runs on the server.
Pyodide is a port of CPython to WebAssembly (WASM) and has some limitations.
Native Python packages
Native Python packages (vs "pure" Python packages written in Python only) are packages
partially written in C, Rust, or other languages producing native code.
Example packages are numpy, cryptography, lxml, pydantic-core.
Pyodide comes with a list of built-in packages. To use a package from PyPI, it must be pure Python or provide a wheel built for Emscripten.
Async and threading
Static websites run in a single browser thread. You can use sync and async handlers, but long-running CPU work or blocking calls will freeze the UI. Prefer async I/O, or move heavy work to a server and call it via a web API.
Micropip
Pyodide installs packages with micropip. You can use the Micropip API directly in your Flet app:
There are two ways to publish a static website:
flet build web- recommended; uses Flutter and packages dependencies into the output.flet publish- no Flutter required; installs dependencies at runtime with micropip.
flet publish#
flet publish is alternative to
flet build web that does not require Flutter. It packages
your app and installs dependencies in the browser at runtime via micropip.
Initial load time is usually higher than flet build web.
To publish an app, run:
The website is published to --distpath (default: ./dist).
Testing the site#
You can try published Flet app using flet serve command:
Then, open http://localhost:8000 in your browser to check the published app.
Assets#
If the assets directory exists (default: ./assets), its contents are copied
to the published site root. Use --assets to point to a different
folder. Assets are not packaged inside the app.tar.gz.
flet build web#
Publish a static website using Flutter and Pyodide.
Note
Complementary and more general information is available here.
Testing the site#
flet serve serves the default
output directory (./build/web):
Configuration options#
These settings apply to flet build web and flet publish, unless noted.
Base URL#
Use a base URL when hosting your app in a subdirectory. Flet normalizes it to
/<value>/ and uses / when unset.
Resolution order#
Its value is determined in the following order of precedence:
--base-url[tool.flet.web].base_url"/"
Example#
Route URL strategy#
Controls how routes are represented in the URL:
path- clean paths; requires SPA-capable hosting.hash- uses the URL hash; works on static hosts without SPA support.
Resolution order#
Its value is determined in the following order of precedence:
--route-url-strategy[tool.flet.web].route_url_strategy"path"
Example#
Web renderer#
Selects the Flutter web renderer:
auto(default) - let Flutter choose the best renderercanvaskitskwasm
Resolution order#
Its value is determined in the following order of precedence:
--web-renderer[tool.flet.web].renderer"auto"
Example#
CDN assets#
By default, Pyodide, CanvasKit, and fonts are loaded from CDNs to keep the output small. Disable CDN loading for offline or air-gapped deployments.
Resolution order#
CDN loading is disabled in the following order of precedence:
--no-cdn[tool.flet.web].cdn = false- default: CDN enabled
Example#
PWA colors#
Configure PWA colors used in manifest.json and browser UI.
Resolution order#
For each setting:
--pwa-background-color/--pwa-theme-color[tool.flet.web].pwa_background_color/[tool.flet.web].pwa_theme_color#FFFFFF/#0175C2
Example#
WASM output#
By default, flet build web enables Flutter's WASM output.
Note
flet build web only.
Resolution order#
The WASM output is disabled in the following order of precedence:
--no-wasm[tool.flet.web].wasm = false- default: WASM enabled