Skip to main content
A FastAPI project runs on Sevalla as an application built from your Git repository: Ingot, Sevalla’s builder, detects FastAPI and starts it with Uvicorn in the web process, and a job runs its Alembic migrations before each deployment. Its data lives in a Sevalla PostgreSQL database that the application reaches over an internal connection.

At a glance

Environment variables

Before you begin

  • A Sevalla company with a payment method, and a GitHub, GitLab or Bitbucket account for the repository. See Git providers.
  • Python 3.14 on your computer.

Create the project

Create a virtual environment, install FastAPI, SQLModel, Alembic and the PostgreSQL driver, and create the app package:
Keep local files out of the repository:
.gitignore
Add the database engine. Sevalla’s connection URLs start with postgres://, which SQLAlchemy doesn’t accept, so the code switches the scheme to postgresql+psycopg://, SQLAlchemy’s name for psycopg 3:
app/db.py
DB_URL is the variable Sevalla adds when you connect the database; without it, the project uses SQLite on your computer. Add a model and the application:
app/models.py
app/main.py

Prepare the project for Sevalla

Set up migrations

Create the Alembic files:
In alembic/env.py, replace everything above def run_migrations_offline() with this, which points Alembic at the same database URL and at the SQLModel tables:
alembic/env.py
SQLModel columns use its own types, so in alembic/script.py.mako, the template Alembic writes migrations from, add import sqlmodel under import sqlalchemy as sa:
alembic/script.py.mako
Generate the first migration, apply it to the local database and start the development server:
fastapi dev finds the application in app/main.py. Open http://127.0.0.1:8000: the response is {"items":0}. Press Ctrl+C to stop the server.

Pin the Python version

Ingot reads the Python version from .python-version. Without it, Ingot builds on its default line (3.14 in Ingot 0.5.0), which a newer Ingot release can move. Pin the version you develop with:
.python-version
See Pin the Python version.

Check the start command

The project needs no start command. Ingot finds app = FastAPI() in app/main.py and starts the web process with uvicorn app.main:app --host 0.0.0.0 --port "$PORT", which the build plan shows in its Start row.
  • Uvicorn listens on all interfaces, on the port in the PORT environment variable. Sevalla sets PORT to the web process’s port, 8080 by default.
  • Requests reach the application through Sevalla’s proxy. Ingot’s image sets FORWARDED_ALLOW_IPS=*, so Uvicorn trusts the X-Forwarded-Proto and X-Forwarded-For headers, and FastAPI sees the https scheme and the visitor’s address. See Request headers.
  • Uvicorn runs one worker process in each instance. On a larger size, set the WEB_CONCURRENCY environment variable to run more, for example 2. See Scaling.
  • Migrations don’t run here. A job runs them once per deployment.
Ingot looks for the application in main.py, app.py, app/main.py and a few other common files. To start it another way, set the web process’s start command; see Set the start command.

List the dependencies

Ingot installs the packages in requirements.txt with pip, so list them with the versions you tested:
Commit everything, including the alembic folder and alembic.ini, and push it to your Git provider:

Deploy to Sevalla

These steps build with Ingot. To build from your own Dockerfile instead, see Deploy with a Dockerfile.
1

Create the database

In the sidebar, click Databases, then click Create database. Under Database, choose PostgreSQL and the newest version. Enter orders-db as the Display name, choose a Data center and a Size, then click Create database. See Create a database for every field.
2

Create the application

In the sidebar, click Applications, then click Create > Application. Under Source, click Private repository, then choose the Git provider, the Repository and the Branch. Under Location, choose the same Data center as the database. Keep the Size at H1 or choose a larger one, then click Create application. The application opens on its Overview tab with the status Not deployed yet: creating an application doesn’t deploy it.
3

Connect the database

Click the Networking tab. Under Connected services, click Add internal connection. Choose orders-db as the Service, turn on Add environment variables to the application, and click Add internal connection. Sevalla adds DB_URL and the other connection variables to the application. See Connect an application.
4

Create the migration job

Click the Processes tab, then click Create process. Choose Job, enter Migrate as the Name and alembic upgrade head as the Custom start command. Keep the Start policy at Before deployment and the Resource at H1, then click Create process.
5

Deploy

Click the Overview tab, then click Deploy now under Recent deployments. Check the Branch and click Deploy.
6

Turn on auto-deploy

To deploy every push to the branch automatically, click the Settings tab, then click Update auto-deploy in the Auto-deploy section. Turn on Auto-deploy and click Update auto-deploy. See Deployments.
The Create process sheet with Job selected, the Name and Custom start command fields, the Start policy set to Before deployment, and the H1 resourceThe Create process sheet with Job selected, the Name and Custom start command fields, the Start policy set to Before deployment, and the H1 resource

