Professional Flask Project Development

To deploy robust web applications using Flask on Square Cloud, it’s essential to follow development best practices and production environment configuration.

Essential Technical Prerequisites

  • Python and pip: Make sure Python and pip are installed on your system. If you don’t have them, download from the official Python website and Pip.
  • Square Cloud account: Create your account via the signup page using your email address.
  • Active paid plan: A paid plan is required to ensure adequate resources for Flask applications. Check our available plans and choose the one that fits your needs.

Flask Environment Setup

With Python and pip installed, create your Flask project. First, install the required dependencies:
Terminal
pip install flask
pip install waitress
Next, create a Python file (for example, app.py) and add the following code to implement a basic Flask application:
app.py
# Import the Flask class from the flask module
from flask import Flask

# Create an instance of the Flask class
app = Flask(__name__)

# Define a route for the root URL (/) that returns 'Hello, World!'
@app.route('/')
def hello_world():
  return 'Hello, World!'

# Check if this script is being run directly (not imported as a module)
if __name__ == '__main__':
  # Run the Flask application on host 0.0.0.0 (all available network interfaces) and port 80
  app.run(host='0.0.0.0', port=80)

Production Environment Setup with Waitress

For professional production deployment, it is recommended to use the Waitress WSGI server, which provides improved stability and performance for Flask applications.
app.py
from flask import Flask

# Create an instance of the Flask application
app = Flask(__name__)

# Define a route for the root URL (/) that returns 'Hello, World!'
@app.route('/')
def hello_world():
  return 'Hello, World!'

# If this script is run directly (not imported as a module)
if __name__ == '__main__':
  from waitress import serve  # Import the serve function from Waitress
    
  # Serve the Flask application using Waitress on host 0.0.0.0 (all interfaces) and port 80
  serve(app, host='0.0.0.0', port=80)
    
  # Print a message indicating the server started successfully on port 80
  print("Server started successfully on port 80.")
In the code above, we implement a simple route that returns “Hello, World!” when accessed. The application is configured to run on port 80, which is the default HTTP port for production environments.

Dependency Management with requirements.txt

The requirements.txt file is an essential component that lists all external libraries required for your project. Make sure to include all used dependencies, excluding Python’s built-in modules such as random and datetime. This file must be included when submitting your application to Square Cloud.
requirements.txt
flask
waitress

Square Cloud Configuration File

Learn about: how to create the configuration file for Square Cloud.

The squarecloud.app file is an essential configuration file used to set up your application on Square Cloud. It defines the name, description, version, main file, and other fundamental settings.

START Field Configuration

In the Square Cloud configuration file, the START field is optional and only required if you are using a custom script to start the website or API. In the provided example, the START field is not necessary.

Purchasing a Plan Before Uploading Your Project

Before uploading your project to Square Cloud, it’s important to understand that a plan purchase is required. The plan you choose will depend on the resources your application needs. See our available plans.
Wondering how much RAM and CPU your plan needs to host a Flask application? Don’t worry — we’re here to help. Flask is known for being lightweight, especially for small projects or learning purposes. Our Standard plan offers 4GB of RAM and 4vCPU, which should be sufficient for most Flask applications. However, if you’re working on a larger project and need extra stability, we recommend considering our Pro plan. With additional resources, you can maintain stability during traffic spikes. To purchase, just click here.

Uploading Your Project to Square Cloud

After preparing all project files, upload them to Square Cloud to host your application professionally.
Go to the Square Cloud Dashboard and upload your project files.

Additional Resources and Documentation

For more detailed information about Flask and its advanced tools, visit the official Flask documentation. There you will find in-depth technical guides, specialized tutorials, and full API documentation to make the most of Flask’s features.

Troubleshooting

Domínio Personalizado

Para usar domínio personalizado (ex: meusite.com) ao invés da URL padrão https://meusite.squareweb.app/, você precisa do plano Standard ou superior. O subdomínio é definido pelo campo SUBDOMAIN no arquivo de configuração. Veja: Como configurar seu domínio personalizado.

Requisitos Mínimos de RAM

Mínimo: 512MB de RAM para websites/APIs simples. Para sites com frameworks (Next.JS, React, Vue, Angular, etc.), sugerimos sempre pelo menos 1GB de RAM. Para aplicações maiores, use mais RAM para evitar erro LACK_OF_RAM e garantir performance.

Não foi possível encontrar esse site.

Verifique se o subdomínio/domínio corresponde ao configurado no campo SUBDOMAIN ou nas configurações de domínio personalizado. Se você acabou de enviar o site, aguarde até 60 segundos para a Square liberar o primeiro acesso.

Site demorou demais para responder...

Verifique se configurou corretamente a porta 80 e host 0.0.0.0 na aplicação. Recomendamos usar as variáveis de ambiente forçadas da Square: PORT e HOST do arquivo .env.
Se você continuar enfrentando dificuldades técnicas, nossa equipe de suporte especializada está disponível para auxiliá-lo. Entre em contato conosco e teremos prazer em ajudá-lo a resolver qualquer questão.