Skip to content

Model registry

get_download_uris(repo, name, version=None, stage=None, **kwargs)

Return download URIs for the specified model.


repo: Git repo URL.
name: Model name.
version: Model version.
stage: Model stage.

Additional keyword arguments will be passed to get_studio_config().


ValueError: Invalid arguments were passed or the API call failed.
Source code in dvc_studio_client/model_registry.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def get_download_uris(
    repo: str,
    name: str,
    version: Optional[str] = None,
    stage: Optional[str] = None,
    **kwargs,
) -> dict[str, str]:
    """Return download URIs for the specified model.

    Args:
    ----
        repo: Git repo URL.
        name: Model name.
        version: Model version.
        stage: Model stage.

    Additional keyword arguments will be passed to get_studio_config().

    Raises:
    ------
        ValueError: Invalid arguments were passed or the API call failed.
    """
    config = get_studio_config(**kwargs)
    if not config:
        raise ValueError("No studio config")  # noqa: TRY003
    params = {"repo": repo, "name": name}
    if version and stage:
        raise ValueError("Version and stage are mutually exclusive")  # noqa: TRY003
    if version:
        params["version"] = version
    if stage:
        params["stage"] = stage

    try:
        url = urljoin(config["url"], GET_DOWNLOAD_URIS_PATH)
        response = requests.get(
            url,
            params=params,
            headers={"Authorization": f"token {config['token']}"},
            timeout=(30, 5),
        )
    except RequestException as e:
        raise ValueError("Failed to reach studio API") from e  # noqa: TRY003

    if response.status_code != 200:
        message = response.content.decode()
        logger.debug(
            "get_download_uris: %d '%s'",
            response.status_code,
            message,
        )
        raise ValueError(f"Failed to get model download URIs from studio: {message}")  # noqa: TRY003
    return response.json()