DVC Studio Client
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
- breaking Python 3.8 support was dropped in version 0.21.0. Users on Python 3.8 or older must upgrade their Python environment to 3.9 or newer to use versions 0.21.0 and later.
- breaking The default Studio URL was updated in versions 0.21.0 and 0.22.0. Older client versions might attempt to connect to an outdated domain, leading to connection issues.
- breaking Authentication functions were renamed and refactored in versions 0.17.0 and 0.17.1. `initiate_authentication` was renamed to `get_access_token` in 0.17.0, and a broader refactoring from 'Authorization' to 'Authentication' occurred in 0.17.1.
- gotcha Version 0.20.0 introduced optional `subdir` information for monorepos within the schema and `post_live_metrics`. If you are operating within a monorepo structure and need to differentiate experiments by subdirectory, you might need to update your data posting logic.
Install
-
pip install dvc-studio-client
Imports
- post_live_metrics
from dvc_studio_client import post_live_metrics
- get_access_token
from dvc_studio_client import get_access_token
Quickstart
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}")