Documentation
Search…
wandb.apis.public.Artifact
A wandb Artifact.
1
Artifact(
2
client, entity, project, name, attrs=None
3
)
Copied!
An artifact that has been logged, including all its attributes, links to the runs that use it, and a link to the run that logged it.

Examples:

Basic usage
1
api = wandb.Api()
2
artifact = api.artifact('project/artifact:alias')
3
4
# Get information about the artifact...
5
artifact.digest
6
artifact.aliases
Copied!
Updating an artifact
1
artifact = api.artifact('project/artifact:alias')
2
3
# Update the description
4
artifact.description = 'My new description'
5
6
# Selectively update metadata keys
7
artifact.metadata["oldKey"] = "new value"
8
9
# Replace the metadata entirely
10
artifact.metadata = {"newKey": "new value"}
11
12
# Add an alias
13
artifact.aliases.append('best')
14
15
# Remove an alias
16
artifact.aliases.remove('latest')
17
18
# Completely replace the aliases
19
artifact.aliases = ['replaced']
20
21
# Persist all artifact modifications
22
artifact.save()
Copied!
Artifact graph traversal
1
artifact = api.artifact('project/artifact:alias')
2
3
# Walk up and down the graph from an artifact:
4
producer_run = artifact.logged_by()
5
consumer_runs = artifact.used_by()
6
7
# Walk up and down the graph from a run:
8
logged_artifacts = run.logged_artifacts()
9
used_artifacts = run.used_artifacts()
Copied!
Deleting an artifact
1
artifact = api.artifact('project/artifact:alias')
2
artifact.delete()
Copied!
Attributes
Text
aliases
The aliases associated with this artifact.
commit_hash
Returns: (str): The artifact's commit hash which is used in http URLs
created_at
Returns: (datetime): The time at which the artifact was created.
description
Returns: (str): Free text that offers a description of the artifact. The description is markdown rendered in the UI, so this is a good place to put links, etc.
digest
Returns: (str): The artifact's logical digest, a checksum of its contents. If an artifact has the same digest as the current latest version, then log_artifact is a no-op.
entity
Returns: (str): The name of the entity this artifact belongs to.
id
Returns: (str): The artifact's ID
manifest
Returns: (ArtifactManifest): The artifact's manifest, listing all of its contents. You cannot add more files to an artifact once you've retrieved its manifest.
metadata
Returns: (dict): Structured data associated with the artifact, for example class distribution of a dataset. This will eventually be queryable and plottable in the UI. There is a hard limit of 100 total keys.
name
Returns: (str): The artifact's name
project
Returns: (str): The name of the project this artifact belongs to.
size
Returns: (int): The size in bytes of the artifact. Includes any references tracked by this artifact.
state
Returns: (str): The state of the artifact, which can be one of "PENDING", "COMMITTED", or "DELETED".
type
Returns: (str): The artifact's type
updated_at
Returns: (datetime): The time at which the artifact was last updated.
version
Returns: (int): The version of this artifact. For example, if this is the first version of an artifact, its version will be 'v0'.

Methods

add

1
add(
2
obj, name
3
)
Copied!
Adds wandb.WBValue obj to the artifact.
1
obj = artifact.get(name)
Copied!
Arguments
Text
obj
(wandb.WBValue) The object to add. Currently support one of Bokeh, JoinedTable, PartitionedTable, Table, Classes, ImageMask, BoundingBoxes2D, Audio, Image, Video, Html, Object3D
name
(str) The path within the artifact to add the object.
Returns
Text
ArtifactManifestEntry
the added manifest entry

Examples:

Basic usage
1
artifact = wandb.Artifact('my_table', 'dataset')
2
table = wandb.Table(columns=["a", "b", "c"], data=[[i, i*2, 2**i]])
3
artifact.add(table, "my_table")
4
5
wandb.log_artifact(artifact)
Copied!
Retrieving an object:
1
artifact = wandb.use_artifact('my_table:latest')
2
table = artifact.get("my_table")
Copied!

add_dir

1
add_dir(
2
path, name=None
3
)
Copied!
Adds a local directory to the artifact.
Arguments
Text
local_path
(str) The path to the directory being added.
name
(str, optional) The path within the artifact to use for the directory being added. Defaults to files being added under the root of the artifact.

Examples:

