Skip to main content

Artifact

Flexible and lightweight building block for dataset and model versioning.

Artifact(
name: str,
type: str,
description: Optional[str] = None,
metadata: Optional[Dict[str, Any]] = None,
incremental: bool = (False),
use_as: Optional[str] = None
) -> None

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 wandb.log_artifact() to log it.

Arguments
nameA 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 the use_artifact Public API. A name can contain letters, numbers, underscores, hyphens, and dots. The name must be unique across a project.
typeThe 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 include dataset or model. Include model within your type string if you want to link the artifact to the W&B Model Registry.
descriptionA 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 the Artifact.description attribute or programmatically with the W&B App UI. W&B renders the description as markdown in the W&B App.
metadataAdditional information about an artifact. Specify metadata as a dictionary of key-value pairs. You can specify no more than 100 total keys.
Returns
An Artifact object.
Attributes
aliasesList 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.
collectionThe 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 the collection that an artifact version originated from. The collection that an artifact originates from is known as the source sequence.
commit_hashThe hash returned when this artifact was committed.
created_atTimestamp when the artifact was created.
descriptionA description of the artifact.
digestThe logical digest of the artifact. The digest is the checksum of the artifact's contents. If an artifact has the same digest as the current latest version, then log_artifact is a no-op.
entityThe name of the entity of the secondary (portfolio) artifact collection.
file_countThe number of files (including references).
idThe artifact's ID.
manifestThe artifact's manifest. The manifest lists all of its contents, and can't be changed once the artifact has been logged.
metadataUser-defined artifact metadata. Structured data associated with the artifact.
nameThe artifact name and version in its secondary (portfolio) collection. A string with the format {collection}:{alias}. Before the artifact is saved, contains only the name since the version is not yet known.
projectThe name of the project of the secondary (portfolio) artifact collection.
qualified_nameThe entity/project/name of the secondary (portfolio) collection.
sizeThe total size of the artifact in bytes. Includes any references tracked by this artifact.
source_collectionThe artifact's primary (sequence) collection.
source_entityThe name of the entity of the primary (sequence) artifact collection.
source_nameThe artifact name and version in its primary (sequence) collection. A string with the format {collection}:{alias}. Before the artifact is saved, contains only the name since the version is not yet known.
source_projectThe name of the project of the primary (sequence) artifact collection.
source_qualified_nameThe entity/project/name of the primary (sequence) collection.
source_versionThe artifact's version in its primary (sequence) collection. A string with the format "v{number}".
stateThe status of the artifact. One of: "PENDING", "COMMITTED", or "DELETED".
ttlThe time-to-live (TTL) policy of an artifact. Artifacts are deleted shortly after a TTL policy's duration passes. If set to None, 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.
typeThe artifact's type. Common types include dataset or model.
updated_atThe time when the artifact was last updated.
versionThe artifact's version in its secondary (portfolio) collection.

Methods

add

View source

add(
obj: data_types.WBValue,
name: StrPath
) -> ArtifactManifestEntry

Add wandb.WBValue obj to the artifact.

Arguments
objThe object to add. Currently support one of Bokeh, JoinedTable, PartitionedTable, Table, Classes, ImageMask, BoundingBoxes2D, Audio, Image, Video, Html, Object3D
nameThe path within the artifact to add the object.
Returns
The added manifest entry
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.

add_dir

View source

add_dir(
local_path: str,
name: Optional[str] = None
) -> None

Add a local directory to the artifact.

Arguments
local_pathThe path of the local directory.
nameThe subdirectory name within an artifact. The name you specify appears in the W&B App UI nested by artifact's type. Defaults to the root of the artifact.
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.

add_file

View source

add_file(
local_path: str,
name: Optional[str] = None,
is_tmp: Optional[bool] = (False)
) -> ArtifactManifestEntry

Add a local file to the artifact.

Arguments
local_pathThe path to the file being added.
nameThe path within the artifact to use for the file being added. Defaults to the basename of the file.
is_tmpIf true, then the file is renamed deterministically to avoid collisions.
Returns
The added manifest entry
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.

add_reference

View source

