Skip to content

resources

openml._api.resources #

DatasetAPI #

DatasetAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for dataset resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

DatasetV1API #

DatasetV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, DatasetAPI

Version 1 API implementation for dataset resources.

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

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

DatasetV2API #

DatasetV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, DatasetAPI

Version 2 API implementation for dataset resources.

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

EstimationProcedureAPI #

EstimationProcedureAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for estimation procedure resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

EstimationProcedureV1API #

EstimationProcedureV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, EstimationProcedureAPI

V1 API implementation for estimation procedures.

Fetches estimation procedures from the v1 XML API endpoint.

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 #

Return a list of all estimation procedures which are on OpenML.

RETURNS DESCRIPTION
procedures

A list of all estimation procedures. Every procedure is represented by a dictionary containing the following information: id, task type id, name, type, repeats, folds, stratified.

TYPE: list

Source code in openml/_api/resources/estimation_procedure.py
def list(self) -> list[OpenMLEstimationProcedure]:
    """Return a list of all estimation procedures which are on OpenML.

    Returns
    -------
    procedures : list
        A list of all estimation procedures. Every procedure is represented by
        a dictionary containing the following information: id, task type id,
        name, type, repeats, folds, stratified.
    """
    path = "estimationprocedure/list"
    response = self._http.get(path)
    xml_content = response.text

    procs_dict = xmltodict.parse(xml_content)

    # Minimalistic check if the XML is useful
    if "oml:estimationprocedures" not in procs_dict:
        raise ValueError("Error in return XML, does not contain tag oml:estimationprocedures.")

    if "@xmlns:oml" not in procs_dict["oml:estimationprocedures"]:
        raise ValueError(
            "Error in return XML, does not contain tag "
            "@xmlns:oml as a child of oml:estimationprocedures.",
        )

    if procs_dict["oml:estimationprocedures"]["@xmlns:oml"] != "http://openml.org/openml":
        raise ValueError(
            "Error in return XML, value of "
            "oml:estimationprocedures/@xmlns:oml is not "
            "http://openml.org/openml, but {}".format(
                str(procs_dict["oml:estimationprocedures"]["@xmlns:oml"])
            ),
        )

    procs: list[OpenMLEstimationProcedure] = []
    for proc_ in procs_dict["oml:estimationprocedures"]["oml:estimationprocedure"]:
        task_type_int = int(proc_["oml:ttid"])
        try:
            task_type_id = TaskType(task_type_int)
            procs.append(
                OpenMLEstimationProcedure(
                    id=int(proc_["oml:id"]),
                    task_type_id=task_type_id,
                    name=proc_["oml:name"],
                    type=proc_["oml:type"],
                )
            )
        except ValueError as e:
            warnings.warn(
                f"Could not create task type id for {task_type_int} due to error {e}",
                RuntimeWarning,
                stacklevel=2,
            )

    return procs

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

EstimationProcedureV2API #

EstimationProcedureV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, EstimationProcedureAPI

V2 API implementation for estimation procedures.

Fetches estimation procedures from the v2 JSON API endpoint.

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

EvaluationAPI #

EvaluationAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for evaluation resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

EvaluationMeasureAPI #

EvaluationMeasureAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for evaluation measure resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

EvaluationMeasureV1API #

EvaluationMeasureV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, EvaluationMeasureAPI

V1 API implementation for evaluation measures.

Fetches evaluation measures from the v1 XML API endpoint.

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() -> list[str]

List all evaluation measures available on OpenML.

RETURNS DESCRIPTION
list[str]

A list of evaluation measure names.

Source code in openml/_api/resources/evaluation_measure.py
def list(self) -> list[str]:
    """List all evaluation measures available on OpenML.

    Returns
    -------
    list[str]
        A list of evaluation measure names.
    """
    path = "evaluationmeasure/list"
    response = self._http.get(path)
    xml_content = response.text

    qualities = xmltodict.parse(xml_content, force_list=("oml:measures"))
    # Minimalistic check if the XML is useful
    if "oml:evaluation_measures" not in qualities:
        raise ValueError('Error in return XML, does not contain "oml:evaluation_measures"')

    if not isinstance(
        qualities["oml:evaluation_measures"]["oml:measures"][0]["oml:measure"], list
    ):
        raise TypeError('Error in return XML, does not contain "oml:measure" as a list')

    return qualities["oml:evaluation_measures"]["oml:measures"][0]["oml:measure"]

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

