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,
or edit single blocks in place with create_block,
update_block, and
delete_block. 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. |
create_block |
Create a single block in a notebook. |
update_block |
Update the content of a single notebook block in place. |
delete_block |
Delete a single block from a notebook. |
get_versions |
Get the saved versions of a notebook. |
restore_version |
Restore a notebook to a saved version. |
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_by_parent_id(
*,
parent_id: ProjectId | TaskId,
max_items: int | None = None,
) -> list[Notebook]
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 |
max_items
|
int
|
Maximum number of notebooks to return. If None (the default), returns every notebook attached to the parent. |
None
|
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
create_block
create_block(
*,
notebook_id: NotebookId,
block: NotebookBlock,
previous_block_id: str | None = None,
) -> NotebookBlock
Create a single block in a Notebook.
The new block takes the id of the given block object; block IDs are
generated automatically (a UUID) when the block object is built. To add
several blocks at once or to reshape the whole document, use
update_block_content
or append_blocks.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook_id
|
NotebookId
|
The Notebook ID to create the block in (format |
required |
block
|
NotebookBlock
|
The block to create, typed according to its block type (e.g.
|
required |
previous_block_id
|
str
|
The ID of the block the new block should follow. |
None
|
Returns:
| Type | Description |
|---|---|
NotebookBlock
|
The created block. |
Source code in src/albert/collections/notebooks.py
update_block
update_block(
*, notebook_id: NotebookId, block: NotebookBlock
) -> NotebookBlock
Update the content of a single Notebook block in place.
Only the block's own content changes; the surrounding blocks are left
untouched. If the content is unchanged, the existing block is returned
unchanged. To change many blocks at once or to reorder them, use
update_block_content.
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_id
|
NotebookId
|
The Notebook ID the block belongs to (format |
required |
block
|
NotebookBlock
|
The block carrying the desired content. Its |
required |
Returns:
| Type | Description |
|---|---|
NotebookBlock
|
The updated block. |
Raises:
| Type | Description |
|---|---|
AlbertException
|
If the given block's type differs from the existing block's type. |
Notes
The following fields can be updated: content.
Source code in src/albert/collections/notebooks.py
delete_block
delete_block(
*, notebook_id: NotebookId, block_id: str
) -> None
Delete a single block from a Notebook.
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 delete. |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in src/albert/collections/notebooks.py
get_versions
get_versions(
*, notebook_id: NotebookId
) -> list[NotebookVersion]
Get the saved versions of a Notebook.
Each NotebookVersion
captures the notebook's content at a point in time. Restore one with
restore_version.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook_id
|
NotebookId
|
The Notebook ID whose versions should be listed (format |
required |
Returns:
| Type | Description |
|---|---|
list[NotebookVersion]
|
The saved versions of the notebook. |
Source code in src/albert/collections/notebooks.py
restore_version
restore_version(
*, notebook_id: NotebookId, version_id: str
) -> Notebook
Restore a Notebook to a saved version.
The notebook's content is replaced with the content captured in the
given version. List the saved versions with
get_versions.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
notebook_id
|
NotebookId
|
The Notebook ID to restore (format |
required |
version_id
|
str
|
The ID of the saved version to restore. |
required |
Returns:
| Type | Description |
|---|---|
Notebook
|
The restored notebook. |
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. |