flet run command runs your Flet application with hot reload enabled, automatically restarting when you modify your code. This is the primary command used during development.
Basic Usage
main.py in the current directory.
Examples
Run Default Script
main.py in the current directory.
Run Specific Script
Run as Web App
Run as Module
Watch Directory Recursively
Run on Mobile Device
Arguments
Path to the Python script that starts your Flet app. If a directory is provided, Flet looks for
main.py inside it.Options
Port and Host
Custom TCP or HTTP port to run the app on. If not specified, a random port is chosen.
The host to run Flet web app on. Use This makes your app accessible from other devices on your network.
"*" to listen on all network interfaces.A unique name for your app. Useful when running multiple apps on the same port.
Module Mode
Treat the script as a Python module path instead of a file path.This is equivalent to
python -m my_app.main.Hot Reload
Watch the directory of the script for changes and hot reload the app accordingly.By default, only the main script file is watched.
Watch script directory and all its subdirectories recursively for file changes.Use this when your app has multiple files in nested directories.
Comma-separated list of directory names to ignore when watching for file changes.This prevents unnecessary reloads when files in these directories change.
Display Modes
Launch the Flet app as a dynamic website and automatically open it in your web browser.The app runs as a web server instead of a desktop window.
Start the application with the window hidden.Useful for system tray applications or background processes.
Mobile Platforms
Launch the app for testing on an Android device.Displays a QR code to scan with the Flet Android app.
Launch the app for testing on an iOS device.Displays a QR code to scan with the Flet iOS app.
Assets
Path to a directory containing static assets used by the app (e.g., images, fonts).The assets directory is served alongside your app.
Terminal Output
When you runflet run, you’ll see output like this:
Desktop Mode
Web Mode
Mobile Mode (Android)
Hot Reload Behavior
When Flet detects file changes:- The app process is automatically terminated
- A new process is started with the updated code
- The app state is reset (no state persistence between reloads)
What Triggers Reload
- Without
-dflag: Only changes to the main script file - With
-dflag: Changes to any file in the script’s directory - With
-rflag: Changes to any file in the script’s directory and subdirectories
Ignored Files
These file types do NOT trigger reload:- Temporary files (
.swp,.tmp) - Version control directories (
.git,.svn) - Python cache (
__pycache__,*.pyc) - Directories specified in
--ignore-dirs
pyproject.toml Configuration
You can configure default paths inpyproject.toml:
src/main.py instead of ./main.py.
Environment Variables
Theflet run command sets these environment variables for your app:
FLET_SERVER_PORT- The port the Flet server is running onFLET_SERVER_IP- The host IP address (if--hostis specified)FLET_SERVER_UDS_PATH- Unix domain socket path (Unix/Linux only)FLET_WEB_APP_PATH- App name/path (if--nameis specified)FLET_ASSETS_DIR- Assets directory pathFLET_FORCE_WEB_SERVER- Set to"true"in web/mobile modesFLET_APP_STORAGE_DATA- Path to app’s persistent storageFLET_APP_STORAGE_TEMP- Path to app’s temporary storage
Common Workflows
Development with Hot Reload
Testing on Mobile
- Run the command
- Scan the QR code with your Android device’s camera
- Open the link in the Flet Android app
- Make changes to your code - the app reloads automatically
Multi-Device Testing
http://YOUR_IP:8080.
Package Development
Troubleshooting
Port Already in Use
If you see an error about the port being in use:Hot Reload Not Working
Ensure you’re using the-d or -r flags:
Assets Not Loading
Verify the assets directory exists and specify it explicitly:Module Not Found
When using-m, ensure the package is installed or in your PYTHONPATH:
Performance Considerations
File Watching
Watching large directory trees with-r can be slow. Use --ignore-dirs to exclude:
Web Server Mode
Web mode (--web) is slightly slower to start than desktop mode due to browser launch time.
Next Steps
Build Command
Build production executables
Assets Guide
Learn about managing assets
Publish Command
Deploy as a web app
Hot Reload
Deep dive into hot reload