> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shardcloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Host Flask Applications

> Learn how to create and deploy Flask applications on Shard Cloud.

## 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](https://www.python.org/).

### Installing Flask

```bash theme={null}
pip install flask gunicorn
```

### Basic Flask Application

Create an `app.py` file:

```python app.py theme={null}
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`:

```txt requirements.txt theme={null}
flask
gunicorn
```

## Production Server with Gunicorn

<Warning>
  Flask's built-in server is not suitable for production. Always use Gunicorn.
</Warning>

## Shard Cloud Configuration

Create a `.shardcloud` file:

```systemd .shardcloud theme={null}
DISPLAY_NAME=Flask API
DESCRIPTION=Python Flask Application
MAIN=app.py
MEMORY=512
VERSION=recommended
SUBDOMAIN=my-flask-api
```

For production with Gunicorn:

```systemd .shardcloud theme={null}
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

<Steps>
  <Step title="Prepare Your Files">
    Ensure you have: - `app.py` - `requirements.txt` - `.shardcloud`
  </Step>

  <Step title="Exclude Unnecessary Files">
    Remove: `__pycache__/`, `venv/`, `*.pyc`
  </Step>

  <Step title="Create ZIP Archive">Compress your project folder.</Step>

  <Step title="Upload to Shard Cloud">
    Go to [Shard Cloud Dashboard](https://shardcloud.app/dash/applications) and
    upload.
  </Step>
</Steps>

## Additional Resources

Visit the [official Flask documentation](https://flask.palletsprojects.com/) for more information.

## Troubleshooting

<AccordionGroup>
  <Accordion title="ModuleNotFoundError">
    Ensure all dependencies are listed in `requirements.txt`.
  </Accordion>

  <Accordion title="Application not accessible">
    Verify you're binding to `0.0.0.0` and port `80`.
  </Accordion>
</AccordionGroup>
