Creating a New Flask Project

  • Before getting started, make sure you have Python and pip installed on your system. If you don’t already have them, you can download them from the official Python website and official Pip website.
  • Next, you will need to create an account on Square Cloud, which can be done through the login page. You can use either your email or Discord, or both, to create an account.
  • Finally, you need to have an active paid plan on your account. You can view our plans and purchase one according to your needs here.

With Python and pip installed, you can create a new Flask project. First, install Flask using pip:

pip install flask
pip install waitress

Then, create a new Python file (e.g., app.py) and add the following code to create a basic Flask application:

# 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 executed 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)

Configuring the Production Environment with Waitress

from flask import Flask

# Create a Flask application instance
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 executed directly (not imported as a module)
if __name__ == '__main__':
    from waitress import serve  # Import 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 to indicate successful server start on port 80
    print("Server successfully started on port 80.")

In the above code, we create a basic route that returns “Hello, World!” when accessed. The application is configured to run on port 80, which is the default port for HTTP traffic.

Managing Dependencies with the requirements.txt file

The requirements.txt file is a file that lists all external libraries required for your project. You should list all libraries your project will use, excluding native libraries like random and datetime. This file should be included when submitting your application to Square Cloud.

requirements.txt
flask

Creating the squarecloud config file

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

The squarecloud.app file is a configuration file that will be used to configure your application; it will be used to define the name, description, version, main file, among other things.

Configuring the START Field

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

Purchasing a Plan Before Uploading Your Project

Before you can upload your project to Square Cloud, it’s important to understand that you need to purchase a plan. The type of plan you choose will depend on the resources required by your application. You can view our plans here.

Are you 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 its efficiency, especially for small projects or learning purposes. Our Standard plan offers 4GB of RAM and 1vCPU, which should be sufficient for most Flask applications. However, if you’re working on a larger project and seeking extra stability, we recommend considering our Pro plan. With additional resources, you can maintain stability even during peak demand. To purchase, simply click here.

Uploading Project to Square Cloud

After preparing your project files, you can now upload them to Square Cloud and host your project.

Access the Square Cloud Dashboard and upload your project files.

Troubleshooting

Additional Resources

For more information about Flask and its tools, visit the official Flask documentation. There, you’ll find detailed guides, tutorials, and API documentation to help you make the most out of Flask.

If you continue to experience any issues, please don’t hesitate to contact our support team.