# Notebooks
URL: https://docs.datarobot.com/en/docs/api/reference/sdk/notebooks.html

# Notebooks

### class datarobot.models.notebooks.enums.NotebookType

Types of notebooks.

### class datarobot.models.notebooks.enums.RunType

Types of notebook job runs.

### class datarobot.models.notebooks.enums.ManualRunType

A subset of [RunType](https://docs.datarobot.com/en/docs/api/reference/sdk/notebooks.html#datarobot.models.notebooks.enums.RunType) To be used in API schemas.

### class datarobot.models.notebooks.enums.SessionType

Types of notebook sessions. Triggered sessions include notebook job runs whether manually triggered or scheduled.

### class datarobot.models.notebooks.enums.ScheduleStatus

Possible statuses for notebook schedules.

### class datarobot.models.notebooks.enums.ScheduledRunStatus

Possible statuses for scheduled notebook runs.

### class datarobot.models.notebooks.enums.NotebookPermissions

Permissions for notebooks.

### class datarobot.models.notebooks.enums.NotebookStatus

Possible statuses for notebook sessions.

### class datarobot.models.notebooks.enums.KernelExecutionStatus

Possible statuses for kernel execution.

### class datarobot.models.notebooks.enums.CellType

Types of cells in a notebook.

### class datarobot.models.notebooks.enums.RuntimeLanguage

Languages as used in notebook jupyter kernels.

### class datarobot.models.notebooks.enums.ImageLanguage

Languages as used and supported in notebook images.

### class datarobot.models.notebooks.enums.KernelSpec

Kernel specifications for Jupyter notebook kernels.

### class datarobot.models.notebooks.enums.KernelState

Possible states for notebook kernels.

### exception datarobot.models.notebooks.exceptions.KernelNotAssignedError

Raised when a Codespace notebook does not have a kernel assigned.

### class datarobot.models.notebooks.notebook.ManualRunPayload

### class datarobot.models.notebooks.notebook.Notebook

Metadata for a DataRobot Notebook accessible to the user.

- Variables:

#### get_uri()

- Returns: url – Permanent static hyperlink to this Notebook in its Use Case or standalone.
- Return type: str

#### classmethod get(notebook_id)

Retrieve a single notebook.

- Parameters: notebook_id ( str ) – The ID of the notebook you want to retrieve.
- Returns: notebook – The requested notebook.
- Return type: Notebook

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> ```

#### create_revision(name=None, notebook_path=None, is_auto=False)

Create a new revision for the notebook.

- Parameters:
- Returns: notebook_revision – Information about the created notebook revision.
- Return type: NotebookRevision

#### download_revision(revision_id, file_path=None, filelike=None)

Downloads the notebook as a JSON (.ipynb) file for the specified revision.

- Parameters:
- Return type: None

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> manual_run = notebook.run_as_job()
> revision_id = manual_run.wait_for_completion()
> notebook.download_revision(revision_id=revision_id, file_path="./results.ipynb")
> ```

#### delete()

Delete a single notebook

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> notebook.delete()
> ```

- Return type: None

#### classmethod list(created_before=None, created_after=None, order_by=None, tags=None, owners=None, query=None, use_cases=None)

List all Notebooks available to the user.

- Parameters:
- Returns: notebooks – A list of Notebooks available to the user.
- Return type: List[Notebook]

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebooks = Notebook.list()
> ```

#### is_running()

Check if the notebook session is currently running.

- Return type: bool

#### get_session_status()

Get the status of the notebook session.

- Return type: NotebookStatus

#### start_session(is_triggered_run=False, parameters=None, open_file_paths=None, clone_repository=None)

Start a new session for the notebook.

- Parameters:
- Returns: notebook_session – The created notebook session.
- Return type: NotebookSession

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> session = notebook.start_session()
> ```

#### stop_session()

Stop the current session for the notebook.

- Returns: notebook_session – The stopped notebook session.
- Return type: NotebookSession

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> session = notebook.stop_session()
> ```

#### execute(notebook_path=None, cell_ids=None)

Execute the notebook. Assumes session is already started.

- Parameters:
- Return type: None

#### get_execution_status()

Get the execution status information of the notebook.

- Returns: execution_status – The notebook execution status information.
- Return type: NotebookExecutionStatus

#### is_finished_executing(notebook_path=None)

Check if the notebook is finished executing.

- Parameters: notebook_path ( Optional[str] ) – The path of the notebook the Codespace. Required only if the notebook is in a Codespace.
  Will raise an error if working with a standalone notebook.
- Returns: is_finished_executing – Whether or not the notebook has finished executing.
- Return type: bool
- Raises:

#### run_as_job(title=None, notebook_path=None, parameters=None, manual_run_type=ManualRunType.MANUAL)

Create a manual scheduled job that runs the notebook.

> [!NOTE] Notes
> The notebook must be part of a Use Case.
> If the notebook is in a Codespace then notebook_path is required.

- Parameters:
- Returns: notebook_scheduled_job – The created notebook schedule job.
- Return type: NotebookScheduledJob
- Raises: InvalidUsageError – If attempting to create a manual scheduled run for a Codespace without a notebook path.

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> manual_run = notebook.run_as_job()
> 
> # Alternatively, with title and parameters:
> # manual_run = notebook.run_as_job(title="My Run", parameters=[{"name": "FOO", "value": "bar"}])
> 
> revision_id = manual_run.wait_for_completion()
> ```

#### list_schedules(enabled_only=False)

List all NotebookScheduledJobs associated with the notebook.

- Parameters: enabled_only ( bool ) – Whether or not to return only enabled schedules.
- Returns: notebook_schedules – A list of schedules for the notebook.
- Return type: List[NotebookScheduledJob]
- Raises: InvalidUsageError – If attempting to list schedules for a notebook not associated with a Use Case.

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> enabled_schedules = notebook.list_schedules(enabled_only=True)
> ```

### class datarobot.models.notebooks.execution_environment.ExecutionEnvironmentAssignPayload

Payload for assigning an execution environment to a notebook.

### class datarobot.models.notebooks.execution_environment.Image

Execution environment image information.

- Variables:

### class datarobot.models.notebooks.execution_environment.Machine

Execution environment machine information.

- Variables:

### class datarobot.models.notebooks.execution_environment.ExecutionEnvironment

An execution environment associated with a notebook.

- Variables:

#### classmethod get(notebook_id)

Get a notebook execution environment by its notebook ID.

- Parameters: notebook_id ( str ) – The ID of the notebook.
- Returns: The notebook execution environment.
- Return type: ExecutionEnvironment

#### classmethod assign_environment(notebook_id, payload)

Assign execution environment values to a notebook.

- Parameters:
- Returns: The assigned execution environment.
- Return type: ExecutionEnvironment

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import ExecutionEnvironment, ExecutionEnvironmentAssignPayload
> 
> payload = ExecutionEnvironmentAssignPayload(machine_slug='medium', time_to_live=10)
> exec_env = ExecutionEnvironment.assign_environment('67914bfab0279fd832dc3fd1', payload)
> ```

### class datarobot.models.notebooks.kernel.NotebookKernel

A kernel associated with a codespace notebook.

- Variables:

### class datarobot.models.notebooks.revision.CreateRevisionPayload

Payload for creating a notebook revision.

### class datarobot.models.notebooks.revision.NotebookRevision

Represents a notebook revision.

- Variables:

#### classmethod create(notebook_id, payload=None)

Create a new notebook revision.

- Parameters:
- Returns: Information about the created notebook revision.
- Return type: NotebookRevision

### class datarobot.models.notebooks.scheduled_job.NotebookScheduledJob

DataRobot Notebook Schedule. A scheduled job that runs a notebook.

- Variables:

#### classmethod get(use_case_id, scheduled_job_id)

Retrieve a single notebook schedule.

- Parameters: scheduled_job_id ( str ) – The ID of the notebook schedule you want to retrieve.
- Returns: notebook_schedule – The requested notebook schedule.
- Return type: NotebookScheduledJob

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import NotebookScheduledJob
> 
> notebook_schedule = NotebookScheduledJob.get(
>     use_case_id="654ad653c6c1e889e8eab12e",
>     scheduled_job_id="65734fe637157200e28bf688",
> )
> ```

#### classmethod list(notebook_ids=None, statuses=None)

List all NotebookScheduledJobs available to the user.

- Parameters:
- Returns: notebook_schedules – A list of NotebookScheduledJobs available to the user.
- Return type: List[NotebookScheduledJob]

#### cancel()

Cancel a running notebook schedule.

- Return type: None

#### get_most_recent_run()

Retrieve the most recent run for the notebook schedule.

- Returns: notebook_scheduled_run – The most recent run for the notebook schedule, or None if no runs have been made.
- Return type: Optional[NotebookScheduledRun]

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import NotebookScheduledJob
> 
> notebook_schedule = NotebookScheduledJob.get(
>     use_case_id="654ad653c6c1e889e8eab12e",
>     scheduled_job_id="65734fe637157200e28bf688",
> )
> most_recent_run = notebook_schedule.get_most_recent_run()
> ```

#### get_job_history()

Retrieve list of historical runs for the notebook schedule. Gets the most recent runs first.

- Returns: notebook_scheduled_runs – The list of historical runs for the notebook schedule.
- Return type: List[NotebookScheduledRun]

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks import NotebookScheduledJob
> 
> notebook_schedule = NotebookScheduledJob.get(
>     use_case_id="654ad653c6c1e889e8eab12e",
>     scheduled_job_id="65734fe637157200e28bf688",
> )
> notebook_scheduled_runs = notebook_schedule.get_job_history()
> ```

#### wait_for_completion(max_wait=600)

Wait for the completion of a scheduled notebook and return the revision ID corresponding to the run’s output.

- Parameters: max_wait ( int ) – The number of seconds to wait before giving up.
- Returns: revision_id – Returns either revision ID or message describing current state.
- Return type: str

> [!NOTE] Examples
> ```
> from datarobot.models.notebooks.notebook import Notebook
> 
> notebook = Notebook.get(notebook_id='6556b00dcc4ea0bb7ea48121')
> manual_run = notebook.run_as_job()
> revision_id = manual_run.wait_for_completion()
> ```

### class datarobot.models.notebooks.scheduled_run.ScheduledJobParam

DataRobot Schedule Job Parameter.

- Variables:

### class datarobot.models.notebooks.scheduled_run.ScheduledJobPayload

DataRobot Schedule Job Payload.

- Variables:

### class datarobot.models.notebooks.scheduled_run.ScheduledRunRevisionMetadata

DataRobot Notebook Revision Metadata specifically for a scheduled run.

Both id and name can be null if for example the job is still running or has failed.

- Variables:

### class datarobot.models.notebooks.scheduled_run.NotebookScheduledRun

DataRobot Notebook Scheduled Run. A historical run of a notebook schedule.

- Variables:

### class datarobot.models.notebooks.session.CloneRepositorySchema

Schema for cloning a repository when starting a notebook session.

### class datarobot.models.notebooks.session.StartSessionParameters

Parameters used as environment variables in a notebook session.

### class datarobot.models.notebooks.session.StartSessionPayload

Payload for starting a notebook session.

### class datarobot.models.notebooks.session.NotebookExecutionStatus

Notebook execution status information.

- Variables:

### class datarobot.models.notebooks.session.CodespaceNotebookCell

Represents a cell in a codespace notebook.

### class datarobot.models.notebooks.session.CodespaceNotebookState

Notebook state information for a codespace notebook.

- Variables:

### class datarobot.models.notebooks.session.NotebookSession

Notebook session information.

- Variables:

#### classmethod get(notebook_id)

Get a notebook session by its notebook ID.

- Parameters: notebook_id ( str ) – The ID of the notebook.
- Returns: The notebook session information.
- Return type: NotebookSession

#### classmethod start(notebook_id, payload)

Start a notebook session.

- Parameters:
- Returns: The notebook session information.
- Return type: NotebookSession

#### classmethod stop(notebook_id)

Stop a notebook session.

- Parameters: notebook_id ( str ) – The ID of the notebook.
- Returns: The notebook session information.
- Return type: NotebookSession

#### classmethod execute_notebook(notebook_id, cell_ids=None)

Execute a notebook.

- Parameters:
- Return type: None

#### classmethod execute_codespace_notebook(notebook_id, notebook_path, generation, cells)

Execute a notebook.

- Parameters:
- Return type: None

#### classmethod get_execution_status(notebook_id)

Get the execution status information of a notebook.

- Parameters: notebook_id ( str ) – The ID of the notebook.
- Returns: The execution status information of the notebook.
- Return type: NotebookExecutionStatus

### class datarobot.models.notebooks.settings.NotebookSettings

Settings for a DataRobot Notebook.

- Variables:

### class datarobot.models.notebooks.user.NotebookUser

A user associated with a Notebook.

- Variables:

### class datarobot.models.notebooks.user.NotebookActivity

A record of activity (i.e., last run, updated, etc.) in a Notebook.

- Variables:

---