EvaluationMeasureV2API #

EvaluationMeasureV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, EvaluationMeasureAPI

V2 API implementation for evaluation measures.

Fetches evaluation measures from the v2 JSON API endpoint.

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

list #

list() -> list[str]

List all evaluation measures available on OpenML.

RETURNS DESCRIPTION
list[str]

A list of evaluation measure names.

Source code in openml/_api/resources/evaluation_measure.py
def list(self) -> list[str]:
    """List all evaluation measures available on OpenML.

    Returns
    -------
    list[str]
        A list of evaluation measure names.
    """
    path = "evaluationmeasure/list"
    response = self._http.get(path)
    data = response.json()

    if not isinstance(data, list):
        raise ValueError(f"Expected list, got {type(data)}")

    return data

EvaluationV1API #

EvaluationV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, EvaluationAPI

V1 API implementation for evaluations. Fetches evaluations from the v1 XML API endpoint.

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, offset: int, *, function: str, tasks: list | None = None, setups: list | None = None, flows: list | None = None, runs: list | None = None, uploaders: list | None = None, study: int | None = None, sort_order: str | None = None, **kwargs: Any) -> list[OpenMLEvaluation]

Retrieve evaluations from the OpenML v1 XML API.

This method builds an evaluation query URL based on the provided filters, sends a request to the OpenML v1 endpoint, parses the XML response into a dictionary, and enriches the result with uploader usernames.

PARAMETER DESCRIPTION
The

ones

limit

the number of evaluations to return

TYPE: int

offset

the number of evaluations to skip, starting from the first

TYPE: int

function

the evaluation function. e.g., predictive_accuracy

TYPE: str

tasks

the list of task IDs

TYPE: list[int, str] DEFAULT: None

setups

the list of setup IDs

TYPE: list | None DEFAULT: None

flows

the list of flow IDs

TYPE: list[int, str] DEFAULT: None

runs

the list of run IDs

TYPE: list | None DEFAULT: None

uploaders

the list of uploader IDs

TYPE: list[int, str] DEFAULT: None

study

TYPE: int DEFAULT: None

kwargs

Legal filter operators: tag, per_fold

TYPE: Any DEFAULT: {}

sort_order

order of sorting evaluations, ascending ("asc") or descending ("desc")

TYPE: str DEFAULT: None

RETURNS DESCRIPTION
list of OpenMLEvaluation objects
Notes

This method performs two API calls: 1. Fetches evaluation data from the specified endpoint 2. Fetches user information for all uploaders in the evaluation data

The user information is used to map uploader IDs to usernames.

Source code in openml/_api/resources/evaluation.py
def list(  # noqa: PLR0913
    self,
    limit: int,
    offset: int,
    *,
    function: str,
    tasks: builtins.list | None = None,
    setups: builtins.list | None = None,
    flows: builtins.list | None = None,
    runs: builtins.list | None = None,
    uploaders: builtins.list | None = None,
    study: int | None = None,
    sort_order: str | None = None,
    **kwargs: Any,
) -> builtins.list[OpenMLEvaluation]:
    """Retrieve evaluations from the OpenML v1 XML API.

    This method builds an evaluation query URL based on the provided
    filters, sends a request to the OpenML v1 endpoint, parses the XML
    response into a dictionary, and enriches the result with uploader
    usernames.

    Parameters
    ----------
    The arguments that are lists are separated from the single value
    ones which are put into the kwargs.

    limit : int
        the number of evaluations to return
    offset : int
        the number of evaluations to skip, starting from the first
    function : str
        the evaluation function. e.g., predictive_accuracy

    tasks : list[int,str], optional
        the list of task IDs
    setups: list[int,str], optional
        the list of setup IDs
    flows : list[int,str], optional
        the list of flow IDs
    runs :list[int,str], optional
        the list of run IDs
    uploaders : list[int,str], optional
        the list of uploader IDs

    study : int, optional

    kwargs: dict, optional
        Legal filter operators: tag, per_fold

    sort_order : str, optional
        order of sorting evaluations, ascending ("asc") or descending ("desc")

    Returns
    -------
    list of OpenMLEvaluation objects

    Notes
    -----
    This method performs two API calls:
    1. Fetches evaluation data from the specified endpoint
    2. Fetches user information for all uploaders in the evaluation data

    The user information is used to map uploader IDs to usernames.
    """
    api_call = self._build_url(
        limit,
        offset,
        function=function,
        tasks=tasks,
        setups=setups,
        flows=flows,
        runs=runs,
        uploaders=uploaders,
        study=study,
        sort_order=sort_order,
        **kwargs,
    )

    eval_response = self._http.get(api_call)
    xml_content = eval_response.text

    return self._parse_list_xml(xml_content)

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

