diff --git a/.codegen/_last_sha b/.codegen/_last_sha index d80d0c353..ab0b9f674 100644 --- a/.codegen/_last_sha +++ b/.codegen/_last_sha @@ -1 +1 @@ -bcd995071117be59fe1e8c3e3ecfae77ac90b355 \ No newline at end of file +7216eeb8c5e517080d626f64b36209fea64788b3 \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f305043f1..64204a0d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Version changelog +## Release v0.145.0 (2026-10-01) + +### API Changes +* Add `list_commands()` method for [w.sandbox](https://databricks-sdk-py.readthedocs.io/en/latest/workspace/sandbox/sandbox.html) workspace-level service. + ## Release v0.144.0 (2026-09-30) ### API Changes @@ -12,10 +17,10 @@ * Add `environment_variables` field for `databricks.sdk.service.jobs.SubmitRun`. * Add `environment_variables_key` field for `databricks.sdk.service.jobs.SubmitTask`. * Add `environment_variables_key` field for `databricks.sdk.service.jobs.Task`. -* Change `command_path` field for `databricks.sdk.service.jobs.DeploymentSpec` to no longer be required. * [Breaking] Change `command_path` field for `databricks.sdk.service.jobs.DeploymentSpec` to no longer be required. -* [Breaking] Change `api_secret_ref` field for `databricks.sdk.service.ml.SchemaRegistryConfig` to no longer be required. +* Change `command_path` field for `databricks.sdk.service.jobs.DeploymentSpec` to no longer be required. * Change `api_secret_ref` field for `databricks.sdk.service.ml.SchemaRegistryConfig` to no longer be required. +* [Breaking] Change `api_secret_ref` field for `databricks.sdk.service.ml.SchemaRegistryConfig` to no longer be required. ## Release v0.143.0 (2026-09-26) diff --git a/databricks/sdk/service/sandbox.py b/databricks/sdk/service/sandbox.py index 6bc4ba34b..5e59e95ee 100644 --- a/databricks/sdk/service/sandbox.py +++ b/databricks/sdk/service/sandbox.py @@ -17,6 +17,7 @@ _duration, _enum, _from_dict, + _int64, _repeated_dict, _timestamp, ) @@ -29,6 +30,76 @@ # all definitions in this file are in alphabetical order +@dataclass +class Command: + """A single command execution.""" + + args: Optional[List[str]] = None + """Arguments passed to the program.""" + + cmd: Optional[str] = None + """The program that was executed.""" + + command_id: Optional[str] = None + """Stable identifier for this command.""" + + exit_code: Optional[int] = None + """Process exit code. Only present when finished is true and the process exited normally (not + killed by signal or failed to start).""" + + finished: Optional[bool] = None + """Whether the command has finished executing.""" + + pid: Optional[int] = None + """PID of the spawned process. Absent if the process failed to start.""" + + def as_dict(self) -> dict: + """Serializes the Command into a dictionary suitable for use as a JSON request body.""" + body = {} + if self.args: + body["args"] = [v for v in self.args] + if self.cmd is not None: + body["cmd"] = self.cmd + if self.command_id is not None: + body["command_id"] = self.command_id + if self.exit_code is not None: + body["exit_code"] = self.exit_code + if self.finished is not None: + body["finished"] = self.finished + if self.pid is not None: + body["pid"] = self.pid + return body + + def as_shallow_dict(self) -> dict: + """Serializes the Command into a shallow dictionary of its immediate attributes.""" + body = {} + if self.args: + body["args"] = self.args + if self.cmd is not None: + body["cmd"] = self.cmd + if self.command_id is not None: + body["command_id"] = self.command_id + if self.exit_code is not None: + body["exit_code"] = self.exit_code + if self.finished is not None: + body["finished"] = self.finished + if self.pid is not None: + body["pid"] = self.pid + return body + + @classmethod + def from_dict(cls, d: Dict[str, Any]) -> Command: + """Deserializes the Command from a dictionary.""" + return cls( + args=d.get("args", None), + cmd=d.get("cmd", None), + command_id=d.get("command_id", None), + exit_code=d.get("exit_code", None), + finished=d.get("finished", None), + pid=_int64(d, "pid"), + ) + + @dataclass class ComputeSpec: inactivity_timeout: Optional[Duration] = None @@ -137,6 +208,40 @@ def from_dict(cls, d: Dict[str, Any]) -> ExecuteCommandSyncResponse: ) +@dataclass +class ListCommandsResponse: + """Response listing tracked command executions.""" + + commands: Optional[List[Command]] = None + """Commands in this page of results.""" + + next_page_token: Optional[str] = None + """Token to retrieve the next page. Empty when there are no more results.""" + + def as_dict(self) -> dict: + """Serializes the ListCommandsResponse into a dictionary suitable for use as a JSON request body.""" + body = {} + if self.commands: + body["commands"] = [v.as_dict() for v in self.commands] + if self.next_page_token is not None: + body["next_page_token"] = self.next_page_token + return body + + def as_shallow_dict(self) -> dict: + """Serializes the ListCommandsResponse into a shallow dictionary of its immediate attributes.""" + body = {} + if self.commands: + body["commands"] = self.commands + if self.next_page_token is not None: + body["next_page_token"] = self.next_page_token + return body + + @classmethod + def from_dict(cls, d: Dict[str, Any]) -> ListCommandsResponse: + """Deserializes the ListCommandsResponse from a dictionary.""" + return cls(commands=_repeated_dict(d, "commands", Command), next_page_token=d.get("next_page_token", None)) + + @dataclass class ListSandboxesResponse: """A list of Sandboxes.""" @@ -422,6 +527,38 @@ def get_sandbox(self, name: str) -> Sandbox: res = self._api.do("GET", f"/api/2.0/{name}", headers=headers) return Sandbox.from_dict(res) + def list_commands( + self, parent: str, *, page_size: Optional[int] = None, page_token: Optional[str] = None + ) -> ListCommandsResponse: + """Lists the tracked command executions (running and completed) in a sandbox. + + :param parent: str + The sandbox whose commands to list, in the form ``sandboxes/{sandbox_id}``. + :param page_size: int (optional) + Maximum number of commands to return. The server may return fewer. If unspecified, the server + returns all commands. + :param page_token: str (optional) + Page token returned by a previous ListCommands call. Use this to retrieve the next page of results. + + :returns: :class:`ListCommandsResponse` + """ + + query = {} + if page_size is not None: + query["page_size"] = page_size + if page_token is not None: + query["page_token"] = page_token + headers = { + "Accept": "application/json", + } + + cfg = self._api._cfg + if cfg.workspace_id: + headers["X-Databricks-Workspace-Id"] = cfg.workspace_id + + res = self._api.do("GET", f"/api/2.0/sandbox-exec/{parent}/commands", query=query, headers=headers) + return ListCommandsResponse.from_dict(res) + def list_sandboxes(self, *, page_size: Optional[int] = None, page_token: Optional[str] = None) -> Iterator[Sandbox]: """Lists all Sandboxes. diff --git a/databricks/sdk/version.py b/databricks/sdk/version.py index 3b5229b1c..37d52baa2 100644 --- a/databricks/sdk/version.py +++ b/databricks/sdk/version.py @@ -1 +1 @@ -__version__ = "0.144.0" +__version__ = "0.145.0" diff --git a/docs/dbdataclasses/sandbox.rst b/docs/dbdataclasses/sandbox.rst index 5c0094f1c..c320f05e4 100644 --- a/docs/dbdataclasses/sandbox.rst +++ b/docs/dbdataclasses/sandbox.rst @@ -4,6 +4,10 @@ Sandbox These dataclasses are used in the SDK to represent API requests and responses for services in the ``databricks.sdk.service.sandbox`` module. .. py:currentmodule:: databricks.sdk.service.sandbox +.. autoclass:: Command + :members: + :undoc-members: + .. autoclass:: ComputeSpec :members: :undoc-members: @@ -25,6 +29,10 @@ These dataclasses are used in the SDK to represent API requests and responses fo :members: :undoc-members: +.. autoclass:: ListCommandsResponse + :members: + :undoc-members: + .. autoclass:: ListSandboxesResponse :members: :undoc-members: diff --git a/docs/workspace/sandbox/sandbox.rst b/docs/workspace/sandbox/sandbox.rst index 00216a60c..197640b8c 100644 --- a/docs/workspace/sandbox/sandbox.rst +++ b/docs/workspace/sandbox/sandbox.rst @@ -95,6 +95,21 @@ :returns: :class:`Sandbox` + .. py:method:: list_commands(parent: str [, page_size: Optional[int], page_token: Optional[str]]) -> ListCommandsResponse + + Lists the tracked command executions (running and completed) in a sandbox. + + :param parent: str + The sandbox whose commands to list, in the form ``sandboxes/{sandbox_id}``. + :param page_size: int (optional) + Maximum number of commands to return. The server may return fewer. If unspecified, the server + returns all commands. + :param page_token: str (optional) + Page token returned by a previous ListCommands call. Use this to retrieve the next page of results. + + :returns: :class:`ListCommandsResponse` + + .. py:method:: list_sandboxes( [, page_size: Optional[int], page_token: Optional[str]]) -> Iterator[Sandbox] Lists all Sandboxes.