Skip to main content

Introduction

This guide covers deploying Flask applications on Shard Cloud. Flask is a lightweight WSGI web framework for Python.

Creating Your Project

Ensure you have Python and pip installed. Download from python.org.

Installing Flask

pip install flask gunicorn

Basic Flask Application

Create an app.py file:
app.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=80)

Requirements File

Create a requirements.txt:
requirements.txt
flask
gunicorn

Production Server with Gunicorn

Flask’s built-in server is not suitable for production. Always use Gunicorn.

Shard Cloud Configuration

Create a .shardcloud file:
.shardcloud
DISPLAY_NAME=Flask API
DESCRIPTION=Python Flask Application
MAIN=app.py
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-flask-api
For production with Gunicorn:
.shardcloud
DISPLAY_NAME=Flask API
DESCRIPTION=Python Flask Application
LANGUAGE=python
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-flask-api
CUSTOM_COMMAND=gunicorn --bind 0.0.0.0:80 --workers 2 app:app

Deploying

1

Prepare Your Files

Ensure you have: - app.py - requirements.txt - .shardcloud
2

Exclude Unnecessary Files

Remove: __pycache__/, venv/, *.pyc
3

Create ZIP Archive

Compress your project folder.
4

Upload to Shard Cloud

Go to Shard Cloud Dashboard and upload.

Additional Resources

Visit the official Flask documentation for more information.

Troubleshooting

Ensure all dependencies are listed in requirements.txt.
Verify you’re binding to 0.0.0.0 and port 80.