Skip to main content

Structure a Bauplan repository

A data platform on Bauplan is made of two kinds of code. Bauplan projects hold the models that run on Bauplan. Client-side code runs on your machine, in CI or in the orchestrator, and creates branches, imports data, submits runs and merges the results.

The basic layout keeps both in one repository. Create one workspace that pins Bauplan once, give each stage of the data lifecycle its own entrypoint, and keep the Bauplan projects inside the stage that runs them, apart from the client-side code. The exact layout depends on your orchestrator, but a structure like this one works in most cases.

    • pyproject.tomldependencies, bauplan included
    • uv.lockexact versions, shared by every entrypoint
      • utilsclient-side helpers: polling, retries, logging
        • main.pyimports new files on a branch, then merges
        • main.pyruns the pipelines on a branch, then merges
            • bauplan_project.yaml
            • models.py
            • expectations.py

Pin Bauplan once for the whole repository

Create a single workspace with uv and add Bauplan to it with uv add bauplan, which pins the latest version in the lockfile.

Do not spread the code across several repositories or virtual environments, each pinning its own Bauplan version. With one workspace and one lockfile, your laptop, CI and the orchestrator run the same Bauplan version and the same dependencies, and an upgrade happens in one place for every entrypoint.

Give each stage an entrypoint

Separate the stages of the data lifecycle, such as ingestion and transformation, into their own folders, and give each stage a main.py entrypoint. In the common case the orchestrator, or you, launches the entrypoint as a command line script. We recommend Typer for that, so arguments such as the pipelines to run or the target branch come from the command line instead of being hardcoded.

Most entrypoints follow the same sequence. They create a timestamped branch, write on it, merge it into main and delete it. For the transformation stage, it looks like this.

src/transformation/main.py
from datetime import UTC, datetime
from pathlib import Path

import bauplan
import typer

PIPELINES_DIR = Path(__file__).parent / "pipelines"


def main(
pipelines: list[str], namespace: str = "orders", base_branch: str = "main", env: str = "prod",
) -> None:
"""Run the pipelines on a fresh branch and publish them with one merge."""

client = bauplan.Client()

# A new branch per run, so that main changes only once every pipeline has succeeded
stamp = datetime.now(UTC).strftime("%Y%m%d%H%M%S")
branch = f"{client.info().user.username}.{namespace}-transformation-{env}-{stamp}"
client.create_branch(branch=branch, from_ref=base_branch)
client.create_namespace(namespace=namespace, branch=branch, if_not_exists=True)

# Run the pipelines one after the other, and stop at the first failure
for pipeline in pipelines:
state = client.run(
project_dir=str(PIPELINES_DIR / pipeline),
ref=branch,
namespace=namespace,
)
if state.job_status != "SUCCESS":
raise RuntimeError(f"{pipeline} failed: {state.error}")

# Publish everything with one merge
client.merge_branch(source_ref=branch, into_branch=base_branch)
client.delete_branch(branch=branch)


if __name__ == "__main__":
typer.run(main)

Each argument of main becomes a command line argument or option, as in

Run the transformation stage
uv run src/transformation/main.py orders --namespace orders

The ingestion entrypoint has the same shape, with a loop over client.import_data calls in place of the runs.