Adding a directory without an explicit name:
1
artifact.add_dir('my_dir/') # All files in `my_dir/` are added at the root of the artifact.
Copied!
Adding a directory without an explicit name:
1
artifact.add_dir('my_dir/', path='destination') # All files in `my_dir/` are added under `destination/`.
Copied!
Raises
Text
Exception
if problem.
Returns
Text
None

add_file

1
add_file(
2
local_path, name=None, is_tmp=(False)
3
)
Copied!
Adds a local file to the artifact.
Arguments
Text
local_path
(str) The path to the file being added.
name
(str, optional) The path within the artifact to use for the file being added. Defaults to the basename of the file.
is_tmp
(bool, optional) If true, then the file is renamed deterministically to avoid collisions. (default: False)

Examples:

Adding a file without an explicit name:
1
artifact.add_file('path/to/file.txt') # Added as `file.txt'
Copied!
Adding a file with an explicit name:
1
artifact.add_file('path/to/file.txt', name='new/path/file.txt') # Added as 'new/path/file.txt'
Copied!
Raises
Text
Exception
if problem
Returns
Text
ArtifactManifestEntry
the added manifest entry

add_reference

1
add_reference(
2
uri, name=None, checksum=(True), max_objects=None
3
)
Copied!
Adds a reference denoted by a URI to the artifact. Unlike adding files or directories, references are NOT uploaded to W&B. However, artifact methods such as download() can be used regardless of whether the artifact contains references or uploaded files.
By default, W&B offers special handling for the following schemes:
  • 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 will be pulled from the object metadata. If bucket versioning is enabled, then the version ID is also tracked.
  • gs: The checksum and size will be pulled from the object metadata. If bucket versioning is enabled, then the version ID is also tracked.
  • file: The checksum and size will be 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
Text
uri
(str) The URI path of the reference to add. Can be an object returned from Artifact.get_path to store a reference to another artifact's entry.
name
(str) The path within the artifact to place the contents of this reference
checksum
(bool, optional) Whether 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. (default: True)
max_objects
(int, optional) The maximum number of objects to consider when adding a reference that points to directory or bucket store prefix. For S3 and GCS, this limit is 10,000 by default but is uncapped for other URI schemes. (default: None)
Raises
Text
Exception
If problem.
Returns
Text
List[ArtifactManifestEntry]: The added manifest entries.

Examples:

Adding an HTTP link:
1
# Adds `file.txt` to the root of the artifact as a reference
2
artifact.add_reference('http://myserver.com/file.txt')
Copied!
Adding an S3 prefix without an explicit name:
1
# All objects under `prefix/` will be added at the root of the artifact.
2
artifact.add_reference('s3://mybucket/prefix')
Copied!
Adding a GCS prefix with an explicit name:
1
# All objects under `prefix/` will be added under `path/` at the top of the artifact.
2
artifact.add_reference('gs://mybucket/prefix', name='path')
Copied!

checkout

1
checkout(
2
root=None
3
)
Copied!
Replaces 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
Text
root
(str, optional) The directory to replace with this artifact's files.
Returns
Text
(str): The path to the checked out contents.

delete

1
delete(
2
delete_aliases=(False)
3
)
Copied!
Delete an artifact and its files.

Examples:

Delete all the "model" artifacts a run has logged:
1
runs = api.runs(path="my_entity/my_project")
2
for run in runs:
3
for artifact in run.logged_artifacts():
4
if artifact.type == "model":
5
artifact.delete(delete_aliases=True)
Copied!
Arguments
Text
delete_aliases
(bool) If true, deletes all aliases associated with the artifact. Otherwise, this raises an exception if the artifact has existing alaises.

download

1
download(
2
root=None, recursive=(False)
3
)
Copied!
Downloads the contents of the artifact to the specified root directory.
NOTE: Any existing files at root are left untouched. Explicitly delete root before calling download if you want the contents of root to exactly match the artifact.
Arguments
Text
root
(str, optional) The directory in which to download this artifact's files.
recursive
(bool, optional) If true, then all dependent artifacts are eagerly downloaded. Otherwise, the dependent artifacts are downloaded as needed.
Returns
Text
(str): The path to the downloaded contents.

expected_type

1
@staticmethod
2
expected_type(
3
client, name, entity_name, project_name
4
)
Copied!
Returns the expected type for a given artifact name and project

file

