How to host Flask applications
1. Prerequisites
- Square Cloud Account: Create your account via the Registration Page (Email or GitHub).
- Active Plan: A paid plan is required for hosting. Check the pricing here.
2. Production Configuration (Gunicorn)
Although Flask has a built-in server (app.run()), it is not suitable for production. Gunicorn allows your application to handle multiple concurrent requests efficiently.
For Square Cloud to route traffic correctly, Gunicorn must be configured to listen on the 0.0.0.0 interface and port 80.
Application Example (app.py)
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Flask running in production on Square Cloud!'
if __name__ == '__main__':
# app.run is only used locally
app.run(host='0.0.0.0', port=80)
3. Performing the Deployment
- Compression: Create a
.zipfile with your source code and therequirements.txt. Do not include cache folders like__pycache__or virtual environments (venv). Therequirements.txtmust be at the project root and contain at least:
flask
gunicorn
- Upload: In the Square Cloud Dashboard, click on upload new application.
- Web Publishing: In the submission menu, check the "Publish to Web" option.
- Subdomain: Choose a name for your free subdomain (e.g.,
my-api.squareweb.app). - Custom Start Command: To use Gunicorn, you must define a custom start command at the time of submission (or in the
squarecloud.appconfiguration file). Use the following format:
python -m gunicorn --bind 0.0.0.0:80 app:app
--bind 0.0.0.0:80: Exposes the application on the port required by the platform.app:app: Indicates that Gunicorn should look for theappobject (the second "app") inside theapp.pyfile (the first "app").
4. Custom Domains (Standard+ Plan)
Users on the Standard plan or higher can configure their own domains:
- Add your domain (e.g.,
api.yoursite.com) in the Network tab. - Square Cloud automatically manages SSL/HTTPS, ensuring your communication is encrypted at no additional cost.
5. Optimization Tips
- Workers: If your application receives a lot of traffic, you can adjust the number of workers in the start command (e.g.,
--workers 3). - Environment Variables: Use the ENV tab in the Dashboard to store
SECRET_KEY, API keys, and database URLs. - Logs: Monitor the Dashboard terminal to identify initialization errors or Python exceptions in real-time.
Updated on: 05/26/2026
Thank you!
