Set up a pipeline project

Create a sample Python pipeline and SQL assets in your own repository, connect them to a pipeline project and run them in Vegalake.

This guide builds a small working project from an empty repository: one Python pipeline with two activities, deployed to a development environment and run from Vegalake. It then adds SQL assets: tables built from SQL models, with a check. When it works, replace the sample code with your own.

A pipeline project reads its code from a Git repository. Every commit on the branch an environment tracks is synced: Vegalake reads the code, finds the pipelines in it and deploys them to that environment. Nothing runs until you start a run or add a schedule.

Before you start

You need:

  • A Git integration for the provider that hosts your repository.
  • A running VegaFlow cluster, and permission to use it. Python pipelines run on a dedicated cluster, not on serverless compute.
  • An active service principal for the pipelines to run as, and permission to act as it. Create one under Access management if your organization has none. Read Users, roles and service principals.
  • Permission to create pipeline projects in the workspace.

Step 1: Add the sample code to your repository

Create a repository in your Git provider, or use an existing one, and add this file at pipelines/daily_orders.py:

pipelines/daily_orders.py
from vegaflow import TaskContext, activity, pipeline


@activity(retries=3)
def load_orders(ctx: TaskContext, day: str) -> list[dict]:
    # Replace with a read from your source system.
    return [
        {"order_id": 1, "day": day, "amount": 120.00, "status": "paid"},
        {"order_id": 2, "day": day, "amount": 45.50, "status": "refunded"},
        {"order_id": 3, "day": day, "amount": 80.25, "status": "paid"},
    ]


@activity
def summarize(ctx: TaskContext, orders: list[dict]) -> dict:
    paid = [order for order in orders if order["status"] == "paid"]
    return {
        "orders": len(orders),
        "paid_orders": len(paid),
        "revenue": round(sum(order["amount"] for order in paid), 2),
    }


@pipeline(name="daily_orders")
def daily_orders(params: dict | None = None) -> dict:
    day = (params or {}).get("day", "2026-01-01")
    orders = load_orders(day)
    return summarize(orders)

Commit and push it to the default branch, for example main. The repository layout is:

your-repository/
└── pipelines/
    └── daily_orders.py

What the code declares:

  • @pipeline marks the entry point that Vegalake lists and runs. Its name is the name you see in Vegalake.
  • @activity marks a step. Each activity call is recorded, so a failed run can retry a step without repeating the ones that already finished. load_orders retries up to three times.
  • The pipeline takes one optional input, a JSON object. Because the input is optional, the pipeline can run without one.

Step 2: Create the project

Open pipeline projects

In the Build space, open Pipeline projects under Code, then select New project.

Name the project

Enter a Project name, such as Sample orders, and select Create and configure. Vegalake opens the project's Settings tab with a Set up the project card, which walks through the next steps in order.

Step 3: Connect the repository

Repository

For Git connection, choose your Git integration. Enter the Repository (for example acme/sample-orders on GitHub) and the Default branch. An Azure DevOps repository also needs its Repository ID. For other providers' repository formats, read Connect the repository to a pipeline project.

Folders to read

Select + Add a folder, enter pipelines and press Enter. Vegalake only reads these folders for pipelines, models and checks.

First environment

Select + Add an environment. Enter the Name Development and keep the Tracked branch set to your default branch. For Compute, choose your cluster. For Run as, choose the service principal. Leave Writes to empty for now; SQL assets need it later. Then select Add environment.

With the Automatic activation policy, the environment deploys each new valid commit automatically. To approve each deployment first, choose Require approval under Activation policy. You can change it later: on the project's Settings tab, select Edit next to the environment.

Step 4: Sync the first commit

Select Connect and sync. Vegalake connects the repository, adds the folder and the environment, then reads the latest commit on the tracked branch, checks the code and finds its pipelines. It does not run them. When it's done, Vegalake opens the project's Overview.

When the sync finishes, the project's Pipelines tab lists daily_orders. If the sync reports problems, read Troubleshooting.

From now on, every push to the tracked branch is synced: as soon as it's pushed if the Git integration has a webhook, otherwise within a few minutes. To sync straight away, select Sync now on the project's Settings tab.

Step 5: Run the pipeline

Start a run

On the project's Pipelines tab, select Run next to daily_orders, then Run to confirm.

Follow the run

Open the run from the Runs tab. Each step has Log, Inputs and Attempts tabs. The run returns:

{ "orders": 3, "paid_orders": 2, "revenue": 200.25 }

To pass an input, such as {"day": "2026-11-24"}, open the pipeline in the code editor, select Run daily_orders… under Schedules and triggers, enter the Input JSON and select Start execution.