EvaluationV2API #

EvaluationV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, EvaluationAPI

V2 API implementation for evaluations. Fetches evaluations from the v2 json API endpoint.

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, offset: int, *, function: str, tasks: list | None = None, setups: list | None = None, flows: list | None = None, runs: list | None = None, uploaders: list | None = None, study: int | None = None, sort_order: str | None = None, **kwargs: Any) -> list[OpenMLEvaluation]

Retrieve evaluation results from the OpenML v2 JSON API.

Notes

This method is not yet implemented.

Source code in openml/_api/resources/evaluation.py
def list(  # noqa: PLR0913
    self,
    limit: int,  # noqa: ARG002
    offset: int,  # noqa: ARG002
    *,
    function: str,  # noqa: ARG002
    tasks: builtins.list | None = None,  # noqa: ARG002
    setups: builtins.list | None = None,  # noqa: ARG002
    flows: builtins.list | None = None,  # noqa: ARG002
    runs: builtins.list | None = None,  # noqa: ARG002
    uploaders: builtins.list | None = None,  # noqa: ARG002
    study: int | None = None,  # noqa: ARG002
    sort_order: str | None = None,  # noqa: ARG002
    **kwargs: Any,  # noqa: ARG002
) -> builtins.list[OpenMLEvaluation]:
    """
    Retrieve evaluation results from the OpenML v2 JSON API.

    Notes
    -----
    This method is not yet implemented.
    """
    self._not_supported(method="list")

FallbackProxy #

FallbackProxy(*api_versions: Any)

Proxy object that provides transparent fallback across multiple API versions.

This class delegates attribute access to a sequence of API implementations. When a callable attribute is invoked and raises OpenMLNotSupportedError, the proxy automatically attempts the same method on subsequent API instances until one succeeds.

PARAMETER DESCRIPTION
*api_versions

One or more API implementation instances ordered by priority. The first API is treated as the primary implementation, and subsequent APIs are used as fallbacks.

TYPE: Any DEFAULT: ()

RAISES DESCRIPTION
ValueError

If no API implementations are provided.

Notes

Attribute lookup is performed dynamically via __getattr__. Only methods that raise OpenMLNotSupportedError trigger fallback behavior. Other exceptions are propagated immediately.

Source code in openml/_api/resources/base/fallback.py
def __init__(self, *api_versions: Any):
    if not api_versions:
        raise ValueError("At least one API version must be provided")
    self._apis = api_versions

__getattr__ #

__getattr__(name: str) -> Any

Dynamically resolve attribute access across API implementations.

PARAMETER DESCRIPTION
name

Name of the attribute being accessed.

TYPE: str

RETURNS DESCRIPTION
Any

The resolved attribute. If it is callable, a wrapped function providing fallback behavior is returned.

RAISES DESCRIPTION
AttributeError

If none of the API implementations define the attribute.

Source code in openml/_api/resources/base/fallback.py
def __getattr__(self, name: str) -> Any:
    """
    Dynamically resolve attribute access across API implementations.

    Parameters
    ----------
    name : str
        Name of the attribute being accessed.

    Returns
    -------
    Any
        The resolved attribute. If it is callable, a wrapped function
        providing fallback behavior is returned.

    Raises
    ------
    AttributeError
        If none of the API implementations define the attribute.
    """
    api, attr = self._find_attr(name)
    if callable(attr):
        return self._wrap_callable(name, api, attr)
    return attr

FlowAPI #

FlowAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for flow resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

FlowV1API #

FlowV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, FlowAPI

Version 1 API implementation for flow resources.

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

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

FlowV2API #

FlowV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, FlowAPI

Version 2 API implementation for flow resources.

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

ResourceAPI #

