Skip to content

Commit bf698e7

Browse files
authored
feat: hub service sm session (#4422)
1 parent d5dfe2f commit bf698e7

File tree

2 files changed

+428
-1
lines changed

2 files changed

+428
-1
lines changed

src/sagemaker/session.py

+264-1
Original file line numberDiff line numberDiff line change
@@ -6207,7 +6207,7 @@ def _intercept_create_request(
62076207
self,
62086208
request: typing.Dict,
62096209
create,
6210-
func_name: str = None
6210+
func_name: str = None,
62116211
# pylint: disable=unused-argument
62126212
):
62136213
"""This function intercepts the create job request.
@@ -6470,6 +6470,269 @@ def wait_for_inference_recommendations_job(
64706470
_check_job_status(job_name, desc, "Status")
64716471
return desc
64726472

6473+
def create_hub(
6474+
self,
6475+
hub_name: str,
6476+
hub_description: str,
6477+
hub_display_name: str = None,
6478+
hub_search_keywords: List[str] = None,
6479+
s3_storage_config: Dict[str, Any] = None,
6480+
tags: List[Dict[str, Any]] = None,
6481+
) -> Dict[str, str]:
6482+
"""Creates a SageMaker Hub
6483+
6484+
Args:
6485+
hub_name (str): The name of the Hub to create.
6486+
hub_description (str): A description of the Hub.
6487+
hub_display_name (str): The display name of the Hub.
6488+
hub_search_keywords (list): The searchable keywords for the Hub.
6489+
s3_storage_config (S3StorageConfig): The Amazon S3 storage configuration for the Hub.
6490+
tags (list): Any tags to associate with the Hub.
6491+
6492+
Returns:
6493+
(dict): Return value from the ``CreateHub`` API.
6494+
"""
6495+
request = {"HubName": hub_name, "HubDescription": hub_description}
6496+
if hub_display_name:
6497+
request["HubDisplayName"] = hub_display_name
6498+
if hub_search_keywords:
6499+
request["HubSearchKeywords"] = hub_search_keywords
6500+
if s3_storage_config:
6501+
request["S3StorageConfig"] = s3_storage_config
6502+
if tags:
6503+
request["Tags"] = tags
6504+
6505+
return self.sagemaker_client.create_hub(**request)
6506+
6507+
def describe_hub(self, hub_name: str) -> Dict[str, Any]:
6508+
"""Describes a SageMaker Hub
6509+
6510+
Args:
6511+
hub_name (str): The name of the hub to describe.
6512+
6513+
Returns:
6514+
(dict): Return value for ``DescribeHub`` API
6515+
"""
6516+
request = {"HubName": hub_name}
6517+
6518+
return self.sagemaker_client.describe_hub(**request)
6519+
6520+
def list_hubs(
6521+
self,
6522+
creation_time_after: str = None,
6523+
creation_time_before: str = None,
6524+
max_results: int = None,
6525+
max_schema_version: str = None,
6526+
name_contains: str = None,
6527+
next_token: str = None,
6528+
sort_by: str = None,
6529+
sort_order: str = None,
6530+
) -> Dict[str, Any]:
6531+
"""Lists all existing SageMaker Hubs
6532+
6533+
Args:
6534+
creation_time_after (str): Only list HubContent that was created after
6535+
the time specified.
6536+
creation_time_before (str): Only list HubContent that was created
6537+
before the time specified.
6538+
max_results (int): The maximum amount of HubContent to list.
6539+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6540+
name_contains (str): Only list HubContent if the name contains the specified string.
6541+
next_token (str): If the response to a previous ``ListHubContents`` request was
6542+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6543+
hub content, use the token in the next request.
6544+
sort_by (str): Sort HubContent versions by either name or creation time.
6545+
sort_order (str): Sort Hubs by ascending or descending order.
6546+
Returns:
6547+
(dict): Return value for ``ListHubs`` API
6548+
"""
6549+
request = {}
6550+
if creation_time_after:
6551+
request["CreationTimeAfter"] = creation_time_after
6552+
if creation_time_before:
6553+
request["CreationTimeBefore"] = creation_time_before
6554+
if max_results:
6555+
request["MaxResults"] = max_results
6556+
if max_schema_version:
6557+
request["MaxSchemaVersion"] = max_schema_version
6558+
if name_contains:
6559+
request["NameContains"] = name_contains
6560+
if next_token:
6561+
request["NextToken"] = next_token
6562+
if sort_by:
6563+
request["SortBy"] = sort_by
6564+
if sort_order:
6565+
request["SortOrder"] = sort_order
6566+
6567+
return self.sagemaker_client.list_hubs(**request)
6568+
6569+
def list_hub_contents(
6570+
self,
6571+
hub_name: str,
6572+
hub_content_type: str,
6573+
creation_time_after: str = None,
6574+
creation_time_before: str = None,
6575+
max_results: int = None,
6576+
max_schema_version: str = None,
6577+
name_contains: str = None,
6578+
next_token: str = None,
6579+
sort_by: str = None,
6580+
sort_order: str = None,
6581+
) -> Dict[str, Any]:
6582+
"""Lists the HubContents in a SageMaker Hub
6583+
6584+
Args:
6585+
hub_name (str): The name of the Hub to list the contents of.
6586+
hub_content_type (str): The type of the HubContent to list.
6587+
creation_time_after (str): Only list HubContent that was created after the
6588+
time specified.
6589+
creation_time_before (str): Only list HubContent that was created before the
6590+
time specified.
6591+
max_results (int): The maximum amount of HubContent to list.
6592+
max_schema_version (str): The upper bound of the HubContentSchemaVersion.
6593+
name_contains (str): Only list HubContent if the name contains the specified string.
6594+
next_token (str): If the response to a previous ``ListHubContents`` request was
6595+
truncated, the response includes a ``NextToken``. To retrieve the next set of
6596+
hub content, use the token in the next request.
6597+
sort_by (str): Sort HubContent versions by either name or creation time.
6598+
sort_order (str): Sort Hubs by ascending or descending order.
6599+
Returns:
6600+
(dict): Return value for ``ListHubContents`` API
6601+
"""
6602+
request = {"HubName": hub_name, "HubContentType": hub_content_type}
6603+
if creation_time_after:
6604+
request["CreationTimeAfter"] = creation_time_after
6605+
if creation_time_before:
6606+
request["CreationTimeBefore"] = creation_time_before
6607+
if max_results:
6608+
request["MaxResults"] = max_results
6609+
if max_schema_version:
6610+
request["MaxSchemaVersion"] = max_schema_version
6611+
if name_contains:
6612+
request["NameContains"] = name_contains
6613+
if next_token:
6614+
request["NextToken"] = next_token
6615+
if sort_by:
6616+
request["SortBy"] = sort_by
6617+
if sort_order:
6618+
request["SortOrder"] = sort_order
6619+
6620+
return self.sagemaker_client.list_hub_contents(**request)
6621+
6622+
def delete_hub(self, hub_name: str) -> None:
6623+
"""Deletes a SageMaker Hub
6624+
6625+
Args:
6626+
hub_name (str): The name of the hub to delete.
6627+
"""
6628+
request = {"HubName": hub_name}
6629+
6630+
return self.sagemaker_client.delete_hub(**request)
6631+
6632+
def import_hub_content(
6633+
self,
6634+
document_schema_version: str,
6635+
hub_content_name: str,
6636+
hub_content_type: str,
6637+
hub_name: str,
6638+
hub_content_document: str,
6639+
hub_content_display_name: str = None,
6640+
hub_content_description: str = None,
6641+
hub_content_version: str = None,
6642+
hub_content_markdown: str = None,
6643+
hub_content_search_keywords: List[str] = None,
6644+
tags: List[Dict[str, Any]] = None,
6645+
) -> Dict[str, str]:
6646+
"""Imports a new HubContent into a SageMaker Hub
6647+
6648+
Args:
6649+
document_schema_version (str): The version of the HubContent schema to import.
6650+
hub_content_name (str): The name of the HubContent to import.
6651+
hub_content_version (str): The version of the HubContent to import.
6652+
hub_content_type (str): The type of HubContent to import.
6653+
hub_name (str): The name of the Hub to import content to.
6654+
hub_content_document (str): The hub content document that describes information
6655+
about the hub content such as type, associated containers, scripts, and more.
6656+
hub_content_display_name (str): The display name of the HubContent to import.
6657+
hub_content_description (str): The description of the HubContent to import.
6658+
hub_content_markdown (str): A string that provides a description of the HubContent.
6659+
This string can include links, tables, and standard markdown formatting.
6660+
hub_content_search_keywords (list): The searchable keywords of the HubContent.
6661+
tags (list): Any tags associated with the HubContent.
6662+
Returns:
6663+
(dict): Return value for ``ImportHubContent`` API
6664+
"""
6665+
request = {
6666+
"DocumentSchemaVersion": document_schema_version,
6667+
"HubContentName": hub_content_name,
6668+
"HubContentType": hub_content_type,
6669+
"HubName": hub_name,
6670+
"HubContentDocument": hub_content_document,
6671+
}
6672+
if hub_content_display_name:
6673+
request["HubContentDisplayName"] = hub_content_display_name
6674+
if hub_content_description:
6675+
request["HubContentDescription"] = hub_content_description
6676+
if hub_content_version:
6677+
request["HubContentVersion"] = hub_content_version
6678+
if hub_content_markdown:
6679+
request["HubContentMarkdown"] = hub_content_markdown
6680+
if hub_content_search_keywords:
6681+
request["HubContentSearchKeywords"] = hub_content_search_keywords
6682+
if tags:
6683+
request["Tags"] = tags
6684+
6685+
return self.sagemaker_client.import_hub_content(**request)
6686+
6687+
def describe_hub_content(
6688+
self,
6689+
hub_content_name: str,
6690+
hub_content_type: str,
6691+
hub_name: str,
6692+
hub_content_version: str = None,
6693+
) -> Dict[str, Any]:
6694+
"""Describes a HubContent in a SageMaker Hub
6695+
6696+
Args:
6697+
hub_content_name (str): The name of the HubContent to describe.
6698+
hub_content_type (str): The type of HubContent in the Hub.
6699+
hub_name (str): The name of the Hub that contains the HubContent to describe.
6700+
hub_content_version (str): The version of the HubContent to describe
6701+
6702+
Returns:
6703+
(dict): Return value for ``DescribeHubContent`` API
6704+
"""
6705+
request = {
6706+
"HubContentName": hub_content_name,
6707+
"HubContentType": hub_content_type,
6708+
"HubName": hub_name,
6709+
}
6710+
if hub_content_version:
6711+
request["HubContentVersion"] = hub_content_version
6712+
6713+
return self.sagemaker_client.describe_hub_content(**request)
6714+
6715+
def delete_hub_content(
6716+
self, hub_content_name: str, hub_content_version: str, hub_content_type: str, hub_name: str
6717+
) -> None:
6718+
"""Deletes a given HubContent in a SageMaker Hub
6719+
6720+
Args:
6721+
hub_content_name (str): The name of the content thatyou want to delete from a Hub.
6722+
hub_content_version (str): The version of the content that you want to delete from
6723+
a Hub.
6724+
hub_content_type (str): The type of the content that you want to delete from a Hub.
6725+
hub_name (str): The name of the Hub that you want to delete content in.
6726+
"""
6727+
request = {
6728+
"HubContentName": hub_content_name,
6729+
"HubContentType": hub_content_type,
6730+
"HubName": hub_name,
6731+
"HubContentVersion": hub_content_version,
6732+
}
6733+
6734+
return self.sagemaker_client.delete_hub_content(**request)
6735+
64736736

64746737
def get_model_package_args(
64756738
content_types=None,

0 commit comments

Comments
 (0)