Skip to main content

Prerequisites

Deploy from Recipe

The fastest way to get started is to deploy our ready-made Python example:
1

Import the Project

Log in to Zerops GUI and click Import a project.
2

Paste the Configuration

Use this YAML configuration:
project:
  name: my-first-python-app
services:
  - hostname: app
    type: [email protected]
    minContainers: 1
    maxContainers: 3
    buildFromGit: https://github.com/zeropsio/recipe-python-hello-world@main
    enableSubdomainAccess: true
3

Wait for Deployment

Click Import project and wait for the build and deployment to complete.
4

Access Your App

Once deployed, find your subdomain URL in the IP Addresses & Public Routing Overview.It will look like: https://app-{project-id}-8080.prg1.zerops.appVisit the URL to see “Hello, World!”

Deploy Your Own Python Application

Step 1: Add zerops.yaml

Create a zerops.yaml file in your repository root:
zerops:
  - setup: app
    build:
      base: [email protected]
      buildCommands:
        - pip install -r requirements.txt
      deployFiles:
        - app
        - requirements.txt
      cache: ~/.cache/pip
    
    run:
      base: [email protected]
      start: python -m uvicorn app.main:app --host 0.0.0.0 --port 8000
      ports:
        - port: 8000
          httpSupport: true

Step 2: Create requirements.txt

List your dependencies:
fastapi==0.109.0
uvicorn[standard]==0.27.0
pydantic==2.5.0

Step 3: Configure Your Service

Create a description.yaml:
project:
  name: my-python-app
services:
  - hostname: app
    type: [email protected]
    minContainers: 1
    maxContainers: 6
Import the project:
zcli project project-import description.yaml

Step 4: Deploy Your Code

Connect your repository and deploy:
zcli service deploy

Framework Examples

FastAPI Application

Create a simple FastAPI app:
app/main.py
from fastapi import FastAPI
import os

app = FastAPI()

@app.get("/")
async def root():
    return {"message": "Hello from FastAPI on Zerops!"}

@app.get("/health")
async def health():
    return {"status": "healthy"}
zerops.yaml
zerops:
  - setup: api
    build:
      base: [email protected]
      buildCommands:
        - pip install -r requirements.txt
      deployFiles:
        - app
        - requirements.txt
    
    run:
      start: uvicorn app.main:app --host 0.0.0.0 --port 8000
      ports:
        - port: 8000
          httpSupport: true

Django Application

zerops.yaml
zerops:
  - setup: web
    build:
      base: [email protected]
      buildCommands:
        - pip install -r requirements.txt
        - python manage.py collectstatic --noinput
      deployFiles: .
      cache: ~/.cache/pip
    
    run:
      initCommands:
        - python manage.py migrate --noinput
      start: gunicorn myproject.wsgi:application --bind 0.0.0.0:8000 --workers 4
      envVariables:
        DJANGO_SETTINGS_MODULE: myproject.settings.production
        DEBUG: false

Flask Application

app.py
from flask import Flask
import os

app = Flask(__name__)

@app.route('/')
def hello():
    return {'message': 'Hello from Flask on Zerops!'}

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=5000)
zerops.yaml
zerops:
  - setup: app
    build:
      base: [email protected]
      buildCommands:
        - pip install -r requirements.txt
      deployFiles:
        - app.py
        - requirements.txt
    
    run:
      start: flask run --host=0.0.0.0 --port=5000
      envVariables:
        FLASK_APP: app.py
        FLASK_ENV: production

Adding a Database

Extend your project with PostgreSQL:
description.yaml
project:
  name: my-python-app
services:
  - hostname: app
    type: [email protected]
    minContainers: 1
    maxContainers: 6
  
  - hostname: db
    type: postgresql@16
    mode: NON_HA
Connect to the database:
import os
import psycopg2

conn = psycopg2.connect(
    host="db",
    database=os.getenv("DB_NAME"),
    user=os.getenv("DB_USER"),
    password=os.getenv("DB_PASSWORD")
)
Or with SQLAlchemy:
from sqlalchemy import create_engine
import os

DATABASE_URL = f"postgresql://{os.getenv('DB_USER')}:{os.getenv('DB_PASSWORD')}@db/{os.getenv('DB_NAME')}"
engine = create_engine(DATABASE_URL)

Environment Variables

Set environment variables in zerops.yaml:
run:
  envVariables:
    APP_ENV: production
    DEBUG: false
    LOG_LEVEL: info
Access in Python:
import os

app_env = os.getenv('APP_ENV', 'development')
debug = os.getenv('DEBUG', 'false').lower() == 'true'

Installing System Dependencies

For packages requiring system libraries:
build:
  base: [email protected]
  os: ubuntu
  prepareCommands:
    - sudo apt-get update
    - sudo apt-get install -y build-essential
    - sudo apt-get install -y libpq-dev
    - sudo apt-get install -y python3-opencv
  buildCommands:
    - pip install -r requirements.txt

Using Poetry

If you prefer Poetry for dependency management:
build:
  base: [email protected]
  buildCommands:
    - pip install poetry
    - poetry config virtualenvs.create false
    - poetry install --no-dev --no-root
  deployFiles:
    - app
    - pyproject.toml
    - poetry.lock

Troubleshooting

Make sure your requirements.txt is properly formatted and all packages are available on PyPI.Try installing with verbose output:
buildCommands:
  - pip install -r requirements.txt --verbose
Check your start command and ensure the port matches:
run:
  start: uvicorn app.main:app --host 0.0.0.0 --port 8000
  ports:
    - port: 8000
Ensure all dependencies are in requirements.txt and the build completes successfully:
build:
  buildCommands:
    - pip install -r requirements.txt
  deployFiles:
    - app
    - requirements.txt  # Don't forget this!
Make sure you’re deploying the correct files:
build:
  deployFiles:
    - app           # Your application code
    - requirements.txt
    - config        # Additional directories if needed

Next Steps

Runtime Overview

Learn about Python runtime features

Environment Variables

Manage secrets and configuration

Scaling

Configure auto-scaling

Monitoring

Monitor your application

Build docs developers (and LLMs) love