DVC Studio Client

0.22.0 · active · verified Sat Apr 11

dvc-studio-client is a Python library designed to facilitate posting data from DVC (Data Version Control) and DVCLive to Iterative Studio. It provides functionalities for managing the Model Registry, sending Live Experiment updates, and handling Studio authentication. The library is currently at version 0.22.0 and maintains a regular release cadence, with recent updates focused on Python version support and Studio URL alignment.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `dvc-studio-client` to post live experiment metrics to Iterative Studio. It simulates an experiment run, capturing metrics and parameters, and then uses the `post_live_metrics` function to send this data. Ensure you have a DVC_STUDIO_TOKEN environment variable set or replace the placeholder.

import os
from dvc_studio_client import post_live_metrics, get_access_token

# A real token would be obtained from Iterative Studio or DVC CLI configuration
studio_token = os.environ.get("DVC_STUDIO_TOKEN", "your_studio_token_here")
if studio_token == "your_studio_token_here":
    print("WARNING: DVC_STUDIO_TOKEN not set. Using placeholder.")

# Mock metrics and parameters for an experiment
metrics_data = {
    "exp_name": "my-first-studio-experiment",
    "metrics": {"train/accuracy": 0.88, "val/loss": 0.12},
    "params": {"learning_rate": 0.005, "batch_size": 64, "epochs": 10},
    "step": 50,
    "dvc_env": {"dvc_version": "3.0.0"}
}

try:
    # Post metrics to Iterative Studio
    # Replace 'https://github.com/iterative/example-repo.git' with your actual repository URL
    # Replace 'abcdef0123...' with a real Git commit SHA (e.g., from your baseline experiment)
    response = post_live_metrics(
        token=studio_token,
        repo_url="https://github.com/iterative/example-repo.git",
        baseline_sha="abcdef0123456789abcdef0123456789abcdef01", 
        **metrics_data
    )
    print(f"Successfully posted metrics. Response: {response.get('url', 'N/A')}")
except Exception as e:
    print(f"Failed to post metrics: {e}")

# The get_access_token function is typically used in more interactive/programmatic authentication flows.
# For quickstart, we acknowledge its presence. Actual usage might open a browser.
# print(f"get_access_token function is available: {get_access_token}")

view raw JSON →