add_reference(
uri: Union[ArtifactManifestEntry, str],
name: Optional[StrPath] = None,
checksum: bool = (True),
max_objects: Optional[int] = None
) -> Sequence[ArtifactManifestEntry]

Add a reference denoted by a URI to the artifact.

Unlike files or directories that you add to an artifact, references are not uploaded to W&B. For more information, see Track external files.

By default, the following schemes are supported:

  • http(s): The size and digest of the file will be inferred by the Content-Length and the ETag 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.

For any other scheme, the digest is just a hash of the URI and the size is left blank.

Arguments
uriThe URI path of the reference to add. The URI path can be an object returned from Artifact.get_entry to store a reference to another artifact's entry.
nameThe path within the artifact to place the contents of this reference.
checksumWhether or not to checksum the resource(s) located at the reference URI. Checksumming is strongly recommended as it enables automatic integrity validation, however it can be disabled to speed up artifact creation.
max_objectsThe 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 and GCS is 10,000. Other URI schemas do not have a maximum.
Returns
The added manifest entries.
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.

checkout

View source

checkout(
root: Optional[str] = None
) -> str

Replace the specified root directory with the contents of the artifact.

WARNING: This will delete all files in root that are not included in the artifact.

Arguments
rootThe directory to replace with this artifact's files.
Returns
The path of the checked out contents.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

delete

View source

delete(
delete_aliases: bool = (False)
) -> None

Delete an artifact and its files.

Arguments
delete_aliasesIf set to True, deletes all aliases associated with the artifact. Otherwise, this raises an exception if the artifact has existing aliases.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

download

View source

download(
root: Optional[str] = None,
allow_missing_references: bool = (False),
skip_cache: Optional[bool] = None,
path_prefix: Optional[StrPath] = None
) -> FilePathStr

Download the contents of the artifact to the specified root directory.

Existing files located within root are not modified. Explicitly delete root before you call download if you want the contents of root to exactly match the artifact.

Arguments
rootThe directory W&B stores the artifact's files.
allow_missing_referencesIf set to True, any invalid reference paths will be ignored while downloading referenced files.
skip_cacheIf set to True, the artifact cache will be skipped when downloading and W&B will download each file into the default root or specified download directory.
Returns
The path to the downloaded contents.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

file

View source

file(
root: Optional[str] = None
) -> StrPath

Download a single file artifact to the directory you specify with root.

Arguments
rootThe root directory to store the file. Defaults to './artifacts/self.name/'.
Returns
The full path of the downloaded file.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.
ValueErrorIf the artifact contains more than one file.

files

View source

files(
names: Optional[List[str]] = None,
per_page: int = 50
) -> ArtifactFiles

Iterate over all files stored in this artifact.

Arguments
namesThe filename paths relative to the root of the artifact you wish to list.
per_pageThe number of files to return per request.
Returns
An iterator containing File objects.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

finalize

View source

finalize() -> None

Finalize the artifact version.

You cannot modify an artifact version once it is finalized because the artifact is logged as a specific artifact version. Create a new artifact version to log more data to an artifact. An artifact is automatically finalized when you log the artifact with log_artifact.

get

View source

get(
name: str
) -> Optional[data_types.WBValue]

Get the WBValue object located at the artifact relative name.

Arguments
nameThe artifact relative name to retrieve.
Returns
W&B object that can be logged with wandb.log() and visualized in the W&B UI.
Raises
ArtifactNotLoggedErrorif the artifact isn't logged or the run is offline

get_added_local_path_name

View source

get_added_local_path_name(
local_path: str
) -> Optional[str]

Get the artifact relative name of a file added by a local filesystem path.

Arguments
local_pathThe local path to resolve into an artifact relative name.
Returns
The artifact relative name.

get_entry

View source

get_entry(
name: StrPath
) -> ArtifactManifestEntry

Get the entry with the given name.

Arguments
nameThe artifact relative name to get
Returns
A W&B object.
Raises
ArtifactNotLoggedErrorif the artifact isn't logged or the run is offline.
KeyErrorif the artifact doesn't contain an entry with the given name.

get_path

View source

get_path(
name: StrPath
) -> ArtifactManifestEntry