Verify the deployment

  1. On the Deployments tab, click the deployment. Its build log shows Ingot’s build plan:
    Build log
    After the build, the log shows Migrate has been successful, then Web has been deployed successfully. If the job fails, the deployment fails and nothing changes for visitors.
  2. Wait for the deployment’s status to change to Deployed. The application’s status next to its name changes to Running.
  3. Click the domain under the application’s name, for example storefront-x7k2m.sevalla.app, or run curl -s https://storefront-x7k2m.sevalla.app/. The response is {"items":0}, which shows that the application reads the PostgreSQL database.
  4. Add an item and read it back, with your application’s domain:
    The first response is {"id":1,"name":"Mug"} and the second is {"items":1}. The interactive API docs are at /docs.
To check the same things through the API, use APP_ID and DEPLOYMENT_ID from Deploy with the API. Get deployment (getDeploymentV3) returns the status, success once the deployment is done:
Get application deployment logs (getApplicationDeploymentLogsV3) returns the build log, build plan included; search keeps the lines that contain a text:
The messages carry terminal color codes, so match the text inside them. The job’s own output is in the runtime logs: Get application runtime logs (getApplicationRuntimeLogsV3) with search=Running%20upgrade returns INFO [alembic.runtime.migration] Running upgrade -> 4a832573a227, Create item table, with your migration’s revision. The CLI has sevalla apps deployments get, sevalla apps deployments logs and sevalla apps logs runtime, and the MCP server get_deployment, get_deployment_logs and search_runtime_logs.

Deploy with a Dockerfile

Ingot needs no Dockerfile. Write your own when you want full control of the image: the base image, the system packages and every layer. Add a Dockerfile and a .dockerignore to the root of the repository:
Dockerfile
.dockerignore
Commit and push both files. Ingot doesn’t use the Dockerfile, so you can keep it in a repository that builds with Ingot, but it adds the .dockerignore patterns to its own: its build plan shows an Ignored row with 7 patterns from .dockerignore. Then switch the application to the Dockerfile build strategy:
1

Choose the Dockerfile build strategy

On the application’s Settings tab, in the Build strategy section, click Update build strategy. Click Dockerfile, keep the Dockerfile path Dockerfile and the Docker context ., then click Update build strategy.
2

Deploy

Click the Overview tab, then click Deploy now under Recent deployments. Check the Branch and click Deploy.
The Update build strategy sheet with Dockerfile selected, the Dockerfile path, the Docker context and the Docker registry credentialThe Update build strategy sheet with Dockerfile selected, the Dockerfile path, the Docker context and the Docker registry credential
The build log shows 📦 Building and pushing docker image using Dockerfile... where Ingot’s build plan was, then Migrate has been successful: the job runs alembic upgrade head in the new image. The domain still returns {"items":1}, from the same database, and curl -i https://storefront-x7k2m.sevalla.app/items/ redirects to https://storefront-x7k2m.sevalla.app/items, with the https scheme that Uvicorn took from the proxy. The deployment’s Dockerfile tab shows your Dockerfile. See Dockerfile.

Deploy changes

With Auto-deploy on, every push to the branch starts a deployment; otherwise, click Deploy now for each change. Each deployment builds the image, runs the Migrate job, then replaces the web process’s instances. For a schema change, run alembic revision --autogenerate on your computer and commit the new migration with the code. After you install a package, run pip freeze > requirements.txt again. See Deployments.

Add a custom domain

Add the domain on the application’s Domains tab. FastAPI doesn’t check the host, so no code change is needed. Custom domains need a web process larger than H1.

Troubleshoot the deployment

For more causes, see Troubleshoot builds and deployments. To add file storage, caching or background tasks, see the FastAPI guides.

Deploy with the API

These calls make the same deployment as Deploy to Sevalla, in an order that an agent or a script runs as is. Each step names the API operation, then the CLI command and the MCP tool that do the same. The CLI reads the key from SEVALLA_API_TOKEN and prints tables; with --json it prints the API’s JSON, except that lists are bare arrays rather than the API’s data field. Before you start:
  • Put an API key in SEVALLA_API_KEY. The key needs the Company developer role or Company admin; see API keys. The commands use curl, jq and openssl.
  • Push the repository and connect its Git account to Sevalla, as in Before you begin. No API call reports whether the account is connected: if it isn’t, or Sevalla’s GitHub App can’t see the repository, creating the application fails with 400 and a message that starts with Cannot access repository https://github.com/acme/storefront: Repository not found or you don't have access. and says where to grant access.
  • Look up the location and the sizes. The first command picks the location by its region ID, here eu-frankfurt-1 (Frankfurt, Germany); see Locations for the others. List clusters (listClustersV3), List process resource types (listProcessResourceTypesV3) and List database resource types (listDatabaseResourceTypesV3) return them; the CLI has sevalla resources clusters, sevalla resources process-types and sevalla resources db-types, and the MCP server get_platform_options.