ResourceAPI(http: HTTPClient, minio: MinIOClient)

Bases: ABC

Abstract base class for OpenML resource APIs.

This class defines the common interface for interacting with OpenML resources (e.g., datasets, flows, runs) across different API versions. Concrete subclasses must implement the resource-specific operations such as publishing, deleting, and tagging.

PARAMETER DESCRIPTION
http

Configured HTTP client used for communication with the OpenML API.

TYPE: HTTPClient

minio

Configured MinIO client used for object storage operations.

TYPE: MinIOClient

ATTRIBUTE DESCRIPTION
api_version

API version implemented by the resource.

TYPE: APIVersion

resource_type

Type of OpenML resource handled by the implementation.

TYPE: ResourceType

_http

Internal HTTP client instance.

TYPE: HTTPClient

_minio

Internal MinIO client instance, if provided.

TYPE: MinIOClient or None

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

ResourceV1API #

ResourceV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Version 1 implementation of the OpenML resource API.

This class provides XML-based implementations for publishing, deleting, tagging, and untagging resources using the V1 API endpoints. Responses are parsed using xmltodict.

Notes

V1 endpoints expect and return XML. Error handling follows the legacy OpenML server behavior and maps specific error codes to more descriptive exceptions where appropriate.

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

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

ResourceV2API #

ResourceV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Version 2 implementation of the OpenML resource API.

This class represents the V2 API for resources. Operations such as publishing, deleting, tagging, and untagging are currently not supported and will raise OpenMLNotSupportedError.

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

RunAPI #

RunAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for run resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

RunV1API #

RunV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, RunAPI

Version 1 API implementation for run resources.

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

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

RunV2API #

RunV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, RunAPI

Version 2 API implementation for run resources.

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

SetupAPI #

SetupAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for setup resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

SetupV1API #

SetupV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, SetupAPI

V1 XML API implementation for setups.

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

exists #

exists(flow: OpenMLFlow, param_settings: list[dict[str, Any]]) -> int | bool

Checks whether a hyperparameter configuration already exists on the server.

PARAMETER DESCRIPTION
flow

The openml flow object. Should have flow id present for the main flow and all subflows (i.e., it should be downloaded from the server by means of flow.get, and not instantiated locally)

TYPE: OpenMLFlow

list

A list of dicts, where each dict has the following entries: oml:name : str: The OpenML parameter name oml:value : mixed: A representation of the parameter value oml:component : int: flow id to which the parameter belongs

RETURNS DESCRIPTION
setup_id

setup id iff exists, False otherwise

TYPE: int

Source code in openml/_api/resources/setup.py
def exists(
    self,
    flow: OpenMLFlow,
    param_settings: builtins.list[dict[str, Any]],
) -> int | bool:
    """
    Checks whether a hyperparameter configuration already exists on the server.

    Parameters
    ----------
    flow : OpenMLFlow
        The openml flow object. Should have flow id present for the main flow
        and all subflows (i.e., it should be downloaded from the server by
        means of flow.get, and not instantiated locally)

    list :
        A list of dicts, where each dict has the following entries:
            oml:name : str: The OpenML parameter name
            oml:value : mixed: A representation of the parameter value
            oml:component : int: flow id to which the parameter belongs

    Returns
    -------
    setup_id : int
        setup id iff exists, False otherwise
    """
    if flow.flow_id is None:
        raise ValueError("Flow must have a flow_id")
    description = xmltodict.unparse(
        SetupV1API._to_dict(flow.flow_id, param_settings), pretty=True
    )
    file_elements = {
        "description": ("description.arff", description),
    }

    api_call = "setup/exists/"
    setup_response = self._http.post(api_call, files=file_elements)
    xml_content = setup_response.text
    result_dict = xmltodict.parse(xml_content)

    setup_id = int(result_dict["oml:setup_exists"]["oml:id"])
    return setup_id if setup_id > 0 else False

get #

get(setup_id: int) -> OpenMLSetup

Downloads the setup (configuration) description from OpenML and returns a structured object

PARAMETER DESCRIPTION
setup_id

The Openml setup_id

TYPE: int

RETURNS DESCRIPTION
OpenMLSetup

An initialized OpenMLSetup object parsed from the XML

