Python Guide
Deploy Python applications on Kova.
Quick Start
Basic Flask App
version: "2.0"
services:
api:
image: python:3.11-alpine
expose:
- port: 5000
as: 5000
to:
- global: true
env:
- FLASK_ENV=production
- PORT=5000
params:
storage:
app:
mount: /app
source: uploads
profiles:
compute:
api:
resources:
cpu:
units: 1
memory:
size: 512Mi
deployment:
api:
anywhere:
profile: api
count: 1
Project Structure
Upload these files to /app:
/app
├── requirements.txt
├── app.py
└── gunicorn.conf.py (optional)
requirements.txt
flask==3.0.0
gunicorn==21.2.0
app.py
from flask import Flask, jsonify
import os
app = Flask(__name__)
@app.route('/')
def home():
return jsonify({'message': 'Hello from Kova!'})
@app.route('/health')
def health():
return jsonify({'status': 'ok'})
if __name__ == '__main__':
port = int(os.environ.get('PORT', 5000))
app.run(host='0.0.0.0', port=port)
Production with Gunicorn
For production, use Gunicorn as WSGI server:
services:
api:
image: python:3.11-alpine
command: ["gunicorn", "--bind", "0.0.0.0:5000", "app:app"]
gunicorn.conf.py
workers = 2
bind = "0.0.0.0:5000"
timeout = 120
Using with Database
services:
api:
image: python:3.11-alpine
env:
- DATABASE_URL=postgres://postgres:password@db:5432/mydb
db:
image: postgres:15-alpine
env:
- POSTGRES_PASSWORD=password
- POSTGRES_DB=mydb
Environment Variables
| Variable | Description |
|----------|-------------|
| FLASK_ENV | Set to production |
| PORT | Port your app listens on |
| DATABASE_URL | Database connection string |
| SECRET_KEY | Flask secret key for sessions |