Qwak Client Examples
Overview
Use QwakClient
to programmatically access many of the JFrog ML functions and operations.
The Qwak client is a wrapper and a single entry point for different JFrog ML clients such as the BatchClient
, DeploymentClient
, and more.
Authentication
get_token
Retrieve a token using an API key or from the default configuration.
This method allows users to retrieve a JFrog ML token via the SDK through the QwakClient. It supports various use cases, including using a pre-configured configuration file, an environment variable, or a specific API key provided as an argument.
Args:
api_key (str, optional)
- The API key for token exchange. If not provided, the method will attempt to fetch the token using other available methods.
Returns:
str
- The build ID of the latest build according to the build status. None if no builds match the filter.
Qwak Configuration File
If the qwak-sdk is already configured, the method fetchs the token from the pre-configured conf file.
from qwak import QwakClient
client = QwakClient()
token = client.get_token()
Environment Variable
The method supports fetching the token from the QWAK_API_KEY
environment variable. Ensure that the environment variable is set before calling the method.
import os
from qwak import QwakClient
os.environ['QWAK_API_KEY'] = 'your_api_key'
client = QwakClient()
token = client.get_token()
Specific API Key
You can directly provide an API key as an argument to fetch the token.
from qwak import QwakClient
client = QwakClient()
token = client.get_token(api_key='your_api_key')
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(model_id="model_id", 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(model_id="model_id", 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(model_id="model_id", tags=['tag1', 'tag2'], include_extra_tags=False, match_any=True)
Advanced filtering
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)])
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()
builds_list = client.list_builds(model_id='your-model-id')
list_file_tags
List file tags by its model ID.
Args:
model_id (str)
- The model IDbuild_id (str, optional, default="")
- The build ID - If not specified, returns all model file tagsfilter (FileTagFilter, optional, default=None)
- Filter the returning list- If not specified, returns all model file tags
- When provided:
value (str)
- Filter valuetype (enum)
- Filter typeFILE_TAG_FILTER_TYPE_CONTAINS
FILE_TAG_FILTER_TYPE_PREFIX
Returns:
List[FileTag]
- List of file tags with their specifications.
from qwak import QwakClient
from qwak.clients.file_versioning.file_tag_filter import FileTagFilter
client = QwakClient()
output = client.list_file_tags(
model_id="model_id",
build_id="build_id",
filter=FileTagFilter(
value="value",
type=FileTagFilter.type.FILE_TAG_FILTER_TYPE_PREFIX
)
)
list_data_tags
List data tags by its model ID.
Args:
model_id (str)
- The model IDbuild_id (str, optional, default="")
- The build ID - If not specified, returns all model data tagsfilter (DataTagFilter, optional, default=None)
- Filter the returning list- If not specified, returns all model file tags
- When provided:
value (str)
- Filter valuetype (enum)
- Filter typeDATA_TAG_FILTER_TYPE_CONTAINS
DATA_TAG_FILTER_TYPE_PREFIX
Returns:
List[DataTag]
- List of data tags with their specifications.
from qwak import QwakClient
from qwak.clients.data_versioning.data_tag_filter import DataTagFilter
client = QwakClient()
output = client.list_data_tags(
model_id="model_id",
build_id="build_id",
filter=DataTagFilter(
value="value",
type=DataTagFilter.type.DATA_TAG_FILTER_TYPE_PREFIX
)
)
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")
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")
list_models
Retrieves all models that belong to the project with the given ID.
Args:
project_id (str)
- the project ID
from qwak import QwakClient
client = QwakClient()
client.list_models(project_id="project_id")
list_model_metadata
Retrieves the metadata of all models that belong to the project with a given ID
Args:
project_id (str)
- the project ID
from qwak import QwakClient
client = QwakClient()
client.list_model_metadata(project_id="project_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")
Batch Executions
list_executions
List batch executions by its model ID
Args:
model_id (str)
- The model IDbuild_id (str, optional, default="")
- The build ID - If not specified, returns all batch executions
Returns:
List[Execution]
- List of executions with their specifications.
from qwak import QwakClient
client = QwakClient()
client.list_executions(model_id="your_model_id", build_id="build_id")
list_execution_tasks
List batch executions tasks by its job ID
Args:
execution_id (str)
- The execution ID
Returns:
List[Task]
- List of execution tasks with their specifications.
from qwak import QwakClient
client = QwakClient()
client.list_execution_tasks(execution_id="execution_id")
Updated 4 months ago