> ## Documentation Index
> Fetch the complete documentation index at: https://wb-21fd5541-sdk-testing-latest.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Run

export const GitHubLink = ({url}) => <a href={url} target="_blank" rel="noopener noreferrer" className="github-source-link">
    <svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
      <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z" />
    </svg>
    GitHub source
  </a>;

<GitHubLink url="https://github.com/wandb/wandb/blob/main/wandb/apis/public/runs.py#L595" />

## <kbd>class</kbd> Run

```python theme={null}
(service_api: 'ServiceApi',
entity: 'str',
project: 'str',
run_id: 'str',
attrs: 'Mapping | None' = None,
include_sweeps: 'bool' = False,
lazy: 'bool' = True,
api_key: 'str | None' = None)
```

## Description

A single run associated with an entity and project.

## Args

* `service_api`: Interface to the wandb-core service that performs W\&B API calls for this run.
* `entity`: the name of the entity associated with the run
* `project`: the project associated with the run
* `run_id`: The unique identifier for the run.
* `attrs`: The attributes of the run.
* `include_sweeps`: Whether to include sweeps in the run.
* `lazy`:
* `api_key`:

## Properties

### <kbd>property</kbd> state

The state of the run.

The following table describes the possible states a run can be in:

| State    | Description                                                                                      |
| -------- | ------------------------------------------------------------------------------------------------ |
| Crashed  | Run stopped sending heartbeats in the internal process, which can happen if the machine crashes. |
| Failed   | Run ended with a non-zero exit status.                                                           |
| Finished | Run ended and fully synced data, or called `wandb.Run.finish()`.                                 |
| Killed   | Run was forcibly stopped before it could finish.                                                 |
| Running  | Run is still running and has recently sent a heartbeat.                                          |
| Pending  | Run is scheduled but not yet started (common in sweeps and Launch jobs).                         |

### <kbd>property</kbd> entity

The entity associated with the run.

### <kbd>property</kbd> username

This API is deprecated. Use `entity` instead.

### <kbd>property</kbd> storage\_id

The unique storage identifier for the run.

### <kbd>property</kbd> id

The unique identifier for the run.

### <kbd>property</kbd> name

The name of the run.

### <kbd>property</kbd> config

Get run config. Auto-loads full data if in lazy mode.

### <kbd>property</kbd> summary

Get run summary metrics. Auto-loads full data if in lazy mode.

### <kbd>property</kbd> system\_metrics

Get run system metrics. Auto-loads full data if in lazy mode.

### <kbd>property</kbd> summary\_metrics

Get run summary metrics. Auto-loads full data if in lazy mode.

### <kbd>property</kbd> rawconfig

Get raw run config including internal keys. Auto-loads full data if in lazy mode.

### <kbd>property</kbd> sweep\_name

Get sweep name. Always available since sweepName is in lightweight fragment.

### <kbd>property</kbd> sweep

The sweep associated with this run. Loads sweep data if include\_sweeps is False.

### <kbd>property</kbd> path

The path of the run. The path is a list containing the entity, project, and run\_id.

### <kbd>property</kbd> url

The URL of the run.

The run URL is generated from the entity, project, and run\_id. For
SaaS users, it takes the form of `https://wandb.ai/entity/project/run_id`.

### <kbd>property</kbd> metadata

Metadata about the run from wandb-metadata.json.

Metadata includes the run's description, tags, start time, memory
usage and more.

### <kbd>property</kbd> lastHistoryStep

Returns the last step logged in the run's history.

## Methods

### <kbd>method</kbd> beta\_scan\_history

```python theme={null}
self,
keys: 'list[str] | None' = None,
page_size: 'int' = 1000,
min_step: 'int' = 0,
max_step: 'int | None' = None,
use_cache: 'bool' = True
```

##### Arguments

* `keys`:
* `page_size`:
* `min_step`:
* `max_step`:
* `use_cache`:

### <kbd>method</kbd> create

```python theme={null}
api: 'public.Api',
run_id: 'str | None' = None,
project: 'str | None' = None,
entity: 'str | None' = None,
state: "Literal['running', 'pending']" = 'running'
```

Create a run for the given project.

For most use cases, use `wandb.init()`. `wandb.init()` provides more robust
logic for creating and updating runs. `wandb.apis.public.Run.create`
is intended for specific scenarios such as creating runs in
a "pending" state for jobs that may be unschedulable
(for example, in a Kubernetes cluster with insufficient GPUs or high
contention). These pending runs can later be resumed and tracked by W\&B.

