Takk

Deploy

Flask

This guide walks you through deploying a Flask application on Takk. Flask is a lightweight WSGI web framework for Python. You can deploy Flask on Takk using the NetworkApp configuration with Gunicorn as the production server.

Prerequisites

Make sure you have the Takk CLI installed and are logged in. If not, follow the Get Started guide first.

Create the Project

Start by creating a new directory and initializing it:

bash
mkdir flask-hello
cd flask-hello
uv init

Add your dependencies:

bash
uv add flask gunicorn takk

Write the Application

Create app.py with a minimal Flask application:

python
from flask import Flask, jsonify

app = Flask(__name__)

@app.route("/")
def hello():
    return jsonify(message="Hello, World!")

@app.route("/greet/<name>")
def greet(name):
    return jsonify(message=f"Hello, {name}!")

Define the Project

Create project.py to tell Takk how to run your Flask app:

python
from takk.models import Project, NetworkApp

project = Project(
    name="flask-hello",
    server=NetworkApp(
        command=["gunicorn", "app:app", "--bind", "0.0.0.0:8000"],
        port=8000,
    ),
)

Flask uses Gunicorn as the production WSGI server. The NetworkApp configuration lets you specify the exact command and port Takk should use.

Run Locally

Start the local development environment:

bash
uv run takk up

Your Flask app is now running at http://localhost:8000. Test it:

bash
curl http://localhost:8000
# {"message": "Hello, World!"}

curl http://localhost:8000/greet/Alice
# {"message": "Hello, Alice!"}

Deploy

Deploy to the cloud with:

bash
uv run takk deploy

Takk builds the container, provisions infrastructure, and starts your Flask application with TLS and networking handled automatically.

Next Steps

Previous
Django