# API Reference

## Run[[trackio.Run]]

#### trackio.Run[[trackio.Run]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/run.py#L35)

## init[[trackio.init]]

#### trackio.init[[trackio.init]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L281)

Creates a new Trackio project and returns a [*Run*] object.

**Parameters:**

project (*str*) : The name of the project (can be an existing project to continue tracking or a new project to start tracking from scratch).

name (*str*, *optional*) : The name of the run (if not provided, a default name will be generated).

group (*str*, *optional*) : The name of the group which this run belongs to in order to help organize related runs together. You can toggle the entire group's visibilitiy in the dashboard.

space_id (*str*, *optional*) : If provided, the project will be logged to a Hugging Face Space instead of a local directory. Should be a complete Space name like *"username/reponame"* or *"orgname/reponame"*, or just *"reponame"* in which case the Space will be created in the currently-logged-in Hugging Face user's namespace. If the Space does not exist, it will be created. If the Space already exists, the project will be logged to it. Can also be set via the *TRACKIO_SPACE_ID* environment variable. You cannot log to a Space that has been **frozen** (converted to the static SDK); use `trackio.sync(..., sdk="static")` only after you are done logging. Takes precedence over *server_url* and *TRACKIO_SERVER_URL* when more than one is set.

server_url (*str*, *optional*) : Base URL of a self-hosted Trackio server (`http://` or `https://`), or the write-access URL from `trackio.show()` which may include a `write_token` query parameter. The client sends that token on each request (`X-Trackio-Write-Token`); you can also set `TRACKIO_WRITE_TOKEN` instead of embedding the token in the URL. When set, metrics are sent to that server over HTTP instead of creating or syncing to a Hugging Face Space. Can also be set via the `TRACKIO_SERVER_URL` environment variable. Ignored when `space_id` or `TRACKIO_SPACE_ID` is set.

space_storage ([*~huggingface_hub.SpaceStorage*], *optional*) : Choice of persistent storage tier.

dataset_id (*str*, *optional*) : Deprecated. Use *bucket_id* instead.

bucket_id (*str*, *optional*) : The ID of the Hugging Face Bucket to use for metric persistence. By default, when a *space_id* is provided and *bucket_id* is not explicitly set, a bucket is auto-generated from the space_id. Buckets provide S3-like storage without git overhead - the SQLite database is stored directly via *hf-mount* in the Space. Specify a Bucket with name like *"username/bucketname"* or just *"bucketname"*.

config (*dict*, *optional*) : A dictionary of configuration options. Provided for compatibility with *wandb.init()*.

resume (*str*, *optional*, defaults to *"never"*) : Controls how to handle resuming a run. Can be one of:  - *"must"*: Must resume the run with the given name, raises error if run doesn't exist - *"allow"*: Resume the run if it exists, otherwise create a new run - *"never"*: Never resume a run, always create a new one

