> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fly.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Run a Flask App

Getting an application running on Fly.io is essentially working out how to package it as a deployable image. Once packaged, it can be deployed to the Fly.io platform.

In this guide we’ll learn how to deploy a [Flask](https://flask.palletsprojects.com/) application on Fly.io.

Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.

Spinning up a flask app is fun!

## *Speedrun*

First, [install flyctl](/flyctl/install), the Fly.io CLI, and [sign up to Fly.io](/getting-started/sign-up-sign-in#first-time-or-no-fly-account-sign-up-for-fly) if you haven't already.

The fastest way to get a basic Flask server on Fly.io is to use our Flask template:

```sh theme={null}
git clone git@github.com:fly-apps/hello-flask-poetry.git flask-app
cd flask-app
fly launch --generate-name
```

## *Deploy a Flask app from scratch*

For managing our project, we use [Poetry](https://python-poetry.org/).
For more information on the initial setup with poetry, refer to [setting up a python environment](/python/the-basics/initial-setup).

We can initialize a new project like so:

```bash theme={null}
poetry new flask-app
cd flask-app
```

<Info>
  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](/python/the-basics/initial-setup) for more details.
</Info>

To run this app we will need 2 dependencies:

* flask: the framework
* gunicorn: the server

```bash theme={null}
poetry add flask gunicorn
```

Now let's create a basic app in `app.py`:

```python theme={null}
from flask import Flask

app = Flask(__name__)

@app.route("/")
def hello_fly():
    return "hello from fly.io"
```

To check that everything is working, we can use the included flask cli tool:

<CodeGroup>
  ```bash cmd theme={null}
  flask run
  ```

  ```out out theme={null}
   * Debug mode: off
  WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
   * Running on http://127.0.0.1:5000
  Press CTRL+C to quit
  ```
</CodeGroup>

Note that `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`](https://flask.palletsprojects.com/en/latest/cli/) to tell Flask where your app is. More details [here](https://flask.palletsprojects.com/en/latest/quickstart/#a-minimal-application).

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:

```bash theme={null}
flask --app hello run
```

If you open [http://127.0.0.1:5000/](http://127.0.0.1:5000/) in your web browser, it should display `hello from fly.io`.

And with that you can deploy the app!

<CodeGroup>
  ```bash cmd theme={null}
  fly launch
  ```

  ```output output theme={null}
  Scanning source code
  Detected a Flask app
  Warning: This organization has no payment method, turning off high availability
  Creating app in [redacted]/[app-name]
  We're about to launch your app on Fly.io. Here's what you're getting:

  Organization: Your Name              (fly launch defaults to the personal org)
  Name:         [app-name]             (derived from your directory name)
  Region:       Amsterdam, Netherlands (this is the fastest region for you)
  App Machines: shared-cpu-1x, 1GB RAM (most apps need about 1GB of RAM)
  Postgres:     <none>                 (not requested)
  Redis:        <none>                 (not requested)
  Sentry:       false                  (not requested)

  ...

  ==> Building image
  ...
  ==> Building image with Docker
  ...

  Watch your deployment at https://fly.io/apps/[app-name]/monitoring
  ...

  Visit your newly deployed app at https://[app-name].fly.dev/

  ```
</CodeGroup>

This will generate a `fly.toml` file with the configuration for your app and a Dockerfile that uses [multi-stage builds](/python/the-basics/multi-stage-builds).
Refer to the [fly.toml docs](/reference/configuration) 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](https://github.com/fly-apps/) for a reference.
