Skip to content

Commit 9e03340

Browse files
evakravibencrabtree
authored andcommitted
feat: hub service sm session (aws#4422)
1 parent 064378d commit 9e03340

File tree

2 files changed

+428
-1
lines changed

2 files changed

+428
-1
lines changed

src/sagemaker/session.py

Lines changed: 264 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6411,7 +6411,7 @@ def _intercept_create_request(
64116411
self,
64126412
request: typing.Dict,
64136413
create,
6414-
func_name: str = None
6414+
func_name: str = None,
64156415
# pylint: disable=unused-argument
64166416
):
64176417
"""This function intercepts the create job request.
@@ -6674,6 +6674,269 @@ def wait_for_inference_recommendations_job(
66746674
_check_job_status(job_name, desc, "Status")
66756675
return desc
66766676

6677+
def create_hub(
6678+
self,
6679+
hub_name: str,
6680+
hub_description: str,
6681+
hub_display_name: str = None,
6682+
hub_search_keywords: List[str] = None,
6683+
s3_storage_config: Dict[str, Any] = None,
6684+
tags: List[Dict[str, Any]] = None,
6685+
) -> Dict[str, str]:
6686+
"""Creates a SageMaker Hub
6687+
6688+
Args:
6689+
hub_name (str): The name of the Hub to create.
6690+
hub_description (str): A description of the Hub.
6691+
hub_display_name (str): The display name of the Hub.
6692+
hub_search_keywords (list): The searchable keywords for the Hub.
6693+
s3_storage_config (S3StorageConfig): The Amazon S3 storage configuration for the Hub.
6694+
tags (list): Any tags to associate with the Hub.
6695+
6696+
Returns:
6697+
(dict): Return value from the ``CreateHub`` API.
6698+
"""
6699+
request = {"HubName": hub_name, "HubDescription": hub_description}
6700+
if hub_display_name:
6701+
request["HubDisplayName"] = hub_display_name
6702+
if hub_search_keywords:
6703+
request["HubSearchKeywords"] = hub_search_keywords
6704+
if s3_storage_config:
6705+
request["S3StorageConfig"] = s3_storage_config
6706+
if tags:
6707+
request["Tags"] = tags
6708+
6709+
return self.sagemaker_client.create_hub(**request)
6710+
6711+
def describe_hub(self, hub_name: str) -> Dict[str, Any]:
6712+
"""Describes a SageMaker Hub
6713+
6714+
Args:
6715+
hub_name (str): The name of the hub to describe.
6716+
6717+
Returns:
6718+
(dict): Return value for ``DescribeHub`` API
6719+
"""
6720+
request = {"HubName": hub_name}
6721+
6722+
return self.sagemaker_client.describe_hub(**request)
6723+
6724+
def list_hubs(
6725+
self,
6726+
creation_time_after: str = None,
6727+
creation_time_before: str = None,
6728+
max_results: int = None,
6729+
max_schema_version: str = None,
6730+
name_contains: str = None,
6731+
next_token: str = None,
6732+
sort_by: str = None,
6733+
sort_order: str = None,
6734+
) -> Dict[str, Any]:
6735+
"""Lists all existing SageMaker Hubs
6736+
6737+
Args:
6738+
creation_time_after (str): Only list HubContent that was created after
6739+
the time specified.
6740+
creation_time_before (str): Only list HubContent that was created
6741+
before the time specified.
6742+
max_results (int): The maximum amount of HubContent to list.
6743+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6744+
name_contains (str): Only list HubContent if the name contains the specified string.
6745+
next_token (str): If the response to a previous ``ListHubContents`` request was
6746+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6747+
hub content, use the token in the next request.
6748+
sort_by (str): Sort HubContent versions by either name or creation time.
6749+
sort_order (str): Sort Hubs by ascending or descending order.
6750+
Returns:
6751+
(dict): Return value for ``ListHubs`` API
6752+
"""
6753+
request = {}
6754+
if creation_time_after:
6755+
request["CreationTimeAfter"] = creation_time_after
6756+
if creation_time_before:
6757+
request["CreationTimeBefore"] = creation_time_before
6758+
if max_results:
6759+
request["MaxResults"] = max_results
6760+
if max_schema_version:
6761+
request["MaxSchemaVersion"] = max_schema_version
6762+
if name_contains:
6763+
request["NameContains"] = name_contains
6764+
if next_token:
6765+
request["NextToken"] = next_token
6766+
if sort_by:
6767+
request["SortBy"] = sort_by
6768+
if sort_order:
6769+
request["SortOrder"] = sort_order
6770+
6771+
return self.sagemaker_client.list_hubs(**request)
6772+
6773+
def list_hub_contents(
6774+
self,
6775+
hub_name: str,
6776+
hub_content_type: str,
6777+
creation_time_after: str = None,
6778+
creation_time_before: str = None,
6779+
max_results: int = None,
6780+
max_schema_version: str = None,
6781+
name_contains: str = None,
6782+
next_token: str = None,
6783+
sort_by: str = None,
6784+
sort_order: str = None,
6785+
) -> Dict[str, Any]:
6786+
"""Lists the HubContents in a SageMaker Hub
6787+
6788+
Args:
6789+
hub_name (str): The name of the Hub to list the contents of.
6790+
hub_content_type (str): The type of the HubContent to list.
6791+
creation_time_after (str): Only list HubContent that was created after the
6792+
time specified.
6793+
creation_time_before (str): Only list HubContent that was created before the
6794+
time specified.
6795+
max_results (int): The maximum amount of HubContent to list.
6796+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6797+
name_contains (str): Only list HubContent if the name contains the specified string.
6798+
next_token (str): If the response to a previous ``ListHubContents`` request was
6799+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6800+
hub content, use the token in the next request.
6801+
sort_by (str): Sort HubContent versions by either name or creation time.
6802+
sort_order (str): Sort Hubs by ascending or descending order.
6803+
Returns:
6804+
(dict): Return value for ``ListHubContents`` API
6805+
"""
6806+
request = {"HubName": hub_name, "HubContentType": hub_content_type}
6807+
if creation_time_after:
6808+
request["CreationTimeAfter"] = creation_time_after
6809+
if creation_time_before:
6810+
request["CreationTimeBefore"] = creation_time_before
6811+
if max_results:
6812+
request["MaxResults"] = max_results
6813+
if max_schema_version:
6814+
request["MaxSchemaVersion"] = max_schema_version
6815+
if name_contains:
6816+
request["NameContains"] = name_contains
6817+
if next_token:
6818+
request["NextToken"] = next_token
6819+
if sort_by:
6820+
request["SortBy"] = sort_by
6821+
if sort_order:
6822+
request["SortOrder"] = sort_order
6823+
6824+
return self.sagemaker_client.list_hub_contents(**request)
6825+
6826+
def delete_hub(self, hub_name: str) -> None:
6827+
"""Deletes a SageMaker Hub
6828+
6829+
Args:
6830+
hub_name (str): The name of the hub to delete.
6831+
"""
6832+
request = {"HubName": hub_name}
6833+
6834+
return self.sagemaker_client.delete_hub(**request)
6835+
6836+
def import_hub_content(
6837+
self,
6838+
document_schema_version: str,
6839+
hub_content_name: str,
6840+
hub_content_type: str,
6841+
hub_name: str,
6842+
hub_content_document: str,
6843+
hub_content_display_name: str = None,
6844+
hub_content_description: str = None,
6845+
hub_content_version: str = None,
6846+
hub_content_markdown: str = None,
6847+
hub_content_search_keywords: List[str] = None,
6848+
tags: List[Dict[str, Any]] = None,
6849+
) -> Dict[str, str]:
6850+
"""Imports a new HubContent into a SageMaker Hub
6851+
6852+
Args:
6853+
document_schema_version (str): The version of the HubContent schema to import.
6854+
hub_content_name (str): The name of the HubContent to import.
6855+
hub_content_version (str): The version of the HubContent to import.
6856+
hub_content_type (str): The type of HubContent to import.
6857+
hub_name (str): The name of the Hub to import content to.
6858+
hub_content_document (str): The hub content document that describes information
6859+
about the hub content such as type, associated containers, scripts, and more.
6860+
hub_content_display_name (str): The display name of the HubContent to import.
6861+
hub_content_description (str): The description of the HubContent to import.
6862+
hub_content_markdown (str): A string that provides a description of the HubContent.
6863+
This string can include links, tables, and standard markdown formatting.
6864+
hub_content_search_keywords (list): The searchable keywords of the HubContent.
6865+
tags (list): Any tags associated with the HubContent.
6866+
Returns:
6867+
(dict): Return value for ``ImportHubContent`` API
6868+
"""
6869+
request = {
6870+
"DocumentSchemaVersion": document_schema_version,
6871+
"HubContentName": hub_content_name,
6872+
"HubContentType": hub_content_type,
6873+
"HubName": hub_name,
6874+
"HubContentDocument": hub_content_document,
6875+
}
6876+
if hub_content_display_name:
6877+
request["HubContentDisplayName"] = hub_content_display_name
6878+
if hub_content_description:
6879+
request["HubContentDescription"] = hub_content_description
6880+
if hub_content_version:
6881+
request["HubContentVersion"] = hub_content_version
6882+
if hub_content_markdown:
6883+
request["HubContentMarkdown"] = hub_content_markdown
6884+
if hub_content_search_keywords:
6885+
request["HubContentSearchKeywords"] = hub_content_search_keywords
6886+
if tags:
6887+
request["Tags"] = tags
6888+
6889+
return self.sagemaker_client.import_hub_content(**request)
6890+
6891+
def describe_hub_content(
6892+
self,
6893+
hub_content_name: str,
6894+
hub_content_type: str,
6895+
hub_name: str,
6896+
hub_content_version: str = None,
6897+
) -> Dict[str, Any]:
6898+
"""Describes a HubContent in a SageMaker Hub
6899+
6900+
Args:
6901+
hub_content_name (str): The name of the HubContent to describe.
6902+
hub_content_type (str): The type of HubContent in the Hub.
6903+
hub_name (str): The name of the Hub that contains the HubContent to describe.
6904+
hub_content_version (str): The version of the HubContent to describe
6905+
6906+
Returns:
6907+
(dict): Return value for ``DescribeHubContent`` API
6908+
"""
6909+
request = {
6910+
"HubContentName": hub_content_name,
6911+
"HubContentType": hub_content_type,
6912+
"HubName": hub_name,
6913+
}
6914+
if hub_content_version:
6915+
request["HubContentVersion"] = hub_content_version
6916+
6917+
return self.sagemaker_client.describe_hub_content(**request)
6918+
6919+
def delete_hub_content(
6920+
self, hub_content_name: str, hub_content_version: str, hub_content_type: str, hub_name: str
6921+
) -> None:
6922+
"""Deletes a given HubContent in a SageMaker Hub
6923+
6924+
Args:
6925+
hub_content_name (str): The name of the content thatyou want to delete from a Hub.
6926+
hub_content_version (str): The version of the content that you want to delete from
6927+
a Hub.
6928+
hub_content_type (str): The type of the content that you want to delete from a Hub.
6929+
hub_name (str): The name of the Hub that you want to delete content in.
6930+
"""
6931+
request = {
6932+
"HubContentName": hub_content_name,
6933+
"HubContentType": hub_content_type,
6934+
"HubName": hub_name,
6935+
"HubContentVersion": hub_content_version,
6936+
}
6937+
6938+
return self.sagemaker_client.delete_hub_content(**request)
6939+
66776940

66786941
def get_model_package_args(
66796942
content_types=None,

0 commit comments

Comments
 (0)