Python
Deploy a FastAPI app on Enzonic
Deploy finds your FastAPI app object (app = FastAPI(...)) in main.py, app.py, server.py, api/index.py, src/main.py, src/app.py, wsgi.py or asgi.py, installs requirements.txt or pyproject.toml, and serves it as an ASGI function on Python 3.12. There is no server process to manage.
At a glance
What Enzonic Deploy does with a FastAPI project when you connect it. You can override any of it in the project settings.
- Language
- Python
- Detected from
- fastapi or starlette in requirements.txt, pyproject.toml or Pipfile; An assignment like app = FastAPI( in one of the entry files
- Build command
- pip install -r requirements.txt (or pip install .)
- Output
- Functions
- Runs as
- Functions
How it runs
Functions
Always: the ASGI app runs in function instances that scale with traffic and to zero.
Deploy FastAPI step by step
- 1List dependencies in requirements.txt (or pyproject.toml).
- 2Keep the app object at module level in main.py (or one of the other entry files).
- 3Connect the repository and deploy.
from fastapi import FastAPI
app = FastAPI()
@app.get('/')
def read_root():
return {'hello': 'world'}Connect a database to FastAPI
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 PostgreSQL.
import os
from sqlalchemy import create_engine, text
# postgresql+psycopg:// selects psycopg 3; the URL comes from Enzonic Databases.
url = os.environ['DATABASE_URL'].replace('postgresql://', 'postgresql+psycopg://', 1)
engine = create_engine(url, pool_size=2, pool_pre_ping=True)
with engine.connect() as conn:
print(conn.execute(text('select now()')).scalar())Postgres projects get two variables: DATABASE_URL through the connection pooler for the app, and DATABASE_URL_UNPOOLED for migrations.
PostgreSQL on Enzonic DatabasesEvery database engineThings to know
- The app object must be named in an assignment Deploy can see (app = FastAPI(...)); an app created inside a factory function is not found.
- Startup and shutdown events run per function instance, not once per deployment.
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 Flask appFlask (and Quart) apps served as WSGI/ASGI functions.
- 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 FastAPI project tonight
Connect the repository and the build settings fill themselves in. Free plan, no card.