labapi.tree.collection.Notebooks#

class labapi.tree.collection.Notebooks(notebooks: Sequence[NotebookInit], user: User)[source]#

Bases: Mapping[IdOrNameIndex, Notebook | Sequence[Notebook]]

A collection of LabArchives notebooks accessible to a user.

This class provides dictionary-like access to notebooks by their ID or name, and supports creating new notebooks. It manages a list of Notebook objects.

__init__(
notebooks: Sequence[NotebookInit],
user: User,
)[source]#

Initialize the notebook collection.

Parameters:
  • notebooks – A sequence of NotebookInit objects containing initial data for the notebooks.

  • user – The authenticated User associated with these notebooks.

Methods

__init__(notebooks, user)

Initialize the notebook collection.

all_items()

Return (name, notebook) pairs in collection order, preserving duplicates.

all_keys()

Return notebook names in collection order, preserving duplicates.

all_values()

Return notebook objects in collection order, preserving duplicates.

create_notebook(name)

Create a new notebook in LabArchives.

get(k[,d])

items()

Return a mapping-compatible view of (name, notebook) pairs.

keys()

Return a mapping-compatible view of notebook names.

values()

Return a mapping-compatible view of notebook objects.

keys() KeysView[str][source]#

Return a mapping-compatible view of notebook names.

Returns:

A keys view of notebook names.

items() ItemsView[str, Notebook][source]#

Return a mapping-compatible view of (name, notebook) pairs.

Returns:

An items view of (name, notebook) pairs.

values() ValuesView[Notebook][source]#

Return a mapping-compatible view of notebook objects.

Returns:

A values view of notebook objects.

all_keys() Sequence[str][source]#

Return notebook names in collection order, preserving duplicates.

all_items() Sequence[tuple[str, Notebook]][source]#

Return (name, notebook) pairs in collection order, preserving duplicates.

get(
k[,
d,]
) D[k] if k in D, else d.  d defaults to None.#
all_values() Sequence[Notebook][source]#

Return notebook objects in collection order, preserving duplicates.

create_notebook(
name: str,
) Notebook[source]#

Create a new notebook in LabArchives.

Parameters:

name – The name of the new notebook.

Returns:

The newly created Notebook object.

Raises:
  • RuntimeError – If the underlying client session has been closed.

  • AuthenticationError – If LabArchives rejects the request due to invalid or expired credentials.

  • ApiError – If LabArchives returns a non-success response, or if the API returns a notebook ID that already exists in the local collection.