Skip to content

hopsworks_common.core.rest #

Stable internal REST helper for SDK consumers (CLI and core/<entity>_api modules).

The Hopsworks Python SDK already has an authenticated HTTP client at hopsworks_common.client.get_instance(), but its surface (_send_request, _project_id) is private — the underscore prefix means callers shouldn't depend on it. Multiple call sites (the hops CLI's fv list, connector list, model list, …) reach through anyway because the SDK's per-entity wrappers don't yet cover every endpoint.

This module exposes the bare minimum stable surface for those call sites:

  • :func:send_request — perform a request against /hopsworks-api/api/... with shared host/auth/TLS configuration.
  • :func:project_path — build a project/<id>/... path tuple so callers don't reach into _project_id directly.

Internal SDK consumers should import from here rather than client.get_instance() directly so the underlying HTTP machinery can change shape without breaking external callers.

project_path #

project_path(*tail: Any) -> list[Any]

Build a ["project", <project_id>, *tail] path list.

PARAMETER DESCRIPTION
*tail

Path components to append after project/<id>. Numeric IDs are accepted alongside strings — :func:send_request URL-encodes them.

TYPE: Any DEFAULT: ()

RETURNS DESCRIPTION
list[Any]

A list ready to pass as path_params to :func:send_request.

RAISES DESCRIPTION
RuntimeError

When the SDK is not connected (hopsworks.login has not been called yet).

send_request #

send_request(
    method: str,
    path_params: list[Any],
    query_params: dict[str, Any] | None = None,
    json_body: Any | None = None,
) -> Any

Issue an authenticated request to /hopsworks-api/api/<path_params>.

Wraps the SDK's internal client so per-call sites don't reach into _send_request directly. Auth, host normalization, TLS verification and base URL construction are all inherited from the active :func:hopsworks_common.client.get_instance instance — the same one the rest of the SDK uses.

PARAMETER DESCRIPTION
method

HTTP method ("GET", "POST", "PUT", "DELETE").

TYPE: str

path_params

List of path components (URL-encoded by the client).

TYPE: list[Any]

query_params

Optional query string parameters.

TYPE: dict[str, Any] | None DEFAULT: None

json_body

Optional Python object to serialize as the JSON request body. The content-type: application/json header is set automatically.

TYPE: Any | None DEFAULT: None

RETURNS DESCRIPTION
Any

The JSON-decoded response body, or whatever the client's

Any

_send_request returns for non-JSON / empty responses.

RAISES DESCRIPTION
hopsworks_common.client.exceptions.RestAPIError

When the backend returns a non-2xx response.