Skip to content

study

openml._api.resources.study #

StudyV1API #

StudyV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, StudyAPI

Source code in openml/_api/resources/base/base.py
def __init__(self, http: HTTPClient, minio: MinIOClient):
    self._http = http
    self._minio = minio

delete #

delete(resource_id: int) -> bool

Delete a resource using the V1 API.

PARAMETER DESCRIPTION
resource_id

Identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the server confirms successful deletion.

RAISES DESCRIPTION
ValueError

If the resource type is not supported for deletion.

OpenMLNotAuthorizedError

If the user is not permitted to delete the resource.

OpenMLServerError

If deletion fails for an unknown reason.

OpenMLServerException

For other server-side errors.

Source code in openml/_api/resources/base/versions.py
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource using the V1 API.

    Parameters
    ----------
    resource_id : int
        Identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the server confirms successful deletion.

    Raises
    ------
    ValueError
        If the resource type is not supported for deletion.
    OpenMLNotAuthorizedError
        If the user is not permitted to delete the resource.
    OpenMLServerError
        If deletion fails for an unknown reason.
    OpenMLServerException
        For other server-side errors.
    """
    if self.resource_type not in _LEGAL_RESOURCES_DELETE:
        raise ValueError(f"Can't delete a {self.resource_type.value}")

    endpoint_name = self._get_endpoint_name()
    path = f"{endpoint_name}/{resource_id}"
    try:
        response = self._http.delete(path)
        result = xmltodict.parse(response.content)
        return f"oml:{endpoint_name}_delete" in result
    except OpenMLServerException as e:
        self._handle_delete_exception(endpoint_name, e)
        raise

list #

list(limit: int | None = None, offset: int | None = None, status: str | None = None, main_entity_type: str | None = None, uploader: list[int] | None = None, benchmark_suite: int | None = None) -> DataFrame

List studies using V1 API.

PARAMETER DESCRIPTION
limit

Maximum number of studies to return.

TYPE: int DEFAULT: None

offset

Number of studies to skip.

TYPE: int DEFAULT: None

status

Filter by status (active, in_preparation, deactivated, all).

TYPE: str DEFAULT: None

main_entity_type

Filter by main entity type (run, task).

TYPE: str DEFAULT: None

uploader

Filter by uploader IDs.

TYPE: list[int] DEFAULT: None

benchmark_suite

Filter by benchmark suite ID.

TYPE: int DEFAULT: None

RETURNS DESCRIPTION
DataFrame

DataFrame containing study information.

Source code in openml/_api/resources/study.py
def list(  # noqa: PLR0913
    self,
    limit: int | None = None,
    offset: int | None = None,
    status: str | None = None,
    main_entity_type: str | None = None,
    uploader: builtins.list[int] | None = None,
    benchmark_suite: int | None = None,
) -> pd.DataFrame:
    """List studies using V1 API.

    Parameters
    ----------
    limit : int, optional
        Maximum number of studies to return.
    offset : int, optional
        Number of studies to skip.
    status : str, optional
        Filter by status (active, in_preparation, deactivated, all).
    main_entity_type : str, optional
        Filter by main entity type (run, task).
    uploader : list[int], optional
        Filter by uploader IDs.
    benchmark_suite : int, optional
        Filter by benchmark suite ID.

    Returns
    -------
    pd.DataFrame
        DataFrame containing study information.
    """
    api_call = self._build_url(
        limit=limit,
        offset=offset,
        status=status,
        main_entity_type=main_entity_type,
        uploader=uploader,
        benchmark_suite=benchmark_suite,
    )
    response = self._http.get(api_call)
    xml_string = response.content.decode("utf-8")
    return self._parse_list_xml(xml_string)

publish #

publish(path: str, files: Mapping[str, Any] | None) -> int

Publish a new resource using the V1 API.

PARAMETER DESCRIPTION
path

API endpoint path for the upload.

TYPE: str

files

Files to upload as part of the request payload.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

RAISES DESCRIPTION
ValueError

If the server response does not contain a valid resource ID.

OpenMLServerException

If the server returns an error during upload.

Source code in openml/_api/resources/base/versions.py
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource using the V1 API.

    Parameters
    ----------
    path : str
        API endpoint path for the upload.
    files : Mapping of str to Any or None
        Files to upload as part of the request payload.

    Returns
    -------
    int
        Identifier of the newly created resource.

    Raises
    ------
    ValueError
        If the server response does not contain a valid resource ID.
    OpenMLServerException
        If the server returns an error during upload.
    """
    response = self._http.post(path, files=files)
    parsed_response = xmltodict.parse(response.content)
    return self._extract_id_from_upload(parsed_response)