If a variable ends up empty or null, run its curl command without jq: the response’s message says what went wrong.
1

Create the database

Create database (createDatabaseV3). You choose the password here, because the API never returns it and DB_URL needs it:
CLI: sevalla databases create --name orders-db --type postgresql --db-version 18 --cluster "$CLUSTER_ID" --resource-type "$DB1_ID" --db-name storefront --db-user storefront --db-password "$DB_PASSWORD". MCP: create_database generates its own password and never returns it. Call it once the application exists, with connect_to_application_id set to the application and env_var_name set to DB_URL: it then also adds the internal connection and DB_URL, in place of the steps that connect the database and add the database URL. Its URL starts with postgresql://, which SQLAlchemy 2.1 connects with psycopg 3 too, so database_url() needs no change.
2

Create the application

Create application (createApplicationV3). It creates the web process and doesn’t deploy:
CLI: sevalla apps create --name storefront --cluster "$CLUSTER_ID" --source privateGit --git-type github --repository https://github.com/acme/storefront --branch main. MCP: create_application with deploy set to false; by default it starts a deployment before the database, the variable and the job exist.
3

Set the web process size

The API creates the web process at S1, not the dashboard’s H1. List processes (listProcessesV3) finds it, and Update process (updateProcessV3) sets H1:
It prints h1. CLI: sevalla apps processes update "$WEB_ID" --app-id "$APP_ID" --resource-type "$H1_ID". MCP: scale_process with size_id and apply_now set to false.
4

Wait for the database

Get database (getDatabaseV3) until its status is ready, then keep its internal hostname and port:
CLI: sevalla databases get "$DB_ID" --json. MCP: get_database.
5

Connect the database

Create internal connection (createApplicationInternalConnectionV3):
CLI: sevalla databases connections internal-create "$DB_ID" --target-id "$APP_ID" --target-type app. MCP: sevalla_api_create with createApplicationInternalConnectionV3 and the same body.
6

Add the database URL

Unlike the dashboard, the API doesn’t add the connection’s variables. Create environment variable (createEnvironmentVariableV3) adds DB_URL in the dashboard’s format, available during runtime only (the API’s default is build and runtime):
It prints {"key":"DB_URL","is_runtime":true,"is_buildtime":false}. CLI: sevalla apps env-vars create "$APP_ID" --key DB_URL --value "postgres://storefront:$DB_PASSWORD@$DB_HOST:$DB_PORT/storefront", which makes it available during build and runtime. MCP: set_environment_variables with runtime true and buildtime false.
7

Create the migration job

Create process (createProcessV3). A job needs job_start_policy, and every process needs scaling_strategy and resource_type_id:
CLI: sevalla apps processes create "$APP_ID" --name Migrate --type job --command "alembic upgrade head" --job-start-policy beforeDeployment --resource-type "$H1_ID". MCP: sevalla_api_create with createProcessV3 and the same body.
8

Deploy

Trigger deployment (triggerDeploymentV3) deploys the latest commit on the branch:
CLI: sevalla apps deployments trigger "$APP_ID". MCP: trigger_deployment.
9

Wait for the deployment

Get deployment (getDeploymentV3) until status is success or failed:
It prints success when the deployment finishes, or failed; after 30 minutes without either, it prints the status it last read. On failed, read the build log with Get application deployment logs (getApplicationDeploymentLogsV3), as in Verify the deployment. CLI: sevalla apps deployments get "$DEPLOYMENT_ID" --app-id "$APP_ID". MCP: get_deployment, then get_deployment_logs.
10

Turn on auto-deploy

Update application (updateApplicationV3):
It prints true. CLI: sevalla apps update "$APP_ID" --data '{"auto_deploy": true}'. MCP: sevalla_api_update with updateApplicationV3 and the same body.
List application domains (listApplicationDomainsV3) returns the domain to run the checks in Verify the deployment against:
The response is {"items":0}. To build from the Dockerfile instead, send {"build_type": "dockerfile", "dockerfile_path": "Dockerfile", "docker_context": "."} to Update application, then deploy and wait again. CLI: sevalla apps update "$APP_ID" --build-type dockerfile --dockerfile-path Dockerfile.