Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk): Add filters to python client. #6748

Merged
merged 3 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion sdk/RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
## Bug Fixes and Other Changes

* Fix placeholder mapping error in v2. [\#6794](https://github.com/kubeflow/pipelines/pull/6794)
* Depends on `kfp-pipeline-spec>=0.1.13,<0.2.0` [\#6803](https://github.com/kubeflow/pipelines/pull/6803)
* Add `OnTransientError` to allowed retry policies [\#6808](https://github.com/kubeflow/pipelines/pull/6808)
* Add optional `filter` argument to list methods of KFP client [\#6748](https://github.com/kubeflow/pipelines/pull/6748)
* Depends on `kfp-pipeline-spec>=0.1.13,<0.2.0` [\#6803](https://github.com/kubeflow/pipelines/pull/6803)

## Documentation Updates

Expand Down
46 changes: 35 additions & 11 deletions sdk/python/kfp/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,8 @@ def list_experiments(self,
page_token='',
page_size=10,
sort_by='',
namespace=None):
namespace=None,
filter=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please document this argument below in the function docstring?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"""List experiments.

Args:
Expand All @@ -516,6 +517,8 @@ def list_experiments(self,
namespace: Kubernetes namespace where the experiment was created.
For single user deployment, leave it as None;
For multi user, input a namespace where the user is authorized.
filter: A url-encoded, JSON-serialized Filter protocol buffer
(see [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto)).

Returns:
A response object including a list of experiments and next page token.
Expand All @@ -527,7 +530,8 @@ def list_experiments(self,
sort_by=sort_by,
resource_reference_key_type=kfp_server_api.models.api_resource_type
.ApiResourceType.NAMESPACE,
resource_reference_key_id=namespace)
resource_reference_key_id=namespace,
filter=filter)
return response

def get_experiment(self,
Expand Down Expand Up @@ -644,19 +648,24 @@ def _override_caching_options(self, workflow: dict, enable_caching: bool):
'pipelines.kubeflow.org/enable_caching'] = str(
enable_caching).lower()

def list_pipelines(self, page_token='', page_size=10, sort_by=''):
def list_pipelines(self, page_token='', page_size=10, sort_by='', filter=None):
"""List pipelines.

Args:
page_token: Token for starting of the page.
page_size: Size of the page.
sort_by: one of 'field_name', 'field_name desc'. For example, 'name desc'.
filter: A url-encoded, JSON-serialized Filter protocol buffer
(see [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto)).

Returns:
A response object including a list of pipelines and next page token.
"""
return self._pipelines_api.list_pipelines(
page_token=page_token, page_size=page_size, sort_by=sort_by)
page_token=page_token,
page_size=page_size,
sort_by=sort_by,
filter=filter)

# TODO: provide default namespace, similar to kubectl default namespaces.
def run_pipeline(
Expand Down Expand Up @@ -1089,7 +1098,8 @@ def list_runs(self,
page_size=10,
sort_by='',
experiment_id=None,
namespace=None):
namespace=None,
filter=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: docstring

"""List runs, optionally can be filtered by experiment or namespace.

Args:
Expand All @@ -1100,6 +1110,8 @@ def list_runs(self,
namespace: Kubernetes namespace to filter upon.
For single user deployment, leave it as None;
For multi user, input a namespace where the user is authorized.
filter: A url-encoded, JSON-serialized Filter protocol buffer
(see [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto)).

Returns:
A response object including a list of experiments and next page token.
Expand All @@ -1112,32 +1124,40 @@ def list_runs(self,
sort_by=sort_by,
resource_reference_key_type=kfp_server_api.models
.api_resource_type.ApiResourceType.EXPERIMENT,
resource_reference_key_id=experiment_id)
resource_reference_key_id=experiment_id,
filter=filter)
elif namespace:
response = self._run_api.list_runs(
page_token=page_token,
page_size=page_size,
sort_by=sort_by,
resource_reference_key_type=kfp_server_api.models
.api_resource_type.ApiResourceType.NAMESPACE,
resource_reference_key_id=namespace)
resource_reference_key_id=namespace,
filter=filter)
else:
response = self._run_api.list_runs(
page_token=page_token, page_size=page_size, sort_by=sort_by)
page_token=page_token,
page_size=page_size,
sort_by=sort_by,
filter=filter)
return response

def list_recurring_runs(self,
page_token='',
page_size=10,
sort_by='',
experiment_id=None):
experiment_id=None,
filter=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

"""List recurring runs.

Args:
page_token: Token for starting of the page.
page_size: Size of the page.
sort_by: One of 'field_name', 'field_name desc'. For example, 'name desc'.
experiment_id: Experiment id to filter upon.
filter: A url-encoded, JSON-serialized Filter protocol buffer
(see [filter.proto](https://github.com/kubeflow/pipelines/blob/master/backend/api/filter.proto)).

Returns:
A response object including a list of recurring_runs and next page token.
Expand All @@ -1149,10 +1169,14 @@ def list_recurring_runs(self,
sort_by=sort_by,
resource_reference_key_type=kfp_server_api.models
.api_resource_type.ApiResourceType.EXPERIMENT,
resource_reference_key_id=experiment_id)
resource_reference_key_id=experiment_id,
filter=filter)
else:
response = self._job_api.list_jobs(
page_token=page_token, page_size=page_size, sort_by=sort_by)
page_token=page_token,
page_size=page_size,
sort_by=sort_by,
filter=filter)
return response

def get_recurring_run(self, job_id):
Expand Down