How to Deploy a Flask API
Add a Dockerfile, push, and deploy in under 2 minutes.
What you're building
A simple Flask API with a health check and an endpoint, deployed on PromptShip with gunicorn.
Your Flask app
# app.py
import os
from flask import Flask, jsonify
app = Flask(__name__)
@app.route("/health")
def health():
return jsonify({"status": "ok"})
@app.route("/api/hello")
def hello():
return jsonify({"message": "Hello from PromptShip!"})
if __name__ == "__main__":
port = int(os.environ.get("PORT", 8080))
app.run(host="0.0.0.0", port=port)
Your requirements.txt:
flask
gunicorn
How do I deploy it?
Step 1: Create the app
create_app(
name: "my-flask-api",
github_repo: "github.com/me/my-flask-api"
)
Step 2: Add a Dockerfile to your repo
FROM python:3.12-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
EXPOSE $PORT
CMD gunicorn --bind 0.0.0.0:$PORT app:app
Step 3: Deploy
deploy_app(app_name: "my-flask-api", branch: "main")
Your API is live at https://my-flask-api-dev.promptship.dev
How do I add a database?
Attach Postgres and DATABASE_URL is injected automatically:
attach_postgres(app_name: "my-flask-api", environment: "dev", tier: "pg-1")
deploy_app(app_name: "my-flask-api", branch: "main")