private (*bool*, *optional*) : Whether to make the Space private. If None (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

settings (*Any*, *optional*) : Not used. Provided for compatibility with *wandb.init()*.

embed (*bool*, *optional*, defaults to *True*) : If running inside a Jupyter/Colab notebook, whether the dashboard should automatically be embedded in the cell when trackio.init() is called. For local runs, this launches a local Trackio dashboard and embeds it. For Space runs, this embeds the Space URL. In Colab, the local dashboard will be accessible via a public share URL when *share=True*.

auto_log_gpu (*bool* or *None*, *optional*, defaults to *None*) : Controls automatic GPU metrics logging. If *None* (default), GPU logging is automatically enabled when *nvidia-ml-py* is installed and an NVIDIA GPU or Apple M series is detected. Set to *True* to force enable or *False* to disable.

gpu_log_interval (*float*, *optional*, defaults to *10.0*) : The interval in seconds between automatic GPU metric logs. Only used when *auto_log_gpu=True*.

webhook_url (*str*, *optional*) : A webhook URL to POST alert payloads to when *trackio.alert()* is called. Supports Slack and Discord webhook URLs natively (payloads are formatted automatically). Can also be set via the *TRACKIO_WEBHOOK_URL* environment variable. Individual alerts can override this URL by passing *webhook_url* to *trackio.alert()*.

webhook_min_level (*AlertLevel* or *str*, *optional*) : Minimum alert level that should trigger webhook delivery. For example, *AlertLevel.WARN* sends only *WARN* and *ERROR* alerts to the webhook destination. Can also be set via *TRACKIO_WEBHOOK_MIN_LEVEL*.

**Returns:**

`*Run*`

A [*Run*] object that can be used to log metrics and finish the run.

## log[[trackio.log]]

#### trackio.log[[trackio.log]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L684)

Logs metrics to the current run.

**Parameters:**

metrics (`dict`) : A dictionary of metrics to log.

step (`int`, *optional*) : The step number. If not provided, the step will be incremented automatically.

## log_gpu[[trackio.log_gpu]]

#### trackio.log_gpu[[trackio.log_gpu]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L718)

Log GPU metrics to the current or specified run as system metrics.
Automatically detects whether an NVIDIA or Apple GPU is available and calls
the appropriate logging method.

Example:
```python
import trackio

run = trackio.init(project="my-project")
trackio.log({"loss": 0.5})
trackio.log_gpu()
trackio.log_gpu(device=0)
```

**Parameters:**

run : Optional Run instance. If None, uses current run from context.

device : CUDA device index to collect metrics from (NVIDIA GPUs only). If None, collects from all GPUs visible to this process. This parameter is ignored for Apple GPUs.

**Returns:**

`dict`

The GPU metrics that were logged.

## log_system[[trackio.log_system]]

#### trackio.log_system[[trackio.log_system]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L704)

Logs system metrics (GPU, etc.) to the current run using timestamps instead of steps.

**Parameters:**

metrics (`dict`) : A dictionary of system metrics to log.

## finish[[trackio.finish]]

#### trackio.finish[[trackio.finish]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L760)

Finishes the current run.

## show[[trackio.show]]

#### trackio.show[[trackio.show]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L1001)

Launches the Trackio dashboard.

**Parameters:**

project (`str`, *optional*) : The name of the project whose runs to show. If not provided, all projects will be shown and the user can select one.

theme (`Any`, *optional*) : Ignored. Kept for backward compatibility; Trackio no longer uses Gradio themes.

mcp_server (`bool`, *optional*) : If `True`, the dashboard exposes an MCP server at `/mcp` when the optional `trackio[mcp]` dependency is installed. If `None` (default), the `GRADIO_MCP_SERVER` environment variable is used (e.g. on Spaces).

footer (`bool`, *optional*, defaults to `True`) : Whether to include `footer=false` in the write-token URL when `False`. This can also be controlled via the `footer` query parameter in the URL.

color_palette (`list[str]`, *optional*) : A list of hex color codes to use for plot lines. If not provided, the `TRACKIO_COLOR_PALETTE` environment variable will be used (comma-separated hex codes), or if that is not set, the default color palette will be used. Example: `['#FF0000', '#00FF00', '#0000FF']`

open_browser (`bool`, *optional*, defaults to `True`) : If `True` and not in a notebook, a new browser tab will be opened with the dashboard. If `False`, the browser will not be opened.

block_thread (`bool`, *optional*) : If `True`, the main thread will be blocked until the dashboard is closed. If `None` (default behavior), then the main thread will not be blocked if the dashboard is launched in a notebook, otherwise the main thread will be blocked.

host (`str`, *optional*) : The host to bind the server to. If not provided, defaults to `'127.0.0.1'` (localhost only). Set to `'0.0.0.0'` to allow remote access.

share (`bool`, *optional*) : If `True`, creates a temporary public URL (Gradio-compatible tunnel). On Colab or hosted notebooks, defaults to `True` unless overridden.

server_port (`int`, *optional*) : Port to bind. If not set, scans from `GRADIO_SERVER_PORT` (default 7860).

**Returns:**

``app``

The dashboard handle (`.close()` stops the server).
`url`: The local URL of the dashboard.
`share_url`: The public share URL, if any.
`full_url`: The full URL including the write token (share URL when sharing, else local).

## sync[[trackio.sync]]

#### trackio.sync[[trackio.sync]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/deploy.py#L949)

Syncs a local Trackio project's database to a Hugging Face Space.
If the Space does not exist, it will be created. Local data is never deleted.

**Freezing:** Passing `sdk="static"` deploys a static Space backed by an HF Bucket
(read-only dashboard, no Gradio server). You can sync the same project again later to
refresh that static Space. If you want a one-time snapshot of an existing Gradio Space,
use `freeze()` instead.

**Parameters:**

project (*str*) : The name of the project to upload.

space_id (*str*, *optional*) : The ID of the Space to upload to (e.g., *"username/space_id"*). If not provided, checks project metadata first, then generates a random space_id.

private (*bool*, *optional*) : Whether to make the Space private. If None (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

force (*bool*, *optional*, defaults to *False*) : If *True*, overwrite the existing database without prompting for confirmation. If *False*, prompt the user before overwriting an existing database.

run_in_background (*bool*, *optional*, defaults to *False*) : If *True*, the Space creation and database upload will be run in a background thread. If *False*, all the steps will be run synchronously.

sdk (*str*, *optional*, defaults to *"gradio"*) : The type of Space to deploy. *"gradio"* deploys a Gradio Space with a live server. *"static"* freezes the Space: deploys a static Space that reads from an HF Bucket (no server needed).

dataset_id (*str*, *optional*) : Deprecated. Use *bucket_id* instead.

bucket_id (*str*, *optional*) : The ID of the HF Bucket to sync to. By default, a bucket is auto-generated from the space_id.

**Returns:**

`*str*`

The Space ID of the synced project.

## freeze[[trackio.freeze]]

#### trackio.freeze[[trackio.freeze]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/deploy.py#L1086)

Creates a new static Hugging Face Space containing a read-only snapshot of
the data for the specified project from the source Gradio Space. The data is
read from the bucket attached to the source Space at freeze time. The original
Space is not modified, and the new static Space does not automatically reflect
metrics uploaded to the original Gradio Space after the freeze completes.

**Parameters:**

space_id (`str`) : The ID of the source Gradio Space (e.g., `"username/my-space"` or a short repo name with the logged-in namespace inferred, like `init()`). Must be a Gradio Space with a bucket mounted at `/data`.

project (`str`) : The name of the project whose data to include in the frozen Space.

new_space_id (`str`, *optional*) : The ID for the new static Space. If not provided, defaults to `"{space_id}_static"`.

private (`bool`, *optional*) : Whether to make the new Space private. If None (default), the repo will be public unless the organization's default is private.

bucket_id (`str`, *optional*) : The ID of the HF Bucket for the new static Space's data storage. If not provided, one is auto-generated from the new Space ID.

**Returns:**

``str``

The Space ID of the newly created static Space.

## delete_project[[trackio.delete_project]]

#### trackio.delete_project[[trackio.delete_project]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L806)

Deletes a project by removing its local SQLite database.

**Parameters:**

project (`str`) : The name of the project to delete.

force (`bool`, *optional*, defaults to `False`) : If `True`, deletes the project without prompting for confirmation. If `False`, prompts the user to confirm before deleting.

**Returns:**

``bool``

`True` if the project was deleted, `False` otherwise.

## import_csv[[trackio.import_csv]]

#### trackio.import_csv[[trackio.import_csv]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/imports.py#L9)

Imports a CSV file into a Trackio project. The CSV file must contain a `"step"`
column, may optionally contain a `"timestamp"` column, and any other columns will be
treated as metrics. It should also include a header row with the column names.

TODO: call init() and return a Run object so that the user can continue to log metrics to it.

**Parameters:**

csv_path (`str` or `Path`) : The str or Path to the CSV file to import.

project (`str`) : The name of the project to import the CSV file into. Must not be an existing project.

name (`str`, *optional*) : The name of the Run to import the CSV file into. If not provided, a default name will be generated.

name (`str`, *optional*) : The name of the run (if not provided, a default name will be generated).

space_id (`str`, *optional*) : If provided, the project will be logged to a Hugging Face Space instead of a local directory. Should be a complete Space name like `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which case the Space will be created in the currently-logged-in Hugging Face user's namespace. If the Space does not exist, it will be created. If the Space already exists, the project will be logged to it.

dataset_id (`str`, *optional*) : Deprecated. Use `bucket_id` instead.

private (`bool`, *optional*) : Whether to make the Space private. If None (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

## import_tf_events[[trackio.import_tf_events]]

#### trackio.import_tf_events[[trackio.import_tf_events]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/imports.py#L156)

Imports TensorFlow Events files from a directory into a Trackio project. Each
subdirectory in the log directory will be imported as a separate run.

**Parameters:**

log_dir (`str` or `Path`) : The str or Path to the directory containing TensorFlow Events files.

project (`str`) : The name of the project to import the TensorFlow Events files into. Must not be an existing project.

name (`str`, *optional*) : The name prefix for runs (if not provided, will use directory names). Each subdirectory will create a separate run.

space_id (`str`, *optional*) : If provided, the project will be logged to a Hugging Face Space instead of a local directory. Should be a complete Space name like `"username/reponame"` or `"orgname/reponame"`, or just `"reponame"` in which case the Space will be created in the currently-logged-in Hugging Face user's namespace. If the Space does not exist, it will be created. If the Space already exists, the project will be logged to it.

dataset_id (`str`, *optional*) : Deprecated. Use `bucket_id` instead.

private (`bool`, *optional*) : Whether to make the Space private. If None (default), the repo will be public unless the organization's default is private. This value is ignored if the repo already exists.

## save[[trackio.save]]

#### trackio.save[[trackio.save]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/__init__.py#L850)

Saves files to a project (not linked to a specific run). If Trackio is running
locally, the file(s) will be copied to the project's files directory. If Trackio is
running in a Space, the file(s) will be uploaded to the Space's files directory.

Example:
```python
import trackio

trackio.init(project="my-project")
trackio.save("config.yaml")
trackio.save("models/*.pth")
```

**Parameters:**

glob_str (`str` or `Path`) : The file path or glob pattern to save. Can be a single file or a pattern matching multiple files (e.g., `"*.py"`, `"models/**/*.pth"`).

project (`str`, *optional*) : The name of the project to save files to. If not provided, uses the current project from `trackio.init()`. If no project is initialized, raises an error.

**Returns:**

``str``

The path where the file(s) were saved (project's files directory).

## Image[[trackio.TrackioImage]]

#### trackio.TrackioImage[[trackio.TrackioImage]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/media/image.py#L13)

Initializes an Image object.

Example:
```python
import trackio
import numpy as np
from PIL import Image

# Create an image from numpy array
image_data = np.random.randint(0, 255, (64, 64, 3), dtype=np.uint8)
image = trackio.Image(image_data, caption="Random image")
trackio.log({"my_image": image})

# Create an image from PIL Image
pil_image = Image.new('RGB', (100, 100), color='red')
image = trackio.Image(pil_image, caption="Red square")
trackio.log({"red_image": image})

# Create an image from file path
image = trackio.Image("path/to/image.jpg", caption="Photo from file")
trackio.log({"file_image": image})
```

**Parameters:**

value (`str`, `Path`, `numpy.ndarray`, or `PIL.Image`, *optional*) : A path to an image, a PIL Image, or a numpy array of shape (height, width, channels). If numpy array, should be of type `np.uint8` with RGB values in the range `[0, 255]`.

caption (`str`, *optional*) : A string caption for the image.

## Video[[trackio.TrackioVideo]]

#### trackio.TrackioVideo[[trackio.TrackioVideo]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/media/video.py#L17)

Initializes a Video object.

Example:
```python
import trackio
import numpy as np

# Create a simple video from numpy array
frames = np.random.randint(0, 255, (10, 3, 64, 64), dtype=np.uint8)
video = trackio.Video(frames, caption="Random video", fps=30)

# Create a batch of videos
batch_frames = np.random.randint(0, 255, (3, 10, 3, 64, 64), dtype=np.uint8)
batch_video = trackio.Video(batch_frames, caption="Batch of videos", fps=15)

# Create video from file path
video = trackio.Video("path/to/video.mp4", caption="Video from file")
```

write_videotrackio.TrackioVideo.write_videohttps://github.com/gradio-app/trackio/blob/v0.24.1/trackio/media/video.py#L93[{"name": "file_path", "val": ": str | pathlib.Path"}, {"name": "video", "val": ": ndarray"}, {"name": "fps", "val": ": float"}, {"name": "codec", "val": ": typing.Literal['h264', 'vp9', 'gif']"}]
RGB uint8 only, shape (F, H, W, 3).

**Parameters:**

value (`str`, `Path`, or `numpy.ndarray`, *optional*) : A path to a video file, or a numpy array. If numpy array, should be of type `np.uint8` with RGB values in the range `[0, 255]`. It is expected to have shape of either (frames, channels, height, width) or (batch, frames, channels, height, width). For the latter, the videos will be tiled into a grid.

caption (`str`, *optional*) : A string caption for the video.

fps (`int`, *optional*) : Frames per second for the video. Only used when value is an ndarray. Default is `24`.

format (`Literal["gif", "mp4", "webm"]`, *optional*) : Video format ("gif", "mp4", or "webm"). Only used when value is an ndarray. Default is "gif".

## Audio[[trackio.TrackioAudio]]

#### trackio.TrackioAudio[[trackio.TrackioAudio]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/media/audio.py#L19)

Initializes an Audio object.

Example:
```python
import trackio
import numpy as np

# Generate a 1-second 440 Hz sine wave (mono)
sr = 16000
t = np.linspace(0, 1, sr, endpoint=False)
wave = 0.2 * np.sin(2 * np.pi * 440 * t)
audio = trackio.Audio(wave, caption="A4 sine", sample_rate=sr, format="wav")
trackio.log({"tone": audio})

# Stereo from numpy array (shape: samples, 2)
stereo = np.stack([wave, wave], axis=1)
audio = trackio.Audio(stereo, caption="Stereo", sample_rate=sr, format="mp3")
trackio.log({"stereo": audio})

# From an existing file
audio = trackio.Audio("path/to/audio.wav", caption="From file")
trackio.log({"file_audio": audio})
```

ensure_int16_pcmtrackio.TrackioAudio.ensure_int16_pcmhttps://github.com/gradio-app/trackio/blob/v0.24.1/trackio/media/audio.py#L90[{"name": "data", "val": ": ndarray"}]

Convert input audio array to contiguous int16 PCM.
Peak normalization is applied to floating inputs.

**Parameters:**

value (`str`, `Path`, or `numpy.ndarray`, *optional*) : A path to an audio file, or a numpy array. The array should be shaped `(samples,)` for mono or `(samples, 2)` for stereo. Float arrays will be peak-normalized and converted to 16-bit PCM; integer arrays will be converted to 16-bit PCM as needed.

caption (`str`, *optional*) : A string caption for the audio.

sample_rate (`int`, *optional*) : Sample rate in Hz. Required when `value` is a numpy array.

format (`Literal["wav", "mp3"]`, *optional*) : Audio format used when `value` is a numpy array. Default is "wav".

## Table[[trackio.Table]]

#### trackio.Table[[trackio.Table]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/table.py#L9)

Initializes a Table object.

Tables can be used to log tabular data including images, numbers, and text.

to_display_formattrackio.Table.to_display_formathttps://github.com/gradio-app/trackio/blob/v0.24.1/trackio/table.py#L124[{"name": "table_data", "val": ": list"}]- **table_data** (`list[dict]`) --
  List of dictionaries representing table rows (from stored `_value`).0`list[dict]`Table data with images converted to markdown syntax and long
text truncated.

Converts stored table data to display format for UI rendering.

Note:
This does not use the `self.data` attribute, but instead uses the
`table_data` parameter, which is what the UI receives.

**Parameters:**

columns (`list[str]`, *optional*) : Names of the columns in the table. Optional if `data` is provided. Not expected if `dataframe` is provided. Currently ignored.

data (`list[list[Any]]`, *optional*) : 2D row-oriented array of values. Each value can be a number, a string (treated as Markdown and truncated if too long), or a `Trackio.Image` or list of `Trackio.Image` objects.

dataframe (`pandas.DataFrame`, *optional*) : DataFrame used to create the table. When set, `data` and `columns` arguments are ignored.

rows (`list[list[Any]]`, *optional*) : Currently ignored.

optional (`bool` or `list[bool]`, *optional*, defaults to `True`) : Currently ignored.

allow_mixed_types (`bool`, *optional*, defaults to `False`) : Currently ignored.

log_mode : (`Literal["IMMUTABLE", "MUTABLE", "INCREMENTAL"]` or `None`, *optional*, defaults to `"IMMUTABLE"`): Currently ignored.

**Returns:**

``list[dict]``

Table data with images converted to markdown syntax and long
text truncated.

## Histogram[[trackio.Histogram]]

#### trackio.Histogram[[trackio.Histogram]]

[Source](https://github.com/gradio-app/trackio/blob/v0.24.1/trackio/histogram.py#L6)

Histogram data type for Trackio, compatible with wandb.Histogram.

Example:
```python
import trackio
import numpy as np

# Create histogram from sequence
data = np.random.randn(1000)
trackio.log({"distribution": trackio.Histogram(data)})

# Create histogram from numpy histogram
hist, bins = np.histogram(data, bins=30)
trackio.log({"distribution": trackio.Histogram(np_histogram=(hist, bins))})

# Specify custom number of bins
trackio.log({"distribution": trackio.Histogram(data, num_bins=50)})
```

**Parameters:**

sequence (`np.ndarray` or `Sequence[float]` or `Sequence[int]`, *optional*) : Sequence of values to create the histogram from.

np_histogram (`tuple`, *optional*) : Pre-computed NumPy histogram as a `(hist, bins)` tuple.

num_bins (`int`, *optional*, defaults to `64`) : Number of bins for the histogram (maximum `512`).

