Qwak Client Examples
Qwak Client helps you programmatically manage operations on the Qwak platform.
Qwak Client is supported starting
qwak-sdk v0.9.79
. Please follow this installation guide to upgrade.
Overview
Use QwakClient
to programmatically access many of Qwak's functions and operations.
The Qwak client is a wrapper and a single entry point for different Qwak clients such as the BatchClient
, DeploymentClient
, and more.
Builds
get_latest_build
Returns the latest build by its model ID.
Optionally gets a build_status, by default filters on 'SUCCESSFUL'.
Args:
model_id (str)
- The model IDbuild_status (str)
- Build statuses to filter on. Valid values are 'SUCCESSFUL', 'IN_PROGRESS', 'FAILED'.
Returns:
str
- The build ID of the latest build according to the build status. None if no builds match the filter.
from qwak import QwakClient
client = QwakClient()
client.get_latest_build(model_id="model_id")
get_builds_by_tags
Returns a list of builds by a given model ID, filtered by a list of build tags.
Note that the method has several options of filtering builds by tags.
Args:
model_id (str)
- The model IDtags (List[str])
- List of tags to filter bymatch_any (boolean, optional, default=True)
- Setting this to True will return builds with at least one tag from the given filter list of tags. Setting it to False will only return builds where all the tags in the provided list are present.include_extra_tags (boolean, optional, default=True)
- Setting it to True will return builds that match exactly or more tags from the provided list of tags. Setting it to False will return exactly the list of tags included.
Returns:
List[Build]
- Returns a list of builds that contain the requested tags.
from qwak import QwakClient
client = QwakClient()
# 1. Return builds with either "tag_1" or "tag_2" or both "tag_1" and "tag_2".
# The builds may have additional tags not listed in the filter.
client.get_builds_by_tags(model_id="model_id", tags=["tag_1", "tag_2"])
# 2. Return builds with both ["tag1", "tag2"] and optional additional tags.
client.get_builds_by_tags(['tag1', 'tag2'], include_extra_tags=True, match_any=False)
# 3. Return builds strictly with "tag1" and "tag2" and no additional tags.
client.get_builds_by_tags(['tag1', 'tag2'], include_extra_tags=False, match_any=False)
# 4. Return builds with either "tag1" or "tag2" or both, without extra tags.
client.get_builds_by_tags(['tag1', 'tag2'], include_extra_tags=False, match_any=True)
list_builds
List builds by its model ID and explicit filters.
Args
model_id (str)
- The model IDtags (List[str])
- List of tags to filter byfilters (List[str])
- List of metric and parameter filters
Returns
List[Build]
- List of builds that contains the requested filters.
from qwak import QwakClient
client = QwakClient()
client.get_builds_by_tags(model_id="model_id", tags=["tag_1", "tag_2"], filters=[
MetricFilter(metric_name="metric_name", metric_value=0.7,
operator=MetricFilter.operator.METRIC_OPERATOR_TYPE_LESS_THAN),
ParameterFilter(parameter_name="parameter_name", parameter_value="parameter_value",
operator=ParameterFilter.operator.PARAMETER_OPERATOR_TYPE_EQUALS)])
Tags
set_tag
Assign a tag to an existing build.
Args:
build_id (str)
- The build IDtag (str)
- The tag to assign
Returns:
List[Build]
- List of builds that contains the requested filters.
from qwak import QwakClient
client = QwakClient()
client.set_tag(build_id="build_id", tag="tag")
set_tags
Assign a list of tags to an existing build.
Args:
build_id (str)
- The build IDtags (List[str])
- List of tags to assign
Returns:
List[Build]
- List of builds that contains the requested filters.
from qwak import QwakClient
client = QwakClient()
client.set_tag(build_id="build_id", tags=["tag_1", "tag_2"])
Projects
create_project
Create a new project.
Args:
project_name (str)
- The requested nameproject_description (str)
- The requested description
Returns:
str
- The project ID of the newly created project.
from qwak import QwakClient
client = QwakClient()
client.create_project(project_name="project_name", project_description="project_description")
get_project
Get model by its project ID.
Args:
project_id (str)
- The project ID
Returns:
Optional[Project]
- Project by ID.
from qwak import QwakClient
client = QwakClient()
client.get_project(project_id="project_id")
list_projects
List projects.
Returns:
List[Project]
- List of projects.
from qwak import QwakClient
client = QwakClient()
client.list_projects()
delete_project
Delete project by its project ID.
Args:
project_id (str)
- The project ID
from qwak import QwakClient
client = QwakClient()
client.delete_project(project_id="project_id")
Models
create_model
Create a new model.
Args:
project_id (str)
- The project ID to associate the modelmodel_name (str)
- The requested namemodel_description (str)
- The requested description
Returns:
str
- The model ID of the newly created project.
from qwak import QwakClient
client = QwakClient()
client.create_model(project_id="project_id", model_name="model_name", model_description="model_description")
get_model
Get model by its model ID.
Args:
model_id (str)
- The model ID
Returns:
Optional[Model]
- Model by ID.
from qwak import QwakClient
client = QwakClient()
client.get_model(model_id="model_id")
get_model_metadata
Get model metadata by its model ID.
Args:
model_id (str)
- The model ID
Returns:
Optional[ModelMetadata]
- Model metadata by ID.
from qwak import QwakClient
client = QwakClient()
client.get_model_metadata(model_id="model_id")
list_model
Retrieves all models that belong to the project with a given ID.
Args:
project_id (str)
- The project ID
Returns
List[Model]
- a list of models
from qwak import QwakClient
client = QwakClient()
client.list_model(project_id="project_id")
list_model_metadata
Get metadata of all models that belong to the project with a given ID.
Args:
project_id (str)
- The project ID
Returns
List[ModelMetadata]
- a list of ModelMetadata objects
from qwak import QwakClient
client = QwakClient()
client.list_model_metadata(project_id="project_id")
delete_model
Delete model by its project & model ID's.
Args:
project_id (str)
- The project IDmodel_id (str)
- The model ID
from qwak import QwakClient
client = QwakClient()
client.delete_model(project_id="project_id", model_id="model_id")
Deployments
get_deployed_build_id_per_environment
Get deployed build ID per environment by its model ID.
Args:
model_id (str)
- The model ID
Returns:
Dict[str, str]
- Map environment to deployed build ID. None if the model is not deployed.
from qwak import QwakClient
client = QwakClient()
client.get_deployed_build_id_per_environment(model_id="model_id")
Updated about 1 year ago