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.txtfile orpyproject.tomlat 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.0Key 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
| Variable | Required | Default | Description |
|---|---|---|---|
PORT | Yes | 5000 | Port your app listens on |
PYTHONUNBUFFERED | Yes | (none) | Set to 1 to ensure immediate output flushing |
PYTHON_VERSION | No | (none) | Specify Python version if needed |
Common Application Variables
| Variable | Default | Description |
|---|---|---|
DEBUG | false | Enable debug mode (set to 0 for production) |
LOG_LEVEL | info | Logging verbosity |
TZ | UTC | Timezone 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()
}, 200In 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:
- Check your build command is correct
- Verify all dependencies are listed in requirements.txt
- Check for syntax errors or missing files
- Make sure you're using compatible package versions
Test locally first:
pip install -r requirements.txt
python app.pyApplication 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.txtlocally to verify all packages are available - Check you have all required packages listed in requirements.txt
Database Connection Issues
Resources
- Flask Documentation
- Django Documentation
- FastAPI Documentation
- Python Best Practices
- Galaxy Community Forum
Need Help?
Having trouble deploying your Python app?
Pro Tip: Live chat is fastest for urgent issues. Available directly from your Galaxy dashboard.