Source code in openml/_api/resources/setup.py
def get(self, setup_id: int) -> OpenMLSetup:
    """
    Downloads the setup (configuration) description from OpenML
    and returns a structured object

    Parameters
    ----------
    setup_id : int
        The Openml setup_id

    Returns
    -------
    OpenMLSetup
        An initialized OpenMLSetup object parsed from the XML
    """
    url_suffix = f"setup/{setup_id}"
    setup_response = self._http.get(url_suffix, enable_cache=True)
    xml_content = setup_response.text
    result_dict = xmltodict.parse(xml_content)

    return SetupV1API._create_setup(result_dict)

list #

list(limit: int, offset: int, *, setup: Iterable[int] | None = None, flow: int | None = None, tag: str | None = None) -> list[OpenMLSetup]

Perform API call /setup/list/{filters}

PARAMETER DESCRIPTION
The

filters

limit

TYPE: int

offset

TYPE: int

setup

TYPE: list(int) DEFAULT: None

flow

TYPE: int DEFAULT: None

tag

TYPE: str DEFAULT: None

RETURNS DESCRIPTION
list

setups that match the filters, going from id to the OpenMLSetup object.

Source code in openml/_api/resources/setup.py
def list(
    self,
    limit: int,
    offset: int,
    *,
    setup: Iterable[int] | None = None,
    flow: int | None = None,
    tag: str | None = None,
) -> builtins.list[OpenMLSetup]:
    """Perform API call `/setup/list/{filters}`

    Parameters
    ----------
    The setup argument that is a list is separated from the single value
    filters which are put into the kwargs.

    limit : int
    offset : int
    setup : list(int), optional
    flow : int, optional
    tag : str, optional

    Returns
    -------
    list
        setups that match the filters, going from id to the OpenMLSetup object.
    """
    api_call = SetupV1API._build_url(limit, offset, setup=setup, flow=flow, tag=tag)
    setup_response = self._http.get(api_call)
    xml_content = setup_response.text

    return SetupV1API._parse_list_xml(xml_content)

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

SetupV2API #

SetupV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, SetupAPI

V2 JSoN API implementation for setups.

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

StudyAPI #

StudyAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for study resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

StudyV1API #

StudyV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, StudyAPI

Version 1 API implementation for study resources.

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

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

Version 2 API implementation for study resources.

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

TaskAPI #

TaskAPI(http: HTTPClient, minio: MinIOClient)

Bases: ResourceAPI

Abstract API interface for task resources.

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

delete abstractmethod #

delete(resource_id: int) -> bool

Delete a resource by its identifier.

PARAMETER DESCRIPTION
resource_id

Unique identifier of the resource to delete.

TYPE: int

RETURNS DESCRIPTION
bool

True if the deletion was successful.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def delete(self, resource_id: int) -> bool:
    """
    Delete a resource by its identifier.

    Parameters
    ----------
    resource_id : int
        Unique identifier of the resource to delete.

    Returns
    -------
    bool
        ``True`` if the deletion was successful.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

publish abstractmethod #

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

Publish a new resource to the OpenML server.

PARAMETER DESCRIPTION
path

API endpoint path used for publishing the resource.

TYPE: str

files

Files or payload data required for publishing. The structure depends on the resource type.

TYPE: Mapping of str to Any or None

RETURNS DESCRIPTION
int

Identifier of the newly created resource.

Notes

Concrete subclasses must implement this method.

Source code in openml/_api/resources/base/base.py
@abstractmethod
def publish(self, path: str, files: Mapping[str, Any] | None) -> int:
    """
    Publish a new resource to the OpenML server.

    Parameters
    ----------
    path : str
        API endpoint path used for publishing the resource.
    files : Mapping of str to Any or None
        Files or payload data required for publishing. The structure
        depends on the resource type.

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

    Notes
    -----
    Concrete subclasses must implement this method.
    """

tag abstractmethod #

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

Add a tag to a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

untag abstractmethod #

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

Remove a tag from a resource.

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.

Notes

Concrete subclasses must implement this method.

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

    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.

    Notes
    -----
    Concrete subclasses must implement this method.
    """

TaskV1API #

TaskV1API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV1API, TaskAPI

Version 1 API implementation for task resources.

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

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

TaskV2API #

TaskV2API(http: HTTPClient, minio: MinIOClient)

Bases: ResourceV2API, TaskAPI

Version 2 API implementation for task resources.

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