Galaxy
Web Apps

Python

Deploy your Python application on Galaxy with zero downtime and automatic scaling.

New to Galaxy? Start with the Web Apps Deployment Guide first. This guide covers Python-specific setup.


What is Python?

Python is a versatile programming language widely used for web applications. Galaxy supports Python 3.10, 3.11, 3.12, and later versions.

Common frameworks you might be running:

  • Flask: Lightweight and flexible web framework
  • Django: Full-featured web framework with batteries included
  • FastAPI: Modern, fast web framework for building APIs
  • Uvicorn: ASGI server for running async Python applications
  • Gunicorn: WSGI HTTP server for Python applications

Galaxy handles the runtime for you. Just push your code, and Galaxy spins up your Python app.


Prerequisites

Before deploying your Python app, ensure you have:

  • An active Galaxy account (sign up here if needed)
  • Your Python app in a GitHub repository
  • A requirements.txt file or pyproject.toml at your repo root (or in a subdirectory)
  • A start script or command defined in your deployment configuration

To deploy any application on Galaxy, you must add a valid payment method for identity verification. We'll place a small temporary hold on your card to verify it, then automatically refund it. You'll only be charged if you deploy a paid app.

Galaxy supports Python 3.10 and later. For best compatibility, use Python 3.11 or 3.12.


Getting Started

Head over to the Web Apps Deployment Guide and follow the general deployment steps. Then come back here for Python-specific details about required files and configuration.


Required Files

Make sure your repository includes these essential files:

requirements.txt

This is required. Galaxy reads your requirements.txt to understand your dependencies and how to build your app.

Flask==2.3.0
python-dotenv==1.0.0
gunicorn==20.1.0

Key points:

  • List all production dependencies your app needs to run
  • Specify versions for reproducible builds
  • Galaxy automatically installs these during deployment

app.py or main.py

Your main application file. Galaxy runs your start command, which should point to this file.

import os
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, Galaxy!'

@app.route('/health')
def health():
    return {'status': 'ok'}, 200

if __name__ == '__main__':
    port = int(os.getenv('PORT', 5000))
    app.run(host='0.0.0.0', port=port)

Critical: Listen on the PORT environment variable, not a hardcoded port. Galaxy passes the PORT environment variable, and your app must use it.

.gitignore

Make sure your git repo excludes files that shouldn't be committed:

__pycache__/
*.py[cod]
*$py.class
.env
.env.local
.DS_Store
*.log
venv/
env/
.venv/
dist/
build/
*.egg-info/

Important: Never commit .env files with secrets. Use environment variables in Galaxy instead.


Environment Variables Reference

These are the variables your Python app might need. Set them in the Galaxy deployment form.

Core Variables

VariableRequiredDefaultDescription
PORTYes5000Port your app listens on
PYTHONUNBUFFEREDYes(none)Set to 1 to ensure immediate output flushing
PYTHON_VERSIONNo(none)Specify Python version if needed

Common Application Variables

VariableDefaultDescription
DEBUGfalseEnable debug mode (set to 0 for production)
LOG_LEVELinfoLogging verbosity
TZUTCTimezone for your app

Advanced Configuration

Custom Build Commands

If you need to run build steps (installing dependencies, migrations, etc.), define them in your deployment configuration.

Then in Galaxy, set:

  • Build Command: pip install -r requirements.txt
  • Start Command: gunicorn app:app

Galaxy runs build, then start.

Health Check Endpoint

Create a simple health check endpoint for Galaxy to monitor:

@app.route('/health')
def health():
    return {
        'status': 'ok',
        'timestamp': datetime.now().isoformat()
    }, 200

In the Galaxy deployment form, set Health Check Path to /health. Galaxy checks this endpoint regularly. If it fails, Galaxy knows something's wrong.


Troubleshooting

Build Failures

Build Failed

Problem: Build exits with an error

Solutions:

  1. Check your build command is correct
  2. Verify all dependencies are listed in requirements.txt
  3. Check for syntax errors or missing files
  4. Make sure you're using compatible package versions

Test locally first:

pip install -r requirements.txt
python app.py

Application Won't Start

App Won't Start

Common causes:

1. Port Not Set Correctly

# Wrong: hardcoded port
app.run(port=5000)

# Correct: use PORT env var
port = int(os.getenv('PORT', 5000))
app.run(port=port)

2. Missing Environment Variables

  • Check your Galaxy environment variables are set
  • Verify database URL is accessible from Galaxy
  • Confirm API keys are correct

3. Missing Dependencies

  • Run pip install -r requirements.txt locally to verify all packages are available
  • Check you have all required packages listed in requirements.txt

Database Connection Issues


Resources


Need Help?

Having trouble deploying your Python app?

Pro Tip: Live chat is fastest for urgent issues. Available directly from your Galaxy dashboard.