To start a run through the API, send the environment ID. With no version_id, the run uses the version in the environment's active deployment:

POST {api-base}/orgs/{org_id}/workspaces/{workspace_id}/pipelines/{pipeline_id}/executions
Idempotency-Key: 3f1c2a6e-1d1b-4c55-9a43-0f3b8d2e7a10
Content-Type: application/json

{
  "environment_id": "<environment id>",
  "input": { "day": "2026-11-24" }
}

Step 6: Add a schedule (optional)

Schedules live in the code next to the pipeline. Add this to the end of pipelines/daily_orders.py, and add schedule to the from vegaflow import line:

schedule(
    name="every morning",
    pipeline=daily_orders,
    expression="0 6 * * *",
    timezone="UTC",
    overlap_policy="SKIP",
)

Push the change. Once the commit is synced and deployed, the schedule is active in that environment and starts the pipeline at 06:00 UTC every day. overlap_policy="SKIP" skips a start while the previous run is still going. Read Schedules and triggers for pausing schedules and the other policies.

Add SQL assets

A SQL asset is a table or view that Vegalake builds from a SELECT query in your repository. This part of the guide adds two SQL models to the same project: a staging table of orders and a daily revenue table built from it. It also adds a check on the revenue table and a job that builds both.

Choose where the tables are written

SQL assets are written to a build target: a VegaDB warehouse or a PostgreSQL database. Each environment that builds assets writes to one build target.

Create a build target

Open Settings (the gear at the foot of the rail), then Workspace › Git and build targets. On the Build targets tab, select Add build target. The Build targets link at the bottom of the Pipeline projects page opens the same list.

Choose the Type:

  • VegaDB: choose the Catalog, the Warehouse that runs the SQL of each build, and the Databases builds may write to. There is nothing to install and no credential to store.
  • PostgreSQL: enter the Host, Port and Database, the three roles Vegalake uses there, and the Secrets for the publisher and provisioner credentials.

Enter a Name and select Create build target. To create a VegaDB build target from a script, use the API:

POST {api-base}/orgs/{org_id}/workspaces/{workspace_id}/pipeline-build-targets
Content-Type: application/json

{
  "name": "VegaDB main",
  "kind": "VEGADB",
  "vegadb": {
    "catalog_id": "<catalog id>",
    "warehouse_id": "<warehouse id>",
    "databases": ["analytics"]
  }
}

Skip this step if the workspace already has a build target you can use.

Set the environment's Writes to

On the project's Settings tab, select Edit next to the environment. Under Writes to, choose the build target, then select Save environment.

Writes to can't be changed later

Once an environment has a build target, it keeps it. To write somewhere else, add another environment. An environment that writes tables needs a dedicated cluster, and you need permission to use the build target.

Each asset is published under the schema in its name, so sales.daily_revenue becomes the table daily_revenue in the sales schema of the build target. A preview environment writes to its base environment's build target, in its own schemas named after its branch, and never changes the base environment's tables.

Add the models

Add these files to the repository, under the same pipelines root:

pipelines/models/stg_orders.sql
-- vega:model {"name":"sales.stg_orders","materialized":"table","description":"Orders with one row per order."}
SELECT order_id, order_day, amount, status
FROM (
  VALUES
    (1, DATE '2026-01-01', 120.00, 'paid'),
    (2, DATE '2026-01-01', 45.50, 'refunded'),
    (3, DATE '2026-01-02', 80.25, 'paid')
) AS orders (order_id, order_day, amount, status)
pipelines/models/daily_revenue.sql
-- vega:model {"name":"sales.daily_revenue","materialized":"table","description":"Paid revenue per day."}
SELECT order_day, COUNT(*) AS paid_orders, SUM(amount) AS revenue
FROM stg_orders
WHERE status = 'paid'
GROUP BY order_day

What the files declare:

  • The first line of each file is a -- vega:model header with a JSON object. name is the schema-qualified name of the asset and is required.
  • daily_revenue reads from stg_orders, so Vegalake builds stg_orders first. Refer to another model in the same schema by its name, or by {{ ref("stg_orders") }}.
  • In a real project, the staging model reads from a table that a pipeline or a QuickFlow loads, instead of from VALUES.

Add a check

A check is a query that returns the rows that break a rule. The check passes when the query returns no rows. Add:

pipelines/models/revenue_not_negative.check.sql
-- vega:check {"asset":"sales.daily_revenue","description":"Revenue is never negative."}
SELECT order_day, revenue
FROM daily_revenue
WHERE revenue < 0

Check files end in .check.sql, and asset names the asset the check belongs to. A failing check stops the build from publishing that asset. To report a problem without stopping the build, add "severity": "warning" to the header.