1
file(
2
root=None
3
)
Copied!
Download a single file artifact to dir specified by the
Arguments
Text
root
(str, optional) The root directory in which to place the file. Defaults to './artifacts/<self.name>/'.
Returns
Text
(str): The full path of the downloaded file.

from_id

1
@classmethod
2
from_id(
3
artifact_id, client
4
)
Copied!

get

1
get(
2
name
3
)
Copied!
Gets the WBValue object located at the artifact relative name.
NOTE: This will raise an error unless the artifact has been fetched using use_artifact, fetched using the API, or wait() has been called.
Arguments
Text
name
(str) The artifact relative name to get
Raises
Text
Exception
if problem

Examples:

Basic usage
1
# Run logging the artifact
2
with wandb.init() as r:
3
artifact = wandb.Artifact('my_dataset', type='dataset')
4
table = wandb.Table(columns=["a", "b", "c"], data=[[i, i*2, 2**i]])
5
artifact.add(table, "my_table")
6
wandb.log_artifact(artifact)
7
8
# Run using the artifact
9
with wandb.init() as r:
10
artifact = r.use_artifact('my_dataset:latest')
11
table = r.get('my_table')
Copied!

get_path

1
get_path(
2
name
3
)
Copied!
Gets the path to the file located at the artifact relative name.
NOTE: This will raise an error unless the artifact has been fetched using use_artifact, fetched using the API, or wait() has been called.
Arguments
Text
name
(str) The artifact relative name to get
Raises
Text
Exception
if problem

Examples:

Basic usage
1
# Run logging the artifact
2
with wandb.init() as r:
3
artifact = wandb.Artifact('my_dataset', type='dataset')
4
artifact.add_file('path/to/file.txt')
5
wandb.log_artifact(artifact)
6
7
# Run using the artifact
8
with wandb.init() as r:
9
artifact = r.use_artifact('my_dataset:latest')
10
path = artifact.get_path('file.txt')
11
12
# Can now download 'file.txt' directly:
13
path.download()
Copied!

json_encode

1
json_encode()
Copied!

logged_by

1
logged_by()
Copied!
Retrieves the run which logged this artifact
Returns
Text
Run
Run object which logged this artifact

new_file

1
new_file(
2
name, mode=None
3
)
Copied!
Open a new temporary file that will be automatically added to the artifact.
Arguments
Text
name
(str) The name of the new file being added to the artifact.
mode
(str, optional) The mode in which to open the new file.

Examples:

1
artifact = wandb.Artifact('my_data', type='dataset')
2
with artifact.new_file('hello.txt') as f:
3
f.write('hello!')
4
wandb.log_artifact(artifact)
Copied!
Returns
Text
(file): A new file object that can be written to. Upon closing, the file will be automatically added to the artifact.

save

1
save()
Copied!
Persists artifact changes to the wandb backend.

used_by

1
used_by()
Copied!
Retrieves the runs which use this artifact directly
Returns
Text
[Run]: a list of Run objects which use this artifact

verify

1
verify(
2
root=None
3
)
Copied!
Verify that the actual contents of an artifact at a specified directory root match the expected contents of the artifact according to its manifest.
All files in the directory are checksummed and the checksums are then cross-referenced against the artifact's manifest.
NOTE: References are not verified.
Arguments
Text
root
(str, optional) The directory to verify. If None artifact will be downloaded to './artifacts/<self.name>/'
Raises
Text
(ValueError): If the verification fails.

wait

1
wait()
Copied!
Waits for this artifact to finish logging, if needed.
Returns
Text
Artifact

__getitem__

1
__getitem__(
2
name
3
)
Copied!
Gets the WBValue object located at the artifact relative name.
NOTE: This will raise an error unless the artifact has been fetched using use_artifact, fetched using the API, or wait() has been called.
Arguments
Text
name
(str) The artifact relative name to get
Raises
Text
Exception
if problem

Examples:

Basic usage
1
artifact = wandb.Artifact('my_table', 'dataset')
2
table = wandb.Table(columns=["a", "b", "c"], data=[[i, i*2, 2**i]])
3
artifact["my_table"] = table
4
5
wandb.log_artifact(artifact)
Copied!
Retrieving an object:
1
artifact = wandb.use_artifact('my_table:latest')
2
table = artifact["my_table"]
Copied!
Class Variables
Text
QUERY