Speedrun
First, install flyctl, the Fly.io CLI, and sign up to Fly.io if you haven’t already. The fastest way to get a basic Flask server on Fly.io is to use our Flask template:Deploy a Flask app from scratch
For managing our project, we use Poetry. For more information on the initial setup with poetry, refer to setting up a python environment. We can initialize a new project like so:If you’re using Poetry 2.0+ (the default when installed via
pipx), the poetry shell command is no longer built in. Use poetry run to run commands (e.g., poetry run python main.py), or activate the environment with poetry env activate. See the initial setup guide for more details.- flask: the framework
- gunicorn: the server
app.py:
flask run command works since our file is named app.py. It also works if your file is named wsgi.py, so you don’t have to use --app to tell Flask where your app is. More details here.
If your file is saved as hello.py instead of app.py, you would need to use the --app option to point to Flask where your app is:
hello from fly.io.
And with that you can deploy the app!
fly.toml file with the configuration for your app and a Dockerfile that uses multi-stage builds.
Refer to the fly.toml docs for more configuration options.
To deploy a new version of your app, simply run fly deploy in the project directory.
You can check out the full (yet minimal) example in this GitHub repository for a reference.