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, Ketcher chemical drawings, Microsoft Office documents, and
embedded reports). 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. |
search |
Search notebook block content across projects. |
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
To find notebooks by their block content instead of by parent, use
search.
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
search
search(
*,
text: str | None = None,
project_id: SearchProjectId | None = None,
sort_by: str | None = None,
order: OrderBy | None = None,
max_items: int | None = None,
) -> Iterator[NotebookSearchItem]
Search for notebook block content matching the given filters.
Each result is a NotebookSearchItem
representing a single matching content block, not a full notebook. Use
get_by_id or
get_block_by_id
to retrieve full notebook content. Results are returned as a lazily
paginated iterator.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Free-text search term matched against block content. |
None
|
project_id
|
SearchProjectId
|
Scope the search to notebooks in the given project (format |
None
|
sort_by
|
str
|
Field to sort on. |
None
|
order
|
OrderBy
|
Sort direction for |
None
|
max_items
|
int
|
Maximum number of items to return in total. If None, iterates over all matches. |
None
|
Returns:
| Type | Description |
|---|---|
Iterator[NotebookSearchItem]
|
A lazily paginated iterator of block-level search hits. |
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).
When writing @-mention chips (<span data-albertid="..." data-type="...">
spans) into block text, also create the backing mention links. Saving the
HTML does not register them, and without a link the chip does not resolve
in the UI. Create one link per mentioned entity with
create
(category="mention", parent = the notebook, child = the mentioned
entity), then re-read the notebook and confirm its links list them.
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.
When |
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. |