Back to Blog
Tutorial

How to Deploy a Flask Application in 1 Minute

Daniel Brooks5 min read
How to Deploy a Flask Application in 1 Minute

Flask is one of the most popular Python web frameworks, known for its simplicity and flexibility. Deploying a Flask application to production, however, often involves complex server configuration, SSL certificates, and infrastructure management.

With Out Plane, you can deploy your Flask application in under a minute. This guide shows you exactly how.

What You'll Need

Before starting, make sure you have:

  • Python 3.10+ installed on your machine
  • A GitHub account
  • A Flask application in a GitHub repository
  • A requirements.txt file with your dependencies

Don't have Python installed? Download it from python.org:

  • Windows: Download the installer and check "Add Python to PATH" during installation
  • macOS: Use brew install python3 or download from python.org
  • Linux: Run sudo apt install python3 python3-pip (Ubuntu/Debian) or sudo dnf install python3 (Fedora)

Once Python is installed, create a project folder and set up a virtual environment:

bash
mkdir my-flask-app && cd my-flask-app
python3 -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
pip install flask gunicorn

If you don't have a Flask app yet, you can use our example below.

Quick Start: Sample Flask Application

Here's a minimal Flask application you can use. Create these three files in your repository:

Create app.py:

python
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def home():
    return jsonify({
        "message": "Hello from Flask!",
        "status": "running"
    })

@app.route("/health")
def health():
    return jsonify({"status": "healthy"})

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080)

Create requirements.txt:

text
flask==3.1.0
gunicorn==22.0.0

Create Procfile (no file extension):

text
web: gunicorn app:app --bind 0.0.0.0:8080

This tells Buildpacks how to start your application.

Push this code to a GitHub repository, and you're ready to deploy.

Optional: Add a Dockerfile

If you prefer full control over the build process, create a Dockerfile instead of using Buildpacks:

dockerfile
FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8080

CMD ["gunicorn", "app:app", "--bind", "0.0.0.0:8080", "--workers", "4"]

With a Dockerfile, select Dockerfile as your build method in the next step. Without one, select Buildpacks and Out Plane handles everything automatically.

Deploy in 3 Steps

Step 1: Connect Your Repository

  1. Go to console.outplane.com
  2. Sign in with your GitHub account
  3. Select your Flask repository from the list

Out Plane automatically detects Python applications and configures the build process using Buildpacks.

Step 2: Configure Your Application

Configure the following settings in the create application form:

Build Method

Select how Out Plane should build your application:

  • Buildpacks (Recommended): Automatically detects Python and installs dependencies from requirements.txt. No additional configuration needed.
  • Dockerfile: Use this if you have a custom Dockerfile in your repository for full control over the build process.

For most Flask applications, Buildpacks is the easiest option.

Basic Settings

  • Port: Set to 8080
  • Branch: Select main or your preferred branch
  • Region: Choose the region closest to your users

Environment Variables (Optional)

If your application uses environment-specific configuration, add them here. For our simple example, no environment variables are required.

For more complex applications, you might add variables like database URLs or API keys using the Add button or Raw Edit for bulk entry.

Step 3: Deploy

Click Deploy Application and watch the build process:

  1. Queued → Waiting for resources
  2. Building → Installing dependencies from requirements.txt
  3. Deploying → Starting your Flask application
  4. Ready → Your app is live

Once the status shows Ready, your application is live. You can find your application URL at the top of the deployment page. Click the URL to open your Flask app in a new tab. SSL is automatically configured.

Production Best Practices

Use Gunicorn for Production

Flask's built-in server is not suitable for production. Always use a WSGI server like Gunicorn:

bash
gunicorn app:app --bind 0.0.0.0:8080 --workers 4

Out Plane's Buildpacks automatically detect Gunicorn in your requirements.txt and configure it properly.

Configure Workers

For better performance under load, you can customize Gunicorn workers. A common formula is (2 × CPU cores) + 1.

If you need custom worker configuration, use a Dockerfile instead of Buildpacks for full control over the start command.

Environment-Based Configuration

For applications that need configuration, read values from environment variables:

python
import os
from flask import Flask

app = Flask(__name__)

# Example: Database connection
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL")

# Example: Debug mode
app.config["DEBUG"] = os.environ.get("FLASK_DEBUG", "0") == "1"

This keeps sensitive data out of your codebase and makes deployments across environments seamless.

Connecting a Database

Most Flask applications need a database. Out Plane provides managed PostgreSQL:

  1. Go to Databases in the sidebar
  2. Click Create Database
  3. Select PostgreSQL version and region
  4. Copy the connection URL

Add the connection URL as an environment variable:

text
DATABASE_URL=postgres://user:password@host/database

Then use it in your Flask app with SQLAlchemy:

python
from flask_sqlalchemy import SQLAlchemy

app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("DATABASE_URL")
db = SQLAlchemy(app)

Custom Domain Setup

Replace the default .outplane.app URL with your own domain:

  1. Navigate to Domains
  2. Click Map Domain
  3. Enter your domain (e.g., api.yourdomain.com)
  4. Add the DNS records shown to your domain registrar

SSL certificates are automatically provisioned once DNS propagates.

Monitoring Your Application

After deployment, monitor your Flask application:

  • Logs: View real-time application logs including Flask request logs
  • Metrics: Track CPU, memory, and network usage
  • HTTP Logs: Analyze incoming requests, response times, and status codes

Access these from the sidebar in your application dashboard.

Troubleshooting

Application Won't Start

Check the port configuration. Make sure you set the port to 8080 in the application settings.

Module Not Found Errors

Verify requirements.txt includes all dependencies. Run pip freeze > requirements.txt locally to capture all installed packages.

500 Internal Server Error

Check your application logs. Navigate to Logs in the sidebar to see Python tracebacks and error messages.

Slow Cold Starts

Optimize your imports. Heavy imports at application startup increase cold start times. Consider lazy loading for large dependencies.

Next Steps

Your Flask application is now deployed and running in production. Here's what to explore next:

  • Scale your application: Adjust instance types and auto-scaling settings for higher traffic
  • Set up CI/CD: Enable automatic deployments on every git push
  • Add monitoring: Integrate with external monitoring tools via Out Plane's metrics export

Summary

Deploying a Flask application to Out Plane takes three steps:

  1. Connect your GitHub repository
  2. Configure port (8080) and environment variables
  3. Deploy and get your live URL

No server configuration, no manual SSL setup, no infrastructure management. Just push your code and go live.

Ready to deploy your Flask application? Get started with Out Plane and receive $20 in free credit.


Tags

flask
python
deployment
tutorial
web-framework

Start deploying in minutes

Connect your GitHub repository and deploy your first application today. $20 free credit. No credit card required.