sagemaker.core.lineage.artifact#

This module contains code to create and manage SageMaker Artifact.

Classes

Artifact([sagemaker_session])

An Amazon SageMaker artifact, which is part of a SageMaker lineage.

DatasetArtifact([sagemaker_session])

A SageMaker Lineage artifact representing a dataset.

ImageArtifact([sagemaker_session])

A SageMaker lineage artifact representing an image.

ModelArtifact([sagemaker_session])

A SageMaker lineage artifact representing a model.

class sagemaker.core.lineage.artifact.Artifact(sagemaker_session=None, **kwargs)[source]#

Bases: Record

An Amazon SageMaker artifact, which is part of a SageMaker lineage.

Examples

from sagemaker.lineage import artifact

my_artifact = artifact.Artifact.create(
    artifact_name='MyArtifact',
    artifact_type='S3File',
    source_uri='s3://...')

my_artifact.properties["added"] = "property"
my_artifact.save()

for artfct in artifact.Artifact.list():
    print(artfct)

my_artifact.delete()
artifact_arn#

The ARN of the artifact.

Type:

str

artifact_name#

The name of the artifact.

Type:

str

artifact_type#

The type of the artifact.

Type:

str

source#

The source of the artifact with a URI and types.

Type:

obj

properties#

Dictionary of properties.

Type:

dict

tags#

A list of tags to associate with the artifact.

Type:

List[dict[str, str]]

creation_time#

When the artifact was created.

Type:

datetime

created_by#

Contextual info on which account created the artifact.

Type:

obj

last_modified_time#

When the artifact was last modified.

Type:

datetime

last_modified_by#

Contextual info on which account created the artifact.

Type:

obj

artifact_arn: str = None#
artifact_name: str = None#
artifact_type: str = None#
classmethod create(artifact_name: str | None = None, source_uri: str | None = None, source_types: list | None = None, artifact_type: str | None = None, properties: dict | None = None, tags: dict | None = None, sagemaker_session=None) Artifact[source]#

Create an artifact and return an Artifact object representing it.

Parameters:
  • artifact_name (str, optional) – Name of the artifact

  • source_uri (str, optional) – Source URI of the artifact

  • source_types (list, optional) – Source types

  • artifact_type (str, optional) – Type of the artifact

  • properties (dict, optional) – key/value properties

  • tags (dict, optional) – AWS tags for the artifact

  • sagemaker_session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created using the default AWS configuration chain.

Returns:

A SageMaker Artifact object.

Return type:

Artifact

created_by: str = None#
creation_time: datetime = None#
delete(disassociate: bool = False)[source]#

Delete the artifact object.

Parameters:

disassociate (bool) – When set to true, disassociate incoming and outgoing association.

downstream_trials(sagemaker_session=None) list[source]#

Use the lineage API to retrieve all downstream trials that use this artifact.

Parameters:

sagemaker_session (obj) – Sagemaker Session to use. If not provided a default session will be created.

Returns:

A list of SageMaker Trial objects.

Return type:

[Trial]

downstream_trials_v2() list[source]#

Use a lineage query to retrieve all downstream trials that use this artifact.

Returns:

A list of SageMaker Trial objects.

Return type:

[Trial]

last_modified_by: str = None#
last_modified_time: datetime = None#
classmethod list(source_uri: str | None = None, artifact_type: str | None = None, created_before: datetime | None = None, created_after: datetime | None = None, sort_by: str | None = None, sort_order: str | None = None, max_results: int | None = None, next_token: str | None = None, sagemaker_session=None) Iterator[ArtifactSummary][source]#

Return a list of artifact summaries.

Parameters:
  • source_uri (str, optional) – A source URI.

  • artifact_type (str, optional) – An artifact type.

  • created_before (datetime.datetime, optional) – Return artifacts created before this instant.

  • created_after (datetime.datetime, optional) – Return artifacts created after this instant.

  • sort_by (str, optional) – Which property to sort results by. One of ‘SourceArn’, ‘CreatedBefore’,’CreatedAfter’

  • sort_order (str, optional) – One of ‘Ascending’, or ‘Descending’.

  • max_results (int, optional) – maximum number of artifacts to retrieve

  • next_token (str, optional) – token for next page of results

  • sagemaker_session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created using the default AWS configuration chain.

Returns:

An iterator

over ArtifactSummary objects.

Return type:

collections.Iterator[ArtifactSummary]

classmethod load(artifact_arn: str, sagemaker_session=None) Artifact[source]#

Load an existing artifact and return an Artifact object representing it.

