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
- 1Add Flask to requirements.txt.
- 2Keep app at module level in app.py or main.py.
- 3Connect the repository and deploy.
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.
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 engineThings 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.
| Limit | Free | Pro |
|---|---|---|
| Build minutes | 3,000/mo, 1 concurrent | 10,000/mo, 3 concurrent |
| Function memory / timeout | 1 GB / 300 s | 4 GB / 1800 s |
| Function invocations | 2 M/mo | 20 M/mo |
| Bandwidth | 150 GB/mo | 2 TB/mo |
Related guides
- Deploy a FastAPI appFastAPI (and Starlette) apps as ASGI functions on Python 3.12.
- Deploy a Django appDjango projects served through their wsgi.py application.
- Deploy a Python functions appPlain Python handlers in api/*.py, no framework needed.
Ship your Flask project tonight
Connect the repository and the build settings fill themselves in. Free plan, no card.