Notebooks
albert.collections.notebooks.NotebookCollection
Bases: BaseCollection
Manage Notebooks in the Albert platform.
A Notebook is an electronic lab notebook (ELN): an ordered document made up
of content blocks (paragraphs, headers, checklists, tables, images, file
attachments, and Ketcher chemical drawings). Each Notebook is attached to a
parent entity, which is a Project, a Task, or a custom template, and is
referenced by its Notebook ID (format NTB..., e.g. "NTB123").
Notebook content is edited block-by-block rather than by overwriting the whole
document. Create an empty Notebook with create, then add or change
blocks with update_block_content or append_blocks. The
update method changes only the Notebook name.
This collection is accessed as client.notebooks.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
base_path |
str
|
The base API route for notebook requests. |
Methods:
| Name | Description |
|---|---|
get_by_id |
Get a single notebook by its ID. |
list_by_parent_id |
List the notebooks attached to a given parent (project or task). |
create |
Find or create an (empty) notebook for the given parent. |
delete |
Delete a notebook by its ID. |
update |
Update a notebook's name. |
update_block_content |
Replace the notebook's block content with the blocks on the object. |
append_blocks |
Append blocks to the end of a notebook, preserving existing blocks. |
get_block_by_id |
Get a single block from a notebook by block ID. |
copy |
Copy a notebook into a specified parent. |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
AlbertSession
|
The authenticated Albert session used for API calls. |
required |
Source code in src/albert/collections/notebooks.py
get_by_id
get_by_id(*, id: NotebookId) -> Notebook
Get a single Notebook by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
NotebookId
|
The Notebook ID to retrieve (format |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The fully populated notebook. |
Source code in src/albert/collections/notebooks.py
list_by_parent_id
List the Notebooks attached to a given parent entity.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent_id
|
ProjectId or TaskId
|
The ID of the parent entity whose notebooks should be listed
(a Project ID, format |
required |
Returns:
| Type | Description |
|---|---|
list[Notebook]
|
The fully populated notebooks attached to the parent. |
Source code in src/albert/collections/notebooks.py
create
Find or create a Notebook for the provided notebook.
The endpoint first tries to find an existing notebook for the same parent with matching properties; if one is found it is returned, otherwise a new notebook is created.
The notebook must be created empty: the blocks field must be empty.
Add content afterward with update_block_content or
append_blocks.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook
|
Notebook
|
The notebook to find or create. Must have a |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The found or newly created notebook. |
Raises:
| Type | Description |
|---|---|
AlbertException
|
If the notebook has pre-filled blocks. |
Source code in src/albert/collections/notebooks.py
delete
delete(*, id: NotebookId) -> None
Delete a Notebook by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
NotebookId
|
The Notebook ID to delete (format |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/notebooks.py
update
Update a Notebook's name.
This method changes only the notebook name; it does not modify block
content. Use update_block_content to change the blocks.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook
|
Notebook
|
The notebook carrying the desired name. It must have an |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The updated notebook. |
Notes
The following fields can be updated: name.
Source code in src/albert/collections/notebooks.py
update_block_content
Replace a Notebook's block content with the blocks on the object.
The notebook's blocks list is treated as the desired final state: the
order of the blocks is preserved, any block not already on Albert is
created, and any existing block that is no longer present is deleted. This
does not change the notebook name (use update for that).
Warning
Updating existing Ketcher blocks is not supported. To change a Ketcher block, delete it and create a new one instead.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook
|
Notebook
|
The notebook whose |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The updated notebook. |
Raises:
| Type | Description |
|---|---|
AlbertException
|
If the notebook has no |
Source code in src/albert/collections/notebooks.py
append_blocks
append_blocks(
*, id: NotebookId, blocks: list[NotebookBlock]
) -> Notebook
Append blocks to the end of a Notebook, preserving existing blocks.
This is a convenience wrapper around update_block_content: it
fetches the current notebook, adds the given blocks after the existing
ones, and saves.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id
|
NotebookId
|
The Notebook ID to append to (format |
required |
blocks
|
list[NotebookBlock]
|
The blocks to append to the end of the notebook. |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The updated notebook. |
Source code in src/albert/collections/notebooks.py
get_block_by_id
get_block_by_id(
*, notebook_id: NotebookId, block_id: str
) -> NotebookBlock
Get a single block from a Notebook by block ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook_id
|
NotebookId
|
The Notebook ID the block belongs to (format |
required |
block_id
|
str
|
The ID of the block to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
NotebookBlock
|
The requested block, typed according to its block type (e.g.
|
Source code in src/albert/collections/notebooks.py
copy
copy(
*,
notebook_copy_info: NotebookCopyInfo,
type: NotebookCopyType,
) -> Notebook
Copy a Notebook into a specified parent.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook_copy_info
|
NotebookCopyInfo
|
Describes the source notebook and the destination parent for the copy. |
required |
type
|
NotebookCopyType
|
The kind of copy to perform (e.g. into a template, task, or project, or restoring a template). |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The newly created copy. |