Programmatically Creating a Build

Some of our clients want to run a Qwak build in a CI/CD script or as a task in Airflow.

You can do it either by creating a bash script and using our CLI in the script or by using the Python API.

In this tutorial, we will show how to create a project and model using Python API. We will also run the model build using Python.

Creating a Project and a Model

First, we have to define a new project and model in the Qwak platform.

Before you run the code shown below, remember to install and configure the Qwak SDK. If you need assistance, take a look at our Getting Started guide.

We must import the ProjectsManagementClient and ModelsManagementClient:

from qwak.projects.client import ProjectsManagementClient
from qwak.models.client import ModelsManagementClient

Now, we create instances of both clients.

projects_client = ProjectsManagementClient()
models_client = ModelsManagementClient()

Using the ProjectsManagementClient, we create a new project. The function will return a Python dictionary containing the project identifier. We are going to need it later.

response = projects_client.create_project('programatic-build', 'this is a description')
project_id = response.project.project_id
models_client.create_model(project_id, 'model-name', 'model description')

Now, we can create the model files and start the build.

Creating Model Configuration

In the next step, we have to create a yaml configuration of the build. You can generate the configuration by adding the --out-conf argument to the qwak models build command.

After generating the configuration, we modify the uri parameter, so it points to the location of your model project. The result may look like this:

    assumed_iam_role_arn: null
    base_image: qwakai/qwak:0.0.13-cpu-py39
    env_vars: []
    no_cache: false
    params: []
    aws_profile: null
    no_push: false
      conda_file: conda.yml
    git_credentials: null
    git_credentials_secret: null
    poetry: null
    qwak_sdk_extra_index_url: null
    virtualenv: null
    is_remote: false
      cpus: 2.0
      gpu_amount: 1
      gpu_type: NVIDIA_K80
      memory: 20Gi
  branch: main
  build_id: null
  model_id: model-name
    git_branch: master
    git_credentials: null
    git_credentials_secret: null
    main_dir: main
      - additional_directory_to_copy_before_build
      - dir_2 
    uri: /home/ml_engineer/the_best_model_ever
  tags: []
post_build: null
pre_build: null

Starting the Build

Finally, we will start the build.

We need two information, the model name you specified earlier and the location of the yaml build configuration.

Let's import the build_cli function:

from import build_cli

and run the build_cli command:

"--model-id", "model-name",
"-f", "absolute_path_to_build_configuration_file"],



Note that we had to specify the model-id (model-name) a few times. If you copy-paste the code from this example, remember to change the identifier everywhere!