{"id":20698169,"url":"https://github.com/fly-apps/python-hellofly-flask","last_synced_at":"2025-06-22T23:07:15.497Z","repository":{"id":44332783,"uuid":"329355205","full_name":"fly-apps/python-hellofly-flask","owner":"fly-apps","description":"A Pythonic version of the Hellofly example ","archived":false,"fork":false,"pushed_at":"2023-02-12T20:56:11.000Z","size":19,"stargazers_count":30,"open_issues_count":1,"forks_count":26,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-22T21:51:58.488Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fly-apps.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-13T15:45:29.000Z","updated_at":"2024-11-15T02:17:43.000Z","dependencies_parsed_at":"2024-11-17T00:36:13.758Z","dependency_job_id":null,"html_url":"https://github.com/fly-apps/python-hellofly-flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/fly-apps/python-hellofly-flask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpython-hellofly-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpython-hellofly-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpython-hellofly-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpython-hellofly-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fly-apps","download_url":"https://codeload.github.com/fly-apps/python-hellofly-flask/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fly-apps%2Fpython-hellofly-flask/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261380906,"owners_count":23149966,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T00:23:19.325Z","updated_at":"2025-06-22T23:07:10.476Z","avatar_url":"https://github.com/fly-apps.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python-hellofly-flask\n\nIn our Hands-On section, we show how to deploy a deployable image file using Flyctl. Now we are going to deploy an application from source. In this _Getting Started_ article, we look at how to deploy a Python application on Fly. \n\n## _The Hellofly-python Application_\n\nYou can get the code for the example from [the Fly-Examples Github repository](https://github.com/fly-examples/python-hellofly-flask). Just `git clone https://github.com/fly-examples/python-hellofly-flask` to get a local copy.\n\nThe Python hellofly application is, as you'd expect for an example, small. It's a Python application that uses the [Flask](https://flask.palletsprojects.com/) web framework. Here's all the code form `hellofly.py`:\n\n```python\nfrom flask import Flask, render_template\n\napp = Flask(__name__)\n\n@app.route('/')\n@app.route('/\u003cname\u003e')\ndef hello(name=None):\n    return render_template('hello.html', name=name)\n```\n\nFlask is set up to route request to a `hello` function which in turn passes a `name` value  (taken from the requests path)to a function to render a template. The template resides in the `templates` directory under the name `hello.html`. It too is very simple too:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003ch1\u003eHello from Fly\u003c/h1\u003e\n{% if name %}\n\u003ch2\u003eand hello to {{name}}\u003c/h2\u003e\n{% endif %}\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nWe're using a template as it makes it easier to show what you should do with assets that aren't the actual application.\n\nYou will need to install Flask itself, or at least set up virtual environments as recommended in the [Flask Install](https://flask.palletsprojects.com/en/1.1.x/installation/#virtual-environments) guide.\n\nOnce you have activated the virtual environment, run:\n\n```\npython -m pip install -r requirements.txt\n```\n\nWhich will load Flask and other required packages. One of those packages will be `gunicorn` which isn't a Flask dependency, but will be used when we deploy the app to Fly.\n\n## _Testing the Application_\n\nFlask apps are run with the `flask run` command, but before you do that, you need to set an environment variable `FLASK_APP` to say which app you want to run.\n\n```cmd\nFLASK_APP=hellofly flask run\n```\n```out\n * Serving Flask app \"hellofly\"\n * Environment: production\n   WARNING: This is a development server. Do not use it in a production deployment.\n   Use a production WSGI server instead.\n * Debug mode: off\n * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)\n ```\n\nThis will run our hellofly app and you should be able to connect to it locally on localhost:5000.\n\nNow, let's move on to deploying this app to Fly.\n\n## _Install Flyctl and Login_\n\nWe are ready to start working with Fly and that means we need `flyctl`, our CLI app for managing apps on Fly. If you've already installed it, carry on. If not, hop over to [our installation guide](/docs/getting-started/installing-flyctl/). Once that is installed you'll want to [login to Fly](/docs/getting-started/login-to-fly/).\n\n## _Configure the App for Fly_\n\nEach Fly application needs a `fly.toml` file to tell the system how we'd like to deploy it. That file can be automatically generated with the command `flyctl launch` command. We are going to use one of Fly's builtin deployment configurations for Python.\n\n```cmd\nflyctl launch\n```\n```output\nCreating app in /\u003cpath\u003e/python-hellofly-flask\nScanning source code\nDetected a Python app\nUsing the following build configuration:\n        Builder: paketobuildpacks/builder:base\nSelected App Name: \n? Select region: lhr (London, United Kingdom)\nCreated app hellofly-flask in organization personal\nWrote config file fly.toml\nWe have generated a simple Procfile for you. Modify it to fit your needs and run \"fly deploy\" to deploy your application.\n```\n\nYou'll be asked for an application name first. We recommend that you go with the autogenerated names for apps to avoid namespace collisions. We're using `hellofly-python` here so you can easily spot it in configuration files.\n\nNext you'll be prompted for an organization. Organizations allow sharing applications between Fly users. When you are asked to select an organization, there should be one with your account name; this is your personal organization. Select that.\n\nNow `flyctl launch` will generate a sample `Procfile` and `fly.toml`, which together will define how fly deploys and launches the application.\n\nUpdate the `Procfile` to look like this:\n\n```Procfile\nweb: gunicorn hellofly:app\n```\n\nThis says the web component of the application is served by `gunicorn` (which we mentioned earlier when talking about dependencies) and that it should run the `hellofly` Flask app.\n\n## _Inside `fly.toml`_\n\nThe `fly.toml` file now contains a default configuration for deploying your app. In the process of creating that file, `flyctl` has also created a Fly-side application slot of the same name, `hellofly-python`. If we look at the `fly.toml` file we can see the name in there:\n\n```toml\n# fly.toml file generated for hellofly-python on 2021-11-30T17:37:33+02:00\n\napp = \"hellofly-python\"\n\nkill_signal = \"SIGINT\"\nkill_timeout = 5\nprocesses = []\n\n[build]\n  builder = \"paketobuildpacks/builder:base\"\n\n[env]\n  PORT = \"8080\"\n\n[experimental]\n  allowed_public_ports = []\n  auto_rollback = true\n\n[[services]]\n  http_checks = []\n  internal_port = 8080\n  processes = [\"app\"]\n  protocol = \"tcp\"\n  script_checks = []\n\n  [services.concurrency]\n    hard_limit = 25\n    soft_limit = 20\n    type = \"connections\"\n\n  [[services.ports]]\n    handlers = [\"http\"]\n    port = 80\n\n  [[services.ports]]\n    handlers = [\"tls\", \"http\"]\n    port = 443\n\n  [[services.tcp_checks]]\n    grace_period = \"1s\"\n    interval = \"15s\"\n    restart_limit = 0\n    timeout = \"2s\"\n```\n\nThe `flyctl` command will always refer to this file in the current directory if it exists, specifically for the `app` name/value at the start. That name will be used to identify the application to the Fly service. The rest of the file contains settings to be applied to the application when it deploys. \n\nWe'll have more details about these properties as we progress, but for now, it's enough to say that they mostly configure which ports the application will be visible on.\n\n## _Deploying to Fly_\n\nWe are now ready to deploy our app to the Fly platform. At the command line, just run:\n\n```cmd\nflyctl deploy\n```\n\nThis will lookup our `fly.toml` file, and get the app name `hellofly-python` from there. Then `flyctl` will start the process of deploying our application to the Fly platform. Flyctl will return you to the command line when it's done.\n\n## _Viewing the Deployed App_\n\nNow the application has been deployed, let's find out more about its deployment. The command `flyctl status` will give you all the essential details.\n\n```cmd\nflyctl status\n```\n```output\nApp\n  Name     = hellofly-python\n  Owner    = demo\n  Version  = 0\n  Status   = running\n  Hostname = hellofly-python.fly.dev\n\nDeployment Status\n  ID          = 0cdc72fe-3db9-aa52-eb84-5c3552053b1e\n  Version     = v0\n  Status      = successful\n  Description = Deployment completed successfully\n  Instances   = 1 desired, 1 placed, 1 healthy, 0 unhealthy\n\nInstances\nID       VERSION REGION DESIRED STATUS  HEALTH CHECKS      RESTARTS CREATED\n0530d622 0       lhr    run     running 1 total, 1 passing 0        40s ago\n```\n\nAs you can see, the application has been with a DNS hostname of `hellofly-python.fly.dev`, and an instance is running in London. Your deployment's name will, of course, be different. \n\n## _Connecting to the App_\n\nThe quickest way to connect to your deployed app is with the `flyctl open` command. This will open a browser on the HTTP version of the site. That will automatically be upgraded to an HTTPS secured connection (for the fly.dev domain). \n\n\n to connect to it securely. Add `/name` to `flyctl open` and it'll be appended to the URL as the path and you'll get an extra greeting from the hellofly-python application.\n\n\n## _Bonus Points_\n\nIf you want to know what IP addresses the app is using, try `flyctl ips list`:\n\n```cmd\nfly ips list\n```\n```out\nTYPE ADDRESS                             CREATED AT\nv4   213.188.195.22                      2m1s ago\nv6   2a09:8280:1:502e:4ce8:6058:7f09:62a 1m58s ago\n```\n\nAnd you can always run `flyctl` as `fly` if you want to save a few keystrokes.\n\n## _Arrived at Destination_\n\nYou have successfully built, deployed, and connected to your first Python application on Fly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fpython-hellofly-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffly-apps%2Fpython-hellofly-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffly-apps%2Fpython-hellofly-flask/lists"}