Skip to content

Python

Deploy a Flask app on Enzonic

A Flask app deploys as a function: Deploy finds app = Flask(__name__) in one of the usual entry files and serves it through its WSGI shim on Python 3.12. Quart apps are detected the same way and run as ASGI.

At a glance

What Enzonic Deploy does with a Flask project when you connect it. You can override any of it in the project settings.

Language
Python
Detected from
flask or quart in requirements.txt, pyproject.toml or Pipfile; app = Flask( (or Quart() in main.py, app.py, server.py, api/index.py, src/main.py, src/app.py, wsgi.py or asgi.py
Build command
pip install -r requirements.txt
Output
Functions
Runs as
Functions

How it runs

  • Functions

    Always.

Deploy Flask step by step

  1. 1Add Flask to requirements.txt.
  2. 2Keep app at module level in app.py or main.py.
  3. 3Connect the repository and deploy.
app.py
from flask import Flask, jsonify

app = Flask(__name__)

@app.get('/')
def index():
    return jsonify(hello='world')

Connect a database to Flask

Create a database on Enzonic Databases (or from the project's settings) and its connection string is added to the project's environment variables. This example uses MySQL.

app.py (database)
import os
from sqlalchemy import create_engine, text

# MySQL or MariaDB on Enzonic: TLS is required, so pass ssl.
url = os.environ['DATABASE_URL'].replace('mysql://', 'mysql+pymysql://', 1)
engine = create_engine(url, connect_args={'ssl': {}}, pool_pre_ping=True)

@app.get('/count')
def count():
    with engine.connect() as conn:
        return {'posts': conn.execute(text('select count(*) from posts')).scalar()}

Postgres projects get two variables: DATABASE_URL through the connection pooler for the app, and DATABASE_URL_UNPOOLED for migrations.

MySQL on Enzonic DatabasesEvery database engine

Things to know

  • app.run() at the bottom of the file is ignored on Enzonic (guard it with if __name__ == '__main__').

Plan limits that matter here

From the live plan data. Every plan includes previews for each branch, instant rollback, environment variables and logs.

Plan limits that matter for Flask
LimitFreePro
Build minutes3,000/mo, 1 concurrent10,000/mo, 3 concurrent
Function memory / timeout1 GB / 300 s4 GB / 1800 s
Function invocations2 M/mo20 M/mo
Bandwidth150 GB/mo2 TB/mo

Compare every plan

Related guides

Ship your Flask project tonight

Connect the repository and the build settings fill themselves in. Free plan, no card.

Start free