Parameters:
  • artifact_arn (str) – ARN of the artifact

  • sagemaker_session (sagemaker.session.Session) – Session object which manages interactions with Amazon SageMaker APIs and any other AWS services needed. If not specified, one is created using the default AWS configuration chain.

Returns:

A SageMaker Artifact object

Return type:

Artifact

properties: dict = None#
s3_uri_artifacts(s3_uri: str) dict[source]#

Retrieve a list of artifacts that use provided s3 uri.

Parameters:

s3_uri (str) – A S3 URI.

Returns:

A list of Artifacts

save() Artifact[source]#

Save the state of this Artifact to SageMaker.

Note that this method must be run from a SageMaker context such as Studio or a training job due to restrictions on the CreateArtifact API.

Returns:

A SageMaker Artifact object.

Return type:

Artifact

set_tag(tag=None)[source]#

Add a tag to the object.

Parameters:

tag (obj) – Key value pair to set tag.

Returns:

str}): a list of key value pairs

Return type:

list({str

set_tags(tags=None)[source]#

Add tags to the object.

Parameters:

tags (Optional[Tags]) – list of key value pairs.

Returns:

str}): a list of key value pairs

Return type:

list({str

source: ArtifactSource = None#
tags: list = None#
upstream_trials() List[source]#

Use the lineage query to retrieve all upstream trials that use this artifact.

Returns:

A list of SageMaker Trial objects.

Return type:

[Trial]

class sagemaker.core.lineage.artifact.DatasetArtifact(sagemaker_session=None, **kwargs)[source]#

Bases: Artifact

A SageMaker Lineage artifact representing a dataset.

Encapsulates common dataset specific lineage traversals to discover how the dataset is connect to related entities.

downstream_datasets() List[Artifact][source]#

Use the lineage query to retrieve downstream artifacts that use this dataset.

Returns:

Artifacts representing an dataset.

Return type:

list of Artifacts

endpoint_contexts(direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.DESCENDANTS) List[Context][source]#

Get contexts representing endpoints from the dataset’s lineage.

Parameters:

direction (LineageQueryDirectionEnum, optional) – The query direction.

Returns:

Contexts representing an endpoint.

Return type:

list of Contexts

trained_models() List[Association][source]#

Given a dataset artifact, get associated trained models.

Returns:

List of Contexts representing model artifacts.

Return type:

list(Association)

upstream_datasets() List[Artifact][source]#

Use the lineage query to retrieve upstream artifacts that use this dataset artifact.

Returns:

Artifacts representing an dataset.

Return type:

list of Artifacts

class sagemaker.core.lineage.artifact.ImageArtifact(sagemaker_session=None, **kwargs)[source]#

Bases: Artifact

A SageMaker lineage artifact representing an image.

Common model specific lineage traversals to discover how the image is connected to other entities.

datasets(direction: LineageQueryDirectionEnum) List[Artifact][source]#

Use the lineage query to retrieve datasets that use this image artifact.

Parameters:

direction (LineageQueryDirectionEnum) – The query direction.

Returns:

Artifacts representing a dataset.

Return type:

list of Artifacts

class sagemaker.core.lineage.artifact.ModelArtifact(sagemaker_session=None, **kwargs)[source]#

Bases: Artifact

A SageMaker lineage artifact representing a model.

Common model specific lineage traversals to discover how the model is connected to other entities.

dataset_artifacts(direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS) List[Artifact][source]#

Get artifacts representing datasets from the model’s lineage.

Parameters:

direction (LineageQueryDirectionEnum, optional) – The query direction.

Returns:

Artifacts representing a dataset.

Return type:

list of Artifacts

endpoint_contexts(direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.DESCENDANTS) List[Context][source]#

Get contexts representing endpoints from the models’s lineage.

Parameters:

direction (LineageQueryDirectionEnum, optional) – The query direction.

Returns:

Contexts representing an endpoint.

Return type:

list of Contexts

endpoints() list[source]#

Get association summaries for endpoints deployed with this model.

Returns:

A list of associations representing the endpoints using the model.

Return type:

[AssociationSummary]

pipeline_execution_arn(direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS) str[source]#

Get the ARN for the pipeline execution associated with this model (if any).

Returns:

A pipeline execution ARN.

Return type:

str

training_job_arns(direction: LineageQueryDirectionEnum = LineageQueryDirectionEnum.ASCENDANTS) List[str][source]#

Get ARNs for all training jobs that appear in the model’s lineage.

Returns:

Training job ARNs.

Return type:

list of str