Skip to content
25 changes: 25 additions & 0 deletions python/hopsworks_common/core/library_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,28 @@ def _install(
),
environment=self,
)

def _uninstall(self, library_name: str, name: str) -> None:
"""Uninstall a library from the environment.

Parameters:
library_name: Name of the library.
name: Name of the environment.

Raises:
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request.
"""
_client = client.get_instance()

path_params = [
"project",
_client._project_id,
"python",
"environments",
name,
"libraries",
library_name,
]

headers = {"content-type": "application/json"}
_client._send_request("DELETE", path_params, headers=headers)
33 changes: 33 additions & 0 deletions python/hopsworks_common/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,39 @@ def install_requirements(self, path: str, await_installation: bool | None = True
if await_installation:
self._environment_engine.await_library_command(self.name, library_name)

@public
@usage.method_logger
def uninstall(
self, library_name: str, await_uninstallation: bool | None = True
) -> None:
"""Uninstall a library from the environment.

```python
import hopsworks

project = hopsworks.login()

env_api = project.get_environment_api()
env = env_api.get_environment("my_custom_environment")

env.uninstall("matplotlib")
```

Parameters:
library_name: Name of the installed library to remove.
await_uninstallation: If `True` the method returns only when the uninstallation finishes.

Raises:
hopsworks.client.exceptions.RestAPIError: If the backend encounters an error when handling the request.
"""
# Wait for any ongoing environment operations
self._environment_engine.await_environment_command(self.name)

self._library_api._uninstall(library_name, self.name)

if await_uninstallation:
self._environment_engine.await_library_command(self.name, library_name)

@public
@usage.method_logger
def delete(self):
Expand Down
22 changes: 22 additions & 0 deletions python/hsml/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ def stop(self, await_stopped: int | None = 600):
"""
self._serving_engine.stop(self, await_status=await_stopped)

@public
@usage.method_logger
def restart(
self,
await_stopped: int | None = 600,
await_running: int | None = 600,
) -> None:
"""Restart the deployment so it picks up the latest code and environment state.

If the deployment is already stopped, it is started in place.

Parameters:
await_stopped: Awaiting time (seconds) for the deployment to stop.
await_running: Awaiting time (seconds) for the deployment to start again.

Raises:
hopsworks.client.exceptions.RestAPIError: In case the backend encounters an issue.
"""
if not self.is_stopped():
self.stop(await_stopped=await_stopped)
self.start(await_running=await_running)

@public
@usage.method_logger
def delete(self, force: bool = False):
Expand Down
Loading
Loading