tag #

tag(resource_id: int, tag: str) -> list[str]

Add a tag to a resource using the V1 API.

PARAMETER DESCRIPTION
resource_id

Identifier of the resource to tag.

TYPE: int

tag

Tag to associate with the resource.

TYPE: str

RETURNS DESCRIPTION
list of str

Updated list of tags assigned to the resource.

RAISES DESCRIPTION
ValueError

If the resource type does not support tagging.

OpenMLServerException

If the server returns an error.

Source code in openml/_api/resources/base/versions.py
def tag(self, resource_id: int, tag: str) -> list[str]:
    """
    Add a tag to a resource using the V1 API.

    Parameters
    ----------
    resource_id : int
        Identifier of the resource to tag.
    tag : str
        Tag to associate with the resource.

    Returns
    -------
    list of str
        Updated list of tags assigned to the resource.

    Raises
    ------
    ValueError
        If the resource type does not support tagging.
    OpenMLServerException
        If the server returns an error.
    """
    if self.resource_type not in _LEGAL_RESOURCES_TAG:
        raise ValueError(f"Can't tag a {self.resource_type.value}")

    endpoint_name = self._get_endpoint_name()
    path = f"{endpoint_name}/tag"
    data = {f"{endpoint_name}_id": resource_id, "tag": tag}
    response = self._http.post(path, data=data)

    parsed_response = xmltodict.parse(response.content, force_list={"oml:tag"})
    result = parsed_response[f"oml:{endpoint_name}_tag"]
    tags: list[str] = result.get("oml:tag", [])

    return tags

untag #

untag(resource_id: int, tag: str) -> list[str]

Remove a tag from a resource using the V1 API.

PARAMETER DESCRIPTION
resource_id

Identifier of the resource to untag.

TYPE: int

tag

Tag to remove from the resource.

TYPE: str

RETURNS DESCRIPTION
list of str

Updated list of tags assigned to the resource.

RAISES DESCRIPTION
ValueError

If the resource type does not support tagging.

OpenMLServerException

If the server returns an error.

Source code in openml/_api/resources/base/versions.py
def untag(self, resource_id: int, tag: str) -> list[str]:
    """
    Remove a tag from a resource using the V1 API.

    Parameters
    ----------
    resource_id : int
        Identifier of the resource to untag.
    tag : str
        Tag to remove from the resource.

    Returns
    -------
    list of str
        Updated list of tags assigned to the resource.

    Raises
    ------
    ValueError
        If the resource type does not support tagging.
    OpenMLServerException
        If the server returns an error.
    """
    if self.resource_type not in _LEGAL_RESOURCES_TAG:
        raise ValueError(f"Can't untag a {self.resource_type.value}")

    endpoint_name = self._get_endpoint_name()
    path = f"{endpoint_name}/untag"
    data = {f"{endpoint_name}_id": resource_id, "tag": tag}
    response = self._http.post(path, data=data)

    parsed_response = xmltodict.parse(response.content, force_list={"oml:tag"})
    result = parsed_response[f"oml:{endpoint_name}_untag"]
    tags: list[str] = result.get("oml:tag", [])

    return tags

StudyV2API #

StudyV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, StudyAPI

Source code in openml/_api/resources/base/base.py
def __init__(self, http: HTTPClient, minio: MinIOClient):
    self._http = http
    self._minio = minio

list #

list(limit: int | None = None, offset: int | None = None, status: str | None = None, main_entity_type: str | None = None, uploader: list[int] | None = None, benchmark_suite: int | None = None) -> DataFrame

V2 API for listing studies is not yet available.

Source code in openml/_api/resources/study.py
def list(  # noqa: PLR0913
    self,
    limit: int | None = None,  # noqa: ARG002
    offset: int | None = None,  # noqa: ARG002
    status: str | None = None,  # noqa: ARG002
    main_entity_type: str | None = None,  # noqa: ARG002
    uploader: builtins.list[int] | None = None,  # noqa: ARG002
    benchmark_suite: int | None = None,  # noqa: ARG002
) -> pd.DataFrame:
    """V2 API for listing studies is not yet available."""
    self._not_supported(method="list")