Deprecated. Use get_entry(name).

is_draft

View source

is_draft() -> bool

Check if artifact is not saved.

Returns: Boolean. False if artifact is saved. True if artifact is not saved.

json_encode

View source

json_encode() -> Dict[str, Any]

Returns the artifact encoded to the JSON format.

Returns
A dict with string keys representing attributes of the artifact.

View source

link(
target_path: str,
aliases: Optional[List[str]] = None
) -> None

Link this artifact to a portfolio (a promoted collection of artifacts).

Arguments
target_pathThe 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, set target_path to the following schema {"model-registry"}/{Registered Model Name} or {entity}/{"model-registry"}/{Registered Model Name}.
aliasesA list of strings that uniquely identifies the artifact inside the specified portfolio.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

logged_by

View source

logged_by() -> Optional[Run]

Get the W&B run that originally logged the artifact.

Returns
The name of the W&B run that originally logged the artifact.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

new_draft

View source

new_draft() -> "Artifact"

Create a new draft artifact with the same content as this committed artifact.

The artifact returned can be extended or modified and logged as a new version.

Returns
An Artifact object.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

new_file

View source

@contextlib.contextmanager
new_file(
name: str,
mode: str = "w",
encoding: Optional[str] = None
) -> Generator[IO, None, None]

Open a new temporary file and add it to the artifact.

Arguments
nameThe name of the new file to add to the artifact.
modeThe file access mode to use to open the new file.
encodingThe encoding used to open the new file.
Returns
A new file object that can be written to. Upon closing, the file will be automatically added to the artifact.
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.

path_contains_dir_prefix

View source

@classmethod
path_contains_dir_prefix(
path: StrPath,
dir_path: StrPath
) -> bool

Returns true if path contains dir_path as a prefix.

remove

View source

remove(
item: Union[StrPath, 'ArtifactManifestEntry']
) -> None

Remove an item from the artifact.

Arguments
itemThe 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.
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.
FileNotFoundErrorIf the item isn't found in the artifact.

save

View source

save(
project: Optional[str] = None,
settings: Optional['wandb.wandb_sdk.wandb_settings.Settings'] = None
) -> None

Persist any changes made to the artifact.

If currently in a run, that run will log this artifact. If not currently in a run, a run of type "auto" is created to track this artifact.

Arguments
projectA project to use for the artifact in the case that a run is not already in context.
settingsA settings object to use when initializing an automatic run. Most commonly used in testing harness.

should_download_entry

View source

@classmethod
should_download_entry(
entry: ArtifactManifestEntry,
prefix: Optional[StrPath]
) -> bool

used_by

View source

used_by() -> List[Run]

Get a list of the runs that have used this artifact.

Returns
A list of Run objects.
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.

verify

View source

verify(
root: Optional[str] = None
) -> None

Verify that the contents of an artifact match the manifest.

All files in the directory are checksummed and the checksums are then cross-referenced against the artifact's manifest. References are not verified.

Arguments
rootThe directory to verify. If None artifact will be downloaded to './artifacts/self.name/'
Raises
ArtifactNotLoggedErrorIf the artifact is not logged.
ValueErrorIf the verification fails.

wait

View source

wait(
timeout: Optional[int] = None
) -> "Artifact"

If needed, wait for this artifact to finish logging.

Arguments
timeoutThe time, in seconds, to wait.
Returns
An Artifact object.

__getitem__

View source

__getitem__(
name: str
) -> Optional[data_types.WBValue]

Get the WBValue object located at the artifact relative name.

Arguments
nameThe artifact relative name to get.
Returns
W&B object that can be logged with wandb.log() and visualized in the W&B UI.
Raises
ArtifactNotLoggedErrorIf the artifact isn't logged or the run is offline.

__setitem__

View source

__setitem__(
name: str,
item: data_types.WBValue
) -> ArtifactManifestEntry

Add item to the artifact at path name.

Arguments
nameThe path within the artifact to add the object.
itemThe object to add.
Returns
The added manifest entry
Raises
ArtifactFinalizedErrorYou cannot make changes to the current artifact version because it is finalized. Log a new artifact version instead.
Was this page helpful?👍👎