Fly.io Hosting for Flet Applications
Fly.io offers robust WebSocket support and global data center deployment for Flet web applications. It provides a generous free tier for hosting up to 3 applications.
Prerequisites
flyctl**: Follow instructions at [fly.io/docs/getting-started/installing-flyctl/](https://fly.io/docs/getting-started/installing-flyctl/).flyctl**: Run fly auth login.Project Files
Place the following files in your Python application's root directory:
requirements.txt**: Lists application dependencies. flet
fly.toml**: Describes the Fly application configuration. app = ""
kill_signal = "SIGINT"
kill_timeout = 5
processes = [] [env]
FLET_SESSION_TIMEOUT = "60"
[http_service]
internal_port = 8000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
[http_service.concurrency]
type = "connections"
soft_limit = 200
hard_limit = 250
* Replace with your desired application name. This name also forms the application URL (e.g., https://.fly.dev ).
* FLET_SESSION_TIMEOUT: Sets user session lifetime in seconds (default: 60).
* The Flet web app defaults to port 8000. This can be changed via the FLET_SERVER_PORT environment variable.
* Refer to [Flet Web App Environment Variables](https://docs.flet.dev/publish/web/dynamic-website/#environment-variables) for a complete list.Dockerfile**: Defines the application container build process. FROM python:3-alpine
WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["python", "main.py"]
* main.py is your main Python application file.
* Fly.io uses Docker containers and provides a free remote Docker builder.Deployment Steps
1. **Create Fly App**: Navigate to your app's directory in the terminal and run:
fly apps create --name
2. **Deploy App**: Run the deploy command:
fly deploy
3. **Open App**: Access your deployed application in the browser:
fly apps open
Regions
Fly.io allows deploying apps to data centers close to users. See [Fly.io Regions](https://fly.io/docs/reference/regions/).
Pricing
Fly.io offers attractive pricing with a free tier. See [Fly.io Pricing](https://fly.io/docs/about/pricing/#free-allowances).