Add a job that builds the assets

A job selects which assets to build. Add:

pipelines/sales_build.py
from vegapipelines.jobs import asset_job, select

sales_build = asset_job(
    name="sales_build",
    selection=select("sales.daily_revenue").upstream(),
)

select("sales.daily_revenue").upstream() selects daily_revenue and every model it reads from, here stg_orders.

The repository layout is now:

your-repository/
└── pipelines/
    ├── daily_orders.py
    ├── sales_build.py
    └── models/
        ├── stg_orders.sql
        ├── daily_revenue.sql
        └── revenue_not_negative.check.sql

Build the assets

Push the files. When the commit is synced, the project's Assets tab lists sales.stg_orders and sales.daily_revenue, and the Pipelines tab lists sales_build. Select Run next to sales_build. The run builds stg_orders, then daily_revenue, then runs the check. When it finishes, both tables are in the sales schema of the build target, and the check result is on the asset's Checks tab. You can schedule sales_build the same way as a pipeline.

Model options

Set these in the -- vega:model header:

OptionValues
materializedtable (the default) rebuilds the table on each build. view creates a view. incremental adds or updates rows instead of rebuilding. ephemeral builds nothing and is inlined into the models that read it.
unique_keyFor incremental models, the columns that identify a row, such as ["order_id"]. Rows with the same key are updated.
incremental_strategyupsert (the default, needs unique_key) or append.
description, owners, tagsShown on the asset in Vegalake.

An incremental model limits what it reads on later builds with is_incremental():

pipelines/models/order_events.sql
-- vega:model {"name":"sales.order_events","materialized":"incremental","unique_key":["order_id"]}
SELECT order_id, status, updated_at
FROM raw.order_events
{% if is_incremental() %}
WHERE updated_at >= {{ incremental_watermark("updated_at", lookback="1 day") }}
{% endif %}

raw.order_events stands for a table that already exists on the build target. The first build reads every row. Later builds read only rows changed since the latest updated_at already in the table, minus one day.

Writing your own pipelines

  • Where Vegalake looks: every .py file under a folder you added under Folders to read (a definitions root) is imported. Files directly under the folder import as top-level modules, so pipelines/daily_orders.py is the module daily_orders. Do not name a file after a standard library or installed module, such as json.py or pandas.py. Folders starting with . are skipped.
  • Keep imports quick and quiet: importing a file must only declare things. Do not read data, call services or print at import time. Output written during import is reported as a warning.
  • Put work in activities: reading and writing data, calling APIs and anything slow or random belongs in an @activity. The @pipeline function only calls activities and combines their results, so a run can resume where it stopped.
  • Declare functions at the top level: pipelines and activities cannot be lambdas or nested functions, and cannot take *args or **kwargs.
  • Python packages: code runs on Python 3.13 with a fixed set of packages that includes pandas, polars, pyarrow, DuckDB, NumPy, scikit-learn and openpyxl. Vegalake does not install packages listed in your repository, such as a requirements.txt or pyproject.toml file.
  • Credentials: never commit passwords or tokens. Use connections and Secret vaults, and give the environment's service principal access to them.
  • Settings for each environment: put non-secret settings, such as a warehouse name, in the environment's Configuration instead of in the code. On the project's Settings tab, select Edit next to the environment and open Advanced.

Troubleshooting

ProblemWhat to check
The configured Definitions roots contain no decorated PipelinesNo file under the roots has a @pipeline function. Check the root folder name and that the file is committed on the tracked branch.
Definitions root does not exist in the source artifactThe folder is missing on the tracked branch, or the root path has a typo. Roots are relative to the repository root, without a leading /.
A module failed to importThe file raised an error when imported, often a missing package or a typo. The problem lists the file and line.
Repository module conflicts with a fixed runtime moduleRename the file so it does not share a name with a standard library or installed module.
The environment needs compute and a service principalOn the project's Settings tab, select Edit next to the environment and choose its Compute and Run as. Deployments cannot activate without them.
The sync or run does not startThe environment's cluster must be running. Start it from VegaFlow → Clusters.
A deployment is waiting for approvalThe environment uses Require approval. Approve it on the project's Releases tab.
The Environment has no materialization binding to build intoThe environment has no build target. Set its Writes to on the project's Settings tab.
SQL model requires a schema-qualified nameThe -- vega:model header is missing, or its name has no schema. Use a name such as sales.daily_revenue.
incremental upsert requires unique_keyAdd unique_key to the incremental model, or use "incremental_strategy": "append".
The repository or branch cannot be readRead Connect a Git repository.

Next steps

Vegalake, VegaDB and VegaFlow are trademarks or registered trademarks of Vegalake Inc.

On this page