Articles on: Websites & APIs

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


  1. Compression: Create a .zip file with your source code and the requirements.txt. Do not include cache folders like __pycache__ or virtual environments (venv). The requirements.txt must be at the project root and contain at least:
flask
gunicorn
  1. Upload: In the Square Cloud Dashboard, click on upload new application.
  2. Web Publishing: In the submission menu, check the "Publish to Web" option.
  3. Subdomain: Choose a name for your free subdomain (e.g., my-api.squareweb.app).
  4. Custom Start Command: To use Gunicorn, you must define a custom start command at the time of submission (or in the squarecloud.app configuration 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 the app object (the second "app") inside the app.py file (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

Was this article helpful?

Share your feedback

Cancel

Thank you!