class Artifact
Flexible and lightweight building block for dataset and model versioning.
Construct an empty W&B Artifact. Populate an artifacts contents with methods that begin with add
. Once the artifact has all the desired files, you can call run.log_artifact()
to log it.
method Artifact.__init__
name
(str): A human-readable name for the artifact. Use the name to identify a specific artifact in the W&B App UI or programmatically. You can interactively reference an artifact with theuse_artifact
Public API. A name can contain letters, numbers, underscores, hyphens, and dots. The name must be unique across a project.type
(str): The artifact’s type. Use the type of an artifact to both organize and differentiate artifacts. You can use any string that contains letters, numbers, underscores, hyphens, and dots. Common types includedataset
ormodel
. Includemodel
within your type string if you want to link the artifact to the W&B Model Registry. Note that some types reserved for internal use and cannot be set by users. Such types includejob
and types that start withwandb-
.description (str | None) = None
: A description of the artifact. For Model or Dataset Artifacts, add documentation for your standardized team model or dataset card. View an artifact’s description programmatically with theArtifact.description
attribute or programmatically with the W&B App UI. W&B renders the description as markdown in the W&B App.metadata (dict[str, Any] | None) = None
: Additional information about an artifact. Specify metadata as a dictionary of key-value pairs. You can specify no more than 100 total keys.incremental
: UseArtifact.new_draft()
method instead to modify an existing artifact.use_as
: Deprecated.is_link
: Boolean indication of if the artifact is a linked artifact(True
) or source artifact(False
).
Artifact
object.
property Artifact.aliases
List of one or more semantically-friendly references or identifying “nicknames” assigned to an artifact version. Aliases are mutable references that you can programmatically reference. Change an artifact’s alias with the W&B App UI or programmatically. See Create new artifact versions for more information. Returns:list[str]
: The aliases property value.
property Artifact.collection
The collection this artifact was retrieved from. A collection is an ordered group of artifact versions. If this artifact was retrieved from a portfolio / linked collection, that collection will be returned rather than the collection that an artifact version originated from. The collection that an artifact originates from is known as the source sequence. Returns:ArtifactCollection
: The collection property value.
property Artifact.commit_hash
The hash returned when this artifact was committed. Returns:str
: The commit_hash property value.
property Artifact.created_at
Timestamp when the artifact was created. Returns:str
: The created_at property value.
property Artifact.description
A description of the artifact. Returns:str | None
: The description property value.
property Artifact.digest
The logical digest of the artifact. The digest is the checksum of the artifact’s contents. If an artifact has the same digest as the currentlatest
version, then log_artifact
is a no-op.
Returns:
str
: The digest property value.
property Artifact.entity
The name of the entity that the artifact collection belongs to. If the artifact is a link, the entity will be the entity of the linked artifact. Returns:str
: The entity property value.
property Artifact.file_count
The number of files (including references). Returns:int
: The file_count property value.
property Artifact.history_step
The nearest step at which history metrics were logged for the source run of the artifact. Examples:int | None
: The history_step property value.
property Artifact.id
The artifact’s ID. Returns:str | None
: The id property value.
property Artifact.is_link
Boolean flag indicating if the artifact is a link artifact. True: The artifact is a link artifact to a source artifact. False: The artifact is a source artifact. Returns:bool
: The is_link property value.
property Artifact.linked_artifacts
Returns a list of all the linked artifacts of a source artifact. If the artifact is a link artifact (artifact.is_link == True
), it will return an empty list. Limited to 500 results.
Returns:
list[Artifact]
: The linked_artifacts property value.
property Artifact.manifest
The artifact’s manifest. The manifest lists all of its contents, and can’t be changed once the artifact has been logged. Returns:ArtifactManifest
: The manifest property value.
property Artifact.metadata
User-defined artifact metadata. Structured data associated with the artifact. Returns:dict
: The metadata property value.
property Artifact.name
The artifact name and version of the artifact. A string with the format{collection}:{alias}
. If fetched before an artifact is logged/saved, the name won’t contain the alias. If the artifact is a link, the name will be the name of the linked artifact.
Returns:
str
: The name property value.
property Artifact.project
The name of the project that the artifact collection belongs to. If the artifact is a link, the project will be the project of the linked artifact. Returns:str
: The project property value.
property Artifact.qualified_name
The entity/project/name of the artifact. If the artifact is a link, the qualified name will be the qualified name of the linked artifact path. Returns:str
: The qualified_name property value.
property Artifact.size
The total size of the artifact in bytes. Includes any references tracked by this artifact. Returns:int
: The size property value.
property Artifact.source_artifact
Returns the source artifact. The source artifact is the original logged artifact. If the artifact itself is a source artifact (artifact.is_link == False
), it will return itself.
Returns:
Artifact
: The source_artifact property value.
property Artifact.source_collection
The artifact’s source collection. The source collection is the collection that the artifact was logged from. Returns:ArtifactCollection
: The source_collection property value.
property Artifact.source_entity
The name of the entity of the source artifact. Returns:str
: The source_entity property value.
property Artifact.source_name
The artifact name and version of the source artifact. A string with the format{source_collection}:{alias}
. Before the artifact is saved, contains only the name since the version is not yet known.
Returns:
str
: The source_name property value.
property Artifact.source_project
The name of the project of the source artifact. Returns:str
: The source_project property value.
property Artifact.source_qualified_name
The source_entity/source_project/source_name of the source artifact. Returns:str
: The source_qualified_name property value.
property Artifact.source_version
The source artifact’s version. A string with the formatv{number}
.
Returns:
str
: The source_version property value.
property Artifact.state
The status of the artifact. One of: “PENDING”, “COMMITTED”, or “DELETED”. Returns:str
: The state property value.
property Artifact.tags
List of one or more tags assigned to this artifact version. Returns:list[str]
: The tags property value.
property Artifact.ttl
The time-to-live (TTL) policy of an artifact. Artifacts are deleted shortly after a TTL policy’s duration passes. If set toNone
, the artifact deactivates TTL policies and will be not scheduled for deletion, even if there is a team default TTL. An artifact inherits a TTL policy from the team default if the team administrator defines a default TTL and there is no custom policy set on an artifact.
Raises:
ArtifactNotLoggedError
: Unable to fetch inherited TTL if the artifact has not been logged or saved.
timedelta | None
: The ttl property value.
property Artifact.type
The artifact’s type. Common types includedataset
or model
.
Returns:
str
: The type property value.
property Artifact.updated_at
The time when the artifact was last updated. Returns:str
: The updated_at property value.
property Artifact.url
Constructs the URL of the artifact. Returns:str
: The URL of the artifact.
str
: The url property value.
property Artifact.use_as
Deprecated. Returns:str | None
: The use_as property value.
property Artifact.version
The artifact’s version. A string with the formatv{number}
. If the artifact is a link artifact, the version will be from the linked collection.
Returns:
str
: The version property value.
method Artifact.add
obj
to the artifact.
Args:
obj
: The object to add. Currently support one of Bokeh, JoinedTable, PartitionedTable, Table, Classes, ImageMask, BoundingBoxes2D, Audio, Image, Video, Html, Object3Dname
: The path within the artifact to add the object.overwrite
: If True, overwrite existing objects with the same file path if applicable.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.
method Artifact.add_dir
local_path
: The path of the local directory.name
: The subdirectory name within an artifact. The name you specify appears in the W&B App UI nested by artifact’stype
. Defaults to the root of the artifact.skip_cache
: If set toTrue
, W&B will not copy/move files to the cache while uploadingpolicy
: By default, “mutable”.- mutable: Create a temporary copy of the file to prevent corruption during upload.
- immutable: Disable protection, rely on the user not to delete or change the file.
merge
: IfFalse
(default), throws ValueError if a file was already added in a previous add_dir call and its content has changed. IfTrue
, overwrites existing files with changed content. Always adds new files and never removes files. To replace an entire directory, pass a name when adding the directory usingadd_dir(local_path, name=my_prefix)
and callremove(my_prefix)
to remove the directory, then add it again.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.ValueError
: Policy must be “mutable” or “immutable”
method Artifact.add_file
local_path
: The path to the file being added.name
: The path within the artifact to use for the file being added. Defaults to the basename of the file.is_tmp
: If true, then the file is renamed deterministically to avoid collisions.skip_cache
: IfTrue
, do not copy files to the cache after uploading.policy
: By default, set to “mutable”. If set to “mutable”, create a temporary copy of the file to prevent corruption during upload. If set to “immutable”, disable protection and rely on the user not to delete or change the file.overwrite
: IfTrue
, overwrite the file if it already exists.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.ValueError
: Policy must be “mutable” or “immutable”
method Artifact.add_reference
- http(s): The size and digest of the file will be inferred by the
Content-Length
and theETag
response headers returned by the server. - s3: The checksum and size are pulled from the object metadata. If bucket versioning is enabled, then the version ID is also tracked.
- gs: The checksum and size are pulled from the object metadata. If bucket versioning is enabled, then the version ID is also tracked.
- https, domain matching
*.blob.core.windows.net
- Azure: The checksum and size are be pulled from the blob metadata. If storage account versioning is enabled, then the version ID is also tracked.
- file: The checksum and size are pulled from the file system. This scheme is useful if you have an NFS share or other externally mounted volume containing files you wish to track but not necessarily upload.
uri
: The URI path of the reference to add. The URI path can be an object returned fromArtifact.get_entry
to store a reference to another artifact’s entry.name
: The path within the artifact to place the contents of this reference.checksum
: Whether or not to checksum the resource(s) located at the reference URI. Checksumming is strongly recommended as it enables automatic integrity validation. Disabling checksumming will speed up artifact creation but reference directories will not iterated through so the objects in the directory will not be saved to the artifact. We recommend settingchecksum=False
when adding reference objects, in which case a new version will only be created if the reference URI changes.max_objects
: The maximum number of objects to consider when adding a reference that points to directory or bucket store prefix. By default, the maximum number of objects allowed for Amazon S3, GCS, Azure, and local files is 10,000,000. Other URI schemas do not have a maximum.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.
method Artifact.checkout
root
that are not included in the artifact.
Args:
root
: The directory to replace with this artifact’s files.
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.delete
artifact.unlink()
instead of artifact.delete()
to remove a link between a source artifact and a linked artifact.
Args:
delete_aliases
: If set toTrue
, deletes all aliases associated with the artifact. Otherwise, this raises an exception if the artifact has existing aliases. This parameter is ignored if the artifact is linked (a member of a portfolio collection).
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.download
root
are not modified. Explicitly delete root
before you call download
if you want the contents of root
to exactly match the artifact.
Args:
root
: The directory W&B stores the artifact’s files.allow_missing_references
: If set toTrue
, any invalid reference paths will be ignored while downloading referenced files.skip_cache
: If set toTrue
, the artifact cache will be skipped when downloading and W&B will download each file into the default root or specified download directory.path_prefix
: If specified, only files with a path that starts with the given prefix will be downloaded. Uses unix format (forward slashes).multipart
: If set toNone
(default), the artifact will be downloaded in parallel using multipart download if individual file size is greater than 2GB. If set toTrue
orFalse
, the artifact will be downloaded in parallel or serially regardless of the file size.
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.file
root
.
Args:
root
: The root directory to store the file. Defaults to./artifacts/self.name/
.
ArtifactNotLoggedError
: If the artifact is not logged.ValueError
: If the artifact contains more than one file.
method Artifact.files
names
: The filename paths relative to the root of the artifact you wish to list.per_page
: The number of files to return per request.
File
objects.
Raises:
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.finalize
log_artifact
.
method Artifact.get
name
.
Args:
name
: The artifact relative name to retrieve.
run.log()
and visualized in the W&B UI.
Raises:
ArtifactNotLoggedError
: if the artifact isn’t logged or the run is offline.
method Artifact.get_added_local_path_name
local_path
: The local path to resolve into an artifact relative name.
method Artifact.get_entry
name
: The artifact relative name to get
W&B
object.
Raises:
ArtifactNotLoggedError
: if the artifact isn’t logged or the run is offline.KeyError
: if the artifact doesn’t contain an entry with the given name.
method Artifact.get_path
get_entry(name)
.
method Artifact.is_draft
False
if artifact is saved. True
if artifact is not saved.
method Artifact.json_encode
dict
with string
keys representing attributes of the artifact.
method Artifact.link
target_path
: The path to the portfolio inside a project. The target path must adhere to one of the following schemas{portfolio}
,{project}/{portfolio}
or{entity}/{project}/{portfolio}
. To link the artifact to the Model Registry, rather than to a generic portfolio inside a project, settarget_path
to the following schema{"model-registry"}/{Registered Model Name}
or{entity}/{"model-registry"}/{Registered Model Name}
.aliases
: A list of strings that uniquely identifies the artifact inside the specified portfolio.
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.logged_by
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.new_draft
Artifact
object.
Raises:
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.new_file
name
: The name of the new file to add to the artifact.mode
: The file access mode to use to open the new file.encoding
: The encoding used to open the new file.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.
method Artifact.remove
item
: The item to remove. Can be a specific manifest entry or the name of an artifact-relative path. If the item matches a directory all items in that directory will be removed.
ArtifactFinalizedError
: You cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.FileNotFoundError
: If the item isn’t found in the artifact.
method Artifact.save
project
: A project to use for the artifact in the case that a run is not already in context.settings
: A settings object to use when initializing an automatic run. Most commonly used in testing harness.
method Artifact.unlink
ArtifactNotLoggedError
: If the artifact is not logged.ValueError
: If the artifact is not linked, in other words, it is not a member of a portfolio collection.
method Artifact.used_by
Run
objects.
Raises:
ArtifactNotLoggedError
: If the artifact is not logged.
method Artifact.verify
root
: The directory to verify. If None artifact will be downloaded to ’./artifacts/self.name/’.
ArtifactNotLoggedError
: If the artifact is not logged.ValueError
: If the verification fails.
method Artifact.wait
timeout
: The time, in seconds, to wait.
Artifact
object.