Deploying Flask Projects
With its minimalist, flexible, and powerful design, Flask is an excellent choice for microservices and APIs. Skyversal deploys your Flask projects instantly via Gunicorn without any extra configuration.
What you'll learn in this guide
- ✅ Required dependencies (Gunicorn requirement)
- ✅ Application instance (app object) detection logic
- ✅ Environment variables usage
- ✅ Custom entry point (FLASK_APP)
1. Required Dependencies (requirements.txt)
Flask applications need a WSGI server alongside the Flask package to run in production. Make sure your dependency file includes these two packages:
2. How Is the Flask App Detected?
Skyversal automatically uses Gunicorn to start your Flask project. For Gunicorn to find your application, your code must define app = Flask(__name__).
Skyversal looks for the app object in these files, in order:
-
app.py -
main.py -
application.py -
wsgi.py
If your application is in a different file (e.g., server.py), go to the Skyversal panel and add a new variable under Settings > Environment Variables:
Key: FLASK_APP
Value: server:app
3. Environment Variables
You should never hardcode passwords, API keys, or database URLs directly in your Flask application code. You can easily read variables added through the Skyversal panel using os.getenv():
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = os.getenv('DATABASE_URL')
@app.route('/')
Common Errors (Troubleshooting)
Fix: Gunicorn can't find the app object. Make sure your file name is standard (app.py, etc.) or that you've correctly set the FLASK_APP variable.
Fix: Missing requirements.txt at root. Export your dependencies with pip freeze > requirements.txt and push to GitHub.
Fix: If you have app.run(port=...) at the bottom of your code, it's unnecessary since Skyversal uses Gunicorn. You can safely remove it.
You're Ready! 🚀
Once all checks pass, just push your code. Skyversal will have your SSL-secured Flask app live in seconds.