Fly.io
Fly.io supports WebSockets and provides automatic HTTPS—a good fit for PyView apps.
Prerequisites
- Create a Fly.io account
- Install the Fly CLI:
# macOSbrew install flyctl
# Linuxcurl -L https://fly.io/install.sh | sh- Log in:
fly auth loginInitial Setup
From your project directory:
fly launchThis creates a fly.toml configuration file. When prompted:
- Choose a unique app name (or accept the generated one)
- Select a region close to your users
- Skip database setup unless you need it
Configuration
Here’s a complete fly.toml for a PyView app:
app = "your-app-name"primary_region = "ewr" # Change to your preferred region
[build] # Uses Dockerfile in the current directory
[env] # Non-secret environment variables PORT = "8000"
[http_service] internal_port = 8000 force_https = true auto_stop_machines = false # Keep alive for WebSocket connections auto_start_machines = true min_machines_running = 1
[http_service.concurrency] type = "connections" hard_limit = 100 soft_limit = 50
[[vm]] size = "shared-cpu-1x" memory = "256mb"Key settings:
force_https = true— Redirects HTTP to HTTPS (recommended)auto_stop_machines = false— Keeps machines running for WebSocket connectionsinternal_port = 8000— Matches uvicorn’s default port
Setting Secrets
fly secrets set PYVIEW_SECRET="$(openssl rand -base64 32)"Secrets are encrypted and injected as environment variables. List them with:
fly secrets listDeploying
fly deployFly builds your Docker image remotely and deploys it. Once deployed:
fly openMonitoring
View logs in real-time:
fly logsCheck app status:
fly statusSSH into a running machine for debugging:
fly ssh consoleScaling
Regions
fly regions add lax ord # Los Angeles, ChicagoMachine Size
fly scale vm shared-cpu-2x --memory 512Or update fly.toml:
[[vm]] size = "shared-cpu-2x" memory = "512mb"Multiple Machines
fly scale count 2Fly’s load balancer uses sticky sessions by default, which works well with PyView’s WebSocket connections.
Custom Domain
fly certs add your-domain.comFollow the DNS instructions provided. Fly handles TLS certificates automatically.
Troubleshooting
App won’t start
Check the logs:
fly logsCommon issues:
- Missing
PYVIEW_SECRET— Set it withfly secrets set - Wrong port — Ensure
internal_portmatches your uvicorn port - Build failures — Check Dockerfile syntax
WebSocket not connecting
- Verify HTTPS is working (WebSocket requires secure connection in production)
- Check that
auto_stop_machines = falseif using aggressive auto-stop
Slow cold starts
If your app stops and restarts frequently:
[http_service] auto_stop_machines = false min_machines_running = 1Example: PyView Demo
The PyView examples run on Fly.io. See the fly.toml in the repository for a working configuration.