Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .codegen/_last_sha
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bcd995071117be59fe1e8c3e3ecfae77ac90b355
7216eeb8c5e517080d626f64b36209fea64788b3
9 changes: 7 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)

Expand Down
137 changes: 137 additions & 0 deletions databricks/sdk/service/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
_duration,
_enum,
_from_dict,
_int64,
_repeated_dict,
_timestamp,
)
Expand All @@ -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
Expand Down Expand Up @@ -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."""
Expand Down Expand Up @@ -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.

Expand Down
2 changes: 1 addition & 1 deletion databricks/sdk/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.144.0"
__version__ = "0.145.0"
8 changes: 8 additions & 0 deletions docs/dbdataclasses/sandbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions docs/workspace/sandbox/sandbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading