Skip to content

Notebooks

create_notebook(workspace, display_name, item_definition, *, description=None, folder=None, df=True)

Creates a new notebook in the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
display_name str

The display name of the notebook.

required
description str

A description for the notebook.

None
folder str

The folder to create the notebook in.

None
path str

The path to the notebook definition file.

required

Returns:

Type Description
dict

The created notebook details.

Examples:

create_notebook('MyProjectWorkspace', 'SalesDataModel', 'path/to/definition.json')
create_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', 'path/to/definition.json')
Source code in src/pyfabricops/items/notebooks.py
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
@df
def create_notebook(
    workspace: str,
    display_name: str,
    item_definition: str,
    *,
    description: Optional[str] = None,
    folder: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Creates a new notebook in the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        display_name (str): The display name of the notebook.
        description (str, optional): A description for the notebook.
        folder (str, optional): The folder to create the notebook in.
        path (str): The path to the notebook definition file.

    Returns:
        (dict): The created notebook details.

    Examples:
        ```python
        create_notebook('MyProjectWorkspace', 'SalesDataModel', 'path/to/definition.json')
        create_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', 'path/to/definition.json')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    payload = {'displayName': display_name, 'definition': item_definition}

    if description:
        payload['description'] = description

    if folder:
        folder_id = resolve_folder(workspace_id, folder)
        if folder_id:
            payload['folderId'] = folder_id

    return api_request(
        endpoint='/workspaces/' + workspace_id + '/notebooks',
        method='post',
        payload=payload,
        support_lro=True,
    )

delete_notebook(workspace, notebook)

Delete a notebook from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The name or ID of the workspace to delete.

required
notebook str

The name or ID of the notebook to delete.

required

Returns:

Name Type Description
None None

If the notebook is successfully deleted.

Raises:

Type Description
ResourceNotFoundError

If the specified workspace is not found.

Examples:

delete_notebook('MyProjectWorkspace', 'SalesDataNotebook')
delete_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/items/notebooks.py
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def delete_notebook(workspace: str, notebook: str) -> None:
    """
    Delete a notebook from the specified workspace.

    Args:
        workspace (str): The name or ID of the workspace to delete.
        notebook (str): The name or ID of the notebook to delete.

    Returns:
        None: If the notebook is successfully deleted.

    Raises:
        ResourceNotFoundError: If the specified workspace is not found.

    Examples:
        ```python
        delete_notebook('MyProjectWorkspace', 'SalesDataNotebook')
        delete_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    notebook_id = resolve_notebook(workspace_id, notebook)

    return api_request(
        endpoint='/workspaces/' + workspace_id + '/notebooks/' + notebook_id,
        method='delete',
    )

get_notebook(workspace, notebook, *, df=True)

Retrieves a notebook by its name or ID from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The notebook details if found. If df=True, returns a DataFrame with flattened keys.

Examples:

get_notebook('MyProjectWorkspace', 'SalesDataNotebook')
get_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', df=True)
Source code in src/pyfabricops/items/notebooks.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
@df
def get_notebook(
    workspace: str,
    notebook: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Retrieves a notebook by its name or ID from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The notebook details if found. If `df=True`, returns a DataFrame with flattened keys.

    Examples:
        ```python
        get_notebook('MyProjectWorkspace', 'SalesDataNotebook')
        get_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', df=True)
        ```
    """
    workspace_id = resolve_workspace(workspace)

    notebook_id = resolve_notebook(workspace_id, notebook)

    return api_request(
        endpoint='/workspaces/' + workspace_id + '/notebooks/' + notebook_id,
    )

get_notebook_definition(workspace, notebook)

Retrieves the definition of a notebook by its name or ID from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook.

required

Returns:

Type Description
Union[Dict[str, Any], None]

The notebook definition if found, otherwise None.

Examples:

get_notebook_definition('MyProjectWorkspace', 'Salesnotebook')
get_notebook_definition('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/items/notebooks.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
def get_notebook_definition(
    workspace: str, notebook: str
) -> Union[Dict[str, Any], None]:
    """
    Retrieves the definition of a notebook by its name or ID from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook.

    Returns:
        (Union[Dict[str, Any], None]): The notebook definition if found, otherwise None.

    Examples:
        ```python
        get_notebook_definition('MyProjectWorkspace', 'Salesnotebook')
        get_notebook_definition('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    notebook_id = resolve_notebook(workspace_id, notebook)

    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/notebooks/'
        + notebook_id
        + '/getDefinition',
        method='post',
        support_lro=True,
    )

get_notebook_id(workspace, notebook)

Retrieves the ID of a notebook by its name or ID from the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook.

required

Returns:

Type Description
Union[str, None]

The ID of the notebook if found, otherwise None.

Examples:

get_notebook_id('MyProjectWorkspace', 'SalesDataNotebook')
get_notebook_id('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/items/notebooks.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
def get_notebook_id(workspace: str, notebook: str) -> Union[str, None]:
    """
    Retrieves the ID of a notebook by its name or ID from the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook.

    Returns:
        (Union[str, None]): The ID of the notebook if found, otherwise None.

    Examples:
        ```python
        get_notebook_id('MyProjectWorkspace', 'SalesDataNotebook')
        get_notebook_id('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    notebooks = list_notebooks(workspace, df=False)
    for nb in notebooks:
        if nb['displayName'] == notebook or nb['id'] == notebook:
            return nb['id']
    return None

list_notebooks(workspace, *, df=True)

Lists all notebooks in the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, List[Dict[str, Any]], None]

A list of notebooks, a DataFrame with flattened keys, or None if not found.

Examples:

list_notebooks('MyProjectWorkspace')
list_notebooks('MyProjectWorkspace', df=True)
Source code in src/pyfabricops/items/notebooks.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@df
def list_notebooks(
    workspace: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, List[Dict[str, Any]], None]:
    """
    Lists all notebooks in the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, List[Dict[str, Any]], None]): A list of notebooks, a DataFrame with flattened keys, or None if not found.

    Examples:
        ```python
        list_notebooks('MyProjectWorkspace')
        list_notebooks('MyProjectWorkspace', df=True)
        ```
    """
    return api_request(
        endpoint='/workspaces/' + resolve_workspace(workspace) + '/notebooks',
        support_pagination=True,
    )

resolve_notebook(workspace, notebook)

Resolves a notebook name or ID to its ID in the specified workspace.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook.

required
silent bool

If True, suppresses warnings. Defaults to False.

required

Returns:

Type Description
Union[str, None]

Optional[str]: The ID of the notebook if found, otherwise None.

Examples:

resolve_notebook('MyProjectWorkspace', 'SalesDataNotebook')
resolve_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
Source code in src/pyfabricops/items/notebooks.py
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def resolve_notebook(
    workspace: str,
    notebook: str,
) -> Union[str, None]:
    """
    Resolves a notebook name or ID to its ID in the specified workspace.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook.
        silent (bool): If True, suppresses warnings. Defaults to False.

    Returns:
        Optional[str]: The ID of the notebook if found, otherwise None.

    Examples:
        ```python
        resolve_notebook('MyProjectWorkspace', 'SalesDataNotebook')
        resolve_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000')
        ```
    """
    if is_valid_uuid(notebook):
        return notebook
    else:
        return get_notebook_id(workspace, notebook)

update_notebook(workspace, notebook, *, display_name=None, description=None, df=True)

Updates the properties of the specified notebook.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook to update.

required
display_name Optional[str]

The new display name for the notebook.

None
description Optional[str]

The new description for the notebook.

None
df Optional[bool]

If True or not provided, returns a DataFrame with flattened keys. If False, returns a list of dictionaries.

True

Returns:

Type Description
Union[DataFrame, Dict[str, Any], None]

The updated notebook details if successful, otherwise None.

Examples:

update_notebook('MyProjectWorkspace', 'SalesDataModel', display_name='UpdatedSalesDataModel')
update_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', description='Updated description')
Source code in src/pyfabricops/items/notebooks.py
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
@df
def update_notebook(
    workspace: str,
    notebook: str,
    *,
    display_name: Optional[str] = None,
    description: Optional[str] = None,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Updates the properties of the specified notebook.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook to update.
        display_name (Optional[str]): The new display name for the notebook.
        description (Optional[str]): The new description for the notebook.
        df (Optional[bool]): If True or not provided, returns a DataFrame with flattened keys.
            If False, returns a list of dictionaries.

    Returns:
        (Union[DataFrame, Dict[str, Any], None]): The updated notebook details if successful, otherwise None.

    Examples:
        ```python
        update_notebook('MyProjectWorkspace', 'SalesDataModel', display_name='UpdatedSalesDataModel')
        update_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', description='Updated description')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    notebook_id = resolve_notebook(workspace_id, notebook)

    payload = {}

    if display_name:
        payload['displayName'] = display_name

    if description:
        payload['description'] = description

    return api_request(
        endpoint='/workspaces/' + workspace_id + '/notebooks/' + notebook_id,
        method='patch',
        payload=payload,
    )

update_notebook_definition(workspace, notebook, item_definition, *, df=True)

Updates the definition of an existing notebook in the specified workspace. If the notebook does not exist, it returns None.

Parameters:

Name Type Description Default
workspace str

The workspace name or ID.

required
notebook str

The name or ID of the notebook to update.

required
path str

The path to the notebook definition.

required

Returns:

Type Description
dict or None

The updated notebook details if successful, otherwise None.

Examples:

update_notebook('MyProjectWorkspace', 'SalesDataModel', display_name='UpdatedSalesDataModel')
update_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', description='Updated description')
Source code in src/pyfabricops/items/notebooks.py
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
@df
def update_notebook_definition(
    workspace: str,
    notebook: str,
    item_definition: str,
    *,
    df: Optional[bool] = True,
) -> Union[DataFrame, Dict[str, Any], None]:
    """
    Updates the definition of an existing notebook in the specified workspace.
    If the notebook does not exist, it returns None.

    Args:
        workspace (str): The workspace name or ID.
        notebook (str): The name or ID of the notebook to update.
        path (str): The path to the notebook definition.

    Returns:
        (dict or None): The updated notebook details if successful, otherwise None.

    Examples:
        ```python
        update_notebook('MyProjectWorkspace', 'SalesDataModel', display_name='UpdatedSalesDataModel')
        update_notebook('MyProjectWorkspace', '123e4567-e89b-12d3-a456-426614174000', description='Updated description')
        ```
    """
    workspace_id = resolve_workspace(workspace)

    notebook_id = resolve_notebook(workspace_id, notebook)

    payload = {'definition': item_definition}

    params = {'updateMetadata': True}

    return api_request(
        endpoint='/workspaces/'
        + workspace_id
        + '/notebooks/'
        + notebook_id
        + '/updateDefinition',
        method='post',
        payload=payload,
        params=params,
        support_lro=True,
    )