Runs created with this method have limited functionality. Calling
`update()` on a run created this way may not work as expected.

##### Arguments

* `api`: The W\&B API instance.
* `run_id`: Optional run ID. If not provided, a random ID will be generated.
* `project`: Optional project name. Defaults to the project in API settings or "uncategorized".
* `entity`: Optional entity (user or team) name.
* `state`: Initial state of the run. Use "pending" for runs that will be resumed later, or "running" for immediate execution.

##### Examples

Creating a pending run for later execution

```python theme={null}
import wandb

api = wandb.Api()

run_name = "my-pending-run"

run = Run.create(
    api=api,
    project="project",
    entity="entity",
    state="pending",
    run_id=run_name,
)
```

### <kbd>method</kbd> delete

```python theme={null}
self,
delete_artifacts: 'bool' = False
```

Delete the given run from the wandb backend.

##### Arguments

* `delete_artifacts`: Whether to delete the artifacts associated with the run.

### <kbd>method</kbd> download\_history\_exports

```python theme={null}
self,
download_dir: 'pathlib.Path | str',
require_complete_history: 'bool' = True
```

Download any parquet history files for the run to the provided directory.

##### Arguments

* `download_dir`: The directory to download the history files to.
* `require_complete_history`: Whether to require the complete history to be downloaded. If true, and the run contains data that has not been exported to parquet files yet, an IncompleteRunHistoryError will be raised.

##### Raises

* `IncompleteRunHistoryError`: If require\_complete\_history is True and the run contains data not yet exported to parquet files.
* `WandbApiFailedError`: If the API request fails for reasons other than incomplete history.

### <kbd>method</kbd> file

```python theme={null}
self,
name: 'str'
```

Return the path of a file with a given name in the artifact.

##### Arguments

* `name`: name of requested file.

### <kbd>method</kbd> files

```python theme={null}
self,
names: 'list[str] | None' = None,
pattern: 'str | None' = None,
per_page: 'int' = 50
```

Returns a `Files` object for all files in the run which match the given criteria.

You can specify a list of exact file names to match, or a pattern to match against.
If both are provided, the pattern will be ignored.

##### Arguments

* `names`: names of the requested files, if empty returns all files
* `pattern`: Pattern to match when returning files from W\&B. This pattern uses mySQL's LIKE syntax, so matching all files that end with .json would be "%.json". If both names and pattern are provided, a ValueError will be raised.
* `per_page`: number of results per page.

### <kbd>method</kbd> history

```python theme={null}
self,
samples: 'int' = 500,
keys: 'list[str] | None' = None,
x_axis: 'str' = '_step',
pandas: 'bool' = True,
stream: "Literal['default', 'system']" = 'default'
```

Return sampled history metrics for a run.

This is simpler and faster if you are ok with the history records being sampled.

##### Arguments

* `samples`: (int, optional) The number of samples to return
* `keys`: (list, optional) Only return metrics for specific keys
* `x_axis`: (str, optional) Use this metric as the xAxis defaults to \_step
* `pandas`: (bool, optional) Return a pandas dataframe
* `stream`: (str, optional) "default" for metrics, "system" for machine metrics

### <kbd>method</kbd> load

```python theme={null}
self,
force: 'bool' = False
```

Load run data using appropriate fragment based on lazy mode.

##### Arguments

* `force`:

### <kbd>method</kbd> load\_full\_data

```python theme={null}
self,
force: 'bool' = False
```

Load full run data including heavy fields like config, systemMetrics, summaryMetrics.

This method is useful when you initially used lazy=True for listing runs,
but need access to the full data for specific runs.

##### Arguments

* `force`: Force reload even if data is already loaded

### <kbd>method</kbd> log\_artifact

```python theme={null}
self,
artifact: 'wandb.Artifact',
aliases: 'Collection[str] | None' = None,
tags: 'Collection[str] | None' = None
```

Declare an artifact as output of a run.

##### Arguments

* `artifact`: An artifact returned from `wandb.Api().artifact(name)`.
* `aliases`: Aliases to apply to this artifact.
* `tags`: (list, optional) Tags to apply to this artifact, if any.

### <kbd>method</kbd> logged\_artifacts

```python theme={null}
self,
per_page: 'int' = 100
```

