Deploying a Python app with FlaskFlask is a popular micro-framework for building Python web apps. It requires minimal setup and is easy to get started with. Structure provides first-class support for creating and deploying Flask apps.
Here, we'll go over what project files are required to deploy a minimal, but production-ready Flask app on Structure.
app.pyYour application file should be called `app.py`, with your Flask application variable also named `app`. Here's an example:
# File: app.py
from flask import *
app = Flask(__name__)
return 'Hello, world!'
Note: You don't need to include an
That's it for your app.py file!
app.run() statement. Structure will automatically handle that for you when you deploy it.
requirements.txtFor our Flask app to run, we'll need the Flask framework itself! We can define this dependency (and others) in a text file called `requirements.txt`.
You can list all your pip dependencies your app needs to run here, along with its version number. When Structure runs your app, it'll use pip (the Python package manager) to install and load all your dependenices.
# File: requirements.txt
Moving forwardFrom here, you're ready to deploy to production! First, create Flask app on Structure (either through the web interface, or by running
structure create through the CLI). Let's assume your app is named "hello-world". Now, navigate to your project directory and run:
$ structure deploy hello-world
Note: Sometimes, like when you change your `requirements.txt` file, you'll need to reload your app when you deploy. You can run `structure restart --app APP-NAME` to do this.