Fetches all artifacts logged by this run.

Retrieves all output artifacts that were logged during the run. Returns a
paginated result that can be iterated over or collected into a single list.

##### Arguments

* `per_page`: Number of artifacts to fetch per API request.

##### Examples

```python theme={null}
import wandb
import tempfile

with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".txt") as tmp:
    tmp.write("This is a test artifact")
    tmp_path = tmp.name
run = wandb.init(project="artifact-example")
artifact = wandb.Artifact("test_artifact", type="dataset")
artifact.add_file(tmp_path)
run.log_artifact(artifact)
run.finish()

api = wandb.Api()

finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")

for logged_artifact in finished_run.logged_artifacts():
    print(logged_artifact.name)
```

### <kbd>method</kbd> save

```python theme={null}
self
```

Persist changes to the run object to the W\&B backend.

### <kbd>method</kbd> scan\_history

```python theme={null}
self,
keys: 'list[str] | None' = None,
page_size: 'int' = 1000,
min_step: 'int' = 0,
max_step: 'int | None' = None,
use_cache: 'bool' = True
```

Returns an iterable collection of all history records for a run.

##### Arguments

* `keys`: list of metrics to read from the run's history. if no keys are provided then all metrics will be returned.
* `page_size`: the number of history records to read at a time.
* `min_step`: The minimum step to start reading history from (inclusive).
* `max_step`: The maximum step to read history up to (exclusive).
* `use_cache`: When set to True, checks the WANDB\_CACHE\_DIR for a run history. If the run history is not found in the cache, it will be downloaded from the server. If set to False, the run history will be downloaded every time.

### <kbd>method</kbd> to\_html

```python theme={null}
self,
height: 'int' = 420,
hidden: 'bool' = False
```

Generate HTML containing an iframe displaying this run.

##### Arguments

* `height`:
* `hidden`:

### <kbd>method</kbd> update

```python theme={null}
self
```

Persist changes to the run object to the wandb backend.

### <kbd>method</kbd> update\_state

```python theme={null}
self,
state: 'str'
```

Update the state of a run.

Supported transitions:

* to `pending` from `running`, `failed`, `crashed`, or `preempted`
  (e.g. to requeue a terminated or in-progress run)
* to `failed` from `pending` or `running`
  (e.g. to mark a preempted or lost run as failed)

Sweep runs cannot have their state updated.

See `Run.state` for the list of possible run states.

##### Arguments

* `state`: The target run state. One of `"pending"` or `"failed"`.

##### Raises

* `wandb.Error`: If the requested state transition is not allowed, or the server does not support this operation.

### <kbd>method</kbd> upload\_file

```python theme={null}
self,
path: 'str',
root: 'str' = '.'
```

Upload a local file to W\&B, associating it with this run.

##### Arguments

* `path`: Path to the file to upload. Can be absolute or relative.
* `root`: The root path to save the file relative to. For example, if you want to have the file saved in the run as "my\_dir/file.txt" and you're currently in "my\_dir" you would set root to "../". Defaults to current directory (".").

### <kbd>method</kbd> use\_artifact

```python theme={null}
self,
artifact: 'wandb.Artifact',
use_as: 'str | None' = None
```

Declare an artifact as an input to a run.

##### Arguments

* `artifact`: An artifact returned from `wandb.Api().artifact(name)`
* `use_as`: A string identifying how the artifact is used in the script. Used to easily differentiate artifacts used in a run, when using the beta wandb launch feature's artifact swapping functionality.

### <kbd>method</kbd> used\_artifacts

```python theme={null}
self,
per_page: 'int' = 100
```

Fetches artifacts explicitly used by this run.

Retrieves only the input artifacts that were explicitly declared as used
during the run, typically via `run.use_artifact()`. Returns a paginated
result that can be iterated over or collected into a single list.

##### Arguments

* `per_page`: Number of artifacts to fetch per API request.

##### Examples

```python theme={null}
import wandb

run = wandb.init(project="artifact-example")
run.use_artifact("test_artifact:latest")
run.finish()

api = wandb.Api()
finished_run = api.run(f"{run.entity}/{run.project}/{run.id}")
for used_artifact in finished_run.used_artifacts():
    print(used_artifact.name)
test_artifact
```

### <kbd>method</kbd> wait\_until\_finished

```python theme={null}
self
```

Check the state of the run until it is finished.
